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;
 }
Exemple #2
0
 public function action_room()
 {
     $base = new Model_Base();
     $options = $base->getOptions();
     if (!isset($options['room']) || $options['room'] != 'TRUE') {
         Controller::redirect('/');
     }
     $this->template->title = 'Личный кабинет';
     $this->template->page_title = 'Личный кабинет';
     $this->template->keywords = 'Личный кабинет';
     $this->template->description = 'Личный кабинет';
     $data = array();
     $errors = array();
     $widgets = $this->getWidgets(0);
     $auth = Auth::instance();
     //        var_dump($auth->hash($_POST['password']));
     if (is_array($widgets)) {
         foreach ($widgets as $position => $widget) {
             $this->template->{$position} = $widget;
         }
     }
     if (!$auth->logged_in('visitor')) {
         if (isset($_POST['login'])) {
             $username = Arr::get($_POST, 'username', '');
             $password = Arr::get($_POST, 'password', '');
             if ($auth->login($username, $password)) {
                 //print('Залогинен');
                 $session = Session::instance();
                 $auth_redirect = $session->get('auth_redirect', '');
                 $session->delete('auth_redirect');
                 Controller::redirect('/user');
             } else {
                 //print('Ошибка');
                 $errors[] = 'Не верный логин или пароль.';
             }
         }
         $this->template->block_center[] = View::factory('widgets/w_auth')->bind('errors', $errors);
     } else {
         $param = $this->request->param('act');
         $materals = new Model_Material('group');
         //получаем пользователя
         $user = $auth->get_user();
         if ($param == 'show') {
             $user_orders = Module::create(array("controller" => "user/cabinet/orders", "action" => "index", "options" => array()));
             //echo $user_orders["body"];
             //получаем материалы пользователя
             $data['materials'] = $materals->getUserMaterials($user->id);
             //$this->template->block_center[] = $user_orders["body"];
             //return new View($file, $data);
             /*$page = View::factory('widgets/w_room')
             				->bind('errors', $errors)
             				->bind('messages', $messages)
             				->bind('data', $data);
             
             				var_dump($page);*/
             // --- tests -------------------------------------------------------------
             $this->template->title = 'Личный кабинет';
             $this->template->page_title = 'Личный кабинет';
             $this->template->keywords = 'Личный кабинет';
             $this->template->description = 'Личный кабинет';
             $auth = Auth::instance();
             if ($auth->logged_in() != 0) {
                 $this->template->content = View::factory('admin/admIndex');
             } else {
                 $this->template->content = View::factory('admin/admLogin');
                 if (isset($_POST['enter'])) {
                     $username = Arr::get($_POST, 'username', '');
                     $password = Arr::get($_POST, 'password', '');
                     if ($auth->login($username, $password)) {
                         //print('Залогинен');
                         $session = Session::instance();
                         $auth_redirect = $session->get('auth_redirect', '');
                         $session->delete('auth_redirect');
                         Controller::redirect($auth_redirect);
                     } else {
                         //print('Ошибка');
                         $this->template->error = 'Не верный логин или пароль.';
                     }
                 }
             }
             // --- tests -------------------------------------------------------------
             //exit();
         } elseif ($param == 'edit') {
             $materialId = $this->request->param('id');
             //получаем материал
             $data['material'] = $materals->getMaterial($materialId, $user->id);
             if ($data['material']) {
                 $gid = $materals->getGroupFromMid($materialId);
                 $data['fieldset'] = $materals->getFieldsSet($gid);
                 //получаем поля
                 $data['fields'] = $materals->getFields($materialId, TRUE);
             } else {
                 $errors[] = 'Данный материал не найден';
             }
         } elseif ($param == 'settings') {
             if (isset($_POST['save_settings'])) {
                 //сохраняем настройки
                 $modelUser = new Model_User();
                 $res = $modelUser->saveUser($_POST, $user->id);
                 if (is_array($res)) {
                     $errors = $res;
                 } else {
                     $messages[] = $res;
                 }
             }
             $data['user'] = ORM::factory('User', array('id' => $user->id));
         }
         $this->template->block_center[] = View::factory('widgets/w_room')->bind('errors', $errors)->bind('messages', $messages)->bind('data', $data);
     }
 }