function display($tpl = null) { $document = JFactory::getDocument(); $document->setMimeEncoding('application/json'); if ($virtuemart_media_id = vRequest::getInt('virtuemart_media_id')) { //JResponse::setHeader( 'Content-Disposition', 'attachment; filename="media'.$virtuemart_media_id.'.json"' ); $model = VmModel::getModel('Media'); $image = $model->createMediaByIds($virtuemart_media_id); if (isset($image[0]) and is_object($image[0])) { $image[0]->file_url_thumb_dyn = $image[0]->getFileUrlThumb(); // echo '<pre>'.print_r($image,1).'</pre>'; $this->json = $image[0]; //echo json_encode($this->json); if (isset($this->json->file_url)) { $this->json->file_root = JURI::root(true) . '/'; $this->json->msg = 'OK'; echo vmJsApi::safe_json_encode($this->json); } else { $this->json->msg = '<b>' . vmText::_('COM_VIRTUEMART_NO_IMAGE_SET') . '</b>'; echo @json_encode($this->json); } } } else { if (!class_exists('VmMediaHandler')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'mediahandler.php'; } $start = vRequest::getInt('start', 0); $type = vRequest::getCmd('mediatype', 0); $list = VmMediaHandler::displayImages($type, $start); echo vmJsApi::safe_json_encode($list); } jExit(); }
function display($tpl = null) { $db = JFactory::getDBO(); if ($virtuemart_media_id = vRequest::getInt('virtuemart_media_id')) { //$db = JFactory::getDBO(); $query = 'SELECT `file_url`,`file_title` FROM `#__virtuemart_medias` where `virtuemart_media_id`=' . $virtuemart_media_id; $db->setQuery($query); $json = $db->loadObject(); if (isset($json->file_url)) { $json->file_url = JURI::root() . $json->file_url; $json->msg = 'OK'; echo vmJsApi::safe_json_encode($json); } else { $json->msg = '<b>' . vmText::_('COM_VIRTUEMART_NO_IMAGE_SET') . '</b>'; echo json_encode($json); } } elseif ($custom_jplugin_id = vRequest::getInt('custom_jplugin_id')) { $table = '#__extensions'; $ext_id = 'extension_id'; $q = 'SELECT `params`,`element` FROM `' . $table . '` WHERE `' . $ext_id . '` = "' . $custom_jplugin_id . '"'; $db->setQuery($q); $this->jCustom = $db->loadObject(); $customModel = VmModel::getModel('custom'); $this->custom = $customModel->getCustom(); // Get the payment XML. $formFile = vRequest::filterPath(VMPATH_ROOT . DS . 'plugins' . DS . 'vmcustom' . DS . $this->jCustom->element . DS . $this->jCustom->element . '.xml'); if (file_exists($formFile)) { VmConfig::loadJLang('plg_vmpsplugin', false); if (!class_exists('vmPlugin')) { require VMPATH_PLUGINLIBS . DS . 'vmplugin.php'; } $filename = 'plg_vmcustom_' . $this->jCustom->element; vmPlugin::loadJLang($filename, 'vmcustom', $this->jCustom->element); $this->custom = VmModel::getModel('custom')->getCustom(); $varsToPush = vmPlugin::getVarsToPushByXML($formFile, 'customForm'); $this->custom->form = JForm::getInstance($this->jCustom->element, $formFile, array(), false, '//vmconfig | //config[not(//vmconfig)]'); $this->custom->params = new stdClass(); foreach ($varsToPush as $k => $field) { if (strpos($k, '_') != 0) { $this->custom->params->{$k} = $field[0]; } } $this->custom->form->bind($this->custom->getProperties()); $form = $this->custom->form; include VMPATH_ADMIN . DS . 'fields' . DS . 'formrenderer.php'; echo '<input type="hidden" value="' . $this->jCustom->element . '" name="custom_value">'; } else { $this->custom->form = null; //VmConfig::$echoDebug = 1; vmdebug('File does not exist ' . $formFile); } } jExit(); }
function display($tpl = null) { $states = array(); $db = JFactory::getDBO(); //retrieving countries id $country_ids = vRequest::getString('tsmart_country_id'); $country_ids = explode(',', $country_ids); foreach ($country_ids as $country_id) { $q = 'SELECT `tsmart_state_id`, `state_name` FROM `#__tsmart_states` WHERE `tsmart_country_id`= "' . (int) $country_id . '" ORDER BY `#__tsmart_states`.`state_name`'; $db->setQuery($q); $states[$country_id] = $db->loadAssocList(); } echo vmJsApi::safe_json_encode($states); }
/** * Method to render the plugin datas * this is an entry point to plugin to easy renders json or html * * * @access public */ function Plugin() { $user = JFactory::getUser(); if (!($user->authorise('core.admin', 'com_virtuemart') or $user->authorise('core.manage', 'com_virtuemart'))) { return false; } $type = vRequest::getCmd('type', 'vmcustom'); $typeWhiteList = array('vmshopper', 'vmcustom', 'vmcalculation', 'vmpayment', 'vmshipment', 'vmuserfield'); if (!in_array($type, $typeWhiteList)) { return false; } $name = vRequest::getString('name', ''); JPluginHelper::importPlugin($type, $name); $dispatcher = JDispatcher::getInstance(); // if you want only one render simple in the plugin use jExit(); // or $render is an array of code to echo as html or json Object! $render = null; $dispatcher->trigger('plgVmOnSelfCallBE', array($type, $name, &$render)); if ($render) { // Get the document object. $document = JFactory::getDocument(); if (vRequest::getCmd('cache', 'no')) { JResponse::setHeader('Cache-Control', 'no-cache, must-revalidate'); JResponse::setHeader('Expires', 'Mon, 6 Jul 2000 10:00:00 GMT'); } $format = vRequest::getCmd('format', 'json'); if ($format == 'json') { $document->setMimeEncoding('application/json'); // Change the suggested filename. JResponse::setHeader('Content-Disposition', 'attachment;filename="' . $type . '".json"'); echo vmJsApi::safe_json_encode($render); } else { echo $render; } } return true; }
public function updateCustomsOrderItems() { $q = 'SELECT `product_attribute` FROM `#__virtuemart_order_items` LIMIT '; $do = true; $db = JFactory::getDbo(); $start = 0; $hunk = 1000; while ($do) { $db->setQuery($q . $start . ',' . $hunk); $items = $db->loadColumn(); if (!$items) { vmdebug('updateCustomsOrderItems Reached end after ' . $start / $hunk . ' loops'); break; } //The stored result in vm2.0.14 looks like this {"48":{"textinput":{"comment":"test"}}} //{"96":"18"} download plugin // 46 is virtuemart_customfield_id //{"46":" <span class=\"costumTitle\">Cap Size<\/span><span class=\"costumValue\" >S<\/span>","110":{"istraxx_customsize":{"invala":"10","invalb":"10"}}} //and now {"32":[{"invala":"100"}]} foreach ($items as $field) { if (strpos($field, '{') !== FALSE) { $jsField = json_decode($field); $fieldProps = get_object_vars($jsField); vmdebug('updateCustomsOrderItems', $fieldProps); $nJsField = array(); foreach ($fieldProps as $k => $props) { if (is_object($props)) { $props = (array) $props; foreach ($props as $ke => $prop) { if (!is_numeric($ke)) { vmdebug('Found old param style', $ke, $prop); if (is_object($prop)) { $prop = (array) $prop; $nJsField[$k] = $prop; /*foreach($prop as $name => $propvalue){ $nJsField[$k][$name] = $propvalue; }*/ } } else { //$nJsField[$k][$name] = $prop; } } } else { if (is_numeric($k) and is_numeric($props)) { $nJsField[$props] = $k; } else { $nJsField[$k] = $props; } } } $nJsField = vmJsApi::safe_json_encode($nJsField); vmdebug('updateCustomsOrderItems json $field encoded', $field, $nJsField); } else { vmdebug('updateCustomsOrderItems $field', $field); } } if (count($items) < $hunk) { vmdebug('Reached end'); break; } $start += $hunk; } // Create the view object $view = $this->getView('orders', 'html'); $view->display(); }
public function fixCustomsParams() { $this->checkPermissionForTools(); $q = 'SELECT `virtuemart_customfield_id` FROM `#__virtuemart_product_customfields` LEFT JOIN `#__virtuemart_customs` USING (`virtuemart_custom_id`) '; $q = 'SELECT `virtuemart_customfield_id`,`customfield_params` FROM `#__virtuemart_product_customfields` '; $q .= ' WHERE `customfield_params`!="" '; $db = JFactory::getDbo(); $db->setQuery($q); $rows = $db->loadAssocList(); foreach ($rows as $fields) { $store = ''; $json = @json_decode($fields['customfield_params']); if ($json) { $vars = get_object_vars($json); foreach ($vars as $key => $value) { $store .= $key . '=' . vmJsApi::safe_json_encode($value) . '|'; } if (!empty($store)) { $q = 'UPDATE `#__virtuemart_product_customfields` SET `customfield_params` = "' . $db->escape($store) . '" WHERE `virtuemart_customfield_id` = "' . $fields['virtuemart_customfield_id'] . '" '; $db->setQuery($q); $db->execute(); } } } $msg = 'Executed'; $this->setredirect($this->redirectPath, $msg); }
jQuery("input[name=\'"+fname+"[update_lines]\']").prop("checked",update_lines); jQuery("textarea[name=\'"+fname+"[comments]\']").text(comments); console.log("Mist ",jQuery("input[name=\'"+fname+"[comments]\']")); jQuery("#order_status"+i).val(newStatus).trigger("chosen:updated").trigger("liszt:updated"); } } }'; vmJsApi::addJScript('set2status', $j); $j = "jQuery('.show_comment').click(function() {\n\t\tjQuery(this).prev('.element-hidden').show();\n\t\treturn false\n\t\t});\n\t\tjQuery('.element-hidden').mouseleave(function() {\n\t\tjQuery(this).hide();\n\t\t});\n\t\tjQuery('.element-hidden').mouseout(function() {\n\t\tjQuery(this).hide();\n\t});"; vmJsApi::addJScript('show_comment', $j); $orderstatusForShopperEmail = VmConfig::get('email_os_s', array('U', 'C', 'S', 'R', 'X')); if (!is_array($orderstatusForShopperEmail)) { $orderstatusForShopperEmail = array($orderstatusForShopperEmail); } $jsOrderStatusShopperEmail = vmJsApi::safe_json_encode($orderstatusForShopperEmail); $j = ' jQuery(document).ready(function() { jQuery(".orderstatus_select").change( function() { var name = jQuery(this).attr("name"); var brindex = name.indexOf("orders["); if ( brindex >= 0){ //yeh, yeh, maybe not the most elegant way, but it does, what it should var s = name.indexOf("[")+1; var e = name.indexOf("]"); var id = name.substring(s,e); var orderstatus = ' . $jsOrderStatusShopperEmail . '; var selected = jQuery(this).val(); var selStr = "[name=\\"orders["+id+"][customer_notified]\\"]";
/** * Create the ordered item records * * @author Oscar van Eijk * @author Kohl Patrick * @param integer $_id integer Order ID * @param object $_cart array The cart data * @return boolean True on success */ private function _createOrderLines($virtuemart_order_id, $cart) { $_orderItems = $this->getTable('order_items'); foreach ($cart->products as $priceKey => $product) { $_orderItems->product_attribute = vmJsApi::safe_json_encode($product->customProductData); $_orderItems->virtuemart_order_item_id = null; $_orderItems->virtuemart_order_id = $virtuemart_order_id; $_orderItems->virtuemart_vendor_id = $product->virtuemart_vendor_id; $_orderItems->virtuemart_product_id = $product->virtuemart_product_id; $_orderItems->order_item_sku = $product->product_sku; $_orderItems->order_item_name = $product->product_name; $_orderItems->product_quantity = $product->quantity; $_orderItems->product_item_price = $product->allPrices[$product->selectedPrice]['basePriceVariant']; $_orderItems->product_basePriceWithTax = $product->allPrices[$product->selectedPrice]['basePriceWithTax']; //$_orderItems->product_tax = $_cart->pricesUnformatted[$priceKey]['subtotal_tax_amount']; $_orderItems->product_tax = $product->allPrices[$product->selectedPrice]['taxAmount']; $_orderItems->product_final_price = $product->allPrices[$product->selectedPrice]['salesPrice']; $_orderItems->product_subtotal_discount = $product->allPrices[$product->selectedPrice]['subtotal_discount']; $_orderItems->product_subtotal_with_tax = $product->allPrices[$product->selectedPrice]['subtotal_with_tax']; $_orderItems->product_priceWithoutTax = $product->allPrices[$product->selectedPrice]['priceWithoutTax']; $_orderItems->product_discountedPriceWithoutTax = $product->allPrices[$product->selectedPrice]['discountedPriceWithoutTax']; $_orderItems->order_status = 'P'; if (!$_orderItems->check()) { return false; } // Save the record to the database if (!$_orderItems->store()) { return false; } $product->virtuemart_order_item_id = $_orderItems->virtuemart_order_item_id; $this->handleStockAfterStatusChangedPerProduct($_orderItems->order_status, 'N', $_orderItems, $_orderItems->product_quantity); } return true; }
function display($tpl = null) { $filter = vRequest::getVar('q', vRequest::getVar('term', false)); $id = vRequest::getInt('id', false); $tsmart_product_id = vRequest::getInt('tsmart_product_id', array()); if (is_array($tsmart_product_id) && count($tsmart_product_id) > 0) { $product_id = (int) $tsmart_product_id[0]; } else { $product_id = (int) $tsmart_product_id; } //$customfield = $this->model->getcustomfield(); /* Get the task */ if ($this->type == 'relatedproducts') { $query = "SELECT tsmart_product_id AS id, CONCAT(product_name, '::', product_sku) AS value\n\t\t\t\tFROM #__tsmart_products_" . tsmConfig::$vmlang . "\n\t\t\t\t JOIN `#__tsmart_products` AS p using (`tsmart_product_id`)"; if ($filter) { $query .= " WHERE product_name LIKE '%" . $this->db->escape($filter, true) . "%' or product_sku LIKE '%" . $this->db->escape($filter, true) . "%' limit 0,10"; } self::setRelatedHtml($product_id, $query, 'R'); } else { if ($this->type == 'relatedcategories') { $query = "SELECT tsmart_category_id AS id, CONCAT(category_name, '::', tsmart_category_id) AS value\n\t\t\t\tFROM #__tsmart_categories_" . tsmConfig::$vmlang; if ($filter) { $query .= " WHERE category_name LIKE '%" . $this->db->escape($filter, true) . "%' limit 0,10"; } self::setRelatedHtml($product_id, $query, 'Z'); } else { if ($this->type == 'custom') { $query = "SELECT CONCAT(tsmart_custom_id, '|', custom_value, '|', field_type) AS id, CONCAT(custom_title, '::', custom_tip) AS value\n\t\t\t\tFROM #__tsmart_customs"; if ($filter) { $query .= " WHERE custom_title LIKE '%" . $filter . "%' limit 0,50"; } $this->db->setQuery($query); $this->json['value'] = $this->db->loadObjectList(); $this->json['ok'] = 1; } else { if ($this->type == 'fields') { if (!class_exists('tsmartModelCustom')) { require VMPATH_ADMIN . DS . 'models' . DS . 'custom.php'; } $fieldTypes = tsmartModelCustom::getCustomTypes(); $model = tmsModel::getModel('custom'); $q = 'SELECT `tsmart_custom_id` FROM `#__tsmart_customs` WHERE (`custom_parent_id`=' . $id . ') '; $q .= 'order by `ordering` asc'; $this->db->setQuery($q); $ids = $this->db->loadColumn(); if ($ids) { array_unshift($ids, $id); } else { $ids = array($id); } foreach ($ids as $k => $i) { $p = $model->getCustom($i); if ($p) { $p->value = $p->custom_value; $rows[] = $p; } } $html = array(); foreach ($rows as $field) { if ($field->field_type == 'deprecatedwasC') { $this->json['table'] = 'childs'; $q = 'SELECT `tsmart_product_id` FROM `#__tsmart_products` WHERE `published`=1 AND `product_parent_id`= ' . vRequest::getInt('tsmart_product_id'); //$this->db->setQuery(' SELECT tsmart_product_id, product_name FROM `#__tsmart_products` WHERE `product_parent_id` ='.(int)$product_id); $this->db->setQuery($q); if ($childIds = $this->db->loadColumn()) { // Get childs foreach ($childIds as $childId) { $field->custom_value = $childId; $display = $this->model->displayProductCustomfieldBE($field, $childId, $this->row); if ($field->is_cart_attribute) { $cartIcone = 'default'; } else { $cartIcone = 'default-off'; } $html[] = '<div class="removable"> <td>' . $field->custom_title . '</td> <td>' . $display . $field->custom_tip . '</td> <td>' . tsmText::_($fieldTypes[$field->field_type]) . ' ' . $this->model->setEditCustomHidden($field, $this->row) . ' </td> <td><span class="vmicon vmicon-16-' . $cartIcone . '"></span></td> <td></td> </div>'; $this->row++; } } } else { //if ($field->field_type =='E') { $this->json['table'] = 'customPlugins'; $colspan = ''; if ($field->field_type == 'E') { $this->model->bindCustomEmbeddedFieldParams($field, 'E'); } else { if ($field->field_type == 'C') { $colspan = 'colspan="2" '; } } $display = $this->model->displayProductCustomfieldBE($field, $product_id, $this->row); if ($field->is_cart_attribute) { $cartIcone = 'default'; } else { $cartIcone = 'default-off'; } $field->tsmart_product_id = $product_id; $html[] = ' <tr class="removable"> <td> <b>' . tsmText::_($fieldTypes[$field->field_type]) . '</b> ' . tsmText::_($field->custom_title) . '</span><br/> <span class="vmicon vmicon-16-' . $cartIcone . '"></span> <span class="vmicon vmicon-16-move"></span> <span class="vmicon vmicon-16-remove"></span> ' . $this->model->setEditCustomHidden($field, $this->row) . ' </td> <td ' . $colspan . '>' . $display . '</td> </tr> </tr>'; $this->row++; } } $this->json['value'] = $html; $this->json['ok'] = 1; } else { if ($this->type == 'userlist') { $status = vRequest::getvar('status'); $productShoppers = 0; if ($status) { $productModel = tmsModel::getModel('product'); $productShoppers = $productModel->getProductShoppersByStatus($product_id, $status); } if (!class_exists('ShopFunctions')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'shopfunctions.php'; } $html = ShopFunctions::renderProductShopperList($productShoppers); $this->json['value'] = $html; } else { $this->json['ok'] = 0; } } } } } if (empty($this->json)) { $this->json['value'] = null; $this->json['ok'] = 1; } echo vmJsApi::safe_json_encode($this->json); }
function storeParams() { if (!empty($this->_xParams) and !empty($this->_varsToPushParam)) { $paramFieldName = $this->_xParams; $this->{$paramFieldName} = ''; $this->_tmpParams = array(); foreach ($this->_varsToPushParam as $key => $v) { if (isset($this->{$key})) { $this->{$paramFieldName} .= $key . '=' . vmJsApi::safe_json_encode($this->{$key}) . '|'; $this->_tmpParams[$key] = $this->{$key}; } else { $this->{$paramFieldName} .= $key . '=' . vmJsApi::safe_json_encode($v[0]) . '|'; $this->_tmpParams[$key] = $v[0]; } unset($this->{$key}); } } return true; }
public function ajax_waitinglist() { $tsmart_product_id = vRequest::getInt('tsmart_product_id'); if (is_array($tsmart_product_id) && count($tsmart_product_id) > 0) { $tsmart_product_id = (int) $tsmart_product_id[0]; } else { $tsmart_product_id = (int) $tsmart_product_id; } $waitinglistmodel = tmsModel::getModel('waitinglist'); $waitinglist = $waitinglistmodel->getWaitingusers($tsmart_product_id); if (empty($waitinglist)) { $waitinglist = array(); } echo vmJsApi::safe_json_encode($waitinglist); exit; }
/** * Paste the table in json format * */ public function paste() { // TODO Test user ? $json = array(); $json['fields'] = 'error'; $json['msg'] = 'Invalid Token'; $json['structure'] = 'empty'; if (!vRequest::vmCheckToken(-1)) { echo json_encode($json); jexit(); } $lang = vRequest::getvar('lg'); $langs = tsmConfig::get('active_languages', array()); $language = JFactory::getLanguage(); if (!in_array($lang, $langs)) { $json['msg'] = 'Invalid language ! ' . $lang; $json['langs'] = $langs; echo json_encode($json); jexit(); } $lang = strtolower($lang); // Remove tag if defaut or // if ($language->getDefault() == $lang ) $dblang =''; $dblang = strtr($lang, '-', '_'); tsmConfig::$vmlang = $dblang; $id = vRequest::getInt('id', 0); $viewKey = vRequest::getCmd('editView'); // TODO temp trick for vendor if ($viewKey == 'vendor') { $id = 1; } $tables = array('category' => 'categories', 'product' => 'products', 'manufacturer' => 'manufacturers', 'manufacturercategories' => 'manufacturercategories', 'vendor' => 'vendors', 'paymentmethod' => 'paymentmethods', 'shipmentmethod' => 'shipmentmethods'); if (!array_key_exists($viewKey, $tables)) { $json['msg'] = "Invalid view " . $viewKey; echo json_encode($json); jExit(); } $tableName = '#__tsmart_' . $tables[$viewKey] . '_' . $dblang; $m = tmsModel::getModel('coupon'); $table = $m->getTable($tables[$viewKey]); //Todo create method to load lang fields only $table->load($id); $vs = $table->loadFieldValues(); $lf = $table->getTranslatableFields(); $json['fields'] = array(); foreach ($lf as $v) { if (isset($vs[$v])) { $json['fields'][$v] = $vs[$v]; } } //if ($json['fields'] = $db->loadAssoc()) { if ($table->getLoaded()) { $json['structure'] = 'filled'; $json['msg'] = tsmText::_('com_tsmart_SELECTED_LANG') . ':' . $lang; } else { $db = JFactory::getDBO(); $json['structure'] = 'empty'; $db->setQuery('SHOW COLUMNS FROM ' . $tableName); $tableDescribe = $db->loadAssocList(); array_shift($tableDescribe); $fields = array(); foreach ($tableDescribe as $key => $val) { $fields[$val['Field']] = $val['Field']; } $json['fields'] = $fields; $json['msg'] = tsmText::sprintf('com_tsmart_LANG_IS_EMPTY', $lang, tsmText::_('com_tsmart_' . strtoupper($viewKey))); } echo vmJsApi::safe_json_encode($json); jExit(); }