30$extrasize =
GETPOST(
'size',
'intcomma');
31$type =
GETPOST(
'type',
'alphanohtml');
32$param =
GETPOST(
'param',
'alphanohtml');
33$css =
GETPOST(
'css',
'alphanohtml');
34$cssview =
GETPOST(
'cssview',
'alphanohtml');
35$csslist =
GETPOST(
'csslist',
'alphanohtml');
37if ($type ==
'double' && strpos($extrasize,
',') ===
false) {
43if ($type ==
'datetime') {
46if ($type ==
'select') {
52if ($action ==
'add') {
53 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
57 $langs->load(
"errors");
58 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
61 if ($type ==
'varchar' && $extrasize <= 0) {
63 $langs->load(
"errors");
64 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
67 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
69 $langs->load(
"errors");
70 $mesg[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
73 if ($type ==
'int' && $extrasize > $maxsizeint) {
75 $langs->load(
"errors");
76 $mesg[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
79 if ($type ==
'select' && !$param) {
81 $langs->load(
"errors");
82 $mesg[] = $langs->trans(
"ErrorNoValueForSelectType");
85 if ($type ==
'sellist' && !$param) {
87 $langs->load(
"errors");
88 $mesg[] = $langs->trans(
"ErrorNoValueForSelectListType");
91 if ($type ==
'checkbox' && !$param) {
93 $langs->load(
"errors");
94 $mesg[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
97 if ($type ==
'link' && !$param) {
99 $langs->load(
"errors");
100 $mesg[] = $langs->trans(
"ErrorNoValueForLinkType");
103 if ($type ==
'radio' && !$param) {
105 $langs->load(
"errors");
106 $mesg[] = $langs->trans(
"ErrorNoValueForRadioType");
109 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
111 $parameters = $param;
112 $parameters_array = explode(
"\r\n", $parameters);
113 foreach ($parameters_array as $param_ligne) {
114 if (!empty($param_ligne)) {
115 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
116 if (count($matches[0]) > 1) {
118 $langs->load(
"errors");
119 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
124 $langs->load(
"errors");
125 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
133 if (strlen(
GETPOST(
'attrname',
'aZ09')) < 3) {
135 $langs->load(
"errors");
136 $mesg[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
143 if (in_array(
GETPOST(
'attrname',
'aZ09'), array(
'and',
'keyword',
'table',
'index',
'int',
'integer',
'float',
'double',
'real',
'position'))) {
145 $langs->load(
"errors");
146 $mesg[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
153 if (GETPOSTISSET(
"attrname") && preg_match(
"/^[a-z0-9_]+$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
155 $default_value =
GETPOST(
'default_value',
'alpha');
156 $parameters = $param;
157 $parameters_array = explode(
"\r\n", $parameters);
160 if ($type ==
'sellist' || $type ==
'chkbxlst') {
161 foreach ($parameters_array as $param_ligne) {
162 $params[
'options'] = array($parameters=>
null);
166 foreach ($parameters_array as $param_ligne) {
167 if (strpos($param_ligne,
',')!==
false) {
168 list($key, $value) = explode(
',', $param_ligne);
169 if (!array_key_exists(
'options', $params)) {
170 $params[
'options'] = array();
176 $params[
'options'][$key] = $value;
181 $visibility =
GETPOST(
'list',
'alpha');
182 if ($type ==
'separate') {
186 $result = $extrafields->addExtraField(
193 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
194 (
GETPOST(
'required',
'alpha') ? 1 : 0),
197 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
201 GETPOST(
'computed_value',
'alpha'),
202 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
205 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
207 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
211 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
215 $mesg = $extrafields->error;
220 $langs->load(
"errors");
221 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities(
"AttributeCode"));
232if ($action ==
'update') {
233 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
237 $langs->load(
"errors");
238 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
241 if ($type ==
'varchar' && $extrasize <= 0) {
243 $langs->load(
"errors");
244 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
247 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
249 $langs->load(
"errors");
250 $mesg[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
253 if ($type ==
'int' && $extrasize > $maxsizeint) {
255 $langs->load(
"errors");
256 $mesg[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
259 if ($type ==
'select' && !$param) {
261 $langs->load(
"errors");
262 $mesg[] = $langs->trans(
"ErrorNoValueForSelectType");
265 if ($type ==
'sellist' && !$param) {
267 $langs->load(
"errors");
268 $mesg[] = $langs->trans(
"ErrorNoValueForSelectListType");
271 if ($type ==
'checkbox' && !$param) {
273 $langs->load(
"errors");
274 $mesg[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
277 if ($type ==
'radio' && !$param) {
279 $langs->load(
"errors");
280 $mesg[] = $langs->trans(
"ErrorNoValueForRadioType");
283 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
285 $parameters = $param;
286 $parameters_array = explode(
"\r\n", $parameters);
287 foreach ($parameters_array as $param_ligne) {
288 if (!empty($param_ligne)) {
289 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
290 if (count($matches[0]) > 1) {
292 $langs->load(
"errors");
293 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
298 $langs->load(
"errors");
299 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
307 if (strlen(
GETPOST(
'attrname',
'aZ09')) < 3 && empty($conf->global->MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE)) {
309 $langs->load(
"errors");
310 $mesg[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
317 if (in_array(
GETPOST(
'attrname',
'aZ09'), array(
'and',
'keyword',
'table',
'index',
'integer',
'float',
'double',
'position')) && empty($conf->global->MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE)) {
319 $langs->load(
"errors");
320 $mesg[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
326 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
329 $parameters = $param;
330 $parameters_array = explode(
"\r\n", $parameters);
333 if ($type ==
'sellist' || $type ==
'chkbxlst') {
334 foreach ($parameters_array as $param_ligne) {
335 $params[
'options'] = array($parameters=>
null);
339 foreach ($parameters_array as $param_ligne) {
340 list($key, $value) = explode(
',', $param_ligne);
341 if (!array_key_exists(
'options', $params)) {
342 $params[
'options'] = array();
344 $params[
'options'][$key] = $value;
349 $visibility =
GETPOST(
'list',
'alpha');
350 if ($type ==
'separate') {
355 $computedvalue =
GETPOST(
'computed_value',
'nohtml');
357 $result = $extrafields->update(
363 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
364 (
GETPOST(
'required',
'alpha') ? 1 : 0),
367 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
371 GETPOST(
'default_value',
'alpha'),
373 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
376 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
378 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
382 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
386 $mesg = $extrafields->error;
391 $langs->load(
"errors");
392 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
402if ($action ==
'delete') {
403 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
"attrname",
'aZ09'))) {
404 $result = $extrafields->delete(
GETPOST(
"attrname",
'aZ09'), $elementtype);
406 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
409 $mesg = $extrafields->error;
413 $langs->load(
"errors");
414 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.