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') {
65$listofreservedwords = array(
66 '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',
67 'CURSOR',
'DATABASE',
'DATABASES',
'DAY_HOUR',
'DAY_MICROSECOND',
'DAY_MINUTE',
'DAY_SECOND',
'DECIMAL',
'DECLARE',
'DEFAULT',
'DELAYED',
'DELETE',
'DESC',
'DESCRIBE',
'DETERMINISTIC',
'DISTINCT',
'DISTINCTROW',
'DOUBLE',
'DROP',
'DUAL',
68 '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',
69 'IGNORE',
'IGNORE_SERVER_IDS',
'INDEX',
'INFILE',
'INNER',
'INOUT',
'INSENSITIVE',
'INSERT',
'INT',
'INTEGER',
'INTERVAL',
'INTO',
'ITERATE',
70 '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',
71 'OFFSET',
'ON',
'OPTION',
'OPTIONALLY',
'OUTER',
'OUTFILE',
'OVER',
72 'PARTITION',
'POSITION',
'PRECISION',
'PRIMARY',
'PROCEDURE',
'PURGE',
'RANGE',
'READS',
'READ_WRITE',
'REAL',
'REFERENCES',
'REGEXP',
'RELEASE',
'RENAME',
'REPEAT',
'REQUIRE',
'RESTRICT',
'RETURN',
'REVOKE',
'RIGHT',
'RLIKE',
73 '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',
74 'TABLE',
'TERMINATED',
'TINYBLOB',
'TINYINT',
'TINYTEXT',
'TRAILING',
'TRIGGER',
'UNDO',
'UNIQUE',
'UNSIGNED',
'UPDATE',
'USAGE',
'USING',
'UTC_DATE',
'UTC_TIME',
'UTC_TIMESTAMP',
'VALUES',
'VARBINARY',
'VARCHAR',
'VARYING',
75 'WHEN',
'WHERE',
'WHILE',
'WRITE',
'XOR',
'YEAR_MONTH',
'ZEROFILL'
79if ($action ==
'add') {
80 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
84 $langs->load(
"errors");
85 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
88 if ($type ==
'varchar' && $extrasize <= 0) {
90 $langs->load(
"errors");
91 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
94 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
96 $langs->load(
"errors");
97 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
100 if ($type ==
'int' && $extrasize > $maxsizeint) {
102 $langs->load(
"errors");
103 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
106 if ($type ==
'stars' && ($extrasize < 1 || $extrasize > 10)) {
108 $langs->load(
"errors");
109 $mesgs[] = $langs->trans(
"ErrorSizeForStarsType");
112 if ($type ==
'select' && !$param) {
114 $langs->load(
"errors");
115 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectType");
118 if ($type ==
'sellist' && !$param) {
120 $langs->load(
"errors");
121 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectListType");
124 if ($type ==
'checkbox' && !$param) {
126 $langs->load(
"errors");
127 $mesgs[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
130 if ($type ==
'link' && !$param) {
132 $langs->load(
"errors");
133 $mesgs[] = $langs->trans(
"ErrorNoValueForLinkType");
136 if ($type ==
'radio' && !$param) {
138 $langs->load(
"errors");
139 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
142 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
144 $parameters = $param;
145 $parameters_array = explode(
"\r\n", $parameters);
146 foreach ($parameters_array as $param_ligne) {
147 if (!empty($param_ligne)) {
148 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
149 if (count($matches[0]) > 1) {
151 $langs->load(
"errors");
152 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
157 $langs->load(
"errors");
158 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
166 if (strlen(
GETPOST(
'attrname',
'aZ09')) < 3) {
168 $langs->load(
"errors");
169 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
176 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords)) {
178 $langs->load(
"errors");
179 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
186 if (GETPOSTISSET(
"attrname") && preg_match(
"/^[a-z0-9_]+$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
188 $default_value =
GETPOST(
'default_value',
'alpha');
189 $parameters = $param;
190 $parameters_array = explode(
"\r\n", $parameters);
193 if ($type ==
'sellist' || $type ==
'chkbxlst') {
194 foreach ($parameters_array as $param_ligne) {
195 $params[
'options'] = array($parameters =>
null);
199 foreach ($parameters_array as $param_ligne) {
200 if (strpos($param_ligne,
',') !==
false) {
201 list($key, $value) = explode(
',', $param_ligne);
202 if (!array_key_exists(
'options', $params)) {
203 $params[
'options'] = array();
209 $params[
'options'][$key] = $value;
214 $visibility =
GETPOST(
'list',
'alpha');
215 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
219 $result = $extrafields->addExtraField(
226 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
227 (
GETPOST(
'required',
'alpha') ? 1 : 0),
230 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
234 GETPOST(
'computed_value',
'alpha'),
235 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
238 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
240 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
244 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
248 $mesg = $extrafields->error;
249 $mesgs = array_merge($mesgs, $extrafields->errors);
254 $langs->load(
"errors");
255 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities(
"AttributeCode"));
266if ($action ==
'update') {
267 if (
GETPOST(
"button") != $langs->trans(
"Cancel")) {
271 $langs->load(
"errors");
272 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type"));
275 if ($type ==
'varchar' && $extrasize <= 0) {
277 $langs->load(
"errors");
278 $mesgs[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"));
281 if ($type ==
'varchar' && $extrasize > $maxsizestring) {
283 $langs->load(
"errors");
284 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForVarcharType", $maxsizestring);
287 if ($type ==
'int' && $extrasize > $maxsizeint) {
289 $langs->load(
"errors");
290 $mesgs[] = $langs->trans(
"ErrorSizeTooLongForIntType", $maxsizeint);
293 if ($type ==
'select' && !$param) {
295 $langs->load(
"errors");
296 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectType");
299 if ($type ==
'sellist' && !$param) {
301 $langs->load(
"errors");
302 $mesgs[] = $langs->trans(
"ErrorNoValueForSelectListType");
305 if ($type ==
'stars' && ($extrasize < 1|| $extrasize > 10)) {
307 $langs->load(
"errors");
308 $mesgs[] = $langs->trans(
"ErrorSizeForStarsType");
311 if ($type ==
'checkbox' && !$param) {
313 $langs->load(
"errors");
314 $mesgs[] = $langs->trans(
"ErrorNoValueForCheckBoxType");
317 if ($type ==
'radio' && !$param) {
319 $langs->load(
"errors");
320 $mesgs[] = $langs->trans(
"ErrorNoValueForRadioType");
323 if ((($type ==
'radio') || ($type ==
'checkbox')) && $param) {
325 $parameters = $param;
326 $parameters_array = explode(
"\r\n", $parameters);
327 foreach ($parameters_array as $param_ligne) {
328 if (!empty($param_ligne)) {
329 if (preg_match_all(
'/,/', $param_ligne, $matches)) {
330 if (count($matches[0]) > 1) {
332 $langs->load(
"errors");
333 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
338 $langs->load(
"errors");
339 $mesgs[] = $langs->trans(
"ErrorBadFormatValueList", $param_ligne);
349 $langs->load(
"errors");
350 $mesgs[] = $langs->trans(
"ErrorValueLength", $langs->transnoentitiesnoconv(
"AttributeCode"), 3);
357 if (in_array(strtoupper(
GETPOST(
'attrname',
'aZ09')), $listofreservedwords) && !
getDolGlobalString(
'MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE')) {
359 $langs->load(
"errors");
360 $mesgs[] = $langs->trans(
"ErrorReservedKeyword",
GETPOST(
'attrname',
'aZ09'));
366 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
'attrname',
'aZ09')) && !is_numeric(
GETPOST(
'attrname',
'aZ09'))) {
369 $parameters = $param;
370 $parameters_array = explode(
"\r\n", $parameters);
373 if ($type ==
'sellist' || $type ==
'chkbxlst') {
374 foreach ($parameters_array as $param_ligne) {
375 $params[
'options'] = array($parameters =>
null);
379 foreach ($parameters_array as $param_ligne) {
380 $tmp = explode(
',', $param_ligne);
382 if (!empty($tmp[1])) {
385 if (!array_key_exists(
'options', $params)) {
386 $params[
'options'] = array();
388 $params[
'options'][$key] = $value;
395 $visibility =
GETPOST(
'list',
'alpha');
396 if (in_array($type, [
'separate',
'point',
'linestrg',
'polygon'])) {
401 $computedvalue =
GETPOST(
'computed_value',
'nohtml');
403 $result = $extrafields->update(
409 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
410 (
GETPOST(
'required',
'alpha') ? 1 : 0),
413 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
417 GETPOST(
'default_value',
'alpha'),
419 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
422 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
424 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
428 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
432 $mesg = $extrafields->error;
433 $mesgs = array_merge($mesgs, $extrafields->errors);
438 $langs->load(
"errors");
439 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
449if ($action ==
'confirm_delete' && $confirm ==
"yes") {
450 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
"attrname",
'aZ09'))) {
451 $attributekey =
GETPOST(
'attrname',
'aZ09');
453 $result = $extrafields->delete($attributekey, $elementtype);
455 setEventMessages($langs->trans(
"ExtrafieldsDeleted", $attributekey),
null,
'mesgs');
457 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
460 $mesg = $extrafields->error;
461 $mesgs = array_merge($mesgs, $extrafields->errors);
465 $langs->load(
"errors");
466 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
471if ($action ==
'encrypt') {
473 $extrafields->fetch_name_optionals_label($elementtype);
474 $attributekey =
GETPOST(
'attrname',
'aZ09');
476 if (!empty($extrafields->attributes[$elementtype][
'type'][$attributekey]) && $extrafields->attributes[$elementtype][
'type'][$attributekey] ==
'password') {
477 if (!empty($extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
478 if (array_key_exists(
'dolcrypt', $extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
481 if (!empty($arrayofelement[
'table_element'])) {
482 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] ==
$conf->entity || empty($extrafields->attributes[$elementtype][
'entityid'][$attributekey])) {
483 dol_syslog(
"Loop on each extafields of table ".$arrayofelement[
'table_element']);
485 $sql =
"SELECT te.rowid, te.".$attributekey;
486 $sql .=
" FROM ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
" as t, ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields as te';
487 $sql .=
" WHERE te.fk_object = t.rowid";
488 $sql .=
" AND te.".$attributekey.
" NOT LIKE 'dolcrypt:%'";
489 $sql .=
" AND te.".$attributekey.
" IS NOT NULL";
490 $sql .=
" AND te.".$attributekey.
" <> ''";
491 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] ==
$conf->entity) {
492 $sql .=
" AND t.entity = ".getEntity($arrayofelement[
'table_element'], 0);
497 $resql = $db->query($sql);
499 $num_rows = $db->num_rows($resql);
501 while ($i < $num_rows) {
502 $objtmp = $db->fetch_object($resql);
503 $id = $objtmp->rowid;
504 $pass = $objtmp->$attributekey;
508 $sqlupdate =
"UPDATE ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields';
509 $sqlupdate .=
" SET ".$attributekey.
" = '".$db->escape($newpassword).
"'";
510 $sqlupdate .=
" WHERE rowid = ".((int)
$id);
512 $resupdate = $db->query($sqlupdate);
526 if ($nbupdatedone > 0) {
527 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'mesgs');
529 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.