Example #1
0
 public function action_index()
 {
     $category = new Model_Category('tree');
     $data['categories'] = $category->getTree();
     if (isset($_POST['btnsubmit'])) {
         $categoryName = Arr::get($_POST, 'categoryName', '');
         $parentId = Arr::get($_POST, 'parentId', '');
         $url = Arr::get($_POST, 'url', '');
         $categoryimage = Arr::get($_POST, 'categoryimage', '');
         $res = $category->catInsert($parentId, array('name' => $categoryName, 'url' => $url, 'icon_url' => $categoryimage));
         if ($res) {
             //Request::initial()->redirect('admin');
             HTTP::redirect('admin');
         } else {
             $data['errors'] = $category->getErrors();
         }
     }
     if (isset($_POST['materialsavebtn'])) {
         $categoryId = Arr::get($_POST, 'categoryId', '');
         $content = Arr::get($_POST, 'content', '');
         $name = Arr::get($_POST, 'name');
         $material_image = Arr::get($_POST, 'material_image');
         $material = ORM::factory('Material');
         $material->addMaterial($categoryId, $content, $name, $material_image);
         HTTP::redirect('admin');
     }
     $this->template->content = View::factory('adminview', $data);
 }
Example #2
0
 public function getPath($dir)
 {
     //первым делом ищем в структуре
     $category = new Model_Category('tree');
     $categoryId = $category->getCategoryIdByUrl($dir);
     if ($categoryId) {
         $dirs = [];
         $categoryData = $category->getCategory($categoryId);
         $parents = $category->getParents($categoryId);
         foreach ($parents as $parent) {
             if ($parent['level'] > 1 && $parent['url'] != 'glavnaya') {
                 $dirs[] = $parent['url'];
             }
         }
         return array('name' => $categoryData['name'], 'path' => implode('/', $dirs));
     }
     //теперь ищем в материалах
     $materials = new Model_Material('group');
     $materialUrl = str_replace('.html', '', $dir);
     $materialId = $materials->getMaterialIdByUrl($materialUrl);
     if ($materialId) {
         $materialData = $materials->getMaterial($materialId);
         $categoryId = $materials->getTreeIdByMid($materialId);
         $categoryData = $category->getCategory($categoryId);
         return array('name' => $materialData['name'], 'path' => $categoryData['url'] . '/' . $dir);
     } else {
         return FALSE;
     }
 }
Example #3
0
 public function action_create()
 {
     if (Auth::is_admin_signed_in() === true) {
         $view = View::factory('acp/categories/create');
         $categories = new Model_Category();
         if ($this->request->method() === Request::POST) {
             $name = $this->request->post('name');
             $slug = $this->request->post('slug');
             $token = $this->request->param('id');
             if (!Security::check($token)) {
                 $this->request->redirect('acp/categories/create');
             }
             if (empty($slug)) {
                 $slug = URL::title($name, '_');
             }
             if (empty($name) && empty($slug)) {
                 $this->request->redirect('acp/categories/create');
             }
             $categories = new Model_Category();
             $create_category = $categories->create_category($name, $slug);
             if (!$create_category) {
                 $this->request->redirect('acp/categories/create');
             }
             $this->request->redirect('acp/categories');
         }
         $this->template->content = $view->render();
     } else {
         $this->request->redirect('acp');
     }
 }
Example #4
0
 public function action_create()
 {
     if (Auth::is_admin_signed_in() === true) {
         $view = View::factory('acp/create/product');
         $categories = new Model_Category();
         $view->categories = $categories->get_list_of_categories();
         if ($this->request->method() === Request::POST) {
             $name = $this->request->post('name');
             $valute = $this->request->post('valute');
             $category = $this->request->post('category');
             $description = $this->request->post('description');
             $price = $this->request->post('price');
             $img_url = $this->request->post('img_url');
             $count = $this->request->post('count');
             $price = Currency::to_database($price, $valute);
             if (empty($name) && empty($category) && empty($description) && empty($price)) {
                 throw new Exception("Please do not make empty fields!");
             }
             $products = new Model_Product();
             $data = array('image_url' => $img_url, 'name' => $name, 'category' => $category, 'description' => $description, 'price' => $price, 'count' => $count);
             $create_new_product = $products->create_new_product($data);
             if (!$create_new_product) {
                 throw new Exception("Error! Please check for DB settings!");
             }
             $this->request->redirect('acp/products');
         }
         $this->template->content = $view->render();
     } else {
         $this->request->redirect('acp');
     }
 }
 public function addeditAction()
 {
     // action body
     $oCategoryForm = new Application_Form_Category();
     $this->view->categoryform = $oCategoryForm;
     if ($this->getRequest()->isPost()) {
         if ($oCategoryForm->isValid($this->getRequest()->getPost())) {
             $saFormDetails = $oCategoryForm->getValues();
             $oCategoryExist = Doctrine::getTable('Model_Category')->checkCategoryExist($saFormDetails['id_users']);
             if (count($oCategoryExist) > 0 && $this->getRequest()->getParam('id_category') == "") {
                 $this->view->errorMessage = "This category is already exist.";
             } elseif ($this->getRequest()->getParam('id_category') != "" && isset($oCategoryExist[0]) && $oCategoryExist[0]['id_category'] != $this->getRequest()->getParam('id_category')) {
                 $this->view->errorMessage = "This category is already exist.";
             } else {
                 $oCategory = new Model_Category();
                 $snIdUser = $oCategory->saveAndUpdateCategoryDetails($oCategory, $saFormDetails, $this->getRequest()->getParam('id_category') != 0 ? $this->getRequest()->getParam('id_category') : '');
                 $this->_redirect('/admin/category/list');
             }
         }
     } elseif ($this->getRequest()->getParam('id') != '') {
         $oCategory = Doctrine::getTable('Model_Category')->getCategoryDetailById($this->getRequest()->getParam('id'));
         $oCategoryForm->populate($oCategory[0]);
     }
     $this->view->param = $this->getRequest()->getParam('id') ? $this->getRequest()->getParam('id') : '';
 }
Example #6
0
 public function action_index()
 {
     $this->template->page_title = 'Главная страница';
     //$this->template->block_center = array($block_center);
     $category = new Model_Category('tree');
     $categoryName = $this->request->param('category');
     $categoryId = $category->getCategoryIdByUrl('glavnaya');
     //ВИДЖЕТЫ ДЛЯ ГЛАВНОЙ СТРАНИЦЫ
     $widgets = $category->getWidgets($categoryId);
     $this->styles = array();
     $wdgtarr = array();
     //        if($this->template->block_center!=NULL)
     //            {
     //                $oldWidgets = $this->template->block_center;
     //                foreach ($oldWidgets as $oldWidget)
     //                    array_push($wdgtarr['block_center'], $oldWidget);
     //            }
     $widgets = $this->getWidgets($categoryId);
     if (is_array($widgets)) {
         foreach ($widgets as $position => $widget) {
             $this->template->{$position} = $widget;
         }
     }
     $old_styles = $this->template->styles;
     array_unique($this->styles);
     $new_styles = array_merge($this->styles, $old_styles);
     $this->template->styles = $new_styles;
 }
Example #7
0
 public function configure()
 {
     // Init category
     $category = new Model_Category(Conf::get('MAIN_CATEGORY'));
     if ($category->getQuestionsTotal(true, true) == 0) {
         return;
     }
     // Get questions
     $questions = $category->getQuestions('latest', $this->page, true, true);
     if ($category->getQuestionsTotal(true, true) <= ($this->page + 1) * Conf::get('QUESTION_PER_PAGE')) {
         header('X-JSON: (Question.setEndReached())');
     }
     $colors = Conf::get('GRAPH_COLORS');
     // Loop through all questions
     foreach ($questions as $key => $question) {
         // Get question's answers
         $answers = $question->getAnswers();
         $data = array();
         foreach (array_reverse($answers) as $key => $answer) {
             $data[] = array('value' => $answer->getPercentResultsMatching() / 100, 'color' => $colors[$key]);
         }
         // Assign question infos
         Globals::$tpl->assignLoopVar('question_archive', array('id' => $question->getId(), 'label' => $question->getLabel(), 'guid' => Tool::makeGuid($question->getLabel()), 'data' => json_encode($data), 'time' => Tool::timeWarp($question->getEndDate())));
         // Assign answers infos
         foreach ($answers as $key => $answer) {
             Globals::$tpl->assignLoopVar('question_archive.answer', array('percentFormated' => round($answer->getPercentResultsMatching()), 'label' => $answer->getLabel(), 'key' => $key));
         }
     }
 }
Example #8
0
 /**
  * Automatically executed before the widget action. Can be used to set
  * class properties, do authorization checks, and execute other custom code.
  *
  * @return  void
  */
 public function before()
 {
     $cat = new Model_Category();
     // loaded category
     if (Controller::$category !== NULL) {
         if (Controller::$category->loaded()) {
             $category = Controller::$category->id_category;
             // id_category
             //list of children of current category
             // if list_cat dosent have siblings take brothers
             $list_cat = $cat->where('id_category_parent', '=', $category)->order_by('order', 'asc')->cached()->find_all();
             if (count($list_cat) == 0) {
                 $list_cat = $cat->where('id_category_parent', '=', Controller::$category->id_category_parent)->order_by('order', 'asc')->cached()->find_all();
             }
             //parent of current category
             $cat_parent_deep = $cat->where('id_category', '=', Controller::$category->id_category_parent)->limit(1)->find();
             // array with name and seoname of a category and his parent. Is to build breadcrumb in widget
             $current_and_parent = array('name' => Controller::$category->name, 'id' => Controller::$category->id_category, 'seoname' => Controller::$category->seoname, 'parent_name' => $cat_parent_deep->name, 'id_parent' => $cat_parent_deep->id_category_parent, 'parent_seoname' => $cat_parent_deep->seoname);
         }
     } else {
         $list_cat = $cat->where('id_category_parent', '=', 1)->order_by('order', 'asc')->cached()->find_all();
         $current_and_parent = NULL;
     }
     $this->cat_items = $list_cat;
     $this->cat_breadcrumb = $current_and_parent;
     $this->loc_seoname = NULL;
     if (Controller::$location !== NULL) {
         if (Controller::$location->loaded()) {
             if (Controller::$location->id_location != 1) {
                 $this->loc_seoname = Controller::$location->seoname;
             }
         }
     }
 }
Example #9
0
 public function getMaterialsByTeacher($pagination, $teacher_id = NULL, $node_id = NULL, $filter = NULL)
 {
     $cat = new Model_Category();
     $qry = DB::select('materials.*', array('users.name', 'name'))->join('users', 'left')->on('users.id', '=', 'materials.teacher_id')->from('materials');
     if ($teacher_id) {
         $qry->where('teacher_id', '=', $teacher_id);
     }
     if ($node_id) {
         $qry->where('node_id', '=', $node_id);
     }
     if (isset($filter['FIO']) && $filter['FIO'] != '') {
         $qry->where('name', 'like', '%' . $filter['FIO'] . '%');
     }
     if (!$teacher_id) {
         $qry->order_by('users.name', 'asc');
     }
     if ($pagination) {
         $data = $qry->order_by('subjectName', 'asc')->order_by('ctime', 'asc')->limit($pagination->items_per_page)->offset($pagination->offset)->execute()->as_array();
     } else {
         $data = $qry->order_by('subjectName', 'asc')->order_by('ctime', 'asc')->execute()->as_array();
     }
     foreach ($data as $key => $item) {
         $data[$key]['path'] = $cat->getPath($item['node_id']);
         $data[$key]['isLeaf'] = $cat->isLeaf($item['node_id']);
         $data[$key]['link'] = $this->getLink($item);
     }
     return $data;
 }
Example #10
0
 public function getCart($userId)
 {
     $result = DB::select()->from($this->tableName)->where('user', '=', $userId)->group_by('mid')->execute()->as_array();
     $material = new Model_Material('groups');
     $category = new Model_Category('tree');
     $base = new Model_Base();
     $arr = array();
     foreach ($result as $item) {
         //var_dump($item);
         //название модели
         $materialData = $material->getMaterial($item['mid']);
         $arr[$item['mid']]['name'] = $materialData['name'];
         $arr[$item['mid']]['mid'] = $item['mid'];
         //url модели
         $categoryName = $category->getNode($material->getTreeIdByMid($item['mid']));
         $categoryName = $base->str2url($categoryName['name']);
         $arr[$item['mid']]['url'] = $categoryName . '/' . $materialData['url'] . '.html';
         //Изображение
         $fields = $material->getFields($item['mid'], true);
         $arr[$item['mid']]['img'] = $fields['Photos'][0];
         //количество
         $arr[$item['mid']]['count'] = $this->getCartCount($userId, $item['mid']);
         //сумма
         $arr[$item['mid']]['sum'] = $this->getCartPrice($userId, $item['mid']);
         //размер
         $arr[$item['mid']]['size'] = $item['size'];
         //цвет
         $arr[$item['mid']]['color'] = $item['color'];
     }
     return $arr;
 }
Example #11
0
 public function action_new()
 {
     if (Auth::instance()->logged_in()) {
         $view = View::factory('topic/new');
         $category = new Model_Category();
         $category_id = $this->request->param('id');
         $view->categories = $category->find_all();
         $user_id = Auth::instance()->get_user()->pk();
         $view->role_id = ORM::factory('Roles_User')->get_last_role_id($user_id);
         $user_id = Auth::instance()->get_user()->pk();
         $users = ORM::factory('User')->get_data($user_id);
         $this->template->content = $view->render();
         if ($this->request->method() === Request::POST) {
             if (!Security::check($this->request->param('id'))) {
                 throw new Exception("Bad token!");
             }
             $title = $this->request->post('title');
             $category_id = $this->request->post('category_id');
             $author = $user_id;
             $content = $this->request->post('content');
             if (empty($title) or empty($category_id) or empty($author) or empty($content)) {
                 throw new Exception("Fields cannot be empty!");
             }
             $data = array('title' => $title, 'category_id' => $category_id, 'author_id' => $author, 'content' => $content, 'published' => time());
             $topic = new Model_Topic();
             $publish_topic = $topic->publish($data);
             if (!$publish_topic) {
                 throw new Exception("Cannot publish your topic!");
             }
             $this->request->redirect('category/index/' . $category_id);
         }
     } else {
         $this->redirect('');
     }
 }
Example #12
0
 private function displayArchives()
 {
     if (!isset($this->displayArchives)) {
         $category = new Model_Category(Conf::get('MAIN_CATEGORY'));
         $this->displayArchives = $category->getQuestionsTotal(true, true) == 0 ? false : true;
     }
     return $this->displayArchives;
 }
 public function action()
 {
     $model = new Model_Category();
     $valuesMain['catList'] = $model->getCategoryAll();
     $view = new View();
     $view->addBufferMain('layout', $valuesMain);
     $view->addBuffers('contactus');
     $view->renderBuffer();
 }
Example #14
0
 public function action_delete()
 {
     $url = $this->request->param('id');
     if ($url != NULL) {
         $category = new Model_Category('tree');
         $result = $category->deleteCategory($category->getCategoryIdByUrl($url));
         Controller::redirect('admin');
     }
 }
Example #15
0
 public function configure()
 {
     // Init category
     $category = new Model_Category(Conf::get('MAIN_CATEGORY'));
     if ($category->getQuestionsTotal(true) == 0) {
         return;
     }
     // Get logged user if there is one
     $user = Model_User::getLoggedUser();
     // Get questions
     $questions = $category->getQuestions('latest', $this->page, 1);
     // Loop through all questions
     foreach ($questions as $question) {
         Globals::$tpl->assignLoopVar('question', array('id' => $question->getId(), 'label' => $question->getLabel(), 'image' => $question->getImageURL('medium'), 'label_urlencoded' => urlencode($question->getLabel()), 'time' => Tool::timeWarp($question->getEndDate())));
         // Get answers
         $answers = $question->getAnswers();
         $friendsVotedId = array();
         if ($user) {
             $userResult = $user->getResult($question);
             $userGuess = $user->getGuess($question);
         }
         // Loop through all answers
         foreach ($answers as $answer) {
             Globals::$tpl->assignLoopVar('question.answer', array('id' => $answer->getId(), 'label' => $answer->getLabel()));
             if ($user && $userResult && $answer->getId() == $userResult->getAnswer()->getId()) {
                 Globals::$tpl->assignLoopVar('question.answer.user', array('class' => 'vote', 'label' => 'Mon opinion', 'id' => $user->getId(), 'login' => $user->getLogin(), 'image' => $user->getAvatarURL('small')));
             }
             if ($user && $userGuess && $answer->getId() == $userGuess->getAnswer()->getId()) {
                 Globals::$tpl->assignLoopVar('question.answer.user', array('class' => 'guess', 'label' => 'Mon pronostic', 'id' => $user->getId(), 'login' => $user->getLogin(), 'image' => 'media/layout/icon24x24/map_mini.png'));
             }
             if ($user) {
                 foreach ($user->getFriendGuesses($question) as $friendGuess) {
                     if ($answer->getId() == $friendGuess->getAnswer()->getId()) {
                         Globals::$tpl->assignLoopVar('question.answer.friend', array('class' => 'friend', 'userId' => $user->getId(), 'id' => $friendGuess->getFriend()->getId(), 'login' => $friendGuess->getFriend()->getLogin(), 'avatar' => $friendGuess->getFriend()->getAvatarURL('small')));
                         $friendsVotedId[] = $friendGuess->getFriend()->getId();
                     }
                 }
             }
         }
         if ($user && !$userResult) {
             Globals::$tpl->assignLoopVar('question.pendingUser', array('class' => 'vote', 'label' => 'Mon opinion', 'id' => $user->getId(), 'login' => $user->getLogin(), 'avatar' => $user->getAvatarURL('small')));
         }
         if ($user && !$userGuess) {
             Globals::$tpl->assignLoopVar('question.pendingUser', array('class' => 'guess', 'label' => 'Mon pronostic', 'id' => $user->getId(), 'login' => $user->getLogin(), 'avatar' => $user->getAvatarURL('small')));
         }
         if ($user) {
             // Construct unvoted friends list
             foreach ($user->getFriends() as $friend) {
                 if (!in_array($friend->getId(), $friendsVotedId)) {
                     Globals::$tpl->assignLoopVar('question.pendingFriend', array('class' => 'friend', 'userId' => $user->getId(), 'id' => $friend->getId(), 'login' => $friend->getLogin(), 'avatar' => $friend->getAvatarURL('small')));
                 }
             }
         }
     }
 }
Example #16
0
 public function save(Model_Category $category)
 {
     if ($category->id) {
         $where[] = 'id = ' . $category->id;
         $this->_db->update('categories', $category->toArray(), $where);
     } else {
         $this->_db->insert('categories', $category->toArray());
         $category->id = $this->_db->lastInsertId();
     }
     return $category;
 }
Example #17
0
 public function actionSettings()
 {
     //Log::sendToScreen(__FILE__, __LINE__, 'Получить настройки из modelUsers (session_user_id)');
     //Log::sendToScreen(__FILE__, __LINE__, 'View -> render');
     $model = new Model_Category();
     $valuesMain['catList'] = $model->getCategoryAll();
     $view = new View();
     $view->addBufferMain('layout', $valuesMain);
     $view->addBuffers('settings');
     $view->renderBuffer();
 }
Example #18
0
 public function action_index()
 {
     $articles = array();
     // подключаем БД
     $article = new Model_Category();
     //считываем оттуда массив данных
     $articles = $article->get_all();
     //  подключаем шаблон и отправляем туда  переменные
     $content = View::factory('/pages/template')->bind('articles', $articles);
     $this->template->content = $content;
     $this->template->title = 'Профи-суши';
     $this->template->styles = array('bootstrap.min', 'backet', 'main', 'main-page');
 }
Example #19
0
 public function action_index()
 {
     $category_id = $this->request->param('id');
     if (empty($category_id)) {
         throw new Exception("Category ID must not be empty!");
     }
     $topic = new Model_Topic();
     $category = new Model_Category();
     $view = View::factory('categories/main');
     $view->topics = $topic->get_topics_by_id($category_id);
     $view->category = $category->get_name($category_id);
     $this->template->content = $view->render();
 }
Example #20
0
 /**
  * Initialize properties before running the controller methods (actions),
  * so they are available to our action.
  */
 public function before($template = NULL)
 {
     parent::before();
     Theme::checker();
     $this->maintenance();
     /**
      * selected category
      */
     if ($this->request->param('category', NULL) != 'all') {
         $slug_cat = new Model_Category();
         $seo_cat = $slug_cat->where('seoname', '=', $this->request->param('category'))->limit(1)->cached()->find();
         if ($seo_cat->loaded()) {
             self::$category = $seo_cat;
         }
     }
     /**
      * selected location
      */
     if ($this->request->param('location', NULL) != NULL || $this->request->param('location') != 'all') {
         $slug_loc = new Model_Location();
         $seo_loc = $slug_loc->where('seoname', '=', $this->request->param('location'))->limit(1)->cached()->find();
         if ($seo_loc->loaded()) {
             self::$location = $seo_loc;
         }
     }
     if ($this->auto_render === TRUE) {
         // Load the template
         if ($template !== NULL) {
             $this->template = $template;
         }
         $this->template = View::factory($this->template);
         // Initialize template values
         $this->template->title = core::config('general.site_name');
         $this->template->meta_keywords = '';
         $this->template->meta_description = '';
         $this->template->meta_copywrite = 'Open Classifieds ' . Core::version;
         $this->template->content = '';
         $this->template->styles = array();
         $this->template->scripts = array();
         //we can not cache this view since theres dynamic parts
         //$this->template->header  = View::factory('header');
         //setting inner views try to get from fragment
         // if (Auth::instance()->logged_in())
         //     $this->template->header  = View::fragment('header_front_login','header');
         // else
         $this->template->header = View::factory('header');
         //             $this->template->header  = View::fragment('header_front','header');
         //no fragment since CSRF gets cached :(
         $this->template->footer = View::fragment('footer_front', 'footer');
     }
 }
Example #21
0
 public function action_index()
 {
     $data = array();
     if (!is_readable(APPPATH . 'config/database.php')) {
         Request::initial()->redirect('install');
     }
     $cat = new Model_Category();
     $materials = new Model_Material();
     $cat->checkTree();
     $tree = $cat->getTree();
     $data['tree'] = $cat->getITree($tree);
     $data['teachers'] = $materials->getTeachersGropupByNode();
     $this->tpl->content = View::factory('main', $data);
 }
Example #22
0
 public function action_index()
 {
     $data = array();
     $category = new Model_Category('tree');
     $category->checkTree(TRUE);
     $data['categories'] = $category->getTree();
     if ($this->isPressed('btnSubmitAdd')) {
         $categoryName = Arr::get($_POST, 'categoryName', '');
         $parentId = Arr::get($_POST, 'parentId', 0);
         $res = $category->catInsert($parentId, array('name' => $categoryName));
         if ($res) {
             Request::initial()->redirect('admin/category');
         }
         $data['errors'] = $category->getErrors();
     }
     if ($this->isPressed('btnSubmitChange')) {
         $categoryName = Arr::get($_POST, 'categoryName', '');
         $parentId = Arr::get($_POST, 'parentId', 0);
         if ($category->changeName($parentId, $categoryName)) {
             Request::initial()->redirect('admin/category');
         }
         $data['errors'] = $category->getErrors();
     }
     if ($this->isPressed('btnSubmitDel')) {
         $catDeleteId = Arr::get($_POST, 'catDeleteId', 0);
         $category->catDelete($catDeleteId);
         Request::initial()->redirect('admin/category');
     }
     $this->tpl->content = View::factory('admin/categoryeditview', $data);
 }
Example #23
0
 public function action_index()
 {
     $href = $this->request->param('id');
     $article = new Model_Category();
     // отбираем или по категориям или по все сразу
     $articles = $article->get_all_sushi();
     $articles = $article->get_id($href);
     $id = $articles[0]['id'];
     $select = $article->get_category($id);
     $this->template->styles = array('bootstrap.min', 'main', 'product-list');
     $this->template->scripts = array('jquery-1.11.3.min', 'bootstrap.min', 'script001', 'cart');
     $content = View::factory('/pages/category')->bind('articles', $select);
     $this->template->content = $content;
 }
Example #24
0
 /**
  * Function for saving emails to subscribers
  */
 public static function find_subscribers($data, $price, $seotitle, $email)
 {
     // locations are optional , get wiget settings for locations and categories
     $jsonObj = json_decode(core::config('widget.Widget_Subscribers_1373877069'), true);
     $subscribers = new Model_Subscribe();
     $category = new Model_Category($data['cat']);
     if ($category->loaded()) {
         if ($category->id_category_parent !== 1) {
             $cat_parent = $category->id_category_parent;
         }
     }
     //only min/max price is required in widget settings
     if ($price !== '0') {
         $subscribers->where('min_price', '<=', $price)->where('max_price', '>=', $price);
     } else {
         $subscribers->where('min_price', '<=', 0)->where('max_price', '>=', 0);
     }
     //location is set
     if ($data['loc'] != NULL and $jsonObj['data']['locations'] !== '0') {
         $subscribers = $subscribers->where('id_location', '=', $data['loc']);
     }
     //category is set
     if ($jsonObj['data']['categories'] !== '0') {
         $subscribers = $subscribers->where('id_category', 'IN', array($data['cat'], $cat_parent));
     }
     $subscribers = $subscribers->find_all();
     $subscribers_id = array();
     // array to be filled with user emails
     foreach ($subscribers as $subs) {
         // do not repeat same users.
         if (!in_array($subs->id_user, $subscribers_id)) {
             $subscribers_id[] = $subs->id_user;
         }
     }
     // query for getting users, transform it to array and pass to email function
     if (count($subscribers_id) > 0) {
         $query = DB::select('email')->select('name')->from('users')->where('id_user', 'IN', $subscribers_id)->where('status', '=', Model_User::STATUS_ACTIVE)->execute();
         $users = $query->as_array();
         $user = new Model_User();
         $user = $user->where('email', '=', $email)->where('status', '=', Model_User::STATUS_ACTIVE)->limit(1)->find();
         // Send mails like in newsletter, to multiple users simultaneously @TODO NOT YET READY
         if (count($users) > 0) {
             $url_ad = $user->ql('ad', array('category' => $data['cat'], 'seotitle' => $seotitle), TRUE);
             if (!Email::send($users, '', "Advertisement is created on " . core::config('general.site_name') . "!", "Hello, You may be interested in this one: \n\n " . $data['title'] . "! \n\n\n                                        You can visit this link to see advertisement " . $url_ad, "no-reply " . core::config('general.site_name'), core::config('email.notify_email'))) {
                 Alert::set(Alert::ERROR, __('Error on mail delivery, not sent'));
             }
         }
     }
 }
 public function action_category()
 {
     $url = $this->request->param('id');
     $data = array();
     $category = new Model_Category('tree');
     $material = new Model_Material();
     $category_id = $category->getCategoryIdByUrl($url);
     if (!$category_id) {
         throw new HTTP_Exception_404('Запрашиваемая категория не найдена');
         return;
     }
     $data['materials'] = $material->getMaterialsByCategory($category_id);
     //$data['category_name'] = $category_info['name'];
     $this->template->content = View::factory('materialsview', $data);
 }
Example #26
0
 public function before()
 {
     parent::before();
     $config = Kohana::$config->load('common');
     $this->template->name = $config->name;
     $this->template->stylesheets = $config->stylesheets;
     $categories = new Model_Category();
     $client = new Model_Client();
     $product = new Model_Product();
     $this->template->products = $product->get_random_product_with_discount();
     $this->template->valute = $client->get_user_valute(Session::instance()->get('email'));
     $this->template->categories = $categories->get_list_of_categories();
     $this->template->users = $client->get_user_data(Session::instance()->get('email'));
     $this->template->scripts = $config->scripts;
 }
 public function action_Edit($Kid = 0)
 {
     //ドロップダウンリストの生成
     $select = Model_College::get_list();
     $Kid and $this->data['category'] = Model_Category::query()->where('Kid', '=', $Kid)->get();
     if (Input::post()) {
         $val = Model_Category::validate();
         if ($val->run()) {
             $query = DB::update('Category')->set(array('Cid' => Input::post('college'), 'Kname' => Input::post('Kname'), 'Kkana' => Input::post('Kkana'), 'luID' => Auth::get_screen_name()))->where('Kid', '=', $Kid)->execute();
             Response::redirect('category');
         } else {
             $this->message = $val->error();
             $view = View::forge('categorymanagement/CategoryEdit', $this->data);
             $view->set_global('message', $this->message, false);
             //ドロップダウン箇所のセット
             $view->set_global('select', $select, false);
         }
     } else {
         $view = View::forge('categorymanagement/CategoryEdit', $this->data);
         $view->set_global('message', $this->message, false);
         //ドロップダウン箇所のセット
         $view->set_global('select', $select, false);
     }
     return $view;
 }
Example #28
0
 public function action_index()
 {
     $page = Input::get('page') ? Input::get('page') : 1;
     $query = Input::get('query') ? Input::get('query') : "";
     if (strlen($query)) {
         $data['news'] = DB::select('*')->from('news')->where('news_title', 'LIKE', '%' . $query . '%')->limit(30)->offset(($page - 1) * 30)->order_by('id', 'desc')->execute()->as_array();
     } else {
         $data['news'] = DB::select('*')->from('news')->limit(30)->offset(($page - 1) * 30)->order_by('id', 'desc')->execute()->as_array();
     }
     $total_rec = DB::count_last_query();
     $data['total_page'] = ceil($total_rec / 30);
     $data['page'] = $page;
     $config = array('pagination_url' => "", 'total_items' => $total_rec, 'per_page' => 30, 'uri_segment' => 2, 'current_page' => $page);
     $pagination = Pagination::forge('pagenav', $config);
     $data['pagination'] = $pagination->render();
     $cats = Model_Category::get_categories();
     $this->theme->set_template('index');
     $this->theme->get_template()->set_global('current_menu', "News", false);
     $this->theme->get_template()->set_global('current_menu_desc', "จัดการข่าวทั้งหมดในระบบ", false);
     $this->theme->get_template()->set('breadcrumb', array(array('title' => "Home", 'icon' => "fa-home", 'link' => Uri::create('home'), 'active' => false), array('title' => "News", 'icon' => "eicon-newspaper", 'link' => "", 'active' => true)));
     $this->theme->get_template()->set_global('query', $query, false);
     $this->theme->get_template()->set_global('cats', $cats, false);
     $this->theme->set_partial('sidebar', 'common/sidebar');
     $this->theme->set_partial('content', 'news/index')->set($data);
 }
Example #29
0
 public function action_Department($Kid)
 {
     //CSRF対策
     $this->data['token_key'] = Config::get('security.csrf_token_key');
     $this->data['token'] = Security::fetch_token();
     //カテゴリごとの投稿件数を取得
     $count = Model_Post::query()->where('Kid', '=', $Kid)->count();
     //ページネーションの設定(カテゴリごとの投稿表示仕様)
     $config = array('pagination_url' => 'noteshare/list/' . $Kid, 'uri_segment' => 3, 'num_links' => 3, 'per_page' => $this->per_page, 'total_items' => $count, 'show_first' => true, 'show_last' => true);
     $pagination = Pagination::forge('post_pagination', $config);
     $this->data['posts'] = Model_Post::query()->where('Kid', '=', $Kid)->order_by('Ptime', 'desc')->limit($this->per_page)->offset($pagination->offset)->get();
     $this->data['department'] = Model_Category::query()->where('Kid', '=', $Kid)->get();
     $this->action_categorize();
     //homeのビューオブジェクトを生成
     if (!$count) {
         $this->data['error'] = true;
         $view = View::forge('list/DepartmentList', $this->data);
         $view->set_safe('pagination', $pagination);
         //メッセージの定義
     } else {
         $view = View::forge('list/DepartmentList', $this->data);
         $view->set_safe('pagination', $pagination);
     }
     return $view;
 }
Example #30
0
 public function action_index()
 {
     //template header
     $this->template->title = '';
     // $this->template->meta_keywords    = 'keywords';
     $this->template->meta_description = Core::config('general.site_description');
     //setting main view/template and render pages
     // swith to decide on ads_in_home
     $ads = new Model_Ad();
     $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED);
     switch (core::config('advertisement.ads_in_home')) {
         case 2:
             $id_ads = array_keys(Model_Visit::popular_ads());
             if (count($id_ads) > 0) {
                 $ads->where('id_ad', 'IN', $id_ads);
             }
             break;
         case 1:
             $ads->where('featured', 'IS NOT', NULL)->where('featured', 'BETWEEN', array(DB::expr('NOW()'), Date::unix2mysql(time() + core::config('payment.featured_days') * 24 * 60 * 60)))->order_by('featured', 'desc');
             break;
         case 0:
         default:
             $ads->order_by('published', 'desc');
             break;
     }
     //if ad have passed expiration time dont show
     if (core::config('advertisement.expire_date') > 0) {
         $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', DB::expr('NOW()'));
     }
     $ads = $ads->limit(Theme::get('num_home_latest_ads', 4))->cached()->find_all();
     $this->ads = $ads;
     $categs = Model_Category::get_category_count();
     $this->template->bind('content', $content);
     $this->template->content = View::factory('pages/home', array('ads' => $ads, 'categs' => $categs));
 }