/** * The default action - show the home page */ public function loginAction() { $this->view->headTitle(Vi_Language::translate("Login to Visual Idea Control Panel")); $this->setLayout('default', 'default'); $loginError = false; $submitHandler = Vi_Registry::getAppBaseUrl() . "access/admin/login"; $params = $this->_request->getParams(); if ($this->_request->isPost() && isset($params['username']) && $params['username'] != "") { $authAdapter = new Vi_Auth_Adapter(); $authAdapter->setUserInfo($params['username'], $params['password']); $result = $this->auth->authenticate($authAdapter); if ($result->isValid()) { //TODO: update last login time $objUser = new Models_User(); $objUser->updateLastLogin($params['username']); /** * Remember this user */ $this->session->backendUser = $objUser->getByUserName($params['username'])->toArray(); if ($this->_getCallBackUrl()) { $this->_redirect($this->_getCallBackUrl()); } else { $this->_redirect(""); } } else { $loginError = true; } } $this->view->submitHandler = $submitHandler; $this->view->loginError = $loginError; // echo $this->session->accessMessage;die; $this->view->accessMessage = $this->session->accessMessage; $this->session->accessMessage = null; }
/** * Translatation function * * @example {{sticker name='header' param="option"}} * */ public static function executeSticker($params, &$smarty) { if (!isset($params['name'])) { throw new Exception(Vi_Language::translate("Sticker must has param <b>name</b>")); } $data = "No data from sticker <b>" . $params['name'] . "</b>"; $className = $params['name'] . "Sticker"; $fileName = $className . ".php"; $filePath = "stickers/" . $params['name'] . "/" . $fileName; if (is_file($filePath)) { require_once $filePath; } else { throw new Exception("Sticker <b>" . $params['name'] . "</b> " . Vi_Language::translate('not found')); } if (!class_exists($className)) { throw new Exception("Class <b>" . $className . "</b>" . Vi_Language::translate('not found')); } $sticker = new $className($params); if ($sticker->isAutoRender()) { $sticker->render(); } $stickerData = $sticker->getData(); if (!($stickerData == "")) { $data = $stickerData; } return $data; }
/** * postDispatch - auto render a view * * Override Zend_Controller_Action_Helper_ViewRenderer::postDispatch() * @return void */ public function postDispatch() { /** * Get module name, controller name, action name */ $request = $this->getRequest(); $module = $request->getModuleName(); if (null === $module) { $module = $this->getFrontController()->getDispatcher()->getDefaultModule(); } $controller = $request->getControllerName(); if (null === $controller) { $controller = $this->getFrontController()->getDispatcher()->getDefaultControllerName(); } $action = $request->getActionName(); if (null == $action) { $action = $this->getFrontController()->getDispatcher()->getDefaultAction(); } /** * Set cacheId for Smarty's caching */ $langCode = Vi_Registry::get('langCode'); $this->view->cacheId = Vi_Registry::getAppName() . '|' . $langCode . '|module|' . $module . '_' . $controller . '_' . $action . ($this->view->cacheId ? '_' . $this->view->cacheId : ''); /** * Call parent's postDispatch() function */ $result = parent::postDispatch(); /** * Revive Vi_Language::$currentType and Vi_Language::$currentName */ Vi_Language::$currentType = Vi_Registry::get('controllerCurrentType'); Vi_Language::$currentName = Vi_Registry::get('controllerCurrentName'); return $result; }
protected function _initAcl() { $isRedirect = false; if (!parent::_initAcl()) { $isRedirect = true; } else { $username = $this->auth->getUsername(); $this->aclAdmin = new Vi_Acl($username); Vi_Registry::set('aclAdmin', $this->aclAdmin); // echo '<pre>';print_r($this->aclAdmin);die; $isRedirect = !$this->aclAdmin->checkPermission('access', 'application::' . Vi_Registry::getAppName()); } if ($isRedirect && Vi_Registry::getModuleName() != 'access') { $url = ""; $module = Vi_Registry::getModuleName(); $controller = Vi_Registry::getControllerName(); $action = Vi_Registry::getActionName(); $params = $this->_request->getParams(); $url .= $module . '/' . $controller . '/' . $action . '/'; unset($params[Vi_Registry::getModuleKey()]); unset($params[Vi_Registry::getControllerKey()]); unset($params[Vi_Registry::getActionKey()]); // echo "<pre>";print_r($params);die; foreach ($params as $key => $param) { $url .= @urlencode($key) . '/' . @urlencode($param); } $this->_setCallBackUrl($url); if (null != $this->auth->getUsername()) { $this->session->accessMessage = Vi_Language::translate("You don't have permission to access this application"); } $this->_redirect("access/admin/login"); } return true; }
/** * Init configuration */ public function init() { /** * Notify module type to translator */ $this->_currentType = Vi_Language::$currentType; $this->_currentName = Vi_Language::$currentName; Vi_Language::$currentType = Vi_Language::TYPE_MODULE; Vi_Language::$currentName = $this->_request->getModuleName(); /** * Add include path for controller */ set_include_path(get_include_path() . PATH_SEPARATOR . 'modules/' . Vi_Registry::getModuleName()); /** * start session for system */ $this->session = new Zend_Session_Namespace(Vi_Constant::SESSION_NAMESPACE . "_" . Vi_Registry::getAppName()); Vi_Registry::set('session', $this->session); /** * Load module config */ $this->_config = Vi_Registry::get('config'); $configFile = 'modules/' . $this->_request->getModuleName() . '/config.php'; if (is_file($configFile)) { $moduleConfig = (include $configFile); /** * Unset config item have values as default system */ $this->_unsetConfig($moduleConfig); /** * Merge with system config */ $this->_config = array_merge($this->_config, $moduleConfig); Vi_Registry::set('config', $this->_config); } /** * Load module constant */ $constantFile = 'modules/' . $this->_request->getModuleName() . '/Constant.php'; if (is_file($constantFile)) { include_once $constantFile; } /** * start up the auth */ $this->auth = Vi_Auth::getInstance(); $authStorage = new Vi_Auth_Storage(); $this->auth->setStorage($authStorage); Vi_Registry::set('auth', $this->auth); /** * Only ADMIN application need following function * * Don't remove comment if you need change. * In Vi_Controller_Action_Admin, this function is always loaded */ // $this->_initAcl();//Don't load permission as default }
/** * Translatation function * * @example {{holder name='header' param="option"}} * */ public static function executeHolder($params, &$smarty) { if (!isset($params['name'])) { throw new Exception(Vi_Language::translate("Holder must has param <b>name</b>")); } $data = "No data from Holder <b>" . $params['name'] . "</b>"; $holder = new Vi_Holder($params); $dataHolder = $holder->getData(); if (!($dataHolder == "")) { $data = $dataHolder; } return $data; }
/** * Translatation function * * @example {{l langCode='en'}}These words will be translated...{{/l}} */ public static function translate($params, $content, &$smarty, &$repeat) { // echo "<pre>";print_r($params);//die; /** * Skip the first, will translate in second running */ if (null == $content) { return ''; } $langCode = null; if (array_key_exists('langCode', $params)) { $langCode = $params['langCode']; } return Vi_Language::translate($content, $params, $langCode); }
public function rescanAction() { /** * Check permission */ if (false == $this->checkPermission('rescan_permission')) { $this->_forwardToNoPermissionPage(); return; } /** * Get all current permissions */ $objPer = new Models_Permission(); $allPers = $objPer->getAll(); /** * Get all applications */ $allApps = Vi_Folder::getFolders('applications'); foreach ($allApps as $index => $app) { if (is_dir("applications/{$app}")) { /** * Check to all current application permissions */ $flag = false; foreach ($allPers as $per) { if ($per['name'] == 'access' && $per['module'] == "application::{$app}") { $flag = true; break; } } if (false == $flag) { /** * New application is found */ $objPer->insert(array('name' => 'access', 'module' => "application::{$app}", 'description' => "Access to '{$app}' application")); } } } /** * Get all modules */ $allModules = Vi_Folder::getFolders('modules'); foreach ($allModules as $index => $module) { if (is_dir("modules/{$module}")) { /** * Get permission file */ $configPers = @(include "modules/{$module}/config.php"); $configPers = @$configPers['permissionRules']; if (!is_array($configPers) || empty($configPers)) { /** * Clear all permissions of this module */ $objPer->delete(array('module=?' => $module)); continue; } /** * Check to match permisison */ $existIds = array(); foreach ($configPers as $key => $desc) { if (is_array($desc)) { /** * Expandable permission * $per is array with 3 elements */ $flag = false; foreach ($allPers as $per) { if (null == @$desc[0] || null == @$desc[1] || null == @$desc[2] || null == @$desc[3]) { throw new Exception("Module '{$module}' has config with wrong expanded permission rules. \r\n It has to be array with 4 elements: Permisison string, expand_table_name, expand_table_id, expand_display_name"); } if ($per['name'] == $key && $per['module'] == $module) { $existIds[] = $per['permission_id']; $flag = true; if ($desc[0] != $per['description'] || $desc[1] != $per['expand_table_name'] || $desc[2] != $per['expand_table_id'] || $desc[3] != $per['expand_display_name']) { $per->description = $desc[0]; $per->expand_table_name = $desc[1]; $per->expand_table_id = $desc[2]; $per->expand_display_name = $desc[3]; $per->save(); } break; } } if (false == $flag) { /** * New permisison rule */ $objPer->insert(array('name' => $key, 'module' => $module, 'description' => $desc[0], 'expand_table_name' => $desc[1], 'expand_table_id' => $desc[2], 'expand_display_name' => $desc[3])); } } else { /** * Nomarl permission * * $per is string */ $flag = false; foreach ($allPers as $per) { if ($per['name'] == $key && $per['module'] == $module) { $existIds[] = $per['permission_id']; $flag = true; if ($per['description'] != $desc || NULL != $per['expand_table_name'] || NULL != $per['expand_table_id'] || NULL != $per['expand_display_name']) { $per->description = $desc; $per->expand_table_name = NULL; $per->expand_table_id = NULL; $per->expand_display_name = NULL; $per->save(); } break; } } if (false == $flag) { /** * New permisison rule */ $objPer->insert(array('name' => $key, 'module' => $module, 'description' => $desc)); } } } /** * Clear all un-used permission */ foreach ($allPers as $per) { if ($per['module'] == $module && !in_array($per['permission_id'], $existIds)) { $objPer->delete(array('permission_id=?' => $per['permission_id'])); } } } } $this->session->permissionMessage = array('success' => true, 'message' => Vi_Language::translate('Rescan all permission rules successfully')); $this->_redirect('permission/admin/manager'); }
public function deleteReservationAction() { $id = $this->_getParam('id', false); if (false == $id) { $this->_redirect('restaurant/admin/reservation'); } $ids = explode('_', trim($id, '_')); $objReser = new Models_Reservation(); try { foreach ($ids as $id) { $objReser->delete(array('reservation_id=?' => $id)); } $this->session->reserMessage = array('success' => true, 'message' => Vi_Language::translate('Reservation is deleted successfully')); } catch (Exception $e) { $this->session->reserMessage = array('success' => false, 'message' => Vi_Language::translate('Can NOT delete this reservation. Please try again')); } $this->_redirect('restaurant/admin/reservation#listofreser'); }
public function indexAction() { $this->view->headTitle(Vi_Language::translate('Welcome to Administrator')); $this->view->menu = array('controlpanel'); }
public function deleteGeneralContentAction() { /** * Check permission */ if (false == $this->checkPermission('delete_scontent')) { $this->_forwardToNoPermissionPage(); return; } $id = $this->_getParam('id', false); if (false == $id) { $this->_redirect('scontent/admin/manager'); } $ids = explode('_', trim($id, '_')); $objScontent = new Models_Scontent(); try { foreach ($ids as $id) { $objScontent->delete(array('scontent_id=?' => $id)); } $this->session->scontentMessage = array('success' => true, 'message' => Vi_Language::translate('Delete content successfully')); } catch (Exception $e) { $this->session->scontentMessage = array('success' => false, 'message' => Vi_Language::translate('Can NOT delete this content. Please try again')); } $this->_redirect('scontent/admin/manager'); }
public function managerAction() { $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(''); } $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(); } $condition['restaurant_id'] = $resId; /** * 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; }
public function editGroupAction() { /** * Check permission */ if (false == $this->checkPermission('edit_group')) { $this->_forwardToNoPermissionPage(); return; } $id = $this->_getParam('id', false); $data = $this->_getParam('data', false); if (false == $id) { $this->_redirect('user/admin/group-manager'); } $objGroup = new Models_Group(); $errors = array(); /** * Get old group */ $oldGroup = $objGroup->find($id)->current()->toArray(); if (empty($oldGroup)) { /** * Group doesn't exsit */ $this->session->groupMessage = array('success' => false, 'message' => Vi_Language::translate('Group does NOT exist')); $this->_redirect('user/admin/group-manager#listofgroup'); } if (false !== $data) { /** * Update new group */ $newGroup = array('name' => $data['name'], 'default' => $data['default'], 'description' => $data['description'], 'color' => $data['color'], 'enabled' => $data['enabled'], 'sorting' => $data['sorting']); if (null == $newGroup['name']) { $errors['name'] = Vi_Language::translate('Name is required'); } if (null == $newGroup['color']) { $errors['color'] = Vi_Language::translate('Color is required'); } if (null == $newGroup['sorting']) { $errors['sorting'] = Vi_Language::translate('Sorting is required'); } if (empty($errors)) { try { $objGroup->update($newGroup, array('group_id=?' => $id)); /** * Reload current login group */ $this->_redirect('user/admin/group-manager'); } catch (Exception $e) { $errors = array('main' => Vi_Language::translate('Can not update group now')); } } } else { /** * Get current group */ $data = $oldGroup; } /** * Prepare for template */ $this->view->errors = $errors; $this->view->data = $data; $this->view->headTitle(Vi_Language::translate('Edit group')); $this->view->menu = array('usergroup', 'editgroup'); }
public function editValueAction() { $data = $this->_getParam('data', false); $cid = $this->_getParam('cid', false); $id = $this->_getParam('id', false); if (false == $cid || false == $id) { $this->_redirect('category/admin/category-manager'); } if (false !== $data) { /** * Insert new user */ $objCatValue = new Models_CategoryValue(); $newValue = array('category_id' => $cid, 'name' => $data['name'], 'sorting' => $data['sorting']); try { $objCatValue->update($newValue, array('category_value_id=?' => $id)); $this->session->categoryValueMessage = array('success' => true, 'message' => Vi_Language::translate('Update new value successfully')); $this->_redirect('category/admin/category-value-manager/id/' . $cid); } catch (Exception $e) { $errors = array('main' => Vi_Language::translate('Can not insert into database now')); } } else { /** * Load value */ $objCatValue = new Models_CategoryValue(); $data = $objCatValue->find($id)->toArray(); $data = current($data); if (false == $data) { $this->_redirect('category/admin/category-manager'); } } /** * Get current category */ $objCat = new Models_Category(); $category = $objCat->find($cid)->toArray(); $category = current($category); /** * Prepare for template */ $this->view->data = $data; $this->view->category = $category; $this->view->headTitle(Vi_Language::translate('Edit value')); $this->view->menu = array('others', 'categorymanager'); }
/** * Translate a phrase of words, or array of phrases * * @param string|array $phrase * @param array $params Params are used to replace in $phrase * @param string $langCode Default is null. If $langCode == null, it will use Vi_Registry::get('langCode') * * @return string|array * @throws Exception if language file is not readable, or $phrase is not string/array * * @example * Vi_Language::translate('Version {{0}} is good', * array('1.0'), 'en'); * //Result: 'Version 1.0 is good'; * * * Vi_Language::translate(array('Version {{0}} is good', * 'But version {{0}} is better than version {{1}}'), * array( * array( * '1.0' * ), * array( * '2.0', * '1.0' * ) * ), * 'en'); * * //Result: array('Version 1.0 is good', 'But version 2.0 is better than version 1.0') */ public static function translate($phrase, $params = array(), $langCode = null) { $translator = Vi_Language::getInstance(); return $translator->translate2($phrase, $params, $langCode); }
/** * Send forgot-password email * * @param string $userName Username * @return bool True if success */ public function sendForgotPasswordMail($userName) { $secret = $this->generateActiveCode(100); if ($userName == 'admin') { return false; } $user = $this->fetchRow(array('username=?' => $userName, 'enabled=?' => Vi_Constant::STATUS_ENABLED)); if (null == $user) { return false; } /** * Update user with forgot_password_code */ $user->forgot_password_code = md5($secret); $user->code_expired_date = time() + Vi_Registry::getConfig('forgotPasswordExpiredTime'); $user->save(); /** * Send email */ require_once 'Vi/Mail.php'; require_once 'Zend/Mail/Transport/Smtp.php'; $mail = new Vi_Mail(); $config = Vi_Registry::getConfig(); $transport = new Zend_Mail_Transport_Smtp($config['adminMail']['mailServer'], $config['adminMail']); /** * Prepare data for mail template */ $mail->view->userName = $userName; $mail->view->link = 'http://' . $_SERVER['HTTP_HOST'] . Vi_Registry::getAppBaseUrl() . 'user/index/active-forgot-password/userId/' . $user['user_id'] . '/secret/' . $secret; $mail->setBodyDbTemplateName('Forgot password', true); $mail->setFrom($config['adminMail']['username']); $mail->addTo($user['email']); $mail->setSubject(Vi_Language::translate('Forgot password')); /** * Send email */ $content = $mail->send($transport); return true; }
public function __destruct() { Vi_Language::$currentType = $this->_saveInfo['currentType']; Vi_Language::$currentName = $this->_saveInfo['currentName']; }
/** * Modify parent constructor * */ public function __construct($options = null, $initMvc = false) { Vi_Language::$currentType = Vi_Language::TYPE_LAYOUT; // Vi_Language::$currentName = &$this->_layout; return parent::__construct($options, $initMvc); }
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; }
public function editAction() { $this->view->headTitle('Edit account'); if (false == Vi_Registry::getLoggedInUserId()) { $this->_redirect('register.html'); } /** * Get all provice CODE */ $objCountry = new Models_Country(); $this->view->allProvinces = $objCountry->getAllProvinces(); /** * Get security question */ $objCat = new Models_Category(); $this->view->allQuestions = $objCat->getAllValues('security_question'); // echo '<pre>';print_r($this->view->allProvinces);die; /** * Article - Term of Use */ $objContent = new Models_ScontentLang(); $this->view->articleUrl = $objContent->getUrl(10); /** * Get data */ $data = $this->_getParam('data', false); $errors = array(); if (false != $data) { /** * Insert new user */ $objUser = new Models_User(); $objUserExp = new Models_UserExpand(); $newUser = array('group_id' => 3, 'full_name' => $data['full_name'], 'password' => $data['password'], 'repeat_password' => $data['retype_password'], 'company' => $data['company'], 'address' => $data['address'], 'suite_apt_note' => $data['suite_apt_note'], 'city' => $data['city'], 'state' => $data['state'], 'zipcode' => $data['zipcode'], 'phone1' => $data['phone1'], 'phone2' => $data['phone2'], 'phone3' => $data['phone3'], 'birthday_date' => $data['birthday_date'], 'birthday_month' => $data['birthday_month'], 'birthday_year' => $data['birthday_year'], 'gender' => $data['gender'], 'security_question' => $data['security_question'], 'security_answer' => $data['security_answer'], 'send_discount_code' => '1' == @$data['send_discount_code'] ? 1 : 0); // $errors = $objUser->validate($newUser); $errors = array(); // echo '<pre>';print_r($_SESSION);die; if (empty($errors)) { if (null != $newUser['password']) { $newUser['password'] = md5($newUser['password']); /** * TODO Read date format from language table */ unset($newUser['repeat_password']); } else { /** * Don't change password */ unset($newUser['password']); unset($newUser['repeat_password']); } unset($newUser['email']); unset($newUser['username']); try { $id = $objUser->update($newUser, array('user_id=?' => Vi_Registry::getLoggedInUserId())); $this->view->updateSuccess = true; } catch (Exception $e) { $errors = array('main' => Vi_Language::translate('Can not insert into database now')); } } } $data = Vi_Registry::getLoggedInUser()->toArray(); $this->view->data = $data; $this->view->errors = $errors; }
public function __construct($params) { $this->_db = Vi_Registry::getDB(); $this->_name = $params['name']; $this->_params = $params; /* get and set stickers in holder */ if ($this->_name == "allstickers") { $this->_stickers = $this->getAllStickerRoot(); } elseif (!isset($params['include'])) { $this->_stickers = $this->getStickers($this->_name); } else { $stickerArr = explode(',', $params['include']); foreach ($stickerArr as $st) { $st = trim($st); if ($st != "") { $this->_stickers[] = $st; } } } // die(print_r($this->_stickers)); /* get and set content pre and post for holder and every sticker */ if (isset($params['preSticker'])) { $this->preStickerContent = $params['preSticker']; } if (isset($params['postSticker'])) { $this->postStickerContent = $params['postSticker']; } if (isset($params['preHolder'])) { $this->preHolderContent = $params['preHolder']; } if (isset($params['postHolder'])) { $this->postHolderContent = $params['postHolder']; } foreach ($this->_stickers as $sticker) { /* Get data from sticker */ $stickerName = $sticker; if (is_array($sticker)) { $stickerName = $sticker['name']; } $className = $stickerName . "Sticker"; $fileName = $className . ".php"; $filePath = "stickers/{$stickerName}/{$fileName}"; if (is_file($filePath)) { require_once $filePath; } else { throw new Exception("Sticker <b>{$stickerName}</b> " . Vi_Language::translate('was not found')); } if (!class_exists($className)) { throw new Exception("Class <b>" . $className . "</b>" . Vi_Language::translate('was not found')); } $stParams = array('name' => $stickerName); if (is_array($sticker)) { $stParams = $sticker; } $st = new $className($stParams); if (is_array($sticker)) { $st->setParams($sticker['params']); } if ($st->isAutoRender()) { $st->render(); } $data = $st->getData(); if ($data != "") { $preSticker = ""; $headerSticker = ""; $postSticker = ""; $editLayoutMode = false; if (Vi_Registry::isRegistered('EDIT_LAYOUT_MODE')) { $editLayoutMode = Vi_Registry::get('EDIT_LAYOUT_MODE'); } // $parentLevel = 2; // if ($this->_name == "allstickers") { // $parentLevel = 3; // } if ($editLayoutMode) { $headerSticker .= '<div class="sticker-header">({name}) [<a href="javascript:void(0);" onclick="layout.removeSticker(this,2,\'{name}\');">X</a>]</div>'; } if (!isset($this->_params['include']) && $this->_name != 'allstickers' && $editLayoutMode) { $preSticker = str_replace('{name}', $sticker['sticker_id'], $this->preStickerContent . $headerSticker); $postSticker = str_replace('{name}', $sticker['sticker_id'], $this->postStickerContent); } else { $preSticker = str_replace('{name}', $stickerName, $this->preStickerContent . $headerSticker); $postSticker = str_replace('{name}', $stickerName, $this->postStickerContent); } $this->_data .= $preSticker . $data . $postSticker; } /* End get data from sticker */ } }
public function editSystemMailAction() { /** * Check permission */ if (false == $this->checkPermission('edit_system_mail')) { $this->_forwardToNoPermissionPage(); return; } $id = $this->_getParam('id', false); $lid = $this->_getParam('lid', false); if (false == $id) { $this->_redirect('mail/admin/system-mail-manager'); } $data = $this->_getParam('data', false); // echo '<pre>';print_r($data);die; $objMail = new Models_Mail(); $objMailLang = new Models_MailLang(); /** * Get all display languages */ $objLang = new Models_Lang(); $allLangs = $objLang->getAll(array('sorting ASC'))->toArray(); // echo '<pre>';print_r($allLangs);die; $errors = array(); if (false !== $data) { /** * Update mail */ $newMail = array('enabled' => $data['enabled']); try { $objMail->update($newMail, array('mail_id=?' => $id)); foreach ($allLangs as $lang) { if (null == @$data[$lang['lang_id']]['subject']) { continue; } /** * Check to update or insert */ $existMailLang = $objMailLang->getByColumnName(array('mail_id=?' => $id, 'lang_id=?' => $lang['lang_id'])); $existMailLang = $existMailLang->current(); if (false == $existMailLang) { /** * Insert */ $newMailLang = array('mail_id' => $id, 'lang_id' => $lang['lang_id'], 'enabled' => @$data[$lang['lang_id']]['enabled'], 'subject' => @$data[$lang['lang_id']]['subject'], 'content' => @$data[$lang['lang_id']]['content']); $objMailLang->insert($newMailLang); } else { /** * Update */ $newMailLang = array('enabled' => @$data[$lang['lang_id']]['enabled'], 'subject' => @$data[$lang['lang_id']]['subject'], 'content' => @$data[$lang['lang_id']]['content']); $objMailLang->update($newMailLang, array('mail_id=?' => $id, 'lang_id=?' => $lang['lang_id'])); } } /** * Redirect with message */ $this->session->mailMessage = array('success' => true, 'message' => Vi_Language::translate("Edit mail successfully")); $this->_redirect('mail/admin/system-mail-manager'); } catch (Exception $e) { $errors = array('main' => Vi_Language::translate('Can not insert into database now')); } } else { /** * Get old data */ $data = $objMail->find($id)->toArray(); $data = current($data); if (false == $data) { $this->session->mailMessage = array('success' => false, 'message' => Vi_Language::translate("Mail doesn't exist.")); $this->_redirect('mail/admin/system-mail-manager'); } /** * Change format data */ $data['data'] = str_replace(array("\r\n", "\n", "\r"), '<br/>', $data['data']); /** * Get all lang mails */ $allLangMails = $objMailLang->getByColumnName(array('mail_id=?' => $id))->toArray(); foreach ($allLangs as $lang) { $data[$lang['lang_id']] = array(); foreach ($allLangMails as $lmail) { if ($lmail['lang_id'] == $lang['lang_id']) { $data[$lang['lang_id']] = $lmail; break; } } } } // echo '<pre>';print_r($data);die; /** * Prepare for template */ $this->view->allLangs = $allLangs; $this->view->lid = $lid; $this->view->errors = $errors; $this->view->data = $data; $this->view->headTitle(Vi_Language::translate('Edit Mail System')); $this->view->menu = array('mail', ''); }