예제 #1
0
파일: pack.php 프로젝트: q0821/esportshop
 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();
 }
예제 #2
0
 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;
 }
예제 #3
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 '';
 }
예제 #4
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);
             }
         }
     }
 }
예제 #5
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'));
 }
예제 #6
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;
 }
예제 #7
0
파일: order.php 프로젝트: q0821/esportshop
 protected function assignPack($pack, $order, $order_product_id)
 {
     $config = hikaserial::config();
     if ($config->get('save_history', 1)) {
         $historyClass = hikaserial::get('class.history');
     }
     if (empty($pack->pack_params->consumer) || !$pack->pack_params->consumer) {
         $pack_serial_status = $config->get('used_serial_status', 'used');
     } else {
         $pack_serial_status = $config->get('assigned_serial_status', 'assigned');
     }
     $ids = null;
     if ($pack->pack_data == 'sql') {
         $query = 'SELECT serial_id FROM ' . hikaserial::table('serial') . ' WHERE serial_pack_id = ' . $pack->pack_id . ' AND ' . '(serial_status = \'\' OR serial_status IN (\'' . implode('\',\'', $this->useable_serial_statuses) . '\')) AND ' . '(serial_user_id = ' . (int) @$order->cart->order_user_id . ' OR serial_user_id = 0 OR serial_user_id IS NULL) AND ' . '(serial_order_id = ' . (int) $order->order_id . ' OR serial_order_id = 0 OR serial_order_id IS NULL) ' . 'ORDER BY serial_user_id DESC, serial_id ASC';
         $this->db->setQuery($query, 0, (int) $pack->quantity);
         if (!HIKASHOP_J25) {
             $ids = $this->db->loadResultArray();
         } else {
             $ids = $this->db->loadColumn();
         }
     }
     if (!empty($ids)) {
         $query = 'UPDATE ' . hikaserial::table('serial') . ' SET serial_order_id = ' . (int) $order->order_id . ', serial_assign_date = ' . (int) time() . ', serial_status = ' . $this->db->quote($pack_serial_status) . ', serial_user_id = ' . (int) @$order->cart->order_user_id . ', serial_order_product_id = ' . (int) $order_product_id . ' WHERE serial_id IN (' . implode(',', $ids) . ') AND (serial_status = \'\' OR serial_status IN (\'' . implode('\',\'', $this->useable_serial_statuses) . '\'))';
         $this->db->setQuery($query);
         $this->db->query();
         if ($config->get('save_history', 1)) {
             $histories = array();
             foreach ($ids as $id) {
                 $histories[] = $historyClass->create($id, $pack_serial_status, 'assignation');
             }
             if (!empty($histories)) {
                 $historyClass->save($histories);
             }
         }
     }
     if (empty($ids) || count($ids) < $pack->quantity) {
         $quantity = $pack->quantity;
         if (!empty($ids)) {
             $quantity -= count($ids);
         }
         $generateTime = time();
         $data = array('serial_pack_id' => (int) $pack->pack_id, 'serial_data' => '', 'serial_extradata' => $this->db->Quote(''), 'serial_status' => $this->db->quote($pack_serial_status), 'serial_assign_date' => (int) $generateTime, 'serial_order_id' => (int) $order->order_id, 'serial_user_id' => (int) @$order->cart->order_user_id, 'serial_order_product_id' => (int) $order_product_id);
         if (!empty($pack->pack_params->no_user_assign)) {
             $data['serial_user_id'] = 0;
         }
         $query = 'INSERT IGNORE INTO ' . hikaserial::table('serial') . ' (' . implode(',', array_keys($data)) . ') VALUES ';
         if (substr($pack->pack_generator, 0, 4) == 'plg.') {
             $pluginId = 0;
             $pluginName = substr($pack->pack_generator, 4);
             if (strpos($pluginName, '-') !== false) {
                 list($pluginName, $pluginId) = explode('-', $pluginName, 2);
                 $pack->{$pluginName} = $pluginId;
             }
             $serials = array();
             $plugin = hikaserial::import('hikaserial', $pluginName);
             if (method_exists($plugin, 'generate')) {
                 $pack->order_product_id = (int) $order_product_id;
                 ob_start();
                 $ret = $plugin->generate($pack, $order, $quantity, $serials);
                 ob_get_clean();
             }
             $queryData = array();
             foreach ($serials as $serial) {
                 $data['serial_extradata'] = $this->db->Quote('');
                 if (is_array($serial)) {
                     $data['serial_data'] = $this->db->Quote($serial['data']);
                     if (!empty($serial['extradata'])) {
                         $data['serial_extradata'] = $this->db->Quote(serialize($serial['extradata']));
                     }
                 } else {
                     if (is_object($serial)) {
                         $data['serial_data'] = $this->db->Quote($serial->data);
                         if (!empty($serial->extradata)) {
                             $data['serial_extradata'] = $this->db->Quote(serialize($serial->extradata));
                         }
                     } else {
                         $data['serial_data'] = $this->db->Quote($serial);
                     }
                 }
                 $queryData[] = '(' . implode(',', $data) . ')';
             }
             if (!empty($queryData)) {
                 $query .= implode(',', $queryData);
                 $this->db->setQuery($query);
                 $this->db->query();
                 if ($config->get('save_history', 1)) {
                     $query = 'SELECT a.* FROM ' . hikaserial::table('serial') . ' AS a WHERE a.serial_assign_date = ' . (int) $generateTime . ' AND serial_order_id = ' . (int) $order->order_id;
                     $this->db->setQuery($query);
                     $generateSerials = $this->db->loadObjectList();
                     $histories = array();
                     foreach ($generateSerials as $serial) {
                         $histories[] = $historyClass->generate(null, $serial, true);
                     }
                     if (!empty($histories)) {
                         $historyClass->save($histories);
                     }
                 }
             }
             if (empty($serials) || count($serials) < $quantity) {
                 if (isset($ret) && $ret === false || (int) $ret == count($serials)) {
                 }
             }
         }
     }
 }