diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index a5992410f0b..8c02f1d7716 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -771,7 +771,7 @@ if ($action == 'create') // Other attributes $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { @@ -992,7 +992,7 @@ if ($action == 'edit') // Other attributes $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { @@ -1304,7 +1304,7 @@ if ($rowid && $action != 'edit') // Other attributes $parameters=array(); $reshook=$hookmanager->executeHooks('showOutputField',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php index 0f124265ee0..882262d6b58 100644 --- a/htdocs/comm/addpropal.php +++ b/htdocs/comm/addpropal.php @@ -243,7 +243,7 @@ if ($action == 'create') // Other attributes $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 041fbadaead..0a5e7437a1d 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -73,7 +73,7 @@ if (isset($socid)) { $objectid=$socid; $module='societe'; - $dbtable=''; + $dbtable='&societe'; } else if (isset($id) && $id > 0) { @@ -1471,7 +1471,7 @@ if ($id > 0 || ! empty($ref)) // Other attributes $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 9854f2c8093..169c24cb171 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2320,38 +2320,26 @@ class Commande extends CommonObject dol_syslog("Commande::delete sql=".$sql); if (! $this->db->query($sql) ) { - dol_syslog("CustomerOrder::delete error", LOG_ERR); + dol_syslog(get_class($this)."::delete error", LOG_ERR); $error++; } // Delete order $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id; - dol_syslog("Commande::delete sql=".$sql); + dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG); if (! $this->db->query($sql) ) { - dol_syslog("CustomerOrder::delete error", LOG_ERR); + dol_syslog(get_class($this)."::delete error", LOG_ERR); $error++; } // Delete linked object - // TODO deplacer dans le common - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; - $sql.= " WHERE fk_target = ".$this->id; - $sql.= " AND targettype = '".$this->element."'"; - dol_syslog("Commande::delete sql=".$sql); - if (! $this->db->query($sql) ) - { - dol_syslog("CustomerOrder::delete error", LOG_ERR); - $error++; - } + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; // Delete linked contacts $res = $this->delete_linked_contact(); - if ($res < 0) - { - dol_syslog("CustomerOrder::delete error", LOG_ERR); - $error++; - } + if ($res < 0) $error++; // On efface le repertoire de pdf provisoire $comref = dol_sanitizeFileName($this->ref); @@ -2381,7 +2369,7 @@ class Commande extends CommonObject } } - if ($error == 0) + if (! $error) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 04edb4bcc1f..e24946a17c7 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1369,7 +1369,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Other attributes $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { @@ -1921,7 +1921,7 @@ else // Other attributes $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 36c3b49cb60..80803d6d714 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -179,7 +179,7 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes') if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $ret=$object->fetch($id); // Reload to get new records - $result=facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + $result=facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); } if ($result >= 0) { @@ -360,7 +360,7 @@ if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->facture->v if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $ret=$object->fetch($id); // Reload to get new records - facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); } } else @@ -437,7 +437,7 @@ if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $ret=$object->fetch($id); // Reload to get new records - facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); } } } @@ -1098,7 +1098,7 @@ if (($action == 'addline' || $action == 'addline_predef') && $user->rights->fact if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $ret=$object->fetch($id); // Reload to get new records - facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); } unset($_POST['qty']); unset($_POST['type']); @@ -1200,7 +1200,7 @@ if ($action == 'updateligne' && $user->rights->facture->creer && $_POST['save'] if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $ret=$object->fetch($id); // Reload to get new records - facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); } } } @@ -1229,7 +1229,7 @@ if ($action == 'up' && $user->rights->facture->creer) $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'#'.$_GET['rowid']); exit; @@ -1251,7 +1251,7 @@ if ($action == 'down' && $user->rights->facture->creer) $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'#'.$_GET['rowid']); exit; @@ -1485,7 +1485,7 @@ if (GETPOST('action') == 'builddoc') // En get ou en post $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } - $result=facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + $result=facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); if ($result <= 0) { dol_print_error($db,$result); @@ -1804,7 +1804,7 @@ if ($action == 'create') // Other attributes $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { @@ -2713,7 +2713,7 @@ else // Other attributes $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { @@ -3057,7 +3057,7 @@ else $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } - $result=facture_pdf_create($db, $object, '', $_REQUEST['model'], $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + $result=facture_pdf_create($db, $object, $_REQUEST['model'], $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); if ($result <= 0) { dol_print_error($db,$result); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index ad5624f8a3f..04ece4813c1 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1130,12 +1130,12 @@ class Facture extends CommonObject $error=0; $this->db->begin(); + + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; - $sql.= " WHERE fk_target = ".$rowid; - $sql.= " AND targettype = '".$this->element."'"; - - if ($this->db->query($sql)) + if (! $error) { // If invoice was converted into a discount not yet consumed, we remove discount $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'societe_remise_except'; @@ -1188,7 +1188,7 @@ class Facture extends CommonObject } else { - $this->error=$this->db->error()." sql=".$sql; + $this->error=$this->db->lasterror()." sql=".$sql; dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); $this->db->rollback(); return -6; @@ -1196,7 +1196,7 @@ class Facture extends CommonObject } else { - $this->error=$this->db->error()." sql=".$sql; + $this->error=$this->db->lasterror()." sql=".$sql; dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); $this->db->rollback(); return -4; @@ -1204,7 +1204,7 @@ class Facture extends CommonObject } else { - $this->error=$this->db->error()." sql=".$sql; + $this->error=$this->db->lasterror(); dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); $this->db->rollback(); return -2; diff --git a/htdocs/compta/paiement/fiche.php b/htdocs/compta/paiement/fiche.php index 0fd3e886354..e4af98742ae 100644 --- a/htdocs/compta/paiement/fiche.php +++ b/htdocs/compta/paiement/fiche.php @@ -112,7 +112,7 @@ if ($action == 'confirm_valide' && GETPOST('confirm') == 'yes' && $user->rights- $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $fac, '', $fac->modelpdf, $outputlangs, $hookmanager); + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $fac, $fac->modelpdf, $outputlangs, $hookmanager); } Header('Location: fiche.php?id='.$paiement->id); diff --git a/htdocs/compta/payment_sc/fiche.php b/htdocs/compta/payment_sc/fiche.php index ab14d509a85..d9bee27e91a 100644 --- a/htdocs/compta/payment_sc/fiche.php +++ b/htdocs/compta/payment_sc/fiche.php @@ -94,7 +94,7 @@ if ($_REQUEST['action'] == 'confirm_valide' && $_REQUEST['confirm'] == 'yes' && $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $fac, '', $fac->modelpdf, $outputlangs, $hookmanager); + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $fac, $fac->modelpdf, $outputlangs, $hookmanager); } Header('Location: fiche.php?id='.$paiement->id); diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index e1462e6dd1a..0c1434a4fd8 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2012 Regis Houssin * * 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 @@ -134,6 +134,14 @@ if((isset($_POST['field']) && ! empty($_POST['field'])) if (! $error) { if (! is_object($object)) $object = new GenericObject($db); + + // Specific for add_object_linked() + // TODO add a function for variable treatment + $object->ext_fk_element = $newvalue; + $object->ext_element = $ext_element; + $object->fk_element = $fk_element; + $object->element = $element; + $ret=$object->$savemethodname($field, $newvalue, $table_element, $fk_element, $format); if ($ret > 0) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 4465d79aa06..cf9c09b70d6 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -294,7 +294,7 @@ abstract class CommonObject $sql.= " WHERE element_id =".$this->id; $sql.= " AND fk_c_type_contact IN (".$listId.")"; - dol_syslog(get_class($this)."::delete_linked_contact sql=".$sql); + dol_syslog(get_class($this)."::delete_linked_contact sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) { return 1; @@ -1514,10 +1514,10 @@ abstract class CommonObject if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $justsource=true; if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $justtarget=true; - $sourceid = (! empty($sourceid) ? $sourceid : $this->id ); - $targetid = (! empty($targetid) ? $targetid : $this->id ); - $sourcetype = (! empty($sourcetype) ? $sourcetype : (! empty($this->origin) ? $this->origin : $this->element ) ); - $targettype = (! empty($targettype) ? $targettype : $this->element ); + $sourceid = (! empty($sourceid) ? $sourceid : $this->id); + $targetid = (! empty($targetid) ? $targetid : $this->id); + $sourcetype = (! empty($sourcetype) ? $sourcetype : (! empty($this->origin) ? $this->origin : $this->element)); + $targettype = (! empty($targettype) ? $targettype : $this->element); // Links beetween objects are stored in this table $sql = 'SELECT fk_source, sourcetype, fk_target, targettype'; @@ -1629,7 +1629,77 @@ abstract class CommonObject dol_print_error($this->db); } } - + + /** + * Update object linked of a current object + * + * @param int $sourceid Object source id + * @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 + */ + function updateObjectLinked($sourceid='', $sourcetype='', $targetid='', $targettype='') + { + $updatesource=false; + $updatetarget=false; + + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; + else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; + + $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; + if ($updatesource) + { + $sql.= "fk_source = ".$sourceid; + $sql.= ", sourcetype = '".$sourcetype."'"; + $sql.= " WHERE fk_target = ".$this->id; + $sql.= " AND targettype = '".$this->element."'"; + } + else if ($updatetarget) + { + $sql.= "fk_target = ".$targetid; + $sql.= ", targettype = '".$targettype."'"; + $sql.= " WHERE fk_source = ".$this->id; + $sql.= " AND sourcetype = '".$this->element."'"; + } + + dol_syslog(get_class($this)."::updateObjectLinked sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { + return 1; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::updateObjectLinked error=".$this->error, LOG_ERR); + return -1; + } + } + + /** + * Delete all links between an object $this + * + * @return int >0 if OK, <0 if KO + */ + function deleteObjectLinked() + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; + $sql.= " WHERE fk_target = ".$this->id; + $sql.= " AND targettype = '".$this->element."'"; + + dol_syslog(get_class($this)."::deleteObjectLinked sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { + return 1; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::deleteObjectLinked error=".$this->error, LOG_ERR); + return -1; + } + } + /** * Set statut of an object * @@ -1787,6 +1857,8 @@ abstract class CommonObject { global $langs; + $error=0; + if (count($this->array_options) > 0) { // Check parameters @@ -2045,19 +2117,19 @@ abstract class CommonObject if ($objecttype == 'facture') { $tplpath = 'compta/'.$element; } - if ($objecttype == 'propal') { + else if ($objecttype == 'propal') { $tplpath = 'comm/'.$element; } - if ($objecttype == 'shipping') { + else if ($objecttype == 'shipping') { $tplpath = 'expedition'; } - if ($objecttype == 'delivery') { + else if ($objecttype == 'delivery') { $tplpath = 'livraison'; } - if ($objecttype == 'invoice_supplier') { + else if ($objecttype == 'invoice_supplier') { $tplpath = 'fourn/facture'; } - if ($objecttype == 'order_supplier') { + else if ($objecttype == 'order_supplier') { $tplpath = 'fourn/commande'; } diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 3babbc8aeee..9acad8b7466 100755 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -148,7 +148,7 @@ class HookManager $var=!$var; // Hooks that return int - if (($method == 'doActions' || $method='formObjectOptions') && method_exists($actioninstance,$method)) + if (($method == 'doActions' || $method == 'formObjectOptions') && method_exists($actioninstance,$method)) { $resaction+=$actioninstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example) if ($resaction < 0 || ! empty($actioninstance->error) || (! empty($actioninstance->errors) && count($actioninstance->errors) > 0)) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index bf81c7ceaad..d85bbcef9dc 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1,10 +1,10 @@ - * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2006 Marc Barilley/Ocebo * Copyright (C) 2007 Franky Van Liedekerke @@ -87,7 +87,6 @@ class Form if ($perm) { $tmp=explode(':',$typeofdata); - if (preg_match('/^(string|email|numeric)$/i',$tmp[0])) $tmp[0] = 'text'; $ret.= '
'; $ret.= $langs->trans($text); $ret.= '
'."\n"; @@ -237,8 +236,7 @@ class Form if (preg_match('/^(string|email|numeric)/',$inputType)) { $tmp=explode(':',$inputType); - $inputType='text'; - $inputOption=$tmp[1]; + $inputType=$tmp[0]; $inputOption=$tmp[1]; if (! empty($tmp[2])) $savemethod=$tmp[2]; } if (preg_match('/^datepicker/',$inputType)) diff --git a/htdocs/core/js/editinplace.js b/htdocs/core/js/editinplace.js index 32ef01985a9..ca3d3bacab8 100644 --- a/htdocs/core/js/editinplace.js +++ b/htdocs/core/js/editinplace.js @@ -107,7 +107,7 @@ $(document).ready(function() { $( '#val_' + $(this).attr('id') ).click(); }); - $('.editval_text').editable(urlSaveInPlace, { + $('.editval_string').editable(urlSaveInPlace, { type : 'text', id : 'field', width : 300, @@ -118,7 +118,7 @@ $(document).ready(function() { indicator : indicatorInPlace, submitdata : function(result, settings) { var htmlname = $(this).attr('id').substr(4); - return getParameters('text', htmlname); + return getParameters('string', htmlname); }, callback : function(result, settings) { var obj = $.parseJSON(result); @@ -131,7 +131,7 @@ $(document).ready(function() { } } }); - $('.editkey_text').hover( + $('.editkey_string').hover( function () { $( '#val_' + $(this).attr('id') ).addClass("editval_hover"); }, @@ -139,7 +139,7 @@ $(document).ready(function() { $( '#val_' + $(this).attr('id') ).removeClass("editval_hover"); } ); - $('.editkey_text').click(function() { + $('.editkey_string').click(function() { $( '#val_' + $(this).attr('id') ).click(); }); @@ -236,7 +236,7 @@ $(document).ready(function() { }, callback : function(result, settings) { var obj = $.parseJSON(result); - + if (obj.error) { $(this).html(this.revert); $.jnotify(obj.error, "error", true); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c587cecffa1..b6dc024b0e3 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1050,7 +1050,7 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1) if ($usealternatemethod || $gm) // Si time gm, seule adodb peut convertir { - $date=adodb_mktime($hour,$minute,$second,$month,$day,$year,$isdst,$gm); + $date=adodb_mktime($hour,$minute,$second,$month,$day,$year,0,$gm); } else { diff --git a/htdocs/core/modules/cheque/pdf/modules_chequereceipts.php b/htdocs/core/modules/cheque/pdf/modules_chequereceipts.php index 9a3fa4c68c8..668e64bf431 100644 --- a/htdocs/core/modules/cheque/pdf/modules_chequereceipts.php +++ b/htdocs/core/modules/cheque/pdf/modules_chequereceipts.php @@ -112,7 +112,7 @@ function chequereceipt_pdf_create($db, $id, $message, $modele, $outputlangs) else { $outputlangs->charset_output=$sav_charset_output; - dol_print_error($db,"facture_pdf_create Error: ".$obj->error); + dol_print_error($db,"chequereceipt_pdf_create Error: ".$obj->error); return -1; } diff --git a/htdocs/core/modules/commande/modules_commande.php b/htdocs/core/modules/commande/modules_commande.php index f0a282725ad..62d8f11411a 100644 --- a/htdocs/core/modules/commande/modules_commande.php +++ b/htdocs/core/modules/commande/modules_commande.php @@ -205,7 +205,7 @@ function commande_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0 require_once($file); $obj = new $classname($db); - $obj->message = $message; + //$obj->message = $message; // We save charset_output to restore it because write_file can change it if needed for // output format that does not support UTF8. diff --git a/htdocs/core/modules/facture/modules_facture.php b/htdocs/core/modules/facture/modules_facture.php index a87a2ed7016..a6e5d6ae38f 100644 --- a/htdocs/core/modules/facture/modules_facture.php +++ b/htdocs/core/modules/facture/modules_facture.php @@ -130,12 +130,11 @@ abstract class ModeleNumRefFactures /** - * Create a document onto disk accordign to template module. + * Create a document onto disk according to template module. * * @param DoliDB $db Database handler * @param Object $object Object invoice - * @param string $message message - * @param string $modele Force le modele a utiliser ('' to not force) + * @param string $modele Force template to use ('' to not force) * @param Translate $outputlangs objet lang a utiliser pour traduction * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description @@ -143,7 +142,7 @@ abstract class ModeleNumRefFactures * @param HookManager $hookmanager Hook manager instance * @return int <0 if KO, >0 if OK */ -function facture_pdf_create($db, $object, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false) +function facture_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false) { global $conf,$user,$langs; @@ -204,7 +203,6 @@ function facture_pdf_create($db, $object, $message, $modele, $outputlangs, $hide require_once($file); $obj = new $classname($db); - $obj->message = $message; // We save charset_output to restore it because write_file can change it if needed for // output format that does not support UTF8. diff --git a/htdocs/core/modules/modWorkflow.class.php b/htdocs/core/modules/modWorkflow.class.php index dfc6c2322f0..68887d57543 100644 --- a/htdocs/core/modules/modWorkflow.class.php +++ b/htdocs/core/modules/modWorkflow.class.php @@ -155,7 +155,7 @@ class modWorkflow extends DolibarrModules $sql = array(); - return $this->_init($sql,$option); + return $this->_init($sql,$options); } /** diff --git a/htdocs/core/modules/propale/modules_propale.php b/htdocs/core/modules/propale/modules_propale.php index ab9c6f09dd3..2ab268c6d9e 100644 --- a/htdocs/core/modules/propale/modules_propale.php +++ b/htdocs/core/modules/propale/modules_propale.php @@ -195,7 +195,7 @@ function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, require_once($file); $obj = new $classname($db); - $obj->message = $message; + //$obj->message = $message; // We save charset_output to restore it because write_file can change it if needed for // output format that does not support UTF8. diff --git a/htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php b/htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php index a45a2d8b958..11d0cddffe5 100755 --- a/htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php +++ b/htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php @@ -58,38 +58,69 @@ abstract class ModelePDFSuppliersInvoices extends CommonDocGenerator * * @param DoliDB $db objet base de donnee * @param Object $object object supplier invoice - * @param string $model force le modele a utiliser ('' to not force) + * @param string $modele Force template to use ('' to not force) * @param Translate $outputlangs objet lang a utiliser pour traduction * @return int 0 if KO, 1 if OK */ -function supplier_invoice_pdf_create($db, $object, $model, $outputlangs) +function supplier_invoice_pdf_create($db, $object, $modele, $outputlangs) { - global $conf, $langs; + global $conf, $user, $langs; $langs->load("suppliers"); - $dir = DOL_DOCUMENT_ROOT."/core/modules/supplier_invoice/pdf/"; + $error=0; + + // Increase limit for PDF build + $err=error_reporting(); + error_reporting(0); + @set_time_limit(120); + error_reporting($err); + + $dir = "/core/modules/supplier_invoice/"; + $srctemplatepath=''; // Positionne modele sur le nom du modele de invoice fournisseur a utiliser - if (! dol_strlen($model)) + if (! dol_strlen($modele)) { if (! empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF)) { - $model = $conf->global->INVOICE_SUPPLIER_ADDON_PDF; + $modele = $conf->global->INVOICE_SUPPLIER_ADDON_PDF; } else { - $model = 'canelle'; - //print $langs->trans("Error")." ".$langs->trans("Error_INVOICE_SUPPLIER_ADDON_PDF_NotDefined"); - //return 0; + $modele = 'canelle'; } } - // Charge le modele - $file = "pdf_".$model.".modules.php"; - if (file_exists($dir.$file)) + + // If selected modele is a filename template (then $modele="modelname:filename") + $tmp=explode(':',$modele,2); + if (! empty($tmp[1])) + { + $modele=$tmp[0]; + $srctemplatepath=$tmp[1]; + } + + // Search template file + $file=''; $classname=''; $filefound=0; + foreach(array('doc','pdf') as $prefix) { - $classname = "pdf_".$model; - require_once($dir.$file); + $file = $prefix."_".$modele.".modules.php"; + + // On verifie l'emplacement du modele + $file = dol_buildpath($dir.'pdf/'.$file); // TODO rename into doc/ + + if (file_exists($file)) + { + $filefound=1; + $classname=$prefix.'_'.$modele; + break; + } + } + + // Charge le modele + if ($filefound) + { + require_once($file); $obj = new $classname($db,$object); @@ -103,6 +134,14 @@ function supplier_invoice_pdf_create($db, $object, $model, $outputlangs) // we delete preview files require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); dol_delete_preview($object); + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($db); + $result=$interface->run_triggers('BILL_BUILDDOC',$object,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + return 1; } else @@ -115,7 +154,7 @@ function supplier_invoice_pdf_create($db, $object, $model, $outputlangs) } else { - print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file); + print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); return 0; } } diff --git a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php index 62f182c6ab8..adab34b9e5a 100755 --- a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php +++ b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php @@ -303,6 +303,24 @@ class pdf_canelle extends ModelePDFSuppliersInvoices $nexY+=2; // Passe espace entre les lignes + // Cherche nombre de lignes a venir pour savoir si place suffisante + if ($i < ($nblignes - 1) && empty($hidedesc)) // If it's not last line + { + //on recupere la description du produit suivant + $follow_descproduitservice = $object->lines[$i+1]->desc; + //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres) + $nblineFollowDesc = dol_nboflines_bis($follow_descproduitservice,52,$outputlangs->charset_output)*4; + // Et si on affiche dates de validite, on ajoute encore une ligne + if ($object->lines[$i]->date_start && $object->lines[$i]->date_end) + { + $nblineFollowDesc += 4; + } + } + else // If it's last line + { + $nblineFollowDesc = 0; + } + // Test if a new page is required if ($pagenb == 1) { diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index e9fd3cfbd76..73295740d16 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -761,16 +761,16 @@ class Expedition extends CommonObject if ( $this->db->query($sql) ) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; - $sql.= " WHERE fk_target = ".$this->id; - $sql.= " AND targettype = '".$this->element."'"; + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; - if ( $this->db->query($sql) ) + if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition"; $sql.= " WHERE rowid = ".$this->id; - if ( $this->db->query($sql) ) + if ($this->db->query($sql)) { $this->db->commit(); diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index ca3eb2cbbb1..b72df22e2de 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -585,16 +585,8 @@ class Fichinter extends CommonObject $this->db->begin(); // Delete linked object - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; - $sql.= " WHERE fk_target = ".$this->id; - $sql.= " AND targettype = '".$this->element."'"; - dol_syslog("Fichinter::delete sql=".$sql); - if (! $this->db->query($sql) ) - { - dol_syslog("Fichinter::delete error", LOG_ERR); - $this->error=$this->db->lasterror(); - $error++; - } + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; // Delete linked contacts $res = $this->delete_linked_contact(); diff --git a/htdocs/livraison/class/livraison.class.php b/htdocs/livraison/class/livraison.class.php index 72d1822e746..5d41bca48f4 100644 --- a/htdocs/livraison/class/livraison.class.php +++ b/htdocs/livraison/class/livraison.class.php @@ -549,15 +549,18 @@ class Livraison extends CommonObject { require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); $this->db->begin(); + + $error=0; $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraisondet"; $sql.= " WHERE fk_livraison = ".$this->id; - if ( $this->db->query($sql) ) + if ($this->db->query($sql)) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; - $sql.= " WHERE fk_target = ".$this->id; - $sql.= " AND targettype = '".$this->element."'"; - if ( $this->db->query($sql) ) + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; + + if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison"; $sql.= " WHERE rowid = ".$this->id; diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 70a549c8df8..3fa8d523db9 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -783,7 +783,7 @@ else // Other attributes $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { @@ -987,7 +987,7 @@ else // Other attributes $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { @@ -1214,7 +1214,7 @@ else // Other attributes $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 3fd17d21210..3fe4af14642 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -941,7 +941,7 @@ else // Other attributes $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { @@ -1369,7 +1369,7 @@ else // Other attributes $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { @@ -1718,7 +1718,7 @@ else // Other attributes $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + if (empty($reshook) && ! empty($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key=>$label) { diff --git a/htdocs/theme/auguria/style.css.php b/htdocs/theme/auguria/style.css.php index 246418765ba..8691787cc49 100644 --- a/htdocs/theme/auguria/style.css.php +++ b/htdocs/theme/auguria/style.css.php @@ -1652,7 +1652,7 @@ table.cal_event td { border: 0px; padding-: 0px; padding-) right top no-repeat; cursor: pointer; } @@ -1662,7 +1662,7 @@ table.cal_event td { border: 0px; padding-: 0px; padding-: 0px; padding-) right top no-repeat; cursor: pointer; } @@ -1854,7 +1854,7 @@ table.cal_event td { border: 0px; padding-: 0px; padding-: 0px; padding-) right top no-repeat; cursor: pointer; } @@ -1801,7 +1801,7 @@ table.cal_event td { border: 0px; padding-: 0px; padding- - * Copyright (C) 2006 Rodolphe Quiedeville - * Copyright (C) 2007-2011 Regis Houssin - * Copyright (C) 2011 Philippe Grand +/* Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2006 Rodolphe Quiedeville + * Copyright (C) 2007-2012 Regis Houssin + * Copyright (C) 2011 Philippe Grand * * 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 @@ -1959,7 +1959,7 @@ table.cal_event td { border: 0px; padding-: 0px; padding-) right top no-repeat; cursor: pointer; } @@ -1969,7 +1969,7 @@ table.cal_event td { border: 0px; padding-: 0px; padding-query($sql) ) } } print "Build PDF for invoice ".$obj->facnumber." - Lang = ".$outputlangs->defaultlang."\n"; - $result=facture_pdf_create($db, $fac, '', $newmodel?$newmodel:$fac->modelpdf, $outputlangs); + $result=facture_pdf_create($db, $fac, $newmodel?$newmodel:$fac->modelpdf, $outputlangs); // Add file into files array $files[] = $conf->facture->dir_output.'/'.$fac->ref.'/'.$fac->ref.'.pdf'; diff --git a/test/phpunit/BuildDocTest.php b/test/phpunit/BuildDocTest.php index c3c490ef4e1..b0977142f33 100644 --- a/test/phpunit/BuildDocTest.php +++ b/test/phpunit/BuildDocTest.php @@ -162,14 +162,14 @@ class BuildDocTest extends PHPUnit_Framework_TestCase // Crabe $localobject->modelpdf='crabe'; - $result=facture_pdf_create($db, $localobject, '', $localobject->modelpdf, $langs); + $result=facture_pdf_create($db, $localobject, $localobject->modelpdf, $langs); $this->assertLessThan($result, 0); print __METHOD__." result=".$result."\n"; // Oursin $localobject->modelpdf='oursin'; - $result=facture_pdf_create($db, $localobject, '', $localobject->modelpdf, $langs); + $result=facture_pdf_create($db, $localobject, $localobject->modelpdf, $langs); $this->assertLessThan($result, 0); print __METHOD__." result=".$result."\n";