<?php session_start();
			if (isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes') {
			include ('../../../scripts/classes.php'); 
			if ($_SESSION['lang']=="EN"){$lang="EN"; include ('../../../lang/en.php');}elseif ($_SESSION['lang']=="GR"){$lang="GR"; include ('../../../lang/gr.php');}else {$lang="EN";include ('../../../lang/en.php');}	

			$array = getGlobalSettings(); //Retrieve Global Settings	
			$mods = getCLSModules('CELEBRATIONS'); foreach ($mods as $modules){extract($modules);} if ($mod_name == true) $_CELEBRATIONS=1; //echo $_CELEBRATIONS;	
			if ( $_CELEBRATIONS!=1 ) exit;
			
			$page_title = $lbl_page_setup_namedays; //Assign Page Title
			$mode = $lbl_page_setup_namedays; //Assign Mode
?>	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title ?></title>
<link rel="shortcut icon" href="../../../img/favicon.png" />
<link href="../../../cms1.css" rel="stylesheet" type="text/css" /> 
</head>
<body>
<script>top.document.title=self.document.title;</script>
	<div>
		<fieldset>
		<legend><?php echo $mode ?></legend>
			<div class="align-left">
			<?php
    ################################################################################
    ## +---------------------------------------------------------------------------+
    ## | 1. Creating & Calling:                                                    | 
    ## +---------------------------------------------------------------------------+

      define ("DATAGRID_DIR", "../../../datagrid/");                     /* Ex.: "datagrid/" */ 
      define ("PEAR_DIR", "../../../datagrid/pear/");                    /* Ex.: "datagrid/pear/" */
    
      require_once(DATAGRID_DIR.'datagrid.class.php');
      require_once(PEAR_DIR.'PEAR.php');
      require_once(PEAR_DIR.'DB.php');
    
    ##  *** creating variables that we need for database connection 

      // includes database connection parameters
      include_once('../../../datagrid/config.inc.php');
    
      ob_start();
      $db_conn = DB::factory('mysql');  /* don't forget to change on appropriate db type */
      $result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
      if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }  
    ##  *** put a primary key on the first place 
      $sql = "SELECT
				id,
				name,
				month,
				day,
				is_transfer,
				is_dual
            FROM namedays";

    ##  *** set needed options and create a new class instance 
      $debug_mode = false;        /* display SQL statements while processing */    
      $messaging = true;          /* display system messages on a screen */ 
      $unique_prefix = "anm_";    /* prevent overlays - must be started with a letter */
      $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
	  //webnail get current mode
	  $mode = isset($_GET[$unique_prefix.'mode']) ? $_GET[$unique_prefix.'mode'] : ""; 
	  
    ##  *** set encoding and collation (default: utf8/utf8_unicode_ci)
      $dg_encoding = "utf8";
      $dg_collation = "utf8_unicode_ci";
      $dgrid->SetEncoding($dg_encoding, $dg_collation);
    ##  *** set data source with needed options
      $default_order_field = "name";
      $default_order_type = "ASC";
      $dgrid->DataSource($db_conn, $sql, $default_order_field, $default_order_type);
      
    ## +---------------------------------------------------------------------------+
    ## | 2. General Settings:                                                      | 
    ## +---------------------------------------------------------------------------+
	##  *** allow multirow operations
        $multirow_option = false;
        $dgrid->AllowMultirowOperations($multirow_option);
        $multirow_operations = array(
            "edit"  => array("view"=>false),
            "delete"  => array("view"=>false),
            "details" => array("view"=>false), 
        );
        $dgrid->SetMultirowOperations($multirow_operations);
		//webnail
		if ($_SESSION['lang']=="EN"){
			$dg_language = "en";
		}elseif ($_SESSION['lang']=="GR"){	
			$dg_language = "gk";
		}else{	
			$dg_language = "en";
		}
		$dgrid->SetInterfaceLang($dg_language);  
         ##  *** set modes for operations ("type" => "link|button|image")
    ##  *** "view" - view mode | "edit" - add/edit/details modes
    ##  *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
    $modes = array(
         "add"	  =>array("view"=>true, "edit"=>false, "type"=>"button", "show_add_button"=>"outside"),
         "edit"	  =>array("view"=>true, "edit"=>true,  "type"=>"image" ),
         "cancel"  =>array("view"=>true, "edit"=>true,  "type"=>"button"),
         "details" =>array("view"=>true, "edit"=>true, "type"=>"image"),
         "delete"  =>array("view"=>true, "edit"=>false,  "type"=>"image"),

    );
    $dgrid->SetModes($modes);   
    ##  *** set CSS class for datagrid
    ##  *** "default|blue|gray|green|pink|empty|x-blue|x-gray|x-green" or your own css style
     $css_class = "default";
     $dgrid->SetCssClass($css_class);
    ##  *** set DataGrid caption
    $dg_caption = "";
      $dgrid->SetCaption($dg_caption);
    
    ## +---------------------------------------------------------------------------+
    ## | 3. Printing & Exporting Settings:                                         | 
    ## +---------------------------------------------------------------------------+
    ##  *** set printing option: true(default) or false 
      $printing_option = true;
      $dgrid->AllowPrinting($printing_option);
	  $exporting_option = true;
		$exporting_directory = "../../../exports/";               
		$export_all = true;
		$dgrid->AllowExporting($exporting_option, $exporting_directory, $export_all);
		$exporting_types = array("excel"=>"true", "pdf"=>"false", "xml"=>"false");
		$dgrid->AllowExportingTypes($exporting_types);
    
    ## +---------------------------------------------------------------------------+
    ## | 4. Sorting & Paging Settings:                                             | 
    ## +---------------------------------------------------------------------------+
    ##  *** set paging option: true(default) or false 
      $paging_option = true;
      $rows_numeration = false;
      $numeration_sign = "#";       
      $dgrid->AllowPaging($paging_option, $rows_numeration, $numeration_sign);
    ##  *** set paging settings
      $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
      $top_paging = array();
      $pages_array = array("20"=>"20", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
      $default_page_size = 20;
      $dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size);
    
    ## +---------------------------------------------------------------------------+
    ## | 5. Filter Settings:                                                       | 
    ## +---------------------------------------------------------------------------+
    ##  *** set filtering option: true or false(default)
      $filtering_option = true;
      $show_search_type = true;
      $dgrid->AllowFiltering($filtering_option, $show_search_type);
    ##  *** set additional filtering settings
       	$fill_from_array = array("0"=>$lbl_no, "1"=>$lbl_yes);  /* as "value"=>"option" */
     	$filtering_fields = array( 	
    	$lbl_grid_name => array("type"=>"textbox", "table"=>"namedays", "field"=>"name", "filter_condition"=>"", "show_operator"=>"false", "default_operator"=>"%like%", "case_sensitive"=>"false", "comparison_type"=>"string", "width"=>"", "on_js_event"=>""),		    
		$lbl_grid_is_dual => array("type"=>"dropdownlist", "table"=>"namedays", "field"=>"is_dual", "field_view"=>"is_dual", "show_count"=>true, "filter_condition"=>"",  "source"=>$fill_from_array, "condition"=>"", "show_operator"=>"false", "default_operator"=>"=", "case_sensitive"=>"false", "comparison_type"=>"numeric", "width"=>"", "multiple"=>"false", "on_js_event"=>""),
		$lbl_grid_is_transfer =>array("type"=>"dropdownlist", "table"=>"namedays", "field"=>"is_transfer", "field_view"=>"is_transfer", "show_count"=>true, "filter_condition"=>"",  "source"=>$fill_from_array, "condition"=>"", "show_operator"=>"false", "default_operator"=>"=", "case_sensitive"=>"false", "comparison_type"=>"numeric", "width"=>"", "multiple"=>"false", "on_js_event"=>""),	
	 );
      $dgrid->SetFieldsFiltering($filtering_fields);
    
    ## +---------------------------------------------------------------------------+
    ## | 6. View Mode Settings:                                                    | 
    ## +---------------------------------------------------------------------------+
    ##  *** set view mode table properties
      $vm_table_properties = array("width"=>"100%");
      $dgrid->SetViewModeTableProperties($vm_table_properties);  
    ##  *** set columns in view mode
    ##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
    ##  ***      "barchart" : number format in SELECT SQL must be equal with number format in max_value
      $vm_colimns = array(
        "id" => array("header"=>$lbl_grid_code, "type"=>"label", "align"=>"left", "width"=>"20px", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>"true", "tooltip_type"=>"floating", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"",  "field_data"=>"", "rel"=>"", "title"=>""),
        "name"     => array("header"=>$lbl_grid_name, "type"=>"label", "align"=>"left", "width"=>"", "wrap"=>"nowrap", "text_length"=>"100", "tooltip"=>"true", "tooltip_type"=>"floating", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
	   "day"     => array("header"=>$lbl_day, "type"=>"label",  "align"=>"center", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),		   				
	   "month"     => array("header"=>$lbl_month, "type"=>"label",  "align"=>"center", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
        "is_dual"     => array("header"=>$lbl_grid_is_dual, "type"=>"checkbox",  "align"=>"center", "sort_type"=>"numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "true_value"=>1, "false_value"=>0),	
    	"is_transfer"=>array("header"=>$lbl_grid_is_transfer, "type"=>"checkbox",  "align"=>"center",  "sort_type"=>"numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "true_value"=>1, "false_value"=>0),		
      );
      $dgrid->SetColumnsInViewMode($vm_colimns);
    
    
    ## +---------------------------------------------------------------------------+
    ## | 7. Add/Edit/Details Mode Settings:                                        | 
    ## +---------------------------------------------------------------------------+
    ##  *** set add/edit mode table properties
	$em_columns = array();
      $em_table_properties = array("width"=>"100%");
      $dgrid->SetEditModeTableProperties($em_table_properties);
    ##  *** set details mode table properties
      $dm_table_properties = array("width"=>"100%");
      $dgrid->SetDetailsModeTableProperties($dm_table_properties);
    ##  ***  set settings for add/edit/details modes
      $table_name  = "namedays";
      $primary_key = "id";
      $condition   = "";
      $dgrid->SetTableEdit($table_name, $primary_key, $condition);
   	if ($mode=="add"){	
	$fill_from_array = array("0"=>$lbl_no, "1"=>$lbl_yes);
	  $fill_from_month = array("1"=>"1","2"=>"2","3"=>"3","4"=>"4","5"=>"5","6"=>"6","7"=>"7","8"=>"8","9"=>"9","10"=>"10","11"=>"11","12"=>"12");
	  $fill_from_day = array("1"=>"1","2"=>"2","3"=>"3","4"=>"4","5"=>"5","6"=>"6","7"=>"7","8"=>"8","9"=>"9","10"=>"10","11"=>"11","12"=>"12","13"=>"13", "14"=>"14","15"=>"15","16"=>"16","17"=>"17","18"=>"18","19"=>"19","20"=>"20","21"=>"21","22"=>"22","23"=>"23","24"=>"24","25"=>"25","26"=>"26","27"=>"27","28"=>"28","29"=>"29","30"=>"30","31"=>"31");	  	
      $em_columns = array(			
            "name"=>array("header"=>$lbl_grid_name, "type"=>"textbox", "req_type"=>"ry", "width"=>"500px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"true", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
			"day"=>array("header"=>$lbl_day, "source"=>$fill_from_day, "req_type"=>"rn", "table"=>"namedays", "field"=>"day", "type"=>"enum",  "width"=>"30px", "title"=>"", "readonly"=>"false", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),
			"month"=>array("header"=>$lbl_month, "source"=>$fill_from_month, "req_type"=>"rn", "table"=>"namedays", "field"=>"month", "type"=>"enum",  "width"=>"30px", "title"=>"", "readonly"=>"false", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),		
			"is_dual"   =>array("header"=>$lbl_grid_is_dual, "source"=>$fill_from_array, "table"=>"namedays", "field"=>"is_dual", "type"=>"enum",  "width"=>"30px", "title"=>"", "readonly"=>"false", "default"=>"0", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),
			"is_transfer"   =>array("header"=>$lbl_grid_is_transfer, "source"=>$fill_from_array, "table"=>"namedays", "field"=>"is_transfer", "type"=>"enum",  "width"=>"30px", "title"=>"", "readonly"=>"false", "default"=>"0", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),
      );														
	  }elseif ($mode=="details"){
	  $fill_from_array = array("0"=>$lbl_no, "1"=>$lbl_yes);
	  $em_columns = array(
            "id"   =>array("header"=>$lbl_grid_code, "type"=>"label"),				
            "name"=>array("header"=>$lbl_grid_name, "type"=>"label"),	
			"day"=>array("header"=>$lbl_day, "type"=>"label"),	
			"month"=>array("header"=>$lbl_month, "type"=>"label"),	
			"is_dual"   =>array("header"=>$lbl_grid_is_dual, "source"=>$fill_from_array, "table"=>"namedays", "field"=>"is_dual", "type"=>"enum",  "width"=>"30px", "title"=>"", "readonly"=>"false", "default"=>"0", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),
			"is_transfer"   =>array("header"=>$lbl_grid_is_transfer, "source"=>$fill_from_array, "table"=>"namedays", "field"=>"is_transfer", "type"=>"enum",  "width"=>"30px", "title"=>"", "readonly"=>"false", "default"=>"0", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),
      );	   
	  }elseif ($mode=="edit"){
	  $fill_from_array = array("0"=>$lbl_no, "1"=>$lbl_yes);
	  $fill_from_month = array("1"=>"1","2"=>"2","3"=>"3","4"=>"4","5"=>"5","6"=>"6","7"=>"7","8"=>"8","9"=>"9","10"=>"10","11"=>"11","12"=>"12");
	  $fill_from_day = array("1"=>"1","2"=>"2","3"=>"3","4"=>"4","5"=>"5","6"=>"6","7"=>"7","8"=>"8","9"=>"9","10"=>"10","11"=>"11","12"=>"12","13"=>"13", "14"=>"14","15"=>"15","16"=>"16","17"=>"17","18"=>"18","19"=>"19","20"=>"20","21"=>"21","22"=>"22","23"=>"23","24"=>"24","25"=>"25","26"=>"26","27"=>"27","28"=>"28","29"=>"29","30"=>"30","31"=>"31");	  
	  $em_columns = array(
            "id"   =>array("header"=>$lbl_grid_code, "type"=>"label", "width"=>"30px", "title"=>"", "readonly"=>"true", "visible"=>"true"),	
            "name"=>array("header"=>$lbl_grid_name, "type"=>"textbox", "req_type"=>"ry", "width"=>"500px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
			"day"=>array("header"=>$lbl_day, "source"=>$fill_from_day, "req_type"=>"rn", "table"=>"namedays", "field"=>"day", "type"=>"enum",  "width"=>"30px", "title"=>"", "readonly"=>"false", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),
			"month"=>array("header"=>$lbl_month, "source"=>$fill_from_month, "req_type"=>"rn", "table"=>"namedays", "field"=>"month", "type"=>"enum",  "width"=>"30px", "title"=>"", "readonly"=>"false", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),		
			"is_dual"   =>array("header"=>$lbl_grid_is_dual, "source"=>$fill_from_array, "table"=>"namedays", "field"=>"is_dual", "type"=>"enum",  "width"=>"30px", "title"=>"", "readonly"=>"false", "default"=>"0", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),
			"is_transfer"   =>array("header"=>$lbl_grid_is_transfer, "source"=>$fill_from_array, "table"=>"namedays", "field"=>"is_transfer", "type"=>"enum",  "width"=>"30px", "title"=>"", "readonly"=>"false", "default"=>"0", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),
      );	
	  }  
      $dgrid->SetColumnsInEditMode($em_columns);
    ##  *** set auto-generated columns in edit mode
      $auto_column_in_edit_mode = false;
      $dgrid->SetAutoColumnsInEditMode($auto_column_in_edit_mode);
    ##  *** set foreign keys for add/edit/details modes (if there are linked tables)
     
    ## +---------------------------------------------------------------------------+
    ## | 8. Bind the DataGrid:                                                     | 
    ## +---------------------------------------------------------------------------+
    ##  *** bind the DataGrid and draw it on the screen
      $dgrid->Bind();        
      ob_end_flush();
?>

			</div>
		</fieldset>
	</div>
</body>
</html>
<?php 
} else {
    header('Location: login.php');
}
?>
