示例#1
0
 public function action_index()
 {
     $base = new Model_Base();
     $pageNum = 0;
     $param = $this->request->param('id');
     $filters = $base->safeArrAssoc($_GET);
     $params = explode('/', $param);
     $gid = $params[0];
     foreach ($params as $paramName) {
         if (preg_match("/page(\\d)/", $paramName)) {
             $pageNum = str_replace('page', '', $paramName);
         }
     }
     $marker = array_pop($params);
     $catalog = new Model_Material('groups');
     //смотрим шаблон для виджета
     $widget = new Model_Widget();
     $template = $widget->getTempalte('catalog2', $gid);
     if ($template) {
         $this->template = View::factory('widgets/' . $template);
     }
     // $categoryName = $catalog->getCategoryNameByCatalog();
     //получить содержимое папки
     // $count = $catalog->getCountMaterials($param);
     $count = $catalog->getCountMaterials($gid);
     $pagination = Pagination::factory(array('total_items' => $count));
     $pagination->current_page = $pageNum;
     $data = $catalog->getFullMaterials($gid);
     $this->template->data = $data;
     $this->template->pagination = $pagination;
 }
示例#2
0
 public function action_index()
 {
     $parentId = $this->request->param('id');
     $tree = new Model_Widgets_Menu('tree');
     //смотрим шаблон для виджета
     $widget = new Model_Widget();
     $template = $widget->getTempalte('menu', $parentId);
     if ($template) {
         $this->template = View::factory('widgets/' . $template);
     }
     //Получаем список меню
     $items = $tree->menuItems($parentId);
     if (isset($_GET['del_mid'])) {
         if (Cookie::get('userId')) {
             $userId = Cookie::get('userId');
             $cart = new Model_Widgets_Cart();
             $cart->delFromCart($userId, $_GET['del_mid']);
         }
     }
     if (Cookie::get('userId')) {
         $userId = Cookie::get('userId');
         $cart = new Model_Widgets_Cart();
         $cartCount = $cart->getCartCount($userId);
         $cartPrice = $cart->getCartPrice($userId);
         $cartData = "<h5>В корзине: <font> " . $cartCount . " </font> товаров</h5>\n            <h5>на сумму:&nbsp;&nbsp; <font> " . $cartPrice . " </font> рублей</h5>";
     } else {
         $cartData = '<h5>Ваша корзина пуста</h5>';
     }
     $this->template->cartData = $cartData;
     $this->template->menu = $items;
 }
示例#3
0
 public function action_index()
 {
     $category = new Model_Category('tree');
     $data['categories'] = $category->getTree();
     if (isset($_POST['add_category'])) {
         $categoryName = Arr::get($_POST, 'categoryName', '');
         $categoryUrl = Arr::get($_POST, 'categoryUrl', '');
         $parentId = Arr::get($_POST, 'parentId', '');
         $previousId = Arr::get($_POST, 'previousId', '');
         $res = $category->catInsert($parentId, $previousId, array('name' => $categoryName, 'url' => $categoryUrl));
         if ($res) {
             Controller::redirect('admin');
         } else {
             $data['errors'] = $category->getErrors();
         }
     }
     if (isset($_POST['save_category'])) {
         $categoryName = Arr::get($_POST, 'categoryName', '');
         $categoryKeywords = Arr::get($_POST, 'categoryKeywords', '');
         $categoryDescription = Arr::get($_POST, 'categoryDescription', '');
         $url = $this->request->param('id');
         $categoryId = $category->getCategoryIdByUrl($url);
         $res = $category->catUpdate($categoryId, array('name' => $categoryName, 'keywords' => $categoryKeywords, 'description' => $categoryDescription));
         if ($res) {
             Controller::redirect('admin/' . $url);
         } else {
             $data['errors'] = $category->getErrors();
         }
     }
     if (isset($_POST['create_from_groups'])) {
         $groupId = Arr::get($_POST, 'groupId', '');
         $parentId = Arr::get($_POST, 'parentId', '');
         $include_content = Arr::get($_POST, 'include_content', '');
         $category->createFromGroups($parentId, $groupId);
         if ($include_content == 'on') {
         }
     }
     $url = $this->request->param('id');
     $widgetId = $this->request->param('widget');
     $widgets = new Model_Widget();
     if ($url != NULL) {
         $data['thisCategory'] = $category->getCategory($category->getCategoryIdByUrl($url));
         //получаем виджеты для категории
         $data['widgets'] = $widgets->getWidgets($category->getCategoryIdByUrl($url));
     }
     if ($widgetId) {
         $data['widget'] = $widgets->getWidget($widgetId);
         $data['widgetTypes'] = $widgets->getWidgetTypes();
     }
     //Получаем группу пользователя
     $auth = Auth::instance();
     $user = $auth->get_user();
     //  echo '<pre>';
     $this->template->content = View::factory('admin/admIndex', array('data' => $data, 'user' => $this->user));
 }
示例#4
0
 public function action_index()
 {
     echo "fsfsff";
     $parentId = $this->request->param('id');
     $tree = new Model_Widgets_Menu('tree');
     //смотрим шаблон для виджета
     $widget = new Model_Widget();
     $template = $widget->getTempalte('menu2', $parentId);
     if ($template) {
         $this->template = View::factory('widgets/' . $template);
     }
     //Получаем список меню
     $items = $tree->menuItems($parentId);
     $this->template->menu = $items;
 }
示例#5
0
 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;
 }
示例#6
0
 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;
 }
示例#7
0
 public function action_index()
 {
     $materials = new Model_Material('group');
     $gid = $this->request->param('id');
     $template = $this->request->param('template');
     if ($template) {
         $this->template = View::factory('widgets/' . $template);
     }
     //смотрим шаблон для виджета
     $widget = new Model_Widget();
     $template = $widget->getTempalte('top', $gid);
     if ($template) {
         $this->template = View::factory('widgets/' . $template);
     }
     $data = $materials->getRandomMaterials($gid, 4, time());
     $this->template->data = $data;
 }
示例#8
0
 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;
     //Получаем список меню
 }
示例#9
0
 public function __construct($request, $response, $adm_data = array())
 {
     parent::__construct($request, $response);
     $this->init();
     // Инициализация twig
     $model_widget = new Model_Widget();
     $this->module_config["methods"] = get_class_methods($this);
     $action_pattern = "/action_(.+)/";
     foreach ($this->module_config["methods"] as $key => $method) {
         if (preg_match($action_pattern, $method)) {
             $action = preg_replace($action_pattern, "\$1", $method);
             $this->module_config["actions"][] = $action;
         }
     }
     //if ($this->request->param('id', false))
     $widget_id = $this->request->param('id');
     $this->action = $this->request->action();
     if ($adm_data) {
         $widget_id = $adm_data["widget_id"];
         $this->action = $adm_data["action"];
     }
     $this->widget_data = $model_widget->getWidgetData($widget_id);
     $this->widget_options = json_decode($this->widget_data["options"], true);
 }
示例#10
0
 public function action_index()
 {
     //смотрим шаблон для виджета
     $id = $this->request->param('id');
     $widget = new Model_Widget();
     $template = $widget->getTempalte('callback', $id);
     if ($template) {
         $this->template = View::factory('widgets/' . $template);
     }
     if (isset($_POST['callback-order'])) {
         if (Captcha::valid(Arr::get($_POST, 'comm-captcha'))) {
             $base = new Model_Base();
             $options = $base->getOptions();
             $vData = $_POST;
             $validation = Validation::factory($vData);
             $validation->rule('cb-name', 'not_empty');
             $validation->rule('cb-name', 'min_length', array(':value', '2'));
             $validation->rule('cb-name', 'max_length', array(':value', '250'));
             $validation->rule('cb-phone', 'not_empty');
             $validation->rule('cb-phone', 'phone');
             $validation->rule('cb-phone', 'min_length', array(':value', '6'));
             $validation->rule('cb-phone', 'max_length', array(':value', '15'));
             if (!$validation->check()) {
                 $this->errors = $validation->errors('callbackErrors');
             } else {
                 $name = Arr::get($_POST, 'cb-name', '');
                 $phone = Arr::get($_POST, 'cb-phone', '');
                 //отправляем письмо
                 $config = Kohana::$config->load('email');
                 Email::connect($config);
                 $to = $config['options']['callback_email'];
                 //$to = '*****@*****.**';
                 $subject = 'Поступила заявка с сайта ' . $options['sitename'] . ' от ' . $name . '';
                 $from = $config['options']['username'];
                 $message = '<h2>Новая заявка</h2>';
                 $message .= 'Отправитель: <b>' . $name . ', </b><br>';
                 $message .= 'Тел: <b>' . $phone . ', </b><br>';
                 $message .= '<em>Отправлено: ' . date("G:i:s M j Y") . '</em>';
                 Email::send($to, $from, $subject, $message, $html = TRUE);
                 if (count($this->errors) > 0) {
                     $base = new Model_Base();
                     $options = $base->getOptions();
                     $to = $options['admin_email'];
                     $subject = 'Ошибки на сайте ' . $options['sitename'];
                     $from = $config['options']['username'];
                     foreach ($this->errors as $error) {
                         $message = '<h2>Ошибка</h2>';
                         $message .= $error;
                         $message .= ' <em>Отправлено: ' . date("G:i:s M j Y") . '</em>';
                     }
                     Email::send($to, $from, $subject, $message, $html = TRUE);
                 } else {
                     $this->messages[] = 'Спасибо! Ваш вопрос успешно отправлен.';
                 }
             }
         } else {
             $this->errors['captcha'] = "Код введен неверно";
         }
     }
     $captcha_image = Captcha::instance()->render();
     $this->template->captcha = $captcha_image;
     $this->template->errors = $this->errors;
     $this->template->messages = $this->messages;
 }
示例#11
0
 public function action_index()
 {
     $category = new Model_Category('tree');
     $widgets = new Model_Widget();
     $data['categories'] = $category->getTree();
     if (isset($_POST['add_category'])) {
         $categoryName = Arr::get($_POST, 'categoryName', '');
         $categoryUrl = Arr::get($_POST, 'categoryUrl', '');
         $parentId = Arr::get($_POST, 'parentId', '');
         $previousId = Arr::get($_POST, 'previousId', '');
         $res = $category->catInsert($parentId, $previousId, array('name' => $categoryName, 'url' => $categoryUrl));
         if ($res) {
             Controller::redirect('admin/structure');
         } else {
             $data['errors'] = $category->getErrors();
         }
     }
     if (isset($_POST['save_category'])) {
         $categoryName = Arr::get($_POST, 'categoryName', '');
         $categoryKeywords = Arr::get($_POST, 'categoryKeywords', '');
         $categoryDescription = Arr::get($_POST, 'categoryDescription', '');
         $url = $this->request->param('id');
         $categoryId = $category->getCategoryIdByUrl($url);
         $res = $category->catUpdate($categoryId, array('name' => $categoryName, 'keywords' => $categoryKeywords, 'description' => $categoryDescription));
         if ($res) {
             Controller::redirect('admin/structure/' . $url);
         } else {
             $data['errors'] = $category->getErrors();
         }
     }
     if (isset($_POST['create_from_groups'])) {
         $groupId = Arr::get($_POST, 'groupId', '');
         $parentId = Arr::get($_POST, 'parentId', '');
         $include_content = Arr::get($_POST, 'include_content', '');
         $category->createFromGroups($parentId, $groupId);
         if ($include_content == 'on') {
         }
     }
     if (isset($_POST['addWidget'])) {
         $widgets->addWidget($_POST);
     }
     if (isset($_POST['checked_del'])) {
         $delArr = Arr::get($_POST, 'check_name', array());
         $widgets->deleteWidgets($delArr);
     }
     $url = $this->request->param('id');
     $widgetId = $this->request->param('widget');
     if ($url != NULL) {
         $data['thisCategory'] = $category->getCategory($category->getCategoryIdByUrl($url));
         //получаем виджеты для категории
         $data['widgets'] = $widgets->getWidgets($category->getCategoryIdByUrl($url));
         $data['widgetsTypes'] = $widgets->getWidgetTypes();
         $data['positions'] = Kohana::$config->load('main')->positions;
         $data['templates'] = $this->getTemplates();
     }
     if ($widgetId) {
         if (isset($_POST['save_widget'])) {
             PC::debug($_POST, "post");
             //сохраняем данные виджета
             $data['errors'] = $widgets->saveWidget($_POST);
         }
         $data['widget'] = $widgets->getWidget($widgetId);
         $data['widgetTypes'] = $widgets->getWidgetTypes();
         if ($data['widget']['template'] && $data['widget']['template'] != '') {
             $template = $data['widget']['template'];
         } else {
             $template = $data['widget']['def_template'];
         }
         $lessfile = DOCROOT . 'css/' . $data['widget']['name'] . '.less';
         $jsfile = DOCROOT . 'js/' . $data['widget']['name'] . '.js';
         if ($template) {
             $filename = DOCROOT . 'application/views/widgets/' . $template . '.php';
             if (is_file($filename) && is_readable($filename) && filesize($filename) > 0) {
                 $fh = fopen($filename, "r");
                 $file = fread($fh, filesize($filename));
                 $data['file'] = $file;
                 fclose($fh);
             }
         }
         if (is_file($lessfile) && is_readable($lessfile) && filesize($lessfile) > 0) {
             $fh = fopen($lessfile, "r");
             $file = fread($fh, filesize($lessfile));
             $data['less'] = $file;
             fclose($fh);
         }
         if (is_file($jsfile) && is_readable($jsfile) && filesize($jsfile) > 0) {
             $fh = fopen($jsfile, "r");
             $file = fread($fh, filesize($jsfile));
             $data['js'] = $file;
             fclose($fh);
         }
         $num_backups = 10;
         $template .= '.php';
         $lname = $data['widget']['name'] . '.less';
         $jname = $data['widget']['name'] . '.js';
         for ($n = 1; $n <= $num_backups; ++$n) {
             $name1 = str_replace($template, str_replace(".", "_" . $n . ".", $template), $template);
             $res = str_replace($template, 'backups/' . $name1, $filename);
             if (is_file($res)) {
                 $data['template_backups'][$n]['file'] = $res;
                 $data['template_backups'][$n]['name'] = $name1;
             }
             $namel = str_replace($lname, str_replace(".", "_" . $n . ".", $lname), $lname);
             $namej = str_replace($jname, str_replace(".", "_" . $n . ".", $jname), $jname);
             $lres = str_replace($lname, 'backups/' . $namel, $lessfile);
             if (is_file($lres)) {
                 $data['less_backups'][$n]['file'] = $lres;
                 $data['less_backups'][$n]['name'] = $namel;
             }
             $jres = str_replace($jname, 'backups/' . $namej, $jsfile);
             if (is_file($jres)) {
                 $data['js_backups'][$n]['file'] = $jres;
                 $data['js_backups'][$n]['name'] = $namej;
             }
         }
     }
     if (isset($_POST['imgUpload'])) {
         //get uploadDir
         $uploadDir = DOCROOT . 'img/user/menu';
         $name = $_POST['filename'];
         //перебираем массив файлов
         for ($i = 0; $i < count($_FILES['file']['name']); ++$i) {
             if ($_FILES['file']['size'][$i] > 11100000) {
                 echo 'Файл не должен быть больше 10 Мб';
             } else {
                 $ext = explode('.', $_FILES['file']['name'][$i]);
                 $extension = array_pop($ext);
                 $base = new Model_Base();
                 $extarr = explode('.', $_FILES['file']['name'][$i]);
                 $ext = array_pop($extarr);
                 $filename = $name . '.' . $ext;
                 //$filename = substr(md5(microtime() * time()),0,rand(20,10)).'.'.$extension;
                 if (copy($_FILES['file']['tmp_name'][$i], $uploadDir . "/" . $filename)) {
                     $base = new Model_Base();
                     $options = $base->getOptions();
                     $size = explode(',', Arr::get($options, 'structure_photos_size'));
                     //изменяем картинку
                     //открываем изображение
                     $image = Image::factory($uploadDir . "/" . $filename);
                     //начинаем работу с нужной картинкой. Путь указан от корня приложения
                     //меняем размер картинки
                     if (count($size) == 2) {
                         $image->resize($size[0], $size[1]);
                     }
                     //сохраняем новое изображение
                     $image->save(NULL, 90);
                     //первый параметр - путь, имя и формат изображения. Второй - качество изображения
                     unset($image);
                 }
             }
         }
     }
     //Получаем группу пользователя
     $auth = Auth::instance();
     $user = $auth->get_user();
     //  echo '<pre>';
     $this->template->content = View::factory('admin/admIndex', array('data' => $data, 'user' => $this->user, 'request' => $this->request, 'response' => $this->response));
 }