Fix delete of member

This commit is contained in:
Laurent Destailleur
2017-06-09 17:02:05 +02:00
parent def784a5fe
commit 3347316d3c
7 changed files with 177 additions and 176 deletions

View File

@@ -45,7 +45,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
$langs->loadLangs(array("orders",'sendings','deliveries','companies','compta','bills'));
$action=GETPOST('action','alpha');
$action=GETPOST('action','aZ09');
$massaction=GETPOST('massaction','alpha');
$show_files=GETPOST('show_files','int');
$confirm=GETPOST('confirm','alpha');
@@ -160,7 +160,7 @@ if (empty($reshook))
{
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers
{
@@ -202,51 +202,51 @@ if (empty($reshook))
// TODO Move this into mass action include
if ($massaction == 'confirm_createbills') {
$orders = GETPOST('toselect');
$createbills_onebythird = GETPOST('createbills_onebythird', 'int');
$validate_invoices = GETPOST('valdate_invoices', 'int');
$TFact = array();
$TFactThird = array();
$nb_bills_created = 0;
$db->begin();
foreach($orders as $id_order) {
$cmd = new Commande($db);
if($cmd->fetch($id_order) <= 0) continue;
$object = new Facture($db);
if(!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $object = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order.
else {
$object->socid = $cmd->socid;
$object->type = Facture::TYPE_STANDARD;
$object->cond_reglement_id = $cmd->cond_reglement_id;
$object->mode_reglement_id = $cmd->mode_reglement_id;
$object->fk_project = $cmd->fk_project;
$datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
if (empty($datefacture))
{
$datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
}
$object->date = $datefacture;
$object->origin = 'commande';
$object->origin_id = $id_order;
$res = $object->create($user);
if($res > 0) $nb_bills_created++;
}
if($object->id > 0) {
$db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
$sql.= "fk_source";
@@ -259,7 +259,7 @@ if (empty($reshook))
$sql.= ", ".$object->id;
$sql.= ", '".$object->element."'";
$sql.= ")";
if ($db->query($sql))
{
$db->commit();
@@ -268,17 +268,17 @@ if (empty($reshook))
{
$db->rollback();
}
$lines = $cmd->lines;
if (empty($lines) && method_exists($cmd, 'fetch_lines'))
{
$cmd->fetch_lines();
$lines = $cmd->lines;
}
$fk_parent_line=0;
$num=count($lines);
for ($i=0;$i<$num;$i++)
{
$desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
@@ -367,43 +367,43 @@ if (empty($reshook))
$fk_parent_line = $result;
}
}
}
}
}
$cmd->classifyBilled($user);
if(!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $object;
else $TFact[$object->id] = $object;
}
// Build doc with all invoices
$TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
$toselect = array();
if(!empty($validate_invoices)) {
$massaction = $action = 'builddoc';
foreach($TAllFact as &$object) {
$object->validate($user);
$toselect[] = $object->id; // For builddoc action
// Fac builddoc
$upload_dir = $conf->facture->dir_output;
$permissioncreate=$user->rights->facture->creer;
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
}
$objectclass='Facture';
$objectlabel='Invoice';
$permtoread = $user->rights->facture->lire;
$permtodelete = $user->rights->facture->supprimer;
$uploaddir = $conf->facture->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
}
if (! $error)
{
$db->commit();
@@ -418,7 +418,7 @@ if (empty($reshook))
setEventMessages($object->error, $object->errors, 'errors');
$error++;
}
}
}
}
@@ -596,9 +596,9 @@ if ($resql)
$title.=' - '.$langs->trans('StatusOrderValidated').', '.(empty($conf->expedition->enabled)?'':$langs->trans("StatusOrderSent").', ').$langs->trans('StatusOrderToBill');
$num = $db->num_rows($resql);
$arrayofselected=is_array($toselect)?$toselect:array();
$param='';
if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
@@ -629,7 +629,7 @@ if ($resql)
$tmpkey=preg_replace('/search_options_/','',$key);
if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
}
// List of mass actions available
$arrayofmassactions = array(
'presend'=>$langs->trans("SendByMail"),
@@ -653,12 +653,12 @@ if ($resql)
print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit);
// TODO Move this into an invluce
if ($massaction == 'presend')
{
$langs->load("mails");
if (! GETPOST('cancel'))
{
$objecttmp=new Commande($db);
@@ -677,14 +677,14 @@ if ($resql)
}
}
}
print '<input type="hidden" name="massaction" value="confirm_presend">';
dol_fiche_head(null, '', '');
$topicmail="SendOrderRef";
$modelmail="order_send";
// Cree l'objet formulaire mail
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
@@ -737,23 +737,23 @@ if ($resql)
$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();
}
elseif ($massaction == 'createbills')
{
//var_dump($_REQUEST);
print '<input type="hidden" name="massaction" value="confirm_createbills">';
print '<table class="border" width="100%" >';
print '<tr>';
print '<td class="titlefieldmiddle">';
@@ -780,7 +780,7 @@ if ($resql)
print '</td>';
print '</tr>';
print '</table>';
print '<br>';
print '<div class="center">';
print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
@@ -788,13 +788,13 @@ if ($resql)
print '</div>';
print '<br>';
}
if ($sall)
{
foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
}
$moreforfilter='';
// If the user can view prospects other than his'
@@ -828,7 +828,7 @@ if ($resql)
$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 '<div class="liste_titre liste_titre_bydiv centpercent">';
@@ -839,27 +839,27 @@ if ($resql)
$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
print '<div class="div-table-responsive">';
print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
print '<tr class="liste_titre_filter">';
// Ref
if (! empty($arrayfields['c.ref']['checked']))
if (! empty($arrayfields['c.ref']['checked']))
{
print '<td class="liste_titre">';
print '<input class="flat" size="6" type="text" name="search_ref" value="'.$search_ref.'">';
print '</td>';
}
// Ref customer
if (! empty($arrayfields['c.ref_client']['checked']))
if (! empty($arrayfields['c.ref_client']['checked']))
{
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="6" name="search_ref_customer" value="'.$search_ref_customer.'">';
print '</td>';
}
// Thirpdarty
if (! empty($arrayfields['s.nom']['checked']))
if (! empty($arrayfields['s.nom']['checked']))
{
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" name="search_company" value="'.$search_company.'">';
@@ -899,7 +899,7 @@ if ($resql)
$formother->select_year($orderyear?$orderyear:-1,'orderyear',1, 20, 5);
print '</td>';
}
if (! empty($arrayfields['c.date_delivery']['checked']))
if (! empty($arrayfields['c.date_delivery']['checked']))
{
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="deliveryday" value="'.$deliveryday.'">';
@@ -972,10 +972,10 @@ if ($resql)
{
print '<td class="liste_titre maxwidthonsmartphone" align="right">';
$liststatus=array(
Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraftShort"),
Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
Commande::STATUS_ACCEPTED=>$langs->trans("StatusOrderSentShort"),
Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraftShort"),
Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
Commande::STATUS_ACCEPTED=>$langs->trans("StatusOrderSentShort"),
Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceledShort")
);
print $form->selectarray('viewstatut', $liststatus, $viewstatut, -4);
@@ -993,7 +993,7 @@ if ($resql)
$searchpicto=$form->showFilterButtons();
print $searchpicto;
print '</td>';
print "</tr>\n";
// Fields title
@@ -1014,9 +1014,9 @@ if ($resql)
// Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{
foreach($extrafields->attribute_label as $key => $val)
foreach($extrafields->attribute_label as $key => $val)
{
if (! empty($arrayfields["ef.".$key]['checked']))
if (! empty($arrayfields["ef.".$key]['checked']))
{
$align=$extrafields->getAlignFlag($key);
print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
@@ -1033,20 +1033,20 @@ if ($resql)
if (! empty($arrayfields['c.facture']['checked'])) print_liste_field_titre($arrayfields['c.facture']['label'],$_SERVER["PHP_SELF"],'c.facture','',$param,'align="center"',$sortfield,$sortorder,'');
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
print '</tr>'."\n";
$total=0;
$subtotal=0;
$productstat_cache=array();
$generic_commande = new Commande($db);
$generic_product = new Product($db);
$i=0;
$totalarray=array();
while ($i < min($num,$limit))
{
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
$notshippable=0;
@@ -1054,7 +1054,7 @@ if ($resql)
$text_info='';
$text_warning='';
$nbprod=0;
// Ref
if (! empty($arrayfields['c.ref']['checked']))
{
@@ -1070,12 +1070,12 @@ if ($resql)
$generic_commande->total_ttc = $obj->total_ttc;
$generic_commande->lines=array();
$generic_commande->getLinesArray();
print '<table class="nobordernopadding"><tr class="nocellnopadd">';
print '<td class="nobordernopadding nowrap">';
print $generic_commande->getNomUrl(1,($viewstatut != 2?0:$obj->fk_statut));
print '</td>';
// Show shippable Icon (create subloop, so may be slow)
if ($conf->stock->enabled)
{
@@ -1083,7 +1083,7 @@ if ($resql)
if (($obj->fk_statut > 0) && ($obj->fk_statut < 3))
{
$numlines = count($generic_commande->lines); // Loop on each line of order
for ($lig=0; $lig < $numlines; $lig++)
for ($lig=0; $lig < $numlines; $lig++)
{
if ($generic_commande->lines[$lig]->product_type == 0 && $generic_commande->lines[$lig]->fk_product > 0) // If line is a product and not a service
{
@@ -1107,8 +1107,8 @@ if ($resql)
$text_info .= ' - '.$langs->trans("Stock").': '.$generic_product->stock_reel;
$text_info .= ' - '.$langs->trans("VirtualStock").': '.$generic_product->stock_theorique;
$text_info .= '<br>';
if ($generic_commande->lines[$lig]->qty > $generic_product->stock_reel)
if ($generic_commande->lines[$lig]->qty > $generic_product->stock_reel)
{
$notshippable++;
}
@@ -1168,7 +1168,7 @@ if ($resql)
$text_info = $langs->trans('NonShippable').'<br>'.$text_info;
}
}
print '<td>';
if ($nbprod)
{
@@ -1179,7 +1179,7 @@ if ($resql)
}
print '</td>';
}
// Warning late icon and note
print '<td class="nobordernopadding nowrap">';
if ($generic_commande->hasDelay()) {
@@ -1192,7 +1192,7 @@ if ($resql)
print '</span>';
}
print '</td>';
print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
$filename=dol_sanitizeFileName($obj->ref);
$filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
@@ -1200,11 +1200,11 @@ if ($resql)
print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
print '</td>';
print '</tr></table>';
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
// Ref customer
if (! empty($arrayfields['c.ref_client']['checked']))
{
@@ -1222,7 +1222,7 @@ if ($resql)
{
print '<td class="tdoverflowmax200">';
print $companystatic->getNomUrl(1,'customer');
// If module invoices enabled and user with invoice creation permissions
if (! empty($conf->facture->enabled) && ! empty($conf->global->ORDER_BILLING_ALL_CUSTOMER))
{
@@ -1278,7 +1278,7 @@ if ($resql)
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
// Order date
if (! empty($arrayfields['c.date_commande']['checked']))
{
@@ -1319,7 +1319,7 @@ if ($resql)
if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
$totalarray['totalttc'] += $obj->total_ttc;
}
// Extra fields
if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
{
@@ -1370,7 +1370,7 @@ if ($resql)
print '<td align="center">'.yn($obj->billed).'</td>';
if (! $i) $totalarray['nbfield']++;
}
// Action column
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
@@ -1381,9 +1381,9 @@ if ($resql)
}
print '</td>';
if (! $i) $totalarray['nbfield']++;
print "</tr>\n";
$total+=$obj->total_ht;
$subtotal+=$obj->total_ht;
$i++;
@@ -1416,14 +1416,14 @@ if ($resql)
}
$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 '</table>'."\n";
print '</div>';
print '</form>'."\n";
if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)
@@ -1433,18 +1433,18 @@ if ($resql)
*/
$urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
$urlsource.=str_replace('&amp;','&',$param);
$filedir=$diroutputmassaction;
$genallowed=$user->rights->commande->lire;
$delallowed=$user->rights->commande->supprimer;
print $formfile->showdocuments('massfilesarea_orders','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
}
else
{
print '<br><a name="show_files"></a><a href="'.$_SERVER["PHP_SELF"].'?show_files=1'.$param.'#show_files">'.$langs->trans("ShowTempMassFilesArea").'</a>';
}
}
else
{