예제 #1
0
 public function copy()
 {
     JRequest::setVar('hidemainmenu', 1);
     JRequest::setVar('layout', 'form');
     $pluginIds = JRequest::getVar('cid', array(), '', 'array');
     $type = JRequest::getCmd('plugin_type');
     $result = true;
     if (!empty($pluginIds) && in_array($type, array('plugin', 'generator', 'consumer'))) {
         JArrayHelper::toInteger($pluginIds);
         $db = JFactory::getDBO();
         $db->setQuery('SELECT * FROM ' . hikaserial::table($type) . ' WHERE ' . $type . '_id IN (' . implode(',', $pluginIds) . ')');
         $plugins = $db->loadObjectList();
         $pluginsClass = hikaserial::get('class.' . $this->type);
         $plugin_id = $this->type . '_id';
         foreach ($plugins as $plugin) {
             unset($plugin->{$plugin_id});
             if (!$pluginsClass->save($plugin)) {
                 $result = false;
             }
         }
         if ($result) {
             $app = JFactory::getApplication();
             if (!HIKASHOP_J30) {
                 $app->enqueueMessage(JText::_('HIKASHOP_SUCC_SAVED'), 'success');
             } else {
                 $app->enqueueMessage(JText::_('HIKASHOP_SUCC_SAVED'));
             }
         }
     }
     return $this->display();
 }
예제 #2
0
파일: pack.php 프로젝트: q0821/esportshop
 public function checkQuantity(&$pack)
 {
     if (empty($pack->pack_params->stock_level_notify) || $pack->pack_params->stock_level_notify <= 0) {
         return true;
     }
     $status = 'free';
     $query = 'SELECT count(*) as qty FROM ' . hikaserial::table('serial') . ' AS a WHERE a.serial_status = ' . $this->db->Quote($status) . ' AND a.serial_pack_id=' . $pack->pack_id;
     $this->db->setQuery($query);
     $pack->current_quantity = $this->db->loadResult();
     if (!empty($pack->pack_params->stock_level_notify) && (int) $pack->current_quantity <= (int) $pack->pack_params->stock_level_notify) {
         $mailClass = hikaserial::get('class.mail');
         $mail = $mailClass->load('pack_quantity_low', $pack);
         if (!empty($mail)) {
             $mail->subject = JText::sprintf($mail->subject, HIKASERIAL_LIVE);
             $shopConfig =& hikaserial::config(false);
             if (!empty($pack->email)) {
                 $mail->dst_email = $pack->email;
             } else {
                 $mail->dst_email = $shopConfig->get('from_email');
             }
             if (!empty($pack->name)) {
                 $mail->dst_name = $pack->name;
             } else {
                 $mail->dst_name = $shopConfig->get('from_name');
             }
             $mailClass->sendMail($mail);
         }
     }
     unset($pack->current_quantity);
     return true;
 }
예제 #3
0
 public function configurationLine($id = 0, $conf = null)
 {
     if (empty($this->toggleHelper)) {
         $this->toggleHelper = hikaserial::get('helper.toggle');
     }
     switch ($id) {
         case 'packs':
             if (empty($this->packs)) {
                 $db = JFactory::getDBO();
                 $db->setQuery('SELECT * FROM ' . hikaserial::table('pack'));
                 $this->packs = $db->loadObjectList('pack_id');
             }
             $ret = array();
             if (!empty($conf->plugin_params->packs)) {
                 if (!is_array($conf->plugin_params->packs)) {
                     $conf->plugin_params->packs = array($conf->plugin_params->packs);
                 }
                 foreach ($conf->plugin_params->packs as $p) {
                     if (isset($this->packs[(int) $p])) {
                         $ret[] = '<a href="' . hikaserial::completeLink('pack&task=edit&cid=' . (int) $p) . '">' . $this->packs[(int) $p]->pack_name . '</a>';
                     }
                 }
             }
             return implode(', ', $ret);
     }
     return null;
 }
예제 #4
0
파일: pack.php 프로젝트: q0821/esportshop
 public function load($addEmpty = false)
 {
     $query = 'SELECT pack_id, pack_name FROM ' . hikaserial::table('pack') . ' ORDER BY pack_name ASC';
     $db = JFactory::getDBO();
     $db->setQuery($query);
     $packs = $db->loadObjectList('pack_id');
     if (!empty($packs)) {
         if ($addEmpty) {
             $this->values[0] = JHTML::_('select.option', '', JText::_('PACKS_ALL'));
         }
         foreach ($packs as $pack) {
             $this->values[(int) $pack->pack_id] = JHTML::_('select.option', (int) $pack->pack_id, $pack->pack_name);
         }
     }
 }
예제 #5
0
 public function save(&$element)
 {
     if (!is_array($element)) {
         return parent::save($element);
     }
     $struct = array();
     $first = reset($element);
     $query = 'INSERT IGNORE INTO ' . hikaserial::table('history') . ' (';
     $sep = '';
     foreach (get_object_vars($first) as $k => $v) {
         if (is_array($v) || is_object($v) || $v === null || $k[0] == '_') {
             continue;
         }
         if (!HIKASHOP_J30) {
             $query .= $sep . $this->db->nameQuote($k);
         } else {
             $query .= $sep . $this->db->quoteName($k);
         }
         $struct[] = $k;
         $sep = ',';
     }
     $query .= ') VALUES ';
     $sep = '';
     foreach ($element as $el) {
         if ($el === false) {
             continue;
         }
         $query .= $sep . '(';
         $sep2 = '';
         foreach ($struct as $k) {
             $value = $el->{$k};
             if (!HIKASHOP_J25) {
                 $query .= $sep2 . ($this->db->isQuoted($k) ? $this->db->Quote($value) : (int) $value);
             } else {
                 $query .= $sep2 . $this->db->Quote($value);
             }
             $sep2 = ',';
         }
         $query .= ')';
         $sep = ',';
     }
     $this->db->setQuery($query);
     $this->db->query();
     return true;
 }
예제 #6
0
 public function shop_form($params = null)
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $config = hikaserial::config();
     $this->assignRef('config', $config);
     $data = null;
     $product_id = 0;
     if (!empty($params)) {
         $product_id = (int) $params->get('product_id');
     }
     if ($product_id > 0) {
         $query = 'SELECT a.*, b.* FROM ' . hikaserial::table('product_pack') . ' as a INNER JOIN ' . hikaserial::table('pack') . ' as b ON a.pack_id = b.pack_id WHERE a.product_id = ' . $product_id;
         $db->setQuery($query);
         $data = $db->loadObjectList();
     }
     $this->assignRef('data', $data);
     $this->assignRef('product_id', $product_id);
 }
예제 #7
0
 public function show($params = null, $viewName = 'email-notification')
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $config = hikaserial::config();
     $this->assignRef('config', $config);
     $data = null;
     $order_id = 0;
     if (!empty($params)) {
         $order_id = (int) $params->get('order_id');
     }
     $display_serial_statuses = $config->get('display_serial_statuses', '');
     if (empty($display_serial_statuses)) {
         $display_serial_statuses = array($config->get('used_serial_status', 'used'));
     } else {
         $display_serial_statuses = explode(',', $display_serial_statuses);
     }
     foreach ($display_serial_statuses as &$s) {
         $s = $db->Quote($s);
     }
     unset($s);
     if ($order_id > 0) {
         $query = 'SELECT a.*, b.*, c.* FROM ' . hikaserial::table('serial') . ' as a ' . 'INNER JOIN ' . hikaserial::table('pack') . ' as b ON a.serial_pack_id = b.pack_id ' . 'LEFT JOIN ' . hikaserial::table('shop.order_product') . ' as c ON a.serial_order_product_id = c.order_product_id ' . 'WHERE a.serial_status IN (' . implode(',', $display_serial_statuses) . ') AND a.serial_order_id = ' . $order_id;
         $db->setQuery($query);
         $data = $db->loadObjectList();
     }
     JPluginHelper::importPlugin('hikaserial');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onDisplaySerials', array(&$data, $viewName));
     if (!empty($data)) {
         foreach ($data as &$serial) {
             if (!isset($serial->serial_text_data)) {
                 $serial->serial_text_data = $serial->serial_data;
                 $serial->serial_data = str_replace(array("\r\n", "\r", "\n"), '<br/>', $serial->serial_data);
             }
             unset($serial);
         }
     }
     $this->assignRef('data', $data);
     $this->assignRef('order_id', $order_id);
 }
예제 #8
0
 public function onDisplaySerials(&$data, $viewName)
 {
     if ($viewName == 'back-serial-form') {
         return;
     }
     $n = 'plg.seriesgen';
     $l = strlen($n) + 1;
     $packs = array();
     foreach ($data as &$serial) {
         if (substr($serial->pack_generator, 0, $l) != $n . '-') {
             continue;
         }
         $id = (int) substr($serial->pack_generator, $l);
         $packs[$id] = $id;
     }
     unset($serial);
     if (!empty($packs)) {
         $this->db->setQuery('SELECT * FROM ' . hikaserial::table('generator') . ' WHERE generator_type = \'seriesgen\' AND generator_id IN (' . implode(',', $packs) . ')');
         $confs = $this->db->loadObjectList('generator_id');
         foreach ($confs as &$conf) {
             if (!empty($conf->generator_params)) {
                 $conf->generator_params = unserialize($conf->generator_params);
             }
             unset($conf);
         }
     }
     foreach ($data as &$serial) {
         if (substr($serial->pack_generator, 0, $l) != $n . '-') {
             continue;
         }
         $id = (int) substr($serial->pack_generator, $l);
         if (!isset($confs[$id]) || empty($confs[$id]->generator_params->format)) {
             continue;
         }
         $format = $confs[$id]->generator_params->format;
         $serial->serial_data = sprintf($format, (int) $serial->serial_data);
     }
     unset($serial);
     return;
 }
예제 #9
0
파일: mail.php 프로젝트: q0821/esportshop
 public function beforeMailSend(&$mail, &$mailer)
 {
     $orderEmails = array('order_creation_notification' => 1, 'order_notification' => 1, 'order_status_notification' => 1);
     $mail_name = $mail->mail_name;
     if (isset($mail->hikamarket) && !empty($mail->hikamarket)) {
         $mail_name = 'market.' . $mail_name;
     }
     if (!isset($orderEmails[$mail_name])) {
         return;
     }
     if (empty($mail->data->order_id) || (int) $mail->data->order_id == 0) {
         return;
     }
     $config = hikaserial::config();
     $display_serial_statuses = $config->get('display_serial_statuses', '');
     if (empty($display_serial_statuses)) {
         $display_serial_statuses = array($config->get('used_serial_status', 'used'));
     } else {
         $display_serial_statuses = explode(',', $display_serial_statuses);
     }
     $statuses = array();
     foreach ($display_serial_statuses as $s) {
         $statuses[] = $this->db->Quote($s);
     }
     $serials = array();
     if (!empty($mail->data->order_id)) {
         $query = 'SELECT s.*, p.*, op.product_id ' . ' FROM ' . hikaserial::table('serial') . ' AS s ' . ' INNER JOIN ' . hikaserial::table('pack') . ' AS p ON s.serial_pack_id = p.pack_id ' . ' LEFT JOIN ' . hikaserial::table('shop.order_product') . ' AS op ON op.order_product_id = s.serial_order_product_id AND op.order_id = s.serial_order_id ' . ' WHERE s.serial_status IN (' . implode(',', $statuses) . ') AND s.serial_order_id = ' . (int) $mail->data->order_id . ' ' . ' ORDER BY s.serial_id';
         $this->db->setQuery($query);
         $serials = $this->db->loadObjectList();
     }
     if (!empty($serials)) {
         JPluginHelper::importPlugin('hikaserial');
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('onBeforeSerialMailSend', array(&$mail, &$mailer, &$serials, $mail->data));
     }
 }
예제 #10
0
파일: order.php 프로젝트: q0821/esportshop
 public function beforeOrderExport(&$rows, &$view)
 {
     $orders = array();
     foreach ($rows as $order) {
         $orders[] = (int) $order->order_id;
     }
     if (!empty($orders)) {
         $query = 'SELECT serial.serial_order_id, serial.serial_data FROM ' . hikaserial::table('serial') . ' AS serial WHERE serial.serial_order_id IN (' . implode(',', $orders) . ') ORDER BY serial.serial_order_id, serial.serial_id';
         $this->db->setQuery($query);
         $serials = $this->db->loadObjectList();
     }
     unset($orders);
     foreach ($rows as $k => $order) {
         $order_serials = array();
         foreach ($serials as $serial) {
             if ($serial->serial_order_id == $order->order_id) {
                 $order_serials[] = $serial->serial_data;
             }
         }
         $rows[$k]->serials = implode(';', $order_serials);
     }
     unset($serials);
 }
예제 #11
0
파일: toggle.php 프로젝트: q0821/esportshop
 public function delete()
 {
     list($value1, $value2) = explode('-', JRequest::getCmd('value'));
     $table = JRequest::getVar('table', '', '', 'word');
     $controller = hikaserial::get('controller.' . $table);
     if (empty($controller)) {
         echo 'No controller';
         exit;
     }
     if (!$controller->authorize('delete')) {
         echo 'Forbidden';
         exit;
     }
     $function = 'delete' . ucfirst($table);
     if (method_exists($this, $function)) {
         $this->{$function}($value1, $value2);
         exit;
     }
     $destClass = hikaserial::get('class.' . $table);
     $deleteToggle = $destClass->toggleDelete();
     list($key1, $key2) = reset($deleteToggle);
     $table = key($deleteToggle);
     if (empty($key1) || empty($key2) || empty($value1) || empty($value2)) {
         echo 'No value';
         exit;
     }
     $db = JFactory::getDBO();
     $db->setQuery('DELETE FROM ' . hikaserial::table($table) . ' WHERE ' . $key1 . ' = ' . $db->Quote($value1) . ' AND ' . $key2 . ' = ' . $db->Quote($value2));
     $db->query();
     exit;
 }
예제 #12
0
 public function useselection()
 {
     $packs = JRequest::getVar('cid', array(), '', 'array');
     $rows = array();
     $data = '';
     $confirm = JRequest::getVar('confirm', true);
     $singleSelection = JRequest::getVar('single', false);
     $elemStruct = array('pack_name', 'pack_data', 'pack_generator');
     if (!empty($packs)) {
         JArrayHelper::toInteger($users);
         $db = JFactory::getDBO();
         $query = 'SELECT a.* FROM ' . hikaserial::table('pack') . ' AS a WHERE a.pack_id IN (' . implode(',', $packs) . ')';
         $db->setQuery($query);
         $rows = $db->loadObjectList();
         if (!empty($rows)) {
             $data = array();
             foreach ($rows as $v) {
                 $d = '{id:' . $v->pack_id;
                 foreach ($elemStruct as $s) {
                     if ($s == 'id') {
                         continue;
                     }
                     $d .= ',' . $s . ':\'' . str_replace('"', '\'', $v->{$s}) . '\'';
                 }
                 $data[] = $d . '}';
             }
             if (!$singleSelection) {
                 $data = '[' . implode(',', $data) . ']';
             } else {
                 $data = $data[0];
                 $rows = $rows[0];
             }
         }
     }
     $this->assignRef('rows', $rows);
     $this->assignRef('data', $data);
     $this->assignRef('confirm', $confirm);
     $this->assignRef('singleSelection', $singleSelection);
     if ($confirm == true) {
         if (!HIKASHOP_J30) {
             JHTML::_('behavior.mootools');
         } else {
             JHTML::_('behavior.framework');
         }
         $js = 'window.addEvent("domready", function(){window.top.hikaserial.submitBox(' . $data . ');});';
         $doc = JFactory::getDocument();
         $doc->addScriptDeclaration($js);
     }
 }
예제 #13
0
 public function onAfterSerialUnassigned(&$serials)
 {
     if (empty($serials)) {
         return;
     }
     $db = JFactory::getDBO();
     $unpublished_coupon = array();
     foreach ($serials as $serial) {
         if (strpos($serial->pack_generator, '-') === false) {
             continue;
         }
         list($generator, $generator_id) = explode('-', $serial->pack_generator, 2);
         if ($generator != 'plg.coupongen') {
             continue;
         }
         $unpublished_coupon[] = $db->Quote($serial->serial_data);
     }
     if (empty($unpublished_coupon)) {
         return;
     }
     $query = 'UPDATE ' . hikaserial::table('shop.discount') . ' SET discount_published = 0 ' . ' WHERE discount_type = ' . $db->Quote('coupon') . ' AND discount_code IN (' . implode(',', $unpublished_coupon) . ')';
     $db->setQuery($query);
     $db->query();
 }
예제 #14
0
 public function export()
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $ids = JRequest::getVar('cid', array(), '', 'array');
     $export_params = array();
     $export_data = JRequest::getString('export_data', '');
     if (!empty($export_data)) {
         $export_datas = explode(';', $export_data);
         foreach ($export_datas as $d) {
             if (strpos($d, '=') !== false) {
                 list($k, $v) = explode('=', $d, 2);
                 $export_params[$k] = $v;
             }
         }
     }
     $this->assignRef('export_params', $export_params);
     $filters = array();
     if (empty($ids)) {
         $pageInfo = new stdClass();
         $pageInfo->filter = new stdClass();
         $pageInfo->filter->serial_status = $app->getUserStateFromRequest($this->paramBase . '.filter_status', 'filter_status', '', 'string');
         $pageInfo->filter->pack = $app->getUserStateFromRequest($this->paramBase . '.filter_pack', 'filter_pack', '', 'string');
         $pageInfo->search = JString::strtolower($app->getUserStateFromRequest($this->paramBase . '.search', 'search', '', 'string'));
         $searchMap = array('serial.serial_id', 'serial.serial_data', 'serial.serial_status', 'pack.pack_name', 'user.username');
         if (!empty($pageInfo->search)) {
             $searchVal = '\'%' . $db->getEscaped(JString::strtolower($pageInfo->search), true) . '%\'';
             $filters[] = '(' . implode(' LIKE ' . $searchVal . ' OR ', $searchMap) . ' LIKE ' . $searchVal . ')';
         }
         if (!empty($pageInfo->filter->serial_status)) {
             $filters[] = ' serial.serial_status = ' . $db->quote($pageInfo->filter->serial_status);
         }
         if (!empty($pageInfo->filter->pack)) {
             if ((int) $pageInfo->filter->pack > 0) {
                 $filters[] = ' pack.pack_id = ' . (int) $pageInfo->filter->pack;
             } else {
                 $filters[] = ' pack.pack_name = ' . $db->quote($pageInfo->filter->pack);
             }
         }
     } else {
         JArrayHelper::toInteger($ids, 0);
         $filters[] = 'serial.serial_id IN (' . implode(',', $ids) . ')';
     }
     if (!empty($filters)) {
         $filters = ' WHERE ' . implode(' AND ', $filters);
     } else {
         $filters = '';
     }
     $query = 'FROM ' . hikaserial::table('serial') . ' AS serial INNER JOIN ' . hikaserial::table('pack') . ' AS pack ON serial.serial_pack_id = pack.pack_id LEFT JOIN ' . hikaserial::table('shop.user') . ' AS user ON serial.serial_user_id = user.user_id LEFT JOIN ' . hikaserial::table('users', false) . ' AS users ON user.user_cms_id = users.id LEFT JOIN ' . hikaserial::table('shop.order') . ' AS shop_order ON serial.serial_order_id = shop_order.order_id ' . $filters;
     $db->setQuery('SELECT * ' . $query);
     $rows = $db->loadObjectList();
     $this->assignRef('rows', $rows);
 }
예제 #15
0
 public function onAfterOrderCreate(&$order, &$send_email)
 {
     if (!empty($this->usedSerials)) {
         if (!$this->init()) {
             return;
         }
         $serialConfig = hikaserial::config();
         $used_status = $serialConfig->get('used_serial_status', 'used');
         $db = JFactory::getDBO();
         $query = 'UPDATE ' . hikaserial::table('serial') . ' SET serial_status = ' . $db->Quote($used_status) . ' WHERE serial_id IN (' . implode(',', $this->usedSerials) . ')';
         $db->setQuery($query);
         $db->query();
     }
     $empty = array();
     $app = JFactory::getApplication();
     $app->setUserState('com_hikaserial.plg_productaddconsumer.products', $empty);
 }
예제 #16
0
파일: serial.php 프로젝트: q0821/esportshop
 public function check($serial_data, $pack = null)
 {
     $do = true;
     $filters = array();
     JPluginHelper::importPlugin('hikashop');
     JPluginHelper::importPlugin('hikaserial');
     $dispatcher = JDispatcher::getInstance();
     if (!empty($pack)) {
         $f = null;
         if (is_array($pack)) {
             $f = reset($pack);
         }
         if (is_int($pack)) {
             $filters[] = 'b.pack_id = ' . (int) $pack;
         }
         if (is_int($f)) {
             JArrayHelper::toInteger($pack);
             $filters[] = 'b.pack_id IN (' . implode(',', $pack) . ')';
         }
         if (is_string($pack)) {
             $filters[] = 'b.pack_name = ' . $this->db->Quote($pack);
         }
         if (is_string($f)) {
             $elems = array();
             foreach ($pack as $p) {
                 $elems[] = $this->db->Quote($p);
             }
             $filters[] = 'b.pack_name IN (' . implode(',', $elems) . ')';
         }
     }
     $dispatcher->trigger('onBeforeSerialCheck', array(&$serial_data, &$do, &$filters));
     if (!$do) {
         return false;
     }
     $query = 'SELECT a.*, b.pack_params FROM ' . hikaserial::table('serial') . ' AS a INNER JOIN ' . hikaserial::table('pack') . ' AS b ' . ' ON a.serial_pack_id = b.pack_id ' . ' WHERE (b.pack_published = 1 AND a.serial_data = ' . $this->db->Quote($serial_data) . ') ' . implode(' AND ', $filters);
     $this->db->setQuery($query);
     $ret = $this->db->loadObjectList();
     if (!empty($ret)) {
         foreach ($ret as $k => &$r) {
             $params = new stdClass();
             if (!empty($r->pack_params)) {
                 $params = unserialize($r->pack_params);
             }
             if (!empty($params->webservice)) {
                 unset($r->pack_params);
                 if (!empty($r->serial_extradata)) {
                     $r->serial_extradata = unserialize($r->serial_extradata);
                 }
             } else {
                 unset($ret[$k]);
             }
         }
     }
     $dispatcher->trigger('onAfterSerialCheck', array($serial_data, &$ret));
     return $ret;
 }
예제 #17
0
 public function form()
 {
     JHTML::_('behavior.modal');
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $config = hikaserial::config();
     $task = JRequest::getVar('task');
     $this->content = '';
     $this->plugin_name = JRequest::getCmd('name', '');
     if (empty($this->plugin_name)) {
         return false;
     }
     $plugin = hikaserial::import('hikaserial', $this->plugin_name);
     if (!$plugin || !method_exists($plugin, 'type')) {
         $app->enqueueMessage('Fail to load the plugin or the plugin is not an HikaSerial one', 'error');
         return false;
     }
     $this->plugin_type = $plugin->type();
     $query = '';
     if (in_array($this->plugin_type, array('generator', 'consumer', 'plugin'))) {
         $query = 'SELECT * FROM ' . hikaserial::table($this->plugin_type) . ' WHERE ' . $this->plugin_type . '_type = ' . $db->Quote($this->plugin_name);
         $query .= ' ORDER BY ' . $this->plugin_type . '_ordering ASC';
     }
     if (empty($query)) {
         return false;
     }
     $db->setQuery($query);
     $elements = $db->loadObjectList($this->plugin_type . '_id');
     if (!empty($elements)) {
         $params_name = $this->plugin_type . '_params';
         foreach ($elements as $k => $el) {
             if (!empty($el->{$params_name})) {
                 $elements[$k]->{$params_name} = unserialize($el->{$params_name});
             }
         }
     }
     $multiple_plugin = false;
     if (method_exists($plugin, 'isMultiple')) {
         $multiple_plugin = $plugin->isMultiple();
     }
     $function = 'onPluginConfiguration';
     $ctrl = '&plugin_type=' . $this->plugin_type . '&task=edit&name=' . $this->plugin_name;
     if ($multiple_plugin === true) {
         $subtask = JRequest::getCmd('subtask', '');
         $ctrl .= '&subtask=' . $subtask;
         if (empty($subtask)) {
             $function = 'onPluginMultipleConfiguration';
         }
         $cid = hikaserial::getCID($this->plugin_type . '_id');
         if (isset($elements[$cid])) {
             $this->assignRef('element', $elements[$cid]);
             $ctrl .= '&' . $this->plugin_type . '_id=' . $cid;
         }
     } else {
         if (!empty($elements)) {
             $this->assignRef('element', reset($elements));
         }
     }
     $this->assignRef('elements', $elements);
     $setTitle = true;
     if (method_exists($plugin, $function)) {
         if (empty($plugin->title)) {
             $plugin->title = JText::_('HIKAS_PLUGIN') . ' ' . $this->plugin_name;
         }
         $plugin->ctrl_url = self::ctrl . $ctrl;
         ob_start();
         $plugin->{$function}($elements);
         $this->content = ob_get_clean();
         $this->data = $plugin->getProperties();
         $setTitle = false;
     }
     $this->assignRef('name', $this->plugin_name);
     $this->assignRef('plugin', $plugin);
     $this->assignRef('multiple_plugin', $multiple_plugin);
     $this->assignRef('content', $this->content);
     $this->assignRef('plugin_type', $this->plugin_type);
     if (empty($plugin->pluginView)) {
         $this->content .= $this->loadPluginTemplate(@$plugin->view, $this->plugin_type);
     }
     if ($setTitle) {
         hikaserial::setTitle(JText::_('HIKAS_PLUGIN') . ' ' . $this->name, self::icon, self::ctrl . $ctrl);
     }
     return true;
 }
예제 #18
0
 public function show($params = null, $viewName = 'email-notification')
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $config = hikaserial::config();
     $this->assignRef('config', $config);
     $data = null;
     $order_id = 0;
     $this->assignRef('data', $data);
     $this->assignRef('order_id', $order_id);
     if (!empty($params)) {
         $order_id = (int) $params->get('order_id');
         $order = $params->get('order_obj', null);
     } else {
         $order_id = hikaserial::getCID('order_id');
     }
     if (empty($order)) {
         $orderClass = hikaserial::get('shop.class.order');
         $order = $orderClass->loadFullOrder($order_id);
     }
     $show_refresh = true;
     if ($order->order_type == 'subsale') {
         $order_id = $order->order_parent_id;
         $show_refresh = false;
     }
     $this->assignRef('show_refresh', $show_refresh);
     if ($order->order_type == 'vendorpayment') {
         $show_refresh = false;
         return false;
     }
     $display_serial_statuses = $config->get('display_serial_statuses', '');
     if (empty($display_serial_statuses)) {
         $display_serial_statuses = array($config->get('used_serial_status', 'used'));
     } else {
         $display_serial_statuses = explode(',', $display_serial_statuses);
     }
     foreach ($display_serial_statuses as &$s) {
         $s = $db->Quote($s);
     }
     unset($s);
     $ajax = JRequest::getVar('tmpl', '') == 'component';
     $this->assignRef('ajax', $ajax);
     if ($order_id > 0) {
         $query = 'SELECT serial.*, pack.*, order_product.*, u.user_cms_id FROM ' . hikaserial::table('serial') . ' as serial ' . 'INNER JOIN ' . hikaserial::table('pack') . ' as pack ON serial.serial_pack_id = pack.pack_id ' . 'LEFT JOIN ' . hikaserial::table('shop.order_product') . ' as order_product ON serial.serial_order_product_id = order_product.order_product_id ' . 'LEFT JOIN ' . hikaserial::table('shop.user') . ' AS u ON serial.serial_user_id = u.user_id ' . 'WHERE serial.serial_status IN (' . implode(',', $display_serial_statuses) . ') AND serial.serial_order_id = ' . $order_id;
         $db->setQuery($query);
         $data = $db->loadObjectList();
     }
     if ($order->order_type == 'subsale' && !empty($order->products)) {
         foreach ($data as $k => $v) {
             $order_product_id = (int) $v->order_product_id;
             $f = false;
             foreach ($order->products as $order_product) {
                 if ((int) $order_product->order_product_parent_id == $order_product_id) {
                     $f = true;
                     break;
                 }
             }
             if (!$f) {
                 unset($data[$k]);
             }
         }
     }
     JPluginHelper::importPlugin('hikaserial');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onDisplaySerials', array(&$data, $viewName));
     if (!empty($data)) {
         $user_cms_id = 0;
         foreach ($data as &$serial) {
             if (!isset($serial->serial_text_data)) {
                 $serial->serial_text_data = $serial->serial_data;
                 $serial->serial_data = str_replace(array("\r\n", "\r", "\n"), '<br/>', $serial->serial_data);
             }
             if (!empty($serial->user_cms_id)) {
                 $user_cms_id = $serial->user_cms_id;
             }
             unset($serial);
         }
         $locale = '';
         if (!empty($user_cms_id)) {
             $user = JFactory::getUser($user_cms_id);
             $locale = $user->getParam('language');
             if (empty($locale)) {
                 $locale = $user->getParam('admin_language');
             }
         }
         if (empty($locale)) {
             $params = JComponentHelper::getParams('com_languages');
             $locale = $params->get('site', 'en-GB');
         }
         if (!empty($locale)) {
             $lang = JFactory::getLanguage();
             $lang->load(HIKASERIAL_COMPONENT, JPATH_SITE, $locale, true);
         }
     }
 }
예제 #19
0
 public function useselection()
 {
     $users = JRequest::getVar('cid', array(), '', 'array');
     $rows = array();
     $data = '';
     $elemStruct = array('user_email', 'user_cms_id', 'name', 'username', 'email');
     if (!empty($users)) {
         JArrayHelper::toInteger($users);
         $db = JFactory::getDBO();
         $query = 'SELECT a.*, b.* FROM ' . hikaserial::table('user', 'shop') . ' AS a LEFT JOIN ' . hikaserial::table('users', false) . ' AS b ON a.user_cms_id = b.id WHERE a.user_id IN (' . implode(',', $users) . ')';
         $db->setQuery($query);
         $rows = $db->loadObjectList();
         if (!empty($rows)) {
             $data = array();
             foreach ($rows as $v) {
                 $d = '{id:' . $v->user_id;
                 foreach ($elemStruct as $s) {
                     if ($s == 'id') {
                         continue;
                     }
                     $d .= ',' . $s . ':"' . str_replace('"', '\\"', $v->{$s}) . '"';
                 }
                 $data[] = $d . '}';
             }
             $data = '[' . implode(',', $data) . ']';
         }
     }
     $this->assignRef('rows', $rows);
     $this->assignRef('data', $data);
     $confirm = JRequest::getVar('confirm', true, '', 'boolean');
     $this->assignRef('confirm', $confirm);
     if ($confirm) {
         $js = 'window.addEvent("domready", function(){window.top.hikaserial.submitBox(' . $data . ');});';
         $doc = JFactory::getDocument();
         $doc->addScriptDeclaration($js);
     }
 }
예제 #20
0
파일: import.php 프로젝트: q0821/esportshop
 public function handleTextContent(&$contentFile)
 {
     $contentFile = str_replace(array("\r\n", "\r"), "\n", trim($contentFile));
     $data = explode("\n", $contentFile);
     if (empty($this->pack_id)) {
         return false;
     }
     $cpt = 0;
     $baseSql = 'REPLACE INTO ' . hikaserial::table('serial') . ' (serial_data, serial_pack_id, serial_status) VALUES ';
     $sql = $baseSql;
     foreach ($data as $d) {
         if ($cpt > 0) {
             $sql .= ', ';
         }
         $sql .= '(' . $this->db->quote($d) . ', ' . $this->pack_id . ', ' . $this->db->quote('free') . ')';
         if ($cpt >= $this->perBatch) {
             $this->db->setQuery($sql);
             $this->db->query();
             $sql = $baseSql;
             $this->serialCounter += $cpt;
             $cpt = 0;
         }
         $cpt++;
     }
     unset($data);
     if ($cpt > 0) {
         $this->db->setQuery($sql);
         $this->db->query();
         $this->serialCounter += $cpt;
     }
     $app = JFactory::getApplication();
     $app->enqueueMessage(JText::sprintf('%d serials imported', $this->serialCounter));
     if ($this->packCounter > 0) {
         $app->enqueueMessage(JText::sprintf('%d packs imported', $this->packCounter));
     }
     return true;
 }
예제 #21
0
파일: config.php 프로젝트: q0821/esportshop
 public function reset()
 {
     $query = 'UPDATE ' . hikaserial::table('config') . ' SET config_value = config_default';
     $this->db->setQuery($query);
     $this->values = $this->db->query();
 }
예제 #22
0
 public function getPlugins($type = 'generator', $name = '')
 {
     $where = array();
     if (!empty($name)) {
         $where[] = $type . '_type=' . $this->db->Quote($name);
     }
     if (!empty($where)) {
         $where = ' WHERE ' . implode(' AND ', $where);
     } else {
         $where = '';
     }
     $query = 'SELECT * FROM ' . hikaserial::table($type) . ' ' . $where;
     $this->db->setQuery($query);
     $methods = $this->db->loadObjectList($type . '_id');
     $this->params($methods, $type);
     if (empty($methods)) {
         $methods = array();
     }
     return $methods;
 }
예제 #23
0
 public function refreshQuantity(&$product)
 {
     $config = hikaserial::config();
     if ($config->get('link_product_quantity', false) == false) {
         return;
     }
     $filter = '';
     if ($product !== null) {
         $filter = 'AND pp.product_id = ' . $product->product_id . ' ';
     }
     $query = 'SELECT p.product_id, pa.pack_id, floor(count(s.serial_id) / pp.quantity) as qty, pa.pack_generator, pa.pack_params, p.product_quantity ' . 'FROM ' . hikaserial::table('product_pack') . ' AS pp ' . 'INNER JOIN ' . hikaserial::table('shop.product') . ' AS p ON pp.product_id = p.product_id ' . 'INNER JOIN ' . hikaserial::table('pack') . ' AS pa ON pp.pack_id = pa.pack_id ' . 'LEFT JOIN ' . hikaserial::table('serial') . ' AS s ON s.serial_pack_id = pa.pack_id AND s.serial_status = \'free\' ' . 'WHERE pp.quantity > 0 ' . $filter . 'GROUP BY p.product_id, pa.pack_id ' . 'ORDER BY p.product_id ASC, qty ASC';
     $this->db->setQuery($query);
     $ret = $this->db->loadObjectList();
     $products = array();
     foreach ($ret as &$p) {
         if (isset($products[$p->product_id]) && isset($products[$p->product_id]->qty) && $products[$p->product_id]->qty >= 0) {
             continue;
         }
         if (!empty($p->pack_generator)) {
             $p->qty = -1;
         }
         if (!empty($p->pack_params)) {
             $p->pack_params = unserialize($p->pack_params);
             if (!empty($p->pack_params->unlimited_quantity)) {
                 $p->qty = -1;
             }
         }
         $products[$p->product_id] =& $p;
         unset($p);
     }
     foreach ($products as $p) {
         if ($p->qty != $p->product_quantity) {
             $this->db->setQuery('UPDATE ' . hikaserial::table('shop.product') . ' SET product_quantity = ' . $p->qty . ' WHERE product_id = ' . $p->product_id);
             $this->db->query();
         }
     }
     unset($products);
     unset($ret);
 }
예제 #24
0
 private function retrieveData($table, $field, &$serial, $order)
 {
     $field = trim($field);
     $table = trim($table);
     switch ($table) {
         case 'serial':
             if (substr($field, 0, 10) == 'extradata.') {
                 $field = substr($field, 10);
                 if (is_string($serial->serial_extradata)) {
                     $serial->serial_extradata = unserialize($serial->serial_extradata);
                 }
                 if (!empty($serial->serial_extradata->{$field})) {
                     return $serial->serial_extradata->{$field};
                 }
                 if (!empty($serial->serial_extradata[$field])) {
                     return $serial->serial_extradata[$field];
                 }
             } else {
                 if (!empty($serial->{$field})) {
                     return $serial->{$field};
                 }
             }
             break;
         case '_':
             return JText::_($field);
             break;
         case 'rawtext':
             return $field;
             break;
         case 'order':
             if (!empty($order->{$field})) {
                 return $order->{$field};
             }
             break;
         case 'customer':
             if (!empty($order->customer->{$field})) {
                 return $order->customer->{$field};
             }
             break;
         case 'order_product':
             if (empty($serial)) {
                 return null;
             }
             $opid = 0;
             $pid = (int) $serial->product_id;
             if (!empty($serial->serial_order_product_id)) {
                 $opid = (int) $serial->serial_order_product_id;
             }
             foreach ($order->products as $product) {
                 if ($opid > 0 && $product->order_product_id == $opid || $opid == 0 && $product->product_id == $pid) {
                     if (!empty($product->{$field})) {
                         if ($field == 'order_product_name') {
                             return strip_tags($product->{$field});
                         }
                         return $product->{$field};
                     }
                     return null;
                 }
             }
             break;
         case 'product_price':
         case 'full_product_price':
             if (empty($serial)) {
                 return null;
             }
             $opid = 0;
             $pid = (int) $serial->product_id;
             if (!empty($serial->serial_order_product_id)) {
                 $opid = (int) $serial->serial_order_product_id;
             }
             $price = null;
             foreach ($order->products as $product) {
                 if ($opid > 0 && $product->order_product_id == $opid || $opid == 0 && $product->product_id == $pid) {
                     if ($price === null) {
                         $price = 0.0;
                     }
                     $price += $product->order_product_price;
                     if ($field == 'incvat') {
                         $price += $product->order_product_tax;
                     }
                     if ($table == 'product_price') {
                         return $price;
                     }
                 }
                 if ($table == 'full_product_price' && $opid > 0 && $product->order_product_option_parent_id == $opid) {
                     if ($price === null) {
                         $price = 0.0;
                     }
                     $price += $product->order_product_price;
                     if ($field == 'incvat') {
                         $price += $product->order_product_tax;
                     }
                 }
             }
             if ($price != null) {
                 return $price;
             }
             break;
         case 'product':
             if ($field == 'image' || substr($field, 0, 6) == 'image.') {
                 if (!isset($this->cache['product_image'])) {
                     $this->cache['product_image'] = array();
                 }
                 if (!isset($this->cache['product_image'][$serial->product_id])) {
                     $db = JFactory::getDBO();
                     $db->setQuery('SELECT * FROM ' . hikaserial::table('shop.file') . ' as f LEFT JOIN ' . hikaserial::table('shop.product') . ' as p ON (f.file_ref_id = ' . $serial->product_id . ' OR f.file_ref_id = p.product_parent_id) WHERE file_type = \'product\' AND p.product_id = ' . $serial->product_id . ' ORDER BY product_parent_id DESC, file_ordering ASC, file_id ASC');
                     $this->cache['product_image'][$serial->product_id] = $db->loadObjectList();
                 }
                 $images = $this->cache['product_image'][$serial->product_id];
                 if ($field == 'image' || $field == 'image.0') {
                     $main_image = reset($images);
                     if (!empty($main_image)) {
                         return $main_image->file_path;
                     }
                 } else {
                     list($field, $pos) = explode('.', $field, 2);
                     $pos = (int) $pos;
                     foreach ($images as $k => $v) {
                         if ($k == $pos) {
                             return $v->file_path;
                         }
                     }
                 }
             } else {
                 if (empty($this->productClass)) {
                     $this->productClass = hikaserial::get('shop.class.product');
                 }
                 if (!isset($this->cache['product'])) {
                     $this->cache['product'] = array();
                 }
                 if (!isset($this->cache['product'][$serial->product_id])) {
                     $this->cache['product'][$serial->product_id] = $this->productClass->get($serial->product_id);
                 }
                 $product = $this->cache['product'][$serial->product_id];
                 if (!empty($product) && !empty($product->{$field})) {
                     return $product->{$field};
                 }
             }
             break;
         case 'shipping':
             if (!empty($order->shipping_address->{$field})) {
                 return $order->shipping_address->{$field};
             }
             break;
         case 'billing':
             if (!empty($order->billing_address->{$field})) {
                 return $order->billing_address->{$field};
             }
             break;
         case 'option_product':
             if (empty($serial)) {
                 return null;
             }
             if (strpos($field, '.') === false) {
                 return null;
             }
             list($pos, $field) = explode('.', $field, 2);
             $pos = (int) $pos + 1;
             if (empty($this->productClass)) {
                 $this->productClass = hikaserial::get('shop.class.product');
             }
             if (!isset($this->cache['product'])) {
                 $this->cache['product'] = array();
             }
             if (!isset($this->cache['product_image'])) {
                 $this->cache['product_image'] = array();
             }
             $opid = 0;
             $pid = (int) $serial->product_id;
             if (!empty($serial->serial_order_product_id)) {
                 $opid = (int) $serial->serial_order_product_id;
             }
             if (empty($opid)) {
                 foreach ($order->products as $product) {
                     if ($product->product_id == $pid) {
                         $opid = (int) $product->order_product_id;
                         break;
                     }
                 }
             }
             if ($opid <= 0) {
                 return null;
             }
             $i = 0;
             foreach ($order->products as $product) {
                 if ($product->order_product_option_parent_id != $opid) {
                     continue;
                 }
                 $i++;
                 if ($i != $pos) {
                     continue;
                 }
                 if ($field == 'image' || substr($field, 0, 6) == 'image.') {
                     if (!isset($this->cache['product_image'][$product->product_id])) {
                         $db = JFactory::getDBO();
                         $db->setQuery('SELECT * FROM ' . hikaserial::table('shop.file') . ' as f LEFT JOIN ' . hikaserial::table('shop.product') . ' as p ON (f.file_ref_id = ' . (int) $product->product_id . ' OR f.file_ref_id = p.product_parent_id) WHERE file_type = \'product\' AND p.product_id = ' . (int) $product->product_id . ' ORDER BY product_parent_id DESC, file_ordering ASC, file_id ASC');
                         $this->cache['product_image'][$product->product_id] = $db->loadObjectList();
                     }
                     $images = $this->cache['product_image'][$product->product_id];
                     if ($field == 'image' || $field == 'image.0') {
                         $main_image = reset($images);
                         if (!empty($main_image)) {
                             return $main_image->file_path;
                         }
                         return null;
                     }
                     list($field, $pos) = explode('.', $field, 2);
                     $pos = (int) $pos;
                     foreach ($images as $k => $v) {
                         if ($k == $pos) {
                             return $v->file_path;
                         }
                     }
                     return null;
                 }
                 if (!isset($this->cache['product'][$product->product_id])) {
                     $this->cache['product'][$product->product_id] = $this->productClass->get($product->product_id);
                 }
                 $full_product = $this->cache['product'][$product->product_id];
                 if (!empty($full_product) && !empty($full_product->{$field})) {
                     return $full_product->{$field};
                 }
                 return null;
             }
             break;
         case 'vendor_product':
             if (empty($serial)) {
                 return null;
             }
             if (!isset($this->cache['product_vendor'])) {
                 $this->cache['product_vendor'] = array();
             }
             if (!defined('HIKAMARKET_COMPONENT')) {
                 $marketHelper = rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_hikamarket' . DS . 'helpers' . DS . 'helper.php';
                 if (!file_exists($marketHelper)) {
                     return null;
                 }
                 include_once $marketHelper;
                 if (!defined('HIKAMARKET_COMPONENT')) {
                     return null;
                 }
             }
             if (!isset($this->cache['product_vendor'][$serial->product_id])) {
                 $query = 'SELECT * FROM ' . hikamarket::table('vendor') . ' AS v INNER JOIN ' . hikamarket::table('shop.product') . ' AS p ON p.product_vendor_id = v.vendor_id WHERE p.product_id = ' . $serial->product_id;
                 $db = JFactory::getDBO();
                 $db->setQuery($query);
                 $this->cache['product_vendor'][$serial->product_id] = $db->loadObject();
             }
             $vendor = $this->cache['product_vendor'][$serial->product_id];
             if (!empty($vendor) && !empty($vendor->{$field})) {
                 return $vendor->{$field};
             }
             break;
         case 'option_order':
             if (empty($serial)) {
                 return null;
             }
             if (strpos($field, '.') === false) {
                 return null;
             }
             list($pos, $field) = explode('.', $field, 2);
             $pos = (int) $pos + 1;
             $opid = 0;
             $pid = (int) $serial->product_id;
             if (!empty($serial->serial_order_product_id)) {
                 $opid = (int) $serial->serial_order_product_id;
             }
             if (empty($opid)) {
                 foreach ($order->products as $product) {
                     if ($product->product_id == $pid) {
                         $opid = $product->order_product_id;
                         break;
                     }
                 }
             }
             if ($opid > 0) {
                 $i = 0;
                 foreach ($order->products as $product) {
                     if ($opid > 0 && $product->order_product_option_parent_id == $opid) {
                         $i++;
                     }
                     if ($i == $pos) {
                         if (!empty($product->{$field})) {
                             if ($field == 'order_product_name') {
                                 return strip_tags($product->{$field});
                             }
                             return $product->{$field};
                         }
                         return null;
                     }
                 }
             }
             break;
         case 'entry':
             if (empty($order->entries)) {
                 $query = 'SELECT * FROM ' . hikaserial::table('shop.entry') . ' WHERE order_id=' . $order->order_id;
                 $db = JFactory::getDBO();
                 $db->setQuery($query);
                 $order->entries = $db->loadObjectList();
             }
             if (!empty($order->entries)) {
                 $opid = 0;
                 $pid = (int) $serial->product_id;
                 if (!empty($serial->serial_order_product_id)) {
                     $opid = (int) $serial->serial_order_product_id;
                 }
                 $cpt_product = 0;
                 $target_product = 0;
                 foreach ($order->products as $product) {
                     if ($product->product_id == $pid) {
                         $cpt_product += $product->order_product_quantity;
                     }
                     if ($opid > 0 && $opid == $product->order_product_id) {
                         $target_product = $cpt_product;
                     }
                 }
                 if ($target_product > 0) {
                     $fieldClass = hikaserial::get('shop.class.field');
                     $data = new stdClass();
                     $entryFields = $fieldClass->getFields('', $data, 'entry');
                     $accept_values = array();
                     foreach ($entryFields as $entryField) {
                         if ($entryField->field_options['product_id'] == $pid) {
                             $accept_values[$entryField->field_namekey] = $entryField->field_options['product_value'];
                         }
                     }
                     $cpt = 0;
                     if (empty($serial->position)) {
                         $serial->position = 1;
                     }
                     foreach ($order->entries as $entry) {
                         foreach ($accept_values as $key => $value) {
                             if ($entry->{$key} == $value || is_array($value) && in_array($entry->{$key}, $value)) {
                                 $cpt++;
                                 if ($cpt + $serial->position - 1 == $target_product) {
                                     return $entry->{$field};
                                 }
                             }
                         }
                     }
                 }
             }
             break;
     }
     return null;
 }
예제 #25
0
 public function downloadHikaShopFile($file_id, $order_id = 0, $file_pos = 1, $serial = '')
 {
     $app = JFactory::getApplication();
     $fileClass = hikaserial::get('shop.class.file');
     $file = $fileClass->get($file_id);
     $file_pos = (int) $file_pos;
     if ($file_pos <= 0) {
         $file_pos = 1;
     }
     if (!$app->isAdmin() && empty($file->file_free_download)) {
         $orderClass = hikaserial::get('shop.class.order');
         $order = $orderClass->get($order_id);
         $file->order = $order;
         $file->order_id = $order_id;
         if (empty($order) || $order->order_type != 'sale') {
             $app->enqueueMessage(JText::_('WRONG_ORDER'));
             return 'wrong_order';
         }
         $shopConfig = hikaserial::config(false);
         $order_status_for_download = $shopConfig->get('order_status_for_download', 'confirmed,shipped');
         if (!in_array($order->order_status, explode(',', $order_status_for_download))) {
             $app->enqueueMessage(JText::_('BECAUSE_STATUS_NO_DOWNLOAD'));
             return 'status';
         }
         $download_time_limit = $shopConfig->get('download_time_limit', 0);
         if (!empty($download_time_limit) && $download_time_limit + $order->order_created < time()) {
             $app->enqueueMessage(JText::_('TOO_LATE_NO_DOWNLOAD'));
             return 'date';
         }
         $query = 'SELECT a.* FROM ' . hikaserial::table('shop.order_product') . ' AS a WHERE a.order_id = ' . $order_id;
         $this->db->setQuery($query);
         $order->products = $this->db->loadObjectList();
         $product_ids = array();
         foreach ($order->products as $product) {
             if ((int) $product->order_product_quantity >= $file_pos || $file_pos == 1) {
                 $product_ids[] = $product->product_id;
             }
         }
         if (empty($product_ids)) {
             $app->enqueueMessage(JText::_('INVALID_FILE_NUMBER'));
             return 'status';
         }
         $query = 'SELECT * FROM ' . hikaserial::table('shop.product') . ' WHERE product_id IN (' . implode(',', $product_ids) . ') AND product_type=\'variant\'';
         $this->db->setQuery($query);
         $products = $this->db->loadObjectList();
         if (!empty($products)) {
             foreach ($products as $product) {
                 foreach ($order->products as $item) {
                     if ($product->product_id == $item->product_id && !empty($product->product_parent_id)) {
                         $item->product_parent_id = $product->product_parent_id;
                         $product_ids[] = $product->product_parent_id;
                     }
                 }
             }
         }
         $filters = array('a.file_ref_id IN (' . implode(',', $product_ids) . ')', 'a.file_type=\'file\'', 'a.file_id=' . $file_id);
         if (substr($file->file_path, 0, 1) == '@' || substr($file->file_path, 0, 1) == '#') {
             $query = 'SELECT a.*,b.* FROM ' . hikaserial::table('shop.file') . ' AS a ' . ' LEFT JOIN ' . hikaserial::table('shop.download') . ' AS b ON b.order_id=' . $order->order_id . ' AND a.file_id = b.file_id AND b.file_pos = ' . $file_pos . ' WHERE ' . implode(' AND ', $filters);
         } else {
             $query = 'SELECT a.*, b.*, c.order_product_quantity FROM ' . hikaserial::table('shop.file') . ' AS a ' . ' LEFT JOIN ' . hikaserial::table('shop.download') . ' AS b ON b.order_id=' . $order->order_id . ' AND a.file_id = b.file_id ' . ' LEFT JOIN ' . hikaserial::table('shop.order_product') . ' AS c ON c.order_id=' . $order->order_id . ' AND c.product_id = a.file_ref_id ' . ' WHERE ' . implode(' AND ', $filters);
         }
         $this->db->setQuery($query);
         $fileData = $this->db->loadObject();
         if (!empty($fileData)) {
             if (!empty($file->file_limit) && (int) $file->file_limit != 0) {
                 $download_number_limit = (int) $file->file_limit;
             } else {
                 $download_number_limit = $shopConfig->get('download_number_limit', 0);
             }
             if ($download_number_limit < 0) {
                 $download_number_limit = 0;
             }
             if (isset($fileData->order_product_quantity) && (int) $fileData->order_product_quantity > 0) {
                 $download_number_limit *= (int) $fileData->order_product_quantity;
             }
             if (!empty($download_number_limit) && $download_number_limit <= $fileData->download_number) {
                 $app->enqueueMessage(JText::_('MAX_REACHED_NO_DOWNLOAD'));
                 return 'limit';
             }
         } else {
             $app->enqueueMessage(JText::_('FILE_NOT_FOUND'));
             return 'no_file';
         }
         $serials = $this->getOrderFileSerials($file);
         if (empty($serials)) {
             return 'no_serial';
         }
         $f = false;
         foreach ($serials as $s) {
             if ($s->serial_data == $serial) {
                 $f = true;
                 break;
             }
         }
         if (!$f) {
             return 'wrong_serial';
         }
     }
     if (!empty($file)) {
         $path = $fileClass->getPath('file');
         if (substr($file->file_path, 0, 7) == 'http://' || substr($file->file_path, 0, 1) == '@' || substr($file->file_path, 0, 1) == '#' || file_exists($path . $file->file_path) || file_exists($file->file_path)) {
             if (!$app->isAdmin()) {
                 if (!empty($file->file_free_download)) {
                     $order_id = 0;
                 }
                 $query = 'SELECT * FROM ' . hikaserial::table('shop.download') . ' WHERE file_id=' . $file->file_id . ' AND order_id=' . $order_id . ' AND file_pos=' . $file_pos;
                 $this->db->setQuery($query);
                 $download = $this->db->loadObject();
                 if (empty($download)) {
                     $query = 'INSERT INTO ' . hikaserial::table('shop.download') . ' (file_id,order_id,download_number,file_pos) VALUES(' . $file->file_id . ',' . $order_id . ',1,' . $file_pos . ');';
                 } else {
                     $query = 'UPDATE ' . hikaserial::table('shop.download') . ' SET download_number=download_number+1 WHERE file_id=' . $file->file_id . ' AND order_id=' . $order_id . ' AND file_pos=' . $file_pos;
                 }
                 $this->db->setQuery($query);
                 $this->db->query();
             }
             $file->order_id = (int) $order_id;
             $file->file_pos = $file_pos;
             $fileClass->sendFile($file, true, $path);
         }
     }
     $app->enqueueMessage(JText::_('FILE_NOT_FOUND'));
     return false;
 }
예제 #26
0
 function generateCoupon($allresults, $i, $user, $send)
 {
     $db =& JFactory::getDBO();
     $packClass = hikaserial::get('class.pack');
     $config = hikaserial::config();
     $generator = null;
     $serials = array();
     $order = null;
     list($pack_id, $serial_status) = explode('|', $allresults[1][$i]);
     if (empty($serial_status)) {
         $serial_status = $config->get('used_serial_status', 'used');
     }
     $pack = $packClass->get($pack_id);
     if (substr($pack->pack_generator, 0, 4) == 'plg.') {
         $pluginName = substr($pack->pack_generator, 4);
         if (strpos($pluginName, '-') !== false) {
             list($pluginName, $pluginId) = explode('-', $pluginName, 2);
             $pack->{$pluginName} = $pluginId;
         }
         $generator = hikaserial::import('hikaserial', $pluginName);
     }
     if ($generator != null && method_exists($generator, 'generate')) {
         if (!$send) {
             $generator->test = true;
         }
         ob_start();
         $generator->generate($pack, $order, 1, $serials);
         ob_get_clean();
     }
     if ($send && !empty($serials)) {
         $serial = reset($serials);
         $extra_data = '';
         if (is_object($serial)) {
             if (!empty($serial->extradata)) {
                 $extra_data = serialize($serial->extradata);
             }
             $serial = $serial->data;
         }
         $data = array('serial_pack_id' => (int) $pack_id, 'serial_data' => $db->Quote($serial), 'serial_status' => $db->Quote($serial_status), 'serial_assign_date' => 'NULL', 'serial_order_id' => 'NULL', 'serial_user_id' => 'NULL', 'serial_order_product_id' => 'NULL', 'serial_extradata' => $db->Quote($extra_data));
         $query = 'INSERT IGNORE INTO ' . hikaserial::table('serial') . ' (' . implode(',', array_keys($data)) . ') VALUES (' . implode(',', $data) . ')';
         $db->setQuery($query);
         $db->query();
         unset($query);
         return $serial;
     } elseif (!empty($serials)) {
         $serial = reset($serials);
         if (is_object($serial)) {
             $serial = $serial->data;
         }
         return $serial;
     }
     return '';
 }
?>
</label></td>
			<td><?php 
$packType = hikaserial::get('type.pack');
echo $packType->displayMultiple('data[plugin][plugin_params][packs]', @$this->element->plugin_params->packs);
?>
</td>
		</tr>
		<tr>
			<td class="key"><label for="data[plugin][plugin_params][custom_field]"><?php 
echo JText::_('SERIAL_PLUGIN_CUSTOM_FIELD');
?>
</label></td>
			<td><?php 
$db = JFactory::getDBO();
$query = 'SELECT field.field_namekey, field.field_realname, field.field_table ' . ' FROM ' . hikaserial::table('shop.field') . ' AS field ' . ' WHERE field.field_table IN (\'order\', \'item\') AND field.field_type IN (\'text\',\'textarea\',\'radio\',\'checkbox\',\'singledropdown\',\'multipledropdown\') AND field_published = 1 AND field_frontcomp = 1' . ' ORDER BY field.field_table, field.field_realname';
$db->setQuery($query);
$customfields = $db->loadObjectList();
$fields = array();
foreach ($customfields as $customfield) {
    $fields[] = JHTML::_('select.option', $customfield->field_table . '.' . $customfield->field_namekey, $customfield->field_table . ' - ' . $customfield->field_realname);
}
unset($query);
unset($customfields);
echo JHTML::_('select.genericlist', $fields, 'data[plugin][plugin_params][custom_field]', '', 'value', 'text', @$this->element->plugin_params->custom_field);
?>
</td>
		</tr>
		<tr>
			<td class="key"><label for="data[plugin][plugin_params][call_attachserial]"><?php 
echo JText::_('SERIAL_PLUGIN_USE_ATTACHSERIAL');
예제 #28
0
파일: order.php 프로젝트: q0821/esportshop
 public function reOrder()
 {
     $db = JFactory::getDBO();
     $orderingMap = $this->orderingMap;
     $query = 'SELECT MAX(`' . $orderingMap . '`) FROM ' . hikaserial::table($this->table) . $this->group(true);
     $db->setQuery($query);
     $max = $db->loadResult() + 1;
     $query = 'UPDATE ' . hikaserial::table($this->table) . ' SET `' . $orderingMap . '` =' . $max . ' WHERE `' . $orderingMap . '`=0' . $this->group();
     $db->setQuery($query);
     $db->query();
     $query = 'SELECT `' . $orderingMap . '`,`' . $this->pkey . '` FROM ' . hikaserial::table($this->table) . $this->group(true);
     $query .= ' ORDER BY `' . $orderingMap . '` ASC';
     $db->setQuery($query);
     $results = $db->loadObjectList();
     $i = 1;
     if (!empty($results)) {
         foreach ($results as $oneResult) {
             if ($oneResult->{$orderingMap} != $i) {
                 $oneResult->{$orderingMap} = $i;
                 $db->updateObject(hikaserial::table($this->table), $oneResult, $this->pkey);
             }
             $i++;
         }
     }
 }
예제 #29
0
 protected function addColumns($table, $columns)
 {
     if (!is_array($columns)) {
         $columns = array($columns);
     }
     $query = 'ALTER TABLE `' . hikaserial::table($table) . '` ADD ' . implode(', ADD', $columns) . ';';
     $this->db->setQuery($query);
     $err = false;
     try {
         $this->db->query();
     } catch (Exception $e) {
         $err = true;
     }
     if (!$err) {
         return true;
     }
     if ($err && count($columns) > 1) {
         foreach ($columns as $col) {
             $query = 'ALTER TABLE `' . hikaserial::table($table) . '` ADD ' . $col . ';';
             $this->db->setQuery($query);
             $err = 0;
             try {
                 $this->db->query();
             } catch (Exception $e) {
                 $err++;
             }
         }
         if ($err < count($columns)) {
             return true;
         }
     }
     return false;
 }