diff --git a/htdocs/admin/holiday.php b/htdocs/admin/holiday.php index f0b0218c0e5..5f6d52e1169 100644 --- a/htdocs/admin/holiday.php +++ b/htdocs/admin/holiday.php @@ -43,7 +43,7 @@ $type='contract'; if (empty($conf->global->HOLIDAY_ADDON)) { - $conf->global->HOLIDAY_ADDON='mod_holiday_madona'; + $conf->global->HOLIDAY_ADDON = 'mod_holiday_madonna'; } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 0c093d561c0..ef15d983d20 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -977,35 +977,22 @@ class Commande extends CommonOrder $sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='".$this->db->escape($initialref)."' WHERE rowid=".$this->id; if ($this->db->query($sql)) { - if ($this->id) + $this->ref = $initialref; + + if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects { - $this->ref = $initialref; + $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds + } - if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects + // Add object linked + if (!$error && $this->id && is_array($this->linked_objects) && !empty($this->linked_objects)) + { + foreach ($this->linked_objects as $origin => $tmp_origin_id) { - $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds - } - - // Add object linked - if (!$error && $this->id && is_array($this->linked_objects) && !empty($this->linked_objects)) - { - foreach ($this->linked_objects as $origin => $tmp_origin_id) + if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) { - if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) + foreach ($tmp_origin_id as $origin_id) { - foreach ($tmp_origin_id as $origin_id) - { - $ret = $this->add_object_linked($origin, $origin_id); - if (!$ret) - { - $this->error = $this->db->lasterror(); - $error++; - } - } - } - else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) - { - $origin_id = $tmp_origin_id; $ret = $this->add_object_linked($origin, $origin_id); if (!$ret) { @@ -1014,44 +1001,54 @@ class Commande extends CommonOrder } } } + else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) + { + $origin_id = $tmp_origin_id; + $ret = $this->add_object_linked($origin, $origin_id); + if (!$ret) + { + $this->error = $this->db->lasterror(); + $error++; + } + } } + } - if (!$error && $this->id && !empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && !empty($this->origin) && !empty($this->origin_id)) // Get contact from origin object + if (!$error && $this->id && !empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && !empty($this->origin) && !empty($this->origin_id)) // Get contact from origin object + { + $originforcontact = $this->origin; + $originidforcontact = $this->origin_id; + if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order { - $originforcontact = $this->origin; - $originidforcontact = $this->origin_id; - if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order + require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; + $exp = new Expedition($this->db); + $exp->fetch($this->origin_id); + $exp->fetchObjectLinked(); + if (count($exp->linkedObjectsIds['commande']) > 0) { - require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; - $exp = new Expedition($this->db); - $exp->fetch($this->origin_id); - $exp->fetchObjectLinked(); - if (count($exp->linkedObjectsIds['commande']) > 0) + foreach ($exp->linkedObjectsIds['commande'] as $key => $value) { - foreach ($exp->linkedObjectsIds['commande'] as $key => $value) - { - $originforcontact = 'commande'; - if (is_object($value)) $originidforcontact = $value->id; - else $originidforcontact = $value; - break; // We take first one - } + $originforcontact = 'commande'; + if (is_object($value)) $originidforcontact = $value->id; + else $originidforcontact = $value; + break; // We take first one } } - - $sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; - $sqlcontact .= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; - - $resqlcontact = $this->db->query($sqlcontact); - if ($resqlcontact) - { - while ($objcontact = $this->db->fetch_object($resqlcontact)) - { - //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n"; - $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object - } - } - else dol_print_error($resqlcontact); } + + $sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; + $sqlcontact .= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; + + $resqlcontact = $this->db->query($sqlcontact); + if ($resqlcontact) + { + while ($objcontact = $this->db->fetch_object($resqlcontact)) + { + //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n"; + $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object + } + } + else dol_print_error($resqlcontact); } if (!$error) diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index d5226bb7e3d..7a3102e8aca 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -422,7 +422,8 @@ function restrictedArea($user, $features, $objectid = 0, $tableandshare = '', $f if (! empty($objectid) && $objectid > 0) { $ok = checkUserAccessToObject($user, $featuresarray, $objectid, $tableandshare, $feature2, $dbt_keyfield, $dbt_select); - return $ok ? 1 : accessforbidden(); + $params=array('objectid' => $objectid, 'features' => join(',', $featuresarray), 'features2' => $feature2); + return $ok ? 1 : accessforbidden('', 1, 1, 0, $params); } return 1; @@ -660,13 +661,14 @@ function checkUserAccessToObject($user, $featuresarray, $objectid = 0, $tableand * Show a message to say access is forbidden and stop program * Calling this function terminate execution of PHP. * - * @param string $message Force error message - * @param int $printheader Show header before - * @param int $printfooter Show footer after - * @param int $showonlymessage Show only message parameter. Otherwise add more information. + * @param string $message Force error message + * @param int $printheader Show header before + * @param int $printfooter Show footer after + * @param int $showonlymessage Show only message parameter. Otherwise add more information. + * @param array|null $params Send params * @return void */ -function accessforbidden($message = '', $printheader = 1, $printfooter = 1, $showonlymessage = 0) +function accessforbidden($message = '', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params = null) { global $conf, $db, $user, $langs, $hookmanager; if (! is_object($langs)) @@ -697,7 +699,7 @@ function accessforbidden($message = '', $printheader = 1, $printfooter = 1, $sho // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('main')); } - $parameters = array('message'=>$message); + $parameters = array('message'=>$message, 'params'=>$params); $reshook=$hookmanager->executeHooks('getAccessForbiddenMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks print $hookmanager->resPrint; if (empty($reshook)) diff --git a/htdocs/core/modules/modExpedition.class.php b/htdocs/core/modules/modExpedition.class.php index d8225a1b2a5..8f99dcc59a1 100644 --- a/htdocs/core/modules/modExpedition.class.php +++ b/htdocs/core/modules/modExpedition.class.php @@ -35,7 +35,6 @@ include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; */ class modExpedition extends DolibarrModules { - /** * Constructor. Define names, constants, directories, boxes, permissions * @@ -189,7 +188,7 @@ class modExpedition extends DolibarrModules $r++; $this->rights[$r][0] = 1101; - $this->rights[$r][1] = 'Lire les bons de livraison'; + $this->rights[$r][1] = 'Read delivery receipts'; $this->rights[$r][2] = 'r'; $this->rights[$r][3] = 0; $this->rights[$r][4] = 'livraison'; @@ -197,7 +196,7 @@ class modExpedition extends DolibarrModules $r++; $this->rights[$r][0] = 1102; - $this->rights[$r][1] = 'Creer modifier les bons de livraison'; + $this->rights[$r][1] = 'Create/modify delivery receipts'; $this->rights[$r][2] = 'w'; $this->rights[$r][3] = 0; $this->rights[$r][4] = 'livraison'; @@ -205,7 +204,7 @@ class modExpedition extends DolibarrModules $r++; $this->rights[$r][0] = 1104; - $this->rights[$r][1] = 'Valider les bons de livraison'; + $this->rights[$r][1] = 'Validate delivery receipts'; $this->rights[$r][2] = 'd'; $this->rights[$r][3] = 0; $this->rights[$r][4] = 'livraison_advance'; @@ -213,7 +212,7 @@ class modExpedition extends DolibarrModules $r++; $this->rights[$r][0] = 1109; - $this->rights[$r][1] = 'Supprimer les bons de livraison'; + $this->rights[$r][1] = 'Delete delivery receipts'; $this->rights[$r][2] = 'd'; $this->rights[$r][3] = 0; $this->rights[$r][4] = 'livraison'; diff --git a/htdocs/core/modules/modHoliday.class.php b/htdocs/core/modules/modHoliday.class.php index 081149be51d..917da8fec25 100644 --- a/htdocs/core/modules/modHoliday.class.php +++ b/htdocs/core/modules/modHoliday.class.php @@ -269,4 +269,45 @@ class modHoliday extends DolibarrModules // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; // $r++; } + + /** + * Function called when module is enabled. + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. + * It also creates data directories + * + * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes') + * @return int 1 if OK, 0 if KO + */ + public function init($options = '') + { + global $conf; + + // Permissions + $this->remove($options); + + //ODT template + /*$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/holiday/template_holiday.odt'; + $dirodt=DOL_DATA_ROOT.'/doctemplates/holiday'; + $dest=$dirodt.'/template_order.odt'; + + if (file_exists($src) && ! file_exists($dest)) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + dol_mkdir($dirodt); + $result=dol_copy($src, $dest, 0, 0); + if ($result < 0) + { + $langs->load("errors"); + $this->error=$langs->trans('ErrorFailToCopyFile', $src, $dest); + return 0; + } + } + + $sql = array( + "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'holiday' AND entity = ".$conf->entity, + "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','holiday',".$conf->entity.")" + );*/ + + return $this->_init($sql, $options); + } } diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index e71d44cd573..6556590c076 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -888,7 +888,7 @@ class EmailCollector extends CommonObject dol_syslog("EmailCollector::doCollectOneCollector start", LOG_DEBUG); - $langs->loadLangs(array("project", "companies", "mails", "errors", "ticket")); + $langs->loadLangs(array("project", "companies", "mails", "errors", "ticket", "agenda")); $error = 0; $this->output = ''; @@ -1122,11 +1122,30 @@ class EmailCollector extends CommonObject $this->db->begin(); + // GET Email meta datas $overview = imap_fetch_overview($connection, $imapemail, 0); dol_syslog("** Process email - msgid=".$overview[0]->message_id." date=".dol_print_date($overview[0]->udate, 'dayrfc', 'gmt')." subject=".$overview[0]->subject); + // Decode $overview[0]->subject according to RFC2047 + // Can use also imap_mime_header_decode($str) + // Can use also mb_decode_mimeheader($str) + // Can use also iconv_mime_decode($str, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8') + if (function_exists('imap_mime_header_decode')) { + $elements = imap_mime_header_decode($overview[0]->subject); + $newstring = ''; + if (! empty($elements)) { + for ($i = 0; $i < count($elements); $i++) { + $newstring .= ($newstring ? ' ' : '').$elements[$i]->text; + } + $overview[0]->subject = $newstring; + } + } + elseif (function_exists('mb_decode_mimeheader')) { + $overview[0]->subject = mb_decode_mimeheader($overview[0]->subject); + } + // Parse IMAP email structure global $htmlmsg, $plainmsg, $charset, $attachments; $this->getmsg($connection, $imapemail); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 28610c14203..a4a7964ca5a 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2675,7 +2675,7 @@ else if ($calculationrule == 'totalofround') $calculationrulenum = 1; else $calculationrulenum = 2; // Show link for "recalculate" - if (empty($object->getVentilExportCompta())) { + if ($object->getVentilExportCompta() == 0) { $s = $langs->trans("ReCalculate").' '; $s .= ''.$langs->trans("Mode1").''; $s .= ' / '; diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index c44c588b335..e1ba230fe38 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -304,12 +304,31 @@ class Holiday extends CommonObject { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday"); - if (!$notrigger) + if ($this->id) { - // Call trigger - $result = $this->call_trigger('HOLIDAY_CREATE', $user); - if ($result < 0) { $error++; } - // End call triggers + // update ref + $initialref = '(PROV'.$this->id.')'; + if (!empty($this->ref)) $initialref = $this->ref; + + $sql = 'UPDATE '.MAIN_DB_PREFIX."holiday SET ref='".$this->db->escape($initialref)."' WHERE rowid=".$this->id; + if ($this->db->query($sql)) + { + $this->ref = $initialref; + + if (!$error) + { + $result = $this->insertExtraFields(); + if ($result < 0) $error++; + } + + if (!$error && !$notrigger) + { + // Call trigger + $result = $this->call_trigger('HOLIDAY_CREATE', $user); + if ($result < 0) { $error++; } + // End call triggers + } + } } } @@ -337,7 +356,7 @@ class Holiday extends CommonObject * * @param int $id Id object * @param string $ref Ref object - * @return int <0 if KO, >0 if OK + * @return int <0 if KO, 0 if not found, >0 if OK */ public function fetch($id, $ref = '') { @@ -402,12 +421,17 @@ class Holiday extends CommonObject $this->fk_user_create = $obj->fk_user_create; $this->fk_type = $obj->fk_type; $this->entity = $obj->entity; + + $this->fetch_optionals(); + + $result = 1; + } + else { + $result = 0; } $this->db->free($resql); - $this->fetch_optionals(); - - return 1; + return $result; } else { diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 05c076625f1..096a710bee8 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -844,10 +844,10 @@ Permission1002=Create/modify warehouses Permission1003=Delete warehouses Permission1004=Read stock movements Permission1005=Create/modify stock movements -Permission1101=Read delivery orders -Permission1102=Create/modify delivery orders -Permission1104=Validate delivery orders -Permission1109=Delete delivery orders +Permission1101=Read delivery receipts +Permission1102=Create/modify delivery receipts +Permission1104=Validate delivery receipts +Permission1109=Delete delivery receipts Permission1121=Read supplier proposals Permission1122=Create/modify supplier proposals Permission1123=Validate supplier proposals diff --git a/htdocs/langs/en_US/commercial.lang b/htdocs/langs/en_US/commercial.lang index 44e78324abf..10c536e0d48 100644 --- a/htdocs/langs/en_US/commercial.lang +++ b/htdocs/langs/en_US/commercial.lang @@ -1,6 +1,6 @@ # Dolibarr language file - Source file is en_US - commercial -Commercial=Commercial -CommercialArea=Commercial area +Commercial=Commerce +CommercialArea=Commerce area Customer=Customer Customers=Customers Prospect=Prospect diff --git a/htdocs/langs/en_US/deliveries.lang b/htdocs/langs/en_US/deliveries.lang index 778cb3332ad..1f48c01de75 100644 --- a/htdocs/langs/en_US/deliveries.lang +++ b/htdocs/langs/en_US/deliveries.lang @@ -2,7 +2,7 @@ Delivery=Delivery DeliveryRef=Ref Delivery DeliveryCard=Receipt card -DeliveryOrder=Delivery order +DeliveryOrder=Delivery receipt DeliveryDate=Delivery date CreateDeliveryOrder=Generate delivery receipt DeliveryStateSaved=Delivery state saved diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 5d2dcb9a15f..dff0dd70175 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -825,14 +825,26 @@ if ($action == 'addcontainer') if (!$error) { - $res = $objectpage->create($user); - if ($res <= 0) - { + $pageid = $objectpage->create($user); + if ($pageid <= 0) { $error++; setEventMessages($objectpage->error, $objectpage->errors, 'errors'); $action = 'createcontainer'; } + else { + // If there is no home page yet, this new page will be set as the home page + if (empty($object->fk_default_home)) { + $object->fk_default_home = $pageid; + $res = $object->update($user); + if ($res <= 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } } + if (!$error) { if (!empty($objectpage->content)) @@ -2891,7 +2903,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') print '
'; if (!empty($conf->use_javascript_ajax)) print ' '; - print '
'; + print '
'; print '
'; print ''; print ''; // Translation of
'; @@ -2912,7 +2924,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') print '
'; if (!empty($conf->use_javascript_ajax)) print ' '; - print '
'; + print '
'; print '
'; } @@ -3015,7 +3027,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') print '
'; print $langs->trans('Language'); print ''; - print $formadmin->select_language($pagelang ? $pagelang : $langs->defaultlang, 'WEBSITE_LANG', 0, null, '1'); + print $formadmin->select_language($pagelang ? $pagelang : $langs->defaultlang, 'WEBSITE_LANG', 0, null, '1', 0, 0, 'minwidth200'); print '