30$extrasize =
GETPOST(
'size',
'intcomma');
31$type =
GETPOST(
'type',
'alphanohtml');
32$param =
GETPOST(
'param',
'alphanohtml');
33$css =
GETPOST(
'css',
'alphanohtml');
34$cssview =
GETPOST(
'cssview',
'alphanohtml');
35$csslist =
GETPOST(
'csslist',
'alphanohtml');
36$confirm =
GETPOST(
'confirm',
'alpha');
38if ($type ==
'double' && strpos($extrasize,
',') ===
false) {
44if ($type ==
'datetime') {
47if ($type ==
'select') {
51$listofreservedwords = array(
52 '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',
53 'CURSOR',
'DATABASE',
'DATABASES',
'DAY_HOUR',
'DAY_MICROSECOND',
'DAY_MINUTE',
'DAY_SECOND',
'DECIMAL',
'DECLARE',
'DEFAULT',
'DELAYED',
'DELETE',
'DESC',
'DESCRIBE',
'DETERMINISTIC',
'DISTINCT',
'DISTINCTROW',
'DOUBLE',
'DROP',
'DUAL',
54 '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',
55 'IGNORE',
'IGNORE_SERVER_IDS',
'INDEX',
'INFILE',
'INNER',
'INOUT',
'INSENSITIVE',
'INSERT',
'INT',
'INTEGER',
'INTERVAL',
'INTO',
'ITERATE',
56 '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',
57 'OFFSET',
'ON',
'OPTION',
'OPTIONALLY',
'OUTER',
'OUTFILE',
58 'PARTITION',
'POSITION',
'PRECISION',
'PRIMARY',
'PROCEDURE',
'PURGE',
'RANGE',
'READS',
'READ_WRITE',
'REAL',
'REFERENCES',
'REGEXP',
'RELEASE',
'RENAME',
'REPEAT',
'REQUIRE',
'RESTRICT',
'RETURN',
'REVOKE',
'RIGHT',
'RLIKE',
59 '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',
60 'TABLE',
'TERMINATED',
'TINYBLOB',
'TINYINT',
'TINYTEXT',
'TRAILING',
'TRIGGER',
'UNDO',
'UNIQUE',
'UNSIGNED',
'UPDATE',
'USAGE',
'USING',
'UTC_DATE',
'UTC_TIME',
'UTC_TIMESTAMP',
'VALUES',
'VARBINARY',
'VARCHAR',
'VARYING',
61 'WHEN',
'WHERE',
'WHILE',
'WRITE',
'XOR',
'YEAR_MONTH',
'ZEROFILL'
65if ($action ==
'add') {
66 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
70 $langs->load(
"errors");
71 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
74 if ($type ==
'varchar' && $extrasize <= 0) {
76 $langs->load(
"errors");
77 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
80 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
82 $langs->load(
"errors");
83 $mesg[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
86 if ($type ==
'int' && $extrasize > $maxsizeint) {
88 $langs->load(
"errors");
89 $mesg[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
92 if ($type ==
'select' && !$param) {
94 $langs->load(
"errors");
95 $mesg[] = $langs->trans(
"ErrorNoValueForSelectType");
98 if ($type ==
'sellist' && !$param) {
100 $langs->load(
"errors");
101 $mesg[] = $langs->trans(
"ErrorNoValueForSelectListType");
104 if ($type ==
'checkbox' && !$param) {
106 $langs->load(
"errors");
107 $mesg[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
110 if ($type ==
'link' && !$param) {
112 $langs->load(
"errors");
113 $mesg[] = $langs->trans(
"ErrorNoValueForLinkType");
116 if ($type ==
'radio' && !$param) {
118 $langs->load(
"errors");
119 $mesg[] = $langs->trans(
"ErrorNoValueForRadioType");
122 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
124 $parameters = $param;
125 $parameters_array = explode(
"\r\n", $parameters);
126 foreach ($parameters_array as $param_ligne) {
127 if (!empty($param_ligne)) {
128 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
129 if (count($matches[0]) > 1) {
131 $langs->load(
"errors");
132 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
137 $langs->load(
"errors");
138 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
146 if (strlen(
GETPOST(
'attrname',
'aZ09')) < 3) {
148 $langs->load(
"errors");
149 $mesg[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
156 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords)) {
158 $langs->load(
"errors");
159 $mesg[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
166 if (GETPOSTISSET(
"attrname") && preg_match(
"/^[a-z0-9_]+$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
168 $default_value =
GETPOST(
'default_value',
'alpha');
169 $parameters = $param;
170 $parameters_array = explode(
"\r\n", $parameters);
173 if ($type ==
'sellist' || $type ==
'chkbxlst') {
174 foreach ($parameters_array as $param_ligne) {
175 $params[
'options'] = array($parameters =>
null);
179 foreach ($parameters_array as $param_ligne) {
180 if (strpos($param_ligne,
',') !==
false) {
181 list($key, $value) = explode(
',', $param_ligne);
182 if (!array_key_exists(
'options', $params)) {
183 $params[
'options'] = array();
189 $params[
'options'][$key] = $value;
194 $visibility =
GETPOST(
'list',
'alpha');
195 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
199 $result = $extrafields->addExtraField(
206 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
207 (
GETPOST(
'required',
'alpha') ? 1 : 0),
210 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
214 GETPOST(
'computed_value',
'alpha'),
215 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
218 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
220 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
224 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
228 $mesg = $extrafields->error;
233 $langs->load(
"errors");
234 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities(
"AttributeCode"));
245if ($action ==
'update') {
246 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
250 $langs->load(
"errors");
251 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
254 if ($type ==
'varchar' && $extrasize <= 0) {
256 $langs->load(
"errors");
257 $mesg[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
260 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
262 $langs->load(
"errors");
263 $mesg[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
266 if ($type ==
'int' && $extrasize > $maxsizeint) {
268 $langs->load(
"errors");
269 $mesg[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
272 if ($type ==
'select' && !$param) {
274 $langs->load(
"errors");
275 $mesg[] = $langs->trans(
"ErrorNoValueForSelectType");
278 if ($type ==
'sellist' && !$param) {
280 $langs->load(
"errors");
281 $mesg[] = $langs->trans(
"ErrorNoValueForSelectListType");
284 if ($type ==
'checkbox' && !$param) {
286 $langs->load(
"errors");
287 $mesg[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
290 if ($type ==
'radio' && !$param) {
292 $langs->load(
"errors");
293 $mesg[] = $langs->trans(
"ErrorNoValueForRadioType");
296 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
298 $parameters = $param;
299 $parameters_array = explode(
"\r\n", $parameters);
300 foreach ($parameters_array as $param_ligne) {
301 if (!empty($param_ligne)) {
302 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
303 if (count($matches[0]) > 1) {
305 $langs->load(
"errors");
306 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
311 $langs->load(
"errors");
312 $mesg[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
322 $langs->load(
"errors");
323 $mesg[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
330 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords) && !
getDolGlobalString(
'MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE')) {
332 $langs->load(
"errors");
333 $mesg[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
339 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
342 $parameters = $param;
343 $parameters_array = explode(
"\r\n", $parameters);
346 if ($type ==
'sellist' || $type ==
'chkbxlst') {
347 foreach ($parameters_array as $param_ligne) {
348 $params[
'options'] = array($parameters =>
null);
352 foreach ($parameters_array as $param_ligne) {
353 $tmp = explode(
',', $param_ligne);
355 if (!empty($tmp[1])) {
358 if (!array_key_exists(
'options', $params)) {
359 $params[
'options'] = array();
361 $params[
'options'][$key] = $value;
368 $visibility =
GETPOST(
'list',
'alpha');
369 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
374 $computedvalue =
GETPOST(
'computed_value',
'nohtml');
376 $result = $extrafields->update(
382 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
383 (
GETPOST(
'required',
'alpha') ? 1 : 0),
386 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
390 GETPOST(
'default_value',
'alpha'),
392 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
395 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
397 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
401 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
405 $mesg = $extrafields->error;
410 $langs->load(
"errors");
411 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
421if ($action ==
'confirm_delete' && $confirm ==
"yes") {
422 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
"attrname",
'aZ09'))) {
423 $attributekey =
GETPOST(
'attrname',
'aZ09');
425 $result = $extrafields->delete($attributekey, $elementtype);
427 setEventMessages($langs->trans(
"ExtrafieldsDeleted", $attributekey),
null,
'mesgs');
429 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
432 $mesg = $extrafields->error;
436 $langs->load(
"errors");
437 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
442if ($action ==
'encrypt') {
444 $extrafields->fetch_name_optionals_label($elementtype);
445 $attributekey =
GETPOST(
'attrname',
'aZ09');
447 if (!empty($extrafields->attributes[$elementtype][
'type'][$attributekey]) && $extrafields->attributes[$elementtype][
'type'][$attributekey] ==
'password') {
448 if (!empty($extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
449 if (array_key_exists(
'dolcrypt', $extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
452 if (!empty($arrayofelement[
'table_element'])) {
453 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] == $conf->entity || empty($extrafields->attributes[$elementtype][
'entityid'][$attributekey])) {
454 dol_syslog(
"Loop on each extafields of table ".$arrayofelement[
'table_element']);
456 $sql =
"SELECT te.rowid, te.".$attributekey;
457 $sql .=
" FROM ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
" as t, ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields as te';
458 $sql .=
" WHERE te.fk_object = t.rowid";
459 $sql .=
" AND te.".$attributekey.
" NOT LIKE 'dolcrypt:%'";
460 $sql .=
" AND te.".$attributekey.
" IS NOT NULL";
461 $sql .=
" AND te.".$attributekey.
" <> ''";
462 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] == $conf->entity) {
463 $sql .=
" AND t.entity = ".getEntity($arrayofelement[
'table_element'], 0);
468 $resql = $db->query($sql);
470 $num_rows = $db->num_rows($resql);
472 while ($i < $num_rows) {
473 $objtmp = $db->fetch_object($resql);
474 $id = $objtmp->rowid;
475 $pass = $objtmp->$attributekey;
479 $sqlupdate =
"UPDATE ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields';
480 $sqlupdate .=
" SET ".$attributekey.
" = '".$db->escape($newpassword).
"'";
481 $sqlupdate .=
" WHERE rowid = ".((int) $id);
483 $resupdate = $db->query($sqlupdate);
497 if ($nbupdatedone > 0) {
498 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'mesgs');
500 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'warnings');
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return 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='AES-256-CTR', $forceseed='')
Encode a string with a symmetric encryption.