44$extrasize =
GETPOST(
'size',
'intcomma');
45$type =
GETPOST(
'type',
'alphanohtml');
46$param =
GETPOST(
'param',
'alphanohtml');
47$css =
GETPOST(
'css',
'alphanohtml');
48$cssview =
GETPOST(
'cssview',
'alphanohtml');
49$csslist =
GETPOST(
'csslist',
'alphanohtml');
50$confirm =
GETPOST(
'confirm',
'alpha');
52if ($type ==
'double' && strpos($extrasize,
',') ===
false) {
58if ($type ==
'datetime') {
61if ($type ==
'select') {
66$listofreservedwords = array(
67 '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',
68 'CURSOR',
'DATABASE',
'DATABASES',
'DAY_HOUR',
'DAY_MICROSECOND',
'DAY_MINUTE',
'DAY_SECOND',
'DECIMAL',
'DECLARE',
'DEFAULT',
'DELAYED',
'DELETE',
'DESC',
'DESCRIBE',
'DETERMINISTIC',
'DISTINCT',
'DISTINCTROW',
'DOUBLE',
'DROP',
'DUAL',
69 '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',
70 'IGNORE',
'IGNORE_SERVER_IDS',
'INDEX',
'INFILE',
'INNER',
'INOUT',
'INSENSITIVE',
'INSERT',
'INT',
'INTEGER',
'INTERVAL',
'INTO',
'ITERATE',
71 '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',
72 'OFFSET',
'ON',
'OPTION',
'OPTIONALLY',
'OUTER',
'OUTFILE',
'OVER',
73 'PARTITION',
'POSITION',
'PRECISION',
'PRIMARY',
'PROCEDURE',
'PURGE',
'RANGE',
'READS',
'READ_WRITE',
'REAL',
'REFERENCES',
'REGEXP',
'RELEASE',
'RENAME',
'REPEAT',
'REQUIRE',
'RESTRICT',
'RETURN',
'REVOKE',
'RIGHT',
'RLIKE',
74 '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',
75 'TABLE',
'TERMINATED',
'TINYBLOB',
'TINYINT',
'TINYTEXT',
'TRAILING',
'TRIGGER',
'UNDO',
'UNIQUE',
'UNSIGNED',
'UPDATE',
'USAGE',
'USING',
'UTC_DATE',
'UTC_TIME',
'UTC_TIMESTAMP',
'VALUES',
'VARBINARY',
'VARCHAR',
'VARYING',
76 'WHEN',
'WHERE',
'WHILE',
'WRITE',
'XOR',
'YEAR_MONTH',
'ZEROFILL'
80if ($action ==
'add') {
81 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
85 $langs->load(
"errors");
86 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
89 if ($type ==
'varchar' && $extrasize <= 0) {
91 $langs->load(
"errors");
92 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
95 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
97 $langs->load(
"errors");
98 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
101 if ($type ==
'int' && $extrasize > $maxsizeint) {
103 $langs->load(
"errors");
104 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
107 if ($type ==
'stars' && ($extrasize < 1 || $extrasize > 10)) {
109 $langs->load(
"errors");
110 $mesgs[] = $langs->trans(
"ErrorSizeForStarsType");
113 if ($type ==
'select' && !$param) {
115 $langs->load(
"errors");
116 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectType");
119 if ($type ==
'sellist' && !$param) {
121 $langs->load(
"errors");
122 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectListType");
125 if ($type ==
'checkbox' && !$param) {
127 $langs->load(
"errors");
128 $mesgs[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
131 if ($type ==
'link' && !$param) {
133 $langs->load(
"errors");
134 $mesgs[] = $langs->trans(
"ErrorNoValueForLinkType");
137 if ($type ==
'link' && $param) {
140 $tmplink = explode(
':', $param);
141 if (empty($tmplink[1]) || !file_exists(
dol_buildpath($tmplink[1]))) {
143 $langs->load(
"errors");
144 $mesgs[] = $langs->trans(
"ErrorFileNotFound", empty($tmplink[1]) ? $param : $tmplink[1]);
148 if ($type ==
'radio' && !$param) {
150 $langs->load(
"errors");
151 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
154 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
156 $parameters = $param;
157 $parameters_array = explode(
"\r\n", $parameters);
158 foreach ($parameters_array as $param_ligne) {
159 if (!empty($param_ligne)) {
160 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
161 if (count($matches[0]) > 1) {
163 $langs->load(
"errors");
164 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
169 $langs->load(
"errors");
170 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
178 if (strlen(
GETPOST(
'attrname',
'aZ09')) < 3) {
180 $langs->load(
"errors");
181 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
188 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords)) {
190 $langs->load(
"errors");
191 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
198 if (GETPOSTISSET(
"attrname") && preg_match(
"/^[a-z0-9_]+$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
200 $default_value =
GETPOST(
'default_value',
'alpha');
201 $parameters = $param;
202 $parameters_array = explode(
"\r\n", $parameters);
205 if ($type ==
'sellist' || $type ==
'chkbxlst') {
206 foreach ($parameters_array as $param_ligne) {
207 $params[
'options'] = array($parameters =>
null);
211 foreach ($parameters_array as $param_ligne) {
212 if (strpos($param_ligne,
',') !==
false) {
213 list($key, $value) = explode(
',', $param_ligne);
214 if (!array_key_exists(
'options', $params)) {
215 $params[
'options'] = array();
221 $params[
'options'][$key] = $value;
226 $visibility =
GETPOST(
'list',
'alpha');
227 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
231 $result = $extrafields->addExtraField(
238 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
239 (
GETPOST(
'required',
'alpha') ? 1 : 0),
242 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
246 GETPOST(
'computed_value',
'alpha'),
247 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
250 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
252 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist),
257 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
261 $mesg = $extrafields->error;
262 $mesgs = array_merge($mesgs, $extrafields->errors);
267 $langs->load(
"errors");
268 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities(
"AttributeCode"));
279if ($action ==
'update') {
280 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
284 $langs->load(
"errors");
285 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
288 if ($type ==
'varchar' && $extrasize <= 0) {
290 $langs->load(
"errors");
291 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
294 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
296 $langs->load(
"errors");
297 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
300 if ($type ==
'int' && $extrasize > $maxsizeint) {
302 $langs->load(
"errors");
303 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
306 if ($type ==
'select' && !$param) {
308 $langs->load(
"errors");
309 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectType");
312 if ($type ==
'sellist' && !$param) {
314 $langs->load(
"errors");
315 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectListType");
318 if ($type ==
'stars' && ($extrasize < 1 || $extrasize > 10)) {
320 $langs->load(
"errors");
321 $mesgs[] = $langs->trans(
"ErrorSizeForStarsType");
324 if ($type ==
'checkbox' && !$param) {
326 $langs->load(
"errors");
327 $mesgs[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
330 if ($type ==
'radio' && !$param) {
332 $langs->load(
"errors");
333 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
336 if ($type ==
'link' && $param) {
339 $tmplink = explode(
':', $param);
340 if (empty($tmplink[1]) || !file_exists(
dol_buildpath($tmplink[1]))) {
342 $langs->load(
"errors");
343 $mesgs[] = $langs->trans(
"ErrorFileNotFound", empty($tmplink[1]) ? $param : $tmplink[1]);
347 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
349 $parameters = $param;
350 $parameters_array = explode(
"\r\n", $parameters);
351 foreach ($parameters_array as $param_ligne) {
352 if (!empty($param_ligne)) {
353 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
354 if (count($matches[0]) > 1) {
356 $langs->load(
"errors");
357 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
362 $langs->load(
"errors");
363 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
373 $langs->load(
"errors");
374 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
381 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords) && !
getDolGlobalString(
'MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE')) {
383 $langs->load(
"errors");
384 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
390 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
393 $parameters = $param;
394 $parameters_array = explode(
"\r\n", $parameters);
397 if ($type ==
'sellist' || $type ==
'chkbxlst') {
398 foreach ($parameters_array as $param_ligne) {
399 $params[
'options'] = array($parameters =>
null);
403 foreach ($parameters_array as $param_ligne) {
404 $tmp = explode(
',', $param_ligne);
406 if (!empty($tmp[1])) {
409 if (!array_key_exists(
'options', $params)) {
410 $params[
'options'] = array();
412 $params[
'options'][$key] = $value;
419 $visibility =
GETPOST(
'list',
'alpha');
420 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
425 $computedvalue =
GETPOST(
'computed_value',
'nohtml');
427 $result = $extrafields->update(
433 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
434 (
GETPOST(
'required',
'alpha') ? 1 : 0),
437 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
441 GETPOST(
'default_value',
'alpha'),
443 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
446 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
448 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist),
453 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
457 $mesg = $extrafields->error;
458 $mesgs = array_merge($mesgs, $extrafields->errors);
463 $langs->load(
"errors");
464 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
474if ($action ==
'confirm_delete' && $confirm ==
"yes") {
475 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
"attrname",
'aZ09'))) {
476 $attributekey =
GETPOST(
'attrname',
'aZ09');
478 $result = $extrafields->delete($attributekey, $elementtype);
480 setEventMessages($langs->trans(
"ExtrafieldsDeleted", $attributekey),
null,
'mesgs');
482 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
485 $mesg = $extrafields->error;
486 $mesgs = array_merge($mesgs, $extrafields->errors);
490 $langs->load(
"errors");
491 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
496if ($action ==
'encrypt') {
498 $extrafields->fetch_name_optionals_label($elementtype);
499 $attributekey =
GETPOST(
'attrname',
'aZ09');
501 if (!empty($extrafields->attributes[$elementtype][
'type'][$attributekey]) && $extrafields->attributes[$elementtype][
'type'][$attributekey] ==
'password') {
502 if (!empty($extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
503 if (array_key_exists(
'dolcrypt', $extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
506 if (!empty($arrayofelement[
'table_element'])) {
507 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] ==
$conf->entity || empty($extrafields->attributes[$elementtype][
'entityid'][$attributekey])) {
508 dol_syslog(
"Loop on each extafields of table ".$arrayofelement[
'table_element']);
510 $sql =
"SELECT te.rowid, te.".$attributekey;
511 $sql .=
" FROM ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
" as t, ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields as te';
512 $sql .=
" WHERE te.fk_object = t.rowid";
513 $sql .=
" AND te.".$attributekey.
" NOT LIKE 'dolcrypt:%'";
514 $sql .=
" AND te.".$attributekey.
" IS NOT NULL";
515 $sql .=
" AND te.".$attributekey.
" <> ''";
516 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] ==
$conf->entity) {
517 $sql .=
" AND t.entity = ".getEntity($arrayofelement[
'element'], 0);
522 $resql = $db->query($sql);
524 $num_rows = $db->num_rows($resql);
526 while ($i < $num_rows) {
527 $objtmp = $db->fetch_object($resql);
528 $id = $objtmp->rowid;
529 $pass = $objtmp->$attributekey;
533 $sqlupdate =
"UPDATE ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields';
534 $sqlupdate .=
" SET ".$attributekey.
" = '".$db->escape($newpassword).
"'";
535 $sqlupdate .=
" WHERE rowid = ".((int)
$id);
537 $resupdate = $db->query($sqlupdate);
551 if ($nbupdatedone > 0) {
552 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'mesgs');
554 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.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
dolEncrypt($chain, $key='', $ciphering='', $forceseed='')
Encode a string with a symmetric encryption.