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 ($type ==
'separate') {
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 list($key, $value) = explode(
',', $param_ligne);
354 if (!array_key_exists(
'options', $params)) {
355 $params[
'options'] = array();
357 $params[
'options'][$key] = $value;
362 $visibility =
GETPOST(
'list',
'alpha');
363 if ($type ==
'separate') {
368 $computedvalue =
GETPOST(
'computed_value',
'nohtml');
370 $result = $extrafields->update(
376 (
GETPOST(
'unique',
'alpha') ? 1 : 0),
377 (
GETPOST(
'required',
'alpha') ? 1 : 0),
380 (
GETPOST(
'alwayseditable',
'alpha') ? 1 : 0),
384 GETPOST(
'default_value',
'alpha'),
386 (
GETPOST(
'entitycurrentorall',
'alpha') ? 0 :
''),
389 (
GETPOST(
'totalizable',
'alpha') ? 1 : 0),
391 array(
'css' => $css,
'cssview' => $cssview,
'csslist' => $csslist)
395 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
399 $mesg = $extrafields->error;
404 $langs->load(
"errors");
405 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
415if ($action ==
'confirm_delete' && $confirm ==
"yes") {
416 if (GETPOSTISSET(
"attrname") && preg_match(
"/^\w[a-zA-Z0-9-_]*$/",
GETPOST(
"attrname",
'aZ09'))) {
417 $attributekey =
GETPOST(
'attrname',
'aZ09');
419 $result = $extrafields->delete($attributekey, $elementtype);
421 setEventMessages($langs->trans(
"ExtrafieldsDeleted", $attributekey),
null,
'mesgs');
423 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
426 $mesg = $extrafields->error;
430 $langs->load(
"errors");
431 $mesg = $langs->trans(
"ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities(
"AttributeCode"));
436if ($action ==
'encrypt') {
438 $extrafields->fetch_name_optionals_label($elementtype);
439 $attributekey =
GETPOST(
'attrname',
'aZ09');
441 if (!empty($extrafields->attributes[$elementtype][
'type'][$attributekey]) && $extrafields->attributes[$elementtype][
'type'][$attributekey] ==
'password') {
442 if (!empty($extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
443 if (array_key_exists(
'dolcrypt', $extrafields->attributes[$elementtype][
'param'][$attributekey][
'options'])) {
446 if (!empty($arrayofelement[
'table_element'])) {
447 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] == $conf->entity || empty($extrafields->attributes[$elementtype][
'entityid'][$attributekey])) {
448 dol_syslog(
"Loop on each extafields of table ".$arrayofelement[
'table_element']);
450 $sql .=
"SELECT te.rowid, te.".$attributekey;
451 $sql .=
" FROM ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
" as t, ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields as te';
452 $sql .=
" WHERE te.fk_object = t.rowid";
453 $sql .=
" AND te.".$attributekey.
" NOT LIKE 'dolcrypt:%'";
454 $sql .=
" AND te.".$attributekey.
" IS NOT NULL";
455 $sql .=
" AND te.".$attributekey.
" <> ''";
456 if ($extrafields->attributes[$elementtype][
'entityid'][$attributekey] == $conf->entity) {
457 $sql .=
" AND t.entity = ".getEntity($arrayofelement[
'table_element'], 0);
462 $resql = $db->query($sql);
464 $num_rows = $db->num_rows($resql);
466 while ($i < $num_rows) {
467 $objtmp = $db->fetch_object($resql);
468 $id = $objtmp->rowid;
469 $pass = $objtmp->$attributekey;
473 $sqlupdate =
"UPDATE ".MAIN_DB_PREFIX.$arrayofelement[
'table_element'].
'_extrafields';
474 $sqlupdate .=
" SET ".$attributekey.
" = '".$db->escape($newpassword).
"'";
475 $sqlupdate .=
" WHERE rowid = ".((int) $id);
477 $resupdate = $db->query($sqlupdate);
491 if ($nbupdatedone > 0) {
492 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'mesgs');
494 setEventMessages($langs->trans(
"PasswordFieldEncrypted", $nbupdatedone),
null,
'warnings');
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.
getElementProperties($element_type)
Get an array with properties of an element.
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 symetric encryption.