Exemple #1
0
 /**
  * initialize all config for vi system
  * @return unknown_type
  */
 public function __construct()
 {
     //MD5(?) AND active = "TRUE"
     $config = Vi_Registry::getConfig();
     $db = Vi_Registry::getDB();
     parent::__construct($db, $config['database']['params']['prefix'] . "user", 'username', 'password', 'MD5(?) AND enabled = 1');
 }
Exemple #2
0
 /**
  * Override Smarty::__construct
  * 
  * @return void
  */
 public function __construct()
 {
     parent::Smarty();
     /**
      * Config some params
      */
     $viewConfig = Vi_Registry::getConfig('viewConfig');
     $viewConfig['template_dir'] = '';
     foreach ($viewConfig as $key => $value) {
         $this->{$key} = $value;
     }
 }
Exemple #3
0
 /**
  * Check permisison
  * 
  * @param string $permission
  * @param string $module
  * @param string|integer $expandId  Note: $expandId == '*": Check to have all expandable permisisnon
  *                                        $expandId == '?': Check to have one or more permisison
  *                                        $expandId is interger: Check for special expand value
  */
 public function checkPermission($permission, $module, $expandId = '*')
 {
     $config = Vi_Registry::getConfig();
     if ($this->_auth->getIdentity() == 'admin' && @$config['useAdminFullControlSystem']) {
         return true;
     }
     if ('*' == $expandId) {
         if (true === @$this->_permissions[$module][$permission]) {
             return true;
         } elseif (is_array($pers = @$this->_permissions[$module][$permission])) {
             /**
              * Check all expandable permissions
              */
             foreach ($pers as $per) {
                 if (false == $per) {
                     return false;
                 }
             }
             return true;
         }
     } else {
         if ('?' == $expandId) {
             /**
              * Match one of all permission
              */
             if (true === @$this->_permissions[$module][$permission]) {
                 return true;
             } elseif (is_array($pers = @$this->_permissions[$module][$permission])) {
                 /**
                  * Check all expandable permissions
                  */
                 foreach ($pers as $per) {
                     if (true == $per) {
                         return true;
                     }
                 }
                 return false;
             }
         } else {
             /**
              * Check expandable permission
              */
             if (true == @$this->_permissions[$module][$permission][$expandId]) {
                 return true;
             }
         }
     }
     return false;
 }
Exemple #4
0
 public function __construct($params)
 {
     if (Vi_Registry::isRegistered('EDIT_LAYOUT_MODE')) {
         $this->_sampleMode = Vi_Registry::get('EDIT_LAYOUT_MODE');
     }
     $this->_name = $params['name'];
     if (isset($params['title'])) {
         $this->_title = $params['title'];
         $this->_holderId = $params['holder_id'];
     }
     $this->_params = $params;
     $view = Vi_Layout::getMvcInstance()->getView();
     $this->view = clone $view;
     $this->db = Vi_Registry::get('db');
     $this->session = Vi_Registry::getSession();
     $this->auth = Vi_Registry::getAuth();
     $this->aclFront = Vi_Registry::getAclFront();
     $this->aclAdmin = Vi_Registry::getAclAdmin();
     $this->view->setEngine(clone $view->getEngine());
     $this->_langCode = Vi_Language::getCurrentLangCode();
     $config = Vi_Registry::getConfig();
     $this->_compileDir = $config['viewConfig']['compile_dir'];
     $this->_cacheDir = $config['viewConfig']['cache_dir'];
     /*
     * set up dir for smarty
     * 'template_dir' => 'stickers/$stickerName',
     			'compile_dir' => 'tmp/compile/stickers/$stickerName/$langCode',
     			'cache_dir' => 'tmp/cache/stickers/$stickerName/$langCode',
     */
     $this->view->setScriptPath('./');
     $this->view->setCompilePath($config['viewConfig']['compile_dir']);
     $this->view->setCachePath($config['viewConfig']['cache_dir']);
     /*
      * call main funtion
      */
     $this->_saveInfo['currentType'] = Vi_Language::$currentType;
     $this->_saveInfo['currentName'] = Vi_Language::$currentName;
     Vi_Language::$currentType = Vi_Language::TYPE_STICKER;
     Vi_Language::$currentName = $this->_name;
     $this->view->STICKER_URL = Vi_Registry::getBaseUrl() . "stickers/{$this->_name}/";
     $this->view->HELPER_URL = $this->view->STICKER_URL . 'helpers/';
     $this->init();
     $this->run();
 }
 public function managerAction()
 {
     /**
      * Check permission
      */
     if (false == $this->checkPermission('see_permission')) {
         $this->_forwardToNoPermissionPage();
         return;
     }
     $this->view->headTitle(Vi_Language::translate('Permission manager'));
     $this->view->menu = array('usergroup', 'permissionmanager');
     $config = Vi_Registry::getConfig();
     /**
      * Load all groups
      */
     $objGroup = new Models_Group();
     /**
      * Set values for tempalte
      */
     $this->view->allGroups = $objGroup->getAll(array('sorting ASC', 'group_id ASC'))->toArray();
     /**
      * Get all applications
      */
     $allApps = Vi_Folder::getFolders('applications');
     foreach ($allApps as $index => $app) {
         if (!is_dir("applications/{$app}")) {
             unset($allApps[$index]);
         }
     }
     $this->view->allApps = $allApps;
     /**
      * Get all modules
      */
     $allModules = Vi_Folder::getFolders('modules');
     foreach ($allModules as $index => $module) {
         if (!is_dir("modules/{$module}")) {
             unset($allModules[$index]);
         }
     }
     $this->view->allModules = $allModules;
     $this->view->permissionMessage = $this->session->permissionMessage;
     $this->session->permissionMessage = null;
 }
 public function managerAction()
 {
     $this->view->headTitle('Meal Manager');
     $resId = Vi_Registry::getRestaurantIdFromLoggedUser();
     if (false == $resId) {
         $this->_redirect('access/index/login');
     }
     $objRes = new Models_Restaurant();
     $res = $objRes->find($resId)->toArray();
     $res = current($res);
     if (false == $res) {
         $this->_redirect('');
     }
     $type = $this->_getParam('type', 0);
     $numRowPerPage = Vi_Registry::getConfig("defaultNumberRowPerPage");
     $currentPage = $this->_getParam("page", 1);
     $objMeal = new Models_Meal();
     /**
      * Get all meals
      */
     $allMeals = $objMeal->getByColumnName(array('restaurant_id=?' => $resId, 'type=?' => $type))->toArray();
     $this->view->allMeals = $allMeals;
     $this->view->res = $res;
     $this->view->mealMessage = $this->session->mealMessage;
     $this->session->mealMessage = '';
     $this->view->type = $type;
 }
 public function reservationAction()
 {
     $this->view->headTitle(Vi_Language::translate('Reservation manager'));
     $this->view->menu = array('reservation');
     $config = Vi_Registry::getConfig();
     $numRowPerPage = Vi_Registry::getConfig("defaultNumberRowPerPage");
     $currentPage = $this->_getParam("page", 1);
     $displayNum = $this->_getParam('displayNum', false);
     /**
      * Get number of reser per page
      */
     if (false === $displayNum) {
         $displayNum = $this->session->reserDisplayNum;
     } else {
         $this->session->reserDisplayNum = $displayNum;
     }
     if (null != $displayNum) {
         $numRowPerPage = $displayNum;
     }
     /**
      * Get condition
      */
     $condition = $this->_getParam('condition', false);
     if (false === $condition) {
         $condition = $this->session->reserCondition;
     } else {
         $this->session->reserCondition = $condition;
         $currentPage = 1;
     }
     if (false == $condition) {
         $condition = array();
     }
     /**
      * Load all resers
      */
     $objReser = new Models_Reservation();
     $allResers = $objReser->getAllResers($condition, 'reservation_id DESC', $numRowPerPage, ($currentPage - 1) * $numRowPerPage);
     /**
      * Count all resers
      */
     $count = count($objReser->getAllResers($condition));
     /**
      * Modify all resers
      */
     foreach ($allResers as &$reser) {
         if (null != $reser['created_date']) {
             $reser['created_date'] = date($config['dateFormat'], $reser['created_date']);
         }
     }
     unset($reser);
     //        echo '<pre>';print_r($allResers);die;
     /**
      * Set values for tempalte
      */
     $this->setPagination($numRowPerPage, $currentPage, $count);
     $this->view->allResers = $allResers;
     $this->view->reserMessage = $this->session->reserMessage;
     $this->session->reserMessage = null;
     $this->view->condition = $condition;
     $this->view->displayNum = $numRowPerPage;
 }
Exemple #8
0
 public function headTitle($string)
 {
     $websiteName = Vi_Registry::getConfig('websiteName');
     if (null != $websiteName) {
         $websiteName .= " - ";
     }
     $this->headTitle->headTitle($websiteName . "{$string}");
 }
Exemple #9
0
 /**
  * Send HTML mail from DB mail template
  * 
  * @param string $mailTemplateName
  * @param array $data
  * @param string|array $to 
  * @param string $subject If null, subject from DB will be chosen
  */
 public function sendHtmlMail($mailTemplateName, $data = array(), $to = array(), $subject = null, $langId = null)
 {
     if (!is_array($to)) {
         $to = array($to);
     }
     if (null == $langId) {
         $langId = 1;
     }
     /**
      * Get mail template
      */
     $select = $this->select()->setIntegrityCheck(false)->from(array('m' => $this->_name))->joinLeft(array('ml' => $this->_prefix . 'mail_lang'), 'm.mail_id = ml.mail_id', array('lang_id', 'subject', 'content'))->where('m.name=?', $mailTemplateName)->where('ml.lang_id=?', $langId);
     $mail = @$this->fetchRow($select)->toArray();
     if (null == $mail) {
         return true;
     }
     /**
      * Change key
      */
     $newKey = array();
     foreach ($data as $index => $item) {
         $newKey['[' . strtoupper($index) . ']'] = $item;
     }
     $data = $newKey;
     /**
      * Insert data file for the first time call
      */
     if (null == $mail['data'] && !empty($data)) {
         $this->update(array('data' => implode('<br/>', array_keys($data))), array('name=?' => $mailTemplateName));
     }
     /**
      * Replace subject
      */
     if (null == $subject) {
         /**
          * Replace subject with DATA
          */
         $mail['subject'] = str_replace(array_keys($data), $data, $mail['subject']);
     } else {
         $mail['subject'] = $subject;
     }
     /**
      * Replace content
      */
     $mail['content'] = str_replace(array_keys($data), $data, $mail['content']);
     //        echo '<pre>';print_r($mail);die;
     $fromMail = Vi_Registry::getConfig('fromMail');
     // To send HTML mail, the Content-type header must be set
     $headers = 'MIME-Version: 1.0' . "\r\n";
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     if (null != $fromMail) {
         $headers .= "From: {$fromMail}" . "\r\n" . "Reply-To: {$fromMail}" . "\r\n" . 'X-Mailer: PHP/' . phpversion();
     }
     /**
      * Send mail
      */
     foreach ($to as $email) {
         @mail($email, $mail['subject'], $mail['content'], $headers);
     }
 }
 public function systemMailManagerAction()
 {
     /**
      * Check permission
      */
     if (false == $this->checkPermission('see_system_mail')) {
         $this->_forwardToNoPermissionPage();
         return;
     }
     $this->view->headTitle(Vi_Language::translate('System Mail Manager'));
     $this->view->menu = array('mail', 'systemmailmanager');
     $config = Vi_Registry::getConfig();
     $numRowPerPage = Vi_Registry::getConfig("defaultNumberRowPerPage");
     $currentPage = $this->_getParam("page", 1);
     $displayNum = $this->_getParam('displayNum', false);
     $objMail = new Models_Mail();
     $objMailLang = new Models_MailLang();
     $objLang = new Models_Lang();
     /**
      * Get number of items per page
      */
     if (false === $displayNum) {
         $displayNum = $this->session->mailDisplayNum;
     } else {
         $this->session->mailDisplayNum = $displayNum;
     }
     if (null != $displayNum) {
         $numRowPerPage = $displayNum;
     }
     /**
      * Get condition
      */
     $condition = $this->_getParam('condition', false);
     if (false === $condition) {
         $condition = $this->session->mailCondition;
     } else {
         $this->session->mailCondition = $condition;
         $currentPage = 1;
     }
     if (false == $condition) {
         $condition = array();
     }
     /**
      * Get all display languages
      */
     $allLangs = $objLang->getAll(array('sorting ASC'))->toArray();
     $this->view->allLangs = $allLangs;
     /**
      * Get all mails
      */
     $allMails = $objMail->getAllSystemMails($condition, array('m.mail_id ASC'), $numRowPerPage, ($currentPage - 1) * $numRowPerPage);
     //        echo '<pre>';print_r($allMails);die;
     /**
      * Count all contents
      */
     $count = count($objMail->getAllSystemMails($condition));
     /**
      * Get content detail
      */
     foreach ($allMails as $index => $mail) {
         $allDetails = $objMailLang->getByColumnName(array('mail_id=?' => $mail['mail_id']))->toArray();
         foreach ($allLangs as $lang) {
             $tmp = array('lang_id' => $lang['lang_id']);
             foreach ($allDetails as $mailLang) {
                 if ($lang['lang_id'] == $mailLang['lang_id']) {
                     $tmp = $mailLang;
                     break;
                 }
             }
             $tmp['lang_image'] = $lang['lang_image'];
             $allMails[$index]['details'][] = $tmp;
         }
     }
     //        echo '<pre>';print_r($allMails);die;
     /**
      * Set values for tempalte
      */
     $this->setPagination($numRowPerPage, $currentPage, $count);
     $this->view->allMails = $allMails;
     $this->view->mailMessage = $this->session->mailMessage;
     $this->session->mailMessage = null;
     $this->view->condition = $condition;
     $this->view->displayNum = $numRowPerPage;
 }
 public function detailAction()
 {
     $this->view->headTitle(Vi_Language::translate('Detail Order'));
     $this->view->menu = array('order');
     $config = Vi_Registry::getConfig();
     $numRowPerPage = Vi_Registry::getConfig("defaultNumberRowPerPage");
     $currentPage = $this->_getParam("page", 1);
     $displayNum = $this->_getParam('displayNum', false);
     $id = $this->_getParam('id', false);
     if (false == $id) {
         $this->_redirect('order/admin/manager');
     }
     /**
      * Load all details
      */
     $objDetail = new Models_OrderDetail();
     $allDetails = $objDetail->getByColumnName(array('order_id=?' => $id))->toArray();
     /**
      * Get order
      */
     $objOrder = new Models_Order();
     $order = $objOrder->find($id)->toArray();
     $order = current($order);
     $this->view->order = $order;
     /**
      * Get restaurant
      */
     $objRes = new Models_Restaurant();
     $res = $objRes->find($order['restaurant_id'])->toArray();
     $res = current($res);
     $this->view->res = $res;
     /**
      * Set values for tempalte
      */
     $this->view->allMeals = $allDetails;
 }
 /**
  * List all meal follow restaurant
  */
 public function indexAction()
 {
     $this->view->headTitle('Cart information');
     //-- begin add information into cart
     $meal_id = $this->_getParam('meal_id', false);
     $quantity = $this->_getParam('quantity', false);
     $mark = $_SESSION['mark'];
     //$this->_getParam('mark', false);
     $state = $this->_getParam('state', 0);
     //-- state=0: delete meal in session cart
     $date = $_SESSION['date'];
     //$this->_getParam('date', false);
     $time = $_SESSION['time'];
     //$this->_getParam('time', false);
     $res_id = $this->_getParam('res_id', false);
     if (false === $res_id) {
         $this->_redirect('');
     }
     $order_id = session_id();
     //-- begin delete meal in session cart
     if (0 != $state) {
         foreach ($_SESSION['cart'][$order_id] as $key => $value) {
             if ($key != $meal_id) {
                 $_SESSION['cart_delete'][$order_id][$key] = $value;
             }
         }
         //-- begin calculate sum
         $_SESSION['cart_delete'][$order_id]['subtotal'] = 0;
         foreach ($_SESSION['cart_delete'][$order_id] as $key => $value) {
             if ($value['total_money'] > 0) {
                 $_SESSION['cart_delete'][$order_id]['subtotal'] += $value['total_money'];
             }
         }
         //-- end calculate sum
         $_SESSION['cart_delete'][$order_id]['ordertotal'] = $_SESSION['cart_delete'][$order_id]['subtotal'] + $_SESSION['cart'][$order_id]['tax'] + $_SESSION['cart'][$order_id]['shipping'];
         unset($_SESSION['cart'][$order_id]);
         $_SESSION['cart'][$order_id] = $_SESSION['cart_delete'][$order_id];
         unset($_SESSION['cart_delete'][$order_id]);
         $this->view->session_cart = $_SESSION['cart'][$order_id];
     } else {
         //-- end delete meal in session cart
         if (false != $meal_id) {
             if (false != $quantity) {
                 $_SESSION['cart'][$order_id][$meal_id]['quantity'] = $quantity;
             } else {
                 if (isset($_SESSION['cart'][$order_id][$meal_id]['meal_id']) && $_SESSION['cart'][$order_id][$meal_id]['meal_id'] == $meal_id) {
                     $_SESSION['cart'][$order_id][$meal_id]['quantity'] = $_SESSION['cart'][$order_id][$meal_id]['quantity'] + 1;
                 } else {
                     $objMeal = new Models_Meal();
                     $arr_meal = $objMeal->getDataById($meal_id);
                     $_SESSION['cart'][$order_id][$meal_id]['meal_id'] = $arr_meal['meal_id'];
                     $_SESSION['cart'][$order_id][$meal_id]['image'] = $arr_meal['image_thumb'] ? $arr_meal['image_thumb'] : $arr_meal['image'];
                     $_SESSION['cart'][$order_id][$meal_id]['name'] = $arr_meal['name'];
                     $_SESSION['cart'][$order_id][$meal_id]['description'] = $arr_meal['description'];
                     $_SESSION['cart'][$order_id][$meal_id]['price'] = $arr_meal['price'];
                     $_SESSION['cart'][$order_id][$meal_id]['quantity'] = 1;
                 }
             }
             $_SESSION['cart'][$order_id][$meal_id]['total_money'] = $_SESSION['cart'][$order_id][$meal_id]['price'] * $_SESSION['cart'][$order_id][$meal_id]['quantity'];
             $_SESSION['cart'][$order_id]['subtotal'] = 0;
             $_SESSION['cart'][$order_id]['restaurant_id'] = $res_id;
             //-- begin calculate sum
             foreach ($_SESSION['cart'][$order_id] as $key => $value) {
                 if ($value['total_money'] > 0 && is_numeric($key)) {
                     $_SESSION['cart'][$order_id]['subtotal'] += $value['total_money'];
                 }
             }
             //-- end calculate sum
             $_SESSION['cart'][$order_id]['tax'] = $_SESSION['cart'][$order_id]['subtotal'] * Vi_Registry::getConfig('taxFee');
             //-- begin get shipping fee for catering delivery and catering
             if (strcmp($mark, 'catering_delivery') == 0 || strcmp($mark, 'delivery') == 0) {
                 $objRestaurant = new Models_Restaurant();
                 $arrRestaurant = $objRestaurant->getShipFeeFromMealId($meal_id);
                 if (strcmp($mark, 'delivery_charge') == 0) {
                     $shippingFee = $arrRestaurant['delivery_charge'];
                 } else {
                     $shippingFee = $arrRestaurant['catering_delivery_charge'];
                 }
                 $_SESSION['cart'][$order_id]['shipping'] = $shippingFee;
             } else {
                 $_SESSION['cart'][$order_id]['shipping'] = 0;
             }
             //-- end get shipping fee for catering delivery and catering
             $_SESSION['cart'][$order_id]['ordertotal'] = $_SESSION['cart'][$order_id]['subtotal'] + $_SESSION['cart'][$order_id]['tax'] + $_SESSION['cart'][$order_id]['shipping'];
             $this->view->session_cart = $_SESSION['cart'][$order_id];
         } else {
             $this->view->session_cart = '';
         }
     }
     $_SESSION['cart'][$order_id]['date'] = $date;
     $_SESSION['cart'][$order_id]['time'] = $time;
     $_SESSION['cart'][$order_id]['order_service'] = $mark;
     //		 echo "<pre>";print_r($_SESSION['cart'][$order_id]);echo "</pre>";
     $this->view->subtotal = $_SESSION['cart'][$order_id]['subtotal'];
     $this->view->tax = $_SESSION['cart'][$order_id]['tax'];
     $this->view->shipping = $_SESSION['cart'][$order_id]['shipping'];
     $this->view->ordertotal = $_SESSION['cart'][$order_id]['ordertotal'];
     //-- end add information into cart
     $this->view->order_id = $order_id;
     $this->view->meal_id = $meal_id;
     $this->view->mark = strtoupper($mark);
     $this->view->date = $date;
     $this->view->time = strtoupper($time);
 }
Exemple #13
0
 /**
  * Send mail to all user
  * 
  * @param string $subject              The subject of mail
  * @param string $bodyText             The text body of mail
  * @param string $bodyHtml             The HTML body of mail
  * @param string $bodyDbTemplateName   The name of mail
  * @param array  $templateData         Array data of template mail
  * @param bool   $isHtmlTempalte       Default is true, that means using HTML email to send
  * @return bool
  */
 public function sendEmailToAllUser($subject, $bodyText = null, $bodyHtml = null, $bodyDbTemplateName = null, $templateData = array(), $isHtmlTempalte = true)
 {
     if (null == $bodyText && null == $bodyHtml && null == $bodyDbTemplateName) {
         return false;
     }
     $allUsers = $this->getAll();
     /**
      * Send email
      */
     require_once 'Vi/Mail.php';
     require_once 'Zend/Mail/Transport/Smtp.php';
     $config = Vi_Registry::getConfig();
     $transport = new Zend_Mail_Transport_Smtp($config['adminMail']['mailServer'], $config['adminMail']);
     try {
         foreach ($allUsers as $user) {
             $mail = new Vi_Mail('utf-8');
             $mail->setSubject($subject);
             $mail->setFrom($config['adminMail']['username']);
             $mail->addTo($user['email']);
             if (null != $bodyText) {
                 $mail->setBodyText($bodyText);
             } else {
                 if (null != $bodyHtml) {
                     $mail->setBodyHtml($bodyHtml);
                 } else {
                     if (null != $bodyDbTemplateName) {
                         $mail->setBodyDbTemplateName($bodyDbTemplateName, $isHtmlTempalte);
                         $mail->view->templateData = $templateData;
                     }
                 }
             }
             $mail->send($transport);
         }
         return true;
     } catch (Exception $e) {
         /**
          * Error
          */
         return false;
     }
 }
 /**
  * ######################################  GROUP FUNCTIONS ############################################## 
  */
 public function groupManagerAction()
 {
     /**
      * Check permission
      */
     if (false == $this->checkPermission('see_group')) {
         $this->_forwardToNoPermissionPage();
         return;
     }
     $this->view->headTitle(Vi_Language::translate('Group manager'));
     $this->view->menu = array('usergroup', 'groupmanager');
     $config = Vi_Registry::getConfig();
     $numRowPerPage = Vi_Registry::getConfig("defaultNumberRowPerPage");
     $currentPage = $this->_getParam("page", 1);
     $displayNum = $this->_getParam('displayNum', false);
     /**
      * Get number of groups per page
      */
     if (false === $displayNum) {
         $displayNum = $this->session->groupDisplayNum;
     } else {
         $this->session->groupDisplayNum = $displayNum;
     }
     if (null != $displayNum) {
         $numRowPerPage = $displayNum;
     }
     /**
      * Load all groups
      */
     $objGroup = new Models_Group();
     $allGroups = $objGroup->getAll('sorting ASC')->toArray();
     /**
      * Count all groups
      */
     $count = count($allGroups);
     /**
      * Load all groups
      */
     /**
      * Set values for tempalte
      */
     $this->setPagination($numRowPerPage, $currentPage, $count);
     $this->view->allGroups = $allGroups;
     $this->view->groupMessage = $this->session->groupMessage;
     $this->session->groupMessage = null;
     $this->view->displayNum = $numRowPerPage;
 }
Exemple #15
0
 /**
  * get database prefix
  * @return string prefix for database
  */
 public static function getDBPrefix()
 {
     $config = Vi_Registry::getConfig();
     return $config['database']['params']['prefix'];
 }
 /**
  * List all restaurant after search
  */
 public function indexAction()
 {
     $this->view->headTitle('Restaurant');
     $config = Vi_Registry::getConfig();
     $numRowPerPage = Vi_Registry::getConfig("defaultNumberRowPerPage");
     //        $numRowPerPage = 1;
     $currentPage = $this->_getParam("page", 1);
     $condition = $this->_getParam('data', array());
     $find = $this->_getParam('find', false);
     if (strpos($_SERVER["REDIRECT_URL"], 'mark_restaurant')) {
         $mark = $_SESSION['mark'] = $this->_getParam('mark', 'pickup');
         //isset($_SESSION['mark'])? $_SESSION['mark']: $this->_getParam('mark', false);
     } else {
         $mark = $_SESSION['mark'] = isset($_SESSION['mark']) && !empty($_SESSION['mark']) ? $_SESSION['mark'] : $this->_getParam('mark', 'pickup');
     }
     $searchword = $this->_getParam('searchword', false);
     $conditions = $this->_getParam('condition', array());
     /**
      * Set variables for template
      */
     $str_lead_time_title = "";
     if (strcmp($mark, 'pickup') == 0) {
         $this->view->mark_pickup = 'checked';
         $str_lead_time_title = 'Pick up';
     } elseif (strcmp($mark, 'curbside') == 0) {
         $this->view->mark_curbside = 'checked';
         $str_lead_time_title = 'Curbside';
     } elseif (strcmp($mark, 'catering_pickup') == 0) {
         $this->view->mark_catering_pickup = 'checked';
         $str_lead_time_title = 'Catering Pickup';
     } elseif (strcmp($mark, 'delivery') == 0) {
         $this->view->mark_delivery = 'checked';
         $str_lead_time_title = 'Delivery';
     } elseif (strcmp($mark, 'catering_delivery') == 0) {
         $this->view->mark_catering_delivery = 'checked';
         $str_lead_time_title = 'Catering Delivery';
     }
     /**
      * Get condition for search
      */
     $arr_condition = array();
     if (false != $mark) {
         //	    	$arr_condition["{$mark} != ?"] = Zend_DB::NULL_EMPTY_STRING;
         $arr_con["mark"] = $mark;
     }
     if (false != $find) {
         //	    	$arr_condition["name LIKE ? "] = $find."%";
         $arr_con["name"] = $find;
     }
     if (null != @$condition['zip']) {
         /**
          * Condition here
          */
         $objCountry = new Models_Country();
         $city_from_code = $objCountry->getCityByCode($condition['zip']);
         //	    	$arr_condition["address LIKE ? "] = "%".$city_from_code[0]['city']."%";
         $arr_con['city'] = $city_from_code[0]['city'];
         $arr_con['zip'] = $condition['zip'];
         //	    	$arr_con['address'] = $city_from_code[0]['city'];
     } else {
         if (false != $searchword) {
             //-- searchword: city
             //	    	$arr_condition["address LIKE ? "] = "%".$searchword."%";
             //	    	$arr_con["address"] = $searchword;
             $arr_con["city"] = $searchword;
         }
     }
     if (null != @$conditions['cuisine'] && $conditions['cuisine'] > 0) {
         /**
          * Condition here
          */
         $arr_con['cuisine_id'] = $conditions['cuisine'];
         if (null != @$conditions['time']) {
             $arr_con['time'] = $conditions['time'];
         }
         if (null != @$conditions['date']) {
             $arr_con['date'] = strtolower(substr($conditions['date'], -3));
         }
     }
     $arr_con = isset($arr_con) ? $arr_con : array();
     $objRestaurant = new Models_Restaurant();
     $restaurants = $objRestaurant->getRestaurantByData($arr_con, $numRowPerPage, ($currentPage - 1) * $numRowPerPage);
     $count = count($objRestaurant->getRestaurantByData($arr_con));
     //	    else{
     //
     //	    $arr_condition["enabled = ? "] = 1;
     //	    $objRestaurant = new Models_Restaurant();
     //	    $restaurants = $objRestaurant->getByColumnName($arr_condition,
     //			    											array('name ASC'),
     //			    											$numRowPerPage,
     //		                                                   ($currentPage - 1) * $numRowPerPage)->toArray();
     //	    $count = count($objRestaurant->getByColumnName($arr_condition));
     //	    }
     $this->view->lead_time = $str_lead_time_title;
     $this->view->mark = $mark;
     $this->view->alphabet = GetAlphabet();
     $strServices = "";
     foreach ($restaurants as $key => $value) {
         //	    	if ( !empty($value['services']) ){
         //		    	$arr_services = explode(',',$value['services']);
         //		    	$restaurants[$key]['arr_service'] = $arr_services;
         //	    	}
         $strServices = "";
         if (!empty($value['pickup'])) {
             if (!empty($strServices)) {
                 $strServices .= ',Pickup';
             } else {
                 $strServices .= 'Pickup';
             }
         }
         if (!empty($value['curbside'])) {
             if (!empty($strServices)) {
                 $strServices .= ',Curbside';
             } else {
                 $strServices .= 'Curbside';
             }
         }
         if (!empty($value['delivery'])) {
             if (!empty($strServices)) {
                 $strServices .= ',Delivery';
             } else {
                 $strServices .= 'Delivery';
             }
         }
         if (!empty($value['catering_pickup'])) {
             if (!empty($strServices)) {
                 $strServices .= ',Catering Pickup';
             } else {
                 $strServices .= 'Catering Pickup';
             }
         }
         if (!empty($value['catering_delivery'])) {
             if (!empty($strServices)) {
                 $strServices .= ',Catering Delivery';
             } else {
                 $strServices .= 'Catering Delivery';
             }
         }
         $arr_services = explode(',', $strServices);
         $restaurants[$key]['arr_service'] = $arr_services;
         $restaurants[$key]['address'] = $value['street'] . " " . $value['city'] . " " . $value['state'];
         $restaurants[$key]['alias'] = Vi_Controller_Action::makeURLSafeString($value['name']) . '.html';
     }
     $this->view->restaurants = $restaurants;
     /**
      * Begin get date and month
      */
     $date_month[] = date("M jS - D");
     for ($i = 1; $i < 14; $i++) {
         $date_month[] = date("M jS - D", time() + $i * 24 * 60 * 60);
     }
     $this->view->date_month = $date_month;
     /**
      * Begin get time
      */
     //		$arr_time[]= '12:15 AM';
     //		$arr_time[]= '12:30 AM';
     //		$arr_time[]= '12:45 AM';
     //		for( $i = 1; $i<12; $i++ ){
     for ($i = 5; $i < 24; $i++) {
         for ($j = 1; $j < 5; $j++) {
             if ($j == 1) {
                 $format = '00';
             } else {
                 if ($j == 2) {
                     $format = '15';
                 } else {
                     if ($j == 3) {
                         $format = '30';
                     } else {
                         if ($j == 4) {
                             $format = '45';
                         }
                     }
                 }
             }
             //				$arr_time[] = $i.":".$format." AM";
             $arr_time[] = $i . ":" . $format;
         }
     }
     //		$arr_time[] = '12:00 PM';
     //		$arr_time[] = '12:15 PM';
     //		$arr_time[] = '12:30 PM';
     //		$arr_time[] = '12:45 PM';
     //		for( $i = 1; $i<13; $i++ ){
     //			for( $j=1;$j<5;$j++ ){
     //				if ( $j==1 )
     //					$format = '00';
     //				else if ( $j==2 )
     //					$format = '15';
     //				else if ( $j==3 )
     //					$format = '30';
     //				else if ( $j==4 )
     //					$format = '45';
     //				$arr_time[] = $i.":".$format." PM";
     //			}
     //		}
     $this->view->arr_time = $arr_time;
     $this->view->zip = null != @$condition['zip'] ? $condition['zip'] : '';
     $this->view->city = $searchword;
     $date = isset($_SESSION['date']) ? $_SESSION['date'] : $this->_getParam('date', false);
     $time = isset($_SESSION['time']) ? $_SESSION['time'] : $this->_getParam('time', false);
     $_SESSION['date'] = null != @$conditions['date'] ? $conditions['date'] : (false != $date ? $date : '');
     $_SESSION['time'] = null != @$conditions['time'] ? $conditions['time'] : (false != $time ? $time : '');
     $this->view->time = $_SESSION['time'];
     $this->view->date = $_SESSION['date'];
     /**
      * Pagination
      */
     $this->setPagination($numRowPerPage, $currentPage, $count);
     $order_id = session_id();
     if (isset($_SESSION['cart'][$order_id])) {
         $this->view->subtotal = $_SESSION['cart'][$order_id]['subtotal'];
         $this->view->tax = $_SESSION['cart'][$order_id]['tax'];
         $this->view->shipping = $_SESSION['cart'][$order_id]['shipping'];
         $this->view->ordertotal = $_SESSION['cart'][$order_id]['ordertotal'];
         $this->view->res_id_ses = $_SESSION['cart'][$order_id]['restaurant_id'];
     }
 }
 /**
  * List all meal follow restaurant
  */
 public function indexAction()
 {
     $this->view->headTitle('Cart information');
     $order_id = session_id();
     if (!isset($_SESSION['cart'][$order_id])) {
         $this->_redirect('');
     }
     /**
      * Get restaurant
      */
     $objRes = new Models_Restaurant();
     $res = $objRes->find($_SESSION['cart'][$order_id]['restaurant_id'])->toArray();
     $res = current($res);
     //        echo '<pre>';print_r($_SESSION);//die;
     //        echo '<pre>';print_r($res);die;
     if (false == $res) {
         $this->_redirect('');
     }
     $this->view->session_cart = $_SESSION['cart'][$order_id];
     $this->view->subtotal = $_SESSION['cart'][$order_id]['subtotal'];
     $this->view->tax = $_SESSION['cart'][$order_id]['tax'];
     $this->view->shipping = $_SESSION['cart'][$order_id]['shipping'];
     $this->view->ordertotal = $_SESSION['cart'][$order_id]['ordertotal'];
     $this->view->mark = strtoupper($_SESSION['cart'][$order_id]['order_service']);
     $this->view->date = $_SESSION['cart'][$order_id]['date'];
     $this->view->time = $_SESSION['cart'][$order_id]['time'];
     $data_info = $this->_getParam('data', false);
     $confirm = $this->_getParam('confirm', false);
     /**
      * Remember customer's infomation
      */
     if (false !== $data_info) {
         $_SESSION['cart_customer'] = $data_info;
     }
     $data_info = $_SESSION['cart_customer'];
     $this->view->full_name = $data_info['full_name'];
     $this->view->address = $data_info['address'];
     $this->view->zip_code = $data_info['zip_code'];
     $this->view->phone = $data_info['phone1'] . "." . $data_info['phone2'] . "." . $data_info['phone3'];
     $this->view->cardType = $_SESSION['cart_customer']['card_type'];
     $cardNumber = $_SESSION['cart_customer']['card_number'];
     $cardNumber[4] = 'X';
     $cardNumber[5] = 'X';
     $cardNumber[6] = 'X';
     $cardNumber[7] = 'X';
     $cardNumber[8] = 'X';
     $cardNumber[9] = 'X';
     $cardNumber[10] = 'X';
     $cardNumber[11] = 'X';
     $this->view->cardNumber = $cardNumber;
     $error = '';
     /**
      * Store to DB and redirect
      */
     if (false != $confirm) {
         /**************************************************************************
          * Make payment
          */
         require_once 'libs/paypal/CallerService.php';
         /**
          * Fist name, last name
          */
         $firstName = trim(substr($data_info['full_name'], 0, strpos($data_info['full_name'] . ' ', ' ') + 1));
         $lastName = trim(substr($data_info['full_name'], strlen($firstName)));
         /**
          * Get required parameters from the web form for the request
          */
         $paymentType = urlencode('Sale');
         $firstName = urlencode($firstName);
         $lastName = urlencode($lastName);
         $creditCardType = urlencode($data_info['card_type']);
         $creditCardNumber = urlencode($data_info['card_number']);
         $expDateMonth = urlencode($data_info['card_month']);
         // Month must be padded with leading zero
         $padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
         $expDateYear = urlencode($data_info['card_year']);
         $cvv2Number = urlencode($data_info['card_cvv']);
         $address1 = urlencode($data_info['address']);
         $address2 = urlencode('');
         $city = urlencode($data_info['city']);
         $state = urlencode($data_info['state']);
         $zip = urlencode($data_info['zip_code']);
         $amount = urlencode(number_format($_SESSION['cart'][$order_id]['ordertotal'], 2, '.', ''));
         $currencyCode = "CAD";
         //            $state = 'NL';
         $country = 'CA';
         /* Construct the request string that will be sent to PayPal.
            The variable $nvpstr contains all the variables and is a
            name value pair string with & as a delimiter */
         $nvpstr = "&PAYMENTACTION={$paymentType}&AMT={$amount}&CREDITCARDTYPE={$creditCardType}&ACCT={$creditCardNumber}&EXPDATE=" . $padDateMonth . $expDateYear . "&CVV2={$cvv2Number}&FIRSTNAME={$firstName}&LASTNAME={$lastName}&STREET={$address1}&CITY={$city}&STATE={$state}" . "&ZIP={$zip}&COUNTRYCODE={$country}&CURRENCYCODE={$currencyCode}";
         //            echo $nvpstr;die;
         /* Make the API call to PayPal, using API signature.
            The API response is stored in an associative array called $resArray */
         $resArray = hash_call("doDirectPayment", $nvpstr);
         //            echo '<pre>';print_r($resArray);die;
         /* Display the API response back to the browser.
            If the response from PayPal was a success, display the response parameters'
            If the response was an error, display the errors received using APIError.php.
            */
         $ack = strtoupper($resArray["ACK"]);
         if ($ack != "SUCCESS") {
             $_SESSION['card_error_msg'] = @$resArray['L_LONGMESSAGE0'];
             $this->_redirect('restaurant/ship');
         }
         /**
          * End payment
          **************************************************************************/
         //-- begin save into db: vi_order and vi_order_detail
         $arr_order = array('sub_total' => $_SESSION['cart'][$order_id]['subtotal'], 'sales_tax' => $_SESSION['cart'][$order_id]['tax'], 'shipping_fee' => $_SESSION['cart'][$order_id]['shipping'], 'order_total' => $_SESSION['cart'][$order_id]['ordertotal'], 'date' => $_SESSION['cart'][$order_id]['date'], 'time' => $_SESSION['cart'][$order_id]['time'], 'order_service' => $_SESSION['cart'][$order_id]['order_service'], 'full_name' => $data_info['full_name'], 'address' => $data_info['address'], 'suite' => $data_info['note'], 'city' => $data_info['city'], 'state' => $data_info['state'], 'zip_code' => $data_info['zip_code'], 'phone' => $data_info['phone1'] . "." . $data_info['phone2'] . "." . $data_info['phone3'], 'email' => $data_info['email'], 'created_date' => time(), 'restaurant_id' => $_SESSION['cart'][$order_id]['restaurant_id']);
         $objOrder = new Models_Order();
         $bResultOrder = $objOrder->insert($arr_order);
         foreach ($_SESSION['cart'][$order_id] as $key => $value) {
             $arr_order_detail = array('order_id' => $bResultOrder, 'meal_id' => $value['meal_id'], 'name' => $value['name'], 'description' => $value['description'], 'price' => $value['price'], 'quantity' => $value['quantity'], 'total' => $value['total_money']);
             if (!empty($value['name'])) {
                 $objOrderDetail = new Models_OrderDetail();
                 $objOrderDetail->insert($arr_order_detail);
             }
         }
         //-- end save into db: vi_order and vi_order_detail
         /**
          * Send email to admin and user
          */
         $objUser = new Models_User();
         $objMail = new Models_Mail();
         $data = $arr_order;
         $config = Vi_Registry::getConfig();
         $data['created_date'] = date($config['dateFormat'], $data['created_date']);
         $data['card_type'] = $this->view->cardType;
         $data['card_number'] = $this->view->cardNumber;
         //            echo '<pre>';print_r($data);die;
         $cartDetail = "\n            <table width='90%'>\n                <tr>\n                    <td width='55%'></td>\n                    <td width='15%'></td>\n                    <td width='15%'></td>\n                    <td width='15%'></td>\n                </tr>\n                <tr>\n                    <td style='color: #442006; font-weight: bold;'>SHIPPING ADDRESS</td>\n                    <td colspan='3'  style='color: #442006; font-weight: bold;'>PAYMENT METHOD</td>\n                </tr> \n                <tr>\n                   <td valign='top'>\n                       <br/>\n                       <table width='400px;'>\n\n                           <tr>\n                               <td width='30%' align='right' style='background-color: #EEEEEE;'>Full Name:</td>\n                               <td width='70%' style='color: #442006;'>{$data['full_name']}</td>\n                           </tr>\n                           <tr>\n                               <td align='right' style='background-color: #EEEEEE;'>Address:</td>\n                               <td style='color: #442006;'>{$data['address']}</td>\n\n                           </tr>\n                           <tr>\n                               <td align='right' style='background-color: #EEEEEE;'>Postal Code:</td>\n                               <td style='color: #442006;'>{$data['zip_code']}</td>\n                           </tr>\n                           <tr>\n                               <td align='right' style='background-color: #EEEEEE;'>Phone:</td>\n\n                               <td style='color: #442006;'>{$data['phone']}</td>\n                           </tr>\n                       </table>\n                       <br/>\n                       \n                   </td>\n                   <td valign='top'>\n                       <br/>\n                       <table width='400px;'>\n\n                           <tr>\n                               <td width='30%' align='right' style='background-color: #EEEEEE;'>Name:</td>\n                               <td width='70%' style='color: #442006;'>{$res['name']}</td>\n                           </tr>\n                           <tr>\n                               <td align='right' style='background-color: #EEEEEE;'>Address:</td>\n                               <td style='color: #442006;'>{$res['street']}, {$res['city']}, {$res['state']}</td>\n                           </tr>\n                           <tr>\n                               <td width='30%' align='right' style='background-color: #EEEEEE;'>Phone:</td>\n                               <td width='70%' style='color: #442006;'>{$res['phone']}</td>\n                           </tr>\n                           \n                           <tr>\n                               <td colspan='2' style='color: #442006; font-weight: bold;'><br/>PAYMENT METHOD</td>\n                           </tr>\n                           <tr>\n                               <td  align='right' colspan='2'>{$data['card_type']}: {$data['card_number']}</td>\n                           </tr>\n                           \n                       </table>\n                       <br/>\n                   </td>\n\n                </tr>\n                \n                </table>\n                <table>\n                \n                <tr style='background-color: #DDDDDD;'>\n                    <td style='color: #AD5B21; font-weight: bold;'> Meal</td>\n                    <td style='color: #AD5B21; font-weight: bold;'> </td>\n                    <td style='color: #AD5B21; font-weight: bold;'> Quanlity</td>\n                    <td style='color: #AD5B21; font-weight: bold;'> Price</td>\n                    <td style='color: #AD5B21; font-weight: bold;'> Total</td>\n                </tr> ";
         foreach ($_SESSION['cart'][$order_id] as $key => $meal) {
             if (null == $meal['meal_id']) {
                 continue;
             }
             $mealImage = Vi_Registry::getConfig('liveSite') . '/' . $meal['image'];
             if (null != $meal['image']) {
                 $mealImage = '<img src="' . $mealImage . '" style="max-width: 100px;">';
             } else {
                 $mealImage = '';
             }
             if (is_numeric($key)) {
                 $cartDetail .= "\n\t                 <tr>\n\t                    <td style='border-bottom: 1px solid #DDDDDD;'>\n\t                        {$mealImage}\n\t                    </td>\n\t                    <td style='border-bottom: 1px solid #DDDDDD;'>\n\t                        <b>{$meal['name']}</b>\n\t\n\t                        <br/>\n\t                        <p>{$meal['description']}</p>\n\t                    </td>\n\t                    <td style='border-bottom: 1px solid #DDDDDD;'>{$meal['quantity']}</td>\n\t                    <td style='border-bottom: 1px solid #DDDDDD;'>\$" . number_format($meal['price'] * 1.0, 2) . "</td>\n\t                    <td style='border-bottom: 1px solid #DDDDDD;'>\$" . number_format($meal['total_money'] * 1.0, 2) . "</td>\n\t                </tr>";
             }
         }
         $cartDetail .= "   \n                <tr>\n                    <td colspan='2'> </td>\n                    <td> Subtotal </td>\n                    <td>\$" . number_format($data['sub_total'], 2) . "</td>\n\n                </tr>\n                <tr>\n                    <td colspan='2'> </td>\n                    <td> Tax </td>\n                    <td>\$" . number_format($data['sales_tax'], 2) . "</td>\n                </tr>\n                <tr>\n                    <td colspan='2'> </td>\n                    <td> Shipping fee </td>\n\n                    <td>\$" . number_format($data['shipping_fee'], 2) . "</td>\n                </tr>\n                <tr>\n                    <td colspan='2'> </td>\n                    <td> Order total </td>\n                    <td  style='color: #AD5B21; font-weight: bold;'>\$" . number_format($data['order_total'], 2) . "</td>\n                </tr>\n            </table>\n            ";
         $data['card_detail'] = $cartDetail;
         //            echo '<pre>';print_r($data);die;
         $admin = $objUser->getByUserName('admin');
         $objMail->sendHtmlMail('meal_order', $data, array($admin['email'], $data['email'], $res['owner_email']));
         /**
          * Clear session
          */
         unset($_SESSION['cart']);
         unset($_SESSION['cart_customer']);
         /**
          * Redirec to success page
          */
         $objContent = new Models_ScontentLang();
         $this->_redirect($objContent->getUrlWithoutAppBaseUrl(21));
         return;
     }
 }
 public function managerAction()
 {
     /**
      * Check permission
      */
     if (false == $this->checkPermission('see_scontent', null, '?')) {
         $this->_forwardToNoPermissionPage();
         return;
     }
     $this->view->headTitle(Vi_Language::translate('Content Manager'));
     $this->view->menu = array('scontent', 'manager');
     $config = Vi_Registry::getConfig();
     $numRowPerPage = Vi_Registry::getConfig("defaultNumberRowPerPage");
     $currentPage = $this->_getParam("page", 1);
     $displayNum = $this->_getParam('displayNum', false);
     $objScontent = new Models_Scontent();
     $objScontentLang = new Models_ScontentLang();
     $objLang = new Models_Lang();
     $objCat = new Models_ScontentCategory();
     /**
      * Update sorting
      */
     $data = $this->_getParam('data', array());
     foreach ($data as $id => $value) {
         $value = intval($value);
         if (1 > $value) {
             continue;
         }
         $objScontent->update(array('sorting' => $value), array('scontent_id=?' => $id));
         $this->session->scontentMessage = array('success' => true, 'message' => Vi_Language::translate("Edit sort numbers successfully"));
     }
     /**
      * Get number of items per page
      */
     if (false === $displayNum) {
         $displayNum = $this->session->contentDisplayNum;
     } else {
         $this->session->contentDisplayNum = $displayNum;
     }
     if (null != $displayNum) {
         $numRowPerPage = $displayNum;
     }
     /**
      * Get condition
      */
     $condition = $this->_getParam('condition', false);
     if (false === $condition) {
         $condition = $this->session->contentCondition;
     } else {
         $this->session->contentCondition = $condition;
         $currentPage = 1;
     }
     if (false == $condition) {
         $condition = array();
     }
     /**
      * Get all categories
      */
     $this->view->allCats = $objCat->getAll(array('sorting ASC'))->toArray();
     /**
      * Get all display languages
      */
     $allLangs = $objLang->getAll(array('sorting ASC'))->toArray();
     $this->view->allLangs = $allLangs;
     /**
      * Check permisison for each language
      */
     foreach ($allLangs as $index => $lang) {
         if (false == $this->checkPermission('see_scontent', null, $lang['lang_id'])) {
             /**
              * Disappaer this language
              */
             unset($allLangs[$index]);
         }
     }
     /**
      * Get all contents
      */
     $allScontents = $objScontent->getAllContents($condition, array('sorting ASC', 's.scontent_id DESC'), $numRowPerPage, ($currentPage - 1) * $numRowPerPage);
     //        echo '<pre>';print_r($allScontents);die;
     /**
      * Count all contents
      */
     $count = count($objScontent->getAllContents($condition));
     /**
      * Get content detail
      */
     foreach ($allScontents as $index => $scontent) {
         $allDetails = $objScontentLang->getByColumnName(array('scontent_id=?' => $scontent['scontent_id']))->toArray();
         foreach ($allLangs as $lang) {
             $tmp = array('lang_id' => $lang['lang_id']);
             foreach ($allDetails as $scontentLang) {
                 if ($lang['lang_id'] == $scontentLang['lang_id']) {
                     $tmp = $scontentLang;
                     break;
                 }
             }
             $tmp['lang_image'] = $lang['lang_image'];
             $allScontents[$index]['details'][] = $tmp;
         }
         /**
          * Change date
          */
         if (0 != $scontent['created_date']) {
             $allScontents[$index]['created_date'] = date($config['dateFormat'], $scontent['created_date']);
         } else {
             $allScontents[$index]['created_date'] = '';
         }
         if (0 != $scontent['publish_up_date']) {
             $allScontents[$index]['publish_up_date'] = date($config['dateFormat'], $scontent['publish_up_date']);
         } else {
             $allScontents[$index]['publish_up_date'] = '';
         }
         if (0 != $scontent['publish_down_date']) {
             $allScontents[$index]['publish_down_date'] = date($config['dateFormat'], $scontent['publish_down_date']);
         } else {
             $allScontents[$index]['publish_down_date'] = '';
         }
     }
     //        echo '<pre>';print_r($allScontents);die;
     /**
      * Set values for tempalte
      */
     $this->setPagination($numRowPerPage, $currentPage, $count);
     $this->view->allScontents = $allScontents;
     $this->view->scontentMessage = $this->session->scontentMessage;
     $this->session->scontentMessage = null;
     $this->view->condition = $condition;
     $this->view->displayNum = $numRowPerPage;
     $this->view->fullPermisison = $this->checkPermission('see_scontent');
 }
 public function categoryValueManagerAction()
 {
     /**
      * Check permission
      */
     if (false == $this->checkPermission('see_value')) {
         $this->_forwardToNoPermissionPage();
         return;
     }
     $this->view->headTitle(Vi_Language::translate('Value manager'));
     $this->view->menu = array('others', 'categorymanager');
     $config = Vi_Registry::getConfig();
     $numRowPerPage = Vi_Registry::getConfig("defaultNumberRowPerPage");
     $currentPage = $this->_getParam("page", 1);
     $displayNum = $this->_getParam('displayNum', false);
     $id = $this->_getParam('id', false);
     if (false == $id) {
         $this->_redirect('category/admin/category-manager');
     }
     /**
      * Update sort
      */
     $data = $this->_getParam('data', false);
     if (false != $data) {
         $objCatVal = new Models_CategoryValue();
         foreach ($data as $index => $value) {
             $objCatVal->update(array('sorting' => $value), array('category_value_id=?' => $index));
         }
         $this->session->categoryValueMessage = array('success' => true, 'message' => Vi_Language::translate('Sorting values are updated successfully'));
     }
     /**
      * Get number of category values per page
      */
     if (false === $displayNum) {
         $displayNum = $this->session->categoryValueDisplayNum;
     } else {
         $this->session->categoryValueDisplayNum = $displayNum;
     }
     if (null != $displayNum) {
         $numRowPerPage = $displayNum;
     }
     /**
      * Get condition
      */
     $condition = $this->_getParam('condition', false);
     if (false === $condition) {
         $condition = $this->session->categoryValueCondition;
     } else {
         $this->session->categoryValueCondition = $condition;
         $currentPage = 1;
     }
     if (false == $condition) {
         $condition = array();
     }
     $condition['category_id'] = $id;
     /**
      * Load all categoryValues
      */
     $objCategoryValue = new Models_CategoryValue();
     $allCategoryValues = $objCategoryValue->getAllCategoryValues($condition, array('sorting ASC', 'name ASC'), $numRowPerPage, ($currentPage - 1) * $numRowPerPage);
     /**
      * Count all categoryValues
      */
     $count = count($objCategoryValue->getAllCategoryValues($condition));
     /**
      * Load category
      */
     $objCategory = new Models_Category();
     $category = $objCategory->find($id)->toArray();
     $category = current($category);
     /**
      * Set values for tempalte
      */
     $this->setPagination($numRowPerPage, $currentPage, $count);
     $this->view->allCategoryValues = $allCategoryValues;
     $this->view->categoryValueMessage = $this->session->categoryValueMessage;
     $this->session->categoryValueMessage = null;
     $this->view->condition = $condition;
     $this->view->displayNum = $numRowPerPage;
     $this->view->category = $category;
 }
 public function forgotPasswordAction()
 {
     $this->view->headTitle('Forgot password');
     $email = $this->_getParam('email', false);
     $error = false;
     if (false != $email) {
         $objUser = new Models_User();
         $user = $objUser->getByColumnName(array('email=?' => $email))->toArray();
         $user = current($user);
         if (false == $user) {
             $error = true;
         } else {
             /**
              * Create random code
              */
             $randomCode = $objUser->generateActiveCode(20);
             $link = Vi_Registry::getConfig('liveSite') . '/user/index/id/' . $user['user_id'] . '/newPasswordAction/code/' . $randomCode;
             /**
              * Update user
              */
             $data = array('forgot_password_code' => $randomCode, 'forgot_password_expired_date' => time() + 24 * 3600);
             $objUserExp = new Models_UserExpand();
             $objUserExp->update($data, array('user_id=?' => $user['user_id']));
             /**
              * Send mail
              */
             $data = array('email' => $email, 'get_password_link' => $link, 'username' => $user['username'], 'full_name' => $user['full_name']);
             $objMail = new Models_Mail();
             $objMail->sendHtmlMail('forgot_password', $data, $email);
             /**
              * Redirect to page
              */
             $objContent = new Models_ScontentLang();
             $this->_redirect($objContent->getUrlWithoutAppBaseUrl(22));
         }
     }
     $this->view->error = $error;
     $this->view->email = $email;
 }