Example #1
0
 public function getUserAddEditForm($target = '/admin/User', $admin = false)
 {
     $form = new Form('user_addedit', 'POST', $target, '', array('class' => 'admin'));
     $form->setConstants(array('section' => 'addedit'));
     $form->addElement('hidden', 'section');
     if (@$_REQUEST['id']) {
         $user = new User($_REQUEST['id']);
         $form->setConstants(array('id' => $_REQUEST['id']));
         $form->addElement('hidden', 'id');
     } else {
         $user = new User();
     }
     $statuses = array(1 => 'Active', 0 => 'Disabled');
     $form->addElement('text', 'a_username', 'Email address(Username)');
     $form->addElement('password', 'a_password', 'Password');
     $form->addElement('password', 'a_password_confirm', 'Confirm Password');
     $form->addElement('text', 'a_name', 'Full Name');
     //$form->addElement( 'text',  'a_email', 'Email Address');
     if ($admin) {
         $form->addElement('select', 'a_status', 'Active Status', $statuses);
     }
     if (isset($this->user) && $this->user->hasPerm('assigngroups')) {
         $sql = 'SELECT agp_id, agp_name from auth_groups';
         $groups = Database::singleton()->query_fetch_all($sql);
         $assignableGroup = array();
         foreach ($groups as $group) {
             $assignableGroup[$group['agp_id']] = $group['agp_name'];
         }
         if (@$user) {
             $defaultValues['a_group'] = $user->getAuthGroup();
         }
         $form->addElement('select', 'a_group', 'Member Group', $assignableGroup);
     }
     $form->addElement('advcheckbox', 'a_join_newsletter', 'Sign me up for your E-Newsletter');
     $form->addElement('submit', 'a_submit', 'Save');
     $defaultValues['a_username'] = $user->getUsername();
     $defaultValues['a_name'] = $user->getName();
     $defaultValues['a_email'] = $user->getEmail();
     $defaultValues['a_password'] = null;
     $defaultValues['a_password_confirm'] = null;
     $defaultValues['a_join_newsletter'] = $user->getJoinNewsletter();
     if ($admin) {
         $defaultValues['a_status'] = $user->getActiveStatus();
     }
     $form->setDefaults($defaultValues);
     $form->addRule('a_username', 'Please enter a username', 'required', null, 'client');
     $form->addRule('a_username', 'Please enter an email address', 'required', null, 'client');
     $form->addRule('a_username', 'Please enter a valid email address for the username', 'email', null, 'client');
     $form->addRule('a_name', 'Please enter your name', 'required', null, 'client');
     //$form->addRule( 'a_email', 'Please enter an email address', 'required', null );
     //$form->addRule( 'a_email', 'Please enter a valid email address', 'email', null );
     if (!isset($_REQUEST['id'])) {
         $form->addRule('a_password', 'Please enter a password', 'required', null, 'client');
         $form->addRule('a_password_confirm', 'Please confirm the passwords match', 'required', null, 'client');
     }
     $form->addRule(array('a_password', 'a_password_confirm'), 'The passwords do not match', 'compare', null, 'client');
     if (isset($_REQUEST['a_submit']) && $form->validate()) {
         $this->template = 'admin/user.tpl';
         $this->doUserSubmit();
     }
     return $form;
 }
Example #2
0
 /**
  * Manage the accounts of the shoppers
  * 
  * This function allows the shoppers to manage their account
  * They can change their profile (address, email, phone number, etc), or view all the orders that they made
  *  
  * @return string
  */
 public function handleMyAccount($action)
 {
     $auth_container = new User();
     $auth = new Auth($auth_container, null, 'authInlineHTML');
     $auth->start();
     if (!$auth->checkAuth()) {
         return authInlineHTML();
     }
     $userId = $_SESSION['authenticated_user']->getId();
     switch ($action) {
         case 'MyProfile':
             //Display my profile
             //It is easier to re-generate the profile form rather than using the original one
             $form = new Form('user_profile', 'POST', '/Store/MyAccount/&action=MyProfile');
             $form->addElement('static', 'a_username', 'Username');
             $form->addElement('password', 'a_password', 'Password');
             $form->addElement('password', 'a_password_confirm', 'Confirm Password');
             $form->addElement('text', 'a_name', 'Full Name');
             //$form->addElement( 'text',  'a_email', 'Email Address');
             $form->addElement('checkbox', 'a_join_newsletter', 'Sign me up for your E-Newsletter');
             $form->addElement('submit', 'a_submit', 'Save');
             $user = new User($userId);
             $defaultValues['a_username'] = $user->getUsername();
             $defaultValues['a_name'] = $user->getName();
             //$defaultValues ['a_email'] = $user->getEmail();
             $defaultValues['a_password'] = null;
             $defaultValues['a_password_confirm'] = null;
             $defaultValues['a_join_newsletter'] = $user->getJoinNewsletter();
             $form->setDefaults($defaultValues);
             $form->addRule('a_name', 'Please enter the user\'s name', 'required', null);
             //$form->addRule( 'a_email', 'Please enter an email address', 'required', null );
             //$form->addRule( 'a_email', 'Please enter a valid email address', 'email', null );
             $form->addRule(array('a_password', 'a_password_confirm'), 'The passwords do not match', 'compare', null);
             if (isset($_REQUEST['a_submit']) && $form->validate()) {
                 if ($_REQUEST['a_password'] != '') {
                     $user->setPassword($_REQUEST['a_password']);
                 }
                 $user->setName($_REQUEST['a_name']);
                 if (!@$_REQUEST['a_join_newsletter']) {
                     $_REQUEST['a_join_newsletter'] = 0;
                 }
                 $user->setJoinNewsletter($_REQUEST['a_join_newsletter']);
                 //$user->setEmail($_REQUEST['a_email']);
                 $user->save();
                 $this->smarty->assign('profileHasBeenChanged', 1);
             }
             $this->smarty->assign('form', $form);
             //After displaying the "standard" user profile, display all the extra fields such as shipping address, billing address, and phone number
             $userDetails = UserDetails::getUserDetailsBasedOnUserId($userId);
             $this->smarty->assign('userDetails', $userDetails);
             return $this->smarty->fetch("MyProfile.tpl");
             break;
         case 'MyOrders':
             //Display all the orders that this user has made, and display the details of a particular order through an ajax call
             if (@$_REQUEST["order_id"]) {
                 $order = new Order($_REQUEST["order_id"]);
                 if ($order->getUser() != $userId) {
                     //Make sure users cannot view orders that do not belong to them
                     return 'Order does not belong to you';
                 }
                 $orderItems = OrderDetail::getAll($_REQUEST["order_id"]);
                 $orderComments = OrderComment::getAll($order->getId());
                 $this->smarty->assign('order', $order);
                 $this->smarty->assign('orderItems', $orderItems);
                 $this->smarty->assign('orderComments', $orderComments);
                 return $this->smarty->fetch("admin/OrderDetail.tpl");
             }
             $this->addJS('/js/facebox.js');
             $this->addCSS('/css/facebox.css');
             $results = Order::getAll(true, $userId);
             $this->smarty->assign('results', $results);
             return $this->smarty->fetch("MyOrders.tpl");
             break;
     }
     return $this->smarty->fetch("MyAccount.tpl");
 }