Fix better management of export of extrafield computed.

This commit is contained in:
Laurent Destailleur 2017-06-13 18:50:31 +02:00
parent c8856182a6
commit c088ccea32
6 changed files with 198 additions and 120 deletions

View File

@ -213,7 +213,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter") || GETPOS
$search_state=""; $search_state="";
$search_type=''; $search_type='';
$search_country=''; $search_country='';
$search_type_thirdparty=''; $search_type_thirdparty='';
$day=''; $day='';
$year=''; $year='';
$month=''; $month='';
@ -239,17 +239,17 @@ if (empty($reshook))
if ($massaction == 'withdrawrequest') if ($massaction == 'withdrawrequest')
{ {
$langs->load("withdrawals"); $langs->load("withdrawals");
if (!$user->rights->prelevement->bons->creer) if (!$user->rights->prelevement->bons->creer)
{ {
$error++; $error++;
setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors'); setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
} }
else else
{ {
//Checking error //Checking error
$error = 0; $error = 0;
$arrayofselected=is_array($toselect)?$toselect:array(); $arrayofselected=is_array($toselect)?$toselect:array();
$listofbills=array(); $listofbills=array();
foreach($arrayofselected as $toselectid) foreach($arrayofselected as $toselectid)
@ -274,7 +274,7 @@ if ($massaction == 'withdrawrequest')
$error++; $error++;
setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors'); setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
} }
$rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande"; $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
$rsql .= " , pfd.date_traite as date_traite"; $rsql .= " , pfd.date_traite as date_traite";
$rsql .= " , pfd.amount"; $rsql .= " , pfd.amount";
@ -291,7 +291,7 @@ if ($massaction == 'withdrawrequest')
{ {
$numprlv = $db->num_rows($result_sql); $numprlv = $db->num_rows($result_sql);
} }
if($numprlv>0){ if($numprlv>0){
$error++; $error++;
setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'errors'); setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'errors');
@ -300,7 +300,7 @@ if ($massaction == 'withdrawrequest')
$error++; $error++;
setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors'); setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors');
} }
} }
} }
@ -327,13 +327,13 @@ if ($massaction == 'withdrawrequest')
if ($nbwithdrawrequestok > 0) if ($nbwithdrawrequestok > 0)
{ {
setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs'); setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs');
} }
} }
} }
} }
/* /*
* View * View
@ -350,7 +350,7 @@ llxHeader('',$langs->trans('CustomersInvoices'),'EN:Customers_Invoices|FR:Factur
$sql = 'SELECT'; $sql = 'SELECT';
if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT';
$sql.= ' f.rowid as facid, f.facnumber, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,'; $sql.= ' f.rowid as id, f.facnumber as ref, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,';
$sql.= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,'; $sql.= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,';
$sql.= ' f.datef as df, f.date_lim_reglement as datelimite,'; $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,';
$sql.= ' f.paye as paye, f.fk_statut,'; $sql.= ' f.paye as paye, f.fk_statut,';
@ -360,7 +360,7 @@ $sql.= " typent.code as typent_code,";
$sql.= " state.code_departement as state_code, state.nom as state_name"; $sql.= " state.code_departement as state_code, state.nom as state_name";
// We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0) // We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0)
// TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field. // TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field.
if (! $sall) $sql.= ', SUM(pf.amount) as dynamount_payed'; if (! $sall) $sql.= ', SUM(pf.amount) as dynamount_payed';
// Add fields from extrafields // Add fields from extrafields
foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
// Add fields from hooks // Add fields from hooks
@ -424,7 +424,7 @@ if ($search_company) $sql .= natural_search('s.nom', $search_company);
if ($search_montant_ht != '') $sql.= natural_search('f.total', $search_montant_ht, 1); if ($search_montant_ht != '') $sql.= natural_search('f.total', $search_montant_ht, 1);
if ($search_montant_vat != '') $sql.= natural_search('f.tva', $search_montant_vat, 1); if ($search_montant_vat != '') $sql.= natural_search('f.tva', $search_montant_vat, 1);
if ($search_montant_localtax1 != '') $sql.= natural_search('f.localtax1', $search_montant_localtax1, 1); if ($search_montant_localtax1 != '') $sql.= natural_search('f.localtax1', $search_montant_localtax1, 1);
if ($search_montant_localtax2 != '') $sql.= natural_search('f.localtax2', $search_montant_localtax2, 1); if ($search_montant_localtax2 != '') $sql.= natural_search('f.localtax2', $search_montant_localtax2, 1);
if ($search_montant_ttc != '') $sql.= natural_search('f.total_ttc', $search_montant_ttc, 1); if ($search_montant_ttc != '') $sql.= natural_search('f.total_ttc', $search_montant_ttc, 1);
if ($search_status != '' && $search_status >= 0) if ($search_status != '' && $search_status >= 0)
{ {
@ -577,7 +577,7 @@ if ($resql)
$langs->load("withdrawals"); $langs->load("withdrawals");
$arrayofmassactions['withdrawrequest']=$langs->trans("MakeWithdrawRequest"); $arrayofmassactions['withdrawrequest']=$langs->trans("MakeWithdrawRequest");
} }
if ($user->rights->facture->supprimer) if ($user->rights->facture->supprimer)
{ {
//if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) || empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) //if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) || empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED))
if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED))
@ -608,8 +608,8 @@ if ($resql)
if ($massaction == 'presend') if ($massaction == 'presend')
{ {
$langs->load("mails"); $langs->load("mails");
if (! GETPOST('cancel')) if (! GETPOST('cancel'))
{ {
$objecttmp=new Facture($db); $objecttmp=new Facture($db);
$listofselectedid=array(); $listofselectedid=array();
@ -618,7 +618,7 @@ if ($resql)
foreach($arrayofselected as $toselectid) foreach($arrayofselected as $toselectid)
{ {
$result=$objecttmp->fetch($toselectid); $result=$objecttmp->fetch($toselectid);
if ($result > 0) if ($result > 0)
{ {
$listofselectedid[$toselectid]=$toselectid; $listofselectedid[$toselectid]=$toselectid;
$thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid; $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid;
@ -629,10 +629,10 @@ if ($resql)
} }
print '<input type="hidden" name="massaction" value="confirm_presend">'; print '<input type="hidden" name="massaction" value="confirm_presend">';
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db); $formmail = new FormMail($db);
dol_fiche_head(null, '', ''); dol_fiche_head(null, '', '');
$topicmail="SendBillRef"; $topicmail="SendBillRef";
@ -700,7 +700,7 @@ if ($resql)
//$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; //$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
print $formmail->get_form(); print $formmail->get_form();
dol_fiche_end(); dol_fiche_end();
} }
@ -709,7 +709,7 @@ if ($resql)
foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall); print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
} }
// If the user can view prospects other than his' // If the user can view prospects other than his'
$moreforfilter=''; $moreforfilter='';
if ($user->rights->societe->client->voir || $socid) if ($user->rights->societe->client->voir || $socid)
@ -753,7 +753,7 @@ if ($resql)
$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1); if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
print '<div class="div-table-responsive">'; print '<div class="div-table-responsive">';
print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n"; print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
@ -788,7 +788,7 @@ if ($resql)
print '</td>'; print '</td>';
} }
// Date invoice // Date invoice
if (! empty($arrayfields['f.date']['checked'])) if (! empty($arrayfields['f.date']['checked']))
{ {
print '<td class="liste_titre" align="center">'; print '<td class="liste_titre" align="center">';
if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.dol_escape_htmltag($day).'">'; if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.dol_escape_htmltag($day).'">';
@ -797,7 +797,7 @@ if ($resql)
print '</td>'; print '</td>';
} }
// Date due // Date due
if (! empty($arrayfields['f.date_lim_reglement']['checked'])) if (! empty($arrayfields['f.date_lim_reglement']['checked']))
{ {
print '<td class="liste_titre" align="center">'; print '<td class="liste_titre" align="center">';
if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day_lim" value="'.dol_escape_htmltag($day_lim).'">'; if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day_lim" value="'.dol_escape_htmltag($day_lim).'">';
@ -812,7 +812,7 @@ if ($resql)
print '<td class="liste_titre" align="left"><input class="flat" type="text" size="6" name="search_project" value="'.$search_project.'"></td>'; print '<td class="liste_titre" align="left"><input class="flat" type="text" size="6" name="search_project" value="'.$search_project.'"></td>';
} }
// Thirpdarty // Thirpdarty
if (! empty($arrayfields['s.nom']['checked'])) if (! empty($arrayfields['s.nom']['checked']))
{ {
print '<td class="liste_titre" align="left"><input class="flat" type="text" size="6" name="search_societe" value="'.$search_societe.'"></td>'; print '<td class="liste_titre" align="left"><input class="flat" type="text" size="6" name="search_societe" value="'.$search_societe.'"></td>';
} }
@ -842,7 +842,7 @@ if ($resql)
print '</td>'; print '</td>';
} }
// Payment mode // Payment mode
if (! empty($arrayfields['f.fk_mode_reglement']['checked'])) if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
{ {
print '<td class="liste_titre" align="left">'; print '<td class="liste_titre" align="left">';
$form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 0, 1, 10); $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 0, 1, 10);
@ -987,8 +987,8 @@ if ($resql)
if (! empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'],$_SERVER["PHP_SELF"],"f.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); if (! empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'],$_SERVER["PHP_SELF"],"f.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
if (! empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'],$_SERVER["PHP_SELF"],"fk_statut,paye,type,dynamount_payed","",$param,'align="right"',$sortfield,$sortorder); if (! empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'],$_SERVER["PHP_SELF"],"fk_statut,paye,type,dynamount_payed","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch '); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
print "</tr>\n"; print "</tr>\n";
if ($num > 0) if ($num > 0)
{ {
$i=0; $i=0;
@ -998,8 +998,8 @@ if ($resql)
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$datelimit=$db->jdate($obj->datelimite); $datelimit=$db->jdate($obj->datelimite);
$facturestatic->id=$obj->facid; $facturestatic->id=$obj->id;
$facturestatic->ref=$obj->facnumber; $facturestatic->ref=$obj->ref;
$facturestatic->type=$obj->type; $facturestatic->type=$obj->type;
$facturestatic->statut=$obj->fk_statut; $facturestatic->statut=$obj->fk_statut;
$facturestatic->date_lim_reglement=$db->jdate($obj->datelimite); $facturestatic->date_lim_reglement=$db->jdate($obj->datelimite);
@ -1011,28 +1011,28 @@ if ($resql)
$totaldeposits = $facturestatic->getSumDepositsUsed(); $totaldeposits = $facturestatic->getSumDepositsUsed();
$totalpay = $paiement + $totalcreditnotes + $totaldeposits; $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
$remaintopay = $obj->total_ttc - $totalpay; $remaintopay = $obj->total_ttc - $totalpay;
print '<tr class="oddeven">'; print '<tr class="oddeven">';
if (! empty($arrayfields['f.facnumber']['checked'])) if (! empty($arrayfields['f.facnumber']['checked']))
{ {
print '<td class="nowrap">'; print '<td class="nowrap">';
print '<table class="nobordernopadding"><tr class="nocellnopadd">'; print '<table class="nobordernopadding"><tr class="nocellnopadd">';
print '<td class="nobordernopadding nowrap">'; print '<td class="nobordernopadding nowrap">';
print $facturestatic->getNomUrl(1,'',200,0,'',0,1); print $facturestatic->getNomUrl(1,'',200,0,'',0,1);
print empty($obj->increment)?'':' ('.$obj->increment.')'; print empty($obj->increment)?'':' ('.$obj->increment.')';
print '</td>'; print '</td>';
print '<td style="min-width: 20px" class="nobordernopadding nowrap">'; print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
$filename=dol_sanitizeFileName($obj->facnumber); $filename=dol_sanitizeFileName($obj->ref);
$filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->facnumber); $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->ref);
$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->facid; $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->id;
print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir); print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
print '</table>'; print '</table>';
print "</td>\n"; print "</td>\n";
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
@ -1089,7 +1089,7 @@ if ($resql)
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
// Third party // Third party
if (! empty($arrayfields['s.nom']['checked'])) if (! empty($arrayfields['s.nom']['checked']))
{ {
@ -1256,18 +1256,18 @@ if ($resql)
print "</td>"; print "</td>";
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
} }
// Action column // Action column
print '<td class="nowrap" align="center">'; print '<td class="nowrap" align="center">';
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{ {
$selected=0; $selected=0;
if (in_array($obj->facid, $arrayofselected)) $selected=1; if (in_array($obj->id, $arrayofselected)) $selected=1;
print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected?' checked="checked"':'').'>'; print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected?' checked="checked"':'').'>';
} }
print '</td>' ; print '</td>' ;
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
print "</tr>\n"; print "</tr>\n";
$i++; $i++;
@ -1303,31 +1303,31 @@ if ($resql)
else print '<td></td>'; else print '<td></td>';
} }
print '</tr>'; print '</tr>';
} }
} }
$db->free($resql); $db->free($resql);
$parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql); $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
$reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
print "</table>\n"; print "</table>\n";
print '</div>'; print '</div>';
print "</form>\n"; print "</form>\n";
if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)
{ {
// Show list of available documents // Show list of available documents
$urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
$urlsource.=str_replace('&amp;','&',$param); $urlsource.=str_replace('&amp;','&',$param);
$filedir=$diroutputmassaction; $filedir=$diroutputmassaction;
$genallowed=$user->rights->facture->lire; $genallowed=$user->rights->facture->lire;
$delallowed=$user->rights->facture->lire; $delallowed=$user->rights->facture->lire;
print $formfile->showdocuments('massfilesarea_invoices','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,''); print $formfile->showdocuments('massfilesarea_invoices','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
} }
else else

View File

@ -8,7 +8,7 @@ if (empty($keyforselect) || empty($keyforelement) || empty($keyforaliasextra))
} }
// Add extra fields // Add extra fields
$sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = '".$keyforselect."' AND type != 'separate' AND entity IN (0, ".$conf->entity.')'; $sql="SELECT name, label, type, param, fieldcomputed, fielddefault FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = '".$keyforselect."' AND type != 'separate' AND entity IN (0, ".$conf->entity.')';
//print $sql; //print $sql;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) // This can fail when class is used on old database (during migration for example) if ($resql) // This can fail when class is used on old database (during migration for example)
@ -42,10 +42,23 @@ if ($resql) // This can fail when class is used on old database (during migra
if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp; if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
break; break;
} }
if ($obj->type!='separate') { if ($obj->type!='separate')
$this->export_fields_array[$r][$fieldname]=$fieldlabel; {
$this->export_TypeFields_array[$r][$fieldname]=$typeFilter; // If not a computed field
$this->export_entities_array[$r][$fieldname]=$keyforelement; if (empty($obj->fieldcomputed))
{
$this->export_fields_array[$r][$fieldname]=$fieldlabel;
$this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
$this->export_entities_array[$r][$fieldname]=$keyforelement;
}
// If this is a computed field
else
{
$this->export_fields_array[$r][$fieldname]=$fieldlabel;
$this->export_TypeFields_array[$r][$fieldname]=$typeFilter.'Compute';
$this->export_special_array[$r][$fieldname]=$obj->fieldcomputed;
$this->export_entities_array[$r][$fieldname]=$keyforelement;
}
} }
} }
} }

View File

@ -215,6 +215,9 @@ class DolibarrModules // Can not be abstract, because we need to insta
*/ */
public $descriptionlong; public $descriptionlong;
// For exports
/** /**
* @var string Module export code * @var string Module export code
*/ */
@ -225,6 +228,19 @@ class DolibarrModules // Can not be abstract, because we need to insta
*/ */
public $export_label; public $export_label;
public $export_permission;
public $export_fields_array;
public $export_TypeFields_array;
public $export_entities_array;
public $export_special_array; // special or computed field
public $export_dependencies_array;
public $export_sql_start;
public $export_sql_end;
public $export_sql_order;
// For import
/** /**
* @var string Module import code * @var string Module import code
*/ */
@ -235,6 +251,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
*/ */
public $import_label; public $import_label;
/** /**
* @var string Module constant name * @var string Module constant name
*/ */
@ -343,6 +360,13 @@ class DolibarrModules // Can not be abstract, because we need to insta
public $hidden = false; public $hidden = false;
/** /**
* Constructor. Define names, constants, directories, boxes, permissions * Constructor. Define names, constants, directories, boxes, permissions
* *

View File

@ -116,14 +116,14 @@ class modProjet extends DolibarrModules
$this->const[$r][3] = ""; $this->const[$r][3] = "";
$this->const[$r][4] = 0; $this->const[$r][4] = 0;
$r++; $r++;
$this->const[$r][0] = "PROJECT_USE_OPPORTUNITIES"; $this->const[$r][0] = "PROJECT_USE_OPPORTUNITIES";
$this->const[$r][1] = "chaine"; $this->const[$r][1] = "chaine";
$this->const[$r][2] = "1"; $this->const[$r][2] = "1";
$this->const[$r][3] = ""; $this->const[$r][3] = "";
$this->const[$r][4] = 0; $this->const[$r][4] = 0;
$r++; $r++;
$this->const[$r][0] = "MAIN_DELAY_PROJECT_TO_CLOSE"; $this->const[$r][0] = "MAIN_DELAY_PROJECT_TO_CLOSE";
$this->const[$r][1] = "chaine"; $this->const[$r][1] = "chaine";
$this->const[$r][2] = "7"; $this->const[$r][2] = "7";
@ -136,7 +136,7 @@ class modProjet extends DolibarrModules
$this->const[$r][3] = ""; $this->const[$r][3] = "";
$this->const[$r][4] = 0; $this->const[$r][4] = 0;
$r++; $r++;
// Boxes // Boxes
$this->boxes = array(); $this->boxes = array();
$r=0; $r=0;
@ -207,7 +207,7 @@ class modProjet extends DolibarrModules
//------- //-------
$this->menu = 1; // This module add menu entries. They are coded into menu manager. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
//Exports //Exports
//-------- //--------
$r=1; $r=1;
@ -240,15 +240,16 @@ class modProjet extends DolibarrModules
unset($this->export_fields_array[$r]['p.opp_amount']); unset($this->export_fields_array[$r]['p.opp_amount']);
unset($this->export_fields_array[$r]['cls.code']); unset($this->export_fields_array[$r]['cls.code']);
} }
// Add fields for project // Add fields for project
$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array()); $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array());
// Add extra fields for project
$keyforselect='projet'; $keyforelement='project'; $keyforaliasextra='extra'; $keyforselect='projet'; $keyforelement='project'; $keyforaliasextra='extra';
include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
// Add fields for tasks // Add fields for tasks
$this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array('pt.rowid'=>'RefTask','pt.label'=>'LabelTask','pt.dateo'=>"TaskDateStart",'pt.datee'=>"TaskDateEnd",'pt.duration_effective'=>"DurationEffective",'pt.planned_workload'=>"PlannedWorkload",'pt.progress'=>"Progress",'pt.description'=>"TaskDescription")); $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array('pt.rowid'=>'RefTask','pt.label'=>'LabelTask','pt.dateo'=>"TaskDateStart",'pt.datee'=>"TaskDateEnd",'pt.duration_effective'=>"DurationEffective",'pt.planned_workload'=>"PlannedWorkload",'pt.progress'=>"Progress",'pt.description'=>"TaskDescription"));
$this->export_entities_array[$r]=array_merge($this->export_entities_array[$r], array('pt.rowid'=>'projecttask','pt.label'=>'projecttask','pt.dateo'=>"projecttask",'pt.datee'=>"projecttask",'pt.duration_effective'=>"projecttask",'pt.planned_workload'=>"projecttask",'pt.progress'=>"projecttask",'pt.description'=>"projecttask")); $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r], array('pt.rowid'=>'projecttask','pt.label'=>'projecttask','pt.dateo'=>"projecttask",'pt.datee'=>"projecttask",'pt.duration_effective'=>"projecttask",'pt.planned_workload'=>"projecttask",'pt.progress'=>"projecttask",'pt.description'=>"projecttask"));
// Add extra fields // Add extra fields for task
$keyforselect='projet_task'; $keyforelement='projecttask'; $keyforaliasextra='extra2'; $keyforselect='projet_task'; $keyforelement='projecttask'; $keyforaliasextra='extra2';
include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
// End add extra fields // End add extra fields
@ -264,8 +265,8 @@ class modProjet extends DolibarrModules
$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task_time as ptt ON pt.rowid = ptt.fk_task"; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task_time as ptt ON pt.rowid = ptt.fk_task";
$this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON p.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON p.fk_soc = s.rowid';
$this->export_sql_end[$r] .=' WHERE p.entity = '.$conf->entity; $this->export_sql_end[$r] .=' WHERE p.entity = '.$conf->entity;
// Import list of tasks // Import list of tasks
if (empty($conf->global->PROJECT_HIDE_TASKS)) if (empty($conf->global->PROJECT_HIDE_TASKS))
{ {
@ -297,7 +298,7 @@ class modProjet extends DolibarrModules
//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t'); //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
$this->import_regex_array[$r]=array('t.dateo'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','t.datee'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','t.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$'); $this->import_regex_array[$r]=array('t.dateo'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','t.datee'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','t.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$');
$this->import_examplevalues_array[$r]=array('t.fk_projet'=>'MyProjectRef','t.ref'=>"auto or TK2010-1234",'t.label'=>"My task",'t.progress'=>"0 (not started) to 100 (finished)",'t.datec'=>'1972-10-10','t.note_private'=>"My private note",'t.note_public'=>"My public note"); $this->import_examplevalues_array[$r]=array('t.fk_projet'=>'MyProjectRef','t.ref'=>"auto or TK2010-1234",'t.label'=>"My task",'t.progress'=>"0 (not started) to 100 (finished)",'t.datec'=>'1972-10-10','t.note_private'=>"My private note",'t.note_public'=>"My public note");
} }
} }

View File

@ -38,6 +38,7 @@ class Export
var $array_export_sql_start=array(); // Tableau des "requetes sql" var $array_export_sql_start=array(); // Tableau des "requetes sql"
var $array_export_sql_end=array(); // Tableau des "requetes sql" var $array_export_sql_end=array(); // Tableau des "requetes sql"
var $array_export_sql_order=array(); // Tableau des "requetes sql" var $array_export_sql_order=array(); // Tableau des "requetes sql"
var $array_export_fields=array(); // Tableau des listes de champ+libelle a exporter var $array_export_fields=array(); // Tableau des listes de champ+libelle a exporter
var $array_export_TypeFields=array(); // Tableau des listes de champ+Type de filtre var $array_export_TypeFields=array(); // Tableau des listes de champ+Type de filtre
var $array_export_FilterValue=array(); // Tableau des listes de champ+Valeur a filtrer var $array_export_FilterValue=array(); // Tableau des listes de champ+Valeur a filtrer
@ -45,7 +46,7 @@ class Export
var $array_export_dependencies=array(); // array of list of entities that must take care of the DISTINCT if a field is added into export var $array_export_dependencies=array(); // array of list of entities that must take care of the DISTINCT if a field is added into export
var $array_export_special=array(); // Tableau des operations speciales sur champ var $array_export_special=array(); // Tableau des operations speciales sur champ
var $array_export_examplevalues=array(); // array with examples var $array_export_examplevalues=array(); // array with examples
// To store export modules // To store export modules
var $hexa; var $hexa;
var $hexafiltervalue; var $hexafiltervalue;
@ -178,7 +179,7 @@ class Export
$this->array_export_special[$i]=(! empty($module->export_special_array[$r])?$module->export_special_array[$r]:''); $this->array_export_special[$i]=(! empty($module->export_special_array[$r])?$module->export_special_array[$r]:'');
// Array of examples // Array of examples
$this->array_export_examplevalues[$i]=$module->export_examplevalues_array[$r]; $this->array_export_examplevalues[$i]=$module->export_examplevalues_array[$r];
// Requete sql du dataset // Requete sql du dataset
$this->array_export_sql_start[$i]=$module->export_sql_start[$r]; $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_end[$i]=$module->export_sql_end[$r];
@ -246,7 +247,7 @@ class Export
} }
$sql.=$sqlWhere; $sql.=$sqlWhere;
} }
// Add the order // Add the order
$sql.=$this->array_export_sql_order[$indice]; $sql.=$this->array_export_sql_order[$indice];
@ -259,7 +260,7 @@ class Export
if (preg_match('/GROUP_CONCAT/i', $key) and $value != '') $sql.=" HAVING ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]); if (preg_match('/GROUP_CONCAT/i', $key) and $value != '') $sql.=" HAVING ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
} }
} }
return $sql; return $sql;
} }
@ -281,7 +282,7 @@ class Export
if (! (strpos($ValueField, '%') === false)) if (! (strpos($ValueField, '%') === false))
$szFilterQuery.=" ".$NameField." LIKE '".$ValueField."'"; $szFilterQuery.=" ".$NameField." LIKE '".$ValueField."'";
else else
$szFilterQuery.=" ".$NameField."='".$ValueField."'"; $szFilterQuery.=" ".$NameField." = '".$ValueField."'";
break; break;
case 'Date': case 'Date':
if (strpos($ValueField, "+") > 0) if (strpos($ValueField, "+") > 0)
@ -325,8 +326,12 @@ class Export
case 'List': case 'List':
if (is_numeric($ValueField)) if (is_numeric($ValueField))
$szFilterQuery=" ".$NameField."=".$ValueField; $szFilterQuery=" ".$NameField."=".$ValueField;
else else {
$szFilterQuery=" ".$NameField."='".$ValueField."'"; if (! (strpos($ValueField, '%') === false))
$szFilterQuery=" ".$NameField." LIKE '".$ValueField."'";
else
$szFilterQuery=" ".$NameField." = '".$ValueField."'";
}
break; break;
default: default:
dol_syslog("Error we try to forge an sql export request with a condition on a field with type '".$InfoFieldList[0]."' (defined into module descriptor) but this type is unknown/not supported. It looks like a bug into module descriptor.", LOG_ERR); dol_syslog("Error we try to forge an sql export request with a condition on a field with type '".$InfoFieldList[0]."' (defined into module descriptor) but this type is unknown/not supported. It looks like a bug into module descriptor.", LOG_ERR);
@ -589,10 +594,8 @@ class Export
$var=true; $var=true;
while ($objp = $this->db->fetch_object($resql)) while ($obj = $this->db->fetch_object($resql))
{ {
// Process special operations // Process special operations
if (! empty($this->array_export_special[$indice])) if (! empty($this->array_export_special[$indice]))
{ {
@ -604,14 +607,14 @@ class Export
{ {
//$alias=$this->array_export_alias[$indice][$key]; //$alias=$this->array_export_alias[$indice][$key];
$alias=str_replace(array('.', '-','(',')'),'_',$key); $alias=str_replace(array('.', '-','(',')'),'_',$key);
if ($objp->$alias < 0) $objp->$alias=''; if ($obj->$alias < 0) $obj->$alias='';
} }
// Operation ZEROIFNEG // Operation ZEROIFNEG
elseif ($this->array_export_special[$indice][$key]=='ZEROIFNEG') elseif ($this->array_export_special[$indice][$key]=='ZEROIFNEG')
{ {
//$alias=$this->array_export_alias[$indice][$key]; //$alias=$this->array_export_alias[$indice][$key];
$alias=str_replace(array('.', '-','(',')'),'_',$key); $alias=str_replace(array('.', '-','(',')'),'_',$key);
if ($objp->$alias < 0) $objp->$alias='0'; if ($obj->$alias < 0) $obj->$alias='0';
} }
// Operation INVOICEREMAINTOPAY // Operation INVOICEREMAINTOPAY
elseif ($this->array_export_special[$indice][$key]=='getRemainToPay') elseif ($this->array_export_special[$indice][$key]=='getRemainToPay')
@ -619,29 +622,34 @@ class Export
//$alias=$this->array_export_alias[$indice][$key]; //$alias=$this->array_export_alias[$indice][$key];
$alias=str_replace(array('.', '-','(',')'),'_',$key); $alias=str_replace(array('.', '-','(',')'),'_',$key);
$remaintopay=''; $remaintopay='';
if ($objp->f_rowid > 0) if ($obj->f_rowid > 0)
{ {
global $tmpobjforcomputecall; global $tmpobjforcomputecall;
if (! is_object($tmpobjforcomputecall)) if (! is_object($tmpobjforcomputecall))
{ {
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$tmpobjforcomputecall=new Facture($this->db); $tmpobjforcomputecall=new Facture($this->db);
} }
$tmpobjforcomputecall->id = $objp->f_rowid; $tmpobjforcomputecall->id = $obj->f_rowid;
$tmpobjforcomputecall->total_ttc = $objp->f_total_ttc; $tmpobjforcomputecall->total_ttc = $obj->f_total_ttc;
$remaintopay=$tmpobjforcomputecall->getRemainToPay(); $remaintopay=$tmpobjforcomputecall->getRemainToPay();
} }
$objp->$alias=$remaintopay; $obj->$alias=$remaintopay;
} }
else else
{ {
$this->error='Operation '.$this->array_export_special[$indice][$key].' not supported.'; // TODO FIXME Export of compute field does not work. $obj containt $obj->alias_field and formulat will contains $obj->field
$computestring=$this->array_export_special[$indice][$key];
$tmp=dol_eval($computestring, 1, 0);
$obj->$alias=$tmp;
$this->error="ERROPNOTSUPPORTED. Operation ".$this->array_export_special[$indice][$key]." not supported. Export of 'computed' extrafields is not yet supported, please remove field.";
return -1; return -1;
} }
} }
} }
// end of special operation processing // end of special operation processing
$objmodel->write_record($array_selected,$objp,$outputlangs,$this->array_export_TypeFields[$indice]); $objmodel->write_record($array_selected,$obj,$outputlangs,$this->array_export_TypeFields[$indice]);
} }
// Genere en-tete // Genere en-tete
@ -732,7 +740,7 @@ class Export
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->model_name = $obj->label; $this->model_name = $obj->label;
$this->datatoexport = $obj->type; $this->datatoexport = $obj->type;
$this->hexa = $obj->field; $this->hexa = $obj->field;
$this->hexafiltervalue = $obj->filter; $this->hexafiltervalue = $obj->filter;

View File

@ -168,7 +168,7 @@ if ($action=='selectfield') // Selection of field at step 2
$warnings=array(); $warnings=array();
$array_selected[$field]=count($array_selected)+1; // We tag the key $field as "selected" $array_selected[$field]=count($array_selected)+1; // We tag the key $field as "selected"
// We check if there is a dependency to activate // We check if there is a dependency to activate
/*var_dump($field); /*var_dump($field);
var_dump($fieldsentitiesarray[$field]); var_dump($fieldsentitiesarray[$field]);
var_dump($fieldsdependenciesarray);*/ var_dump($fieldsdependenciesarray);*/
@ -187,7 +187,7 @@ if ($action=='selectfield') // Selection of field at step 2
if (is_array($tmp)) $listofdependencies=$tmp; if (is_array($tmp)) $listofdependencies=$tmp;
else $listofdependencies=array($tmp); else $listofdependencies=array($tmp);
} }
if (count($listofdependencies)) if (count($listofdependencies))
{ {
foreach($listofdependencies as $fieldid) foreach($listofdependencies as $fieldid)
@ -270,7 +270,7 @@ if ($action == 'builddoc')
{ {
@ini_set("max_execution_time", $max_execution_time_for_export); // This work only if safe mode is off. also web servers has timeout of 300 @ini_set("max_execution_time", $max_execution_time_for_export); // This work only if safe mode is off. also web servers has timeout of 300
} }
// Build export file // Build export file
$result=$objexport->build_file($user, GETPOST('model','alpha'), $datatoexport, $array_selected, $array_filtervalue); $result=$objexport->build_file($user, GETPOST('model','alpha'), $datatoexport, $array_selected, $array_filtervalue);
if ($result < 0) if ($result < 0)
@ -535,9 +535,9 @@ if ($step == 2 && $datatoexport)
print '</table>'; print '</table>';
print '</div>'; print '</div>';
dol_fiche_end(); dol_fiche_end();
print '<br>'; print '<br>';
// Combo list of export models // Combo list of export models
@ -561,7 +561,7 @@ if ($step == 2 && $datatoexport)
print '<td>'.$langs->trans("ExportableFields").'</td>'; print '<td>'.$langs->trans("ExportableFields").'</td>';
print '<td width="100" align="center">'; print '<td width="100" align="center">';
print '<a class="liste_titre" title='.$langs->trans("All").' alt='.$langs->trans("All").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field=all">'.$langs->trans("All")."</a>"; print '<a class="liste_titre" title='.$langs->trans("All").' alt='.$langs->trans("All").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field=all">'.$langs->trans("All")."</a>";
print '/'; print ' / ';
print '<a class="liste_titre" title='.$langs->trans("None").' alt='.$langs->trans("None").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field=all">'.$langs->trans("None")."</a>"; print '<a class="liste_titre" title='.$langs->trans("None").' alt='.$langs->trans("None").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field=all">'.$langs->trans("None")."</a>";
print '</td>'; print '</td>';
print '<td width="44%">'.$langs->trans("ExportedFields").'</td>'; print '<td width="44%">'.$langs->trans("ExportedFields").'</td>';
@ -585,7 +585,7 @@ if ($step == 2 && $datatoexport)
foreach($fieldsarray as $code=>$label) foreach($fieldsarray as $code=>$label)
{ {
print '<tr class="oddeven">'; print '<tr class="oddeven">';
$i++; $i++;
@ -597,7 +597,7 @@ if ($step == 2 && $datatoexport)
print '<td class="nowrap">'; print '<td class="nowrap">';
// If value of entityicon=entitylang='icon:Label' // If value of entityicon=entitylang='icon:Label'
//print $code.'-'.$label.'-'.$entity; //print $code.'-'.$label.'-'.$entity;
$tmparray=explode(':',$entityicon); $tmparray=explode(':',$entityicon);
if (count($tmparray) >=2) if (count($tmparray) >=2)
{ {
@ -606,7 +606,9 @@ if ($step == 2 && $datatoexport)
} }
print img_object('',$entityicon).' '.$langs->trans($entitylang); print img_object('',$entityicon).' '.$langs->trans($entitylang);
print '</td>'; print '</td>';
$text=$langs->trans($label);
$text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($label).(empty($objexport->array_export_special[0][$code])?'':'</i>');
$tablename=getablenamefromfield($code,$sqlmaxforexport); $tablename=getablenamefromfield($code,$sqlmaxforexport);
$htmltext ='<b>'.$langs->trans("Name").":</b> ".$text.'<br>'; $htmltext ='<b>'.$langs->trans("Name").":</b> ".$text.'<br>';
if (! empty($objexport->array_export_special[0][$code])) if (! empty($objexport->array_export_special[0][$code]))
@ -617,11 +619,16 @@ if ($step == 2 && $datatoexport)
{ {
$htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>"; $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
} }
if (! empty($objexport->array_export_examplevalues[0][$code])) if (! empty($objexport->array_export_examplevalues[0][$code]))
{ {
$htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>'; $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
} }
if (isset($array_selected[$code]) && $array_selected[$code]) if (! empty($objexport->array_export_TypeFields[0][$code]))
{
$htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
}
if (isset($array_selected[$code]) && $array_selected[$code])
{ {
// Selected fields // Selected fields
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
@ -649,7 +656,7 @@ if ($step == 2 && $datatoexport)
print '</table>'; print '</table>';
/* /*
* Barre d'action * Barre d'action
*/ */
@ -740,7 +747,7 @@ if ($step == 3 && $datatoexport)
print '</table>'; print '</table>';
print '</div>'; print '</div>';
print '<br>'; print '<br>';
// Combo list of export models // Combo list of export models
@ -772,7 +779,6 @@ if ($step == 3 && $datatoexport)
// on boucle sur les champs // on boucle sur les champs
foreach($fieldsarray as $code => $label) foreach($fieldsarray as $code => $label)
{ {
print '<tr class="oddeven">'; print '<tr class="oddeven">';
$i++; $i++;
@ -794,15 +800,27 @@ if ($step == 3 && $datatoexport)
// Field name // Field name
$labelName=(! empty($fieldsarray[$code])?$fieldsarray[$code]:''); $labelName=(! empty($fieldsarray[$code])?$fieldsarray[$code]:'');
$ValueFilter=(! empty($array_filtervalue[$code])?$array_filtervalue[$code]:''); $ValueFilter=(! empty($array_filtervalue[$code])?$array_filtervalue[$code]:'');
$text=$langs->trans($labelName); $text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>');
$tablename=getablenamefromfield($code,$sqlmaxforexport); $tablename=getablenamefromfield($code,$sqlmaxforexport);
$htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>'; $htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
$htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>"; if (! empty($objexport->array_export_special[0][$code]))
{
$htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
}
else
{
$htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
}
if (! empty($objexport->array_export_examplevalues[0][$code])) if (! empty($objexport->array_export_examplevalues[0][$code]))
{ {
$htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>'; $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
} }
if (! empty($objexport->array_export_TypeFields[0][$code]))
{
$htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
}
print '<td>'; print '<td>';
print $form->textwithpicto($text,$htmltext); print $form->textwithpicto($text,$htmltext);
print '</td>'; print '</td>';
@ -849,7 +867,7 @@ if ($step == 4 && $datatoexport)
header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport); header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
exit; exit;
} }
asort($array_selected); asort($array_selected);
llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones'); llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
@ -937,7 +955,7 @@ if ($step == 4 && $datatoexport)
print '</table>'; print '</table>';
print '</div>'; print '</div>';
print '<br>'; print '<br>';
// Select request if all fields are selected // Select request if all fields are selected
@ -957,7 +975,6 @@ if ($step == 4 && $datatoexport)
$var=true; $var=true;
foreach($array_selected as $code=>$value) foreach($array_selected as $code=>$value)
{ {
print '<tr class="oddeven">'; print '<tr class="oddeven">';
$entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]); $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
@ -975,15 +992,30 @@ if ($step == 4 && $datatoexport)
print img_object('',$entityicon).' '.$langs->trans($entitylang); print img_object('',$entityicon).' '.$langs->trans($entitylang);
print '</td>'; print '</td>';
print '<td>'; $labelName=$objexport->array_export_fields[0][$code];
$text=$langs->trans($objexport->array_export_fields[0][$code]);
$text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>');
$tablename=getablenamefromfield($code,$sqlmaxforexport); $tablename=getablenamefromfield($code,$sqlmaxforexport);
$htmltext ='<b>'.$langs->trans("Name").":</b> ".$text.'<br>'; $htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
$htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>"; if (! empty($objexport->array_export_special[0][$code]))
if (! empty($objexport->array_export_examplevalues[0][$code])) {
{ $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
$htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>'; }
} else
{
$htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
}
if (! empty($objexport->array_export_examplevalues[0][$code]))
{
$htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
}
if (! empty($objexport->array_export_TypeFields[0][$code]))
{
$htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
}
print '<td>';
print $form->textwithpicto($text,$htmltext); print $form->textwithpicto($text,$htmltext);
//print ' ('.$code.')'; //print ' ('.$code.')';
print '</td>'; print '</td>';
@ -1056,7 +1088,7 @@ if ($step == 4 && $datatoexport)
$var=false; $var=false;
while ($i < $num) while ($i < $num)
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
print '<tr class="oddeven"><td>'; print '<tr class="oddeven"><td>';
print $obj->label; print $obj->label;
@ -1085,7 +1117,7 @@ if ($step == 5 && $datatoexport)
header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport); header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
exit; exit;
} }
asort($array_selected); asort($array_selected);
llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones'); llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
@ -1135,7 +1167,7 @@ if ($step == 5 && $datatoexport)
print '<div class="fichecenter">'; print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<table width="100%" class="border">'; print '<table width="100%" class="border">';
// Module // Module
@ -1186,7 +1218,7 @@ if ($step == 5 && $datatoexport)
print '</table>'; print '</table>';
print '</div>'; print '</div>';
print '<br>'; print '<br>';
print $langs->trans("NowClickToGenerateToBuildExportFile").'<br>'; print $langs->trans("NowClickToGenerateToBuildExportFile").'<br>';
@ -1210,7 +1242,7 @@ if ($step == 5 && $datatoexport)
unset($liste[$key]); unset($liste[$key]);
} }
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td width="16">'.img_picto_common($key,$objmodelexport->getPictoForKey($key)).'</td>'; print '<td width="16">'.img_picto_common($key,$objmodelexport->getPictoForKey($key)).'</td>';
$text=$objmodelexport->getDriverDescForKey($key); $text=$objmodelexport->getDriverDescForKey($key);
@ -1222,7 +1254,7 @@ if ($step == 5 && $datatoexport)
print '</div>'; print '</div>';
print '<table width="100%">'; print '<table width="100%">';
if ($sqlusedforexport && $user->admin) if ($sqlusedforexport && $user->admin)
@ -1233,7 +1265,7 @@ if ($step == 5 && $datatoexport)
} }
print '</table>'; print '</table>';
print '<div class="fichecenter"><div class="fichehalfleft">'; print '<div class="fichecenter"><div class="fichehalfleft">';
if (! is_dir($conf->export->dir_temp)) dol_mkdir($conf->export->dir_temp); if (! is_dir($conf->export->dir_temp)) dol_mkdir($conf->export->dir_temp);
@ -1243,7 +1275,7 @@ if ($step == 5 && $datatoexport)
print $formfile->showdocuments('export','',$upload_dir,$_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport,$liste,1,(! empty($_POST['model'])?$_POST['model']:'csv'),1,1); print $formfile->showdocuments('export','',$upload_dir,$_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport,$liste,1,(! empty($_POST['model'])?$_POST['model']:'csv'),1,1);
print '</div><div class="fichehalfright"><div class="ficheaddleft">'; print '</div><div class="fichehalfright"><div class="ficheaddleft">';
print '</div></div></div>'; print '</div></div></div>';
} }
@ -1265,11 +1297,11 @@ function getablenamefromfield($code,$sqlmaxforexport)
{ {
$alias=preg_replace('/\.(.*)$/i','',$code); // Keep only 'Alias' and remove '.Fieldname' $alias=preg_replace('/\.(.*)$/i','',$code); // Keep only 'Alias' and remove '.Fieldname'
$regexstring='/([a-zA-Z_]+) as '.preg_quote($alias).'[, \)]/i'; $regexstring='/([a-zA-Z_]+) as '.preg_quote($alias).'[, \)]/i';
$newsql=$sqlmaxforexport; $newsql=$sqlmaxforexport;
$newsql=preg_replace('/^(.*) FROM /i','',$newsql); // Remove part before the FROM $newsql=preg_replace('/^(.*) FROM /i','',$newsql); // Remove part before the FROM
$newsql=preg_replace('/WHERE (.*)$/i','',$newsql); // Remove part after the WHERE so we have now only list of table aliases in a string. We must keep the ' ' before WHERE $newsql=preg_replace('/WHERE (.*)$/i','',$newsql); // Remove part after the WHERE so we have now only list of table aliases in a string. We must keep the ' ' before WHERE
if (preg_match($regexstring,$newsql,$reg)) if (preg_match($regexstring,$newsql,$reg))
{ {
return $reg[1]; // The tablename return $reg[1]; // The tablename