From 5ca6593a5797420e5b6eff3d52844f9e7fd35db3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 28 Jul 2015 14:13:16 +0200 Subject: [PATCH] Fix serious deadlock feature. It was possible to link with no way to unlink. What if user make a bad click ? I complete feature with reverse action to be sure to not have users with a corrupted situation. --- .../tpl/linkedobjectblock.tpl.php | 17 +- htdocs/comm/propal.php | 50 +- .../comm/propal/tpl/linkedobjectblock.tpl.php | 19 +- htdocs/commande/card.php | 7 +- htdocs/commande/tpl/linkedobjectblock.tpl.php | 19 +- htdocs/compta/facture.php | 56 +- .../facture/tpl/linkedobjectblock.tpl.php | 19 +- htdocs/contrat/card.php | 3 + htdocs/contrat/tpl/linkedobjectblock.tpl.php | 12 +- htdocs/core/actions_dellink.inc.php | 36 + htdocs/core/class/commonobject.class.php | 48 +- htdocs/expedition/card.php | 5 + .../expedition/tpl/linkedobjectblock.tpl.php | 19 +- htdocs/fichinter/card.php | 1564 +++++++++-------- .../fichinter/tpl/linkedobjectblock.tpl.php | 10 +- htdocs/fourn/commande/card.php | 3 + .../commande/tpl/linkedobjectblock.tpl.php | 17 +- htdocs/fourn/facture/card.php | 3 + .../facture/tpl/linkedobjectblock.tpl.php | 19 +- htdocs/langs/en_US/compta.lang | 2 +- 20 files changed, 972 insertions(+), 956 deletions(-) create mode 100644 htdocs/core/actions_dellink.inc.php diff --git a/htdocs/comm/askpricesupplier/tpl/linkedobjectblock.tpl.php b/htdocs/comm/askpricesupplier/tpl/linkedobjectblock.tpl.php index a45fac8b3c9..48d916c6a5c 100644 --- a/htdocs/comm/askpricesupplier/tpl/linkedobjectblock.tpl.php +++ b/htdocs/comm/askpricesupplier/tpl/linkedobjectblock.tpl.php @@ -38,24 +38,26 @@ print_titre($langs->trans('RelatedAskPriceSupplier')); trans("Date"); ?> trans("AmountHTShort"); ?> trans("Status"); ?> + $objectlink) { $var=!$var; ?> > - trans("ShowAskPriceSupplier"),"askpricesupplier").' '.$object->ref; ?> + trans("ShowAskPriceSupplier"),"askpricesupplier").' '.$objectlink->ref; ?> - datec,'day'); ?> + datec,'day'); ?> rights->askpricesupplier->lire) { - $total = $total + $object->total_ht; - echo price($object->total_ht); + $total = $total + $objectlink->total_ht; + echo price($objectlink->total_ht); } ?> - getLibStatut(3); ?> + getLibStatut(3); ?> + ">transnoentitiesnoconv("RemoveLink")); ?> rights->askpricesupplier->lire) { echo price($total); } ?> -   + + diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index dc0f376234e..4b9f84553ce 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -103,6 +103,8 @@ if ($id > 0 || ! empty($ref)) { $hookmanager->initHooks(array('propalcard','globalcard')); $permissionnote = $user->rights->propale->creer; // Used by the include of actions_setnotes.inc.php +$permissiondellink=$user->rights->propale->creer; // Used by the include of actions_dellink.inc.php +$permissiontoedit = $user->rights->propale->creer; // Used by the include of actions_lineupdown.inc.php /* @@ -117,7 +119,11 @@ if (empty($reshook)) { if ($cancel) $action = ''; - include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not includ_once + include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once + + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + + include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once // Action clone object if ($action == 'confirm_clone' && $confirm == 'yes') @@ -1133,47 +1139,7 @@ if (empty($reshook)) $result=$object->setShippingMethod(GETPOST('shipping_method_id', 'int')); } - /* - * Ordonnancement des lignes - */ - - else if ($action == 'up' && $user->rights->propal->creer) { - $object->line_up(GETPOST('rowid')); - - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - // Define output language - $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) { - $outputlangs = new Translate("", $conf); - $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); - $outputlangs->setDefaultLang($newlang); - } - $ret = $object->fetch($id); // Reload to get new records - $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - - header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id . '#' . GETPOST('rowid')); - exit(); - } - - else if ($action == 'down' && $user->rights->propal->creer) { - $object->line_down(GETPOST('rowid')); - - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - // Define output language - $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) { - $outputlangs = new Translate("", $conf); - $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); - $outputlangs->setDefaultLang($newlang); - } - $ret = $object->fetch($id); // Reload to get new records - $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - - header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id . '#' . GETPOST('rowid')); - exit(); - } else if ($action == 'update_extras') { + else if ($action == 'update_extras') { // Fill array 'array_options' with data from update form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); diff --git a/htdocs/comm/propal/tpl/linkedobjectblock.tpl.php b/htdocs/comm/propal/tpl/linkedobjectblock.tpl.php index 19763f8510c..66cde8692ce 100644 --- a/htdocs/comm/propal/tpl/linkedobjectblock.tpl.php +++ b/htdocs/comm/propal/tpl/linkedobjectblock.tpl.php @@ -43,24 +43,26 @@ print_titre($langs->trans('RelatedCommercialProposals')); trans("Date"); ?> trans("AmountHTShort"); ?> trans("Status"); ?> + $objectlink) { $var=!$var; ?> > - getNomUrl(1); ?> - ref_client; ?> - date,'day'); ?> + getNomUrl(1); ?> + ref_client; ?> + date,'day'); ?> rights->propale->lire) { - $total = $total + $object->total_ht; - echo price($object->total_ht); + $total = $total + $objectlink->total_ht; + echo price($objectlink->total_ht); } ?> - getLibStatut(3); ?> + getLibStatut(3); ?> + ">transnoentitiesnoconv("RemoveLink")); ?> rights->propale->lire) { echo price($total); } ?> -   + + diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 5cc0c6db9ce..5c860eee1f6 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -93,8 +93,9 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be inclu // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('ordercard','globalcard')); -$permissionnote = $user->rights->commande->creer; // Used by the include of actions_setnotes.inc.php -$permissionedit = $user->rights->commande->creer; // Used by the include of actions_lineupdown.inc.php +$permissionnote = $user->rights->commande->creer; // Used by the include of actions_setnotes.inc.php +$permissiondellink = $user->rights->commande->creer; // Used by the include of actions_dellink.inc.php +$permissionedit = $user->rights->commande->creer; // Used by the include of actions_lineupdown.inc.php @@ -112,6 +113,8 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once // Action clone object diff --git a/htdocs/commande/tpl/linkedobjectblock.tpl.php b/htdocs/commande/tpl/linkedobjectblock.tpl.php index 2eb94d7974a..a661013802d 100644 --- a/htdocs/commande/tpl/linkedobjectblock.tpl.php +++ b/htdocs/commande/tpl/linkedobjectblock.tpl.php @@ -40,24 +40,26 @@ print_titre($langs->trans('RelatedCustomerOrders')); trans("Date"); ?> trans("AmountHTShort"); ?> trans("Status"); ?> + $objectlink) { $var=!$var; ?> > - getNomUrl(1); ?> - ref_client; ?> - date,'day'); ?> + getNomUrl(1); ?> + ref_client; ?> + date,'day'); ?> rights->commande->lire) { - $total = $total + $object->total_ht; - echo price($object->total_ht); + $total = $total + $objectlink->total_ht; + echo price($objectlink->total_ht); } ?> - getLibStatut(3); ?> + getLibStatut(3); ?> + ">transnoentitiesnoconv("RemoveLink")); ?> rights->commande->lire) { echo price($total); } ?> -   + + diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 087780fdaad..7f5b33ee73a 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -108,6 +108,8 @@ if ($id > 0 || ! empty($ref)) { $hookmanager->initHooks(array('invoicecard','globalcard')); $permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php +$permissiondellink=$user->rights->facture->creer; // Used by the include of actions_dellink.inc.php +$permissiontoedit = $user->rights->facture->creer; // Used by the include of actions_lineupdonw.inc.php /* @@ -120,7 +122,11 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { - include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not includ_once + include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once + + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + + include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once // Action clone object if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->facture->creer) { @@ -1644,54 +1650,6 @@ if (empty($reshook)) exit(); } - // Modify line position (up) - else if ($action == 'up' && $user->rights->facture->creer) { - $object->fetch($id); - $object->fetch_thirdparty(); - $object->line_up($_GET ['rowid']); - - // Define output language - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) - $newlang = $_REQUEST['lang_id']; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) - $newlang = $object->thirdparty->default_lang; - if (! empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - - header('Location: ' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '#' . $_GET ['rowid']); - exit(); - } // Modify line position (down) - else if ($action == 'down' && $user->rights->facture->creer) { - $object->fetch($id); - $object->fetch_thirdparty(); - $object->line_down($_GET ['rowid']); - - // Define output language - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) - $newlang = $_REQUEST['lang_id']; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) - $newlang = $object->thirdparty->default_lang; - if (! empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - - header('Location: ' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '#' . $_GET ['rowid']); - exit(); - } - // Link invoice to order if (GETPOST('linkedOrder')) { $object->fetch($id); diff --git a/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php b/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php index eac0043e56f..b295e72f19e 100644 --- a/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php +++ b/htdocs/compta/facture/tpl/linkedobjectblock.tpl.php @@ -39,24 +39,26 @@ print_titre($langs->trans("RelatedCustomerInvoices")); trans("Date"); ?> trans("AmountHTShort"); ?> trans("Status"); ?> + $objectlink) { $var=!$var; ?> > - getNomUrl(1); ?> - ref_client; ?> - date,'day'); ?> + getNomUrl(1); ?> + ref_client; ?> + date,'day'); ?> rights->facture->lire) { - $total = $total + $object->total_ht; - echo price($object->total_ht); + $total = $total + $objectlink->total_ht; + echo price($objectlink->total_ht); } ?> - getLibStatut(3); ?> + getLibStatut(3); ?> + ">transnoentitiesnoconv("RemoveLink")); ?> rights->facture->lire) { echo price($total); } ?> -   + + diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 4005cb9abdf..4cea0fb8c5e 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -90,6 +90,7 @@ $extrafieldsline = new ExtraFields($db); $extralabelslines=$extrafieldsline->fetch_name_optionals_label($object->table_element_line); $permissionnote=$user->rights->contrat->creer; // Used by the include of actions_setnotes.inc.php +$permissiondellink=$user->rights->contrat->creer; // Used by the include of actions_dellink.inc.php /* @@ -98,6 +99,8 @@ $permissionnote=$user->rights->contrat->creer; // Used by the include of actions include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once +include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer) { $result = $object->active_line($user, GETPOST('ligne'), GETPOST('date'), GETPOST('dateend'), GETPOST('comment')); diff --git a/htdocs/contrat/tpl/linkedobjectblock.tpl.php b/htdocs/contrat/tpl/linkedobjectblock.tpl.php index f7f840dce13..4daf5deef02 100644 --- a/htdocs/contrat/tpl/linkedobjectblock.tpl.php +++ b/htdocs/contrat/tpl/linkedobjectblock.tpl.php @@ -34,19 +34,21 @@ print_titre($langs->trans('RelatedContracts')); trans("Date"); ?>   trans("Status"); ?> + $objectlink) { - $object->fetch_lines(); + $objectlink->fetch_lines(); $var=!$var; ?> > - getNomUrl(1); ?> - date_contrat,'day'); ?> + getNomUrl(1); ?> + date_contrat,'day'); ?>   - getLibStatut(6); ?> + getLibStatut(6); ?> + ">transnoentitiesnoconv("RemoveLink")); ?> diff --git a/htdocs/core/actions_dellink.inc.php b/htdocs/core/actions_dellink.inc.php new file mode 100644 index 00000000000..1ba98a8435a --- /dev/null +++ b/htdocs/core/actions_dellink.inc.php @@ -0,0 +1,36 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/core/actions_dellink.inc.php + * \brief Code for actions on deleting link between elements + */ + + +// $action must be defined +// $object must be defined +// $permissiondellink must be defined + +$dellinkid = GETPOST('dellinkid','int'); + +// Set public note +if ($action == 'dellink' && ! empty($permissiondellink) && ! GETPOST('cancel') && $dellinkid > 0) +{ + $result=$object->deleteObjectLinked(0, '', 0, '', $dellinkid); + if ($result < 0) setEventMessages($object->error,$object->errors,'errors'); +} diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 5bc08cab739..69f1c6df145 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2166,7 +2166,7 @@ abstract class CommonObject } // Links between objects are stored in table element_element - $sql = 'SELECT fk_source, sourcetype, fk_target, targettype'; + $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; $sql.= " WHERE "; if ($justsource || $justtarget) @@ -2201,11 +2201,11 @@ abstract class CommonObject $obj = $this->db->fetch_object($resql); if ($obj->fk_source == $sourceid) { - $this->linkedObjectsIds[$obj->targettype][]=$obj->fk_target; + $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; } if ($obj->fk_target == $targetid) { - $this->linkedObjectsIds[$obj->sourcetype][]=$obj->fk_source; + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; } $i++; } @@ -2260,16 +2260,15 @@ abstract class CommonObject $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; } + // Here $module, $classfile and $classname are set if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) { dol_include_once('/'.$classpath.'/'.$classfile.'.class.php'); - $num=count($objectids); - - for ($i=0;$i<$num;$i++) + foreach($objectids as $i => $objectid); // $i is rowid into llx_element_element { $object = new $classname($this->db); - $ret = $object->fetch($objectids[$i]); + $ret = $object->fetch($objectid); if ($ret >= 0) { $this->linkedObjects[$objecttype][$i] = $object; @@ -2338,10 +2337,11 @@ abstract class CommonObject * @param string $sourcetype Object source type * @param int $targetid Object target id * @param string $targettype Object target type - * @return int >0 if OK, <0 if KO + * @param int $rowid Row id of line to delete. If defined, other parameters are not used. + * @return int >0 if OK, <0 if KO * @see add_object_linked, updateObjectLinked, fetchObjectLinked */ - function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='') + function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='') { $deletesource=false; $deletetarget=false; @@ -2356,21 +2356,28 @@ abstract class CommonObject $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; $sql.= " WHERE"; - if ($deletesource) + if ($rowid > 0) { - $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; - $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->element."'"; - } - else if ($deletetarget) - { - $sql.= " fk_target = ".$targetid." AND targettype = '".$targettype."'"; - $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->element."'"; + $sql.=" rowid = ".$rowid; } else { - $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->element."')"; - $sql.= " OR"; - $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->element."')"; + if ($deletesource) + { + $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; + $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->element."'"; + } + else if ($deletetarget) + { + $sql.= " fk_target = ".$targetid." AND targettype = '".$targettype."'"; + $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->element."'"; + } + else + { + $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->element."')"; + $sql.= " OR"; + $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->element."')"; + } } dol_syslog(get_class($this)."::deleteObjectLinked", LOG_DEBUG); @@ -2381,6 +2388,7 @@ abstract class CommonObject else { $this->error=$this->db->lasterror(); + $this->errors[]=$this->error; return -1; } } diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 51a3bc51fbe..9cee623b679 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -82,6 +82,9 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be inclu // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('expeditioncard','globalcard')); +$permissiondellink=$user->rights->expedition->livraison->creer; // Used by the include of actions_dellink.inc.php + + /* * Actions @@ -114,6 +117,8 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + if ($action == 'add') { $error=0; diff --git a/htdocs/expedition/tpl/linkedobjectblock.tpl.php b/htdocs/expedition/tpl/linkedobjectblock.tpl.php index abca7594962..d4a9d1f9af2 100644 --- a/htdocs/expedition/tpl/linkedobjectblock.tpl.php +++ b/htdocs/expedition/tpl/linkedobjectblock.tpl.php @@ -39,24 +39,26 @@ print_titre($langs->trans('RelatedShippings')); trans("DateDeliveryPlanned"); ?> trans("AmountHTShort"); ?> trans("Status"); ?> + $objectlink) { $var=!$var; ?> > - getNomUrl(1); ?> - date_creation,'day'); ?> - date_delivery,'day'); ?> + getNomUrl(1); ?> + date_creation,'day'); ?> + date_delivery,'day'); ?> rights->expedition->lire) { - $total = $total + $object->total_ht; - echo price($object->total_ht); + $total = $total + $objectlink->total_ht; + echo price($objectlink->total_ht); } ?> - getLibStatut(3); ?> + getLibStatut(3); ?> + ">transnoentitiesnoconv("RemoveLink")); ?> rights->expedition->lire) { echo price($total); } ?> -   + + diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index b73d2281a3a..198eb11dddb 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -93,6 +93,7 @@ if ($id > 0 || ! empty($ref)) } $permissionnote=$user->rights->ficheinter->creer; // Used by the include of actions_setnotes.inc.php +$permissiondellink=$user->rights->ficheinter->creer; // Used by the include of actions_dellink.inc.php /* @@ -103,832 +104,837 @@ $parameters=array('socid'=>$socid); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once - -if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->ficheinter->creer) +if (empty($reshook)) { - $result = $object->setValid($user); - if ($result >= 0) + include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once + + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + + if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->ficheinter->creer) { - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs); - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - else - { - $mesg='
'.$object->error.'
'; - } -} - -else if ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->ficheinter->creer) -{ - $result = $object->setDraft($user); - if ($result >= 0) - { - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) $result=fichinter_create($db, $object, (!GETPOST('model','alpha'))?$object->model:GETPOST('model','apha'), $outputlangs); - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - else - { - $mesg='
'.$object->error.'
'; - } -} - -else if ($action == 'add' && $user->rights->ficheinter->creer) -{ - $object->socid = $socid; - $object->duration = GETPOST('duration','int'); - $object->fk_project = GETPOST('projectid','int'); - $object->fk_contrat = GETPOST('contratid','int'); - $object->author = $user->id; - $object->description = GETPOST('description'); - $object->ref = $ref; - $object->modelpdf = GETPOST('model','alpha'); - $object->note_private = GETPOST('note_private'); - $object->note_public = GETPOST('note_public'); - - if ($object->socid > 0) - { - // If creation from another object of another module (Example: origin=propal, originid=1) - if (!empty($origin) && !empty($originid) ) - { - // Parse element/subelement (ex: project_task) - $element = $subelement = $_POST['origin']; - if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs)) - { - $element = $regs[1]; - $subelement = $regs[2]; - } - - // For compatibility - if ($element == 'order') { - $element = $subelement = 'commande'; - } - if ($element == 'propal') { - $element = 'comm/propal'; $subelement = 'propal'; - } - if ($element == 'contract') { - $element = $subelement = 'contrat'; - } - - $object->origin = $origin; - $object->origin_id = $originid; - - // Possibility to add external linked objects with hooks - $object->linked_objects[$object->origin] = $object->origin_id; - if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) - { - $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); - } - - // Extrafields - $extrafields = new ExtraFields($db); - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $array_options = $extrafields->getOptionalsFromPost($extralabels); - - $object->array_options = $array_options; - - $id = $object->create($user); - - if ($id > 0) - { - dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); - - $classname = ucfirst($subelement); - $srcobject = new $classname($db); - - dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines"); - $result=$srcobject->fetch($object->origin_id); - if ($result > 0) - { - $srcobject->fetch_thirdparty(); - $lines = $srcobject->lines; - if (empty($lines) && method_exists($srcobject,'fetch_lines')) - { - $srcobject->fetch_lines(); - $lines = $srcobject->lines; - } - - $fk_parent_line=0; - $num=count($lines); - - for ($i=0;$i<$num;$i++) - { - $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); - - if ($product_type == 1 || !empty($conf->global->FICHINTER_PRINT_PRODUCTS)) { //only services except if config includes products - // service prédéfini - if ($lines[$i]->fk_product > 0) - { - // Define output language - if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) - { - $prod = new Product($db); - $prod->id=$lines[$i]->fk_product; - $prod->getMultiLangs(); - // We show if duration is present on service (so we get it) - $prod->fetch($lines[$i]->fk_product); - if ($prod->duration_value && $prod->duration_unit == 'h' && $conf->global->FICHINTER_USE_SERVICE_DURATION) - { - $durationproduct=$prod->duration_value * 3600 * $lines[$i]->qty; - } - else - $durationproduct=3600; - $outputlangs = $langs; - $newlang=''; - if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); - if (empty($newlang)) $newlang=$srcobject->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - - $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label; - } - else - { - $label = $lines[$i]->product_label; - } - - $desc = $label; - $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')'; - } - else { - $desc = dol_htmlentitiesbr($lines[$i]->desc); - $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')'; - } - $timearray=dol_getdate(mktime()); - $date_intervention=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']); - if ($product_type == 1) - { //service - $duration = $durationproduct; - } - else - { //product - $duration = 0; - } - - $predef = ''; - // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); - - - $result = $object->addline( - $user, - $id, - $desc, - $date_intervention, - $duration, - $array_options - ); - - if ($result < 0) - { - $error++; - break; - } - - } - } - - } - else - { - $mesg=$srcobject->error; - $error++; - } - } - else - { - $mesg=$object->error; - $error++; - } - } - else - { - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) { - $error ++; - $action = 'create'; - } - - if (! $error) - { - // Extrafields - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $array_options = $extrafields->getOptionalsFromPost($extralabels); - - $object->array_options = $array_options; - - $result = $object->create($user); - if ($result > 0) - { - $id=$result; // Force raffraichissement sur fiche venant d'etre cree - } - else - { - $langs->load("errors"); - setEventMessages($object->error, $object->errors, 'errors'); - $action = 'create'; - } - } - } - } - else - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("ThirdParty")).'
'; - $action = 'create'; - } -} - -else if ($action == 'update' && $user->rights->ficheinter->creer) -{ - $object->socid = $socid; - $object->fk_project = GETPOST('projectid','int'); - $object->fk_contrat = GETPOST('contratid','int'); - $object->author = $user->id; - $object->description = GETPOST('description','alpha'); - $object->ref = $ref; - - $result=$object->update($user); - if ($result<0) { - setEventMessage($object->error,'errors'); - } -} - -/* - * Build doc - */ -else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou en post -{ - $object->fetch_lines(); - - // Save last template used to generate document - if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); - - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs); - if ($result <= 0) - { - dol_print_error($db,$result); - exit; - } -} - -// Remove file in doc form -else if ($action == 'remove_file') -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - $object->fetch_thirdparty(); - - $langs->load("other"); - $upload_dir = $conf->ficheinter->dir_output; - $file = $upload_dir . '/' . GETPOST('file'); - $ret=dol_delete_file($file,0,0,0,$object); - if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); - else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); -} - -// Set into a project -else if ($action == 'classin' && $user->rights->ficheinter->creer) -{ - $result=$object->setProject(GETPOST('projectid','int')); - if ($result < 0) dol_print_error($db,$object->error); -} - -// Set into a contract -else if ($action == 'setcontrat' && $user->rights->contrat->creer) -{ - $result=$object->set_contrat($user,GETPOST('contratid','int')); - if ($result < 0) dol_print_error($db,$object->error); -} - -else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer) -{ - $result=$object->delete($user); - if ($result<0) { - setEventMessage($object->error,'errors'); - } - - header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter'); - exit; -} - -else if ($action == 'setdescription' && $user->rights->ficheinter->creer) -{ - $result=$object->set_description($user,GETPOST('description')); - if ($result < 0) dol_print_error($db,$object->error); -} - -// Add line -else if ($action == "addline" && $user->rights->ficheinter->creer) -{ - if (!GETPOST('np_desc')) - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).'
'; - $error++; - } - if (!GETPOST('durationhour','int') && !GETPOST('durationmin','int')) - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Duration")).'
'; - $error++; - } - if (GETPOST('durationhour','int') >= 24 && GETPOST('durationmin','int') > 0) - { - $mesg='
'.$langs->trans("ErrorValueTooHigh").'
'; - $error++; - } - if (! $error) - { - $db->begin(); - - $desc=GETPOST('np_desc'); - $date_intervention = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int')); - $duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int')); - - - // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline); - - $result=$object->addline( - $user, - $id, - $desc, - $date_intervention, - $duration, - $array_options - ); - - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - + $result = $object->setValid($user); if ($result >= 0) { - $db->commit(); + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs); - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); exit; } else { - $mesg=$object->error; - $db->rollback(); + $mesg='
'.$object->error.'
'; } } -} -// Classify Billed -else if ($action == 'classifybilled' && $user->rights->ficheinter->creer) -{ - $result=$object->setStatut(2); - if ($result > 0) + else if ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->ficheinter->creer) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } -} - -// Classify Billed -else if ($action == 'classifyunbilled' && $user->rights->ficheinter->creer) -{ - $result=$object->setStatut(1); - if ($result > 0) - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - else - { - $mesg='
'.$object->error.'
'; - } -} - -/* - * Mise a jour d'une ligne d'intervention - */ -else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST('save','alpha') == $langs->trans("Save")) -{ - $objectline = new FichinterLigne($db); - if ($objectline->fetch($lineid) <= 0) - { - dol_print_error($db); - exit; - } - - if ($object->fetch($objectline->fk_fichinter) <= 0) - { - dol_print_error($db); - exit; - } - $object->fetch_thirdparty(); - - $desc = GETPOST('np_desc'); - $date_inter = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int')); - $duration = convertTime2Seconds(GETPOST('durationhour','int'),GETPOST('durationmin','int')); - - $objectline->datei = $date_inter; - $objectline->desc = $desc; - $objectline->duration = $duration; - - // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline); - $objectline->array_options = $array_options; - - $result = $objectline->update($user); - if ($result < 0) - { - dol_print_error($db); - exit; - } - - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; -} - -/* - * Supprime une ligne d'intervention AVEC confirmation -*/ -else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->ficheinter->creer) -{ - $objectline = new FichinterLigne($db); - if ($objectline->fetch($lineid) <= 0) - { - dol_print_error($db); - exit; - } - $result=$objectline->deleteline($user); - - if ($object->fetch($objectline->fk_fichinter) <= 0) - { - dol_print_error($db); - exit; - } - - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); -} - -/* - * Ordonnancement des lignes -*/ - -else if ($action == 'up' && $user->rights->ficheinter->creer) -{ - $object->line_up($lineid); - - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid); - exit; -} - -else if ($action == 'down' && $user->rights->ficheinter->creer) -{ - $object->line_down($lineid); - - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid); - exit; -} - - -/* - * Add file in email form -*/ -if (GETPOST('addfile','alpha')) -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - // Set tmp user directory TODO Use a dedicated directory for temp mails files - $vardir=$conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; - - dol_add_file_process($upload_dir_tmp,0,0); - $action='presend'; -} - -/* - * Remove file in email form -*/ -if (GETPOST('removedfile','alpha')) -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - // Set tmp user directory - $vardir=$conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; - - // TODO Delete only files that was uploaded from email form - dol_remove_file_process(GETPOST('removedfile','alpha'),0); - $action='presend'; -} - -/* - * Send mail -*/ -if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send)) -{ - $langs->load('mails'); - - if (GETPOST('sendto','alpha')) - { - // Le destinataire a ete fourni via le champ libre - $sendto = GETPOST('sendto','alpha'); - $sendtoid = 0; - } - elseif (GETPOST('receiver','alpha') != '-1') - { - // Recipient was provided from combo list - if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party + $result = $object->setDraft($user); + if ($result >= 0) { - $sendto = $object->client->email; + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) $result=fichinter_create($db, $object, (!GETPOST('model','alpha'))?$object->model:GETPOST('model','apha'), $outputlangs); + + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + else + { + $mesg='
'.$object->error.'
'; + } + } + + else if ($action == 'add' && $user->rights->ficheinter->creer) + { + $object->socid = $socid; + $object->duration = GETPOST('duration','int'); + $object->fk_project = GETPOST('projectid','int'); + $object->fk_contrat = GETPOST('contratid','int'); + $object->author = $user->id; + $object->description = GETPOST('description'); + $object->ref = $ref; + $object->modelpdf = GETPOST('model','alpha'); + $object->note_private = GETPOST('note_private'); + $object->note_public = GETPOST('note_public'); + + if ($object->socid > 0) + { + // If creation from another object of another module (Example: origin=propal, originid=1) + if (!empty($origin) && !empty($originid) ) + { + // Parse element/subelement (ex: project_task) + $element = $subelement = $_POST['origin']; + if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs)) + { + $element = $regs[1]; + $subelement = $regs[2]; + } + + // For compatibility + if ($element == 'order') { + $element = $subelement = 'commande'; + } + if ($element == 'propal') { + $element = 'comm/propal'; $subelement = 'propal'; + } + if ($element == 'contract') { + $element = $subelement = 'contrat'; + } + + $object->origin = $origin; + $object->origin_id = $originid; + + // Possibility to add external linked objects with hooks + $object->linked_objects[$object->origin] = $object->origin_id; + if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) + { + $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); + } + + // Extrafields + $extrafields = new ExtraFields($db); + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $array_options = $extrafields->getOptionalsFromPost($extralabels); + + $object->array_options = $array_options; + + $id = $object->create($user); + + if ($id > 0) + { + dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); + + $classname = ucfirst($subelement); + $srcobject = new $classname($db); + + dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines"); + $result=$srcobject->fetch($object->origin_id); + if ($result > 0) + { + $srcobject->fetch_thirdparty(); + $lines = $srcobject->lines; + if (empty($lines) && method_exists($srcobject,'fetch_lines')) + { + $srcobject->fetch_lines(); + $lines = $srcobject->lines; + } + + $fk_parent_line=0; + $num=count($lines); + + for ($i=0;$i<$num;$i++) + { + $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); + + if ($product_type == 1 || !empty($conf->global->FICHINTER_PRINT_PRODUCTS)) { //only services except if config includes products + // service prédéfini + if ($lines[$i]->fk_product > 0) + { + // Define output language + if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) + { + $prod = new Product($db); + $prod->id=$lines[$i]->fk_product; + $prod->getMultiLangs(); + // We show if duration is present on service (so we get it) + $prod->fetch($lines[$i]->fk_product); + if ($prod->duration_value && $prod->duration_unit == 'h' && $conf->global->FICHINTER_USE_SERVICE_DURATION) + { + $durationproduct=$prod->duration_value * 3600 * $lines[$i]->qty; + } + else + $durationproduct=3600; + $outputlangs = $langs; + $newlang=''; + if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); + if (empty($newlang)) $newlang=$srcobject->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label; + } + else + { + $label = $lines[$i]->product_label; + } + + $desc = $label; + $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')'; + } + else { + $desc = dol_htmlentitiesbr($lines[$i]->desc); + $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')'; + } + $timearray=dol_getdate(mktime()); + $date_intervention=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']); + if ($product_type == 1) + { //service + $duration = $durationproduct; + } + else + { //product + $duration = 0; + } + + $predef = ''; + // Extrafields + $extrafieldsline = new ExtraFields($db); + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); + + + $result = $object->addline( + $user, + $id, + $desc, + $date_intervention, + $duration, + $array_options + ); + + if ($result < 0) + { + $error++; + break; + } + + } + } + + } + else + { + $mesg=$srcobject->error; + $error++; + } + } + else + { + $mesg=$object->error; + $error++; + } + } + else + { + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + if ($ret < 0) { + $error ++; + $action = 'create'; + } + + if (! $error) + { + // Extrafields + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $array_options = $extrafields->getOptionalsFromPost($extralabels); + + $object->array_options = $array_options; + + $result = $object->create($user); + if ($result > 0) + { + $id=$result; // Force raffraichissement sur fiche venant d'etre cree + } + else + { + $langs->load("errors"); + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'create'; + } + } + } + } + else + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("ThirdParty")).'
'; + $action = 'create'; + } + } + + else if ($action == 'update' && $user->rights->ficheinter->creer) + { + $object->socid = $socid; + $object->fk_project = GETPOST('projectid','int'); + $object->fk_contrat = GETPOST('contratid','int'); + $object->author = $user->id; + $object->description = GETPOST('description','alpha'); + $object->ref = $ref; + + $result=$object->update($user); + if ($result<0) { + setEventMessage($object->error,'errors'); + } + } + + /* + * Build doc + */ + else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou en post + { + $object->fetch_lines(); + + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); + + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + } + + // Remove file in doc form + else if ($action == 'remove_file') + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + $object->fetch_thirdparty(); + + $langs->load("other"); + $upload_dir = $conf->ficheinter->dir_output; + $file = $upload_dir . '/' . GETPOST('file'); + $ret=dol_delete_file($file,0,0,0,$object); + if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); + else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); + } + + // Set into a project + else if ($action == 'classin' && $user->rights->ficheinter->creer) + { + $result=$object->setProject(GETPOST('projectid','int')); + if ($result < 0) dol_print_error($db,$object->error); + } + + // Set into a contract + else if ($action == 'setcontrat' && $user->rights->contrat->creer) + { + $result=$object->set_contrat($user,GETPOST('contratid','int')); + if ($result < 0) dol_print_error($db,$object->error); + } + + else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer) + { + $result=$object->delete($user); + if ($result<0) { + setEventMessage($object->error,'errors'); + } + + header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter'); + exit; + } + + else if ($action == 'setdescription' && $user->rights->ficheinter->creer) + { + $result=$object->set_description($user,GETPOST('description')); + if ($result < 0) dol_print_error($db,$object->error); + } + + // Add line + else if ($action == "addline" && $user->rights->ficheinter->creer) + { + if (!GETPOST('np_desc')) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).'
'; + $error++; + } + if (!GETPOST('durationhour','int') && !GETPOST('durationmin','int')) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Duration")).'
'; + $error++; + } + if (GETPOST('durationhour','int') >= 24 && GETPOST('durationmin','int') > 0) + { + $mesg='
'.$langs->trans("ErrorValueTooHigh").'
'; + $error++; + } + if (! $error) + { + $db->begin(); + + $desc=GETPOST('np_desc'); + $date_intervention = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int')); + $duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int')); + + + // Extrafields + $extrafieldsline = new ExtraFields($db); + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline); + + $result=$object->addline( + $user, + $id, + $desc, + $date_intervention, + $duration, + $array_options + ); + + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + if ($result >= 0) + { + $db->commit(); + + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + else + { + $mesg=$object->error; + $db->rollback(); + } + } + } + + // Classify Billed + else if ($action == 'classifybilled' && $user->rights->ficheinter->creer) + { + $result=$object->setStatut(2); + if ($result > 0) + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + // Classify Billed + else if ($action == 'classifyunbilled' && $user->rights->ficheinter->creer) + { + $result=$object->setStatut(1); + if ($result > 0) + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + else + { + $mesg='
'.$object->error.'
'; + } + } + + /* + * Mise a jour d'une ligne d'intervention + */ + else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST('save','alpha') == $langs->trans("Save")) + { + $objectline = new FichinterLigne($db); + if ($objectline->fetch($lineid) <= 0) + { + dol_print_error($db); + exit; + } + + if ($object->fetch($objectline->fk_fichinter) <= 0) + { + dol_print_error($db); + exit; + } + $object->fetch_thirdparty(); + + $desc = GETPOST('np_desc'); + $date_inter = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int')); + $duration = convertTime2Seconds(GETPOST('durationhour','int'),GETPOST('durationmin','int')); + + $objectline->datei = $date_inter; + $objectline->desc = $desc; + $objectline->duration = $duration; + + // Extrafields + $extrafieldsline = new ExtraFields($db); + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline); + $objectline->array_options = $array_options; + + $result = $objectline->update($user); + if ($result < 0) + { + dol_print_error($db); + exit; + } + + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); + + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + + /* + * Supprime une ligne d'intervention AVEC confirmation + */ + else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->ficheinter->creer) + { + $objectline = new FichinterLigne($db); + if ($objectline->fetch($lineid) <= 0) + { + dol_print_error($db); + exit; + } + $result=$objectline->deleteline($user); + + if ($object->fetch($objectline->fk_fichinter) <= 0) + { + dol_print_error($db); + exit; + } + + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); + } + + /* + * Ordonnancement des lignes + */ + + else if ($action == 'up' && $user->rights->ficheinter->creer) + { + $object->line_up($lineid); + + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); + + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid); + exit; + } + + else if ($action == 'down' && $user->rights->ficheinter->creer) + { + $object->line_down($lineid); + + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs); + + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid); + exit; + } + + + /* + * Add file in email form + */ + if (GETPOST('addfile','alpha')) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + // Set tmp user directory TODO Use a dedicated directory for temp mails files + $vardir=$conf->user->dir_output."/".$user->id; + $upload_dir_tmp = $vardir.'/temp'; + + dol_add_file_process($upload_dir_tmp,0,0); + $action='presend'; + } + + /* + * Remove file in email form + */ + if (GETPOST('removedfile','alpha')) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + // Set tmp user directory + $vardir=$conf->user->dir_output."/".$user->id; + $upload_dir_tmp = $vardir.'/temp'; + + // TODO Delete only files that was uploaded from email form + dol_remove_file_process(GETPOST('removedfile','alpha'),0); + $action='presend'; + } + + /* + * Send mail + */ + if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send)) + { + $langs->load('mails'); + + if (GETPOST('sendto','alpha')) + { + // Le destinataire a ete fourni via le champ libre + $sendto = GETPOST('sendto','alpha'); $sendtoid = 0; } - else // Id du contact + elseif (GETPOST('receiver','alpha') != '-1') { - $sendto = $object->client->contact_get_property(GETPOST('receiver'),'email'); - $sendtoid = GETPOST('receiver','alpha'); - } - } - - if (dol_strlen($sendto)) - { - $langs->load("commercial"); - - $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>'; - $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>'; - $message = GETPOST('message'); - $sendtocc = GETPOST('sendtocc','alpha'); - $deliveryreceipt = GETPOST('deliveryreceipt','alpha'); - - if ($action == 'send') - { - if (strlen(GETPOST('subject','alphs'))) $subject = GETPOST('subject','alpha'); - else $subject = $langs->transnoentities('Intervention').' '.$object->ref; - $actiontypecode='AC_OTH_AUTO'; - $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto; - if ($message) + // Recipient was provided from combo list + if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party { - if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc); - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject); - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":"); - $actionmsg = dol_concatdesc($actionmsg, $message); + $sendto = $object->client->email; + $sendtoid = 0; } - $actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref); - } - - // Create form object - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); - - $attachedfiles=$formmail->get_attached_files(); - $filepath = $attachedfiles['paths']; - $filename = $attachedfiles['names']; - $mimetype = $attachedfiles['mimes']; - - // Send by email - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1); - if ($mailfile->error) - { - $mesg='
'.$mailfile->error.'
'; - } - else - { - $result=$mailfile->sendfile(); - if ($result) + else // Id du contact { - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); - setEventMessage($mesg); - $error=0; + $sendto = $object->client->contact_get_property(GETPOST('receiver'),'email'); + $sendtoid = GETPOST('receiver','alpha'); + } + } - // Initialisation donnees - $object->sendtoid = $sendtoid; - $object->actiontypecode = $actiontypecode; - $object->actionmsg = $actionmsg; - $object->actionmsg2 = $actionmsg2; - $object->fk_element = $object->id; - $object->elementtype = $object->element; + if (dol_strlen($sendto)) + { + $langs->load("commercial"); - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($db); - $result=$interface->run_triggers('FICHINTER_SENTBYMAIL',$object,$user,$langs,$conf); - if ($result < 0) { - $error++; $object->errors=$interface->errors; - } - // Fin appel triggers + $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>'; + $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>'; + $message = GETPOST('message'); + $sendtocc = GETPOST('sendtocc','alpha'); + $deliveryreceipt = GETPOST('deliveryreceipt','alpha'); - if ($error) + if ($action == 'send') + { + if (strlen(GETPOST('subject','alphs'))) $subject = GETPOST('subject','alpha'); + else $subject = $langs->transnoentities('Intervention').' '.$object->ref; + $actiontypecode='AC_OTH_AUTO'; + $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto; + if ($message) { - dol_print_error($db); - } - else - { - // Redirect here - // This avoid sending mail twice if going out and then back to page - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; + if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc); + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject); + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":"); + $actionmsg = dol_concatdesc($actionmsg, $message); } + $actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref); + } + + // Create form object + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + + $attachedfiles=$formmail->get_attached_files(); + $filepath = $attachedfiles['paths']; + $filename = $attachedfiles['names']; + $mimetype = $attachedfiles['mimes']; + + // Send by email + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1); + if ($mailfile->error) + { + $mesg='
'.$mailfile->error.'
'; } else { - $langs->load("other"); - $mesg='
'; - if ($mailfile->error) + $result=$mailfile->sendfile(); + if ($result) { - $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); - $mesg.='
'.$mailfile->error; + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); + setEventMessage($mesg); + $error=0; + + // Initialisation donnees + $object->sendtoid = $sendtoid; + $object->actiontypecode = $actiontypecode; + $object->actionmsg = $actionmsg; + $object->actionmsg2 = $actionmsg2; + $object->fk_element = $object->id; + $object->elementtype = $object->element; + + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($db); + $result=$interface->run_triggers('FICHINTER_SENTBYMAIL',$object,$user,$langs,$conf); + if ($result < 0) { + $error++; $object->errors=$interface->errors; + } + // Fin appel triggers + + if ($error) + { + dol_print_error($db); + } + else + { + // Redirect here + // This avoid sending mail twice if going out and then back to page + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } } else { - $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + $langs->load("other"); + $mesg='
'; + if ($mailfile->error) + { + $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); + $mesg.='
'.$mailfile->error; + } + else + { + $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + } + $mesg.='
'; } - $mesg.='
'; } } - } - else - { - $langs->load("other"); - $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; - dol_syslog('Recipient email is empty'); - } - - $action='presend'; -} - -else if ($action == 'update_extras') -{ - // Fill array 'array_options' with data from update form - $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); - if ($ret < 0) $error++; - - if (! $error) - { - // Actions on extra fields (by external module or standard code) - // TODO le hook fait double emploi avec le trigger !! - $hookmanager->initHooks(array('interventiondao')); - $parameters=array('id'=>$object->id); - $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks - if (empty($reshook)) - { - $result=$object->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } - else if ($reshook < 0) $error++; - } - - if ($error) $action = 'edit_extras'; -} - -if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer) -{ - if ($action == 'addcontact') - { - if ($result > 0 && $id > 0) - { - $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int')); - $result = $object->add_contact($contactid, GETPOST('type','int'), GETPOST('source','alpha')); - } - - if ($result >= 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + $langs->load("other"); + $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; + dol_syslog('Recipient email is empty'); + } + + $action='presend'; + } + + else if ($action == 'update_extras') + { + // Fill array 'array_options' with data from update form + $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); + $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); + if ($ret < 0) $error++; + + if (! $error) + { + // Actions on extra fields (by external module or standard code) + // TODO le hook fait double emploi avec le trigger !! + $hookmanager->initHooks(array('interventiondao')); + $parameters=array('id'=>$object->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) { - $langs->load("errors"); - $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; + $result=$object->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + else if ($reshook < 0) $error++; + } + + if ($error) $action = 'edit_extras'; + } + + if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer) + { + if ($action == 'addcontact') + { + if ($result > 0 && $id > 0) + { + $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int')); + $result = $object->add_contact($contactid, GETPOST('type','int'), GETPOST('source','alpha')); + } + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; } else { - $mesg = '
'.$object->error.'
'; + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; + } + else + { + $mesg = '
'.$object->error.'
'; + } } } - } - // bascule du statut d'un contact - else if ($action == 'swapstatut') - { - $result=$object->swapContactStatus(GETPOST('ligne','int')); - } - - // Efface un contact - else if ($action == 'deletecontact') - { - $result = $object->delete_contact(GETPOST('lineid','int')); - - if ($result >= 0) + // bascule du statut d'un contact + else if ($action == 'swapstatut') { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; + $result=$object->swapContactStatus(GETPOST('ligne','int')); } - else { - dol_print_error($db); + + // Efface un contact + else if ($action == 'deletecontact') + { + $result = $object->delete_contact(GETPOST('lineid','int')); + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else { + dol_print_error($db); + } } } } diff --git a/htdocs/fichinter/tpl/linkedobjectblock.tpl.php b/htdocs/fichinter/tpl/linkedobjectblock.tpl.php index adc348a1c53..81a82f06627 100644 --- a/htdocs/fichinter/tpl/linkedobjectblock.tpl.php +++ b/htdocs/fichinter/tpl/linkedobjectblock.tpl.php @@ -34,17 +34,19 @@ print_titre($langs->trans('RelatedInterventions')); trans("Ref"); ?> trans("Date"); ?> trans("Status"); ?> + $objectlink) { $var=!$var; ?> > - getNomUrl(1); ?> - datev,'day'); ?> - getLibStatut(3); ?> + getNomUrl(1); ?> + datev,'day'); ?> + getLibStatut(3); ?> + ">transnoentitiesnoconv("RemoveLink")); ?> 0) } $permissionnote=$user->rights->fournisseur->commande->creer; // Used by the include of actions_setnotes.inc.php +$permissiondellink=$user->rights->fournisseur->commande->creer; // Used by the include of actions_dellink.inc.php $permissiontoedit=$user->rights->fournisseur->commande->creer; // Used by the include of actions_lineupdown.inc.php @@ -134,6 +135,8 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer) diff --git a/htdocs/fourn/commande/tpl/linkedobjectblock.tpl.php b/htdocs/fourn/commande/tpl/linkedobjectblock.tpl.php index b0ed5906d14..cfcb5567bb6 100644 --- a/htdocs/fourn/commande/tpl/linkedobjectblock.tpl.php +++ b/htdocs/fourn/commande/tpl/linkedobjectblock.tpl.php @@ -37,23 +37,25 @@ print_titre($langs->trans('RelatedSupplierOrders')); trans("Date"); ?> trans("AmountHTShort"); ?> trans("Status"); ?> + $objectlink) { $var=!$var; ?> > - trans("ShowOrder"),"order").' '.$object->ref; ?> - date,'day'); ?> + trans("ShowOrder"),"order").' '.$objectlink->ref; ?> + date,'day'); ?> rights->fournisseur->commande->lire) { - $total = $total + $object->total_ht; - echo price($object->total_ht); + $total = $total + $objectlink->total_ht; + echo price($objectlink->total_ht); } ?> - getLibStatut(3); ?> + getLibStatut(3); ?> + ">transnoentitiesnoconv("RemoveLink")); ?> rights->fournisseur->commande->lire) { echo price($total); } ?> -   + + diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 9dd7435c95c..b6261e75f0c 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -87,6 +87,7 @@ if ($id > 0 || ! empty($ref)) } $permissionnote=$user->rights->fournisseur->facture->creer; // Used by the include of actions_setnotes.inc.php +$permissiondellink=$user->rights->fournisseur->facture->creer; // Used by the include of actions_dellink.inc.php $permissionedit=$user->rights->fournisseur->facture->creer; // Used by the include of actions_lineupdown.inc.php @@ -104,6 +105,8 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once // Action clone object diff --git a/htdocs/fourn/facture/tpl/linkedobjectblock.tpl.php b/htdocs/fourn/facture/tpl/linkedobjectblock.tpl.php index 669d5043c01..8678d22384b 100644 --- a/htdocs/fourn/facture/tpl/linkedobjectblock.tpl.php +++ b/htdocs/fourn/facture/tpl/linkedobjectblock.tpl.php @@ -40,24 +40,26 @@ print_titre($langs->trans("RelatedSupplierInvoices")); trans("Date"); ?> trans("AmountHTShort"); ?> trans("Status"); ?> + $objectlink) { $var=!$var; ?> > - trans("ShowBill"),"bill").' '.$object->ref; ?> - ref_supplier; ?> - date,'day'); ?> + trans("ShowBill"),"bill").' '.$objectlink->ref; ?> + ref_supplier; ?> + date,'day'); ?> rights->fournisseur->facture->lire) { - $total = $total + $object->total_ht; - echo price($object->total_ht); + $total = $total + $objectlink->total_ht; + echo price($objectlink->total_ht); } ?> - getLibStatut(3); ?> + getLibStatut(3); ?> + ">transnoentitiesnoconv("RemoveLink")); ?> rights->fournisseur->facture->lire) { echo price($total); } ?> -   + + diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index 7ce82448cb5..8b38758e737 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -194,7 +194,7 @@ ReCalculate=Recalculate Mode1=Method 1 Mode2=Method 2 CalculationRuleDesc=To calculate total VAT, there is two methods:
Method 1 is rounding vat on each line, then summing them.
Method 2 is summing all vat on each line, then rounding result.
Final result may differs from few cents. Default mode is mode %s. -CalculationRuleDescSupplier=according to supplier, choose appropriate method to apply same calculation rule and get same result expected by your supplier. +CalculationRuleDescSupplier=According to supplier, choose appropriate method to apply same calculation rule and get same result expected by your supplier. TurnoverPerProductInCommitmentAccountingNotRelevant=Turnover report per product, when using a cash accountancy mode is not relevant. This report is only available when using engagement accountancy mode (see setup of accountancy module). CalculationMode=Calculation mode AccountancyJournal=Accountancy code journal