summaryrefslogtreecommitdiffstats
path: root/modules/admin.php
blob: 42e24e48f08a0f34e05994a675e81e7772f7e20c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?php
/*

 This contains all of the subroutines for handling any
   administration function such as prefereneces, etc.

*/

/*              
 * show_access_list
 *
 *   Used in the access.inc template for getting information about
 *    remote servers that have access to use this Ampache server's
 *    catalog.
 */                                                                                                
function show_access_list () {
	$dbh = dbh();
        
	$sql = "SELECT * FROM access_list";
	$db_result = mysql_query($sql, $dbh);

	if ( mysql_num_rows($db_result) ) {
		while ($host = mysql_fetch_object($db_result) ) {

			$ip = int2ip($host->ip);

			print("\t<tr><td bgcolor=\"" . conf('secondary_color') . "\">$host->name</td>".
				"<td bgcolor=\"" . conf('secondary_color') . "\">$ip</td>".
				"<td bgcolor=\"" . conf('secondary_color') . "\"><a href=\"" . conf('web_path') . "/access.php?action=delete_host&amp;id=$host->id\">Delete</td></tr>\n");
		}
	}
	else {
		print("\t<tr><td bgcolor=\"" . conf('secondary_color') . "\"colspan=\"3\">You don't have any hosts in your access list.</td></tr>\n");
	}
} // show_access_list()  


/*
 * show_manage_users
 *
 */

function show_manage_users () {

	echo "<table class=\"text-box\">\n<tr><td>\n";
	echo "<span class=\"header2\">" . _("Manage Users") . "</span><br />\n";
	echo "<p>Use the following tools to manage the users that access your site.</p>\n";
	echo "<ul>\n\t<li><a href=\"".conf('web_path') . "/admin/users.php?action=show_add_user\">" . _("Add a new user") . "</a></li>\n</ul>\n";
	echo "</td></tr></table>";
	
	show_users();
} // show_manage_users()


/*!
	@function show_user_form
	@discussion shows the user form
*/
function show_user_form ($username, $fullname, $email, $access, $type, $error) {

	require(conf('prefix').'/templates/userform.inc');
    
} // show_user_form()


/*
 * show_change_password
 *
 */

function show_change_password ($username) {

	$user = get_user($username);

        print("<form name=\"change_password\" method=\"post\" action=\"user.php\">");

	print("<p style=\"font-size: 10px; font-weight: bold;\">Changing User Password</p>\n");

        print("<table width=\"90%\">");

        print("<tr>\n");
        print("<td>Enter password:</td>");
        print("<td><input type=password name=new_password_1 size=30 value=\"\"></td>");
        print("</tr>\n");

        print("<tr>\n");
        print("<td>Enter password again:</td>");
        print("<td><input type=password name=new_password_2 size=30 value=\"\"></td>");
        print("</tr>\n");

        print("</table>\n");
        print("<input type=submit name=\"action\" value=\"Change Password\">");
        print("</form>");
} // show_change_password

/*
 * show_update_user_info
 *
 */

function show_update_user_info ($username) {
        
	$user = get_user($username);

	$user->offset_limit = abs($user->offset_limit);

        print("<form name=\"change_password\" method=\"post\" action=\"user.php\">");

	print("<p style=\"font-size: 10px; font-weight: bold;\">Changing User Information for $user->fullname</p>\n");

        print("<table width=\"90%\">");

        print("<tr>\n");
        print("<td>Fullname:</td>");
        print("<td><input type=text name=new_fullname size=30 value=\"$user->fullname\"></td>");
        print("</tr>\n");

        print("<tr>\n");
        print("<td>Email:</td>");
        print("<td><input type=text name=new_email size=30 value=\"$user->email\"></td>");
        print("</tr>\n");

	print("<tr>\n");
	print("<td>View Limit:</td>");
	print("<td><input type=text name=new_offset size=5 value=\"$user->offset_limit\"></td>");
	print("</tr>\n");

        print("</table>\n");
        print("<input type=submit name=\"action\" value=\"Update Profile\">");
        print("</form>");
} // show_update_user_info()

/*
 * show_delete_stats
 *
 */

function show_delete_stats($username) {
        print("<form name=\"clear_statistics\" method=\"post\" action=\"user.php\">");
	print("<br>");

	if ( $username == 'all') {
		print("<p style=\"font-size: 10px; font-weight: bold;\">Delete Your Personal Statistics</p>\n");
	}
	else {
		print("<p style=\"font-size: 10px; font-weight: bold;\">Delete Your Personal Statistics</p>\n");
	}

        print("<input type=submit name=\"action\" value=\"Clear Stats\">");
        print("</form>");
} // show_delete_stats()



/*
 * get_user
 *
 */
function get_user_byid ($id) {


	$sql = "SELECT * FROM user WHERE id='$id'";
	$db_result = mysql_query($sql, dbh());
	return (mysql_fetch_object($db_result));
} // get_user_byid()

function get_user ($username) {


	$sql = "SELECT * FROM user WHERE username='$username'";
	$db_result = mysql_query($sql, dbh());

	return (mysql_fetch_object($db_result));
} // get_user()

/*
 * delete_user
 *
 */

function delete_user ($username) {

	// delete from the user table
        $sql = "DELETE FROM user WHERE username='$username'";
        $db_result = mysql_query($sql, dbh());

	// also delete playlists for user
	$sql = "DELETE FROM playlist WHERE username='$username'";
	$db_result = mysql_query($sql, dbh());

	delete_user_stats('all');

} // delete_user()

/*
 * update_user
 *
 */

function update_user ($username, $fullname, $email, $access) 
{
    $dbh = libglue_param(libglue_param('dbh_name'));
    if(!$username || !$fullname || !$email || !$access) return 0; 
    $sql = "UPDATE user ".
           "SET fullname='$fullname',".
           "email='$email',".
           "access='$access'".
           "WHERE username='$username'";
    $db_result = mysql_query($sql, $dbh);
    if($db_result) return 1;
    else return 0;
} // update_user()

/*
 * update_user_info
 *
 * this for use by 'user' to update limited amounts of info
 *
 */

function update_user_info ($username, $fullname, $email,$offset) {

    $dbh = libglue_param(libglue_param('dbh_name'));

        $sql = "UPDATE user SET fullname='$fullname', email='$email', offset_limit='$offset' WHERE username='$username'";
        $db_result = mysql_query($sql, $dbh);

	// Update current session (so the views are updated)
	$_SESSION['offset_limit'] = $offset;

    return ($db_result)?1:0;

} // update_user_info()


/*
 * set_user_password
 *
 */

function set_user_password ($username, $password1, $password2) {

    $dbh = libglue_param(libglue_param('dbh_name'));
    if($password1 !== $password2) return 0;

	$sql = "UPDATE user SET password=PASSWORD('$password1') WHERE username='$username' LIMIT 1";
	$db_result = mysql_query($sql, $dbh);
    return ($db_result)?1:0;
} // set_user_password()

?>