ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/users.php
Go to the documentation of this file.
00001 <?php
00010 require('includes/application_top.php');
00011 
00012 // Check if session has timed out
00013 if (!isset($_SESSION['admin_id'])) zen_redirect(zen_href_link(FILENAME_LOGIN));
00014 
00015 // make a note of the current user - they can't delete themselves (by accident) or change their own status
00016 $currentUser = $_SESSION['admin_id'];
00017 
00018 // determine whether an action has been requested
00019 if (isset($_POST['action']) && in_array($_POST['action'], array('insert','update','reset'))) {
00020   $action = $_POST['action'];
00021 } elseif (isset($_GET['action']) && in_array($_GET['action'], array('add','edit','password','delete', 'delete_confirm'))) {
00022   $action = $_GET['action'];
00023 } else {
00024   $action = '';
00025 }
00026 
00027 // if needed, check that a valid user id has been passed
00028 if (($action == 'update' || $action == 'reset') && isset($_POST['user']))
00029 {
00030   $user = $_POST['user'];
00031 }
00032 elseif (($action == 'edit' || $action == 'password' || $action == 'delete' || $action == 'delete_confirm') && $_GET['user'])
00033 {
00034   $user = $_GET['user'];
00035 }
00036 elseif(($action=='delete' || $action=='delete_confirm') && isset($_POST['user']))
00037 {
00038   $user = $_POST['user'];
00039 }
00040 elseif (in_array($action, array('edit','password','delete','delete_confirm','update','reset')))
00041 {
00042   $messageStack->add_session(ERROR_NO_USER_DEFINED, 'error');
00043   zen_redirect(zen_href_link(FILENAME_USERS));
00044 }
00045 
00046 // act upon any specific action specified
00047 switch ($action) {
00048   case 'add': // display unpopulated form for adding a new user
00049     $formAction = 'insert';
00050     $profilesList = array_merge(array(array('id'=>0,'text'=>'Choose Profile')), zen_get_profiles());
00051     break;
00052   case 'edit': // display populated form for editing existing user
00053     $formAction = 'update';
00054     $profilesList = array_merge(array(array('id'=>0,'text'=>'Choose Profile')), zen_get_profiles());
00055     break;
00056   case 'password': // display unpopulated form for resetting existing user's password
00057     $formAction = 'reset';
00058     break;
00059   case 'delete_confirm': // remove existing user from database
00060     if (isset($_POST['user']))
00061     {
00062        zen_delete_user($_POST['user']);
00063     }
00064     break;
00065   case 'insert': // insert new user into database. Post data is prep'd for db in the first function call
00066     $errors = zen_insert_user($_POST['name'],$_POST['email'], $_POST['password'], $_POST['confirm'], $_POST['profile']);
00067     if (sizeof($errors) > 0)
00068     {
00069       foreach ($errors as $error)
00070       {
00071         $messageStack->add($error, 'error');
00072       }
00073       $action = 'add';
00074       $formAction = 'insert';
00075       $profilesList = array_merge(array(array('id'=>0,'text'=>'Choose Profile')), zen_get_profiles());
00076     } else
00077     {
00078       $action = '';
00079       $messageStack->add(SUCCESS_NEW_USER_ADDED, 'success');
00080     }
00081     break;
00082   case 'update': // update existing user's details in database. Post data is prep'd for db in the first function call
00083     $errors = zen_update_user($_POST['name'],$_POST['email'], $_POST['id'], $_POST['profile']);
00084     if (sizeof($errors) > 0)
00085     {
00086       foreach ($errors as $error)
00087       {
00088         $messageStack->add($error, 'error');
00089       }
00090       $action = 'edit';
00091       $formAction = 'update';
00092       $profilesList = array_merge(array(array('id'=>0,'text'=>'Choose Profile')), zen_get_profiles());
00093     } else
00094     {
00095       $action = '';
00096       $messageStack->add(SUCCESS_USER_DETAILS_UPDATED, 'success');
00097     }
00098     break;
00099   case 'reset': // reset existing user's password in database. Post data is prep'd for db in the first function call
00100     $errors = zen_reset_password($_POST['user'], $_POST['password'], $_POST['confirm']);
00101     if (sizeof($errors) > 0)
00102     {
00103       foreach ($errors as $error)
00104     {
00105       $messageStack->add($error, 'error');
00106     }
00107     $action = 'password';
00108     $formAction = 'reset';
00109     } else
00110     {
00111       $action = '';
00112       $messageStack->add(SUCCESS_PASSWORD_UPDATED, 'success');
00113     }
00114     break;
00115   default: // no action, simply drop through and display existing users
00116 }
00117 
00118 // we'll always display a list of the available users
00119 $userList = zen_get_users();
00120 ?>
00121 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
00122 <html <?php echo HTML_PARAMS; ?>>
00123 <head>
00124 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
00125 <title><?php echo TITLE; ?></title>
00126 <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
00127 <link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
00128 <link rel="stylesheet" type="text/css" href="includes/admin_access.css">
00129 <script type="text/javascript" src="includes/menu.js"></script>
00130 <script type="text/javascript" src="includes/general.js"></script>
00131 <script type="text/javascript">
00132   <!--
00133   function init()
00134   {
00135     cssjsmenu('navbar');
00136     if (document.getElementById)
00137     {
00138       var kill = document.getElementById('hoverJS');
00139       kill.disabled = true;
00140     }
00141   }
00142   // -->
00143 </script>
00144 </head>
00145 <body onload="init()">
00146 <!-- header //-->
00147 <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
00148 <!-- header_eof //-->
00149 
00150 <!-- body //-->
00151 <div id="pageWrapper">
00152 
00153 <h1><?php echo HEADING_TITLE ?></h1>
00154 <?php if ($action == 'edit' || $action == 'add' || $action == 'password') { ?>
00155 <?php echo zen_draw_form('users', FILENAME_USERS); ?>
00156 <?php if (isset($formAction)) echo zen_draw_hidden_field('action',$formAction) ?>
00157 <?php } ?>
00158 <?php if ($action == 'edit' || $action == 'password') echo zen_draw_hidden_field('user',$user) ?>
00159   <table cellspacing="0">
00160     <thead>
00161       <tr class="headingRow">
00162         <th class="id"><?php echo TEXT_ID ?></th>
00163         <th class="name"><?php echo TEXT_NAME ?></th>
00164         <th class="email"><?php echo TEXT_EMAIL ?></th>
00165         <th class="profile"><?php echo TEXT_PROFILE ?></th>
00166 <?php if ($action == 'add' || $action == 'password') { ?>
00167         <th class="password"><?php echo TEXT_PASSWORD ?></th>
00168         <th class="password"><?php echo TEXT_CONFIRM_PASSWORD ?></th>
00169 <?php } ?>
00170         <th class="actions">&nbsp;</th>
00171       </tr>
00172     </thead>
00173     <tfoot>
00174 <?php if ($action != 'add' && $action != 'edit' && $action != 'password') { ?>
00175       <tr>
00176         <td colspan="5"><a href="<?php echo zen_href_link(FILENAME_USERS, 'action=add') ?>"><?php echo zen_image_button('button_add_user.gif', IMAGE_ADD_USER) ?></a></td>
00177       </tr>
00178 <?php } ?>
00179     </tfoot>
00180 
00181     <tbody>
00182 <?php if ($action == 'add') { ?>
00183       <tr>
00184         <td class="id">&nbsp;</td>
00185         <td class="name"><?php echo zen_draw_input_field('name', isset($_POST['name']) ? $_POST['name'] : '', 'class="field"', false, 'text', true) ?></td>
00186         <td class="email"><?php echo zen_draw_input_field('email', isset($_POST['email']) ? $_POST['email'] : '', 'class="field"', false, 'text', true) ?></td>
00187         <td class="profile"><?php echo zen_draw_pull_down_menu('profile', $profilesList, isset($_POST['profile']) ? $_POST['profile'] : 0) ?></td>
00188         <td class="password"><input type="password" name="password" class="field" value="<?php echo isset($_POST['password']) ? $_POST['password'] : '' ?>"/></td>
00189         <td class="confirm"><input type="password" name="confirm" class="field" value="<?php echo isset($_POST['confirm']) ? $_POST['confirm'] : '' ?>"/></td>
00190         <td class="actions"><?php echo zen_image_submit('button_insert.gif', IMAGE_INSERT) ?> <a href="<?php echo zen_href_link(FILENAME_USERS) ?>"> <?php echo zen_image_button('button_cancel.gif', IMAGE_CANCEL) ?></a></td>
00191       </tr>
00192 <?php } ?>
00193 <?php if (sizeof($userList) > 0) { ?>
00194 <?php foreach ($userList as $userDetails) { ?>
00195       <tr>
00196 <?php if (($action == 'edit' || $action == 'password') && $user == $userDetails['id']) { ?>
00197         <td class="id"><?php echo $userDetails['id'] ?><?php echo zen_draw_hidden_field('id', $userDetails['id']) ?></td>
00198 <?php } else { ?>
00199         <td class="id"><?php echo $userDetails['id'] ?></td>
00200 <?php } ?>
00201 <?php if ($action == 'edit' && $user == $userDetails['id']) { ?>
00202         <td class="name"><?php echo zen_draw_input_field('name', $userDetails['name'], 'class="field"', false, 'text', true) ?></td>
00203         <td class="email"><?php echo zen_draw_input_field('email', $userDetails['email'], 'class="field"', false, 'text', true) ?></td>
00204 <?php } else { ?>
00205         <td class="name"><?php echo $userDetails['name'] ?></td>
00206         <td class="email"><?php echo $userDetails['email'] ?></td>
00207 <?php } ?>
00208 <?php if ($action == 'edit' && $user == $userDetails['id'] && $user != $currentUser) { ?>
00209         <td class="profile"><?php echo zen_draw_pull_down_menu('profile', $profilesList, $userDetails['profile']) ?></td>
00210 <?php } else { ?>
00211         <td class="profile"><?php echo $userDetails['profileName'] ?></td>
00212 <?php } ?>
00213 <?php if ($action == 'password' && $user == $userDetails['id']) { ?>
00214         <td class="password"><?php echo zen_draw_input_field('password', '', 'class="field"', false, 'password', true) ?></td>
00215         <td class="confirm"><?php echo zen_draw_input_field('confirm', '', 'class="field"', false, 'password', true) ?></td>
00216 <?php } elseif($action == 'add' || $action == 'password') { ?>
00217         <td class="password">&nbsp;</td>
00218         <td class="confirm">&nbsp;</td>
00219 <?php } ?>
00220 <?php if ($action == 'edit' || $action == 'password') { ?>
00221 <?php if ($user == $userDetails['id']) { ?>
00222         <td class="actions">
00223           <?php echo zen_image_submit('button_update.gif', IMAGE_UPDATE) ?>
00224           <a href="<?php echo zen_href_link(FILENAME_USERS) ?>"><?php echo zen_image_button('button_cancel.gif', IMAGE_CANCEL) ?></a>
00225         </td>
00226 <?php } else { ?>
00227         <td class="actions">&nbsp;</td>
00228 <?php } ?>
00229 <?php } elseif ($action != 'add') { ?>
00230         <td class="actions">
00231 <?php if ($action != 'delete') { ?>
00232           <a href="<?php echo zen_href_link(FILENAME_USERS, 'action=edit&amp;user=' . $userDetails['id']) ?>"><?php echo zen_image_button('button_edit.gif', IMAGE_EDIT) ?></a>
00233           <a href="<?php echo zen_href_link(FILENAME_USERS, 'action=password&amp;user=' . $userDetails['id']) ?>"><?php echo zen_image_button('button_reset_pwd.gif', IMAGE_RESET_PWD) ?></a>
00234 <?php } ?>
00235 <?php if ($userDetails['id'] != $currentUser) {
00236 
00237   $btn_img = '';
00238   if ($action == 'delete' && $userDetails['id'] == $user) {
00239     $btn_img = 'button_confirm_red.gif';
00240   } else if ($action != 'delete') {
00241     $btn_img = 'button_delete.gif';
00242   }
00243 ?>
00244           <?php echo zen_draw_form('delete_user', FILENAME_USERS, 'action=' . ($action == 'delete' ? 'delete_confirm' : 'delete')); ?>
00245           <input type="hidden" name="user" value="<?php echo $userDetails['id']; ?>" />
00246           <?php echo ($action == 'delete' && $userDetails['id'] == $user ? TEXT_CONFIRM_DELETE : '') . ($btn_img == '' ? '' : zen_image_submit($btn_img, IMAGE_DELETE)) ?>
00247 <?php if ($action == 'delete' && $userDetails['id'] == $user) { ?>
00248             <a href="<?php echo zen_href_link(FILENAME_USERS) ?>"><?php echo zen_image_button('button_cancel.gif', IMAGE_CANCEL) ?></a>
00249 <?php } ?>
00250           </form>
00251 <?php } ?>
00252         </td>
00253       </tr>
00254 <?php } } } else { ?>
00255       <tr>
00256         <td rowspan="4"><?php echo TEXT_NO_USERS_FOUND ?></td>
00257       </tr>
00258 <?php } ?>
00259     </tbody>
00260   </table>
00261 
00262 </div>
00263 <!-- body_eof //-->
00264 
00265 <!-- footer //-->
00266 <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
00267 <!-- footer_eof //-->
00268 <br>
00269 </body>
00270 </html>
00271 <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
 All Data Structures Namespaces Files Functions Variables Enumerations