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),
254 (
GETPOST(
'emptyonclone',
'alpha') ? 1 : 0)
258 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
262 $mesg = $extrafields->error;
263 $mesgs = array_merge($mesgs, $extrafields->errors);
268 $langs->load(
"errors");
269 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities(
"AttributeCode"));
280if ($action ==
'update') {
281 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
285 $langs->load(
"errors");
286 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
289 if ($type ==
'varchar' && $extrasize <= 0) {
291 $langs->load(
"errors");
292 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
295 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
297 $langs->load(
"errors");
298 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
301 if ($type ==
'int' && $extrasize > $maxsizeint) {
303 $langs->load(
"errors");
304 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
307 if ($type ==
'select' && !$param) {
309 $langs->load(
"errors");
310 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectType");
313 if ($type ==
'sellist' && !$param) {
315 $langs->load(
"errors");
316 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectListType");
319 if ($type ==
'stars' && ($extrasize < 1 || $extrasize > 10)) {
321 $langs->load(
"errors");
322 $mesgs[] = $langs->trans(
"ErrorSizeForStarsType");
325 if ($type ==
'checkbox' && !$param) {
327 $langs->load(
"errors");
328 $mesgs[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
331 if ($type ==
'radio' && !$param) {
333 $langs->load(
"errors");
334 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
337 if ($type ==
'link' && $param) {
340 $tmplink = explode(
':', $param);
341 if (empty($tmplink[1]) || !file_exists(
dol_buildpath($tmplink[1]))) {
343 $langs->load(
"errors");
344 $mesgs[] = $langs->trans(
"ErrorFileNotFound", empty($tmplink[1]) ? $param : $tmplink[1]);
348 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
350 $parameters = $param;
351 $parameters_array = explode(
"\r\n", $parameters);
352 foreach ($parameters_array as $param_ligne) {
353 if (!empty($param_ligne)) {
354 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
355 if (count($matches[0]) > 1) {
357 $langs->load(
"errors");
358 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
363 $langs->load(
"errors");
364 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
374 $langs->load(
"errors");
375 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
382 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords) && !
getDolGlobalString(
'MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE')) {
384 $langs->load(
"errors");
385 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
391 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
394 $parameters = $param;
395 $parameters_array = explode(
"\r\n", $parameters);
398 if ($type ==
'sellist' || $type ==
'chkbxlst') {
399 foreach ($parameters_array as $param_ligne) {
400 $params[
'options'] = array($parameters =>
null);
404 foreach ($parameters_array as $param_ligne) {
405 $tmp = explode(
',', $param_ligne);
407 if (!empty($tmp[1])) {
410 if (!array_key_exists(
'options', $params)) {
411 $params[
'options'] = array();
413 $params[
'options'][$key] = $value;
420 $visibility =
GETPOST(
'list',
'alpha');
421 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
426 $computedvalue =
GETPOST(
'computed_value',
'nohtml');
428 $result = $extrafields->update(
434 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
435 (
GETPOST(
'required',
'alpha') ? 1 : 0),
438 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
442 GETPOST(
'default_value',
'alpha'),
444 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
447 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
449 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist),
451 (
GETPOST(
'emptyonclone',
'alpha') ? 1 : 0)
455 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
459 $mesg = $extrafields->error;
460 $mesgs = array_merge($mesgs, $extrafields->errors);
465 $langs->load(
"errors");
466 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
476if ($action ==
'confirm_delete' && $confirm ==
"yes") {
477 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
"attrname",
'aZ09'))) {
478 $attributekey =
GETPOST(
'attrname',
'aZ09');
480 $result = $extrafields->delete($attributekey, $elementtype);
482 setEventMessages($langs->trans(
"ExtrafieldsDeleted", $attributekey),
null,
'mesgs');
484 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
487 $mesg = $extrafields->error;
488 $mesgs = array_merge($mesgs, $extrafields->errors);
492 $langs->load(
"errors");
493 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
498if ($action ==
'encrypt') {
500 $extrafields->fetch_name_optionals_label($elementtype);
501 $attributekey =
GETPOST(
'attrname',
'aZ09');
503 if (!empty($extrafields->attributes[$elementtype][
'type'][$attributekey]) && $extrafields->attributes[$elementtype][
'type'][$attributekey] ==
'password') {
504 if (!empty($extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
505 if (array_key_exists(
'dolcrypt', $extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
508 if (!empty($arrayofelement[
'table_element'])) {
509 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] == $conf->entity || empty($extrafields->attributes[$elementtype][
'entityid'][$attributekey])) {
510 dol_syslog(
"Loop on each extafields of table ".$arrayofelement[
'table_element']);
512 $sql =
"SELECT te.rowid, te.".$attributekey;
513 $sql .=
" FROM ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
" as t, ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields as te';
514 $sql .=
" WHERE te.fk_object = t.rowid";
515 $sql .=
" AND te.".$attributekey.
" NOT LIKE 'dolcrypt:%'";
516 $sql .=
" AND te.".$attributekey.
" IS NOT NULL";
517 $sql .=
" AND te.".$attributekey.
" <> ''";
518 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] == $conf->entity) {
519 $sql .=
" AND t.entity = ".getEntity($arrayofelement[
'element'], 0);
524 $resql = $db->query($sql);
526 $num_rows = $db->num_rows($resql);
528 while ($i < $num_rows) {
529 $objtmp = $db->fetch_object($resql);
530 $id = $objtmp->rowid;
531 $pass = $objtmp->$attributekey;
535 $sqlupdate =
"UPDATE ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields';
536 $sqlupdate .=
" SET ".$attributekey.
" = '".$db->escape($newpassword).
"'";
537 $sqlupdate .=
" WHERE rowid = ".((int)
$id);
539 $resupdate = $db->query($sqlupdate);
553 if ($nbupdatedone > 0) {
554 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'mesgs');
556 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.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='')
Encode a string with a symmetric encryption.