43$extrasize =
GETPOST(
'size',
'intcomma');
44$type =
GETPOST(
'type',
'alphanohtml');
45$param =
GETPOST(
'param',
'alphanohtml');
46$css =
GETPOST(
'css',
'alphanohtml');
47$cssview =
GETPOST(
'cssview',
'alphanohtml');
48$csslist =
GETPOST(
'csslist',
'alphanohtml');
49$confirm =
GETPOST(
'confirm',
'alpha');
51if ($type ==
'double' && strpos($extrasize,
',') ===
false) {
57if ($type ==
'datetime') {
60if ($type ==
'select') {
64$listofreservedwords = array(
65 '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',
66 'CURSOR',
'DATABASE',
'DATABASES',
'DAY_HOUR',
'DAY_MICROSECOND',
'DAY_MINUTE',
'DAY_SECOND',
'DECIMAL',
'DECLARE',
'DEFAULT',
'DELAYED',
'DELETE',
'DESC',
'DESCRIBE',
'DETERMINISTIC',
'DISTINCT',
'DISTINCTROW',
'DOUBLE',
'DROP',
'DUAL',
67 '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',
68 'IGNORE',
'IGNORE_SERVER_IDS',
'INDEX',
'INFILE',
'INNER',
'INOUT',
'INSENSITIVE',
'INSERT',
'INT',
'INTEGER',
'INTERVAL',
'INTO',
'ITERATE',
69 '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',
70 'OFFSET',
'ON',
'OPTION',
'OPTIONALLY',
'OUTER',
'OUTFILE',
71 'PARTITION',
'POSITION',
'PRECISION',
'PRIMARY',
'PROCEDURE',
'PURGE',
'RANGE',
'READS',
'READ_WRITE',
'REAL',
'REFERENCES',
'REGEXP',
'RELEASE',
'RENAME',
'REPEAT',
'REQUIRE',
'RESTRICT',
'RETURN',
'REVOKE',
'RIGHT',
'RLIKE',
72 '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',
73 'TABLE',
'TERMINATED',
'TINYBLOB',
'TINYINT',
'TINYTEXT',
'TRAILING',
'TRIGGER',
'UNDO',
'UNIQUE',
'UNSIGNED',
'UPDATE',
'USAGE',
'USING',
'UTC_DATE',
'UTC_TIME',
'UTC_TIMESTAMP',
'VALUES',
'VARBINARY',
'VARCHAR',
'VARYING',
74 'WHEN',
'WHERE',
'WHILE',
'WRITE',
'XOR',
'YEAR_MONTH',
'ZEROFILL'
78if ($action ==
'add') {
79 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
83 $langs->load(
"errors");
84 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
87 if ($type ==
'varchar' && $extrasize <= 0) {
89 $langs->load(
"errors");
90 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
93 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
95 $langs->load(
"errors");
96 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
99 if ($type ==
'int' && $extrasize > $maxsizeint) {
101 $langs->load(
"errors");
102 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
105 if ($type ==
'stars' && ($extrasize < 1 || $extrasize > 10)) {
107 $langs->load(
"errors");
108 $mesgs[] = $langs->trans(
"ErrorSizeForStarsType");
111 if ($type ==
'select' && !$param) {
113 $langs->load(
"errors");
114 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectType");
117 if ($type ==
'sellist' && !$param) {
119 $langs->load(
"errors");
120 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectListType");
123 if ($type ==
'checkbox' && !$param) {
125 $langs->load(
"errors");
126 $mesgs[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
129 if ($type ==
'link' && !$param) {
131 $langs->load(
"errors");
132 $mesgs[] = $langs->trans(
"ErrorNoValueForLinkType");
135 if ($type ==
'radio' && !$param) {
137 $langs->load(
"errors");
138 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
141 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
143 $parameters = $param;
144 $parameters_array = explode(
"\r\n", $parameters);
145 foreach ($parameters_array as $param_ligne) {
146 if (!empty($param_ligne)) {
147 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
148 if (count($matches[0]) > 1) {
150 $langs->load(
"errors");
151 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
156 $langs->load(
"errors");
157 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
165 if (strlen(
GETPOST(
'attrname',
'aZ09')) < 3) {
167 $langs->load(
"errors");
168 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
175 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords)) {
177 $langs->load(
"errors");
178 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
185 if (GETPOSTISSET(
"attrname") && preg_match(
"/^[a-z0-9_]+$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
187 $default_value =
GETPOST(
'default_value',
'alpha');
188 $parameters = $param;
189 $parameters_array = explode(
"\r\n", $parameters);
192 if ($type ==
'sellist' || $type ==
'chkbxlst') {
193 foreach ($parameters_array as $param_ligne) {
194 $params[
'options'] = array($parameters =>
null);
198 foreach ($parameters_array as $param_ligne) {
199 if (strpos($param_ligne,
',') !==
false) {
200 list($key, $value) = explode(
',', $param_ligne);
201 if (!array_key_exists(
'options', $params)) {
202 $params[
'options'] = array();
208 $params[
'options'][$key] = $value;
213 $visibility =
GETPOST(
'list',
'alpha');
214 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
218 $result = $extrafields->addExtraField(
225 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
226 (
GETPOST(
'required',
'alpha') ? 1 : 0),
229 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
233 GETPOST(
'computed_value',
'alpha'),
234 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
237 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
239 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
243 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
247 $mesg = $extrafields->error;
248 $mesgs = array_merge($mesgs, $extrafields->errors);
253 $langs->load(
"errors");
254 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities(
"AttributeCode"));
265if ($action ==
'update') {
266 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
270 $langs->load(
"errors");
271 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
274 if ($type ==
'varchar' && $extrasize <= 0) {
276 $langs->load(
"errors");
277 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
280 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
282 $langs->load(
"errors");
283 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
286 if ($type ==
'int' && $extrasize > $maxsizeint) {
288 $langs->load(
"errors");
289 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
292 if ($type ==
'select' && !$param) {
294 $langs->load(
"errors");
295 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectType");
298 if ($type ==
'sellist' && !$param) {
300 $langs->load(
"errors");
301 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectListType");
304 if ($type ==
'stars' && ($extrasize < 1|| $extrasize > 10)) {
306 $langs->load(
"errors");
307 $mesgs[] = $langs->trans(
"ErrorSizeForStarsType");
310 if ($type ==
'checkbox' && !$param) {
312 $langs->load(
"errors");
313 $mesgs[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
316 if ($type ==
'radio' && !$param) {
318 $langs->load(
"errors");
319 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
322 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
324 $parameters = $param;
325 $parameters_array = explode(
"\r\n", $parameters);
326 foreach ($parameters_array as $param_ligne) {
327 if (!empty($param_ligne)) {
328 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
329 if (count($matches[0]) > 1) {
331 $langs->load(
"errors");
332 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
337 $langs->load(
"errors");
338 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
348 $langs->load(
"errors");
349 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
356 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords) && !
getDolGlobalString(
'MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE')) {
358 $langs->load(
"errors");
359 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
365 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
368 $parameters = $param;
369 $parameters_array = explode(
"\r\n", $parameters);
372 if ($type ==
'sellist' || $type ==
'chkbxlst') {
373 foreach ($parameters_array as $param_ligne) {
374 $params[
'options'] = array($parameters =>
null);
378 foreach ($parameters_array as $param_ligne) {
379 $tmp = explode(
',', $param_ligne);
381 if (!empty($tmp[1])) {
384 if (!array_key_exists(
'options', $params)) {
385 $params[
'options'] = array();
387 $params[
'options'][$key] = $value;
394 $visibility =
GETPOST(
'list',
'alpha');
395 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
400 $computedvalue =
GETPOST(
'computed_value',
'nohtml');
402 $result = $extrafields->update(
408 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
409 (
GETPOST(
'required',
'alpha') ? 1 : 0),
412 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
416 GETPOST(
'default_value',
'alpha'),
418 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
421 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
423 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
427 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
431 $mesg = $extrafields->error;
432 $mesgs = array_merge($mesgs, $extrafields->errors);
437 $langs->load(
"errors");
438 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
448if ($action ==
'confirm_delete' && $confirm ==
"yes") {
449 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
"attrname",
'aZ09'))) {
450 $attributekey =
GETPOST(
'attrname',
'aZ09');
452 $result = $extrafields->delete($attributekey, $elementtype);
454 setEventMessages($langs->trans(
"ExtrafieldsDeleted", $attributekey),
null,
'mesgs');
456 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
459 $mesg = $extrafields->error;
460 $mesgs = array_merge($mesgs, $extrafields->errors);
464 $langs->load(
"errors");
465 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
470if ($action ==
'encrypt') {
472 $extrafields->fetch_name_optionals_label($elementtype);
473 $attributekey =
GETPOST(
'attrname',
'aZ09');
475 if (!empty($extrafields->attributes[$elementtype][
'type'][$attributekey]) && $extrafields->attributes[$elementtype][
'type'][$attributekey] ==
'password') {
476 if (!empty($extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
477 if (array_key_exists(
'dolcrypt', $extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
480 if (!empty($arrayofelement[
'table_element'])) {
481 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] ==
$conf->entity || empty($extrafields->attributes[$elementtype][
'entityid'][$attributekey])) {
482 dol_syslog(
"Loop on each extafields of table ".$arrayofelement[
'table_element']);
484 $sql =
"SELECT te.rowid, te.".$attributekey;
485 $sql .=
" FROM ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
" as t, ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields as te';
486 $sql .=
" WHERE te.fk_object = t.rowid";
487 $sql .=
" AND te.".$attributekey.
" NOT LIKE 'dolcrypt:%'";
488 $sql .=
" AND te.".$attributekey.
" IS NOT NULL";
489 $sql .=
" AND te.".$attributekey.
" <> ''";
490 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] ==
$conf->entity) {
491 $sql .=
" AND t.entity = ".getEntity($arrayofelement[
'table_element'], 0);
496 $resql = $db->query($sql);
498 $num_rows = $db->num_rows($resql);
500 while ($i < $num_rows) {
501 $objtmp = $db->fetch_object($resql);
502 $id = $objtmp->rowid;
503 $pass = $objtmp->$attributekey;
507 $sqlupdate =
"UPDATE ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields';
508 $sqlupdate .=
" SET ".$attributekey.
" = '".$db->escape($newpassword).
"'";
509 $sqlupdate .=
" WHERE rowid = ".((int)
$id);
511 $resupdate = $db->query($sqlupdate);
525 if ($nbupdatedone > 0) {
526 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'mesgs');
528 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'warnings');
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.
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.