39'@phan-var-force int $error';
40'@phan-var-force string $action';
41'@phan-var-force string $elementtype';
42'@phan-var-force string $value';
49$extrasize =
GETPOST(
'size',
'intcomma');
50$type =
GETPOST(
'type',
'alphanohtml');
51$param =
GETPOST(
'param',
'alphanohtml');
52$css =
GETPOST(
'css',
'alphanohtml');
53$cssview =
GETPOST(
'cssview',
'alphanohtml');
54$csslist =
GETPOST(
'csslist',
'alphanohtml');
55$confirm =
GETPOST(
'confirm',
'alpha');
57if ($type ==
'double' && strpos($extrasize,
',') ===
false) {
63if ($type ==
'datetime') {
66if ($type ==
'select') {
71$listofreservedwords = array(
72 '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',
73 'CURSOR',
'DATABASE',
'DATABASES',
'DAY_HOUR',
'DAY_MICROSECOND',
'DAY_MINUTE',
'DAY_SECOND',
'DECIMAL',
'DECLARE',
'DEFAULT',
'DELAYED',
'DELETE',
'DESC',
'DESCRIBE',
'DETERMINISTIC',
'DISTINCT',
'DISTINCTROW',
'DOUBLE',
'DROP',
'DUAL',
74 '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',
75 'IGNORE',
'IGNORE_SERVER_IDS',
'INDEX',
'INFILE',
'INNER',
'INOUT',
'INSENSITIVE',
'INSERT',
'INT',
'INTEGER',
'INTERVAL',
'INTO',
'ITERATE',
76 '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',
77 'OFFSET',
'ON',
'OPTION',
'OPTIONALLY',
'OUTER',
'OUTFILE',
'OVER',
78 'PARTITION',
'POSITION',
'PRECISION',
'PRIMARY',
'PROCEDURE',
'PURGE',
'RANGE',
'READS',
'READ_WRITE',
'REAL',
'REFERENCES',
'REGEXP',
'RELEASE',
'RENAME',
'REPEAT',
'REQUIRE',
'RESTRICT',
'RETURN',
'REVOKE',
'RIGHT',
'RLIKE',
79 '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',
80 'TABLE',
'TERMINATED',
'TINYBLOB',
'TINYINT',
'TINYTEXT',
'TRAILING',
'TRIGGER',
'UNDO',
'UNIQUE',
'UNSIGNED',
'UPDATE',
'USAGE',
'USING',
'UTC_DATE',
'UTC_TIME',
'UTC_TIMESTAMP',
'VALUES',
'VARBINARY',
'VARCHAR',
'VARYING',
81 'WHEN',
'WHERE',
'WHILE',
'WRITE',
'XOR',
'YEAR_MONTH',
'ZEROFILL'
85if ($action ==
'add') {
86 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
90 $langs->load(
"errors");
91 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
94 if ($type ==
'varchar' && $extrasize <= 0) {
96 $langs->load(
"errors");
97 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
100 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
102 $langs->load(
"errors");
103 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
106 if ($type ==
'int' && $extrasize > $maxsizeint) {
108 $langs->load(
"errors");
109 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
112 if ($type ==
'stars' && ($extrasize < 1 || $extrasize > 10)) {
114 $langs->load(
"errors");
115 $mesgs[] = $langs->trans(
"ErrorSizeForStarsType");
118 if ($type ==
'select' && !$param) {
120 $langs->load(
"errors");
121 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectType");
124 if ($type ==
'sellist' && !$param) {
126 $langs->load(
"errors");
127 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectListType");
130 if ($type ==
'checkbox' && !$param) {
132 $langs->load(
"errors");
133 $mesgs[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
136 if ($type ==
'link' && !$param) {
138 $langs->load(
"errors");
139 $mesgs[] = $langs->trans(
"ErrorNoValueForLinkType");
142 if ($type ==
'radio' && !$param) {
144 $langs->load(
"errors");
145 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
148 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
150 $parameters = $param;
151 $parameters_array = explode(
"\r\n", $parameters);
152 foreach ($parameters_array as $param_ligne) {
153 if (!empty($param_ligne)) {
155 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
156 if (count($matches[0]) > 1) {
158 $langs->load(
"errors");
159 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
164 $langs->load(
"errors");
165 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
173 if (strlen(
GETPOST(
'attrname',
'aZ09')) < 3) {
175 $langs->load(
"errors");
176 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
183 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords)) {
185 $langs->load(
"errors");
186 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
193 if (GETPOSTISSET(
"attrname") && preg_match(
"/^[a-z0-9_]+$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
195 $default_value =
GETPOST(
'default_value',
'alpha');
196 $parameters = $param;
197 $parameters_array = explode(
"\r\n", $parameters);
200 if ($type ==
'sellist' || $type ==
'chkbxlst') {
201 foreach ($parameters_array as $param_ligne) {
202 $params[
'options'] = array($parameters =>
null);
206 foreach ($parameters_array as $param_ligne) {
207 if (strpos($param_ligne,
',') !==
false) {
208 list($key, $value) = explode(
',', $param_ligne);
209 if (!array_key_exists(
'options', $params)) {
210 $params[
'options'] = array();
216 $params[
'options'][$key] = $value;
221 $visibility =
GETPOST(
'list',
'alpha');
222 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
226 $result = $extrafields->addExtraField(
233 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
234 (
GETPOST(
'required',
'alpha') ? 1 : 0),
237 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
241 GETPOST(
'computed_value',
'alpha'),
242 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
245 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
247 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist),
249 (
GETPOST(
'emptyonclone',
'alpha') ? 1 : 0),
250 (
GETPOST(
'showintooltip',
'int') ? 1 : 0),
255 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
259 $mesg = $extrafields->error;
260 $mesgs = array_merge($mesgs, $extrafields->errors);
265 $langs->load(
"errors");
266 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities(
"AttributeCode"));
277if ($action ==
'update') {
278 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
282 $langs->load(
"errors");
283 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
286 if ($type ==
'varchar' && $extrasize <= 0) {
288 $langs->load(
"errors");
289 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
292 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
294 $langs->load(
"errors");
295 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
298 if ($type ==
'int' && $extrasize > $maxsizeint) {
300 $langs->load(
"errors");
301 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
304 if ($type ==
'select' && !$param) {
306 $langs->load(
"errors");
307 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectType");
310 if ($type ==
'sellist' && !$param) {
312 $langs->load(
"errors");
313 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectListType");
316 if ($type ==
'stars' && ($extrasize < 1 || $extrasize > 10)) {
318 $langs->load(
"errors");
319 $mesgs[] = $langs->trans(
"ErrorSizeForStarsType");
322 if ($type ==
'checkbox' && !$param) {
324 $langs->load(
"errors");
325 $mesgs[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
328 if ($type ==
'radio' && !$param) {
330 $langs->load(
"errors");
331 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
334 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
336 $parameters = $param;
337 $parameters_array = explode(
"\r\n", $parameters);
338 foreach ($parameters_array as $param_ligne) {
339 if (!empty($param_ligne)) {
340 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
341 if (count($matches[0]) > 1) {
343 $langs->load(
"errors");
344 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
349 $langs->load(
"errors");
350 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
360 $langs->load(
"errors");
361 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
368 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords) && !
getDolGlobalString(
'MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE')) {
370 $langs->load(
"errors");
371 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
377 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
380 $parameters = $param;
381 $parameters_array = explode(
"\r\n", $parameters);
384 if ($type ==
'sellist' || $type ==
'chkbxlst') {
385 foreach ($parameters_array as $param_ligne) {
386 $params[
'options'] = array($parameters =>
null);
390 foreach ($parameters_array as $param_ligne) {
391 $tmp = explode(
',', $param_ligne);
393 if (!empty($tmp[1])) {
396 if (!array_key_exists(
'options', $params)) {
397 $params[
'options'] = array();
399 $params[
'options'][$key] = $value;
406 $visibility =
GETPOST(
'list',
'alpha');
407 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
412 $computedvalue =
GETPOST(
'computed_value',
'nohtml');
414 $result = $extrafields->update(
420 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
421 (
GETPOST(
'required',
'alpha') ? 1 : 0),
424 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
428 GETPOST(
'default_value',
'alpha'),
430 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
433 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
435 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist),
437 (
GETPOST(
'emptyonclone',
'alpha') ? 1 : 0),
438 (
GETPOST(
'showintooltip',
'int') ? 1 : 0),
443 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
447 $mesg = $extrafields->error;
448 $mesgs = array_merge($mesgs, $extrafields->errors);
453 $langs->load(
"errors");
454 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
464if ($action ==
'confirm_delete' && $confirm ==
"yes") {
465 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
"attrname",
'aZ09'))) {
466 $attributekey =
GETPOST(
'attrname',
'aZ09');
468 $result = $extrafields->delete($attributekey, $elementtype);
470 setEventMessages($langs->trans(
"ExtrafieldsDeleted", $attributekey),
null,
'mesgs');
472 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
475 $mesg = $extrafields->error;
476 $mesgs = array_merge($mesgs, $extrafields->errors);
480 $langs->load(
"errors");
481 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
486if ($action ==
'encrypt') {
488 $extrafields->fetch_name_optionals_label($elementtype);
489 $attributekey =
GETPOST(
'attrname',
'aZ09');
491 if (!empty($extrafields->attributes[$elementtype][
'type'][$attributekey]) && $extrafields->attributes[$elementtype][
'type'][$attributekey] ==
'password') {
492 if (!empty($extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
493 if (array_key_exists(
'dolcrypt', $extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
495 $arrayofelement = getElementProperties($elementtype);
496 if (!empty($arrayofelement[
'table_element'])) {
497 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] ==
$conf->entity || empty($extrafields->attributes[$elementtype][
'entityid'][$attributekey])) {
498 dol_syslog(
"Loop on each extafields of table ".$arrayofelement[
'table_element']);
500 $sql =
"SELECT te.rowid, te.".$db->sanitize($attributekey);
501 $sql .=
" FROM ".MAIN_DB_PREFIX.$db->sanitize($arrayofelement[
'table_element']).
" as t, ".MAIN_DB_PREFIX.$db->sanitize($arrayofelement[
'table_element']).
'_extrafields as te';
502 $sql .=
" WHERE te.fk_object = t.rowid";
503 $sql .=
" AND te.".$db->sanitize($attributekey).
" NOT LIKE 'dolcrypt:%'";
504 $sql .=
" AND te.".$db->sanitize($attributekey).
" IS NOT NULL";
505 $sql .=
" AND te.".$db->sanitize($attributekey).
" <> ''";
506 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] ==
$conf->entity) {
507 $sql .=
" AND t.entity = ".getEntity($arrayofelement[
'element'], 0);
512 $resql =
$db->query($sql);
514 $num_rows =
$db->num_rows($resql);
516 while ($i < $num_rows) {
517 $objtmp =
$db->fetch_object($resql);
518 $id = $objtmp->rowid;
519 $pass = $objtmp->$attributekey;
523 $sqlupdate =
"UPDATE ".MAIN_DB_PREFIX.$db->sanitize($arrayofelement[
'table_element']).
'_extrafields';
524 $sqlupdate .=
" SET ".$attributekey.
" = '".
$db->escape($newpassword).
"'";
525 $sqlupdate .=
" WHERE rowid = ".((int)
$id);
527 $resupdate =
$db->query($sqlupdate);
541 if ($nbupdatedone > 0) {
542 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'mesgs');
544 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'warnings');
$id
Support class for third parties, contacts, members, users or resources.
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.
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='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.