<?php
//$base = base_url();
$include_path = osa_include_path();
$page_img = osa_imagepath() . 'page.gif';
$edit_img = osa_imagepath() . 'edit.gif';
$copy_img = osa_imagepath() . 'copy.gif';
$mytree_img = osa_imagepath() . 'mycourse.gif';
//must specific name and path of theme
$jstree_script = "
<script type='text/javascript'>
function init_jstree(treename, tree_html, other_trees) {
	$(function () {
		$('#'+treename).jstree({
			'core' : { 'initially_open' : [ 'root' ] },
			'html_data' : {
			  'data' : tree_html,
			  'ajax' : {
			  		'url' : function (node){
						var current_url = $(node).children('a').attr('name');
			  			return current_url;
			  		}
			  	}
			},
			'themes' : {
				'theme' : 'classic',
				'url' : '{$include_path}js/jstree/themes/classic/style.css'
         },
         'types' : {
         	'types' :{
         		//leaf nodes (nodes have no children)
         		'file' : {'icon' : {'image' : '$page_img'}},
         		'editicon_type' : {'icon' : {'image' : '$edit_img'}},
         		'copyicon_type' : {'icon' : {'image' : '$copy_img'}},
         		'mytree_icon_type' : {'icon' : {'image' : '$mytree_img'}}
         	}
         },
			'plugins' : [ 'themes', 'html_data', 'cookies', 'types', 'ui']
		});
		$('#'+treename+' a').live('click', function(e) {
        $('#'+treename).jstree('toggle_node', this);
        $(other_trees).jstree('deselect_all');
        return false;
		});
	});
}
</script>";

$treedata = osa_menu_treedata();
echo $jstree_script;
echo "<script type='text/javascript'>" .
		"init_jstree({$treedata[CMS_MENU_COURSE_TREE][0]},{$treedata[CMS_MENU_COURSE_TREE][1]},{$treedata[CMS_MENU_COURSE_TREE][2]})</script>";
echo "<script type='text/javascript'>" .
			  "init_jstree({$treedata[CMS_MENU_DEPARTMENT_TREE][0]},{$treedata[CMS_MENU_DEPARTMENT_TREE][1]},{$treedata[CMS_MENU_DEPARTMENT_TREE][2]})</script>";
echo "<script type='text/javascript'>" .
			  "init_jstree({$treedata[CMS_MENU_GRADE_TREE][0]},{$treedata[CMS_MENU_GRADE_TREE][1]},{$treedata[CMS_MENU_GRADE_TREE][2]})</script>";
?>
<div id="general_tree">
<?php
		// my course tree
		echo "<h4 style='margin-left:2px;margin-top:3px;margin-bottom:3px;padding:0px'>" . lang('home_mycourses') . "</h4>";
		echo '<div id=\''. CMS_MENU_COURSE_TREE .'\'></div>';
		// departmnet treee
		echo "<H4 style='margin-left:2px;margin-top:5px;margin-bottom:0px;padding:0px'>" . lang('home_browseallcourses') . "</H4>";
		echo '<div id=\''. CMS_MENU_DEPARTMENT_TREE .'\'></div>';
		// grade tree
		echo '<div id=\''. CMS_MENU_GRADE_TREE .'\'></div>';
?>
	<div>
		<?php if (!$this->config->item('cms_not_show_gradetree_button')) { ?>
		<center>
			<form method="post" name="menus" onSubmit="return false;">
				<input type="button" name="switch_menu" value="<?php echo lang('home_gradebutton');?>"
				       onClick="return doMenuTree(); return false;" <?php osa_btn();?>/>
			</form>
		</center>
		<?php } ?>
	</div>
	<div id="total_unit">
	<?php
		$data->menutrees = $menutrees;
		$this->load->view('template/total_unit_view', $data);
	?>
	</div>
</div>
<div id="school_tree"></div>