3 if($_SESSION["slogged"] == false) {
4 header('Location: login.php?referer=approval.php?accountid='.$_GET['accountid']);
9 include('menulist.html');
10 include('configuration');
11 $accountid = $_GET['accountid'];
12 $username = $_SESSION['susername'];
14 if(!isset($_POST['submit']) && !isset($_POST['cancel']))
16 //checking for admin rites
17 $handle = sqlite3_open($db) or die("Could not open database");
18 $query = "SELECT * FROM users where username=\"$username\"";
19 $result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
20 $row = sqlite3_fetch_array($result);
21 if ($row["admin"] == "false") {
22 echo "<div align=\"center\">You donot have a rite to approve users</div>";
26 //extracting user information
27 $query = "SELECT * FROM users where username=\"$accountid\"";
28 $result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
29 if (($row = sqlite3_fetch_array($result)) == '') {
30 echo "<div align=\"center\">Not a valid account id</div>";
35 $email = $row["email"];
36 $website = $row["website"];
37 $desc = $row["description"];
39 if($row["approved"] == "true") {
40 $query = "SELECT * FROM approval where approved=\"$accountid\"";
41 $result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
42 $row = sqlite3_fetch_array($result);
43 echo "<div align=\"center\"> Already <b>$accountid</b> is approved by <b>".$row["approvedby"]."</b>...</div>";
47 <h3 class="firstheader" align="center">Approval</h3>
48 <form method="post" action="approval.php?accountid=<?=$accountid?>" >
49 <table align="center" border="0" cellpadding="10" bgcolor="gray">
50 <tr align="left" bgcolor="lightgray">
51 <td> <p>Full name: </td><td><?=$name;?></p></td>
53 <tr align="left" bgcolor="silver">
54 <td> <p>Account id: </td><td><?=$accountid;?></p></td>
56 <tr align="left" bgcolor="lightgray">
57 <td> <p>Email: </td><td><?=$email;?></p>
60 <tr align="left" bgcolor="silver">
61 <td> <p>Description: </td><td><?=$desc;?></p> </td>
63 <tr align="left" bgcolor="lightgray">
64 <td> <p>Web Site: </td><td><?=$website;?></p> </td>
66 <tr align="left" bgcolor="lightgray">
67 <td>Admin rites</td><td><input type="checkbox" name="isadmin"> (check this if you want this user to be admin) </td>
70 <td> <input type="submit" name="submit" value="Approve"/></td>
71 <td><input type="submit" name="cancel" value="Cancel Approval"/></td>
81 else if (isset($_POST['submit'])) {
83 $handle = sqlite3_open($db) or die("Could not open database");
84 $query = "update users set approved=\"true\" where username=\"$accountid\"";
85 $result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
87 //where whether user is given admin permission
88 if($_POST['isadmin']) {
89 $query = "update users set admin=\"true\" where username=\"$accountid\"";
90 $result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
94 $query = "insert into approval values(\"$accountid\",\"$username\")";
95 $result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
98 $query = "SELECT * FROM users where username=\"$accountid\"";
99 $result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
100 $row = sqlite3_fetch_array($result);
101 $email = $row["email"];
103 //generate password and send mail
104 $password = generate_passwd(8);
105 $subject = "Approval of ccan account";
106 $message = "Your request for ccan account id is being approved.\n\n Please use the following password to login\n Password: ".$password;
107 $password = md5($password);
110 $query = "insert into login (username,password) values(\"$accountid\",\"$password\")";
111 $result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
114 mail($email, $subject, $message, "From: $frommail");
115 echo "<div align=center> Successfully approved <b>$accountid</b>...</div>";
118 //if approval is canceled
119 else if (isset($_POST['cancel'])) {
121 $handle = sqlite3_open($db) or die("Could not open database");
122 $query = "delete from users where username=\"$accountid\"";
123 $result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
124 echo "<div align=center> Successfully cancelled <b>$accountid</b>...</div>";
127 function generate_passwd($length = 16) {
128 static $chars = '!@#$%^&*abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ23456789';
129 $chars_len = strlen($chars);
130 for ($i = 0; $i < $length; $i++)
131 $password .= $chars[mt_rand(0, $chars_len - 1)];