'index.php',"name" => get_lang('PlatformAdmin')); //$interbreadcrumb[]=array('url' => 'configure_homepage.php',"name" => get_lang('ConfigureHomePage')); Display::display_header($tool_name); //api_display_tool_title($tool_name); if(!empty($category)) { $myquery = "SELECT * FROM $tbl_category WHERE code ='$category'"; $result = Database::query($myquery); if(Database::num_rows($result)==0) { $category = ''; } } if(empty($action)) { $myquery="SELECT t1.name,t1.code,t1.parent_id,t1.tree_pos,t1.children_count,COUNT(DISTINCT t3.code) AS nbr_courses FROM $tbl_category t1 LEFT JOIN $tbl_category t2 ON t1.code=t2.parent_id LEFT JOIN $tbl_course t3 ON t3.category_code=t1.code WHERE t1.parent_id ".(empty($category)?"IS NULL":"='$category'")." GROUP BY t1.name,t1.code,t1.parent_id,t1.tree_pos,t1.children_count ORDER BY t1.tree_pos"; $result=Database::query($myquery); $Categories=Database::store_result($result); } if($action == 'add' || $action == 'edit') { ?>
addElement('header', '', $form_title); $form->display(); ?>
:
:
/> />
 
0){ $parent_id=Database::fetch_array($result); } $parent_id['parent_id']?$link=' ('.$parent_id['parent_id'].')':$link=''; ?>
'".$row['tree_pos']."'"); Database::query("DELETE FROM $tbl_category WHERE code='$node'"); if(!empty($row['parent_id'])) { updateFils($row['parent_id']); } } } function addNode($code,$name,$canHaveCourses,$parent_id) { global $tbl_category; $canHaveCourses=$canHaveCourses?'TRUE':'FALSE'; $code = Database::escape_string($code); $name = Database::escape_string($name); $parent_id = Database::escape_string($parent_id); $result=Database::query("SELECT 1 FROM $tbl_category WHERE code='$code'"); if(Database::num_rows($result)) { return false; } $result=Database::query("SELECT MAX(tree_pos) AS maxTreePos FROM $tbl_category"); $row=Database::fetch_array($result); $tree_pos=$row['maxTreePos']+1; Database::query("INSERT INTO $tbl_category(name,code,parent_id,tree_pos,children_count,auth_course_child) VALUES('$name','$code',".(empty($parent_id)?"NULL":"'$parent_id'").",'$tree_pos','0','$canHaveCourses')"); updateFils($parent_id); return true; } function editNode($code,$name,$canHaveCourses,$old_code) { global $tbl_category; $canHaveCourses=$canHaveCourses?'TRUE':'FALSE'; $code = Database::escape_string($code); $name = Database::escape_string($name); $old_code = Database::escape_string($old_code); if($code != $old_code) { $result=Database::query("SELECT 1 FROM $tbl_category WHERE code='$code'"); if(Database::num_rows($result)) { return false; } } Database::query("UPDATE $tbl_category SET name='$name',code='$code',auth_course_child='$canHaveCourses' WHERE code='$old_code'"); return true; } function moveNodeUp($code,$tree_pos,$parent_id) { global $tbl_category; $code = Database::escape_string($code); $tree_pos = Database::escape_string($tree_pos); $parent_id = Database::escape_string($parent_id); $result=Database::query("SELECT code,tree_pos FROM $tbl_category WHERE parent_id ".(empty($parent_id)?"IS NULL":"='$parent_id'")." AND tree_pos<'$tree_pos' ORDER BY tree_pos DESC LIMIT 0,1"); if(!$row=Database::fetch_array($result)) { $result=Database::query("SELECT code,tree_pos FROM $tbl_category WHERE parent_id ".(empty($parent_id)?"IS NULL":"='$parent_id'")." AND tree_pos>'$tree_pos' ORDER BY tree_pos DESC LIMIT 0,1"); if(!$row=Database::fetch_array($result)) { return false; } } Database::query("UPDATE $tbl_category SET tree_pos='".$row['tree_pos']."' WHERE code='$code'"); Database::query("UPDATE $tbl_category SET tree_pos='$tree_pos' WHERE code='$row[code]'"); } function updateFils($category) { global $tbl_category; $category = Database::escape_string($category); $result=Database::query("SELECT parent_id FROM $tbl_category WHERE code='$category'"); if($row=Database::fetch_array($result)) { updateFils($row['parent_id']); } $children_count=compterFils($category,0)-1; Database::query("UPDATE $tbl_category SET children_count='$children_count' WHERE code='$category'"); } function compterFils($pere,$cpt) { global $tbl_category; $pere = Database::escape_string($pere); $result=Database::query("SELECT code FROM $tbl_category WHERE parent_id='$pere'"); while($row=Database::fetch_array($result)) { $cpt=compterFils($row['code'],$cpt); } return ($cpt+1); } ?>