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