* @author Laurent Giovannoni */ include("session.php"); $source = $_SESSION['config']['tmpdir']; //----------------------- Field selection in the models_index.xml file-----------------------// $table_users = false; $table_doctypes = false; $table_sender = false; $table_document = false; $table_services = false; $xmlfile = simplexml_load_file($dir . 'xml/mapping_file.xml'); $i_map = 0; foreach ($xmlfile->item as $item) { if ($item->field <> 'none') { $varNameTmp = str_replace('[', '', $item->var_name); $varNameTmp = str_replace(']', '', $varNameTmp); $tab_export_var_name[$i_map] = $varNameTmp; $tab_export_field[$i_map] = $item->field; $tab_export_table[$i_map] = $item->table; $tab_export_argument[$i_map] = $item->argument; $i_map++; } } //-----------------------Declaration des tables necessaires--------------------------------// for ($t=0;$tconnect(); //$db->show_array($tab_export_field); //$db->show_array($tab_export_table); $select = ""; // Fields positioning for ($i_query=0;$i_query<$i_map;$i_query++) { $tempName = (string)$tab_export_table[$i_query]; if ($tab_export_argument[$i_query] <> '') { $select .= $tab_export_argument[$i_query] . "(" . $tables[$tempName] . "." . $tab_export_field[$i_query] . ") AS '" . $tab_export_var_name[$i_query] . "',"; } else { $select .= $tables[$tempName].".".$tab_export_field[$i_query]." AS '".$tab_export_var_name[$i_query]."',"; } } $select = substr($select, 0, -1); $from = ''; foreach ($tables as $tableName => $tableAlias) { $from .= $tableName.' '.$tableAlias.', '; } $from = substr($from, 0, -2); $where = $_SESSION['export_where_request']; //Creation des jointures si necessaire if ($_SESSION['courrier']['res_id'] <> '') { $where .= " and ".$tables[$_SESSION['ressources'][0]['tablename']].".RES_ID = ".$_SESSION['courrier']['res_id'].' '; } if ($table_doctypes) { $where .= " and ".$tables[$_SESSION['ressources'][0]['tablename']].".TYPE_ID = ".$tables[$_SESSION['tablename']['doctypes']].".TYPE_ID "; } if ($table_sender) { $where .= " and ".$tables[$_SESSION['ressources'][0]['tablename']].".AUTHOR = ".$tables[$_SESSION['tablename']['senders']].".NAME "; } if ($table_users) { $where .= " and ((".$tables[$_SESSION['ressources'][0]['tablename']].".DEST_USER = 'courrier') or (".$tables[$_SESSION['ressources'][0]['tablename']].".DEST_USER = ".$tables[$_SESSION['tablename']['users']].".USER_ID)) "; } if ($table_services) { $where .= " and ".$tables[$_SESSION['ressources'][0]['tablename']].".DESTINATION = ".$tables[$_SESSION['tablename']['services']].".ID "; } $pos = strpos($where, 'and'); if ($pos <> false) { $where = substr($where, $pos + 3, strlen($where)); } $db->query("SELECT ".$select." FROM ".$from." WHERE (".$where.")"); //$db->show();exit; //----------------------- Result ----------------------------------------// $func = new functions(); $result = $db->fetch_object(); $resultArray = array(); $resultArray = $func->object2array($result); //Debug //$func->show_array($resultArray); /*for ($i_reg=0;$i_reg<$i_map;$i_reg++) { if($tab_export_name[$i_reg] <> '') { echo 'colonne : ' . $tab_export_var_name[$i_reg] . ' valeur : '. utf8_decode($result->$tab_export_name[$i_reg]) . '
'; } } foreach ($resultArray as $key => $field) { echo $key . ' ' . $field . '
'; } $content = '

[date_limite_traitement] [CIV] [prenom] [author]

'; foreach ($resultArray as $key => $value) { $posDate = strpos($key, 'date'); if ($posDate <> false) { $content = str_replace("[" . $key . "]", html_entity_decode(utf8_decode(stripslashes($value))), $content); } else { $content = str_replace("[" . $key . "]", html_entity_decode(utf8_decode($db->inverse_date($value))), $content); } } echo $content;*/