From 32faa96ab6a2e574733ae47041478d9f758c499d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 3 Mar 2009 00:42:40 +0000 Subject: [PATCH] New: For admin users, show the SQL request in export build. --- ChangeLog | 1 + htdocs/exports/export.class.php | 97 +++++++++++++++-------------- htdocs/exports/export.php | 107 ++++++++++++++++++-------------- htdocs/langs/en_US/exports.lang | 3 +- htdocs/langs/fr_FR/exports.lang | 3 +- htdocs/lib/functions.lib.php | 4 +- 6 files changed, 118 insertions(+), 97 deletions(-) diff --git a/ChangeLog b/ChangeLog index 87a3e5e8172..f345f367327 100644 --- a/ChangeLog +++ b/ChangeLog @@ -37,6 +37,7 @@ For users: - New: Changements to support the external BitTorrent module. - New: Can filter on social contribution type in list. - New: Upload of joined files need create/modify permissions to work. +- New: For admin users, show the SQL request in export build. - Fix: Partial payment on social contributions not shown on main page. - Fix: Handle correctly the comment in status changing of supplier orders. - Fix: Author, title and topic are correctly encoded in PDF. diff --git a/htdocs/exports/export.class.php b/htdocs/exports/export.class.php index ad8e98d40f0..53eef819d58 100644 --- a/htdocs/exports/export.class.php +++ b/htdocs/exports/export.class.php @@ -33,7 +33,7 @@ class Export { var $db; - + var $array_export_code=array(); // Tableau de "idmodule_numlot" var $array_export_module=array(); // Tableau de "nom de modules" var $array_export_label=array(); // Tableau de "libelle de lots" @@ -41,13 +41,15 @@ class Export var $array_export_fields=array(); // Tableau des listes de champ+libell� � exporter var $array_export_alias=array(); // Tableau des listes de champ+alias � exporter var $array_export_special=array(); // Tableau des operations speciales sur champ - + // To store export modules var $hexa; var $datatoexport; var $model_name; - - + + var $sqlusedforexport; + + /** * \brief Constructeur de la classe * \param DB Handler acces base de donnees @@ -56,8 +58,8 @@ class Export { $this->db=$DB; } - - + + /** * \brief Load an exportable dataset * \param user Object user making export @@ -66,7 +68,7 @@ class Export function load_arrays($user,$filter='') { global $langs,$conf; - + dol_syslog("Export::load_arrays user=".$user->id." filter=".$filter); $dir=DOL_DOCUMENT_ROOT."/includes/modules"; @@ -80,12 +82,12 @@ class Export if (eregi("^(mod.*)\.class\.php",$file,$reg)) { $modulename=$reg[1]; - + // Defined if module is enabled $enabled=true; $part=strtolower(eregi_replace('^mod','',$modulename)); - if (empty($conf->$part->enabled)) $enabled=false; - + if (empty($conf->$part->enabled)) $enabled=false; + if ($enabled) { // Chargement de la classe @@ -99,7 +101,7 @@ class Export foreach($module->export_code as $r => $value) { if ($filter && ($filter != $module->export_code[$r])) continue; - + // Test si permissions ok \todo tester sur toutes permissions $perm=$module->export_permission[$r][0]; //print_r("$perm[0]-$perm[1]-$perm[2]
"); @@ -113,7 +115,7 @@ class Export } if ($perm[0]=='user' && $user->admin) $bool=true; //print $bool." $perm[0]"."
"; - + // Permissions ok // if ($bool) // { @@ -121,12 +123,12 @@ class Export $langtoload=$module->getLangFilesArray(); if (is_array($langtoload)) { - foreach($langtoload as $key) + foreach($langtoload as $key) { $langs->load($key); } } - + // Module $this->array_export_module[$i]=$module; // Permission @@ -145,16 +147,16 @@ class Export $this->array_export_alias[$i]=$module->export_alias_array[$r]; // Tableau des operations speciales sur champ $this->array_export_special[$i]=$module->export_special_array[$r]; - + // Requete sql du dataset $this->array_export_sql_start[$i]=$module->export_sql_start[$r]; $this->array_export_sql_end[$i]=$module->export_sql_end[$r]; //$this->array_export_sql[$i]=$module->export_sql[$r]; - + dol_syslog("Export loaded for module ".$modulename." with index ".$i.", dataset=".$module->export_code[$r].", nb of fields=".sizeof($module->export_fields_code[$r])); $i++; // } - } + } } } } @@ -170,23 +172,23 @@ class Export * \param array_selected Tableau des champs � exporter * \remarks Les tableaux array_export_xxx sont d�j� charg�es pour le bon datatoexport * aussi le parametre datatoexport est inutilis� - */ + */ function build_file($user, $model, $datatoexport, $array_selected) { global $conf,$langs; - + $indice=0; asort($array_selected); - + dol_syslog("Export::build_file $model, $datatoexport, $array_selected"); - + // Creation de la classe d'export du model ExportXXX $dir = DOL_DOCUMENT_ROOT . "/includes/modules/export/"; $file = "export_".$model.".modules.php"; $classname = "Export".$model; require_once($dir.$file); $objmodel = new $classname($db); - + // Build the sql request $sql=$this->array_export_sql_start[$indice]; $i=0; @@ -202,8 +204,9 @@ class Export $sql.=$newfield; } $sql.=$this->array_export_sql_end[$indice]; - + // Run the sql + $this->sqlusedforexport=$sql; dol_syslog("Export::build_file sql=".$sql); $resql = $this->db->query($sql); if ($resql) @@ -214,7 +217,7 @@ class Export $dirname=$conf->export->dir_temp.'/'.$user->id; $outputlangs=$langs; // Lang for output - + // Open file create_exdir($dirname); $result=$objmodel->open_file($dirname."/".$filename, $outputlangs); @@ -230,7 +233,7 @@ class Export while ($objp = $this->db->fetch_object($resql)) { $var=!$var; - + // Process special operations if (! empty($this->array_export_special[$indice])) { @@ -252,13 +255,13 @@ class Export } } // end of special operation processing - + $objmodel->write_record($this->array_export_alias[$indice],$array_selected,$objp,$outputlangs); } - + // Genere en-tete $objmodel->write_footer($outputlangs); - + // Close file $objmodel->close_file(); } @@ -276,7 +279,7 @@ class Export return -1; } } - + /** * \brief Create an export model in database * \param user Objet utilisateur qui cree @@ -284,15 +287,15 @@ class Export function create($user) { global $conf; - + dol_syslog("Export.class.php::create"); - + $this->db->begin(); - + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'export_model ('; $sql.= 'label, type, field)'; $sql.= " VALUES ('".$this->model_name."', '".$this->datatoexport."', '".$this->hexa."')"; - + dol_syslog("Export::create sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) @@ -319,7 +322,7 @@ class Export $sql = 'SELECT em.rowid, em.field, em.label, em.type'; $sql.= ' FROM '.MAIN_DB_PREFIX.'export_model as em'; $sql.= ' WHERE em.rowid = '.$id; - + dol_syslog("Export::fetch sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql) ; if ($result) @@ -331,13 +334,13 @@ class Export $this->hexa = $obj->field; $this->model_name = $obj->label; $this->datatoexport = $obj->type; - + return 1; } else { $this->error="Model not found"; - return -2; + return -2; } } else @@ -346,8 +349,8 @@ class Export return -3; } } - - + + /** * \brief Delete object in database * \param user User that delete @@ -358,32 +361,32 @@ class Export { global $conf, $langs; $error=0; - + $sql = "DELETE FROM ".MAIN_DB_PREFIX."export_model"; $sql.= " WHERE rowid=".$this->id; - + $this->db->begin(); - + dol_syslog(get_class($this)."::delete sql=".$sql); $resql = $this->db->query($sql); if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - + if (! $error) { if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action call a trigger. - + //// Call triggers //include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); //$interface=new Interfaces($this->db); //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); //if ($result < 0) { $error++; $this->errors=$interface->errors; } //// End call triggers - } + } } - + // Commit or rollback if ($error) { @@ -391,7 +394,7 @@ class Export { dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); $this->error.=($this->error?', '.$errmsg:$errmsg); - } + } $this->db->rollback(); return -1*$error; } @@ -401,7 +404,7 @@ class Export return 1; } } - + } ?> diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index e01253312e6..00bd3e96f56 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2005-2009 Laurent Destailleur * Copyright (C) 2005-2007 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -23,7 +23,7 @@ \brief Page d'edition d'un export \version $Id$ */ - + require_once("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/html.formother.class.php"); @@ -78,14 +78,15 @@ $objmodelexport=new ModeleExports(); $html = new Form($db); $htmlother = new FormOther($db); $formfile = new FormFile($db); +$sqlusedforexport=''; /* * Actions */ - + if ($action=='selectfield') -{ +{ if ($_GET["field"]=='all') { $fieldsarray=$objexport->array_export_alias[0]; @@ -103,17 +104,17 @@ if ($action=='selectfield') //print_r($array_selected); $_SESSION["export_selected_fields"]=$array_selected; } - + } if ($action=='unselectfield') -{ +{ if ($_GET["field"]=='all') { $array_selected=array(); - $_SESSION["export_selected_fields"]=$array_selected; + $_SESSION["export_selected_fields"]=$array_selected; } else - { + { unset($array_selected[$_GET["field"]]); // Renumber fields of array_selected (from 1 to nb_elements) asort($array_selected); @@ -129,7 +130,7 @@ if ($action=='unselectfield') } } if ($action=='downfield' || $action=='upfield') -{ +{ $pos=$array_selected[$_GET["field"]]; if ($action=='downfield') $newpos=$pos+1; if ($action=='upfield') $newpos=$pos-1; @@ -169,6 +170,7 @@ if ($action == 'builddoc') else { $mesg='
'.$langs->trans("FileSuccessfullyBuilt").'
'; + $sqlusedforexport=$objexport->sqlusedforexport; } } @@ -198,7 +200,7 @@ if ($action == 'add_export_model') $objexport->model_name = $export_name; $objexport->datatoexport = $datatoexport; $objexport->hexa = $hexa; - + $result = $objexport->create($user); if ($result >= 0) { @@ -209,7 +211,7 @@ if ($action == 'add_export_model') $langs->load("errors"); if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $mesg='
'.$langs->trans("ErrorExportDuplicateProfil").'
'; + $mesg='
'.$langs->trans("ErrorExportDuplicateProfil").'
'; } else $mesg='
'.$objexport->error.'
'; } @@ -221,7 +223,7 @@ if ($action == 'add_export_model') } if ($step == 2 && $action == 'select_model') -{ +{ $_SESSION["export_selected_fields"]=array(); $array_selected=array(); $result = $objexport->fetch($exportmodelid); @@ -243,7 +245,7 @@ if ($step == 2 && $action == 'select_model') * Affichage Pages des Etapes */ - + if ($step == 1 || ! $datatoexport) { llxHeader('',$langs->trans("NewExport")); @@ -263,14 +265,14 @@ if ($step == 1 || ! $datatoexport) $head[$h][1] = $langs->trans("Step")." 2"; $h++; */ - + dol_fiche_head($head, $hselected, $langs->trans("NewExport")); print ''; print $langs->trans("SelectExportDataSet").'
'; - + // Affiche les modules d'exports print '
'; print ''; @@ -307,10 +309,10 @@ if ($step == 1 || ! $datatoexport) { print ''; } - print '
'.$langs->trans("NoExportableData").'
'; + print ''; print ''; - + print ''; if ($mesg) print $mesg; @@ -335,7 +337,7 @@ if ($step == 2 && $datatoexport) $head[$h][1] = $langs->trans("Step")." 2"; $hselected=$h; $h++; - + dol_fiche_head($head, $hselected, $langs->trans("NewExport")); print ''; @@ -353,10 +355,10 @@ if ($step == 2 && $datatoexport) print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_icon[0]).' '; print $objexport->array_export_label[0]; print ''; - + print '
'; print '
'; - + // Liste deroulante des modeles d'export print '
'; print ''; @@ -369,7 +371,7 @@ if ($step == 2 && $datatoexport) print ''; print ''; print '
'; - + print ''; print ''; @@ -393,10 +395,10 @@ if ($step == 2 && $datatoexport) # $this->array_export_fields[0]=$module->export_fields_array[$r]; # $this->array_export_entities[0]=$module->export_fields_entities[$r]; # $this->array_export_alias[0]=$module->export_fields_alias[$r]; - + $var=true; $i = 0; - + foreach($fieldsarray as $code=>$label) { $var=!$var; @@ -450,7 +452,7 @@ if ($step == 2 && $datatoexport) { print ''.$langs->trans("NextStep").''; } - + print ''; } @@ -460,7 +462,7 @@ if ($step == 3 && $datatoexport) asort($array_selected); llxHeader('',$langs->trans("NewExport")); - + /* * Affichage onglets */ @@ -478,7 +480,7 @@ if ($step == 3 && $datatoexport) $head[$h][1] = $langs->trans("Step")." 3"; $hselected=$h; $h++; - + dol_fiche_head($head, $hselected, $langs->trans("NewExport")); print '
'; @@ -509,9 +511,9 @@ if ($step == 3 && $datatoexport) print '
'; print '
'; - + print $langs->trans("ChooseFieldsOrdersAndTitle").'
'; - + print ''; print ''; print ''; @@ -532,7 +534,7 @@ if ($step == 3 && $datatoexport) $entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity; print ''; - + print ''; print '
'.$langs->trans("Entities").''.img_object('',$entityicon).' '.$langs->trans($entitylang).''.$langs->trans($objexport->array_export_fields[0][$code]).' ('.$code.')'; @@ -550,12 +552,12 @@ if ($step == 3 && $datatoexport) } print '
'; - - + + print ''; if ($mesg) print $mesg; - + /* * Barre d'action * @@ -569,13 +571,13 @@ if ($step == 3 && $datatoexport) print ''; - + // Area for profils export if (sizeof($array_selected)) { print '
'; print $langs->trans("SaveExportModel"); - + print '
'; print ''; print ''; @@ -621,11 +623,11 @@ if ($step == 3 && $datatoexport) else { dol_print_error($this->db); } - + print ''; print '
'; } - + } if ($step == 4 && $datatoexport) @@ -633,7 +635,7 @@ if ($step == 4 && $datatoexport) asort($array_selected); llxHeader('',$langs->trans("NewExport")); - + /* * Affichage onglets */ @@ -655,7 +657,7 @@ if ($step == 4 && $datatoexport) $head[$h][1] = $langs->trans("Step")." 4"; $hselected=$h; $h++; - + dol_fiche_head($head, $hselected, $langs->trans("NewExport")); print ''; @@ -686,9 +688,9 @@ if ($step == 4 && $datatoexport) print '
'; print '
'; - + print $langs->trans("NowClickToGenerateToBuildExportFile").'
'; - + // Liste des formats d'exports disponibles $var=true; print ''; @@ -704,11 +706,24 @@ if ($step == 4 && $datatoexport) $var=!$var; print ''; } - print '
'.$objmodelexport->getDriverLabel($key).''.$objmodelexport->getLibLabel($key).''.$objmodelexport->getLibVersion($key).'
'; + print ''; print ''; - if ($mesg) print $mesg; + print ''; + if ($mesg) + { + print ''; + } + if ($sqlusedforexport && $user->admin) + { + print ''; + } + print '
'; + print $mesg; + print '
'; + print info_admin($langs->trans("SQLUsedForExport").':
'.$sqlusedforexport); + print '
'; print ''; print '
'; @@ -717,10 +732,10 @@ if ($step == 4 && $datatoexport) // Affiche liste des documents // NB: La fonction show_documents rescanne les modules qd genallowed=1 $formfile->show_documents('export','',$conf->export->dir_temp.'/'.$user->id,$_SERVER["PHP_SELF"].'?step=4&datatoexport='.$datatoexport,$liste,1,(! empty($_POST['model'])?$_POST['model']:'csv'),'',1); - + print ' 
'; - + // If external library PHPEXCELREADER is available // and defined by PHPEXCELREADER constant. if (file_exists(PHPEXCELREADER.'excelreader.php')) @@ -731,10 +746,10 @@ if ($step == 4 && $datatoexport) //viewExcelFileContent($conf->export->dir_temp.'/1/export_member_1.xls',5,3); //viewCsvFileContent($conf->export->dir_temp.'/1/export_member_1.csv',5); //print ''; - } + } } - + print '
'; diff --git a/htdocs/langs/en_US/exports.lang b/htdocs/langs/en_US/exports.lang index 3b137bf3956..8376d4afa9b 100644 --- a/htdocs/langs/en_US/exports.lang +++ b/htdocs/langs/en_US/exports.lang @@ -33,4 +33,5 @@ FormatedExportDesc2=First step is to choose a predefined dataset, then to choose FormatedExportDesc3=When data to export are selected, you can define output file format you want to export your data to. Sheet=Sheet NoImportableData=No importable data (no module with definitions to allow data imports) -FileSuccessfullyBuilt=Export file generated \ No newline at end of file +FileSuccessfullyBuilt=Export file generated +SQLUsedForExport=SQL Request used to build export file diff --git a/htdocs/langs/fr_FR/exports.lang b/htdocs/langs/fr_FR/exports.lang index 05dcb205688..122e6c2bc01 100644 --- a/htdocs/langs/fr_FR/exports.lang +++ b/htdocs/langs/fr_FR/exports.lang @@ -33,4 +33,5 @@ FormatedExportDesc2=La première étape est de choisir un des lots de données p FormatedExportDesc3=Une fois les données sélectionnées, il est possible de choisir le format du fichier export généré. Sheet=Feuille NoImportableData=Pas de type de données importable (aucun module contenant des définitions de données importable n'est actif) -FileSuccessfullyBuilt=Fichier export généré \ No newline at end of file +FileSuccessfullyBuilt=Fichier export généré +SQLUsedForExport=Requête SQL utilisée pour construire le fichier export \ No newline at end of file diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index d90b08d5d72..438fed41ee5 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -1291,9 +1291,9 @@ function img_mime($file,$alt='') /** - * \brief Affiche info admin + * \brief Show information for admin users * \param text Text info - * \param infoonimgalt Info is shown on alt of star picto + * \param infoonimgalt Info is shown on alt of star picto, otherwise it is show on output * \return string String with info text */ function info_admin($texte,$infoonimgalt=0)