From 2537cef00d5be4975e8933f91f72423da10f6270 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 6 Oct 2007 09:23:44 +0000 Subject: [PATCH] nettoyage du code --- htdocs/comm/propal.php | 45 ++++++---------- htdocs/commande/fiche.php | 64 ++++++++++++---------- htdocs/compta/facture.php | 108 +++++++++++++++++--------------------- 3 files changed, 101 insertions(+), 116 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index e4fd97620b8..4790b2ffd8d 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -81,6 +81,7 @@ $form=new Form($db); /* Actions */ /******************************************************************************/ +// Suppression de la propale if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes') { if ($user->rights->propale->supprimer) @@ -96,42 +97,28 @@ if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes') } /* - * Supprime une ligne produit SANS confirmation + * Supprime une ligne produit AVEC OU SANS confirmation */ -if ($_GET['action'] == 'deleteline' && $user->rights->propale->creer && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE) +if (($_REQUEST['action'] == 'confirm_deleteline' && $_REQUEST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) + || ($_GET['action'] == 'deleteline' && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE)) { - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - $propal->delete_product($_GET['ligne']); - if ($_REQUEST['lang_id']) - { - $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs); -} - -/* - * Supprime une ligne produit AVEC confirmation - */ -if ($_REQUEST['action'] == 'confirm_deleteline' && $_REQUEST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) -{ - if ($user->rights->propale->creer) + if ($user->rights->propale->creer) { $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - $result=$propal->delete_product($_GET['ligne']); - if ($_REQUEST['lang_id']) - { - $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs); - } - Header('Location: '.$_SERVER["PHP_SELF"].'?propalid='.$_GET['propalid']); + $propal->fetch($_GET['propalid']); + $result = $propal->delete_product($_GET['ligne']); + if ($_REQUEST['lang_id']) + { + $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs); + } + Header('Location: '.$_SERVER["PHP_SELF"].'?propalid='.$_GET['propalid']); exit; } +// Validation de la propale if ($_REQUEST['action'] == 'confirm_validate' && $_REQUEST['confirm'] == 'yes') { if ($user->rights->propale->valider) diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index b420e432776..1f17d3e50a7 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -77,9 +77,44 @@ if ($_GET["projetid"]) $projetid = $_GET["projetid"]; } +/******************************************************************************/ +/* Actions */ +/******************************************************************************/ + +// Suppression de la commande +if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') +{ + if ($user->rights->commande->supprimer ) + { + $commande = new Commande($db); + $commande->fetch($_GET['id']); + $commande->delete(); + Header('Location: index.php'); + exit; + } +} + /* - * Actions + * Supprime une ligne produit AVEC ou SANS confirmation */ +if (($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) + || ($_GET['action'] == 'deleteline' && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE)) +{ + if ($user->rights->commande->creer) + { + $commande = new Commande($db); + $commande->fetch($_GET['id']); + $result = $commande->delete_line($_GET['lineid']); + if ($_REQUEST['lang_id']) + { + $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + commande_pdf_create($db, $_GET['id'], $commande->modelpdf, $outputlangs); + } + Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET['id']); + exit; +} // Categorisation dans projet if ($_POST['action'] == 'classin' && $user->rights->commande->creer) @@ -378,21 +413,6 @@ if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POS exit; } -if ($_GET['action'] == 'deleteline' && $user->rights->commande->creer && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE) -{ - $commande = new Commande($db); - $commande->fetch($_GET['id']); - $result = $commande->delete_line($_GET['lineid']); - if ($_REQUEST['lang_id']) - { - $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - commande_pdf_create($db, $_GET['id'], $commande->modelpdf, $outputlangs); - Header('Location: fiche.php?id='.$_GET['id']); - exit; -} - if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->rights->commande->valider) { $commande = new Commande($db); @@ -416,18 +436,6 @@ if ($_POST['action'] == 'confirm_cancel' && $_POST['confirm'] == 'yes' && $user- $result = $commande->cancel($user); } -if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') -{ - if ($user->rights->commande->supprimer ) - { - $commande = new Commande($db); - $commande->fetch($_GET['id']); - $commande->delete(); - Header('Location: index.php'); - exit; - } -} - if ($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) { if ($user->rights->commande->creer) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 9bd5fea6e71..2d92fe2a23a 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -76,10 +76,58 @@ if ($_GET["projetid"]) $NBLINES=4; +/******************************************************************************/ +/* Actions */ +/******************************************************************************/ + +// Suppression de la facture +if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') +{ + if ($user->rights->facture->supprimer) + { + $fac = new Facture($db); + $result = $fac->fetch($_GET['facid']); + $result = $fac->delete(); + if ($result > 0) + { + Header('Location: '.$_SERVER["PHP_SELF"]); + exit; + } + else + { + $mesg='
'.$fac->error.'
'; + } + } +} /* - * Actions + * Supprime une ligne produit AVEC ou SANS confirmation */ +if (($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) + || ($_GET['action'] == 'deleteline' && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE)) +{ + if ($user->rights->facture->creer) + { + $fac = new Facture($db); + $fac->fetch($_GET['facid']); + $result = $fac->deleteline($_GET['rowid'], $user); + if ($result > 0) + { + if ($_REQUEST['lang_id']) + { + $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs); + } + else + { + print $fac->error; + } + } + Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$_GET['facid']); + exit; +} // Validation if ($_GET['action'] == 'valid') @@ -236,24 +284,6 @@ if ($_GET['action'] == 'modif' && $user->rights->facture->modifier && $conf->glo } } -if ($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) -{ - if ($user->rights->facture->creer) - { - $fac = new Facture($db); - $fac->fetch($_GET['facid']); - $fac->deleteline($_GET['rowid'], $user); - if ($_REQUEST['lang_id']) - { - $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs); - } - Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$_GET['facid']); - exit; -} - // Classe à "payée" if ($_POST['action'] == 'confirm_payed' && $_POST['confirm'] == 'yes' && $user->rights->facture->paiement) { @@ -293,25 +323,6 @@ if ($_POST['action'] == 'confirm_canceled' && $_POST['confirm'] == 'yes') $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Reason")).'
'; } } -// Supprimer -if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') -{ - if ($user->rights->facture->supprimer) - { - $fac = new Facture($db); - $result = $fac->fetch($_GET['facid']); - $result = $fac->delete(); - if ($result > 0) - { - Header('Location: '.$_SERVER["PHP_SELF"]); - exit; - } - else - { - $mesg='
'.$fac->error.'
'; - } - } -} // Convertir en reduc if ($_POST['action'] == 'confirm_converttoreduc' && $_POST['confirm'] == 'yes' && $user->rights->facture->creer) @@ -854,27 +865,6 @@ if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST exit; } -if ($_GET['action'] == 'deleteline' && $user->rights->facture->creer && ! $conf->global->PRODUIT_CONFIRM_DELETE_LINE) -{ - $fac = new Facture($db,'',$_GET['facid']); - $fac->fetch($_GET['facid']); - $result = $fac->deleteline($_GET['rowid'], $user); - if ($result > 0) - { - if ($_REQUEST['lang_id']) - { - $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - // facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs); - } - else - { - print $fac->error; - } -} - - /* * Ordonnancement des lignes