<?php

    print("<h4>1. ".$parser->gt('simpletree', __FILE__)." (".$parser->gt('pages').")</h4>");

    // Create new instance of the wAjaxTree class
    include_once(SYS_BASE_PATH.'main/classes/wajaxtree.class.php');
    $w = new wAjaxTree();
    $w->container = 'page_tree';
    // Set sql
    $w->q->select('objid');
    $w->q->select('name', '', array('lang' => true));
    $w->q->select('isfolder');
    $w->q->select('parent');
    $w->q->from('sys_objects');
    $w->q->where("objid<>'0'");
    $w->q->where("objtype='sys_elements_pages'");
    $w->q->where("parent=:parent:");
    $w->q->orderby('name', true);
    // Print the tree
    $w->show();
    print("<pre class=\"brush:php\">
    // Create new instance of the wAjaxTree class
    include_once(SYS_BASE_PATH.'main/classes/wajaxtree.class.php');
    ".'$'."w = new wAjaxTree();

    // Set sql
    ".'$'."w->q->select('objid');
    ".'$'."w->q->select('name', '', array('lang' => true)); // Or  ".'$'."w->q->lselect('name');
    ".'$'."w->q->select('isfolder');
    ".'$'."w->q->select('parent');
    ".'$'."w->q->from('sys_objects');
    ".'$'."w->q->where(\"objid<>'0'\");
    ".'$'."w->q->where(\"objtype='sys_elements_pages'\");
    ".'$'."w->q->where(\"parent=:parent:\");
    ".'$'."w->q->orderby('name', true);                     // Or  ".'$'."w->q->lorderby('name');

    // Print the tree
    ".'$'."w->show();

    </pre>");

    print("<h4>2. ".$parser->gt('treeeditable', __FILE__)." (".$parser->gt('clickondiam').")</h4>");
    print("<div style=\"width:250px\">");
    // Create new instance of the wAjaxTree class
    include_once(SYS_BASE_PATH.'main/classes/wajaxtree.class.php');
    $w = new wAjaxTree('test_uni');
    $w->container = 'tree_editable';

    // Set sql
    $w->q->select('id');
    $w->q->select('name');
    $w->q->select('isfolder');
    $w->q->select('parent');
    $w->q->from('test_uni');
    $w->q->where('id>0');
    $w->q->where('parent=:parent:');
    $w->q->orderby('name');

    // Set permissions for tree
    $w->editing = true;
    $w->adding = true;
    $w->deleting = true;

    // Print the tree
    $w->show();
    print("</div>");

    print("<pre class=\"brush:php\">
    // Create new instance of the wAjaxTree class
    include_once(SYS_BASE_PATH.'main/classes/wajaxtree.class.php');
    ".'$'."w = new wAjaxTree('test_uni');
    ".'$'."w->container = 'tree_editable';

    // Set sql
    ".'$'."w->q->select('id');
    ".'$'."w->q->select('name');
    ".'$'."w->q->select('isfolder');
    ".'$'."w->q->select('parent');
    ".'$'."w->q->from('test_uni');
    ".'$'."w->q->where('id>0');
    ".'$'."w->q->where('parent=:parent:');
    ".'$'."w->q->orderby('name');

    // Set permissions for tree
    ".'$'."w->editing = true;
    ".'$'."w->adding = true;
    ".'$'."w->deleting = true;

    // Print the tree
    ".'$'."w->show();

    </pre>");


    print("<h4>3. ".$parser->gt('extracontmenu', __FILE__)." (".$parser->gt('clickondiam').")</h4>");
    print("<div style=\"width:250px\">");
    // Create new instance of the wAjaxTree class
    include_once(SYS_BASE_PATH.'main/classes/wajaxtree.class.php');
    $w = new wAjaxTree('test_uni');
    $w->container = 'tree_extracontmenu';

    // Set sql
    $w->q->select('id');
    $w->q->select('name');
    $w->q->select('isfolder');
    $w->q->select('parent');
    $w->q->from('test_uni');
    $w->q->where('id>0');
    $w->q->where('parent=:parent:');
    $w->q->orderby('name');

    // Set permissions for tree
    $w->editing = true;
    $w->adding = true;
    $w->deleting = true;

    // Add some contexmenu items
    $w->addContextMenu('<b style="color:red">'.$parser->gt('test', __FILE__).' '.$parser->gt('contextmenu', __FILE__).'</b>','testaction', $parser->gt('menu_comment', __FILE__));
    // Handling menu action
    $action =  (isset($_POST["action"])) ? $_POST["action"] : '';
    $containerid =  (isset($_POST["containerid"])) ? $_POST["containerid"] : '';
    $formid =  (isset($_POST["formid"])) ? $_POST["formid"] : ''; // id of row element for contextmenu
    if($action && ($containerid == $w->container))
    {
        switch($action)
        {
            case 'testaction':
                        if(ob_get_length()) ob_clean();
                                print($parser->gt('do_smth_cont', $fn).$formid);
                        exit;
            break;
        }
    }

    // Print the tree
    $w->show();
    print("</div>");
    print("<pre class=\"brush:php\">
    // Create new instance of the wAjaxTree class
    include_once(SYS_BASE_PATH.'main/classes/wajaxtree.class.php');
    ".'$'."w = new wAjaxTree('test_uni');
    ".'$'."w->container = 'tree_extracontmenu';

    // Set sql
    ".'$'."w->q->select('id');
    ".'$'."w->q->select('name');
    ".'$'."w->q->select('isfolder');
    ".'$'."w->q->select('parent');
    ".'$'."w->q->from('test_uni');
    ".'$'."w->q->where('id>0');
    ".'$'."w->q->where('parent=:parent:');
    ".'$'."w->q->orderby('name');

    // Set permissions for tree
    ".'$'."w->editing = true;
    ".'$'."w->adding = true;
    ".'$'."w->deleting = true;

    // Add some contexmenu items
    ".'$'."w->addContextMenu('<b style=\"color:red\">'.".'$'."parser->gt('test', __FILE__).' '.".'$'."parser->gt('contextmenu', __FILE__).'</b>','testaction', ".'$'."parser->gt('menu_comment', __FILE__));
    // Handling menu action
    ".'$'."action =  (isset(".'$'."_POST[\"action\"])) ? ".'$'."_POST[\"action\"] : '';
    ".'$'."containerid =  (isset(".'$'."_POST[\"containerid\"])) ? ".'$'."_POST[\"containerid\"] : '';
    ".'$'."formid =  (isset(".'$'."_POST[\"formid\"])) ? ".'$'."_POST[\"formid\"] : ''; // id of row element for contextmenu
    if(".'$'."action && (".'$'."containerid == ".'$'."w->container))
    {
        switch(".'$'."action)
        {
            case 'testaction':
                        if(ob_get_length()) ob_clean();
                                print(".'$'."parser->gt('do_smth_cont', ".'$'."fn).".'$'."formid);
                        exit;
            break;
        }
    }

    // Print the tree
    ".'$'."w->show();

    </pre>");


    print("<h4>4. ".$parser->gt('treeonclick', __FILE__)."</h4>");

    // Create new instance of the wAjaxTree class
    include_once(SYS_BASE_PATH.'main/classes/wajaxtree.class.php');
    $w = new wAjaxTree();
    $w->container = 'tree_clicks';
    // Set sql
    $w->q->select('objid');
    $w->q->select('name', '', array('lang' => true));
    $w->q->select('isfolder');
    $w->q->select('parent');
    $w->q->from('sys_objects');
    $w->q->where("objid<>'0'");
    $w->q->where("objtype='sys_elements_pages'");
    $w->q->where("parent=:parent:");
    $w->q->orderby('name', true);
    // Set onclick functions separately for folder and leaf
    $w->folder_func = 'folderclick';
    $w->leaf_func = 'leafclick';
    $src = "<script type=\"text/javascript\">
    function folderclick(id, notes)
    {
     alert('It is a folder ' + id);
    }
    function leafclick(id, notes)
    {
     alert('It is a leaf ' + id);
    }
    </script>";
    $parser->addScript($src);
    // Print the tree
    $w->show();
    print("<pre class=\"brush:php\">
    // Create new instance of the wAjaxTree class
    include_once(SYS_BASE_PATH.'main/classes/wajaxtree.class.php');
    ".'$'."w = new wAjaxTree();
    ".'$'."w->container = 'tree_clicks';
    // Set sql
    ".'$'."w->q->select('objid');
    ".'$'."w->q->select('name', '', array('lang' => true));
    ".'$'."w->q->select('isfolder');
    ".'$'."w->q->select('parent');
    ".'$'."w->q->from('sys_objects');
    ".'$'."w->q->where(\"objid<>'0'\");
    ".'$'."w->q->where(\"objtype='sys_elements_pages'\");
    ".'$'."w->q->where(\"parent=:parent:\");
    ".'$'."w->q->orderby('name', true);
    // Set onclick functions separately for folder and leaf
    ".'$'."w->folder_func = 'folderclick';
    ".'$'."w->leaf_func = 'leafclick';
    ".'$'."src = \"<script type='text/javascript'>
    function folderclick(id, notes)
    {
     alert('It is a folder ' + id);
    }
    function leafclick(id, notes)
    {
     alert('It is a leaf ' + id);
    }
    </script>\";
    ".'$'."parser->addScript(".'$'."src);
    // Print the tree
    ".'$'."w->show();

    </pre>");

    print("<h4>5. ".$parser->gt('difflevels', __FILE__)." (".$parser->gt('caption_cities', __FILE__).")</h4>");
    // Create new instance of the wAjaxTree class
    include_once(SYS_BASE_PATH.'main/classes/wajaxtree.class.php');
    $w = new wAjaxTree();
    $w->container = 'cntr_city';
    // Set datasource for level
    $treetype =  (isset($_POST["treetype"])) ? $_POST["treetype"] : 0;
    switch($treetype)
    {
        case 0:
            $dat = array('Asia', 'Europe', 'North America', 'Africa', 'Oceania', 'Antarctica', 'South America');
            for($i = 0; $i < sizeof($dat); $i++) $w->addData($dat[$i],$dat[$i],1,0,'',1);
        break;
        case 1:
            $w->q->select('id');
            $w->q->select('name');
            $w->q->select('1 AS isfolder');
            $w->q->select('1 AS parent');
            $w->q->select("'' AS notes");
            $w->q->select('2 AS treetype');
            $w->q->from('test_countries');
            $w->q->where("continent=:parent:");
            $w->q->orderby('name');
        break;
        case 2:
            $w->q->select('id');
            $w->q->select('name');
            $w->q->select('0 AS isfolder');
            $w->q->select('1 AS parent');
            $w->q->select("'' AS notes");
            $w->q->select('3 AS treetype');
            $w->q->from('test_cities');
            $w->q->where("countrycode=:parent:");
            $w->q->orderby('name');
        break;
    }
    // Print the tree
    $w->show();

    print("<pre class=\"brush:php\">
    // Create new instance of the wAjaxTree class
    include_once(SYS_BASE_PATH.'main/classes/wajaxtree.class.php');
    ".'$'."w = new wAjaxTree();
    // Set datasource for level
    ".'$'."treetype =  (isset(".'$'."_POST[\"treetype\"])) ? ".'$'."_POST[\"treetype\"] : 0;
    switch(".'$'."treetype)
    {
        case 0:
            ".'$'."dat = array('Asia', 'Europe', 'North America', 'Africa', 'Oceania', 'Antarctica', 'South America');
            for(".'$'."i = 0; ".'$'."i < sizeof(".'$'."dat); ".'$'."i++) ".'$'."w->addData(".'$'."dat[".'$'."i],".'$'."dat[".'$'."i],1,0,'',1);
        break;
        case 1:
            ".'$'."w->q->select('id');
            ".'$'."w->q->select('name');
            ".'$'."w->q->select('1 AS isfolder');
            ".'$'."w->q->select('1 AS parent');
            ".'$'."w->q->select(\"'' AS notes\");
            ".'$'."w->q->select('2 AS treetype');
            ".'$'."w->q->from('test_countries');
            ".'$'."w->q->where(\"continent=:parent:\");
            ".'$'."w->q->orderby('name');
        break;
        case 2:
            ".'$'."w->q->select('id');
            ".'$'."w->q->select('name');
            ".'$'."w->q->select('0 AS isfolder');
            ".'$'."w->q->select('1 AS parent');
            ".'$'."w->q->select(\"'' AS notes\");
            ".'$'."w->q->select('3 AS treetype');
            ".'$'."w->q->from('test_cities');
            ".'$'."w->q->where(\"countrycode=:parent:\");
            ".'$'."w->q->orderby('name');
        break;
    }
    // Print the tree
    ".'$'."w->show();

    </pre>");

?>