Changeset 279
- Timestamp:
- 05/31/07 10:48:06
- Files:
-
- FreakAuth/trunk/www/system/application/controllers/admin/admins.php (modified) (5 diffs)
- FreakAuth/trunk/www/system/application/controllers/admin/users.php (modified) (5 diffs)
- FreakAuth/trunk/www/system/application/views/FreakAuth_light/template_admin/users/detail.php (modified) (3 diffs)
- FreakAuth/trunk/www/system/application/views/FreakAuth_light/template_admin/users/list.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
FreakAuth/trunk/www/system/application/controllers/admin/admins.php
r244 r279 118 118 119 119 if ($query->num_rows()>0) 120 { 121 $i=1;122 foreach ($query->result() as $row)120 { 121 $i=1; 122 foreach ($query->result() as $row) 123 123 { 124 // when do we display links for editing or deleting a user ? 125 // note: if we are in the admins controller, we are a superadmin 126 // we display the edit link if 127 // - the user in the table is not a superadmin 128 // - we are a superadmin editing himself 129 $data['user'][$i]['show_edit_link'] = 130 ($row->role != 'superadmin' OR $row->id == getUserProperty('id')); 131 // we display the delete link if 132 // - the user in the table is not a superadmin 133 $data['user'][$i]['show_delete_link'] = 134 ($row->role != 'superadmin'); 135 136 // then we just fill the infos 124 137 $data['user'][$i]['id']= $row->id; 125 138 $data['user'][$i]['user_name']= $row->user_name; … … 168 181 if ($query->num_rows() == 1) 169 182 { 170 $row = $query->row(); 183 $row = $query->row(); 184 185 // initializing two flags, for the edit and delete links 186 // we can edit the displayed admin if 187 // - we are a superadmin 188 // - OR the displayed user is not a superadmin 189 $data['can_edit_user'] = ( 190 getUserProperty('role') != 'superadmin' 191 OR $row->id == getUserProperty('id') 192 OR $row->role != 'superadmin' 193 ); 194 // we cannot delete a superadmin 195 $data['can_delete_user'] = 196 ($row->role != 'superadmin'); 197 171 198 $data['user']['id']= $row->id; 172 199 $data['user']['user_name']= $row->user_name; … … 312 339 /** 313 340 * Manages the edit 314 * 341 * superadmins can only be edited by themselves 342 * 315 343 * @access public 316 * 344 * @param integer $id the id of the admin 317 345 */ 318 function edit( )346 function edit($id) 319 347 { 320 $id = $this->uri->segment(4); 348 // we only allow edition of this admin if he/she is 349 // - not a superadmin OR 350 // - a superadmin editing himself 351 $allowed = ( 352 (getUserPropertyFromId($id, 'role') != 'superadmin') 353 OR (getUserProperty('id') == $id) 354 ); 355 if (!$allowed) $this->freakauth_light->denyAccess(getUserProperty('role')); 321 356 322 357 //set validation rules … … 450 485 451 486 /** 452 * D isplays the registration form.453 * 487 * Deletes an administrator, but not a superadmin 488 * 454 489 * @access public 455 * 490 * @param integer $id the id of the admin 456 491 */ 457 492 function del($id) 458 493 { 459 //CHECK IF ADMIN#1 OR ONLY ONE ADMIN LEFT 460 $fields = 'id'; 461 $query=$this->usermodel->getAdmins($fields); 462 463 //first system admin 464 if ($id==1) 465 { 466 //set a flash message 467 $msg = "It's not allowed to delete the system administrator #1"; 468 469 } 470 //last admin left 471 elseif ($id!=1 AND $query->num_rows()<1) 472 { 473 //set a flash message 474 $msg = "It's not allowed to delete the last system administrator left!"; 475 } 476 else 477 { 478 $this->usermodel->deleteUser($id); 479 480 if ($this->config->item('FAL_create_user_profile')==TRUE) 481 { 482 $this->load->model('Userprofile'); 483 $this->Userprofile->deleteUserProfile($id); 484 } 485 //set a flash message 486 $msg = $this->db->affected_rows().$this->lang->line('FAL_user_deleted'); 487 flashMsg($msg); 488 $this->usermodel->deleteAdmin($id) ; 489 //set a flash message 490 $msg = $this->db->affected_rows().' administrator successfully deleted!'; 491 redirect('admin/admins', 'location'); 492 } 493 494 // we only allow edition of this admin if if he/she is 495 // - not a superadmin 496 $allowed = (getUserPropertyFromId($id, 'role') != 'superadmin'); 497 498 if (!$allowed) $this->freakauth_light->denyAccess(getUserProperty('role')); 499 500 $this->usermodel->deleteUser($id); 501 //set a flash message 502 $msg = $this->db->affected_rows().$this->lang->line('FAL_user_deleted'); 503 504 if ($this->config->item('FAL_create_user_profile')==TRUE) 505 { 506 $this->load->model('Userprofile'); 507 $this->Userprofile->deleteUserProfile($id); 508 } 509 $this->usermodel->deleteUser($id) ; 510 511 flashMsg($msg); 512 redirect('admin/admins', 'location'); 494 513 } 495 514 … … 562 581 return false; 563 582 } 583 564 584 } 565 585 ?> FreakAuth/trunk/www/system/application/controllers/admin/users.php
r245 r279 121 121 foreach ($query->result() as $row) 122 122 { 123 // when do we display links for editing or deleting a user ? 124 // we display the edit and delete links if 125 // the user in the table is neither a superadmin nor an admin 126 $data['user'][$i]['show_edit_link'] = 127 ($row->role != 'admin' AND $row->role != 'superadmin'); 128 $data['user'][$i]['show_delete_link'] = 129 ($row->role != 'admin' AND $row->role != 'superadmin'); 130 131 // then we just fill the infos 123 132 $data['user'][$i]['id']= $row->id; 124 133 $data['user'][$i]['user_name']= $row->user_name; … … 168 177 if ($query->num_rows() == 1) 169 178 { 170 $row = $query->row(); 179 $row = $query->row(); 180 181 // initializing two flags, for the edit and delete links 182 // we can edit the displayed user if 183 // - we are an admin 184 // - OR the displayed user is not a superadmin 185 $data['can_edit_user'] = 186 ($row->role != 'superadmin' AND $row->role != 'admin'); 187 // we cannot delete a superadmin or an admin 188 $data['can_delete_user'] = 189 ($row->role != 'superadmin' AND $row->role != 'admin'); 190 171 191 $data['user']['id']= $row->id; 172 192 $data['user']['user_name']= $row->user_name; … … 329 349 * 330 350 */ 331 function edit( )351 function edit($id) 332 352 { 333 $id = $this->uri->segment(4);334 335 353 // security check: 336 // we need to be a superadmin 337 // OR the target user must not be a superadmin 338 $this->_check_superadmin_handling($id); 354 // admins or superadmins cannot be edited in the users controller 355 $edited_role = getUserPropertyFromId($id, 'role'); 356 $allowed = ($edited_role != 'admin' AND $edited_role != 'superadmin'); 357 if (!$allowed) $this->freakauth_light->denyAccess(getUserProperty('role')); 339 358 340 359 //set validation rules … … 477 496 { 478 497 // security check: 479 // we need to be a superadmin 480 // OR the target user must not be a superadmin 481 $this->_check_superadmin_handling($id); 498 // admins or superadmins cannot be deleted in the users controller 499 $edited_role = getUserPropertyFromId($id, 'role'); 500 $allowed = ($edited_role != 'admin' AND $edited_role != 'superadmin'); 501 if (!$allowed) $this->freakauth_light->denyAccess(getUserProperty('role')); 482 502 483 503 $this->usermodel->deleteUser($id); … … 564 584 return false; 565 585 } 566 567 /**568 * security check used in edit and del functions569 * we need to be a superadmin570 * OR the target user must not be a superadmin571 *572 * @return boolean573 */574 function _check_superadmin_handling($id)575 {576 $allowed =577 (getUserProperty('role') == 'superadmin'578 OR getUserPropertyFromId($id, 'role') != 'superadmin');579 580 if (!$allowed) $this->freakauth_light->denyAccess(getUserProperty('role'));581 }582 586 } 583 587 ?> FreakAuth/trunk/www/system/application/views/FreakAuth_light/template_admin/users/detail.php
r271 r279 35 35 36 36 <?php if (isset($user)) 37 { 38 // initializing a flag 39 // we can handle the displayed user if 40 // we are a superadmin OR the displayed user is not a superadmin 41 $can_handle_user = (getUserProperty('role') == 'superadmin' OR $user['role'] != 'superadmin'); 42 ?> 37 {?> 43 38 <table> 44 39 <tr> … … 56 51 57 52 <?php 58 if ($can_ handle_user)53 if ($can_edit_user OR $can_delete_user) 59 54 {?> 60 55 <th scope="col"> </th> … … 75 70 }?> 76 71 77 <?php 78 if ($can_handle_user) 79 {?> 72 <?php if ($can_edit_user OR $can_delete_user):?> 80 73 <td> 74 <?php endif;?> 75 <?php if ($can_edit_user):?> 81 76 <?=anchor('admin/'.$controller.'/edit/'.$user['id'], '<img src="'.base_url().$this->config->item('FAL_assets_admin').'/'.$this->config->item('FAL_images').'/pencil.png" alt="edit" title="edit">', array('title' => 'edit'));?> 77 <?php endif;?> 78 <?php if ($can_delete_user):?> 82 79 <?=anchor('admin/'.$controller.'/del/'.$user['id'], '<img src="'.base_url().$this->config->item('FAL_assets_admin').'/'.$this->config->item('FAL_images').'/cross.png" alt="delete" title="delete">', array('onCLick' => "return confirm('Are you SURE you want to delete this record?')", 'title'=>'delete'));?> 80 <?php endif;?> 81 <?php if ($can_edit_user OR $can_delete_user):?> 83 82 </td> 84 <?php 85 }?> 86 </tr> 83 <?php endif;?> 84 </tr> 87 85 </table> 88 86 <?php FreakAuth/trunk/www/system/application/views/FreakAuth_light/template_admin/users/list.php
r261 r279 28 28 <td><?=$user[$key]['user_name'];?></td> 29 29 <td><?=$user[$key]['role']?></td> 30 <td> 31 <?=anchor('admin/'.$controller.'/show/'.$user[$key]['id'], '<img src="'.base_url().$this->config->item('FAL_assets_admin').'/'.$this->config->item('FAL_images').'/zoom.png" alt="view" title="view">', array('title' => 'view'));?> 32 <?php 33 // now let's control when we display links for modifying or deleting a user 34 // we display the links to superadmins or if the user in the table is not a superadmin or an admin 35 $admins_list = ($controller == 'admins'); // if we are in the admins controller, we are a superadmin 36 $user_is_not_an_admin = ($user[$key]['role']!='superadmin' AND $user[$key]['role']!='admin'); 37 if ($admins_list OR $user_is_not_an_admin) 38 {?> 39 <?=anchor('admin/'.$controller.'/edit/'.$user[$key]['id'], '<img src="'.base_url().$this->config->item('FAL_assets_admin').'/'.$this->config->item('FAL_images').'/pencil.png" alt="edit" title="edit">', array('title' => 'edit'));?> 40 <?=anchor('admin/'.$controller.'/del/'.$user[$key]['id'], '<img src="'.base_url().$this->config->item('FAL_assets_admin').'/'.$this->config->item('FAL_images').'/cross.png" alt="delete" title="delete">', array('onCLick' => "return confirm('Are you SURE you want to delete this record?')", 'title' => 'delete'));?> 41 <?php 42 } 43 ?> 30 <td> 31 <?=anchor('admin/'.$controller.'/show/'.$user[$key]['id'], '<img src="'.base_url().$this->config->item('FAL_assets_admin').'/'.$this->config->item('FAL_images').'/zoom.png" alt="view" title="view">', array('title' => 'view'));?> 32 <?php 33 if ($user[$key]['show_edit_link']) 34 echo anchor('admin/'.$controller.'/edit/'.$user[$key]['id'], '<img src="'.base_url().$this->config->item('FAL_assets_admin').'/'.$this->config->item('FAL_images').'/pencil.png" alt="edit" title="edit">', array('title' => 'edit')); 35 if ($user[$key]['show_delete_link']) 36 echo anchor('admin/'.$controller.'/del/'.$user[$key]['id'], '<img src="'.base_url().$this->config->item('FAL_assets_admin').'/'.$this->config->item('FAL_images').'/cross.png" alt="delete" title="delete">', array('onCLick' => "return confirm('Are you SURE you want to delete this record?')", 'title' => 'delete')); 37 ?> 44 38 </td> 45 39 </tr>
