2 include_once("acctfuncs_po.inc");
4 # Display the standard Account form, pass in default values if any
6 function display_account_form($UTYPE,$A,$U="",$T="",$S="",
7 $E="",$P="",$C="",$R="",$L="",$I="",$N="",$UID=0) {
8 # UTYPE: what user type the form is being displayed for
9 # A: what "form" name to use
10 # U: value to display for username
11 # T: value to display for account type
12 # S: value to display for account suspended
13 # E: value to display for email address
15 # C: confirm password value
16 # R: value to display for RealName
17 # L: value to display for Language preference
18 # I: value to display for IRC nick
19 # N: new package notify value
20 # UID: Users.ID value in case form is used for editing
22 global $SUPPORTED_LANGS;
24 print "<form action='/account.php' method='post'>\n";
25 print "<input type='hidden' name='Action' value='".$A."'>\n";
27 print "<input type='hidden' name='ID' value='".$UID."'>\n";
30 print "<table border='0' cellpadding='0' cellspacing='0' width='80%'>\n";
31 print "<tr><td colspan='2'> </td></tr>\n";
34 print "<td align='left'>".__("Username").":</td>";
35 print "<td align='left'><input type='text' size='30' maxlength='64'";
36 print " name='U' value='".$U."'> (".__("required").")</td>";
39 if ($UTYPE == "Trusted User" || $UTYPE == "Developer") {
40 # only TUs or Devs can promote/demote/suspend a user
43 print "<td align='left'>".__("Account Type").":</td>";
44 print "<td align='left'><select name=T>\n";
45 print "<option value='1'";
46 $T == "User" ? print " selected>" : print ">";
47 print __("Normal user")."\n";
48 print "<option value='2'";
49 $T == "Trusted User" ? print " selected>" : print ">";
50 print __("Trusted user")."\n";
51 if ($UTYPE == "Developer") {
52 # only developers can make another account a developer
54 print "<option value='3'";
55 $T == "Developer" ? print " selected>" : print ">";
56 print __("Developer")."\n";
58 print "</select></td>";
62 print "<td align='left'>".__("Account Suspended").":</td>";
63 print "<td align='left'><input type='checkbox' name='S'";
73 print "<td align='left'>".__("Email Address").":</td>";
74 print "<td align='left'><input type='text' size='30' maxlength='64'";
75 print " name='E' value='".$E."'> (".__("required").")</td>";
79 print "<td align='left'>".__("Password").":</td>";
80 print "<td align='left'><input type='password' size='30' maxlength='32'";
81 print " name='P' value='".$P."'>";
83 print " (".__("required").")";
88 print "<td align='left'>".__("Re-type password").":</td>";
89 print "<td align='left'><input type='password' size='30' maxlength='32'";
90 print " name='C' value='".$C."'>";
92 print " (".__("required").")";
97 print "<td align='left'>".__("Real Name").":</td>";
98 print "<td align='left'><input type='text' size='30' maxlength='32'";
99 print " name='R' value='".$R."'></td>";
103 print "<td align='left'>".__("IRC Nick").":</td>";
104 print "<td align='left'><input type='text' size='30' maxlength='32'";
105 print " name='I' value='".$I."'></td>";
109 print "<td align='left'>".__("Language").":</td>";
110 print "<td align='left'><select name=L>\n";
111 while (list($code, $lang) = each($SUPPORTED_LANGS)) {
113 print "<option value=".$code." selected> ".$lang."\n";
115 print "<option value=".$code."> ".$lang."\n";
118 print "</select></td>";
122 print "<td align='left'>".__("New Package Notify").":</td>";
123 print "<td align='left'><input type='checkbox' name='N'";
131 print "<tr><td colspan='2'> </td></tr>\n";
133 print "<td> </td>";
134 print "<td align='left'>";
135 if ($A == "UpdateAccount") {
136 print "<input type='submit' class='button'";
137 print " value='".__("Update")."'> ";
139 print "<input type='submit' class='button'";
140 print " value='".__("Create")."'> ";
142 print "<input type='reset' class='button' value='".__("Reset")."'>";
150 } # function display_account_form()
153 # process form input from a new/edit account form
155 function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
156 $P="",$C="",$R="",$L="",$I="",$N="",$UID=0) {
157 # UTYPE: The user's account type
158 # TYPE: either "edit" or "new"
159 # A: what parent "form" name to use
160 # U: value to display for username
161 # T: value to display for account type
162 # S: value to display for account suspended
163 # E: value to display for email address
165 # C: confirm password value
166 # R: value to display for RealName
167 # L: value to display for Language preference
168 # I: value to display for IRC nick
169 # N: new package notify value
170 # UID: database Users.ID value
172 # error check and process request for a new/modified account
174 global $SUPPORTED_LANGS;
178 if (!isset($E) || !isset($U)) {
179 $error = __("Missing a required field.");
181 if ($TYPE == "new") {
182 # they need password fields for this type of action
184 if (!isset($P) || !isset($C)) {
185 $error = __("Missing a required field.");
189 $error = __("Missing User ID");
192 if (!$error && $P && $C && ($P != $C)) {
193 $error = __("Password fields do not match.");
195 if (!$error && !valid_email($E)) {
196 $error = __("The email address is invalid.");
198 if ($UTYPE == "Trusted User" && $T == 3) {
199 $error = __("A Trusted User cannot assign Developer status.");
201 if (!$error && !array_key_exists($L, $SUPPORTED_LANGS)) {
202 $error = __("Language is not currently supported.");
205 # check to see if this username is available
206 # NOTE: a race condition exists here if we care...
208 $q = "SELECT COUNT(*) AS CNT FROM Users ";
209 $q.= "WHERE Username = '".mysql_real_escape_string($U)."'";
210 if ($TYPE == "edit") {
211 $q.= " AND ID != ".intval($UID);
213 $result = db_query($q, $dbh);
215 $row = mysql_fetch_array($result);
217 $error = __("The username, %h%s%h, is already in use.",
218 array("<b>", $U, "</b>"));
223 # check to see if this email address is available
224 # NOTE: a race condition exists here if we care...
226 $q = "SELECT COUNT(*) AS CNT FROM Users ";
227 $q.= "WHERE Email = '".mysql_real_escape_string($E)."'";
228 if ($TYPE == "edit") {
229 $q.= " AND ID != ".intval($UID);
231 $result = db_query($q, $dbh);
233 $row = mysql_fetch_array($result);
235 $error = __("The address, %h%s%h, is already in use.",
236 array("<b>", $E, "</b>"));
241 print "<span class='error'>".$error."</span><br/>\n";
242 display_account_form($UTYPE, $A, $U, $T, $S, $E, "", "",
243 $R, $L, $I, $N, $UID);
245 if ($TYPE == "new") {
246 # no errors, go ahead and create the unprivileged user
249 #md5hash the password
251 $q = "INSERT INTO Users (AccountTypeID, Suspended, Username, Email, ";
252 $q.= "Passwd, RealName, LangPreference, IRCNick, NewPkgNotify) ";
253 $q.= "VALUES (1, 0, '".mysql_real_escape_string($U)."'";
254 $q.= ", '".mysql_real_escape_string($E)."'";
255 $q.= ", '".mysql_real_escape_string($P)."'";
256 $q.= ", '".mysql_real_escape_string($R)."'";
257 $q.= ", '".mysql_real_escape_string($L)."'";
258 $q.= ", '".mysql_real_escape_string($I)."'";
264 $result = db_query($q, $dbh);
266 print __("Error trying to create account, %h%s%h: %s.",
267 array("<b>", $U, "</b>", mysql_error($dbh)));
269 # account created/modified, tell them so.
271 print __("The account, %h%s%h, has been successfully created.",
272 array("<b>", $U, "</b>"));
274 print __("Click on the Home link above to login.");
279 # no errors, go ahead and modify the user account
282 #md5 hash the password
283 $q = "UPDATE Users SET ";
284 $q.= "Username = '".mysql_real_escape_string($U)."'";
286 $q.= ", AccountTypeID = ".intval($T);
289 $q.= ", Suspended = 1";
291 $q.= ", Suspended = 0";
293 $q.= ", Email = '".mysql_real_escape_string($E)."'";
295 $q.= ", Passwd = '".mysql_real_escape_string(md5($P))."'";
297 $q.= ", RealName = '".mysql_real_escape_string($R)."'";
298 $q.= ", LangPreference = '".mysql_real_escape_string($L)."'";
299 $q.= ", IRCNick = '".mysql_real_escape_string($I)."'";
300 $q.= ", NewPkgNotify = ";
306 $q.= "WHERE ID = ".intval($UID);
307 $result = db_query($q, $dbh);
309 print __("Error trying to modify account, %h%s%h: %s.",
310 array("<b>", $U, "</b>", mysql_error($dbh)));
312 print __("The account, %h%s%h, has been successfully modified.",
313 array("<b>", $U, "</b>"));
320 # search existing accounts
322 function search_accounts_form() {
323 print "<form action='/account.php' method='post'>\n";
324 print "<input type='hidden' name='Action' value='SearchAccounts'>\n";
326 print "<table border='0' cellpadding='0' cellspacing='0' width='80%'>\n";
327 print "<tr><td colspan='2'> </td></tr>\n";
330 print "<td align='left'>".__("Username").":</td>";
331 print "<td align='left'><input type='text' size='30' maxlength='64'";
332 print " name='U'></td>";
336 print "<td align='left'>".__("Account Type").":</td>";
337 print "<td align='left'><select name=T>\n";
338 print "<option value=''> ".__("Any type")."\n";
339 print "<option value='u'> ".__("Normal user")."\n";
340 print "<option value='t'> ".__("Trusted user")."\n";
341 print "<option value='d'> ".__("Developer")."\n";
342 print "</select></td>";
346 print "<td align='left'>".__("Account Suspended").":</td>";
347 print "<td align='left'><input type='checkbox' name='S'>";
351 print "<td align='left'>".__("Email Address").":</td>";
352 print "<td align='left'><input type='text' size='30' maxlength='64'";
353 print " name='E'></td>";
357 print "<td align='left'>".__("Real Name").":</td>";
358 print "<td align='left'><input type='text' size='30' maxlength='32'";
359 print " name='R'></td>";
363 print "<td align='left'>".__("IRC Nick").":</td>";
364 print "<td align='left'><input type='text' size='30' maxlength='32'";
365 print " name='I'></td>";
369 print "<td align='left'>".__("Sort by").":</td>";
370 print "<td align='left'><select name=SB>\n";
371 print "<option value='u'> ".__("Username")."\n";
372 print "<option value='t'> ".__("Account Type")."\n";
373 print "<option value='r'> ".__("Real Name")."\n";
374 print "<option value='i'> ".__("IRC Nick")."\n";
375 print "<option value='v'> ".__("Last vote")."\n";
376 print "</select></td>";
380 print "<td> </td>";
381 print "<td align='left'> <br/> ";
382 print "<input type='submit' class='button'";
383 print " value='".__("Search'")."> ";
384 print "<input type='reset' class='button'";
385 print " value='".__("Reset")."'></td>";
395 # search results page
397 function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="",
398 $S="",$E="",$R="",$I="") {
399 # UTYPE: what account type the user belongs to
400 # O: what row offset we're at
401 # SB: how to sort the results
402 # U: value to display for username
403 # T: value to display for account type
404 # S: value to display for account suspended
405 # E: value to display for email address
406 # R: value to display for RealName
407 # I: value to display for IRC nick
411 $OFFSET = intval($O);
418 $search_vars = array();
420 $q = "SELECT Users.*, AccountTypes.AccountType ";
421 $q.= "FROM Users, AccountTypes ";
422 $q.= "WHERE AccountTypes.ID = Users.AccountTypeID ";
424 $q.= "AND AccountTypes.ID = 1 ";
425 $search_vars[] = "T";
426 } elseif ($T == "t") {
427 $q.= "AND AccountTypes.ID = 2 ";
428 $search_vars[] = "T";
429 } elseif ($T == "d") {
430 $q.= "AND AccountTypes.ID = 3 ";
431 $search_vars[] = "T";
434 $q.= "AND Users.Suspended = 1 ";
435 $search_vars[] = "S";
438 $q.= "AND Username LIKE '%".mysql_real_escape_string($U)."%' ";
439 $search_vars[] = "U";
442 $q.= "AND Email LIKE '%".mysql_real_escape_string($E)."%' ";
443 $search_vars[] = "E";
446 $q.= "AND RealName LIKE '%".mysql_real_escape_string($R)."%' ";
447 $search_vars[] = "R";
450 $q.= "AND IRCNick LIKE '%".mysql_real_escape_string($I)."%' ";
451 $search_vars[] = "I";
455 $q.= "ORDER BY AccountTypeID, Username ";
458 $q.= "ORDER BY RealName, AccountTypeID ";
461 $q.= "ORDER BY IRCNick, AccountTypeID ";
464 $q.= "ORDER BY LastVoted, Username ";
467 $q.= "ORDER BY Username, AccountTypeID ";
470 $search_vars[] = "SB";
471 $q.= "LIMIT ". $OFFSET . ", " . $HITS_PER_PAGE;
473 $result = db_query($q, $dbh);
475 print __("No results matched your search criteria.");
477 $num_rows = mysql_num_rows($result);
480 print "<table border='0' cellpadding='0'";
481 print " cellspacing='0' width='90%'>\n";
483 print "<td colspan='2'>";
484 print "<table border='0' cellpadding='0'";
485 print " cellspacing='0' width='100%'>\n";
486 print "<th class='header'>";
487 print "<span class='f2'>".__("Username")."</span></th>";
488 print "<th class='header'>";
489 print "<span class='f2'>".__("Type")."</span></th>";
490 print "<th class='header'>";
491 print "<span class='f2'>".__("Status")."</span></th>";
492 print "<th class='header'>";
493 print "<span class='f2'>".__("Real Name")."</span></th>";
494 print "<th class='header'>";
495 print "<span class='f2'>".__("IRC Nick")."</span></th>";
496 print "<th class='header'>";
497 print "<span class='f2'>".__("Last Voted")."</span></th>";
498 print "<th class='header'>";
499 print "<span class='f2'>".__("Edit Account")."</span></th>";
502 while ($row = mysql_fetch_assoc($result)) {
509 print "<td class='".$c."'>";
510 print "<span class='f5'><a href='/packages.php?SeB=m&K=".$row["Username"]."'>".$row["Username"]."</a></span></td>";
511 print "<td class='".$c."'>";
512 print "<span class='f5'>".$row["AccountType"];
513 print "</span></td>";
514 print "<td class='".$c."'><span class='f5'>";
515 if ($row["Suspended"]) {
516 print __("Suspended");
520 print "</span></td>";
521 print "<td class='".$c."'><span class='f5'>";
522 $row["RealName"] ? print $row["RealName"] : print " ";
523 print "</span></td>";
524 print "<td class='".$c."'><span class='f5'>";
525 $row["IRCNick"] ? print $row["IRCNick"] : print " ";
526 print "</span></td>";
527 print "<td class='".$c."'><span class='f5'>";
529 ? print date("Ymd", $row["LastVoted"])
531 print "</span></td>";
532 print "<td class='".$c."'><span class='f5'>";
533 if ($UTYPE == "Trusted User" && $row["AccountType"] == "Developer") {
534 # TUs can't edit devs
536 print " </span></td>";
538 $edit_url = "/account.php?Action=DisplayAccount&ID=".$row["ID"];
539 print "<a href='".$edit_url . "'>";
540 print "Edit</a></span></td>";
546 print "</td></tr>\n";
549 print "<td align='left'>";
550 print "<form action='/account.php' method='post'>\n";
551 print "<input type='hidden' name='Action' value='SearchAccounts'>\n";
552 print "<input type='hidden' name='O'";
553 print " value='".($OFFSET-$HITS_PER_PAGE)."'>\n";
555 while (list($k, $ind) = each($search_vars)) {
556 print "<input type='hidden' name='".$ind."'";
557 print " value='".${$ind}."'>\n";
559 print "<input type='submit' class='button'";
560 print " value='<-- ".__("Less")."'>";
563 print "<td align='right'>";
564 print "<form action='/account.php' method='post'>\n";
565 print "<input type='hidden' name='Action' value='SearchAccounts'>\n";
566 print "<input type='hidden' name='O'";
567 print " value='".($OFFSET+$HITS_PER_PAGE)."'>\n";
569 while (list($k, $ind) = each($search_vars)) {
570 print "<input type='hidden' name='".$ind."'";
571 print " value='".${$ind}."'>\n";
573 print "<input type='submit' class='button'";
574 print " value='".__("More")." -->'>";
582 print __("No more results to display.");
589 # Display non-editable account info
591 function display_account_info($U="",$T="",
593 # U: value to display for username
594 # T: value to display for account type
595 # E: value to display for email address
596 # R: value to display for RealName
597 # I: value to display for IRC nick
599 global $SUPPORTED_LANGS;
602 print "<table border='0' cellpadding='0' cellspacing='0' width='33%'>\n";
604 print " <td colspan='2'> </td>\n";
608 print " <td align='left'>".__("Username").":</td>\n";
609 print " <td align='left'>".$U."</td>\n";
613 print " <td align='left'>".__("Account Type").":</td>\n";
614 print " <td align='left'>";
617 } elseif ($T == "Trusted User") {
618 print __("Trusted User");
619 } elseif ($T == "Developer") {
620 print __("Developer");
625 print " <td align='left'>".__("Email Address").":</td>\n";
626 print " <td align='left'><a href='mailto:".$E."'>".$E."</a></td>\n";
630 print " <td align='left'>".__("Real Name").":</td>\n";
631 print " <td align='left'>".$R."</td>\n";
635 print " <td align='left'>".__("IRC Nick").":</td>\n";
636 print " <td align='left'>".$I."</td>\n";
640 print " <td colspan='2'><a href='/packages.php?K=".$U."&SeB=m'>".__("View this user's packages")."</a></td>\n";
648 # vim: ts=2 sw=2 noet ft=php