--- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_actions_addupdatedelete.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_addupdatedelete.inc.php @@ -31 +30,0 @@ -// $noback may be defined @@ -34,12 +33,8 @@ -$hidedetails = isset($hidedetails) ? $hidedetails : ''; -$hidedesc = isset($hidedesc) ? $hidedesc : ''; -$hideref = isset($hideref) ? $hideref : ''; - - -if (!empty($permissionedit) && empty($permissiontoadd)) { - $permissiontoadd = $permissionedit; // For backward compatibility -} - -if ($cancel) { - /*var_dump($cancel);var_dump($backtopage);var_dump($backtopageforcancel);exit;*/ - if (!empty($backtopageforcancel)) { +if (!empty($permissionedit) && empty($permissiontoadd)) $permissiontoadd = $permissionedit; // For backward compatibility + +if ($cancel) +{ + /*var_dump($cancel); + var_dump($backtopage);exit;*/ + if (!empty($backtopageforcancel)) + { @@ -48 +43,3 @@ - } elseif (!empty($backtopage)) { + } + elseif (!empty($backtopage)) + { @@ -57,2 +54,4 @@ -if ($action == 'add' && !empty($permissiontoadd)) { - foreach ($object->fields as $key => $val) { +if ($action == 'add' && !empty($permissiontoadd)) +{ + foreach ($object->fields as $key => $val) + { @@ -60,3 +59,21 @@ - if (GETPOST($key.'hour') == '' && GETPOST($key.'min') == '') { - continue; // The field was not submited to be saved - } + if (GETPOST($key.'hour') == '' && GETPOST($key.'min') == '') continue; // The field was not submited to be edited + } + else { + if (!GETPOSTISSET($key)) continue; // The field was not submited to be edited + } + // Ignore special fields + 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, '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')); + } elseif ($object->fields[$key]['type'] == 'datetime') { + $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, 'none')); // To fix decimal separator according to lang setup + } elseif ($object->fields[$key]['type'] == 'boolean') { + $value = (GETPOST($key) == 'on' ? 1 : 0); @@ -64,64 +81,6 @@ - if (!GETPOSTISSET($key) && !preg_match('/^chkbxlst:/', $object->fields[$key]['type'])) { - continue; // The field was not submited to be saved - } - } - // 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 - } - } - - // Set value to insert - if (preg_match('/^text/', $object->fields[$key]['type'])) { - $tmparray = explode(':', $object->fields[$key]['type']); - if (!empty($tmparray[1])) { - $value = GETPOST($key, $tmparray[1]); - } else { - $value = GETPOST($key, 'nohtml'); - } - } elseif (preg_match('/^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'); - } - } 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 - } 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'); - } elseif ($object->fields[$key]['type'] == 'duration') { - $value = 60 * 60 * GETPOSTINT($key.'hour') + 60 * GETPOSTINT($key.'min'); - } elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) { - $value = price2num(GETPOST($key, 'alphanohtml')); // 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'); - } elseif (preg_match('/^chkbxlst:(.*)/', $object->fields[$key]['type']) || $object->fields[$key]['type'] == 'checkbox') { - $value = ''; - $values_arr = GETPOST($key, 'array'); - if (!empty($values_arr)) { - $value = implode(',', $values_arr); - } - } else { - if ($key == 'lang') { - $value = GETPOST($key, 'aZ09') ? GETPOST($key, 'aZ09') : ""; - } else { - $value = GETPOST($key, 'alphanohtml'); - } - } - if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') { - $value = ''; // This is an implicit foreign key field - } - if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') { - $value = ''; // This is an explicit foreign key field - } - - //var_dump($key.' '.$value.' '.$object->fields[$key]['type'].' '.$object->fields[$key]['notnull']); - + $value = GETPOST($key, 'alphanohtml'); + } + if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value = ''; // This is an implicit foreign key field + if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') $value = ''; // This is an explicit foreign key field + + //var_dump($key.' '.$value.' '.$object->fields[$key]['type']); @@ -129,20 +88,8 @@ - if (!empty($val['notnull']) && $val['notnull'] > 0 && $object->$key == '' && isset($val['default']) && $val['default'] == '(PROV)') { - $object->$key = '(PROV)'; - } - if ($key == 'pass_crypted') { - $object->pass = GETPOST("pass", "none"); - // TODO Manadatory for password not yet managed - } else { - if (!empty($val['notnull']) && $val['notnull'] > 0 && $object->$key == '' && !isset($val['default'])) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors'); - } - } - - // Validation of fields values - if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1 || getDolGlobalString('MAIN_ACTIVATE_VALIDATION_RESULT')) { - if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) { - if (!$object->validateField($object->fields, $key, $value)) { - $error++; - } - } + if ($val['notnull'] > 0 && $object->$key == '' && !is_null($val['default']) && $val['default'] == '(PROV)') + { + $object->$key = '(PROV)'; + } + if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default'])) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors'); @@ -154,9 +101,6 @@ - $ret = $extrafields->setOptionalsFromPost(null, $object, '', 1); - if ($ret < 0) { - $error++; - } - } - - if (!$error) { - $db->begin(); - + $ret = $extrafields->setOptionalsFromPost(null, $object); + if ($ret < 0) $error++; + } + + if (!$error) + { @@ -164,7 +108,3 @@ - if ($result > 0) { - // Creation OK - if (isModEnabled('categorie') && method_exists($object, 'setCategories')) { - $categories = GETPOST('categories', 'array:int'); - $object->setCategories($categories); - } - + if ($result > 0) + { + // Creation OK @@ -173,11 +113,5 @@ - - $db->commit(); - - if (empty($noback)) { - header("Location: " . $urltogo); - exit; - } - } else { - $db->rollback(); - - $error++; + header("Location: ".$urltogo); + exit; + } + else + { @@ -185,5 +119,2 @@ - if (!empty($object->errors)) { - setEventMessages(null, $object->errors, 'errors'); - } else { - setEventMessages($object->error, null, 'errors'); - } + if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); + else setEventMessages($object->error, null, 'errors'); @@ -192 +123,3 @@ - } else { + } + else + { @@ -198,2 +131,4 @@ -if ($action == 'update' && !empty($permissiontoadd)) { - foreach ($object->fields as $key => $val) { +if ($action == 'update' && !empty($permissiontoadd)) +{ + foreach ($object->fields as $key => $val) + { @@ -202,4 +137,3 @@ - if (!GETPOSTISSET($key.'hour') || !GETPOSTISSET($key.'min')) { - continue; // The field was not submited to be saved - } - } elseif ($object->fields[$key]['type'] == 'boolean') { + if (!GETPOSTISSET($key.'hour') || !GETPOSTISSET($key.'min')) continue; // The field was not submited to be edited + } + elseif ($object->fields[$key]['type'] == 'boolean') { @@ -210,4 +144,4 @@ - } else { - if (!GETPOSTISSET($key) && !preg_match('/^chkbxlst:/', $object->fields[$key]['type']) && $object->fields[$key]['type']!=='checkbox') { - continue; // The field was not submited to be saved - } + } + + else { + if (!GETPOSTISSET($key)) continue; // The field was not submited to be edited @@ -216,8 +150 @@ - 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 cases to update - } - } + if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; @@ -226,14 +153,2 @@ - if (preg_match('/^text/', $object->fields[$key]['type'])) { - $tmparray = explode(':', $object->fields[$key]['type']); - if (!empty($tmparray[1])) { - $value = GETPOST($key, $tmparray[1]); - } else { - $value = GETPOST($key, 'nohtml'); - } - } elseif (preg_match('/^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'); @@ -241 +156 @@ - $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')); @@ -243 +158 @@ - $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')); @@ -251 +166 @@ - $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 @@ -253,9 +168 @@ - $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'); - } elseif (preg_match('/^chkbxlst:/', $object->fields[$key]['type']) || $object->fields[$key]['type'] == 'checkbox') { - $value = ''; - $values_arr = GETPOST($key, 'array'); - if (!empty($values_arr)) { - $value = implode(',', $values_arr); - } + $value = (GETPOST($key) == 'on' ? 1 : 0); @@ -263,12 +170,4 @@ - if ($key == 'lang') { - $value = GETPOST($key, 'aZ09'); - } else { - $value = GETPOST($key, 'alphanohtml'); - } - } - if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') { - $value = ''; // This is an implicit foreign key field - } - if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') { - $value = ''; // This is an explicit foreign key field - } + $value = GETPOST($key, 'alpha'); + } + if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value = ''; // This is an implicit foreign key field + if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') $value = ''; // This is an explicit foreign key field @@ -277 +176,2 @@ - if ($val['notnull'] > 0 && $object->$key == '' && (!isset($val['default']) || is_null($val['default']))) { + if ($val['notnull'] > 0 && $object->$key == '' && is_null($val['default'])) + { @@ -281,18 +181 @@ - - // Validation of fields values - if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1 || getDolGlobalString('MAIN_ACTIVATE_VALIDATION_RESULT')) { - if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) { - if (!$object->validateField($object->fields, $key, $value)) { - $error++; - } - } - } - - if (isModEnabled('categorie')) { - $categories = GETPOST('categories', 'array'); - if (method_exists($object, 'setCategories')) { - $object->setCategories($categories); - } - } - } - + } @@ -303,6 +186,5 @@ - if ($ret < 0) { - $error++; - } - } - - if (!$error) { + if ($ret < 0) $error++; + } + + if (!$error) + { @@ -310 +192,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -312,8 +195,3 @@ - $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 - if ($urltogo && empty($noback)) { - header("Location: " . $urltogo); - exit; - } - } else { - $error++; + } + else + { @@ -323,0 +202,19 @@ + } + else + { + $action = 'edit'; + } +} + +// Action to update one extrafield +if ($action == "update_extras" && !empty($permissiontoadd)) +{ + $object->fetch(GETPOST('id', 'int')); + + $attributekey = GETPOST('attribute', 'alpha'); + $attributekeylong = 'options_'.$attributekey; + + if (GETPOSTISSET($attributekeylong.'day') && GETPOSTISSET($attributekeylong.'month') && GETPOSTISSET($attributekeylong.'year')) { + // This is properties of a date + $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; @@ -325,45 +222,12 @@ - $action = 'edit'; - } -} - -// Action to update one modulebuilder field -$reg = array(); -if (preg_match('/^set(\w+)$/', $action, $reg) && GETPOST('id', 'int') > 0 && !empty($permissiontoadd)) { - $object->fetch(GETPOST('id', 'int')); - - $keyforfield = $reg[1]; - if (property_exists($object, $keyforfield)) { - if (!empty($object->fields[$keyforfield]) && in_array($object->fields[$keyforfield]['type'], array('date', 'datetime', 'timestamp'))) { - $object->$keyforfield = dol_mktime(GETPOST($keyforfield.'hour'), GETPOST($keyforfield.'min'), GETPOST($keyforfield.'sec'), GETPOST($keyforfield.'month'), GETPOST($keyforfield.'day'), GETPOST($keyforfield.'year')); - } else { - $object->$keyforfield = GETPOST($keyforfield); - } - - $result = $object->update($user); - - if ($result > 0) { - setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); - $action = 'view'; - } else { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - $action = 'edit'.$reg[1]; - } - } -} - -// Action to update one extrafield -if ($action == "update_extras" && GETPOST('id', 'int') > 0 && !empty($permissiontoadd)) { - $object->fetch(GETPOST('id', 'int')); - - $object->oldcopy = dol_clone($object, 2); - - $attribute = GETPOST('attribute', 'alphanohtml'); - - $error = 0; - - // Fill array 'array_options' with data from update form - $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute); - if ($ret < 0) { - $error++; - setEventMessages($extrafields->error, $object->errors, 'errors'); + $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, ' alpha'); + } + + $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user); + if ($result > 0) + { + setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); + $action = 'view'; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); @@ -371,10 +234,0 @@ - } else { - $result = $object->updateExtraField($attribute, empty($triggermodname) ? '' : $triggermodname, $user); - if ($result > 0) { - setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); - $action = 'view'; - } else { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - $action = 'edit_extras'; - } @@ -385,7 +239,7 @@ -if ($action == 'confirm_delete' && !empty($permissiontodelete)) { - if (!($object->id > 0)) { - dol_print_error('', 'Error, object must be fetched before being deleted'); - exit; - } - - $db->begin(); +if ($action == 'confirm_delete' && !empty($permissiontodelete)) +{ + if (!($object->id > 0)) + { + dol_print_error('', 'Error, object must be fetched before being deleted'); + exit; + } @@ -394,4 +248,2 @@ - - if ($result > 0) { - $db->commit(); - + if ($result > 0) + { @@ -400,21 +252,8 @@ - - if (empty($noback)) { - if (empty($backurlforlist)) { - print 'Error backurlforlist is not defined'; - exit; - } - header("Location: " . $backurlforlist); - exit; - } - } else { - $db->rollback(); - - $error++; - if (!empty($object->errors)) { - setEventMessages(null, $object->errors, 'errors'); - } else { - setEventMessages($object->error, null, 'errors'); - } - } - - $action = ''; + header("Location: ".$backurlforlist); + exit; + } + else + { + if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); + else setEventMessages($object->error, null, 'errors'); + } @@ -424,7 +263,5 @@ -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); - } - if ($result > 0) { +if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissiontoadd)) +{ + $result = $object->deleteline($user, $lineid); + if ($result > 0) + { @@ -434 +271,2 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) + { @@ -437 +275,2 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && is_object($object->thirdparty)) { + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && is_object($object->thirdparty)) + { @@ -444,4 +283,31 @@ - if (!getDolGlobalString('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); + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + $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 + { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + +// Action validate object +if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) +{ + $result = $object->validate($user); + if ($result >= 0) + { + // 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 = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); @@ -449,6 +315,103 @@ - } - - setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs'); - - if (empty($noback)) { - header('Location: '.((empty($backtopage)) ? $_SERVER["PHP_SELF"].'?id='.$object->id : $backtopage)); + $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'); + } +} + +// Action close object +if ($action == 'confirm_close' && $confirm == 'yes' && $permissiontoadd) +{ + $result = $object->cancel($user); + if ($result >= 0) + { + // 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 = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $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'); + } +} + +// Action setdraft object +if ($action == 'confirm_setdraft' && $confirm == 'yes' && $permissiontoadd) +{ + $result = $object->setDraft($user); + if ($result >= 0) + { + // Nothing else done + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + +// Action reopen object +if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd) +{ + $result = $object->reopen($user); + if ($result >= 0) + { + // 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 = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $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'); + } +} + +// Action clone object +if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd)) +{ + 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. + //$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) + { + $newid = 0; + if (is_object($result)) $newid = $result->id; + else $newid = $result; + header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid); // Open record of new object @@ -457,152 +420,3 @@ - } else { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - $action = ''; -} - -// Action validate object -if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) { - if ($object->element == 'inventory' && !empty($include_sub_warehouse)) { - // Can happen when the conf INVENTORY_INCLUDE_SUB_WAREHOUSE is set - $result = $object->validate($user, false, $include_sub_warehouse); - } else { - $result = $object->validate($user); - } - - if ($result >= 0) { - // Define output language - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { - if (method_exists($object, 'generateDocument')) { - $outputlangs = $langs; - $newlang = ''; - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { - $newlang = !empty($object->thirdparty->default_lang) ? $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'); - } - } - } - } else { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - $action = ''; -} - -// Action close object -if ($action == 'confirm_close' && $confirm == 'yes' && $permissiontoadd) { - $result = $object->cancel($user); - if ($result >= 0) { - // Define output language - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { - if (method_exists($object, 'generateDocument')) { - $outputlangs = $langs; - $newlang = ''; - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('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); - } - } - } else { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - $action = ''; -} - -// Action setdraft object -if ($action == 'confirm_setdraft' && $confirm == 'yes' && $permissiontoadd) { - $result = $object->setDraft($user); - if ($result >= 0) { - // Nothing else done - } else { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - $action = ''; -} - -// Action reopen object -if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd) { - $result = $object->reopen($user); - if ($result >= 0) { - // Define output language - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { - if (method_exists($object, 'generateDocument')) { - $outputlangs = $langs; - $newlang = ''; - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('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); - } - } - } else { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - $action = ''; -} - -// Action clone object -if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd)) { - if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) { - setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); - } else { - // We clone object to avoid to denaturate loaded object when setting some properties for clone or if createFromClone modifies the object. - $objectutil = dol_clone($object, 1); - // We used native clone to keep this->db valid and allow to use later all the methods of object. - //$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) { - $newid = 0; - if (is_object($result)) { - $newid = $result->id; - } else { - $newid = $result; - } - - if (empty($noback)) { - header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $newid); // Open record of new object - exit; - } - } else { - $error++; - setEventMessages($objectutil->error, $objectutil->errors, 'errors'); + else + { + setEventMessages($objectutil->error, $objectutil->errors, 'errors'); --- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_actions_builddoc.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_builddoc.inc.php @@ -29 +29 @@ -// $upload_dir must be defined (example $conf->project->dir_output . "/";) +// $upload_dir must be defined (example $conf->projet->dir_output . "/";) @@ -32,3 +32 @@ -if (!empty($permissioncreate) && empty($permissiontoadd)) { - $permissiontoadd = $permissioncreate; // For backward compatibility -} +if (!empty($permissioncreate) && empty($permissiontoadd)) $permissiontoadd = $permissioncreate; // For backward compatibility @@ -37,12 +35,16 @@ -if ($action == 'builddoc' && ($permissiontoadd || !empty($usercangeneretedoc))) { - 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) - { - dol_print_error('Object must have been loaded by a fetch'); - exit; - }*/ +if ($action == 'builddoc' && $permissiontoadd) +{ + 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) + { + dol_print_error('Object must have been loaded by a fetch'); + exit; + }*/ @@ -50,4 +52,5 @@ - // 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')); + } @@ -55,10 +58,10 @@ - // 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; + } + //} @@ -66,2 +69,2 @@ - $outputlangs = $langs; - $newlang = ''; + $outputlangs = $langs; + $newlang = ''; @@ -69,13 +72,8 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && isset($object->thirdparty->default_lang)) { - $newlang = $object->thirdparty->default_lang; // for proposal, order, invoice, ... - } - if (getDolGlobalInt('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); + } @@ -83,13 +81,5 @@ - // 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; @@ -97,7 +87,11 @@ - $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); @@ -105,3 +99,3 @@ - /*$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 @@ -109,5 +103,5 @@ - header('Location: '.$urltoredirect.'#builddoc'); - exit;*/ - } - } - } + header('Location: '.$urltoredirect.'#builddoc'); + exit; + } + } + } @@ -117 +111,2 @@ -if ($action == 'remove_file' && $permissiontoadd) { +if ($action == 'remove_file' && $permissiontoadd) +{ @@ -119 +114 @@ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -121,5 +116,6 @@ - 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(); + } @@ -127,13 +123,6 @@ - $langs->load("other"); - $filetodelete = GETPOST('file', 'alpha'); - $file = $upload_dir.'/'.$filetodelete; - $dirthumb = dirname($file).'/thumbs/'; // Chemin du dossier contenant la vignette (if file is an image) - $ret = dol_delete_file($file, 0, 0, 0, $object); - if ($ret) { - // 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); - } + $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'); @@ -141,5 +130,4 @@ - $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); - } - } + // 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); @@ -147,13 +135,4 @@ - 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); - - header('Location: '.$urltoredirect); - exit; - } else { + header('Location: '.$urltoredirect); + exit; + } + else { --- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_actions_changeselectedfields.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_changeselectedfields.inc.php @@ -31,2 +31,3 @@ -if (GETPOST('formfilteraction', 'alphanohtml') == 'listafterchangingselectedfields') { - $tabparam = array(); +if (GETPOST('formfilteraction', 'none') == 'listafterchangingselectedfields') +{ + $tabparam = array(); @@ -34 +35 @@ - $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; + $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; @@ -36,5 +37,2 @@ - 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] = ''; @@ -42 +40 @@ - include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; @@ -44 +42 @@ - $result = dol_set_user_param($db, $conf, $user, $tabparam); + $result = dol_set_user_param($db, $conf, $user, $tabparam); @@ -46,2 +44,2 @@ - //$action='list'; - //var_dump($tabparam);exit; + //$action='list'; + //var_dump($tabparam);exit; --- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_actions_comments.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_comments.inc.php @@ -36,3 +36,5 @@ -if ($action == 'addcomment') { - $description = GETPOST('comment_description', 'restricthtml'); - if (!empty($description)) { +if ($action == 'addcomment') +{ + $description = GETPOST('comment_description', 'none'); + if (!empty($description)) + { @@ -40 +42 @@ - $comment->datec = dol_now(); + $comment->datec = time(); @@ -45 +47,2 @@ - if ($comment->create($user) > 0) { + if ($comment->create($user) > 0) + { @@ -49 +52,3 @@ - } else { + } + else + { @@ -55,6 +60,26 @@ -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' : '')); +if ($action === 'updatecomment') +{ + 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') +{ + if ($comment->fetch($idcomment) >= 0) + { + if ($comment->delete($user) > 0) + { + setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs'); + header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : '')); @@ -62 +87,3 @@ - } else { + } + else + { @@ -68,12 +94,0 @@ -if ($action == 'deletecomment') { - if ($comment->fetch($idcomment) >= 0) { - if ($comment->delete($user) > 0) { - setEventMessages($langs->trans("CommentDeleted"), null, 'mesgs'); - header('Location: '.$varpage.'?id='.$id.($withproject ? '&withproject=1' : '')); - exit; - } else { - setEventMessages($comment->error, $comment->errors, 'errors'); - $action = ''; - } - } -} --- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_actions_extrafields.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_extrafields.inc.php @@ -2 +2 @@ -/* Copyright (C) 2011-2020 Laurent Destailleur +/* Copyright (C) 2011-2015 Laurent Destailleur @@ -31,32 +31,8 @@ -$type = GETPOST('type', 'alphanohtml'); -$param = GETPOST('param', 'alphanohtml'); -$css = GETPOST('css', 'alphanohtml'); -$cssview = GETPOST('cssview', 'alphanohtml'); -$csslist = GETPOST('csslist', 'alphanohtml'); -$confirm = GETPOST('confirm', 'alpha'); - -if ($type == 'double' && strpos($extrasize, ',') === false) { - $extrasize = '24,8'; -} -if ($type == 'date') { - $extrasize = ''; -} -if ($type == 'datetime') { - $extrasize = ''; -} -if ($type == 'select') { - $extrasize = ''; -} - -$listofreservedwords = array( - 'ADD', 'ALL', 'ALTER', 'ANALYZE', 'AND', 'AS', 'ASENSITIVE', 'BEFORE', 'BETWEEN', 'BINARY', 'BLOB', 'BOTH', 'CALL', 'CASCADE', 'CASE', 'CHANGE', 'CHAR', 'CHARACTER', 'CHECK', 'COLLATE', 'COLUMN', 'CONDITION', 'CONSTRAINT', 'CONTINUE', 'CONVERT', 'CREATE', 'CROSS', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', - 'CURSOR', 'DATABASE', 'DATABASES', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DECIMAL', 'DECLARE', 'DEFAULT', 'DELAYED', 'DELETE', 'DESC', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCT', 'DISTINCTROW', 'DOUBLE', 'DROP', 'DUAL', - 'EACH', 'ELSE', 'ELSEIF', 'ENCLOSED', 'ESCAPED', 'EXISTS', 'EXPLAIN', 'FALSE', 'FETCH', 'FLOAT', 'FLOAT4', 'FLOAT8', 'FORCE', 'FOREIGN', 'FULLTEXT', 'GRANT', 'GROUP', 'HAVING', 'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', - 'IGNORE', 'IGNORE_SERVER_IDS', 'INDEX', 'INFILE', 'INNER', 'INOUT', 'INSENSITIVE', 'INSERT', 'INT', 'INTEGER', 'INTERVAL', 'INTO', 'ITERATE', - 'KEYS', 'KEYWORD', 'LEADING', 'LEAVE', 'LEFT', 'LIKE', 'LIMIT', 'LINES', 'LOCALTIME', 'LOCALTIMESTAMP', 'LONGBLOB', 'LONGTEXT', 'MASTER_SSL_VERIFY_SERVER_CERT', 'MATCH', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MODIFIES', 'NATURAL', 'NOT', 'NO_WRITE_TO_BINLOG', 'NUMERIC', - 'OFFSET', 'ON', 'OPTION', 'OPTIONALLY', 'OUTER', 'OUTFILE', - 'PARTITION', 'POSITION', 'PRECISION', 'PRIMARY', 'PROCEDURE', 'PURGE', 'RANGE', 'READS', 'READ_WRITE', 'REAL', 'REFERENCES', 'REGEXP', 'RELEASE', 'RENAME', 'REPEAT', 'REQUIRE', 'RESTRICT', 'RETURN', 'REVOKE', 'RIGHT', 'RLIKE', - 'SCHEMAS', 'SECOND_MICROSECOND', 'SENSITIVE', 'SEPARATOR', 'SIGNAL', 'SMALLINT', 'SPATIAL', 'SPECIFIC', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT', 'SSL', 'STARTING', 'STRAIGHT_JOIN', - 'TABLE', 'TERMINATED', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TRAILING', 'TRIGGER', 'UNDO', 'UNIQUE', 'UNSIGNED', 'UPDATE', 'USAGE', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'VALUES', 'VARBINARY', 'VARCHAR', 'VARYING', - 'WHEN', 'WHERE', 'WHILE', 'WRITE', 'XOR', 'YEAR_MONTH', 'ZEROFILL' -); +$type = GETPOST('type', 'alpha'); +$param = GETPOST('param', 'alpha'); + +if ($type == 'double' && strpos($extrasize, ',') === false) $extrasize = '24,8'; +if ($type == 'date') $extrasize = ''; +if ($type == 'datetime') $extrasize = ''; +if ($type == 'select') $extrasize = ''; + @@ -65,4 +41,7 @@ -if ($action == 'add') { - if (GETPOST("button") != $langs->trans("Cancel")) { - // Check values - if (!$type) { +if ($action == 'add') +{ + if ($_POST["button"] != $langs->trans("Cancel")) + { + // Check values + if (!$type) + { @@ -74,5 +53,6 @@ - if ($type == 'varchar' && $extrasize <= 0) { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size")); - $action = 'edit'; + if ($type == 'varchar' && $extrasize <= 0) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size")); + $action = 'edit'; @@ -80,133 +60,121 @@ - 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(strtoupper(GETPOST('attrname', 'aZ09')), $listofreservedwords)) { - $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); - $params = array(); - //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) { - if (strpos($param_ligne, ',')!==false) { - list($key, $value) = explode(',', $param_ligne); - if (!array_key_exists('options', $params)) { - $params['options'] = array(); - } - } else { - $key=$param_ligne; - $value=null; - } - $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, + 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', '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, @@ -214,27 +182,33 @@ - GETPOST('computed_value', 'alpha'), - (GETPOST('entitycurrentorall', 'alpha') ? 0 : ''), - GETPOST('langfile', 'alpha'), - 1, - (GETPOST('totalizable', 'alpha') ? 1 : 0), - GETPOST('printable', 'alpha'), - array('css' => $css, 'cssview' => $cssview, 'csslist' => $csslist) - ); - 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'); + } @@ -245,4 +219,7 @@ -if ($action == 'update') { - if (GETPOST("button") != $langs->trans("Cancel")) { - // Check values - if (!$type) { +if ($action == 'update') +{ + if ($_POST["button"] != $langs->trans("Cancel")) + { + // Check values + if (!$type) + { @@ -254,5 +231,6 @@ - if ($type == 'varchar' && $extrasize <= 0) { - $error++; - $langs->load("errors"); - $mesg[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size")); - $action = 'edit'; + if ($type == 'varchar' && $extrasize <= 0) + { + $error++; + $langs->load("errors"); + $mesg[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size")); + $action = 'edit'; @@ -260,123 +238,112 @@ - 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 && !getDolGlobalString('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(strtoupper(GETPOST('attrname', 'aZ09')), $listofreservedwords) && !getDolGlobalString('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); - $params = array(); - //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); - if (!array_key_exists('options', $params)) { - $params['options'] = array(); - } - $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, + 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 (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, @@ -384,27 +351,33 @@ - GETPOST('default_value', 'alpha'), - $computedvalue, - (GETPOST('entitycurrentorall', 'alpha') ? 0 : ''), - GETPOST('langfile'), - GETPOST('enabled', 'nohtml'), - (GETPOST('totalizable', 'alpha') ? 1 : 0), - GETPOST('printable', 'alpha'), - array('css' => $css, 'cssview' => $cssview, 'csslist' => $csslist) - ); - 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'); + } @@ -415,15 +388,15 @@ -if ($action == 'confirm_delete' && $confirm == "yes") { - if (GETPOSTISSET("attrname") && preg_match("/^\w[a-zA-Z0-9-_]*$/", GETPOST("attrname", 'aZ09'))) { - $attributekey = GETPOST('attrname', 'aZ09'); - - $result = $extrafields->delete($attributekey, $elementtype); - if ($result >= 0) { - setEventMessages($langs->trans("ExtrafieldsDeleted", $attributekey), null, 'mesgs'); - - 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++; @@ -434,68 +406,0 @@ - -// Recrypt data password -if ($action == 'encrypt') { - // Load $extrafields->attributes - $extrafields->fetch_name_optionals_label($elementtype); - $attributekey = GETPOST('attrname', 'aZ09'); - - if (!empty($extrafields->attributes[$elementtype]['type'][$attributekey]) && $extrafields->attributes[$elementtype]['type'][$attributekey] == 'password') { - if (!empty($extrafields->attributes[$elementtype]['param'][$attributekey]['options'])) { - if (array_key_exists('dolcrypt', $extrafields->attributes[$elementtype]['param'][$attributekey]['options'])) { - // We can encrypt data with dolCrypt() - $arrayofelement = getElementProperties($elementtype); - if (!empty($arrayofelement['table_element'])) { - if ($extrafields->attributes[$elementtype]['entityid'][$attributekey] == $conf->entity || empty($extrafields->attributes[$elementtype]['entityid'][$attributekey])) { - dol_syslog("Loop on each extafields of table ".$arrayofelement['table_element']); - - $sql .= "SELECT te.rowid, te.".$attributekey; - $sql .= " FROM ".MAIN_DB_PREFIX.$arrayofelement['table_element']." as t, ".MAIN_DB_PREFIX.$arrayofelement['table_element'].'_extrafields as te'; - $sql .= " WHERE te.fk_object = t.rowid"; - $sql .= " AND te.".$attributekey." NOT LIKE 'dolcrypt:%'"; - $sql .= " AND te.".$attributekey." IS NOT NULL"; - $sql .= " AND te.".$attributekey." <> ''"; - if ($extrafields->attributes[$elementtype]['entityid'][$attributekey] == $conf->entity) { - $sql .= " AND t.entity = ".getEntity($arrayofelement['table_element'], 0); - } - - //print $sql; - $nbupdatedone = 0; - $resql = $db->query($sql); - if ($resql) { - $num_rows = $db->num_rows($resql); - $i=0; - while ($i < $num_rows) { - $objtmp = $db->fetch_object($resql); - $id = $objtmp->rowid; - $pass = $objtmp->$attributekey; - if ($pass) { - $newpassword = dolEncrypt($pass); - - $sqlupdate = "UPDATE ".MAIN_DB_PREFIX.$arrayofelement['table_element'].'_extrafields'; - $sqlupdate .= " SET ".$attributekey." = '".$db->escape($newpassword)."'"; - $sqlupdate .= " WHERE rowid = ".((int) $id); - - $resupdate = $db->query($sqlupdate); - if ($resupdate) { - $nbupdatedone++; - } else { - setEventMessages($db->lasterror(), '', 'errors'); - $error++; - break; - } - } - - $i++; - } - } - - if ($nbupdatedone > 0) { - setEventMessages($langs->trans("PasswordFieldEncrypted", $nbupdatedone), null, 'mesgs'); - } else { - setEventMessages($langs->trans("PasswordFieldEncrypted", $nbupdatedone), null, 'warnings'); - } - } - } - } - } - } -} --- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_actions_fetchobject.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_fetchobject.inc.php @@ -31,20 +31,24 @@ -if (($id > 0 || (!empty($ref) && !in_array($action, array('create', 'createtask', 'add')))) && (empty($cancel) || $id > 0)) { - if (($id > 0 && is_numeric($id)) || !empty($ref)) { // To discard case when id is list of ids like '1,2,3...' - if ($object->element == 'usergroup') { - $ret = $object->fetch($id, (empty($ref) ? '' : $ref), true); // to load $object->members - } else { - $ret = $object->fetch($id, (empty($ref) ? '' : $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 = ''; - } +if (($id > 0 || (!empty($ref) && !in_array($action, array('create', 'createtask', 'add')))) && (empty($cancel) || $id > 0)) +{ + if (($id > 0 && is_numeric($id)) || !empty($ref)) // To discard case when id is list of ids like '1,2,3...' + { + $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 = ''; + } --- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_actions_lineupdown.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_lineupdown.inc.php @@ -31 +31,2 @@ -if ($action == 'up' && $permissiontoedit) { +if ($action == 'up' && $permissiontoedit) +{ @@ -37,6 +38,2 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { - $newlang = $object->thirdparty->default_lang; - } + 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; @@ -48,2 +45,2 @@ - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); @@ -56 +53,2 @@ -if ($action == 'down' && $permissiontoedit) { +if ($action == 'down' && $permissiontoedit) +{ @@ -62,6 +60,2 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { - $newlang = $object->thirdparty->default_lang; - } + 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; @@ -72,2 +66,2 @@ - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); --- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_actions_linkedfiles.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_linkedfiles.inc.php @@ -24 +23,0 @@ -// If variable $permissiontoadd is defined, we check it is true. Note: A test on permission should already have been done into the restrictedArea() method called by parent page. @@ -30,20 +28,0 @@ -// Protection to understand what happen when submitting files larger than post_max_size -if (GETPOST('uploadform', 'int') && empty($_POST) && empty($_FILES)) { - dol_syslog("The PHP parameter 'post_max_size' is too low. All POST parameters and FILES were set to empty."); - $langs->loadLangs(array("errors", "install")); - print $langs->trans("ErrorFileSizeTooLarge").' '; - print $langs->trans("ErrorGoBackAndCorrectParameters"); - die; -} - -if ((GETPOST('sendit', 'alpha') - || GETPOST('linkit', 'restricthtml') - || ($action == 'confirm_deletefile' && $confirm == 'yes') - || ($action == 'confirm_updateline' && GETPOST('save', 'alpha') && GETPOST('link', 'alpha')) - || ($action == 'renamefile' && GETPOST('renamefilesave', 'alpha'))) && empty($permissiontoadd)) { - dol_syslog('The file actions_linkedfiles.inc.php was included but parameter $permissiontoadd was not set before.'); - print 'The file actions_linkedfiles.inc.php was included but parameter $permissiontoadd was not set before.'; - die; -} - - @@ -51,10 +30,11 @@ -if (GETPOST('sendit', 'alpha') && getDolGlobalString('MAIN_UPLOAD_DOC') && !empty($permissiontoadd)) { - if (!empty($_FILES) && is_array($_FILES['userfile'])) { - if (is_array($_FILES['userfile']['tmp_name'])) { - $userfiles = $_FILES['userfile']['tmp_name']; - } else { - $userfiles = array($_FILES['userfile']['tmp_name']); - } - - foreach ($userfiles as $key => $userfile) { - if (empty($_FILES['userfile']['tmp_name'][$key])) { +if (GETPOST('sendit', 'alpha') && !empty($conf->global->MAIN_UPLOAD_DOC)) +{ + if (!empty($_FILES)) + { + if (is_array($_FILES['userfile']['tmp_name'])) $userfiles = $_FILES['userfile']['tmp_name']; + else $userfiles = array($_FILES['userfile']['tmp_name']); + + foreach ($userfiles as $key => $userfile) + { + if (empty($_FILES['userfile']['tmp_name'][$key])) + { @@ -64 +44,2 @@ - } else { + } + else { @@ -68,4 +48,0 @@ - if (preg_match('/__.*__/', $_FILES['userfile']['name'][$key])) { - $error++; - setEventMessages($langs->trans('ErrorWrongFileName'), null, 'errors'); - } @@ -74 +51,2 @@ - if (!$error) { + if (!$error) + { @@ -77,2 +55,6 @@ - if (GETPOST('section_dir', 'alpha')) { - $generatethumbs = 0; + if (GETPOST('section_dir', 'alpha')) $generatethumbs = 0; + $allowoverwrite = (GETPOST('overwritefile', 'int') ? 1 : 0); + + 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); @@ -80,6 +62,3 @@ - $allowoverwrite = (GETPOST('overwritefile', 'int') ? 1 : 0); - - if (!empty($upload_dirold) && getDolGlobalInt('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_dir, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs, $object); + elseif (!empty($upload_dir)) + { + $result = dol_add_file_process($upload_dir, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs); @@ -89,27 +68,27 @@ -} elseif (GETPOST('linkit', 'restricthtml') && getDolGlobalString('MAIN_UPLOAD_DOC') && !empty($permissiontoadd)) { - $link = GETPOST('link', 'alpha'); - if ($link) { - if (substr($link, 0, 7) != 'http://' && substr($link, 0, 8) != 'https://' && substr($link, 0, 7) != 'file://' && substr($link, 0, 7) != 'davs://') { - $link = 'http://'.$link; - } - - // Parse $newUrl - $newUrlArray = parse_url($link); - - // Allow external links to svg ? - if (!getDolGlobalString('MAIN_ALLOW_SVG_FILES_AS_EXTERNAL_LINKS')) { - if (!empty($newUrlArray['path']) && preg_match('/\.svg$/i', $newUrlArray['path'])) { - $error++; - $langs->load("errors"); - setEventMessages($langs->trans('ErrorSVGFilesNotAllowedAsLinksWithout', 'MAIN_ALLOW_SVG_FILES_AS_EXTERNAL_LINKS'), null, 'errors'); - } - } - // Check URL is external (must refuse local link by default) - if (!getDolGlobalString('MAIN_ALLOW_LOCAL_LINKS_AS_EXTERNAL_LINKS')) { - // Test $newUrlAray['host'] to check link is external using isIPAllowed() and if not refuse the local link - // TODO - } - - if (!$error) { - 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 = basename($urlfile); + $file = $upload_dir.(preg_match('/\/$/', $upload_dir) ? '' : '/').$urlfile; + if (!empty($upload_dirold)) $fileold = $upload_dirold."/".$urlfile; @@ -117,95 +96,94 @@ -} - - -// Delete file/link -if ($action == 'confirm_deletefile' && $confirm == 'yes' && !empty($permissiontoadd)) { - $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; - 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 ($ret) { - // 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); - } - } - 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 (!empty($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') && !empty($permissiontoadd)) { - require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; - - $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') && !empty($permissiontoadd)) { - // For documents pages, upload_dir contains already the path to the file from module dir - if (!empty($upload_dir)) { + $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)) + { @@ -215,109 +193,100 @@ - // 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 (preg_match('/__.*__/', $filenameto)) { - $error++; - setEventMessages($langs->trans('ErrorWrongFileName'), null, 'errors'); - } - - // Check that filename is not the one of a reserved allowed CLI command - if (empty($error)) { - global $dolibarr_main_restrict_os_commands; - if (!empty($dolibarr_main_restrict_os_commands)) { - $arrayofallowedcommand = explode(',', $dolibarr_main_restrict_os_commands); - $arrayofallowedcommand = array_map('trim', $arrayofallowedcommand); - if (in_array(basename($filenameto), $arrayofallowedcommand)) { - $error++; - $langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now. - setEventMessages($langs->trans("ErrorFilenameReserved", basename($filenameto)), null, 'errors'); - } - } - } - - if (empty($error) && $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) && !getDolGlobalString('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', 'aZ09') == 'medias') { - $generatethumbs = 0; - } - - if ($generatethumbs) { - if ($object->id > 0) { - // Create thumbs for the new file - $object->addThumbs($destpath); - - // Delete thumb files 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_19.0.3_actions_massactions.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_massactions.inc.php @@ -3 +3 @@ - * Copyright (C) 2018-2021 Nicolas ZABOURI + * Copyright (C) 2018 Nicolas ZABOURI @@ -6 +6 @@ - * Copyright (C) 2019-2021 Frédéric France + * Copyright (C) 2019 Frédéric France @@ -34 +34 @@ -// $uploaddir may be defined (example to $conf->project->dir_output."/";) +// $uploaddir may be defined (example to $conf->projet->dir_output."/";) @@ -40 +40,2 @@ -if (empty($objectclass) || empty($uploaddir)) { +if (empty($objectclass) || empty($uploaddir)) +{ @@ -44,4 +44,0 @@ -if (empty($massaction)) { - $massaction = ''; -} -$error = 0; @@ -50,9 +47,4 @@ -if (!empty($permtoread) && empty($permissiontoread)) { - $permissiontoread = $permtoread; -} -if (!empty($permtocreate) && empty($permissiontoadd)) { - $permissiontoadd = $permtocreate; -} -if (!empty($permtodelete) && empty($permissiontodelete)) { - $permissiontodelete = $permtodelete; -} +if (!empty($permtoread) && empty($permissiontoread)) $permissiontoread = $permtoread; +if (!empty($permtocreate) && empty($permissiontoadd)) $permissiontoadd = $permtocreate; +if (!empty($permtodelete) && empty($permissiontodelete)) $permissiontodelete = $permtodelete; + @@ -61,2 +53,3 @@ -$maxformassaction = (!getDolGlobalString('MAIN_LIMIT_FOR_MASS_ACTIONS') ? 1000 : $conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS); -if ($massaction && is_array($toselect) && count($toselect) < 1) { +$maxformassaction = (empty($conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS) ? 1000 : $conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS); +if (!empty($massaction) && is_array($toselect) && count($toselect) < 1) +{ @@ -66 +59,2 @@ -if (!$error && isset($toselect) && is_array($toselect) && count($toselect) > $maxformassaction) { +if (!$error && is_array($toselect) && count($toselect) > $maxformassaction) +{ @@ -71 +65,2 @@ -if (!$error && $massaction == 'confirm_presend' && !GETPOST('sendmail')) { // If we do not choose button send (for example when we change template or limit), we must not send email, but keep on send email form +if (!$error && $massaction == 'confirm_presend' && !GETPOST('sendmail')) // If we do not choose button send (for example when we change template or limit), we must not send email, but keep on send email form +{ @@ -74 +69,2 @@ -if (!$error && $massaction == 'confirm_presend') { +if (!$error && $massaction == 'confirm_presend') +{ @@ -80 +75,0 @@ - include_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php'; @@ -88,3 +83,6 @@ - $oneemailperrecipient = (GETPOST('oneemailperrecipient', 'int') ? 1 : 0); - - if (!$error) { + $oneemailperrecipient = (GETPOST('oneemailperrecipient') == 'on' ? 1 : 0); + + if (!$error) + { + $thirdparty = new Societe($db); + @@ -92,16 +90,5 @@ - - // Define object $thirdparty (Societe or User, Adherent, ConferenceOrBoothAttendee...) - $thirdparty = new Societe($db); - if ($objecttmp->element == 'expensereport') { - $thirdparty = new User($db); - } elseif ($objecttmp->element == 'contact') { - $thirdparty = new Contact($db); - } elseif ($objecttmp->element == 'partnership' && getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') { - $thirdparty = new Adherent($db); - } elseif ($objecttmp->element == 'holiday') { - $thirdparty = new User($db); - } elseif ($objecttmp->element == 'conferenceorboothattendee') { - $thirdparty = new ConferenceOrBoothAttendee($db); - } - - foreach ($toselect as $toselectid) { + if ($objecttmp->element == 'expensereport') $thirdparty = new User($db); + if ($objecttmp->element == 'holiday') $thirdparty = new User($db); + + foreach ($toselect as $toselectid) + { @@ -110 +97,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -112,17 +100,6 @@ - $tmpobjectid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid); - if ($objecttmp->element == 'societe') { - $tmpobjectid = $objecttmp->id; - } elseif ($objecttmp->element == 'contact') { - $tmpobjectid = $objecttmp->id; - } elseif ($objecttmp->element == 'expensereport') { - $tmpobjectid = $objecttmp->fk_user_author; - } elseif ($objecttmp->element == 'partnership' && getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') { - $tmpobjectid = $objecttmp->fk_member; - } elseif ($objecttmp->element == 'holiday') { - $tmpobjectid = $objecttmp->fk_user; - } elseif ($objecttmp->element == 'conferenceorboothattendee') { - $tmpobjectid = $objecttmp->id; - } - if (empty($tmpobjectid)) { - $tmpobjectid = 0; - } + + $thirdpartyid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid); + if ($objecttmp->element == 'societe') $thirdpartyid = $objecttmp->id; + if ($objecttmp->element == 'expensereport') $thirdpartyid = $objecttmp->fk_user_author; + if ($objecttmp->element == 'holiday') $thirdpartyid = $objecttmp->fk_user; + if (empty($thirdpartyid)) $thirdpartyid = 0; @@ -138,15 +115,7 @@ - } elseif ($objectclass == 'CommandeFournisseur') { - $tmparraycontact = array(); - $tmparraycontact = $objecttmp->liste_contact(-1, 'external', 0, 'CUSTOMER'); - if (is_array($tmparraycontact) && count($tmparraycontact) > 0) { - foreach ($tmparraycontact as $data_email) { - $listofobjectcontacts[$toselectid][$data_email['id']] = $data_email['email']; - } - } - } - - $listofobjectthirdparties[$tmpobjectid] = $tmpobjectid; - $listofobjectref[$tmpobjectid][$toselectid] = $objecttmp; - } - } - } + } + + $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid; + $listofobjectref[$thirdpartyid][$toselectid] = $objecttmp; + } + } + } @@ -155 +124,2 @@ - if (GETPOST('fromtype', 'alpha') === 'user' && empty($user->email)) { + if (GETPOST('fromtype', 'alpha') === 'user' && empty($user->email)) + { @@ -161,15 +131,15 @@ - $receiver = GETPOST('receiver', 'alphawithlgt'); - if (!is_array($receiver)) { - if (empty($receiver) || $receiver == '-1') { - $receiver = array(); - } else { - $receiver = array($receiver); - } - } - if (!trim($_POST['sendto']) && count($receiver) == 0 && count($listofobjectthirdparties) == 1) { // if only one recipient, receiver is mandatory - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Recipient")), null, 'warnings'); - $massaction = 'presend'; - } - - if (!GETPOST('subject', 'restricthtml')) { + $receiver = $_POST['receiver']; + if (!is_array($receiver)) + { + if (empty($receiver) || $receiver == '-1') $receiver = array(); + else $receiver = array($receiver); + } + if (!trim($_POST['sendto']) && count($receiver) == 0 && count($listofobjectthirdparties) == 1) // if only one recipient, receiver is mandatory + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Recipient")), null, 'warnings'); + $massaction = 'presend'; + } + + if (!GETPOST('subject', 'none')) + { @@ -181,3 +151,5 @@ - // Loop on each recipient (may be a thirdparty but also a user, a conferenceorboothattendee, ...) - if (!$error) { - foreach ($listofobjectthirdparties as $thirdpartyid) { + // Loop on each recipient/thirdparty + if (!$error) + { + foreach ($listofobjectthirdparties as $thirdpartyid) + { @@ -185 +157,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -193 +166 @@ - //$sendtoid = array(); + $sendtoid = array(); @@ -197 +170,2 @@ - if (trim($_POST['sendto'])) { + if (trim($_POST['sendto'])) + { @@ -199,4 +173,6 @@ - $tmparray[] = trim(GETPOST('sendto', 'alphawithlgt')); - } - if (count($receiver) > 0) { - foreach ($receiver as $key => $val) { + $tmparray[] = trim($_POST['sendto']); + } + if (count($receiver) > 0) + { + foreach ($receiver as $key=>$val) + { @@ -204 +180,2 @@ - if ($val == 'thirdparty') { // Id of third party or user + if ($val == 'thirdparty') // Id of third party or user + { @@ -206 +183,3 @@ - } elseif ($val && method_exists($thirdparty, 'contact_get_property')) { // Id of contact + } + elseif ($val && method_exists($thirdparty, 'contact_get_property')) // Id of contact + { @@ -208 +187 @@ - //$sendtoid[] = $val; + $sendtoid[] = $val; @@ -215,7 +194,5 @@ - $receivercc = GETPOST('receivercc', 'alphawithlgt'); - if (!is_array($receivercc)) { - if ($receivercc == '-1') { - $receivercc = array(); - } else { - $receivercc = array($receivercc); - } + $receivercc = $_POST['receivercc']; + if (!is_array($receivercc)) + { + if ($receivercc == '-1') $receivercc = array(); + else $receivercc = array($receivercc); @@ -224,5 +201,8 @@ - if (trim($_POST['sendtocc'])) { - $tmparray[] = trim(GETPOST('sendtocc', 'alphawithlgt')); - } - if (count($receivercc) > 0) { - foreach ($receivercc as $key => $val) { + if (trim($_POST['sendtocc'])) + { + $tmparray[] = trim($_POST['sendtocc']); + } + if (count($receivercc) > 0) + { + foreach ($receivercc as $key=>$val) + { @@ -230 +210,2 @@ - if ($val == 'thirdparty') { // Id of third party + if ($val == 'thirdparty') // Id of third party + { @@ -232 +213,3 @@ - } elseif ($val) { // Id du contact + } + elseif ($val) // Id du contact + { @@ -245 +228,2 @@ - foreach ($listofobjectref[$thirdpartyid] as $objectid => $objectobj) { + foreach ($listofobjectref[$thirdpartyid] as $objectid => $objectobj) + { @@ -247 +231,2 @@ - if ($objectclass == 'Propal' && $objectobj->statut == Propal::STATUS_DRAFT) { + if ($objectclass == 'Propal' && $objectobj->statut == Propal::STATUS_DRAFT) + { @@ -253 +238,2 @@ - if ($objectclass == 'Commande' && $objectobj->statut == Commande::STATUS_DRAFT) { + if ($objectclass == 'Commande' && $objectobj->statut == Commande::STATUS_DRAFT) + { @@ -259 +245,2 @@ - if ($objectclass == 'Facture' && $objectobj->statut == Facture::STATUS_DRAFT) { + if ($objectclass == 'Facture' && $objectobj->statut == Facture::STATUS_DRAFT) + { @@ -267,2 +254,4 @@ - if (empty($sendto)) { // For the case, no recipient were set (multi thirdparties send) - if ($objectobj->element == 'societe') { + if (empty($sendto)) // For the case, no recipient were set (multi thirdparties send) + { + if ($objectobj->element == 'societe') + { @@ -270 +259,3 @@ - } elseif ($objectobj->element == 'expensereport') { + } + elseif ($objectobj->element == 'expensereport') + { @@ -274,13 +265,9 @@ - } elseif ($objectobj->element == 'contact') { - $fcontact = new Contact($db); - $fcontact->fetch($objectobj->id); - $sendto = $fcontact->email; - } elseif ($objectobj->element == 'partnership' && getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') { - $fadherent = new Adherent($db); - $fadherent->fetch($objectobj->fk_member); - $sendto = $fadherent->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])) + { @@ -299,16 +286,3 @@ - } elseif ($objectobj->element == 'order_supplier' && !empty($listofobjectcontacts[$objectid])) { - $emails_to_sends = array(); - $objectobj->fetch_thirdparty(); - $contactidtosend = array(); - foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) { - $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid, 'email'); - if (!in_array($contactemailid, $contactidtosend)) { - $contactidtosend[] = $contactemailid; - } - } - if (count($emails_to_sends) > 0) { - $sendto = implode(',', $emails_to_sends); - } - } elseif ($objectobj->element == 'conferenceorboothattendee') { - $sendto = $objectobj->email; - } else { + } + else + { @@ -320 +294,2 @@ - if (empty($sendto)) { + if (empty($sendto)) + { @@ -325,3 +300,4 @@ - //print "No recipient for thirdparty ".$objectobj->thirdparty->name; - $nbignored++; - if (empty($thirdpartywithoutemail[$objectobj->thirdparty->id])) { + //print "No recipient for thirdparty ".$objectobj->thirdparty->name; + $nbignored++; + if (empty($thirdpartywithoutemail[$objectobj->thirdparty->id])) + { @@ -332,4 +308,5 @@ - continue; - } - - if (GETPOST('addmaindocfile')) { + continue; + } + + if ($_POST['addmaindocfile']) + { @@ -337 +314 @@ - // TODO If not defined, use $objectobj->model_pdf (or defaut invoice config) to know what is template to use to regenerate doc. + // TODO If not defined, use $objectobj->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc. @@ -343 +320 @@ - $filepath = $filedir.'/'.$filename; + $file = $filedir.'/'.$filename; @@ -346 +323,2 @@ - if ($objectobj->element == 'invoice_supplier') { + if ($objectobj->element == 'invoice_supplier') + { @@ -348,26 +326,7 @@ - $filepath = $fileparams['fullname']; - } - - // try to find other files generated for this object (last_main_doc) - $filename_found = ''; - $filepath_found = ''; - $file_check_list = array(); - $file_check_list[] = array( - 'name' => $filename, - 'path' => $filepath, - ); - if (getDolGlobalString('MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND') && !empty($objectobj->last_main_doc)) { - $file_check_list[] = array( - 'name' => basename($objectobj->last_main_doc), - 'path' => DOL_DATA_ROOT . '/' . $objectobj->last_main_doc, - ); - } - foreach ($file_check_list as $file_check_arr) { - if (dol_is_file($file_check_arr['path'])) { - $filename_found = $file_check_arr['name']; - $filepath_found = $file_check_arr['path']; - break; - } - } - - if ($filepath_found) { + $file = $fileparams['fullname']; + } + + $mime = dol_mimetype($file); + + if (dol_is_file($file)) + { @@ -376,3 +335,3 @@ - 'paths'=>array($filepath_found), - 'names'=>array($filename_found), - 'mimes'=>array(dol_mimetype($filepath_found)) + 'paths'=>array($file), + 'names'=>array($filename), + 'mimes'=>array($mime) @@ -380,8 +339,8 @@ - } else { - $nbignored++; - $langs->load("errors"); - foreach ($file_check_list as $file_check_arr) { - $resaction .= '
'.$langs->trans('ErrorCantReadFile', $file_check_arr['path']).'

'; - dol_syslog('Failed to read file: '.$file_check_arr['path'], LOG_WARNING); - } - continue; + } + else + { + $nbignored++; + $langs->load("errors"); + $resaction .= '
'.$langs->trans('ErrorCantReadFile', $file).'

'; + dol_syslog('Failed to read file: '.$file, LOG_WARNING); + continue; @@ -400 +359,2 @@ - if (count($listofqualifiedobj) > 0) { + if (count($listofqualifiedobj) > 0) + { @@ -406,4 +366,6 @@ - $from = dol_string_nospecial($user->getFullName($langs), ' ', array(",")).' <'.$user->email.'>'; - } elseif ($fromtype === 'company') { - $from = getDolGlobalString('MAIN_INFO_SOCIETE_NOM') . ' <' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL').'>'; - } elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { + $from = $user->getFullName($langs).' <'.$user->email.'>'; + } + elseif ($fromtype === 'company') { + $from = $conf->global->MAIN_INFO_SOCIETE_NOM.' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; + } + elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { @@ -412,2 +374,3 @@ - } elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { - $tmp = explode(',', getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES')); + } + elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { + $tmp = explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES); @@ -415,2 +378,3 @@ - } 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]; + } + 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]; @@ -419,5 +383,7 @@ - if ($obj) { - $from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>'; - } - } else { - $from = GETPOST('fromname').' <'.GETPOST('frommail').'>'; + if ($obj) + { + $from = $obj->label.' <'.$obj->email.'>'; + } + } + else { + $from = $_POST['fromname'].' <'.$_POST['frommail'].'>'; @@ -427,2 +393,2 @@ - $subject = GETPOST('subject', 'restricthtml'); - $message = GETPOST('message', 'restricthtml'); + $subject = GETPOST('subject', 'none'); + $message = GETPOST('message', 'none'); @@ -431,21 +397,7 @@ - if ($objectclass == 'Propal') { - $sendtobcc .= (!getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROPOSAL_TO') ? '' : (($sendtobcc ? ", " : "") . getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROPOSAL_TO'))); - } - if ($objectclass == 'Commande') { - $sendtobcc .= (!getDolGlobalString('MAIN_MAIL_AUTOCOPY_ORDER_TO') ? '' : (($sendtobcc ? ", " : "") . getDolGlobalString('MAIN_MAIL_AUTOCOPY_ORDER_TO'))); - } - if ($objectclass == 'Facture') { - $sendtobcc .= (!getDolGlobalString('MAIN_MAIL_AUTOCOPY_INVOICE_TO') ? '' : (($sendtobcc ? ", " : "") . getDolGlobalString('MAIN_MAIL_AUTOCOPY_INVOICE_TO'))); - } - if ($objectclass == 'SupplierProposal') { - $sendtobcc .= (!getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO') ? '' : (($sendtobcc ? ", " : "") . getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO'))); - } - if ($objectclass == 'CommandeFournisseur') { - $sendtobcc .= (!getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO') ? '' : (($sendtobcc ? ", " : "") . getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO'))); - } - if ($objectclass == 'FactureFournisseur') { - $sendtobcc .= (!getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO') ? '' : (($sendtobcc ? ", " : "") . getDolGlobalString('MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO'))); - } - if ($objectclass == 'Project') { - $sendtobcc .= (!getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROJECT_TO') ? '' : (($sendtobcc ? ", " : "") . getDolGlobalString('MAIN_MAIL_AUTOCOPY_PROJECT_TO'))); - } + if ($objectclass == 'Propal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)); + if ($objectclass == 'Commande') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)); + if ($objectclass == 'Facture') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)); + if ($objectclass == 'Supplier_Proposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO)); + if ($objectclass == 'CommandeFournisseur') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO)); + if ($objectclass == 'FactureFournisseur') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO)); + if ($objectclass == 'Project') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO) ? '' : (($sendtobcc ? ", " : "").$conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO)); @@ -456 +408,2 @@ - if (!$oneemailperrecipient) { + if (!$oneemailperrecipient) + { @@ -458,4 +411,7 @@ - foreach ($looparray as $key => $objecttmp) { - $looparray[$key]->thirdparty = $thirdparty; // Force thirdparty on object - } - } else { + foreach ($looparray as $key => $objecttmp) + { + $looparray[$key]->thirdparty = $thirdparty; // Force thirdparty on object + } + } + else + { @@ -467,3 +423,4 @@ - 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 + { @@ -471 +428,2 @@ - if (isModEnabled('project') && method_exists($objecttmp, 'fetch_projet') && is_null($objecttmp->project)) { + if (!empty($conf->projet->enabled) && method_exists($objecttmp, 'fetch_projet') && is_null($objecttmp->project)) + { @@ -478 +436 @@ - $substitutionarray['__CHECK_READ__'] = ''; + $substitutionarray['__CHECK_READ__'] = ''; @@ -491,5 +449,6 @@ - $subjectreplaced = make_substitutions($subject, $substitutionarray); - $messagereplaced = make_substitutions($message, $substitutionarray); - - $attachedfiles = array('paths'=>array(), 'names'=>array(), 'mimes'=>array()); - if ($oneemailperrecipient) { + $subjectreplaced = make_substitutions($subject, $substitutionarray); + $messagereplaced = make_substitutions($message, $substitutionarray); + + $attachedfiles = array('paths'=>array(), 'names'=>array(), 'mimes'=>array()); + if ($oneemailperrecipient) + { @@ -497,2 +456,3 @@ - if (is_array($attachedfilesThirdpartyObj[$thirdparty->id]) && count($attachedfilesThirdpartyObj[$thirdparty->id])) { - foreach ($attachedfilesThirdpartyObj[$thirdparty->id] as $keyObjId => $objAttachedFiles) { + if (is_array($attachedfilesThirdpartyObj[$thirdparty->id]) && count($attachedfilesThirdpartyObj[$thirdparty->id])) + { + foreach ($attachedfilesThirdpartyObj[$thirdparty->id] as $keyObjId => $objAttachedFiles) { @@ -507 +467,2 @@ - } elseif (!empty($attachedfilesThirdpartyObj[$thirdparty->id][$objectid])) { + } + elseif (!empty($attachedfilesThirdpartyObj[$thirdparty->id][$objectid])) { @@ -518,30 +479,18 @@ - if ($oneemailperrecipient) { - $trackid = 'thi'.$thirdparty->id; - if ($objecttmp->element == 'expensereport') { - $trackid = 'use'.$thirdparty->id; - } elseif ($objecttmp->element == 'contact') { - $trackid = 'ctc'.$thirdparty->id; - } elseif ($objecttmp->element == 'holiday') { - $trackid = 'use'.$thirdparty->id; - } - } else { - $trackid = strtolower(get_class($objecttmp)); - if (get_class($objecttmp) == 'Contact') { - $trackid = 'ctc'; - } elseif (get_class($objecttmp) == 'Contrat') { - $trackid = 'con'; - } elseif (get_class($objecttmp) == 'Propal') { - $trackid = 'pro'; - } elseif (get_class($objecttmp) == 'Commande') { - $trackid = 'ord'; - } elseif (get_class($objecttmp) == 'Facture') { - $trackid = 'inv'; - } elseif (get_class($objecttmp) == 'SupplierProposal') { - $trackid = 'spr'; - } elseif (get_class($objecttmp) == 'CommandeFournisseur') { - $trackid = 'sor'; - } elseif (get_class($objecttmp) == 'FactureFournisseur') { - $trackid = 'sin'; - } - - $trackid .= $objecttmp->id; + 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; @@ -553,7 +502 @@ - if (empty($sendcontext)) { - $sendcontext = 'standard'; - } - - // Set tmp user directory (used to convert images embedded as img src=data:image) - $vardir = $conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path + if (empty($sendcontext)) $sendcontext = 'standard'; @@ -562,3 +505,4 @@ - 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, '', $upload_dir_tmp); - if ($mailfile->error) { + 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) + { @@ -566 +510,3 @@ - } else { + } + else + { @@ -568,2 +514,3 @@ - if ($result > 0) { - $resaction .= $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($mailfile->addr_from, 2), $mailfile->getValidAddress($mailfile->addr_to, 2)).'
'; // Must not contain " + if ($result) + { + $resaction .= $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2)).'
'; // Must not contain " @@ -574,6 +521,5 @@ - 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)); + 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)); @@ -582,5 +528,5 @@ - if ($objectclass == 'Commande') $actiontypecode='AC_COM'; - if ($objectclass == 'Facture') $actiontypecode='AC_FAC'; - if ($objectclass == 'SupplierProposal') $actiontypecode='AC_SUP_PRO'; - if ($objectclass == 'CommandeFournisseur') $actiontypecode='AC_SUP_ORD'; - if ($objectclass == 'FactureFournisseur') $actiontypecode='AC_SUP_INV';*/ + if ($objectclass == 'Commande') $actiontypecode='AC_COM'; + if ($objectclass == 'Facture') $actiontypecode='AC_FAC'; + if ($objectclass == 'Supplier_Proposal') $actiontypecode='AC_SUP_PRO'; + if ($objectclass == 'CommandeFournisseur') $actiontypecode='AC_SUP_ORD'; + if ($objectclass == 'FactureFournisseur') $actiontypecode='AC_SUP_INV';*/ @@ -589,5 +535,4 @@ - if ($message) { - if ($sendtocc) { - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc); - } - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subjectreplaced); + if ($message) + { + if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".$sendtocc); + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subjectreplaced); @@ -595 +540 @@ - $actionmsg = dol_concatdesc($actionmsg, $messagereplaced); + $actionmsg = dol_concatdesc($actionmsg, $messagereplaced); @@ -599,9 +544,6 @@ - // 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; - if (getDolGlobalString('MAIN_MAIL_REPLACE_EVENT_TITLE_BY_EMAIL_SUBJECT')) { - $objectobj2->actionmsg2 = $subjectreplaced; // Short text - } + // 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; @@ -610,29 +552,11 @@ - if ($triggername == 'SOCIETE_SENTBYMAIL') { - $triggername = 'COMPANY_SENTBYMAIL'; - } - if ($triggername == 'CONTRAT_SENTBYMAIL') { - $triggername = 'CONTRACT_SENTBYMAIL'; - } - if ($triggername == 'COMMANDE_SENTBYMAIL') { - $triggername = 'ORDER_SENTBYMAIL'; - } - if ($triggername == 'FACTURE_SENTBYMAIL') { - $triggername = 'BILL_SENTBYMAIL'; - } - if ($triggername == 'EXPEDITION_SENTBYMAIL') { - $triggername = 'SHIPPING_SENTBYMAIL'; - } - if ($triggername == 'COMMANDEFOURNISSEUR_SENTBYMAIL') { - $triggername = 'ORDER_SUPPLIER_SENTBYMAIL'; - } - if ($triggername == 'FACTUREFOURNISSEUR_SENTBYMAIL') { - $triggername = 'BILL_SUPPLIER_SENTBYMAIL'; - } - if ($triggername == 'SUPPLIERPROPOSAL_SENTBYMAIL') { - $triggername = 'PROPOSAL_SUPPLIER_SENTBYMAIL'; - } - if ($triggername == 'PROJET_SENTBYMAIL') { - $triggername = 'PROJECT_SENTBYMAIL'; - } - - if (!empty($triggername)) { + if ($triggername == 'SOCIETE_SENTBYMAIL') $triggername = 'COMPANY_SENTBYMAIL'; + if ($triggername == 'CONTRAT_SENTBYMAIL') $triggername = 'CONTRACT_SENTBYMAIL'; + if ($triggername == 'COMMANDE_SENTBYMAIL') $triggername = 'ORDER_SENTBYMAIL'; + if ($triggername == 'FACTURE_SENTBYMAIL') $triggername = 'BILL_SENTBYMAIL'; + if ($triggername == 'EXPEDITION_SENTBYMAIL') $triggername = 'SHIPPING_SENTBYMAIL'; + if ($triggername == 'COMMANDEFOURNISSEUR_SENTBYMAIL') $triggername = 'ORDER_SUPPLIER_SENTBYMAIL'; + if ($triggername == 'FACTUREFOURNISSEUR_SENTBYMAIL') $triggername = 'BILL_SUPPLIER_SENTBYMAIL'; + if ($triggername == 'SUPPLIERPROPOSAL_SENTBYMAIL') $triggername = 'PROPOSAL_SUPPLIER_SENTBYMAIL'; + + if (!empty($triggername)) + { @@ -641,3 +565 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -646 +568,2 @@ - if ($error) { + if ($error) + { @@ -654 +577,3 @@ - } else { + } + else + { @@ -656 +581,2 @@ - if ($mailfile->error) { + if ($mailfile->error) + { @@ -659 +585,3 @@ - } elseif (getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) { + } + else + { @@ -661,2 +588,0 @@ - } else { - $resaction .= $langs->trans('ErrorFailedToSendMail', $from, $sendto) . '
(unhandled error)
'; @@ -676 +602,2 @@ - if ($nbsent) { + if ($nbsent) + { @@ -681 +608,3 @@ - } else { + } + else + { @@ -691,2 +620,11 @@ - -if (!$error && $massaction == 'cancelorders') { +if ($massaction == 'confirm_createbills') // Create bills from orders +{ + $orders = GETPOST('toselect', 'array'); + $createbills_onebythird = GETPOST('createbills_onebythird', 'int'); + $validate_invoices = GETPOST('validate_invoices', 'int'); + + $TFact = array(); + $TFactThird = array(); + + $nb_bills_created = 0; + @@ -694,0 +633,267 @@ + foreach ($orders as $id_order) + { + $cmd = new Commande($db); + if ($cmd->fetch($id_order) <= 0) continue; + + $objecttmp = new Facture($db); + if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order. + else { + // Load extrafields of order + $cmd->fetch_optionals(); + + $objecttmp->socid = $cmd->socid; + $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->date = $datefacture; + $objecttmp->origin = 'commande'; + $objecttmp->origin_id = $id_order; + + $objecttmp->array_options = $cmd->array_options; // Copy extrafields + + $res = $objecttmp->create($user); + + if ($res > 0) $nb_bills_created++; + } + + if ($objecttmp->id > 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; + $sql .= "fk_source"; + $sql .= ", sourcetype"; + $sql .= ", fk_target"; + $sql .= ", targettype"; + $sql .= ") VALUES ("; + $sql .= $id_order; + $sql .= ", '".$objecttmp->origin."'"; + $sql .= ", ".$objecttmp->id; + $sql .= ", '".$objecttmp->element."'"; + $sql .= ")"; + + if (!$db->query($sql)) + { + $error++; + } + + if (!$error) + { + $lines = $cmd->lines; + if (empty($lines) && method_exists($cmd, 'fetch_lines')) + { + $cmd->fetch_lines(); + $lines = $cmd->lines; + } + + $fk_parent_line = 0; + $num = count($lines); + + for ($i = 0; $i < $num; $i++) + { + $desc = ($lines[$i]->desc ? $lines[$i]->desc : ''); + // 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')); + } + + if ($lines[$i]->subprice < 0) + { + // Negative line, we create a discount line + $discount = new DiscountAbsolute($db); + $discount->fk_soc = $objecttmp->socid; + $discount->amount_ht = abs($lines[$i]->total_ht); + $discount->amount_tva = abs($lines[$i]->total_tva); + $discount->amount_ttc = abs($lines[$i]->total_ttc); + $discount->tva_tx = $lines[$i]->tva_tx; + $discount->fk_user = $user->id; + $discount->description = $desc; + $discountid = $discount->create($user); + if ($discountid > 0) + { + $result = $objecttmp->insert_discount($discountid); + //$result=$discount->link_to_invoice($lineid,$id); + } + else + { + setEventMessages($discount->error, $discount->errors, 'errors'); + $error++; + break; + } + } + else + { + // Positive line + $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0); + // Date start + $date_start = false; + if ($lines[$i]->date_debut_prevue) $date_start = $lines[$i]->date_debut_prevue; + if ($lines[$i]->date_debut_reel) $date_start = $lines[$i]->date_debut_reel; + if ($lines[$i]->date_start) $date_start = $lines[$i]->date_start; + //Date end + $date_end = false; + if ($lines[$i]->date_fin_prevue) $date_end = $lines[$i]->date_fin_prevue; + if ($lines[$i]->date_fin_reel) $date_end = $lines[$i]->date_fin_reel; + if ($lines[$i]->date_end) $date_end = $lines[$i]->date_end; + // Reset fk_parent_line for no child products and special product + if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) + { + $fk_parent_line = 0; + } + + // Extrafields + if (method_exists($lines[$i], 'fetch_optionals')) { + $lines[$i]->fetch_optionals(); + $array_options = $lines[$i]->array_options; + } + + $result = $objecttmp->addline( + $desc, + $lines[$i]->subprice, + $lines[$i]->qty, + $lines[$i]->tva_tx, + $lines[$i]->localtax1_tx, + $lines[$i]->localtax2_tx, + $lines[$i]->fk_product, + $lines[$i]->remise_percent, + $date_start, + $date_end, + 0, + $lines[$i]->info_bits, + $lines[$i]->fk_remise_except, + 'HT', + 0, + $product_type, + $ii, + $lines[$i]->special_code, + $objecttmp->origin, + $lines[$i]->rowid, + $fk_parent_line, + $lines[$i]->fk_fournprice, + $lines[$i]->pa_ht, + $lines[$i]->label, + $array_options, + 100, + 0, + $lines[$i]->fk_unit + ); + if ($result > 0) + { + $lineid = $result; + } + else + { + $lineid = 0; + $error++; + break; + } + // Defined the new fk_parent_line + if ($result > 0 && $lines[$i]->product_type == 9) + { + $fk_parent_line = $result; + } + } + } + } + } + + //$cmd->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module. + + if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $objecttmp; + else $TFact[$objecttmp->id] = $objecttmp; + } + + // Build doc with all invoices + $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird; + $toselect = array(); + + if (!$error && $validate_invoices) + { + $massaction = $action = 'builddoc'; + + foreach ($TAllFact as &$objecttmp) + { + $result = $objecttmp->validate($user); + if ($result <= 0) + { + $error++; + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + break; + } + + $id = $objecttmp->id; // For builddoc action + $object = $objecttmp; + + // Builddoc + $donotredirect = 1; + $upload_dir = $conf->facture->dir_output; + $permissiontoadd = $user->rights->facture->creer; + + // Call action to build doc + $savobject = $object; + $object = $objecttmp; + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; + $object = $savobject; + } + + $massaction = $action = 'confirm_createbills'; + } + + if (!$error) + { + $db->commit(); + 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 = ''; + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); + if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); + if ($sall) $param .= '&sall='.urlencode($sall); + if ($socid > 0) $param .= '&socid='.urlencode($socid); + if ($search_status != '') $param .= '&search_status='.urlencode($search_status); + if ($search_orderday) $param .= '&search_orderday='.urlencode($search_orderday); + if ($search_ordermonth) $param .= '&search_ordermonth='.urlencode($search_ordermonth); + if ($search_orderyear) $param .= '&search_orderyear='.urlencode($search_orderyear); + if ($search_deliveryday) $param .= '&search_deliveryday='.urlencode($search_deliveryday); + if ($search_deliverymonth) $param .= '&search_deliverymonth='.urlencode($search_deliverymonth); + if ($search_deliveryyear) $param .= '&search_deliveryyear='.urlencode($search_deliveryyear); + if ($search_ref) $param .= '&search_ref='.urlencode($search_ref); + if ($search_company) $param .= '&search_company='.urlencode($search_company); + if ($search_ref_customer) $param .= '&search_ref_customer='.urlencode($search_ref_customer); + if ($search_user > 0) $param .= '&search_user='.urlencode($search_user); + if ($search_sale > 0) $param .= '&search_sale='.urlencode($search_sale); + if ($search_total_ht != '') $param .= '&search_total_ht='.urlencode($search_total_ht); + if ($search_total_vat != '') $param .= '&search_total_vat='.urlencode($search_total_vat); + if ($search_total_ttc != '') $param .= '&search_total_ttc='.urlencode($search_total_ttc); + if ($search_project_ref >= 0) $param .= "&search_project_ref=".urlencode($search_project_ref); + if ($show_files) $param .= '&show_files='.urlencode($show_files); + if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); + if ($billed != '') $param .= '&billed='.urlencode($billed); + + header("Location: ".$_SERVER['PHP_SELF'].'?'.$param); + exit; + } + else + { + $db->rollback(); + $action = 'create'; + $_GET["origin"] = $_POST["origin"]; + $_GET["originid"] = $_POST["originid"]; + setEventMessages("Error", null, 'errors'); + $error++; + } +} + +if (!$error && $massaction == 'cancelorders') +{ + $db->begin(); + @@ -696,0 +902 @@ + @@ -698 +904,2 @@ - foreach ($orders as $id_order) { + foreach ($orders as $id_order) + { @@ -700 +907 @@ - if ($cmd->fetch($id_order) <= 0) { + if ($cmd->fetch($id_order) <= 0) @@ -702,3 +909,3 @@ - } - - if ($cmd->statut != Commande::STATUS_VALIDATED) { + + if ($cmd->statut != Commande::STATUS_VALIDATED) + { @@ -714 +921,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -718 +926,2 @@ - } else { + } + else @@ -720,4 +929,4 @@ - } - } - if (!$error) { - if ($nbok > 1) { + } + if (!$error) + { + if ($nbok > 1) @@ -725 +934 @@ - } else { + else @@ -727 +935,0 @@ - } @@ -729 +937,3 @@ - } else { + } + else + { @@ -735,2 +945,4 @@ -if (!$error && $massaction == "builddoc" && $permissiontoread && !GETPOST('button_search')) { - if (empty($diroutputmassaction)) { +if (!$error && $massaction == "builddoc" && $permissiontoread && !GETPOST('button_search')) +{ + if (empty($diroutputmassaction)) + { @@ -749 +961,2 @@ - foreach ($toselect as $toselectid) { + foreach ($toselect as $toselectid) + { @@ -752 +965,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -754 +968 @@ - $thirdpartyid = !empty($objecttmp->fk_soc) ? $objecttmp->fk_soc : $objecttmp->socid; + $thirdpartyid = $objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid; @@ -761,6 +975,2 @@ - foreach ($listofobjectref as $tmppdf) { - $arrayofinclusion[] = '^'.preg_quote(dol_sanitizeFileName($tmppdf), '/').'\.pdf$'; - } - foreach ($listofobjectref as $tmppdf) { - $arrayofinclusion[] = '^'.preg_quote(dol_sanitizeFileName($tmppdf), '/').'_[a-zA-Z0-9\-\_\'\&\.]+\.pdf$'; // To include PDF generated from ODX files - } + foreach ($listofobjectref as $tmppdf) $arrayofinclusion[] = '^'.preg_quote(dol_sanitizeFileName($tmppdf), '/').'\.pdf$'; + foreach ($listofobjectref as $tmppdf) $arrayofinclusion[] = '^'.preg_quote(dol_sanitizeFileName($tmppdf), '/').'_[a-zA-Z0-9-_]+\.pdf$'; // To include PDF generated from ODX files @@ -771 +981,2 @@ - foreach ($listofobjectref as $basename) { + foreach ($listofobjectref as $basename) + { @@ -773,2 +984,4 @@ - foreach ($listoffiles as $filefound) { - if (strstr($filefound["name"], $basename)) { + foreach ($listoffiles as $filefound) + { + if (strstr($filefound["name"], $basename)) + { @@ -784,6 +997,2 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - //elseif (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && is_object($objecttmp->thirdparty)) { // On massaction, we can have several values for $objecttmp->thirdparty - // $newlang = $objecttmp->thirdparty->default_lang; - //} + 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; @@ -795 +1004,2 @@ - if (getDolGlobalString('USE_PDFTK_FOR_PDF_CONCAT')) { + if (!empty($conf->global->USE_PDFTK_FOR_PDF_CONCAT)) + { @@ -804,15 +1014,10 @@ - if (in_array($objecttmp->element, array('facture', 'facture_fournisseur')) && $search_status == Facture::STATUS_VALIDATED) { - if ($option == 'late') { - $filename .= '_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late"))); - } else { - $filename .= '_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))); - } - } - if ($year) { - $filename .= '_'.$year; - } - if ($month) { - $filename .= '_'.$month; - } - - if (count($files) > 0) { + if (in_array($objecttmp->element, array('facture', 'facture_fournisseur')) && $search_status == Facture::STATUS_VALIDATED) + { + if ($option == 'late') $filename .= '_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late"))); + else $filename .= '_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))); + } + if ($year) $filename .= '_'.$year; + if ($month) $filename .= '_'.$month; + + if (count($files) > 0) + { @@ -827 +1032 @@ - $cmd = 'pdftk '.$input_files.' cat output '.escapeshellarg($file); + $cmd = 'pdftk ' . $input_files . ' cat output '.escapeshellarg($file); @@ -832,2 +1037,2 @@ - dolChmod($file); - + if (!empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); @@ -839 +1044,3 @@ - } else { + } + else + { @@ -842 +1049,2 @@ - } else { + } + else { @@ -851 +1059,2 @@ - if (class_exists('TCPDF')) { + if (class_exists('TCPDF')) + { @@ -857,3 +1066 @@ - if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) { - $pdf->SetCompression(false); - } + if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); @@ -862 +1069,2 @@ - foreach ($files as $file) { + foreach ($files as $file) + { @@ -865 +1073,2 @@ - for ($i = 1; $i <= $pagecount; $i++) { + for ($i = 1; $i <= $pagecount; $i++) + { @@ -881,14 +1090,9 @@ - if (in_array($objecttmp->element, array('facture', 'facture_fournisseur')) && $search_status == Facture::STATUS_VALIDATED) { - if ($option == 'late') { - $filename .= '_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late"))); - } else { - $filename .= '_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))); - } - } - if ($year) { - $filename .= '_'.$year; - } - if ($month) { - $filename .= '_'.$month; - } - if ($pagecount) { + if (in_array($objecttmp->element, array('facture', 'facture_fournisseur')) && $search_status == Facture::STATUS_VALIDATED) + { + if ($option == 'late') $filename .= '_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late"))); + else $filename .= '_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))); + } + if ($year) $filename .= '_'.$year; + if ($month) $filename .= '_'.$month; + if ($pagecount) + { @@ -898 +1102,2 @@ - dolChmod($file); + if (!empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); @@ -902,2 +1107,4 @@ - } else { - setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors'); + } + else + { + setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors'); @@ -909 +1116,2 @@ -if ($action == 'remove_file') { +if ($action == 'remove_file') +{ @@ -916,5 +1124,2 @@ - if ($ret) { - setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs'); - } else { - setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors'); - } + if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs'); + else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors'); @@ -924 +1128,0 @@ - @@ -926 +1130,2 @@ -if (!$error && $massaction == 'validate' && $permissiontoadd) { +if (!$error && $massaction == 'validate' && $permissiontoadd) +{ @@ -929 +1134,2 @@ - if (($objecttmp->element == 'facture' || $objecttmp->element == 'invoice') && isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_BILL')) { + if (($objecttmp->element == 'facture' || $objecttmp->element == 'invoice') && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) + { @@ -934 +1140,2 @@ - if ($objecttmp->element == 'invoice_supplier' && isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL')) { + if ($objecttmp->element == 'invoice_supplier' && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) + { @@ -939,21 +1146,2 @@ - if ($objecttmp->element == 'facture') { - if (!empty($toselect) && getDolGlobalString('INVOICE_CHECK_POSTERIOR_DATE')) { - // order $toselect by date - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture"; - $sql .= " WHERE rowid IN (".$db->sanitize(implode(",", $toselect)).")"; - $sql .= " ORDER BY datef"; - - $resql = $db->query($sql); - if ($resql) { - $toselectnew = []; - while (!empty($arr = $db->fetch_row($resql))) { - $toselectnew[] = $arr[0]; - } - $toselect = (empty($toselectnew)) ? $toselect : $toselectnew; - } else { - dol_print_error($db); - $error++; - } - } - } - if (!$error) { + if (!$error) + { @@ -963 +1151,2 @@ - foreach ($toselect as $toselectid) { + foreach ($toselect as $toselectid) + { @@ -965,10 +1154,5 @@ - if ($result > 0) { - if (method_exists($objecttmp, 'validate')) { - $result = $objecttmp->validate($user); - } elseif (method_exists($objecttmp, 'setValid')) { - $result = $objecttmp->setValid($user); - } else { - $objecttmp->error = 'No method validate or setValid on this object'; - $result = -1; - } - if ($result == 0) { + if ($result > 0) + { + $result = $objecttmp->validate($user); + if ($result == 0) + { @@ -979 +1163,3 @@ - } elseif ($result < 0) { + } + elseif ($result < 0) + { @@ -983,38 +1169,5 @@ - } else { - // validate() rename pdf but do not regenerate - // Define output language - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { - $outputlangs = $langs; - $newlang = ''; - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && property_exists($objecttmp, 'thirdparty')) { - if ((property_exists($objecttmp, 'socid') || property_exists($objecttmp, 'fk_soc')) && empty($objecttmp->thirdparty)) { - $objecttmp->fetch_thirdparty(); - } - if (!empty($objecttmp->thirdparty)) { - $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 : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0); - $hidedesc = !empty($hidedesc) ? $hidedesc : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0); - $hideref = !empty($hideref) ? $hideref : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 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 + { @@ -1027,6 +1180,4 @@ - if (!$error) { - if ($nbok > 1) { - setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); - } else { - setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); - } + if (!$error) + { + if ($nbok > 1) setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); + else setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); @@ -1034 +1185,3 @@ - } else { + } + else + { @@ -1041 +1194,36 @@ -//var_dump($_POST);var_dump($massaction);exit; +// 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(); + } +} + @@ -1044 +1232,2 @@ -if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete) { +if (!$error && ($massaction == 'delete' || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete) +{ @@ -1049,5 +1238,2 @@ - $TMsg = array(); - - //$toselect could contain duplicate entries, cf https://github.com/Dolibarr/dolibarr/issues/26244 - $unique_arr = array_unique($toselect); - foreach ($unique_arr as $toselectid) { + foreach ($toselect as $toselectid) + { @@ -1055 +1241,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -1057 +1244,2 @@ - if ($objectclass == 'Facture' && !getDolGlobalString('INVOICE_CAN_ALWAYS_BE_REMOVED') && $objecttmp->status != Facture::STATUS_DRAFT) { + if ($objectclass == 'Facture' && empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $objecttmp->status != Facture::STATUS_DRAFT) + { @@ -1060 +1248 @@ - $TMsg[] = '
'.$langs->trans('ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).'

'; + $resaction .= '
'.$langs->trans('ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).'

'; @@ -1064,16 +1252,3 @@ - if (method_exists($objecttmp, 'is_erasable') && $objecttmp->is_erasable() <= 0) { - $langs->load("errors"); - $nbignored++; - $TMsg[] = '
'.$langs->trans('ErrorRecordHasChildren').' '.$objecttmp->ref.'

'; - continue; - } - - if ($objectclass == 'Holiday' && ! in_array($objecttmp->statut, array(Holiday::STATUS_DRAFT, Holiday::STATUS_CANCELED, Holiday::STATUS_REFUSED))) { - $langs->load("errors"); - $nbignored++; - $TMsg[] = '
'.$langs->trans('ErrorLeaveRequestMustBeDraftCanceledOrRefusedToBeDeleted', $objecttmp->ref).'

'; - continue; - } - - if ($objectclass == "Task" && $objecttmp->hasChildren() > 0) { - $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET fk_task_parent = 0 WHERE fk_task_parent = ".((int) $objecttmp->id); + if ($objectclass == "Task" && $objecttmp->hasChildren() > 0) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET fk_task_parent = 0 WHERE fk_task_parent = ".$objecttmp->id; @@ -1082 +1257,2 @@ - if (!$res) { + if (!$res) + { @@ -1088,18 +1264,13 @@ - if (in_array($objecttmp->element, array('societe', 'member'))) { - $result = $objecttmp->delete($objecttmp->id, $user, 1); - } elseif (in_array($objecttmp->element, array('action'))) { - $result = $objecttmp->delete(); // TODO Add User $user as first param - } else { - $result = $objecttmp->delete($user); - } - - if (empty($result)) { // if delete returns 0, there is at least one object linked - $TMsg = array_merge($objecttmp->errors, $TMsg); - } elseif ($result < 0) { // if delete returns is < 0, there is an error, we break and rollback later - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } else { - $nbok++; - } - } else { + if (in_array($objecttmp->element, array('societe', 'member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1); + else $result = $objecttmp->delete($user); + + if ($result <= 0) + { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + else $nbok++; + } + else + { @@ -1112,16 +1283,4 @@ - if (empty($error)) { - // Message for elements well deleted - if ($nbok > 1) { - setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); - } elseif ($nbok > 0) { - setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs'); - } else { - setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs'); - } - - // Message for elements which can't be deleted - if (!empty($TMsg)) { - sort($TMsg); - setEventMessages('', array_unique($TMsg), 'warnings'); - } - + if (!$error) + { + if ($nbok > 1) setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); + else setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs'); @@ -1129 +1288,3 @@ - } else { + } + else + { @@ -1132 +1292,0 @@ - @@ -1138,68 +1298,57 @@ -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 (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) { - $newlang = $objecttmp->thirdparty->default_lang; // for proposal, order, invoice, ... - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->default_lang)) { - $newlang = $objecttmp->default_lang; // for thirdparty - } - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && empty($objecttmp->thirdparty)) { //load lang from thirdparty - $objecttmp->fetch_thirdparty(); - $newlang = $objecttmp->thirdparty->default_lang; // for proposal, order, invoice, ... - } - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - - // To be sure vars is defined - if (empty($hidedetails)) { - $hidedetails = (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0); - } - if (empty($hidedesc)) { - $hidedesc = (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0); - } - if (empty($hideref)) { - $hideref = (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0); - } - if (empty($moreparams)) { - $moreparams = null; - } - - $result = $objecttmp->generateDocument($objecttmp->model_pdf, $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(); - } +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(); + } @@ -1208,584 +1357 @@ -if (!$error && ($action == 'affecttag' && $confirm == 'yes') && $permissiontoadd) { - $db->begin(); - - $affecttag_type=GETPOST('affecttag_type', 'alpha'); - if (!empty($affecttag_type)) { - $affecttag_type_array=explode(',', $affecttag_type); - } else { - setEventMessage('CategTypeNotFound', 'errors'); - } - if (!empty($affecttag_type_array)) { - //check if tag type submited exists into Tag Map categorie class - require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $categ = new Categorie($db); - $to_affecttag_type_array=array(); - $categ_type_array=$categ->getMapList(); - foreach ($categ_type_array as $categdef) { - if (in_array($categdef['code'], $affecttag_type_array)) { - $to_affecttag_type_array[] = $categdef['code']; - } - } - - //For each valid categ type set common categ - $nbok = 0; - if (!empty($to_affecttag_type_array)) { - foreach ($to_affecttag_type_array as $categ_type) { - $contcats = GETPOST('contcats_' . $categ_type, 'array'); - //var_dump($toselect);exit; - foreach ($toselect as $toselectid) { - $result = $object->fetch($toselectid); - //var_dump($contcats);exit; - if ($result > 0) { - $result = $object->setCategoriesCommon($contcats, $categ_type, false); - if ($result > 0) { - $nbok++; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - break; - } - } - } - } - } - - if (!$error) { - if ($nbok > 1) { - setEventMessages($langs->trans("RecordsModified", $nbok), null); - } else { - setEventMessages($langs->trans("RecordsModified", $nbok), null); - } - $db->commit(); - $toselect=array(); - } else { - $db->rollback(); - } -} - -if (!$error && ($action == 'updateprice' && $confirm == 'yes') && $permissiontoadd) { - $db->begin(); - if (GETPOSTISSET('pricerate')) { - $pricepercentage=GETPOST('pricerate', 'int'); - if ($pricepercentage == 0) { - setEventMessages($langs->trans("RecordsModified", 0), null); - } else { - foreach ($toselect as $toselectid) { - $result = $object->fetch($toselectid); - //var_dump($contcats);exit; - if ($result > 0) { - if ($obj->price_base_type == 'TTC') { - $newprice = $object->price_ttc * (100 + $pricepercentage) / 100; - $minprice = $object->price_min_ttc; - } else { - $newprice = $object->price * (100 + $pricepercentage) / 100; - $minprice = $object->price_min; - } - $res = $object->updatePrice($newprice, $obj->price_base_type, $user, $object->tva_tx, $minprice, 0, $object->tva_npr, 0, 0, array(), $object->default_vat_code); - if ($res > 0) { - $nbok++; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - break; - } - } - } - } - - if (!$error) { - if ($nbok > 0) { - setEventMessages($langs->trans("RecordsModified", $nbok), null); - } - $db->commit(); - $toselect=array(); - } else { - $db->rollback(); - } -} - -if (!$error && ($action == 'setsupervisor' && $confirm == 'yes') && $permissiontoadd) { - $db->begin(); - $supervisortoset=GETPOST('supervisortoset'); - if (!empty($supervisortoset)) { - foreach ($toselect as $toselectid) { - $result = $object->fetch($toselectid); - //var_dump($contcats);exit; - if ($result > 0) { - $object->fk_user = $supervisortoset; - $res = $object->update($user); - if ($res > 0) { - $nbok++; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - break; - } - } - } else { - setEventMessage('UserNotFound', 'errors'); - $error++; - } - - if (!$error) { - if ($nbok > 1) { - setEventMessages($langs->trans("RecordsModified", $nbok), null); - } else { - setEventMessages($langs->trans("RecordsModified", $nbok), null); - } - $db->commit(); - $toselect=array(); - } else { - $db->rollback(); - } -} - -if (!$error && ($action == 'affectuser' && $confirm == 'yes') && $permissiontoadd) { - $db->begin(); - - $usertoaffect=GETPOST('usertoaffect'); - $projectrole=GETPOST('projectrole'); - $tasksrole=GETPOST('tasksrole'); - if (!empty($usertoaffect)) { - foreach ($toselect as $toselectid) { - $result = $object->fetch($toselectid); - //var_dump($contcats);exit; - if ($result > 0) { - $res = $object->add_contact($usertoaffect, $projectrole, 'internal'); - if ($res >= 0) { - $taskstatic = new Task($db); - $task_array = $taskstatic->getTasksArray(0, 0, $object->id, 0, 0); - - foreach ($task_array as $task) { - $tasksToAffect = new Task($db); - $result = $tasksToAffect->fetch($task->id); - if ($result > 0) { - $res = $tasksToAffect->add_contact($usertoaffect, $tasksrole, 'internal'); - if ($res < 0) { - setEventMessages($tasksToAffect->error, $tasksToAffect->errors, 'errors'); - } - } - } - $nbok++; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - break; - } - } - } else { - setEventMessage('UserNotFound', 'errors'); - $error++; - } - - if (!$error) { - if ($nbok > 1) { - setEventMessages($langs->trans("RecordsModified", $nbok), null); - } else { - setEventMessages($langs->trans("RecordsModified", $nbok), null); - } - $db->commit(); - $toselect=array(); - } else { - $db->rollback(); - } -} - -if (!$error && ($massaction == 'enable' || ($action == 'enable' && $confirm == 'yes')) && $permissiontoadd) { - $db->begin(); - - $objecttmp = new $objectclass($db); - $nbok = 0; - foreach ($toselect as $toselectid) { - $result = $objecttmp->fetch($toselectid); - if ($result>0) { - if (in_array($objecttmp->element, array('societe'))) { - $result =$objecttmp->setStatut(1); - } - 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("RecordsEnabled", $nbok), null, 'mesgs'); - } else { - setEventMessages($langs->trans("RecordEnabled"), null, 'mesgs'); - } - $db->commit(); - } else { - $db->rollback(); - } -} - -if (!$error && ($massaction == 'disable' || ($action == 'disable' && $confirm == 'yes')) && $permissiontoadd) { - $db->begin(); - - $objecttmp = new $objectclass($db); - $nbok = 0; - foreach ($toselect as $toselectid) { - $result = $objecttmp->fetch($toselectid); - if ($result>0) { - if (in_array($objecttmp->element, array('societe'))) { - $result =$objecttmp->setStatut(0); - } - 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("RecordsDisabled", $nbok), null, 'mesgs'); - } else { - setEventMessages($langs->trans("RecordDisabled"), null, 'mesgs'); - } - $db->commit(); - } else { - $db->rollback(); - } -} - -if (!$error && $action == 'confirm_edit_value_extrafields' && $confirm == 'yes' && $permissiontoadd) { - $db->begin(); - - $objecttmp = new $objectclass($db); - $e = new ExtraFields($db);// fetch optionals attributes and labels - $e->fetch_name_optionals_label($objecttmp->table_element); - - $nbok = 0; - $extrafieldKeyToUpdate = GETPOST('extrafield-key-to-update'); - - - foreach ($toselect as $toselectid) { - /** @var CommonObject $objecttmp */ - $objecttmp = new $objectclass($db); // to avoid ghost data - $result = $objecttmp->fetch($toselectid); - if ($result>0) { - // Fill array 'array_options' with data from add form - $ret = $e->setOptionalsFromPost(null, $objecttmp, $extrafieldKeyToUpdate); - if ($ret > 0) { - $objecttmp->insertExtraFields(); - } else { - $error++; - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - } - } else { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } - } - - if (!$error) { - if ($nbok > 1) { - setEventMessages($langs->trans("RecordsDisabled", $nbok), null, 'mesgs'); - } else { - setEventMessages($langs->trans("save"), null, 'mesgs'); - } - $db->commit(); - } else { - $db->rollback(); - } -} - -if (!$error && ($massaction == 'affectcommercial' || ($action == 'affectcommercial' && $confirm == 'yes')) && $permissiontoadd) { - $db->begin(); - - $objecttmp = new $objectclass($db); - $nbok = 0; - - foreach ($toselect as $toselectid) { - $result = $objecttmp->fetch($toselectid); - if ($result>0) { - if (in_array($objecttmp->element, array('societe'))) { - $result = $objecttmp->setSalesRep(GETPOST("commercial", "alpha")); - } - 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("CommercialsAffected", $nbok), null, 'mesgs'); - } else { - setEventMessages($langs->trans("CommercialAffected"), null, 'mesgs'); - } - $db->commit(); - } else { - $db->rollback(); - } -} - -// Approve for leave only -if (!$error && ($massaction == 'approveleave' || ($action == 'approveleave' && $confirm == 'yes')) && $permissiontoapprove) { - $db->begin(); - - $objecttmp = new $objectclass($db); - $nbok = 0; - foreach ($toselect as $toselectid) { - $result = $objecttmp->fetch($toselectid); - if ($result > 0) { - if ($objecttmp->statut != Holiday::STATUS_VALIDATED) { - setEventMessages($langs->trans('StatusOfRefMustBe', $objecttmp->ref, $langs->transnoentitiesnoconv('Validated')), null, 'warnings'); - continue; - } - if ($user->id == $objecttmp->fk_validator) { - $objecttmp->oldcopy = dol_clone($objecttmp); - - $objecttmp->date_valid = dol_now(); - $objecttmp->fk_user_valid = $user->id; - $objecttmp->statut = Holiday::STATUS_APPROVED; - - $verif = $objecttmp->approve($user); - - if ($verif <= 0) { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - } - - // If no SQL error, we redirect to the request form - if (!$error) { - // Calculcate number of days consumed - $nbopenedday = num_open_day($objecttmp->date_debut_gmt, $objecttmp->date_fin_gmt, 0, 1, $objecttmp->halfday); - $soldeActuel = $objecttmp->getCpforUser($objecttmp->fk_user, $objecttmp->fk_type); - $newSolde = ($soldeActuel - $nbopenedday); - - // The modification is added to the LOG - $result = $objecttmp->addLogCP($user->id, $objecttmp->fk_user, $langs->transnoentitiesnoconv("Holidays"), $newSolde, $objecttmp->fk_type); - if ($result < 0) { - $error++; - setEventMessages(null, $objecttmp->errors, 'errors'); - } - - // Update balance - $result = $objecttmp->updateSoldeCP($objecttmp->fk_user, $newSolde, $objecttmp->fk_type); - if ($result < 0) { - $error++; - setEventMessages(null, $objecttmp->errors, 'errors'); - } - } - - if (!$error) { - // To - $destinataire = new User($db); - $destinataire->fetch($objecttmp->fk_user); - $emailTo = $destinataire->email; - - if (!$emailTo) { - dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email"); - } else { - // From - $expediteur = new User($db); - $expediteur->fetch($objecttmp->fk_validator); - //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email. - $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM; - - // Subject - $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM; - if (getDolGlobalString('MAIN_APPLICATION_TITLE')) { - $societeName = $conf->global->MAIN_APPLICATION_TITLE; - } - - $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysValidated"); - - // Content - $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n"; - $message .= "\n"; - - $message .= $langs->transnoentities("HolidaysValidatedBody", dol_print_date($objecttmp->date_debut, 'day'), dol_print_date($objecttmp->date_fin, 'day'))."\n"; - - $message .= "- ".$langs->transnoentitiesnoconv("ValidatedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n"; - - $message .= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$objecttmp->id."\n\n"; - $message .= "\n"; - - $trackid = 'leav'.$objecttmp->id; - - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); - - // Sending email - $result = $mail->sendfile(); - - if (!$result) { - setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1 - $action = ''; - } - } - } - } else { - $langs->load("errors"); - setEventMessages($langs->trans('ErrorNotApproverForHoliday', $objecttmp->ref), null, 'errors'); - } - } else { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } - } - - if (!$error) { - if ($nbok > 1) { - setEventMessages($langs->trans("RecordsApproved", $nbok), null, 'mesgs'); - } elseif ($nbok == 1) { - setEventMessages($langs->trans("RecordAproved"), null, 'mesgs'); - } - $db->commit(); - } else { - $db->rollback(); - } -} - -if (!$error && ($massaction == 'increaseholiday' || ($action == 'increaseholiday' && $confirm == 'yes')) && $permissiontoapprove) { - $db->begin(); - $objecttmp = new $objectclass($db); - $nbok = 0; - $typeholiday = GETPOST('typeholiday', 'alpha'); - $nbdaysholidays = GETPOST('nbdaysholidays', 'double'); - - if ($nbdaysholidays <= 0) { - setEventMessages($langs->trans("WrongAmount"), "", 'errors'); - $error++; - } - - if (!$error) { - foreach ($toselect as $toselectid) { - $balancecpuser = $objecttmp->getCPforUser($toselectid, $typeholiday); - if (!empty($balancecpuser)) { - $newnbdaysholidays = $nbdaysholidays + $balancecpuser; - } else { - $newnbdaysholidays = $nbdaysholidays; - } - $result = $holiday->addLogCP($user->id, $toselectid, $langs->transnoentitiesnoconv('ManualUpdate'), $newnbdaysholidays, $typeholiday); - if ($result <= 0) { - setEventMessages($holiday->error, $holiday->errors, 'errors'); - $error++; - break; - } - - $objecttmp->updateSoldeCP($toselectid, $newnbdaysholidays, $typeholiday); - if ($result > 0) { - $nbok++; - } else { - setEventMessages("", $langs->trans("ErrorUpdatingUsersCP"), 'errors'); - $error++; - break; - } - } - } - - if (!$error) { - if ($nbok > 1) { - setEventMessages($langs->trans("HolidayRecordsIncreased", $nbok), null, 'mesgs'); - } elseif ($nbok == 1) { - setEventMessages($langs->trans("HolidayRecordIncreased"), null, 'mesgs'); - } - $db->commit(); - $toselect=array(); - } else { - $db->rollback(); - } -} - -//if (!$error && $massaction == 'clonetasks' && $user->rights->projet->creer) { -if (!$error && ($massaction == 'clonetasks' || ($action == 'clonetasks' && $confirm == 'yes'))) { - $num = 0; - - dol_include_once('/projet/class/task.class.php'); - - $origin_task = new Task($db); - $clone_task = new Task($db); - - foreach (GETPOST('selected') as $task) { - $origin_task->fetch($task, $ref = '', $loadparentdata = 0); - - $defaultref = ''; - $obj = !getDolGlobalString('PROJECT_TASK_ADDON') ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON; - if (getDolGlobalString('PROJECT_TASK_ADDON') && is_readable(DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . getDolGlobalString('PROJECT_TASK_ADDON') . ".php")) { - require_once DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . getDolGlobalString('PROJECT_TASK_ADDON') . '.php'; - $modTask = new $obj(); - $defaultref = $modTask->getNextValue(0, $clone_task); - } - - if (!$error) { - $clone_task->fk_project = GETPOST('projectid', 'int'); - $clone_task->ref = $defaultref; - $clone_task->label = $origin_task->label; - $clone_task->description = $origin_task->description; - $clone_task->planned_workload = $origin_task->planned_workload; - $clone_task->fk_task_parent = $origin_task->fk_task_parent; - $clone_task->date_c = dol_now(); - $clone_task->date_start = $origin_task->date_start; - $clone_task->date_end = $origin_task->date_end; - $clone_task->progress = $origin_task->progress; - - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $clone_task); - - $taskid = $clone_task->create($user); - - if ($taskid > 0) { - $result = $clone_task->add_contact(GETPOST("userid", 'int'), 'TASKEXECUTIVE', 'internal'); - $num++; - } else { - if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $langs->load("projects"); - setEventMessages($langs->trans('NewTaskRefSuggested'), '', 'warnings'); - $duplicate_code_error = true; - } else { - setEventMessages($clone_task->error, $clone_task->errors, 'errors'); - } - $action = 'list'; - $error++; - } - } - } - - if (!$error) { - setEventMessage($langs->trans('NumberOfTasksCloned', $num)); - header("Refresh: 1;URL=".DOL_URL_ROOT.'/projet/tasks.php?id=' . GETPOST('projectid', 'int')); - } -} - -$parameters['toselect'] = (empty($toselect) ? array() : $toselect); +$parameters['toselect'] = $toselect; @@ -1794 +1360 @@ -$parameters['diroutputmassaction'] = isset($diroutputmassaction) ? $diroutputmassaction : null; +$parameters['diroutputmassaction'] = $diroutputmassaction; @@ -1797,3 +1363 @@ -if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -} +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); --- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_actions_printing.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_printing.inc.php @@ -31 +31 @@ -if ($action == 'print_file' && $user->hasRight('printing', 'read')) { +if ($action == 'print_file' && $user->rights->printing->read) { @@ -36 +35,0 @@ - $dirmodels = array_merge(array('/core/modules/printing/'), (array) $conf->modules_parts['printing']); @@ -41,7 +40,2 @@ - 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); @@ -50 +43,0 @@ - $langs->load($printer::LANGFILE); @@ -53 +46,2 @@ - if (getDolGlobalString($printer->active)) { + if (!empty($conf->global->{$printer->active})) + { @@ -58,2 +52,3 @@ - switch ($module) { - case 'livraison': + switch ($module) + { + case 'livraison' : @@ -63 +58 @@ - case 'expedition': + case 'expedition' : @@ -66 +61 @@ - case 'commande_fournisseur': + case 'commande_fournisseur' : @@ -77 +72,2 @@ - if ($ret == 0) { + if ($ret == 0) + { @@ -82 +78,3 @@ - } catch (Exception $e) { + } + catch (Exception $e) + { @@ -88,3 +86 @@ - if ($printerfound == 0) { - setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings'); - } + if ($printerfound == 0) setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings'); --- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_actions_sendmails.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_sendmails.inc.php @@ -36 +36,2 @@ -if (GETPOST('addfile', 'alpha')) { +if (GETPOST('addfile', 'alpha')) +{ @@ -52 +53,2 @@ -if (GETPOST('removedfile') && !GETPOST('removAll')) { +if (!empty($_POST['removedfile']) && empty($_POST['removAll'])) +{ @@ -70 +72,2 @@ -if (GETPOST('removAll', 'alpha')) { +if (GETPOST('removAll', 'alpha')) +{ @@ -77,9 +80,3 @@ - if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) { - $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); - } - if (!empty($_SESSION["listofnames".$keytoavoidconflict])) { - $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); - } - if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) { - $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); - } + if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); + if (!empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); + if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); @@ -91 +88,2 @@ - foreach ($listofpaths as $key => $value) { + foreach ($listofpaths as $key => $value) + { @@ -106,12 +104,5 @@ -if (($action == 'send' || $action == 'relance') && !GETPOST('addfile') && !GETPOST('removAll') && !GETPOST('removedfile') && !GETPOST('cancel') && !GETPOST('modelselected')) { - if (empty($trackid)) { - $trackid = GETPOST('trackid', 'aZ09'); - } - - // Set tmp user directory (used to convert images embedded as img src=data:image) - $vardir = $conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path - - $subject = ''; - //$actionmsg = ''; - $actionmsg2 = ''; +if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST['removAll'] && !$_POST['removedfile'] && !$_POST['cancel'] && !$_POST['modelselected']) +{ + if (empty($trackid)) $trackid = GETPOST('trackid', 'aZ09'); + + $subject = ''; $actionmsg = ''; $actionmsg2 = ''; @@ -121 +112,2 @@ - if (is_object($object)) { + if (is_object($object)) + { @@ -125,2 +117,4 @@ - 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 @@ -128,4 +122,4 @@ - if (is_object($thirdparty)) { - $sendtosocid = $thirdparty->id; - } - } elseif ($object->element == 'member' || $object->element == 'user') { + $sendtosocid = $thirdparty->id; + } + elseif ($object->element == 'member' || $object->element == 'user') + { @@ -133,4 +127,4 @@ - if ($object->socid > 0) { - $sendtosocid = $object->socid; - } - } elseif ($object->element == 'expensereport') { + if ($object->socid > 0) $sendtosocid = $object->socid; + } + elseif ($object->element == 'expensereport') + { @@ -140,4 +134,4 @@ - if ($object->socid > 0) { - $sendtosocid = $object->socid; - } - } elseif ($object->element == 'societe') { + if ($object->socid > 0) $sendtosocid = $object->socid; + } + elseif ($object->element == 'societe') + { @@ -145,4 +139,4 @@ - 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') + { @@ -150,12 +144,6 @@ - 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 (is_object($hookmanager)) { + 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)) + { @@ -165,2 +152,0 @@ - } else { - $thirdparty = $mysoc; @@ -168,2 +154,4 @@ - - if ($result > 0) { + else $thirdparty = $mysoc; + + if ($result > 0) + { @@ -178,7 +166,5 @@ - $receiver = GETPOST('receiver', 'alphawithlgt'); - if (!is_array($receiver)) { - if ($receiver == '-1') { - $receiver = array(); - } else { - $receiver = array($receiver); - } + $receiver = $_POST['receiver']; + if (!is_array($receiver)) + { + if ($receiver == '-1') $receiver = array(); + else $receiver = array($receiver); @@ -188,14 +174,12 @@ - if (trim($_POST['sendto'])) { - // Recipients are provided into free text field - $tmparray[] = trim(GETPOST('sendto', 'alphawithlgt')); - } - - if (isset($_POST['tomail']) && trim($_POST['tomail'])) { - // Recipients are provided into free hidden text field - $tmparray[] = trim(GETPOST('tomail', 'alphawithlgt')); - } - - 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) + if (trim($_POST['sendto'])) + { + // Recipients are provided into free text + $tmparray[] = trim($_POST['sendto']); + } + if (count($receiver) > 0) + { + foreach ($receiver as $key=>$val) + { + // Recipient was provided from combo list + if ($val == 'thirdparty') // Key selected means currentthird party (may be usd for current member or current user too) + { @@ -203 +187,4 @@ - } elseif ($val == 'contact') { // Key selected means current contact + } + // Recipient was provided from combo list + elseif ($val == 'contact') // Key selected means current contact + { @@ -205,2 +192,3 @@ - $sendtoid[] = $contact->id; - } elseif ($val) { // $val is the Id of a contact + } + elseif ($val) // $val is the Id of a contact + { @@ -208,8 +196,10 @@ - $sendtoid[] = ((int) $val); - } - } - } - - if (getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) { - $receiveruser = GETPOST('receiveruser', 'alphawithlgt'); - if (is_array($receiveruser) && count($receiveruser) > 0) { + $sendtoid[] = $val; + } + } + } + + if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) + { + $receiveruser = $_POST['receiveruser']; + if (is_array($receiveruser) && count($receiveruser) > 0) + { @@ -217 +207,2 @@ - foreach ($receiveruser as $key => $val) { + foreach ($receiveruser as $key=>$val) + { @@ -227,7 +218,5 @@ - $receivercc = GETPOST('receivercc', 'alphawithlgt'); - if (!is_array($receivercc)) { - if ($receivercc == '-1') { - $receivercc = array(); - } else { - $receivercc = array($receivercc); - } + $receivercc = $_POST['receivercc']; + if (!is_array($receivercc)) + { + if ($receivercc == '-1') $receivercc = array(); + else $receivercc = array($receivercc); @@ -236,7 +225,11 @@ - if (trim($_POST['sendtocc'])) { - $tmparray[] = trim(GETPOST('sendtocc', 'alphawithlgt')); - } - if (count($receivercc) > 0) { - foreach ($receivercc as $key => $val) { - if ($val == 'thirdparty') { // Key selected means current thirdparty (may be usd for current member or current user too) - // Recipient was provided from combo list + if (trim($_POST['sendtocc'])) + { + $tmparray[] = trim($_POST['sendtocc']); + } + if (count($receivercc) > 0) + { + foreach ($receivercc as $key=>$val) + { + // Recipient was provided from combo list + if ($val == 'thirdparty') // Key selected means currentthird party (may be usd for current member or current user too) + { @@ -244,2 +237,4 @@ - } elseif ($val == 'contact') { // Key selected means current contact - // Recipient was provided from combo list + } + // Recipient was provided from combo list + elseif ($val == 'contact') // Key selected means current contact + { @@ -247,2 +242,3 @@ - //$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 + { @@ -250,8 +246,9 @@ - //$sendtoid[] = ((int) $val); TODO Add also id of contact in CC ? - } - } - } - if (getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) { - $receiverccuser = GETPOST('receiverccuser', 'alphawithlgt'); - - if (is_array($receiverccuser) && count($receiverccuser) > 0) { + //$sendtoid[] = $val; TODO Add also id of contact in CC ? + } + } + } + if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { + $receiverccuser = $_POST['receiverccuser']; + + if (is_array($receiverccuser) && count($receiverccuser) > 0) + { @@ -259 +256,2 @@ - foreach ($receiverccuser as $key => $val) { + foreach ($receiverccuser as $key=>$val) + { @@ -267,7 +265,8 @@ - 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'; + 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'; @@ -280,2 +279,3 @@ - $from = dol_string_nospecial($conf->global->MAIN_MAIL_EMAIL_FROM, ' ', array(",")).' <' . getDolGlobalString('MAIN_MAIL_EMAIL_FROM').'>'; - } elseif ($fromtype === 'user') { + $from = dol_string_nospecial($conf->global->MAIN_MAIL_EMAIL_FROM, ' ', array(",")).' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.'>'; + } + elseif ($fromtype === 'user') { @@ -283,3 +283,5 @@ - } elseif ($fromtype === 'company') { - $from = dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM, ' ', array(",")).' <' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL').'>'; - } elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { + } + 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)) { @@ -288,2 +290,3 @@ - } elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { - $tmp = explode(',', getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES')); + } + elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { + $tmp = explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES); @@ -291 +294,2 @@ - } elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) { + } + elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) { @@ -296 +300,2 @@ - if ($obj) { + if ($obj) + { @@ -299,15 +304,8 @@ - } elseif (preg_match('/from_template_(\d+)/', $fromtype, $reg)) { - $sql = 'SELECT rowid, email_from FROM '.MAIN_DB_PREFIX.'c_email_templates'; - $sql .= ' WHERE rowid = '.(int) $reg[1]; - $resql = $db->query($sql); - $obj = $db->fetch_object($resql); - if ($obj) { - $from = $obj->email_from; - } - } else { - $from = dol_string_nospecial(GETPOST('fromname'), ' ', array(",")).' <'.GETPOST('frommail').'>'; - } - - $replyto = dol_string_nospecial(GETPOST('replytoname'), ' ', array(",")).' <'.GETPOST('replytomail').'>'; - $message = GETPOST('message', 'restricthtml'); - $subject = GETPOST('subject', 'restricthtml'); + } + else { + $from = dol_string_nospecial($_POST['fromname'], ' ', array(",")).' <'.$_POST['frommail'].'>'; + } + + $replyto = dol_string_nospecial($_POST['replytoname'], ' ', array(",")).' <'.$_POST['replytomail'].'>'; + $message = GETPOST('message', 'none'); + $subject = GETPOST('subject', 'none'); @@ -324,9 +322,12 @@ - if (!empty($autocopy)) { - $sendtobcc .= (empty($conf->global->$autocopy) ? '' : (($sendtobcc ? ", " : "") . getDolGlobalString($autocopy))); - } - - $deliveryreceipt = GETPOST('deliveryreceipt'); - - if ($action == 'send' || $action == 'relance') { - $actionmsg2 = $langs->transnoentities('MailSentByTo', CMailFile::getValidAddress($from, 4, 0, 1), CMailFile::getValidAddress($sendto, 4, 0, 1)); - /*if ($message) { + if (!empty($autocopy)) + { + $sendtobcc .= (empty($conf->global->$autocopy) ? '' : (($sendtobcc ? ", " : "").$conf->global->$autocopy)); + } + + $deliveryreceipt = $_POST['deliveryreceipt']; + + if ($action == 'send' || $action == 'relance') + { + $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto, 4, 0, 1); + if ($message) + { @@ -335,3 +336 @@ - if ($sendtocc) { - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc)); - } + if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc)); @@ -341 +340 @@ - }*/ + } @@ -353,0 +353,44 @@ + // Feature to push mail sent into Sent folder + /* This code must be now included into the hook mail, method sendMailAfter + if (! empty($conf->dolimail->enabled)) + { + $mailfromid = explode("#", $_POST['frommail'],3); // $_POST['frommail'] = 'aaa#Sent# ' // TODO Use a better way to define Sent dir. + if (count($mailfromid)==0) $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; + else + { + $mbid = $mailfromid[1]; + + // IMAP Postbox + $mailboxconfig = new IMAP($db); + $mailboxconfig->fetch($mbid); + if ($mailboxconfig->mailbox_imap_host) $ref=$mailboxconfig->get_ref(); + + $mailboxconfig->folder_id=$mailboxconfig->mailbox_imap_outbox; + $mailboxconfig->userfolder_fetch(); + + if ($mailboxconfig->mailbox_save_sent_mails == 1) + { + + $folder=str_replace($ref, '', $mailboxconfig->folder_cache_key); + if (!$folder) $folder = "Sent"; // Default Sent folder + + $mailboxconfig->mbox = imap_open($mailboxconfig->get_connector_url().$folder, $mailboxconfig->mailbox_imap_login, $mailboxconfig->mailbox_imap_password); + if (false === $mailboxconfig->mbox) + { + $info = false; + $err = $langs->trans('Error3_Imap_Connection_Error'); + setEventMessages($err,$mailboxconfig->element, null, 'errors'); + } + else + { + $mailboxconfig->mailboxid=$_POST['frommail']; + $mailboxconfig->foldername=$folder; + $from = $mailfromid[0] . $mailfromid[2]; + $imap=1; + } + + } + } + } + */ + @@ -357 +400 @@ - $substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty)) ? '' : ''; + $substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty)) ? '' : ''; @@ -365 +408,2 @@ - if (is_object($object) && method_exists($object, 'makeSubstitution')) { + if (method_exists($object, 'makeSubstitution')) + { @@ -371,6 +415,5 @@ - if (empty($sendcontext)) { - $sendcontext = 'standard'; - } - $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid, '', $sendcontext, '', $upload_dir_tmp); - - if (!empty($mailfile->error) || !empty($mailfile->errors)) { + if (empty($sendcontext)) $sendcontext = 'standard'; + $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1, '', '', $trackid, '', $sendcontext); + + if ($mailfile->error) + { @@ -379 +422,3 @@ - } else { + } + else + { @@ -381 +426,2 @@ - if ($result) { + if ($result) + { @@ -383,4 +429,3 @@ - if (is_object($object)) { - if (empty($actiontypecode)) { - $actiontypecode = 'AC_OTH_AUTO'; // Event insert into agenda automatically - } + if (is_object($object)) + { + if (empty($actiontypecode)) $actiontypecode = 'AC_OTH_AUTO'; // Event insert into agenda automatically @@ -389 +434 @@ - $object->sendtoid = $sendtoid; // To link to contact-addresses. This is an array. + $object->sendtoid = $sendtoid; // To link to contact addresses. This is an array. @@ -391,5 +436,2 @@ - $object->actionmsg = $message; // Long text - $object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...); - if (getDolGlobalString('MAIN_MAIL_REPLACE_EVENT_TITLE_BY_EMAIL_SUBJECT')) { - $object->actionmsg2 = $subject; // Short text - } + $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')...); @@ -398,2 +440,2 @@ - $object->fk_element = $object->id; - $object->elementtype = $object->element; + $object->fk_element = $object->id; + $object->elementtype = $object->element; @@ -403 +445 @@ - if (is_array($sendtouserid) && count($sendtouserid) > 0 && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) { + if (is_array($sendtouserid) && count($sendtouserid) > 0 && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { @@ -413,0 +456 @@ + $object->email_msgid = $mailfile->msgid; @@ -416 +459,2 @@ - if (!empty($triggersendname) || !empty($trigger_name)) { + if (!empty($triggersendname) || !empty($trigger_name)) + { @@ -419,3 +463 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -422,0 +465 @@ + @@ -425 +468 @@ - } + } @@ -435,7 +478,7 @@ - $moreparam = ''; - 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 { + $moreparam = ''; + 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 + { @@ -444 +487,2 @@ - if (!empty($mailfile->error) || !empty($mailfile->errors)) { + if ($mailfile->error) + { @@ -446,13 +490,5 @@ - if (!empty($mailfile->error)) { - $mesg .= '
'.$mailfile->error; - } - if (!empty($mailfile->errors) && is_array($mailfile->errors)) { - $mesg .= '
'.implode('
', $mailfile->errors); - } - } else { - $mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto)); - if (getDolGlobalString('MAIN_DISABLE_ALL_MAILS')) { - $mesg .= '
Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; - } else { - $mesg .= '
Unkown Error, please refers to your administrator'; - } + $mesg .= '
'.$mailfile->error; + } + else + { + $mesg .= 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; @@ -466 +502,3 @@ - } else { + } + else + { @@ -472,2 +510,4 @@ - } else { - $langs->load("errors"); + } + else + { + $langs->load("other"); --- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_actions_setmoduleoptions.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_setmoduleoptions.inc.php @@ -24 +24 @@ -// $error must have been initialized to 0 + @@ -29 +28,0 @@ -// $formSetup may be defined @@ -31,8 +30,2 @@ - -if ($action == 'update' && !empty($formSetup) && is_object($formSetup) && !empty($user->admin)) { - $formSetup->saveConfFromPost(); - return; -} - - -if ($action == 'update' && is_array($arrayofparameters) && !empty($user->admin)) { +if ($action == 'update' && is_array($arrayofparameters)) +{ @@ -41 +34,3 @@ - foreach ($arrayofparameters as $key => $val) { + $ok = true; + foreach ($arrayofparameters as $key => $val) + { @@ -43,16 +38,8 @@ - if (GETPOSTISSET($key)) { - if (!empty($val['type']) && preg_match('/category:/', $val['type'])) { - if (GETPOST($key, 'int') == '-1') { - $val_const = ''; - } else { - $val_const = GETPOST($key, 'int'); - } - } else { - $val_const = GETPOST($key, 'alpha'); - } - - $result = dolibarr_set_const($db, $key, $val_const, 'chaine', 0, '', $conf->entity); - if ($result < 0) { - $error++; - break; - } + if (GETPOSTISSET($key)) + { + $result = dolibarr_set_const($db, $key, GETPOST($key, 'alpha'), 'chaine', 0, '', $conf->entity); + if ($result < 0) + { + $ok = false; + break; + } @@ -62 +49,2 @@ - if (!$error) { + if (!$error) + { @@ -64,4 +52,4 @@ - if (empty($nomessageinupdate)) { - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } - } else { + if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { @@ -69,32 +57 @@ - if (empty($nomessageinupdate)) { - setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); - } - } -} - -if ($action == 'deletefile' && $modulepart == 'doctemplates' && !empty($user->admin)) { - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $keyforuploaddir = GETPOST('keyforuploaddir', 'aZ09'); - $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim(getDolGlobalString($keyforuploaddir)))); - - foreach ($listofdir as $key => $tmpdir) { - $tmpdir = preg_replace('/DOL_DATA_ROOT\/*/', '', $tmpdir); // Clean string if we found a hardcoded DOL_DATA_ROOT - if (!$tmpdir) { - unset($listofdir[$key]); - continue; - } - $tmpdir = DOL_DATA_ROOT.'/'.$tmpdir; // Complete with DOL_DATA_ROOT. Only files into DOL_DATA_ROOT can be reach/set - if (!is_dir($tmpdir)) { - if (empty($nomessageinsetmoduleoptions)) { - setEventMessages($langs->trans("ErrorDirNotFound", $tmpdir), null, 'warnings'); - } - } else { - $upload_dir = $tmpdir; - break; // So we take the first directory found into setup $conf->global->$keyforuploaddir - } - } - - $filetodelete = $tmpdir.'/'.GETPOST('file'); - $result = dol_delete_file($filetodelete); - if ($result > 0) { - setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs'); + if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); @@ -105,2 +62,3 @@ -if ($action == 'setModuleOptions' && !empty($user->admin)) { - $db->begin(); +if ($action == 'setModuleOptions') +{ + $db->begin(); @@ -108,16 +66,18 @@ - // 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++; + } + } + } + } @@ -125,5 +85,25 @@ - // 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(getDolGlobalString($keyforuploaddir)))); + // 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++; + } + } @@ -131,37 +111,10 @@ - foreach ($listofdir as $key => $tmpdir) { - $tmpdir = trim($tmpdir); - $tmpdir = preg_replace('/DOL_DATA_ROOT\/*/', '', $tmpdir); // Clean string if we found a hardcoded DOL_DATA_ROOT - if (!$tmpdir) { - unset($listofdir[$key]); - continue; - } - $tmpdir = DOL_DATA_ROOT.'/'.$tmpdir; // Complete with DOL_DATA_ROOT. Only files into DOL_DATA_ROOT can be reach/set - if (!is_dir($tmpdir)) { - if (empty($nomessageinsetmoduleoptions)) { - setEventMessages($langs->trans("ErrorDirNotFound", $tmpdir), null, 'warnings'); - } - } else { - $upload_dir = $tmpdir; - break; // So we take the first directory found into setup $conf->global->$keyforuploaddir - } - } - - if ($upload_dir) { - $result = dol_add_file_process($upload_dir, 1, 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_19.0.3_actions_setnotes.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_actions_setnotes.inc.php @@ -31,7 +31,4 @@ -if ($action == 'setnote_public' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) { - 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 - } +if ($action == 'setnote_public' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) +{ + 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 @@ -39 +36 @@ - $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'); @@ -41,3 +38,3 @@ - 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'))) { + 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'))) + { @@ -45 +42,2 @@ - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { @@ -48,6 +46,2 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { - $newlang = $object->thirdparty->default_lang; - } + 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; @@ -58,4 +52,4 @@ - $model = $object->model_pdf; - $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0)); - $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0)); - $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0)); + $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 +57 @@ - //see #21072: Update a public note with a "document model not found" is not really a problem : the PDF is not created/updated - //but the note is saved, so just add a notification will be enought - $resultGenDoc = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($resultGenDoc < 0) { - setEventMessages($object->error, $object->errors, 'warnings'); - } + $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); @@ -70,3 +59 @@ - if ($result < 0) { - dol_print_error($db, $result); - } + if ($result < 0) dol_print_error($db, $result); @@ -75,14 +62,6 @@ -} elseif ($action == 'setnote_private' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) { // Set public note - if (empty($user->socid)) { - // Private notes (always hidden to external users) - 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, 'UTF-8', 1), '_private'); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - } +} elseif ($action == 'setnote_private' && !empty($permissionnote) && !GETPOST('cancel', 'alpha')) { + // 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', 'none'), ENT_QUOTES), '_private'); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); --- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_commonfieldsinexport.inc.php +++ /tmp/dsg/dolibarr/htdocs/core/client_commonfieldsinexport.inc.php @@ -3,4 +3,5 @@ -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; +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; @@ -8,3 +9 @@ -if (empty($keyforalias)) { - $keyforalias = 't'; -} +if (empty($keyforalias)) $keyforalias = 't'; @@ -13 +12,2 @@ -if (class_exists($keyforclass)) { +if (class_exists($keyforclass)) +{ @@ -17 +17,2 @@ - foreach ($tmpobject->fields as $keyfield => $valuefield) { + foreach ($tmpobject->fields as $keyfield => $valuefield) + { @@ -40 +41 @@ - * $tmpparam=jsonOrUnserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null + * $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null @@ -60 +61,3 @@ -} else { +} +else +{ --- /tmp/dsg/dolibarr/htdocs/core/github_19.0.3_customreports.php +++ /tmp/dsg/dolibarr/htdocs/core/client_customreports.php @@ -2 +2 @@ -/* Copyright (C) 2020-2023 Laurent Destailleur +/* Copyright (C) 2020 Laurent Destailleur @@ -15 +15 @@ - * along with this program. If not, see . + * along with this program. If not, see . @@ -18 +18 @@ - * define('USE_CUSTOM_REPORT_AS_INCLUDE', 1); + * define('USE_CUSTOME_REPORT_AS_INCLUDE', 1); @@ -28 +28,2 @@ -if (!defined('USE_CUSTOM_REPORT_AS_INCLUDE')) { +if (!defined('USE_CUSTOME_REPORT_AS_INCLUDE')) +{ @@ -32 +33 @@ - $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... + $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... @@ -39,4 +40,3 @@ - if (empty($objecttype)) { - $objecttype = 'thirdparty'; - } - + if (empty($objecttype)) $objecttype = 'thirdparty'; + + $search_filters = GETPOST('search_filters', 'array'); @@ -46,5 +46,2 @@ - if (GETPOST('search_xaxis', 'alpha') && GETPOST('search_xaxis', 'alpha') != '-1') { - $search_xaxis = array(GETPOST('search_xaxis', 'alpha')); - } else { - $search_xaxis = array(); - } + if (GETPOST('search_xaxis', 'alpha') && GETPOST('search_xaxis', 'alpha') != '-1') $search_xaxis = array(GETPOST('search_xaxis', 'alpha')); + else $search_xaxis = array(); @@ -52,5 +49,2 @@ - if (GETPOST('search_groupby', 'alpha') && GETPOST('search_groupby', 'alpha') != '-1') { - $search_groupby = array(GETPOST('search_groupby', 'alpha')); - } else { - $search_groupby = array(); - } + if (GETPOST('search_groupby', 'alpha') && GETPOST('search_groupby', 'alpha') != '-1') $search_groupby = array(GETPOST('search_groupby', 'alpha')); + else $search_groupby = array(); @@ -59 +53 @@ - $search_graph = GETPOST('search_graph', 'restricthtml'); + $search_graph = GETPOST('search_graph', 'none'); @@ -63,2 +57,2 @@ - $sortfield = GETPOST('sortfield', 'aZ09comma'); - $sortorder = GETPOST('sortorder', 'aZ09comma'); + $sortfield = GETPOST('sortfield', 'alpha'); + $sortorder = GETPOST('sortorder', 'alpha'); @@ -66,3 +60 @@ - 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 + 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 @@ -96,13 +88,12 @@ - 'thirdparty' => array('langs'=>'companies', 'label' => 'ThirdParties', 'picto'=>'company', 'ObjectClassName' => 'Societe', 'enabled' => isModEnabled('societe'), 'ClassPath' => "/societe/class/societe.class.php"), - 'contact' => array('label' => 'Contacts', 'picto'=>'contact', 'ObjectClassName' => 'Contact', 'enabled' => isModEnabled('societe'), 'ClassPath' => "/contact/class/contact.class.php"), - 'proposal' => array('label' => 'Proposals', 'picto'=>'proposal', 'ObjectClassName' => 'Propal', 'enabled' => isModEnabled('propal'), 'ClassPath' => "/comm/propal/class/propal.class.php"), - 'order' => array('label' => 'Orders', 'picto'=>'order', 'ObjectClassName' => 'Commande', 'enabled' => isModEnabled('commande'), 'ClassPath' => "/commande/class/commande.class.php"), - 'invoice' => array('langs'=>'facture', 'label' => 'Invoices', 'picto'=>'bill', 'ObjectClassName' => 'Facture', 'enabled' => isModEnabled('facture'), 'ClassPath' => "/compta/facture/class/facture.class.php"), - 'invoice_template'=>array('label' => 'PredefinedInvoices', 'picto'=>'bill', 'ObjectClassName' => 'FactureRec', 'enabled' => isModEnabled('facture'), 'ClassPath' => "/compta/class/facturerec.class.php", 'langs'=>'bills'), - 'contract' => array('label' => 'Contracts', 'picto'=>'contract', 'ObjectClassName' => 'Contrat', 'enabled' => isModEnabled('contrat'), 'ClassPath' => "/contrat/class/contrat.class.php", 'langs'=>'contracts'), - 'contractdet' => array('label' => 'ContractLines', 'picto'=>'contract', 'ObjectClassName' => 'ContratLigne', 'enabled' => isModEnabled('contrat'), 'ClassPath' => "/contrat/class/contrat.class.php", 'langs'=>'contracts'), - 'bom' => array('label' => 'BOM', 'picto'=>'bom', 'ObjectClassName' => 'Bom', 'enabled' => isModEnabled('bom')), - 'mo' => array('label' => 'MO', 'picto'=>'mrp', 'ObjectClassName' => 'Mo', 'enabled' => isModEnabled('mrp'), 'ClassPath' => "/mrp/class/mo.class.php"), - 'ticket' => array('label' => 'Ticket', 'picto'=>'ticket', 'ObjectClassName' => 'Ticket', 'enabled' => isModEnabled('ticket')), - 'member' => array('label' => 'Adherent', 'picto'=>'member', 'ObjectClassName' => 'Adherent', 'enabled' => isModEnabled('adherent'), 'ClassPath' => "/adherents/class/adherent.class.php", 'langs'=>'members'), - 'cotisation' => array('label' => 'Subscriptions', 'picto'=>'member', 'ObjectClassName' => 'Subscription', 'enabled' => isModEnabled('adherent'), 'ClassPath' => "/adherents/class/subscription.class.php", 'langs'=>'members'), + 'thirdparty' => array('label' => 'ThirdParties', 'ObjectClassName' => 'Societe', 'enabled' => $conf->societe->enabled, 'ClassPath' => "/societe/class/societe.class.php"), + 'contact' => array('label' => 'Contacts', 'ObjectClassName' => 'Contact', 'enabled' => $conf->societe->enabled, 'ClassPath' => "/contact/class/contact.class.php"), + 'proposal' => array('label' => 'Proposals', 'ObjectClassName' => 'Propal', 'enabled' => $conf->propal->enabled, 'ClassPath' => "/comm/propal/class/propal.class.php"), + 'order' => array('label' => 'Orders', 'ObjectClassName' => 'Commande', 'enabled' => $conf->commande->enabled, 'ClassPath' => "/commande/class/commande.class.php"), + 'invoice' => array('label' => 'Invoices', 'ObjectClassName' => 'Facture', 'enabled' => $conf->facture->enabled, 'ClassPath' => "/compta/facture/class/facture.class.php"), + 'invoice_template'=>array('label' => 'PredefinedInvoices', 'ObjectClassName' => 'FactureRec', 'enabled' => $conf->facture->enabled, 'ClassPath' => "/compta/class/facturerec.class.php", 'langs'=>'bills'), + 'contract' => array('label' => 'Contracts', 'ObjectClassName' => 'Contrat', 'enabled' => $conf->contrat->enabled, 'ClassPath' => "/contrat/class/contrat.class.php", 'langs'=>'contract'), + 'bom' => array('label' => 'BOM', 'ObjectClassName' => 'Bom', 'enabled' => $conf->bom->enabled), + 'mo' => array('label' => 'MO', 'ObjectClassName' => 'Mo', 'enabled' => $conf->mrp->enabled, 'ClassPath' => "/mrp/class/mo.class.php"), + 'ticket' => array('label' => 'Ticket', 'ObjectClassName' => 'Ticket', 'enabled' => $conf->ticket->enabled), + 'member' => array('label' => 'Adherent', 'ObjectClassName' => 'Adherent', 'enabled' => $conf->adherent->enabled, 'ClassPath' => "/adherents/class/adherent.class.php", 'langs'=>'members'), + 'cotisation' => array('label' => 'Subscriptions', 'ObjectClassName' => 'Subscription', 'enabled' => $conf->adherent->enabled, 'ClassPath' => "/adherents/class/subscription.class.php", 'langs'=>'members'), @@ -114,3 +105,2 @@ -if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -} elseif (is_array($hookmanager->resArray)) { +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +elseif (is_array($hookmanager->resArray)) { @@ -128,2 +118,2 @@ - $arrayoftype[$key] = $val; - } + $arrayoftype[$key] = $val; + } @@ -134,11 +124,12 @@ - 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; + } @@ -149 +140,2 @@ -if ($user->socid > 0) { // Protection if external user +if ($user->socid > 0) // Protection if external user +{ @@ -153,0 +146,2 @@ +$result = restrictedArea($user, $object->element, 0, ''); + @@ -155 +149 @@ -$extrafields->fetch_name_optionals_label('all'); // We load all extrafields definitions for all objects +$extrafields->fetch_name_optionals_label($object->table_element); @@ -161,6 +154,0 @@ -$search_component_params_hidden = GETPOST('search_component_params_hidden', 'alphanohtml'); - -// For the case we enter a criteria manually, the search_component_params_input will be defined and must be used in priority -if (GETPOST('search_component_params_input', 'alphanohtml')) { - $search_component_params_hidden = GETPOST('search_component_params_input', 'alphanohtml'); -} @@ -178 +166 @@ -$arrayofmesures = array(); +$arrayofmesures = array('t.count'=>'Count'); @@ -184,8 +171,0 @@ -$features = $object->element; -if (!empty($object->element_for_permission)) { - $features = $object->element_for_permission; -} - -restrictedArea($user, $features, 0, ''); - -$error = 0; @@ -198 +178 @@ -// None + @@ -209 +189 @@ -if (!defined('USE_CUSTOM_REPORT_AS_INCLUDE')) { +if (!defined('USE_CUSTOME_REPORT_AS_INCLUDE')) { @@ -212,25 +192,2 @@ - print dol_get_fiche_head($head, 'customreports', $title, -1, $picto); -} - -$newarrayoftype = array(); -foreach ($arrayoftype as $key => $val) { - if (dol_eval($val['enabled'], 1, 1, '1')) { - $newarrayoftype[$key] = $arrayoftype[$key]; - } - if (!empty($val['langs'])) { - $langs->load($val['langs']); - } -} - -$count = 0; -$arrayofmesures = fillArrayOfMeasures($object, 't', $langs->trans($newarrayoftype[$objecttype]['label']), $arrayofmesures, 0, $count); -$arrayofmesures = dol_sort_array($arrayofmesures, 'position', 'asc', 0, 0, 1); - -$count = 0; -$arrayofxaxis = fillArrayOfXAxis($object, 't', $langs->trans($newarrayoftype[$objecttype]['label']), $arrayofxaxis, 0, $count); -$arrayofxaxis = dol_sort_array($arrayofxaxis, 'position', 'asc', 0, 0, 1); - -$count = 0; -$arrayofgroupby = fillArrayOfGroupBy($object, 't', $langs->trans($newarrayoftype[$objecttype]['label']), $arrayofgroupby, 0, $count); -$arrayofgroupby = dol_sort_array($arrayofgroupby, 'position', 'asc', 0, 0, 1); - + dol_fiche_head($head, 'customreports', $title, -1, $picto); +} @@ -278,14 +235,3 @@ - $sql = "SELECT DISTINCT ".$fieldtocount." as val"; - - if (strpos($fieldtocount, 'te') === 0) { - $tabletouse = $object->table_element; - $tablealiastouse = 'te'; - if (!empty($arrayofgroupby[$gval])) { - $tmpval = explode('.', $gval); - $tabletouse = $arrayofgroupby[$gval]['table']; - $tablealiastouse = $tmpval[0]; - } - //var_dump($tablealiastouse);exit; - - //$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element."_extrafields as te"; - $sql .= " FROM ".MAIN_DB_PREFIX.$tabletouse."_extrafields as ".$tablealiastouse; + $sql = 'SELECT DISTINCT '.$fieldtocount.' as val'; + if (strpos($fieldtocount, 'te.') === 0) { + $sql .= ' FROM '.MAIN_DB_PREFIX.$object->table_element.'_extrafields as te'; @@ -293,8 +239 @@ - $tabletouse = $object->table_element; - $tablealiastouse = 't'; - if (!empty($arrayofgroupby[$gval])) { - $tmpval = explode('.', $gval); - $tabletouse = $arrayofgroupby[$gval]['table']; - $tablealiastouse = $tmpval[0]; - } - $sql .= " FROM ".MAIN_DB_PREFIX.$tabletouse." as ".$tablealiastouse; + $sql .= ' FROM '.MAIN_DB_PREFIX.$object->table_element.' as t'; @@ -302,10 +241,3 @@ - - // Add a where here keeping only the citeria on $tabletouse - // TODO - /*$sqlfilters = ... GETPOST('search_component_params_hidden', 'alphanohtml'); - if ($sqlfilters) { - $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); - }*/ - - $sql .= " LIMIT ".((int) ($MAXUNIQUEVALFORGROUP + 1)); + // TODO Add the where here + + $sql .= ' LIMIT '.($MAXUNIQUEVALFORGROUP + 1); @@ -323 +255,2 @@ - } elseif ($obj->val === '') { + } + elseif ($obj->val === '') { @@ -326 +259,2 @@ - } else { + } + else { @@ -334,3 +268 @@ - if (is_null($valuetranslated)) { - $valuetranslated = $langs->transnoentitiesnoconv("UndefinedKey"); - } + if (is_null($valuetranslated)) $valuetranslated = $langs->transnoentitiesnoconv("UndefinedKey"); @@ -338 +270,2 @@ - } elseif (preg_match('/integer:([^:]+):([^:]+)$/', $object->fields[$gvalwithoutprefix]['type'], $regs)) { + } + elseif (preg_match('/integer:([^:]+):([^:]+)$/', $object->fields[$gvalwithoutprefix]['type'], $regs)) { @@ -358,8 +290,0 @@ - // Add also the possible NULL value if field is a parent field that is not a strict join - $tmpfield = explode('.', $gval); - if ($tmpfield[0] != 't' || (is_array($object->fields[$tmpfield[1]]) && empty($object->fields[$tmpfield[1]]['notnull']))) { - dol_syslog("The group by field ".$gval." may be null (because field is null or it is a left join), so we add __NULL__ entry in list of possible values"); - //var_dump($gval); var_dump($object->fields); - $arrayofvaluesforgroupby['g_'.$gkey]['__NULL__'] = $langs->transnoentitiesnoconv("NotDefined"); - } - @@ -368 +292,0 @@ - // Add a protection/error to refuse the request if number of differentr values for the group by is higher than $MAXUNIQUEVALFORGROUP @@ -371,32 +295,3 @@ - - if (strpos($fieldtocount, 'te') === 0) { // This is a field of an extrafield - //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]; - $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield); - } elseif (strpos($fieldtocount, 't__') === 0) { // This is a field of a foreign key - $reg = array(); - if (preg_match('/^(.*)\.(.*)/', $gvalwithoutprefix, $reg)) { - /* - $gvalwithoutprefix = preg_replace('/\..*$/', '', $gvalwithoutprefix); - $gvalwithoutprefix = preg_replace('/^t__/', '', $gvalwithoutprefix); - $keyforlabeloffield = $object->fields[$gvalwithoutprefix]['label']; - $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield).'-'.$reg[2]; - */ - $labeloffield = $arrayofgroupby[$fieldtocount]['labelnohtml']; - } else { - $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield); - } - } else { // This is a common field - $reg = array(); - if (preg_match('/^(.*)\-(year|month|day)/', $gvalwithoutprefix, $reg)) { - $gvalwithoutprefix = preg_replace('/\-(year|month|day)/', '', $gvalwithoutprefix); - $keyforlabeloffield = $object->fields[$gvalwithoutprefix]['label']; - $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield).'-'.$reg[2]; - } else { - $keyforlabeloffield = $object->fields[$gvalwithoutprefix]['label']; - $labeloffield = $langs->transnoentitiesnoconv($keyforlabeloffield); - } - } - //var_dump($object->fields); + //var_dump($gkey.' '.$gval.' '.$gvalwithoutprefix); + $gvalwithoutprefix = preg_replace('/\-(year|month|day)/', '', $gvalwithoutprefix); + $labeloffield = $langs->transnoentitiesnoconv($object->fields[$gvalwithoutprefix]['label']); @@ -421,2 +316,2 @@ -print '
'; -print ''; +print ''; +print ''; @@ -426,22 +321 @@ -$viewmode = ''; - -$viewmode .= '
'; -$arrayofgraphs = array('bars' => 'Bars', 'lines' => 'Lines'); // also 'pies' -$viewmode .= '
'.$langs->trans("Graph").'
'; -$viewmode .= $form->selectarray('search_graph', $arrayofgraphs, $search_graph, 0, 0, 0, '', 1, 0, 0, '', 'graphtype width100'); -$viewmode .= '
'; - -$num = 0; -$massactionbutton = ''; -$nav = ''; -$newcardbutton = ''; -$limit = 0; - -print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, -1, 'object_action', 0, $nav.''.$newcardbutton, '', $limit, 1, 0, 1, $viewmode); - - -foreach ($newarrayoftype as $tmpkey => $tmpval) { - $newarrayoftype[$tmpkey]['label'] = img_picto('', $tmpval['picto'], 'class="pictofixedwidth"').$langs->trans($tmpval['label']); -} - -print '
'; +print '
'; @@ -452,6 +326,13 @@ -print $form->selectarray('objecttype', $newarrayoftype, $objecttype, 0, 0, 0, '', 1, 0, 0, '', 'minwidth200', 1, '', 0, 1); -if (empty($conf->use_javascript_ajax)) { - print ''; -} else { - print ' - '."\n"; -} else { +if (GETPOST('mode') && GETPOST('mode') == 'test') +{ + print ''."\n"; +} +else +{ @@ -96 +83 @@ -print '