<?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'); }
			$mods = getCLSModules('POS'); foreach ($mods as $cls_modules){extract($cls_modules);} if ($mod_name == "POS") $_POS=1; //echo $_POS;
            $array = getGlobalSettings(); //Retrieve Global Settings		
            
            $sms_module_installed = Core::ModuleIsInstalled('SMS');

			$page_title = $lbl_page_core_settings; //Assign Page Title
			$mode = $lbl_page_core_settings; //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/");
      define ("PEAR_DIR", "datagrid/pear/");    
    
      require_once(DATAGRID_DIR.'datagrid.class.php');
      require_once(PEAR_DIR.'PEAR.php');
      require_once(PEAR_DIR.'DB.php');
      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,
	  		domain,
			description,
			owner,
			superadminEmail,
			adminEmail,
			cms_version,
			supportPage,
			default_lang,
			currency,
			web_flag,
			adb_flag,
			som_flag,
			sms_flag,
			cls_flag,
			barcode_len,
			barcode_type,
			print_receipt,
			logs_mb,
            custom_1,
            sms_provider,
            sms_mode
            FROM core_settings
			WHERE id='1'
			";

        ##  *** 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 = "set_";    /* 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 = "id";
          $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);  
		
    	$layouts = array("view"=>"1", "edit"=>"1", "details"=>"1", "filter"=>"1"); 
     	$dgrid->SetLayouts($layouts);
	
        $modes = array(
             "add"	  =>array("view"=>false, "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"=>false, "edit"=>false, "type"=>"image"),
             "delete"  =>array("view"=>false, "edit"=>false,  "type"=>"image"),
        
        );
        $dgrid->SetModes($modes);   
        $css_class = "default";
        $dgrid->SetCssClass($css_class);
        $dg_caption = "";
        $dgrid->SetCaption($dg_caption);
    
        ## +---------------------------------------------------------------------------+
        ## | 3. Printing & Exporting Settings:                                         | 
        ## +---------------------------------------------------------------------------+
        $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:                                             | 
        ## +---------------------------------------------------------------------------+
        $paging_option = false;
        $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:                                                       | 
        ## +---------------------------------------------------------------------------+
        $filtering_option = false;
        $show_search_type = true;
        $dgrid->AllowFiltering($filtering_option, $show_search_type);
        $filtering_fields = array();
        $dgrid->SetFieldsFiltering($filtering_fields);
    
        ## +---------------------------------------------------------------------------+
        ## | 6. View Mode Settings:                                                    | 
        ## +---------------------------------------------------------------------------+
        $vm_table_properties = array("width"=>"100%");
        $dgrid->SetViewModeTableProperties($vm_table_properties); 
         
        if ( $_POS==1 ){ $printer="true"; } else { $printer="false";};
        //check if SMS Module is installed
        $sms_settings_visible = 'no'; //initialization
        ($sms_module_installed == 'yes') ? $sms_settings_visible = true : $sms_settings_visible = false;
        
        $vm_colimns = array(
            "description"     => array("header"=>$lbl_grid_description, "type"=>"label", "target"=>"_self", "align"=>"left", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>"true", "tooltip_type"=>"floating", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
    		"cms_version" => array("header"=>$lbl_grid_version, "type"=>"label",      "align"=>"left", "wrap"=>"nowrap", "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),	
    		"owner" => array("header"=>$lbl_grid_owner, "type"=>"label",      "align"=>"left", "wrap"=>"nowrap",  "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),	
    		"superadminEmail" => array("header"=>$lbl_grid_super_admin_email, "type"=>"label",      "align"=>"left", "wrap"=>"nowrap", "text_length"=>"50", "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),		
    		"adminEmail" => array("header"=>$lbl_grid_admin_email, "type"=>"label",      "align"=>"left", "wrap"=>"nowrap", "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
    		"supportPage" => array("header"=>$lbl_grid_support_page, "type"=>"label",    "target"=>"_blank", "href"=>$lbl_grid_support_page,  "align"=>"left", "wrap"=>"nowrap",  "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),	
    		"default_lang" => array("header"=>$lbl_grid_default_lang, "type"=>"label",      "align"=>"left", "wrap"=>"nowrap",  "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),
    		"currency" => array("header"=>$lbl_grid_currency, "type"=>"label",      "align"=>"left", "wrap"=>"nowrap",  "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),	 
    		"barcode_len" => array("header"=>$lbl_grid_barcode_len, "type"=>"label",      "align"=>"left", "wrap"=>"nowrap",  "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),	
    		"barcode_type" => array("header"=>$lbl_grid_barcode_type, "type"=>"label",      "align"=>"left", "wrap"=>"nowrap",  "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),	
    		"logs_mb" => array("header"=>$lbl_grid_logs_space, "type"=>"label",      "align"=>"left", "wrap"=>"nowrap",  "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),		
    		"print_receipt" => array("header"=>$lbl_grid_print_receipt, "type"=>"checkbox",      "align"=>"left", "wrap"=>"nowrap",  "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>$printer,  "true_value"=>1, "false_value"=>0),	
            "custom_1" => array("header"=>_REFERENCE_CREDITS, "type"=>"label",      "align"=>"left", "wrap"=>"nowrap",  "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),		  								
            "sms_provider" => array("header"=>_SMS_PROVIDER, "type"=>"label", "visible"=>$sms_settings_visible,     "align"=>"left", "wrap"=>"nowrap",  "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "on_js_event"=>""),
            "sms_mode" => array("header"=>_SMS_MODE, "type"=>"label", "align"=>"left", "visible"=>$sms_settings_visible, "wrap"=>"nowrap",  "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "on_js_event"=>""),
        );
        $dgrid->SetColumnsInViewMode($vm_colimns);
    
    
    ## +---------------------------------------------------------------------------+
    ## | 7. Add/Edit/Details Mode Settings:                                        | 
    ## +---------------------------------------------------------------------------+
    ##  *** set add/edit mode table properties
      $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  = "core_settings";
      $primary_key = "id";
      $condition   = "";
      $dgrid->SetTableEdit($table_name, $primary_key, $condition);
	  $em_columns=array();
      if ($mode=="add"){	  
        exit('Add mode is not available');														
	  }elseif ($mode=="details"){
        $em_columns = array(													
      );	   
	  }elseif ($mode=="edit"){
	  $lang_array = array("GR"=>"GR", "EN"=>"EN"); /* as "value"=>"option" */
	  
      $check_array = array("0"=>$lbl_no, "1"=>$lbl_yes); /* as "value"=>"option" */
      $sms_providers_array = array("Clickatell"=>"Clickatell", "SMSAPI"=>"SMSAPI");
      $sms_modes_array = array("TEST"=>"TEST", "LIVE"=>"LIVE");
       
	  $em_columns = array(		
        "description"=>array("header"=>$lbl_grid_description, "type"=>"label", "req_type"=>"ry", "width"=>"300px", "title"=>"", "readonly"=>"true", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
        "cms_version"=>array("header"=>$lbl_grid_version, "type"=>"label", "req_type"=>"ry", "width"=>"300px", "title"=>"", "readonly"=>"true", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
        "owner"=>array("header"=>$lbl_grid_owner, "type"=>"textbox", "req_type"=>"ry", "width"=>"300px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
        "superadminEmail"=>array("header"=>$lbl_grid_super_admin_email, "type"=>"label", "req_type"=>"re", "width"=>"300px", "title"=>"", "readonly"=>"true", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),	
        "adminEmail"=>array("header"=>$lbl_grid_admin_email, "type"=>"textbox", "req_type"=>"re", "width"=>"300px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),	
        "supportPage"=>array("header"=>$lbl_grid_support_page, "type"=>"label", "req_type"=>"ry", "width"=>"300px", "title"=>"", "readonly"=>"true", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),			
        "default_lang" =>array("header"=>$lbl_grid_default_lang, "type"=>"enum",       "req_type"=>"ry", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "source"=>$lang_array, "view_type"=>"radiobutton", "radiobuttons_alignment"=>"horizontal", "multiple"=>"false", "multiple_size"=>"4"),			
        "currency"=>array("header"=>$lbl_grid_currency, "type"=>"textbox", "req_type"=>"ry", "width"=>"25px", "title"=>"", "readonly"=>"false", "maxlength"=>"2",  "visible"=>"true"),	
        "barcode_len"=>array("header"=>$lbl_grid_barcode_len, "type"=>"textbox", "req_type"=>"ry", "width"=>"25px", "title"=>"", "readonly"=>"false", "maxlength"=>"2",  "visible"=>"true"),	
        "barcode_type"=>array("header"=>$lbl_grid_barcode_type, "type"=>"textbox", "req_type"=>"ry", "width"=>"100px", "title"=>"", "readonly"=>"false", "maxlength"=>"100",  "visible"=>"true"),	
        "logs_mb" => array("header"=>$lbl_grid_logs_space, "type"=>"textbox",    "req_type"=>"rn",  "align"=>"left", "wrap"=>"nowrap",  "tooltip"=>"true", "tooltip_type"=>"simple", "case"=>"normal", "summarize"=>"false", "sort_type"=>"string", "sort_by"=>"", "visible"=>"true", "on_js_event"=>""),				
        "print_receipt" =>array("header"=>$lbl_grid_print_receipt, "type"=>"enum",       "req_type"=>"ry", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>$printer, "on_js_event"=>"", "source"=>$check_array, "view_type"=>"radiobutton", "radiobuttons_alignment"=>"vertical", "multiple"=>"false", "multiple_size"=>"4"),																																								
        "custom_1"=>array("header"=>_REFERENCE_CREDITS, "type"=>"textbox", "req_type"=>"ry", "width"=>"40px", "title"=>"", "readonly"=>"false", "maxlength"=>"4",  "visible"=>"true"),     
        "sms_provider" =>array("header"=>_SMS_PROVIDER, "type"=>"enum", "req_type"=>"ry", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>$sms_settings_visible, "on_js_event"=>"", "source"=>$sms_providers_array, "view_type"=>"radiobutton", "radiobuttons_alignment"=>"vertical", "multiple"=>"false", "multiple_size"=>"4"),
        "sms_mode" =>array("header"=>_SMS_MODE, "type"=>"enum", "req_type"=>"ry", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>$sms_settings_visible, "on_js_event"=>"", "source"=>$sms_modes_array, "view_type"=>"radiobutton", "radiobuttons_alignment"=>"vertical", "multiple"=>"false", "multiple_size"=>"4"),
      );	
	  }  
      $dgrid->SetColumnsInEditMode($em_columns);
    ##  *** set auto-generated columns in edit mode
      $auto_column_in_edit_mode = false;
      $dgrid->SetAutoColumnsInEditMode($auto_column_in_edit_mode);
      $foreign_keys = array(
        "usertype"=>array("table"=>"usertypes", "field_key"=>"id", "field_name"=>"name", "condition"=>"mask<>0", "view_type"=>"dropdownlist", "order_by_field"=>"mask", "order_type"=>"ASC", "on_js_event"=>""),
        "default_printer"=>array("table"=>"core_printers", "field_key"=>"id", "field_name"=>"alias", "condition"=>"active=1", "view_type"=>"dropdownlist", "order_by_field"=>"", "order_type"=>"ASC", "on_js_event"=>""),												
      ); 
      $dgrid->SetForeignKeysEdit($foreign_keys);
     
    ## +---------------------------------------------------------------------------+
    ## | 8. Bind the DataGrid:                                                     | 
    ## +---------------------------------------------------------------------------+
    ##  *** bind the DataGrid and draw it on the screen
      $dgrid->Bind();        
      ob_end_flush();

    ################################################################################   
?>
			</div>
		</fieldset>
<?php
	## ECHO INSTALLED MODULES ##
	echo "<fieldset style='margin-top:25px'><legend>".$lbl_installed_modules."</legend>";
	echo "<div style='padding:15px; margin-top:25px; background-color:#F4F9FB'>";
	$sql_modules="SELECT * FROM ".TABLE_MODULES."";
		$result_modules = mysqli_query($mysqli, $sql_modules) or die (mysqli_error($mysqli));
		while($row = mysqli_fetch_array($result_modules)){
			$mod_id=$row['id'];
            $mod_name=$row['mod_name'];
			$mod_description=$row['mod_description'];
		echo "<span style='padding:5px;'>{".$mod_id."} <font color='blue'> ".$mod_name."</font> <font color='grey'>{".$mod_description."}</font></span><br />";
		}
	echo "</div>";
	echo "</fieldset>";	
?>		
	</div>
</body>
</html>
<?php
} else {
    header('Location: login.php');
}
?>

