33 if (!empty($permissionedit) && empty($permissiontoadd)) $permissiontoadd = $permissionedit;
39 if (!empty($backtopageforcancel))
41 header(
"Location: ".$backtopageforcancel);
43 } elseif (!empty($backtopage))
45 header(
"Location: ".$backtopage);
53 if ($action ==
'add' && !empty($permissiontoadd))
55 foreach ($object->fields as $key => $val)
57 if ($object->fields[$key][
'type'] ==
'duration') {
58 if (
GETPOST($key.
'hour') ==
'' &&
GETPOST($key.
'min') ==
'')
continue;
63 if (in_array($key, array(
'rowid',
'entity',
'import_key')))
continue;
64 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
65 if (!in_array(abs($val[
'visible']), array(1, 3)))
continue;
69 if (in_array($object->fields[$key][
'type'], array(
'text',
'html'))) {
70 $value =
GETPOST($key,
'restricthtml');
71 } elseif ($object->fields[$key][
'type'] ==
'date') {
73 } elseif ($object->fields[$key][
'type'] ==
'datetime') {
74 $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');
75 } elseif ($object->fields[$key][
'type'] ==
'duration') {
76 $value = 60 * 60 *
GETPOST($key.
'hour',
'int') + 60 *
GETPOST($key.
'min',
'int');
77 } elseif (preg_match(
'/^(integer|price|real|double)/', $object->fields[$key][
'type'])) {
79 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
80 $value = ((
GETPOST($key) ==
'1' ||
GETPOST($key) ==
'on') ? 1 : 0);
81 } elseif ($object->fields[$key][
'type'] ==
'reference') {
82 $tmparraykey = array_keys($object->param_list);
85 $value =
GETPOST($key,
'alphanohtml');
87 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') $value =
'';
88 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') $value =
'';
91 $object->$key = $value;
92 if ($val[
'notnull'] > 0 && $object->$key ==
'' && !is_null($val[
'default']) && $val[
'default'] ==
'(PROV)')
94 $object->$key =
'(PROV)';
96 if ($val[
'notnull'] > 0 && $object->$key ==
'' && is_null($val[
'default']))
99 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])), null,
'errors');
105 $ret = $extrafields->setOptionalsFromPost(null, $object);
106 if ($ret < 0) $error++;
111 $result = $object->create($user);
115 $urltogo = $backtopage ? str_replace(
'__ID__', $result, $backtopage) : $backurlforlist;
116 $urltogo = preg_replace(
'/--IDFORBACKTOPAGE--/', $object->id, $urltogo);
117 header(
"Location: ".$urltogo);
121 if (!empty($object->errors))
setEventMessages(null, $object->errors,
'errors');
131 if ($action ==
'update' && !empty($permissiontoadd))
133 foreach ($object->fields as $key => $val)
136 if ($object->fields[$key][
'type'] ==
'duration') {
138 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
147 if (in_array($key, array(
'rowid',
'entity',
'import_key')))
continue;
148 if (in_array($key, array(
'date_creation',
'tms',
'fk_user_creat',
'fk_user_modif'))) {
149 if (!in_array(abs($val[
'visible']), array(1, 3, 4)))
continue;
153 if (preg_match(
'/^(text|html)/', $object->fields[$key][
'type'])) {
154 $tmparray = explode(
':', $object->fields[$key][
'type']);
155 if (!empty($tmparray[1])) {
156 $value =
GETPOST($key, $tmparray[1]);
158 $value =
GETPOST($key,
'restricthtml');
160 } elseif ($object->fields[$key][
'type'] ==
'date') {
162 } elseif ($object->fields[$key][
'type'] ==
'datetime') {
163 $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');
164 } elseif ($object->fields[$key][
'type'] ==
'duration') {
165 if (
GETPOST($key.
'hour',
'int') !=
'' ||
GETPOST($key.
'min',
'int') !=
'') {
166 $value = 60 * 60 *
GETPOST($key.
'hour',
'int') + 60 *
GETPOST($key.
'min',
'int');
170 } elseif (preg_match(
'/^(integer|price|real|double)/', $object->fields[$key][
'type'])) {
172 } elseif ($object->fields[$key][
'type'] ==
'boolean') {
173 $value = ((
GETPOST($key,
'aZ09') ==
'on' ||
GETPOST($key,
'aZ09') ==
'1') ? 1 : 0);
174 } elseif ($object->fields[$key][
'type'] ==
'reference') {
175 $value = array_keys($object->param_list)[
GETPOST($key)].
','.
GETPOST($key.
'2');
177 $value =
GETPOST($key,
'alpha');
179 if (preg_match(
'/^integer:/i', $object->fields[$key][
'type']) && $value ==
'-1') $value =
'';
180 if (!empty($object->fields[$key][
'foreignkey']) && $value ==
'-1') $value =
'';
182 $object->$key = $value;
183 if ($val[
'notnull'] > 0 && $object->$key ==
'' && is_null($val[
'default']))
186 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv($val[
'label'])), null,
'errors');
192 $ret = $extrafields->setOptionalsFromPost(null, $object,
'@GETPOSTISSET');
193 if ($ret < 0) $error++;
198 $result = $object->update($user);
213 if ($action ==
"update_extras" && !empty($permissiontoadd))
215 $object->fetch(
GETPOST(
'id',
'int'));
217 $attributekey =
GETPOST(
'attribute',
'alpha');
218 $attributekeylong =
'options_'.$attributekey;
222 $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'));
225 $object->array_options[
'options_'.$attributekey] =
GETPOST($attributekeylong,
'alpha');
228 $result = $object->insertExtraFields(empty($triggermodname) ?
'' : $triggermodname, $user);
235 $action =
'edit_extras';
240 if ($action ==
'confirm_delete' && !empty($permissiontodelete))
242 if (!($object->id > 0))
244 dol_print_error(
'',
'Error, object must be fetched before being deleted');
248 $result = $object->delete($user);
253 header(
"Location: ".$backurlforlist);
256 if (!empty($object->errors))
setEventMessages(null, $object->errors,
'errors');
262 if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && !empty($permissiontoadd))
264 if (method_exists($object,
'deleteline')) {
265 $result = $object->deleteline($user, $lineid);
267 $result = $object->deleteLine($user, $lineid);
272 $outputlangs = $langs;
274 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09'))
276 $newlang =
GETPOST(
'lang_id',
'aZ09');
278 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && is_object($object->thirdparty))
280 $newlang = $object->thirdparty->default_lang;
282 if (!empty($newlang)) {
284 $outputlangs->setDefaultLang($newlang);
286 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
287 if (method_exists($object,
'generateDocument')) {
288 $ret = $object->fetch($object->id);
289 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
294 header(
'Location: '.
$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
302 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $permissiontoadd)
304 $result = $object->validate($user);
308 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
309 if (method_exists($object,
'generateDocument')) {
310 $outputlangs = $langs;
312 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
313 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
314 if (!empty($newlang)) {
316 $outputlangs->setDefaultLang($newlang);
319 $ret = $object->fetch($id);
321 $model = $object->model_pdf;
323 $retgen = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
335 if ($action ==
'confirm_close' && $confirm ==
'yes' && $permissiontoadd)
337 $result = $object->cancel($user);
341 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
342 if (method_exists($object,
'generateDocument')) {
343 $outputlangs = $langs;
345 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
346 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
347 if (!empty($newlang)) {
349 $outputlangs->setDefaultLang($newlang);
351 $model = $object->model_pdf;
352 $ret = $object->fetch($id);
354 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
363 if ($action ==
'confirm_setdraft' && $confirm ==
'yes' && $permissiontoadd)
365 $result = $object->setDraft($user);
375 if ($action ==
'confirm_reopen' && $confirm ==
'yes' && $permissiontoadd)
377 $result = $object->reopen($user);
381 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
382 if (method_exists($object,
'generateDocument')) {
383 $outputlangs = $langs;
385 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
386 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
387 if (!empty($newlang)) {
389 $outputlangs->setDefaultLang($newlang);
391 $model = $object->model_pdf;
392 $ret = $object->fetch($id);
394 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
403 if ($action ==
'confirm_clone' && $confirm ==
'yes' && !empty($permissiontoadd))
405 if (1 == 0 && !
GETPOST(
'clone_content') && !
GETPOST(
'clone_receivers'))
412 $result = $objectutil->createFromClone($user, (($object->id > 0) ? $object->id : $id));
413 if (is_object($result) || $result > 0)
416 if (is_object($result)) $newid = $result->id;
417 else $newid = $result;
418 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
'?id='.$newid);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
Class to manage translations.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...