ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/profiles.php
Go to the documentation of this file.
00001 <?php
00010 require('includes/application_top.php');
00011 
00012 // determine whether an action has been requested
00013 if (isset($_POST['action']) && in_array($_POST['action'], array('insert','update','update_name')))
00014 {
00015   $action = $_POST['action'];
00016 } elseif (isset($_GET['action']) && in_array($_GET['action'], array('add','edit','rename','delete'))) {
00017   $action = $_GET['action'];
00018 } else {
00019   $action = '';
00020 }
00021 
00022 // if needed, check that a valid profile id has been passed
00023 if (isset($action) && ($action == 'update' || $action == 'update_name') && $_POST['profile'])
00024 {
00025   $profile = $_POST['profile'];
00026 }
00027 elseif (isset($action) && ($action == 'edit' || $action == 'delete') && $_GET['profile'])
00028 {
00029   $profile = $_GET['profile'];
00030 }
00031 elseif (in_array($action, array('edit','delete','update','update-name')))
00032 {
00033   $messageStack->add_session(ERROR_NO_PROFILE_DEFINED, 'error');
00034   zen_redirect(zen_href_link(FILENAME_PROFILES));
00035 }
00036 
00037 // take appropriate steps depending upon the action requested
00038 switch ($action) {
00039   case 'add':
00040     $pagesByMenu = zen_get_admin_pages(FALSE);
00041     $menuTitles = zen_get_menu_titles();
00042     break;
00043   case 'edit':
00044     $pagesByMenu = zen_get_admin_pages(FALSE);
00045     $menuTitles = zen_get_menu_titles();
00046     $profileName = zen_get_profile_name($profile);
00047     $permittedPages = zen_get_permitted_pages_for_profile($profile);
00048     break;
00049   case 'delete':
00050     $error = zen_delete_profile($profile);
00051     if ($error != '')
00052     {
00053       $messageStack->add_session($error, 'error');
00054       zen_redirect(zen_href_link(FILENAME_PROFILES));
00055     }
00056     else
00057     {
00058       $messageStack->add(SUCCESS_PROFILE_DELETED, 'success');
00059       unset($action);
00060       $profileList = zen_get_profiles(TRUE);
00061     }
00062     break;
00063   case 'insert':
00064     $error = zen_create_profile($_POST);
00065     if ($error != '')
00066     {
00067       $messageStack->add($error, 'error');
00068       $pagesByMenu = zen_get_admin_pages(FALSE);
00069       $action = 'add';
00070     }
00071     else
00072     {
00073       $messageStack->add_session(SUCCESS_PROFILE_INSERTED, 'success');
00074       zen_redirect(zen_href_link(FILENAME_PROFILES));
00075     }
00076     break;
00077   case 'update':
00078     zen_remove_profile_permits($profile);
00079     zen_insert_pages_into_profile($profile, $_POST['p']);
00080     $messageStack->add_session(SUCCESS_PROFILE_UPDATED, 'success');
00081     zen_redirect(zen_href_link(FILENAME_PROFILES));
00082     break;
00083   case 'update_name':
00084     zen_update_profile_name($profile, $_POST['profile-name']);
00085     $messageStack->add_session(SUCCESS_PROFILE_NAME_UPDATED, 'success');
00086     zen_redirect(zen_href_link(FILENAME_PROFILES));
00087     break;
00088   case 'rename':
00089   default: // if no specific action requested prepare the listing data
00090     $profileList = zen_get_profiles(TRUE);
00091     break;
00092 }
00093 ?>
00094 <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
00095 <html <?php echo HTML_PARAMS; ?>>
00096 <head>
00097 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
00098 <title><?php echo TITLE; ?></title>
00099 <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
00100 <link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
00101 <link rel="stylesheet" type="text/css" href="includes/admin_access.css">
00102 <script type="text/javascript" src="includes/menu.js"></script>
00103 <script type="text/javascript" src="includes/general.js"></script>
00104 <script type="text/javascript">
00105   <!--
00106   function init()
00107   {
00108     cssjsmenu('navbar');
00109     if (document.getElementById)
00110     {
00111       var kill = document.getElementById('hoverJS');
00112       kill.disabled = true;
00113     }
00114   }
00115   function checkAll(form,header,value){
00116     for (var i = 0; i < form.elements.length; i++){
00117       if (form.elements[i].className == header){
00118         form.elements[i].checked = value;
00119       }
00120     }
00121   }
00122   // -->
00123 </script>
00124 </head>
00125 <body onload="init()">
00126 <!-- header //-->
00127 <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
00128 <!-- header_eof //-->
00129 
00130 <!-- body //-->
00131 <div id="pageWrapper">
00132 
00133 <?php if (!isset($action) || $action == '' || $action == 'rename') { ?>
00134 
00135   <h1><?php echo HEADING_TITLE_ALL_PROFILES ?></h1>
00136 
00137   <table cellspacing="0">
00138     <thead>
00139       <tr>
00140         <th class="id"><?php echo TEXT_ID ?></th>
00141         <th class="name"><?php echo TEXT_NAME ?></th>
00142         <th class="users"><?php echo TEXT_USERS ?></th>
00143         <th class="actions">&nbsp;</th>
00144       </tr>
00145     </head>
00146 
00147 <?php if ($action != 'rename') { ?>
00148     <tfoot>
00149       <tr>
00150         <td colspan="4"><a href="<?php echo zen_href_link(FILENAME_PROFILES, 'action=add') ?>"><?php echo zen_image_button('button_add_profile.gif', IMAGE_ADD_PROFILE) ?></a></td>
00151       </tr>
00152     </tfoot>
00153 <?php } ?>
00154 
00155     <tbody>
00156 <?php if (sizeof($profileList) > 0) { ?>
00157 <?php foreach ($profileList as $profileDetails) { ?>
00158       <tr>
00159         <td class="id"><?php echo $profileDetails['id'] ?></td>
00160 <?php if ($action == 'rename' && $_GET['profile'] == $profileDetails['id']) { ?>
00161         <td colspan="3">
00162           <?php echo zen_draw_form('profileNameForm', FILENAME_PROFILES, '', 'post', 'id="profile-update"') ?>
00163             <input type="hidden" name="action" value="update_name"/>
00164             <input type="hidden" name="profile" value ="<?php echo $profileDetails['id'] ?>"/>
00165             <input type="text" name="profile-name" value="<?php echo $profileDetails['name'] ?>"/>
00166             <?php echo zen_image_submit('button_update.gif', IMAGE_UPDATE) ?>
00167             <a href="<?php echo zen_href_link(FILENAME_PROFILES) ?>"><?php echo zen_image_button('button_cancel.gif', IMAGE_CANCEL) ?></a>
00168           </form>
00169         </td>
00170 <?php } else { ?>
00171         <td class="name"><?php echo $profileDetails['name'] ?></td>
00172         <td class="users"><?php echo $profileDetails['users'] ?></td>
00173 <?php if ($profileDetails['id'] != SUPERUSER_PROFILE) { ?>
00174         <td class="actions">
00175           <a href="<?php echo zen_href_link(FILENAME_PROFILES, 'action=edit&amp;profile=' . $profileDetails['id']) ?>"><?php echo zen_image_button('button_edit.gif', IMAGE_EDIT) ?></a>
00176           <a href="<?php echo zen_href_link(FILENAME_PROFILES, 'action=rename&amp;profile=' . $profileDetails['id']) ?>"><?php echo zen_image_button('button_rename.gif', IMAGE_RENAME) ?></a>
00177 <?php if ($profileDetails['users'] == 0) { ?>
00178           <a href="<?php echo zen_href_link(FILENAME_PROFILES, 'action=delete&amp;profile=' . $profileDetails['id']) ?>"><?php echo zen_image_button('button_delete.gif', IMAGE_DELETE) ?></a>
00179 <?php } ?>
00180         </td>
00181 <?php } else { ?>
00182         <td>&nbsp;</td>
00183 <?php } ?>
00184 <?php } ?>
00185 <?php } // end foreach ?>
00186       </tr>
00187 <?php } else { ?>
00188       <tr>
00189         <td colspan="4"><?php echo TEXT_NO_PROFILES_FOUND ?></td>
00190       </tr>
00191 <?php } ?>
00192     </tbody>
00193   </table>
00194 
00195 <?php } elseif ($action == 'edit') { ?>
00196 
00197   <h1><?php echo sprintf(HEADING_TITLE_INDIVIDUAL_PROFILE, $profileName) ?></h1>
00198 
00199   <form id="profileBoxes" name="profileBoxes" action="<?php echo zen_href_link(FILENAME_PROFILES) ?>" method="post">
00200     <input type="hidden" name="action" value="update"/>
00201     <input type="hidden" name="profile" value="<?php echo $profile ?>"/>
00202     <div class="formButtons">
00203       <?php echo zen_image_submit('button_update.gif', IMAGE_UPDATE) ?>
00204       <a href="<?php echo zen_href_link(FILENAME_PROFILES) ?>"><?php echo zen_image_button('button_cancel.gif', IMAGE_CANCEL) ?></a>
00205     </div>
00206 <?php foreach($pagesByMenu as $menuKey => $pageList) { ?>
00207     <dl>
00208       <dt>
00209         <strong class="checkLabel"><?php echo $menuTitles[$menuKey] ?></strong>
00210         <input class="checkButton" type="button" value="check All" onclick="checkAll(this.form,'<?php echo $menuKey ?>',true);">
00211         <input class="checkButton" type="button" value="Uncheck All" onclick="checkAll(this.form,'<?php echo $menuKey ?>',false);">
00212       </dt>
00213 <?php foreach ($pageList as $pageKey => $page) { ?>
00214 <?php $checked = in_array($pageKey,$permittedPages) ? 'checked="checked"' : '' ?>
00215       <dd><label><input name="p[]" class="<?php echo $menuKey ?>" type="checkbox" value="<?php echo $pageKey ?>" <?php echo $checked ?>><?php echo $page['name'] ?></label></dd>
00216 <?php } ?>
00217     </dl>
00218 <?php } ?>
00219     <div class="formButtons">
00220       <?php echo zen_image_submit('button_update.gif', IMAGE_UPDATE) ?>
00221       <a href="<?php echo zen_href_link(FILENAME_PROFILES) ?>"><?php echo zen_image_button('button_cancel.gif', IMAGE_CANCEL) ?></a>
00222     </div>
00223   </form>
00224 
00225 <?php } elseif ($action == 'add') { ?>
00226 
00227   <h1><?php echo HEADING_TITLE_NEW_PROFILE ?></h1>
00228     <?php echo zen_draw_form('profiles', FILENAME_PROFILES, 'action=insert') ?>
00229     <?php echo zen_draw_input_field('name', isset($_POST['name']) ? $_POST['name'] : '', 'class="field"', false, 'text', true) ?>
00230     <input type="hidden" name="action" value="insert"/>
00231     <div class="formButtons">
00232       <?php echo zen_image_submit('button_save.gif', IMAGE_SAVE) ?>
00233       <a href="<?php echo zen_href_link(FILENAME_PROFILES) ?>"><?php echo zen_image_button('button_cancel.gif', IMAGE_CANCEL) ?></a>
00234     </div>
00235 <?php foreach($pagesByMenu as $menuKey => $pageList) { ?>
00236     <dl>
00237       <dt>
00238         <strong><?php echo $menuTitles[$menuKey] ?></strong>
00239         <input class="checkButton" type="button" value="check All" onclick="checkAll(this.form,'<?php echo $menuKey ?>',true);">
00240         <input class="checkButton" type="button" value="Uncheck All" onclick="checkAll(this.form,'<?php echo $menuKey ?>',false);">
00241       </dt>
00242 <?php foreach ($pageList as $pageKey => $page) {
00243         $checked = isset($_POST['p']) && in_array($pageKey, $_POST['p']) ? ' checked="checked"' : '' ?>
00244       <dd><label><input name="p[]" class="<?php echo $menuKey ?>" type="checkbox" value="<?php echo $pageKey ?>"<?php echo $checked ?>><?php echo $page['name'] ?></label></dd>
00245 <?php } ?>
00246     </dl>
00247 <?php } ?>
00248     <div class="formButtons">
00249       <?php echo zen_image_submit('button_save.gif', IMAGE_SAVE) ?>
00250       <a href="<?php echo zen_href_link(FILENAME_PROFILES) ?>"><?php echo zen_image_button('button_cancel.gif', IMAGE_CANCEL) ?></a>
00251     </div>
00252   </form>
00253 <?php } ?>
00254 
00255 </div>
00256 <!-- body_eof //-->
00257 
00258 <!-- footer //-->
00259 <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
00260 <!-- footer_eof //-->
00261 <br>
00262 </body>
00263 </html>
00264 <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
 All Data Structures Namespaces Files Functions Variables Enumerations