Example #1
0
 public function get_response()
 {
     $this->template = View::factory('base');
     $config = Kohana::$config->load('main')->site;
     $base = new Model_Base();
     $options = $base->getOptions();
     $this->template->styles = $config['styles'];
     $this->template->styles[] = 'css/menu.css';
     $this->template->scripts = $config['scripts'];
     $this->template->scripts[] = 'js/errors.js';
     $this->template->title = 'Ошибка 404 - Страница не найдена';
     $this->template->description = $options['description'];
     $this->template->keywords = $options['keywords'];
     $this->template->page_title = null;
     $header = View::factory('header');
     $footer = View::factory('footer');
     $this->template->header = $header;
     $this->template->footer = $footer;
     $this->template->for_cart = null;
     $this->template->top_menu = array(Request::factory('widgets/menu/index/4')->execute());
     $this->template->left_menu = null;
     $this->template->block_left = null;
     $this->template->block_right = null;
     $this->template->pathway = null;
     $this->message = '<h1>Упс! Ошибка 404.</h1><br><p>Запрашиваемая страница не найдена. Скорее всего она была перемещена или удалена.</p>';
     // Remembering that `$this` is an instance of HTTP_Exception_404
     //проверка редиректов
     $gid = 34;
     $materials = new Model_Material('group');
     $redirects = $materials->getMaterials($gid, 1000, 0);
     $url = Request::detect_uri();
     foreach ($redirects as $redirect) {
         if ($redirect['name'] == Kohana::$base_url . substr($url, 1)) {
             $fields = $materials->getFields2($redirect['id'], TRUE);
             $this->redirect = $fields['to'];
         }
     }
     if (Kohana::$environment === Kohana::PRODUCTION) {
         $view = View::factory('errors/404')->set('message', $this->message)->set('redirect', $this->redirect)->render();
     } else {
         $view = View::factory('errors/404')->set('message', $this->message)->render();
     }
     $this->template->block_center = array($view);
     $response = Response::factory()->status(404)->body($this->template->render());
     return $response;
 }
Example #2
0
 public function action_index()
 {
     $data = array();
     $id = $this->request->param('id');
     $emails = new Model_Email();
     $material = new Model_Material('group');
     if (isset($_POST['send'])) {
         $fields = $material->getFields2($_POST['template'], TRUE);
         //отправляем письмо
         $config = Kohana::$config->load('email');
         Email::connect($config);
         $subject = Arr::get($fields, 'title');
         $from = $config['options']['username'];
         $message = Arr::get($fields, 'text');
         //генерируем уникальный разделитель
         $bound = "--" . md5(uniqid(time()));
         foreach ($_POST['check_name'] as $subscriberId) {
             $subscriber = $emails->getSubscriber($subscriberId);
             $message = str_replace('@#subscriber#@', $subscriber['name'], $message);
             $subject = str_replace('@#subscriber#@', $subscriber['name'], $subject);
             $message = str_replace('@#site#@', Kohana::$base_url, $message);
             $mail_header = "MIME-Version: 1.0;\r\n";
             $mail_header .= "Content-Type: multipart/mixed; boundary=\"{$bound}\"\r\n";
             $mail_header .= "Отправитель: <" . $from . ">\r\n";
             $mail_header .= "Для ответа <" . $from . ">\r\n";
             $mail_header .= "Subject: {$subject} \n";
             //прикрепляем файл
             //путь к файлу
             $file_path = DOCROOT . '/img/user/novost-1_859f1ca6ad9b29c3475.png';
             //если файл найден, прикрепляем его к сообщению
             if (file_exists($file_path)) {
                 $file_name = basename($file_path);
                 $fa = fopen($file_path, "rb");
                 if ($fa) {
                     $multipart_message = "\r\n--{$bound}\r\n";
                     $multipart_message .= "Content-Type: text/html; charset=UTF-8\r\n";
                     $multipart_message .= "Content-Transfer-Encoding: base64\r\n";
                     $multipart_message .= "\r\n";
                     $multipart_message .= chunk_split(base64_encode($message));
                     $multipart_message .= "\r\n\r\n--{$bound}\r\n";
                     $multipart_message .= "Content-Type: application/octet-stream; name=\"{$file_name}\"\r\n";
                     $multipart_message .= "Content-Transfer-Encoding: base64\r\n";
                     $multipart_message .= "Content-Disposition: attachment; filename=\"{$file_name}\"\r\n";
                     $multipart_message .= "\r\n";
                     $multipart_message .= chunk_split(base64_encode(fread($fa, filesize($file_path))));
                     fclose($fa);
                     //передаем текст сообщения и прикрепленный файл в переменную
                     $message = $multipart_message;
                 } else {
                     $message = $message;
                 }
             } else {
                 //если файл не существует передаем текстовое сообщение
                 $message = $message;
             }
             //   var_dump($message);
             try {
                 if (mail($subscriber['email'], $subject, $message, $mail_header)) {
                     //                    if(Email::send($subscriber['email'], $from, $subject, $message, $html = TRUE))
                     $this->messages[] = 'Успешная отправка на ' . $subscriber['email'];
                 } else {
                     $this->errors[] = 'Ошибка отправки на ' . $subscriber['email'];
                 }
             } catch (Exception $e) {
                 $this->errors[] = 'Ошибка отправки на ' . $subscriber['email'];
             }
         }
     }
     if ($id == NULL) {
         $this->templates = $material->getMaterials(59, 100, 0, '', array(), array('text'));
         $data['emails'] = $emails->getEmails();
     }
     $this->template->content = View::factory('admin/admEmails', array('data' => $data, 'user' => $this->user, 'templates' => $this->templates, 'errors' => $this->errors, 'messages' => $this->messages));
 }
Example #3
0
 public function before()
 {
     // Выполняем функцию родительского класса
     parent::before();
     $base = new Model_Base();
     $config = Kohana::$config->load('main')->site;
     $positions = Kohana::$config->load('main')->positions;
     $options = $base->getOptions();
     $auth = Auth::instance();
     if (isset($options['work']) && $options['work'] == 'TRUE' && $auth->logged_in('admin') == 0) {
         $this->template = View::factory('cap');
     }
     $this->template->title = $options['title'];
     $this->template->description = $options['description'];
     $this->template->keywords = $options['keywords'];
     $this->template->page_title = null;
     $this->template->links = array();
     // $cart = Request::factory("widgets/");
     $header = Request::factory('widgets/header/index')->execute();
     // ->bind('cart', $cart);
     $footer = Request::factory('widgets/footer/index')->execute();
     foreach ($positions as $key => $value) {
         $this->template->{$key} = $value;
     }
     $this->template->header = $header;
     $this->template->footer = $footer;
     if (isset($_GET['login'])) {
         //активируем пользователя
         $vData = $_GET;
         $validation = Validation::factory($vData);
         $validation->rule('username', 'not_empty');
         $validation->rule('username', 'min_length', array(':value', '2'));
         $validation->rule('username', 'max_length', array(':value', '250'));
         $validation->rule('password', 'not_empty');
         $validation->rule('password', 'min_length', array(':value', '6'));
         $validation->rule('password', 'max_length', array(':value', '50'));
         if (!$validation->check()) {
             $errors[] = $validation->errors('registrationErrors');
         } else {
             $auth = Auth::instance();
             $username = Arr::get($_GET, 'username', '');
             $password = Arr::get($_GET, 'password', '');
             if ($auth->login($username, $password)) {
                 Controller::redirect('/user');
             } else {
                 $errors[] = 'Не верный логин или пароль.';
             }
         }
     }
     if (isset($_GET['site_version'])) {
         if ($_GET['site_version'] == 'standart') {
             Cookie::set('site_version', 'standart');
         } else {
             Cookie::set('site_version', 'adaptive');
         }
     }
     $site_version = Cookie::get('site_version', 'adaptive');
     //проверка редиректов
     $gid = 46;
     $materials = new Model_Material('group');
     $redirects = $materials->getMaterials($gid, 1000, 0);
     $url = Request::detect_uri();
     foreach ($redirects as $redirect) {
         if ($redirect['name'] == DIRECTORY_SEPARATOR . substr($url, 1)) {
             $fields = $materials->getFields2($redirect['id'], TRUE);
             Controller::redirect(Kohana::$base_url . substr($fields['to'], 1), 301);
         }
     }
     $auth = Request::factory('widgets/auth/')->execute();
     $this->template->site_version = $site_version;
     $this->template->auth = $auth;
     $this->template->styles = array();
     $this->template->scripts = $config['scripts'];
 }
Example #4
0
 public function action_index()
 {
     $group = new Model_Material('groups');
     $pagination = '';
     $folders = $this->getFolders();
     //Добавление группы
     if (isset($_POST['add_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $parentId = Arr::get($_POST, 'parentId', '');
         $previousId = Arr::get($_POST, 'previousId', '');
         $res = $group->groupInsert($parentId, $previousId, array('name' => $groupName));
         if ($res) {
             Controller::redirect('admin/materials');
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Редактирование группы
     if (isset($_POST['save_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $groupKeywords = Arr::get($_POST, 'groupKeywords', '');
         $groupDescription = Arr::get($_POST, 'groupDescription', '');
         $id = $this->request->param('id');
         $res = $group->groupUpdate($id, array('name' => $groupName, 'keywords' => $groupKeywords, 'description' => $groupDescription));
         if ($res) {
             Controller::redirect('admin/materials/' . $id);
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Добавление поля группы
     if (isset($_POST['add_field'])) {
         $groupId = $this->request->param('id');
         $paramTitle = Arr::get($_POST, 'field_title', '');
         $paramName = Arr::get($_POST, 'field_name', '');
         $paramType = Arr::get($_POST, 'field_type', '');
         $previousPos = Arr::get($_POST, 'previousPos', '0');
         $addToChildren = Arr::get($_POST, 'add_to_children', '');
         $ordering = $previousPos + 1;
         $param_data = array('gid' => $groupId, 'name' => $paramName, 'title' => $paramTitle, 'type' => $paramType, 'ordering' => $ordering);
         if ($addToChildren) {
             $parent_data = $group->getGroup($groupId);
             $children_groups = DB::select()->from('groups')->where('left_key', '>', $parent_data['left_key'])->and_where('right_key', '<', $parent_data['right_key'])->execute();
             foreach ($children_groups as $group_data) {
                 $param_data["gid"] = $group_data["id"];
                 $result = $group->addParam($param_data);
                 if (!$result) {
                     $data['groupErrors'] = $group->getErrors();
                 }
             }
         }
         $param_data["gid"] = $groupId;
         $result = $group->addParam($param_data);
         if (!$result) {
             $data['groupErrors'] = $group->getErrors();
         }
     }
     if (isset($_POST['change_group'])) {
         $groupId = $this->request->param('id');
         $newGroup = Arr::get($_POST, 'new_group', '0');
         $ids = Arr::get($_POST, 'check_name', NULL);
         if (!empty($ids)) {
             $result = $group->changeGroup($groupId, $newGroup, $ids);
         }
     }
     if (isset($_POST['save_selects'])) {
         $selects = new Model_Params_Selects();
         $values = $_POST;
         unset($values['save_selects']);
         $selects->saveSelectsValues($values, $_POST['save_selects']);
     }
     if (isset($_POST['sort_fields'])) {
         $groupId = $this->request->param('id');
         $group->sortParams($_POST['params'], $groupId);
     }
     if (isset($_POST['save_param'])) {
         $selects = new Model_Selects();
         $values = $_POST;
         unset($values['save_param']);
         $selects->saveSelectsParam($values, $_POST['save_param'], $_FILES);
     }
     //Загрузка из Excell
     if (isset($_POST['load_xls'])) {
         $groupId = $this->request->param('id');
         $excel = new Model_Excel();
         //  $file = DOCROOT . '/upload/task/file.xlsx';
         //  $load = $excel->load_xls($file, 602, 11, 20);
         $load = $excel->load_xls($_FILES, $groupId);
     }
     if (isset($_GET['exportExcel'])) {
         $excel = new Model_Excel();
         $res = $excel->uploadFile($_GET['exportExcel']);
         if ($res) {
             $data['messages'] = $res;
         }
     }
     if (isset($_POST['delete_fields'])) {
         $groupId = $this->request->param('id');
         $paramId = Arr::get($_POST, 'pid', '');
         $result = $group->deleteParams($paramId);
     }
     //удаление отмеченных материалов
     if (isset($_POST['checked_del'])) {
         $gid = $this->request->param('id');
         $delArr = Arr::get($_POST, 'check_name', array());
         $group = new Model_Material('groups');
         foreach ($delArr as $del) {
             $group->deleteMaterial($del, $gid);
         }
     }
     //if(isset())
     $groupId = $this->request->param('id');
     $pageNum = str_replace('page', '', $this->request->param('page'));
     if ($groupId != NULL && $groupId != 'cart') {
         $data['thisGroup'] = $group->getGroup($groupId);
         $data['groupParams'] = $group->getParams($groupId);
         $data['admfields'] = $group->getAdminFields($groupId, TRUE);
         if (!$this->request->param('url')) {
             $q = Arr::get($_GET, 'q', '');
             $countMaterials = $group->getCountAdmMaterials($groupId, $q);
             $pagination = Pagination::factory(array('total_items' => $countMaterials, 'items_per_page' => 100, 'view' => 'pagination/basic2'));
             $pagination->current_page = intval($pageNum);
             if (isset($_GET['sort']) && $_GET['sort'] != '') {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q, array($_GET['sort']));
             } else {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q);
             }
         } else {
             if (isset($_POST['save_material'])) {
                 $res = $group->saveMaterial($_POST, $_FILES);
                 if ($res) {
                     Controller::redirect('admin/materials/' . $groupId);
                 } else {
                     $data['errors'] = $group->getErrors();
                 }
             }
             //Данные материала
             $materialId = $group->getMaterialIdByUrl($this->request->param('url'), $groupId);
             $data['material'] = $group->getAdminMaterial($materialId);
             //                    //комментарии
             $comments['data'] = $group->getComments($materialId, FALSE);
             //комментарии
             //$docs['data'] = $group->getDocs($materialId);
             //Поля
             $fieldset = array();
             $fields = $group->getFields2($data['material']['id']);
             foreach ($fields as $field) {
                 //генерируем код для каждого поля
                 //если поле - список выбора
                 if ($field['type'] == 'select') {
                     $values = $group->getSelectValues($field['id']);
                     $field['myValues'] = $values;
                 }
                 if ($field['type'] == 'photoalbum') {
                     $base = new Model_Base();
                     $options = $base->getOptions();
                     $field['photos_base_path'] = $options['photos_base_path'];
                 }
                 if ($field['type'] == 'files') {
                     $base = new Model_Base();
                     $options = $base->getOptions();
                     $field['files_base_path'] = $options['files_base_path'];
                 }
                 $fieldset[] = View::factory('admin/fields/' . $field['type'])->bind('data', $field)->bind('multiselect', $field['multiselect'])->bind('folders', $folders)->bind('user', $this->user)->render();
             }
             $data['fields'] = $fieldset;
         }
     } elseif ($groupId == 'cart') {
         $data['items'] = $group->getMaterials($groupId);
         $data['is_cart'] = TRUE;
     }
     $data['groups'] = $group->getTree();
     //
     $wpm['status'] = Cookie::get('wpm', FALSE);
     $wpm['folder'] = Cookie::get('wpm_folder', '');
     $pictures = $this->action_pictures($wpm['folder']);
     //$comments['status'] = Cookie::get('comments', FALSE);
     // $docs['status'] = Cookie::get('comments', FALSE);
     $this->template->content = View::factory('admin/admMaterials', array('data' => $data, 'folders' => $folders, 'pictures' => $pictures, 'wpm' => $wpm, 'user' => $this->user, 'pagination' => $pagination));
     //$this->template->content = View::factory('admin/admMaterials', array('data'=> $data, 'user' => $this->user, 'pagination' => $pagination, 'comments' => $comments));
 }
Example #5
0
 public function action_index()
 {
     $group = new Model_Material('groups');
     $pagination = '';
     //Добавление группы
     if (isset($_POST['add_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $parentId = Arr::get($_POST, 'parentId', '');
         $previousId = Arr::get($_POST, 'previousId', '');
         $res = $group->groupInsert($parentId, $previousId, array('name' => $groupName));
         if ($res) {
             Controller::redirect('admin/materials');
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Редактирование группы
     if (isset($_POST['save_group'])) {
         $groupName = Arr::get($_POST, 'groupName', '');
         $groupKeywords = Arr::get($_POST, 'groupKeywords', '');
         $groupDescription = Arr::get($_POST, 'groupDescription', '');
         $id = $this->request->param('id');
         $res = $group->groupUpdate($id, array('name' => $groupName, 'keywords' => $groupKeywords, 'description' => $groupDescription));
         if ($res) {
             Controller::redirect('admin/materials/' . $id);
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     //Добавление поля группы
     if (isset($_POST['add_field'])) {
         $groupId = $this->request->param('id');
         $paramTitle = Arr::get($_POST, 'field_title', '');
         $paramName = Arr::get($_POST, 'field_name', '');
         $paramType = Arr::get($_POST, 'field_type', '');
         $previousPos = Arr::get($_POST, 'previousPos', '0');
         $ordering = $previousPos + 1;
         $result = $group->addParam(array('gid' => $groupId, 'name' => $paramName, 'title' => $paramTitle, 'type' => $paramType, 'ordering' => $ordering));
         if (!$result) {
             $data['groupErrors'] = $group->getErrors();
         }
     }
     if (isset($_POST['change_group'])) {
         $oldGroup = Arr::get($_POST, 'old_group', '0');
         $newGroup = Arr::get($_POST, 'new_group', '0');
         $ids = Arr::get($_POST, 'check_name', NULL);
         $result = $group->changeGroup($oldGroup, $newGroup, $ids);
     }
     //Загрузка из Excell
     if (isset($_POST['load_xls'])) {
         $groupId = $this->request->param('id');
         $excel = new Model_Excel();
         $load = $excel->load_xls($_FILES, $groupId);
     }
     if (isset($_POST['delete_fields'])) {
         $groupId = $this->request->param('id');
         $paramId = Arr::get($_POST, 'pid', '');
         $result = $group->deleteParams($paramId);
     }
     //удаление отмеченных материалов
     if (isset($_POST['checked_del'])) {
         $gid = $this->request->param('id');
         $delArr = Arr::get($_POST, 'check_name', array());
         $group = new Model_Material('groups');
         foreach ($delArr as $del) {
             $group->deleteMaterial($del, $gid);
         }
     }
     //if(isset())
     $groupId = $this->request->param('id');
     $pageNum = str_replace('page', '', $this->request->param('page'));
     if ($groupId != NULL && $groupId != 'cart') {
         $data['thisGroup'] = $group->getGroup($groupId);
         $data['groupParams'] = $group->getParams($groupId);
         if (!$this->request->param('url')) {
             $q = Arr::get($_GET, 'q', '');
             $countMaterials = $group->getCountAdmMaterials($groupId, $q);
             $pagination = Pagination::factory(array('total_items' => $countMaterials));
             $pagination->current_page = $pageNum;
             if (isset($_GET['sort'])) {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q, array($_GET['sort']));
             } else {
                 $data['items'] = $group->getMaterials($groupId, $pagination->items_per_page, $pagination->offset, $q);
             }
         } else {
             if (isset($_POST['save_material'])) {
                 $res = $group->saveMaterial($_POST, $_FILES);
                 if ($res) {
                     Controller::redirect('admin/materials/' . $groupId);
                 } else {
                     $data['errors'] = $group->getErrors();
                 }
             }
             //Данные материала
             $materialId = $group->getMaterialIdByUrl($this->request->param('url'));
             $data['material'] = $group->getAdminMaterial($materialId);
             //комментарии
             $comments['data'] = $group->getComments($materialId, FALSE);
             //Поля
             $fieldset = array();
             $fields = $group->getFields2($data['material']['id']);
             foreach ($fields as $field) {
                 //генерируем код для каждого поля
                 //если поле - список выбора
                 if ($field['type'] == 'select') {
                     $values = $group->getSelectValues($field['id']);
                     $field['myValues'] = $values;
                 }
                 $fieldset[] = View::factory('admin/fields/' . $field['type'])->bind('data', $field)->render();
             }
             $data['fields'] = $fieldset;
         }
     } elseif ($groupId == 'cart') {
         $data['items'] = $group->getMaterials($groupId);
         $data['is_cart'] = TRUE;
     }
     $data['groups'] = $group->getTree();
     //
     $wpm['status'] = Cookie::get('wpm', FALSE);
     $wpm['folder'] = Cookie::get('wpm_folder', '');
     $folders = $this->getFolders();
     $pictures = $this->action_pictures($wpm['folder']);
     $comments['status'] = Cookie::get('comments', FALSE);
     $this->template->content = View::factory('admin/admMaterials', array('data' => $data, 'folders' => $folders, 'pictures' => $pictures, 'wpm' => $wpm, 'user' => $this->user, 'pagination' => $pagination));
     // $this->template->content = View::factory('admin/admMaterials', array('data'=> $data, 'user' => $this->user, 'pagination' => $pagination, 'comments' => $comments, 'pictures' => $pictures, 'wpm' => $wpm, ));
 }