Beispiel #1
0
 public function saveForm()
 {
     $serial = new stdClass();
     $serial->serial_id = hikaserial::getCID('serial_id');
     $formData = JRequest::getVar('data', array(), '', 'array');
     foreach ($formData['serial'] as $col => $val) {
         hikaserial::secureField($col);
         if (is_array($val) || is_object($val)) {
             continue;
         }
         $serial->{$col} = strip_tags($val);
     }
     if (!empty($formData['serial']['serial_extradata'])) {
         $serial->serial_extradata = $formData['serial']['serial_extradata'];
     } else {
         $isExtraData = JRequest::getInt('hikaserial_extradata', 0);
         if ($isExtraData) {
             $serial->serial_extradata = '';
         }
     }
     JPluginHelper::importPlugin('hikashop');
     JPluginHelper::importPlugin('hikaserial');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onBeforeSerialSave', array(&$serial));
     $status = $this->save($serial);
     if ($status) {
         $productClass = hikaserial::get('class.product');
         $productClass->refreshQuantities();
     }
     return $status;
 }
Beispiel #2
0
 public function refresh()
 {
     $app = JFactory::getApplication();
     $orderClass = hikaserial::get('class.order');
     $orderId = hikaserial::getCID('order_id');
     if (empty($orderId)) {
         $app->redirect(hikaserial::completeLink('dashboard'));
     }
     $orderClass->refresh($orderId);
     $app->redirect(hikaserial::completeLink('shop.order&task=edit&cid[]=' . $orderId, false, true));
 }
Beispiel #3
0
 public function unassign()
 {
     $serialClass = hikaserial::get('class.serial');
     $type = JRequest::getVar('type', '');
     $serial_id = hikaserial::getCID('serial_id');
     $success = $serialClass->unassign($serial_id, $type);
     if ($success) {
         echo '1';
     } else {
         echo '0';
     }
     exit;
 }
Beispiel #4
0
 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();
 }
Beispiel #5
0
 public function saveForm()
 {
     $pack = new stdClass();
     $pack->pack_id = hikaserial::getCID('pack_id');
     $formData = JRequest::getVar('data', array(), '', 'array');
     foreach ($formData['pack'] as $col => $val) {
         hikaserial::secureField($col);
         $pack->{$col} = strip_tags($val);
     }
     $pack->pack_params = null;
     if (!empty($formData['pack_params'])) {
         $pack->pack_params = new stdClass();
         foreach ($formData['pack_params'] as $k => $v) {
             hikaserial::secureField($k);
             $pack->pack_params->{$k} = $v;
         }
     }
     $pack->pack_description = JRequest::getVar('pack_description', '', '', 'string', JREQUEST_ALLOWRAW);
     $status = $this->save($pack);
     if ($status) {
     }
     return $status;
 }
Beispiel #6
0
 public function download()
 {
     $app = JFactory::getApplication();
     JRequest::setVar('layout', 'consume');
     $order_id = hikaserial::getCID('order_id');
     $file_id = JRequest::getInt('file_id');
     $file_pos = JRequest::getInt('file_pos', 1);
     $serial = JRequest::getString('serial', '');
     if (empty($order_id)) {
         return parent::display();
     }
     $downloadClass = hikaserial::get('class.download');
     $ret = $downloadClass->downloadHikaShopFile($file_id, $order_id, $file_pos, $serial);
     if ($ret !== true) {
         switch ($ret) {
             case 'login':
                 break;
             case 'no_order':
                 break;
             default:
                 break;
         }
     }
     return parent::display();
 }
Beispiel #7
0
 public function store()
 {
     $this->plugin = JRequest::getCmd('name', '');
     $this->plugin_type = JRequest::getCmd('plugin_type', 'generator');
     if (empty($this->plugin) || !in_array($this->plugin_type, array('generator', 'consumer', 'plugin'))) {
         return false;
     }
     $data = hikaserial::import('hikaserial', $this->plugin);
     $element = new stdClass();
     $id = hikaserial::getCID($this->plugin_type . '_id');
     $formData = JRequest::getVar('data', array(), '', 'array');
     $params_name = $this->plugin_type . '_params';
     if (!empty($formData[$this->plugin_type])) {
         $element = new stdClass();
         $plugin_id = $this->plugin_type . '_id';
         $element->{$plugin_id} = $id;
         foreach ($formData[$this->plugin_type] as $column => $value) {
             hikaserial::secureField($column);
             if (is_array($value)) {
                 if ($column == $params_name) {
                     $element->{$params_name} = new stdClass();
                     foreach ($formData[$this->plugin_type][$column] as $key => $val) {
                         hikaserial::secureField($key);
                         if (!is_array($val)) {
                             $element->{$params_name}->{$key} = strip_tags($val);
                         } else {
                             $element->{$params_name}->{$key} = $val;
                         }
                     }
                 }
             } else {
                 $element->{$column} = strip_tags($value);
             }
         }
         $plugin_description = $this->plugin_type . '_description';
         $plugin_description_data = JRequest::getVar($plugin_description, '', '', 'string', JREQUEST_ALLOWRAW);
         $element->{$plugin_description} = $plugin_description_data;
     }
     $function = 'on' . ucfirst($this->plugin_type) . 'ConfigurationSave';
     if (method_exists($data, $function)) {
         $data->{$function}($element);
     }
     if (!empty($element)) {
         $pluginClass = hikaserial::get('class.' . $this->plugin_type);
         if (isset($element->{$params_name})) {
             $element->{$params_name} = serialize($element->{$params_name});
         }
         $status = $pluginClass->save($element);
         if (!$status) {
             JRequest::setVar('fail', $element);
         } else {
             $app = JFactory::getApplication();
             $app->enqueueMessage(JText::_('HIKASHOP_SUCC_SAVED'), 'message');
             if (empty($id)) {
                 JRequest::setVar($this->plugin_type . '_id', $status);
             }
         }
     }
 }
Beispiel #8
0
 public function generate($tpl = null)
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     JHTML::_('behavior.modal');
     $ctrl = '';
     $pack_id = hikaserial::getCID();
     if (empty($pack_id)) {
         $app->redirect(hikaserial::completeLink('pack&task=list'));
     }
     $packClass = hikaserial::get('class.pack');
     $pack = $packClass->get($pack_id);
     $task = 'generate';
     $cid = '&cid[]=' . $pack_id;
     $ctrl .= '&task=' . $task . $cid;
     $this->assignRef('task', $task);
     $this->assignRef('pack', $pack);
     $generator = null;
     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 (!empty($generator) && (!method_exists($generator, 'canPopulate') || $generator->canPopulate() != true)) {
         $app->enqueueMessage(JText::_('PLUGIN_GENERATOR_CAN_NOT_POPULATE'));
         $app->redirect(hikaserial::completeLink('pack&task=edit&cid[]=' . $pack_id, false, true));
     }
     $populateFormData = '';
     if (!empty($generator) && method_exists($generator, 'populateForm')) {
         $populateFormData = $generator->populateForm($pack);
     }
     $this->assignRef('populateFormData', $populateFormData);
     $packGeneratorType = hikaserial::get('type.pack_generator');
     $this->assignRef('packGeneratorType', $packGeneratorType);
     $serialStatusType = hikaserial::get('type.serial_status');
     $this->assignRef('serialStatusType', $serialStatusType);
     hikaserial::setTitle(JText::_(self::name), self::icon, self::ctrl . $ctrl);
     $this->toolbar = array(array('name' => 'custom', 'icon' => 'upload', 'task' => 'generate', 'alt' => JText::_('GENERATE'), 'check' => false), array('name' => 'hikacancel', 'url' => hikaserial::completeLink('pack&task=edit&cid[]=' . $pack_id)), '|', array('name' => 'pophelp', 'target' => self::ctrl . '-form'));
 }
Beispiel #9
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);
         }
     }
 }
Beispiel #10
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;
 }
Beispiel #11
0
 public function form()
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     JHTML::_('behavior.modal');
     $ctrl = '';
     $cid = '';
     $cancelUrl = urlencode(base64_encode(hikaserial::completeLink('serial')));
     $this->assignRef('cancelUrl', $cancelUrl);
     $config = hikaserial::config();
     $this->assignRef('config', $config);
     $shopConfig = hikaserial::config(false);
     $this->assignRef('shopConfig', $shopConfig);
     $popup = hikaserial::get('shop.helper.popup');
     $this->assignRef('popup', $popup);
     $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);
     $serial = null;
     $serial_id = hikaserial::getCID();
     if (!empty($serial_id)) {
         $serialClass = hikaserial::get('class.serial');
         $serial = $serialClass->get($serial_id, true);
         $task = 'edit';
         $cid = '&cid[]=' . $serial_id;
         $cancelUrl = urlencode(base64_encode(hikaserial::completeLink('serial&task=edit&cid[]=' . $serial_id)));
     } else {
         $task = 'add';
     }
     $ctrl .= '&task=' . $task . $cid;
     $this->assignRef('task', $task);
     $this->assignRef('serial', $serial);
     JPluginHelper::importPlugin('hikaserial');
     $dispatcher = JDispatcher::getInstance();
     $serials = array(&$serial);
     $dispatcher->trigger('onDisplaySerials', array(&$serials, 'back-serial-form'));
     $packType = hikaserial::get('type.pack');
     $this->assignRef('packType', $packType);
     $serialStatusType = hikaserial::get('type.serial_status');
     $this->assignRef('serialStatusType', $serialStatusType);
     hikaserial::setTitle(JText::_(self::name), self::icon, self::ctrl . $ctrl);
     $this->toolbar = array('|', 'save', 'apply', 'hikacancel', '|', array('name' => 'pophelp', 'target' => self::ctrl . '-form'));
 }