30 $extrasize =
GETPOST(
'size',
'intcomma');
31 $type =
GETPOST(
'type',
'alpha');
32 $param =
GETPOST(
'param',
'alpha');
34 if ($type ==
'double' && strpos($extrasize,
',') ===
false) {
37 if ($type ==
'date') {
40 if ($type ==
'datetime') {
43 if ($type ==
'select') {
49 if ($action ==
'add') {
50 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
54 $langs->load(
"errors");
55 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
58 if ($type ==
'varchar' && $extrasize <= 0) {
60 $langs->load(
"errors");
61 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
64 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
66 $langs->load(
"errors");
67 $mesg[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
70 if ($type ==
'int' && $extrasize > $maxsizeint) {
72 $langs->load(
"errors");
73 $mesg[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
76 if ($type ==
'select' && !$param) {
78 $langs->load(
"errors");
79 $mesg[] = $langs->trans(
"ErrorNoValueForSelectType");
82 if ($type ==
'sellist' && !$param) {
84 $langs->load(
"errors");
85 $mesg[] = $langs->trans(
"ErrorNoValueForSelectListType");
88 if ($type ==
'checkbox' && !$param) {
90 $langs->load(
"errors");
91 $mesg[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
94 if ($type ==
'link' && !$param) {
96 $langs->load(
"errors");
97 $mesg[] = $langs->trans(
"ErrorNoValueForLinkType");
100 if ($type ==
'radio' && !$param) {
102 $langs->load(
"errors");
103 $mesg[] = $langs->trans(
"ErrorNoValueForRadioType");
106 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
108 $parameters = $param;
109 $parameters_array = explode(
"\r\n", $parameters);
110 foreach ($parameters_array as $param_ligne) {
111 if (!empty($param_ligne)) {
112 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
113 if (count($matches[0]) > 1) {
115 $langs->load(
"errors");
116 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
121 $langs->load(
"errors");
122 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
130 if (strlen(
GETPOST(
'attrname',
'aZ09')) < 3) {
132 $langs->load(
"errors");
133 $mesg[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
140 if (in_array(
GETPOST(
'attrname',
'aZ09'), array(
'and',
'keyword',
'table',
'index',
'int',
'integer',
'float',
'double',
'real',
'position'))) {
142 $langs->load(
"errors");
143 $mesg[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
150 if (
GETPOSTISSET(
"attrname") && preg_match(
"/^[a-z0-9_]+$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
152 $default_value =
GETPOST(
'default_value',
'alpha');
153 $parameters = $param;
154 $parameters_array = explode(
"\r\n", $parameters);
157 if ($type ==
'sellist' || $type ==
'chkbxlst') {
158 foreach ($parameters_array as $param_ligne) {
159 $params[
'options'] = array($parameters=>
null);
163 foreach ($parameters_array as $param_ligne) {
164 list($key, $value) = explode(
',', $param_ligne);
165 if (!array_key_exists(
'options', $params)) {
166 $params[
'options'] = array();
168 $params[
'options'][$key] = $value;
173 $visibility =
GETPOST(
'list',
'alpha');
174 if ($type ==
'separate') {
178 $result = $extrafields->addExtraField(
185 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
186 (
GETPOST(
'required',
'alpha') ? 1 : 0),
189 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
193 GETPOST(
'computed_value',
'alpha'),
194 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
197 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
202 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
206 $mesg = $extrafields->error;
211 $langs->load(
"errors");
212 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities(
"AttributeCode"));
223 if ($action ==
'update') {
224 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
228 $langs->load(
"errors");
229 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
232 if ($type ==
'varchar' && $extrasize <= 0) {
234 $langs->load(
"errors");
235 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
238 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
240 $langs->load(
"errors");
241 $mesg[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
244 if ($type ==
'int' && $extrasize > $maxsizeint) {
246 $langs->load(
"errors");
247 $mesg[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
250 if ($type ==
'select' && !$param) {
252 $langs->load(
"errors");
253 $mesg[] = $langs->trans(
"ErrorNoValueForSelectType");
256 if ($type ==
'sellist' && !$param) {
258 $langs->load(
"errors");
259 $mesg[] = $langs->trans(
"ErrorNoValueForSelectListType");
262 if ($type ==
'checkbox' && !$param) {
264 $langs->load(
"errors");
265 $mesg[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
268 if ($type ==
'radio' && !$param) {
270 $langs->load(
"errors");
271 $mesg[] = $langs->trans(
"ErrorNoValueForRadioType");
274 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
276 $parameters = $param;
277 $parameters_array = explode(
"\r\n", $parameters);
278 foreach ($parameters_array as $param_ligne) {
279 if (!empty($param_ligne)) {
280 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
281 if (count($matches[0]) > 1) {
283 $langs->load(
"errors");
284 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
289 $langs->load(
"errors");
290 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
298 if (strlen(
GETPOST(
'attrname',
'aZ09')) < 3 && empty($conf->global->MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE)) {
300 $langs->load(
"errors");
301 $mesg[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
308 if (in_array(
GETPOST(
'attrname',
'aZ09'), array(
'and',
'keyword',
'table',
'index',
'integer',
'float',
'double',
'position')) && empty($conf->global->MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE)) {
310 $langs->load(
"errors");
311 $mesg[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
317 if (
GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
320 $parameters = $param;
321 $parameters_array = explode(
"\r\n", $parameters);
324 if ($type ==
'sellist' || $type ==
'chkbxlst') {
325 foreach ($parameters_array as $param_ligne) {
326 $params[
'options'] = array($parameters=>
null);
330 foreach ($parameters_array as $param_ligne) {
331 list($key, $value) = explode(
',', $param_ligne);
332 if (!array_key_exists(
'options', $params)) {
333 $params[
'options'] = array();
335 $params[
'options'][$key] = $value;
340 $visibility =
GETPOST(
'list',
'alpha');
341 if ($type ==
'separate') {
346 $computedvalue =
GETPOST(
'computed_value',
'nohtml');
348 $result = $extrafields->update(
354 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
355 (
GETPOST(
'required',
'alpha') ? 1 : 0),
358 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
362 GETPOST(
'default_value',
'alpha'),
364 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
367 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
372 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
376 $mesg = $extrafields->error;
381 $langs->load(
"errors");
382 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
392 if ($action ==
'delete') {
393 if (
GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
"attrname",
'aZ09'))) {
394 $result = $extrafields->delete(
GETPOST(
"attrname",
'aZ09'), $elementtype);
396 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
399 $mesg = $extrafields->error;
403 $langs->load(
"errors");
404 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));