Beispiel #1
0
 public function index($offset = 0, $orderField = '', $orderCriteria = '')
 {
     $model = SCallbacksQuery::create()->joinSCallbackStatuses(null, 'left join')->joinSCallbackThemes(null, 'left join');
     if ($this->input->get('filterID') && $this->input->get('filterID') > 0) {
         $model = $model->filterById((int) $this->input->get('filterID'));
     }
     if ($this->input->get('user_name')) {
         $user_name = $this->input->get('user_name');
         if (!strpos($user_name, '%')) {
             $user_name = '%' . $user_name . '%';
         }
         $model->condition('name', 'SCallbacks.Name LIKE ?', $user_name);
         $model->where(array('name'), Criteria::LOGICAL_OR);
     }
     if ($this->input->get('phone')) {
         $phone = $this->input->get('phone');
         if (!strpos($phone, '%')) {
             $phone = '%' . $phone . '%';
         }
         $model->condition('phone', 'SCallbacks.Phone LIKE ?', $phone);
         $model->where(array('phone'), Criteria::LOGICAL_OR);
     }
     if ($this->input->get('ThemeId')) {
         if ((int) $this->input->get('ThemeId') > 0) {
             $model = $model->filterByThemeId((int) $this->input->get('ThemeId'));
         }
         if ($this->input->get('ThemeId') === 'without') {
             $model = $model->where('SCallbacks.ThemeId = ?', 0);
         }
     }
     if ($this->input->get('StatusId') && $this->input->get('StatusId') > 0) {
         $model = $model->filterByStatusId((int) $this->input->get('StatusId'));
     }
     if ($this->input->get('created_from')) {
         $model = $model->where('FROM_UNIXTIME(SCallbacks.Date, \'%Y-%m-%d\') >= ?', date('Y-m-d', strtotime($this->input->get('created_from'))));
     }
     if ($this->input->get('created_to')) {
         $model = $model->where('FROM_UNIXTIME(SCallbacks.Date, \'%Y-%m-%d\') <= ?', date('Y-m-d', strtotime($this->input->get('created_to'))));
     }
     if ($orderField !== '' && $orderCriteria !== '' && (method_exists($model, 'filterBy' . $orderField) || $orderField == 'SCallbackStatuses.Text' || $orderField == 'SCallbackThemes.Text')) {
         switch ($orderCriteria) {
             case 'ASC':
                 $model = $model->orderBy($orderField, Criteria::ASC);
                 $nextOrderCriteria = 'DESC';
                 break;
             case 'DESC':
                 $model = $model->orderBy($orderField, Criteria::DESC);
                 $nextOrderCriteria = 'ASC';
                 break;
         }
     } else {
         $model->orderById(Criteria::DESC);
     }
     $totalCallbacks = $this->_count($model);
     $model = $model->limit(10)->offset((int) $offset)->find();
     $callbackStatuses = SCallbackStatusesQuery::create()->joinWithI18n(MY_Controller::defaultLocale(), Criteria::RIGHT_JOIN)->where('SCallbackStatusesI18n.Locale = "' . MY_Controller::defaultLocale() . '"')->orderBy('IsDefault', Criteria::DESC)->orderById()->find();
     \CMSFactory\assetManager::create()->setData(array('model' => $model, 'totalCallbacks' => $totalCallbacks, 'nextOrderCriteria' => $nextOrderCriteria, 'orderField' => $orderField, 'callbackStatuses' => $callbackStatuses))->render('main');
 }
 /**
  * updare settings for email
  */
 public function update_settings($locale)
 {
     $locale = $locale ? $locale : MY_Controller::defaultLocale();
     if ($_POST) {
         $this->form_validation->set_rules('settings[admin_email]', lang('Admin email', 'cmsemail'), 'required|xss_clean|valid_email');
         $this->form_validation->set_rules('settings[from_email]', lang('Email sender', 'cmsemail'), 'required|xss_clean|valid_email');
         $this->form_validation->set_rules('settings[from]', lang('From', 'cmsemail'), 'required|xss_clean');
         $this->form_validation->set_rules('settings[theme]', lang('From email', 'cmsemail'), 'xss_clean|required');
         if ($_POST['settings']['wraper_activ']) {
             $this->form_validation->set_rules('settings[wraper]', lang('Wraper', 'cmsemail'), 'required|xss_clean|callback_wraper_check');
         } else {
             $this->form_validation->set_rules('settings[wraper]', lang('Wraper', 'cmsemail'), 'xss_clean');
         }
         if ($this->form_validation->run($this) == FALSE) {
             showMessage(validation_errors(), lang('Message', 'cmsemail'), 'r');
         } else {
             $data = array('locale' => $locale, 'settings' => $_POST['settings']);
             if ($this->email->setSettings($data)) {
                 showMessage(lang('Settings saved', 'cmsemail'), lang('Message', 'cmsemail'));
                 $this->lib_admin->log(lang("Template customization mails have been changed", "cmsemail") . '. Id: ' . $id);
             }
         }
         $this->cache->delete_all();
     }
 }
 /**
  * Returns license agreement from template, or default agreement
  * @return string
  */
 public function getLicenseAgreement()
 {
     $licenses = $this->getLicensensesAgreements();
     $locale = getLanguage(array('locale' => \CI::$APP->config->item('language')));
     $locale = $locale ? $locale['identif'] : \MY_Controller::defaultLocale();
     if (count($licenses) > 0) {
         if (key_exists($locale, $licenses)) {
             $licenseText = file_get_contents($licenses[$locale]);
         } else {
             //                $licenseText = file_get_contents(current($licenses));
         }
         return str_replace('{template_name}', $this->label, $licenseText);
     }
     return 0;
 }
 function search()
 {
     if (!empty($_GET)) {
         //cp_check_perm('user_view_data');
         //?s_data=ad&s_email=&role=0
         $locale = MY_Controller::defaultLocale();
         @($s_data = $this->input->get('s_data'));
         @($s_email = $this->input->get('s_email'));
         $role = $this->input->get('role');
         $page = (int) $this->uri->segment(8);
         $this->db->select("users.*", FALSE);
         $this->db->select("shop_rbac_roles.name AS role_name", FALSE);
         $this->db->select("shop_rbac_roles_i18n.alt_name AS role_alt_name, shop_rbac_roles_i18n.locale", FALSE);
         $this->db->join("shop_rbac_roles", "shop_rbac_roles.id = users.role_id", 'left');
         $this->db->join("shop_rbac_roles_i18n", "shop_rbac_roles.id = shop_rbac_roles_i18n.id AND shop_rbac_roles_i18n.locale='{$locale}'", 'left');
         if (!empty($s_data)) {
             $this->db->like('username', $s_data);
         } elseif (!empty($s_email)) {
             $this->db->like('email', $s_email);
         }
         $this->db->order_by('created', 'desc');
         $query = $this->db->get('users');
         if ($query->num_rows() == 0) {
             $this->template->add_array($this->show_edit_prems_tpl($id = 2));
             $this->template->add_array(array('role_id' => $role));
             $this->template->assign('users', FALSE);
             $rezult_table = $this->fetch_tpl('main');
             echo $rezult_table;
         } else {
             $users = $query->result_array();
             for ($i = 0, $users_c = count($users); $i < $users_c; $i++) {
                 if ($role != 0) {
                     if ($users[$i]['role_id'] != $role) {
                         unset($users[$i]);
                     }
                 }
             }
             // recount users
             if (count($users) == 0) {
                 $this->template->add_array($this->show_edit_prems_tpl($id = 2));
                 $this->template->add_array(array('role_id' => $role));
                 $this->template->assign('users', FALSE);
                 $rezult_table = $this->fetch_tpl('main');
                 echo $rezult_table;
             } else {
                 $this->template->assign('users', $users);
                 $this->template->add_array($this->show_edit_prems_tpl($id = 2));
                 $this->template->add_array(array('role_id' => $role));
                 $rezult_table = $this->fetch_tpl('main');
                 echo $rezult_table;
             }
         }
     } else {
         showMessage(lang('a_bas_filt_pass_not_post'), '', 'r');
         pjax('/admin/components/init_window/user_manager');
         exit;
     }
 }
 /**
  * edit a RBAC role
  *
  * @access	public
  * @param	integer $roleId
  * @return	void
  */
 public function roleEdit($roleId)
 {
     $sqlModel = 'SELECT SRR.id, SRR.name, SRR.importance, SRRI.alt_name, SRRI.description
         FROM shop_rbac_roles SRR
         LEFT JOIN shop_rbac_roles_i18n SRRI ON SRRI.id = SRR.id  AND SRRI.locale = "' . MY_Controller::getCurrentLocale() . '" WHERE SRR.id = "' . $roleId . '" ORDER BY SRR.name ASC';
     $queryModel = $this->db->query($sqlModel);
     $queryModel->row();
     if ($queryModel === null) {
         $this->error404(lang("Role not found"));
     }
     if (!empty($_POST)) {
         $this->form_validation->set_rules('alt_name', lang('Title'), 'required');
         if ($this->form_validation->run($this) == FALSE) {
             showMessage(validation_errors(), '', 'r');
         } else {
             $sql = "UPDATE shop_rbac_roles SET importance = " . $this->db->escape($_POST['Importance']) . " WHERE id   =   '" . $roleId . "'";
             $this->db->query($sql);
             //                echo "<pre>";
             //                var_dump($_POST);
             //                var_dump($roleId);
             //                exit('ok');
             $sqlI = "UPDATE `shop_rbac_roles_i18n` SET `alt_name` = " . $this->db->escape($_POST['alt_name']) . ", `description` = " . $this->db->escape($_POST['Description']) . " WHERE id = '" . $roleId . "' AND locale = '" . MY_Controller::getCurrentLocale() . "'";
             $this->db->query($sqlI);
             //$this->db->where('id',$roleId)->update('shop_rbac_roles',array('name', $_POST['Name']));
             if ($_POST['Privileges']) {
                 $idForDelete = implode(', ', $_POST['Privileges']);
                 $sqlDelete = "DELETE FROM `shop_rbac_roles_privileges` WHERE `role_id`=" . $roleId . " AND `privilege_id` NOT IN (" . $idForDelete . ")";
                 $this->db->query($sqlDelete);
                 foreach ($_POST['Privileges'] as $idPrivilege) {
                     if (!$this->db->where(array('role_id' => $roleId, 'privilege_id' => (int) $idPrivilege))->get(self::$rbac_roles_privileges_table)->num_rows()) {
                         $sqlPrivilege = "INSERT INTO shop_rbac_roles_privileges (role_id, privilege_id) VALUES(" . $this->db->escape($roleId) . ", " . $this->db->escape($idPrivilege) . ")";
                         $this->db->query($sqlPrivilege);
                     }
                 }
             }
             $this->lib_admin->log(lang("Role was edited") . '. Id: ' . $roleId);
             showMessage(lang("Changes have been saved"));
             pjax('/admin/rbac/roleEdit/' . $roleId);
             if ($_POST['action'] != 'edit') {
                 pjax('/admin/rbac/roleList');
             }
         }
     } else {
         //preparing array of privileges ids which belong to currenc role
         $sql = 'SELECT `privilege_id`
         FROM `shop_rbac_roles_privileges` WHERE `role_id` = ' . $roleId;
         $queryPrivilegeR = $this->db->query($sql)->result_array();
         $role_privileges = array();
         foreach ($queryPrivilegeR as $item) {
             $role_privileges[] = (int) $item['privilege_id'];
         }
         //preparing array of controller types
         $types = $this->db->query("SELECT DISTINCT `type` FROM " . self::$rbac_group_table)->result_array();
         foreach ($types as $item) {
             $controller_types[] = $item['type'];
         }
         //preparing groups
         $locale = MY_Controller::defaultLocale();
         $res = $this->db->select('id')->get_where(self::$rbac_group_table . "_i18n", ['locale' => $locale])->result_array();
         if (count($res) < 1) {
             $locale = 'en';
         }
         foreach ($controller_types as $controller_type) {
             $result[$controller_type] = $this->db->query("SELECT *, " . self::$rbac_group_table . ".id as id FROM " . self::$rbac_group_table . "\n                    LEFT JOIN `" . self::$rbac_group_table . "_i18n` ON " . self::$rbac_group_table . ".id=" . self::$rbac_group_table . "_i18n.id AND `locale` = '" . $locale . "'\n                        WHERE `type`='" . $controller_type . "'")->result_array();
             if (!empty($result[$controller_type])) {
                 foreach ($result[$controller_type] as $key => $group) {
                     $result[$controller_type][$key]['privileges'] = $this->db->query("SELECT *, " . self::$rbac_privileges_table . ".id as id FROM " . self::$rbac_privileges_table . "\n                            LEFT JOIN " . self::$rbac_privileges_table . "_i18n ON " . self::$rbac_privileges_table . ".id=" . self::$rbac_privileges_table . "_i18n.id AND `locale` = '" . $locale . "'\n                                WHERE `group_id`=" . (int) $group['id'])->result_array();
                     /* echo "SELECT * FROM " . self::$rbac_privileges_table . "
                        LEFT JOIN " . self::$rbac_privileges_table . "_i18n ON " . self::$rbac_privileges_table . ".id=" . self::$rbac_privileges_table . "_i18n.id AND `locale` = '" . MY_Controller::getCurrentLocale() . "'
                        WHERE `group_id`=" . (int) $group['id'] . '<br/>'; */
                 }
             }
         }
         //array sort
         foreach ($controller_types as $controller_type) {
             //foreach ($result[$controller_type] as $key => $value) {
             for ($j = 0; $j < count($result[$controller_type]); $j++) {
                 for ($i = 0; $i < count($result[$controller_type]) - $j; $i++) {
                     if ($result[$controller_type][$i + 1]) {
                         if (count($result[$controller_type][$i + 1]['privileges']) < count($result[$controller_type][$i]['privileges'])) {
                             $temp = $result[$controller_type][$i];
                             $result[$controller_type][$i] = $result[$controller_type][$i + 1];
                             $result[$controller_type][$i + 1] = $temp;
                         }
                     }
                 }
             }
         }
         $sqlLangSel = 'SELECT lang_sel FROM settings';
         $Lang = $this->db->query($sqlLangSel)->row();
         $this->template->add_array(array('model' => $queryModel->row(), 'lang_sel' => $Lang, 'types' => $result, 'privilegeCheck' => $role_privileges));
         $this->template->show('roleEdit', FALSE);
     }
 }
 /**
  * Get widget info title/description/method
  */
 private function parse_widget_xml($xml_folder)
 {
     $modulePath = getModulePath($xml_folder);
     if ($this->lib_xml->load($modulePath . 'widgets')) {
         $widgets_array = $this->lib_xml->parse();
         $info = $widgets_array['widgets'][0]['widget'];
         $return = array();
         $locale = MY_Controller::defaultLocale();
         foreach ($info as $k => $v) {
             if ($v['i18n_' . $locale]) {
                 $temp = array('title' => $v['i18n_' . $locale][0]['title'][0], 'description' => $v['i18n_' . $locale][0]['description'][0], 'method' => $v['method'][0]);
                 array_push($return, $temp);
             }
         }
         if (count($return) > 0) {
             return $return;
         }
     }
     return FALSE;
 }
 /**
  * Show edit_page form
  *
  * @access public
  */
 function edit($page_id, $lang = 0)
 {
     //cp_check_perm('page_edit');
     //        CI::$APP->config->set_item('cur_lang', $lang);
     if ($this->cms_admin->get_page($page_id) == FALSE) {
         showMessage(lang("Page", "admin") . $page_id . lang("Not found", "admin"), false, 'r');
         exit;
     }
     // Get page data
     $data = $this->db->get_where('content', array('id' => $page_id))->row_array();
     if ($data['lang_alias'] != 0) {
         redirect('/admin/pages/edit/' . $data['lang_alias'] . '/' . $data['lang']);
     }
     if ($lang != 0 and $lang != $data['lang']) {
         $data = $this->db->get_where('content', array('lang_alias' => $page_id, 'lang' => $lang));
         if ($data->num_rows() > 0) {
             $data = $data->row_array();
         } else {
             $data = FALSE;
         }
     }
     /** Init Event. Pre Edit Page */
     \CMSFactory\Events::create()->registerEvent(array('pageId' => $page_id, 'url' => $data['url']), 'BaseAdminPage:preUpdate');
     \CMSFactory\Events::runFactory();
     ($hook = get_hook('admin_page_edit_found')) ? eval($hook) : NULL;
     if ($data) {
         $this->template->assign('page_id', $page_id);
         $this->template->assign('update_page_id', $data['id']);
         $this->template->add_array($data);
         $this->load->module('tags');
         $this->template->assign('tags', $this->tags->get_page_tags($data['id']));
         // Roles
         $this->db->where('page_id', $page_id);
         $query = $this->db->get('content_permissions', 1);
         $page_roles = $query->row_array();
         $page_roles = unserialize($page_roles['data']);
         // Set roles
         $locale = MY_Controller::defaultLocale();
         $g_query = $this->db->query("SELECT * FROM `shop_rbac_roles` JOIN `shop_rbac_roles_i18n` ON shop_rbac_roles.id=shop_rbac_roles_i18n.id WHERE locale='{$locale}'");
         $roles = $g_query->result_array();
         if ($roles != FALSE) {
             for ($i = 0, $cnt = count($roles); $i < $cnt; $i++) {
                 for ($i2 = 0, $cnt2 = count($page_roles); $i2 < $cnt2; $i2++) {
                     if ($page_roles[$i2]['role_id'] == $roles[$i]['id']) {
                         $roles[$i]['selected'] = 'selected="true"';
                     }
                     if ($page_roles[$i2]['role_id'] == '0') {
                         $this->template->assign('all_selected', 'selected="true"');
                     }
                 }
             }
         }
         $this->template->assign('roles', $roles);
         // roles
         // explode publush_date to date and time
         $this->template->assign('publish_date', date('Y-m-d', $data['publish_date']));
         $this->template->assign('publish_time', date('H:i:s', $data['publish_date']));
         $this->template->assign('create_date', date('Y-m-d', $data['created']));
         $this->template->assign('create_time', date('H:i:s', $data['created']));
         // end
         // set langs
         $langs = $this->cms_admin->get_langs();
         if (count($langs) > 1) {
             $this->template->assign('show_langs', 1);
         }
         // Load category
         $category = $this->lib_category->get_category($data['category']);
         $this->template->add_array(array('page_lang' => $data['lang'], 'page_identif' => $data[identif], 'tree' => $this->lib_category->build(), 'parent_id' => $data['category'], 'langs' => $langs, 'defLang' => $def_lang, 'category' => $category));
         if ($data['lang_alias'] != 0) {
             $orig_page = $this->cms_admin->get_page($data['lang_alias']);
             $this->template->assign('orig_page', $orig_page);
         }
         ($hook = get_hook('admin_show_edit_page_tpl')) ? eval($hook) : NULL;
         $this->template->show('edit_page', FALSE);
     } else {
         // create page copy for $lang
         $cur_lang = $this->cms_admin->get_lang($lang);
         if ($cur_lang != FALSE) {
             // lang exists
             $defpage = $this->cms_admin->get_page($page_id);
             $new_data = array('author' => $this->dx_auth->get_username(), 'comments_status' => $defpage['comments_status'], 'category' => $defpage['category'], 'cat_url' => $defpage['cat_url'], 'url' => $defpage['url'], 'created' => $defpage['created'], 'publish_date' => $defpage['publish_date'], 'post_status' => $defpage['post_status'], 'lang' => $lang, 'lang_alias' => $defpage['id'], 'full_tpl' => $defpage['full_tpl'], 'main_tpl' => $defpage['main_tpl']);
             ($hook = get_hook('admin_page_create_empty_translation')) ? eval($hook) : NULL;
             $new_p_id = $this->cms_admin->add_page($new_data);
             if ($new_p_id > 0) {
                 showMessage(lang("Language of the page", "admin") . '<b> ' . $cur_lang['lang_name'] . '. </b>' . lang("ID", 'admin') . ' <b>' . $new_p_id . '.</b>');
                 if ($this->pjaxRequest) {
                     pjax('/admin/pages/edit/' . $page_id . '/' . $lang);
                 } else {
                     redirect('/admin/pages/edit/' . $page_id . '/' . $lang);
                 }
                 //exit;
             } else {
                 die('Cant get page id!');
             }
         }
     }
 }