4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
11 require_once 'plc_drupal.php';
13 drupal_set_title('Persons');
14 include 'plc_header.php';
17 require_once 'plc_functions.php';
18 require_once 'plc_sorts.php';
21 $_person= $plc->person;
22 $_roles= $_person['role_ids'];
26 if( $_POST['person_id'] )
27 $person_id= $_POST['person_id'];
30 // if site_id submitted add the person to that site_id
31 if( $_POST['site_add'] ) {
32 $site_id= $_POST['site_add'];
34 $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
35 header( "location: index.php?id=$person_id" );
40 if ( $_POST['Remove_Sites']){
41 if( $_POST['rem_site'] ) {
42 foreach( $_POST['rem_site'] as $site_id ) {
43 $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
45 header( "location: index.php?id=$person_id" );
48 echo "<h3><span class='plc-warning'>Please select one or more Sites to remove.<br /></h3> </span>\n";
49 echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
54 if ( $_POST['Remove_Roles']){
55 if($_POST['rem_role']) {
56 $rem_ids= $_POST['rem_role'];
57 foreach( $rem_ids as $role_id ) {
58 $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
60 header( "location: index.php?id=$person_id" );
63 echo "<h3><span class='plc-warning'>Please select one or more Roles to remove.<br /></h3> </span>\n";
64 echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
69 if( $_POST['add_role'] ) {
70 $role_id= $_POST['add_role'];
72 $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
74 header( "location: index.php?id=$person_id" );
79 if( $_GET['enab_id'] ) {
80 $per_id= $_GET['enab_id'];
82 $fields= array( "enabled"=>true );
84 $api->UpdatePerson( intval( $per_id ), $fields );
86 header( "location: index.php?id=$per_id" );
92 if( $_GET['dis_id'] ) {
93 $per_id= $_GET['dis_id'];
95 $fields= array( "enabled"=>false );
97 $api->UpdatePerson( intval( $per_id ), $fields );
99 header( "location: index.php?id=$person_id" );
104 // if action exists figure out what to do
105 if( $_POST['action'] ) {
107 // depending on action, run function
108 switch( $_POST['action'] ) {
110 header( "location: person_actions.php?del_id=$person_id" );
114 header( "location: person_actions.php?dis_id=$person_id" );
118 header( "location: person_actions.php?enab_id=$person_id" );
122 plc_debug('plc',$plc);
123 $plc->BecomePerson (intval($person_id));
124 header ( "location: index.php" );
131 if( $_GET['per_id'] ) {
132 $person_id= $_GET['per_id'];
134 $api->DeletePerson( intval( $person_id ) );
136 header( "location: index.php" );
141 if ( $_POST['Remove_keys'] ){
142 if( $_POST['rem_key'] ) {
143 $key_ids= $_POST['rem_key'];
145 foreach( $key_ids AS $key_id ) {
146 $api->DeleteKey( intval( $key_id ) );
148 header( "location: index.php?id=$person_id" );
151 echo "<h3><span class='plc-warning'>Please select one or more keys to remove.<br /></h3> </span>\n";
152 echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
156 // upload a key if the user submitted one
157 if ( $_POST['Upload']){
158 if( isset( $_FILES['key'] ) ) {
159 $key_file= $_FILES['key']['tmp_name'];
161 $fp = fopen( $key_file, "r" );
164 // opened the key file, read the one line of contents
165 // The POST operation always creates a file even if the filename
166 // the user specified was garbage. If there was some problem
167 // with the source file, we'll get a zero length read here.
168 $key = fread($fp, filesize($key_file));
171 $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
174 $error= $api->error();
175 echo "<h3><span class='plc-warning'> Please verify your SSH file content.<br /></h3> </span>\n";
176 print '<br /><div class="messages error">' . $error . '</div>';
177 echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
180 header( "location: index.php?id=$person_id" );
184 $error= "Unable to open key file.";
185 print '<div class="messages error">' . $error . '</div>';
188 echo "<h3><span class='plc-warning'>Please select a valid SSH key file to upload.<br /></h3> </span>\n";
189 echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
194 // delete person confimation
195 if( $_GET['del_id'] ) {
196 $person_id= $_GET['del_id'];
198 // get person info from API
199 $person_info= $api->GetPersons( array( intval( $person_id ) ), array( "first_name", "last_name", "email", "roles" ) );
202 echo "<form action='person_actions.php?per_id=$person_id' method=post>\n";
204 // show delete confirmation
205 echo "<h2>Delete ". $person_info[0]['first_name'] ." ". $person_info[0]['last_name'] ."</h2>\n";
206 echo "<p>Are you sure you want to delete this user?\n";
208 echo "<table><tbody>\n";
209 echo "<tr><th>Email: </th><td> ". $person_info[0]['email'] ."</td></tr>\n";
210 echo "<tr><th>Roles: </th><td> ";
212 foreach( $person_info[0]['roles'] as $role ) {
213 echo "$role<br />\n";
218 echo "</tbody></table>\n";
219 echo "<p><input type=submit value='Delete User' name='delete'>\n";
226 include 'plc_footer.php';