Fix: uniformize code

This commit is contained in:
Regis Houssin 2012-11-30 00:06:25 +01:00
parent b507c12b13
commit 31785c8868

View File

@ -73,18 +73,15 @@ include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager=new HookManager($db); $hookmanager=new HookManager($db);
$hookmanager->initHooks(array('ordersuppliercard')); $hookmanager->initHooks(array('ordersuppliercard'));
$mesg='';
$errors=array();
$object = new CommandeFournisseur($db); $object = new CommandeFournisseur($db);
// Load object // Load object
if ($id > 0 || ! empty($ref)) if ($id > 0 || ! empty($ref))
{ {
$resObj = $object->fetch($id, $ref); $ret = $object->fetch($id, $ref);
$resTP = $object->fetch_thirdparty(); if ($ret < 0) dol_print_error($db,$object->error);
if ($resObj < 0) dol_print_error($db,$object->error); $ret = $object->fetch_thirdparty();
if ($resTP < 0) dol_print_error($db,$object->error); if ($ret < 0) dol_print_error($db,$object->error);
} else if($socid) { } else if($socid) {
$object->socid = $socid; $object->socid = $socid;
$resTP = $object->fetch_thirdparty(); $resTP = $object->fetch_thirdparty();
@ -120,7 +117,7 @@ if ($action == 'setdate_livraison' && $user->rights->fournisseur->commande->cree
$result=$object->set_date_livraison($user,$datelivraison); $result=$object->set_date_livraison($user,$datelivraison);
if ($result < 0) if ($result < 0)
{ {
$mesg='<div class="error">'.$object->error.'</div>'; setEventMessage($object->error, 'errors');
} }
} }
@ -397,7 +394,7 @@ else if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->r
else else
{ {
$error++; $error++;
$mesg=$object->error; setEventMessage($object->error, 'errors');
} }
if (! $error) if (! $error)
@ -427,7 +424,7 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fourn
} }
else else
{ {
$mesg=$object->error; setEventMessage($object->error, 'errors');
} }
// If we have permission, and if we don't need to provide th idwarehouse, we go directly on approved step // If we have permission, and if we don't need to provide th idwarehouse, we go directly on approved step
@ -462,7 +459,7 @@ else if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fou
} }
else else
{ {
$mesg=$object->error; setEventMessage($object->error, 'errors');
} }
} }
} }
@ -477,7 +474,7 @@ else if ($action == 'confirm_refuse' && $confirm == 'yes' && $user->rights->four
} }
else else
{ {
$mesg=$object->error; setEventMessage($object->error, 'errors');
} }
} }
@ -491,7 +488,7 @@ else if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fo
} }
else else
{ {
$mesg=$object->error; setEventMessage($object->error, 'errors');
} }
} }
@ -506,7 +503,7 @@ else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->four
} }
else else
{ {
$mesg=$object->error; setEventMessage($object->error, 'errors');
} }
} }
@ -515,7 +512,7 @@ else if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->fourn
{ {
if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
{ {
$mesg='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>'; setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors');
} }
else else
{ {
@ -529,7 +526,7 @@ else if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->fourn
} }
else else
{ {
$mesg='<div class="error">'.$object->error.'</div>'; setEventMessage($object->error, 'errors');
$action=''; $action='';
} }
} }
@ -552,7 +549,7 @@ else if ($action == 'livraison' && $user->rights->fournisseur->commande->recepti
} }
else if($result == -3) else if($result == -3)
{ {
$mesg='<div class="error">'.$langs->trans("NotAuthorized").'</div>'; setEventMessage($langs->trans("NotAuthorized"), 'errors');
} }
else else
{ {
@ -576,7 +573,7 @@ else if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->four
} }
else else
{ {
$mesg=$object->error; setEventMessage($object->error, 'errors');
} }
} }
@ -616,16 +613,16 @@ else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) /
// Sauvegarde le dernier module choisi pour generer un document // Sauvegarde le dernier module choisi pour generer un document
if ($_REQUEST['model']) if (GETPOST('model'))
{ {
$object->setDocModel($user, $_REQUEST['model']); $object->setDocModel($user, GETPOST('model'));
} }
$outputlangs = $langs; $outputlangs = $langs;
if (! empty($_REQUEST['lang_id'])) if (GETPOST('lang_id'))
{ {
$outputlangs = new Translate("",$conf); $outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']); $outputlangs->setDefaultLang(GETPOST('lang_id'));
} }
$result=supplier_order_pdf_create($db, $object,$object->modelpdf,$outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); $result=supplier_order_pdf_create($db, $object,$object->modelpdf,$outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
if ($result <= 0) if ($result <= 0)
@ -641,12 +638,9 @@ else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) /
} }
// Delete file in doc form // Delete file in doc form
else if ($action == 'remove_file' && $user->rights->fournisseur->commande->creer) else if ($action == 'remove_file' && $object->id > 0 && $user->rights->fournisseur->commande->creer)
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
if ($resObj)
{
$langs->load("other"); $langs->load("other");
$upload_dir = $conf->fournisseur->commande->dir_output; $upload_dir = $conf->fournisseur->commande->dir_output;
$file = $upload_dir . '/' . GETPOST('file'); $file = $upload_dir . '/' . GETPOST('file');
@ -654,7 +648,6 @@ else if ($action == 'remove_file' && $user->rights->fournisseur->commande->creer
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
} }
}
/* /*
* Create an order * Create an order
@ -674,7 +667,7 @@ else if ($action == 'create' && $user->rights->fournisseur->commande->creer)
if (! $orderid > 0) if (! $orderid > 0)
{ {
$error++; $error++;
$mesg=$object->error; setEventMessage($object->error, 'errors');
} }
if (! $error) if (! $error)
@ -733,7 +726,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
{ {
$langs->load('mails'); $langs->load('mails');
if ($resObj) if ($object->id > 0)
{ {
// $ref = dol_sanitizeFileName($object->ref); // $ref = dol_sanitizeFileName($object->ref);
// $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; // $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
@ -800,7 +793,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt); $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
if ($mailfile->error) if ($mailfile->error)
{ {
$mesg='<div class="error">'.$mailfile->error.'</div>'; setEventMessage($mailfile->error, 'errors');
} }
else else
{ {
@ -808,6 +801,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
if ($result) if ($result)
{ {
$mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain " $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain "
setEventMessage($mesg);
$error=0; $error=0;
@ -841,17 +835,17 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
else else
{ {
$langs->load("other"); $langs->load("other");
$mesg='<div class="error">';
if ($mailfile->error) if ($mailfile->error)
{ {
$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); $mesg = $langs->trans('ErrorFailedToSendMail',$from,$sendto);
$mesg.= '<br>'.$mailfile->error; $mesg.= '<br>'.$mailfile->error;
} }
else else
{ {
$mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; $mesg = 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
} }
$mesg.='</div>';
setEventMessage($mesg, 'errors');
} }
} }
/* } /* }
@ -866,14 +860,14 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
else else
{ {
$langs->load("errors"); $langs->load("errors");
$mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>'; setEventMessage($langs->trans('ErrorCantReadFile',$file), 'errors');
dol_syslog('Failed to read file: '.$file); dol_syslog('Failed to read file: '.$file);
} }
} }
else else
{ {
$langs->load("other"); $langs->load("other");
$mesg='<div class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'</div>'; setEventMessage($langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")), 'errors');
dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.'); dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
} }
} }
@ -882,7 +876,7 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fourniss
{ {
if ($action == 'addcontact') if ($action == 'addcontact')
{ {
if ($resObj) if ($object->id > 0)
{ {
$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
$result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
@ -898,30 +892,23 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fourniss
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{ {
$langs->load("errors"); $langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>'; setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
} }
else else
{ {
$mesg = '<div class="error">'.$object->error.'</div>'; setEventMessage($object->error, 'errors');
} }
} }
} }
// bascule du statut d'un contact // bascule du statut d'un contact
else if ($action == 'swapstatut') else if ($action == 'swapstatut' && $object->id > 0)
{
if ($resObj)
{ {
$result=$object->swapContactStatus(GETPOST('ligne')); $result=$object->swapContactStatus(GETPOST('ligne'));
} }
else
{
dol_print_error($db);
}
}
// Efface un contact // Efface un contact
else if ($action == 'deletecontact') else if ($action == 'deletecontact' && $object->id > 0)
{ {
$result = $object->delete_contact($_GET["lineid"]); $result = $object->delete_contact($_GET["lineid"]);
@ -957,10 +944,7 @@ $productstatic = new Product($db);
$now=dol_now(); $now=dol_now();
if ($id > 0 || ! empty($ref)) if ($object->id > 0)
{
//if ($mesg) print $mesg.'<br>';
if ($result >= 0)
{ {
$author = new User($db); $author = new User($db);
$author->fetch($object->user_author_id); $author->fetch($object->user_author_id);
@ -975,7 +959,7 @@ if ($id > 0 || ! empty($ref))
*/ */
if ($action == 'delete') if ($action == 'delete')
{ {
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 2); $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 2);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
@ -1011,9 +995,10 @@ if ($id > 0 || ! empty($ref))
$text.=$notify->confirmMessage(3,$object->socid); $text.=$notify->confirmMessage(3,$object->socid);
} }
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_valid', '', 0, 1); $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_valid', '', 0, 1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
/* /*
* Confirmation de l'approbation * Confirmation de l'approbation
*/ */
@ -1029,18 +1014,20 @@ if ($id > 0 || ! empty($ref))
//'text' => $langs->trans("ConfirmClone"), //'text' => $langs->trans("ConfirmClone"),
//array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
//array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1), //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1))); array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1))
);
} }
$ret=$form->form_confirm("fiche.php?id=".$object->id,$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder",$object->ref),"confirm_approve", $formquestion, 1, 1, 240); $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder",$object->ref),"confirm_approve", $formquestion, 1, 1, 240);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
/* /*
* Confirmation de la desapprobation * Confirmation de la desapprobation
*/ */
if ($action == 'refuse') if ($action == 'refuse')
{ {
$ret=$form->form_confirm("fiche.php?id=$object->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder",$object->ref),"confirm_refuse", '', 0, 1); $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=$object->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder",$object->ref),"confirm_refuse", '', 0, 1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
@ -1049,7 +1036,7 @@ if ($id > 0 || ! empty($ref))
*/ */
if ($action == 'cancel') if ($action == 'cancel')
{ {
$ret=$form->form_confirm("fiche.php?id=$object->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder",$object->ref),"confirm_cancel", '', 0, 1); $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=$object->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder",$object->ref),"confirm_cancel", '', 0, 1);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
@ -1059,7 +1046,7 @@ if ($id > 0 || ! empty($ref))
if ($action == 'commande') if ($action == 'commande')
{ {
$date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); $date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
$ret=$form->form_confirm("fiche.php?id=".$object->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"]."&comment=".urlencode($_POST["comment"]), $langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dol_print_date($date_com,'day')),"confirm_commande",'',0,2); $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"]."&comment=".urlencode($_POST["comment"]), $langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dol_print_date($date_com,'day')),"confirm_commande",'',0,2);
if ($ret == 'html') print '<br>'; if ($ret == 'html') print '<br>';
} }
@ -1272,9 +1259,6 @@ if ($id > 0 || ! empty($ref))
include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
} }
dol_htmloutput_mesg($mesg);
dol_htmloutput_errors('',$errors);
/* /*
* Lines * Lines
*/ */
@ -1580,7 +1564,6 @@ if ($id > 0 || ! empty($ref))
if ($action != 'presend') if ($action != 'presend')
{ {
/** /**
* Boutons actions * Boutons actions
*/ */
@ -1675,11 +1658,9 @@ if ($id > 0 || ! empty($ref))
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>'; print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
} }
print "</div>"; print "</div>";
} }
print '<table width="100%"><tr><td width="50%" valign="top">'; print '<table width="100%"><tr><td width="50%" valign="top">';
print '<a name="builddoc"></a>'; // ancre print '<a name="builddoc"></a>'; // ancre
@ -1704,12 +1685,11 @@ if ($id > 0 || ! empty($ref))
*/ */
$somethingshown=$object->showLinkedObjectBlock(); $somethingshown=$object->showLinkedObjectBlock();
print '</td><td valign="top" width="50%">'; print '</td><td valign="top" width="50%">';
if ($user->rights->fournisseur->commande->commander && $object->statut == 2) if ($user->rights->fournisseur->commande->commander && $object->statut == 2)
{ {
/** /*
* Commander (action=commande) * Commander (action=commande)
*/ */
print '<br>'; print '<br>';
@ -1735,7 +1715,7 @@ if ($id > 0 || ! empty($ref))
if ($user->rights->fournisseur->commande->receptionner && ($object->statut == 3 || $object->statut == 4)) if ($user->rights->fournisseur->commande->receptionner && ($object->statut == 3 || $object->statut == 4))
{ {
/** /*
* Receptionner (action=livraison) * Receptionner (action=livraison)
*/ */
print '<br>'; print '<br>';
@ -1776,11 +1756,8 @@ if ($id > 0 || ! empty($ref))
print '</td></tr></table>'; print '</td></tr></table>';
} }
/* /*
* Action presend * Action presend
*
*/ */
if ($action == 'presend') if ($action == 'presend')
{ {
@ -1814,6 +1791,7 @@ if ($id > 0 || ! empty($ref))
} }
print '<br>'; print '<br>';
print_titre($langs->trans('SendOrderByMail')); print_titre($langs->trans('SendOrderByMail'));
// Cree l'objet formulaire mail // Cree l'objet formulaire mail
@ -1859,13 +1837,6 @@ if ($id > 0 || ! empty($ref))
} }
print '</td></tr></table>'; print '</td></tr></table>';
}
else
{
// Commande non trouvee
dol_print_error($db);
}
} }
// End of page // End of page