Fix grab_file test after move from string module.
[ccan] / web / changedetail.php
1 <?php
2 session_start(); // start session.
3 if($_SESSION["slogged"] == false) {
4         header('Location: login.php?referer=changedetail.php');
5         exit();
6 }
7
8 else {
9 include('logo.html');
10 include('menulist.html');
11 include('configuration');
12
13 //get account data 
14 $handle = sqlite3_open($db) or die("Could not open database");
15 $accountid = $_SESSION['susername'];
16 $query = "SELECT * FROM users where username=\"$accountid\"";
17 $result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
18
19 $row = sqlite3_fetch_array($result);
20 $name = $row["name"];
21 $email = $row["email"];
22 $website = $row["website"];
23 $password = '';
24 $repassword = '';
25 }
26
27 if(isset($_POST['submit'])) {
28         $name = $_REQUEST['name'];
29         $email = $_REQUEST['email'];
30         $website = $_REQUEST['website'];
31         $password = $_REQUEST['password'];
32         $repassword = $_REQUEST['repassword'];
33         if(trim($name) == '') { 
34                 $errmsg = 'Please enter your name';
35         } 
36
37         else if(trim($email) == '') {
38                 $errmsg = 'Please enter your email address';
39         }
40
41         else if(!isEmail($email)) {
42                 $errmsg = 'Your email address is not valid';
43         }
44
45         if($password != '' || $repassword != '') {
46                 if(strlen($password) < 6 || strlen($password) > 16) 
47                          $errmsg = 'Password should have length between 6 and 16';
48                 if($password != $repassword)
49                          $errmsg = 'Password and retype password not match';
50         }
51 }
52
53 if(trim($errmsg) != '' || !isset($_POST['submit'])) {
54 ?>
55                 <h3 class="firstheader" align="center">Change CCAN account</h3>
56                 <div align="center" class="errmsg"><font color="RED"><?=$errmsg;?></font></div>
57                 <div align="center">Note: Please leave password fields blank if you donot want to change</div>
58                 <form method="post" align="center" action="changedetail.php">
59                 <table align="center" width="70%" border="0" bgcolor="gray" cellpadding="8" cellspacing="1">
60                 <tr align="left" bgcolor="lightgray">
61                 <td><p>Full name: </p><p><input name="name" type="text" value="<?=$name;?>"/></p></td
62                 </tr>
63                 <tr align="left" bgcolor="silver">
64                 <td><p>Email: </p><p><input name="email" type="text" value="<?=$email;?>"/> </p></td>
65                 </tr>
66                 <tr align="left" bgcolor="lightgray">
67                 <td><p>New Password: </p><p><input name="password" type="password" value="<?=$password;?>"/></p></td>
68                 </tr>
69                 <tr align="left" bgcolor="silver">
70                 <td><p>Retype Password: </p><p><input name="repassword" type="password" value="<?=$repassword;?>"/><br /></p>
71                 </td>
72                 </tr>
73                 <tr align="left" bgcolor="lightgray">
74                 <td><p>Web Site[Optional]: </p><p><input name="website" type="text" value="<?=$website;?>"/><br /></p>
75                 </td>
76                 </tr>
77                 <tr align="center">
78                 <td><input type="submit" name="submit" value="Change Account"/></td>
79                 </tr>
80                 </table>
81                 </form>
82                 <hr>
83                 </body>
84                 </html>
85 <?php
86 }
87 else {
88 $handle = sqlite3_open($db) or die("Could not open database");
89 $query = "update users set name=\"".$name."\",email=\"".$email."\",website=\"".$website."\" where username=\"$accountid\"";
90 $result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
91 $ispass = '';
92 if($password != '' && $repassword != '' && $password == $repassword ) {
93         $password = md5($password);
94         $query = "update login set password=\"$password\" where username=\"$accountid\"";
95         $result = sqlite3_exec($handle, $query) or die("Error in query: ".sqlite3_error($handle));
96         $ispass = "password. Please login again";
97         session_destroy();
98 }
99 echo "<div align=\"center\"> Sucessfully changed ".$ispass."... <//div><//body><//html>";
100 }
101
102 function isEmail($email)
103 {
104         return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"
105                         ,$email));
106 }
107 ?>