<?php

    print("<h4>1. ".$parser->gt('simplegrid', __FILE__).". ".$parser->gt('datafromdb', __FILE__)."</h4>");
    // To use the proper language library
    $fn = __FILE__;
    // Create new instance of the wAjaxGrid class
    include_once(SYS_BASE_PATH.'main/classes/wajaxgrid.class.php');
    $w = new wAjaxGrid();
    $w->container = 'ajaxgrid_simplegriddb';
    $w->pagelen = 5;
    $w->caption = $parser->gt('country_list', $fn);

    // Set sql
    $w->q->select('c.id', $parser->gt('id', $fn));
    $w->q->select('c.name', $parser->gt('name', $fn));
    $w->q->select('c.continent', $parser->gt('continent', $fn));
    $w->q->select('c.region',  $parser->gt('region', $fn));
    $w->q->select('c.surfacearea',  $parser->gt('surface', $fn));
    $w->q->select('c.population',  $parser->gt('population', $fn));
    $w->q->select('cc.name as cName',  $parser->gt('capital', $fn));
    $w->q->from('test_countries c');
    $w->q->from('test_cities cc');
    $w->q->where("c.capital=cc.id");
    $w->q->orderby('c.id');

    // Print the grid
    $w->show();

    print("<pre class=\"brush:php\">
    // To use the proper language library
    ".'$'."fn = __FILE__;
    // Create new instance of the wAjaxGrid class
    include_once(SYS_BASE_PATH.'main/classes/wajaxgrid.class.php');
    ".'$'."w = new wAjaxGrid();
    ".'$'."w->container = 'ajaxgrid_simplegriddb';
    ".'$'."w->pagelen = 5;
    ".'$'."w->caption = ".'$'."parser->gt('country_list', ".'$'."fn);

    // Set sql
    ".'$'."w->q->select('c.id', ".'$'."parser->gt('id', ".'$'."fn));
    ".'$'."w->q->select('c.name', ".'$'."parser->gt('name', ".'$'."fn));
    ".'$'."w->q->select('c.continent', ".'$'."parser->gt('continent', ".'$'."fn));
    ".'$'."w->q->select('c.region',  ".'$'."parser->gt('region', ".'$'."fn));
    ".'$'."w->q->select('c.surfacearea',  ".'$'."parser->gt('surface', ".'$'."fn));
    ".'$'."w->q->select('c.population',  ".'$'."parser->gt('population', ".'$'."fn));
    ".'$'."w->q->select('cc.name as cName',  ".'$'."parser->gt('capital', ".'$'."fn));
    ".'$'."w->q->from('test_countries c');
    ".'$'."w->q->from('test_cities cc');
    ".'$'."w->q->where(\"c.capital=cc.id\");
    ".'$'."w->q->orderby('c.id');

    // Print the grid
    ".'$'."w->show();
    </pre>");

    print("<h4>2. ".$parser->gt('simplegrid', __FILE__).". ".$parser->gt('datafromarray', __FILE__)."</h4>");

    // To use the proper language library
    $fn = __FILE__;

    // Create new instance of the wAjaxGrid class
    include_once(SYS_BASE_PATH.'main/classes/wajaxgrid.class.php');
    $w = new wAjaxGrid();
    $w->container = 'grid_arrsimple';
    $w->caption = $parser->gt('country_list', $fn);
    $w->pagelen = 5;

    // Set column names
    $w->colnames =  $parser->gt('id', $fn).','.$parser->gt('name', $fn).','.$parser->gt('continent', $fn).','.$parser->gt('region', $fn).','.$parser->gt('capital', $fn);

    // Set data array
    $w->addData(array(1, 'Aruba', 'North America', 'Caribbean', 'Abu Dhabi'));
    $w->addData(array(2, 'Afghanistan', 'Asia', 'Southern and Central Asia', 'Kabul'));
    $w->addData(array(3, 'Angola', 'Africa', 'Central Africa', 'Luanda'));
    $w->addData(array(4, 'Anguilla', 'North America', 'Caribbean', 'The Valley'));
    $w->addData(array(5, 'Albania', 'Europe', 'Southern Europe', 'Tirana'));
    $w->addData(array(6, 'Andorra', 'Europe', 'Southern Europe', 'Andorra la Vella'));
    $w->addData(array(7, 'Netherlands Antilles', 'North America', 'Caribbean', 'Willemstad'));
    $w->addData(array(8, 'United Arab Emirates', 'Asia', 'Middle East', 'Abu Dhabi'));
    $w->addData(array(9, 'Argentina', 'South America', 'South America', 'Buenos Aires'));
    $w->addData(array(10, 'Armenia', 'Asia', 'Middle East', 'Yerevan'));
    $w->addData(array(11, 'American Samoa', 'Oceania', 'Polynesia', 'Fagatogo'));
    $w->addData(array(12, 'Antigua and Barbuda', 'North America', 'Caribbean', 'Saint John´s'));
    $w->addData(array(13, 'Australia', 'Oceania', 'Australia and New Zealand', 'Canberra'));
    $w->addData(array(14, 'Austria', 'Europe', 'Western Europe', 'Wien'));
    $w->addData(array(15, 'Azerbaijan', 'Asia', 'Middle East', 'Baku'));
    $w->addData(array(16, 'Burundi', 'Africa', 'Eastern Africa', 'Bujumbura'));
    $w->addData(array(17, 'Belgium', 'Europe', 'Western Europe', 'Bruxelles'));
    $w->addData(array(18, 'Benin', 'Africa', 'Western Africa', 'Porto-Novo'));
    $w->addData(array(19, 'Burkina Faso', 'Africa', 'Western Africa', 'Ouagadougou'));
    $w->addData(array(20, 'Bangladesh', 'Asia', 'Southern and Central Asia', 'Dhaka'));
    $w->addData(array(21, 'Bulgaria', 'Europe', 'Eastern Europe', 'Sofija'));
    $w->addData(array(22, 'Bahrain', 'Asia', 'Middle East', 'al-Manama'));
    $w->addData(array(23, 'Bahamas', 'North America', 'Caribbean', 'Nassau'));

    // Print the grid
    $w->Show();

    print("<pre class=\"brush:php\">
    // To use the proper language library
    ".'$'."fn = __FILE__;

    // Create new instance of the wAjaxGrid class
    include_once(SYS_BASE_PATH.'main/classes/wajaxgrid.class.php');
    ".'$'."w = new wAjaxGrid();
    ".'$'."w->container = 'grid_arrsimple';
    ".'$'."w->pagelen = 5;

    // Set column names
    ".'$'."w->colnames =  ".'$'."parser->gt('id', ".'$'."fn).','.".'$'."parser->gt('name', ".'$'."fn).','.".'$'."parser->gt('continent', ".'$'."fn).','.".'$'."parser->gt('region', ".'$'."fn).','.".'$'."parser->gt('capital', ".'$'."fn);

    // Set data array
    ".'$'."w->addData(array(1, 'Aruba', 'North America', 'Caribbean', 'Abu Dhabi'));
    ".'$'."w->addData(array(2, 'Afghanistan', 'Asia', 'Southern and Central Asia', 'Kabul'));
    ".'$'."w->addData(array(3, 'Angola', 'Africa', 'Central Africa', 'Luanda'));
    ".'$'."w->addData(array(4, 'Anguilla', 'North America', 'Caribbean', 'The Valley'));
    ".'$'."w->addData(array(5, 'Albania', 'Europe', 'Southern Europe', 'Tirana'));
    ".'$'."w->addData(array(6, 'Andorra', 'Europe', 'Southern Europe', 'Andorra la Vella'));
    ".'$'."w->addData(array(7, 'Netherlands Antilles', 'North America', 'Caribbean', 'Willemstad'));
    ".'$'."w->addData(array(8, 'United Arab Emirates', 'Asia', 'Middle East', 'Abu Dhabi'));
    ".'$'."w->addData(array(9, 'Argentina', 'South America', 'South America', 'Buenos Aires'));
    ".'$'."w->addData(array(10, 'Armenia', 'Asia', 'Middle East', 'Yerevan'));
    ".'$'."w->addData(array(11, 'American Samoa', 'Oceania', 'Polynesia', 'Fagatogo'));
    ".'$'."w->addData(array(12, 'Antigua and Barbuda', 'North America', 'Caribbean', 'Saint John´s'));
    ".'$'."w->addData(array(13, 'Australia', 'Oceania', 'Australia and New Zealand', 'Canberra'));
    ".'$'."w->addData(array(14, 'Austria', 'Europe', 'Western Europe', 'Wien'));
    ".'$'."w->addData(array(15, 'Azerbaijan', 'Asia', 'Middle East', 'Baku'));
    ".'$'."w->addData(array(16, 'Burundi', 'Africa', 'Eastern Africa', 'Bujumbura'));
    ".'$'."w->addData(array(17, 'Belgium', 'Europe', 'Western Europe', 'Bruxelles'));
    ".'$'."w->addData(array(18, 'Benin', 'Africa', 'Western Africa', 'Porto-Novo'));
    ".'$'."w->addData(array(19, 'Burkina Faso', 'Africa', 'Western Africa', 'Ouagadougou'));
    ".'$'."w->addData(array(20, 'Bangladesh', 'Asia', 'Southern and Central Asia', 'Dhaka'));
    ".'$'."w->addData(array(21, 'Bulgaria', 'Europe', 'Eastern Europe', 'Sofija'));
    ".'$'."w->addData(array(22, 'Bahrain', 'Asia', 'Middle East', 'al-Manama'));
    ".'$'."w->addData(array(23, 'Bahamas', 'North America', 'Caribbean', 'Nassau'));

    // Print the grid
    ".'$'."w->Show();

    </pre>");


    print("<h4>3. ".$parser->gt('gridtotals', __FILE__)."</h4>");
    // To use the proper language library
    $fn = __FILE__;

    // Create new instance of the wAjaxGrid class
    include_once(SYS_BASE_PATH.'main/classes/wajaxgrid.class.php');
    $w = new wAjaxGrid('test_uni');
    $w->container = 'ajaxgrid_totals';
    $w->pagelen = 5;
    $w->caption = $parser->gt('caption_test', $fn);

    // Editable field attribute
    $par = array('edit' => true);

    // Get a dataset
    $w->q->select('id', $parser->gt('id', $fn));
    $w->q->select('name', $parser->gt('name', $fn), $par);
    $w->q->select('floatfield', $parser->gt('float', $fn), $par);
    $w->q->select('intfield', $parser->gt('int', $fn), $par);
    $w->q->select('boolfield', $parser->gt('bool', $fn), $par);
    $w->q->select('datefield', $parser->gt('date', $fn));
    $w->rowclass_col = $w->q->select('color', $parser->gt('color'), array('hide' => 1));
    $w->q->from('test_uni');
    $w->q->where("id>0");
    $w->q->orderby('name');

    // One of the posibilities to calculate totals
    $totals = array();
    $totals[] = '';
    $totals[] = $parser->gt('total');
    $totals[] = $parser->utils->getFieldFromSql("SELECT SUM(floatfield) FROM test_uni WHERE id>0", 0);
    $totals[] = $parser->utils->getFieldFromSql("SELECT SUM(intfield) FROM test_uni WHERE id>0", 0);
    $totals[] = '';
    $totals[] = '';
    $w->addRow($totals, 'listtotal');

    // Search fields
    $w->addSearchField('strfield', $parser->gt('string', $fn));
    $w->addSearchField('floatfield', $parser->gt('float', $fn), 'F');
    $w->addSearchField('intfield', $parser->gt('int', $fn), 'I');
    $w->addSearchField('boolfield', $parser->gt('bool', $fn), 'B');
    $w->addSearchField('datefield', $parser->gt('date', $fn),'D');

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

    // Point to summary function
    $w->summary_handler = 'test2_func';

    // Add menu and contexmenu items
    $w->addMainMenu0('<b style="color:red">'.$parser->gt('test', $fn).' '.$parser->gt('menu', $fn).'</b>', 'testmainaction', $parser->gt('menu_comment', $fn));
    $w->addContextMenu('<b style="color:red">'.$parser->gt('test', $fn).' '.$parser->gt('contextmenu', $fn).'</b>','testaction', $parser->gt('menu_comment', $fn));

    // 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 'testmainaction':
                        if(ob_get_length()) ob_clean();
                                print($parser->gt('do_smth_main', $fn));
                        exit;
            break;
            case 'testaction':
                        if(ob_get_length()) ob_clean();
                                print($parser->gt('do_smth_cont', $fn).$formid);
                        exit;
            break;
        }
    }

    // Print the grid
    $w->show();

    // Print page summaries
    function test2_func($obj)
    {
        global $parser;
        $a = $parser->utils->getFieldsFromSql("SELECT SUM(floatfield) AS sum1, SUM(intfield) AS sum2
                               FROM test_uni WHERE id > 0", array(0,0));
        return        '<h3 style="text-align:right; color:red">'.$parser->gt('total').', '.$parser->gt('float').': '.$parser->utils->nf($a['sum1']).'</h3>'.
                '<h3 style="text-align:right; color:blue">'.$parser->gt('total').', '.$parser->gt('int').': '.$parser->utils->nf($a['sum2'], 0).'</h3>';
    }

    print("<pre class=\"brush:php\">
    // To use the proper language library
    ".'$'."fn = __FILE__;

    // Create new instance of the wAjaxGrid class
    include_once(SYS_BASE_PATH.'main/classes/wajaxgrid.class.php');
    ".'$'."w = new wAjaxGrid('test_uni');
    ".'$'."w->container = 'ajaxgrid_totals';
    ".'$'."w->pagelen = 5;
    ".'$'."w->caption = ".'$'."parser->gt('caption_test', ".'$'."fn);

    // Editable field attribute
    ".'$'."par = array('edit' => true);

    // Get a dataset
    ".'$'."w->q->select('id', ".'$'."parser->gt('id', ".'$'."fn));
    ".'$'."w->q->select('name', ".'$'."parser->gt('name', ".'$'."fn), ".'$'."par);
    ".'$'."w->q->select('floatfield', ".'$'."parser->gt('float', ".'$'."fn), ".'$'."par);
    ".'$'."w->q->select('intfield', ".'$'."parser->gt('int', ".'$'."fn), ".'$'."par);
    ".'$'."w->q->select('boolfield', ".'$'."parser->gt('bool', ".'$'."fn), ".'$'."par);
    ".'$'."w->q->select('datefield', ".'$'."parser->gt('date', ".'$'."fn));
    ".'$'."w->rowclass_col = ".'$'."w->q->select('color', ".'$'."parser->gt('color'), array('hide' => 1));
    ".'$'."w->q->from('test_uni');
    ".'$'."w->q->where(\"id>0\");
    ".'$'."w->q->orderby('name');

    // One of the posibilities to calculate totals
    ".'$'."totals = array();
    ".'$'."totals[] = '';
    ".'$'."totals[] = ".'$'."parser->gt('total');
    ".'$'."totals[] = ".'$'."parser->utils->getFieldFromSql(\"SELECT SUM(floatfield) FROM test_uni WHERE id>0\", 0);
    ".'$'."totals[] = ".'$'."parser->utils->getFieldFromSql(\"SELECT SUM(intfield) FROM test_uni WHERE id>0\", 0);
    ".'$'."totals[] = '';
    ".'$'."totals[] = '';
    ".'$'."w->addRow(".'$'."totals, 'listtotal');

    // Search fields
    ".'$'."w->addSearchField('strfield', ".'$'."parser->gt('string', ".'$'."fn));
    ".'$'."w->addSearchField('floatfield', ".'$'."parser->gt('float', ".'$'."fn), 'F');
    ".'$'."w->addSearchField('intfield', ".'$'."parser->gt('int', ".'$'."fn), 'I');
    ".'$'."w->addSearchField('boolfield', ".'$'."parser->gt('bool', ".'$'."fn), 'B');
    ".'$'."w->addSearchField('datefield', ".'$'."parser->gt('date', ".'$'."fn),'D');

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

    // Point to summary function
    ".'$'."w->summary_handler = 'test2_func';

    // Add menu and contexmenu items
    ".'$'."w->addMainMenu0('<b style=\"color:red\">'.".'$'."parser->gt('test', ".'$'."fn).' '.".'$'."parser->gt('menu', ".'$'."fn).'</b>', 'testmainaction', ".'$'."parser->gt('menu_comment', ".'$'."fn));
    ".'$'."w->addContextMenu('<b style=\"color:red\">'.".'$'."parser->gt('test', ".'$'."fn).' '.".'$'."parser->gt('contextmenu', ".'$'."fn).'</b>','testaction', ".'$'."parser->gt('menu_comment', ".'$'."fn));

    // 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 'testmainaction':
                        if(ob_get_length()) ob_clean();
                                print(".'$'."parser->gt('do_smth_main', ".'$'."fn));
                        exit;
            break;
            case 'testaction':
                        if(ob_get_length()) ob_clean();
                                print(".'$'."parser->gt('do_smth_cont', ".'$'."fn).".'$'."formid);
                        exit;
            break;
        }
    }

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

    // Print page summaries
    function test2_func(".'$'."obj)
    {
        global ".'$'."parser;
        ".'$'."a = ".'$'."parser->utils->getFieldsFromSql(\"SELECT SUM(floatfield) AS sum1, SUM(intfield) AS sum2
                               FROM test_uni WHERE id > 0\", array(0,0));
        return        '<h3 style=\"text-align:right; color:red\">'.".'$'."parser->gt('total').', '.".'$'."parser->gt('float').': '.".'$'."parser->utils->nf(".'$'."a['sum1']).'</h3>'.
                '<h3 style=\"text-align:right; color:blue\">'.".'$'."parser->gt('total').', '.".'$'."parser->gt('int').': '.".'$'."parser->utils->nf(".'$'."a['sum2'], 0).'</h3>';
    }

    </pre>");

    print("<h4>4. ".$parser->gt('groupgrid', __FILE__)."</h4>");
    // To use the proper language library
    $fn = __FILE__;
    // Create new instance of the wAjaxGrid class
    include_once(SYS_BASE_PATH.'main/classes/wajaxgrid.class.php');
    $w = new wAjaxGrid();
    $w->container = 'ajaxgrid_groupgrid';
    $w->pagelen = 5;
    $w->caption = $parser->gt('country_list', $fn);

    // Set sql
    $w->q->select('c.id', $parser->gt('id', $fn));
    $w->q->select('c.name', $parser->gt('name', $fn));
    $w->group_col = $w->q->select('c.continent', $parser->gt('continent', $fn), array('hide' => 1));
    $w->q->select('c.region',  $parser->gt('region', $fn));
    $w->q->select('c.surfacearea',  $parser->gt('surface', $fn));
    $w->q->select('c.population',  $parser->gt('population', $fn));
    $w->q->select('cc.name as cName',  $parser->gt('capital', $fn));
    $w->q->from('test_countries c');
    $w->q->from('test_cities cc');
    $w->q->where("c.capital=cc.id");
    $w->q->orderby('c.continent');
    $w->q->orderby('c.id');

    // Set search fields
    $w->addSearchField('c.id', $parser->gt('id', $fn));
    $w->addSearchField('c.name', $parser->gt('name', $fn));
    $w->addSearchField('c.continent', $parser->gt('continent', $fn));
    $w->addSearchField('c.region',  $parser->gt('region', $fn));
    $w->addSearchField('c.surfacearea',  $parser->gt('surface', $fn), 'F');
    $w->addSearchField('c.population',  $parser->gt('population', $fn), 'I');
    $w->addSearchField('cc.id',  $parser->gt('capital', $fn), 'test_cities');

    // Print the grid
    $w->show();

    print("<pre class=\"brush:php\">
    // To use the proper language library
    ".'$'."fn = __FILE__;
    // Create new instance of the wAjaxGrid class
    include_once(SYS_BASE_PATH.'main/classes/wajaxgrid.class.php');
    ".'$'."w = new wAjaxGrid();
    ".'$'."w->container = 'ajaxgrid_groupgrid';
    ".'$'."w->pagelen = 5;
    ".'$'."w->caption = ".'$'."parser->gt('country_list', ".'$'."fn);

    // Set sql
    ".'$'."w->q->select('c.id', ".'$'."parser->gt('id', ".'$'."fn));
    ".'$'."w->q->select('c.name', ".'$'."parser->gt('name', ".'$'."fn));
    ".'$'."w->group_col = ".'$'."w->q->select('c.continent', ".'$'."parser->gt('continent', ".'$'."fn), array('hide' => 1));
    ".'$'."w->q->select('c.region',  ".'$'."parser->gt('region', ".'$'."fn));
    ".'$'."w->q->select('c.surfacearea',  ".'$'."parser->gt('surface', ".'$'."fn));
    ".'$'."w->q->select('c.population',  ".'$'."parser->gt('population', ".'$'."fn));
    ".'$'."w->q->select('cc.name as cName',  ".'$'."parser->gt('capital', ".'$'."fn));
    ".'$'."w->q->from('test_countries c');
    ".'$'."w->q->from('test_cities cc');
    ".'$'."w->q->where(\"c.capital=cc.id\");
    ".'$'."w->q->orderby('c.continent');
    ".'$'."w->q->orderby('c.id');

    // Set search fields
    ".'$'."w->addSearchField('c.id', ".'$'."parser->gt('id', ".'$'."fn));
    ".'$'."w->addSearchField('c.name', ".'$'."parser->gt('name', ".'$'."fn));
    ".'$'."w->addSearchField('c.continent', ".'$'."parser->gt('continent', ".'$'."fn));
    ".'$'."w->addSearchField('c.region',  ".'$'."parser->gt('region', ".'$'."fn));
    ".'$'."w->addSearchField('c.surfacearea',  ".'$'."parser->gt('surface', ".'$'."fn), 'F');
    ".'$'."w->addSearchField('c.population',  ".'$'."parser->gt('population', ".'$'."fn), 'I');
    ".'$'."w->addSearchField('cc.id',  ".'$'."parser->gt('capital', ".'$'."fn), 'test_cities');

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

    </pre>");

?>