function _getCourseTreeStatus() { require_once _lms_ . '/lib/category/class.categorytree.php'; $treecat = new Categorytree(); if (!isset($_SESSION['course_category']['filter_status']['c_category'])) { $_SESSION['course_category']['filter_status']['c_category'] = 0; } $treestatus =& $_SESSION['course_category']['filter_status']['c_category']; $result = array(); $folders = $treecat->getOpenedFolders($treestatus); $ref =& $result; foreach ($folders as $folder) { if ($folder > 0) { for ($i = 0; $i < count($ref); $i++) { if ($ref[$i]['id'] == $folder) { $ref[$i]['expanded'] = true; $ref[$i]['children'] = array(); $ref =& $ref[$i]['children']; break; } } } $childrens = $treecat->getChildrensById($folder); while (list($id_category, $idParent, $path, $lev, $left, $right) = sql_fetch_row($childrens)) { $is_leaf = $right - $left == 1; $node_options = getNodeOptions($id_category, $is_leaf); $ref[] = array('type' => 'FolderNode', 'id' => $id_category, 'label' => end(explode('/', $path)), 'html' => end(explode('/', $path)), 'is_leaf' => $is_leaf, 'count_content' => (int) (($right - $left - 1) / 2), 'options' => $node_options); } } return $result; }
| Copyright (c) 2013 (Forma) | | http://www.formalms.org | | License http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt | | | | from docebo 4.0.5 CE 2008-2012 (c) docebo | | License http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt | \ ======================================================================== */ require_once _base_ . '/lib/lib.json.php'; require_once _lms_ . '/lib/category/class.categorytree.php'; $op = Get::req("op", DOTY_ALPHANUM); switch ($op) { case "expand": $json = new Services_JSON(); $node_id = Get::req('query', DOTY_INT, 0); $result = array(); $treecat = new Categorytree(); $re = $treecat->getChildrensById($node_id); while (list($idCategory, $idParent, $path, $lev, $left, $right) = sql_fetch_row($re)) { $result[] = array('id' => $idCategory, 'label' => end(explode('/', $path)), 'is_leaf' => $right - $left == 1, 'count_content' => ''); //change this } aout($json->encode($result)); break; case "getaddnodeform": $url = Get::req('server_url', DOTY_ALPHANUM, false); $parent_id = Get::req('parent_id', DOTY_ALPHANUM, false); $output = array(); $output['body'] = '<form name="tree_addfolder_form" method="POST" action="' . $url . '">' . '<input type="hidden" id="authentic_request_addfolder" name="authentic_request" value="' . Util::getSignature() . '" />' . '<input type="hidden" name="op" value="add_folder" />' . '<input type="hidden" name="parent_id" value="' . $parent_id . '" />' . '<label for="newname">' . "lang._NEW_FOLDER" . ':</label><input type="text" name="newname" /></form>'; $json = new Services_JSON(); aout($json->encode($output)); break;
<?php defined("IN_FORMA") or die('Direct access is forbidden.'); /* ======================================================================== \ | FORMA - The E-Learning Suite | | | | Copyright (c) 2013 (Forma) | | http://www.formalms.org | | License http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt | | | | from docebo 4.0.5 CE 2008-2012 (c) docebo | | License http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt | \ ======================================================================== */ require_once _lms_ . '/lib/category/class.categorytree.php'; $treecat = new Categorytree(); require_once _base_ . '/lib/lib.json.php'; $json = new Services_JSON(); //checkPerm('view', true, 'course', 'lms'); require_once _lms_ . '/lib/folder_tree/lib.category_tree.php'; // Resolve the requested action $command = Get::req('command', DOTY_STRING, false); switch ($command) { case "expand": $lang =& DoceboLanguage::CreateInstance('course', 'lms'); $node_id = Get::req('node_id', DOTY_INT, 0); $initial = Get::req('initial', DOTY_INT, 0); //$initial = 0; $result = array(); if ($initial == 1) { if (!isset($_SESSION['course_category']['filter_status']['c_category'])) { $_SESSION['course_category']['filter_status']['c_category'] = 0;
public function gettreedata() { require_once _lms_ . '/lib/category/class.categorytree.php'; $treecat = new Categorytree(); $command = Get::req('command', DOTY_ALPHANUM, ""); switch ($command) { case "expand": $node_id = Get::req('node_id', DOTY_INT, 0); $initial = Get::req('initial', DOTY_INT, 0); $db = DbConn::getInstance(); $result = array(); if ($initial == 1) { $treestatus = $this->_getSessionTreeData('c_category', 0); $folders = $treecat->getOpenedFolders($treestatus); $result = array(); $ref =& $result; foreach ($folders as $folder) { if ($folder > 0) { for ($i = 0; $i < count($ref); $i++) { if ($ref[$i]['node']['id'] == $folder) { $ref[$i]['children'] = array(); $ref =& $ref[$i]['children']; break; } } } $childrens = $treecat->getChildrensById($folder); while (list($id_category, $idParent, $path, $lev, $left, $right) = $db->fetch_row($childrens)) { $is_leaf = $right - $left == 1; $node_options = $this->_getNodeActions($id_category, $is_leaf); $ref[] = array('node' => array('id' => $id_category, 'label' => end(explode('/', $path)), 'is_leaf' => $is_leaf, 'count_content' => (int) (($right - $left - 1) / 2), 'options' => $node_options)); } } } else { //not initial selection, just an opened folder $re = $treecat->getChildrensById($node_id); while (list($id_category, $idParent, $path, $lev, $left, $right) = $db->fetch_row($re)) { $is_leaf = $right - $left == 1; $node_options = $this->_getNodeActions($id_category, $is_leaf); $result[] = array('id' => $id_category, 'label' => end(explode('/', $path)), 'is_leaf' => $is_leaf, 'count_content' => (int) (($right - $left - 1) / 2), 'options' => $node_options); //change this } } $output = array('success' => true, 'nodes' => $result, 'initial' => $initial == 1); echo $this->json->encode($output); break; case "set_selected_node": $id_node = Get::req('node_id', DOTY_INT, -1); if ($id_node >= 0) { $this->_setSessionTreeData('c_category', $id_node); } break; case "modify": $node_id = Get::req('node_id', DOTY_INT, 0); $new_name = Get::req('name', DOTY_STRING, false); $result = array('success' => false); if ($new_name !== false) { $result['success'] = $treecat->renameFolderById($node_id, $new_name); } if ($result['success']) { $result['new_name'] = stripslashes($new_name); } echo $this->json->encode($result); break; case "create": $node_id = Get::req('node_id', DOTY_INT, false); $node_name = Get::req('name', DOTY_STRING, false); //no multilang required for categories $result = array(); if ($node_id === false) { $result['success'] = false; } else { $success = false; $new_node_id = $treecat->addFolderById($node_id, $node_name); if ($new_node_id != false && $new_node_id > 0) { $success = true; } $result['success'] = $success; if ($success) { $result['node'] = array('id' => $new_node_id, 'label' => $node_name, 'is_leaf' => true, 'count_content' => 0, 'options' => $this->_getNodeActions($new_node_id, true)); } } echo $this->json->encode($result); break; case "delete": $node_id = Get::req('node_id', DOTY_INT, 0); $result = array('success' => $treecat->deleteTreeById($node_id)); echo $this->json->encode($result); break; case "move": $node_id = Get::req('node_id', DOTY_INT, 0); $node_dest = Get::req('node_dest', DOTY_INT, 0); $result = array('success' => $treecat->move($node_id, $node_dest)); echo $this->json->encode($result); break; case "options": $node_id = Get::req('node_id', DOTY_INT, 0); //get properties from DB $count = $treecat->getChildrenCount($node_id); $is_leaf = true; if ($count > 0) { $is_leaf = false; } $node_options = $this->_getNodeActions($node_id, $is_leaf); $result = array('success' => true, 'options' => $node_options, '_debug' => $count); echo $this->json->encode($result); break; //invalid command //invalid command default: } }