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');
37 if ($type ==
'double' && strpos($extrasize,
',') ===
false) {
40 if ($type ==
'date') {
43 if ($type ==
'datetime') {
46 if ($type ==
'select') {
52 if ($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 list($key, $value) = explode(
',', $param_ligne);
168 if (!array_key_exists(
'options', $params)) {
169 $params[
'options'] = array();
171 $params[
'options'][$key] = $value;
176 $visibility =
GETPOST(
'list',
'alpha');
177 if ($type ==
'separate') {
181 $result = $extrafields->addExtraField(
188 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
189 (
GETPOST(
'required',
'alpha') ? 1 : 0),
192 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
196 GETPOST(
'computed_value',
'alpha'),
197 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
200 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
202 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
206 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
210 $mesg = $extrafields->error;
215 $langs->load(
"errors");
216 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities(
"AttributeCode"));
227 if ($action ==
'update') {
228 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
232 $langs->load(
"errors");
233 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
236 if ($type ==
'varchar' && $extrasize <= 0) {
238 $langs->load(
"errors");
239 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
242 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
244 $langs->load(
"errors");
245 $mesg[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
248 if ($type ==
'int' && $extrasize > $maxsizeint) {
250 $langs->load(
"errors");
251 $mesg[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
254 if ($type ==
'select' && !$param) {
256 $langs->load(
"errors");
257 $mesg[] = $langs->trans(
"ErrorNoValueForSelectType");
260 if ($type ==
'sellist' && !$param) {
262 $langs->load(
"errors");
263 $mesg[] = $langs->trans(
"ErrorNoValueForSelectListType");
266 if ($type ==
'checkbox' && !$param) {
268 $langs->load(
"errors");
269 $mesg[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
272 if ($type ==
'radio' && !$param) {
274 $langs->load(
"errors");
275 $mesg[] = $langs->trans(
"ErrorNoValueForRadioType");
278 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
280 $parameters = $param;
281 $parameters_array = explode(
"\r\n", $parameters);
282 foreach ($parameters_array as $param_ligne) {
283 if (!empty($param_ligne)) {
284 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
285 if (count($matches[0]) > 1) {
287 $langs->load(
"errors");
288 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
293 $langs->load(
"errors");
294 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
302 if (strlen(
GETPOST(
'attrname',
'aZ09')) < 3 && empty($conf->global->MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE)) {
304 $langs->load(
"errors");
305 $mesg[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
312 if (in_array(
GETPOST(
'attrname',
'aZ09'), array(
'and',
'keyword',
'table',
'index',
'integer',
'float',
'double',
'position')) && empty($conf->global->MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE)) {
314 $langs->load(
"errors");
315 $mesg[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
321 if (
GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
324 $parameters = $param;
325 $parameters_array = explode(
"\r\n", $parameters);
328 if ($type ==
'sellist' || $type ==
'chkbxlst') {
329 foreach ($parameters_array as $param_ligne) {
330 $params[
'options'] = array($parameters=>
null);
334 foreach ($parameters_array as $param_ligne) {
335 list($key, $value) = explode(
',', $param_ligne);
336 if (!array_key_exists(
'options', $params)) {
337 $params[
'options'] = array();
339 $params[
'options'][$key] = $value;
344 $visibility =
GETPOST(
'list',
'alpha');
345 if ($type ==
'separate') {
350 $computedvalue =
GETPOST(
'computed_value',
'nohtml');
352 $result = $extrafields->update(
358 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
359 (
GETPOST(
'required',
'alpha') ? 1 : 0),
362 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
366 GETPOST(
'default_value',
'alpha'),
368 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
371 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
373 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
377 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
381 $mesg = $extrafields->error;
386 $langs->load(
"errors");
387 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
397 if ($action ==
'delete') {
398 if (
GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
"attrname",
'aZ09'))) {
399 $result = $extrafields->delete(
GETPOST(
"attrname",
'aZ09'), $elementtype);
401 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
404 $mesg = $extrafields->error;
408 $langs->load(
"errors");
409 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.