home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / admin / do_user_aed.php < prev    next >
Encoding:
PHP Script  |  2003-11-05  |  1.5 KB  |  62 lines

  1. <?php /* ADMIN $Id: do_user_aed.php,v 1.5 2003/11/04 23:13:09 ajdonnison Exp $ */
  2.  
  3. $del = isset($_REQUEST['del']) ? $_REQUEST['del'] : FALSE;
  4.  
  5. $obj = new CUser();
  6.  
  7. if (!$obj->bind( $_POST )) {
  8.     $AppUI->setMsg( $obj->getError(), UI_MSG_ERROR );
  9.     $AppUI->redirect();
  10. }
  11.  
  12. // prepare (and translate) the module name ready for the suffix
  13. $AppUI->setMsg( 'User' );
  14.  
  15. if ($del) {
  16.     if (($msg = $obj->delete())) {
  17.         $AppUI->setMsg( $msg, UI_MSG_ERROR );
  18.         $AppUI->redirect();
  19.     } else {
  20.         $AppUI->setMsg( "deleted", UI_MSG_ALERT, true );
  21.         $AppUI->redirect( '', -1 );
  22.     }
  23.     return;
  24. }
  25.     $isNewUser = !($_REQUEST['user_id']);
  26.     if ( $isNewUser ) {
  27.         // check if a user with the param Username already exists
  28.         $userEx = FALSE;
  29.  
  30.         function userExistence( $userName ) {
  31.             global $obj, $userEx;
  32.             if ( $userName == $obj->user_username ) {
  33.                 $userEx = TRUE;
  34.             }
  35.         }
  36.  
  37.         //pull a list of existing usernames
  38.         $sql = "SELECT user_username FROM users";
  39.         $users = db_loadList( $sql );
  40.  
  41.         // Iterate the above userNameExistenceCheck for each user
  42.         foreach ( $users as $usrs ) {
  43.             $usrLst = array_map( "userExistence", $usrs );
  44.         }
  45.         // If userName already exists quit with error and do nothing
  46.         if ( $userEx == TRUE ) {
  47.             $AppUI->setMsg( "already exists. Try another username.", UI_MSG_ERROR, true );
  48.             $AppUI->redirect( );
  49.         }
  50.  
  51.         $obj->user_owner = $AppUI->user_id;
  52.     }
  53.  
  54.     if (($msg = $obj->store())) {
  55.         $AppUI->setMsg( $msg, UI_MSG_ERROR );
  56.     } else {
  57.         $AppUI->setMsg( $isNewUser ? 'added' : 'updated', UI_MSG_OK, true );
  58.     }
  59.     $AppUI->redirect();
  60.  
  61. ?>
  62.