Здравствуйте, подскажите пожалуйста как сделать функцию так чтобы в меню добалялось optgroup меню
функция из DLE:
$cat_info = array(
1 => array( 'id' => 1, 'parentid' => 0, 'name' => 'test one' ),
2 => array( 'id' => 2, 'parentid' => 1, 'name' => 'test1' ),
3 => array( 'id' => 3, 'parentid' => 1, 'name' => 'test2' ),
4 => array( 'id' => 4, 'parentid' => 0, 'name' => 'test two' ),
5 => array( 'id' => 5, 'parentid' => 4, 'name' => 'test3' ),
6 => array( 'id' => 6, 'parentid' => 4, 'name' => 'test4' ),
);
function CategoryNewsSelection($categoryid = 0, $parentid = 0, $nocat = TRUE, $sublevelmarker = '', $returnstring = '') {
global $cat_info, $user_group, $member_id, $dle_module;
if ($dle_module == 'addnews') $allow_list = explode( ',', $user_group[$member_id['user_group']]['cat_allow_addnews'] );
else $allow_list = explode( ',', $user_group[$member_id['user_group']]['allow_cats'] );
$spec_list = explode( ',', $user_group[$member_id['user_group']]['cat_add'] );
$root_category = array ();
if( $parentid == 0 ) {
if( $nocat ) $returnstring .= '<option value="0"></option>';
} else {
$sublevelmarker .= ' ';
}
if( count( $cat_info ) ) {
foreach ( $cat_info as $cats ) {
if( $cats['parentid'] == $parentid ) $root_category[] = $cats['id'];
}
if( count( $root_category ) ) {
foreach ( $root_category as $id ) {
if( $allow_list[0] == "all" OR in_array( $id, $allow_list ) ) {
if( $spec_list[0] == "all" or in_array( $id, $spec_list ) ) $color = "black";
else $color = "red";
$returnstring .= "<option style=\"color: {$color}\" value=\"" . $id . '" ';
if( is_array( $categoryid ) ) {
foreach ( $categoryid as $element ) {
if( $element == $id ) $returnstring .= 'SELECTED';
}
} elseif( $categoryid == $id ) $returnstring .= 'SELECTED';
$returnstring .= '>' . $sublevelmarker . $cat_info[$id]['name'] . '</option>';
}
$returnstring = CategoryNewsSelection( $categoryid, $id, $nocat, $sublevelmarker, $returnstring );
}
}
}
return $returnstring;
}
Сам optgroup это то что жирным написано:
Не могу добиться именно такого результата:
<optgroup label="test one">
<option value="2"> test1</option>
<option value="3"> test2</option>
</optgroup>
<optgroup label="test two">
<option value="5"> test3</option>
<option value="6"> test4</option>
</optgroup>
optgroup label=test one и test two - Это parent_id = 0
Спасибо заранее за помощь!