From 890e6f59c815a774e7f311170834ddec705d1b84 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 5 Aug 2016 13:08:23 +0200 Subject: [PATCH] NEW Support mass actions for proposals --- dev/skeletons/skeleton_list.php | 9 +- htdocs/comm/propal/list.php | 231 +++++++++++++++++++----- htdocs/commande/list.php | 12 +- htdocs/compta/facture/list.php | 1 + htdocs/core/actions_massactions.inc.php | 4 +- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/lib/files.lib.php | 20 +- 7 files changed, 217 insertions(+), 62 deletions(-) diff --git a/dev/skeletons/skeleton_list.php b/dev/skeletons/skeleton_list.php index 130582b3812..b53231e24a0 100644 --- a/dev/skeletons/skeleton_list.php +++ b/dev/skeletons/skeleton_list.php @@ -157,10 +157,11 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") ||GETPO if (empty($reshook)) { - $objectclass='Commande'; - $permtoread = $user->rights->commande->lire; - $permtodelete = $user->rights->commande->supprimer; - $uploaddir = $conf->commande->dir_output; + $objectclass='Skeleton'; + $objectlabel='Skeleton'; + $permtoread = $user->rights->skeleton->read; + $permtodelete = $user->rights->skeleton->delete; + $uploaddir = $conf->skeleton->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index ad338b150b7..4ba01b8cd31 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -51,6 +51,12 @@ $langs->load('products'); $socid=GETPOST('socid','int'); +$action=GETPOST('action','alpha'); +$massaction=GETPOST('massaction','alpha'); +$show_files=GETPOST('show_files','int'); +$confirm=GETPOST('confirm','alpha'); +$toselect = GETPOST('toselect', 'array'); + $search_user=GETPOST('search_user','int'); $search_sale=GETPOST('search_sale','int'); $search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha'); @@ -159,7 +165,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab */ if (GETPOST('cancel')) { $action='list'; $massaction=''; } -if (! GETPOST('confirmmassaction')) { $massaction=''; } +if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; } $parameters=array('socid'=>$socid); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks @@ -192,28 +198,19 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP $day=''; $viewstatut=''; $object_statut=''; + $toselect=''; $search_array_options=array(); } if ($object_statut != '') $viewstatut=$object_statut; if (empty($reshook)) { - // Mass actions. Controls on number of lines checked - $maxformassaction=1000; - if (! empty($massaction) && count($toselect) < 1) - { - $error++; - setEventMessages($langs->trans("NoLineChecked"), null, "warnings"); - } - if (! $error && count($toselect) > $maxformassaction) - { - setEventMessages($langs->trans('TooManyRecordForMassAction',$maxformassaction), null, 'errors'); - $error++; - } - - - - + $objectclass='Propal'; + $objectlabel='Proposals'; + $permtoread = $user->rights->propal->lire; + $permtodelete = $user->rights->propal->supprimer; + $uploaddir = $conf->propal->dir_output; + include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } @@ -222,7 +219,7 @@ if (empty($reshook)) * View */ -llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos'); +$now=dol_now(); $form = new Form($db); $formother = new FormOther($db); @@ -231,14 +228,15 @@ $formpropal = new FormPropal($db); $companystatic=new Societe($db); $formcompany=new FormCompany($db); -$now=dol_now(); +$help_url='EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos'; +llxHeader('',$langs->trans('Proposal'),$help_url); $sql = 'SELECT'; if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; -$sql.= ' s.rowid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, '; +$sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, '; $sql.= " typent.code as typent_code,"; $sql.= " state.code_departement as state_code, state.nom as state_name,"; -$sql.= ' p.rowid as propalid, p.note_private, p.total_ht, p.tva as total_vat, p.total as total_ttc, p.localtax1, p.localtax2, p.ref, p.ref_client, p.fk_statut, p.fk_user_author, p.datep as dp, p.fin_validite as dfv,'; +$sql.= ' p.rowid, p.note_private, p.total_ht, p.tva as total_vat, p.total as total_ttc, p.localtax1, p.localtax2, p.ref, p.ref_client, p.fk_statut, p.fk_user_author, p.datep as dp, p.fin_validite as dfv,'; $sql.= ' p.datec as date_creation, p.tms as date_update,'; if (! $user->rights->societe->client->voir && ! $socid) $sql .= " sc.fk_soc, sc.fk_user,"; $sql.= ' u.login'; @@ -340,19 +338,27 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) $sql.= $db->plimit($limit+1, $offset); -$result=$db->query($sql); -if ($result) +$resql=$db->query($sql); +if ($resql) { $objectstatic=new Propal($db); $userstatic=new User($db); - $num = $db->num_rows($result); - if ($socid) + if ($socid > 0) { $soc = new Societe($db); - $soc->fetch($socid); + $soc->fetch($socid); + $title = $langs->trans('ListOfProposals') . ' - '.$soc->name; } + else + { + $title = $langs->trans('ListOfProposals'); + } + $num = $db->num_rows($resql); + + $arrayofselected=is_array($toselect)?$toselect:array(); + $param='&socid='.$socid.'&viewstatut='.$viewstatut; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; @@ -375,10 +381,17 @@ if ($result) if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); } - //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"))); + // List of mass actions available + $arrayofmassactions = array( + 'presend'=>$langs->trans("SendByMail"), + 'builddoc'=>$langs->trans("PDFMerge"), + ); + if ($user->rights->propal->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete"); + if ($massaction == 'presend') $arrayofmassactions=array(); + $massactionbutton=$form->selectMassAction('', $arrayofmassactions); // Lignes des champs de filtre - print '
'; + print ''; if ($optioncss != '') print ''; print ''; print ''; @@ -386,12 +399,107 @@ if ($result) print ''; print ''; - print_barre_liste($langs->trans('ListOfProposals').' '.($socid?'- '.$soc->name:''), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,'title_commercial.png', 0, '', '', $limit); + print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit); + + if ($massaction == 'presend') + { + $langs->load("mails"); + + if (! GETPOST('cancel')) + { + $objecttmp=new Propal($db); + $listofselectedid=array(); + $listofselectedthirdparties=array(); + $listofselectedref=array(); + foreach($arrayofselected as $toselectid) + { + $result=$objecttmp->fetch($toselectid); + if ($result > 0) + { + $listofselectedid[$toselectid]=$toselectid; + $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid; + $listofselectedthirdparties[$thirdpartyid]=$thirdpartyid; + $listofselectedref[$thirdpartyid][$toselectid]=$objecttmp->ref; + } + } + } + + print ''; + + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + + dol_fiche_head(null, '', ''); + + $topicmail="SendProposalRef"; + $modelmail="propal_send"; + + // Cree l'objet formulaire mail + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + $formmail->withform=-1; + $formmail->fromtype = 'user'; + $formmail->fromid = $user->id; + $formmail->fromname = $user->getFullName($langs); + $formmail->frommail = $user->email; + if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 1)) // If bit 1 is set + { + $formmail->trackid='ord'.$object->id; + } + if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set + { + include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'ord'.$object->id); + } + $formmail->withfrom=1; + $liste=$langs->trans("AllRecipientSelected"); + if (count($listofselectedthirdparties) == 1) + { + $liste=array(); + $thirdpartyid=array_shift($listofselectedthirdparties); + $soc=new Societe($db); + $soc->fetch($thirdpartyid); + foreach ($soc->thirdparty_and_contact_email_array(1) as $key=>$value) + { + $liste[$key]=$value; + } + $formmail->withtoreadonly=0; + } + else + { + $formmail->withtoreadonly=1; + } + $formmail->withto=$liste; + $formmail->withtofree=0; + $formmail->withtocc=1; + $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; + $formmail->withtopic=$langs->transnoentities($topicmail, '__REF__', '__REFCLIENT__'); + $formmail->withfile=$langs->trans("OnlyPDFattachmentSupported"); + $formmail->withbody=1; + $formmail->withdeliveryreceipt=1; + $formmail->withcancel=1; + // Tableau des substitutions + $formmail->substit['__REF__']='__REF__'; // We want to keep the tag + $formmail->substit['__SIGNATURE__']=$user->signature; + $formmail->substit['__REFCLIENT__']='__REFCLIENT__'; // We want to keep the tag + $formmail->substit['__PERSONALIZED__']=''; + $formmail->substit['__CONTACTCIVNAME__']=''; + + // Tableau des parametres complementaires du post + $formmail->param['action']=$action; + $formmail->param['models']=$modelmail; + $formmail->param['models_id']=GETPOST('modelmailselected','int'); + $formmail->param['id']=join(',',$arrayofselected); + //$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; + + print $formmail->get_form(); + + dol_fiche_end(); + } if ($sall) { foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); - //sort($fieldstosearchall); print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall); } @@ -426,6 +534,11 @@ if ($result) $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1); $moreforfilter.=''; } + $parameters=array(); + $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook + if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; + else $moreforfilter = $hookmanager->resPrint; + if (! empty($moreforfilter)) { print '
'; @@ -438,6 +551,7 @@ if ($result) print ''."\n"; + // Fields title print ''; if (! empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'],$_SERVER["PHP_SELF"],'p.ref','',$param,'',$sortfield,$sortorder); if (! empty($arrayfields['p.ref_client']['checked'])) print_liste_field_titre($arrayfields['p.ref_client']['label'],$_SERVER["PHP_SELF"],'p.ref_client','',$param,'',$sortfield,$sortorder); @@ -473,8 +587,8 @@ if ($result) if (! empty($arrayfields['p.tms']['checked'])) print_liste_field_titre($arrayfields['p.tms']['label'],$_SERVER["PHP_SELF"],"p.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); if (! empty($arrayfields['p.fk_statut']['checked'])) print_liste_field_titre($arrayfields['p.fk_statut']['label'],$_SERVER["PHP_SELF"],"p.fk_statut","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch '); - print "\n"; - + print ''."\n"; + print ''; if (! empty($arrayfields['p.ref']['checked'])) { @@ -610,7 +724,7 @@ if ($result) } // Action column print ''; @@ -622,7 +736,7 @@ if ($result) $totalarray=array(); while ($i < min($num,$limit)) { - $obj = $db->fetch_object($result); + $obj = $db->fetch_object($resql); $var=!$var; print ''; @@ -630,7 +744,7 @@ if ($result) { print ''; + print ''; if (! $i) $totalarray['nbfield']++; print "\n"; @@ -863,15 +982,39 @@ if ($result) } - $db->free($result); + $db->free($resql); $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql); $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - print '
'; - $searchpitco=$form->showFilterAndCheckAddButtons(0); + $searchpitco=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1); print $searchpitco; print '
'; - $objectstatic->id=$obj->propalid; + $objectstatic->id=$obj->rowid; $objectstatic->ref=$obj->ref; print ''; @@ -644,7 +758,7 @@ if ($result) if (! empty($obj->note_private)) { print ' '; - print ''.img_picto($langs->trans("ViewPrivateNote"),'object_generic').''; + print ''.img_picto($langs->trans("ViewPrivateNote"),'object_generic').''; print ''; } print ''; @@ -652,7 +766,7 @@ if ($result) print '
'; $filename=dol_sanitizeFileName($obj->ref); $filedir=$conf->propal->dir_output . '/' . dol_sanitizeFileName($obj->ref); - $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->propalid; + $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid; print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir); print '
'; @@ -669,9 +783,7 @@ if ($result) if (! $i) $totalarray['nbfield']++; } - $url = DOL_URL_ROOT.'/comm/card.php?socid='.$obj->rowid; - - $companystatic->id=$obj->rowid; + $companystatic->id=$obj->socid; $companystatic->name=$obj->name; $companystatic->client=$obj->client; $companystatic->code_client=$obj->code_client; @@ -833,7 +945,14 @@ if ($result) if (! $i) $totalarray['nbfield']++; } // Action column - print '
'; + 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; + if (in_array($obj->rowid, $arrayofselected)) $selected=1; + print ''; + } + print '
'; + print ''."\n"; - print ''; + print ''."\n"; + + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) + { + /* + * Show list of available documents + */ + $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; + $urlsource.=str_replace('&','&',$param); + + $filedir=$diroutputmassaction; + $genallowed=$user->rights->propal->lire; + $delallowed=$user->rights->propal->lire; + + print '
'; + $paramwithoutshowfiles=preg_replace('/show_files=1&?/','',$param); + $title=$langs->trans("MassFilesArea").' ('.$langs->trans("Hide").')'; + + print $formfile->showdocuments('massfilesarea_proposals','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,''); + } + else + { + print '
'.$langs->trans("ShowTempMassFilesArea").''; + } + } else { diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 665ec578627..cc4a156746f 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -196,6 +196,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP if (empty($reshook)) { $objectclass='Commande'; + $objectlabel='Orders'; $permtoread = $user->rights->commande->lire; $permtodelete = $user->rights->commande->supprimer; $uploaddir = $conf->commande->dir_output; @@ -411,6 +412,7 @@ if ($resql) if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); } + // List of mass actions available $arrayofmassactions = array( 'presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"), @@ -1118,8 +1120,8 @@ if ($resql) print ''; if (! $i) $totalarray['nbfield']++; - print ''; - + print "\n"; + $total+=$obj->total_ht; $subtotal+=$obj->total_ht; $i++; @@ -1167,8 +1169,8 @@ if ($resql) $urlsource.=str_replace('&','&',$param); $filedir=$diroutputmassaction; - $genallowed=$user->rights->facture->lire; - $delallowed=$user->rights->facture->lire; + $genallowed=$user->rights->commande->lire; + $delallowed=$user->rights->commande->lire; print '
'; $paramwithoutshowfiles=preg_replace('/show_files=1&?/','',$param); @@ -1187,6 +1189,6 @@ else dol_print_error($db); } +// End of page llxFooter(); - $db->close(); diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index e3c0faff35e..bab9ab00769 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -219,6 +219,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter") || GETPOS if (empty($reshook)) { $objectclass='Facture'; + $objectlabel='Invoices'; $permtoread = $user->rights->facture->lire; $permtodelete = $user->rights->facture->supprimer; $uploaddir = $conf->facture->dir_output; diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 3c800f1f7fb..085f98b0218 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -23,7 +23,7 @@ // $massaction must be defined -// $objectclass must be defined +// $objectclass and $$objectlabel must be defined // $uploaddir (example $conf->projet->dir_output . "/";) // $toselect may be defined @@ -413,7 +413,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se dol_mkdir($diroutputmassaction); // Save merged file - $filename=strtolower(dol_sanitizeFileName($langs->transnoentities("Invoices"))); + $filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel))); if ($filter=='paye:0') { if ($option=='late') $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late"))); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 66bb880147f..310c7e6bb69 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5057,7 +5057,7 @@ class Form $out =' -