--- /tmp/dsg/dolibarr/htdocs/core/github_actions_addupdatedelete.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_addupdatedelete.inc.php @@ -40,7 +40,8 @@ { header("Location: ".$backtopageforcancel); exit; - } elseif (!empty($backtopage)) + } + elseif (!empty($backtopage)) { header("Location: ".$backtopage); exit; @@ -56,31 +57,26 @@ { if ($object->fields[$key]['type'] == 'duration') { if (GETPOST($key.'hour') == '' && GETPOST($key.'min') == '') continue; // The field was not submited to be edited - } else { + } + else { if (!GETPOSTISSET($key)) continue; // The field was not submited to be edited } // Ignore special fields - if (in_array($key, array('rowid', 'entity', 'import_key'))) continue; - if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) { - if (!in_array(abs($val['visible']), array(1, 3))) continue; // Only 1 and 3 that are case to create - } + if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Set value to insert if (in_array($object->fields[$key]['type'], array('text', 'html'))) { - $value = GETPOST($key, 'restricthtml'); + $value = GETPOST($key, 'none'); } elseif ($object->fields[$key]['type'] == 'date') { - $value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); // for date without hour, we use gmt + $value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); } elseif ($object->fields[$key]['type'] == 'datetime') { - $value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), GETPOST($key.'sec', 'int'), GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'), 'tzuserrel'); + $value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); } elseif ($object->fields[$key]['type'] == 'duration') { $value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int'); } elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) { - $value = price2num(GETPOST($key, 'alphanohtml')); // To fix decimal separator according to lang setup + $value = price2num(GETPOST($key, 'none')); // To fix decimal separator according to lang setup } elseif ($object->fields[$key]['type'] == 'boolean') { - $value = ((GETPOST($key) == '1' || GETPOST($key) == 'on') ? 1 : 0); - } elseif ($object->fields[$key]['type'] == 'reference') { - $tmparraykey = array_keys($object->param_list); - $value = $tmparraykey[GETPOST($key)].','.GETPOST($key.'2'); + $value = (GETPOST($key) == 'on' ? 1 : 0); } else { $value = GETPOST($key, 'alphanohtml'); } @@ -91,7 +87,7 @@ $object->$key = $value; if ($val['notnull'] > 0 && $object->$key == '' && !is_null($val['default']) && $val['default'] == '(PROV)') { - $object->$key = '(PROV)'; + $object->$key = '(PROV)'; } if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default'])) { @@ -111,18 +107,22 @@ $result = $object->create($user); if ($result > 0) { - // Creation OK + // Creation OK $urltogo = $backtopage ? str_replace('__ID__', $result, $backtopage) : $backurlforlist; $urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $object->id, $urltogo); // New method to autoselect project after a New on another form object creation header("Location: ".$urltogo); exit; - } else { + } + else + { // Creation KO if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); - else setEventMessages($object->error, null, 'errors'); + else setEventMessages($object->error, null, 'errors'); $action = 'create'; } - } else { + } + else + { $action = 'create'; } } @@ -135,32 +135,27 @@ // Check if field was submited to be edited if ($object->fields[$key]['type'] == 'duration') { if (!GETPOSTISSET($key.'hour') || !GETPOSTISSET($key.'min')) continue; // The field was not submited to be edited - } elseif ($object->fields[$key]['type'] == 'boolean') { + } + elseif ($object->fields[$key]['type'] == 'boolean') { if (!GETPOSTISSET($key)) { $object->$key = 0; // use 0 instead null if the field is defined as not null continue; } - } else { + } + + else { if (!GETPOSTISSET($key)) continue; // The field was not submited to be edited } // Ignore special fields - if (in_array($key, array('rowid', 'entity', 'import_key'))) continue; - if (in_array($key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) { - if (!in_array(abs($val['visible']), array(1, 3, 4))) continue; // Only 1 and 3 and 4 that are case to update - } + if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Set value to update - if (preg_match('/^(text|html)/', $object->fields[$key]['type'])) { - $tmparray = explode(':', $object->fields[$key]['type']); - if (!empty($tmparray[1])) { - $value = GETPOST($key, $tmparray[1]); - } else { - $value = GETPOST($key, 'restricthtml'); - } + if (in_array($object->fields[$key]['type'], array('text', 'html'))) { + $value = GETPOST($key, 'none'); } elseif ($object->fields[$key]['type'] == 'date') { - $value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); // for date without hour, we use gmt + $value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); } elseif ($object->fields[$key]['type'] == 'datetime') { - $value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), GETPOST($key.'sec', 'int'), GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'), 'tzuserrel'); + $value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); } elseif ($object->fields[$key]['type'] == 'duration') { if (GETPOST($key.'hour', 'int') != '' || GETPOST($key.'min', 'int') != '') { $value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int'); @@ -168,11 +163,9 @@ $value = ''; } } elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) { - $value = price2num(GETPOST($key, 'alphanohtml')); // To fix decimal separator according to lang setup + $value = price2num(GETPOST($key, 'none')); // To fix decimal separator according to lang setup } elseif ($object->fields[$key]['type'] == 'boolean') { - $value = ((GETPOST($key, 'aZ09') == 'on' || GETPOST($key, 'aZ09') == '1') ? 1 : 0); - } elseif ($object->fields[$key]['type'] == 'reference') { - $value = array_keys($object->param_list)[GETPOST($key)].','.GETPOST($key.'2'); + $value = (GETPOST($key) == 'on' ? 1 : 0); } else { $value = GETPOST($key, 'alpha'); } @@ -199,12 +192,16 @@ if ($result > 0) { $action = 'view'; - } else { + } + else + { // Creation KO setEventMessages($object->error, $object->errors, 'errors'); $action = 'edit'; } - } else { + } + else + { $action = 'edit'; } } @@ -222,7 +219,7 @@ $object->array_options['options_'.$attributekey] = dol_mktime(GETPOST($attributekeylong.'hour', 'int'), GETPOST($attributekeylong.'min', 'int'), GETPOST($attributekeylong.'sec', 'int'), GETPOST($attributekeylong.'month', 'int'), GETPOST($attributekeylong.'day', 'int'), GETPOST($attributekeylong.'year', 'int')); //var_dump(dol_print_date($object->array_options['options_'.$attributekey]));exit; } else { - $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, 'alpha'); + $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, ' alpha'); } $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user); @@ -230,7 +227,9 @@ { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); $action = 'view'; - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); $action = 'edit_extras'; } @@ -239,11 +238,11 @@ // Action to delete if ($action == 'confirm_delete' && !empty($permissiontodelete)) { - if (!($object->id > 0)) - { - dol_print_error('', 'Error, object must be fetched before being deleted'); - exit; - } + if (!($object->id > 0)) + { + dol_print_error('', 'Error, object must be fetched before being deleted'); + exit; + } $result = $object->delete($user); if ($result > 0) @@ -252,7 +251,9 @@ setEventMessages("RecordDeleted", null, 'mesgs'); header("Location: ".$backurlforlist); exit; - } else { + } + else + { if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); else setEventMessages($object->error, null, 'errors'); } @@ -261,11 +262,7 @@ // Remove a line if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissiontoadd)) { - if (method_exists($object, 'deleteline')) { - $result = $object->deleteline($user, $lineid); // For backward compatibility - } else { - $result = $object->deleteLine($user, $lineid); - } + $result = $object->deleteline($user, $lineid); if ($result > 0) { // Define output language @@ -284,16 +281,16 @@ $outputlangs->setDefaultLang($newlang); } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - if (method_exists($object, 'generateDocument')) { - $ret = $object->fetch($object->id); // Reload to get new records - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - } + $ret = $object->fetch($object->id); // Reload to get new records + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs'); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); exit; - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); } } @@ -305,28 +302,24 @@ if ($result >= 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - if (method_exists($object, 'generateDocument')) { - $outputlangs = $langs; - $newlang = ''; - 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 (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - - $ret = $object->fetch($id); // Reload to get new records - - $model = $object->model_pdf; - - $retgen = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($retgen < 0) { - setEventMessages($object->error, $object->errors, 'warnings'); - } + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + 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 (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); } - } - } else { + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + else + { setEventMessages($object->error, $object->errors, 'errors'); } } @@ -338,23 +331,24 @@ if ($result >= 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - if (method_exists($object, 'generateDocument')) { - $outputlangs = $langs; - $newlang = ''; - 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 (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + 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 (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); } - } - } else { + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + else + { setEventMessages($object->error, $object->errors, 'errors'); } } @@ -366,7 +360,9 @@ if ($result >= 0) { // Nothing else done - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); } } @@ -378,23 +374,24 @@ if ($result >= 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - if (method_exists($object, 'generateDocument')) { - $outputlangs = $langs; - $newlang = ''; - 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 (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + 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 (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); } - } - } else { + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + else + { setEventMessages($object->error, $object->errors, 'errors'); } } @@ -405,20 +402,24 @@ if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); - } else { - $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. + } + else + { + $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')); - // ... - $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id)); - if (is_object($result) || $result > 0) + // ... + $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id)); + if (is_object($result) || $result > 0) { $newid = 0; if (is_object($result)) $newid = $result->id; else $newid = $result; header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid); // Open record of new object exit; - } else { - setEventMessages($objectutil->error, $objectutil->errors, 'errors'); + } + else + { + setEventMessages($objectutil->error, $objectutil->errors, 'errors'); $action = ''; } } --- /tmp/dsg/dolibarr/htdocs/core/github_actions_builddoc.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_builddoc.inc.php @@ -34,103 +34,108 @@ // Build doc if ($action == 'builddoc' && $permissiontoadd) { - if (is_numeric(GETPOST('model', 'alpha'))) - { - $error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Model")); - } else { + if (is_numeric(GETPOST('model', 'alpha'))) + { + $error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Model")); + } + else + { // Reload to get all modified line records and be ready for hooks - $ret = $object->fetch($id); - $ret = $object->fetch_thirdparty(); - /*if (empty($object->id) || ! $object->id > 0) + $ret = $object->fetch($id); + $ret = $object->fetch_thirdparty(); + /*if (empty($object->id) || ! $object->id > 0) { dol_print_error('Object must have been loaded by a fetch'); exit; }*/ - // Save last template used to generate document - if (GETPOST('model', 'alpha')) - { - $object->setDocModel($user, GETPOST('model', 'alpha')); - } + // Save last template used to generate document + if (GETPOST('model', 'alpha')) + { + $object->setDocModel($user, GETPOST('model', 'alpha')); + } - // Special case to force bank account - //if (property_exists($object, 'fk_bank')) - //{ - if (GETPOST('fk_bank', 'int')) { - // this field may come from an external module - $object->fk_bank = GETPOST('fk_bank', 'int'); - } elseif (!empty($object->fk_account)) { - $object->fk_bank = $object->fk_account; - } - //} + // Special case to force bank account + //if (property_exists($object, 'fk_bank')) + //{ + if (GETPOST('fk_bank', 'int')) { + // this field may come from an external module + $object->fk_bank = GETPOST('fk_bank', 'int'); + } elseif (!empty($object->fk_account)) { + $object->fk_bank = $object->fk_account; + } + //} - $outputlangs = $langs; - $newlang = ''; + $outputlangs = $langs; + $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->thirdparty->default_lang)) $newlang = $object->thirdparty->default_lang; // for proposal, order, invoice, ... - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->default_lang)) $newlang = $object->default_lang; // for thirdparty - if (!empty($newlang)) - { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->thirdparty->default_lang)) $newlang = $object->thirdparty->default_lang; // for proposal, order, invoice, ... + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->default_lang)) $newlang = $object->default_lang; // for thirdparty + if (!empty($newlang)) + { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } - // To be sure vars is defined - if (empty($hidedetails)) $hidedetails = 0; - if (empty($hidedesc)) $hidedesc = 0; - if (empty($hideref)) $hideref = 0; - if (empty($moreparams)) $moreparams = null; + // To be sure vars is defined + if (empty($hidedetails)) $hidedetails = 0; + if (empty($hidedesc)) $hidedesc = 0; + if (empty($hideref)) $hideref = 0; + if (empty($moreparams)) $moreparams = null; - $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); - if ($result <= 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $action = ''; - } else { - if (empty($donotredirect)) // This is set when include is done by bulk action "Bill Orders" - { - setEventMessages($langs->trans("FileGenerated"), null); + $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); + if ($result <= 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $action = ''; + } + else + { + if (empty($donotredirect)) // This is set when include is done by bulk action "Bill Orders" + { + setEventMessages($langs->trans("FileGenerated"), null); - $urltoredirect = $_SERVER['REQUEST_URI']; - $urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect); - $urltoredirect = preg_replace('/action=builddoc&?/', '', $urltoredirect); // To avoid infinite loop + $urltoredirect = $_SERVER['REQUEST_URI']; + $urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect); + $urltoredirect = preg_replace('/action=builddoc&?/', '', $urltoredirect); // To avoid infinite loop - header('Location: '.$urltoredirect.'#builddoc'); - exit; - } - } - } + header('Location: '.$urltoredirect.'#builddoc'); + exit; + } + } + } } // Delete file in doc form if ($action == 'remove_file' && $permissiontoadd) { if (!empty($upload_dir)) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - if (empty($object->id) || !$object->id > 0) - { - // Reload to get all modified line records and be ready for hooks - $ret = $object->fetch($id); - $ret = $object->fetch_thirdparty(); - } + if (empty($object->id) || !$object->id > 0) + { + // Reload to get all modified line records and be ready for hooks + $ret = $object->fetch($id); + $ret = $object->fetch_thirdparty(); + } - $langs->load("other"); - $filetodelete = GETPOST('file', 'alpha'); - $file = $upload_dir.'/'.$filetodelete; - $ret = dol_delete_file($file, 0, 0, 0, $object); - if ($ret) setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs'); - else setEventMessages($langs->trans("ErrorFailToDeleteFile", $filetodelete), null, 'errors'); + $langs->load("other"); + $filetodelete = GETPOST('file', 'alpha'); + $file = $upload_dir.'/'.$filetodelete; + $ret = dol_delete_file($file, 0, 0, 0, $object); + if ($ret) setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs'); + else setEventMessages($langs->trans("ErrorFailToDeleteFile", $filetodelete), null, 'errors'); - // Make a redirect to avoid to keep the remove_file into the url that create side effects - $urltoredirect = $_SERVER['REQUEST_URI']; - $urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect); - $urltoredirect = preg_replace('/action=remove_file&?/', '', $urltoredirect); + // Make a redirect to avoid to keep the remove_file into the url that create side effects + $urltoredirect = $_SERVER['REQUEST_URI']; + $urltoredirect = preg_replace('/#builddoc$/', '', $urltoredirect); + $urltoredirect = preg_replace('/action=remove_file&?/', '', $urltoredirect); - header('Location: '.$urltoredirect); - exit; - } else { + header('Location: '.$urltoredirect); + exit; + } + else { setEventMessages('BugFoundVarUploaddirnotDefined', null, 'errors'); } } --- /tmp/dsg/dolibarr/htdocs/core/github_actions_changeselectedfields.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_changeselectedfields.inc.php @@ -28,19 +28,19 @@ // $object must be defined (object is loaded in this file with fetch) // Save selection -if (GETPOST('formfilteraction', 'alphanohtml') == 'listafterchangingselectedfields') +if (GETPOST('formfilteraction', 'none') == 'listafterchangingselectedfields') { - $tabparam = array(); + $tabparam = array(); - $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; + $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; - if (GETPOST("selectedfields")) $tabparam["MAIN_SELECTEDFIELDS_".$varpage] = GETPOST("selectedfields"); - else $tabparam["MAIN_SELECTEDFIELDS_".$varpage] = ''; + if (GETPOST("selectedfields")) $tabparam["MAIN_SELECTEDFIELDS_".$varpage] = GETPOST("selectedfields"); + else $tabparam["MAIN_SELECTEDFIELDS_".$varpage] = ''; - include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $result = dol_set_user_param($db, $conf, $user, $tabparam); + $result = dol_set_user_param($db, $conf, $user, $tabparam); - //$action='list'; - //var_dump($tabparam);exit; + //$action='list'; + //var_dump($tabparam);exit; } --- /tmp/dsg/dolibarr/htdocs/core/github_actions_comments.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_comments.inc.php @@ -35,7 +35,7 @@ if ($action == 'addcomment') { - $description = GETPOST('comment_description', 'restricthtml'); + $description = GETPOST('comment_description', 'none'); if (!empty($description)) { $comment->description = $description; @@ -49,7 +49,9 @@ setEventMessages($langs->trans("CommentAdded"), null, 'mesgs'); header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : '')); exit; - } else { + } + else + { setEventMessages($comment->error, $comment->errors, 'errors'); $action = ''; } @@ -57,19 +59,21 @@ } if ($action === 'updatecomment') { - if ($comment->fetch($idcomment) >= 0) - { - $comment->description = GETPOST('comment_description', 'restricthtml'); - if ($comment->update($user) > 0) - { - setEventMessages($langs->trans("CommentAdded"), null, 'mesgs'); - header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1#comment' : '')); - exit; - } else { - setEventMessages($comment->error, $comment->errors, 'errors'); - $action = ''; - } - } + if ($comment->fetch($idcomment) >= 0) + { + $comment->description = GETPOST('comment_description', 'none'); + if ($comment->update($user) > 0) + { + setEventMessages($langs->trans("CommentAdded"), null, 'mesgs'); + header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1#comment' : '')); + exit; + } + else + { + setEventMessages($comment->error, $comment->errors, 'errors'); + $action = ''; + } + } } if ($action == 'deletecomment') { @@ -80,7 +84,9 @@ setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs'); header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : '')); exit; - } else { + } + else + { setEventMessages($comment->error, $comment->errors, 'errors'); $action = ''; } --- /tmp/dsg/dolibarr/htdocs/core/github_actions_extrafields.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_extrafields.inc.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2015 Laurent Destailleur * * 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 @@ -40,9 +40,9 @@ // Add attribute if ($action == 'add') { - if (GETPOST("button") != $langs->trans("Cancel")) + if ($_POST["button"] != $langs->trans("Cancel")) { - // Check values + // Check values if (!$type) { $error++; @@ -52,182 +52,175 @@ } if ($type == 'varchar' && $extrasize <= 0) { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size")); - $action = 'edit'; + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size")); + $action = 'edit'; } - if ($type == 'varchar' && $extrasize > $maxsizestring) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorSizeTooLongForVarcharType", $maxsizestring); - $action = 'create'; - } - if ($type == 'int' && $extrasize > $maxsizeint) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorSizeTooLongForIntType", $maxsizeint); - $action = 'create'; - } - if ($type == 'select' && !$param) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorNoValueForSelectType"); - $action = 'create'; - } - if ($type == 'sellist' && !$param) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorNoValueForSelectListType"); - $action = 'create'; - } - if ($type == 'checkbox' && !$param) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorNoValueForCheckBoxType"); - $action = 'create'; - } - if ($type == 'link' && !$param) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorNoValueForLinkType"); - $action = 'create'; - } - if ($type == 'radio' && !$param) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorNoValueForRadioType"); - $action = 'create'; - } - if ((($type == 'radio') || ($type == 'checkbox')) && $param) - { - // Construct array for parameter (value of select list) - $parameters = $param; - $parameters_array = explode("\r\n", $parameters); - foreach ($parameters_array as $param_ligne) - { - if (!empty($param_ligne)) { - if (preg_match_all('/,/', $param_ligne, $matches)) - { - if (count($matches[0]) > 1) { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorBadFormatValueList", $param_ligne); - $action = 'create'; - } - } else { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorBadFormatValueList", $param_ligne); - $action = 'create'; - } - } - } - } - - if (!$error) { - if (strlen(GETPOST('attrname', 'aZ09')) < 3) { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorValueLength", $langs->transnoentitiesnoconv("AttributeCode"), 3); - $action = 'create'; - } - } - - // Check reserved keyword with more than 3 characters - if (!$error) { - if (in_array(GETPOST('attrname', 'aZ09'), array('and', 'keyword', 'table', 'index', 'integer', 'float', 'double', 'position'))) { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorReservedKeyword", GETPOST('attrname', 'aZ09')); - $action = 'create'; - } - } - - if (!$error) { - // attrname must be alphabetical and lower case only - if (GETPOSTISSET("attrname") && preg_match("/^[a-z0-9-_]+$/", GETPOST('attrname', 'aZ09')) && !is_numeric(GETPOST('attrname', 'aZ09'))) { - // Construct array for parameter (value of select list) - $default_value = GETPOST('default_value', 'alpha'); - $parameters = $param; - $parameters_array = explode("\r\n", $parameters); - //In sellist we have only one line and it can have come to do SQL expression - if ($type == 'sellist' || $type == 'chkbxlst') { - foreach ($parameters_array as $param_ligne) - { - $params['options'] = array($parameters=>null); - } - } else { - // Else it's separated key/value and coma list - foreach ($parameters_array as $param_ligne) - { - list($key, $value) = explode(',', $param_ligne); - $params['options'][$key] = $value; - } - } - - // Visibility: -1=not visible by default in list, 1=visible, 0=hidden - $visibility = GETPOST('list', 'alpha'); + if ($type == 'varchar' && $extrasize > $maxsizestring) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorSizeTooLongForVarcharType", $maxsizestring); + $action = 'create'; + } + if ($type == 'int' && $extrasize > $maxsizeint) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorSizeTooLongForIntType", $maxsizeint); + $action = 'create'; + } + if ($type == 'select' && !$param) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorNoValueForSelectType"); + $action = 'create'; + } + if ($type == 'sellist' && !$param) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorNoValueForSelectListType"); + $action = 'create'; + } + if ($type == 'checkbox' && !$param) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorNoValueForCheckBoxType"); + $action = 'create'; + } + if ($type == 'link' && !$param) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorNoValueForLinkType"); + $action = 'create'; + } + if ($type == 'radio' && !$param) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorNoValueForRadioType"); + $action = 'create'; + } + if ((($type == 'radio') || ($type == 'checkbox')) && $param) + { + // Construct array for parameter (value of select list) + $parameters = $param; + $parameters_array = explode("\r\n", $parameters); + foreach ($parameters_array as $param_ligne) + { + if (!empty($param_ligne)) { + if (preg_match_all('/,/', $param_ligne, $matches)) + { + if (count($matches[0]) > 1) { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorBadFormatValueList", $param_ligne); + $action = 'create'; + } + } + else + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorBadFormatValueList", $param_ligne); + $action = 'create'; + } + } + } + } + + if (!$error) + { + // attrname must be alphabetical and lower case only + if (isset($_POST["attrname"]) && preg_match("/^[a-z0-9-_]+$/", $_POST['attrname']) && !is_numeric($_POST["attrname"])) + { + // Construct array for parameter (value of select list) + $default_value = GETPOST('default_value', 'alpha'); + $parameters = $param; + $parameters_array = explode("\r\n", $parameters); + //In sellist we have only one line and it can have come to do SQL expression + if ($type == 'sellist') { + foreach ($parameters_array as $param_ligne) + { + $params['options'] = array($parameters=>null); + } + } + else + { + //Esle it's separated key/value and coma list + foreach ($parameters_array as $param_ligne) + { + list($key, $value) = explode(',', $param_ligne); + $params['options'][$key] = $value; + } + } + + // Visibility: -1=not visible by default in list, 1=visible, 0=hidden + $visibility = GETPOST('list', 'alpha'); if ($type == 'separate') $visibility = 3; - $result = $extrafields->addExtraField( - GETPOST('attrname', 'aZ09'), - GETPOST('label', 'alpha'), - $type, - GETPOST('pos', 'int'), - $extrasize, - $elementtype, - (GETPOST('unique', 'alpha') ? 1 : 0), - (GETPOST('required', 'alpha') ? 1 : 0), - $default_value, - $params, - (GETPOST('alwayseditable', 'alpha') ? 1 : 0), - (GETPOST('perms', 'alpha') ?GETPOST('perms', 'alpha') : ''), - $visibility, + $result = $extrafields->addExtraField( + GETPOST('attrname', 'alpha'), + GETPOST('label', 'alpha'), + $type, + GETPOST('pos', 'int'), + $extrasize, + $elementtype, + (GETPOST('unique', 'alpha') ? 1 : 0), + (GETPOST('required', 'alpha') ? 1 : 0), + $default_value, + $params, + (GETPOST('alwayseditable', 'alpha') ? 1 : 0), + (GETPOST('perms', 'alpha') ?GETPOST('perms', 'alpha') : ''), + $visibility, GETPOST('help', 'alpha'), - GETPOST('computed_value', 'alpha'), - (GETPOST('entitycurrentorall', 'alpha') ? 0 : ''), - GETPOST('langfile', 'alpha'), - 1, - (GETPOST('totalizable', 'alpha') ? 1 : 0), - GETPOST('printable', 'alpha') - ); - if ($result > 0) - { - setEventMessages($langs->trans('SetupSaved'), null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"]); - exit; - } else { - $error++; - $mesg = $extrafields->error; - setEventMessages($mesg, null, 'errors'); - } - } else { - $error++; - $langs->load("errors"); - $mesg = $langs->trans("ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities("AttributeCode")); - setEventMessages($mesg, null, 'errors'); - $action = 'create'; - } - } else { - setEventMessages($mesg, null, 'errors'); - } + GETPOST('computed_value', 'alpha'), + (GETPOST('entitycurrentorall', 'alpha') ? 0 : ''), + GETPOST('langfile', 'alpha'), + 1, + (GETPOST('totalizable', 'alpha') ? 1 : 0), + GETPOST('printable', 'alpha') + ); + if ($result > 0) + { + setEventMessages($langs->trans('SetupSaved'), null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + $error++; + $mesg = $extrafields->error; + setEventMessages($mesg, null, 'errors'); + } + } + else + { + $error++; + $langs->load("errors"); + $mesg = $langs->trans("ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities("AttributeCode")); + setEventMessages($mesg, null, 'errors'); + $action = 'create'; + } + } + else + { + setEventMessages($mesg, null, 'errors'); + } } } // Rename field if ($action == 'update') { - if (GETPOST("button") != $langs->trans("Cancel")) + if ($_POST["button"] != $langs->trans("Cancel")) { - // Check values + // Check values if (!$type) { $error++; @@ -237,181 +230,176 @@ } if ($type == 'varchar' && $extrasize <= 0) { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size")); - $action = 'edit'; + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size")); + $action = 'edit'; } if ($type == 'varchar' && $extrasize > $maxsizestring) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorSizeTooLongForVarcharType", $maxsizestring); - $action = 'edit'; - } - if ($type == 'int' && $extrasize > $maxsizeint) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorSizeTooLongForIntType", $maxsizeint); - $action = 'edit'; - } - if ($type == 'select' && !$param) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorNoValueForSelectType"); - $action = 'edit'; - } - if ($type == 'sellist' && !$param) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorNoValueForSelectListType"); - $action = 'edit'; - } - if ($type == 'checkbox' && !$param) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorNoValueForCheckBoxType"); - $action = 'edit'; - } - if ($type == 'radio' && !$param) - { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorNoValueForRadioType"); - $action = 'edit'; - } - if ((($type == 'radio') || ($type == 'checkbox')) && $param) - { - // Construct array for parameter (value of select list) - $parameters = $param; - $parameters_array = explode("\r\n", $parameters); - foreach ($parameters_array as $param_ligne) - { - if (!empty($param_ligne)) { - if (preg_match_all('/,/', $param_ligne, $matches)) - { - if (count($matches[0]) > 1) { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorBadFormatValueList", $param_ligne); - $action = 'edit'; - } - } else { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorBadFormatValueList", $param_ligne); - $action = 'edit'; - } - } - } - } - - if (!$error) { - if (strlen(GETPOST('attrname', 'aZ09')) < 3 && empty($conf->global->MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE)) { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorValueLength", $langs->transnoentitiesnoconv("AttributeCode"), 3); - $action = 'edit'; - } - } - - // Check reserved keyword with more than 3 characters - if (!$error) { - if (in_array(GETPOST('attrname', 'aZ09'), array('and', 'keyword', 'table', 'index', 'integer', 'float', 'double', 'position')) && empty($conf->global->MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE)) { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorReservedKeyword", GETPOST('attrname', 'aZ09')); - $action = 'edit'; - } - } - - if (!$error) - { - if (GETPOSTISSET("attrname") && preg_match("/^\w[a-zA-Z0-9-_]*$/", GETPOST('attrname', 'aZ09')) && !is_numeric(GETPOST('attrname', 'aZ09'))) - { - $pos = GETPOST('pos', 'int'); - // Construct array for parameter (value of select list) - $parameters = $param; - $parameters_array = explode("\r\n", $parameters); - //In sellist we have only one line and it can have come to do SQL expression - if ($type == 'sellist' || $type == 'chkbxlst') { - foreach ($parameters_array as $param_ligne) - { - $params['options'] = array($parameters=>null); - } - } else { - //Esle it's separated key/value and coma list - foreach ($parameters_array as $param_ligne) - { - list($key, $value) = explode(',', $param_ligne); - $params['options'][$key] = $value; - } - } - - // Visibility: -1=not visible by default in list, 1=visible, 0=hidden - $visibility = GETPOST('list', 'alpha'); - if ($type == 'separate') $visibility = 3; - - // Example: is_object($object) ? ($object->id < 10 ? round($object->id / 2, 2) : (2 * $user->id) * (int) substr($mysoc->zip, 1, 2)) : 'objnotdefined' - $computedvalue = GETPOST('computed_value', 'nohtml'); - - $result = $extrafields->update( - GETPOST('attrname', 'aZ09'), - GETPOST('label', 'alpha'), - $type, - $extrasize, - $elementtype, - (GETPOST('unique', 'alpha') ? 1 : 0), - (GETPOST('required', 'alpha') ? 1 : 0), - $pos, - $params, - (GETPOST('alwayseditable', 'alpha') ? 1 : 0), - (GETPOST('perms', 'alpha') ?GETPOST('perms', 'alpha') : ''), - $visibility, + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorSizeTooLongForVarcharType", $maxsizestring); + $action = 'edit'; + } + if ($type == 'int' && $extrasize > $maxsizeint) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorSizeTooLongForIntType", $maxsizeint); + $action = 'edit'; + } + if ($type == 'select' && !$param) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorNoValueForSelectType"); + $action = 'edit'; + } + if ($type == 'sellist' && !$param) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorNoValueForSelectListType"); + $action = 'edit'; + } + if ($type == 'checkbox' && !$param) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorNoValueForCheckBoxType"); + $action = 'edit'; + } + if ($type == 'radio' && !$param) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorNoValueForRadioType"); + $action = 'edit'; + } + if ((($type == 'radio') || ($type == 'checkbox')) && $param) + { + // Construct array for parameter (value of select list) + $parameters = $param; + $parameters_array = explode("\r\n", $parameters); + foreach ($parameters_array as $param_ligne) + { + if (!empty($param_ligne)) { + if (preg_match_all('/,/', $param_ligne, $matches)) + { + if (count($matches[0]) > 1) { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorBadFormatValueList", $param_ligne); + $action = 'edit'; + } + } + else + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorBadFormatValueList", $param_ligne); + $action = 'edit'; + } + } + } + } + + if (!$error) + { + if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/", $_POST['attrname'])) + { + $pos = GETPOST('pos', 'int'); + // Construct array for parameter (value of select list) + $parameters = $param; + $parameters_array = explode("\r\n", $parameters); + //In sellist we have only one line and it can have come to do SQL expression + if ($type == 'sellist') { + foreach ($parameters_array as $param_ligne) + { + $params['options'] = array($parameters=>null); + } + } + else + { + //Esle it's separated key/value and coma list + foreach ($parameters_array as $param_ligne) + { + list($key, $value) = explode(',', $param_ligne); + $params['options'][$key] = $value; + } + } + + // Visibility: -1=not visible by default in list, 1=visible, 0=hidden + $visibility = GETPOST('list', 'alpha'); + if ($type == 'separate') $visibility = 3; + + $result = $extrafields->update( + GETPOST('attrname', 'alpha'), + GETPOST('label', 'alpha'), + $type, + $extrasize, + $elementtype, + (GETPOST('unique', 'alpha') ? 1 : 0), + (GETPOST('required', 'alpha') ? 1 : 0), + $pos, + $params, + (GETPOST('alwayseditable', 'alpha') ? 1 : 0), + (GETPOST('perms', 'alpha') ?GETPOST('perms', 'alpha') : ''), + $visibility, GETPOST('help', 'alpha'), - GETPOST('default_value', 'alpha'), - $computedvalue, - (GETPOST('entitycurrentorall', 'alpha') ? 0 : ''), - GETPOST('langfile'), - GETPOST('enabled', 'alpha'), - (GETPOST('totalizable', 'alpha') ? 1 : 0), - GETPOST('printable', 'alpha') - ); - if ($result > 0) { - setEventMessages($langs->trans('SetupSaved'), null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"]); - exit; - } else { - $error++; - $mesg = $extrafields->error; - setEventMessages($mesg, null, 'errors'); - } - } else { - $error++; - $langs->load("errors"); - $mesg = $langs->trans("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("AttributeCode")); - setEventMessages($mesg, null, 'errors'); - } - } else { - setEventMessages($mesg, null, 'errors'); - } + GETPOST('default_value', 'alpha'), + GETPOST('computed_value', 'alpha'), + (GETPOST('entitycurrentorall', 'alpha') ? 0 : ''), + GETPOST('langfile'), + 1, + (GETPOST('totalizable', 'alpha') ? 1 : 0), + GETPOST('printable', 'alpha') + ); + if ($result > 0) + { + setEventMessages($langs->trans('SetupSaved'), null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + $error++; + $mesg = $extrafields->error; + setEventMessages($mesg, null, 'errors'); + } + } + else + { + $error++; + $langs->load("errors"); + $mesg = $langs->trans("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("AttributeCode")); + setEventMessages($mesg, null, 'errors'); + } + } + else + { + setEventMessages($mesg, null, 'errors'); + } } } // Delete attribute -if ($action == 'delete') { - if (GETPOSTISSET("attrname") && preg_match("/^\w[a-zA-Z0-9-_]*$/", GETPOST("attrname", 'aZ09'))) { - $result = $extrafields->delete(GETPOST("attrname", 'aZ09'), $elementtype); - if ($result >= 0) { - header("Location: ".$_SERVER["PHP_SELF"]); - exit; - } else $mesg = $extrafields->error; - } else { - $error++; +if ($action == 'delete') +{ + if (isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/", $_GET["attrname"])) + { + $result = $extrafields->delete($_GET["attrname"], $elementtype); + if ($result >= 0) + { + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else $mesg = $extrafields->error; + } + else + { + $error++; $langs->load("errors"); $mesg = $langs->trans("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("AttributeCode")); } --- /tmp/dsg/dolibarr/htdocs/core/github_actions_fetchobject.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_fetchobject.inc.php @@ -34,20 +34,23 @@ { $ret = $object->fetch($id, $ref); if ($ret > 0) - { - $object->fetch_thirdparty(); - $id = $object->id; - } else { - if (empty($object->error) && !count($object->errors)) - { - if ($ret < 0) // if $ret == 0, it means not found. - { - setEventMessages('Fetch on object (type '.get_class($object).') return an error without filling $object->error nor $object->errors', null, 'errors'); - } - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - $action = ''; - } + { + $object->fetch_thirdparty(); + $id = $object->id; + } + else + { + if (empty($object->error) && !count($object->errors)) + { + if ($ret < 0) // if $ret == 0, it means not found. + { + setEventMessages('Fetch on object (type '.get_class($object).') return an error without filling $object->error nor $object->errors', null, 'errors'); + } + } + else { + setEventMessages($object->error, $object->errors, 'errors'); + } + $action = ''; + } } } --- /tmp/dsg/dolibarr/htdocs/core/github_actions_lineupdown.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_lineupdown.inc.php @@ -43,7 +43,7 @@ } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('rowid')); @@ -64,7 +64,7 @@ $outputlangs->setDefaultLang($newlang); } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('rowid')); --- /tmp/dsg/dolibarr/htdocs/core/github_actions_linkedfiles.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_linkedfiles.inc.php @@ -29,7 +29,7 @@ // Submit file/link if (GETPOST('sendit', 'alpha') && !empty($conf->global->MAIN_UPLOAD_DOC)) { - if (!empty($_FILES)) + if (!empty($_FILES)) { if (is_array($_FILES['userfile']['tmp_name'])) $userfiles = $_FILES['userfile']['tmp_name']; else $userfiles = array($_FILES['userfile']['tmp_name']); @@ -41,7 +41,8 @@ $error++; if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2) { setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors'); - } else { + } + else { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors'); } } @@ -56,122 +57,132 @@ if (!empty($upload_dirold) && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { - $result = dol_add_file_process($upload_dirold, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs, $object); - } elseif (!empty($upload_dir)) + $result = dol_add_file_process($upload_dirold, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs); + } + elseif (!empty($upload_dir)) { - $result = dol_add_file_process($upload_dir, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs, $object); + $result = dol_add_file_process($upload_dir, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs); } } } -} elseif (GETPOST('linkit', 'restricthtml') && !empty($conf->global->MAIN_UPLOAD_DOC)) -{ - $link = GETPOST('link', 'alpha'); - if ($link) - { - if (substr($link, 0, 7) != 'http://' && substr($link, 0, 8) != 'https://' && substr($link, 0, 7) != 'file://') { - $link = 'http://'.$link; - } - dol_add_file_process($upload_dir, 0, 1, 'userfile', null, $link, '', 0); - } +} +elseif (GETPOST('linkit', 'none') && !empty($conf->global->MAIN_UPLOAD_DOC)) +{ + $link = GETPOST('link', 'alpha'); + if ($link) + { + if (substr($link, 0, 7) != 'http://' && substr($link, 0, 8) != 'https://' && substr($link, 0, 7) != 'file://') { + $link = 'http://'.$link; + } + dol_add_file_process($upload_dir, 0, 1, 'userfile', null, $link, '', 0); + } } // Delete file/link if ($action == 'confirm_deletefile' && $confirm == 'yes') { - $urlfile = GETPOST('urlfile', 'alpha', 0, null, null, 1); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). - if (GETPOST('section', 'alpha')) { - // For a delete from the ECM module, upload_dir is ECM root dir and urlfile contains relative path from upload_dir - $file = $upload_dir.(preg_match('/\/$/', $upload_dir) ? '' : '/').$urlfile; - } else // For a delete from the file manager into another module, or from documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile. + $urlfile = GETPOST('urlfile', 'alpha', 0, null, null, 1); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). + if (GETPOST('section', 'alpha')) { + // For a delete from the ECM module, upload_dir is ECM root dir and urlfile contains relative path from upload_dir + $file = $upload_dir.(preg_match('/\/$/', $upload_dir) ? '' : '/').$urlfile; + } + else // For a delete from the file manager into another module, or from documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile. { - $urlfile = basename($urlfile); - $file = $upload_dir.(preg_match('/\/$/', $upload_dir) ? '' : '/').$urlfile; + $urlfile = basename($urlfile); + $file = $upload_dir.(preg_match('/\/$/', $upload_dir) ? '' : '/').$urlfile; if (!empty($upload_dirold)) $fileold = $upload_dirold."/".$urlfile; } - $linkid = GETPOST('linkid', 'int'); - - if ($urlfile) { - // delete of a file - $dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine - $dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette (if file is an image) - - $ret = dol_delete_file($file, 0, 0, 0, (is_object($object) ? $object : null)); - if (!empty($fileold)) dol_delete_file($fileold, 0, 0, 0, (is_object($object) ? $object : null)); // Delete file using old path - - // If it exists, remove thumb. - $regs = array(); - if (preg_match('/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i', $file, $regs)) - { - $photo_vignette = basename(preg_replace('/'.$regs[0].'/i', '', $file).'_small'.$regs[0]); - if (file_exists(dol_osencode($dirthumb.$photo_vignette))) - { - dol_delete_file($dirthumb.$photo_vignette); - } - - $photo_vignette = basename(preg_replace('/'.$regs[0].'/i', '', $file).'_mini'.$regs[0]); - if (file_exists(dol_osencode($dirthumb.$photo_vignette))) - { - dol_delete_file($dirthumb.$photo_vignette); - } - } - - if ($ret) { - setEventMessages($langs->trans("FileWasRemoved", $urlfile), null, 'mesgs'); - } else { - setEventMessages($langs->trans("ErrorFailToDeleteFile", $urlfile), null, 'errors'); - } - } elseif ($linkid) { // delete of external link - require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; - $link = new Link($db); - $link->fetch($linkid); - $res = $link->delete($user); - - $langs->load('link'); - if ($res > 0) { - setEventMessages($langs->trans("LinkRemoved", $link->label), null, 'mesgs'); - } else { - if (count($link->errors)) { - setEventMessages('', $link->errors, 'errors'); - } else { - setEventMessages($langs->trans("ErrorFailedToDeleteLink", $link->label), null, 'errors'); - } - } - } - - if (is_object($object) && $object->id > 0) { - if ($backtopage) { - header('Location: '.$backtopage); - exit; - } else { - $tmpurl = $_SERVER["PHP_SELF"].'?id='.$object->id.(GETPOST('section_dir', 'alpha') ? '§ion_dir='.urlencode(GETPOST('section_dir', 'alpha')) : '').(!empty($withproject) ? '&withproject=1' : ''); - header('Location: '.$tmpurl); - exit; - } - } -} elseif ($action == 'confirm_updateline' && GETPOST('save', 'alpha') && GETPOST('link', 'alpha')) -{ - require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; - $langs->load('link'); - $link = new Link($db); - $f = $link->fetch(GETPOST('linkid', 'int')); - if ($f) - { - $link->url = GETPOST('link', 'alpha'); - if (substr($link->url, 0, 7) != 'http://' && substr($link->url, 0, 8) != 'https://' && substr($link->url, 0, 7) != 'file://') - { - $link->url = 'http://'.$link->url; - } - $link->label = GETPOST('label', 'alphanohtml'); - $res = $link->update($user); - if (!$res) - { - setEventMessages($langs->trans("ErrorFailedToUpdateLink", $link->label), null, 'mesgs'); - } - } else { - //error fetching - } -} elseif ($action == 'renamefile' && GETPOST('renamefilesave', 'alpha')) + $linkid = GETPOST('linkid', 'int'); + + if ($urlfile) { + // delete of a file + $dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine + $dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette (if file is an image) + + $ret = dol_delete_file($file, 0, 0, 0, (is_object($object) ? $object : null)); + if (!empty($fileold)) dol_delete_file($fileold, 0, 0, 0, (is_object($object) ? $object : null)); // Delete file using old path + + // Si elle existe, on efface la vignette + if (preg_match('/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i', $file, $regs)) + { + $photo_vignette = basename(preg_replace('/'.$regs[0].'/i', '', $file).'_small'.$regs[0]); + if (file_exists(dol_osencode($dirthumb.$photo_vignette))) + { + dol_delete_file($dirthumb.$photo_vignette); + } + + $photo_vignette = basename(preg_replace('/'.$regs[0].'/i', '', $file).'_mini'.$regs[0]); + if (file_exists(dol_osencode($dirthumb.$photo_vignette))) + { + dol_delete_file($dirthumb.$photo_vignette); + } + } + + if ($ret) { + setEventMessages($langs->trans("FileWasRemoved", $urlfile), null, 'mesgs'); + } else { + setEventMessages($langs->trans("ErrorFailToDeleteFile", $urlfile), null, 'errors'); + } + } + elseif ($linkid) // delete of external link + { + require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; + $link = new Link($db); + $link->fetch($linkid); + $res = $link->delete($user); + + $langs->load('link'); + if ($res > 0) { + setEventMessages($langs->trans("LinkRemoved", $link->label), null, 'mesgs'); + } else { + if (count($link->errors)) { + setEventMessages('', $link->errors, 'errors'); + } else { + setEventMessages($langs->trans("ErrorFailedToDeleteLink", $link->label), null, 'errors'); + } + } + } + + if (is_object($object) && $object->id > 0) { + if ($backtopage) { + header('Location: '.$backtopage); + exit; + } + else + { + $tmpurl = $_SERVER["PHP_SELF"].'?id='.$object->id.(GETPOST('section_dir', 'alpha') ? '§ion_dir='.urlencode(GETPOST('section_dir', 'alpha')) : '').(!empty($withproject) ? '&withproject=1' : ''); + header('Location: '.$tmpurl); + exit; + } + } +} +elseif ($action == 'confirm_updateline' && GETPOST('save', 'alpha') && GETPOST('link', 'alpha')) +{ + require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; + $langs->load('link'); + $link = new Link($db); + $f = $link->fetch(GETPOST('linkid', 'int')); + if ($f) + { + $link->url = GETPOST('link', 'alpha'); + if (substr($link->url, 0, 7) != 'http://' && substr($link->url, 0, 8) != 'https://' && substr($link->url, 0, 7) != 'file://') + { + $link->url = 'http://'.$link->url; + } + $link->label = GETPOST('label', 'alphanohtml'); + $res = $link->update($user); + if (!$res) + { + setEventMessages($langs->trans("ErrorFailedToUpdateLink", $link->label), null, 'mesgs'); + } + } + else + { + //error fetching + } +} +elseif ($action == 'renamefile' && GETPOST('renamefilesave', 'alpha')) { // For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile. if (!empty($upload_dir)) @@ -179,101 +190,103 @@ $filenamefrom = dol_sanitizeFileName(GETPOST('renamefilefrom', 'alpha'), '_', 0); // Do not remove accents $filenameto = dol_sanitizeFileName(GETPOST('renamefileto', 'alpha'), '_', 0); // Do not remove accents - // We apply dol_string_nohtmltag also to clean file names (this remove duplicate spaces) because - // this function is also applied when we upload and when we make try to download file (by the GETPOST(filename, 'alphanohtml') call). - $filenameto = dol_string_nohtmltag($filenameto); - - if ($filenamefrom != $filenameto) - { - // Security: - // Disallow file with some extensions. We rename them. - // Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code. - if (isAFileWithExecutableContent($filenameto) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED)) - { - // $upload_dir ends with a slash, so be must be sure the medias dir to compare to ends with slash too. - $publicmediasdirwithslash = $conf->medias->multidir_output[$conf->entity]; - if (!preg_match('/\/$/', $publicmediasdirwithslash)) $publicmediasdirwithslash .= '/'; - - if (strpos($upload_dir, $publicmediasdirwithslash) !== 0) { // We never add .noexe on files into media directory - $filenameto .= '.noexe'; - } - } - - if ($filenamefrom && $filenameto) - { - $srcpath = $upload_dir.'/'.$filenamefrom; - $destpath = $upload_dir.'/'.$filenameto; - - $reshook = $hookmanager->initHooks(array('actionlinkedfiles')); - $parameters = array('filenamefrom' => $filenamefrom, 'filenameto' => $filenameto, 'upload_dir' => $upload_dir); - $reshook = $hookmanager->executeHooks('renameUploadedFile', $parameters, $object); - - if (empty($reshook)) - { - if (preg_match('/^\./', $filenameto)) { - $langs->load("errors"); // lang must be loaded because we can't rely on loading during output, we need var substitution to be done now. - setEventMessages($langs->trans("ErrorFilenameCantStartWithDot", $filenameto), null, 'errors'); - } elseif (!file_exists($destpath)) { - $result = dol_move($srcpath, $destpath); - if ($result) - { - // Define if we have to generate thumbs or not - $generatethumbs = 1; - // When we rename a file from the file manager in ecm, we must not regenerate thumbs (not a problem, we do pass here) - // When we rename a file from the website module, we must not regenerate thumbs (module = medias in such a case) - // but when we rename from a tab "Documents", we must regenerate thumbs - if (GETPOST('modulepart') == 'medias') $generatethumbs = 0; - - if ($generatethumbs) - { - if ($object->id) - { - $object->addThumbs($destpath); - } - - // TODO Add revert function of addThumbs to remove thumbs with old name - //$object->delThumbs($srcpath); - } - - setEventMessages($langs->trans("FileRenamed"), null); - } else { - $langs->load("errors"); // lang must be loaded because we can't rely on loading during output, we need var substitution to be done now. - setEventMessages($langs->trans("ErrorFailToRenameFile", $filenamefrom, $filenameto), null, 'errors'); - } - } else { - $langs->load("errors"); // lang must be loaded because we can't rely on loading during output, we need var substitution to be done now. - setEventMessages($langs->trans("ErrorDestinationAlreadyExists", $filenameto), null, 'errors'); - } - } - } - } - } - - // Update properties in ECM table - if (GETPOST('ecmfileid', 'int') > 0) - { - $shareenabled = GETPOST('shareenabled', 'alpha'); - - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; - $ecmfile = new EcmFiles($db); - $result = $ecmfile->fetch(GETPOST('ecmfileid', 'int')); - if ($result > 0) - { - if ($shareenabled) - { - if (empty($ecmfile->share)) - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; - $ecmfile->share = getRandomPassword(true); - } - } else { - $ecmfile->share = ''; - } - $result = $ecmfile->update($user); - if ($result < 0) - { - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); - } - } - } -} + if ($filenamefrom != $filenameto) + { + // Security: + // Disallow file with some extensions. We rename them. + // Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code. + if (isAFileWithExecutableContent($filenameto) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED)) + { + // $upload_dir ends with a slash, so be must be sure the medias dir to compare to ends with slash too. + $publicmediasdirwithslash = $conf->medias->multidir_output[$conf->entity]; + if (! preg_match('/\/$/', $publicmediasdirwithslash)) $publicmediasdirwithslash.='/'; + + if (strpos($upload_dir, $publicmediasdirwithslash) !== 0) { // We never add .noexe on files into media directory + $filenameto .= '.noexe'; + } + } + + if ($filenamefrom && $filenameto) + { + $srcpath = $upload_dir.'/'.$filenamefrom; + $destpath = $upload_dir.'/'.$filenameto; + + $reshook = $hookmanager->initHooks(array('actionlinkedfiles')); + $parameters = array('filenamefrom' => $filenamefrom, 'filenameto' => $filenameto, 'upload_dir' => $upload_dir); + $reshook = $hookmanager->executeHooks('renameUploadedFile', $parameters, $object); + + if (empty($reshook)) + { + if (preg_match('/^\./', $filenameto)) { + $langs->load("errors"); // lang must be loaded because we can't rely on loading during output, we need var substitution to be done now. + setEventMessages($langs->trans("ErrorFilenameCantStartWithDot", $filenameto), null, 'errors'); + } elseif (!file_exists($destpath)) { + $result = dol_move($srcpath, $destpath); + if ($result) + { + // Define if we have to generate thumbs or not + $generatethumbs = 1; + // When we rename a file from the file manager in ecm, we must not regenerate thumbs (not a problem, we do pass here) + // When we rename a file from the website module, we must not regenerate thumbs (module = medias in such a case) + // but when we rename from a tab "Documents", we must regenerate thumbs + if (GETPOST('modulepart') == 'medias') $generatethumbs = 0; + + if ($generatethumbs) + { + if ($object->id) + { + $object->addThumbs($destpath); + } + + // TODO Add revert function of addThumbs to remove thumbs with old name + //$object->delThumbs($srcpath); + } + + setEventMessages($langs->trans("FileRenamed"), null); + } + else + { + $langs->load("errors"); // lang must be loaded because we can't rely on loading during output, we need var substitution to be done now. + setEventMessages($langs->trans("ErrorFailToRenameFile", $filenamefrom, $filenameto), null, 'errors'); + } + } + else + { + $langs->load("errors"); // lang must be loaded because we can't rely on loading during output, we need var substitution to be done now. + setEventMessages($langs->trans("ErrorDestinationAlreadyExists", $filenameto), null, 'errors'); + } + } + } + } + } + + // Update properties in ECM table + if (GETPOST('ecmfileid', 'int') > 0) + { + $shareenabled = GETPOST('shareenabled', 'alpha'); + + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; + $ecmfile = new EcmFiles($db); + $result = $ecmfile->fetch(GETPOST('ecmfileid', 'int')); + if ($result > 0) + { + if ($shareenabled) + { + if (empty($ecmfile->share)) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; + $ecmfile->share = getRandomPassword(true); + } + } + else + { + $ecmfile->share = ''; + } + $result = $ecmfile->update($user); + if ($result < 0) + { + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); + } + } + } +} --- /tmp/dsg/dolibarr/htdocs/core/github_actions_massactions.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_massactions.inc.php @@ -3,7 +3,7 @@ * Copyright (C) 2018 Nicolas ZABOURI * Copyright (C) 2018 Juanjo Menent * Copyright (C) 2019 Ferran Marcet - * Copyright (C) 2019-2021 Frédéric France + * Copyright (C) 2019 Frédéric France * * 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 @@ -114,11 +114,11 @@ } } - $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid; - $listofobjectref[$thirdpartyid][$toselectid] = $objecttmp; - } - } - } + $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid; + $listofobjectref[$thirdpartyid][$toselectid] = $objecttmp; + } + } + } // Check mandatory parameters if (GETPOST('fromtype', 'alpha') === 'user' && empty($user->email)) @@ -141,7 +141,7 @@ $massaction = 'presend'; } - if (!GETPOST('subject', 'restricthtml')) + if (!GETPOST('subject', 'none')) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MailTopic")), null, 'warnings'); @@ -180,7 +180,8 @@ if ($val == 'thirdparty') // Id of third party or user { $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>'; - } elseif ($val && method_exists($thirdparty, 'contact_get_property')) // Id of contact + } + elseif ($val && method_exists($thirdparty, 'contact_get_property')) // Id of contact { $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email'); $sendtoid[] = $val; @@ -209,7 +210,8 @@ if ($val == 'thirdparty') // Id of third party { $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>'; - } elseif ($val) // Id du contact + } + elseif ($val) // Id du contact { $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email'); //$sendtoid[] = $val; TODO Add also id of contact in CC ? @@ -254,17 +256,20 @@ if ($objectobj->element == 'societe') { $sendto = $objectobj->email; - } elseif ($objectobj->element == 'expensereport') + } + elseif ($objectobj->element == 'expensereport') { $fuser = new User($db); $fuser->fetch($objectobj->fk_user_author); $sendto = $fuser->email; - } elseif ($objectobj->element == 'holiday') - { - $fuser = new User($db); - $fuser->fetch($objectobj->fk_user); - $sendto = $fuser->email; - } elseif ($objectobj->element == 'facture' && !empty($listofobjectcontacts[$objectid])) + } + elseif ($objectobj->element == 'holiday') + { + $fuser = new User($db); + $fuser->fetch($objectobj->fk_user); + $sendto = $fuser->email; + } + elseif ($objectobj->element == 'facture' && !empty($listofobjectcontacts[$objectid])) { $emails_to_sends = array(); $objectobj->fetch_thirdparty(); @@ -278,7 +283,9 @@ if (count($emails_to_sends) > 0) { $sendto = implode(',', $emails_to_sends); } - } else { + } + else + { $objectobj->fetch_thirdparty(); $sendto = $objectobj->thirdparty->email; } @@ -329,7 +336,9 @@ 'names'=>array($filename), 'mimes'=>array($mime) ); - } else { + } + else + { $nbignored++; $langs->load("errors"); $resaction .= '
'.$langs->trans('ErrorCantReadFile', $file).'

'; @@ -355,15 +364,19 @@ $fromtype = GETPOST('fromtype'); if ($fromtype === 'user') { $from = $user->getFullName($langs).' <'.$user->email.'>'; - } elseif ($fromtype === 'company') { + } + elseif ($fromtype === 'company') { $from = $conf->global->MAIN_INFO_SOCIETE_NOM.' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; - } elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { + } + elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { $tmp = explode(',', $user->email_aliases); $from = trim($tmp[($reg[1] - 1)]); - } elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { + } + elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { $tmp = explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES); $from = trim($tmp[($reg[1] - 1)]); - } elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) { + } + elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) { $sql = 'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE rowid = '.(int) $reg[1]; $resql = $db->query($sql); $obj = $db->fetch_object($resql); @@ -371,13 +384,14 @@ { $from = $obj->label.' <'.$obj->email.'>'; } - } else { + } + else { $from = $_POST['fromname'].' <'.$_POST['frommail'].'>'; } $replyto = $from; - $subject = GETPOST('subject', 'restricthtml'); - $message = GETPOST('message', 'restricthtml'); + $subject = GETPOST('subject', 'none'); + $message = GETPOST('message', 'none'); $sendtobcc = GETPOST('sendtoccc'); if ($objectclass == 'Propal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)); @@ -396,17 +410,19 @@ $looparray = $listofqualifiedobj; foreach ($looparray as $key => $objecttmp) { - $looparray[$key]->thirdparty = $thirdparty; // Force thirdparty on object - } - } else { + $looparray[$key]->thirdparty = $thirdparty; // Force thirdparty on object + } + } + else + { $objectforloop = new $objectclass($db); $objectforloop->thirdparty = $thirdparty; // Force thirdparty on object (even if object was not loaded) $looparray[0] = $objectforloop; } //var_dump($looparray);exit; - dol_syslog("We have set an array of ".count($looparray)." emails to send. oneemailperrecipient=".$oneemailperrecipient); - //var_dump($oneemailperrecipient); var_dump($listofqualifiedobj); var_dump($listofqualifiedref); - foreach ($looparray as $objectid => $objecttmp) // $objecttmp is a real object or an empty object if we choose to send one email per thirdparty instead of one per object + dol_syslog("We have set an array of ".count($looparray)." emails to send. oneemailperrecipient=".$oneemailperrecipient); + //var_dump($oneemailperrecipient); var_dump($listofqualifiedobj); var_dump($listofqualifiedref); + foreach ($looparray as $objectid => $objecttmp) // $objecttmp is a real object or an empty object if we choose to send one email per thirdparty instead of one per object { // Make substitution in email content if (!empty($conf->projet->enabled) && method_exists($objecttmp, 'fetch_projet') && is_null($objecttmp->project)) @@ -430,10 +446,10 @@ complete_substitutions_array($substitutionarray, $langs, $objecttmp, $parameters); - $subjectreplaced = make_substitutions($subject, $substitutionarray); - $messagereplaced = make_substitutions($message, $substitutionarray); - - $attachedfiles = array('paths'=>array(), 'names'=>array(), 'mimes'=>array()); + $subjectreplaced = make_substitutions($subject, $substitutionarray); + $messagereplaced = make_substitutions($message, $substitutionarray); + + $attachedfiles = array('paths'=>array(), 'names'=>array(), 'mimes'=>array()); if ($oneemailperrecipient) { // if "one email per recipient" is check we must collate $attachedfiles by thirdparty @@ -448,7 +464,8 @@ ); } } - } elseif (!empty($attachedfilesThirdpartyObj[$thirdparty->id][$objectid])) { + } + elseif (!empty($attachedfilesThirdpartyObj[$thirdparty->id][$objectid])) { // Create form object // if "one email per recipient" isn't check we must separate $attachedfiles by object $attachedfiles = $attachedfilesThirdpartyObj[$thirdparty->id][$objectid]; @@ -461,20 +478,22 @@ // Define the trackid when emails sent from the mass action if ($oneemailperrecipient) { - $trackid = 'thi'.$thirdparty->id; - if ($objecttmp->element == 'expensereport') $trackid = 'use'.$thirdparty->id; - if ($objecttmp->element == 'holiday') $trackid = 'use'.$thirdparty->id; - } else { - $trackid = strtolower(get_class($objecttmp)); - if (get_class($objecttmp) == 'Contrat') $trackid = 'con'; - if (get_class($objecttmp) == 'Propal') $trackid = 'pro'; - if (get_class($objecttmp) == 'Commande') $trackid = 'ord'; - if (get_class($objecttmp) == 'Facture') $trackid = 'inv'; - if (get_class($objecttmp) == 'Supplier_Proposal') $trackid = 'spr'; - if (get_class($objecttmp) == 'CommandeFournisseur') $trackid = 'sor'; - if (get_class($objecttmp) == 'FactureFournisseur') $trackid = 'sin'; - - $trackid .= $objecttmp->id; + $trackid = 'thi'.$thirdparty->id; + if ($objecttmp->element == 'expensereport') $trackid = 'use'.$thirdparty->id; + if ($objecttmp->element == 'holiday') $trackid = 'use'.$thirdparty->id; + } + else + { + $trackid = strtolower(get_class($objecttmp)); + if (get_class($objecttmp) == 'Contrat') $trackid = 'con'; + if (get_class($objecttmp) == 'Propal') $trackid = 'pro'; + if (get_class($objecttmp) == 'Commande') $trackid = 'ord'; + if (get_class($objecttmp) == 'Facture') $trackid = 'inv'; + if (get_class($objecttmp) == 'Supplier_Proposal') $trackid = 'spr'; + if (get_class($objecttmp) == 'CommandeFournisseur') $trackid = 'sor'; + if (get_class($objecttmp) == 'FactureFournisseur') $trackid = 'sin'; + + $trackid .= $objecttmp->id; } //var_dump($filepath); //var_dump($trackid);exit; @@ -483,12 +502,14 @@ if (empty($sendcontext)) $sendcontext = 'standard'; // Send mail (substitutionarray must be done just before this) - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subjectreplaced, $sendto, $from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid, '', $sendcontext); + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($subjectreplaced, $sendto, $from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid, '', $sendcontext); if ($mailfile->error) { $resaction .= '
'.$mailfile->error.'
'; - } else { + } + else + { $result = $mailfile->sendfile(); if ($result) { @@ -497,11 +518,11 @@ $error = 0; // Insert logs into agenda - foreach ($listofqualifiedobj as $objid2 => $objectobj2) + foreach ($listofqualifiedobj as $objid2 => $objectobj2) { - if ((!$oneemailperrecipient) && $objid2 != $objectid) continue; // We discard this pass to avoid duplicate with other pass in looparray at higher level - - dol_syslog("Try to insert email event into agenda for objid=".$objid2." => objectobj=".get_class($objectobj2)); + if ((!$oneemailperrecipient) && $objid2 != $objectid) continue; // We discard this pass to avoid duplicate with other pass in looparray at higher level + + dol_syslog("Try to insert email event into agenda for objid=".$objid2." => objectobj=".get_class($objectobj2)); /*if ($objectclass == 'Propale') $actiontypecode='AC_PROP'; if ($objectclass == 'Commande') $actiontypecode='AC_COM'; @@ -514,18 +535,18 @@ if ($message) { if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc); - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subjectreplaced); + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subjectreplaced); $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":"); - $actionmsg = dol_concatdesc($actionmsg, $messagereplaced); + $actionmsg = dol_concatdesc($actionmsg, $messagereplaced); } $actionmsg2 = ''; - // Initialisation donnees - $objectobj2->sendtoid = (empty($contactidtosend) ? 0 : $contactidtosend); - $objectobj2->actionmsg = $actionmsg; // Long text - $objectobj2->actionmsg2 = $actionmsg2; // Short text - $objectobj2->fk_element = $objid2; - $objectobj2->elementtype = $objectobj2->element; + // Initialisation donnees + $objectobj2->sendtoid = (empty($contactidtosend) ? 0 : $contactidtosend); + $objectobj2->actionmsg = $actionmsg; // Long text + $objectobj2->actionmsg2 = $actionmsg2; // Short text + $objectobj2->fk_element = $objid2; + $objectobj2->elementtype = $objectobj2->element; $triggername = strtoupper(get_class($objectobj2)).'_SENTBYMAIL'; if ($triggername == 'SOCIETE_SENTBYMAIL') $triggername = 'COMPANY_SENTBYMAIL'; @@ -553,13 +574,17 @@ $nbsent++; // Nb of object sent } - } else { + } + else + { $langs->load("other"); if ($mailfile->error) { $resaction .= $langs->trans('ErrorFailedToSendMail', $from, $sendto); $resaction .= '
'.$mailfile->error.'
'; - } else { + } + else + { $resaction .= '
No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS
'; } } @@ -580,7 +605,9 @@ //setEventMessages($langs->trans("EMailSentToNRecipients", $nbsent.'/'.count($toselect)), null, 'mesgs'); setEventMessages($langs->trans("EMailSentForNElements", $nbsent.'/'.count($toselect)), null, 'mesgs'); setEventMessages($resaction, null, 'mesgs'); - } else { + } + else + { //setEventMessages($langs->trans("EMailSentToNRecipients", 0), null, 'warnings'); // May be object has no generated PDF file setEventMessages($resaction, null, 'warnings'); } @@ -615,17 +642,17 @@ $cmd->fetch_optionals(); $objecttmp->socid = $cmd->socid; - $objecttmp->type = $objecttmp::TYPE_STANDARD; + $objecttmp->type = Facture::TYPE_STANDARD; $objecttmp->cond_reglement_id = $cmd->cond_reglement_id; $objecttmp->mode_reglement_id = $cmd->mode_reglement_id; $objecttmp->fk_project = $cmd->fk_project; - $objecttmp->multicurrency_code = $cmd->multicurrency_code; - if (empty($createbills_onebythird)) $objecttmp->ref_client = $cmd->ref_client; - - $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); - if (empty($datefacture)) - { - $datefacture = dol_now(); + $objecttmp->multicurrency_code = $cmd->multicurrency_code; + if (empty($createbills_onebythird)) $objecttmp->ref_client = $cmd->ref_client; + + $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); + if (empty($datefacture)) + { + $datefacture = dol_now(); } $objecttmp->date = $datefacture; @@ -648,9 +675,9 @@ $sql .= ", targettype"; $sql .= ") VALUES ("; $sql .= $id_order; - $sql .= ", '".$db->escape($objecttmp->origin)."'"; + $sql .= ", '".$objecttmp->origin."'"; $sql .= ", ".$objecttmp->id; - $sql .= ", '".$db->escape($objecttmp->element)."'"; + $sql .= ", '".$objecttmp->element."'"; $sql .= ")"; if (!$db->query($sql)) @@ -676,7 +703,7 @@ // If we build one invoice for several order, we must put the invoice of order on the line if (!empty($createbills_onebythird)) { - $desc = dol_concatdesc($desc, $langs->trans("Order").' '.$cmd->ref.' - '.dol_print_date($cmd->date, 'day')); + $desc = dol_concatdesc($desc, $langs->trans("Order").' '.$cmd->ref.' - '.dol_print_date($cmd->date, 'day')); } if ($lines[$i]->subprice < 0) @@ -695,12 +722,16 @@ { $result = $objecttmp->insert_discount($discountid); //$result=$discount->link_to_invoice($lineid,$id); - } else { + } + else + { setEventMessages($discount->error, $discount->errors, 'errors'); $error++; break; } - } else { + } + else + { // Positive line $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0); // Date start @@ -742,7 +773,7 @@ 'HT', 0, $product_type, - $lines[$i]->rang, + $ii, $lines[$i]->special_code, $objecttmp->origin, $lines[$i]->rowid, @@ -758,7 +789,9 @@ if ($result > 0) { $lineid = $result; - } else { + } + else + { $lineid = 0; $error++; break; @@ -807,7 +840,7 @@ // Call action to build doc $savobject = $object; - $object = $objecttmp; + $object = $objecttmp; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; $object = $savobject; } @@ -818,7 +851,7 @@ if (!$error) { $db->commit(); - setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs'); + setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs'); // Make a redirect to avoid to bill twice if we make a refresh or back $param = ''; @@ -848,7 +881,9 @@ header("Location: ".$_SERVER['PHP_SELF'].'?'.$param); exit; - } else { + } + else + { $db->rollback(); $action = 'create'; $_GET["origin"] = $_POST["origin"]; @@ -888,15 +923,20 @@ setEventMessages($cmd->error, $cmd->errors, 'errors'); $error++; break; - } else $nbok++; + } + else + $nbok++; } if (!$error) { if ($nbok > 1) setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); - else setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); + else + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); $db->commit(); - } else { + } + else + { $db->rollback(); } } @@ -989,23 +1029,25 @@ $input_files .= ' '.escapeshellarg($f); } - $cmd = 'pdftk '.$input_files.' cat output '.escapeshellarg($file); + $cmd = 'pdftk ' . $input_files . ' cat output '.escapeshellarg($file); exec($cmd); // check if pdftk is installed if (file_exists($file)) { if (!empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); - $langs->load("exports"); setEventMessages($langs->trans('FileSuccessfullyBuilt', $filename.'_'.dol_print_date($now, 'dayhourlog')), null, 'mesgs'); } else { setEventMessages($langs->trans('ErrorPDFTkOutputFileNotFound'), null, 'errors'); } - } else { + } + else + { setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors'); } - } else { + } + else { // Create empty PDF $formatarray = pdf_getFormat(); $page_largeur = $formatarray['width']; @@ -1062,8 +1104,10 @@ $langs->load("exports"); setEventMessages($langs->trans('FileSuccessfullyBuilt', $filename.'_'.dol_print_date($now, 'dayhourlog')), null, 'mesgs'); - } else { - setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors'); + } + else + { + setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors'); } } } @@ -1082,7 +1126,6 @@ $action = ''; } - // Validate records if (!$error && $massaction == 'validate' && $permissiontoadd) { @@ -1111,48 +1154,23 @@ if ($result > 0) { $result = $objecttmp->validate($user); - if ($result == 0) { + if ($result == 0) + { $langs->load("errors"); setEventMessages($langs->trans("ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref), null, 'errors'); $error++; break; - } elseif ($result < 0) { + } + elseif ($result < 0) + { setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); $error++; break; - } else { - // validate() rename pdf but do not regenerate - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { - $newlang = $objecttmp->thirdparty->default_lang; - } - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - $outputlangs->load('products'); - } - $model = $objecttmp->model_pdf; - $ret = $objecttmp->fetch($objecttmp->id); // Reload to get new records - // To be sure vars is defined - $hidedetails = !empty($hidedetails) ? $hidedetails : 0; - $hidedesc = !empty($hidedesc) ? $hidedesc : 0; - $hideref = !empty($hideref) ? $hideref : 0; - $moreparams = !empty($moreparams) ? $moreparams : null; - - $result = $objecttmp->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result < 0) { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - } - } - $nbok++; - } - } else { + } + else $nbok++; + } + else + { setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); $error++; break; @@ -1164,7 +1182,9 @@ if ($nbok > 1) setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); else setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); $db->commit(); - } else { + } + else + { $db->rollback(); } //var_dump($listofobjectthirdparties);exit; @@ -1173,37 +1193,40 @@ // Closed records if (!$error && $massaction == 'closed' && $objectclass == "Propal" && $permissiontoclose) { - $db->begin(); - - $objecttmp = new $objectclass($db); - $nbok = 0; - foreach ($toselect as $toselectid) { - $result = $objecttmp->fetch($toselectid); - if ($result > 0) { - $result = $objecttmp->cloture($user, 3); - if ($result <= 0) { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } else $nbok++; - } else { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } - } - - if (!$error) { - if ($nbok > 1) - setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); - else setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); - $db->commit(); - } else { - $db->rollback(); - } + $db->begin(); + + $objecttmp = new $objectclass($db); + $nbok = 0; + foreach ($toselect as $toselectid) { + $result = $objecttmp->fetch($toselectid); + if ($result > 0) { + $result = $objecttmp->cloture($user, 3); + if ($result <= 0) { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } else + $nbok++; + } + else { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + } + + if (!$error) { + if ($nbok > 1) + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); + else + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); + $db->commit(); + } + else { + $db->rollback(); + } } -//var_dump($_POST);var_dump($massaction);exit; // Delete record from mass action (massaction = 'delete' for direct delete, action/confirm='delete'/'yes' with a confirmation step before) if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete) @@ -1243,11 +1266,14 @@ if ($result <= 0) { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } else $nbok++; - } else { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + else $nbok++; + } + else + { setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); $error++; break; @@ -1259,7 +1285,9 @@ if ($nbok > 1) setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); else setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs'); $db->commit(); - } else { + } + else + { $db->rollback(); } //var_dump($listofobjectthirdparties);exit; @@ -1269,56 +1297,61 @@ // @todo : propose model selection if (!$error && $massaction == 'generate_doc' && $permissiontoread) { - $db->begin(); - - $objecttmp = new $objectclass($db); - $nbok = 0; - foreach ($toselect as $toselectid) - { - $result = $objecttmp->fetch($toselectid); - if ($result > 0) - { - $outputlangs = $langs; - $newlang = ''; - - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) $newlang = $objecttmp->thirdparty->default_lang; // for proposal, order, invoice, ... - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->default_lang)) $newlang = $objecttmp->default_lang; // for thirdparty - if (!empty($newlang)) - { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - - // To be sure vars is defined - if (empty($hidedetails)) $hidedetails = 0; - if (empty($hidedesc)) $hidedesc = 0; - if (empty($hideref)) $hideref = 0; - if (empty($moreparams)) $moreparams = null; - - $result = $objecttmp->generateDocument($objecttmp->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); - - if ($result <= 0) - { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } else $nbok++; - } else { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } - } - - if (!$error) - { - if ($nbok > 1) setEventMessages($langs->trans("RecordsGenerated", $nbok), null, 'mesgs'); - else setEventMessages($langs->trans("RecordGenerated", $nbok), null, 'mesgs'); - $db->commit(); - } else { - $db->rollback(); - } + $db->begin(); + + $objecttmp = new $objectclass($db); + $nbok = 0; + foreach ($toselect as $toselectid) + { + $result = $objecttmp->fetch($toselectid); + if ($result > 0) + { + $outputlangs = $langs; + $newlang = ''; + + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) $newlang = $objecttmp->thirdparty->default_lang; // for proposal, order, invoice, ... + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->default_lang)) $newlang = $objecttmp->default_lang; // for thirdparty + if (!empty($newlang)) + { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + + // To be sure vars is defined + if (empty($hidedetails)) $hidedetails = 0; + if (empty($hidedesc)) $hidedesc = 0; + if (empty($hideref)) $hideref = 0; + if (empty($moreparams)) $moreparams = null; + + $result = $objecttmp->generateDocument($objecttmp->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); + + if ($result <= 0) + { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + else $nbok++; + } + else + { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + } + + if (!$error) + { + if ($nbok > 1) setEventMessages($langs->trans("RecordsGenerated", $nbok), null, 'mesgs'); + else setEventMessages($langs->trans("RecordGenerated", $nbok), null, 'mesgs'); + $db->commit(); + } + else + { + $db->rollback(); + } } $parameters['toselect'] = $toselect; --- /tmp/dsg/dolibarr/htdocs/core/github_actions_printing.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_printing.inc.php @@ -33,24 +33,18 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php'; $objectprint = new PrintingDriver($db); $list = $objectprint->listDrivers($db, 10); - $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']); if (!empty($list)) { $errorprint = 0; $printerfound = 0; foreach ($list as $driver) { - foreach ($dirmodels as $dir) { - if (file_exists(dol_buildpath($dir, 0).$driver.'.modules.php')) { - $classfile = dol_buildpath($dir, 0).$driver.'.modules.php'; - break; - } - } - require_once $classfile; + require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php'; + $langs->load($driver); $classname = 'printing_'.$driver; $printer = new $classname($db); - $langs->load($printer::LANGFILE); //print '
'.print_r($printer, true).'
'; - if (!empty($conf->global->{$printer->active})) { + if (!empty($conf->global->{$printer->active})) + { $printerfound++; $subdir = ''; @@ -81,7 +75,8 @@ setEventMessages($printer->error, $printer->errors); setEventMessages($langs->transnoentitiesnoconv("FileWasSentToPrinter", basename(GETPOST('file', 'alpha'))).' '.$langs->transnoentitiesnoconv("ViaModule").' '.$printer->name, null); } - } catch (Exception $e) + } + catch (Exception $e) { $ret = 1; setEventMessages($e->getMessage(), null, 'errors'); --- /tmp/dsg/dolibarr/htdocs/core/github_actions_sendmails.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_sendmails.inc.php @@ -114,43 +114,44 @@ $result = $object->fetch($id); $sendtosocid = 0; // Id of related thirdparty - if (method_exists($object, "fetch_thirdparty") && !in_array($object->element, array('member', 'user', 'expensereport', 'societe', 'contact'))) - { - $resultthirdparty = $object->fetch_thirdparty(); + if (method_exists($object, "fetch_thirdparty") && !in_array($object->element, array('societe', 'member', 'user', 'expensereport', 'contact'))) + { + $result = $object->fetch_thirdparty(); + if ($object->element == 'user' && $result == 0) $result = 1; // Even if not found, we consider ok $thirdparty = $object->thirdparty; - if (is_object($thirdparty)) $sendtosocid = $thirdparty->id; - } elseif ($object->element == 'member' || $object->element == 'user') + $sendtosocid = $thirdparty->id; + } + elseif ($object->element == 'member' || $object->element == 'user') { $thirdparty = $object; if ($object->socid > 0) $sendtosocid = $object->socid; - } elseif ($object->element == 'expensereport') + } + elseif ($object->element == 'expensereport') { $tmpuser = new User($db); $tmpuser->fetch($object->fk_user_author); $thirdparty = $tmpuser; if ($object->socid > 0) $sendtosocid = $object->socid; - } elseif ($object->element == 'societe') + } + elseif ($object->element == 'societe') { $thirdparty = $object; - if (is_object($thirdparty) && $thirdparty->id > 0) $sendtosocid = $thirdparty->id; - } elseif ($object->element == 'contact') + if ($thirdparty->id > 0) $sendtosocid = $thirdparty->id; + } + elseif ($object->element == 'contact') { $contact = $object; - if ($contact->id > 0) { - $contact->fetch_thirdparty(); - $thirdparty = $contact->thirdparty; - if (is_object($thirdparty) && $thirdparty->id > 0) $sendtosocid = $thirdparty->id; - } - } else dol_print_error('', "Use actions_sendmails.in.php for an element/object '".$object->element."' that is not supported"); + if ($contact->id > 0) $sendtosocid = $contact->fetch_thirdparty()->id; + } + else dol_print_error('', "Use actions_sendmails.in.php for an element/object '".$object->element."' that is not supported"); if (is_object($hookmanager)) { $parameters = array(); $reshook = $hookmanager->executeHooks('initSendToSocid', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks } - } else { - $thirdparty = $mysoc; } + else $thirdparty = $mysoc; if ($result > 0) { @@ -175,24 +176,24 @@ // Recipients are provided into free text $tmparray[] = trim($_POST['sendto']); } - if (count($receiver) > 0) { - // Recipient was provided from combo list foreach ($receiver as $key=>$val) { - if ($val == 'thirdparty') // Key selected means current third party ('thirdparty' may be used for current member or current user too) + // Recipient was provided from combo list + if ($val == 'thirdparty') // Key selected means currentthird party (may be usd for current member or current user too) { $tmparray[] = dol_string_nospecial($thirdparty->getFullName($langs), ' ', array(",")).' <'.$thirdparty->email.'>'; } + // Recipient was provided from combo list elseif ($val == 'contact') // Key selected means current contact { $tmparray[] = dol_string_nospecial($contact->getFullName($langs), ' ', array(",")).' <'.$contact->email.'>'; - $sendtoid[] = $contact->id; - } elseif ($val) // $val is the Id of a contact + } + elseif ($val) // $val is the Id of a contact { $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email'); - $sendtoid[] = ((int) $val); + $sendtoid[] = $val; } } } @@ -238,11 +239,11 @@ elseif ($val == 'contact') // Key selected means current contact { $tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>'; - //$sendtoid[] = $contact->id; TODO Add also id of contact in CC ? - } elseif ($val) // $val is the Id of a contact + } + elseif ($val) // $val is the Id of a contact { $tmparray[] = $thirdparty->contact_get_property((int) $val, 'email'); - //$sendtoid[] = ((int) $val); TODO Add also id of contact in CC ? + //$sendtoid[] = $val; TODO Add also id of contact in CC ? } } } @@ -263,12 +264,12 @@ if (dol_strlen($sendto)) { - // Define $urlwithroot - $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); - $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file - //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current - - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + // Define $urlwithroot + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current + + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; $langs->load("commercial"); @@ -276,17 +277,22 @@ $fromtype = GETPOST('fromtype', 'alpha'); if ($fromtype === 'robot') { $from = dol_string_nospecial($conf->global->MAIN_MAIL_EMAIL_FROM, ' ', array(",")).' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.'>'; - } elseif ($fromtype === 'user') { + } + elseif ($fromtype === 'user') { $from = dol_string_nospecial($user->getFullName($langs), ' ', array(",")).' <'.$user->email.'>'; - } elseif ($fromtype === 'company') { + } + elseif ($fromtype === 'company') { $from = dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM, ' ', array(",")).' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; - } elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { + } + elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { $tmp = explode(',', $user->email_aliases); $from = trim($tmp[($reg[1] - 1)]); - } elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { + } + elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { $tmp = explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES); $from = trim($tmp[($reg[1] - 1)]); - } elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) { + } + elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) { $sql = 'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile'; $sql .= ' WHERE rowid = '.(int) $reg[1]; $resql = $db->query($sql); @@ -295,13 +301,14 @@ { $from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>'; } - } else { + } + else { $from = dol_string_nospecial($_POST['fromname'], ' ', array(",")).' <'.$_POST['frommail'].'>'; } $replyto = dol_string_nospecial($_POST['replytoname'], ' ', array(",")).' <'.$_POST['replytomail'].'>'; - $message = GETPOST('message', 'restricthtml'); - $subject = GETPOST('subject', 'restricthtml'); + $message = GETPOST('message', 'none'); + $subject = GETPOST('subject', 'none'); // Make a change into HTML code to allow to include images from medias directory with an external reabable URL. // @@ -321,7 +328,7 @@ if ($action == 'send' || $action == 'relance') { - $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('at').' '.CMailFile::getValidAddress($sendto, 4, 0, 1); + $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto, 4, 0, 1); if ($message) { $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from); @@ -412,17 +419,19 @@ { setEventMessages($mailfile->error, $mailfile->errors, 'errors'); $action = 'presend'; - } else { + } + else + { $result = $mailfile->sendfile(); if ($result) { // Initialisation of datas of object to call trigger if (is_object($object)) { - if (empty($actiontypecode)) $actiontypecode = 'AC_OTH_AUTO'; // Event insert into agenda automatically + if (empty($actiontypecode)) $actiontypecode = 'AC_OTH_AUTO'; // Event insert into agenda automatically $object->socid = $sendtosocid; // To link to a company - $object->sendtoid = $sendtoid; // To link to contact-addresses. This is an array. + $object->sendtoid = $sendtoid; // To link to contact addresses. This is an array. $object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) $object->actionmsg = $actionmsg; // Long text (@todo Replace this with $message, we already have details of email in dedicated properties) $object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...); @@ -456,7 +465,7 @@ if ($error) { setEventMessages($object->error, $object->errors, 'errors'); - } + } } // End call of triggers } @@ -470,19 +479,19 @@ if (isset($paramname2) || isset($paramval2)) $moreparam .= '&'.($paramname2 ? $paramname2 : 'mid').'='.$paramval2; header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname ? $paramname : 'id').'='.(is_object($object) ? $object->id : '').$moreparam); exit; - } else { + } + else + { $langs->load("other"); $mesg = '
'; - if ($mailfile->error) { + if ($mailfile->error) + { $mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto)); $mesg .= '
'.$mailfile->error; - } else { - $mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto)); - if (!empty($conf->global->MAIN_DISABLE_ALL_MAILS)) { - $mesg .= '
Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; - } else { - $mesg .= '
Unkown Error, please refers to your administrator'; - } + } + else + { + $mesg .= 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; } $mesg .= '
'; @@ -490,14 +499,18 @@ $action = 'presend'; } } - } else { + } + else + { $langs->load("errors"); setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("MailTo")), null, 'warnings'); dol_syslog('Try to send email with no recipient defined', LOG_WARNING); $action = 'presend'; } - } else { - $langs->load("errors"); + } + else + { + $langs->load("other"); setEventMessages($langs->trans('ErrorFailedToReadObject', $object->element), null, 'errors'); dol_syslog('Failed to read data of object id='.$object->id.' element='.$object->element); $action = 'presend'; --- /tmp/dsg/dolibarr/htdocs/core/github_actions_setmoduleoptions.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_setmoduleoptions.inc.php @@ -21,7 +21,7 @@ * \brief Code for actions on setting notes of object page */ -// $error must have been initialized to 0 + // $action must be defined // $arrayofparameters must be set for action 'update' // $nomessageinupdate can be set to 1 @@ -31,17 +31,18 @@ { $db->begin(); + $ok = true; foreach ($arrayofparameters as $key => $val) { // Modify constant only if key was posted (avoid resetting key to the null value) if (GETPOSTISSET($key)) { $result = dolibarr_set_const($db, $key, GETPOST($key, 'alpha'), 'chaine', 0, '', $conf->entity); - if ($result < 0) - { - $error++; - break; - } + if ($result < 0) + { + $ok = false; + break; + } } } @@ -49,7 +50,9 @@ { $db->commit(); if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } else { + } + else + { $db->rollback(); if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); } @@ -58,62 +61,61 @@ // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) if ($action == 'setModuleOptions') { - $db->begin(); + $db->begin(); - // Process common param fields - if (is_array($_POST)) - { - foreach ($_POST as $key => $val) - { - $reg = array(); - if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ... - { - $param = GETPOST("param".$reg[1], 'alpha'); - $value = GETPOST("value".$reg[1], 'alpha'); - if ($param) - { - $res = dolibarr_set_const($db, $param, $value, 'chaine', 0, '', $conf->entity); - if (!($res > 0)) $error++; - } - } - } - } + // Process common param fields + if (is_array($_POST)) + { + foreach ($_POST as $key => $val) + { + $reg = array(); + if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ... + { + $param = GETPOST("param".$reg[1], 'alpha'); + $value = GETPOST("value".$reg[1], 'alpha'); + if ($param) + { + $res = dolibarr_set_const($db, $param, $value, 'chaine', 0, '', $conf->entity); + if (!$res > 0) $error++; + } + } + } + } - // Process upload fields - if (GETPOST('upload', 'alpha') && GETPOST('keyforuploaddir', 'aZ09')) - { - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $keyforuploaddir = GETPOST('keyforuploaddir', 'aZ09'); - $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->$keyforuploaddir))); - foreach ($listofdir as $key=>$tmpdir) - { - $tmpdir = trim($tmpdir); - $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); - if (!$tmpdir) { - unset($listofdir[$key]); continue; - } - if (!is_dir($tmpdir)) { - if (empty($nomessageinsetmoduleoptions)) { - setEventMessages($langs->trans("ErrorDirNotFound", $tmpdir), null, 'warnings'); - } - } - else { - $upload_dir = $tmpdir; - } - } - if ($upload_dir) - { - $result = dol_add_file_process($upload_dir, 1, 1, 'uploadfile', ''); - if ($result <= 0) $error++; - } - } + // Process upload fields + if (GETPOST('upload', 'alpha') && GETPOST('keyforuploaddir', 'aZ09')) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $keyforuploaddir = GETPOST('keyforuploaddir', 'aZ09'); + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->$keyforuploaddir))); + foreach ($listofdir as $key=>$tmpdir) + { + $tmpdir = trim($tmpdir); + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); + if (!$tmpdir) { + unset($listofdir[$key]); continue; + } + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); + else + { + $upload_dir = $tmpdir; + } + } + if ($upload_dir) + { + $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', ''); + if ($result <= 0) $error++; + } + } - if (!$error) - { - $db->commit(); - if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } else { - $db->rollback(); - if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); - } + if (!$error) + { + $db->commit(); + if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + $db->rollback(); + if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); + } } --- /tmp/dsg/dolibarr/htdocs/core/github_actions_setnotes.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_setnotes.inc.php @@ -33,7 +33,7 @@ if (empty($action) || !is_object($object) || empty($id)) dol_print_error('', 'Include of actions_setnotes.inc.php was done but required variable was not set before'); if (empty($object->id)) $object->fetch($id); // Fetch may not be already done - $result_update = $object->update_note(dol_html_entity_decode(GETPOST('note_public', 'restricthtml'), ENT_QUOTES | ENT_HTML5, 'UTF-8', 1), '_public'); + $result_update = $object->update_note(dol_html_entity_decode(GETPOST('note_public', 'none'), ENT_QUOTES, 'UTF-8', 1), '_public'); if ($result_update < 0) setEventMessages($object->error, $object->errors, 'errors'); elseif (in_array($object->table_element, array('supplier_proposal', 'propal', 'commande_fournisseur', 'commande', 'facture_fourn', 'facture'))) @@ -49,7 +49,7 @@ $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } - $model = $object->model_pdf; + $model = $object->modelpdf; $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); @@ -63,6 +63,6 @@ // Set public note if (empty($action) || !is_object($object) || empty($id)) dol_print_error('', 'Include of actions_setnotes.inc.php was done but required variable was not set before'); if (empty($object->id)) $object->fetch($id); // Fetch may not be already done - $result = $object->update_note(dol_html_entity_decode(GETPOST('note_private', 'restricthtml'), ENT_QUOTES | ENT_HTML5), '_private'); + $result = $object->update_note(dol_html_entity_decode(GETPOST('note_private', 'none'), ENT_QUOTES), '_private'); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } --- /tmp/dsg/dolibarr/htdocs/core/github_commonfieldsinexport.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_commonfieldsinexport.inc.php @@ -2,9 +2,9 @@ if (empty($keyforclass) || empty($keyforclassfile) || empty($keyforelement)) { - //print $keyforclass.' - '.$keyforclassfile.' - '.$keyforelement; - dol_print_error('', 'include of file commonfieldsinexport.inc.php was done but var $keyforclass or $keyforclassfile or $keyforelement was not set'); - exit; + //print $keyforclass.' - '.$keyforclassfile.' - '.$keyforelement; + dol_print_error('', 'include of file commonfieldsinexport.inc.php was done but var $keyforclass or $keyforclassfile or $keyforelement was not set'); + exit; } if (empty($keyforalias)) $keyforalias = 't'; @@ -58,7 +58,9 @@ $this->export_help_array[$r][$fieldname] = $helpfield; } } -} else { +} +else +{ dol_print_error($this->db, 'Failed to find class '.$keyforclass.', even after the include of '.$keyforclassfile); } // End add common fields --- /tmp/dsg/dolibarr/htdocs/core/github_customreports.php +++ /tmp/dsg/dolibarr/htdocs/core/client_customreports.php @@ -54,8 +54,8 @@ // Load variable for pagination $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; - $sortfield = GETPOST('sortfield', 'aZ09comma'); - $sortorder = GETPOST('sortorder', 'aZ09comma'); + $sortfield = GETPOST('sortfield', 'alpha'); + $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action $offset = $limit * $page; @@ -115,23 +115,24 @@ } if (!empty($hookmanager->resArray['arrayoftype'])) { // Add entries from hook foreach ($hookmanager->resArray['arrayoftype'] as $key => $val) { - $arrayoftype[$key] = $val; - } + $arrayoftype[$key] = $val; + } } } if ($objecttype) { - try { - if (!empty($arrayoftype[$objecttype]['ClassPath'])) { - dol_include_once($arrayoftype[$objecttype]['ClassPath']); - } else { - dol_include_once("/".$objecttype."/class/".$objecttype.".class.php"); - } - $ObjectClassName = $arrayoftype[$objecttype]['ObjectClassName']; - $object = new $ObjectClassName($db); - } catch (Exception $e) { - print 'Failed to load class for type '.$objecttype; - } + try { + if (!empty($arrayoftype[$objecttype]['ClassPath'])) { + dol_include_once($arrayoftype[$objecttype]['ClassPath']); + } else { + dol_include_once("/".$objecttype."/class/".$objecttype.".class.php"); + } + $ObjectClassName = $arrayoftype[$objecttype]['ObjectClassName']; + $object = new $ObjectClassName($db); + } + catch (Exception $e) { + print 'Failed to load class for type '.$objecttype; + } } // Security check @@ -188,7 +189,7 @@ if (!defined('USE_CUSTOME_REPORT_AS_INCLUDE')) { llxHeader('', $langs->transnoentitiesnoconv('CustomReports'), ''); - print dol_get_fiche_head($head, 'customreports', $title, -1, $picto); + dol_fiche_head($head, 'customreports', $title, -1, $picto); } // Check parameters @@ -251,10 +252,12 @@ if (is_null($obj->val)) { $keytouse = '__NULL__'; $valuetranslated = $langs->transnoentitiesnoconv("NotDefined"); - } elseif ($obj->val === '') { + } + elseif ($obj->val === '') { $keytouse = ''; $valuetranslated = $langs->transnoentitiesnoconv("Empty"); - } else { + } + else { $keytouse = (string) $obj->val; $valuetranslated = $obj->val; } @@ -264,7 +267,8 @@ $valuetranslated = $object->fields[$gvalwithoutprefix]['arrayofkeyval'][$obj->val]; if (is_null($valuetranslated)) $valuetranslated = $langs->transnoentitiesnoconv("UndefinedKey"); $valuetranslated = $langs->trans($valuetranslated); - } elseif (preg_match('/integer:([^:]+):([^:]+)$/', $object->fields[$gvalwithoutprefix]['type'], $regs)) { + } + elseif (preg_match('/integer:([^:]+):([^:]+)$/', $object->fields[$gvalwithoutprefix]['type'], $regs)) { $classname = $regs[1]; $classpath = $regs[2]; dol_include_once($classpath); @@ -288,17 +292,9 @@ if (count($arrayofvaluesforgroupby['g_'.$gkey]) > $MAXUNIQUEVALFORGROUP) { $langs->load("errors"); - if (strpos($fieldtocount, 'te.') === 0) { - //if (!empty($extrafields->attributes[$object->table_element]['langfile'][$gvalwithoutprefix])) { - // $langs->load($extrafields->attributes[$object->table_element]['langfile'][$gvalwithoutprefix]); - //} - $keyforlabeloffield = $extrafields->attributes[$object->table_element]['label'][$gvalwithoutprefix]; - } else { - $keyforlabeloffield = $object->fields[$gvalwithoutprefix]['label']; - } //var_dump($gkey.' '.$gval.' '.$gvalwithoutprefix); $gvalwithoutprefix = preg_replace('/\-(year|month|day)/', '', $gvalwithoutprefix); - $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield); + $labeloffield = $langs->transnoentitiesnoconv($object->fields[$gvalwithoutprefix]['label']); setEventMessages($langs->trans("ErrorTooManyDifferentValueForSelectedGroupBy", $MAXUNIQUEVALFORGROUP, $labeloffield), null, 'warnings'); $search_groupby = array(); } @@ -318,7 +314,7 @@ $param = ''; print '
'; -print ''; +print ''; print ''; print ''; @@ -339,7 +335,7 @@ print $form->selectarray('objecttype', $newarrayoftype, $objecttype, 0, 0, 0, '', 1, 0, 0, '', 'minwidth200', 1); if (empty($conf->use_javascript_ajax)) print ''; else { - print ''."\n"; -} else { +} +else +{ print ''.$langs->trans("Calendar").''; } @@ -107,7 +109,9 @@ { //print $_GET["cm"].",".$_GET["sd"].",".$_GET["m"].",".$_GET["y"];exit; displayBox(GETPOST("sd", 'alpha'), GETPOST("m", 'int'), GETPOST("y", 'int')); -} else { +} +else +{ dol_print_error('', 'ErrorBadParameters'); } @@ -150,7 +154,9 @@ { $selDate = xyzToUnixTimestamp($selectedDate); $xyz = dol_print_date($selDate, "%Y%m%d"); - } else { + } + else + { $selDate = 0; $xyz = 0; } @@ -214,7 +220,9 @@ echo " "; $cols++; } - } else { + } + else + { if ($mydate["wday"] == $startday) { echo ""; @@ -247,7 +255,9 @@ if ($thedate == '') { $stoploop = 1; - } else { + } + else + { $mydate = dol_getdate($thedate); if ($firstdate["month"] != $mydate["month"]) $stoploop = 1; } @@ -267,7 +277,9 @@ print $langs->trans("Month".$selectMonth)." "; print sprintf("%02s", $tempDate["mday"]); print ", ".$selectYear; - } else { + } + else + { print "Click a Date"; } ?> --- /tmp/dsg/dolibarr/htdocs/core/github_extrafieldsinexport.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_extrafieldsinexport.inc.php @@ -2,14 +2,13 @@ if (empty($keyforselect) || empty($keyforelement) || empty($keyforaliasextra)) { - //print $keyforselet.' - '.$keyforelement.' - '.$keyforaliasextra; - dol_print_error('', 'include of file extrafieldsinexport.inc.php was done but var $keyforselect or $keyforelement or $keyforaliasextra was not set'); - exit; + //print $keyforselet.' - '.$keyforelement.' - '.$keyforaliasextra; + dol_print_error('', 'include of file extrafieldsinexport.inc.php was done but var $keyforselect or $keyforelement or $keyforaliasextra was not set'); + exit; } // Add extra fields -$sql = "SELECT name, label, type, param, fieldcomputed, fielddefault FROM ".MAIN_DB_PREFIX."extrafields"; -$sql .= " WHERE elementtype = '".$this->db->escape($keyforselect)."' AND type != 'separate' AND entity IN (0, ".$conf->entity.') ORDER BY pos ASC'; +$sql = "SELECT name, label, type, param, fieldcomputed, fielddefault FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = '".$keyforselect."' AND type != 'separate' AND entity IN (0, ".$conf->entity.') ORDER BY pos ASC'; //print $sql; $resql = $this->db->query($sql); if ($resql) // This can fail when class is used on old database (during migration for example) @@ -36,14 +35,14 @@ $typeFilter = "Boolean"; break; case 'select': - if (!empty($conf->global->EXPORT_LABEL_FOR_SELECT)) - { - $tmpparam = unserialize($obj->param); // $tmpparam may be array with 'options' = array(key1=>val1, key2=>val2 ...) - if ($tmpparam['options'] && is_array($tmpparam['options'])) { - $typeFilter = "Select:".$obj->param; - } - } - break; + if (!empty($conf->global->EXPORT_LABEL_FOR_SELECT)) + { + $tmpparam = unserialize($obj->param); // $tmpparam may be array with 'options' = array(key1=>val1, key2=>val2 ...) + if ($tmpparam['options'] && is_array($tmpparam['options'])) { + $typeFilter = "Select:".$obj->param; + } + } + break; case 'sellist': $tmp = ''; $tmpparam = unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null @@ -56,19 +55,20 @@ } if ($obj->type != 'separate') { - // If not a computed field - if (empty($obj->fieldcomputed)) + // If not a computed field + if (empty($obj->fieldcomputed)) + { + $this->export_fields_array[$r][$fieldname] = $fieldlabel; + $this->export_TypeFields_array[$r][$fieldname] = $typeFilter; + $this->export_entities_array[$r][$fieldname] = $keyforelement; + } + // If this is a computed field + else { - $this->export_fields_array[$r][$fieldname] = $fieldlabel; - $this->export_TypeFields_array[$r][$fieldname] = $typeFilter; - $this->export_entities_array[$r][$fieldname] = $keyforelement; - } - // If this is a computed field - else { - $this->export_fields_array[$r][$fieldname] = $fieldlabel; - $this->export_TypeFields_array[$r][$fieldname] = $typeFilter.'Compute'; - $this->export_special_array[$r][$fieldname] = $obj->fieldcomputed; - $this->export_entities_array[$r][$fieldname] = $keyforelement; + $this->export_fields_array[$r][$fieldname] = $fieldlabel; + $this->export_TypeFields_array[$r][$fieldname] = $typeFilter.'Compute'; + $this->export_special_array[$r][$fieldname] = $obj->fieldcomputed; + $this->export_entities_array[$r][$fieldname] = $keyforelement; } } } --- /tmp/dsg/dolibarr/htdocs/core/github_get_info.php +++ /tmp/dsg/dolibarr/htdocs/core/client_get_info.php @@ -60,6 +60,8 @@ print '
'; //print '
'; +$nbofsearch = 0; + // Define link to login card $appli = constant('DOL_APPLICATION_TITLE'); if (!empty($conf->global->MAIN_APPLICATION_TITLE)) @@ -68,8 +70,10 @@ if (preg_match('/\d\.\d/', $appli)) { if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core - } else $appli .= " ".DOL_VERSION; -} else $appli .= " ".DOL_VERSION; + } + else $appli .= " ".DOL_VERSION; +} +else $appli .= " ".DOL_VERSION; if (!empty($conf->global->MAIN_FEATURES_LEVEL)) $appli .= "
".$langs->trans("LevelOfFeature").': '.$conf->global->MAIN_FEATURES_LEVEL; @@ -85,7 +89,9 @@ //$logouttext .= img_picto($langs->trans('Logout').":".$langs->trans('Logout'), 'logout_top.png', 'class="login"', 0, 0, 1); $logouttext .= ''; $logouttext .= ''; - } else { + } + else + { $logouthtmltext .= $langs->trans("NoLogoutProcessWithAuthMode", $_SESSION["dol_authmode"]); $logouttext .= img_picto($langs->trans('Logout').":".$langs->trans('Logout'), 'logout_top.png', 'class="login"', 0, 0, 1); } @@ -112,13 +118,9 @@ if (is_numeric($result)) { if (empty($result)) $toprightmenu .= $hookmanager->resPrint; // add - else $toprightmenu = $hookmanager->resPrint; // replace -} else $toprightmenu .= $result; // For backward compatibility - -if (!isset($form) || !is_object($form)) { - include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; - $form = new Form($db); -} + else $toprightmenu = $hookmanager->resPrint; // replace +} +else $toprightmenu .= $result; // For backward compatibility // Link to module builder if (!empty($conf->modulebuilder->enabled)) @@ -127,7 +129,7 @@ //$text.= img_picto(":".$langs->trans("ModuleBuilder"), 'printer_top.png', 'class="printer"'); $text .= ''; $text .= ''; - $toprightmenu .= $form->textwithtooltip('', $langs->trans("ModuleBuilder"), 2, 1, $text, 'login_block_elem', 2); + $toprightmenu .= @Form::textwithtooltip('', $langs->trans("ModuleBuilder"), 2, 1, $text, 'login_block_elem', 2); } // Link to print main content area @@ -147,7 +149,7 @@ //$text.= img_picto(":".$langs->trans("PrintContentArea"), 'printer_top.png', 'class="printer"'); $text.=''; $text.=''; - $toprightmenu .= $form->textwithtooltip('',$langs->trans("PrintContentArea"),2,1,$text,'login_block_elem',2); + $toprightmenu.=@Form::textwithtooltip('',$langs->trans("PrintContentArea"),2,1,$text,'login_block_elem',2); } */ @@ -186,13 +188,13 @@ //if ($mode == 'wiki') $text.=' ('.dol_trunc(strtr($helppage,'_',' '),8).')'; $text.=''; //$toprightmenu.='
'."\n"; - $toprightmenu .= $form->textwithtooltip('',$title,2,1,$text,'login_block_elem',2); + $toprightmenu.=@Form::textwithtooltip('',$title,2,1,$text,'login_block_elem',2); } } */ // Logout link -if (GETPOST('withlogout', 'int')) $toprightmenu .= $form->textwithtooltip('', $logouthtmltext, 2, 1, $logouttext, 'login_block_elem', 2); +if (GETPOST('withlogout', 'int')) $toprightmenu .= @Form::textwithtooltip('', $logouthtmltext, 2, 1, $logouttext, 'login_block_elem', 2); $toprightmenu .= ''; --- /tmp/dsg/dolibarr/htdocs/core/github_get_menudiv.php +++ /tmp/dsg/dolibarr/htdocs/core/client_get_menudiv.php @@ -32,13 +32,13 @@ //if (! defined('NOLOGIN')) define('NOLOGIN',1); // Not disabled cause need to load personalized language if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1); if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1); -if (!defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', 1); if (!defined('DISABLE_JQUERY_TABLEDND')) define('DISABLE_JQUERY_TABLEDND', 1); if (!defined('DISABLE_JQUERY_JNOTIFY')) define('DISABLE_JQUERY_JNOTIFY', 1); if (!defined('DISABLE_JQUERY_FLOT')) define('DISABLE_JQUERY_FLOT', 1); if (!defined('DISABLE_JQUERY_JEDITABLE')) define('DISABLE_JQUERY_JEDITABLE', 1); if (!defined('DISABLE_CKEDITOR')) define('DISABLE_CKEDITOR', 1); +if (!defined('DISABLE_BROWSER_NOTIF')) define('DISABLE_BROWSER_NOTIF', 1); if (!defined('DISABLE_DATE_PICKER')) define('DISABLE_DATE_PICKER', 1); if (!defined('DISABLE_SELECT2')) define('DISABLE_SELECT2', 1); @@ -177,14 +177,15 @@ if (empty($user->socid)) // If internal user or not defined { $conf->standard_menu = (empty($conf->global->MAIN_MENU_STANDARD_FORCED) ? (empty($conf->global->MAIN_MENU_STANDARD) ? 'eldy_menu.php' : $conf->global->MAIN_MENU_STANDARD) : $conf->global->MAIN_MENU_STANDARD_FORCED); -} else // If external user +} +else // If external user { $conf->standard_menu = (empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED) ? (empty($conf->global->MAIN_MENUFRONT_STANDARD) ? 'eldy_menu.php' : $conf->global->MAIN_MENUFRONT_STANDARD) : $conf->global->MAIN_MENUFRONT_STANDARD_FORCED); } // Load the menu manager (only if not already done) $file_menu = $conf->standard_menu; -if (GETPOST('menu', 'aZ09')) $file_menu = GETPOST('menu', 'aZ09'); // example: menu=eldy_menu.php +if (GETPOST('menu', 'aZ09')) $file_menu = GETPOST('menu', 'aZ09'); // example: menu=eldy_menu.php if (!class_exists('MenuManager')) { $menufound = 0; --- /tmp/dsg/dolibarr/htdocs/core/github_photos_resize.php +++ /tmp/dsg/dolibarr/htdocs/core/client_photos_resize.php @@ -32,7 +32,7 @@ $langs->loadLangs(array("products", "other")); $id = GETPOST('id', 'int'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $modulepart = GETPOST('modulepart', 'alpha') ?GETPOST('modulepart', 'alpha') : 'produit|service'; $original_file = GETPOST("file"); $backtourl = GETPOST('backtourl'); @@ -42,7 +42,6 @@ $num = GETPOST('num', 'alpha'); // Used for document on bank statement $website = GETPOST('website', 'alpha'); - // Security check if (empty($modulepart)) accessforbidden('Bad value for modulepart'); $accessallowed = 0; @@ -51,32 +50,38 @@ $result = restrictedArea($user, 'produit|service', $id, 'product&product'); if ($modulepart == 'produit|service' && (!$user->rights->produit->lire && !$user->rights->service->lire)) accessforbidden(); $accessallowed = 1; -} elseif ($modulepart == 'project') -{ - $result = restrictedArea($user, 'projet', $id); +} +elseif ($modulepart == 'project') +{ + $result = restrictedArea($user, 'projet', $id); if (!$user->rights->projet->lire) accessforbidden(); $accessallowed = 1; -} elseif ($modulepart == 'bom') +} +elseif ($modulepart == 'bom') { $result = restrictedArea($user, $modulepart, $id, 'bom_bom'); if (!$user->rights->bom->read) accessforbidden(); $accessallowed = 1; -} elseif ($modulepart == 'member') +} +elseif ($modulepart == 'member') { $result = restrictedArea($user, 'adherent', $id, '', '', 'fk_soc', 'rowid'); if (!$user->rights->adherent->lire) accessforbidden(); $accessallowed = 1; -} elseif ($modulepart == 'user') +} +elseif ($modulepart == 'user') { $result = restrictedArea($user, $modulepart, $id, $modulepart); if (!$user->rights->user->user->lire) accessforbidden(); $accessallowed = 1; -} elseif ($modulepart == 'tax') +} +elseif ($modulepart == 'tax') { $result = restrictedArea($user, $modulepart, $id, 'chargesociales', 'charges'); if (!$user->rights->tax->charges->lire) accessforbidden(); $accessallowed = 1; -} elseif ($modulepart == 'bank') +} +elseif ($modulepart == 'bank') { $result = restrictedArea($user, 'banque', $id, 'bank_account'); if (!$user->rights->banque->lire) accessforbidden(); @@ -85,11 +90,6 @@ { $permtoadd = ($user->rights->mailing->creer || $user->rights->website->write); if (!$permtoadd) accessforbidden(); - $accessallowed = 1; -} elseif ($modulepart == 'facture_fourn' || $modulepart == 'facture_fournisseur') -{ - $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture'); - if (!$user->rights->fournisseur->facture->lire) accessforbidden(); $accessallowed = 1; } else // ticket, holiday, expensereport, societe... { @@ -118,17 +118,19 @@ if ($object->type == Product::TYPE_PRODUCT) $dir = $conf->product->multidir_output[$object->entity]; if ($object->type == Product::TYPE_SERVICE) $dir = $conf->service->multidir_output[$object->entity]; } -} elseif ($modulepart == 'project') -{ - require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; - $object = new Project($db); - if ($id > 0) - { - $result = $object->fetch($id); - if ($result <= 0) dol_print_error($db, 'Failed to load object'); - $dir = $conf->project->multidir_output[$object->entity]; // By default - } -} elseif ($modulepart == 'propal') +} +elseif ($modulepart == 'project') +{ + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + $object = new Project($db); + if ($id > 0) + { + $result = $object->fetch($id); + if ($result <= 0) dol_print_error($db, 'Failed to load object'); + $dir = $conf->project->multidir_output[$object->entity]; // By default + } +} +elseif ($modulepart == 'propal') { require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; $object = new Propal($db); @@ -138,7 +140,8 @@ if ($result <= 0) dol_print_error($db, 'Failed to load object'); $dir = $conf->propal->multidir_output[$object->entity]; // By default } -} elseif ($modulepart == 'holiday') +} +elseif ($modulepart == 'holiday') { require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; $object = new Holiday($db); @@ -148,7 +151,8 @@ if ($result <= 0) dol_print_error($db, 'Failed to load object'); $dir = $conf->$modulepart->dir_output; // By default } -} elseif ($modulepart == 'member') +} +elseif ($modulepart == 'member') { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; $object = new Adherent($db); @@ -158,37 +162,41 @@ if ($result <= 0) dol_print_error($db, 'Failed to load object'); $dir = $conf->adherent->dir_output; // By default } -} elseif ($modulepart == 'societe') -{ - require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; - $object = new Societe($db); - if ($id > 0) - { - $result = $object->fetch($id); - if ($result <= 0) dol_print_error($db, 'Failed to load object'); - $dir = $conf->$modulepart->dir_output; - } -} elseif ($modulepart == 'user') -{ - require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; - $object = new User($db); - if ($id > 0) - { - $result = $object->fetch($id); - if ($result <= 0) dol_print_error($db, 'Failed to load object'); - $dir = $conf->$modulepart->dir_output; // By default - } -} elseif ($modulepart == 'expensereport') -{ - require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; - $object = new ExpenseReport($db); - if ($id > 0) - { - $result = $object->fetch($id); - if ($result <= 0) dol_print_error($db, 'Failed to load object'); - $dir = $conf->expensereport->dir_output; // By default - } -} elseif ($modulepart == 'tax') +} +elseif ($modulepart == 'societe') +{ + require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; + $object = new Societe($db); + if ($id > 0) + { + $result = $object->fetch($id); + if ($result <= 0) dol_print_error($db, 'Failed to load object'); + $dir = $conf->$modulepart->dir_output; + } +} +elseif ($modulepart == 'user') +{ + require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; + $object = new User($db); + if ($id > 0) + { + $result = $object->fetch($id); + if ($result <= 0) dol_print_error($db, 'Failed to load object'); + $dir = $conf->$modulepart->dir_output; // By default + } +} +elseif ($modulepart == 'expensereport') +{ + require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; + $object = new ExpenseReport($db); + if ($id > 0) + { + $result = $object->fetch($id); + if ($result <= 0) dol_print_error($db, 'Failed to load object'); + $dir = $conf->expensereport->dir_output; // By default + } +} +elseif ($modulepart == 'tax') { require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; $object = new ChargeSociales($db); @@ -198,7 +206,8 @@ if ($result <= 0) dol_print_error($db, 'Failed to load object'); $dir = $conf->$modulepart->dir_output; // By default } -} elseif ($modulepart == 'ticket') +} +elseif ($modulepart == 'ticket') { require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php'; $object = new Ticket($db); @@ -208,7 +217,8 @@ if ($result <= 0) dol_print_error($db, 'Failed to load object'); $dir = $conf->$modulepart->dir_output; // By default } -} elseif ($modulepart == 'bom') +} +elseif ($modulepart == 'bom') { require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php'; $object = new BOM($db); @@ -236,58 +246,39 @@ if ($result <= 0) dol_print_error($db, 'Failed to load object'); $dir = $conf->bank->dir_output; // By default } -} elseif ($modulepart == 'facture') { - require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; - $object = new Facture($db); - if ($id > 0) - { - $result = $object->fetch($id); - if ($result <= 0) dol_print_error($db, 'Failed to load object'); - $dir = $conf->$modulepart->dir_output; // By default - } -} elseif ($modulepart == 'facture_fourn' || $modulepart == 'facture_fournisseur') { - require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; - $object = new FactureFournisseur($db); - if ($id > 0) - { - $result = $object->fetch($id); - if ($result <= 0) dol_print_error($db, 'Failed to load object'); - $dir = $conf->fournisseur->dir_output.'/facture'; // By default - } } elseif ($modulepart == 'medias') { $dir = $dolibarr_main_data_root.'/'.$modulepart; } else { - print 'Bug: Action crop for modulepart = '.$modulepart.' is not supported yet by photos_resize.php.'; + print 'Action crop for modulepart = '.$modulepart.' is not supported yet by photos_resize.php.'; } if (empty($backtourl)) { $regs = array(); - if (in_array($modulepart, array('product', 'produit', 'service', 'produit|service'))) $backtourl = DOL_URL_ROOT."/product/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('expensereport'))) $backtourl = DOL_URL_ROOT."/expensereport/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('holiday'))) $backtourl = DOL_URL_ROOT."/holiday/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('member'))) $backtourl = DOL_URL_ROOT."/adherents/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('project'))) $backtourl = DOL_URL_ROOT."/projet/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('propal'))) $backtourl = DOL_URL_ROOT."/comm/propal/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('societe'))) $backtourl = DOL_URL_ROOT."/societe/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('tax'))) $backtourl = DOL_URL_ROOT."/compta/sociales/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('ticket'))) $backtourl = DOL_URL_ROOT."/ticket/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('user'))) $backtourl = DOL_URL_ROOT."/user/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('facture'))) $backtourl = DOL_URL_ROOT."/compta/facture/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('facture_fourn', 'facture_fournisseur'))) $backtourl = DOL_URL_ROOT."/fourn/facture/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('bank')) && preg_match('/\/statement\/([^\/]+)\//', $file, $regs)) { - $num = $regs[1]; - $backtourl = DOL_URL_ROOT."/compta/bank/account_statement_document.php?id=".$id.'&num='.urlencode($num).'&file='.urldecode($file); - } elseif (in_array($modulepart, array('bank'))) $backtourl = DOL_URL_ROOT."/compta/bank/document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('mrp'))) $backtourl = DOL_URL_ROOT."/mrp/mo_document.php?id=".$id.'&file='.urldecode($file); - elseif (in_array($modulepart, array('medias'))) { - $section_dir = dirname($file); - if (!preg_match('/\/$/', $section_dir)) $section_dir .= '/'; - $backtourl = DOL_URL_ROOT."/website/index.php?action=file_manager&website=".$website.'§ion_dir='.urlencode($section_dir); - } - // Generic case that should work for everybody else - else $backtourl = DOL_URL_ROOT."/".$modulepart."/".$modulepart."_document.php?id=".$id.'&file='.urldecode($file); + if (in_array($modulepart, array('product', 'produit', 'service', 'produit|service'))) $backtourl = DOL_URL_ROOT."/product/document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('expensereport'))) $backtourl = DOL_URL_ROOT."/expensereport/document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('holiday'))) $backtourl = DOL_URL_ROOT."/holiday/document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('member'))) $backtourl = DOL_URL_ROOT."/adherents/document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('project'))) $backtourl = DOL_URL_ROOT."/projet/document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('propal'))) $backtourl = DOL_URL_ROOT."/comm/propal/document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('societe'))) $backtourl = DOL_URL_ROOT."/societe/document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('tax'))) $backtourl = DOL_URL_ROOT."/compta/sociales/document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('ticket'))) $backtourl = DOL_URL_ROOT."/ticket/document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('user'))) $backtourl = DOL_URL_ROOT."/user/document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('bank')) && preg_match('/\/statement\/([^\/]+)\//', $file, $regs)) { + $num = $regs[1]; + $backtourl = DOL_URL_ROOT."/compta/bank/account_statement_document.php?id=".$id.'&num='.urlencode($num).'&file='.urldecode($file); + } + elseif (in_array($modulepart, array('bank'))) $backtourl = DOL_URL_ROOT."/compta/bank/document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('mrp'))) $backtourl = DOL_URL_ROOT."/mrp/mo_document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('medias'))) { + $section_dir = dirname($file); + if (! preg_match('/\/$/', $section_dir)) $section_dir.='/'; + $backtourl = DOL_URL_ROOT."/website/index.php?action=file_manager&website=".$website.'§ion_dir='.urlencode($section_dir); + } + // Generic case that should work for everybody else + else $backtourl = DOL_URL_ROOT."/".$modulepart."/".$modulepart."_document.php?id=".$id.'&file='.urldecode($file); } @@ -295,22 +286,22 @@ * Actions */ -if ($cancel) { - if ($backtourl) { +if ($cancel) +{ + if ($backtourl) + { header("Location: ".$backtourl); exit; - } else { - dol_print_error('', 'Cancel on photo_resize with a not supported value of modulepart='.$modulepart); - exit; + } + else + { + dol_print_error('', 'Cancel on photo_resize with a not supported value of modulepart='.$modulepart); + exit; } } if ($action == 'confirm_resize' && GETPOSTISSET("file") && GETPOSTISSET("sizex") && GETPOSTISSET("sizey")) { - if (empty($dir)) { - print 'Bug: Value for $dir could not be defined.'; - } - $fullpath = $dir."/".$original_file; $result = dol_imageResizeOrCrop($fullpath, 0, GETPOST('sizex', 'int'), GETPOST('sizey', 'int')); @@ -331,44 +322,49 @@ $result = $ecmfile->fetch(0, '', $rel_filename); if ($result > 0) // If found { - $filename = basename($rel_filename); - $rel_dir = dirname($rel_filename); - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - - $ecmfile->label = md5_file(dol_osencode($fullpath)); - $result = $ecmfile->update($user); - } elseif ($result == 0) // If not found - { - $filename = basename($rel_filename); - $rel_dir = dirname($rel_filename); - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - - $ecmfile->filepath = $rel_dir; - $ecmfile->filename = $filename; - $ecmfile->label = md5_file(dol_osencode($fullpath)); // $fullpath is a full path to file - $ecmfile->fullpath_orig = $fullpath; - $ecmfile->gen_or_uploaded = 'unknown'; - $ecmfile->description = ''; // indexed content - $ecmfile->keyword = ''; // keyword content - $result = $ecmfile->create($user); - if ($result < 0) - { - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); - } - $result = $ecmfile->create($user); + $filename = basename($rel_filename); + $rel_dir = dirname($rel_filename); + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); + + $ecmfile->label = md5_file(dol_osencode($fullpath)); + $result = $ecmfile->update($user); + } + elseif ($result == 0) // If not found + { + $filename = basename($rel_filename); + $rel_dir = dirname($rel_filename); + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); + + $ecmfile->filepath = $rel_dir; + $ecmfile->filename = $filename; + $ecmfile->label = md5_file(dol_osencode($fullpath)); // $fullpath is a full path to file + $ecmfile->fullpath_orig = $fullpath; + $ecmfile->gen_or_uploaded = 'unknown'; + $ecmfile->description = ''; // indexed content + $ecmfile->keyword = ''; // keyword content + $result = $ecmfile->create($user); + if ($result < 0) + { + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); + } + $result = $ecmfile->create($user); } if ($backtourl) { header("Location: ".$backtourl); exit; - } else { - dol_print_error('', 'confirm_resize on photo_resize without backtourl defined for modulepart='.$modulepart); - exit; - } - } else { + } + else + { + dol_print_error('', 'confirm_resize on photo_resize without backtourl defined for modulepart='.$modulepart); + exit; + } + } + else + { setEventMessages($result, null, 'errors'); $_GET['file'] = $_POST["file"]; $action = ''; @@ -378,13 +374,9 @@ // Crop d'une image if ($action == 'confirm_crop') { - if (empty($dir)) { - print 'Bug: Value for $dir could not be defined.'; - } - $fullpath = $dir."/".$original_file; - //var_dump($fullpath.' '.$_POST['w'].'x'.$_POST['h'].'-'.$_POST['x'].'x'.$_POST['y']);exit; + //var_dump($_POST['w'].'x'.$_POST['h'].'-'.$_POST['x'].'x'.$_POST['y']);exit; $result = dol_imageResizeOrCrop($fullpath, 1, GETPOST('w', 'int'), GETPOST('h', 'int'), GETPOST('x', 'int'), GETPOST('y', 'int')); if ($result == $fullpath) @@ -402,43 +394,49 @@ $result = $ecmfile->fetch(0, '', $rel_filename); if ($result > 0) // If found { - $filename = basename($rel_filename); - $rel_dir = dirname($rel_filename); - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - - $ecmfile->label = md5_file(dol_osencode($fullpath)); - $result = $ecmfile->update($user); - } elseif ($result == 0) // If not found - { - $filename = basename($rel_filename); - $rel_dir = dirname($rel_filename); - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - - $ecmfile->filepath = $rel_dir; - $ecmfile->filename = $filename; - $ecmfile->label = md5_file(dol_osencode($fullpath)); // $fullpath is a full path to file - $ecmfile->fullpath_orig = $fullpath; - $ecmfile->gen_or_uploaded = 'unknown'; - $ecmfile->description = ''; // indexed content - $ecmfile->keyword = ''; // keyword content - $result = $ecmfile->create($user); - if ($result < 0) - { - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); - } - $result = $ecmfile->create($user); - } - - if ($backtourl) { + $filename = basename($rel_filename); + $rel_dir = dirname($rel_filename); + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); + + $ecmfile->label = md5_file(dol_osencode($fullpath)); + $result = $ecmfile->update($user); + } + elseif ($result == 0) // If not found + { + $filename = basename($rel_filename); + $rel_dir = dirname($rel_filename); + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); + + $ecmfile->filepath = $rel_dir; + $ecmfile->filename = $filename; + $ecmfile->label = md5_file(dol_osencode($fullpath)); // $fullpath is a full path to file + $ecmfile->fullpath_orig = $fullpath; + $ecmfile->gen_or_uploaded = 'unknown'; + $ecmfile->description = ''; // indexed content + $ecmfile->keyword = ''; // keyword content + $result = $ecmfile->create($user); + if ($result < 0) + { + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); + } + $result = $ecmfile->create($user); + } + + if ($backtourl) + { header("Location: ".$backtourl); exit; - } else { - dol_print_error('', 'confirm_crop on photo_resize without backtourl defined for modulepart='.$modulepart); - exit; - } - } else { + } + else + { + dol_print_error('', 'confirm_crop on photo_resize without backtourl defined for modulepart='.$modulepart); + exit; + } + } + else + { setEventMessages($result, null, 'errors'); $_GET['file'] = $_POST["file"]; $action = ''; @@ -450,12 +448,10 @@ * View */ -$title= $langs->trans("ImageEditor"); - -llxHeader($head, $title, '', '', 0, 0, array('/includes/jquery/plugins/jcrop/js/jquery.Jcrop.min.js', '/core/js/lib_photosresize.js'), array('/includes/jquery/plugins/jcrop/css/jquery.Jcrop.css')); - - -print load_fiche_titre($title); +llxHeader($head, $langs->trans("Image"), '', '', 0, 0, array('/includes/jquery/plugins/jcrop/js/jquery.Jcrop.min.js', '/core/js/lib_photosresize.js'), array('/includes/jquery/plugins/jcrop/css/jquery.Jcrop.css')); + + +print load_fiche_titre($langs->trans("ImageEditor")); $infoarray = dol_getImageSize($dir."/".GETPOST("file", 'alpha')); $height = $infoarray['height']; @@ -488,7 +484,7 @@ print '
'; print ''; print ' '; -print ''; +print ''; print ''."\n"; print '
'; print '
'."\n"; @@ -547,7 +543,7 @@
  - + '."\n"; print ''."\n"; print '
'; --- /tmp/dsg/dolibarr/htdocs/core/github_search.php +++ /tmp/dsg/dolibarr/htdocs/core/client_search.php @@ -147,6 +147,8 @@ { header("Location: ".$_SERVER['HTTP_REFERER']); exit; -} else { +} +else +{ print 'The wrapper search.php was called without any search criteria'; } --- /tmp/dsg/dolibarr/htdocs/core/github_search_page.php +++ /tmp/dsg/dolibarr/htdocs/core/client_search_page.php @@ -74,7 +74,9 @@ if (!is_object($form)) $form = new Form($db); $selected = -1; $searchform .= '

'.$form->selectArrayAjax('searchselectcombo', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'minwidth300', 1, $langs->trans("Search"), 0); -} else { +} +else +{ $usedbyinclude = 1; // Used into next include $showtitlebefore = GETPOST('showtitlebefore', 'int'); $arrayresult = array(); @@ -107,7 +109,8 @@ if (empty($reshook)) { $searchform .= $hookmanager->resPrint; -} else $searchform = $hookmanager->resPrint; +} +else $searchform = $hookmanager->resPrint; print "\n"; --- /tmp/dsg/dolibarr/htdocs/core/github_website.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_website.inc.php @@ -53,7 +53,7 @@ } if (!is_object($websitepage)) { - $websitepage = new WebsitePage($db); + $websitepage = new WebsitePage($db); } // Define $weblangs if (!is_object($weblangs)) @@ -68,23 +68,25 @@ { $websitepage->fetch($pageid); - $weblangs->setDefaultLang(GETPOSTISSET('lang') ? GETPOST('lang', 'aZ09') : (empty($_COOKIE['weblangs-shortcode']) ? 'auto' : preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE['weblangs-shortcode']))); + $weblangs->setDefaultLang(GETPOSTISSET('lang') ? GETPOST('lang', 'aZ09') : (empty($_COOKIE['weblangs-shortcode']) ? 'auto' : $_COOKIE['weblangs-shortcode'])); $pagelangs->setDefaultLang($websitepage->lang ? $websitepage->lang : $weblangs->shortlang); - if (!defined('USEDOLIBARREDITOR') && (in_array($websitepage->type_container, array('menu', 'other')) || empty($websitepage->status))) + if (!defined('USEDOLIBARREDITOR') && in_array($websitepage->type_container, array('menu', 'other'))) { $weblangs->load("website"); http_response_code(404); - print '


'.$weblangs->trans("YouTryToAccessToAFileThatIsNotAWebsitePage", $websitepage->pageurl, $websitepage->type_container, $websitepage->status).'
'; + print '


'.$weblangs->trans("YouTryToAccessToAFileThatIsNotAWebsitePage").'
'; exit; } } if (!defined('USEDOLIBARRSERVER') && !defined('USEDOLIBARREDITOR')) { header("X-Content-Type-Options: nosniff"); - if (empty($websitepage->allowed_in_frames) && empty($conf->global->WEBSITE_ALLOW_FRAMES_ON_ALL_PAGES)) { + /* TODO Manage allow_frames flag on websitepage. + if (empty($websitepage->allow_frames) && empty($conf->global->WEBSITE_ALLOW_FRAMES_ON_ALL_PAGES)) { header("X-Frame-Options: SAMEORIGIN"); } + */ } // A lang was forced, so we change weblangs init @@ -115,7 +117,9 @@ if (defined('USEDOLIBARRSERVER')) { header("Location: ".DOL_URL_ROOT.'/public/website/index.php?website='.$websitekey.'&pageid='.$newpageid.'&l='.GETPOST('l', 'aZ09')); exit; - } else { + } + else + { $newpageref = $obj->pageurl; header("Location: ".(($obj->lang && $obj->lang != $website->lang) ? '/'.$obj->lang.'/' : '/').$newpageref.'.php?l='.GETPOST('l', 'aZ09')); exit;