root/branches/multiuser/admin/users.php

Revision 1759, 5.2 kB (checked in by mdodoo, 3 years ago)

Lots of things are still not working, but I think this code is better than what was currently committed ([1639]
should have been reverted, and the person who committed should have had their SVN access pulled, for example).
Created this by grabbing the trunk code and then manually inserting the MU branch's changes in. This is probably
not usable in an actual installation (no support for creating new user accounts yet, for example), but patches are
welcome.

Not sure why I write so much here - I am not sure anyone other than my fellow devs actually read them...

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2###############################################################################
3# Gregarius - A PHP based RSS aggregator.
4# Copyright (C) 2003 - 2006 Marco Bonetti
5#
6###############################################################################
7# This program is free software and open source software; you can redistribute
8# it and/or modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 2 of the License,
10# or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful, but WITHOUT
13# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14# FITNESS FOR A PARTICULAR PURPOSE.      See the GNU General Public License for
15# more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  or visit
20# http://www.gnu.org/licenses/gpl.html
21#
22###############################################################################
23# E-mail:          mbonetti at gmail dot com
24# Web page:        http://gregarius.net/
25#
26###############################################################################
27
28
29function set_admin_pass($uname=null,$pass=null) {
30        $sql = "select count(*) from " . getTable('users')
31                ." where password != '' and ulevel >=99";
32        list($adminexists) = rss_fetch_row(rss_query($sql));
33        if ($adminexists) {
34                die('Oops. Admin already exists!');
35        }
36       
37        if ($uname && $pass) {
38                rss_query( "update " . getTable('users') . " set uname='$uname', "
39                 ."password='" . md5(md5($pass)) . "' where ulevel=99" );
40                rss_invalidate_cache(); 
41                rss_redirect('admin/');
42                exit();
43        }
44       
45        admin_header();
46                ?>
47        <script type="text/javascript">
48        <!--
49                function on_submit_password_match() {
50                        pass=document.getElementById('password').value;
51                        pass2=document.getElementById('password2').value;
52                        if(pass !== pass2){
53                                msg = '<?php echo __('Passwords do not match!') ?>';
54                                document.getElementById('admin_match_result').innerHTML = msg;
55                                document.getElementById('password').value = '';
56                                document.getElementById('password2').value = '';
57                                return false;
58                        }else{
59                                document.getElementById('password2').value = '';
60                                return loginHandler();
61                        }
62                }       
63        -->
64        </script>
65       
66        <?php
67  echo "\n<div id=\"channel_admin\" class=\"frame\">";
68        echo "<h2></h2>\n"
69                . __('<p>No Administrator has been specified yet!</p><p>Please provide an Administrator username and password now!</p>');
70       
71        echo "<form action=\"".$_SERVER['PHP_SELF'] . "\" onsubmit=\"return on_submit_password_match();\" method=\"post\">\n"
72        ."<fieldset style=\"width:400px;\">"
73        ."<p><label style=\"display:block\" for=\"username\">".__('Username').":</label>\n"
74        ."<input type=\"text\" id=\"username\" name=\"username\" /></p>\n"
75        ."<p><label style=\"display:block\" for=\"password\">".__('Password').":</label>\n"
76        ."<input type=\"password\" id=\"password\" name=\"password\" /></p>\n"
77        ."<p><label style=\"display:block\" for=\"password2\">".__('Password (again)').":</label>\n"
78        ."<input type=\"password\" id=\"password2\" name=\"password2\" /></p>\n"
79        ."<p><input type=\"submit\" value=\"".__('OK')."\" /></p>\n"
80        ."<div style=\"display:inline;\" id=\"admin_match_result\"></div>\n"
81        ."</fieldset>\n"
82        ."</form>\n";
83       
84        echo "</div>\n";
85        admin_footer(); 
86        exit();
87}
88
89function rss_login_form($uname=null,$pass=null) {
90       
91        admin_header();
92  echo "\n<div id=\"channel_admin\" class=\"frame\">";
93               
94        echo "<form id=\"admin_login\" onsubmit=\"return loginHandler();\" 
95                style=\"text-align:center\" action=\"".$_SERVER['PHP_SELF'] ."\" method=\"post\">\n"
96        ."<fieldset>"
97        ."<legend>" . __('Please log in') . "</legend>\n"
98        ."<p><label style=\"display:block\" for=\"username\">".__('Username').":</label>\n"
99        ."<input type=\"text\" id=\"username\" name=\"username\" /></p>\n"
100        ."<p><label style=\"display:block\" for=\"password\">".__('Password').":</label>\n"
101        ."<input type=\"password\" id=\"password\" name=\"password\" /></p>\n"
102        ."<p id=\"admin_login_submit\"><input type=\"submit\" value=\"".__('Login')."\" /></p>\n"
103        ."<span style=\"display:inline;\" id=\"admin_login_result\"></span>\n"
104        ."</fieldset>\n"
105        ."</form>\n";
106       
107        echo "</div>\n";
108        admin_footer(); 
109        exit();
110}
111
112
113function users(){
114        echo "<h2 class=\"trigger\">".LBL_ADMIN_USERS."</h2>\n";
115        if(rss_user_check_user_level(RSS_USER_LEVEL_ADMIN)){
116                // TODO: we need more labels here
117                echo "<table>\n"
118                ."<tr>\n"
119                ."\t<th>" . __('Username') . "</th>\n"
120                ."\t<th></th>\n"
121                ."\t<th></th>\n"
122                ."\t<th></th>\n"
123                ."</tr>\n";
124                $sql = "select uid, uname, realname, ulevel, lastlogin from " .getTable("users");
125                $res = rss_query($sql);
126            $cntr = 0;
127            while (list($uid, $uname, $realname, $ulevel, $lastlogin) = rss_fetch_row($res)){
128                $class_ = (($cntr++ % 2 == 0)?"even":"odd");
129                echo "<tr class=\"$class_\" id=\"u$uid\">\n"
130                ."\t<td>$uname</td>\n"
131                ."\t<td>$realname</td>\n"
132                ."\t<td>$ulevel</td>\n"
133                ."\t<td>$lastlogin</td>\n"
134                ."</tr>\n";
135            }
136                echo "</table>\n";
137                // TODO: add new user dialog
138        }else if($auth_level == RSS_USER_LEVEL_BASIC){
139                // TODO: allow user to edit own profile
140        }       
141}
142
143function users_admin(){
144// perform actions
145}
146?>
Note: See TracBrowser for help on using the browser.