diff --git a/htdocs/admin/mails.php b/htdocs/admin/mails.php index abf526544ac..b340cd43bc3 100644 --- a/htdocs/admin/mails.php +++ b/htdocs/admin/mails.php @@ -99,6 +99,7 @@ $triggersendname = ''; // Disable triggers $paramname = 'id'; $mode = 'emailfortest'; $trackid = (($action == 'testhtml') ? "testhtml" : "test"); +$sendcontext=''; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; if ($action == 'presend' && GETPOST('trackid', 'alphanohtml') == 'test') $action = 'test'; @@ -791,7 +792,7 @@ else print load_fiche_titre($langs->trans("DoTestServerAvailability")); include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mail = new CMailFile('', '', '', ''); + $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, '', '', '', '', $trackid, $sendcontext); $result = $mail->check_server_port($server, $port); if ($result) print '
'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'
'; else diff --git a/htdocs/admin/mails_emailing.php b/htdocs/admin/mails_emailing.php index 60de9f34443..94b9bb4b83f 100644 --- a/htdocs/admin/mails_emailing.php +++ b/htdocs/admin/mails_emailing.php @@ -535,8 +535,9 @@ else print load_fiche_titre($langs->trans("DoTestServerAvailability")); include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mail = new CMailFile('', '', '', ''); - $result=$mail->check_server_port($server, $port); + $mail = new CMailFile('', '', '', '', array(), array(), array(), '', '', 0, '', '', '', '', $trackid, $sendcontext); + + $result = $mail->check_server_port($server, $port); if ($result) print '
'.$langs->trans("ServerAvailableOnIPOrPort", $server, $port).'
'; else { diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 224a3a65cc9..2137fa76e04 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1002,6 +1002,7 @@ class Categorie extends CommonObject // phpcs:enable $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie"; $sql .= " WHERE fk_parent = ".$this->id; + $sql .= " AND entity IN (".getEntity('category').")"; $res = $this->db->query($sql); if ($res) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 5bd45655f69..3d6c28f7536 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6962,7 +6962,7 @@ abstract class CommonObject * This function is responsible to output the and according to correct number of columns received into $params['colspan'] * * @param Extrafields $extrafields Extrafield Object - * @param string $mode Show output (view) or input (edit) for extrafield + * @param string $mode Show output ('view') or input ('create' or 'edit') for extrafield * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan) * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names) * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names) @@ -7010,7 +7010,8 @@ abstract class CommonObject $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); } - if (($mode == 'create' || $mode == 'edit') && abs($visibility) != 1 && abs($visibility) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list + if (($mode == 'create') && abs($visibility) != 1 && abs($visibility) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list + elseif (($mode == 'edit') && abs($visibility) != 1 && abs($visibility) != 3 && abs($visibility) != 4) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list and <> 4 = not visible at the creation elseif ($mode == 'view' && empty($visibility)) continue; if (empty($perms)) continue; // Load language if required @@ -7038,9 +7039,10 @@ abstract class CommonObject case "view": $value = $this->array_options["options_".$key.$keysuffix]; break; - case "edit": - $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. - // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc') + case "create": + case "edit": + $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. + // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc') if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) { if (is_array($getposttemp)) { @@ -7144,7 +7146,8 @@ abstract class CommonObject case "view": $out .= $extrafields->showOutputField($key, $value); break; - case "edit": + case "create": + case "edit": $out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id, $this->table_element); break; } diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 20c723ba8a2..f688880b789 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1508,10 +1508,10 @@ class FormFile if (!empty($addfilterfields)) { print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; // Action column print ''; $searchpicto = $form->showFilterButtons(); diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index ecf137adb04..a48cf36c117 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -127,7 +127,7 @@ class FormTicket * @param int $withdolfichehead With dol_fiche_head * @return void */ - public function showForm($withdolfichehead = 0) + public function showForm($withdolfichehead = 0, $mode = 'edit') { global $conf, $langs, $user, $hookmanager; @@ -414,7 +414,7 @@ class FormTicket $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $ticketstat, $this->action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { - print $ticketstat->showOptionals($extrafields, 'edit'); + print $ticketstat->showOptionals($extrafields, 'create'); } print ''; diff --git a/htdocs/core/tpl/extrafields_add.tpl.php b/htdocs/core/tpl/extrafields_add.tpl.php index 45ca9a29197..53cbe3d99cf 100644 --- a/htdocs/core/tpl/extrafields_add.tpl.php +++ b/htdocs/core/tpl/extrafields_add.tpl.php @@ -45,7 +45,7 @@ if (empty($reshook)) { $params = array(); if (isset($tpl_context)) $params['tpl_context'] = $tpl_context; $params['cols'] = $parameters['colspanvalue']; - print $object->showOptionals($extrafields, 'edit', $params); // BUG #11554 : Add context in params + print $object->showOptionals($extrafields, 'create', $params); } ?> diff --git a/htdocs/core/tpl/extrafields_view.tpl.php b/htdocs/core/tpl/extrafields_view.tpl.php index 1ef3ef07255..e6cbad245d9 100644 --- a/htdocs/core/tpl/extrafields_view.tpl.php +++ b/htdocs/core/tpl/extrafields_view.tpl.php @@ -73,7 +73,7 @@ if (empty($reshook) && is_array($extrafields->attributes[$object->table_element] //print $key.'-'.$enabled.'-'.$perms.'-'.$label.$_POST["options_" . $key].'
'."\n"; if (empty($enabled)) continue; // 0 = Never visible field - if (abs($enabled) != 1 && abs($enabled) != 3 && abs($enabled) != 5) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list + if (abs($enabled) != 1 && abs($enabled) != 3 && abs($enabled) != 5 && abs($enabled) != 4) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list <> 4 = not visible at the creation if (empty($perms)) continue; // 0 = Not visible // Load language if required diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php index f621d332003..242ad38c077 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php @@ -98,10 +98,10 @@ class mod_myobject_advanced extends ModeleNumRefMyObject */ public function getExample() { - global $conf, $langs, $mysoc; + global $conf, $db, $langs, $mysoc; - $object = new MyObject($this->db); - $object->initAsSpecimen(); + $object = new MyObject($db); + $object->initAsSpecimen(); /*$old_code_client = $mysoc->code_client; $old_code_type = $mysoc->typent_code; diff --git a/htdocs/product/card.php b/htdocs/product/card.php index b2cab72a0a1..41b00fb85ef 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1280,7 +1280,13 @@ else // Accountancy_code_buy print ''.$langs->trans("ProductAccountancyBuyCode").''; print ''; - print $formaccounting->select_account(GETPOST('accountancy_code_buy', 'alpha'), 'accountancy_code_buy', 1, null, 1, 1, ''); + if($type == 0) + { + $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha')?(GETPOST('accountancy_code_buy', 'alpha')):$conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT); + } else { + $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha'); + } + print $formaccounting->select_account($accountancy_code_buy, 'accountancy_code_buy', 1, null, 1, 1, ''); print ''; // Accountancy_code_buy_intra diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 8ca8bd22bfe..d59581fa914 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -637,7 +637,7 @@ if ($action == 'create' || $action == 'presend') $defaultref = ''; } - $formticket->showForm(1); + $formticket->showForm(1, 'create'); } if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'presend' || $action == 'presend_addmessage' || $action == 'close' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'reopen' diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 384b3e864ba..4ea187c198c 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -1240,13 +1240,8 @@ if ($action == 'create' || $action == 'adduserldap') } // Other attributes - $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"'); - $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - if (empty($reshook)) - { - print $object->showOptionals($extrafields, 'edit'); - } + $parameters = array('colspan' => ' colspan="3"'); + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; // Note print ''; @@ -2512,74 +2507,6 @@ else } } - // // Skype - // if (! empty($conf->socialnetworks->enabled)) - // { - // print ''.$langs->trans("Skype").''; - // print ''; - // if ($caneditfield && empty($object->ldap_sid)) - // { - // print ''; - // } - // else - // { - // print ''; - // print $object->skype; - // } - // print ''; - // } - - // // Twitter - // if (! empty($conf->socialnetworks->enabled)) - // { - // print ''.$langs->trans("Twitter").''; - // print ''; - // if ($caneditfield && empty($object->ldap_sid)) - // { - // print ''; - // } - // else - // { - // print ''; - // print $object->twitter; - // } - // print ''; - // } - - // // Facebook - // if (! empty($conf->socialnetworks->enabled)) - // { - // print ''.$langs->trans("Facebook").''; - // print ''; - // if ($caneditfield && empty($object->ldap_sid)) - // { - // print ''; - // } - // else - // { - // print ''; - // print $object->facebook; - // } - // print ''; - // } - - // // LinkedIn - // if (! empty($conf->socialnetworks->enabled)) - // { - // print ''.$langs->trans("LinkedIn").''; - // print ''; - // if ($caneditfield && empty($object->ldap_sid)) - // { - // print ''; - // } - // else - // { - // print ''; - // print $object->linkedin; - // } - // print ''; - // } - // OpenID url if (isset($conf->file->main_authentication) && preg_match('/openid/', $conf->file->main_authentication) && !empty($conf->global->MAIN_OPENIDURL_PERUSER)) { @@ -2735,12 +2662,12 @@ else // Other attributes $parameters = array('colspan' => ' colspan="2"'); + //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php'; // We do not use common tpl here because we need a special test on $caneditfield $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; if (empty($reshook)) { - if ($caneditfield) - { + if ($caneditfield) { print $object->showOptionals($extrafields, 'edit'); } else { print $object->showOptionals($extrafields, 'view'); diff --git a/scripts/user/migrate_picture_path.php b/scripts/user/migrate_picture_path.php new file mode 100755 index 00000000000..f478c42b865 --- /dev/null +++ b/scripts/user/migrate_picture_path.php @@ -0,0 +1,129 @@ +#!/usr/bin/env php + + * Copyright (C) 2015 Jean Heimburger + * + * 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 . + */ + +/** + * \file scripts/product/migrate_picture_path.php + * \ingroup scripts + * \brief Migrate pictures from old system prior to 3.7 to new path for 3.7+ + */ +$sapi_type = php_sapi_name(); +$script_file = basename(__FILE__); +$path = __DIR__ . '/'; + +// Test if batch mode +if (substr($sapi_type, 0, 3) == 'cgi') { + echo "Error: You are using PHP for CGI. To execute " . $script_file . " from command line, you must use PHP for CLI mode.\n"; + exit(- 1); +} + +@set_time_limit(0); // No timeout for this script +define('EVEN_IF_ONLY_LOGIN_ALLOWED', 1); // Set this define to 0 if you want to lock your script when dolibarr setup is "locked to admin user only". + +// Include and load Dolibarr environment variables +require_once $path . "../../htdocs/master.inc.php"; +require_once DOL_DOCUMENT_ROOT . "/user/class/user.class.php"; +require_once DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php"; +// After this $db, $mysoc, $langs, $conf and $hookmanager are defined (Opened $db handler to database will be closed at end of file). +// $user is created but empty. + +// $langs->setDefaultLang('en_US'); // To change default language of $langs +$langs->load("main"); // To load language file for default language + +// Global variables +$version = DOL_VERSION; +$error = 0; +$forcecommit = 0; + +print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n"; +dol_syslog($script_file . " launched with arg " . join(',', $argv)); + +if (! isset($argv[1]) || $argv[1] != 'user') { + print "Usage: $script_file user\n"; + exit(- 1); +} + +print '--- start' . "\n"; + +// Case to migrate products path +if ($argv[1] == 'user') { + $u = new User($db); + + $sql = "SELECT rowid as uid from " . MAIN_DB_PREFIX . "user"; // Get list of all products + $resql = $db->query($sql); + if ($resql) { + while ($obj = $db->fetch_object($resql)) { + $u->fetch($obj->uid); + print " migrating user id=" . $u->id . " ref=" . $u->ref . "\n"; + migrate_user_filespath($u); + } + } else { + print "\n sql error " . $sql; + exit(); + } +} + +$db->close(); // Close $db database opened handler + +exit($error); + +/** + * Migrate file from old path to new one for user $u + * + * @param User $u Object user + * @return void + */ +function migrate_user_filespath($u) +{ + global $conf; + + // Les fichiers joints des users sont toujours sur l'entité 1 + $dir = $conf->user->dir_output; + $origin = $dir . '/' . get_exdir($u->id, 2, 0, 0, $u, 'user'); + $destin = $dir . '/' . $u->id; + + $error = 0; + + $origin_osencoded = dol_osencode($origin); + $destin_osencoded = dol_osencode($destin); + dol_mkdir($destin); + + if (dol_is_dir($origin)) { + + $handle = opendir($origin_osencoded); + if (is_resource($handle)) { + while (($file = readdir($handle)) !== false) { + if ($file != '.' && $file != '..' && is_dir($origin_osencoded . '/' . $file)) { + $thumbs = opendir($origin_osencoded . '/' . $file); + if (is_resource($thumbs)) { + dol_mkdir($destin . '/' . $file); + while (($thumb = readdir($thumbs)) !== false) { + dol_move($origin . '/' . $file . '/' . $thumb, $destin . '/' . $file . '/' . $thumb); + } + // dol_delete_dir($origin.'/'.$file); + } + } else { + if (dol_is_file($origin . '/' . $file)) { + dol_move($origin . '/' . $file, $destin . '/' . $file); + } + } + } + } + } +}