Esempio n. 1
0
 public function actionUpdate($id = false, $page = 1)
 {
     $role_id = Users::model()->findByPk(Yii::app()->user->id)->role_id;
     if ($role_id != 7 || $role_id == 7 && $id == 1) {
         $pages = new Pages();
         if (!empty($id) && Pages::model()->existsPage($id)) {
             $active = Modules::model()->getActiveModule($id);
             $model = $pages->findByPk($id);
             if (isset($_POST['Pages'])) {
                 if ($model->validate()) {
                     $old_file_id = $model->image_id;
                     if ($_POST['Pages']['image_id'] == 'NULL') {
                         $_POST['Pages']['image_id'] = '';
                     }
                     $model->attributes = $_POST['Pages'];
                     if ($model->save()) {
                         if ((int) $_POST['Pages']['image_id']) {
                             Files::model()->saveTempFile((int) $_POST['Pages']['image_id']);
                         } elseif ($_POST['Pages']['image_id'] == '') {
                             Files::model()->deleteFile($old_file_id, 'page');
                         }
                         if ($old_file_id != $model->image_id) {
                             Files::model()->deleteFile($old_file_id, 'page');
                         }
                         // Yii::app()->user->setFlash('message','<p style="color:green;">Сохранено</p>');
                         $this->redirect(YII::app()->baseUrl . '/admin.php?r=pages/update&id=' . $id);
                     } else {
                         // Yii::app()->user->setFlash('message','<p style="color:red;">Ошибка</p>');
                     }
                 }
             }
             $image = Pages::model()->getImage($id, 'page');
             $this->pageTitle = 'Редактирование раздела — ' . $model->name;
             $this->render('update', array('model' => $model, 'name' => $model->getPageNameById($id), 'active' => $active, 'image' => $image, 'page' => $page));
         } else {
             $this->redirect(Yii::app()->request->baseUrl);
         }
     } else {
         $this->redirect(Yii::app()->baseUrl . '/admin.php?r=pages/access');
     }
 }
Esempio n. 2
0
 public function actionIndex()
 {
     //if($this->beginCache('doc_url_'.md5(Yii::app()->request->url), array('duration'=>3600*24))) {
     $pages = new Pages();
     $data = [];
     $data['helper']['tree'] = ModuleHelper::model()->getTree();
     $data['helper']['list'] = ModuleHelper::model()->getList();
     $data['tree'] = $pages->getTreePages2(true);
     // $pages->getTreePages(NULL,$data['tree'],true);
     $data['pages'] = $pages;
     $data['doc_id'] = $this->get_id(Yii::app()->request->pathInfo, $data['tree']);
     //        echo '<pre>';
     //        var_dump($data['tree']);
     //        die;
     $data['doc_id_top'] = $this->get_id(Yii::app()->request->pathInfo, $data['tree'], 1);
     $data['doc_id_last'] = $this->get_id(Yii::app()->request->pathInfo, $data['tree'], -1);
     $data['page_images'] = $pages->get_images($data['doc_id_last']);
     $data['content'] = trim($pages->getPageText($data['doc_id_last']));
     $data['title'] = trim($pages->getPageNameById($data['doc_id_last']));
     $data['longtitle'] = trim($pages->findByPk($data['doc_id_last'])->title);
     if (empty($data['longtitle'])) {
         $data['longtitle'] = $data['title'];
     }
     $data['short'] = trim($pages->findByPk($data['doc_id_last'])->short);
     $data['code'] = trim($pages->findByPk($data['doc_id_last'])->code);
     $data['meta_keywords'] = trim($pages->findByPk($data['doc_id_last'])->meta_keywords);
     $data['meta_description'] = trim($pages->findByPk($data['doc_id_last'])->meta_description);
     $data['breadcrumbs'] = $this->breadcrumbs($data['doc_id'], $data['doc_id_last']);
     if (empty($data['meta_keywords'])) {
         $data['meta_keywords'] = trim($pages->findByPk(1)->meta_keywords);
     }
     if (empty($data['meta_description'])) {
         $data['meta_description'] = trim($pages->findByPk(1)->meta_description);
     }
     $data['url_for_menu'] = Yii::app()->request->pathInfo;
     // следующая/предыдущая страница
     $data['doc_id_next'] = $this->get_id(Yii::app()->request->pathInfo, $data['tree'], 0, 'next');
     $data['doc_id_prev'] = $this->get_id(Yii::app()->request->pathInfo, $data['tree'], 0, 'prev');
     $data['additional_main_data'] = ModuleFields::model()->getValueListByPageId(1);
     // привязка форм
     switch ($data['doc_id']) {
         /*case '2':
         		$data['include'] = array('forms/purchase');
         		$data['include_title'] = '';
         		break;*/
         default:
             $data['include'] = [];
             break;
     }
     $hidden_pages = [];
     $pages_id_records_templates = ['lenta_files_category' => [], 'lenta_records_simple' => [], 'lenta_records' => [], 'magazine' => [], 'consult' => []];
     $pages_id_redirect_to_next_level = [];
     $pages_id_not_redirect_to_next_level = [25, 13];
     if ($data['doc_id'] == 27) {
         if ($_POST['type'] == 'vacancy') {
             if (isset($_FILES['file']) && !empty($_FILES['file']['tmp_name'])) {
                 $filepath = [$_FILES['file']['tmp_name']];
                 $filename = [$_FILES['file']['name']];
                 $subject = 'Резюме с сайта «Экопромбанк»';
                 $message = '<p>Новое резюме с сайта «Экопромбанка» на должность «' . $_POST['title'] . '»</p>';
                 $this->emails = Settings::model()->getMail2();
                 $out = $this->sending($subject, [], $filepath, $filename, $message);
                 $this->emails = '';
                 if ($out == 0) {
                     Yii::app()->user->setFlash('message', '<p class="success"><strong>Спасибо Вам! Мы рассмотрим резюме и свяжемся с Вами в ближайшее время!</strong></p>');
                 } else {
                     Yii::app()->user->setFlash('message', '<p class="success" style="color:red;"><strong>К сожаленью произошла ошибка. Попробуйте отправить резюме позже или свяжитесь с нами по телефону (342) 200-79-77.</strong></p>');
                     Yii::app()->user->setFlash('error', '1');
                 }
             } else {
                 Yii::app()->user->setFlash('message', '<p class="success" style="color:red;"><strong>Необходимо прикрепить файл.</strong></p>');
                 Yii::app()->user->setFlash('error', '1');
             }
             Yii::app()->user->setFlash('form_id', $_POST['form_id']);
             $this->redirect('/' . Yii::app()->request->pathInfo . '/#vform_' . $_POST['form_id']);
         }
     }
     // $this->cookie_basket($data);
     if (empty(Yii::app()->request->pathInfo)) {
         /*$login = $this->login();
         		if((count($login)>0 && empty($login['error'])) || !empty(Yii::app()->user->id)){
         			if(empty(Yii::app()->request->pathInfo)) $this->redirect('/state/');
         			$this->redirect('/'.Yii::app()->request->pathInfo.'/');
         		}
         		$data['error'] = $login['error'];
         		$data['username'] = $login['username'];
         		$data['password'] = $login['password'];*/
         $data['doc_id'] = 1;
         $data['doc_id_top'] = 1;
         $data['doc_id_last'] = 1;
         $data['content'] = trim($pages->getPageText($data['doc_id_last']));
         $data['title'] = trim($pages->getPageNameById($data['doc_id_last']));
         $data['short'] = trim($pages->findByPk($data['doc_id_last'])->short);
         $data['code'] = 'index';
         $data['news_common_doc_id'] = 65;
         $data['news_common_list'] = ModuleNews::model()->getList(ModulesInPages::model()->getLink($data['news_common_doc_id'], 'news'), 0, 5, 1);
         $this->render('index', $data);
     } else {
         $active_modules = Modules::model()->getActiveModule($data['doc_id_last']);
         if (count($active_modules)) {
             if (count($active_modules) == 2 && array_key_exists(6, $active_modules) && array_key_exists(9, $active_modules)) {
                 $this->moduleList3($data);
             } else {
                 foreach ($active_modules as $a_id => $a) {
                     /*if($a['code']!='news'){
                     			$data['news_common_doc_id'] = 6;
                     			$data['news_common_list'] = ModuleNews::model()->getList(ModulesInPages::model()->getLink($data['news_common_doc_id'],'news'),0,1,1);
                     			$data['list2_common_doc_id'] = 6;
                     			$data['list2_common_list'] = ModuleList2::model()->getList(ModulesInPages::model()->getLink($data['list2_common_doc_id'],'list2'),0,1,1);
                     		}*/
                     switch ($a['code']) {
                         /*case 'catalog':
                         		$this->moduleCatalog($data);
                         		break;*/
                         case 'news':
                             $this->moduleNews($data);
                             break 2;
                         case 'list':
                             $this->moduleList($data);
                             break 2;
                         case 'list2':
                             $this->moduleList2($data);
                             break 2;
                         case 'list3':
                             $this->moduleList3($data);
                             break 2;
                         case 'mfiles':
                             $this->moduleMfiles($data);
                             break 2;
                         case 'ymaps':
                             $this->moduleYmaps($data);
                             break 2;
                             /*case 'complaint_book':
                             			$this->moduleComplaint_book($data);
                             			break;
                             		case 'fields':
                             			$this->moduleFields($data);
                             			break;
                             		case 'flats':
                             			$this->moduleFlats($data);
                             			break;
                             		case 'questions':
                             			$this->moduleQuestions($data);
                             			break;*/
                         /*case 'complaint_book':
                         			$this->moduleComplaint_book($data);
                         			break;
                         		case 'fields':
                         			$this->moduleFields($data);
                         			break;
                         		case 'flats':
                         			$this->moduleFlats($data);
                         			break;
                         		case 'questions':
                         			$this->moduleQuestions($data);
                         			break;*/
                         default:
                             //$this->actionError();
                             $active_modules = [];
                             break;
                     }
                 }
             }
         }
         if (count($active_modules) == 0) {
             /*echo $data['doc_id'];
               die;*/
             /*
             $data['news_common_doc_id'] = 6;
             $data['news_common_list'] = ModuleNews::model()->getList(ModulesInPages::model()->getLink($data['news_common_doc_id'],'news'),0,1,1);
             $data['list2_common_doc_id'] = 6;
             $data['list2_common_list'] = ModuleList2::model()->getList(ModulesInPages::model()->getLink($data['list2_common_doc_id'],'list2'),0,1,1);
             */
             switch ($data['doc_id_last']) {
                 default:
                     switch ($data['doc_id']) {
                         case 0:
                             $this->actionError();
                             break;
                         case 12:
                             $this->render('safe', $data);
                             break;
                         case 23:
                             $this->render('safe', $data);
                             break;
                         case 39:
                             $this->moduleCardSelect($data);
                             break;
                         case 49:
                             $this->render('perevod', $data);
                             break;
                         case 77:
                             $this->render('exchange', $data);
                             break;
                         case 26:
                             // $mpage_id = ModulesInPages::model()->getLink($data['doc_id_last'],'ymaps');
                             // $mpage_id = ModulesInPages::model()->getLink(26,'ymaps');
                             // $data['list'] = ModuleYmapsCategories::model()->getList($mpage_id,0,0,1,true);
                             $cache_hash = md5('data#atms_list');
                             $data['list'] = Yii::app()->cache->get($cache_hash);
                             if ($data['list'] === false) {
                                 $data['list'] = [];
                                 $i = 0;
                                 foreach ([100 => 256, 101 => 281, 102 => 286] as $page_id => $category_param_id) {
                                     $i++;
                                     $mpage_id = ModulesInPages::model()->getLink($page_id, 'list4');
                                     $object = [];
                                     $object['title'] = Pages::model()->findByPk($page_id)->name;
                                     $object['points'] = '';
                                     $object = (object) $object;
                                     $object->points = ModuleList4::model()->getList($mpage_id, 0, 0, 1);
                                     foreach ($object->points as $key => $value) {
                                         $item = ModuleList4::model()->getList4($key, $mpage_id, 2);
                                         if (count($item['params'][$category_param_id]['values'])) {
                                             $new_params = $item['params'][$category_param_id]['values'][0]['value']['params'];
                                             $array = [];
                                             foreach ($new_params as $k => $v) {
                                                 $array[$v['code']] = ['id' => $v['id'], 'title' => $v['title'], 'data_type_id' => $v['data_type_id'], 'value' => '', 'value_id' => ''];
                                                 if (isset($v['values'][0]['value'])) {
                                                     $array[$v['code']]['value'] = $v['values'][0]['value'];
                                                 }
                                                 if (isset($v['values'][0]['value_id'])) {
                                                     $array[$v['code']]['value_id'] = $v['values'][0]['value_id'];
                                                 }
                                             }
                                             $params = $value->params;
                                             $object->points[$key]->params = $params + $array;
                                             // echo '<pre>';
                                             // var_dump($new_params);
                                             // var_dump($object->points[$key]->params);
                                             // echo '</pre>';
                                             // die;
                                         }
                                         foreach ($object->points[$key]->params as $k => $v) {
                                             $object->points[$key]->params[$k] = (object) $v;
                                         }
                                     }
                                     $data['list'][$i] = $object;
                                 }
                                 Yii::app()->cache->set($cache_hash, $data['list'], 3600 * 24 * 30);
                             }
                             $this->render('atms', $data);
                             break;
                         default:
                             if (!in_array($data['doc_id'], $pages_id_not_redirect_to_next_level)) {
                                 $temp_array = [];
                                 $temp_array = $pages->getTreePages($data['doc_id'], $temp_array);
                                 foreach ($temp_array as $id => $t) {
                                     break;
                                 }
                                 if (count($temp_array) > 0) {
                                     $this->redirect($pages->make_url($id));
                                 }
                             }
                             if (!in_array(Yii::app()->request->pathInfo, $hidden_pages)) {
                                 $this->render('list', $data);
                             } else {
                                 Yii::app()->runController('main/' . Yii::app()->request->pathInfo);
                             }
                             break;
                     }
                     break;
             }
         }
     }
     //	$this->endCache();
     //}
 }