<?php

// Data functions (insert, update, delete, form) for table informations

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

function informations_insert(){
	global $Translation;

	// mm: can member insert record?
	$arrPerm=getTablePermissions('informations');
	if(!$arrPerm[1]){
		return false;
	}

	$data['matricule'] = makeSafe($_REQUEST['matricule']);
		if($data['matricule'] == empty_lookup_value){ $data['matricule'] = ''; }
	$data['nom_prenom'] = makeSafe($_REQUEST['matricule']);
		if($data['nom_prenom'] == empty_lookup_value){ $data['nom_prenom'] = ''; }
	$data['diplome_primordial'] = makeSafe($_REQUEST['diplome_primordial']);
		if($data['diplome_primordial'] == empty_lookup_value){ $data['diplome_primordial'] = ''; }
	$data['date_diplome'] = intval($_REQUEST['date_diplomeYear']) . '-' . intval($_REQUEST['date_diplomeMonth']) . '-' . intval($_REQUEST['date_diplomeDay']);
	$data['date_diplome'] = parseMySQLDate($data['date_diplome'], '');
	$data['institution'] = makeSafe($_REQUEST['institution']);
		if($data['institution'] == empty_lookup_value){ $data['institution'] = ''; }
	$data['lieu_diplome'] = makeSafe($_REQUEST['lieu_diplome']);
		if($data['lieu_diplome'] == empty_lookup_value){ $data['lieu_diplome'] = ''; }
	$data['diplome_certificat'] = makeSafe($_REQUEST['diplome_certificat']);
		if($data['diplome_certificat'] == empty_lookup_value){ $data['diplome_certificat'] = ''; }
	$data['specialite'] = makeSafe($_REQUEST['specialite']);
		if($data['specialite'] == empty_lookup_value){ $data['specialite'] = ''; }
	$data['institution_specialite'] = makeSafe($_REQUEST['institution_specialite']);
		if($data['institution_specialite'] == empty_lookup_value){ $data['institution_specialite'] = ''; }
	$data['lieu_specialite'] = makeSafe($_REQUEST['lieu_specialite']);
		if($data['lieu_specialite'] == empty_lookup_value){ $data['lieu_specialite'] = ''; }
	if(is_array($_REQUEST['arabe'])){
		$MultipleSeparator=', ';
		foreach($_REQUEST['arabe'] as $k => $v)
			$data['arabe'] .= makeSafe($v) . $MultipleSeparator;
		$data['arabe'] = substr($data['arabe'], 0, -1 * strlen($MultipleSeparator));
	}else{
		$data['arabe']='';
	}
	if(is_array($_REQUEST['francais'])){
		$MultipleSeparator=', ';
		foreach($_REQUEST['francais'] as $k => $v)
			$data['francais'] .= makeSafe($v) . $MultipleSeparator;
		$data['francais'] = substr($data['francais'], 0, -1 * strlen($MultipleSeparator));
	}else{
		$data['francais']='';
	}
	if(is_array($_REQUEST['anglais'])){
		$MultipleSeparator=', ';
		foreach($_REQUEST['anglais'] as $k => $v)
			$data['anglais'] .= makeSafe($v) . $MultipleSeparator;
		$data['anglais'] = substr($data['anglais'], 0, -1 * strlen($MultipleSeparator));
	}else{
		$data['anglais']='';
	}
	$data['autres1'] = makeSafe($_REQUEST['autres1']);
		if($data['autres1'] == empty_lookup_value){ $data['autres1'] = ''; }
	if(is_array($_REQUEST['autres2'])){
		$MultipleSeparator=', ';
		foreach($_REQUEST['autres2'] as $k => $v)
			$data['autres2'] .= makeSafe($v) . $MultipleSeparator;
		$data['autres2'] = substr($data['autres2'], 0, -1 * strlen($MultipleSeparator));
	}else{
		$data['autres2']='';
	}
	$data['utilisation'] = makeSafe($_REQUEST['utilisation']);
		if($data['utilisation'] == empty_lookup_value){ $data['utilisation'] = ''; }
	$data['programmation'] = makeSafe($_REQUEST['programmation']);
		if($data['programmation'] == empty_lookup_value){ $data['programmation'] = ''; }

	// hook: informations_before_insert
	if(function_exists('informations_before_insert')){
		$args=array();
		if(!informations_before_insert($data, getMemberInfo(), $args)){ return false; }
	}

	$o = array('silentErrors' => true);
	sql('insert into `informations` set       `matricule`=' . (($data['matricule'] !== '' && $data['matricule'] !== NULL) ? "'{$data['matricule']}'" : 'NULL') . ', `nom_prenom`=' . (($data['nom_prenom'] !== '' && $data['nom_prenom'] !== NULL) ? "'{$data['nom_prenom']}'" : 'NULL') . ', `diplome_primordial`=' . (($data['diplome_primordial'] !== '' && $data['diplome_primordial'] !== NULL) ? "'{$data['diplome_primordial']}'" : 'NULL') . ', `date_diplome`=' . (($data['date_diplome'] !== '' && $data['date_diplome'] !== NULL) ? "'{$data['date_diplome']}'" : 'NULL') . ', `institution`=' . (($data['institution'] !== '' && $data['institution'] !== NULL) ? "'{$data['institution']}'" : 'NULL') . ', `lieu_diplome`=' . (($data['lieu_diplome'] !== '' && $data['lieu_diplome'] !== NULL) ? "'{$data['lieu_diplome']}'" : 'NULL') . ', `diplome_certificat`=' . (($data['diplome_certificat'] !== '' && $data['diplome_certificat'] !== NULL) ? "'{$data['diplome_certificat']}'" : 'NULL') . ', `specialite`=' . (($data['specialite'] !== '' && $data['specialite'] !== NULL) ? "'{$data['specialite']}'" : 'NULL') . ', `institution_specialite`=' . (($data['institution_specialite'] !== '' && $data['institution_specialite'] !== NULL) ? "'{$data['institution_specialite']}'" : 'NULL') . ', `lieu_specialite`=' . (($data['lieu_specialite'] !== '' && $data['lieu_specialite'] !== NULL) ? "'{$data['lieu_specialite']}'" : 'NULL') . ', `arabe`=' . (($data['arabe'] !== '' && $data['arabe'] !== NULL) ? "'{$data['arabe']}'" : 'NULL') . ', `francais`=' . (($data['francais'] !== '' && $data['francais'] !== NULL) ? "'{$data['francais']}'" : 'NULL') . ', `anglais`=' . (($data['anglais'] !== '' && $data['anglais'] !== NULL) ? "'{$data['anglais']}'" : 'NULL') . ', `autres1`=' . (($data['autres1'] !== '' && $data['autres1'] !== NULL) ? "'{$data['autres1']}'" : 'NULL') . ', `autres2`=' . (($data['autres2'] !== '' && $data['autres2'] !== NULL) ? "'{$data['autres2']}'" : 'NULL') . ', `utilisation`=' . (($data['utilisation'] !== '' && $data['utilisation'] !== NULL) ? "'{$data['utilisation']}'" : 'NULL') . ', `programmation`=' . (($data['programmation'] !== '' && $data['programmation'] !== NULL) ? "'{$data['programmation']}'" : 'NULL'), $o);
	if($o['error']!=''){
		echo $o['error'];
		echo "<a href=\"informations_view.php?addNew_x=1\">{$Translation['< back']}</a>";
		exit;
	}

	$recID = db_insert_id(db_link());

	// hook: informations_after_insert
	if(function_exists('informations_after_insert')){
		$res = sql("select * from `informations` where `idinformation`='" . makeSafe($recID, false) . "' limit 1", $eo);
		if($row = db_fetch_assoc($res)){
			$data = array_map('makeSafe', $row);
		}
		$data['selectedID'] = makeSafe($recID, false);
		$args=array();
		if(!informations_after_insert($data, getMemberInfo(), $args)){ return $recID; }
	}

	// mm: save ownership data
	set_record_owner('informations', $recID, getLoggedMemberID());

	return $recID;
}

function informations_delete($selected_id, $AllowDeleteOfParents=false, $skipChecks=false){
	// insure referential integrity ...
	global $Translation;
	$selected_id=makeSafe($selected_id);

	// mm: can member delete record?
	$arrPerm=getTablePermissions('informations');
	$ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='informations' and pkValue='$selected_id'");
	$ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='informations' and pkValue='$selected_id'");
	if(($arrPerm[4]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[4]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[4]==3){ // allow delete?
		// delete allowed, so continue ...
	}else{
		return $Translation['You don\'t have enough permissions to delete this record'];
	}

	// hook: informations_before_delete
	if(function_exists('informations_before_delete')){
		$args=array();
		if(!informations_before_delete($selected_id, $skipChecks, getMemberInfo(), $args))
			return $Translation['Couldn\'t delete this record'];
	}

	// child table: cursus
	$res = sql("select `idinformation` from `informations` where `idinformation`='$selected_id'", $eo);
	$idinformation = db_fetch_row($res);
	$rires = sql("select count(1) from `cursus` where `idinformation`='".addslashes($idinformation[0])."'", $eo);
	$rirow = db_fetch_row($rires);
	if($rirow[0] && !$AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["couldn't delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "cursus", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "cursus", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='informations_view.php?SelectedID=".urlencode($selected_id)."&delete_x=1&confirmed=1';\">", $RetMsg);
		$RetMsg = str_replace("<Cancel>", "<input type=\"button\" class=\"button\" value=\"".$Translation['no']."\" onClick=\"window.location='informations_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	sql("delete from `informations` where `idinformation`='$selected_id'", $eo);

	// hook: informations_after_delete
	if(function_exists('informations_after_delete')){
		$args=array();
		informations_after_delete($selected_id, getMemberInfo(), $args);
	}

	// mm: delete ownership data
	sql("delete from membership_userrecords where tableName='informations' and pkValue='$selected_id'", $eo);
}

function informations_update($selected_id){
	global $Translation;

	// mm: can member edit record?
	$arrPerm=getTablePermissions('informations');
	$ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='informations' and pkValue='".makeSafe($selected_id)."'");
	$ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='informations' and pkValue='".makeSafe($selected_id)."'");
	if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){ // allow update?
		// update allowed, so continue ...
	}else{
		return false;
	}

	$data['matricule'] = makeSafe($_REQUEST['matricule']);
		if($data['matricule'] == empty_lookup_value){ $data['matricule'] = ''; }
	$data['nom_prenom'] = makeSafe($_REQUEST['matricule']);
		if($data['nom_prenom'] == empty_lookup_value){ $data['nom_prenom'] = ''; }
	$data['diplome_primordial'] = makeSafe($_REQUEST['diplome_primordial']);
		if($data['diplome_primordial'] == empty_lookup_value){ $data['diplome_primordial'] = ''; }
	$data['date_diplome'] = intval($_REQUEST['date_diplomeYear']) . '-' . intval($_REQUEST['date_diplomeMonth']) . '-' . intval($_REQUEST['date_diplomeDay']);
	$data['date_diplome'] = parseMySQLDate($data['date_diplome'], '');
	$data['institution'] = makeSafe($_REQUEST['institution']);
		if($data['institution'] == empty_lookup_value){ $data['institution'] = ''; }
	$data['lieu_diplome'] = makeSafe($_REQUEST['lieu_diplome']);
		if($data['lieu_diplome'] == empty_lookup_value){ $data['lieu_diplome'] = ''; }
	$data['diplome_certificat'] = makeSafe($_REQUEST['diplome_certificat']);
		if($data['diplome_certificat'] == empty_lookup_value){ $data['diplome_certificat'] = ''; }
	$data['specialite'] = makeSafe($_REQUEST['specialite']);
		if($data['specialite'] == empty_lookup_value){ $data['specialite'] = ''; }
	$data['institution_specialite'] = makeSafe($_REQUEST['institution_specialite']);
		if($data['institution_specialite'] == empty_lookup_value){ $data['institution_specialite'] = ''; }
	$data['lieu_specialite'] = makeSafe($_REQUEST['lieu_specialite']);
		if($data['lieu_specialite'] == empty_lookup_value){ $data['lieu_specialite'] = ''; }
	if(is_array($_REQUEST['arabe'])){
		$MultipleSeparator = ', ';
		foreach($_REQUEST['arabe'] as $k => $v)
			$data['arabe'] .= makeSafe($v) . $MultipleSeparator;
		$data['arabe']=substr($data['arabe'], 0, -1 * strlen($MultipleSeparator));
	}else{
		$data['arabe']='';
	}
	if(is_array($_REQUEST['francais'])){
		$MultipleSeparator = ', ';
		foreach($_REQUEST['francais'] as $k => $v)
			$data['francais'] .= makeSafe($v) . $MultipleSeparator;
		$data['francais']=substr($data['francais'], 0, -1 * strlen($MultipleSeparator));
	}else{
		$data['francais']='';
	}
	if(is_array($_REQUEST['anglais'])){
		$MultipleSeparator = ', ';
		foreach($_REQUEST['anglais'] as $k => $v)
			$data['anglais'] .= makeSafe($v) . $MultipleSeparator;
		$data['anglais']=substr($data['anglais'], 0, -1 * strlen($MultipleSeparator));
	}else{
		$data['anglais']='';
	}
	$data['autres1'] = makeSafe($_REQUEST['autres1']);
		if($data['autres1'] == empty_lookup_value){ $data['autres1'] = ''; }
	if(is_array($_REQUEST['autres2'])){
		$MultipleSeparator = ', ';
		foreach($_REQUEST['autres2'] as $k => $v)
			$data['autres2'] .= makeSafe($v) . $MultipleSeparator;
		$data['autres2']=substr($data['autres2'], 0, -1 * strlen($MultipleSeparator));
	}else{
		$data['autres2']='';
	}
	$data['utilisation'] = makeSafe($_REQUEST['utilisation']);
		if($data['utilisation'] == empty_lookup_value){ $data['utilisation'] = ''; }
	$data['programmation'] = makeSafe($_REQUEST['programmation']);
		if($data['programmation'] == empty_lookup_value){ $data['programmation'] = ''; }
	$data['selectedID']=makeSafe($selected_id);

	// hook: informations_before_update
	if(function_exists('informations_before_update')){
		$args=array();
		if(!informations_before_update($data, getMemberInfo(), $args)){ return false; }
	}

	$o=array('silentErrors' => true);
	sql('update `informations` set       `matricule`=' . (($data['matricule'] !== '' && $data['matricule'] !== NULL) ? "'{$data['matricule']}'" : 'NULL') . ', `nom_prenom`=' . (($data['nom_prenom'] !== '' && $data['nom_prenom'] !== NULL) ? "'{$data['nom_prenom']}'" : 'NULL') . ', `diplome_primordial`=' . (($data['diplome_primordial'] !== '' && $data['diplome_primordial'] !== NULL) ? "'{$data['diplome_primordial']}'" : 'NULL') . ', `date_diplome`=' . (($data['date_diplome'] !== '' && $data['date_diplome'] !== NULL) ? "'{$data['date_diplome']}'" : 'NULL') . ', `institution`=' . (($data['institution'] !== '' && $data['institution'] !== NULL) ? "'{$data['institution']}'" : 'NULL') . ', `lieu_diplome`=' . (($data['lieu_diplome'] !== '' && $data['lieu_diplome'] !== NULL) ? "'{$data['lieu_diplome']}'" : 'NULL') . ', `diplome_certificat`=' . (($data['diplome_certificat'] !== '' && $data['diplome_certificat'] !== NULL) ? "'{$data['diplome_certificat']}'" : 'NULL') . ', `specialite`=' . (($data['specialite'] !== '' && $data['specialite'] !== NULL) ? "'{$data['specialite']}'" : 'NULL') . ', `institution_specialite`=' . (($data['institution_specialite'] !== '' && $data['institution_specialite'] !== NULL) ? "'{$data['institution_specialite']}'" : 'NULL') . ', `lieu_specialite`=' . (($data['lieu_specialite'] !== '' && $data['lieu_specialite'] !== NULL) ? "'{$data['lieu_specialite']}'" : 'NULL') . ', `arabe`=' . (($data['arabe'] !== '' && $data['arabe'] !== NULL) ? "'{$data['arabe']}'" : 'NULL') . ', `francais`=' . (($data['francais'] !== '' && $data['francais'] !== NULL) ? "'{$data['francais']}'" : 'NULL') . ', `anglais`=' . (($data['anglais'] !== '' && $data['anglais'] !== NULL) ? "'{$data['anglais']}'" : 'NULL') . ', `autres1`=' . (($data['autres1'] !== '' && $data['autres1'] !== NULL) ? "'{$data['autres1']}'" : 'NULL') . ', `autres2`=' . (($data['autres2'] !== '' && $data['autres2'] !== NULL) ? "'{$data['autres2']}'" : 'NULL') . ', `utilisation`=' . (($data['utilisation'] !== '' && $data['utilisation'] !== NULL) ? "'{$data['utilisation']}'" : 'NULL') . ', `programmation`=' . (($data['programmation'] !== '' && $data['programmation'] !== NULL) ? "'{$data['programmation']}'" : 'NULL') . " where `idinformation`='".makeSafe($selected_id)."'", $o);
	if($o['error']!=''){
		echo $o['error'];
		echo '<a href="informations_view.php?SelectedID='.urlencode($selected_id)."\">{$Translation['< back']}</a>";
		exit;
	}


	// hook: informations_after_update
	if(function_exists('informations_after_update')){
		$res = sql("SELECT * FROM `informations` WHERE `idinformation`='{$data['selectedID']}' LIMIT 1", $eo);
		if($row = db_fetch_assoc($res)){
			$data = array_map('makeSafe', $row);
		}
		$data['selectedID'] = $data['idinformation'];
		$args = array();
		if(!informations_after_update($data, getMemberInfo(), $args)){ return; }
	}

	// mm: update ownership data
	sql("update membership_userrecords set dateUpdated='".time()."' where tableName='informations' and pkValue='".makeSafe($selected_id)."'", $eo);

}

function informations_form($selected_id = '', $AllowUpdate = 1, $AllowInsert = 1, $AllowDelete = 1, $ShowCancel = 0, $TemplateDV = '', $TemplateDVP = ''){
	// function to return an editable form for a table records
	// and fill it with data of record whose ID is $selected_id. If $selected_id
	// is empty, an empty form is shown, with only an 'Add New'
	// button displayed.

	global $Translation;

	// mm: get table permissions
	$arrPerm=getTablePermissions('informations');
	if(!$arrPerm[1] && $selected_id==''){ return ''; }
	$AllowInsert = ($arrPerm[1] ? true : false);
	// print preview?
	$dvprint = false;
	if($selected_id && $_REQUEST['dvprint_x'] != ''){
		$dvprint = true;
	}

	$filterer_matricule = thisOr(undo_magic_quotes($_REQUEST['filterer_matricule']), '');

	// populate filterers, starting from children to grand-parents

	// unique random identifier
	$rnd1 = ($dvprint ? rand(1000000, 9999999) : '');
	// combobox: matricule
	$combo_matricule = new DataCombo;
	// combobox: date_diplome
	$combo_date_diplome = new DateCombo;
	$combo_date_diplome->DateFormat = "dmy";
	$combo_date_diplome->MinYear = 1900;
	$combo_date_diplome->MaxYear = 2100;
	$combo_date_diplome->DefaultDate = parseMySQLDate('', '');
	$combo_date_diplome->MonthNames = $Translation['month names'];
	$combo_date_diplome->NamePrefix = 'date_diplome';
	// combobox: arabe
	$combo_arabe = new Combo;
	$combo_arabe->ListType = 3;
	$combo_arabe->MultipleSeparator = ', ';
	$combo_arabe->ListBoxHeight = 10;
	$combo_arabe->RadiosPerLine = 1;
	if(is_file(dirname(__FILE__).'/hooks/informations.arabe.csv')){
		$arabe_data = addslashes(implode('', @file(dirname(__FILE__).'/hooks/informations.arabe.csv')));
		$combo_arabe->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions($arabe_data)));
		$combo_arabe->ListData = $combo_arabe->ListItem;
	}else{
		$combo_arabe->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions("LU;;ECRIT;;PARLE")));
		$combo_arabe->ListData = $combo_arabe->ListItem;
	}
	$combo_arabe->SelectName = 'arabe';
	// combobox: francais
	$combo_francais = new Combo;
	$combo_francais->ListType = 3;
	$combo_francais->MultipleSeparator = ', ';
	$combo_francais->ListBoxHeight = 10;
	$combo_francais->RadiosPerLine = 1;
	if(is_file(dirname(__FILE__).'/hooks/informations.francais.csv')){
		$francais_data = addslashes(implode('', @file(dirname(__FILE__).'/hooks/informations.francais.csv')));
		$combo_francais->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions($francais_data)));
		$combo_francais->ListData = $combo_francais->ListItem;
	}else{
		$combo_francais->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions("LU;;ECRIT;;PARLE")));
		$combo_francais->ListData = $combo_francais->ListItem;
	}
	$combo_francais->SelectName = 'francais';
	// combobox: anglais
	$combo_anglais = new Combo;
	$combo_anglais->ListType = 3;
	$combo_anglais->MultipleSeparator = ', ';
	$combo_anglais->ListBoxHeight = 10;
	$combo_anglais->RadiosPerLine = 1;
	if(is_file(dirname(__FILE__).'/hooks/informations.anglais.csv')){
		$anglais_data = addslashes(implode('', @file(dirname(__FILE__).'/hooks/informations.anglais.csv')));
		$combo_anglais->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions($anglais_data)));
		$combo_anglais->ListData = $combo_anglais->ListItem;
	}else{
		$combo_anglais->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions("LU;;ECRIT;;PARLE")));
		$combo_anglais->ListData = $combo_anglais->ListItem;
	}
	$combo_anglais->SelectName = 'anglais';
	// combobox: autres2
	$combo_autres2 = new Combo;
	$combo_autres2->ListType = 3;
	$combo_autres2->MultipleSeparator = ', ';
	$combo_autres2->ListBoxHeight = 10;
	$combo_autres2->RadiosPerLine = 1;
	if(is_file(dirname(__FILE__).'/hooks/informations.autres2.csv')){
		$autres2_data = addslashes(implode('', @file(dirname(__FILE__).'/hooks/informations.autres2.csv')));
		$combo_autres2->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions($autres2_data)));
		$combo_autres2->ListData = $combo_autres2->ListItem;
	}else{
		$combo_autres2->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions("LU;;ECRIT;;PARLE")));
		$combo_autres2->ListData = $combo_autres2->ListItem;
	}
	$combo_autres2->SelectName = 'autres2';
	// combobox: utilisation
	$combo_utilisation = new Combo;
	$combo_utilisation->ListType = 0;
	$combo_utilisation->MultipleSeparator = ', ';
	$combo_utilisation->ListBoxHeight = 10;
	$combo_utilisation->RadiosPerLine = 1;
	if(is_file(dirname(__FILE__).'/hooks/informations.utilisation.csv')){
		$utilisation_data = addslashes(implode('', @file(dirname(__FILE__).'/hooks/informations.utilisation.csv')));
		$combo_utilisation->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions($utilisation_data)));
		$combo_utilisation->ListData = $combo_utilisation->ListItem;
	}else{
		$combo_utilisation->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions("OUI;;NON")));
		$combo_utilisation->ListData = $combo_utilisation->ListItem;
	}
	$combo_utilisation->SelectName = 'utilisation';
	// combobox: programmation
	$combo_programmation = new Combo;
	$combo_programmation->ListType = 0;
	$combo_programmation->MultipleSeparator = ', ';
	$combo_programmation->ListBoxHeight = 10;
	$combo_programmation->RadiosPerLine = 1;
	if(is_file(dirname(__FILE__).'/hooks/informations.programmation.csv')){
		$programmation_data = addslashes(implode('', @file(dirname(__FILE__).'/hooks/informations.programmation.csv')));
		$combo_programmation->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions($programmation_data)));
		$combo_programmation->ListData = $combo_programmation->ListItem;
	}else{
		$combo_programmation->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions("OUI;;NON")));
		$combo_programmation->ListData = $combo_programmation->ListItem;
	}
	$combo_programmation->SelectName = 'programmation';

	if($selected_id){
		// mm: check member permissions
		if(!$arrPerm[2]){
			return "";
		}
		// mm: who is the owner?
		$ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='informations' and pkValue='".makeSafe($selected_id)."'");
		$ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='informations' and pkValue='".makeSafe($selected_id)."'");
		if($arrPerm[2]==1 && getLoggedMemberID()!=$ownerMemberID){
			return "";
		}
		if($arrPerm[2]==2 && getLoggedGroupID()!=$ownerGroupID){
			return "";
		}

		// can edit?
		if(($arrPerm[3]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[3]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[3]==3){
			$AllowUpdate=1;
		}else{
			$AllowUpdate=0;
		}

		$res = sql("select * from `informations` where `idinformation`='".makeSafe($selected_id)."'", $eo);
		if(!($row = db_fetch_array($res))){
			return error_message($Translation['No records found'], 'informations_view.php', false);
		}
		$urow = $row; /* unsanitized data */
		$hc = new CI_Input();
		$row = $hc->xss_clean($row); /* sanitize data */
		$combo_matricule->SelectedData = $row['matricule'];
		$combo_date_diplome->DefaultDate = $row['date_diplome'];
		$combo_arabe->SelectedData = $row['arabe'];
		$combo_francais->SelectedData = $row['francais'];
		$combo_anglais->SelectedData = $row['anglais'];
		$combo_autres2->SelectedData = $row['autres2'];
		$combo_utilisation->SelectedData = $row['utilisation'];
		$combo_programmation->SelectedData = $row['programmation'];
	}else{
		$combo_matricule->SelectedData = $filterer_matricule;
		$combo_utilisation->SelectedText = ( $_REQUEST['FilterField'][1]=='21' && $_REQUEST['FilterOperator'][1]=='<=>' ? (get_magic_quotes_gpc() ? stripslashes($_REQUEST['FilterValue'][1]) : $_REQUEST['FilterValue'][1]) : "");
		$combo_programmation->SelectedText = ( $_REQUEST['FilterField'][1]=='22' && $_REQUEST['FilterOperator'][1]=='<=>' ? (get_magic_quotes_gpc() ? stripslashes($_REQUEST['FilterValue'][1]) : $_REQUEST['FilterValue'][1]) : "");
	}
	$combo_matricule->HTML = '<span id="matricule-container' . $rnd1 . '"></span><input type="hidden" name="matricule" id="matricule' . $rnd1 . '" value="' . html_attr($combo_matricule->SelectedData) . '">';
	$combo_matricule->MatchText = '<span id="matricule-container-readonly' . $rnd1 . '"></span><input type="hidden" name="matricule" id="matricule' . $rnd1 . '" value="' . html_attr($combo_matricule->SelectedData) . '">';
	$combo_arabe->Render();
	$combo_francais->Render();
	$combo_anglais->Render();
	$combo_autres2->Render();
	$combo_utilisation->Render();
	$combo_programmation->Render();

	ob_start();
	?>

	<script>
		// initial lookup values
		AppGini.current_matricule__RAND__ = { text: "", value: "<?php echo addslashes($selected_id ? $urow['matricule'] : $filterer_matricule); ?>"};

		jQuery(function() {
			setTimeout(function(){
				if(typeof(matricule_reload__RAND__) == 'function') matricule_reload__RAND__();
			}, 10); /* we need to slightly delay client-side execution of the above code to allow AppGini.ajaxCache to work */
		});
		function matricule_reload__RAND__(){
		<?php if(($AllowUpdate || $AllowInsert) && !$dvprint){ ?>

			$j("#matricule-container__RAND__").select2({
				/* initial default value */
				initSelection: function(e, c){
					$j.ajax({
						url: 'ajax_combo.php',
						dataType: 'json',
						data: { id: AppGini.current_matricule__RAND__.value, t: 'informations', f: 'matricule' },
						success: function(resp){
							c({
								id: resp.results[0].id,
								text: resp.results[0].text
							});
							$j('[name="matricule"]').val(resp.results[0].id);
							$j('[id=matricule-container-readonly__RAND__]').html('<span id="matricule-match-text">' + resp.results[0].text + '</span>');
							if(resp.results[0].id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=dossier_individuel_view_parent]').hide(); }else{ $j('.btn[id=dossier_individuel_view_parent]').show(); }


							if(typeof(matricule_update_autofills__RAND__) == 'function') matricule_update_autofills__RAND__();
						}
					});
				},
				width: '100%',
				formatNoMatches: function(term){ /* */ return '<?php echo addslashes($Translation['No matches found!']); ?>'; },
				minimumResultsForSearch: 5,
				loadMorePadding: 200,
				ajax: {
					url: 'ajax_combo.php',
					dataType: 'json',
					cache: true,
					data: function(term, page){ /* */ return { s: term, p: page, t: 'informations', f: 'matricule' }; },
					results: function(resp, page){ /* */ return resp; }
				},
				escapeMarkup: function(str){ /* */ return str; }
			}).on('change', function(e){
				AppGini.current_matricule__RAND__.value = e.added.id;
				AppGini.current_matricule__RAND__.text = e.added.text;
				$j('[name="matricule"]').val(e.added.id);
				if(e.added.id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=dossier_individuel_view_parent]').hide(); }else{ $j('.btn[id=dossier_individuel_view_parent]').show(); }


				if(typeof(matricule_update_autofills__RAND__) == 'function') matricule_update_autofills__RAND__();
			});

			if(!$j("#matricule-container__RAND__").length){
				$j.ajax({
					url: 'ajax_combo.php',
					dataType: 'json',
					data: { id: AppGini.current_matricule__RAND__.value, t: 'informations', f: 'matricule' },
					success: function(resp){
						$j('[name="matricule"]').val(resp.results[0].id);
						$j('[id=matricule-container-readonly__RAND__]').html('<span id="matricule-match-text">' + resp.results[0].text + '</span>');
						if(resp.results[0].id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=dossier_individuel_view_parent]').hide(); }else{ $j('.btn[id=dossier_individuel_view_parent]').show(); }

						if(typeof(matricule_update_autofills__RAND__) == 'function') matricule_update_autofills__RAND__();
					}
				});
			}

		<?php }else{ ?>

			$j.ajax({
				url: 'ajax_combo.php',
				dataType: 'json',
				data: { id: AppGini.current_matricule__RAND__.value, t: 'informations', f: 'matricule' },
				success: function(resp){
					$j('[id=matricule-container__RAND__], [id=matricule-container-readonly__RAND__]').html('<span id="matricule-match-text">' + resp.results[0].text + '</span>');
					if(resp.results[0].id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=dossier_individuel_view_parent]').hide(); }else{ $j('.btn[id=dossier_individuel_view_parent]').show(); }

					if(typeof(matricule_update_autofills__RAND__) == 'function') matricule_update_autofills__RAND__();
				}
			});
		<?php } ?>

		}
	</script>
	<?php

	$lookups = str_replace('__RAND__', $rnd1, ob_get_contents());
	ob_end_clean();


	// code for template based detail view forms

	// open the detail view template
	if($dvprint){
		$template_file = is_file("./{$TemplateDVP}") ? "./{$TemplateDVP}" : './templates/informations_templateDVP.html';
		$templateCode = @file_get_contents($template_file);
	}else{
		$template_file = is_file("./{$TemplateDV}") ? "./{$TemplateDV}" : './templates/informations_templateDV.html';
		$templateCode = @file_get_contents($template_file);
	}

	// process form title
	$templateCode = str_replace('<%%DETAIL_VIEW_TITLE%%>', 'Informations', $templateCode);
	$templateCode = str_replace('<%%RND1%%>', $rnd1, $templateCode);
	$templateCode = str_replace('<%%EMBEDDED%%>', ($_REQUEST['Embedded'] ? 'Embedded=1' : ''), $templateCode);
	// process buttons
	if($AllowInsert){
		if(!$selected_id) $templateCode = str_replace('<%%INSERT_BUTTON%%>', '<button type="submit" class="btn btn-success" id="insert" name="insert_x" value="1" onclick="return informations_validateData();"><i class="glyphicon glyphicon-plus-sign"></i> ' . $Translation['Save New'] . '</button>', $templateCode);
		$templateCode = str_replace('<%%INSERT_BUTTON%%>', '<button type="submit" class="btn btn-default" id="insert" name="insert_x" value="1" onclick="return informations_validateData();"><i class="glyphicon glyphicon-plus-sign"></i> ' . $Translation['Save As Copy'] . '</button>', $templateCode);
	}else{
		$templateCode = str_replace('<%%INSERT_BUTTON%%>', '', $templateCode);
	}

	// 'Back' button action
	if($_REQUEST['Embedded']){
		$backAction = 'AppGini.closeParentModal(); return false;';
	}else{
		$backAction = '$j(\'form\').eq(0).attr(\'novalidate\', \'novalidate\'); document.myform.reset(); return true;';
	}

	if($selected_id){
		if(!$_REQUEST['Embedded']) $templateCode = str_replace('<%%DVPRINT_BUTTON%%>', '<button type="submit" class="btn btn-default" id="dvprint" name="dvprint_x" value="1" onclick="$j(\'form\').eq(0).prop(\'novalidate\', true); document.myform.reset(); return true;" title="' . html_attr($Translation['Print Preview']) . '"><i class="glyphicon glyphicon-print"></i> ' . $Translation['Print Preview'] . '</button>', $templateCode);
		if($AllowUpdate){
			$templateCode = str_replace('<%%UPDATE_BUTTON%%>', '<button type="submit" class="btn btn-success btn-lg" id="update" name="update_x" value="1" onclick="return informations_validateData();" title="' . html_attr($Translation['Save Changes']) . '"><i class="glyphicon glyphicon-ok"></i> ' . $Translation['Save Changes'] . '</button>', $templateCode);
		}else{
			$templateCode = str_replace('<%%UPDATE_BUTTON%%>', '', $templateCode);
		}
		if(($arrPerm[4]==1 && $ownerMemberID==getLoggedMemberID()) || ($arrPerm[4]==2 && $ownerGroupID==getLoggedGroupID()) || $arrPerm[4]==3){ // allow delete?
			$templateCode = str_replace('<%%DELETE_BUTTON%%>', '<button type="submit" class="btn btn-danger" id="delete" name="delete_x" value="1" onclick="return confirm(\'' . $Translation['are you sure?'] . '\');" title="' . html_attr($Translation['Delete']) . '"><i class="glyphicon glyphicon-trash"></i> ' . $Translation['Delete'] . '</button>', $templateCode);
		}else{
			$templateCode = str_replace('<%%DELETE_BUTTON%%>', '', $templateCode);
		}
		$templateCode = str_replace('<%%DESELECT_BUTTON%%>', '<button type="submit" class="btn btn-default" id="deselect" name="deselect_x" value="1" onclick="' . $backAction . '" title="' . html_attr($Translation['Back']) . '"><i class="glyphicon glyphicon-chevron-left"></i> ' . $Translation['Back'] . '</button>', $templateCode);
	}else{
		$templateCode = str_replace('<%%UPDATE_BUTTON%%>', '', $templateCode);
		$templateCode = str_replace('<%%DELETE_BUTTON%%>', '', $templateCode);
		$templateCode = str_replace('<%%DESELECT_BUTTON%%>', ($ShowCancel ? '<button type="submit" class="btn btn-default" id="deselect" name="deselect_x" value="1" onclick="' . $backAction . '" title="' . html_attr($Translation['Back']) . '"><i class="glyphicon glyphicon-chevron-left"></i> ' . $Translation['Back'] . '</button>' : ''), $templateCode);
	}

	// set records to read only if user can't insert new records and can't edit current record
	if(($selected_id && !$AllowUpdate && !$AllowInsert) || (!$selected_id && !$AllowInsert)){
		$jsReadOnly .= "\tjQuery('#matricule').prop('disabled', true).css({ color: '#555', backgroundColor: '#fff' });\n";
		$jsReadOnly .= "\tjQuery('#matricule_caption').prop('disabled', true).css({ color: '#555', backgroundColor: 'white' });\n";
		$jsReadOnly .= "\tjQuery('#diplome_primordial').replaceWith('<div class=\"form-control-static\" id=\"diplome_primordial\">' + (jQuery('#diplome_primordial').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#date_diplome').prop('readonly', true);\n";
		$jsReadOnly .= "\tjQuery('#date_diplomeDay, #date_diplomeMonth, #date_diplomeYear').prop('disabled', true).css({ color: '#555', backgroundColor: '#fff' });\n";
		$jsReadOnly .= "\tjQuery('#institution').replaceWith('<div class=\"form-control-static\" id=\"institution\">' + (jQuery('#institution').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#lieu_diplome').replaceWith('<div class=\"form-control-static\" id=\"lieu_diplome\">' + (jQuery('#lieu_diplome').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#diplome_certificat').replaceWith('<div class=\"form-control-static\" id=\"diplome_certificat\">' + (jQuery('#diplome_certificat').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#specialite').replaceWith('<div class=\"form-control-static\" id=\"specialite\">' + (jQuery('#specialite').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#institution_specialite').replaceWith('<div class=\"form-control-static\" id=\"institution_specialite\">' + (jQuery('#institution_specialite').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#lieu_specialite').replaceWith('<div class=\"form-control-static\" id=\"lieu_specialite\">' + (jQuery('#lieu_specialite').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#arabe').replaceWith('<div class=\"form-control-static\" id=\"arabe\">' + (jQuery('#arabe').val() || '') + '</div>'); jQuery('#arabe-multi-selection-help').hide();\n";
		$jsReadOnly .= "\tjQuery('#s2id_arabe').remove();\n";
		$jsReadOnly .= "\tjQuery('#francais').replaceWith('<div class=\"form-control-static\" id=\"francais\">' + (jQuery('#francais').val() || '') + '</div>'); jQuery('#francais-multi-selection-help').hide();\n";
		$jsReadOnly .= "\tjQuery('#s2id_francais').remove();\n";
		$jsReadOnly .= "\tjQuery('#anglais').replaceWith('<div class=\"form-control-static\" id=\"anglais\">' + (jQuery('#anglais').val() || '') + '</div>'); jQuery('#anglais-multi-selection-help').hide();\n";
		$jsReadOnly .= "\tjQuery('#s2id_anglais').remove();\n";
		$jsReadOnly .= "\tjQuery('#autres1').replaceWith('<div class=\"form-control-static\" id=\"autres1\">' + (jQuery('#autres1').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#autres2').replaceWith('<div class=\"form-control-static\" id=\"autres2\">' + (jQuery('#autres2').val() || '') + '</div>'); jQuery('#autres2-multi-selection-help').hide();\n";
		$jsReadOnly .= "\tjQuery('#s2id_autres2').remove();\n";
		$jsReadOnly .= "\tjQuery('#utilisation').replaceWith('<div class=\"form-control-static\" id=\"utilisation\">' + (jQuery('#utilisation').val() || '') + '</div>'); jQuery('#utilisation-multi-selection-help').hide();\n";
		$jsReadOnly .= "\tjQuery('#programmation').replaceWith('<div class=\"form-control-static\" id=\"programmation\">' + (jQuery('#programmation').val() || '') + '</div>'); jQuery('#programmation-multi-selection-help').hide();\n";
		$jsReadOnly .= "\tjQuery('.select2-container').hide();\n";

		$noUploads = true;
	}elseif($AllowInsert){
		$jsEditable .= "\tjQuery('form').eq(0).data('already_changed', true);"; // temporarily disable form change handler
			$jsEditable .= "\tjQuery('form').eq(0).data('already_changed', false);"; // re-enable form change handler
	}

	// process combos
	$templateCode = str_replace('<%%COMBO(matricule)%%>', $combo_matricule->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(matricule)%%>', $combo_matricule->MatchText, $templateCode);
	$templateCode = str_replace('<%%URLCOMBOTEXT(matricule)%%>', urlencode($combo_matricule->MatchText), $templateCode);
	$templateCode = str_replace('<%%COMBO(date_diplome)%%>', ($selected_id && !$arrPerm[3] ? '<div class="form-control-static">' . $combo_date_diplome->GetHTML(true) . '</div>' : $combo_date_diplome->GetHTML()), $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(date_diplome)%%>', $combo_date_diplome->GetHTML(true), $templateCode);
	$templateCode = str_replace('<%%COMBO(arabe)%%>', $combo_arabe->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(arabe)%%>', $combo_arabe->SelectedData, $templateCode);
	$templateCode = str_replace('<%%COMBO(francais)%%>', $combo_francais->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(francais)%%>', $combo_francais->SelectedData, $templateCode);
	$templateCode = str_replace('<%%COMBO(anglais)%%>', $combo_anglais->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(anglais)%%>', $combo_anglais->SelectedData, $templateCode);
	$templateCode = str_replace('<%%COMBO(autres2)%%>', $combo_autres2->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(autres2)%%>', $combo_autres2->SelectedData, $templateCode);
	$templateCode = str_replace('<%%COMBO(utilisation)%%>', $combo_utilisation->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(utilisation)%%>', $combo_utilisation->SelectedData, $templateCode);
	$templateCode = str_replace('<%%COMBO(programmation)%%>', $combo_programmation->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(programmation)%%>', $combo_programmation->SelectedData, $templateCode);

	/* lookup fields array: 'lookup field name' => array('parent table name', 'lookup field caption') */
	$lookup_fields = array(  'matricule' => array('dossier_individuel', 'Matricule'));
	foreach($lookup_fields as $luf => $ptfc){
		$pt_perm = getTablePermissions($ptfc[0]);

		// process foreign key links
		if($pt_perm['view'] || $pt_perm['edit']){
			$templateCode = str_replace("<%%PLINK({$luf})%%>", '<button type="button" class="btn btn-default view_parent hspacer-md" id="' . $ptfc[0] . '_view_parent" title="' . html_attr($Translation['View'] . ' ' . $ptfc[1]) . '"><i class="glyphicon glyphicon-eye-open"></i></button>', $templateCode);
		}

		// if user has insert permission to parent table of a lookup field, put an add new button
		if($pt_perm['insert'] && !$_REQUEST['Embedded']){
			$templateCode = str_replace("<%%ADDNEW({$ptfc[0]})%%>", '<button type="button" class="btn btn-success add_new_parent hspacer-md" id="' . $ptfc[0] . '_add_new" title="' . html_attr($Translation['Add New'] . ' ' . $ptfc[1]) . '"><i class="glyphicon glyphicon-plus-sign"></i></button>', $templateCode);
		}
	}

	// process images
	$templateCode = str_replace('<%%UPLOADFILE(idinformation)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(situation)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(matricule)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(education)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(diplome_primordial)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(date_diplome)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(institution)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(lieu_diplome)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(diplome_certificat)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(specialite)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(institution_specialite)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(lieu_specialite)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(langues)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(arabe)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(francais)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(anglais)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(autres1)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(autres2)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(informatique)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(utilisation)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(programmation)%%>', '', $templateCode);

	// process values
	if($selected_id){
		if( $dvprint) $templateCode = str_replace('<%%VALUE(idinformation)%%>', safe_html($urow['idinformation']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(idinformation)%%>', html_attr($row['idinformation']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(idinformation)%%>', urlencode($urow['idinformation']), $templateCode);
		$templateCode = str_replace('<%%VALUE(situation)%%>', safe_html($urow['situation']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(situation)%%>', urlencode($urow['situation']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(matricule)%%>', safe_html($urow['matricule']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(matricule)%%>', html_attr($row['matricule']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(matricule)%%>', urlencode($urow['matricule']), $templateCode);
		$templateCode = str_replace('<%%VALUE(education)%%>', safe_html($urow['education']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(education)%%>', urlencode($urow['education']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(diplome_primordial)%%>', safe_html($urow['diplome_primordial']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(diplome_primordial)%%>', html_attr($row['diplome_primordial']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(diplome_primordial)%%>', urlencode($urow['diplome_primordial']), $templateCode);
		$templateCode = str_replace('<%%VALUE(date_diplome)%%>', @date('d/m/Y', @strtotime(html_attr($row['date_diplome']))), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(date_diplome)%%>', urlencode(@date('d/m/Y', @strtotime(html_attr($urow['date_diplome'])))), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(institution)%%>', safe_html($urow['institution']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(institution)%%>', html_attr($row['institution']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(institution)%%>', urlencode($urow['institution']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(lieu_diplome)%%>', safe_html($urow['lieu_diplome']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(lieu_diplome)%%>', html_attr($row['lieu_diplome']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(lieu_diplome)%%>', urlencode($urow['lieu_diplome']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(diplome_certificat)%%>', safe_html($urow['diplome_certificat']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(diplome_certificat)%%>', html_attr($row['diplome_certificat']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(diplome_certificat)%%>', urlencode($urow['diplome_certificat']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(specialite)%%>', safe_html($urow['specialite']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(specialite)%%>', html_attr($row['specialite']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(specialite)%%>', urlencode($urow['specialite']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(institution_specialite)%%>', safe_html($urow['institution_specialite']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(institution_specialite)%%>', html_attr($row['institution_specialite']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(institution_specialite)%%>', urlencode($urow['institution_specialite']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(lieu_specialite)%%>', safe_html($urow['lieu_specialite']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(lieu_specialite)%%>', html_attr($row['lieu_specialite']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(lieu_specialite)%%>', urlencode($urow['lieu_specialite']), $templateCode);
		$templateCode = str_replace('<%%VALUE(langues)%%>', safe_html($urow['langues']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(langues)%%>', urlencode($urow['langues']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(arabe)%%>', safe_html($urow['arabe']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(arabe)%%>', html_attr($row['arabe']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(arabe)%%>', urlencode($urow['arabe']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(francais)%%>', safe_html($urow['francais']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(francais)%%>', html_attr($row['francais']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(francais)%%>', urlencode($urow['francais']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(anglais)%%>', safe_html($urow['anglais']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(anglais)%%>', html_attr($row['anglais']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(anglais)%%>', urlencode($urow['anglais']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(autres1)%%>', safe_html($urow['autres1']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(autres1)%%>', html_attr($row['autres1']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(autres1)%%>', urlencode($urow['autres1']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(autres2)%%>', safe_html($urow['autres2']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(autres2)%%>', html_attr($row['autres2']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(autres2)%%>', urlencode($urow['autres2']), $templateCode);
		$templateCode = str_replace('<%%VALUE(informatique)%%>', safe_html($urow['informatique']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(informatique)%%>', urlencode($urow['informatique']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(utilisation)%%>', safe_html($urow['utilisation']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(utilisation)%%>', html_attr($row['utilisation']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(utilisation)%%>', urlencode($urow['utilisation']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(programmation)%%>', safe_html($urow['programmation']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(programmation)%%>', html_attr($row['programmation']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(programmation)%%>', urlencode($urow['programmation']), $templateCode);
	}else{
		$templateCode = str_replace('<%%VALUE(idinformation)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(idinformation)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(situation)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(situation)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(matricule)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(matricule)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(education)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(education)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(diplome_primordial)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(diplome_primordial)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(date_diplome)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(date_diplome)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(institution)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(institution)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(lieu_diplome)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(lieu_diplome)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(diplome_certificat)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(diplome_certificat)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(specialite)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(specialite)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(institution_specialite)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(institution_specialite)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(lieu_specialite)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(lieu_specialite)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(langues)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(langues)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(arabe)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(arabe)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(francais)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(francais)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(anglais)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(anglais)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(autres1)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(autres1)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(autres2)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(autres2)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(informatique)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(informatique)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(utilisation)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(utilisation)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(programmation)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(programmation)%%>', urlencode(''), $templateCode);
	}

	// process translations
	foreach($Translation as $symbol=>$trans){
		$templateCode = str_replace("<%%TRANSLATION($symbol)%%>", $trans, $templateCode);
	}

	// clear scrap
	$templateCode = str_replace('<%%', '<!-- ', $templateCode);
	$templateCode = str_replace('%%>', ' -->', $templateCode);

	// hide links to inaccessible tables
	if($_REQUEST['dvprint_x'] == ''){
		$templateCode .= "\n\n<script>\$j(function(){\n";
		$arrTables = getTableList();
		foreach($arrTables as $name => $caption){
			$templateCode .= "\t\$j('#{$name}_link').removeClass('hidden');\n";
			$templateCode .= "\t\$j('#xs_{$name}_link').removeClass('hidden');\n";
		}

		$templateCode .= $jsReadOnly;
		$templateCode .= $jsEditable;

		if(!$selected_id){
		}

		$templateCode.="\n});</script>\n";
	}

	// ajaxed auto-fill fields
	$templateCode .= '<script>';
	$templateCode .= '$j(function() {';

	$templateCode .= "\tmatricule_update_autofills$rnd1 = function(){\n";
	$templateCode .= "\t\t\$j.ajax({\n";
	if($dvprint) {
		$templateCode .= "\t\t\turl: 'informations_autofill.php?rnd1=$rnd1&mfk=matricule&id=' + encodeURIComponent('".addslashes($row['matricule'])."'),\n";
		$templateCode .= "\t\t\tcontentType: 'application/x-www-form-urlencoded; charset=" . datalist_db_encoding . "',\n";
		$templateCode .= "\t\t\ttype: 'GET'\n";
	} else {
		$templateCode .= "\t\t\turl: 'informations_autofill.php?rnd1=$rnd1&mfk=matricule&id=' + encodeURIComponent(AppGini.current_matricule{$rnd1}.value),\n";
		$templateCode .= "\t\t\tcontentType: 'application/x-www-form-urlencoded; charset=" . datalist_db_encoding . "',\n";
		$templateCode .= "\t\t\ttype: 'GET',\n";
		$templateCode .= "\t\t\tbeforeSend: function() { \$j('#matricule$rnd1').prop('disabled', true); \$j('#matriculeLoading').html('<img src=loading.gif align=top>'); },\n";
		$templateCode .= "\t\t\tcomplete: function() { " . (($arrPerm[1] || (($arrPerm[3] == 1 && $ownerMemberID == getLoggedMemberID()) || ($arrPerm[3] == 2 && $ownerGroupID == getLoggedGroupID()) || $arrPerm[3] == 3)) ? "\$j('#matricule$rnd1').prop('disabled', false); " : "\$j('#matricule$rnd1').prop('disabled', true); ")."\$j('#matriculeLoading').html(''); \$j(window).resize(); }\n";
	}
	$templateCode .= "\t\t});\n";
	$templateCode .= "\t};\n";
	if(!$dvprint) $templateCode .= "\tif(\$j('#matricule_caption').length) \$j('#matricule_caption').click(function(){ /* */ matricule_update_autofills$rnd1(); });\n";


	$templateCode.="});";
	$templateCode.="</script>";
	$templateCode .= $lookups;

	// handle enforced parent values for read-only lookup fields

	// don't include blank images in lightbox gallery
	$templateCode = preg_replace('/blank.gif" data-lightbox=".*?"/', 'blank.gif"', $templateCode);

	// don't display empty email links
	$templateCode=preg_replace('/<a .*?href="mailto:".*?<\/a>/', '', $templateCode);

	/* default field values */
	$rdata = $jdata = get_defaults('informations');
	if($selected_id){
		$jdata = get_joined_record('informations', $selected_id);
		if($jdata === false) $jdata = get_defaults('informations');
		$rdata = $row;
	}
	$templateCode .= loadView('informations-ajax-cache', array('rdata' => $rdata, 'jdata' => $jdata));

	// hook: informations_dv
	if(function_exists('informations_dv')){
		$args=array();
		informations_dv(($selected_id ? $selected_id : FALSE), getMemberInfo(), $templateCode, $args);
	}

	return $templateCode;
}
?>