<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Jure
 * Date: 18.3.14
 * Time: 13:23
 * To change this template use File | Settings | File Templates.
 */
//ini_set("display_errors", "1");
include_once(PATH_TO_ROOT . "_ajaxManipulators/_class/class.treeData.php");
include_once(PATH_TO_ROOT . "_ajaxManipulators/_class/class.gridData.php");
include_once(PATH_TO_ROOT . "CRM/class/class.checkString.php");

class WebCatiManagerCommonGroupsTreeDataMan extends TreeDataManipulator
{

    function selectAction()
    {

        if ($_POST['database']) $addIt = $_POST['database'] . "."; else $addIt = "";

        $parent = $_POST['node'];
        $sql = 'SELECT * FROM ' . $addIt . $this->tableTree . ' WHERE  ';

        if (strlen($_POST['filter']) > 0) {
            $fil = $_POST['filter'];
            $sql .= " (idLab LIKE '%$fil%' AND is_leaf = 1) ";
        } else

            $sql .= "id_sup = " . $parent;


        $sql .= ' ORDER BY is_leaf ASC, idLab ASC';


        If (!$res = $this->db->SQLexecute($sql)) {

            Echo '{success:false,error:"' . $this->db->GetError() . '", STATEMENT: "' . $sql . '"}';
        } else {
            //echo $sql;
            // display each child
            while ($row = $this->db->fetchAssoc($res)) {

                    //echo $sql;
                    // Response parameters.
                    $path = array();


                    if ($_REQUEST['boldRoots'] && $parent == 0) {
                        $path['cls'] = 'treeFontBold';
                        //$path['children'][] = array(text=>'1');
                        //$path['children'][] = array(text=>'2');
                    }

                    $path['text'] = html_entity_decode($row['idLab']);

                    $path['id'] = $row['id'];
                    $path['position'] = $row['orderBy'];
                    $path['isProject'] = $row['is_leaf'];
                    $path['id_project'] = $row['id_project'];
                    //	$path['cls'] = 'textSize';
                    // Check if node is a leaf or a folder.

                    if (!$path['isProject']) {
                        $path['leaf'] = false;

                    } else {
                        $path['leaf'] = true;
                        $path['checked'] = false;
                    }


                    if (isset($row['node_img']) && $row['node_img'] != '') {
                        $path['icon'] = $row['node_img'];
                    }

                    if (isset($row['q_pos']))
                        $path['q_pos'] = $row['q_pos'];

                    // call this function again to display this
                    // child's children
                    $nodes[] = $path;
                

            }

            //return $nodes;
        }
        echo "/* $sql */";

        include_once(PATH_TO_ROOT . "_support/include.projectRights.php");

        return json_encode($bla);

    }
}

?>