cd7f99c65ed84623ef5f61f02da1af5cdb7792d5
[plewww.git] / planetlab / persons / update.php
1 <?
2
3 // Require login
4 require_once 'plc_login.php';
5
6 // Get session and API handles
7 require_once 'plc_session.php';
8 global $plc, $api;
9
10 // Common functions
11 require_once 'plc_functions.php';
12 require_once 'plc_sorts.php';
13
14 // find person roles
15 $_person= $plc->person;
16 $_roles= $_person['role_ids'];
17
18
19 $is_submitted= isset($_POST['submitted']) ? $_POST['submitted'] : 0;
20
21 // show details for the current user.
22 if( isset($_GET['id']) && is_numeric($_GET['id']) ) {
23   $person_id= intval($_GET['id']);
24  } else {
25   header( "location: index.php" );
26   exit();
27  }
28
29 $errors= array();
30
31 if( $is_submitted ) {
32   // attempt to update this person
33   $first_name= $_POST['first_name'];
34   $last_name= $_POST['last_name'];
35   $title= $_POST['title'];
36   $email= $_POST['email'];
37   $phone= $_POST['phone'];
38   $url= $_POST['url'];
39   $bio= str_replace("\r", "", $_POST['bio']);
40   $password1= $_POST['password1'];
41   $password2= $_POST['password2'];
42
43   if( $password1 != $password2 ) {
44     $errors[]= "The passwords do not match";
45   }
46
47   if( count($errors) == 0 ) {   
48     $update_vals= array();
49     $update_vals['first_name']= $first_name;
50     $update_vals['last_name']= $last_name;
51     $update_vals['title']= $title;
52     $update_vals['email']= $email;
53     $update_vals['phone']= $phone;
54     $update_vals['url']= $url;
55     $update_vals['bio']= $bio;
56                 
57     if( $password1 != "" )
58       $update_vals['password']= $password1;
59     
60     $rc= $api->UpdatePerson( intval( $person_id ), $update_vals);
61     
62     if( $rc == 1 ) {
63       Header( "Location: /db/persons/index.php?id=$person_id" );
64       exit();
65     }
66     elseif ($rc === NULL) {
67       $errors[] = $api->error();
68     }
69   }
70  } else {
71   // get details for the user
72   $person_details= $api->GetPersons( array( intval( $person_id ) ), array( "person_id", "first_name", "last_name", "title", "email", "phone", "url", "bio" ) );
73   if ( $person_details === NULL ) {
74     $errors[] = $api->error();
75   } else {
76     $person_detail= $person_details[0];
77   
78     $first_name= $person_detail['first_name'];
79     $last_name= $person_detail['last_name'];
80     $title= $person_detail['title'];
81     $email= $person_detail['email'];
82     $phone= $person_detail['phone'];
83     $url= $person_detail['url'];
84     $bio= $person_detail['bio'];
85   }
86 }
87
88 // Print header
89 require_once 'plc_drupal.php';
90 drupal_set_title('Update Person');
91 include 'plc_header.php';
92
93 ?>
94
95 <h2>Update Account</h2>
96
97 <?
98 if( count($errors) > 0 )
99 {
100   print( "<p><strong>The following errors occured:</strong>" );
101   print( "<font color='red' size='-1'><ul>\n" );
102   foreach( $errors as $err )
103     {
104       print( "<li>$err\n" );
105     }
106   print( "</ul></font>\n" );
107 }
108 ?>
109
110 <h3>Personal Information</h3>
111
112 <form method="post" action="update.php?id=<?php print($person_id); ?>">
113 <input type="hidden" name="submitted" value="1">
114
115 <table width="100%" cellspacing="0" cellpadding="4" border="0">
116
117 <tr>
118 <td>First Name:</td>
119 <td><input type="text" name="first_name"
120 value="<?php print($first_name); ?>" size="30" maxlength="256"></td>
121 </tr>
122
123 <tr>
124 <td>Last Name:</td>
125 <td><input type="text" name="last_name"
126 value="<?php print($last_name); ?>" size="30" maxlength="256"></td>
127 </tr>
128
129 <tr>
130 <td>Title:</td>
131 <td><input type="text" name="title"
132 value="<?php print($title); ?>" size="30" maxlength="256"></td>
133 </tr>
134
135 <tr>
136 <td>Email:</td>
137 <td><input type="text" name="email"
138 value="<?php print($email); ?>" size="30" maxlength="256"></td>
139 </tr>
140
141 <tr>
142 <td>Phone:</td>
143 <td><input type="text" name="phone"
144 value="<?php print($phone); ?>" size="30" maxlength="32"></td>
145 </tr>
146
147 <tr>
148 <td>URL:</td>
149 <td><input type="text" name="url"
150 value="<?php print($url); ?>" size="30" maxlength="200"></td>
151 </tr>
152
153 <tr>
154 <td valign=top>Bio:</td>
155 <td><textarea name="bio" cols="40" rows="5" wrap>
156 <?php print($bio); ?>
157 </textarea></td>
158 </tr>
159
160 <tr>
161 <td>Password (blank for no change):</td>
162 <td><input type="password" name="password1" size="30" maxlength="256"></td>
163 </tr>
164
165 <tr>
166 <td>Repeat Password:</td>
167 <td><input type="password" name="password2" size="30" maxlength="256"></td>
168 </tr>
169
170 </table>
171
172 <input type="submit" name="Submit" value="Update">
173
174 </form>
175
176 <?
177
178 // Print footer
179 include 'plc_footer.php';
180
181 ?>