示例#1
0
 /**
  * Print Product
  * @param int $id
  * @param int $var
  */
 public function print_product($id, $var)
 {
     if (!$this->no_install) {
         return false;
     }
     $product = SProductsQuery::create()->joinWithI18n(MY_Controller::getCurrentLocale())->findPk($id);
     $variant = SProductVariantsQuery::create()->joinWithI18n(MY_Controller::getCurrentLocale())->findPk($var);
     \CMSFactory\assetManager::create()->registerStyleWithoutTemplate('style');
     \CMSFactory\assetManager::create()->setData(array('product' => $product, 'variant' => $variant))->render('print_product', TRUE);
 }
 /**
  * Data Autocomplete
  * @access public
  * @author L.Andriy <*****@*****.**>
  * @copyright (c) 2013, ImageCMS
  */
 public function autosearch()
 {
     switch ($this->input->post('queryString')) {
         case 'product':
             $entity = SProductsQuery::create()->joinWithI18n($this->def_locale)->filterByActive(true)->withColumn('SProductsI18n.Name', 'Name')->select(array('Id', 'Name'))->find()->toArray();
             break;
         case 'shop_category':
             $entity = SCategoryQuery::create()->joinWithI18n($this->def_locale)->withColumn('SCategoryI18n.Name', 'Name')->select(array('Id', 'Name'))->find()->toArray();
             break;
         case 'brand':
             $entity = SBrandsQuery::create()->joinWithI18n($this->def_locale)->withColumn('SBrandsI18n.Name', 'Name')->select(array('Id', 'Name'))->find()->toArray();
             break;
         case 'category':
             $entity = $this->db->select('id as Id')->select('name as Name')->get('category')->result_array();
             break;
         case 'page':
             $entity = $this->db->select('id as Id')->select('title as Name')->get('content')->result_array();
             break;
         case 'main':
             $entity = array(array('Id' => 0, 'Name' => lang('Main', 'banners')));
             break;
         default:
             break;
     }
     /** Show template with data */
     \CMSFactory\assetManager::create()->setData('entity', $entity)->render($this->input->post('tpl'), TRUE);
 }
示例#3
0
 /**
  * @covers ProductApi::setProductAdditionalCategories
  * @todo   Implement testSetProductAdditionalCategories().
  */
 public function testSetProductAdditionalCategories()
 {
     $model = SProductsQuery::create()->findOneById($this->testDbProduct['id']);
     $result = $this->object->setProductAdditionalCategories($model);
     $this->assertFalse($result);
     if (!$result) {
         $this->assertTrue($this->object->getError() === lang('You did not specified categories array'));
     }
     $result = $this->object->setProductAdditionalCategories($model, $this->testData);
     $this->assertTrue($result);
 }
示例#4
0
 /**
  * Selection of products in the categories specified by the user
  * @return array Products and products variants         
  */
 public function getProducts($idsCat)
 {
     $products = SProductsQuery::create()->distinct()->filterByCategoryId($idsCat)->useProductVariantQuery()->filterByStock(array('min' => 1))->endUse()->filterByActive(true)->find();
     $products->populateRelation('ProductVariant');
     return $products;
 }
示例#5
0
 public function newPost()
 {
     $this->load->model('base');
     $this->init_settings();
     ($hook = get_hook('comments_on_add')) ? eval($hook) : NULL;
     $this->load->library('user_agent');
     $this->load->library('form_validation');
     $this->load->model('base');
     $item_id = $this->parsUrl($_SERVER['HTTP_REFERER']);
     if ($this->period > 0) {
         if ($this->check_comment_period() == FALSE) {
             echo json_encode(array('answer' => 'error', 'validation_errors' => lang('The following comment can be left through', 'comments') . ' ' . $this->period . ' ' . lang('minutes', 'comments')));
             return;
         }
     }
     // Validate email and nickname from unregistered users.
     if ($this->dx_auth->is_logged_in() == FALSE) {
         ($hook = get_hook('comments_set_val_rules')) ? eval($hook) : NULL;
         $this->form_validation->set_rules('comment_email', lang('Email', 'comments'), 'trim|required|xss_clean|valid_email');
         $this->form_validation->set_rules('comment_author', lang('Your name', 'comments'), 'trim|required|xss_clean|max_length[50]');
         $this->form_validation->set_rules('comment_site', lang('Site', 'comments'), 'trim|xss_clean|max_length[250]');
     }
     // Check captcha code if captcha_check enabled and user in not admin.
     if ($this->use_captcha == TRUE and $this->dx_auth->is_admin() == FALSE) {
         ($hook = get_hook('comments_set_captcha')) ? eval($hook) : NULL;
         $this->form_validation->set_message('callback_captcha_check', lang('Wrong code protection', 'comments'));
         if ($this->dx_auth->use_recaptcha) {
             $this->form_validation->set_rules('recaptcha_response_field', lang("Code protection", 'comments'), 'trim|required|xss_clean|callback_captcha_check');
         } else {
             $this->form_validation->set_rules('captcha', lang("Code protection", 'comments'), 'trim|required|xss_clean|callback_captcha_check');
         }
     }
     if ($this->max_comment_length != 0) {
         $this->form_validation->set_rules('comment_text', lang('Comment', 'comments'), 'trim|required|xss_clean|max_length[' . $this->max_comment_length . ']');
     } else {
         $this->form_validation->set_rules('comment_text', lang('Comment', 'comments'), 'trim|required|xss_clean');
     }
     if ($this->form_validation->run($this) == FALSE) {
         ($hook = get_hook('comments_validation_failed')) ? eval($hook) : NULL;
         //$this->core->error( validation_errors() );
         //            $this->template->assign('comment_errors', validation_errors());
     } else {
         if ($this->dx_auth->is_logged_in() == FALSE) {
             ($hook = get_hook('comments_author_not_logged')) ? eval($hook) : NULL;
             $comment_author = trim(htmlspecialchars($this->input->post('comment_author')));
             $comment_email = trim(htmlspecialchars($this->input->post('comment_email')));
             // Write on cookie nickname and email
             $this->_write_cookie($comment_author, $comment_email, $this->input->post('comment_site'));
         } else {
             ($hook = get_hook('comments_author_logged')) ? eval($hook) : NULL;
             $user = $this->db->get_where('users', array('id' => $this->dx_auth->get_user_id()))->row_array();
             $comment_author = $user['username'];
             $comment_email = $user['email'];
         }
         $comment_text = trim(htmlspecialchars($this->input->post('comment_text')));
         $comment_text = str_replace("\n", '<br/>', $comment_text);
         $comment_text_plus = trim(htmlspecialchars($this->input->post('comment_text_plus')));
         $comment_text_plus = str_replace("\n", '<br/>', $comment_text_plus);
         $comment_text_minus = trim(htmlspecialchars($this->input->post('comment_text_minus')));
         $comment_text_minus = str_replace("\n", '<br/>', $comment_text_minus);
         $rate = $this->input->post('ratec');
         if ($this->input->post('ratec')) {
             if (class_exists('SProductsQuery')) {
                 if (SProductsQuery::create()->findPk($item_id) !== null) {
                     $model = SProductsRatingQuery::create()->findPk($item_id);
                     if ($model === null) {
                         $model = new SProductsRating();
                         $model->setProductId($item_id);
                     }
                     $model->setVotes($model->getVotes() + 1);
                     $model->setRating($model->getRating() + $rate);
                     $model->save();
                 }
             }
         }
     }
     if ($this->input->post('action') == 'newPost') {
         $email = $this->db->select('email')->get_where('users', array('id' => $this->dx_auth->get_user_id()), 1)->row();
         if (!validation_errors()) {
             $comment_data = array('module' => $this->module, 'user_id' => $this->dx_auth->get_user_id(), 'user_name' => $this->dx_auth->is_logged_in() ? $this->dx_auth->get_username() : trim(htmlspecialchars($this->input->post('comment_author'))), 'user_mail' => $this->dx_auth->is_logged_in() ? $email->email : trim(htmlspecialchars($this->input->post('comment_email'))), 'user_site' => htmlspecialchars($this->input->post(comment_site)), 'text' => $comment_text, 'text_plus' => $comment_text_plus, 'text_minus' => $comment_text_minus, 'item_id' => $item_id, 'status' => $this->_comment_status(), 'agent' => $this->agent->agent_string(), 'user_ip' => $this->input->ip_address(), 'date' => time(), 'rate' => $this->input->post('ratec'), 'parent' => $this->input->post('comment_parent'));
             $this->db->insert('comments', $comment_data);
             $this->_recount_comments($item_id, $comment_data['module']);
             \CMSFactory\Events::create()->registerEvent(array('commentId' => $this->db->insert_id()));
             $this->validation_errors = '';
             //return sucesfull JSON answer
             echo json_encode(array('answer' => 'sucesfull'));
         } else {
             if ($this->dx_auth->use_recaptcha) {
                 $field_name = 'recaptcha_response_field';
             } else {
                 $field_name = 'captcha';
             }
             //                if ($this->form_validation->error($field_name)) {
             $this->dx_auth->captcha();
             $cap_image = $this->dx_auth->get_captcha_image();
             //                }
             //                if ($this->use_captcha == TRUE && !$this->dx_auth->is_admin()) {
             //                    $this->dx_auth->captcha();
             //                    $data['cap_image'] = $this->dx_auth->get_captcha_image();
             //                }
             echo json_encode(array('answer' => 'error', 'validation_errors' => validation_errors(), 'cap_image' => $cap_image));
         }
     }
 }
示例#6
0
 /**
  * Change rating for pages / product
  * @return type
  */
 public function ajax_rate()
 {
     $id = $_POST['cid'];
     $type = $_POST['type'];
     $rating = (int) $_POST['val'];
     if ($id != null && $type != null && !$this->session->userdata('voted_g' . $id . $type) == true) {
         //Check if rating exists
         $check = $this->rating_model->get_rating($id, $type);
         if ($check != null) {
             $this->new_votes = $check->votes + 1;
             $this->new_rating = $check->rating + $rating;
             $data = array('votes' => $this->new_votes, 'rating' => $this->new_rating);
             $rating_res = $this->new_rating / $this->new_votes * 20;
             $votes_res = $this->new_votes;
             $this->rating_model->update_rating($id, $type, $data);
         } else {
             $data = array('id_type' => $id, 'type' => $type, 'votes' => 1, 'rating' => $rating);
             $votes_res = 1;
             $rating_res = $rating * 20;
             $this->rating_model->insert_rating($data);
         }
         //Change rating for product
         if ($type == 'product') {
             if (SProductsQuery::create()->findPk($id) !== null) {
                 $model = SProductsRatingQuery::create()->findPk($id);
                 if ($model === null) {
                     $model = new SProductsRating();
                     $model->setProductId($id);
                 }
                 $rating_res = ($model->getRating() + $rating) / ($model->getVotes() + 1) * 20;
                 $votes_res = $model->getVotes() + 1;
                 $model->setVotes($model->getVotes() + 1);
                 $model->setRating($model->getRating() + $rating);
                 $model->save();
             }
         }
         //Save in session user's info
         $this->session->set_userdata('voted_g' . $id . $type, true);
         //If ajax request than return data for with new rating and votes
         if ($this->input->is_ajax_request()) {
             return json_encode(array("rate" => "{$rating_res}", "votes" => "{$votes_res}"));
         }
     } else {
         return json_encode(array("rate" => null));
     }
 }
示例#7
0
 public function getProducts()
 {
     $this->db->select('value');
     $this->db->where('id', 1);
     $query = $this->db->get('mod_hotline_categories');
     $arr = $query->row_array();
     $arr = unserialize($arr['value']);
     $names = array(implode($arr, ','));
     $query = $this->db->query("\n                           SELECT shop_category.id, shop_category.parent_id, shop_category_i18n.name  FROM shop_category\n                           LEFT JOIN shop_category_i18n ON (shop_category_i18n.id = shop_category.id)\n                           WHERE shop_category.id IN (" . $names[0] . " ) AND shop_category_i18n.locale = 'ru'\n                        ");
     $this->categories = $query->result_array();
     $Ids = $this->db->select('id')->where_in('category_id', $arr)->get('shop_products')->result_array();
     foreach ($Ids as $id) {
         $productsIds[] = $id['id'];
     }
     $products = SProductsQuery::create()->distinct()->filterById($productsIds)->leftJoin('ProductVariant')->useProductVariantQuery()->filterByStock(array('min' => 1))->endUse()->filterByActive(true)->find();
     $products->populateRelation('ProductVariant');
     return $products;
 }
示例#8
0
 /**
  * Add comment
  * @deprecated ImageCMS 4.3
  */
 public function add()
 {
     ($hook = get_hook('comments_on_add')) ? eval($hook) : NULL;
     // Load comments model
     $this->load->model('base');
     $this->init_settings();
     // Check access only for registered users
     if ($this->can_comment === 1 and $this->dx_auth->is_logged_in() == FALSE) {
         ($hook = get_hook('comments_login_for_comments')) ? eval($hook) : NULL;
         $this->core->error(lang('Only authorized users can leave comments.', 'comments') . '<a href="%s" class="loginAjax"> ' . lang('log in, please.', 'comments') . '</ a>');
     }
     $item_id = $this->input->post('comment_item_id');
     // Check if page comments status.
     if ($this->module == 'core') {
         if ($this->base->get_item_comments_status($item_id) == FALSE) {
             ($hook = get_hook('comments_page_comments_disabled')) ? eval($hook) : NULL;
             $this->core->error(lang('Commenting on recording is prohibited.', 'comments'));
         }
     }
     $this->load->library('user_agent');
     $this->load->library('form_validation');
     //        $this->form_validation->CI = & $this;
     // Check post comment period.
     if ($this->period > 0) {
         if ($this->check_comment_period() == FALSE) {
             ($hook = get_hook('comments_period_error')) ? eval($hook) : NULL;
             $this->core->error(sprintf(lang('Allowed to comment once in %s minutes.', 'comments'), $this->period));
         }
     }
     // Validate email and nickname from unregistered users.
     if ($this->dx_auth->is_logged_in() == FALSE) {
         ($hook = get_hook('comments_set_val_rules')) ? eval($hook) : NULL;
         $this->form_validation->set_rules('comment_email', lang('Email', 'comments'), 'trim|required|xss_clean|valid_email');
         $this->form_validation->set_rules('comment_author', lang('Your name', 'comments'), 'trim|required|xss_clean|max_length[50]');
         $this->form_validation->set_rules('comment_site', lang('Site', 'comments'), 'trim|xss_clean|max_length[250]');
     }
     // Check captcha code if captcha_check enabled and user in not admin.
     if ($this->use_captcha == TRUE and $this->dx_auth->is_admin() == FALSE) {
         ($hook = get_hook('comments_set_captcha')) ? eval($hook) : NULL;
         if ($this->dx_auth->use_recaptcha) {
             $this->form_validation->set_rules('recaptcha_response_field', lang("Code protection"), 'trim|required|xss_clean|callback_captcha_check');
         } else {
             $this->form_validation->set_rules('captcha', lang("Code protection"), 'trim|required|xss_clean|callback_captcha_check');
         }
     }
     $this->form_validation->set_rules('comment_text', lang('Comment', 'comments'), 'trim|required|xss_clean|max_length[' . $this->max_comment_length . ']');
     if ($this->form_validation->run($this) == FALSE) {
         ($hook = get_hook('comments_validation_failed')) ? eval($hook) : NULL;
         //$this->core->error( validation_errors() );
         $this->template->assign('comment_errors', validation_errors());
     } else {
         if ($this->dx_auth->is_logged_in() == FALSE) {
             ($hook = get_hook('comments_author_not_logged')) ? eval($hook) : NULL;
             $comment_author = trim(htmlspecialchars($this->input->post('comment_author')));
             $comment_email = trim(htmlspecialchars($this->input->post('comment_email')));
             // Write on cookie nickname and email
             $this->_write_cookie($comment_author, $comment_email, $this->input->post('comment_site'));
         } else {
             ($hook = get_hook('comments_author_logged')) ? eval($hook) : NULL;
             $user = $this->db->get_where('users', array('id' => $this->dx_auth->get_user_id()))->row_array();
             $comment_author = $user['username'];
             $comment_email = $user['email'];
         }
         $comment_text = trim(htmlspecialchars($this->input->post('comment_text')));
         $comment_text = str_replace("\n", '<br/>', $comment_text);
         $comment_text_plus = trim(htmlspecialchars($this->input->post('comment_text_plus')));
         $comment_text_plus = str_replace("\n", '<br/>', $comment_text_plus);
         $comment_text_minus = trim(htmlspecialchars($this->input->post('comment_text_minus')));
         $comment_text_minus = str_replace("\n", '<br/>', $comment_text_minus);
         $rate = $this->input->post('ratec');
         if ($this->input->post('ratec')) {
             if (SProductsQuery::create()->findPk($item_id) !== null) {
                 $model = SProductsRatingQuery::create()->findPk($item_id);
                 if ($model === null) {
                     $model = new SProductsRating();
                     $model->setProductId($item_id);
                 }
                 $model->setVotes($model->getVotes() + 1);
                 $model->setRating($model->getRating() + $rate);
                 $model->save();
             }
         }
         $parent = $this->input->post('parent');
         if ($comment_text != '') {
             $comment_data = array('module' => $this->module, 'user_id' => $this->dx_auth->get_user_id(), 'user_name' => htmlspecialchars($comment_author), 'user_mail' => $comment_email, 'user_site' => htmlspecialchars($this->input->post('comment_site')), 'text' => $comment_text, 'text_plus' => $comment_text_plus, 'text_minus' => $comment_text_minus, 'item_id' => $item_id, 'status' => $this->_comment_status(), 'agent' => $this->agent->agent_string(), 'user_ip' => $this->input->ip_address(), 'date' => time(), 'rate' => $rate, 'parent' => $parent);
             ($hook = get_hook('comments_db_insert')) ? eval($hook) : NULL;
             $id = $this->base->add($comment_data);
             if ($comment_data['status'] == 0) {
                 ($hook = get_hook('comments_update_count')) ? eval($hook) : NULL;
                 $this->db->set('comments_count', 'comments_count + 1', FALSE);
                 $this->db->where('id', $comment_data['item_id']);
                 $this->db->update('content');
             }
             // Drop cached comments
             $this->cache->delete('comments_' . $item_id . $this->module, 'comments');
             ($hook = get_hook('comments_goes_redirect')) ? eval($hook) : NULL;
             // Redirect back to page
             //redirect($this->input->post('redirect'));
             if ($_POST['redirect']) {
                 redirect(substr($this->input->post('redirect'), 0, 1) == '/' ? $this->input->post('redirect') : '/' . $this->input->post('redirect'), 301);
             } else {
                 redirect('/');
             }
         } else {
             ($hook = get_hook('comments_empty_text')) ? eval($hook) : NULL;
             $this->core->error(lang('Fill text in comment.', 'comments'));
         }
     }
 }
示例#9
0
 function get_entity_mod($w)
 {
     $ci =& get_instance();
     switch ($w) {
         case $w == 'product_0':
             return 'product - all';
             break;
         case $w == 'shop_category_0':
             return 'shop_category - all';
             break;
         case $w == 'brand_0':
             return 'brand - all';
             break;
         case $w == 'category_0':
             return 'category - all';
             break;
         case $w == 'page_0':
             return 'page - all';
             break;
         case strstr($w, 'product'):
             $id = (int) str_replace('product_', '', $w);
             $prod = SProductsQuery::create()->findPk($id);
             if ($prod) {
                 return 'product - ' . $prod->getName();
             }
             break;
         case strstr($w, 'shop_category'):
             $id = (int) str_replace('shop_category_', '', $w);
             $cat = SCategoryQuery::create()->findPk($id);
             if ($cat) {
                 return 'shop_category - ' . $cat->getName();
             }
             break;
         case strstr($w, 'brand'):
             $id = (int) str_replace('brand_', '', $w);
             $br = SBrandsQuery::create()->findPk($id);
             if ($br) {
                 return 'brand - ' . $br->getName();
             }
             break;
         case strstr($w, 'page'):
             $id = (int) str_replace('page_', '', $w);
             $page = $ci->db->where('id', $id)->get('content')->result_array();
             if (count($page) > 0) {
                 return 'page - ' . $page[0]['title'];
             }
             break;
         case strstr($w, 'category'):
             $id = (int) str_replace('category_', '', $w);
             $page = $ci->db->where('id', $id)->get('category')->result_array();
             if (count($page) > 0) {
                 return 'category - ' . $page[0]['name'];
             }
             break;
         case strstr($w, 'main'):
             return 'main - ' . lang('Main', 'banners');
             break;
         default:
             break;
     }
 }