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 ==
'radio' && !$param) {
139 $langs->load(
"errors");
140 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
143 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
145 $parameters = $param;
146 $parameters_array = explode(
"\r\n", $parameters);
147 foreach ($parameters_array as $param_ligne) {
148 if (!empty($param_ligne)) {
149 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
150 if (count($matches[0]) > 1) {
152 $langs->load(
"errors");
153 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
158 $langs->load(
"errors");
159 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
167 if (strlen(
GETPOST(
'attrname',
'aZ09')) < 3) {
169 $langs->load(
"errors");
170 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
177 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords)) {
179 $langs->load(
"errors");
180 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
187 if (GETPOSTISSET(
"attrname") && preg_match(
"/^[a-z0-9_]+$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
189 $default_value =
GETPOST(
'default_value',
'alpha');
190 $parameters = $param;
191 $parameters_array = explode(
"\r\n", $parameters);
194 if ($type ==
'sellist' || $type ==
'chkbxlst') {
195 foreach ($parameters_array as $param_ligne) {
196 $params[
'options'] = array($parameters =>
null);
200 foreach ($parameters_array as $param_ligne) {
201 if (strpos($param_ligne,
',') !==
false) {
202 list($key, $value) = explode(
',', $param_ligne);
203 if (!array_key_exists(
'options', $params)) {
204 $params[
'options'] = array();
210 $params[
'options'][$key] = $value;
215 $visibility =
GETPOST(
'list',
'alpha');
216 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
220 $result = $extrafields->addExtraField(
227 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
228 (
GETPOST(
'required',
'alpha') ? 1 : 0),
231 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
235 GETPOST(
'computed_value',
'alpha'),
236 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
239 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
241 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist),
243 (
GETPOST(
'emptyonclone',
'alpha') ? 1 : 0)
247 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
251 $mesg = $extrafields->error;
252 $mesgs = array_merge($mesgs, $extrafields->errors);
257 $langs->load(
"errors");
258 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities(
"AttributeCode"));
269if ($action ==
'update') {
270 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
274 $langs->load(
"errors");
275 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
278 if ($type ==
'varchar' && $extrasize <= 0) {
280 $langs->load(
"errors");
281 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
284 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
286 $langs->load(
"errors");
287 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
290 if ($type ==
'int' && $extrasize > $maxsizeint) {
292 $langs->load(
"errors");
293 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
296 if ($type ==
'select' && !$param) {
298 $langs->load(
"errors");
299 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectType");
302 if ($type ==
'sellist' && !$param) {
304 $langs->load(
"errors");
305 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectListType");
308 if ($type ==
'stars' && ($extrasize < 1 || $extrasize > 10)) {
310 $langs->load(
"errors");
311 $mesgs[] = $langs->trans(
"ErrorSizeForStarsType");
314 if ($type ==
'checkbox' && !$param) {
316 $langs->load(
"errors");
317 $mesgs[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
320 if ($type ==
'radio' && !$param) {
322 $langs->load(
"errors");
323 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
326 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
328 $parameters = $param;
329 $parameters_array = explode(
"\r\n", $parameters);
330 foreach ($parameters_array as $param_ligne) {
331 if (!empty($param_ligne)) {
332 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
333 if (count($matches[0]) > 1) {
335 $langs->load(
"errors");
336 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
341 $langs->load(
"errors");
342 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
352 $langs->load(
"errors");
353 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
360 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords) && !
getDolGlobalString(
'MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE')) {
362 $langs->load(
"errors");
363 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
369 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
372 $parameters = $param;
373 $parameters_array = explode(
"\r\n", $parameters);
376 if ($type ==
'sellist' || $type ==
'chkbxlst') {
377 foreach ($parameters_array as $param_ligne) {
378 $params[
'options'] = array($parameters =>
null);
382 foreach ($parameters_array as $param_ligne) {
383 $tmp = explode(
',', $param_ligne);
385 if (!empty($tmp[1])) {
388 if (!array_key_exists(
'options', $params)) {
389 $params[
'options'] = array();
391 $params[
'options'][$key] = $value;
398 $visibility =
GETPOST(
'list',
'alpha');
399 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
404 $computedvalue =
GETPOST(
'computed_value',
'nohtml');
406 $result = $extrafields->update(
412 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
413 (
GETPOST(
'required',
'alpha') ? 1 : 0),
416 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
420 GETPOST(
'default_value',
'alpha'),
422 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
425 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
427 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist),
429 (
GETPOST(
'emptyonclone',
'alpha') ? 1 : 0)
433 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
437 $mesg = $extrafields->error;
438 $mesgs = array_merge($mesgs, $extrafields->errors);
443 $langs->load(
"errors");
444 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
454if ($action ==
'confirm_delete' && $confirm ==
"yes") {
455 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
"attrname",
'aZ09'))) {
456 $attributekey =
GETPOST(
'attrname',
'aZ09');
458 $result = $extrafields->delete($attributekey, $elementtype);
460 setEventMessages($langs->trans(
"ExtrafieldsDeleted", $attributekey),
null,
'mesgs');
462 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
465 $mesg = $extrafields->error;
466 $mesgs = array_merge($mesgs, $extrafields->errors);
470 $langs->load(
"errors");
471 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
476if ($action ==
'encrypt') {
478 $extrafields->fetch_name_optionals_label($elementtype);
479 $attributekey =
GETPOST(
'attrname',
'aZ09');
481 if (!empty($extrafields->attributes[$elementtype][
'type'][$attributekey]) && $extrafields->attributes[$elementtype][
'type'][$attributekey] ==
'password') {
482 if (!empty($extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
483 if (array_key_exists(
'dolcrypt', $extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
486 if (!empty($arrayofelement[
'table_element'])) {
487 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] == $conf->entity || empty($extrafields->attributes[$elementtype][
'entityid'][$attributekey])) {
488 dol_syslog(
"Loop on each extafields of table ".$arrayofelement[
'table_element']);
490 $sql =
"SELECT te.rowid, te.".$attributekey;
491 $sql .=
" FROM ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
" as t, ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields as te';
492 $sql .=
" WHERE te.fk_object = t.rowid";
493 $sql .=
" AND te.".$attributekey.
" NOT LIKE 'dolcrypt:%'";
494 $sql .=
" AND te.".$attributekey.
" IS NOT NULL";
495 $sql .=
" AND te.".$attributekey.
" <> ''";
496 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] == $conf->entity) {
497 $sql .=
" AND t.entity = ".getEntity($arrayofelement[
'element'], 0);
502 $resql = $db->query($sql);
504 $num_rows = $db->num_rows($resql);
506 while ($i < $num_rows) {
507 $objtmp = $db->fetch_object($resql);
508 $id = $objtmp->rowid;
509 $pass = $objtmp->$attributekey;
513 $sqlupdate =
"UPDATE ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields';
514 $sqlupdate .=
" SET ".$attributekey.
" = '".$db->escape($newpassword).
"'";
515 $sqlupdate .=
" WHERE rowid = ".((int)
$id);
517 $resupdate = $db->query($sqlupdate);
531 if ($nbupdatedone > 0) {
532 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'mesgs');
534 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.
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.