33$extrasize =
GETPOST(
'size',
'intcomma');
34$type =
GETPOST(
'type',
'alphanohtml');
35$param =
GETPOST(
'param',
'alphanohtml');
36$css =
GETPOST(
'css',
'alphanohtml');
37$cssview =
GETPOST(
'cssview',
'alphanohtml');
38$csslist =
GETPOST(
'csslist',
'alphanohtml');
39$confirm =
GETPOST(
'confirm',
'alpha');
41if ($type ==
'double' && strpos($extrasize,
',') ===
false) {
47if ($type ==
'datetime') {
50if ($type ==
'select') {
54$listofreservedwords = array(
55 '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',
56 'CURSOR',
'DATABASE',
'DATABASES',
'DAY_HOUR',
'DAY_MICROSECOND',
'DAY_MINUTE',
'DAY_SECOND',
'DECIMAL',
'DECLARE',
'DEFAULT',
'DELAYED',
'DELETE',
'DESC',
'DESCRIBE',
'DETERMINISTIC',
'DISTINCT',
'DISTINCTROW',
'DOUBLE',
'DROP',
'DUAL',
57 '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',
58 'IGNORE',
'IGNORE_SERVER_IDS',
'INDEX',
'INFILE',
'INNER',
'INOUT',
'INSENSITIVE',
'INSERT',
'INT',
'INTEGER',
'INTERVAL',
'INTO',
'ITERATE',
59 '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',
60 'OFFSET',
'ON',
'OPTION',
'OPTIONALLY',
'OUTER',
'OUTFILE',
61 'PARTITION',
'POSITION',
'PRECISION',
'PRIMARY',
'PROCEDURE',
'PURGE',
'RANGE',
'READS',
'READ_WRITE',
'REAL',
'REFERENCES',
'REGEXP',
'RELEASE',
'RENAME',
'REPEAT',
'REQUIRE',
'RESTRICT',
'RETURN',
'REVOKE',
'RIGHT',
'RLIKE',
62 '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',
63 'TABLE',
'TERMINATED',
'TINYBLOB',
'TINYINT',
'TINYTEXT',
'TRAILING',
'TRIGGER',
'UNDO',
'UNIQUE',
'UNSIGNED',
'UPDATE',
'USAGE',
'USING',
'UTC_DATE',
'UTC_TIME',
'UTC_TIMESTAMP',
'VALUES',
'VARBINARY',
'VARCHAR',
'VARYING',
64 'WHEN',
'WHERE',
'WHILE',
'WRITE',
'XOR',
'YEAR_MONTH',
'ZEROFILL'
68if ($action ==
'add') {
69 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
73 $langs->load(
"errors");
74 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
77 if ($type ==
'varchar' && $extrasize <= 0) {
79 $langs->load(
"errors");
80 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
83 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
85 $langs->load(
"errors");
86 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
89 if ($type ==
'int' && $extrasize > $maxsizeint) {
91 $langs->load(
"errors");
92 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
95 if ($type ==
'stars' && ($extrasize < 1 || $extrasize > 10)) {
97 $langs->load(
"errors");
98 $mesgs[] = $langs->trans(
"ErrorSizeForStarsType");
101 if ($type ==
'select' && !$param) {
103 $langs->load(
"errors");
104 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectType");
107 if ($type ==
'sellist' && !$param) {
109 $langs->load(
"errors");
110 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectListType");
113 if ($type ==
'checkbox' && !$param) {
115 $langs->load(
"errors");
116 $mesgs[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
119 if ($type ==
'link' && !$param) {
121 $langs->load(
"errors");
122 $mesgs[] = $langs->trans(
"ErrorNoValueForLinkType");
125 if ($type ==
'radio' && !$param) {
127 $langs->load(
"errors");
128 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
131 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
133 $parameters = $param;
134 $parameters_array = explode(
"\r\n", $parameters);
135 foreach ($parameters_array as $param_ligne) {
136 if (!empty($param_ligne)) {
137 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
138 if (count($matches[0]) > 1) {
140 $langs->load(
"errors");
141 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
146 $langs->load(
"errors");
147 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
155 if (strlen(
GETPOST(
'attrname',
'aZ09')) < 3) {
157 $langs->load(
"errors");
158 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
165 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords)) {
167 $langs->load(
"errors");
168 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
175 if (GETPOSTISSET(
"attrname") && preg_match(
"/^[a-z0-9_]+$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
177 $default_value =
GETPOST(
'default_value',
'alpha');
178 $parameters = $param;
179 $parameters_array = explode(
"\r\n", $parameters);
182 if ($type ==
'sellist' || $type ==
'chkbxlst') {
183 foreach ($parameters_array as $param_ligne) {
184 $params[
'options'] = array($parameters =>
null);
188 foreach ($parameters_array as $param_ligne) {
189 if (strpos($param_ligne,
',') !==
false) {
190 list($key, $value) = explode(
',', $param_ligne);
191 if (!array_key_exists(
'options', $params)) {
192 $params[
'options'] = array();
198 $params[
'options'][$key] = $value;
203 $visibility =
GETPOST(
'list',
'alpha');
204 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
208 $result = $extrafields->addExtraField(
215 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
216 (
GETPOST(
'required',
'alpha') ? 1 : 0),
219 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
223 GETPOST(
'computed_value',
'alpha'),
224 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
227 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
229 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
233 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
237 $mesg = $extrafields->error;
238 $mesgs = array_merge($mesgs, $extrafields->errors);
243 $langs->load(
"errors");
244 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities(
"AttributeCode"));
255if ($action ==
'update') {
256 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
260 $langs->load(
"errors");
261 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
264 if ($type ==
'varchar' && $extrasize <= 0) {
266 $langs->load(
"errors");
267 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
270 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
272 $langs->load(
"errors");
273 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
276 if ($type ==
'int' && $extrasize > $maxsizeint) {
278 $langs->load(
"errors");
279 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
282 if ($type ==
'select' && !$param) {
284 $langs->load(
"errors");
285 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectType");
288 if ($type ==
'sellist' && !$param) {
290 $langs->load(
"errors");
291 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectListType");
294 if ($type ==
'stars' && ($extrasize < 1|| $extrasize > 10)) {
296 $langs->load(
"errors");
297 $mesgs[] = $langs->trans(
"ErrorSizeForStarsType");
300 if ($type ==
'checkbox' && !$param) {
302 $langs->load(
"errors");
303 $mesgs[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
306 if ($type ==
'radio' && !$param) {
308 $langs->load(
"errors");
309 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
312 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
314 $parameters = $param;
315 $parameters_array = explode(
"\r\n", $parameters);
316 foreach ($parameters_array as $param_ligne) {
317 if (!empty($param_ligne)) {
318 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
319 if (count($matches[0]) > 1) {
321 $langs->load(
"errors");
322 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
327 $langs->load(
"errors");
328 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
338 $langs->load(
"errors");
339 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
346 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords) && !
getDolGlobalString(
'MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE')) {
348 $langs->load(
"errors");
349 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
355 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
358 $parameters = $param;
359 $parameters_array = explode(
"\r\n", $parameters);
362 if ($type ==
'sellist' || $type ==
'chkbxlst') {
363 foreach ($parameters_array as $param_ligne) {
364 $params[
'options'] = array($parameters =>
null);
368 foreach ($parameters_array as $param_ligne) {
369 $tmp = explode(
',', $param_ligne);
371 if (!empty($tmp[1])) {
374 if (!array_key_exists(
'options', $params)) {
375 $params[
'options'] = array();
377 $params[
'options'][$key] = $value;
384 $visibility =
GETPOST(
'list',
'alpha');
385 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
390 $computedvalue =
GETPOST(
'computed_value',
'nohtml');
392 $result = $extrafields->update(
398 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
399 (
GETPOST(
'required',
'alpha') ? 1 : 0),
402 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
406 GETPOST(
'default_value',
'alpha'),
408 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
411 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
413 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
417 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
421 $mesg = $extrafields->error;
422 $mesgs = array_merge($mesgs, $extrafields->errors);
427 $langs->load(
"errors");
428 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
438if ($action ==
'confirm_delete' && $confirm ==
"yes") {
439 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
"attrname",
'aZ09'))) {
440 $attributekey =
GETPOST(
'attrname',
'aZ09');
442 $result = $extrafields->delete($attributekey, $elementtype);
444 setEventMessages($langs->trans(
"ExtrafieldsDeleted", $attributekey),
null,
'mesgs');
446 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
449 $mesg = $extrafields->error;
450 $mesgs = array_merge($mesgs, $extrafields->errors);
454 $langs->load(
"errors");
455 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
460if ($action ==
'encrypt') {
462 $extrafields->fetch_name_optionals_label($elementtype);
463 $attributekey =
GETPOST(
'attrname',
'aZ09');
465 if (!empty($extrafields->attributes[$elementtype][
'type'][$attributekey]) && $extrafields->attributes[$elementtype][
'type'][$attributekey] ==
'password') {
466 if (!empty($extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
467 if (array_key_exists(
'dolcrypt', $extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
470 if (!empty($arrayofelement[
'table_element'])) {
471 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] == $conf->entity || empty($extrafields->attributes[$elementtype][
'entityid'][$attributekey])) {
472 dol_syslog(
"Loop on each extafields of table ".$arrayofelement[
'table_element']);
474 $sql =
"SELECT te.rowid, te.".$attributekey;
475 $sql .=
" FROM ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
" as t, ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields as te';
476 $sql .=
" WHERE te.fk_object = t.rowid";
477 $sql .=
" AND te.".$attributekey.
" NOT LIKE 'dolcrypt:%'";
478 $sql .=
" AND te.".$attributekey.
" IS NOT NULL";
479 $sql .=
" AND te.".$attributekey.
" <> ''";
480 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] == $conf->entity) {
481 $sql .=
" AND t.entity = ".getEntity($arrayofelement[
'table_element'], 0);
486 $resql = $db->query($sql);
488 $num_rows = $db->num_rows($resql);
490 while ($i < $num_rows) {
491 $objtmp = $db->fetch_object($resql);
492 $id = $objtmp->rowid;
493 $pass = $objtmp->$attributekey;
497 $sqlupdate =
"UPDATE ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields';
498 $sqlupdate .=
" SET ".$attributekey.
" = '".$db->escape($newpassword).
"'";
499 $sqlupdate .=
" WHERE rowid = ".((int)
$id);
501 $resupdate = $db->query($sqlupdate);
515 if ($nbupdatedone > 0) {
516 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'mesgs');
518 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'warnings');
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getElementProperties($elementType)
Get an array with properties of an element.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='')
Encode a string with a symmetric encryption.