<?php
// This script and data application were generated by AppGini 5.76
// 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/curriculum_vitae.php");
	include("$currDir/curriculum_vitae_dml.php");

	// mm: can the current member access this page?
	$perm=getTablePermissions('curriculum_vitae');
	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 = "curriculum_vitae";

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(   
		"`curriculum_vitae`.`idcv`" => "idcv",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`matricule`), CONCAT_WS('',   `dossier_individuel1`.`matricule`), '') /* Matricule */" => "matricule",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* Nom prenom */" => "nom_prenom",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* Fonction */" => "fonction",
		"`curriculum_vitae`.`curriculum_vitae`" => "curriculum_vitae"
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(   
		1 => '`curriculum_vitae`.`idcv`',
		2 => '`dossier_individuel1`.`matricule`',
		3 => '`dossier_individuel1`.`nom_prenom`',
		4 => 4,
		5 => 5
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(   
		"`curriculum_vitae`.`idcv`" => "idcv",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`matricule`), CONCAT_WS('',   `dossier_individuel1`.`matricule`), '') /* Matricule */" => "matricule",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* Nom prenom */" => "nom_prenom",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* Fonction */" => "fonction",
		"`curriculum_vitae`.`curriculum_vitae`" => "curriculum_vitae"
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(   
		"`curriculum_vitae`.`idcv`" => "ID",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`matricule`), CONCAT_WS('',   `dossier_individuel1`.`matricule`), '') /* Matricule */" => "Matricule",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* Nom prenom */" => "Nom prenom",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* Fonction */" => "Fonction",
		"`curriculum_vitae`.`curriculum_vitae`" => "Curriculum vitae"
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(   
		"`curriculum_vitae`.`idcv`" => "idcv",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`matricule`), CONCAT_WS('',   `dossier_individuel1`.`matricule`), '') /* Matricule */" => "matricule",
		"IF(    CHAR_LENGTH(`dossier_individuel1`.`nom_prenom`), CONCAT_WS('',   `dossier_individuel1`.`nom_prenom`), '') /* Nom prenom */" => "nom_prenom",
		"IF(    CHAR_LENGTH(`fonctions1`.`fonction`), CONCAT_WS('',   `fonctions1`.`fonction`), '') /* Fonction */" => "fonction",
		"`curriculum_vitae`.`curriculum_vitae`" => "curriculum_vitae"
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array(  'matricule' => 'Matricule');

	$x->QueryFrom = "`curriculum_vitae` LEFT JOIN `dossier_individuel` as dossier_individuel1 ON `dossier_individuel1`.`iddindividuel`=`curriculum_vitae`.`matricule` LEFT JOIN `fonctions` as fonctions1 ON `fonctions1`.`idfonction`=`dossier_individuel1`.`fonction` ";
	$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 = 1000;
	$x->QuickSearch = 1;
	$x->QuickSearchText = $Translation["quick search"];
	$x->ScriptFileName = "curriculum_vitae_view.php";
	$x->RedirectAfterInsert = "curriculum_vitae_view.php?SelectedID=#ID#";
	$x->TableTitle = "CURRICULUM VITAE";
	$x->TableIcon = "resources/table_icons/client_account_template.png";
	$x->PrimaryKey = "`curriculum_vitae`.`idcv`";
	$x->DefaultSortField = '1';
	$x->DefaultSortDirection = 'asc';

	$x->ColWidth   = array(  150, 150, 150, 150);
	$x->ColCaption = array("Matricule", "Nom prenom", "Fonction", "Curriculum vitae");
	$x->ColFieldName = array('matricule', 'nom_prenom', 'fonction', 'curriculum_vitae');
	$x->ColNumber  = array(2, 3, 4, 5);

	// template paths below are based on the app main directory
	$x->Template = 'templates/curriculum_vitae_templateTV.html';
	$x->SelectedTemplate = 'templates/curriculum_vitae_templateTVS.html';
	$x->TemplateDV = 'templates/curriculum_vitae_templateDV.html';
	$x->TemplateDVP = 'templates/curriculum_vitae_templateDVP.html';

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

	// 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 `curriculum_vitae`.`idcv`=membership_userrecords.pkValue and membership_userrecords.tableName='curriculum_vitae' 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 `curriculum_vitae`.`idcv`=membership_userrecords.pkValue and membership_userrecords.tableName='curriculum_vitae' 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 = '`curriculum_vitae`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: curriculum_vitae_init
	$render=TRUE;
	if(function_exists('curriculum_vitae_init')){
		$args=array();
		$render=curriculum_vitae_init($x, getMemberInfo(), $args);
	}

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

	// hook: curriculum_vitae_header
	$headerCode='';
	if(function_exists('curriculum_vitae_header')){
		$args=array();
		$headerCode=curriculum_vitae_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: curriculum_vitae_footer
	$footerCode='';
	if(function_exists('curriculum_vitae_footer')){
		$args=array();
		$footerCode=curriculum_vitae_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);
	}
?>