type])){ $query = 'SELECT category_id FROM '.hikashop_table('category').' WHERE category_parent_id=0 LIMIT 1'; $db = JFactory::getDBO(); $db->setQuery($query); $parent = (int)$db->loadResult(); $select = 'SELECT a.category_name,a.category_id,a.category_namekey'; $table = ' FROM '.hikashop_table('category') . ' AS a'; $app = JFactory::getApplication(); $translationHelper = hikashop_get('helper.translation'); if($app->isAdmin() && $translationHelper->isMulti()){ $user = JFactory::getUser(); $locale = $user->getParam('language'); if(empty($locale)){ $config = JFactory::getConfig(); if(HIKASHOP_J30){ $locale = $config->get('language'); }else{ $locale = $config->getValue('config.language'); } } $lgid = $translationHelper->getId($locale); $select .= ',b.value'; $trans_table = 'jf_content'; if($translationHelper->falang){ $trans_table = 'falang_content'; } $table .=' LEFT JOIN '.hikashop_table($trans_table,false).' AS b ON a.category_id=b.reference_id AND b.reference_table=\'hikashop_category\' AND b.reference_field=\'category_name\' AND b.published=1 AND language_id='.$lgid; } $query = $select.$table; $query .= ' WHERE a.category_type = \''.$this->type.'\' AND a.category_parent_id!='.$parent.' ORDER BY a.category_ordering ASC'; $db->setQuery($query); if(!$app->isAdmin() && $translationHelper->isMulti(true) && class_exists('JFalangDatabase')){ $this->categories = $db->loadObjectList('','stdClass',false); }elseif(!$app->isAdmin() && $translationHelper->isMulti(true) && (class_exists('JFDatabase')||class_exists('JDatabaseMySQLx'))){ if(HIKASHOP_J25){ $this->categories = $db->loadObjectList('','stdClass',false); }else{ $this->categories = $db->loadObjectList('',false); } }else{ $this->categories = $db->loadObjectList(); } $data[$this->type] =& $this->categories; }else{ $this->categories =& $data[$this->type]; } $this->values = array(); if($form){ if(in_array($this->type,array('status','tax'))){ $this->values[] = JHTML::_('select.option', '', JText::_('HIKA_NONE') ); }else{ $this->values[] = JHTML::_('select.option', 0, JText::_('HIKA_NONE') ); } }else{ if($this->type=='status'){ $this->values[] = JHTML::_('select.option', '', JText::_('ALL_STATUSES') ); }else{ $this->values[] = JHTML::_('select.option', 0, JText::_('ALL_'.strtoupper($this->type)) ); } } if(!empty($this->categories)){ foreach($this->categories as $k => $category){ if(empty($category->value)){ $val = str_replace(' ','_',strtoupper($category->category_name)); $category->value = JText::_($val); if($val==$category->value){ $category->value = $category->category_name; } $this->categories[$k]->value = $category->value; } if($this->type=='status'){ $this->values[] = JHTML::_('select.option', $category->category_name, $category->value ); }elseif($this->type=='tax'){ $field = $this->field; $this->values[] = JHTML::_('select.option', $category->$field, $category->value ); }else{ $this->values[] = JHTML::_('select.option', (int)$category->category_id, $category->value ); } } } } function trans($status){ foreach($this->categories as $value){ if($value->category_name == $status){ return $value->value; } } foreach($this->categories as $value){ if($value->category_namekey == $status){ return $value->value; } } return $status; } function get($val){ foreach($this->values as $value){ if($value->value == $val){ return $value->text; } } return $val; } function display($map,$value,$form=true,$none=true,$id=''){ $this->value = $value; if(!is_bool($form)){ $attribute = $form; $form = $none; }elseif(!$form){ $attribute = ' onchange="document.adminForm.submit();"'; }else{ $attribute = ''; } $this->load($form); if(!in_array($this->type,array('status','tax'))){ $value = (int)$value; } if(strpos($attribute,'size="')===false){ if($this->multiple && !HIKASHOP_J30){ $attribute.=' size="3"'; }else{ $attribute.=' size="1"'; } } if($this->multiple){ $attribute .= ' multiple="multiple"'; $map .='[]'; } if(!empty($id)){ return JHTML::_('select.genericlist', $this->values, $map, 'class="inputbox"'.$attribute, 'value', 'text', $value , $id); }else{ return JHTML::_('select.genericlist', $this->values, $map, 'class="inputbox"'.$attribute, 'value', 'text', $value ); } } public function displaySingle($map, $value, $type = '', $root = 0, $delete = false) { hikashop_loadJslib('otree'); $id = str_replace(array('[',']'),array('_',''),$map); $key = 0; $name = 'Root'; if((int)$value > 0) { $categoryClass = hikashop_get('class.category'); $category = $categoryClass->get((int)$value); if($category) { $key = (int)$value; $name = $category->category_name; } } if($delete && ($value === null || $value === '')) { $key = ''; $name = ''.JText::_('HIKA_NONE').''; } if(empty($type)) $type = array('product','manufacturer','vendor'); $cleanText = ''.str_replace("'", "\\'", JText::_('HIKA_NONE')).''; $ret = '
'.$name.' '.(!$delete?'-': 'X').'
'; return $ret; } public function displayMultiple($map, $values, $type = '', $root = 0) { if(substr($map,-2) == '[]') $map = substr($map,0,-2); $id = str_replace(array('[',']'),array('_',''),$map); $ret = '
'; if(!empty($values)) { foreach($values as $key => $name) { $obj = null; if(is_object($name)) { $obj = $name; $name = $name->category_name; } $ret .= '
'. ''.$name. ' X'. '
'; } } $ret .= ''; $ret .= '
'. ''. ''. '
'; hikashop_loadJslib('otree'); if(empty($type)) $type = array('product','manufacturer','vendor'); $ret .= '
'; return $ret; } public function displayTree($id, $root = 0, $type = null, $displayRoot = false, $selectRoot = false) { hikashop_loadJslib('otree'); if(empty($type)) $type = array('product','manufacturer','vendor'); $ret = ''; $ret .= '
'; return $ret; } private function getData($type = 'product', $root = 0, $displayRoot = false, $selectRoot = false) { $categoryClass = hikashop_get('class.category'); if($root == 1) $root = 0; $elements = $categoryClass->getList($type, $root, $displayRoot); $ret = '['; $cpt = count($elements)-1; $sep = ''; $rootDepth = 0; foreach($elements as $k => $element) { $next = null; if($k < $cpt) $next = $elements[$k+1]; $status = 4; if(!empty($next) && $next->category_parent_id == $element->category_id) $status = 2; if($element->category_type == 'root') { $status = 5; $rootDepth = (int)$element->category_depth + 1; } if(($element->category_id == $root) || ($root == 0 && !$displayRoot && $rootDepth == 0)) $rootDepth = (int)$element->category_depth; $ret .= $sep.'{"status":'.$status.',"name":"'.str_replace('"','"',$element->category_name).'"'; if($element->category_type == 'root') { $ret .= ',"icon":"world"'; if(!$selectRoot) $ret .= ',"noselection":1'; else $ret .= ',"value":'.$element->category_id; } else { $ret .= ',"value":'.$element->category_id; } $sep = ''; if(!empty($next)) { if($next->category_depth > $element->category_depth && $element->category_type != 'root') { $ret .= ',"data":['; } else if($next->category_depth < $element->category_depth) { $ret .= '}'.str_repeat(']}', $element->category_depth - $next->category_depth); $sep = ','; } else { $ret .= '}'; $sep = ','; } } else { $ret .= '}'; if($element->category_depth >= $rootDepth) $ret .= str_repeat(']}', $element->category_depth - $rootDepth); } } $ret .= ']'; return $ret; } }