'; if ($view != 'user' and $view != 'shoppergroup') { $cid = 'cid'; } else if ($view == 'user'){ $cid = 'virtuemart_user_id'; } else { $cid = 'virtuemart_shoppergroup_id'; } $model = new VmModel(); $table = $model->getTable($table); if(!is_array($idList)){ $db = JFactory::getDBO (); $q = 'SELECT `' . $table->getPKey() . '` FROM `#__virtuemart_' . $db->escape ($tableXref) . '` WHERE ' . $db->escape ($tableSecondaryKey) . ' = "' . (int)$idList . '"'; $db->setQuery ($q); $idList = $db->loadColumn (); } $i = 0; foreach($idList as $id ){ $item = $table->load ((int)$id); if($translate) $item->{$name} = vmText::_($item->{$name}); $link = JHtml::_('link', JRoute::_('index.php?option=com_virtuemart&view='.$view.'&task=edit&'.$cid.'[]='.$id,false), $item->{$name}); if($i<$quantity and $i<=count($idList)){ $list .= '
  • ' . $link . '
  • '; } else if ($i==$quantity and $igetTable($table); if(!is_array($idList) and !empty($idList) and $tableXref != false){ $db = JFactory::getDBO (); $q = 'SELECT `' . $table->getPKey() . '` FROM `#__virtuemart_' . $db->escape ($tableXref) . '` WHERE ' . $db->escape ($tableSecondaryKey) . ' = "' . (int)$idList . '"'; $db->setQuery ($q); $idList = $db->loadColumn (); } $i = 0; if(is_array($idList) and !empty($idList)){ foreach($idList as $id ){ $item = $table->load ((int)$id); if($translate) $item->{$name} = vmText::_($item->{$name}); $link = ', '.JHtml::_('link', JRoute::_('index.php?option=com_virtuemart&view='.$view.'&task=edit&'.$cid.'[]='.$id,false), $item->{$name}); if($i<$quantity and $i<=count($idList)){ $list .= $link; } else if ($i==$quantity and $i{$name}; if($i>($quantity + 6)) { $ttip .= ',...'; break; } $i++; } } if(!$list) return ''; $list = substr ($list, 2); $ttip = substr ($ttip, 2); return '' . $list . ''; } /** * Creates a Drop Down list of available Vendors * * @author Max Milbers * @access public * @param int $virtuemart_shoppergroup_id the shopper group to pre-select * @param bool $multiple if the select list should allow multiple selections * @return string HTML select option list */ static public function renderVendorList ($vendorId=false, $name = 'virtuemart_vendor_id', $sendForm = false, $multiple = false) { $view = vRequest::getCmd('view',false); if($vendorId === false){ if(vmAccess::manager('managevendors')){ $vendorId = strtolower (JFactory::getApplication()->getUserStateFromRequest ('com_virtuemart.'.$view.'.virtuemart_vendor_id', 'virtuemart_vendor_id', vmAccess::getVendorId(), 'int')); } else{ $vendorId = vmAccess::getVendorId(); } } if(!vmAccess::manager(array($view,'managevendors'),0,true)) { if (empty($vendorId)) { $vendor = vmText::_('COM_VIRTUEMART_USER_NOT_A_VENDOR'); } else { $db = JFactory::getDBO (); $q = 'SELECT `vendor_name` FROM `#__virtuemart_vendors` WHERE `virtuemart_vendor_id` = "' . (int)$vendorId . '" '; $db->setQuery ($q); $vendor = $db->loadResult (); } return '' . $vendor . ''; } else { return self::renderVendorFullVendorList($vendorId, $multiple, $name, $sendForm); } } static public function renderVendorFullVendorList($vendorId, $multiple = false, $name = 'virtuemart_vendor_id', $sendForm = true){ $vendors = VirtueMartModelVendor::getVendorNames(); $attrs = array(); $id = '['; $idA = $name; $attrs['class'] = 'vm-chzn-select vm-drop'; if ($multiple) { $attrs['multiple'] = 'multiple'; $idA .= '[]'; } else { $emptyOption = JHtml::_ ('select.option', '', vmText::_ ('COM_VIRTUEMART_SELECT_VENDOR'), 'virtuemart_vendor_id', 'vendor_name'); array_unshift ($vendors, $emptyOption); } if($sendForm){ $attrs['class'] .= ' changeSendForm'; } $listHTML = JHtml::_ ('select.genericlist', $vendors, $idA, $attrs, 'virtuemart_vendor_id', 'vendor_name', $vendorId, $id); return $listHTML; } /** * Creates a Drop Down list of available Shopper Groups * * @author Max Milbers * @access public * @param int $shopperGroupId the shopper group to pre-select * @param bool $multiple if the select list should allow multiple selections * @return string HTML select option list */ static public function renderShopperGroupList ($shopperGroupId = 0, $multiple = TRUE,$name='virtuemart_shoppergroup_id', $select_attribute='COM_VIRTUEMART_DRDOWN_AVA2ALL', $attrs = array() ) { vmLanguage::loadJLang('com_virtuemart_shoppers',TRUE); $shopperModel = VmModel::getModel ('shoppergroup'); $shoppergrps = $shopperModel->getShopperGroups (FALSE, TRUE); if(empty($attrs['class'])) $attrs['class'] = 'vm-chzn-select vm-drop'; //if(!isset($attrs['style'])) $attrs['style'] = 'min-width:150px'; //$attrs['style']='width: 200px;'; if ($multiple) { $attrs['multiple'] = 'multiple'; $attrs['data-placeholder'] = vmText::_($select_attribute); if($name=='virtuemart_shoppergroup_id'){ $name.= '[]'; } } else { $emptyOption = JHTML::_ ('select.option', '', vmText::_ ($select_attribute), 'virtuemart_shoppergroup_id', 'shopper_group_name'); array_unshift ($shoppergrps, $emptyOption); } $listHTML = JHTML::_ ('select.genericlist', $shoppergrps, $name, $attrs, 'virtuemart_shoppergroup_id', 'shopper_group_name', $shopperGroupId,'[',true); $listHTML .= ''; return $listHTML; } /** * Renders the list of Manufacturers * * @author St. Kraft * Mod. St.Kraft 2013-02-24 Herstellerrabatt */ static public function renderManufacturerList ($manufacturerId = 0, $multiple = FALSE, $name = 'virtuemart_manufacturer_id') { $manufacturerModel = VmModel::getModel ('manufacturer'); $manufacturers = $manufacturerModel->getManufacturers (FALSE, TRUE); //$attrs = array('style'=>"width: 210px"); $attrs['class'] = 'vm-chzn-select vm-drop'; //$attrs['style'] = 'min-width:150px'; if ($multiple) { $attrs['multiple'] = 'multiple'; if($name=='virtuemart_manufacturer_id') $name.= '[]'; } else { $emptyOption = JHtml::_ ('select.option', '', vmText::_ ('COM_VIRTUEMART_LIST_EMPTY_OPTION'), 'virtuemart_manufacturer_id', 'mf_name'); array_unshift ($manufacturers, $emptyOption); } $listHTML = JHtml::_ ('select.genericlist', $manufacturers, $name, $attrs, 'virtuemart_manufacturer_id', 'mf_name', $manufacturerId); return $listHTML; } /** * Renders the list for the tax rules * * @author Max Milbers */ static function renderTaxList ($selected, $name = 'product_tax_id', $class = '') { $taxes = VirtueMartModelCalc::getTaxes (); $taxrates = array(); $taxrates[] = JHtml::_ ('select.option', '-1', vmText::_ ('COM_VIRTUEMART_PRODUCT_TAX_NONE'), $name); $taxrates[] = JHtml::_ ('select.option', '0', vmText::_ ('COM_VIRTUEMART_PRODUCT_TAX_NO_SPECIAL'), $name); foreach ($taxes as $tax) { $taxrates[] = JHtml::_ ('select.option', $tax->virtuemart_calc_id, vmText::_($tax->calc_name), $name); } $listHTML = JHtml::_ ('select.genericlist', $taxrates, $name, $class, $name, 'text', $selected,'['); return $listHTML; } /** * Creates the chooseable template list * * @author Max Milbers, impleri * * @param string defaultText Text for the empty option * @param boolean defaultOption you can supress the empty otion setting this to false * return array of Template objects */ static public function renderTemplateList ($defaultText = 0, $defaultOption = TRUE) { if (empty($defaultText)) { $defaultText = vmText::_ ('COM_VIRTUEMART_TEMPLATE_DEFAULT'); } $defaulttemplate = array(); if ($defaultOption) { $defaulttemplate[0] = new stdClass; $defaulttemplate[0]->name = $defaultText; $defaulttemplate[0]->directory = 0; $defaulttemplate[0]->value = ''; } $q = 'SELECT * FROM `#__template_styles` WHERE `client_id`="0"'; $db = JFactory::getDbo(); $db->setQuery($q); $jtemplates = $db->loadObjectList(); foreach ($jtemplates as $key => $template) { $template->name = $template->title; $template->value = $template->id; $template->directory = $template->template; } return array_merge ($defaulttemplate, $jtemplates); } static function renderOrderingList($table,$fieldname,$selected,$where='',$orderingField = 'ordering'){ // Ordering dropdown $qry = 'SELECT ordering AS value, '.$fieldname.' AS text' . ' FROM #__virtuemart_'.$table.' '.$where . ' ORDER BY '.$orderingField; $db = JFactory::getDbo(); $db->setQuery($qry); $orderStatusList = $db -> loadAssocList(); foreach($orderStatusList as &$text){ $text['text'] = $text['value'].' '.vmText::_($text['text']); } return JHtml::_('select.genericlist',$orderStatusList,'ordering','','value','text',$selected); } static function renderShipmentDropdown($virtuemart_shipment_ids){ $m = VmModel::getModel('shipmentmethod'); if(!$m){ return false; } $m->_noLimit = true; $values = $m->getShipments(); $m->_noLimit = false; $options = array(); $lvalue = 'virtuemart_shipmentmethod_id'; $ltext = 'shipment_name'; foreach ($values as $v) { $options[] = JHtml::_('select.option', $v->{$lvalue}, $v->{$ltext}); } $name = $idTag = 'virtuemart_shipmentmethod_ids'; $attrs['multiple'] = 'multiple'; $name .= '[]'; return JHtml::_ ('select.genericlist', $options, $name, $attrs, 'value', 'text', $virtuemart_shipment_ids, $idTag); } /** * Returns all the weight unit * * @author Valérie Isaksen */ static function getWeightUnit () { static $weigth_unit; if ($weigth_unit) { return $weigth_unit; } return $weigth_unit = array( 'KG' => vmText::_ ('COM_VIRTUEMART_UNIT_NAME_KG') , 'G' => vmText::_ ('COM_VIRTUEMART_UNIT_NAME_G') , 'MG' => vmText::_ ('COM_VIRTUEMART_UNIT_NAME_MG') , 'LB' => vmText::_ ('COM_VIRTUEMART_UNIT_NAME_LB') , 'OZ' => vmText::_ ('COM_VIRTUEMART_UNIT_NAME_ONCE') ); } /** * Renders the string for the * * @author Valérie Isaksen */ static function renderWeightUnit ($name) { $weigth_unit = self::getWeightUnit (); if (isset($weigth_unit[$name])) { return $weigth_unit[$name]; } else { return ''; } } /** * Renders the list for the Weight Unit * * @author Valérie Isaksen */ static function renderWeightUnitList ($name, $selected) { $weight_unit_default = self::getWeightUnit (); //In case a unit got stored, which is not in the default list, we add the unit here, else we would lose the information if ((!empty($selected)) && (!in_array($selected, $weight_unit_default))) $weight_unit_default[$selected] = $selected; foreach ($weight_unit_default as $key => $value) { $wu_list[] = JHtml::_ ('select.option', $key, $value, $name); } $listHTML = JHtml::_ ('select.genericlist', $wu_list, $name, '', $name, 'text', $selected); return $listHTML; } static function renderUnitIsoList($name, $selected){ $weight_unit_default = explode(',',VmConfig::get('norm_units', 'KG,100G,M,SM,CUBM,L,100ML,P')); if ((!empty($selected)) && (!in_array($selected, $weight_unit_default))) $weight_unit_default[] = $selected; foreach ($weight_unit_default as $value) { $wu_list[] = JHtml::_ ('select.option', trim($value), vmText::_('COM_VIRTUEMART_UNIT_SYMBOL_'.strtoupper(trim($value))), $name); } $listHTML = JHtml::_ ('select.genericlist', $wu_list, $name, '', $name, 'text', $selected); return $listHTML; } /** * typo problem with the function name. We must keep the other one for compatibility purposes * @deprecated * @param $value * @param $from * @param $to */ static function convertWeigthUnit ($value, $from, $to) { return self::convertWeightUnit ($value, $from, $to); } /** * Convert Weight Unit * * @author Valérie Isaksen */ static function convertWeightUnit ($value, $from, $to) { $from = strtoupper($from); $to = strtoupper($to); $value = str_replace (',', '.', $value); if ($from === $to) { return $value; } if (is_nan(floatval($value))) { return 0; } $g = (float)$value; switch ($from) { case 'KG': $g = (float)(1000 * $value); break; case 'MG': $g = (float)($value / 1000); break; case 'LB': $g = (float)(453.59237 * $value); break; case 'OZ': $g = (float)(28.3495 * $value); break; } switch ($to) { case 'KG' : $value = (float)($g / 1000); break; case 'G' : $value = $g; break; case 'MG' : $value = (float)(1000 * $g); break; case 'LB' : $value = (float)($g / 453.59237); break; case 'OZ' : $value = (float)($g / 28.3495); break; } return $value; } /** * Convert Metric Unit * * @author Florian Voutzinos */ static function convertDimensionUnit ($value, $from, $to) { $from = strtoupper($from); $to = strtoupper($to); $value = (float)str_replace (',', '.', $value); if ($from === $to) { return $value; } $meter = (float)$value; // transform $value in meters switch ($from) { case 'CM': $meter = (float)(0.01 * $value); break; case 'MM': $meter = (float)(0.001 * $value); break; case 'YD' : $meter =(float) (0.9144 * $value); break; case 'FT' : $meter = (float)(0.3048 * $value); break; case 'IN' : $meter = (float)(0.0254 * $value); break; } switch ($to) { case 'M' : $value = $meter; break; case 'CM': $value = (float)($meter / 0.01); break; case 'MM': $value = (float)($meter / 0.001); break; case 'YD' : $value =(float) ($meter / 0.9144); break; case 'FT' : $value = (float)($meter / 0.3048); break; case 'IN' : $value = (float)($meter / 0.0254); break; } return $value; } /** * Renders the list for the Length, Width, Height Unit * * @author Valérie Isaksen */ static function renderLWHUnitList ($name, $selected) { $lwh_unit_default = array('M' => vmText::_ ('COM_VIRTUEMART_UNIT_NAME_M') , 'CM' => vmText::_ ('COM_VIRTUEMART_UNIT_NAME_CM') , 'MM' => vmText::_ ('COM_VIRTUEMART_UNIT_NAME_MM') , 'YD' => vmText::_ ('COM_VIRTUEMART_UNIT_NAME_YARD') , 'FT' => vmText::_ ('COM_VIRTUEMART_UNIT_NAME_FOOT') , 'IN' => vmText::_ ('COM_VIRTUEMART_UNIT_NAME_INCH') ); foreach ($lwh_unit_default as $key => $value) { $lu_list[] = JHtml::_ ('select.option', $key, $value, $name); } $listHTML = JHtml::_ ('select.genericlist', $lu_list, $name, '', $name, 'text', $selected); return $listHTML; } /** * This generates the list when the user have different ST addresses saved * @deprecated use shopFunctionsF::generateStAddressList instead * @author Oscar van Eijk */ static function generateStAddressList ($view, $userModel, $task) { return shopFunctionsF::generateStAddressList($view, $userModel, $task); } /** * @deprecated use shopFunctionsF::renderVendorAddress instead * @param $vendorId * @param string $lineSeparator * @param array $skips * @return string */ static public function renderVendorAddress ($vendorId,$lineSeparator="
    ", $skips = array('name','username','email','agreed')) { return shopFunctionsF::renderVendorAddress($vendorId, $lineSeparator, $skips); } public static $counter = 0; public static $categoryTree = array(); public static $cache = null; static public function categoryListTree ($selectedCategories = array(), $cid = 0, $level = 0, $disabledFields = array(), $onlyPublished = null) { if(VmConfig::get('UseCachegetChildCategoryList',true)){ self::$cache = VmConfig::getCache('com_virtuemart_cats_dropdown',''); $cachedCats = self::$cache->get('com_virtuemart_cats_dropdown'); if($cachedCats){ self::$categoryTree = $cachedCats; } } if(!is_array($selectedCategories)){ $selectedCategories = array($selectedCategories); } if($onlyPublished === null){ $onlyPublished = VmConfig::isSite(); } $hash = implode('.', $selectedCategories).'-'.$cid.'-'.$level.'-'.implode('.', $disabledFields).'_'.$onlyPublished; if(!isset(self::$categoryTree[$hash])){ $vendorId = vmAccess::isSuperVendor(); //self::$categoryTree[$hash] = ShopFunctions::categoryListTreeLoop($selectedCategories, $cid, $level, $disabledFields, VmConfig::isSite(), $vendorId, VmConfig::$vmlang); $cats = VirtueMartModelCategory::getCatsTree(false, $vendorId, 0, 10, false, $onlyPublished); $categoryTree = ''; if (!empty($cats)) { foreach ($cats as $key => $category) { if ($category->virtuemart_category_id != $cid) { if (in_array ($category->virtuemart_category_id, $selectedCategories)) { $selected = 'selected="selected"'; //that was selected=\"selected\" } else { $selected = ''; } $disabled = ''; if (in_array ($category->virtuemart_category_id, $disabledFields)) { $disabled = 'disabled="disabled"'; } if ($disabled != '' && stristr ($_SERVER['HTTP_USER_AGENT'], 'msie')) { //IE7 suffers from a bug, which makes disabled option fields selectable } else { $categoryTree .= ''; } } } } self::$categoryTree[$hash] = $categoryTree; } if(self::$cache!==null) self::$cache->store(self::$categoryTree, 'com_virtuemart_cats_dropdown'); return self::$categoryTree[$hash]; } /** * Creates structured option fields for all categories * * @deprecated * @author Max Milbers, jseros * @param array $selectedCategories All category IDs that will be pre-selected * @param int $cid Internally used for recursion * @param int $level Internally used for recursion * @return string $category_tree HTML: Category tree list */ static public function categoryListTreeLoop ($selectedCategories, $cid, $level, $disabledFields, $isSite, $vendorId, $vmlang,$categoryParentName='') { vmSetStartTime('categoryListTreeLoop'); static $categoryTree = ''; if($level==0) { $categoryTree = ''; self::$counter = 0; } self::$counter++; $categoryModel = VmModel::getModel ('category'); $level++; $categoryModel->_noLimit = TRUE; //$records = $categoryModel->getCategories ($isSite, $cid, false, '', $vendorId); $records = $categoryModel->getChildCategoryList($vendorId, $cid, 'c.ordering,category_name', 'ASC', false); $selected = ""; if (!empty($records)) { foreach ($records as $key => $category) { if ($category->virtuemart_category_id != $cid) { if (in_array ($category->virtuemart_category_id, $selectedCategories)) { $selected = 'selected="selected"'; //that was selected=\"selected\" } else { $selected = ''; } $disabled = ''; if (in_array ($category->virtuemart_category_id, $disabledFields)) { $disabled = 'disabled="disabled"'; } if ($disabled != '' && stristr ($_SERVER['HTTP_USER_AGENT'], 'msie')) { //IE7 suffers from a bug, which makes disabled option fields selectable } else { $categoryTree .= ''; } } if ($category->has_children) { self::categoryListTreeLoop ($selectedCategories, $category->virtuemart_category_id, $level, $disabledFields,$isSite, $vendorId, $vmlang, $categoryName); } } } vmTime('categoryListTreeLoop','categoryListTreeLoop'); return $categoryTree; } /** * Return the countryname or code of a given countryID * * @author Max Milbers * @access public * @param int $id Country ID * @param char $fld Field to return: country_name (default), country_2_code or country_3_code. * @return string Country name or code */ static public function getCountryByID ($id, $fld = 'country_name') { if (empty($id)) { return ''; } VmModel::getModel('country'); return VirtueMartModelCountry::getCountryFieldByID($id, $fld); } /** * Return the virtuemart_country_id of a given country name * * @author Max Milbers * @access public * @param string $name Country name (can be country_name or country_3_code or country_2_code ) * @return int virtuemart_country_id */ static public function getCountryIDByName ($name) { if (empty($name)) { return 0; } VmModel::getModel('country'); $c = VirtueMartModelCountry::getCountryByCode($name); if($c and isset($c->virtuemart_country_id)){ return $c->virtuemart_country_id; } else { return false; } } /** * Return the statename or code of a given virtuemart_state_id * * @author Oscar van Eijk * @access public * @param int $id State ID * @param char $fld Field to return: state_name (default), state_2_code or state_3_code. * @return string state name or code */ static public function getStateByID ($id, $fld = 'state_name') { if (empty($id)) { return ''; } $db = JFactory::getDBO (); $q = 'SELECT ' . $db->escape ($fld) . ' AS fld FROM `#__virtuemart_states` WHERE virtuemart_state_id = "' . (int)$id . '"'; $db->setQuery ($q); $r = $db->loadObject (); return $r->fld; } /** * Return the stateID of a given state name * * @author Max Milbers * @access public * @param string $name Country name * @return int virtuemart_state_id */ static public function getStateIDByName ($name) { if (empty($name)) { return 0; } $db = JFactory::getDBO (); if (strlen ($name) === 2) { $fieldname = 'state_2_code'; } else { if (strlen ($name) === 3) { $fieldname = 'state_3_code'; } else { $fieldname = 'state_name'; } } $q = 'SELECT `virtuemart_state_id` FROM `#__virtuemart_states` WHERE `' . $fieldname . '` = "' . $db->escape ($name) . '"'; $db->setQuery ($q); $r = $db->loadResult (); return $r; } /* * Returns the associative array for a given virtuemart_calc_id * * @author Valérie Isaksen * @access public * @param int $id virtuemart_calc_id * @return array Result row */ static public function getTaxByID ($id) { if (empty($id)) { return ''; } $id = (int)$id; $db = JFactory::getDBO (); $q = 'SELECT * FROM `#__virtuemart_calcs` WHERE virtuemart_calc_id = ' . (int)$id; $db->setQuery ($q); return $db->loadAssoc (); } /** * Return any field from table '#__virtuemart_currencies' * * @author Valérie Isaksen * @access public * @param int $id Currency ID * @param char $fld Field from table '#__virtuemart_currencies' to return: currency_name (default), currency_code_2, currency_code_3 etc. * @return string Currency name or code */ static public function getCurrencyByID ($id, $fld = 'currency_name') { if (empty($id)) { return ''; } static $currencyNameById = array(); if(!isset($currencyNameById[$id][$fld])){ $currency = VmModel::getModel('currency')->getCurrency($id); $currencyNameById[$id][$fld] = $currency->{$fld}; /*$db = JFactory::getDBO (); $q = 'SELECT ' . $db->escape ($fld) . ' AS fld FROM `#__virtuemart_currencies` WHERE virtuemart_currency_id = ' . (int)$id; $db->setQuery ($q); $currencyNameById[$id][$fld] = $db->loadResult ();*/ } return $currencyNameById[$id][$fld]; } /** * Return the currencyID of a given Currency name * This function becomes dangerous if there is a currency name with 3 letters * @author Valerie Isaksen, Max Milbers * @access public * @param string $name Currency name * @return int virtuemart_currency_id */ static public function getCurrencyIDByName ($name) { if (empty($name)) { return 0; } static $currencyIdByName = array(); if(!isset($currencyIdByName[$name])){ $db = JFactory::getDBO (); if (strlen ($name) === 2) { $fieldname = 'currency_code_2'; } else { if (strlen ($name) === 3) { $fieldname = 'currency_code_3'; } else { $fieldname = 'currency_name'; } } $q = 'SELECT `virtuemart_currency_id` FROM `#__virtuemart_currencies` WHERE `' . $fieldname . '` = "' . ($name) . '"'; $db->setQuery ($q); $currencyIdByName[$name] = $db->loadResult (); } return $currencyIdByName[$name]; } /** * Print a select-list with enumerated categories * * @author jseros * * @param boolean $onlyPublished Show only published categories? * @param boolean $withParentId Keep in mind $parentId param? * @param integer $parentId Show only its childs * @param string $attribs HTML attributes for the list * @return string