public function action_index() { $materialId = $this->request->param('id'); $materials = new Model_Material('groups'); //получить содержимое папки $data = $materials->getMaterial($materialId); $fields = $materials->getFields2($materialId, TRUE); $model = array("photos" => array()); $model["id"] = Arr::get($data, "id"); $model["name"] = Arr::get($data, "name"); $model["article"] = Arr::get($data, "art"); $model["price"] = number_format(Arr::get($fields, 'price'), 0, "", " "); Resources::add_scripts(array("js/modules/material/material.js"), get_class()); // --- Фотки ---------------------------------------------------- // есть фото if (isset($fields["photos"][0])) { $photos = $fields["photos"]; $model["general_photo"] = $photos[0]["value"]; // Фоток больше 1 if (count($photos) > 1) { foreach ($photos as $photo) { $model["photos"][] = array("original" => $photo["value"], "mini" => Route::url("miniimg2", array("filename" => $photo["value"]))); } } } else { $model["general_photo"] = "/img/noimg.png"; } // --- /Фотки ---------------------------------------------------- // --- Коментарии ------------------------------------------------ echo '<script>window.material_id = JSON.parse(\'' . $materialId . '\');</script>'; $this->load_module("comments", "/widgets/Comments/index"); // --- /Коментарии ----------------------------------------------- $this->set_template("/widgets/material/material.php", "twig")->render($model)->body(); }
public function action_index() { $errors = array(); $materialId = $this->request->param('id'); $materials = new Model_Material('group'); //смотрим шаблон для виджета $widget = new Model_Widget(); $template = $widget->getTempalte('polls', $materialId); if ($template) { $this->template = View::factory('widgets/' . $template); } $name = 'polls_' . $materialId; $voted = FALSE; //Cookie::delete($name); if (Cookie::get($name)) { $voted = TRUE; } else { if (isset($_POST['save_polls'])) { $polls = new Model_Polls(); //сохраняем результаты голосования $result = $polls->vote($_POST['save_polls'], $_POST['answer']); if ($result) { //создаем куки по данному опросу if (!Cookie::set($name, 'voted', Date::YEAR)) { $errors[] = 'Вероятно в Вашем браузере отключены Cookie.'; } else { $voted = TRUE; } } } } $data = $materials->getMaterial($materialId); $fields = $materials->getFields2($materialId, TRUE); $fields2 = $materials->getFields2($materialId, FALSE); $this->template->data = $data; $this->template->fields = $fields; $this->template->fields2 = $fields2; $this->template->voted = $voted; //Получаем список меню }
public function action_index() { $materialId = $this->request->param('id'); $materials = new Model_Material('groups'); //get widget template $widget = new Model_Widget(); $template = $widget->getTempalte('files', $materialId); if ($template) { $this->template = View::factory('widgets/' . $template); } //get data $data = $materials->getMaterial($materialId); $fields = $materials->getFields2($materialId, TRUE); $this->template->material = $data; $this->template->fields = $fields; }
public function action_index() { $materialId = $this->request->param('id'); $materials = new Model_Material('groups'); //получить содержимое папки $data = $materials->getMaterial($materialId); $fields = $materials->getFields2($materialId, TRUE); //смотрим шаблон для виджета $widget = new Model_Widget(); $template = $widget->getTempalte('material', $materialId); if ($template) { $this->template = View::factory('widgets/' . $template); } $group = $materials->getGroup($materials->getGroupFromMid($materialId)); if ($group['name'] == 'Новости') { $this->template = View::factory('widgets/w_news_item'); $this->template->breadcrumbs = Request::factory('widgets/breadcrumb/index/')->execute(); } // if($group['name']=='Диспенсеры') // { // if(isset($fields['type'][0])) // { // $uri = Request::detect_uri(); // $dirs = explode('/', $uri); // array_pop($dirs); // $categoryName = array_pop($dirs); // // $category = new Model_Category('tree'); // $categoryId = $category->getCategoryIdByUrl($categoryName); // // $GLOBALS['categoryId'] = $categoryId; // // $dopdata = $materials->getFullMaterials2($group['id'], 5, 0, NULL, array('type' => array($fields['type'][0]['value']))); // unset($dopdata[$materialId]); // // $this->template->dopdata = array_slice($dopdata, 0, 4); // } // } //получаем комментарии $comments = Request::factory('widgets/comments/index/' . $materialId)->execute(); $callback_form = Request::factory('widgets/callback/index/')->execute(); $this->template->callback = $callback_form; $this->template->material = $data; $this->template->fields = $fields; $this->template->comments = $comments; }
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; }
public function vote($materialId, $ansver) { $ansverId = trim(str_replace('Вариант', '', $ansver)); $materials = new Model_Material('group'); $fields = $materials->getFields2($materialId); foreach ($fields as $field) { if ($field['title'] == 'Ответов ' . $ansverId) { //получаем значение $query = 'SELECT b.* FROM group_param_values a, ' . $field['type'] . ' b WHERE a.mid =' . $materialId . ' AND a.pid =' . $field['id'] . ' AND a.value = b.id'; $res = DB::query(Database::SELECT, $query)->execute()->current(); $cnt = intval($res['value']) + 1; $query = 'UPDATE ' . $field['type'] . ' SET value = ' . $cnt . ' WHERE id =' . $res['id']; $res = DB::query(Database::UPDATE, $query)->execute(); if ($res) { return TRUE; } } } }
public function action_catalog() { $materials = new Model_Material('groups'); //получаем url материала $materialID = $this->request->param('id'); $material = $materials->getMaterial($materialID); $fields = $materials->getFields2($materialID, TRUE); $this->template->title = $material['name']; $this->template->page_title = $material['name']; $this->template->keywords = $material['keywords']; $this->template->description = $material['description']; $this->template->links = array('<link rel="canonical" href="' . Kohana::$base_url . 'catalog/' . $materialID . '.html"/>'); $this->template->styles = Resources::load_styles(); if (!$material['id']) { throw new HTTP_Exception_404(); } //обновляем просмотры $materials->updateViews($material['id']); $widgets[] = Request::factory('widgets/material/index/' . $materialID)->execute(); $this->template->block_center = $widgets; }
public function send($data) { $material = new Model_Material('groups'); $fields = $material->getFields2($data['template'], TRUE); //отправляем письмо $config = Kohana::$config->load('email'); Email::connect($config); $subject = Arr::get($fields, 'title'); $from = $config['options']['username']; $message = Arr::get($fields, 'text'); $message = str_replace('@#object#@', Arr::get($data, 'object_name'), $message); $message = str_replace('@#url#@', Arr::get($data, 'object_url'), $message); //генерируем уникальный разделитель $bound = "--" . md5(uniqid(time())); foreach ($data['check_name'] as $subscriberId) { $subscriber = $this->getSubscriber($subscriberId); if ($subscriber['active'] == 1) { $message = str_replace('@#subscriber#@', $subscriber['name'], $message); $subject = str_replace('@#subscriber#@', $subscriber['name'], $subject); $message = str_replace('@#site#@', Kohana::$base_url, $message); $mymessage = str_replace('@#email#@', $subscriber['email'], $message); // $mail_header = "MIME-Version: 1.0;\r\n"; // $mail_header.= "Content-Type: multipart/mixed; boundary=\"$bound\"\r\n"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=UTF-8\r\n"; $headers .= "From: Morrismedia <" . $from . ">\r\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($mail_header); $result = mail($subscriber['email'], $subject, $mymessage, $headers); if ($result) { $this->messages[] = 'Успешная отправка на ' . $subscriber['email']; $this->updateSend($subscriber['email']); } else { $this->errors[] = 'Ошибка отправки на ' . $subscriber['email']; } // try // { // if(mail($subscriber['email'], $subject, $message, $mail_header, '*****@*****.**')) //// if(Email::send($subscriber['email'], $from, $subject, $message, $html = TRUE)) // { // $this->messages[] = 'Успешная отправка на '.$subscriber['email']; // $this->updateSend($subscriber['email']); // } // else // $this->errors[] = 'Ошибка отправки на '.$subscriber['email']; // } // catch (Exception $e) // { // $this->errors[] = 'Ошибка отправки на '.$subscriber['email']; // } } } return array('messages' => $this->messages, 'errors' => $this->errors); }
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)); }
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']; }
public function getOrder($orderId) { $order = ORM::factory("Orders")->where("id", "=", $orderId)->find()->as_array(); $items = DB::select()->from("order_materials")->where("order_id", "=", $orderId)->execute()->as_array(); $materials = new Model_Material("groups"); $catalog = new Model_Category("tree"); foreach ($items as $item) { $material = $materials->getMaterial($item["mid"]); $fields = $materials->getFields2($item["mid"], TRUE); $categoryId = $materials->getTreeIdByMid($item["mid"]); $parents = $catalog->getParents($categoryId); $node = ""; foreach ($parents as $key => $parent) { if ($parent["url"] == "glavnaya") { $node .= $parents[$key + 1]["url"] . "/"; break; } } $order["items"][$item["mid"]] = array_merge($material, $fields); $order["items"][$item["mid"]]["cnt"] = $item["cnt"]; $order["items"][$item["mid"]]["node"] = $node; } return $order; }
public function action_cart() { /* Добавление товара в корзину $data: $item_id* - id товара $item_count* - кол-во товара $order_id - id заказа */ $methods['add_item'] = function ($data) { PC::debug($data, 'add item data'); $model_orders = new Model_Orders(); $materials = new Model_Material('groups'); // Добавление товара к существующему заказу if (isset($data['order_id'])) { PC::debug(1, 1); $res = $model_orders->addGood(Arr::get($data, 'order_id'), Arr::get($data, 'item_id'), Arr::get($data, 'item_count')); } else { PC::debug(2, 1); $item_count = Arr::get($data, 'item_count'); $res = $model_orders->newOrder(Arr::get($data, 'item_id'), $item_count); $new_count = $item_count; } $material = $materials->getMaterial(Arr::get($data, 'item_id')); $fields = $materials->getFields2(Arr::get($data, 'item_id'), TRUE); $catalog = new Model_Category('tree'); $categoryId = $materials->getTreeIdByMid(Arr::get($data, 'item_id')); $parents = $catalog->getParents($categoryId); $node = ''; foreach ($parents as $parent) { if ($parent['level'] > 1 && $parent['url'] != 'glavnaya') { $node .= $parent['url'] . '/'; } } $itemdata = $model_orders->getOrderCount(Arr::get($data, 'order_id'), Arr::get($data, 'item_id')); $item[Arr::get($data, 'item_id')] = array_merge($material, $fields); if (isset($new_count)) { $item[Arr::get($data, 'item_id')]['cnt'] = $new_count; } else { $item[Arr::get($data, 'item_id')]['cnt'] = $itemdata['cnt']; } $item[Arr::get($data, 'item_id')]['node'] = $node; return array('order_id' => $res, 'item' => $item); }; /* Удаление товара из корзины $data: $order_id* - id заказа $item_id* - id товара $item_count* - кол-во товара */ $methods['del_item'] = function ($data) { $model_orders = new Model_Orders(); extract($data); // Удаление товара из корзины $res = $model_orders->deleteItem(Arr::get($data, 'order_id'), Arr::get($data, 'item_id'), Arr::get($data, 'item_count')); return $res; }; /* Получение информации о заказе $data: $order_id* - id заказа */ $mathods['get_order'] = function ($data) { $model_orders = new Model_Orders(); $order_data = $model_orders->getOrder($data['order_id']); return $order_data; }; /* Удаление заказа $data: $order_id* - id заказа */ $mathods['del_order'] = function ($data) { PC::debug($data, 'del_order'); $model_orders = new Model_Orders(); $res = $model_orders->deleteOrder($data['order_id']); return $res; }; /* Получение информации о заказе $data: $order_id* - id заказа */ $methods['get_items'] = function ($data) { $model_orders = new Model_Orders(); //extract($data); $res = $model_orders->getOrder(Arr::get($data, 'order_id', '')); return $res; }; $data = Arr::get($_POST, 'data', ''); if ($data == '') { $data = Arr::get($_GET, 'data', ''); } extract(json_decode($data, true)); $res = false; if (isset($methods[$method])) { $res = $methods[$method]($data); PC::debug($res, 'Ajax: "' . $method . '"'); } exit(json_encode($res)); }
public function action_fluid() { $this->setopt(array("name" => "material_id", "description" => "Ид статического материала", "default" => 1)); $material_id = $this->getopt('material_id'); $materials = new Model_Material('groups'); //смотрим шаблон для виджета $widget = new Model_Widget(); /* $pathway = Request::factory('widgets/breadcrumb/index') ->execute();*/ //получить содержимое папки $data = $materials->getMaterial($material_id); $fields = $materials->getFields2($material_id, true); $model = array("text" => $fields["text"]); if (isset($fields['files']) && !empty($fields['files'])) { $files = array(); foreach ($fields['files'] as $file) { $file["app_icon"] = "/img/apps_icon/" . strtolower($file['ext'] . ".png"); $file["size"] = round((int) $file['size'] / 1024); $files[] = $file; } $model["files"] = $files; } $this->set_template("widgets/static/fluid.php", "twig")->render($model)->body(); //$this->template->pathway = $pathway; //$this->template->data = array_merge($data, $fields); //$this->template->material = $data; // $this->template->fields = $fields; }
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)); }
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, )); }