<?php
/**
 * PHP Grid Component
 *
 * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
 * @version 1.4.6
 * @license: see license.txt included in package
 */
 
$name =get_user();

if ($name=='') header('Location:index.php'); 
  
$version = "Penztar - mattorgroup.com 2015 V2.2 ( project autocomplete  )  - ".$name." / ".get_uip()." @ ".$beginsession;
//$version = "Penztar - mattorgroup.com 2015 V2.1 ( pw  )  - ".$name." / ".get_uip()." @ ".$beginsession;
//$version = "Penztar - mattorgroup.com 2013-2014 V2.0 (Dropdown)";
//$version = "Penztar - mattorgroup.com 2013-2014 V1.2 (Subtotals)";


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
//	Functions
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


  function get_user(){
	session_start();
	$name = $_SESSION['user'] ;
        return $name;
    }

  function get_uip(){
        $client  = $_SERVER['HTTP_CLIENT_IP'];
        $forward = $_SERVER['HTTP_X_FORWARDED_FOR'];
        $remote  = $_SERVER['REMOTE_ADDR'];

        if(filter_var($client, FILTER_VALIDATE_IP)){
            $ip = $client;
        }elseif(filter_var($forward, FILTER_VALIDATE_IP)){
            $ip = $forward;
        }else{
            $ip = $remote;
        }
        return $ip;
    }


// set up DB
$conn = mysql_connect("127.0.0.1", "finance", "1Finance");
mysql_select_db("finance");

// set your db encoding -- for ascent chars (if required)
//mysql_query("SET NAMES 'utf8'");

// include and create object 
$base_path = strstr(realpath("."),"demos",true)."lib/"; 
include($base_path."inc/jqgrid_dist.php");


// set few params
//$grid["caption"] = "Mattor Penztar";



//$grid["multiselect"] = true;
//$g->set_options($grid);

$g = new jqgrid();
// set database table for CRUD operations
$g->table = "penztar_mattor";
//$g->select_command = "SELECT * FROM penztar_mattor WHERE 1";


$col = array();
$col["title"] = "ID"; // caption of column
$col["name"] = "ID"; 
$col["width"] = "4";
# $col["hidden"] = true; // hide column by default
$col["align"] = "center"; // this column is not editable
$col["search"] = false; // this column is not searchable
$col["editable"] = false; // this column is not editable
$cols[] = $col;		

// normal textbox, with autocomplete enabled
$col = array();
$col["title"] = "Szallito";
$col["name"] = "Ceg";
$col["dbname"] = "penztar_mattor.Ceg"; // this is required as we need to search in name field, not id
$col["width"] = "8";
$col["align"] = "center";
$col["search"] = true;
$col["editable"] = true;
$col["formatter"] = "autocomplete"; // autocomplete
$col["formatoptions"] = array(    
                                "sql"=>"SELECT * FROM (SELECT Ceg as v FROM penztar_mattor GROUP BY Ceg) o",
                                "search_on"=>"v", 
                                "update_field" => "Ceg");
$cols[] = $col;

$col = array();
$col["title"] = "Sorszama";
$col["name"] = "Sorszam";
$col["width"] = "8";
$col["align"] = "center";
$col["search"] = true;
$col["editable"] = true;
$cols[] = $col;


$col = array();
$col["title"] = "Utal";
$col["name"] = "Utalas";
$col["width"] = "3";
$col["align"] = "left"; // this column is not editable
$col["editable"] = true; // this column is not editable
//$col["editrules"] = array("required"=>true); // and is required
$col["edittype"] = "checkbox"; 
$col["formatter"] = "checkbox";
$col["editoptions"] = array("value"=>"Yes:No"); 
$cols[] = $col;

$col = array();
$col["title"] = "Nev";
$col["name"] = "Nev"; 
$col["editable"] = true;
$col["width"] = "10";
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $g->get_dropdown_values("select distinct Name as k, Name as v from users where Exp = '0' order by Name ASC");
$col["editoptions"] = array(
							"value"=>$str,
							"onchange" => array(	
									"sql"=>"select * from users",
									"search_on"=>"Name",
									"callback" => "fill_form" )
							);
$col["formatter"] = "select"; // display label, not value
$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
$cols[] = $col;	





$col = array();
$col["title"] = "Datum_KI";
$col["name"] = "Datum_ki";
$col["width"] = "10";
$col["editable"] = true; // this column is not editable
$col["align"] = "center"; // this column is not editable
$col["formatter"] = "date"; // format as date
$col["editoptions"] = array("size"=>10); // with default display of textbox with size 20
$col["editrules"] = array("required"=>true); // and is required

# $col["formatter"] = "image"; // format as image -- if data is image url e.g. http://<domain>/test.jpg
# $col["formatoptions"] = array("width"=>'20',"height"=>'30'); // image width / height etc

$cols[] = $col;

$col = array();
$col["title"] = "Osszeg_KI";
$col["name"] = "Osszeg_KI";
$col["width"] = "10"; // not specifying width will expand to fill space
$col["search"] = false; // this column is not searchable
$col["editable"] = true;
$col["formatter"] = "currency"; // format as currency
$col["align"] = "right"; // this column is not editable
$col["editrules"] = array("required"=>true); // and is required

//$col["editoptions"] = array("rows"=>2, "cols"=>20); // with these attributes
$cols[] = $col;

$col = array();
$col["title"] = "Koltott";
$col["name"] = "Koltott";
$col["width"] = "10"; // not specifying width will expand to fill space
$col["search"] = false; // this column is not searchable
$col["editable"] = true;
$col["formatter"] = "currency"; // format as currency
$col["align"] = "right"; // this column is not editable
$col["editrules"] = array("required"=>true); // and is required

//$col["editoptions"] = array("rows"=>2, "cols"=>20); // with these attributes
$cols[] = $col;

$col = array();
$col["title"] = "Osszeg_BE";
$col["name"] = "Osszeg_BE";
$col["width"] = "10"; // not specifying width will expand to fill space
$col["search"] = false; // this column is not searchable
$col["editable"] = true;
$col["formatter"] = "currency"; // format as currency
$col["align"] = "right"; // this column is not editable
$col["editrules"] = array("required"=>true); // and is required
$cols[] = $col;

$col = array();
$col["title"] = "ARU_NEVE";
$col["name"] = "ARU_NEVE";
$col["width"] = "20";
$col["editable"] = true; // this column is not editable
$col["editrules"] = array("required"=>true); // and is required
$cols[] = $col;


$col = array();
$col["title"] = "Projekt";
$col["name"] = "PROJEKT";
$col["dbname"] = "penztar_mattor.PROJEKT"; // this is required as we need to search in name field, not id
$col["width"] = "15";
$col["align"] = "center";
$col["search"] = true;
$col["editable"] = true;
$col["formatter"] = "autocomplete"; // autocomplete
$col["formatoptions"] = array(    
                                "sql"=>"SELECT * FROM (SELECT Id as k, NAME as v FROM projekt where INVOICED <> '1' order by NAME ASC) o",
                                "search_on"=>"v", 
                                "update_field" => "PROJEKT");
$cols[] = $col;





$col = array();
$col["title"] = "KASSZA_MOST";
$col["name"] = "KASSZA_MOST";
$col["width"] = "15"; // not specifying width will expand to fill space
$col["search"] = false; // this column is not searchable
$col["editable"] = true;
$col["formatter"] = "currency"; // format as currency
$col["align"] = "right"; // this column is not editable

$cols[] = $col;


$g->set_actions(array(     
                        "add"=>true, // allow/disallow add 
                        "edit"=>true, // allow/disallow edit 
                        "delete"=>false, // allow/disallow delete 
                        "rowactions"=>true, // show/hide row wise edit/del/save option 
                        "autofilter" => true, // show/hide autofilter for search 
//			"bulkedit"=>true,
			"export_excel"=>false, // export excel button 
                        "export_pdf"=>false, // export pdf button 

                        "search" => "advance" // show single/multi field search condition (e.g. simple or advance) 
                    )  
                ); 

$e["js_on_load_complete"] = "do_onload";
$g->set_events($e);

// set few params
$grid["caption"] = $version;

$grid["autowidth"] = true; 
$grid["sortorder"] = 'desc';

$grid["altRows"] = true;  
$grid["altclass"] = "myAltRowClass";  
$grid["rowList"] = array(10,20,50,100,All); 

$grid["footerrow"] = true; // footer row to summarize working hours

$g->set_options($grid);

// $e["js_on_load_complete"] = "do_onload";
// $g->set_events($e);

 $g->set_columns($cols);

			
// render grid
$out = $g->render("list1");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>

<head>
	<link rel="stylesheet" type="text/css" media="screen" href="lib/js/themes/redmond/jquery-ui.custom.css"></link>	
	<link rel="stylesheet" type="text/css" media="screen" href="lib/js/jqgrid/css/ui.jqgrid.css"></link>	
	
	<script src="lib/js/jquery.min.js" type="text/javascript"></script>
	<script src="lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
	<script src="lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>	
	<script src="lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
</head>

<script>


	function do_onload() {
	        var grid = $("#list1"),

	        sum = grid.jqGrid('getCol', 'Koltott', false, 'sum');

	        grid.jqGrid('footerData','set',{Id: 'Subtotal: ',Koltott: sum});

	    }




</script>

<div style="margin:10px;">



<?php echo $out?>


</div>

</body> 

</html>