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'];
24 //////////////////////////////
26 if( $_POST['person_id'] )
27 $person_id= $_POST['person_id'];
30 //////////////////// add in site
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 //////////////////// remove from sites
41 if ( $_POST['Remove_Sites']){
42 if( $_POST['rem_site'] ) {
43 foreach( $_POST['rem_site'] as $site_id ) {
44 $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
46 header( "location: index.php?id=$person_id" );
49 echo "<h3><span class='plc-warning'>Please select one or more Sites to remove.<br /></h3> </span>\n";
50 echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
55 //////////////////// remove roles
57 if ( $_POST['Remove_Roles']){
58 if($_POST['rem_role']) {
59 $rem_ids= $_POST['rem_role'];
60 foreach( $rem_ids as $role_id ) {
61 $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
63 header( "location: index.php?id=$person_id" );
66 echo "<h3><span class='plc-warning'>Please select one or more Roles to remove.<br /></h3> </span>\n";
67 echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
71 //////////////////// add roles
72 if( $_POST['add_role'] ) {
73 $role_id= $_POST['add_role'];
75 $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
77 header( "location: index.php?id=$person_id" );
81 //////////////////// enable
83 if ( $_GET['enab_id'] ) {
84 $per_id= $_GET['enab_id'];
86 $fields= array( "enabled"=>true );
88 $api->UpdatePerson( intval( $per_id ), $fields );
90 header( "location: index.php?id=$per_id" );
95 //////////////////// disable person
96 if( $_GET['dis_id'] ) {
97 $per_id= $_GET['dis_id'];
99 $fields= array( "enabled"=>false );
101 $api->UpdatePerson( intval( $per_id ), $fields );
103 header( "location: index.php?id=$per_id" );
108 // if action exists figure out what to do
109 if( $_POST['action'] ) {
111 // depending on action, run function
112 switch( $_POST['action'] ) {
114 header( "location: person_actions.php?del_id=$person_id" );
118 header( "location: person_actions.php?dis_id=$person_id" );
122 header( "location: person_actions.php?enab_id=$person_id" );
126 plc_debug('plc',$plc);
127 $plc->BecomePerson (intval($person_id));
128 header ( "location: index.php" );
134 //////////////////// delete person
135 if( $_GET['per_id'] ) {
136 $per_id= $_GET['per_id'];
138 $api->DeletePerson( intval( $per_id ) );
140 header( "location: index.php" );
145 if ( $_POST['Remove_keys'] ){
146 if( $_POST['rem_key'] ) {
147 $key_ids= $_POST['rem_key'];
149 foreach( $key_ids AS $key_id ) {
150 $api->DeleteKey( intval( $key_id ) );
152 header( "location: index.php?id=$person_id" );
155 echo "<h3><span class='plc-warning'>Please select one or more keys to remove.<br /></h3> </span>\n";
156 echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
160 // upload a key if the user submitted one
161 if ( $_POST['Upload']){
162 if( isset( $_FILES['key'] ) ) {
163 $key_file= $_FILES['key']['tmp_name'];
165 $fp = fopen( $key_file, "r" );
168 // opened the key file, read the one line of contents
169 // The POST operation always creates a file even if the filename
170 // the user specified was garbage. If there was some problem
171 // with the source file, we'll get a zero length read here.
172 $key = fread($fp, filesize($key_file));
175 $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
178 $error= $api->error();
179 echo "<h3><span class='plc-warning'> Please verify your SSH file content.<br /></h3> </span>\n";
180 print '<br /><div class="messages error">' . $error . '</div>';
181 echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
184 header( "location: index.php?id=$person_id" );
188 $error= "Unable to open key file.";
189 print '<div class="messages error">' . $error . '</div>';
192 echo "<h3><span class='plc-warning'>Please select a valid SSH key file to upload.<br /></h3> </span>\n";
193 echo "<br /><hr /><p><a href='/db/persons/index.php?id=$person_id'>Back to person page</a></div>";
198 // delete person confimation
199 if( $_GET['del_id'] ) {
200 $person_id= $_GET['del_id'];
202 // get person info from API
203 $person_info= $api->GetPersons( array( intval( $person_id ) ), array( "first_name", "last_name", "email", "roles" ) );
206 echo "<form action='person_actions.php?per_id=$person_id' method=post>\n";
208 // show delete confirmation
209 echo "<h2>Delete ". $person_info[0]['first_name'] ." ". $person_info[0]['last_name'] ."</h2>\n";
210 echo "<p>Are you sure you want to delete this user?\n";
212 echo "<table><tbody>\n";
213 echo "<tr><th>Email: </th><td> ". $person_info[0]['email'] ."</td></tr>\n";
214 echo "<tr><th>Roles: </th><td> ";
216 foreach( $person_info[0]['roles'] as $role ) {
217 echo "$role<br />\n";
222 echo "</tbody></table>\n";
223 echo "<p><input type=submit value='Delete User' name='delete'>\n";
230 include 'plc_footer.php';