public function displayMultiple($map, $values) { if (empty($this->values)) { $this->load(); } if (empty($values)) { $values = array(); } else { if (is_string($values)) { $values = explode(',', $values); } } $shopConfig = hikaserial::config(false); hikaserial::loadJslib('otree'); if (substr($map, -2) == '[]') { $map = substr($map, 0, -2); } $id = str_replace(array('[', ']'), array('_', ''), $map); $ret = '<div class="nameboxes" id="' . $id . '" onclick="window.oNameboxes[\'' . $id . '\'].focus(\'' . $id . '_text\');">'; if (!empty($values)) { foreach ($values as $key) { if (isset($this->values[$key])) { $name = $this->values[$key]->text; } else { $name = JText::sprintf('UNKNOWN_PACK_X', $key); } $ret .= '<div class="namebox" id="' . $id . '_' . $key . '">' . '<input type="hidden" name="' . $map . '[]" value="' . $key . '"/>' . $name . ' <a class="closebutton" href="#" onclick="window.oNameboxes[\'' . $id . '\'].unset(this,\'' . $key . '\');window.oNamebox.cancelEvent();return false;"><span>X</span></a>' . '</div>'; } } $ret .= '<div class="namebox" style="display:none;" id="' . $id . 'tpl">' . '<input type="hidden" name="{map}" value="{key}"/>{name}' . ' <a class="closebutton" href="#" onclick="window.oNameboxes[\'' . $id . '\'].unset(this,\'{key}\');window.oNamebox.cancelEvent();return false;"><span>X</span></a>' . '</div>'; $ret .= '<div class="nametext">' . '<input id="' . $id . '_text" type="text" style="width:50px;min-width:60px" onfocus="window.oNameboxes[\'' . $id . '\'].focus(this);" onkeyup="window.oNameboxes[\'' . $id . '\'].search(this);" onchange="window.oNameboxes[\'' . $id . '\'].search(this);"/>' . '<span style="position:absolute;top:0px;left:-2000px;visibility:hidden" id="' . $id . '_span">span</span>' . '</div>'; $data = array(); foreach ($this->values as $key => $value) { if (empty($key)) { continue; } $data[$key] = $value->text; } $namebox_options = array('mode' => 'list', 'img_dir' => HIKASHOP_IMAGES, 'map' => $map, 'min' => $shopConfig->get('namebox_search_min_length', 3), 'multiple' => true); $ret .= '<div style="clear:both;float:none;"></div></div> <div class="namebox-popup"> <div id="' . $id . '_olist" style="display:none;" class="oList namebox-popup-content"></div> </div> <script type="text/javascript"> new window.oNamebox( \'' . $id . '\', ' . json_encode($data) . ', ' . json_encode($namebox_options) . ' );'; if (!empty($values)) { $ret .= ' try{ window.oNameboxes[\'' . $id . '\'].content.block(' . json_encode($values) . '); }catch(e){}'; } $ret .= ' </script>'; return $ret; }
public function __construct() { $this->db = JFactory::getDBO(); $this->config = hikaserial::config(); $this->shopConfig = hikaserial::config(false); $this->serialClass = hikaserial::get('class.serial'); $this->packClass = hikaserial::get('class.pack'); }
public function create($string) { $string = str_replace('&', '&', preg_replace('#(index\\.php\\??)#i', '', $string)); $query = array(); $allValues = explode('&', $string); foreach ($allValues as $oneValue) { list($var, $val) = explode('=', $oneValue); $query[$var] = $val; } $segments = array(); if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } if (class_exists('hikaserial') || (include_once rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_hikaserial' . DS . 'helpers' . DS . 'helper.php')) { $shopConfig = hikaserial::config(false); if ($shopConfig->get('activate_sef', 1)) { } } if (isset($query['ctrl'])) { $segments[] = $query['ctrl']; unset($query['ctrl']); if (isset($query['task'])) { $segments[] = $query['task']; unset($query['task']); } } elseif (isset($query['view'])) { $segments[] = $query['view']; unset($query['view']); if (isset($query['layout'])) { $segments[] = $query['layout']; unset($query['layout']); } } if (isset($query['cid']) && isset($query['name'])) { if (is_numeric($query['name'])) { $query['name'] = $query['name'] . '-'; } $segments[] = $query['cid'] . ':' . $query['name']; unset($query['cid']); unset($query['name']); } unset($query['option']); if (isset($query['Itemid'])) { unset($query['Itemid']); } if (!empty($query)) { foreach ($query as $name => $value) { $segments[] = $name . ':' . $value; } } return implode('/', $segments); }
private function showIframe($url) { $config = hikaserial::config(); $shopConfig = hikaserial::config(false); $menu_style = $shopConfig->get('menu_style', 'title_bottom'); if (HIKASHOP_J30) { $menu_style = 'content_top'; } if ($menu_style == 'content_top') { echo hikaserial::getMenu(); } echo '<div id="hikaserial_div"><iframe allowtransparency="true" scrolling="auto" height="450px" frameborder="0" width="100%" name="hikaserial_frame" id="hikaserial_frame" ' . 'src="' . $url . '&level=' . $config->get('level') . '&component=' . HIKASERIAL_LNAME . '&version=' . $config->get('version') . '"></iframe></div>'; }
public function generate() { $pack_id = hikaserial::getCID(); $formData = JRequest::getVar('data', array(), '', 'array'); if (!empty($formData) && !empty($formData['number_serials']) && (int) $formData['number_serials'] > 0 && !empty($pack_id)) { JRequest::checkToken('request') || die('Invalid Token'); $quantity = (int) $formData['number_serials']; $app = JFactory::getApplication(); $db = JFactory::getDBO(); $config = hikaserial::config(); $packClass = hikaserial::get('class.pack'); $pack = $packClass->get($pack_id); $serial_status = @$formData['serial_status']; if (empty($serial_status)) { $serial_status = $config->get('unassigned_serial_status', 'free'); } $pluginId = 0; $pluginName = substr($pack->pack_generator, 4); if (strpos($pluginName, '-') !== false) { list($pluginName, $pluginId) = explode('-', $pluginName, 2); $pack->{$pluginName} = $pluginId; } $serials = array(); $order = new stdClass(); $order->hikaserial = new stdClass(); $order->hikaserial->type = 'generate'; $order->hikaserial->formData = $formData; $plugin = hikaserial::import('hikaserial', $pluginName); if (method_exists($plugin, 'generate')) { ob_start(); $plugin->generate($pack, $order, $quantity, $serials); ob_get_clean(); } if (!empty($serials)) { $struct = array('serial_pack_id' => (int) $pack_id, 'serial_status' => $serial_status); $serialClass = hikaserial::get('class.serial'); $serialClass->generate($serials, $struct); $app->enqueueMessage(JText::sprintf('X_SERIAL_GENERATED', count($serials))); // _('X_SERIAL_GENERATED') } else { $app->enqueueMessage(JText::_('ERROR_GENERATING_SERIALS'), 'error'); } JRequest::setVar('serials', $serials); } JRequest::setVar('hidemainmenu', 1); JRequest::setVar('layout', 'generate'); return $this->display(); }
public function show($tpl = null) { hikaserial::setTitle(JText::_(self::name), self::icon, self::ctrl); $config = hikaserial::config(); $this->assignRef('config', $config); $importData = array(array('text' => JText::_('IMPORT_FROM_CSV'), 'key' => 'csv'), array('text' => JText::_('IMPORT_FROM_TEXTAREA'), 'key' => 'textarea')); $this->assignRef('importData', $importData); $defaultValue = $importData[0]['key']; $this->assignRef('defaultValue', $defaultValue); $importValues = array(); foreach ($importData as $data) { $importValues[] = JHTML::_('select.option', $data['key'], $data['text']); } $this->assignRef('importValues', $importValues); $this->toolbar = array('|', array('name' => 'custom', 'icon' => 'upload', 'alt' => JText::_('IMPORT'), 'task' => 'import', 'check' => false), '|', array('name' => 'pophelp', 'target' => self::ctrl), 'dashboard'); }
public function sql($tpl = null) { hikaserial::setTitle(JText::_('HIKA_CONFIGURATION_SQL'), self::icon, self::ctrl); $config = hikaserial::config(); $this->assignRef('config', $config); $toolbar = JToolBar::getInstance('toolbar'); $sql_data = JRequest::getVar('sql_data', '', '', 'string', JREQUEST_ALLOWRAW); $this->assignRef('sql_data', $sql_data); $user = JFactory::getUser(); $iAmSuperAdmin = false; if (!HIKASHOP_J16) { $iAmSuperAdmin = $user->get('gid') == 25; } else { $iAmSuperAdmin = $user->authorise('core.admin'); } $query_result = ''; if (!empty($sql_data) && $iAmSuperAdmin) { $p = strpos($sql_data, ' '); if ($p) { $db = JFactory::getDBO(); $word = strtolower(substr($sql_data, 0, $p)); if (in_array($word, array('insert', 'update', 'delete'))) { $db->setQuery($sql_data); $db->query(); $query_result = JText::_('HIKA_X_ROWS_AFFECTED', $db->getAffectedRows()); } else { if ($word == 'select') { $db->setQuery($sql_data); $query_result = $db->loadObjectList(); } else { if (in_array($word, array('create', 'drop', 'alter'))) { $db->setQuery($sql_data); if ($db->query()) { $query_result = JText::_('HIKA_QUERY_SUCCESS'); } else { $query_result = JText::_('HIKA_QUERY_FAILURE'); } } } } } } $this->assignRef('query_result', $query_result); $this->toolbar = array('|', array('name' => 'custom', 'icon' => 'apply', 'alt' => JText::_('APPLY'), 'task' => 'sql', 'check' => false), 'hikacancel', '|', array('name' => 'pophelp', 'target' => 'config'), 'dashboard'); }
function listing() { hikaserial::setTitle(JText::_(self::name), self::icon, self::ctrl); $bar = JToolBar::getInstance('toolbar'); $bar->appendButton('Link', HIKASERIAL_LNAME, JText::_('HIKASHOP_CPANEL'), hikaserial::completeLink('dashboard')); $config = hikaserial::config(); $level = $config->get('level'); $url = HIKASERIAL_HELPURL . 'documentation&level=' . $level; $shopConfig = hikaserial::config(false); $menu_style = $shopConfig->get('menu_style', 'title_bottom'); if (HIKASHOP_J30) { $menu_style = 'content_top'; } if ($menu_style == 'content_top') { echo hikaserial::getMenu(); } echo '<div id="hikaserial_div"><iframe allowtransparency="true" scrolling="auto" height="450px" frameborder="0" width="100%" name="hikaserial_frame" id="hikaserial_frame" src="' . $url . '"></iframe></div>'; }
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); }
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); }
public function coupon() { $app = JFactory::getApplication(); global $Itemid; $url_itemid = ''; if (!empty($Itemid)) { $url_itemid = '&Itemid=' . $Itemid; } $this->assignRef('url_itemid', $url_itemid); $config = hikaserial::config(); $this->assignRef('config', $config); $shopConfig = hikaserial::config(false); $this->assignRef('shopConfig', $shopConfig); $cart = $this->params->view->initCart(); if (isset($cart->coupon)) { $this->assignRef('coupon', $cart->coupon); } $this->assignRef('step', $this->params->view->step); $cartHelper = hikaserial::get('shop.helper.cart'); $this->assignRef('cartHelper', $cartHelper); }
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); }
public function fetchButton($type = 'Pophelp', $namekey = '', $id = 'pophelp') { $doc = JFactory::getDocument(); $config = hikaserial::config(); $level = $config->get('level'); $url = HIKASERIAL_HELPURL . $namekey . '&level=' . $level; $js = ' function displayDoc(){ var d = document, init = false, b = d.getElementById("iframedoc"); if(!b) return true; if(typeof(b.openHelp) == "undefined") { b.openHelp = true; init = true; } if(b.openHelp) { b.innerHTML = \'<iframe src="' . $url . '" width="100%" height="100%" style="border:0px" border="no" scrolling="auto"></iframe>\'; b.setStyle("display","block"); } try { if(typeof(b.fxEffect) == "undefined") { b.fxEffect = b.effects({duration: 1500, transition: Fx.Transitions.Quart.easeOut}); } if(b.openHelp){ if(init) { b.height = 0; b.style.height = 0; } b.fxEffect.stop(); b.fxEffect.start({height: 300}); }else{ b.fxEffect.stop(); b.fxEffect.start({height: 0}).chain(function() { b.innerHTML = ""; b.setStyle("display", "none"); }); } } catch(err) { if(typeof(b.vslide) == "undefined") { b.vslide = new Fx.Slide("iframedoc"); } if(b.openHelp){ if(init) { b.vslide.hide(); } b.vslide.slideIn(); }else{ b.vslide.slideOut().chain(function() { b.innerHTML = ""; b.setStyle("display", "none"); }); } } b.openHelp = !b.openHelp; return false; }'; $doc->addScriptDeclaration($js); if (!HIKASHOP_J30) { return '<a href="' . $url . '" target="_blank" onclick="return displayDoc();" class="toolbar"><span class="icon-32-help" title="' . JText::_('HIKA_HELP', true) . '"></span>' . JText::_('HIKA_HELP') . '</a>'; } return '<button class="btn btn-small" onclick="return displayDoc();"><i class="icon-help"></i> ' . JText::_('HIKA_HELP') . '</button>'; }
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)); } }
?> </label></td> <td> <input style="width:100%" type="text" name="data[plugin][plugin_params][image_path]" value="<?php echo @$this->element->plugin_params->image_path; ?> "/> <?php if (!empty($this->element->plugin_params->image_path)) { $file_path = $this->element->plugin_params->image_path; $realfilepath = HIKASERIAL_ROOT . $file_path; if (!JFile::exists($realfilepath)) { $realfilepath = null; } if (empty($realfilepath)) { $shopConfig = hikaserial::config(false); $uploadFolder = ltrim(JPath::clean(html_entity_decode($shopConfig->get('uploadfolder'))), DS); $realfilepath = JPATH_ROOT . DS . rtrim($uploadFolder, DS) . DS . $file_path; if (!JFile::exists($realfilepath)) { $realfilepath = null; } } if (empty($realfilepath)) { $realfilepath = $file_path; if (!JFile::exists($file_path)) { $realfilepath = null; } } $display_filename = '<span class="attachserial_filename">' . $file_path . '</span>'; $extension = strtolower(substr($file_path, strrpos($file_path, '.') + 1)); if (!empty($realfilepath) && !in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) {
public function consume($serial_id, $extra_data = null, $checkUser = true) { $app = JFactory::getApplication(); $config = hikaserial::config(); $serial = $this->get($serial_id, true); $assigned_status = $config->get('assigned_serial_status', 'assigned'); $used_status = $config->get('used_serial_status', 'used'); $do = true; if (!empty($serial->pack->pack_params) && is_string($serial->pack->pack_params)) { $serial->pack->pack_params = unserialize($serial->pack->pack_params); } if (empty($serial->pack->pack_params->consumer) || !$serial->pack->pack_params->consumer || $serial->serial_status != $assigned_status) { return false; } $user_id = 0; if (!$app->isAdmin() && $checkUser) { $user_id = hikaserial::loadUser(); if ($user_id == 0 || $serial->serial_user_id > 0 && $serial->serial_user_id != $user_id) { return false; } } JPluginHelper::importPlugin('hikashop'); JPluginHelper::importPlugin('hikaserial'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onBeforeSerialConsume', array(&$serial, $user_id, &$do, &$extra_data)); if (!$do) { return false; } if (!empty($serial->managed)) { return $serial->serial_id; } $serialConsumed = new stdClass(); $serialConsumed->serial_id = $serial->serial_id; $serialConsumed->serial_status = $used_status; if (!empty($serial->status)) { $serialConsumed->serial_status = $serial->status; } if ($user_id > 0) { $serialConsumed->serial_user_id = $user_id; } if (!empty($extra_data)) { $serialConsumed->serial_extradata = array(); if (!empty($serial->serial_extradata)) { $serialConsumed->serial_extradata = $serial->serial_extradata; } foreach ($extra_data as $key => $value) { $serialConsumed->serial_extradata[$key] = $value; } } $status = $this->save($serialConsumed); if ($status) { $dispatcher->trigger('onAfterSerialConsume', array(&$serial)); } return $status; }
private function includeImage($img, $d) { $shopConfig = hikaserial::config(false); $uploadFolder = JPATH_ROOT . DS . $shopConfig->get('uploadfolder', 'media/com_hikashop/upload/'); $filename = $d['text']; $file_path = ''; jimport('joomla.filesystem.file'); if (JFile::exists($uploadFolder . $filename)) { $file_path = $uploadFolder . $filename; } else { if (JFile::exists(HIKASHOP_MEDIA . 'images' . DS . $filename)) { $file_path = HIKASHOP_MEDIA . 'images' . DS . $filename; } } if (empty($file_path)) { return null; } $extension = strtolower(substr($file_path, strrpos($file_path, '.') + 1)); $include_image = $this->initializeImage($file_path, $extension); $imgW = imagesx($include_image); $imgH = imagesy($include_image); $finalW = $imgW; $finalH = $imgH; if (!empty($d['w']) || !empty($d['h'])) { if (empty($d['w'])) { $d['w'] = 0; } if (empty($d['h'])) { $d['h'] = 0; } $scale = $this->scaleImage($imgW, $imgH, (int) $d['w'], (int) $d['h']); if (!empty($scale)) { $finalW = $scale[0]; $finalH = $scale[1]; } } imagesavealpha($img, false); imagealphablending($img, true); imagecopyresized($img, $include_image, $d['x'], $d['y'], 0, 0, $finalW, $finalH, $imgW, $imgH); imagedestroy($include_image); imagealphablending($img, false); imagesavealpha($img, true); return null; }
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; }
<?php /** * @package HikaSerial for Joomla! * @version 1.9.1 * @author Obsidev S.A.R.L. * @copyright (C) 2011-2015 OBSIDEV. All rights reserved. * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ defined('_JEXEC') or die('Restricted access'); if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } include_once rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_hikaserial' . DS . 'helpers' . DS . 'helper.php'; $taskGroup = JRequest::getCmd('ctrl', 'dashboard'); $hikaSerialConfig = hikaserial::config(); JHTML::_('behavior.tooltip'); $bar = JToolBar::getInstance('toolbar'); $bar->addButtonPath(HIKASERIAL_BUTTON); if ($taskGroup != 'update' && !$hikaSerialConfig->get('installcomplete')) { $url = hikaserial::completeLink('update&task=install', false, true); echo '<script>document.location.href="' . $url . '";</script>' . "\r\n" . 'Install not finished... You will be redirected to the second part of the install screen<br/>' . '<a href="' . $url . '">Please click here if you are not automatically redirected within 3 seconds</a>'; return; } $currentuser = JFactory::getUser(); if ($taskGroup != 'update' && HIKASHOP_J16 && !$currentuser->authorise('core.manage', 'com_hikaserial')) { return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); } if ($taskGroup == 'config' && HIKASHOP_J16 && !$currentuser->authorise('core.admin', 'com_hikaserial')) { return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); }
public function select() { $app = JFactory::getApplication(); $db = JFactory::getDBO(); hikaserial::setTitle(JText::_(self::name), self::icon, self::ctrl); $config = hikaserial::config(); $this->assignRef('config', $config); $shopConfig = hikaserial::config(false); $this->assignRef('shopConfig', $shopConfig); $serialStatusType = hikaserial::get('type.serial_status'); $this->assignRef('serialStatusType', $serialStatusType); $packType = hikaserial::get('type.pack'); $this->assignRef('packType', $packType); $filterType = $app->getUserStateFromRequest($this->paramBase . ".filter_type", 'filter_type', 0, 'int'); $singleSelection = JRequest::getVar('single', false); $this->assignRef('singleSelection', $singleSelection); $confirm = JRequest::getVar('confirm', true); $this->assignRef('confirm', $confirm); $elemStruct = array('serial_data', 'serial_id', 'serial_pack_id', 'serial_status', 'pack_name'); $this->assignRef('elemStruct', $elemStruct); $cfg = array('table' => 'serial', 'main_key' => 'serial_id', 'order_sql_value' => 'a.serial_id'); $manage = true; // TODO $this->assignRef('manage', $manage); $manage_shop_order = hikaserial::isAllowed($shopConfig->get('acl_order_manage', 'all')); $this->assignRef('manage_shop_order', $manage_shop_order); $manage_shop_user = hikaserial::isAllowed($shopConfig->get('acl_user_manage', 'all')); $this->assignRef('manage_shop_user', $manage_shop_user); $pageInfo = new stdClass(); $filters = array(); $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->filter->order = new stdClass(); $pageInfo->filter->order->value = $app->getUserStateFromRequest($this->paramBase . ".filter_order", 'filter_order', $cfg['order_sql_value'], 'cmd'); $pageInfo->filter->order->dir = $app->getUserStateFromRequest($this->paramBase . ".filter_order_Dir", 'filter_order_Dir', 'asc', 'word'); $pageInfo->limit = new stdClass(); $pageInfo->limit->value = $app->getUserStateFromRequest($this->paramBase . '.list_limit', 'limit', $app->getCfg('list_limit'), 'int'); if (empty($pageInfo->limit->value)) { $pageInfo->limit->value = 500; } if (JRequest::getVar('search') != $app->getUserState($this->paramBase . ".search")) { $app->setUserState($this->paramBase . '.limitstart', 0); $pageInfo->limit->start = 0; } else { $pageInfo->limit->start = $app->getUserStateFromRequest($this->paramBase . '.limitstart', 'limitstart', 0, 'int'); } $pageInfo->search = JString::strtolower($app->getUserStateFromRequest($this->paramBase . ".search", 'search', '', 'string')); $this->assignRef('pageInfo', $pageInfo); $filters = array(); $searchMap = array('a.serial_id', 'a.serial_data', 'a.serial_status', 'b.pack_name', 'd.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[] = ' a.serial_status = ' . $db->quote($pageInfo->filter->serial_status); } if (!empty($pageInfo->filter->pack)) { if ((int) $pageInfo->filter->pack > 0) { $filters[] = ' b.pack_id = ' . (int) $pageInfo->filter->pack; } else { $filters[] = ' b.pack_name = ' . $db->quote($pageInfo->filter->pack); } } if (!empty($filters)) { $filters = ' WHERE ' . implode(' AND ', $filters); } else { $filters = ''; } $order = ''; if (!empty($pageInfo->filter->order->value)) { $order = ' ORDER BY ' . $pageInfo->filter->order->value . ' ' . $pageInfo->filter->order->dir; } $query = 'FROM ' . hikaserial::table($cfg['table']) . ' AS a INNER JOIN ' . hikaserial::table('pack') . ' AS b ON a.serial_pack_id = b.pack_id LEFT JOIN ' . hikaserial::table('shop.user') . ' AS c ON a.serial_user_id = c.user_id LEFT JOIN ' . hikaserial::table('users', false) . ' AS d ON c.user_cms_id = d.id LEFT JOIN ' . hikaserial::table('shop.order') . ' AS e ON a.serial_order_id = e.order_id ' . $filters . $order; $db->setQuery('SELECT * ' . $query, (int) $pageInfo->limit->start, (int) $pageInfo->limit->value); $rows = $db->loadObjectList(); if (!empty($pageInfo->search)) { $rows = hikaserial::search($pageInfo->search, $rows, $cfg['main_key']); } $this->assignRef('rows', $rows); JPluginHelper::importPlugin('hikaserial'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onDisplaySerials', array(&$rows, 'back-serial-listing')); $db->setQuery('SELECT COUNT(*) ' . $query); $pageInfo->elements = new stdClass(); $pageInfo->elements->total = $db->loadResult(); $pageInfo->elements->page = count($rows); jimport('joomla.html.pagination'); if ($pageInfo->limit->value == 500) { $pageInfo->limit->value = 100; } $pagination = new JPagination($pageInfo->elements->total, $pageInfo->limit->start, $pageInfo->limit->value); $this->assignRef('pagination', $pagination); $doOrdering = !$filterType; $this->assignRef('doOrdering', $doOrdering); if ($doOrdering) { $ordering = new stdClass(); $ordering->ordering = false; $ordering->orderUp = 'orderup'; $ordering->orderDown = 'orderdown'; $ordering->reverse = false; if ($pageInfo->filter->order->value == 'a.ordering') { $ordering->ordering = true; if ($pageInfo->filter->order->dir == 'desc') { $ordering->orderUp = 'orderdown'; $ordering->orderDown = 'orderup'; $ordering->reverse = true; } } $this->assignRef('ordering', $ordering); } }
private function deleteConfig($namekey, $val) { $config = hikaserial::config(); $newConfig = new stdClass(); $newConfig->{$namekey} = $val; $config->save($newConfig); }
public function consume() { $formData = JRequest::getVar('hikaserial', array(), '', 'array'); JRequest::setVar('layout', 'consume'); if (empty($formData) || empty($formData['serial_data'])) { return $this->display(); } $config = hikaserial::config(); $serialClass = hikaserial::get('class.serial'); $serial_data = $formData['serial_data']; $serial_extra_data = null; if (!empty($formData['serial_extra_data'])) { $serial_extra_data = array(); if (is_array($formData['serial_extra_data'])) { $serial_extra_data = $formData['serial_extra_data']; } else { $serial_extra_data = array($formData['serial_extra_data']); } } $serial = null; $pack = null; if (!empty($formData['pack_name']) && is_string($formData['pack_name'])) { $pack = $formData['pack_name']; } if (!empty($formData['pack_id'])) { $pack = (int) $formData['pack_id']; } $user_id = 0; if (empty($formData['format'])) { JRequest::checkToken('request') || die('Invalid Token'); $user_id = hikaserial::loadUser(); if (empty($user_id) && $config->get('forbidden_consume_guest', 1)) { $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('CONSUME_NOT_LOGGED'), 'error'); return $this->display(); } if (empty($user_id)) { $user_id = null; } $filters = null; if ($pack !== null) { if (is_int($pack)) { $filters = array('pack.pack_id = ' . $pack); } else { $db = JFactory::getDBO(); $filters = array('pack.pack_name = ' . $db->Quote($pack)); } } $serials = $serialClass->find($serial_data, $filters, array('serial_user_id DESC', 'serial_id ASC')); } else { $serials = $serialClass->check($serial_data, $pack); JRequest::setVar('layout', 'consumed'); } if (count($serials) == 1) { $serial = reset($serials); } else { if (!empty($serials)) { $assigned_status = $config->get('assigned_serial_status', 'assigned'); foreach ($serials as $s) { if (($s->serial_user_id == $user_id || $s->serial_user_id == 0 || $user_id === 0) && $s->serial_status == $assigned_status) { $serial = $s; } if ($serial != null) { break; } } } } if (empty($serial) || empty($serial->serial_id)) { JRequest::setVar('consumed_serial', false); return $this->display(); } $ret = false; $assigned_status = $config->get('assigned_serial_status', 'assigned'); if ($serial->serial_status != $assigned_status) { $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('HIKASERIAL_ALREADY_USED'), 'error'); } else { $packClass = hikaserial::get('class.pack'); $serial_pack = $packClass->get((int) $serial->serial_pack_id); $checkUser = !empty($serial_pack->pack_params->consume_user_assign); $ret = $serialClass->consume($serial->serial_id, $serial_extra_data, $checkUser); } if ($ret) { $serial = $serialClass->get($serial->serial_id, true); JRequest::setVar('consumed_serial', $serial); JRequest::setVar('layout', 'consumed'); } else { JRequest::setVar('consumed_serial', false); } return $this->display(); }
public function select() { $app = JFactory::getApplication(); $db = JFactory::getDBO(); $config = hikaserial::config(); $this->assignRef('config', $config); $toggleClass = hikaserial::get('helper.toggle'); $this->assignRef('toggleClass', $toggleClass); $packGeneratorType = hikaserial::get('type.pack_generator'); $this->assignRef('packGeneratorType', $packGeneratorType); $serialStatusType = hikaserial::get('type.serial_status'); $this->assignRef('serialStatusType', $serialStatusType); $filterType = $app->getUserStateFromRequest($this->paramBase . ".filter_type", 'filter_type', 0, 'int'); $singleSelection = JRequest::getVar('single', false); $confirm = JRequest::getVar('confirm', true); $cfg = array('table' => 'pack', 'main_key' => 'pack_id', 'order_sql_value' => 'a.pack_id'); $elemStruct = array('pack_name', 'pack_data', 'pack_generator'); $manage = true; $this->assignRef('manage', $manage); $pageInfo = new stdClass(); $pageInfo->search = $app->getUserStateFromRequest($this->paramBase . ".search", 'search', '', 'string'); $pageInfo->filter = new stdClass(); $pageInfo->filter->order = new stdClass(); $pageInfo->filter->order->value = $app->getUserStateFromRequest($this->paramBase . ".filter_order", 'filter_order', 'a.pack_id', 'cmd'); $pageInfo->filter->order->dir = $app->getUserStateFromRequest($this->paramBase . ".filter_order_Dir", 'filter_order_Dir', 'desc', 'word'); $pageInfo->limit = new stdClass(); $pageInfo->limit->value = $app->getUserStateFromRequest($this->paramBase . '.list_limit', 'limit', $app->getCfg('list_limit'), 'int'); if (empty($pageInfo->limit->value)) { $pageInfo->limit->value = 500; } $pageInfo->limit->start = $app->getUserStateFromRequest($this->paramBase . '.limitstart', 'limitstart', 0, 'int'); $pageInfo->filter->filter_partner = $app->getUserStateFromRequest($this->paramBase . ".filter_partner", 'filter_partner', '', 'int'); $pageInfo->search = JString::strtolower($app->getUserStateFromRequest($this->paramBase . ".search", 'search', '', 'string')); $this->assignRef('pageInfo', $pageInfo); $filters = array(); $searchMap = array('a.pack_id', 'a.pack_name', 'a.pack_data', 'a.pack_generator'); if (!empty($pageInfo->search)) { $searchVal = '\'%' . $db->getEscaped($pageInfo->search, true) . '%\''; $filters[] = '(' . implode(' LIKE ' . $searchVal . ' OR ', $searchMap) . ' LIKE ' . $searchVal . ')'; } if (!empty($filters)) { $filters = ' WHERE ' . implode(' AND ', $filters); } else { $filters = ''; } $order = ''; if (!empty($pageInfo->filter->order->value)) { $order = ' ORDER BY ' . $pageInfo->filter->order->value . ' ' . $pageInfo->filter->order->dir; } $query = ' FROM ' . hikaserial::table('pack') . ' AS a ' . $filters . $order; $db->setQuery('SELECT * ' . $query, (int) $pageInfo->limit->start, (int) $pageInfo->limit->value); $rows = $db->loadObjectList(); if (!empty($pageInfo->search)) { $rows = hikaserial::search($pageInfo->search, $rows, 'pack_id'); } $this->assignRef('rows', $rows); $db->setQuery('SELECT COUNT(*)' . $query); $pageInfo->elements = new stdClass(); $pageInfo->elements->total = $db->loadResult(); $pageInfo->elements->page = count($rows); $query = 'SELECT serial_pack_id, serial_status, COUNT(serial_id) AS counter FROM ' . hikaserial::table('serial') . ' GROUP BY serial_pack_id, serial_status ORDER BY serial_pack_id, serial_status'; $db->setQuery($query); $dbcounters = $db->loadObjectList(); $counters = array(); foreach ($dbcounters as $counter) { if (!isset($counters[$counter->serial_pack_id])) { $counters[$counter->serial_pack_id] = array(); } $counters[$counter->serial_pack_id][$counter->serial_status] = $counter->counter; } unset($dbcounters); $this->assignRef('counters', $counters); jimport('joomla.html.pagination'); if ($pageInfo->limit->value == 500) { $pageInfo->limit->value = 100; } $pagination = new JPagination($pageInfo->elements->total, $pageInfo->limit->start, $pageInfo->limit->value); $this->assignRef('pagination', $pagination); $doOrdering = !$filterType; $this->assignRef('doOrdering', $doOrdering); if ($doOrdering) { $ordering = new stdClass(); $ordering->ordering = false; $ordering->orderUp = 'orderup'; $ordering->orderDown = 'orderdown'; $ordering->reverse = false; if ($pageInfo->filter->order->value == 'a.ordering') { $ordering->ordering = true; if ($pageInfo->filter->order->dir == 'desc') { $ordering->orderUp = 'orderdown'; $ordering->orderDown = 'orderup'; $ordering->reverse = true; } } $this->assignRef('ordering', $ordering); } $this->assignRef('singleSelection', $singleSelection); $this->assignRef('confirm', $confirm); $this->assignRef('elemStruct', $elemStruct); $this->assignRef('pageInfo', $pageInfo); }
public function addUpdateSite() { $config = hikaserial::config(); $newconfig = new stdClass(); $newconfig->website = HIKASHOP_LIVE; $config->save($newconfig); if (!HIKASHOP_J16) { return false; } $query = 'SELECT update_site_id FROM #__update_sites WHERE location LIKE \'%hikaserial%\' AND type = \'extension\''; $this->db->setQuery($query); $update_site_id = $this->db->loadResult(); $object = new stdClass(); $object->name = 'HikaSerial'; $object->type = 'extension'; $object->enabled = 1; $object->location = 'http://www.hikashop.com/component/updateme/updatexml/component-hikaserial/version-' . $config->get('version') . '/level-' . $config->get('level') . '/li-' . urlencode(base64_encode(HIKASHOP_LIVE)) . '/file-extension.xml'; if (empty($update_site_id)) { $this->db->insertObject('#__update_sites', $object); $update_site_id = $this->db->insertid(); } else { $object->update_site_id = $update_site_id; $this->db->updateObject('#__update_sites', $object, 'update_site_id'); } $query = 'SELECT extension_id FROM #__extensions WHERE `name` = \'hikaserial\' AND type LIKE \'component\''; $this->db->setQuery($query); $extension_id = $this->db->loadResult(); if (empty($update_site_id) || empty($extension_id)) { return false; } $query = 'INSERT IGNORE INTO #__update_sites_extensions (update_site_id, extension_id) values (' . $update_site_id . ',' . $extension_id . ')'; $this->db->setQuery($query); $this->db->query(); return true; }
private function afterCouponCheckoutStep(&$go_back, $original_go_back, &$controller) { $app = JFactory::getApplication(); $coupon = JRequest::getString('hikaserial_coupon', ''); $qty = 1; if (empty($coupon)) { $coupon = JRequest::getInt('removecoupon', 0); $qty = 0; } if (!empty($coupon)) { $go_back = true; $config = hikaserial::config(); $user_id = hikaserial::loadUser(); $serialClass = hikaserial::get('class.serial'); $serial = null; $serials = null; if (is_string($coupon)) { $serials = $serialClass->find($coupon, null, array('serial_user_id DESC', 'serial_id ASC')); } if (count($serials) == 1) { $serial = reset($serials); } else { if (!empty($serials)) { $assigned_status = $config->get('assigned_serial_status', 'assigned'); foreach ($serials as $s) { if (($s->serial_user_id == $user_id || $s->serial_user_id == 0 || $user_id == 0) && $s->serial_status == $assigned_status) { $serial = $s; } if ($serial != null) { break; } } } } $consume_ret = false; if (!empty($serial) && !empty($serial->serial_id)) { if (empty($user_id) && $config->get('forbidden_consume_guest', 1)) { $app->enqueueMessage(JText::_('CONSUME_NOT_LOGGED'), 'error'); } else { $consume_ret = $serialClass->consume($serial->serial_id, null, false); if ($consume_ret) { $full_serial = $serialClass->get($serial->serial_id); $msg = JText::sprintf('SERIAL_CHECKOUT_X_CONSUMED', $coupon); if (!empty($msg)) { $app->enqueueMessage($msg, 'success'); } } } } $cart = $controller->initCart(); $coupon_ret = false; if (empty($cart->coupon) || $coupon == 1 && $qty == 0) { $class = hikaserial::get('shop.class.cart'); if ($class->update($coupon, $qty, 0, 'coupon')) { if (strpos($controller->checkout_workflow, 'shipping') !== false) { $controller->before_shipping(true); } if (strpos($controller->checkout_workflow, 'payment') !== false) { $controller->before_payment(true); } $controller->initCart(true); $controller->cart_update = true; $coupon_ret = true; } } if (!$coupon_ret && !$consume_ret) { $msg = JText::sprintf('SERIAL_CHECKOUT_UNKNOWN_CODE', $coupon); if (!empty($msg)) { $app->enqueueMessage($msg, 'error'); } } return false; } return true; }
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 ''; }
echo 'class="hikaserial_menu_top"'; } ?> > <ul class="menu"> <?php } else { ?> <div class="navbar"> <div class="navbar-inner"> <div class="container"> <div class="nav"> <ul id="hikaserial_menu_j3" class="nav"> <?php } $config = hikaserial::config(); foreach ($this->menus as $menu) { $html = ''; if (!empty($menu['children'])) { $i = 1; $cpt = count($menu['children']); foreach ($menu['children'] as $child) { $task = 'view'; if (!empty($child['task'])) { $task = $child['task']; } if (empty($child['acl']) || hikaserial::isAllowed($config->get('acl_' . $child['acl'] . '_' . $task, 'all'))) { $liclasses = ''; $classes = ''; if (isset($child['active']) && $child['active']) { $classes .= ' sel';
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; }
private function sendCustomEmail($serials, &$order) { $send_serials = array(); $custom_field_value = ''; list($type, $custom_field) = explode('.', $this->plugin_params->custom_field, 2); if (!in_array($type, array('order', 'item'))) { return false; } if ($type == 'order') { foreach ($serials as $k => $serial) { if (is_string($this->plugin_params->packs) && strpos(',' . $this->plugin_params->packs . ',', ',' . $serial->serial_pack_id . ',') === false) { continue; } if (is_array($this->plugin_params->packs) && !in_array($serial->serial_pack_id, $this->plugin_params->packs)) { continue; } $send_serials[] = $serial; } if (!empty($order->{$custom_field})) { $custom_field_value = $order->{$custom_field}; } } if ($type == 'item') { $send_serials[] = $serials; foreach ($order->products as $k => $product) { if ((int) $product->order_product_id == (int) $serials->serial_order_product_id) { if (!empty($product->{$custom_field})) { $custom_field_value = $product->{$custom_field}; } break; } } } $custom_field_value = trim($custom_field_value); if (empty($custom_field_value)) { return false; } if (!preg_match('/^([a-z0-9_\'&\\.\\-\\+=])+\\@(([a-z0-9\\-])+\\.)+([a-z0-9]{2,10})+$/i', $custom_field_value)) { return false; } $data = new stdClass(); $data->serials = $send_serials; $data->dest_email = $custom_field_value; $data->order =& $order; $mailClass = hikaserial::get('class.mail'); $mail = $mailClass->load('mailtocustomfield', $data); if (empty($mail)) { return false; } if (!empty($this->plugin_params->call_attachserial)) { $attachserialPlugin = hikaserial::import('hikaserial', 'attachserial'); $attachserialPlugin->onBeforeSerialMailSend($mail, $mail->mailer, $send_serials, $order); } $mail->subject = JText::sprintf($mail->subject, HIKASERIAL_LIVE); $shopConfig =& hikaserial::config(false); if (empty($mail->from_email)) { $mail->from_email = $shopConfig->get('from_email'); $mail->from_name = $shopConfig->get('from_name'); } if (empty($mail->reply_email)) { $mail->reply_email = $shopConfig->get('from_email'); $mail->reply_name = $shopConfig->get('from_name'); } if (empty($mail->dst_email)) { $mail->dst_email = $custom_field_value; } if (empty($mail->dst_name)) { $mail->dst_name = $custom_field_value; } $mailClass->sendMail($mail); return true; }
public function generate(&$pack, &$order, $quantity, &$serials) { if (!isset($pack->coupongen)) { return; } parent::pluginParams($pack->coupongen); if (empty($this->plugin_params->format) || !preg_match_all('#\\\\[|\\\\]|\\[[^]]+\\]\\{.*\\}|\\[.*\\]|.#iU', $this->plugin_params->format, $matches)) { $matches = array(array('[a-zA-Z0-9]{size}')); } $config = hikaserial::config(); $fastRandom = (int) $config->get('use_fast_random', 0); for ($q = 0; $q < $quantity; $q++) { $serial = ''; $serialObj = new stdClass(); if (!HIKASHOP_J16 || $fastRandom) { $stat = @stat(__FILE__); if (empty($stat) || !is_array($stat)) { $stat = array(php_uname()); } mt_srand(crc32(microtime() . implode('|', $stat))); } else { if (empty($this->plugin_params->size) || $this->plugin_params->size == 0) { $this->plugin_params->size = 15; } $rndCpt = 1; $random = JCrypt::genRandomBytes($this->plugin_params->size + 1); $shift = ord($random[0]); } foreach ($matches[0] as $m) { if (strlen($m) == 1) { $serial .= $m; } else { $repeat = 1; $format = $m; if (strpos($m, '{') !== false) { list($format, $repeat) = explode('{', $m); $repeat = trim(trim($repeat, '}')); if (empty($repeat) || (int) $repeat == 0) { $repeat = $this->plugin_params->size; } else { $repeat = (int) $repeat; } } $format = substr($format, 1, -1); $list = ''; $l = strlen($format); for ($i = 0; $i < $l; $i++) { if ($i + 2 < $l) { if ($format[$i + 1] == '-') { $s = $format[$i]; $e = $format[$i + 2]; $s1 = $s >= 'a' && $s <= 'z'; $s2 = $s >= 'A' && $s <= 'Z'; $s3 = $s >= '0' && $s <= '9'; $e1 = $e >= 'a' && $e <= 'z'; $e2 = $e >= 'A' && $e <= 'Z'; $e3 = $e >= '0' && $e <= '9'; if (!$s1 && !$s2 && !$s3) { $list .= $s . '-'; $i++; // Skip '-' continue; } if ($s1 && $e1 || $s2 && $e2 || $s3 && $e3) { if ($s > $e) { $c = $s; $s = $e; $e = $c; } for ($c = $s; $c < $e; $c++) { $list .= $c; } $i += 2; } else { if ($s1 && $e2) { for ($c = $s; $c < 'z'; $c++) { $list .= $c; } for ($c = 'A'; $c < $e; $c++) { $list .= $c; } $i += 2; } else { $list .= $s . '-'; $i++; // Skip '-' } } } else { $list .= $format[$i]; } } else { $list .= $format[$i]; } } $base = strlen($list); if (!HIKASHOP_J16 || $fastRandom) { for ($i = 1; $i <= $repeat; $i++) { $serial .= $list[mt_rand(0, $base - 1)]; } } else { for ($i = 1; $i <= $repeat; $i++) { $serial .= $list[($shift + ord($random[$rndCpt])) % $base]; $shift += ord($random[$rndCpt++]); if ($rndCpt == $this->plugin_params->size) { $rndCpt = 1; $random = JCrypt::genRandomBytes($this->plugin_params->size + 1); $shift = ord($random[0]); } } } } } $discount_id = (int) $this->plugin_params->discount_id; $result = true; if (!$this->test && !empty($discount_id)) { $discountClass = hikaserial::get('shop.class.discount'); $data = $discountClass->get($discount_id); if ($data) { unset($data->discount_id); $data->discount_code = $serial; $data->discount_published = 1; $data->discount_used_times = 0; if (!empty($this->plugin_params->validity_period) && !empty($this->plugin_params->validity_value) && (int) $this->plugin_params->validity_value > 0) { $date_d = date("d"); $date_m = date("m"); $date_y = date("Y"); $v = (int) $this->plugin_params->validity_value; switch ($this->plugin_params->validity_period) { case 'year': $data->discount_end = mktime(0, 0, 0, $date_m, $date_d, $date_y + $v); break; case 'month': $data->discount_end = mktime(0, 0, 0, $date_m + $v, $date_d, $date_y); break; case 'day': $data->discount_end = mktime(0, 0, 0, $date_m, $date_d + $v, $date_y); break; } if (!isset($serialObj->extradata)) { $serialObj->extradata = array(); } $serialObj->extradata['discount_end'] = $data->discount_end; } if (!empty($this->plugin_params->discount_percent)) { $v = hikaserial::toFloat(trim($this->plugin_params->discount_percent)); $product_price = 0; if (!empty($order->cart->products)) { foreach ($order->cart->products as $p) { if ($p->product_id == $pack->product_id || isset($pack->order_product_id) && $p->order_product_id == $pack->order_product_id) { $product_price = hikaserial::toFloat($p->order_product_price); if (!empty($this->plugin_params->discount_percent_tax)) { $product_price += hikaserial::toFloat($p->order_product_tax); } break; } } } if (!empty($product_price)) { if (!empty($order->order_currency_id)) { $data->discount_currency_id = (int) $order->order_currency_id; } else { $data->discount_currency_id = (int) $order->old->order_currency_id; } $data->discount_flat_amount = $product_price * $v / 100; $data->discount_percent_amount = 0.0; } } if (!$discountClass->save($data)) { $result = false; } } } if (!$result) { $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('ERR_CREATING_DISCOUNT_COUPON')); } if (!empty($serialObj) && !empty($serialObj->extradata)) { $serialObj->data = $serial; $serials[] = $serialObj; } else { $serials[] = $serial; } } }