<?php
// This script and data application were generated by AppGini 5.81
// Download AppGini for free from https://bigprof.com/appgini/download/

	$currDir=dirname(__FILE__);
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");
	@include("$currDir/hooks/suivi_client.php");
	include("$currDir/suivi_client_dml.php");

	// mm: can the current member access this page?
	$perm=getTablePermissions('suivi_client');
	if(!$perm[0]) {
		echo error_message($Translation['tableAccessDenied'], false);
		echo '<script>setTimeout("window.location=\'index.php?signOut=1\'", 2000);</script>';
		exit;
	}

	$x = new DataList;
	$x->TableName = "suivi_client";

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(
		"`suivi_client`.`idsuivi_client`" => "idsuivi_client",
		"`suivi_client`.`num_dossier`" => "num_dossier",
		"IF(    CHAR_LENGTH(`clients1`.`nom`), CONCAT_WS('',   `clients1`.`nom`), '') /* Nom */" => "nom",
		"IF(    CHAR_LENGTH(`clients1`.`prenom`), CONCAT_WS('',   `clients1`.`prenom`), '') /* Prenom */" => "prenom",
		"IF(    CHAR_LENGTH(`clients1`.`raison_sociale`), CONCAT_WS('',   `clients1`.`raison_sociale`), '') /* Raison sociale */" => "raison_sociale",
		"IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') /* Telephone */" => "telephone",
		"IF(    CHAR_LENGTH(`clients1`.`email`), CONCAT_WS('',   `clients1`.`email`), '') /* Email */" => "email",
		"IF(    CHAR_LENGTH(`clients1`.`whatsapp`), CONCAT_WS('',   `clients1`.`whatsapp`), '') /* Whatsapp */" => "whatsapp",
		"IF(    CHAR_LENGTH(`produits_services1`.`produit_service`), CONCAT_WS('',   `produits_services1`.`produit_service`), '') /* Service demande */" => "service_demande",
		"if(`suivi_client`.`date_demande`,date_format(`suivi_client`.`date_demande`,'%d/%m/%Y'),'')" => "date_demande",
		"`suivi_client`.`statut_service`" => "statut_service",
		"`suivi_client`.`num_visa`" => "num_visa",
		"if(`suivi_client`.`date_debut_visa`,date_format(`suivi_client`.`date_debut_visa`,'%d/%m/%Y'),'')" => "date_debut_visa",
		"if(`suivi_client`.`date_fin_visa`,date_format(`suivi_client`.`date_fin_visa`,'%d/%m/%Y'),'')" => "date_fin_visa",
		"IF(    CHAR_LENGTH(`type_visa1`.`type_visa`), CONCAT_WS('',   `type_visa1`.`type_visa`), '') /* Type de visa */" => "type_de_visa",
		"`suivi_client`.`observations`" => "observations",
		"`suivi_client`.`groupe`" => "groupe",
		"`suivi_client`.`agent`" => "agent",
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(
		1 => '`suivi_client`.`idsuivi_client`',
		2 => 2,
		3 => '`clients1`.`nom`',
		4 => '`clients1`.`prenom`',
		5 => '`clients1`.`raison_sociale`',
		6 => '`clients1`.`telephone`',
		7 => '`clients1`.`email`',
		8 => '`clients1`.`whatsapp`',
		9 => '`produits_services1`.`produit_service`',
		10 => '`suivi_client`.`date_demande`',
		11 => 11,
		12 => 12,
		13 => '`suivi_client`.`date_debut_visa`',
		14 => '`suivi_client`.`date_fin_visa`',
		15 => '`type_visa1`.`type_visa`',
		16 => 16,
		17 => 17,
		18 => 18,
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(
		"`suivi_client`.`idsuivi_client`" => "idsuivi_client",
		"`suivi_client`.`num_dossier`" => "num_dossier",
		"IF(    CHAR_LENGTH(`clients1`.`nom`), CONCAT_WS('',   `clients1`.`nom`), '') /* Nom */" => "nom",
		"IF(    CHAR_LENGTH(`clients1`.`prenom`), CONCAT_WS('',   `clients1`.`prenom`), '') /* Prenom */" => "prenom",
		"IF(    CHAR_LENGTH(`clients1`.`raison_sociale`), CONCAT_WS('',   `clients1`.`raison_sociale`), '') /* Raison sociale */" => "raison_sociale",
		"IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') /* Telephone */" => "telephone",
		"IF(    CHAR_LENGTH(`clients1`.`email`), CONCAT_WS('',   `clients1`.`email`), '') /* Email */" => "email",
		"IF(    CHAR_LENGTH(`clients1`.`whatsapp`), CONCAT_WS('',   `clients1`.`whatsapp`), '') /* Whatsapp */" => "whatsapp",
		"IF(    CHAR_LENGTH(`produits_services1`.`produit_service`), CONCAT_WS('',   `produits_services1`.`produit_service`), '') /* Service demande */" => "service_demande",
		"if(`suivi_client`.`date_demande`,date_format(`suivi_client`.`date_demande`,'%d/%m/%Y'),'')" => "date_demande",
		"`suivi_client`.`statut_service`" => "statut_service",
		"`suivi_client`.`num_visa`" => "num_visa",
		"if(`suivi_client`.`date_debut_visa`,date_format(`suivi_client`.`date_debut_visa`,'%d/%m/%Y'),'')" => "date_debut_visa",
		"if(`suivi_client`.`date_fin_visa`,date_format(`suivi_client`.`date_fin_visa`,'%d/%m/%Y'),'')" => "date_fin_visa",
		"IF(    CHAR_LENGTH(`type_visa1`.`type_visa`), CONCAT_WS('',   `type_visa1`.`type_visa`), '') /* Type de visa */" => "type_de_visa",
		"`suivi_client`.`observations`" => "observations",
		"`suivi_client`.`groupe`" => "groupe",
		"`suivi_client`.`agent`" => "agent",
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(
		"`suivi_client`.`idsuivi_client`" => "ID",
		"`suivi_client`.`num_dossier`" => "N&#176; dossier",
		"IF(    CHAR_LENGTH(`clients1`.`nom`), CONCAT_WS('',   `clients1`.`nom`), '') /* Nom */" => "Nom",
		"IF(    CHAR_LENGTH(`clients1`.`prenom`), CONCAT_WS('',   `clients1`.`prenom`), '') /* Prenom */" => "Prenom",
		"IF(    CHAR_LENGTH(`clients1`.`raison_sociale`), CONCAT_WS('',   `clients1`.`raison_sociale`), '') /* Raison sociale */" => "Raison sociale",
		"IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') /* Telephone */" => "Telephone",
		"IF(    CHAR_LENGTH(`clients1`.`email`), CONCAT_WS('',   `clients1`.`email`), '') /* Email */" => "Email",
		"IF(    CHAR_LENGTH(`clients1`.`whatsapp`), CONCAT_WS('',   `clients1`.`whatsapp`), '') /* Whatsapp */" => "Whatsapp",
		"IF(    CHAR_LENGTH(`produits_services1`.`produit_service`), CONCAT_WS('',   `produits_services1`.`produit_service`), '') /* Service demande */" => "Service demande",
		"`suivi_client`.`date_demande`" => "Date de la demande",
		"`suivi_client`.`statut_service`" => "Statut du service",
		"`suivi_client`.`num_visa`" => "N&#176; visa",
		"`suivi_client`.`date_debut_visa`" => "Date debut visa",
		"`suivi_client`.`date_fin_visa`" => "Date fin visa",
		"IF(    CHAR_LENGTH(`type_visa1`.`type_visa`), CONCAT_WS('',   `type_visa1`.`type_visa`), '') /* Type de visa */" => "Type de visa",
		"`suivi_client`.`observations`" => "Observations",
		"`suivi_client`.`groupe`" => "Groupe",
		"`suivi_client`.`agent`" => "Agent",
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(
		"`suivi_client`.`idsuivi_client`" => "idsuivi_client",
		"`suivi_client`.`num_dossier`" => "num_dossier",
		"IF(    CHAR_LENGTH(`clients1`.`nom`), CONCAT_WS('',   `clients1`.`nom`), '') /* Nom */" => "nom",
		"IF(    CHAR_LENGTH(`clients1`.`prenom`), CONCAT_WS('',   `clients1`.`prenom`), '') /* Prenom */" => "prenom",
		"IF(    CHAR_LENGTH(`clients1`.`raison_sociale`), CONCAT_WS('',   `clients1`.`raison_sociale`), '') /* Raison sociale */" => "raison_sociale",
		"IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') /* Telephone */" => "telephone",
		"IF(    CHAR_LENGTH(`clients1`.`email`), CONCAT_WS('',   `clients1`.`email`), '') /* Email */" => "email",
		"IF(    CHAR_LENGTH(`clients1`.`whatsapp`), CONCAT_WS('',   `clients1`.`whatsapp`), '') /* Whatsapp */" => "whatsapp",
		"IF(    CHAR_LENGTH(`produits_services1`.`produit_service`), CONCAT_WS('',   `produits_services1`.`produit_service`), '') /* Service demande */" => "service_demande",
		"if(`suivi_client`.`date_demande`,date_format(`suivi_client`.`date_demande`,'%d/%m/%Y'),'')" => "date_demande",
		"`suivi_client`.`statut_service`" => "statut_service",
		"`suivi_client`.`num_visa`" => "num_visa",
		"if(`suivi_client`.`date_debut_visa`,date_format(`suivi_client`.`date_debut_visa`,'%d/%m/%Y'),'')" => "date_debut_visa",
		"if(`suivi_client`.`date_fin_visa`,date_format(`suivi_client`.`date_fin_visa`,'%d/%m/%Y'),'')" => "date_fin_visa",
		"IF(    CHAR_LENGTH(`type_visa1`.`type_visa`), CONCAT_WS('',   `type_visa1`.`type_visa`), '') /* Type de visa */" => "type_de_visa",
		"`suivi_client`.`observations`" => "observations",
		"`suivi_client`.`groupe`" => "groupe",
		"`suivi_client`.`agent`" => "agent",
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array('nom' => 'Nom', 'service_demande' => 'Service demande', 'type_de_visa' => 'Type de visa', );

	$x->QueryFrom = "`suivi_client` LEFT JOIN `clients` as clients1 ON `clients1`.`idclient`=`suivi_client`.`nom` LEFT JOIN `produits_services` as produits_services1 ON `produits_services1`.`idps`=`suivi_client`.`service_demande` LEFT JOIN `type_visa` as type_visa1 ON `type_visa1`.`idtype_visa`=`suivi_client`.`type_de_visa` ";
	$x->QueryWhere = '';
	$x->QueryOrder = '';

	$x->AllowSelection = 1;
	$x->HideTableView = ($perm[2]==0 ? 1 : 0);
	$x->AllowDelete = $perm[4];
	$x->AllowMassDelete = true;
	$x->AllowInsert = $perm[1];
	$x->AllowUpdate = $perm[3];
	$x->SeparateDV = 1;
	$x->AllowDeleteOfParents = 0;
	$x->AllowFilters = 1;
	$x->AllowSavingFilters = 1;
	$x->AllowSorting = 1;
	$x->AllowNavigation = 1;
	$x->AllowPrinting = 1;
	$x->AllowPrintingDV = 1;
	$x->AllowCSV = 1;
	$x->RecordsPerPage = 10;
	$x->QuickSearch = 1;
	$x->QuickSearchText = $Translation["quick search"];
	$x->ScriptFileName = "suivi_client_view.php";
	$x->RedirectAfterInsert = "suivi_client_view.php?SelectedID=#ID#";
	$x->TableTitle = "SUIVI CLIENTS";
	$x->TableIcon = "resources/table_icons/client_account_template.png";
	$x->PrimaryKey = "`suivi_client`.`idsuivi_client`";
	$x->DefaultSortField = '`suivi_client`.`date_demande`';
	$x->DefaultSortDirection = 'desc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("N&#176; dossier", "Nom", "Prenom", "Raison sociale", "Telephone", "Email", "Whatsapp", "Service demande", "Date de la demande", "Statut du service", "N&#176; visa", "Date debut visa", "Date fin visa", "Type de visa", "Groupe", "Agent");
	$x->ColFieldName = array('num_dossier', 'nom', 'prenom', 'raison_sociale', 'telephone', 'email', 'whatsapp', 'service_demande', 'date_demande', 'statut_service', 'num_visa', 'date_debut_visa', 'date_fin_visa', 'type_de_visa', 'groupe', 'agent');
	$x->ColNumber  = array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18);

	// template paths below are based on the app main directory
	$x->Template = 'templates/suivi_client_templateTV.html';
	$x->SelectedTemplate = 'templates/suivi_client_templateTVS.html';
	$x->TemplateDV = 'templates/suivi_client_templateDV.html';
	$x->TemplateDVP = 'templates/suivi_client_templateDVP.html';

	$x->ShowTableHeader = 1;
	$x->TVClasses = "";
	$x->DVClasses = "";
	$x->HighlightColor = '#FFF0C2';
	$x->HasCalculatedFields = false;

	// mm: build the query based on current member's permissions
	$DisplayRecords = $_REQUEST['DisplayRecords'];
	if(!in_array($DisplayRecords, array('user', 'group'))) { $DisplayRecords = 'all'; }
	if($perm[2]==1 || ($perm[2]>1 && $DisplayRecords=='user' && !$_REQUEST['NoFilter_x'])) { // view owner only
		$x->QueryFrom.=', membership_userrecords';
		$x->QueryWhere="where `suivi_client`.`idsuivi_client`=membership_userrecords.pkValue and membership_userrecords.tableName='suivi_client' and lcase(membership_userrecords.memberID)='".getLoggedMemberID()."'";
	}elseif($perm[2]==2 || ($perm[2]>2 && $DisplayRecords=='group' && !$_REQUEST['NoFilter_x'])) { // view group only
		$x->QueryFrom.=', membership_userrecords';
		$x->QueryWhere="where `suivi_client`.`idsuivi_client`=membership_userrecords.pkValue and membership_userrecords.tableName='suivi_client' and membership_userrecords.groupID='".getLoggedGroupID()."'";
	}elseif($perm[2]==3) { // view all
		// no further action
	}elseif($perm[2]==0) { // view none
		$x->QueryFields = array("Not enough permissions" => "NEP");
		$x->QueryFrom = '`suivi_client`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: suivi_client_init
	$render=TRUE;
	if(function_exists('suivi_client_init')) {
		$args=array();
		$render=suivi_client_init($x, getMemberInfo(), $args);
	}

	if($render) $x->Render();

	// hook: suivi_client_header
	$headerCode='';
	if(function_exists('suivi_client_header')) {
		$args=array();
		$headerCode=suivi_client_header($x->ContentType, getMemberInfo(), $args);
	}  
	if(!$headerCode) {
		include_once("$currDir/header.php"); 
	}else{
		ob_start(); include_once("$currDir/header.php"); $dHeader=ob_get_contents(); ob_end_clean();
		echo str_replace('<%%HEADER%%>', $dHeader, $headerCode);
	}

	echo $x->HTML;
	// hook: suivi_client_footer
	$footerCode='';
	if(function_exists('suivi_client_footer')) {
		$args=array();
		$footerCode=suivi_client_footer($x->ContentType, getMemberInfo(), $args);
	}  
	if(!$footerCode) {
		include_once("$currDir/footer.php"); 
	}else{
		ob_start(); include_once("$currDir/footer.php"); $dFooter=ob_get_contents(); ob_end_clean();
		echo str_replace('<%%FOOTER%%>', $dFooter, $footerCode);
	}
?>