/** * Creates structured option fields for all categories * * @todo: Connect to vendor data * @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 */ public static function categoryListTreeLoop($selectedCategories = array(), $cid = 0, $level = 0, $disabledFields = array(), $isSite, $vendorId, $vmlang, $categoryParentName = '') { 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); $selected = ""; if (!empty($records)) { foreach ($records as $key => $category) { $childId = $category->category_child_id; if ($childId != $cid) { if (in_array($childId, $selectedCategories)) { $selected = 'selected=\\"selected\\"'; } else { $selected = ''; } $disabled = ''; if (in_array($childId, $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 .= '<option ' . $selected . ' ' . $disabled . ' value="' . $childId . '">'; $categoryName = $category->category_name; if (VmConfig::get('full_catname_tree', 0)) { if (!empty($categoryParentName)) { $categoryName = $categoryParentName . ' | ' . $category->category_name; } } else { $categoryTree .= str_repeat(' - ', $level - 1); } $categoryTree .= $categoryName . '</option>'; } } if ($categoryModel->hasChildren($childId)) { self::categoryListTreeLoop($selectedCategories, $childId, $level, $disabledFields, $isSite, $vendorId, $vmlang, $categoryName); } } } return $categoryTree; }