</div> <div class="form-group"> <div class="col-sm-4"> <label><?php echo lang('idea_admin_categories_edit_category_parent_category'); ?> </label> <?php $cate_val = array('0' => set_value('data[parent_id]', $category->parent_id)); echo '<select class="form-control" name="data[parent_id]">'; echo '<option value="0">' . lang('root') . '</option>'; if ($category->id != '') { echo dispayCateTree($categories, 0, $cate_val, $category->id); } else { echo dispayCateTree($categories, 0, $cate_val); } echo '</select>'; ?> </div> </div> <div class="form-group" style="display: none;"> <div class="col-sm-4"> <label><?php echo lang('language'); ?> </label> <?php $lang = array('en' => 'English', 'vn' => 'Vietname'); echo form_dropdown('data[language]', $lang, 'en', 'class="form-control"');
</div> </div> <div class="form-group"> <label class="col-sm-3"><?php lang('art_category_choose'); ?> </label> <div class="col-sm-7"> <select name="art[cate_id]" class="form-control"> <option value="0"><?php lang('art_category'); ?> </option> <?php echo dispayCateTree($data['categories'], 0, array(setValue($data['art'], 'cate_id', 0))); ?> </select> </div> </div> <div class="form-group"> <label class="col-sm-3"><?php lang('description'); ?> </label> <div class="col-sm-7"> <textarea type="text" class="form-control" name="art[description]" rows="3"><?php echo setValue($data['art'], 'description', ''); ?> </textarea>
function dispayCateTree($categories, $level = 0, $cate_checked = array(), $remove_id = '') { if (!is_array($categories) or empty($categories)) { return ''; } $html = ''; if (count($categories)) { foreach ($categories as $category) { if ($category->id != $remove_id) { $checked = ''; if (in_array($category->id, $cate_checked)) { $checked = 'selected="selected"'; } $html .= '<option ' . $checked . ' value="' . $category->id . '">' . str_repeat(' ', $level) . str_repeat(' ', $level) . $category->title . '</option>'; if (isset($category->children) && count($category->children) > 0) { $html .= dispayCateTree($category->children, $level + 1, $cate_checked, $remove_id); } } } } return $html; }