Esempio n. 1
0
 private function build_tree($params)
 {
     $db = JFactory::getDBO();
     $categories = $params->get('categories', array());
     $sql = $db->getQuery(true);
     $sql->select('kc.*')->from('#__ksenmart_categories as kc')->where('kc.published=1')->order('kc.ordering');
     if ($categories) {
         $sql->where('kc.id IN(' . implode(', ', $categories) . ') OR kc.parent_id IN(' . implode(', ', $categories) . ')');
     }
     KSMedia::setItemMainImageToQuery($sql, 'category', 'kc.');
     $db->setQuery($sql);
     $rows = $db->loadObjectList('id');
     $top_parent = (object) array('id' => 0, 'children' => array());
     $menu = array(0 => $top_parent);
     foreach ($rows as $k => $v) {
         if (!empty($v->folder)) {
             $v->img = KSMedia::resizeImage($v->filename, $v->folder, $params->get('img_width', 200), $params->get('img_height', 200), json_decode($v->params, true));
         }
         if (isset($menu[$k])) {
             $v->children = $menu[$k]->children;
         } else {
             $v->children = array();
         }
         $menu[$k] = $v;
         if (!isset($menu[$v->parent_id])) {
             $menu[$v->parent_id] = new stdClass();
             $menu[$v->parent_id]->children = array();
         }
         $menu[$v->parent_id]->children[$v->id] = $v;
     }
     $this->menu = $menu;
 }
Esempio n. 2
0
 public static function getDiscounts($discounts, $params)
 {
     if (empty($discounts)) {
         return array();
     }
     $arr_params = $params->toArray();
     $types = isset($arr_params['types']) && is_array($arr_params['types']) && count($arr_params['types']) ? $arr_params['types'] : array('all');
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('d.id, d.title, d.content, d.from_date, d.to_date, d.info_methods');
     $query->from('#__ksenmart_discounts as d');
     $query->where("d.id IN (" . implode(',', $discounts) . ")");
     if (!in_array('all', $types)) {
         foreach ($types as &$type) {
             $type = $db->quote($type);
         }
         $query->where('d.type in (' . implode(',', $types) . ')');
     }
     $query = KSMedia::setItemMainImageToQuery($query, 'discount', 'd.');
     $results = $db->setQuery($query)->loadObjectList('id');
     foreach ($results as $key => $res) {
         $content = JDispatcher::getInstance()->trigger('onGetDiscountContent', array($res->id));
         if (isset($content[0]) && !empty($content[0])) {
             $results[$key]->content = $content[0];
         }
         $info_methods = json_decode($res->info_methods, true);
         $results[$key]->image = !empty($results[$key]->filename) ? KSMedia::resizeImage($results[$key]->filename, $results[$key]->folder, $params->get('img_width', 200), $params->get('img_height', 100), json_decode($results[$key]->params, true)) : '';
         if (!in_array('module', $info_methods)) {
             unset($results[$key]);
         }
     }
     unset($res);
     return $results;
 }
Esempio n. 3
0
 function get_set_childs()
 {
     $db = JFactory::getDBO();
     $id = JRequest::getInt('id');
     $html = '';
     $model = $this->getModel('catalog');
     $view = $this->getView('catalog', 'html');
     $view->setModel($model, true);
     $query = $db->getQuery(true);
     $query->select('p.*,pp.product_id as set_id')->from('#__ksenmart_products as p')->innerjoin('#__ksenmart_products_relations as pp on pp.relative_id=p.id')->where('pp.product_id=' . $id)->where('pp.relation_type=' . $db->quote('set'))->order('p.ordering');
     $query = KSMedia::setItemMainImageToQuery($query);
     $db->setQuery($query);
     $items = $db->loadObjectList();
     foreach ($items as $item) {
         $item->small_img = KSMedia::resizeImage($item->filename, $item->folder, $model->params->get('admin_product_thumb_image_width'), $model->params->get('admin_product_thumb_image_heigth'), json_decode($item->params, true));
         $item->medium_img = KSMedia::resizeImage($item->filename, $item->folder, $model->params->get('admin_product_medium_image_width'), $model->params->get('admin_product_medium_image_heigth'), json_decode($item->params, true));
         $view->setLayout('default_item_form');
         $view->item =& $item;
         ob_start();
         $view->display();
         $html .= ob_get_contents();
         ob_end_clean();
     }
     $response = array('html' => $html, 'message' => array(), 'errors' => 0);
     $response = json_encode($response);
     JFactory::getDocument()->setMimeEncoding('application/json');
     echo $response;
     JFactory::getApplication()->close();
 }
Esempio n. 4
0
 function getManufacturers($group)
 {
     $db = JFactory::getDBO();
     $session_manufacturers = JRequest::getVar('manufacturers', array());
     JArrayHelper::toInteger($session_manufacturers);
     $query = $db->getQuery(true);
     $query->select('
     		km.*,
     		kf.filename,
     		kf.folder,
     		kf.params
     	')->from('#__ksenmart_manufacturers as km')->leftjoin("#__ksenmart_countries as kc on km.country=kc.id")->leftjoin("#__ksenmart_files as kf on kc.id=kf.owner_id and kf.owner_type='country'")->where('km.published=1')->order('km.title');
     if ($group) {
         $query->select('
                 kc.id AS country_id,
                 kc.title AS country_title
             ');
     } else {
         $query->group('km.id');
     }
     $db->setQuery($query);
     $manufacturers = $db->loadObjectList('id');
     $tmpManufacturers = array();
     foreach ($manufacturers as &$manufacturer) {
         $manufacturer->selected = in_array($manufacturer->id, $session_manufacturers) ? true : false;
         if (!empty($manufacturer->folder)) {
             $manufacturer->small_img = KSMedia::resizeImage($manufacturer->filename, $manufacturer->folder, 25, 30, json_decode($manufacturer->params, true));
         }
         unset($manufacturer->filename);
         unset($manufacturer->folder);
         $manufacturer->link = JRoute::_('index.php?option=com_ksenmart&view=catalog&manufacturers[]=' . $manufacturer->id . '&Itemid=' . KSSystem::getShopItemid());
         if ($group) {
             $tmpManufacturers[$manufacturer->country_title][] = $manufacturer;
         }
     }
     if (!$tmpManufacturers) {
         $tmpManufacturers = $manufacturers;
     }
     return $tmpManufacturers;
 }
Esempio n. 5
0
 private static function getEmptyUserObject()
 {
     global $ext_name_com;
     $session = JFactory::getSession();
     $params = JComponentHelper::getParams($ext_name_com);
     $user = new stdClass();
     $user->id = 0;
     $user->region_id = $session->get('user_region', 0);
     $user->phone = $session->get('phone_code', '');
     $user->watched = array();
     $user->favorites = array();
     $user->name = JText::_('ksm_users_anonym');
     $user->username = null;
     $user->email = null;
     $user->groups = array();
     $user->usertype = null;
     $user->block = null;
     $user->city = null;
     $user->zip = null;
     $user->street = null;
     $user->house = null;
     $user->floor = null;
     $user->flat = null;
     $user->coords = null;
     $user->address = null;
     $user->sendmails = null;
     $user->params = null;
     $user->settings = json_decode('{"catalog_layout":"' . $params->get('catalog_default_view', 'grid') . '"}');
     $user->folder = 'users';
     $user->filename = 'no.jpg';
     $user->small_img = KSMedia::resizeImage($user->filename, $user->folder, $params->get('admin_product_thumb_image_width', 36), $params->get('admin_product_thumb_image_heigth', 36));
     $user->medium_img = KSMedia::resizeImage($user->filename, $user->folder, $params->get('admin_product_medium_image_width', 120), $params->get('admin_product_medium_image_heigth', 120));
     KSUsers::setAvatarLogoInObject($user);
     return $user;
 }
Esempio n. 6
0
 function saveRegion($data)
 {
     $this->onExecuteBefore('saveRegion', array(&$data));
     $data['alias'] = KSFunctions::CheckAlias($data['alias'], $data['id']);
     $data['alias'] = $data['alias'] == '' ? KSFunctions::GenAlias($data['title']) : $data['alias'];
     $data['country_id'] = isset($data['country_id']) ? $data['country_id'] : 0;
     $table = $this->getTable('regions');
     if (empty($data['id'])) {
         $query = $this->_db->getQuery(true);
         $query->update('#__ksenmart_regions')->set('ordering=ordering+1');
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     if (!$table->bindCheckStore($data)) {
         $this->setError($table->getError());
         return false;
     }
     $id = $table->id;
     KSMedia::saveItemMedia($id, $data, 'region', 'regions');
     $on_close = 'window.parent.RegionsList.refreshList();';
     $return = array('id' => $id, 'on_close' => $on_close);
     $this->onExecuteAfter('saveRegion', array(&$return));
     return $return;
 }
Esempio n. 7
0
 function savePayment($data)
 {
     $this->onExecuteBefore('savePayment', array(&$data));
     $data['params'] = isset($data['params']) && is_array($data['params']) ? json_encode($data['params']) : json_encode(array());
     $data['regions'] = isset($data['regions']) && is_array($data['regions']) ? $data['regions'] : array();
     $data['published'] = isset($data['published']) ? $data['published'] : 0;
     $data['images'] = isset($data['images']) ? $data['images'] : array();
     foreach ($data['regions'] as &$country) {
         $country = array_filter($country, 'KSFunctions::filterArray');
     }
     unset($country);
     $data['regions'] = json_encode($data['regions']);
     $table = $this->getTable('payments');
     if (empty($data['id'])) {
         $query = $this->_db->getQuery(true);
         $query->update('#__ksenmart_payments')->set('ordering=ordering+1');
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     if (!$table->bindCheckStore($data)) {
         $this->setError($table->getError());
         return false;
     }
     $id = $table->id;
     KSMedia::saveItemMedia($id, $data, 'payment', 'payments');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onAfterSavePayment', array($id));
     $on_close = 'window.parent.PaymentsList.refreshList();';
     $return = array('id' => $id, 'on_close' => $on_close);
     $this->onExecuteAfter('savePayment', array(&$return));
     return $return;
 }
Esempio n. 8
0
 function SaveDiscount($data)
 {
     $this->onExecuteBefore('SaveDiscount', array(&$data));
     $data['categories'] = is_array($data['categories']) ? json_encode($data['categories']) : json_encode(array());
     $data['manufacturers'] = is_array($data['manufacturers']) ? json_encode($data['manufacturers']) : json_encode(array());
     $data['regions'] = isset($data['regions']) && is_array($data['regions']) ? $data['regions'] : array();
     $data['params'] = is_array($data['params']) ? json_encode($data['params']) : json_encode(array());
     $data['user_actions'] = isset($data['user_actions']) && is_array($data['user_actions']) ? json_encode($data['user_actions']) : json_encode(array());
     $data['user_groups'] = isset($data['user_groups']) && is_array($data['user_groups']) ? json_encode($data['user_groups']) : json_encode(array());
     $data['info_methods'] = isset($data['info_methods']) && is_array($data['info_methods']) ? json_encode($data['info_methods']) : json_encode(array());
     $data['from_date'] = date('Y-m-d', strtotime($data['from_date']));
     $data['to_date'] = date('Y-m-d', strtotime($data['to_date']));
     $data['sum'] = isset($data['sum']) ? $data['sum'] : 0;
     $data['enabled'] = isset($data['enabled']) ? $data['enabled'] : 0;
     $data['images'] = isset($data['images']) ? $data['images'] : array();
     foreach ($data['regions'] as &$country) {
         $country = array_filter($country, 'KSFunctions::filterArray');
     }
     unset($country);
     $data['regions'] = json_encode($data['regions']);
     $table = $this->getTable('discounts');
     if (empty($data['id'])) {
         $query = $this->_db->getQuery(true);
         $query->update('#__ksenmart_discounts')->set('ordering=ordering+1');
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     if (!$table->bindCheckStore($data)) {
         $this->setError($table->getError());
         return false;
     }
     $id = $table->id;
     KSMedia::saveItemMedia($id, $data, 'discount', 'discounts');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onAfterSaveDiscount', array($id));
     $on_close = 'window.parent.DiscountsList.refreshList();';
     $return = array('id' => $id, 'on_close' => $on_close);
     $this->onExecuteAfter('SaveDiscount', array(&$return));
     return $return;
 }
Esempio n. 9
0
 /**
  * KsenMartModelcatalog::getManufacturer()
  * 
  * @return
  */
 public function getManufacturer()
 {
     $this->onExecuteBefore('getManufacturer');
     if (!empty($this->_manufacturers)) {
         $query = $this->_db->getQuery(true);
         $query->select('
                 m.id,
                 m.title,
                 m.alias,
                 m.content,
                 m.introcontent,
                 m.country,
                 m.metatitle,
                 m.metadescription,
                 m.metakeywords,
                 f.filename,
                 f.folder,
                 f.params
             ')->from('#__ksenmart_manufacturers AS m')->leftjoin('#__ksenmart_files AS f ON m.id=f.owner_id AND f.owner_type=' . $this->_db->quote('manufacturer'))->where('m.published=1')->where('m.id=' . $this->_manufacturers[0]);
         $this->_db->setQuery($query);
         $manufacturer = $this->_db->loadObject();
         if (!empty($manufacturer)) {
             $manufacturer->image = KSMedia::resizeImage($manufacturer->filename, $manufacturer->folder, $this->_params->get('thumb_width'), $this->_params->get('thumb_height'));
         }
         $this->onExecuteAfter('getManufacturer', array(&$manufacturer));
         return $manufacturer;
     }
     return false;
 }
Esempio n. 10
0
 public function getPaymentsByRegionId($region_id)
 {
     $this->onExecuteBefore('getPaymentsByRegionId', array(&$region_id));
     $payments = array();
     if (!empty($region_id) && $region_id > 0) {
         $query = $this->_db->getQuery(true);
         $query->select('
                 p.id,
                 p.title,
                 p.type,
                 p.regions,
                 p.description,
                 p.params,
                 f.filename,
                 f.folder,
                 f.params AS params_f,					
                 p.ordering
             ')->from('#__ksenmart_payments AS p')->leftjoin('#__ksenmart_files AS f ON f.owner_type=' . $this->_db->quote('payment') . ' AND f.owner_id=p.id')->where('p.published=1')->order('p.ordering');
         $this->_db->setQuery($query);
         $db_payments = $this->_db->loadObjectList();
         foreach ($db_payments as $db_payment) {
             if (!$this->checkRegion($db_payment->regions, $region_id)) {
                 continue;
             }
             $db_payment->icon = !empty($db_payment->filename) ? KSMedia::resizeImage($db_payment->filename, $db_payment->folder, 80, 80, json_decode($db_payment->params_f, true)) : '';
             $payments[] = $db_payment;
         }
     }
     $this->onExecuteAfter('getPaymentsByRegionId', array(&$payments));
     return $payments;
 }
Esempio n. 11
0
 public function getInput()
 {
     $document = JFactory::getDocument();
     $document->addScript(JURI::base() . 'components/com_ksen/assets/js/swfupload/swfupload.js');
     $document->addScript(JURI::base() . 'components/com_ksen/assets/js/swfupload/swfupload.queue.js');
     $document->addScript(JURI::base() . 'components/com_ksen/assets/js/swfupload/js/fileprogress.js');
     $document->addScript(JURI::base() . 'components/com_ksen/assets/js/swfupload/js/handlers.js');
     $document->addScript(JURI::base() . 'components/com_ksen/assets/js/swfupload/config_image.js');
     $extension = (string) $this->element['extension'];
     $html = '';
     $keys = array_keys($this->value);
     if (count($keys) == 0 || $keys[0] > 0) {
         $html .= '<div class="thumb-img photos">';
         $html .= '  <div class="photos-row">';
     }
     foreach ($this->value as $file) {
         $cparams = JComponentHelper::getParams($extension);
         $source_filename = JPATH_ROOT . DS . 'media' . DS . $extension . DS . $file->media_type . 's' . DS . $file->folder . DS . 'original' . DS . $file->filename;
         JForm::addFormPath(JPATH_ADMINISTRATOR . '/components/com_ksen/models/forms/');
         $form = JForm::getInstance('com_ksen.image' . $file->id, 'image', array('control' => $this->name . '[' . $file->id . '][params]'));
         $params = (array) json_decode($file->params);
         $keys = array('title', 'watermark', 'displace', 'halign', 'valign');
         foreach ($keys as $k) {
             if (array_key_exists($k, $params)) {
                 $v = $params[$k];
             } else {
                 $v = $cparams->get($k, null);
             }
             if ($v !== null) {
                 $form->setValue($k, null, $v);
             }
         }
         $thumb_url = KSMedia::resizeImage($source_filename, $file->folder, $cparams->get('admin_product_medium_image_width', 120), $cparams->get('admin_product_medium_image_height', 120), $params, $extension);
         $dst_filename = basename($thumb_url);
         $html .= '<div class="photo">';
         $html .= '<span class="del-img"></span>';
         $html .= '
             <div>
                 <img class="image-preview" src="' . $thumb_url . '">
             </div>
         ';
         $html .= '<div class="popupForm">
                     <div class="form">
                         <div class="heading">
                             <h3>Параметры изображения</h3>
                             <div class="save-close">
                                 <input type="button" class="close" onclick="iparamClose(this);return false;" />
                             </div>
                         </div>
                         <div class="edit">
                             <table width="100%">
                                 <tr>
                                     <td class="onecol" id="iparamscontent">';
         $html .= '
         <div id="images-preview">
             <div class="leftcol">';
         foreach ($keys as $k) {
             $html .= '<div class="row">' . $form->getLabel($k) . $form->getInput($k) . '</div>';
         }
         $html .= '
             </div>
             <div class="rightcol">
                 <div class="preview">
                     <table>
                         <tr>
                             <td style="text-align: center;vertical-align: middle;">
                                 <img src="' . $thumb_url . '" alt="" class="previewxa" />
                             </td>
                         </tr>
                     </table>
                 </div>
             </div>
         </div>';
         $html .= '</td>
                                 </tr>
                             </table>
                         </div>
                     </div>';
         $html .= '</div>';
         $html .= '<input type="hidden" value="' . $file->ordering . '" class="ordering" name="' . $this->name . '[' . $file->id . '][ordering]" />';
         $html .= '<input type="hidden" class="task" value="save"  name="' . $this->name . '[' . $file->id . '][task]" >';
         $html .= '<input type="hidden" class="task filename" value="' . basename($file->filename) . '"  name="' . $this->name . '[' . $file->id . '][filename]" >';
         $html .= '</div>';
     }
     $keys = array_keys($this->value);
     if (count($keys) == 0 || $keys[0] > 0) {
         $html .= '  </div>';
         $html .= '</div>';
         $html .= '<br clear="both">';
         $html .= '<div class="uploadButtons">';
         $html .= '  <span id="spanButtonPlaceHolder"></span>';
         $html .= '  <input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />';
         $html .= '</div>';
         $html .= '<div class="fieldset flash" id="fsUploadProgress">';
         $html .= '</div>';
         $html = KSSystem::wrapFormField('slidemodule', $this->element, $html);
     }
     $session = JFactory::getSession();
     $script = '
         var session_id="' . $session->getId() . '";
         var session_name="' . $session->getName() . '";
         var token="' . JSession::getFormToken() . '";
         var upload_to="' . $this->element['upload_to'] . '";
         var upload_folder="' . $this->element['upload_folder'] . '";
     ';
     $document->addScriptDeclaration($script);
     return $html;
 }
Esempio n. 12
0
 public function getImages()
 {
     $this->onExecuteBefore('getImages');
     $query = $this->_db->getQuery(true);
     $query->select($this->_db->qn(array('f.id', 'f.owner_id', 'f.media_type', 'f.owner_type', 'f.folder', 'f.filename', 'f.mime_type', 'f.title', 'f.ordering', 'f.params')))->from($this->_db->qn('#__ksenmart_files', 'f'))->where($this->_db->qn('f.owner_id') . '=' . $this->_db->q($this->_id))->where($this->_db->qn('f.owner_type') . '=' . $this->_db->q('product'))->where($this->_db->qn('f.media_type') . '=' . $this->_db->q('image'))->order('ordering');
     $this->_db->setQuery($query);
     $rows = $this->_db->loadObjectList();
     for ($k = 0; $k < count($rows); $k++) {
         $rows[$k]->img_small = KSMedia::resizeImage($rows[$k]->filename, $rows[$k]->folder, $this->params->get('mini_thumb_width', 130), $this->params->get('mini_thumb_height', 80), json_decode($rows[$k]->params, true));
         $rows[$k]->img = KSMedia::resizeImage($rows[$k]->filename, $rows[$k]->folder, $this->params->get('middle_width', 200), $this->params->get('middle_height', 200));
         $rows[$k]->img_link = KSMedia::resizeImage($rows[$k]->filename, $rows[$k]->folder, $this->params->get('full_width', 900), $this->params->get('full_height', 900));
     }
     $this->onExecuteAfter('getImages', array(&$rows));
     return $rows;
 }
Esempio n. 13
0
 function saveUser($data)
 {
     $this->onExecuteBefore('saveUser', array(&$data));
     $data['name'] = '';
     if (!empty($data['last_name'])) {
         $data['name'] .= $data['last_name'] . ' ';
     }
     if (!empty($data['first_name'])) {
         $data['name'] .= $data['first_name'] . ' ';
     }
     if (!empty($data['middle_name'])) {
         $data['name'] .= $data['middle_name'];
     }
     if ($data['social'] == 1) {
         $data['email'] = $data['username'] . '@email.ru';
     }
     $user = JUser::getInstance($data['id']);
     if (!$user->bind($data)) {
         $this->setError($user->getError());
         return false;
     }
     if (!$user->save()) {
         $this->setError($user->getError());
         return false;
     }
     $id = $user->id;
     $query = $this->_db->getQuery(true);
     $query->select('id')->from('#__ksen_users')->where('id=' . (int) $data['id']);
     $this->_db->setQuery($query);
     $count = $this->_db->loadResult();
     if (empty($count)) {
         $query = $this->_db->getQuery(true);
         $query->insert('#__ksen_users')->columns('id')->values(array($id));
         $this->_db->setQuery($query);
         $this->_db->query();
         $data['id'] = $user->id;
     }
     $table = $this->getTable('KMUsers');
     if (!$table->bindCheckStore($data)) {
         $this->setError($table->getError());
         return false;
     }
     KSMedia::saveItemMedia($id, $data, 'user', 'users');
     $in = array();
     foreach ($data['addresses'] as $k => $v) {
         $v['user_id'] = $id;
         $table = $this->getTable('useraddresses');
         if ($k > 0) {
             $v['id'] = $k;
         }
         if (!$table->bindCheckStore($v)) {
             $this->setError($table->getError());
             return false;
         }
         $in[] = $table->id;
     }
     $query = $this->_db->getQuery(true);
     $query->delete('#__ksen_user_addresses')->where('user_id=' . $id);
     if (count($in)) {
         $query->where('id not in (' . implode(',', $in) . ')');
     }
     $this->_db->setQuery($query);
     $this->_db->query();
     $in = array();
     foreach ($data['fields'] as $k => $v) {
         $value = array('user_id' => $id, 'field_id' => $k, 'value' => $v);
         $table = $this->getTable('userfieldsvalues');
         if (!$table->bindCheckStore($value)) {
             $this->setError($table->getError());
             return false;
         }
         $in[] = $table->id;
     }
     $query = $this->_db->getQuery(true);
     $query->delete('#__ksen_user_fields_values')->where('user_id=' . $id);
     if (count($in)) {
         $query->where('id not in (' . implode(',', $in) . ')');
     }
     $this->_db->setQuery($query);
     $this->_db->query();
     $on_close = 'window.parent.UsersList.refreshList();';
     $return = array('id' => $id, 'on_close' => $on_close);
     $this->onExecuteAfter('saveUser', array(&$return));
     return $return;
 }
Esempio n. 14
0
    public function getInput()
    {
        $db = JFactory::getDBO();
        $params = JComponentHelper::getParams('com_ksenmart');
        $html = '';
        $html .= '<div class="positions">';
        $html .= '	<div id="ksm-slidemodule-commentproduct-container">';
        if ($this->value > 0) {
            $query = $db->getQuery(true);
            $query->select('p.*')->from('#__ksenmart_products as p')->where('p.id=' . $this->value);
            $query = KSMedia::setItemMainImageToQuery($query);
            $db->setQuery($query);
            $product = $db->loadObject();
            if (!count($product)) {
                $product = new stdClass();
                $product->title = JText::_('ksm_comments_comment_deletedproduct_title');
                $product->small_img = KSMedia::resizeImage('', 'products', $params->get('admin_product_medium_image_width'), $params->get('admin_product_medium_image_heigth'));
            } else {
                $product->small_img = KSMedia::resizeImage($product->filename, $product->folder, $params->get('admin_product_thumb_image_width'), $params->get('admin_product_thumb_image_heigth'), json_decode($product->params, true));
            }
            $html .= '	<div class="position">';
            $html .= '		<div class="col1">';
            $html .= '			<div class="img"><img alt="" src="' . $product->small_img . '"></div>';
            $html .= '			<div class="name">' . $product->title . '</div>';
            $html .= '		</div>';
            $html .= '		<a href="#" class="del"></a>';
            $html .= '		<input type="hidden" name="' . $this->name . '" value="' . $this->value . '">';
            $html .= '	</div>';
        } else {
            $html .= '	<div class="position no-items">';
            $html .= '		<div class="col1">' . JText::_('ksm_comments_comment_no_product') . '</div>';
            $html .= '		<input type="hidden" name="' . $this->name . '" value="' . $this->value . '">';
            $html .= '	</div >';
        }
        $html .= '	</div>';
        if ($this->value == 0) {
            $html .= '<div class="row">';
            $html .= '	<a href="' . JRoute::_('index.php?option=com_ksenmart&view=catalog&layout=search&items_tpl=commentproduct&items_to=ksm-slidemodule-commentproduct-container&tmpl=component') . '" class="add">' . JText::_('ksm_add') . '</a>';
            $html .= '</div>';
        }
        $html .= '</div>';
        $script = '
		jQuery(document).ready(function(){
				
			jQuery("body").on("click", ".ksm-slidemodule-commentproduct .add", function(){
				var url=jQuery(this).attr("href");
				jQuery(".ksm-slidemodule-commentproduct input[type=\'hidden\']").each(function(){
					url+="&excluded[]="+jQuery(this).val();
				});
				url+="&excluded[]=";
				var width=jQuery(window).width();
				var height=jQuery(window).height();
				openPopupWindow(url,width,height);
				return false;
			});
			
			jQuery("body").on("click", ".ksm-slidemodule-commentproduct .del", function(){
				jQuery(this).parents(".position:first").remove();
				jQuery("#ksm-slidemodule-commentproduct-container").html("<input type=hidden id=jformproduct_id name=' . $this->name . ' value=0>");
				onChangeProduct();
				return false;
			});
			
		});
		
		function onChangeProduct()
		{
			var data={};
			var vars={};
			var form=jQuery(".form");
			data["model"]="comments";
			data["form"]="comment";
			data["fields"]=["product_id"];
			vars["product_id"]=form.find("#jformproduct_id").val();			
			data["vars"]=vars;
			data["id"]=form.find(".id").val();
			KMRenewFormFields(data);
		}	

		function afterAddingItems()
		{
			jQuery(".ksm-slidemodule-commentproduct .position:first").remove();
			onChangeProduct();
		}		
		';
        $document = JFactory::getDocument();
        $document->addScriptDeclaration($script);
        return $html;
    }
Esempio n. 15
0
 function SaveShipping($data)
 {
     $this->onExecuteBefore('SaveShipping', array(&$data));
     $data['params'] = isset($data['params']) && is_array($data['params']) ? json_encode($data['params']) : json_encode(array());
     $data['regions'] = isset($data['regions']) && is_array($data['regions']) ? $data['regions'] : array();
     $data['published'] = isset($data['published']) ? $data['published'] : 0;
     $data['user_fields'] = isset($data['user_fields']) ? $data['user_fields'] : array();
     $data['images'] = isset($data['images']) ? $data['images'] : array();
     foreach ($data['regions'] as &$country) {
         $country = array_filter($country, 'KSFunctions::filterArray');
     }
     unset($country);
     $data['regions'] = json_encode($data['regions']);
     $table = $this->getTable('shippings');
     if (empty($data['id'])) {
         $query = $this->_db->getQuery(true);
         $query->update('#__ksenmart_shippings')->set('ordering=ordering+1');
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     if (!$table->bindCheckStore($data)) {
         $this->setError($table->getError());
         return false;
     }
     $id = $table->id;
     KSMedia::saveItemMedia($id, $data, 'shipping', 'shippings');
     $in = array();
     foreach ($data['user_fields'] as $key => $field) {
         $key = (int) $key;
         if ($key > 0) {
             $field['id'] = $key;
         }
         $field['shipping_id'] = $id;
         $field['required'] = isset($field['required']) ? $field['required'] : 0;
         $table = $this->getTable('ShippingFields');
         if (!$table->bindCheckStore($field)) {
             $this->setError($table->getError());
             return false;
         }
         $in[] = $table->id;
         if ($field['type'] == 'select') {
             foreach ($field['values'] as $key => $value) {
                 $key = (int) $key;
                 if ($key > 0) {
                     $value['id'] = $key;
                 }
                 $value['field_id'] = $table->id;
                 $vtable = $this->getTable('ShippingFieldsValues');
                 if (!$vtable->bindCheckStore($value)) {
                     $this->setError($vtable->getError());
                     return false;
                 }
             }
         }
     }
     foreach ($data['address_fields'] as $key => $field) {
         $key = (int) $key;
         if ($key > 0) {
             $field['id'] = $key;
         }
         $field['shipping_id'] = $id;
         $field['required'] = isset($field['required']) ? $field['required'] : 0;
         $table = $this->getTable('ShippingFields');
         if (!$table->bindCheckStore($field)) {
             $this->setError($table->getError());
             return false;
         }
         $in[] = $table->id;
         if ($field['type'] == 'select') {
             foreach ($field['values'] as $key => $value) {
                 $key = (int) $key;
                 if ($key > 0) {
                     $value['id'] = $key;
                 }
                 $value['field_id'] = $table->id;
                 $vtable = $this->getTable('ShippingFieldsValues');
                 if (!$vtable->bindCheckStore($value)) {
                     $this->setError($vtable->getError());
                     return false;
                 }
             }
         }
     }
     $query = $this->_db->getQuery(true);
     $query->select('id')->from('#__ksenmart_shipping_fields')->where('shipping_id=' . $id);
     if (count($in)) {
         $query->where('id not in (' . implode(', ', $in) . ')');
     }
     $this->_db->setQuery($query);
     $ids = $this->_db->loadColumn();
     if (count($ids) > 0) {
         $query = $this->_db->getQuery(true);
         $query->delete('#__ksenmart_shipping_fields')->where('id in (' . implode(',', $ids) . ')');
         $this->_db->setQuery($query);
         $this->_db->query();
         $query = $this->_db->getQuery(true);
         $query->delete('#__ksenmart_shipping_fields_values')->where('field_id in (' . implode(',', $ids) . ')');
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onAfterSaveShipping', array($id));
     $on_close = 'window.parent.ShippingsList.refreshList();';
     $return = array('id' => $id, 'on_close' => $on_close);
     $this->onExecuteAfter('SaveShipping', array(&$return));
     return $return;
 }
Esempio n. 16
0
 function delete_file()
 {
     $filename = JRequest::getVar('filename', '');
     $folder = JRequest::getVar('folder', '');
     KSMedia::deleteFile($filename, $folder);
     JFactory::getApplication()->close();
 }
Esempio n. 17
0
 public static function getProductManufacturer($id)
 {
     $params = JComponentHelper::getParams('com_ksenmart');
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select($db->qn(array('m.id', 'm.title', 'm.alias', 'm.content', 'm.introcontent', 'm.country', 'm.ordering', 'm.metatitle', 'm.metadescription', 'm.metakeywords', 'f.filename', 'f.folder', 'f.params')))->from($db->qn('#__ksenmart_manufacturers', 'm'))->leftjoin($db->qn('#__ksenmart_files', 'f') . ' ON ' . $db->qn('m.id') . '=' . $db->qn('f.owner_id') . 'AND' . $db->qn('f.owner_type') . '=' . $db->q('manufacturer'))->where($db->qn('m.id') . '=' . $db->q($id))->where($db->qn('m.published') . '=' . $db->q('1'));
     $db->setQuery($query);
     $manufacturer = $db->loadObject();
     if (count($manufacturer) > 0) {
         $manufacturer->img = KSMedia::resizeImage($manufacturer->filename, $manufacturer->folder, $params->get('manufacturer_width', 240), $params->get('manufacturer_height', 120), json_decode($manufacturer->params, true));
         unset($manufacturer->filename);
         unset($manufacturer->folder);
         unset($manufacturer->params);
         $query = $db->getQuery(true);
         $query->select('*')->from($db->qn('#__ksenmart_countries', 'c'))->where($db->qn('id') . '=' . $db->q($manufacturer->country));
         $db->setQuery($query);
         $manufacturer->country = $db->loadObject();
     }
     return $manufacturer;
 }
Esempio n. 18
0
 function getOrder($vars = array())
 {
     $this->onExecuteBefore('getOrder', array(&$value));
     $id = JRequest::getInt('id');
     $order = KSSystem::loadDbItem($id, 'orders');
     if (isset($vars['user_id'])) {
         $order->user_id = $vars['user_id'];
     }
     if (isset($vars['region_id'])) {
         $order->region_id = $vars['region_id'];
     }
     if (isset($vars['shipping_id'])) {
         $order->shipping_id = $vars['shipping_id'];
     }
     if (isset($vars['payment_id'])) {
         $order->payment_id = $vars['payment_id'];
     }
     $order->cost = 0;
     $order->discounts = property_exists($order, 'discounts') ? $order->discounts : '[]';
     $order->customer_fields = json_decode($order->customer_fields, true);
     $order->address_fields = json_decode($order->address_fields, true);
     if (!isset($vars['items'])) {
         $query = $this->_db->getQuery(true);
         $query->select('*')->from('#__ksenmart_order_items')->where('order_id=' . $id);
         $this->_db->setQuery($query);
         $order->items = $this->_db->loadObjectList();
     } else {
         $items = array();
         if (count($vars['items']) == 1 && !is_array($vars['items'][0])) {
             $vars['items'] = array();
         }
         foreach ($vars['items'] as $item) {
             $item['properties'] = isset($item['properties']) ? $item['properties'] : array();
             $item = (object) $item;
             $item->price = KSMProducts::getPriceWithProperties($item->product_id, $item->properties, $item->basic_price);
             $item->properties = json_encode($item->properties);
             $items[] = $item;
         }
         $order->items = $items;
     }
     foreach ($order->items as &$item) {
         $query = $this->_db->getQuery(true);
         $query->select('p.*')->from('#__ksenmart_products as p')->where('p.id=' . $item->product_id);
         $query = KSMedia::setItemMainImageToQuery($query);
         $this->_db->setQuery($query);
         $product = $this->_db->loadObject();
         if (count($product)) {
             $item->title = $product->title;
             $item->alias = $product->alias;
             $item->product_code = $product->product_code;
             $item->product_packaging = $product->product_packaging;
             $item->properties = json_decode($item->properties, true);
             $query = $this->_db->getQuery(true);
             $query->select('kp.*')->from('#__ksenmart_properties as kp')->innerjoin('#__ksenmart_product_properties_values as kppv on kp.id=kppv.property_id')->where('kppv.product_id=' . $item->product_id)->where('kp.type=' . $this->_db->quote('select'))->order('kp.ordering')->group('kp.id');
             $this->_db->setQuery($query);
             $properties = $this->_db->loadObjectList('id');
             foreach ($properties as &$property) {
                 $query = $this->_db->getQuery(true);
                 $query->select('kpv.*')->from('#__ksenmart_property_values as kpv')->innerjoin('#__ksenmart_product_properties_values as kppv on kpv.id=kppv.value_id')->where('kppv.product_id=' . $item->product_id)->where('kpv.property_id=' . $property->id)->order('kpv.ordering')->group('kpv.id');
                 $this->_db->setQuery($query);
                 $property->values = $this->_db->loadObjectList('id');
                 foreach ($property->values as $value) {
                     if (isset($item->properties[$property->id]) && is_array($item->properties[$property->id]) && in_array($value->id, $item->properties[$property->id])) {
                         $value->selected = true;
                     } else {
                         $value->selected = false;
                     }
                 }
             }
             $item->properties = $properties;
             $item->small_img = KSMedia::resizeImage($product->filename, 'products', $this->params->get('admin_product_medium_image_width', 36), $this->params->get('admin_product_medium_image_heigth', 36), json_decode($product->params, true));
         } else {
             $item->title = JText::_('ksm_orders_order_deleteditem_title');
             $item->alias = '';
             $item->product_code = '';
             $item->product_packaging = 1;
             $item->properties = array();
             $item->small_img = KSMedia::resizeImage('', 'products', $this->params->get('admin_product_medium_image_width', 36), $this->params->get('admin_product_medium_image_heigth', 36));
         }
         $item->val_price = KSMPrice::showPriceWithTransform($item->price);
         $item->val_total_price = KSMPrice::showPriceWithTransform($item->price * $item->count);
         $order->cost += $item->price * $item->count;
     }
     $order->costs = array('cost' => $order->cost, 'cost_val' => KSMPrice::showPriceWithTransform($order->cost), 'discount_cost' => 0, 'discount_cost_val' => KSMPrice::showPriceWithTransform(0), 'shipping_cost' => 0, 'shipping_cost_val' => KSMPrice::showPriceWithTransform(0), 'total_cost' => $order->cost, 'total_cost_val' => KSMPrice::showPriceWithTransform($order->cost));
     $this->onExecuteAfter('getOrder', array(&$order));
     return $order;
 }
Esempio n. 19
0
    public function getPayments()
    {
        $this->onExecuteBefore('getPayments');
        $payment_selected = 0;
        $payments = array();
        if (!empty($this->_region_id)) {
            $query = $this->_db->getQuery(true);
            $query->select('
					p.id,
					p.title,
					p.type,
					p.regions,
					p.params,
					f.filename,
					f.folder,
					f.params AS params_f,
					p.ordering
				')->from('#__ksenmart_payments AS p')->leftjoin('#__ksenmart_files AS f ON f.owner_type=' . $this->_db->quote('payment') . ' AND f.owner_id=p.id')->where('p.published=1')->order('p.ordering');
            $this->_db->setQuery($query);
            $rows = $this->_db->loadObjectList();
            foreach ($rows as $row) {
                $row->icon = !empty($row->filename) ? KSMedia::resizeImage($row->filename, $row->folder, 160, 80, json_decode($row->params_f, true)) : '';
                $row->regions = json_decode($row->regions, true);
                foreach ($row->regions as $country) {
                    if (in_array($this->_region_id, $country)) {
                        $row->selected = false;
                        $payment_selected = $payment_selected;
                        if ($row->id == $this->_payment_id) {
                            $row->selected = true;
                            $payment_selected = $row->id;
                        }
                        $payments[] = $row;
                    }
                }
            }
            $this->setState('payment_id', $payment_selected);
            $this->_session->set($this->context . '.payment_id', $payment_selected);
        }
        $this->onExecuteAfter('getPayments', array(&$payments));
        return $payments;
    }
Esempio n. 20
0
 function getFavoritesProducts()
 {
     $this->onExecuteBefore('getFavoritesProducts');
     $order_dir = $this->getState('order_dir');
     $order_type = $this->getState('order_type');
     if ($order_type != 'favorites') {
         $order_type = 'p.' . $order_type;
     }
     $query = $this->_db->getQuery(true);
     $query->select('*')->from('#__ksen_users');
     $this->_db->setQuery($query);
     $users = $this->_db->loadObjectList();
     $favorites = array(0);
     foreach ($users as $user) {
         $user->favorites = json_decode($user->favorites, true);
         if (is_array($user->favorites)) {
             foreach ($user->favorites as $f) {
                 if (!in_array($f, $favorites) && $f != '') {
                     $favorites[] = $f;
                 }
             }
         }
     }
     $query = $this->_db->getQuery(true);
     $query->select('SQL_CALC_FOUND_ROWS p.*,(select count(id) from #__ksen_users where INSTR(favorites,p.id)!=0) as favorites')->from('#__ksenmart_products as p')->order($order_type . ' ' . $order_dir);
     $query->where('p.id in (' . implode(',', $favorites) . ')');
     $query = KSMedia::setItemMainImageToQuery($query);
     $this->_db->setQuery($query, $this->getState('list.start'), $this->getState('list.limit'));
     $items = $this->_db->loadObjectList();
     $query = $this->_db->getQuery(true);
     $query->select('FOUND_ROWS()');
     $this->_db->setQuery($query);
     $this->total = $this->_db->loadResult();
     foreach ($items as &$item) {
         $item->img = KSMedia::resizeImage($item->filename, $item->folder, 30, 30, json_decode($item->params, true));
     }
     $this->onExecuteAfter('getFavoritesProducts', array(&$items));
     return $items;
 }
Esempio n. 21
0
 function deleteManufacturer($id)
 {
     $this->onExecuteBefore('deleteManufacturer', array(&$id));
     $table = $this->getTable('manufacturers');
     $table->delete($id);
     KSMedia::deleteItemMedia($id, 'category');
     $query = $this->_db->getQuery(true);
     $query->update('#__ksenmart_products')->set('manufacturer=0')->where('manufacturer=' . $id);
     $this->_db->setQuery($query);
     $this->_db->query();
     $this->onExecuteAfter('deleteManufacturer', array(&$id));
     return true;
 }
Esempio n. 22
0
 public static function deleteItemMedia($id = null, $owner_type = null)
 {
     global $ext_name, $ext_name_com;
     $owner_id = (int) $id;
     if (!$owner_id) {
         return false;
     }
     if (!$owner_type) {
         return false;
     }
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $query->select('*')->from('#__' . $ext_name . '_files')->where('owner_type=' . $db->quote($owner_type))->where('owner_id=' . $owner_id);
     $db->setQuery($query);
     $medias = $db->loadObjectList('id');
     foreach ($medias as $media) {
         if ($media->media_type == 'image') {
             KSMedia::deletePhoto($media->filename, $media->folder);
         }
         if ($media->media_type == 'file') {
         }
         if ($media->media_type == 'video') {
         }
     }
     return true;
 }