Scrutinizer Auto-Fixes

This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
This commit is contained in:
Scrutinizer Auto-Fixer 2019-11-13 17:32:11 +00:00
parent 7118dbbd1d
commit 87585c0f2a
12 changed files with 3564 additions and 3564 deletions

File diff suppressed because it is too large Load Diff

View File

@ -78,9 +78,9 @@ if ($action == 'add' && ! empty($permissiontoadd))
} }
} }
if (! $error) if (!$error)
{ {
$result=$object->create($user); $result = $object->create($user);
if ($result > 0) if ($result > 0)
{ {
// Creation OK // Creation OK
@ -92,40 +92,40 @@ if ($action == 'add' && ! empty($permissiontoadd))
else else
{ {
// Creation KO // Creation KO
if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
else setEventMessages($object->error, null, 'errors'); else setEventMessages($object->error, null, 'errors');
$action='create'; $action = 'create';
} }
} }
else else
{ {
$action='create'; $action = 'create';
} }
} }
// Action to update record // Action to update record
if ($action == 'update' && ! empty($permissiontoadd)) if ($action == 'update' && !empty($permissiontoadd))
{ {
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val)
{ {
if (! GETPOSTISSET($key)) continue; // The field was not submited to be edited if (!GETPOSTISSET($key)) continue; // The field was not submited to be edited
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields
// Set value to update // Set value to update
if (in_array($object->fields[$key]['type'], array('text', 'html'))) { if (in_array($object->fields[$key]['type'], array('text', 'html'))) {
$value = GETPOST($key, 'none'); $value = GETPOST($key, 'none');
} elseif ($object->fields[$key]['type']=='date') { } elseif ($object->fields[$key]['type'] == 'date') {
$value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); $value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year'));
} elseif ($object->fields[$key]['type']=='datetime') { } elseif ($object->fields[$key]['type'] == 'datetime') {
$value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); $value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year'));
} elseif (in_array($object->fields[$key]['type'], array('price', 'real'))) { } elseif (in_array($object->fields[$key]['type'], array('price', 'real'))) {
$value = price2num(GETPOST($key)); $value = price2num(GETPOST($key));
} else { } else {
$value = GETPOST($key, 'alpha'); $value = GETPOST($key, 'alpha');
} }
if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value=''; // This is an implicit foreign key field if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value = ''; // This is an implicit foreign key field
if (! empty($object->fields[$key]['foreignkey']) && $value == '-1') $value=''; // This is an explicit foreign key field if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') $value = ''; // This is an explicit foreign key field
$object->$key=$value; $object->$key = $value;
if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default'])) if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default']))
{ {
$error++; $error++;
@ -133,28 +133,28 @@ if ($action == 'update' && ! empty($permissiontoadd))
} }
} }
if (! $error) if (!$error)
{ {
$result=$object->update($user); $result = $object->update($user);
if ($result > 0) if ($result > 0)
{ {
$action='view'; $action = 'view';
} }
else else
{ {
// Creation KO // Creation KO
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$action='edit'; $action = 'edit';
} }
} }
else else
{ {
$action='edit'; $action = 'edit';
} }
} }
// Action to update one extrafield // Action to update one extrafield
if ($action == "update_extras" && ! empty($permissiontoadd)) if ($action == "update_extras" && !empty($permissiontoadd))
{ {
$object->fetch(GETPOST('id', 'int')); $object->fetch(GETPOST('id', 'int'));
@ -162,7 +162,7 @@ if ($action == "update_extras" && ! empty($permissiontoadd))
$attributekeylong = 'options_'.$attributekey; $attributekeylong = 'options_'.$attributekey;
$object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, ' alpha'); $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, ' alpha');
$result = $object->insertExtraFields(empty($triggermodname)?'':$triggermodname, $user); $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user);
if ($result > 0) if ($result > 0)
{ {
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
@ -176,15 +176,15 @@ if ($action == "update_extras" && ! empty($permissiontoadd))
} }
// Action to delete // Action to delete
if ($action == 'confirm_delete' && ! empty($permissiontodelete)) if ($action == 'confirm_delete' && !empty($permissiontodelete))
{ {
if (! ($object->id > 0)) if (!($object->id > 0))
{ {
dol_print_error('', 'Error, object must be fetched before being deleted'); dol_print_error('', 'Error, object must be fetched before being deleted');
exit; exit;
} }
$result=$object->delete($user); $result = $object->delete($user);
if ($result > 0) if ($result > 0)
{ {
// Delete OK // Delete OK
@ -194,13 +194,13 @@ if ($action == 'confirm_delete' && ! empty($permissiontodelete))
} }
else else
{ {
if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
else setEventMessages($object->error, null, 'errors'); else setEventMessages($object->error, null, 'errors');
} }
} }
// Remove a line // Remove a line
if ($action == 'confirm_deleteline' && $confirm == 'yes' && ! empty($permissiontoadd)) if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissiontoadd))
{ {
$result = $object->deleteline($user, $lineid); $result = $object->deleteline($user, $lineid);
if ($result > 0) if ($result > 0)
@ -216,7 +216,7 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && ! empty($permissiont
{ {
$newlang = $object->thirdparty->default_lang; $newlang = $object->thirdparty->default_lang;
} }
if (! empty($newlang)) { if (!empty($newlang)) {
$outputlangs = new Translate("", $conf); $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
} }
@ -248,11 +248,11 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd)
$newlang = ''; $newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) { if (!empty($newlang)) {
$outputlangs = new Translate("", $conf); $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
} }
$model=$object->modelpdf; $model = $object->modelpdf;
$ret = $object->fetch($id); // Reload to get new records $ret = $object->fetch($id); // Reload to get new records
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
@ -277,11 +277,11 @@ if ($action == 'confirm_close' && $confirm == 'yes' && $permissiontoadd)
$newlang = ''; $newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) { if (!empty($newlang)) {
$outputlangs = new Translate("", $conf); $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
} }
$model=$object->modelpdf; $model = $object->modelpdf;
$ret = $object->fetch($id); // Reload to get new records $ret = $object->fetch($id); // Reload to get new records
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
@ -320,11 +320,11 @@ if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd)
$newlang = ''; $newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) { if (!empty($newlang)) {
$outputlangs = new Translate("", $conf); $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
} }
$model=$object->modelpdf; $model = $object->modelpdf;
$ret = $object->fetch($id); // Reload to get new records $ret = $object->fetch($id); // Reload to get new records
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
@ -337,9 +337,9 @@ if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd)
} }
// Action clone object // Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && ! empty($permissiontoadd)) if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd))
{ {
if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers'))
{ {
setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
} }
@ -348,7 +348,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ! empty($permissiontoadd)
$objectutil = dol_clone($object, 1); // To avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object. We use native clone to keep this->db valid. $objectutil = dol_clone($object, 1); // To avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object. We use native clone to keep this->db valid.
//$objectutil->date = dol_mktime(12, 0, 0, GETPOST('newdatemonth', 'int'), GETPOST('newdateday', 'int'), GETPOST('newdateyear', 'int')); //$objectutil->date = dol_mktime(12, 0, 0, GETPOST('newdatemonth', 'int'), GETPOST('newdateday', 'int'), GETPOST('newdateyear', 'int'));
// ... // ...
$result=$objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id)); $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
if (is_object($result) || $result > 0) if (is_object($result) || $result > 0)
{ {
$newid = 0; $newid = 0;
@ -360,7 +360,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ! empty($permissiontoadd)
else else
{ {
setEventMessages($objectutil->error, $objectutil->errors, 'errors'); setEventMessages($objectutil->error, $objectutil->errors, 'errors');
$action=''; $action = '';
} }
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -35,15 +35,15 @@ $allowinstall = 0;
$allowupgrade = false; $allowupgrade = false;
$checksok = 1; $checksok = 1;
$setuplang=GETPOST("selectlang", 'aZ09', 3)?GETPOST("selectlang", 'aZ09', 3):$langs->getDefaultLang(); $setuplang = GETPOST("selectlang", 'aZ09', 3) ?GETPOST("selectlang", 'aZ09', 3) : $langs->getDefaultLang();
$langs->setDefaultLang($setuplang); $langs->setDefaultLang($setuplang);
$langs->load("install"); $langs->load("install");
// Now we load forced/pre-set values from install.forced.php file. // Now we load forced/pre-set values from install.forced.php file.
$useforcedwizard=false; $useforcedwizard = false;
$forcedfile="./install.forced.php"; $forcedfile = "./install.forced.php";
if ($conffile == "/etc/dolibarr/conf.php") $forcedfile="/etc/dolibarr/install.forced.php"; if ($conffile == "/etc/dolibarr/conf.php") $forcedfile = "/etc/dolibarr/install.forced.php";
if (@file_exists($forcedfile)) { if (@file_exists($forcedfile)) {
$useforcedwizard = true; $useforcedwizard = true;
include_once $forcedfile; include_once $forcedfile;
@ -65,28 +65,28 @@ pHeader('', ''); // No next step for navigation buttons. Next step is define
print '<h3><img class="valigntextbottom" src="../theme/common/octicons/build/svg/gear.svg" width="20" alt="Database"> '.$langs->trans("MiscellaneousChecks").":</h3>\n"; print '<h3><img class="valigntextbottom" src="../theme/common/octicons/build/svg/gear.svg" width="20" alt="Database"> '.$langs->trans("MiscellaneousChecks").":</h3>\n";
// Check browser // Check browser
$useragent=$_SERVER['HTTP_USER_AGENT']; $useragent = $_SERVER['HTTP_USER_AGENT'];
if (! empty($useragent)) if (!empty($useragent))
{ {
$tmp=getBrowserInfo($_SERVER["HTTP_USER_AGENT"]); $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
$browserversion=$tmp['browserversion']; $browserversion = $tmp['browserversion'];
$browsername=$tmp['browsername']; $browsername = $tmp['browsername'];
if ($browsername == 'ie' && $browserversion < 7) print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("WarningBrowserTooOld")."<br>\n"; if ($browsername == 'ie' && $browserversion < 7) print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("WarningBrowserTooOld")."<br>\n";
} }
// Check PHP version // Check PHP version
$arrayphpminversionerror = array(5,5,0); $arrayphpminversionerror = array(5, 5, 0);
$arrayphpminversionwarning = array(5,5,0); $arrayphpminversionwarning = array(5, 5, 0);
if (versioncompare(versionphparray(), $arrayphpminversionerror) < 0) // Minimum to use (error if lower) if (versioncompare(versionphparray(), $arrayphpminversionerror) < 0) // Minimum to use (error if lower)
{ {
print '<img src="../theme/eldy/img/error.png" alt="Error"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionerror)); print '<img src="../theme/eldy/img/error.png" alt="Error"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionerror));
$checksok=0; // 0=error, 1=warning $checksok = 0; // 0=error, 1=warning
} }
elseif (versioncompare(versionphparray(), $arrayphpminversionwarning) < 0) // Minimum supported (warning if lower) elseif (versioncompare(versionphparray(), $arrayphpminversionwarning) < 0) // Minimum supported (warning if lower)
{ {
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionwarning)); print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionwarning));
$checksok=0; // 0=error, 1=warning $checksok = 0; // 0=error, 1=warning
} }
else else
{ {
@ -97,12 +97,12 @@ print "<br>\n";
// Check PHP support for $_POST // Check PHP support for $_POST
if (! isset($_GET["testget"]) && ! isset($_POST["testpost"])) if (!isset($_GET["testget"]) && !isset($_POST["testpost"]))
{ {
print '<img src="../theme/eldy/img/warning.png" alt="Warning"> '.$langs->trans("PHPSupportPOSTGETKo"); print '<img src="../theme/eldy/img/warning.png" alt="Warning"> '.$langs->trans("PHPSupportPOSTGETKo");
print ' (<a href="'.$_SERVER["PHP_SELF"].'?testget=ok">'.$langs->trans("Recheck").'</a>)'; print ' (<a href="'.$_SERVER["PHP_SELF"].'?testget=ok">'.$langs->trans("Recheck").'</a>)';
print "<br>\n"; print "<br>\n";
$checksok=0; $checksok = 0;
} }
else else
{ {
@ -111,10 +111,10 @@ else
// Check if sessions enabled // Check if sessions enabled
if (! function_exists("session_id")) if (!function_exists("session_id"))
{ {
print '<img src="../theme/eldy/img/error.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportSessions")."<br>\n"; print '<img src="../theme/eldy/img/error.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportSessions")."<br>\n";
$checksok=0; $checksok = 0;
} }
else else
{ {
@ -123,7 +123,7 @@ else
// Check if GD supported (we need GD for image conversion) // Check if GD supported (we need GD for image conversion)
if (! function_exists("imagecreate")) if (!function_exists("imagecreate"))
{ {
$langs->load("errors"); $langs->load("errors");
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportGD")."<br>\n"; print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportGD")."<br>\n";
@ -136,7 +136,7 @@ else
// Check if Curl supported // Check if Curl supported
if (! function_exists("curl_init")) if (!function_exists("curl_init"))
{ {
$langs->load("errors"); $langs->load("errors");
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportCurl")."<br>\n"; print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportCurl")."<br>\n";
@ -148,7 +148,7 @@ else
} }
// Check if PHP calendar extension is available // Check if PHP calendar extension is available
if (! function_exists("easter_date")) if (!function_exists("easter_date"))
{ {
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportCalendar")."<br>\n"; print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportCalendar")."<br>\n";
} }
@ -159,7 +159,7 @@ else
// Check if UTF8 supported // Check if UTF8 supported
if (! function_exists("utf8_encode")) if (!function_exists("utf8_encode"))
{ {
$langs->load("errors"); $langs->load("errors");
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportUTF8")."<br>\n"; print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportUTF8")."<br>\n";
@ -174,7 +174,7 @@ else
// Check if intl methods are supported // Check if intl methods are supported
if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost') if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost')
{ {
if (! function_exists("locale_get_primary_language") || ! function_exists("locale_get_region")) if (!function_exists("locale_get_primary_language") || !function_exists("locale_get_region"))
{ {
$langs->load("errors"); $langs->load("errors");
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportIntl")."<br>\n"; print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportIntl")."<br>\n";
@ -188,18 +188,18 @@ if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@loc
// Check memory // Check memory
$memrequiredorig='64M'; $memrequiredorig = '64M';
$memrequired=64*1024*1024; $memrequired = 64 * 1024 * 1024;
$memmaxorig=@ini_get("memory_limit"); $memmaxorig = @ini_get("memory_limit");
$memmax=@ini_get("memory_limit"); $memmax = @ini_get("memory_limit");
if ($memmaxorig != '') if ($memmaxorig != '')
{ {
preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg); preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg);
if ($reg[2]) if ($reg[2])
{ {
if (strtoupper($reg[2]) == 'G') $memmax=$reg[1]*1024*1024*1024; if (strtoupper($reg[2]) == 'G') $memmax = $reg[1] * 1024 * 1024 * 1024;
if (strtoupper($reg[2]) == 'M') $memmax=$reg[1]*1024*1024; if (strtoupper($reg[2]) == 'M') $memmax = $reg[1] * 1024 * 1024;
if (strtoupper($reg[2]) == 'K') $memmax=$reg[1]*1024; if (strtoupper($reg[2]) == 'K') $memmax = $reg[1] * 1024;
} }
if ($memmax >= $memrequired || $memmax == -1) if ($memmax >= $memrequired || $memmax == -1)
{ {
@ -216,37 +216,37 @@ if ($memmaxorig != '')
clearstatcache(); clearstatcache();
if (is_readable($conffile) && filesize($conffile) > 8) if (is_readable($conffile) && filesize($conffile) > 8)
{ {
dolibarr_install_syslog("check: conf file '" . $conffile . "' already defined"); dolibarr_install_syslog("check: conf file '".$conffile."' already defined");
$confexists=1; $confexists = 1;
include_once $conffile; include_once $conffile;
$databaseok=1; $databaseok = 1;
if ($databaseok) if ($databaseok)
{ {
// Already installed for all parts (config and database). We can propose upgrade. // Already installed for all parts (config and database). We can propose upgrade.
$allowupgrade=true; $allowupgrade = true;
} }
else else
{ {
$allowupgrade=false; $allowupgrade = false;
} }
} }
else else
{ {
// If not, we create it // If not, we create it
dolibarr_install_syslog("check: we try to create conf file '" . $conffile . "'"); dolibarr_install_syslog("check: we try to create conf file '".$conffile."'");
$confexists=0; $confexists = 0;
// First we try by copying example // First we try by copying example
if (@copy($conffile.".example", $conffile)) if (@copy($conffile.".example", $conffile))
{ {
// Success // Success
dolibarr_install_syslog("check: successfully copied file " . $conffile . ".example into " . $conffile); dolibarr_install_syslog("check: successfully copied file ".$conffile.".example into ".$conffile);
} }
else else
{ {
// If failed, we try to create an empty file // If failed, we try to create an empty file
dolibarr_install_syslog("check: failed to copy file " . $conffile . ".example into " . $conffile . ". We try to create it.", LOG_WARNING); dolibarr_install_syslog("check: failed to copy file ".$conffile.".example into ".$conffile.". We try to create it.", LOG_WARNING);
$fp = @fopen($conffile, "w"); $fp = @fopen($conffile, "w");
if ($fp) if ($fp)
@ -255,17 +255,17 @@ else
@fputs($fp, "\n"); @fputs($fp, "\n");
fclose($fp); fclose($fp);
} }
else dolibarr_install_syslog("check: failed to create a new file " . $conffile . " into current dir " . getcwd() . ". Please check permissions.", LOG_ERR); else dolibarr_install_syslog("check: failed to create a new file ".$conffile." into current dir ".getcwd().". Please check permissions.", LOG_ERR);
} }
// First install: no upgrade necessary/required // First install: no upgrade necessary/required
$allowupgrade=false; $allowupgrade = false;
} }
// File is missing and cannot be created // File is missing and cannot be created
if (! file_exists($conffile)) if (!file_exists($conffile))
{ {
print '<img src="../theme/eldy/img/error.png" alt="Error"> '.$langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated", $conffiletoshow); print '<img src="../theme/eldy/img/error.png" alt="Error"> '.$langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated", $conffiletoshow);
print "<br><br>"; print "<br><br>";
@ -281,7 +281,7 @@ else
{ {
print '<img src="../theme/eldy/img/error.png" alt="Warning"> '.$langs->trans("ConfFileMustBeAFileNotADir", $conffiletoshow); print '<img src="../theme/eldy/img/error.png" alt="Warning"> '.$langs->trans("ConfFileMustBeAFileNotADir", $conffiletoshow);
$allowinstall=0; $allowinstall = 0;
} }
// File exists but cannot be modified // File exists but cannot be modified
elseif (!is_writable($conffile)) elseif (!is_writable($conffile))
@ -298,7 +298,7 @@ else
print '<img src="../theme/eldy/img/tick.png" alt="Warning"> '.$langs->trans("ConfFileIsNotWritable", $conffiletoshow); print '<img src="../theme/eldy/img/tick.png" alt="Warning"> '.$langs->trans("ConfFileIsNotWritable", $conffiletoshow);
print "<br>\n"; print "<br>\n";
$allowinstall=0; $allowinstall = 0;
} }
// File exists and can be modified // File exists and can be modified
else else
@ -315,32 +315,32 @@ else
print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileIsWritable", $conffiletoshow); print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileIsWritable", $conffiletoshow);
print "<br>\n"; print "<br>\n";
$allowinstall=1; $allowinstall = 1;
} }
print "<br>\n"; print "<br>\n";
// Requirements met/all ok: display the next step button // Requirements met/all ok: display the next step button
if ($checksok) if ($checksok)
{ {
$ok=0; $ok = 0;
// Try to create db connection // Try to create db connection
if (file_exists($conffile)) if (file_exists($conffile))
{ {
include_once $conffile; include_once $conffile;
if (! empty($dolibarr_main_db_type) && ! empty($dolibarr_main_document_root)) if (!empty($dolibarr_main_db_type) && !empty($dolibarr_main_document_root))
{ {
if (! file_exists($dolibarr_main_document_root."/core/lib/admin.lib.php")) if (!file_exists($dolibarr_main_document_root."/core/lib/admin.lib.php"))
{ {
print '<span class="error">A '.$conffiletoshow.' file exists with a dolibarr_main_document_root to '.$dolibarr_main_document_root.' that seems wrong. Try to fix or remove the '.$conffiletoshow.' file.</span><br>'."\n"; print '<span class="error">A '.$conffiletoshow.' file exists with a dolibarr_main_document_root to '.$dolibarr_main_document_root.' that seems wrong. Try to fix or remove the '.$conffiletoshow.' file.</span><br>'."\n";
dol_syslog("A '" . $conffiletoshow . "' file exists with a dolibarr_main_document_root to " . $dolibarr_main_document_root . " that seems wrong. Try to fix or remove the '" . $conffiletoshow . "' file.", LOG_WARNING); dol_syslog("A '".$conffiletoshow."' file exists with a dolibarr_main_document_root to ".$dolibarr_main_document_root." that seems wrong. Try to fix or remove the '".$conffiletoshow."' file.", LOG_WARNING);
} }
else else
{ {
require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php'; require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
// If password is encoded, we decode it // If password is encoded, we decode it
if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || ! empty($dolibarr_main_db_encrypted_pass)) if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass))
{ {
require_once $dolibarr_main_document_root.'/core/lib/security.lib.php'; require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) if (preg_match('/crypted:/i', $dolibarr_main_db_pass))
@ -358,10 +358,10 @@ else
$conf->db->name = $dolibarr_main_db_name; $conf->db->name = $dolibarr_main_db_name;
$conf->db->user = $dolibarr_main_db_user; $conf->db->user = $dolibarr_main_db_user;
$conf->db->pass = $dolibarr_main_db_pass; $conf->db->pass = $dolibarr_main_db_pass;
$db=getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port); $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
if ($db->connected && $db->database_selected) if ($db->connected && $db->database_selected)
{ {
$ok=true; $ok = true;
} }
} }
} }
@ -370,26 +370,26 @@ else
// If database access is available, we set more variables // If database access is available, we set more variables
if ($ok) if ($ok)
{ {
if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption=0; if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption = 0;
$conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption; $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey=''; if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey = '';
$conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey; $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
$conf->setValues($db); $conf->setValues($db);
// Reset forced setup after the setValues // Reset forced setup after the setValues
if (defined('SYSLOG_FILE')) $conf->global->SYSLOG_FILE=constant('SYSLOG_FILE'); if (defined('SYSLOG_FILE')) $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1; $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
// Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
// Version to install is DOL_VERSION // Version to install is DOL_VERSION
$dolibarrlastupgradeversionarray=preg_split('/[\.-]/', isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL)?$conf->global->MAIN_VERSION_LAST_INSTALL:'')); $dolibarrlastupgradeversionarray = preg_split('/[\.-]/', isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL) ? $conf->global->MAIN_VERSION_LAST_INSTALL : ''));
$dolibarrversiontoinstallarray=versiondolibarrarray(); $dolibarrversiontoinstallarray = versiondolibarrarray();
} }
// Show title // Show title
if (! empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ! empty($conf->global->MAIN_VERSION_LAST_INSTALL)) if (!empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || !empty($conf->global->MAIN_VERSION_LAST_INSTALL))
{ {
print $langs->trans("VersionLastUpgrade").': <b><span class="ok">'.(empty($conf->global->MAIN_VERSION_LAST_UPGRADE)?$conf->global->MAIN_VERSION_LAST_INSTALL:$conf->global->MAIN_VERSION_LAST_UPGRADE).'</span></b> - '; print $langs->trans("VersionLastUpgrade").': <b><span class="ok">'.(empty($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_INSTALL : $conf->global->MAIN_VERSION_LAST_UPGRADE).'</span></b> - ';
print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b>'; print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b>';
//print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired")); //print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired"));
print '<br>'; print '<br>';
@ -400,7 +400,7 @@ else
//print $langs->trans("InstallEasy")." "; //print $langs->trans("InstallEasy")." ";
print '<h3><span class="soustitre">'.$langs->trans("ChooseYourSetupMode").'</span></h3>'; print '<h3><span class="soustitre">'.$langs->trans("ChooseYourSetupMode").'</span></h3>';
$foundrecommandedchoice=0; $foundrecommandedchoice = 0;
$available_choices = array(); $available_choices = array();
$notavailable_choices = array(); $notavailable_choices = array();
@ -417,7 +417,7 @@ else
//print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE); //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
$choice .= '<div class="center"><div class="ok">'.$langs->trans("InstallChoiceSuggested").'</div></div>'; $choice .= '<div class="center"><div class="ok">'.$langs->trans("InstallChoiceSuggested").'</div></div>';
// <img src="../theme/eldy/img/tick.png" alt="Ok"> '; // <img src="../theme/eldy/img/tick.png" alt="Ok"> ';
$foundrecommandedchoice=1; // To show only once $foundrecommandedchoice = 1; // To show only once
} }
$choice .= '</td>'; $choice .= '</td>';
@ -441,14 +441,14 @@ else
} }
// Show upgrade lines // Show upgrade lines
$allowupgrade=true; $allowupgrade = true;
if (empty($dolibarr_main_db_host)) // This means install process was not run if (empty($dolibarr_main_db_host)) // This means install process was not run
{ {
$allowupgrade=false; $allowupgrade = false;
} }
if (defined("MAIN_NOT_INSTALLED")) $allowupgrade=false; if (defined("MAIN_NOT_INSTALLED")) $allowupgrade = false;
if (GETPOST('allowupgrade')) $allowupgrade=true; if (GETPOST('allowupgrade')) $allowupgrade = true;
$migrationscript=array( array('from'=>'3.0.0', 'to'=>'3.1.0'), $migrationscript = array(array('from'=>'3.0.0', 'to'=>'3.1.0'),
array('from'=>'3.1.0', 'to'=>'3.2.0'), array('from'=>'3.1.0', 'to'=>'3.2.0'),
array('from'=>'3.2.0', 'to'=>'3.3.0'), array('from'=>'3.2.0', 'to'=>'3.3.0'),
array('from'=>'3.3.0', 'to'=>'3.4.0'), array('from'=>'3.3.0', 'to'=>'3.4.0'),
@ -467,26 +467,26 @@ else
array('from'=>'10.0.0', 'to'=>'11.0.0') array('from'=>'10.0.0', 'to'=>'11.0.0')
); );
$count=0; $count = 0;
foreach ($migrationscript as $migarray) foreach ($migrationscript as $migarray)
{ {
$choice = ''; $choice = '';
$count++; $count++;
$recommended_choice = false; $recommended_choice = false;
$version=DOL_VERSION; $version = DOL_VERSION;
$versionfrom=$migarray['from']; $versionfrom = $migarray['from'];
$versionto=$migarray['to']; $versionto = $migarray['to'];
$versionarray=preg_split('/[\.-]/', $version); $versionarray = preg_split('/[\.-]/', $version);
$dolibarrversionfromarray=preg_split('/[\.-]/', $versionfrom); $dolibarrversionfromarray = preg_split('/[\.-]/', $versionfrom);
$dolibarrversiontoarray=preg_split('/[\.-]/', $versionto); $dolibarrversiontoarray = preg_split('/[\.-]/', $versionto);
// Define string newversionxxx that are used for text to show // Define string newversionxxx that are used for text to show
$newversionfrom=preg_replace('/(\.[0-9]+)$/i', '.*', $versionfrom); $newversionfrom = preg_replace('/(\.[0-9]+)$/i', '.*', $versionfrom);
$newversionto=preg_replace('/(\.[0-9]+)$/i', '.*', $versionto); $newversionto = preg_replace('/(\.[0-9]+)$/i', '.*', $versionto);
$newversionfrombis=''; $newversionfrombis = '';
if (versioncompare($dolibarrversiontoarray, $versionarray) < -2) // From x.y.z -> x.y.z+1 if (versioncompare($dolibarrversiontoarray, $versionarray) < -2) // From x.y.z -> x.y.z+1
{ {
$newversionfrombis=' '.$langs->trans("or").' '.$versionto; $newversionfrombis = ' '.$langs->trans("or").' '.$versionto;
} }
if ($ok) if ($ok)
@ -498,7 +498,7 @@ else
(versioncompare($dolibarrversiontoarray, $dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray, $versionarray) < -2) (versioncompare($dolibarrversiontoarray, $dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray, $versionarray) < -2)
) )
{ {
$foundrecommandedchoice=1; // To show only once $foundrecommandedchoice = 1; // To show only once
$recommended_choice = true; $recommended_choice = true;
} }
} }
@ -531,10 +531,10 @@ else
$choice .= '<td class="center">'; $choice .= '<td class="center">';
if ($allowupgrade) if ($allowupgrade)
{ {
$disabled=false; $disabled = false;
if ($foundrecommandedchoice == 2) if ($foundrecommandedchoice == 2)
{ {
$disabled=true; $disabled = true;
} }
if ($foundrecommandedchoice == 1) if ($foundrecommandedchoice == 1)
{ {
@ -546,7 +546,7 @@ else
} }
else else
{ {
$choice .= '<a class="button runupgrade" href="upgrade.php?action=upgrade'.($count<count($migrationscript)?'_'.$versionto:'').'&amp;selectlang='.$setuplang.'&amp;versionfrom='.$versionfrom.'&amp;versionto='.$versionto.'">'.$langs->trans("Start").'</a>'; $choice .= '<a class="button runupgrade" href="upgrade.php?action=upgrade'.($count < count($migrationscript) ? '_'.$versionto : '').'&amp;selectlang='.$setuplang.'&amp;versionfrom='.$versionfrom.'&amp;versionto='.$versionto.'">'.$langs->trans("Start").'</a>';
} }
} }
else else
@ -566,8 +566,8 @@ else
// If there is no choice at all, we show all of them. // If there is no choice at all, we show all of them.
if (empty($available_choices)) if (empty($available_choices))
{ {
$available_choices=$notavailable_choices; $available_choices = $notavailable_choices;
$notavailable_choices=array(); $notavailable_choices = array();
} }
// Array of install choices // Array of install choices

View File

@ -23,7 +23,7 @@
*/ */
// Put here all includes required by your class file // Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
@ -89,7 +89,7 @@ class MyObject extends CommonObject
/** /**
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
*/ */
public $fields=array( public $fields = array(
'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'noteditable'=>1, 'notnull'=> 1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'noteditable'=>1, 'notnull'=> 1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
'ref' =>array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'noteditable'=>0, 'default'=>'', 'notnull'=> 1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), 'ref' =>array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'noteditable'=>0, 'default'=>'', 'notnull'=> 1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>20), 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>20),
@ -214,11 +214,11 @@ class MyObject extends CommonObject
$this->db = $db; $this->db = $db;
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0; if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0;
if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0; if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0;
// Unset fields that are disabled // Unset fields that are disabled
foreach($this->fields as $key => $val) foreach ($this->fields as $key => $val)
{ {
if (isset($val['enabled']) && empty($val['enabled'])) if (isset($val['enabled']) && empty($val['enabled']))
{ {
@ -274,7 +274,7 @@ class MyObject extends CommonObject
// Load source object // Load source object
$result = $object->fetchCommon($fromid); $result = $object->fetchCommon($fromid);
if ($result > 0 && ! empty($object->table_element_line)) $object->fetchLines(); if ($result > 0 && !empty($object->table_element_line)) $object->fetchLines();
// get lines so they will be clone // get lines so they will be clone
//foreach($this->lines as $line) //foreach($this->lines as $line)
@ -287,18 +287,18 @@ class MyObject extends CommonObject
// Clear fields // Clear fields
$object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref: $this->fields['ref']['default']; $object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref : $this->fields['ref']['default'];
$object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label: $this->fields['label']['default']; $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
$object->status = self::STATUS_DRAFT; $object->status = self::STATUS_DRAFT;
// ... // ...
// Clear extrafields that are unique // Clear extrafields that are unique
if (is_array($object->array_options) && count($object->array_options) > 0) if (is_array($object->array_options) && count($object->array_options) > 0)
{ {
$extrafields->fetch_name_optionals_label($this->table_element); $extrafields->fetch_name_optionals_label($this->table_element);
foreach($object->array_options as $key => $option) foreach ($object->array_options as $key => $option)
{ {
$shortkey = preg_replace('/options_/', '', $key); $shortkey = preg_replace('/options_/', '', $key);
if (! empty($extrafields->attributes[$this->element]['unique'][$shortkey])) if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey]))
{ {
//var_dump($key); var_dump($clonedObj->array_options[$key]); exit; //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
unset($object->array_options[$key]); unset($object->array_options[$key]);
@ -315,7 +315,7 @@ class MyObject extends CommonObject
$this->errors = $object->errors; $this->errors = $object->errors;
} }
if (! $error) if (!$error)
{ {
// copy internal contacts // copy internal contacts
if ($this->copy_linked_contact($object, 'internal') < 0) if ($this->copy_linked_contact($object, 'internal') < 0)
@ -324,7 +324,7 @@ class MyObject extends CommonObject
} }
} }
if (! $error) if (!$error)
{ {
// copy external contacts if same company // copy external contacts if same company
if (property_exists($this, 'socid') && $this->socid == $object->socid) if (property_exists($this, 'socid') && $this->socid == $object->socid)
@ -356,7 +356,7 @@ class MyObject extends CommonObject
public function fetch($id, $ref = null) public function fetch($id, $ref = null)
{ {
$result = $this->fetchCommon($id, $ref); $result = $this->fetchCommon($id, $ref);
if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines(); if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
return $result; return $result;
} }
@ -367,7 +367,7 @@ class MyObject extends CommonObject
*/ */
public function fetchLines() public function fetchLines()
{ {
$this->lines=array(); $this->lines = array();
$result = $this->fetchLinesCommon(); $result = $this->fetchLinesCommon();
return $result; return $result;
@ -391,40 +391,40 @@ class MyObject extends CommonObject
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
$records=array(); $records = array();
$sql = 'SELECT '; $sql = 'SELECT ';
$sql .= $this->getFieldList(); $sql .= $this->getFieldList();
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')'; if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
else $sql .= ' WHERE 1 = 1'; else $sql .= ' WHERE 1 = 1';
// Manage filter // Manage filter
$sqlwhere = array(); $sqlwhere = array();
if (count($filter) > 0) { if (count($filter) > 0) {
foreach ($filter as $key => $value) { foreach ($filter as $key => $value) {
if ($key=='t.rowid') { if ($key == 't.rowid') {
$sqlwhere[] = $key . '='. $value; $sqlwhere[] = $key.'='.$value;
} }
elseif (strpos($key, 'date') !== false) { elseif (strpos($key, 'date') !== false) {
$sqlwhere[] = $key.' = \''.$this->db->idate($value).'\''; $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
} }
elseif ($key=='customsql') { elseif ($key == 'customsql') {
$sqlwhere[] = $value; $sqlwhere[] = $value;
} }
else { else {
$sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
} }
} }
} }
if (count($sqlwhere) > 0) { if (count($sqlwhere) > 0) {
$sql .= ' AND (' . implode(' '.$filtermode.' ', $sqlwhere).')'; $sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')';
} }
if (!empty($sortfield)) { if (!empty($sortfield)) {
$sql .= $this->db->order($sortfield, $sortorder); $sql .= $this->db->order($sortfield, $sortorder);
} }
if (!empty($limit)) { if (!empty($limit)) {
$sql .= ' ' . $this->db->plimit($limit, $offset); $sql .= ' '.$this->db->plimit($limit, $offset);
} }
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -446,8 +446,8 @@ class MyObject extends CommonObject
return $records; return $records;
} else { } else {
$this->errors[] = 'Error ' . $this->db->lasterror(); $this->errors[] = 'Error '.$this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
return -1; return -1;
} }
@ -587,51 +587,51 @@ class MyObject extends CommonObject
{ {
global $conf, $langs, $hookmanager; global $conf, $langs, $hookmanager;
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
$result = ''; $result = '';
$label = '<u>' . $langs->trans("MyObject") . '</u>'; $label = '<u>'.$langs->trans("MyObject").'</u>';
$label.= '<br>'; $label .= '<br>';
$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref; $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
$url = dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$this->id; $url = dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$this->id;
if ($option != 'nolink') if ($option != 'nolink')
{ {
// Add param to save lastsearch_values or not // Add param to save lastsearch_values or not
$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
} }
$linkclose=''; $linkclose = '';
if (empty($notooltip)) if (empty($notooltip))
{ {
if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{ {
$label=$langs->trans("ShowMyObject"); $label = $langs->trans("ShowMyObject");
$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
} }
$linkclose.=' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"'; $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
} }
else $linkclose = ($morecss?' class="'.$morecss.'"':''); else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
$linkstart = '<a href="'.$url.'"'; $linkstart = '<a href="'.$url.'"';
$linkstart.=$linkclose.'>'; $linkstart .= $linkclose.'>';
$linkend='</a>'; $linkend = '</a>';
$result .= $linkstart; $result .= $linkstart;
if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1); if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result.= $this->ref; if ($withpicto != 2) $result .= $this->ref;
$result .= $linkend; $result .= $linkend;
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
global $action,$hookmanager; global $action, $hookmanager;
$hookmanager->initHooks(array('myobjectdao')); $hookmanager->initHooks(array('myobjectdao'));
$parameters=array('id'=>$this->id, 'getnomurl'=>$result); $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
$reshook=$hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) $result = $hookmanager->resPrint; if ($reshook > 0) $result = $hookmanager->resPrint;
else $result .= $hookmanager->resPrint; else $result .= $hookmanager->resPrint;
@ -687,10 +687,10 @@ class MyObject extends CommonObject
public function info($id) public function info($id)
{ {
$sql = 'SELECT rowid, date_creation as datec, tms as datem,'; $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
$sql.= ' fk_user_creat, fk_user_modif'; $sql .= ' fk_user_creat, fk_user_modif';
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql.= ' WHERE t.rowid = '.$id; $sql .= ' WHERE t.rowid = '.$id;
$result=$this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
if ($this->db->num_rows($result)) if ($this->db->num_rows($result))
@ -749,7 +749,7 @@ class MyObject extends CommonObject
*/ */
public function getLinesArray() public function getLinesArray()
{ {
$this->lines=array(); $this->lines = array();
$objectline = new MyObjectLine($this->db); $objectline = new MyObjectLine($this->db);
$result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_myobject = '.$this->id)); $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_myobject = '.$this->id));
@ -780,16 +780,16 @@ class MyObject extends CommonObject
*/ */
public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
{ {
global $conf,$langs; global $conf, $langs;
$langs->load("mymodule@mymodule"); $langs->load("mymodule@mymodule");
if (! dol_strlen($modele)) { if (!dol_strlen($modele)) {
$modele = 'standard'; $modele = 'standard';
if ($this->modelpdf) { if ($this->modelpdf) {
$modele = $this->modelpdf; $modele = $this->modelpdf;
} elseif (! empty($conf->global->MYOBJECT_ADDON_PDF)) { } elseif (!empty($conf->global->MYOBJECT_ADDON_PDF)) {
$modele = $conf->global->MYOBJECT_ADDON_PDF; $modele = $conf->global->MYOBJECT_ADDON_PDF;
} }
} }
@ -814,7 +814,7 @@ class MyObject extends CommonObject
$error = 0; $error = 0;
$this->output = ''; $this->output = '';
$this->error=''; $this->error = '';
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);

View File

@ -42,14 +42,14 @@ $batch = GETPOST('batch', 'alpha');
$productid = GETPOST('productid', 'int'); $productid = GETPOST('productid', 'int');
$ref = GETPOST('ref', 'alpha'); // ref is productid_batch $ref = GETPOST('ref', 'alpha'); // ref is productid_batch
$search_entity=GETPOST('search_entity', 'int'); $search_entity = GETPOST('search_entity', 'int');
$search_fk_product=GETPOST('search_fk_product', 'int'); $search_fk_product = GETPOST('search_fk_product', 'int');
$search_batch=GETPOST('search_batch', 'alpha'); $search_batch = GETPOST('search_batch', 'alpha');
$search_fk_user_creat=GETPOST('search_fk_user_creat', 'int'); $search_fk_user_creat = GETPOST('search_fk_user_creat', 'int');
$search_fk_user_modif=GETPOST('search_fk_user_modif', 'int'); $search_fk_user_modif = GETPOST('search_fk_user_modif', 'int');
$search_import_key=GETPOST('search_import_key', 'int'); $search_import_key = GETPOST('search_import_key', 'int');
if (empty($action) && empty($id) && empty($ref)) $action='list'; if (empty($action) && empty($id) && empty($ref)) $action = 'list';
// Protection if external user // Protection if external user
@ -73,16 +73,16 @@ if ($id || $ref)
{ {
if ($ref) if ($ref)
{ {
$tmp=explode('_', $ref); $tmp = explode('_', $ref);
$productid=$tmp[0]; $productid = $tmp[0];
$batch=$tmp[1]; $batch = $tmp[1];
} }
$object->fetch($id, $productid, $batch); $object->fetch($id, $productid, $batch);
$object->ref = $object->batch; // For document management ( it use $object->ref) $object->ref = $object->batch; // For document management ( it use $object->ref)
} }
// Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array // Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('productlotcard','globalcard')); $hookmanager->initHooks(array('productlotcard', 'globalcard'));
$permissionnote = $user->rights->stock->creer; // Used by the include of actions_setnotes.inc.php $permissionnote = $user->rights->stock->creer; // Used by the include of actions_setnotes.inc.php
@ -97,8 +97,8 @@ $usercandelete = $user->rights->produit->supprimer;
* Actions * Actions
*/ */
$parameters=array(); $parameters = array();
$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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'); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) if (empty($reshook))
@ -112,7 +112,7 @@ if (empty($reshook))
if ($action == 'setsellby' && $user->rights->stock->creer) if ($action == 'setsellby' && $user->rights->stock->creer)
{ {
$newvalue=dol_mktime(12, 0, 0, $_POST['sellbymonth'], $_POST['sellbyday'], $_POST['sellbyyear']); $newvalue = dol_mktime(12, 0, 0, $_POST['sellbymonth'], $_POST['sellbyday'], $_POST['sellbyyear']);
$result = $object->setValueFrom('sellby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); $result = $object->setValueFrom('sellby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY');
if ($result < 0) dol_print_error($db, $object->error); if ($result < 0) dol_print_error($db, $object->error);
} }
@ -125,7 +125,7 @@ if (empty($reshook))
$ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none'));
if ($ret < 0) $error++; if ($ret < 0) $error++;
if (! $error) if (!$error)
{ {
// Actions on extra fields // Actions on extra fields
$result = $object->insertExtraFields('PRODUCT_LOT_MODIFY'); $result = $object->insertExtraFields('PRODUCT_LOT_MODIFY');
@ -145,21 +145,21 @@ if (empty($reshook))
{ {
if (GETPOST('cancel', 'alpha')) if (GETPOST('cancel', 'alpha'))
{ {
$urltogo=$backtopage?$backtopage:dol_buildpath('/stock/list.php', 1); $urltogo = $backtopage ? $backtopage : dol_buildpath('/stock/list.php', 1);
header("Location: ".$urltogo); header("Location: ".$urltogo);
exit; exit;
} }
$error=0; $error = 0;
/* object_prop_getpost_prop */ /* object_prop_getpost_prop */
$object->entity=GETPOST('entity', 'int'); $object->entity = GETPOST('entity', 'int');
$object->fk_product=GETPOST('fk_product', 'int'); $object->fk_product = GETPOST('fk_product', 'int');
$object->batch=GETPOST('batch', 'alpha'); $object->batch = GETPOST('batch', 'alpha');
$object->fk_user_creat=GETPOST('fk_user_creat', 'int'); $object->fk_user_creat = GETPOST('fk_user_creat', 'int');
$object->fk_user_modif=GETPOST('fk_user_modif', 'int'); $object->fk_user_modif = GETPOST('fk_user_modif', 'int');
$object->import_key=GETPOST('import_key', 'int'); $object->import_key = GETPOST('import_key', 'int');
if (empty($object->ref)) if (empty($object->ref))
{ {
@ -167,43 +167,43 @@ if (empty($reshook))
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors');
} }
if (! $error) if (!$error)
{ {
$result=$object->create($user); $result = $object->create($user);
if ($result > 0) if ($result > 0)
{ {
// Creation OK // Creation OK
$urltogo=$backtopage?$backtopage:dol_buildpath('/stock/list.php', 1); $urltogo = $backtopage ? $backtopage : dol_buildpath('/stock/list.php', 1);
header("Location: ".$urltogo); header("Location: ".$urltogo);
exit; exit;
} }
{ {
// Creation KO // Creation KO
if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
else setEventMessages($object->error, null, 'errors'); else setEventMessages($object->error, null, 'errors');
$action='create'; $action = 'create';
} }
} }
else else
{ {
$action='create'; $action = 'create';
} }
} }
// Cancel // Cancel
if ($action == 'update' && GETPOST('cancel', 'alpha')) $action='view'; if ($action == 'update' && GETPOST('cancel', 'alpha')) $action = 'view';
// Action to update record // Action to update record
if ($action == 'update' && ! GETPOST('cancel', 'alpha')) if ($action == 'update' && !GETPOST('cancel', 'alpha'))
{ {
$error=0; $error = 0;
$object->entity=GETPOST('entity', 'int'); $object->entity = GETPOST('entity', 'int');
$object->fk_product=GETPOST('fk_product', 'int'); $object->fk_product = GETPOST('fk_product', 'int');
$object->batch=GETPOST('batch', 'alpha'); $object->batch = GETPOST('batch', 'alpha');
$object->fk_user_creat=GETPOST('fk_user_creat', 'int'); $object->fk_user_creat = GETPOST('fk_user_creat', 'int');
$object->fk_user_modif=GETPOST('fk_user_modif', 'int'); $object->fk_user_modif = GETPOST('fk_user_modif', 'int');
$object->import_key=GETPOST('import_key', 'int'); $object->import_key = GETPOST('import_key', 'int');
if (empty($object->ref)) if (empty($object->ref))
{ {
@ -211,31 +211,31 @@ if (empty($reshook))
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors'); setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors');
} }
if (! $error) if (!$error)
{ {
$result=$object->update($user); $result = $object->update($user);
if ($result > 0) if ($result > 0)
{ {
$action='view'; $action = 'view';
} }
else else
{ {
// Creation KO // Creation KO
if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
else setEventMessages($object->error, null, 'errors'); else setEventMessages($object->error, null, 'errors');
$action='edit'; $action = 'edit';
} }
} }
else else
{ {
$action='edit'; $action = 'edit';
} }
} }
// Action to delete // Action to delete
if ($action == 'confirm_delete') if ($action == 'confirm_delete')
{ {
$result=$object->delete($user); $result = $object->delete($user);
if ($result > 0) if ($result > 0)
{ {
// Delete OK // Delete OK
@ -245,7 +245,7 @@ if (empty($reshook))
} }
else else
{ {
if (! empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
else setEventMessages($object->error, null, 'errors'); else setEventMessages($object->error, null, 'errors');
} }
} }
@ -265,7 +265,7 @@ if (empty($reshook))
llxHeader('', 'ProductLot', ''); llxHeader('', 'ProductLot', '');
$form=new Form($db); $form = new Form($db);
// Part to create // Part to create
@ -310,15 +310,15 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
if ($action == 'delete') { if ($action == 'delete') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteBatch'), $langs->trans('ConfirmDeleteBatch'), 'confirm_delete', '', 0, 1); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBatch'), $langs->trans('ConfirmDeleteBatch'), 'confirm_delete', '', 0, 1);
print $formconfirm; print $formconfirm;
} }
$linkback = '<a href="' . DOL_URL_ROOT . '/product/stock/productlot_list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>'; $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$shownav = 1; $shownav = 1;
if ($user->socid && ! in_array('batch', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0; if ($user->socid && !in_array('batch', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0;
dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch'); dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch');
@ -352,7 +352,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// Other attributes // Other attributes
$cols = 2; $cols = 2;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
print '</table>'; print '</table>';
@ -363,8 +363,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// Buttons // Buttons
print '<div class="tabsAction">'."\n"; print '<div class="tabsAction">'."\n";
$parameters=array(); $parameters = array();
$reshook=$hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) if (empty($reshook))
@ -403,12 +403,12 @@ if (empty($action))
// Documents // Documents
$filedir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product_batch').dol_sanitizeFileName($object->ref); $filedir = $conf->productbatch->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product_batch').dol_sanitizeFileName($object->ref);
$urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
$genallowed=$usercanread; $genallowed = $usercanread;
$delallowed=$usercancreate; $delallowed = $usercancreate;
print $formfile->showdocuments('product_batch', dol_sanitizeFileName($object->ref), $filedir, $urlsource, $genallowed, $delallowed, '', 0, 0, 0, 28, 0, '', 0, '', $object->default_lang, '', $object); print $formfile->showdocuments('product_batch', dol_sanitizeFileName($object->ref), $filedir, $urlsource, $genallowed, $delallowed, '', 0, 0, 0, 28, 0, '', 0, '', $object->default_lang, '', $object);
$somethingshown=$formfile->numoffiles; $somethingshown = $formfile->numoffiles;
print '</div>'; print '</div>';
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff