<?php

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

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

function dossier_individuel_insert(){
	global $Translation;

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

	$data['matricule'] = makeSafe($_REQUEST['matricule']);
		if($data['matricule'] == empty_lookup_value){ $data['matricule'] = ''; }
	$data['nom_prenom'] = makeSafe($_REQUEST['nom_prenom']);
		if($data['nom_prenom'] == empty_lookup_value){ $data['nom_prenom'] = ''; }
	$data['date_naissance'] = intval($_REQUEST['date_naissanceYear']) . '-' . intval($_REQUEST['date_naissanceMonth']) . '-' . intval($_REQUEST['date_naissanceDay']);
	$data['date_naissance'] = parseMySQLDate($data['date_naissance'], '1');
	$data['matrimoniale'] = makeSafe($_REQUEST['matrimoniale']);
		if($data['matrimoniale'] == empty_lookup_value){ $data['matrimoniale'] = ''; }
	$data['enfants'] = makeSafe($_REQUEST['enfants']);
		if($data['enfants'] == empty_lookup_value){ $data['enfants'] = ''; }
	$data['nni'] = makeSafe($_REQUEST['nni']);
		if($data['nni'] == empty_lookup_value){ $data['nni'] = ''; }
	$data['telephone'] = makeSafe($_REQUEST['telephone']);
		if($data['telephone'] == empty_lookup_value){ $data['telephone'] = ''; }
	$data['courriel'] = makeSafe($_REQUEST['courriel']);
		if($data['courriel'] == empty_lookup_value){ $data['courriel'] = ''; }
	$data['postale'] = makeSafe($_REQUEST['postale']);
		if($data['postale'] == empty_lookup_value){ $data['postale'] = ''; }
	$data['date_recrutement'] = intval($_REQUEST['date_recrutementYear']) . '-' . intval($_REQUEST['date_recrutementMonth']) . '-' . intval($_REQUEST['date_recrutementDay']);
	$data['date_recrutement'] = parseMySQLDate($data['date_recrutement'], '1');
	$data['fonction'] = makeSafe($_REQUEST['fonction']);
		if($data['fonction'] == empty_lookup_value){ $data['fonction'] = ''; }
	$data['direction'] = makeSafe($_REQUEST['direction']);
		if($data['direction'] == empty_lookup_value){ $data['direction'] = ''; }
	$data['service'] = makeSafe($_REQUEST['service']);
		if($data['service'] == empty_lookup_value){ $data['service'] = ''; }
	$data['division'] = makeSafe($_REQUEST['division']);
		if($data['division'] == empty_lookup_value){ $data['division'] = ''; }
	$data['categorie'] = makeSafe($_REQUEST['categorie']);
		if($data['categorie'] == empty_lookup_value){ $data['categorie'] = ''; }
	$data['statut'] = makeSafe($_REQUEST['statut']);
		if($data['statut'] == empty_lookup_value){ $data['statut'] = ''; }
	$data['salaire'] = makeSafe($_REQUEST['salaire']);
		if($data['salaire'] == empty_lookup_value){ $data['salaire'] = ''; }
	$data['prime_ts'] = makeSafe($_REQUEST['categorie']);
		if($data['prime_ts'] == empty_lookup_value){ $data['prime_ts'] = ''; }
	$data['compte'] = makeSafe($_REQUEST['compte']);
		if($data['compte'] == empty_lookup_value){ $data['compte'] = ''; }
	$data['banque'] = makeSafe($_REQUEST['banque']);
		if($data['banque'] == empty_lookup_value){ $data['banque'] = ''; }
	$data['observation'] = br2nl(makeSafe($_REQUEST['observation']));
	$data['photo'] = PrepareUploadedFile('photo', 1024000,'jpg|jpeg|gif|png', false, '');
	if($data['photo']) createThumbnail($data['photo'], getThumbnailSpecs('dossier_individuel', 'photo', 'tv'));
	if($data['photo']) createThumbnail($data['photo'], getThumbnailSpecs('dossier_individuel', 'photo', 'dv'));
	if($data['total_income'] == '') $data['total_income'] = "0";
	if($data['total_expense'] == '') $data['total_expense'] = "0";
	if($data['available_budget'] == '') $data['available_budget'] = "0";

	/* for empty upload fields, when saving a copy of an existing record, copy the original upload field */
	if($_REQUEST['SelectedID']){
		$res = sql("select * from dossier_individuel where iddindividuel='" . makeSafe($_REQUEST['SelectedID']) . "'", $eo);
		if($row = db_fetch_assoc($res)){
			if(!$data['photo']) $data['photo'] = makeSafe($row['photo']);
		}
	}

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

	$o = array('silentErrors' => true);
	sql('insert into `dossier_individuel` set       ' . ($data['photo'] != '' ? "`photo`='{$data['photo']}'" : '`photo`=NULL') . ', `matricule`=' . (($data['matricule'] !== '' && $data['matricule'] !== NULL) ? "'{$data['matricule']}'" : 'NULL') . ', `nom_prenom`=' . (($data['nom_prenom'] !== '' && $data['nom_prenom'] !== NULL) ? "'{$data['nom_prenom']}'" : 'NULL') . ', `date_naissance`=' . (($data['date_naissance'] !== '' && $data['date_naissance'] !== NULL) ? "'{$data['date_naissance']}'" : 'NULL') . ', `matrimoniale`=' . (($data['matrimoniale'] !== '' && $data['matrimoniale'] !== NULL) ? "'{$data['matrimoniale']}'" : 'NULL') . ', `enfants`=' . (($data['enfants'] !== '' && $data['enfants'] !== NULL) ? "'{$data['enfants']}'" : 'NULL') . ', `nni`=' . (($data['nni'] !== '' && $data['nni'] !== NULL) ? "'{$data['nni']}'" : 'NULL') . ', `telephone`=' . (($data['telephone'] !== '' && $data['telephone'] !== NULL) ? "'{$data['telephone']}'" : 'NULL') . ', `courriel`=' . (($data['courriel'] !== '' && $data['courriel'] !== NULL) ? "'{$data['courriel']}'" : 'NULL') . ', `postale`=' . (($data['postale'] !== '' && $data['postale'] !== NULL) ? "'{$data['postale']}'" : 'NULL') . ', `date_recrutement`=' . (($data['date_recrutement'] !== '' && $data['date_recrutement'] !== NULL) ? "'{$data['date_recrutement']}'" : 'NULL') . ', `fonction`=' . (($data['fonction'] !== '' && $data['fonction'] !== NULL) ? "'{$data['fonction']}'" : 'NULL') . ', `direction`=' . (($data['direction'] !== '' && $data['direction'] !== NULL) ? "'{$data['direction']}'" : 'NULL') . ', `service`=' . (($data['service'] !== '' && $data['service'] !== NULL) ? "'{$data['service']}'" : 'NULL') . ', `division`=' . (($data['division'] !== '' && $data['division'] !== NULL) ? "'{$data['division']}'" : 'NULL') . ', `categorie`=' . (($data['categorie'] !== '' && $data['categorie'] !== NULL) ? "'{$data['categorie']}'" : 'NULL') . ', `statut`=' . (($data['statut'] !== '' && $data['statut'] !== NULL) ? "'{$data['statut']}'" : 'NULL') . ', `salaire`=' . (($data['salaire'] !== '' && $data['salaire'] !== NULL) ? "'{$data['salaire']}'" : 'NULL') . ', `prime_ts`=' . (($data['prime_ts'] !== '' && $data['prime_ts'] !== NULL) ? "'{$data['prime_ts']}'" : 'NULL') . ', `compte`=' . (($data['compte'] !== '' && $data['compte'] !== NULL) ? "'{$data['compte']}'" : 'NULL') . ', `banque`=' . (($data['banque'] !== '' && $data['banque'] !== NULL) ? "'{$data['banque']}'" : 'NULL') . ', `observation`=' . (($data['observation'] !== '' && $data['observation'] !== NULL) ? "'{$data['observation']}'" : 'NULL'), $o);
	if($o['error']!=''){
		echo $o['error'];
		echo "<a href=\"dossier_individuel_view.php?addNew_x=1\">{$Translation['< back']}</a>";
		exit;
	}

	$recID = db_insert_id(db_link());

	// hook: dossier_individuel_after_insert
	if(function_exists('dossier_individuel_after_insert')){
		$res = sql("select * from `dossier_individuel` where `iddindividuel`='" . 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(!dossier_individuel_after_insert($data, getMemberInfo(), $args)){ return $recID; }
	}

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

	return $recID;
}

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

	// mm: can member delete record?
	$arrPerm=getTablePermissions('dossier_individuel');
	$ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='dossier_individuel' and pkValue='$selected_id'");
	$ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='dossier_individuel' 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: dossier_individuel_before_delete
	if(function_exists('dossier_individuel_before_delete')){
		$args=array();
		if(!dossier_individuel_before_delete($selected_id, $skipChecks, getMemberInfo(), $args))
			return $Translation['Couldn\'t delete this record'];
	}

	// child table: gestion_salaire
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `gestion_salaire` where `matricule`='".addslashes($iddindividuel[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>", "gestion_salaire", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "gestion_salaire", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: gestion_prime
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `gestion_prime` where `matricule`='".addslashes($iddindividuel[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>", "gestion_prime", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "gestion_prime", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: etat_paiements
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `etat_paiements` where `matricule`='".addslashes($iddindividuel[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>", "etat_paiements", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "etat_paiements", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: etat_banques
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `etat_banques` where `matricule`='".addslashes($iddindividuel[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>", "etat_banques", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "etat_banques", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: fiche_pointages
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `fiche_pointages` where `nom_prenom_fp`='".addslashes($iddindividuel[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>", "fiche_pointages", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "fiche_pointages", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: permissions
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `permissions` where `nom_prenom`='".addslashes($iddindividuel[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>", "permissions", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "permissions", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: conges
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `conges` where `nom_prenom`='".addslashes($iddindividuel[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>", "conges", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "conges", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: demandes_permission
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `demandes_permission` where `matricule`='".addslashes($iddindividuel[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>", "demandes_permission", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "demandes_permission", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: demandes_conge_m
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `demandes_conge_m` where `matricule`='".addslashes($iddindividuel[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>", "demandes_conge_m", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "demandes_conge_m", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: demandes_permissions
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `demandes_permissions` where `matricule`='".addslashes($iddindividuel[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>", "demandes_permissions", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "demandes_permissions", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: demandes_conge_sg
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `demandes_conge_sg` where `matricule`='".addslashes($iddindividuel[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>", "demandes_conge_sg", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "demandes_conge_sg", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: conges_permissions
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `conges_permissions` where `matricule`='".addslashes($iddindividuel[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>", "conges_permissions", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "conges_permissions", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: demandes_conge
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `demandes_conge` where `matricule`='".addslashes($iddindividuel[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>", "demandes_conge", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "demandes_conge", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: formations
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `formations` where `matricule`='".addslashes($iddindividuel[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>", "formations", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "formations", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: informations
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `informations` where `matricule`='".addslashes($iddindividuel[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>", "informations", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "informations", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: carrieres
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `carrieres` where `matricule`='".addslashes($iddindividuel[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>", "carrieres", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "carrieres", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: demandes
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `demandes` where `matricule`='".addslashes($iddindividuel[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>", "demandes", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "demandes", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: ordres_missions
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `ordres_missions` where `nom_prenom`='".addslashes($iddindividuel[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>", "ordres_missions", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "ordres_missions", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: decomptes
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `decomptes` where `matricule`='".addslashes($iddindividuel[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>", "decomptes", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "decomptes", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: incomes
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `incomes` where `client`='".addslashes($iddindividuel[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>", "incomes", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "incomes", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: expenses
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `expenses` where `matricule`='".addslashes($iddindividuel[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>", "expenses", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "expenses", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	// child table: curriculum_vitae
	$res = sql("select `iddindividuel` from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);
	$iddindividuel = db_fetch_row($res);
	$rires = sql("select count(1) from `curriculum_vitae` where `matricule`='".addslashes($iddindividuel[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>", "curriculum_vitae", $RetMsg);
		return $RetMsg;
	}elseif($rirow[0] && $AllowDeleteOfParents && !$skipChecks){
		$RetMsg = $Translation["confirm delete"];
		$RetMsg = str_replace("<RelatedRecords>", $rirow[0], $RetMsg);
		$RetMsg = str_replace("<TableName>", "curriculum_vitae", $RetMsg);
		$RetMsg = str_replace("<Delete>", "<input type=\"button\" class=\"button\" value=\"".$Translation['yes']."\" onClick=\"window.location='dossier_individuel_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='dossier_individuel_view.php?SelectedID=".urlencode($selected_id)."';\">", $RetMsg);
		return $RetMsg;
	}

	sql("delete from `dossier_individuel` where `iddindividuel`='$selected_id'", $eo);

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

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

function dossier_individuel_update($selected_id){
	global $Translation;

	// mm: can member edit record?
	$arrPerm=getTablePermissions('dossier_individuel');
	$ownerGroupID=sqlValue("select groupID from membership_userrecords where tableName='dossier_individuel' and pkValue='".makeSafe($selected_id)."'");
	$ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='dossier_individuel' 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['nom_prenom']);
		if($data['nom_prenom'] == empty_lookup_value){ $data['nom_prenom'] = ''; }
	$data['date_naissance'] = intval($_REQUEST['date_naissanceYear']) . '-' . intval($_REQUEST['date_naissanceMonth']) . '-' . intval($_REQUEST['date_naissanceDay']);
	$data['date_naissance'] = parseMySQLDate($data['date_naissance'], '1');
	$data['matrimoniale'] = makeSafe($_REQUEST['matrimoniale']);
		if($data['matrimoniale'] == empty_lookup_value){ $data['matrimoniale'] = ''; }
	$data['enfants'] = makeSafe($_REQUEST['enfants']);
		if($data['enfants'] == empty_lookup_value){ $data['enfants'] = ''; }
	$data['nni'] = makeSafe($_REQUEST['nni']);
		if($data['nni'] == empty_lookup_value){ $data['nni'] = ''; }
	$data['telephone'] = makeSafe($_REQUEST['telephone']);
		if($data['telephone'] == empty_lookup_value){ $data['telephone'] = ''; }
	$data['courriel'] = makeSafe($_REQUEST['courriel']);
		if($data['courriel'] == empty_lookup_value){ $data['courriel'] = ''; }
	$data['postale'] = makeSafe($_REQUEST['postale']);
		if($data['postale'] == empty_lookup_value){ $data['postale'] = ''; }
	$data['date_recrutement'] = intval($_REQUEST['date_recrutementYear']) . '-' . intval($_REQUEST['date_recrutementMonth']) . '-' . intval($_REQUEST['date_recrutementDay']);
	$data['date_recrutement'] = parseMySQLDate($data['date_recrutement'], '1');
	$data['fonction'] = makeSafe($_REQUEST['fonction']);
		if($data['fonction'] == empty_lookup_value){ $data['fonction'] = ''; }
	$data['direction'] = makeSafe($_REQUEST['direction']);
		if($data['direction'] == empty_lookup_value){ $data['direction'] = ''; }
	$data['service'] = makeSafe($_REQUEST['service']);
		if($data['service'] == empty_lookup_value){ $data['service'] = ''; }
	$data['division'] = makeSafe($_REQUEST['division']);
		if($data['division'] == empty_lookup_value){ $data['division'] = ''; }
	$data['categorie'] = makeSafe($_REQUEST['categorie']);
		if($data['categorie'] == empty_lookup_value){ $data['categorie'] = ''; }
	$data['statut'] = makeSafe($_REQUEST['statut']);
		if($data['statut'] == empty_lookup_value){ $data['statut'] = ''; }
	$data['salaire'] = makeSafe($_REQUEST['salaire']);
		if($data['salaire'] == empty_lookup_value){ $data['salaire'] = ''; }
	$data['prime_ts'] = makeSafe($_REQUEST['categorie']);
		if($data['prime_ts'] == empty_lookup_value){ $data['prime_ts'] = ''; }
	$data['compte'] = makeSafe($_REQUEST['compte']);
		if($data['compte'] == empty_lookup_value){ $data['compte'] = ''; }
	$data['banque'] = makeSafe($_REQUEST['banque']);
		if($data['banque'] == empty_lookup_value){ $data['banque'] = ''; }
	$data['observation'] = br2nl(makeSafe($_REQUEST['observation']));
	$data['selectedID']=makeSafe($selected_id);
	if($_REQUEST['photo_remove'] == 1){
		$data['photo'] = '';
	}else{
		$data['photo'] = PrepareUploadedFile('photo', 1024000, 'jpg|jpeg|gif|png', false, "");
		if($data['photo']) createThumbnail($data['photo'], getThumbnailSpecs('dossier_individuel', 'photo', 'tv'));
		if($data['photo']) createThumbnail($data['photo'], getThumbnailSpecs('dossier_individuel', 'photo', 'dv'));
	}

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

	$o=array('silentErrors' => true);
	sql('update `dossier_individuel` set       ' . ($data['photo']!='' ? "`photo`='{$data['photo']}'" : ($_REQUEST['photo_remove'] != 1 ? '`photo`=`photo`' : '`photo`=NULL')) . ', `matricule`=' . (($data['matricule'] !== '' && $data['matricule'] !== NULL) ? "'{$data['matricule']}'" : 'NULL') . ', `nom_prenom`=' . (($data['nom_prenom'] !== '' && $data['nom_prenom'] !== NULL) ? "'{$data['nom_prenom']}'" : 'NULL') . ', `date_naissance`=' . (($data['date_naissance'] !== '' && $data['date_naissance'] !== NULL) ? "'{$data['date_naissance']}'" : 'NULL') . ', `matrimoniale`=' . (($data['matrimoniale'] !== '' && $data['matrimoniale'] !== NULL) ? "'{$data['matrimoniale']}'" : 'NULL') . ', `enfants`=' . (($data['enfants'] !== '' && $data['enfants'] !== NULL) ? "'{$data['enfants']}'" : 'NULL') . ', `nni`=' . (($data['nni'] !== '' && $data['nni'] !== NULL) ? "'{$data['nni']}'" : 'NULL') . ', `telephone`=' . (($data['telephone'] !== '' && $data['telephone'] !== NULL) ? "'{$data['telephone']}'" : 'NULL') . ', `courriel`=' . (($data['courriel'] !== '' && $data['courriel'] !== NULL) ? "'{$data['courriel']}'" : 'NULL') . ', `postale`=' . (($data['postale'] !== '' && $data['postale'] !== NULL) ? "'{$data['postale']}'" : 'NULL') . ', `date_recrutement`=' . (($data['date_recrutement'] !== '' && $data['date_recrutement'] !== NULL) ? "'{$data['date_recrutement']}'" : 'NULL') . ', `fonction`=' . (($data['fonction'] !== '' && $data['fonction'] !== NULL) ? "'{$data['fonction']}'" : 'NULL') . ', `direction`=' . (($data['direction'] !== '' && $data['direction'] !== NULL) ? "'{$data['direction']}'" : 'NULL') . ', `service`=' . (($data['service'] !== '' && $data['service'] !== NULL) ? "'{$data['service']}'" : 'NULL') . ', `division`=' . (($data['division'] !== '' && $data['division'] !== NULL) ? "'{$data['division']}'" : 'NULL') . ', `categorie`=' . (($data['categorie'] !== '' && $data['categorie'] !== NULL) ? "'{$data['categorie']}'" : 'NULL') . ', `statut`=' . (($data['statut'] !== '' && $data['statut'] !== NULL) ? "'{$data['statut']}'" : 'NULL') . ', `salaire`=' . (($data['salaire'] !== '' && $data['salaire'] !== NULL) ? "'{$data['salaire']}'" : 'NULL') . ', `prime_ts`=' . (($data['prime_ts'] !== '' && $data['prime_ts'] !== NULL) ? "'{$data['prime_ts']}'" : 'NULL') . ', `compte`=' . (($data['compte'] !== '' && $data['compte'] !== NULL) ? "'{$data['compte']}'" : 'NULL') . ', `banque`=' . (($data['banque'] !== '' && $data['banque'] !== NULL) ? "'{$data['banque']}'" : 'NULL') . ', `observation`=' . (($data['observation'] !== '' && $data['observation'] !== NULL) ? "'{$data['observation']}'" : 'NULL') . " where `iddindividuel`='".makeSafe($selected_id)."'", $o);
	if($o['error']!=''){
		echo $o['error'];
		echo '<a href="dossier_individuel_view.php?SelectedID='.urlencode($selected_id)."\">{$Translation['< back']}</a>";
		exit;
	}


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

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

}

function dossier_individuel_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('dossier_individuel');
	if(!$arrPerm[1] && $selected_id==''){ return ''; }
	$AllowInsert = ($arrPerm[1] ? true : false);
	// print preview?
	$dvprint = false;
	if($selected_id && $_REQUEST['dvprint_x'] != ''){
		$dvprint = true;
	}

	$filterer_fonction = thisOr(undo_magic_quotes($_REQUEST['filterer_fonction']), '');
	$filterer_direction = thisOr(undo_magic_quotes($_REQUEST['filterer_direction']), '');
	$filterer_service = thisOr(undo_magic_quotes($_REQUEST['filterer_service']), '');
	$filterer_division = thisOr(undo_magic_quotes($_REQUEST['filterer_division']), '');
	$filterer_categorie = thisOr(undo_magic_quotes($_REQUEST['filterer_categorie']), '');
	$filterer_statut = thisOr(undo_magic_quotes($_REQUEST['filterer_statut']), '');
	$filterer_banque = thisOr(undo_magic_quotes($_REQUEST['filterer_banque']), '');

	// populate filterers, starting from children to grand-parents
	if($filterer_service && !$filterer_direction) $filterer_direction = sqlValue("select from_direction from services where idservice='" . makeSafe($filterer_service) . "'");
	if($filterer_division && !$filterer_service) $filterer_service = sqlValue("select to_services from divisions where iddivision='" . makeSafe($filterer_division) . "'");

	// unique random identifier
	$rnd1 = ($dvprint ? rand(1000000, 9999999) : '');
	// combobox: date_naissance
	$combo_date_naissance = new DateCombo;
	$combo_date_naissance->DateFormat = "dmy";
	$combo_date_naissance->MinYear = 1900;
	$combo_date_naissance->MaxYear = 2100;
	$combo_date_naissance->DefaultDate = parseMySQLDate('1', '1');
	$combo_date_naissance->MonthNames = $Translation['month names'];
	$combo_date_naissance->NamePrefix = 'date_naissance';
	// combobox: matrimoniale
	$combo_matrimoniale = new Combo;
	$combo_matrimoniale->ListType = 0;
	$combo_matrimoniale->MultipleSeparator = ', ';
	$combo_matrimoniale->ListBoxHeight = 10;
	$combo_matrimoniale->RadiosPerLine = 1;
	if(is_file(dirname(__FILE__).'/hooks/dossier_individuel.matrimoniale.csv')){
		$matrimoniale_data = addslashes(implode('', @file(dirname(__FILE__).'/hooks/dossier_individuel.matrimoniale.csv')));
		$combo_matrimoniale->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions($matrimoniale_data)));
		$combo_matrimoniale->ListData = $combo_matrimoniale->ListItem;
	}else{
		$combo_matrimoniale->ListItem = explode('||', entitiesToUTF8(convertLegacyOptions("M;;C;;D;;V")));
		$combo_matrimoniale->ListData = $combo_matrimoniale->ListItem;
	}
	$combo_matrimoniale->SelectName = 'matrimoniale';
	// combobox: date_recrutement
	$combo_date_recrutement = new DateCombo;
	$combo_date_recrutement->DateFormat = "dmy";
	$combo_date_recrutement->MinYear = 1900;
	$combo_date_recrutement->MaxYear = 2100;
	$combo_date_recrutement->DefaultDate = parseMySQLDate('1', '1');
	$combo_date_recrutement->MonthNames = $Translation['month names'];
	$combo_date_recrutement->NamePrefix = 'date_recrutement';
	// combobox: fonction
	$combo_fonction = new DataCombo;
	// combobox: direction
	$combo_direction = new DataCombo;
	// combobox: service, filterable by: direction
	$combo_service = new DataCombo;
	// combobox: division, filterable by: service
	$combo_division = new DataCombo;
	// combobox: categorie
	$combo_categorie = new DataCombo;
	// combobox: statut
	$combo_statut = new DataCombo;
	// combobox: banque
	$combo_banque = new DataCombo;

	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='dossier_individuel' and pkValue='".makeSafe($selected_id)."'");
		$ownerMemberID=sqlValue("select lcase(memberID) from membership_userrecords where tableName='dossier_individuel' 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 `dossier_individuel` where `iddindividuel`='".makeSafe($selected_id)."'", $eo);
		if(!($row = db_fetch_array($res))){
			return error_message($Translation['No records found'], 'dossier_individuel_view.php', false);
		}
		$urow = $row; /* unsanitized data */
		$hc = new CI_Input();
		$row = $hc->xss_clean($row); /* sanitize data */
		$combo_date_naissance->DefaultDate = $row['date_naissance'];
		$combo_matrimoniale->SelectedData = $row['matrimoniale'];
		$combo_date_recrutement->DefaultDate = $row['date_recrutement'];
		$combo_fonction->SelectedData = $row['fonction'];
		$combo_direction->SelectedData = $row['direction'];
		$combo_service->SelectedData = $row['service'];
		$combo_division->SelectedData = $row['division'];
		$combo_categorie->SelectedData = $row['categorie'];
		$combo_statut->SelectedData = $row['statut'];
		$combo_banque->SelectedData = $row['banque'];
	}else{
		$combo_matrimoniale->SelectedText = ( $_REQUEST['FilterField'][1]=='6' && $_REQUEST['FilterOperator'][1]=='<=>' ? (get_magic_quotes_gpc() ? stripslashes($_REQUEST['FilterValue'][1]) : $_REQUEST['FilterValue'][1]) : "");
		$combo_fonction->SelectedData = $filterer_fonction;
		$combo_direction->SelectedData = $filterer_direction;
		$combo_service->SelectedData = $filterer_service;
		$combo_division->SelectedData = $filterer_division;
		$combo_categorie->SelectedData = $filterer_categorie;
		$combo_statut->SelectedData = $filterer_statut;
		$combo_banque->SelectedData = $filterer_banque;
	}
	$combo_matrimoniale->Render();
	$combo_fonction->HTML = '<span id="fonction-container' . $rnd1 . '"></span><input type="hidden" name="fonction" id="fonction' . $rnd1 . '" value="' . html_attr($combo_fonction->SelectedData) . '">';
	$combo_fonction->MatchText = '<span id="fonction-container-readonly' . $rnd1 . '"></span><input type="hidden" name="fonction" id="fonction' . $rnd1 . '" value="' . html_attr($combo_fonction->SelectedData) . '">';
	$combo_direction->HTML = '<span id="direction-container' . $rnd1 . '"></span><input type="hidden" name="direction" id="direction' . $rnd1 . '" value="' . html_attr($combo_direction->SelectedData) . '">';
	$combo_direction->MatchText = '<span id="direction-container-readonly' . $rnd1 . '"></span><input type="hidden" name="direction" id="direction' . $rnd1 . '" value="' . html_attr($combo_direction->SelectedData) . '">';
	$combo_service->HTML = '<span id="service-container' . $rnd1 . '"></span><input type="hidden" name="service" id="service' . $rnd1 . '" value="' . html_attr($combo_service->SelectedData) . '">';
	$combo_service->MatchText = '<span id="service-container-readonly' . $rnd1 . '"></span><input type="hidden" name="service" id="service' . $rnd1 . '" value="' . html_attr($combo_service->SelectedData) . '">';
	$combo_division->HTML = '<span id="division-container' . $rnd1 . '"></span><input type="hidden" name="division" id="division' . $rnd1 . '" value="' . html_attr($combo_division->SelectedData) . '">';
	$combo_division->MatchText = '<span id="division-container-readonly' . $rnd1 . '"></span><input type="hidden" name="division" id="division' . $rnd1 . '" value="' . html_attr($combo_division->SelectedData) . '">';
	$combo_categorie->HTML = '<span id="categorie-container' . $rnd1 . '"></span><input type="hidden" name="categorie" id="categorie' . $rnd1 . '" value="' . html_attr($combo_categorie->SelectedData) . '">';
	$combo_categorie->MatchText = '<span id="categorie-container-readonly' . $rnd1 . '"></span><input type="hidden" name="categorie" id="categorie' . $rnd1 . '" value="' . html_attr($combo_categorie->SelectedData) . '">';
	$combo_statut->HTML = '<span id="statut-container' . $rnd1 . '"></span><input type="hidden" name="statut" id="statut' . $rnd1 . '" value="' . html_attr($combo_statut->SelectedData) . '">';
	$combo_statut->MatchText = '<span id="statut-container-readonly' . $rnd1 . '"></span><input type="hidden" name="statut" id="statut' . $rnd1 . '" value="' . html_attr($combo_statut->SelectedData) . '">';
	$combo_banque->HTML = '<span id="banque-container' . $rnd1 . '"></span><input type="hidden" name="banque" id="banque' . $rnd1 . '" value="' . html_attr($combo_banque->SelectedData) . '">';
	$combo_banque->MatchText = '<span id="banque-container-readonly' . $rnd1 . '"></span><input type="hidden" name="banque" id="banque' . $rnd1 . '" value="' . html_attr($combo_banque->SelectedData) . '">';

	ob_start();
	?>

	<script>
		// initial lookup values
		AppGini.current_fonction__RAND__ = { text: "", value: "<?php echo addslashes($selected_id ? $urow['fonction'] : $filterer_fonction); ?>"};
		AppGini.current_direction__RAND__ = { text: "", value: "<?php echo addslashes($selected_id ? $urow['direction'] : $filterer_direction); ?>"};
		AppGini.current_service__RAND__ = { text: "", value: "<?php echo addslashes($selected_id ? $urow['service'] : $filterer_service); ?>"};
		AppGini.current_division__RAND__ = { text: "", value: "<?php echo addslashes($selected_id ? $urow['division'] : $filterer_division); ?>"};
		AppGini.current_categorie__RAND__ = { text: "", value: "<?php echo addslashes($selected_id ? $urow['categorie'] : $filterer_categorie); ?>"};
		AppGini.current_statut__RAND__ = { text: "", value: "<?php echo addslashes($selected_id ? $urow['statut'] : $filterer_statut); ?>"};
		AppGini.current_banque__RAND__ = { text: "", value: "<?php echo addslashes($selected_id ? $urow['banque'] : $filterer_banque); ?>"};

		jQuery(function() {
			setTimeout(function(){
				if(typeof(fonction_reload__RAND__) == 'function') fonction_reload__RAND__();
				if(typeof(direction_reload__RAND__) == 'function') direction_reload__RAND__();
				<?php echo (!$AllowUpdate || $dvprint ? 'if(typeof(service_reload__RAND__) == \'function\') service_reload__RAND__(AppGini.current_direction__RAND__.value);' : ''); ?>
				<?php echo (!$AllowUpdate || $dvprint ? 'if(typeof(division_reload__RAND__) == \'function\') division_reload__RAND__(AppGini.current_service__RAND__.value);' : ''); ?>
				if(typeof(categorie_reload__RAND__) == 'function') categorie_reload__RAND__();
				if(typeof(statut_reload__RAND__) == 'function') statut_reload__RAND__();
				if(typeof(banque_reload__RAND__) == 'function') banque_reload__RAND__();
			}, 10); /* we need to slightly delay client-side execution of the above code to allow AppGini.ajaxCache to work */
		});
		function fonction_reload__RAND__(){
		<?php if(($AllowUpdate || $AllowInsert) && !$dvprint){ ?>

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


							if(typeof(fonction_update_autofills__RAND__) == 'function') fonction_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: 'dossier_individuel', f: 'fonction' }; },
					results: function(resp, page){ /* */ return resp; }
				},
				escapeMarkup: function(str){ /* */ return str; }
			}).on('change', function(e){
				AppGini.current_fonction__RAND__.value = e.added.id;
				AppGini.current_fonction__RAND__.text = e.added.text;
				$j('[name="fonction"]').val(e.added.id);
				if(e.added.id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=fonctions_view_parent]').hide(); }else{ $j('.btn[id=fonctions_view_parent]').show(); }


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

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

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

		<?php }else{ ?>

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

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

		}
		function direction_reload__RAND__(){
		<?php if(($AllowUpdate || $AllowInsert) && !$dvprint){ ?>

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

						if(typeof(service_reload__RAND__) == 'function') service_reload__RAND__(AppGini.current_direction__RAND__.value);

							if(typeof(direction_update_autofills__RAND__) == 'function') direction_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: 'dossier_individuel', f: 'direction' }; },
					results: function(resp, page){ /* */ return resp; }
				},
				escapeMarkup: function(str){ /* */ return str; }
			}).on('change', function(e){
				AppGini.current_direction__RAND__.value = e.added.id;
				AppGini.current_direction__RAND__.text = e.added.text;
				$j('[name="direction"]').val(e.added.id);
				if(e.added.id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=directions_view_parent]').hide(); }else{ $j('.btn[id=directions_view_parent]').show(); }

						if(typeof(service_reload__RAND__) == 'function') service_reload__RAND__(AppGini.current_direction__RAND__.value);

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

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

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

		<?php }else{ ?>

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

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

		}
		function service_reload__RAND__(filterer_direction){
		<?php if(($AllowUpdate || $AllowInsert) && !$dvprint){ ?>

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

						if(typeof(division_reload__RAND__) == 'function') division_reload__RAND__(AppGini.current_service__RAND__.value);

							if(typeof(service_update_autofills__RAND__) == 'function') service_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 { filterer_direction: filterer_direction, s: term, p: page, t: 'dossier_individuel', f: 'service' }; },
					results: function(resp, page){ /* */ return resp; }
				},
				escapeMarkup: function(str){ /* */ return str; }
			}).on('change', function(e){
				AppGini.current_service__RAND__.value = e.added.id;
				AppGini.current_service__RAND__.text = e.added.text;
				$j('[name="service"]').val(e.added.id);
				if(e.added.id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=services_view_parent]').hide(); }else{ $j('.btn[id=services_view_parent]').show(); }

						if(typeof(division_reload__RAND__) == 'function') division_reload__RAND__(AppGini.current_service__RAND__.value);

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

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

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

		<?php }else{ ?>

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

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

		}
		function division_reload__RAND__(filterer_service){
		<?php if(($AllowUpdate || $AllowInsert) && !$dvprint){ ?>

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


							if(typeof(division_update_autofills__RAND__) == 'function') division_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 { filterer_service: filterer_service, s: term, p: page, t: 'dossier_individuel', f: 'division' }; },
					results: function(resp, page){ /* */ return resp; }
				},
				escapeMarkup: function(str){ /* */ return str; }
			}).on('change', function(e){
				AppGini.current_division__RAND__.value = e.added.id;
				AppGini.current_division__RAND__.text = e.added.text;
				$j('[name="division"]').val(e.added.id);
				if(e.added.id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=divisions_view_parent]').hide(); }else{ $j('.btn[id=divisions_view_parent]').show(); }


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

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

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

		<?php }else{ ?>

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

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

		}
		function categorie_reload__RAND__(){
		<?php if(($AllowUpdate || $AllowInsert) && !$dvprint){ ?>

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


							if(typeof(categorie_update_autofills__RAND__) == 'function') categorie_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: 'dossier_individuel', f: 'categorie' }; },
					results: function(resp, page){ /* */ return resp; }
				},
				escapeMarkup: function(str){ /* */ return str; }
			}).on('change', function(e){
				AppGini.current_categorie__RAND__.value = e.added.id;
				AppGini.current_categorie__RAND__.text = e.added.text;
				$j('[name="categorie"]').val(e.added.id);
				if(e.added.id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=categorie_prime_view_parent]').hide(); }else{ $j('.btn[id=categorie_prime_view_parent]').show(); }


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

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

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

		<?php }else{ ?>

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

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

		}
		function statut_reload__RAND__(){
		<?php if(($AllowUpdate || $AllowInsert) && !$dvprint){ ?>

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


							if(typeof(statut_update_autofills__RAND__) == 'function') statut_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: 'dossier_individuel', f: 'statut' }; },
					results: function(resp, page){ /* */ return resp; }
				},
				escapeMarkup: function(str){ /* */ return str; }
			}).on('change', function(e){
				AppGini.current_statut__RAND__.value = e.added.id;
				AppGini.current_statut__RAND__.text = e.added.text;
				$j('[name="statut"]').val(e.added.id);
				if(e.added.id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=statut_view_parent]').hide(); }else{ $j('.btn[id=statut_view_parent]').show(); }


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

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

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

		<?php }else{ ?>

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

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

		}
		function banque_reload__RAND__(){
		<?php if(($AllowUpdate || $AllowInsert) && !$dvprint){ ?>

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


							if(typeof(banque_update_autofills__RAND__) == 'function') banque_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: 'dossier_individuel', f: 'banque' }; },
					results: function(resp, page){ /* */ return resp; }
				},
				escapeMarkup: function(str){ /* */ return str; }
			}).on('change', function(e){
				AppGini.current_banque__RAND__.value = e.added.id;
				AppGini.current_banque__RAND__.text = e.added.text;
				$j('[name="banque"]').val(e.added.id);
				if(e.added.id == '<?php echo empty_lookup_value; ?>'){ $j('.btn[id=les_banques_view_parent]').hide(); }else{ $j('.btn[id=les_banques_view_parent]').show(); }


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

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

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

		<?php }else{ ?>

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

					if(typeof(banque_update_autofills__RAND__) == 'function') banque_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/dossier_individuel_templateDVP.html';
		$templateCode = @file_get_contents($template_file);
	}else{
		$template_file = is_file("./{$TemplateDV}") ? "./{$TemplateDV}" : './templates/dossier_individuel_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 dossier_individuel_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 dossier_individuel_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 dossier_individuel_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('#photo').replaceWith('<div class=\"form-control-static\" id=\"photo\">' + (jQuery('#photo').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#matricule').replaceWith('<div class=\"form-control-static\" id=\"matricule\">' + (jQuery('#matricule').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#nom_prenom').replaceWith('<div class=\"form-control-static\" id=\"nom_prenom\">' + (jQuery('#nom_prenom').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#date_naissance').prop('readonly', true);\n";
		$jsReadOnly .= "\tjQuery('#date_naissanceDay, #date_naissanceMonth, #date_naissanceYear').prop('disabled', true).css({ color: '#555', backgroundColor: '#fff' });\n";
		$jsReadOnly .= "\tjQuery('#matrimoniale').replaceWith('<div class=\"form-control-static\" id=\"matrimoniale\">' + (jQuery('#matrimoniale').val() || '') + '</div>'); jQuery('#matrimoniale-multi-selection-help').hide();\n";
		$jsReadOnly .= "\tjQuery('#enfants').replaceWith('<div class=\"form-control-static\" id=\"enfants\">' + (jQuery('#enfants').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#nni').replaceWith('<div class=\"form-control-static\" id=\"nni\">' + (jQuery('#nni').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#telephone').replaceWith('<div class=\"form-control-static\" id=\"telephone\">' + (jQuery('#telephone').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#courriel').replaceWith('<div class=\"form-control-static\" id=\"courriel\">' + (jQuery('#courriel').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#postale').replaceWith('<div class=\"form-control-static\" id=\"postale\">' + (jQuery('#postale').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#date_recrutement').prop('readonly', true);\n";
		$jsReadOnly .= "\tjQuery('#date_recrutementDay, #date_recrutementMonth, #date_recrutementYear').prop('disabled', true).css({ color: '#555', backgroundColor: '#fff' });\n";
		$jsReadOnly .= "\tjQuery('#fonction').prop('disabled', true).css({ color: '#555', backgroundColor: '#fff' });\n";
		$jsReadOnly .= "\tjQuery('#fonction_caption').prop('disabled', true).css({ color: '#555', backgroundColor: 'white' });\n";
		$jsReadOnly .= "\tjQuery('#direction').prop('disabled', true).css({ color: '#555', backgroundColor: '#fff' });\n";
		$jsReadOnly .= "\tjQuery('#direction_caption').prop('disabled', true).css({ color: '#555', backgroundColor: 'white' });\n";
		$jsReadOnly .= "\tjQuery('#service').prop('disabled', true).css({ color: '#555', backgroundColor: '#fff' });\n";
		$jsReadOnly .= "\tjQuery('#service_caption').prop('disabled', true).css({ color: '#555', backgroundColor: 'white' });\n";
		$jsReadOnly .= "\tjQuery('#division').prop('disabled', true).css({ color: '#555', backgroundColor: '#fff' });\n";
		$jsReadOnly .= "\tjQuery('#division_caption').prop('disabled', true).css({ color: '#555', backgroundColor: 'white' });\n";
		$jsReadOnly .= "\tjQuery('#categorie').prop('disabled', true).css({ color: '#555', backgroundColor: '#fff' });\n";
		$jsReadOnly .= "\tjQuery('#categorie_caption').prop('disabled', true).css({ color: '#555', backgroundColor: 'white' });\n";
		$jsReadOnly .= "\tjQuery('#statut').prop('disabled', true).css({ color: '#555', backgroundColor: '#fff' });\n";
		$jsReadOnly .= "\tjQuery('#statut_caption').prop('disabled', true).css({ color: '#555', backgroundColor: 'white' });\n";
		$jsReadOnly .= "\tjQuery('#salaire').replaceWith('<div class=\"form-control-static\" id=\"salaire\">' + (jQuery('#salaire').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#compte').replaceWith('<div class=\"form-control-static\" id=\"compte\">' + (jQuery('#compte').val() || '') + '</div>');\n";
		$jsReadOnly .= "\tjQuery('#banque').prop('disabled', true).css({ color: '#555', backgroundColor: '#fff' });\n";
		$jsReadOnly .= "\tjQuery('#banque_caption').prop('disabled', true).css({ color: '#555', backgroundColor: 'white' });\n";
		$jsReadOnly .= "\tjQuery('#observation').replaceWith('<div class=\"form-control-static\" id=\"observation\">' + (jQuery('#observation').val() || '') + '</div>');\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(date_naissance)%%>', ($selected_id && !$arrPerm[3] ? '<div class="form-control-static">' . $combo_date_naissance->GetHTML(true) . '</div>' : $combo_date_naissance->GetHTML()), $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(date_naissance)%%>', $combo_date_naissance->GetHTML(true), $templateCode);
	$templateCode = str_replace('<%%COMBO(matrimoniale)%%>', $combo_matrimoniale->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(matrimoniale)%%>', $combo_matrimoniale->SelectedData, $templateCode);
	$templateCode = str_replace('<%%COMBO(date_recrutement)%%>', ($selected_id && !$arrPerm[3] ? '<div class="form-control-static">' . $combo_date_recrutement->GetHTML(true) . '</div>' : $combo_date_recrutement->GetHTML()), $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(date_recrutement)%%>', $combo_date_recrutement->GetHTML(true), $templateCode);
	$templateCode = str_replace('<%%COMBO(fonction)%%>', $combo_fonction->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(fonction)%%>', $combo_fonction->MatchText, $templateCode);
	$templateCode = str_replace('<%%URLCOMBOTEXT(fonction)%%>', urlencode($combo_fonction->MatchText), $templateCode);
	$templateCode = str_replace('<%%COMBO(direction)%%>', $combo_direction->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(direction)%%>', $combo_direction->MatchText, $templateCode);
	$templateCode = str_replace('<%%URLCOMBOTEXT(direction)%%>', urlencode($combo_direction->MatchText), $templateCode);
	$templateCode = str_replace('<%%COMBO(service)%%>', $combo_service->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(service)%%>', $combo_service->MatchText, $templateCode);
	$templateCode = str_replace('<%%URLCOMBOTEXT(service)%%>', urlencode($combo_service->MatchText), $templateCode);
	$templateCode = str_replace('<%%COMBO(division)%%>', $combo_division->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(division)%%>', $combo_division->MatchText, $templateCode);
	$templateCode = str_replace('<%%URLCOMBOTEXT(division)%%>', urlencode($combo_division->MatchText), $templateCode);
	$templateCode = str_replace('<%%COMBO(categorie)%%>', $combo_categorie->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(categorie)%%>', $combo_categorie->MatchText, $templateCode);
	$templateCode = str_replace('<%%URLCOMBOTEXT(categorie)%%>', urlencode($combo_categorie->MatchText), $templateCode);
	$templateCode = str_replace('<%%COMBO(statut)%%>', $combo_statut->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(statut)%%>', $combo_statut->MatchText, $templateCode);
	$templateCode = str_replace('<%%URLCOMBOTEXT(statut)%%>', urlencode($combo_statut->MatchText), $templateCode);
	$templateCode = str_replace('<%%COMBO(banque)%%>', $combo_banque->HTML, $templateCode);
	$templateCode = str_replace('<%%COMBOTEXT(banque)%%>', $combo_banque->MatchText, $templateCode);
	$templateCode = str_replace('<%%URLCOMBOTEXT(banque)%%>', urlencode($combo_banque->MatchText), $templateCode);

	/* lookup fields array: 'lookup field name' => array('parent table name', 'lookup field caption') */
	$lookup_fields = array(  'fonction' => array('fonctions', 'FONCTION'), 'direction' => array('directions', 'DIRECTION'), 'service' => array('services', 'SERVICE'), 'division' => array('divisions', 'DIVISION'), 'categorie' => array('categorie_prime', 'Categorie'), 'statut' => array('statut', 'STATUT'), 'banque' => array('les_banques', 'BANQUE'));
	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(photo)%%>', ($noUploads ? '' : '<input type=hidden name=MAX_FILE_SIZE value=1024000>'.$Translation['upload image'].' <input type="file" name="photo" id="photo">'), $templateCode);
	if($AllowUpdate && $row['photo'] != ''){
		$templateCode = str_replace('<%%REMOVEFILE(photo)%%>', '<br><input type="checkbox" name="photo_remove" id="photo_remove" value="1"> <label for="photo_remove" style="color: red; font-weight: bold;">'.$Translation['remove image'].'</label>', $templateCode);
	}else{
		$templateCode = str_replace('<%%REMOVEFILE(photo)%%>', '', $templateCode);
	}
	$templateCode = str_replace('<%%UPLOADFILE(matricule)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(iddindividuel)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(nom_prenom)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(date_naissance)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(matrimoniale)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(enfants)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(nni)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(telephone)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(courriel)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(postale)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(date_recrutement)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(fonction)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(direction)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(service)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(division)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(categorie)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(statut)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(salaire)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(compte)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(banque)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(total_income)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(total_expense)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(available_budget)%%>', '', $templateCode);
	$templateCode = str_replace('<%%UPLOADFILE(observation)%%>', '', $templateCode);

	// process values
	if($selected_id){
		$row['photo'] = ($row['photo'] != '' ? $row['photo'] : 'blank.gif');
		if( $dvprint) $templateCode = str_replace('<%%VALUE(photo)%%>', safe_html($urow['photo']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(photo)%%>', html_attr($row['photo']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(photo)%%>', urlencode($urow['photo']), $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);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(iddindividuel)%%>', safe_html($urow['iddindividuel']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(iddindividuel)%%>', html_attr($row['iddindividuel']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(iddindividuel)%%>', urlencode($urow['iddindividuel']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(nom_prenom)%%>', safe_html($urow['nom_prenom']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(nom_prenom)%%>', html_attr($row['nom_prenom']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(nom_prenom)%%>', urlencode($urow['nom_prenom']), $templateCode);
		$templateCode = str_replace('<%%VALUE(date_naissance)%%>', @date('d/m/Y', @strtotime(html_attr($row['date_naissance']))), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(date_naissance)%%>', urlencode(@date('d/m/Y', @strtotime(html_attr($urow['date_naissance'])))), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(matrimoniale)%%>', safe_html($urow['matrimoniale']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(matrimoniale)%%>', html_attr($row['matrimoniale']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(matrimoniale)%%>', urlencode($urow['matrimoniale']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(enfants)%%>', safe_html($urow['enfants']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(enfants)%%>', html_attr($row['enfants']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(enfants)%%>', urlencode($urow['enfants']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(nni)%%>', safe_html($urow['nni']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(nni)%%>', html_attr($row['nni']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(nni)%%>', urlencode($urow['nni']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(telephone)%%>', safe_html($urow['telephone']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(telephone)%%>', html_attr($row['telephone']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(telephone)%%>', urlencode($urow['telephone']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(courriel)%%>', safe_html($urow['courriel']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(courriel)%%>', html_attr($row['courriel']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(courriel)%%>', urlencode($urow['courriel']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(postale)%%>', safe_html($urow['postale']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(postale)%%>', html_attr($row['postale']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(postale)%%>', urlencode($urow['postale']), $templateCode);
		$templateCode = str_replace('<%%VALUE(date_recrutement)%%>', @date('d/m/Y', @strtotime(html_attr($row['date_recrutement']))), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(date_recrutement)%%>', urlencode(@date('d/m/Y', @strtotime(html_attr($urow['date_recrutement'])))), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(fonction)%%>', safe_html($urow['fonction']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(fonction)%%>', html_attr($row['fonction']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(fonction)%%>', urlencode($urow['fonction']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(direction)%%>', safe_html($urow['direction']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(direction)%%>', html_attr($row['direction']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(direction)%%>', urlencode($urow['direction']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(service)%%>', safe_html($urow['service']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(service)%%>', html_attr($row['service']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(service)%%>', urlencode($urow['service']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(division)%%>', safe_html($urow['division']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(division)%%>', html_attr($row['division']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(division)%%>', urlencode($urow['division']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(categorie)%%>', safe_html($urow['categorie']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(categorie)%%>', html_attr($row['categorie']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(categorie)%%>', urlencode($urow['categorie']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(statut)%%>', safe_html($urow['statut']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(statut)%%>', html_attr($row['statut']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(statut)%%>', urlencode($urow['statut']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(salaire)%%>', safe_html($urow['salaire']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(salaire)%%>', html_attr($row['salaire']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(salaire)%%>', urlencode($urow['salaire']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(compte)%%>', safe_html($urow['compte']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(compte)%%>', html_attr($row['compte']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(compte)%%>', urlencode($urow['compte']), $templateCode);
		if( $dvprint) $templateCode = str_replace('<%%VALUE(banque)%%>', safe_html($urow['banque']), $templateCode);
		if(!$dvprint) $templateCode = str_replace('<%%VALUE(banque)%%>', html_attr($row['banque']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(banque)%%>', urlencode($urow['banque']), $templateCode);
		$templateCode = str_replace('<%%VALUE(total_income)%%>', safe_html($urow['total_income']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(total_income)%%>', urlencode($urow['total_income']), $templateCode);
		$templateCode = str_replace('<%%VALUE(total_expense)%%>', safe_html($urow['total_expense']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(total_expense)%%>', urlencode($urow['total_expense']), $templateCode);
		$templateCode = str_replace('<%%VALUE(available_budget)%%>', safe_html($urow['available_budget']), $templateCode);
		$templateCode = str_replace('<%%URLVALUE(available_budget)%%>', urlencode($urow['available_budget']), $templateCode);
		if($dvprint || (!$AllowUpdate && !$AllowInsert)){
			$templateCode = str_replace('<%%VALUE(observation)%%>', safe_html($urow['observation']), $templateCode);
		}else{
			$templateCode = str_replace('<%%VALUE(observation)%%>', html_attr($row['observation']), $templateCode);
		}
		$templateCode = str_replace('<%%URLVALUE(observation)%%>', urlencode($urow['observation']), $templateCode);
	}else{
		$templateCode = str_replace('<%%VALUE(photo)%%>', 'blank.gif', $templateCode);
		$templateCode = str_replace('<%%VALUE(matricule)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(matricule)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(iddindividuel)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(iddindividuel)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(nom_prenom)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(nom_prenom)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(date_naissance)%%>', '1', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(date_naissance)%%>', urlencode('1'), $templateCode);
		$templateCode = str_replace('<%%VALUE(matrimoniale)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(matrimoniale)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(enfants)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(enfants)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(nni)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(nni)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(telephone)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(telephone)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(courriel)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(courriel)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(postale)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(postale)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(date_recrutement)%%>', '1', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(date_recrutement)%%>', urlencode('1'), $templateCode);
		$templateCode = str_replace('<%%VALUE(fonction)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(fonction)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(direction)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(direction)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(service)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(service)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(division)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(division)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(categorie)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(categorie)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(statut)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(statut)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(salaire)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(salaire)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(compte)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(compte)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(banque)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(banque)%%>', urlencode(''), $templateCode);
		$templateCode = str_replace('<%%VALUE(total_income)%%>', '0', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(total_income)%%>', urlencode('0'), $templateCode);
		$templateCode = str_replace('<%%VALUE(total_expense)%%>', '0', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(total_expense)%%>', urlencode('0'), $templateCode);
		$templateCode = str_replace('<%%VALUE(available_budget)%%>', '0', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(available_budget)%%>', urlencode('0'), $templateCode);
		$templateCode = str_replace('<%%VALUE(observation)%%>', '', $templateCode);
		$templateCode = str_replace('<%%URLVALUE(observation)%%>', 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 .= "\tcategorie_update_autofills$rnd1 = function(){\n";
	$templateCode .= "\t\t\$j.ajax({\n";
	if($dvprint) {
		$templateCode .= "\t\t\turl: 'dossier_individuel_autofill.php?rnd1=$rnd1&mfk=categorie&id=' + encodeURIComponent('".addslashes($row['categorie'])."'),\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: 'dossier_individuel_autofill.php?rnd1=$rnd1&mfk=categorie&id=' + encodeURIComponent(AppGini.current_categorie{$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('#categorie$rnd1').prop('disabled', true); \$j('#categorieLoading').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('#categorie$rnd1').prop('disabled', false); " : "\$j('#categorie$rnd1').prop('disabled', true); ")."\$j('#categorieLoading').html(''); \$j(window).resize(); }\n";
	}
	$templateCode .= "\t\t});\n";
	$templateCode .= "\t};\n";
	if(!$dvprint) $templateCode .= "\tif(\$j('#categorie_caption').length) \$j('#categorie_caption').click(function(){ /* */ categorie_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('dossier_individuel');
	if($selected_id){
		$jdata = get_joined_record('dossier_individuel', $selected_id);
		if($jdata === false) $jdata = get_defaults('dossier_individuel');
		$rdata = $row;
	}
	$templateCode .= loadView('dossier_individuel-ajax-cache', array('rdata' => $rdata, 'jdata' => $jdata));

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

	return $templateCode;
}
?>