dolibarr 24.0.0-beta
actions_extrafields.inc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 *
20 * $elementype must be defined.
21 */
22
39'@phan-var-force int $error';
40'@phan-var-force string $action';
41'@phan-var-force string $elementtype';
42'@phan-var-force string $value';
43
44$maxsizestring = 255;
45$maxsizeint = 10;
46$mesg = '';
47$mesgs = array();
48
49$extrasize = GETPOST('size', 'intcomma');
50$type = GETPOST('type', 'alphanohtml');
51$param = GETPOST('param', 'alphanohtml');
52$css = GETPOST('css', 'alphanohtml');
53$cssview = GETPOST('cssview', 'alphanohtml');
54$csslist = GETPOST('csslist', 'alphanohtml');
55$confirm = GETPOST('confirm', 'alpha');
56
57if ($type == 'double' && strpos($extrasize, ',') === false) {
58 $extrasize = '24,8';
59}
60if ($type == 'date') {
61 $extrasize = '';
62}
63if ($type == 'datetime') {
64 $extrasize = '';
65}
66if ($type == 'select') {
67 $extrasize = '';
68}
69
70// List of reserved words for databases
71$listofreservedwords = array(
72 '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',
73 'CURSOR', 'DATABASE', 'DATABASES', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DECIMAL', 'DECLARE', 'DEFAULT', 'DELAYED', 'DELETE', 'DESC', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCT', 'DISTINCTROW', 'DOUBLE', 'DROP', 'DUAL',
74 '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',
75 'IGNORE', 'IGNORE_SERVER_IDS', 'INDEX', 'INFILE', 'INNER', 'INOUT', 'INSENSITIVE', 'INSERT', 'INT', 'INTEGER', 'INTERVAL', 'INTO', 'ITERATE',
76 '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',
77 'OFFSET', 'ON', 'OPTION', 'OPTIONALLY', 'OUTER', 'OUTFILE', 'OVER',
78 'PARTITION', 'POSITION', 'PRECISION', 'PRIMARY', 'PROCEDURE', 'PURGE', 'RANGE', 'READS', 'READ_WRITE', 'REAL', 'REFERENCES', 'REGEXP', 'RELEASE', 'RENAME', 'REPEAT', 'REQUIRE', 'RESTRICT', 'RETURN', 'REVOKE', 'RIGHT', 'RLIKE',
79 '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',
80 'TABLE', 'TERMINATED', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TRAILING', 'TRIGGER', 'UNDO', 'UNIQUE', 'UNSIGNED', 'UPDATE', 'USAGE', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'VALUES', 'VARBINARY', 'VARCHAR', 'VARYING',
81 'WHEN', 'WHERE', 'WHILE', 'WRITE', 'XOR', 'YEAR_MONTH', 'ZEROFILL'
82);
83
84// Add attribute
85if ($action == 'add') {
86 if (GETPOST("button") != $langs->trans("Cancel")) {
87 // Check values
88 if (!$type) {
89 $error++;
90 $langs->load("errors");
91 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
92 $action = 'create';
93 }
94 if ($type == 'varchar' && $extrasize <= 0) {
95 $error++;
96 $langs->load("errors");
97 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size"));
98 $action = 'edit';
99 }
100 if ($type == 'varchar' && $extrasize > $maxsizestring) {
101 $error++;
102 $langs->load("errors");
103 $mesgs[] = $langs->trans("ErrorSizeTooLongForVarcharType", $maxsizestring);
104 $action = 'create';
105 }
106 if ($type == 'int' && $extrasize > $maxsizeint) {
107 $error++;
108 $langs->load("errors");
109 $mesgs[] = $langs->trans("ErrorSizeTooLongForIntType", $maxsizeint);
110 $action = 'create';
111 }
112 if ($type == 'stars' && ($extrasize < 1 || $extrasize > 10)) {
113 $error++;
114 $langs->load("errors");
115 $mesgs[] = $langs->trans("ErrorSizeForStarsType");
116 $action = 'create';
117 }
118 if ($type == 'select' && !$param) {
119 $error++;
120 $langs->load("errors");
121 $mesgs[] = $langs->trans("ErrorNoValueForSelectType");
122 $action = 'create';
123 }
124 if ($type == 'sellist' && !$param) {
125 $error++;
126 $langs->load("errors");
127 $mesgs[] = $langs->trans("ErrorNoValueForSelectListType");
128 $action = 'create';
129 }
130 if ($type == 'checkbox' && !$param) {
131 $error++;
132 $langs->load("errors");
133 $mesgs[] = $langs->trans("ErrorNoValueForCheckBoxType");
134 $action = 'create';
135 }
136 if ($type == 'link' && !$param) {
137 $error++;
138 $langs->load("errors");
139 $mesgs[] = $langs->trans("ErrorNoValueForLinkType");
140 $action = 'create';
141 }
142 if ($type == 'radio' && !$param) {
143 $error++;
144 $langs->load("errors");
145 $mesgs[] = $langs->trans("ErrorNoValueForRadioType");
146 $action = 'create';
147 }
148 if ((($type == 'radio') || ($type == 'checkbox')) && $param) {
149 // Construct array for parameter (value of select list)
150 $parameters = $param;
151 $parameters_array = explode("\r\n", $parameters);
152 foreach ($parameters_array as $param_ligne) {
153 if (!empty($param_ligne)) {
154 $matches = array();
155 if (preg_match_all('/,/', $param_ligne, $matches)) {
156 if (count($matches[0]) > 1) {
157 $error++;
158 $langs->load("errors");
159 $mesgs[] = $langs->trans("ErrorBadFormatValueList", $param_ligne);
160 $action = 'create';
161 }
162 } else {
163 $error++;
164 $langs->load("errors");
165 $mesgs[] = $langs->trans("ErrorBadFormatValueList", $param_ligne);
166 $action = 'create';
167 }
168 }
169 }
170 }
171
172 if (!$error) {
173 if (strlen(GETPOST('attrname', 'aZ09')) < 3) {
174 $error++;
175 $langs->load("errors");
176 $mesgs[] = $langs->trans("ErrorValueLength", $langs->transnoentitiesnoconv("AttributeCode"), 3);
177 $action = 'create';
178 }
179 }
180
181 // Check reserved keyword with more than 3 characters
182 if (!$error) {
183 if (in_array(strtoupper(GETPOST('attrname', 'aZ09')), $listofreservedwords)) {
184 $error++;
185 $langs->load("errors");
186 $mesgs[] = $langs->trans("ErrorReservedKeyword", GETPOST('attrname', 'aZ09'));
187 $action = 'create';
188 }
189 }
190
191 if (!$error) {
192 // attrname must be alphabetical and lower case only
193 if (GETPOSTISSET("attrname") && preg_match("/^[a-z0-9_]+$/", GETPOST('attrname', 'aZ09')) && !is_numeric(GETPOST('attrname', 'aZ09'))) {
194 // Construct array for parameter (value of select list)
195 $default_value = GETPOST('default_value', 'alpha');
196 $parameters = $param;
197 $parameters_array = explode("\r\n", $parameters);
198 $params = array();
199 //In sellist we have only one line and it can have come to do SQL expression
200 if ($type == 'sellist' || $type == 'chkbxlst') {
201 foreach ($parameters_array as $param_ligne) {
202 $params['options'] = array($parameters => null);
203 }
204 } else {
205 // Else it's separated key/value and coma list
206 foreach ($parameters_array as $param_ligne) {
207 if (strpos($param_ligne, ',') !== false) {
208 list($key, $value) = explode(',', $param_ligne);
209 if (!array_key_exists('options', $params)) {
210 $params['options'] = array();
211 }
212 } else {
213 $key = $param_ligne;
214 $value = null;
215 }
216 $params['options'][$key] = $value;
217 }
218 }
219
220 // Visibility: -1=not visible by default in list, 1=visible, 0=hidden
221 $visibility = GETPOST('list', 'alpha');
222 if (in_array($type, ['separate', 'point', 'linestrg', 'polygon'])) {
223 $visibility = 3;
224 }
225
226 $result = $extrafields->addExtraField(
227 GETPOST('attrname', 'aZ09'),
228 GETPOST('label', 'alpha'),
229 $type,
230 GETPOSTINT('pos'),
231 $extrasize,
232 $elementtype,
233 (GETPOST('unique', 'alpha') ? 1 : 0),
234 (GETPOST('required', 'alpha') ? 1 : 0),
235 $default_value,
236 $params,
237 (GETPOST('alwayseditable', 'alpha') ? 1 : 0),
238 (GETPOST('perms', 'alpha') ? GETPOST('perms', 'alpha') : ''),
239 $visibility,
240 GETPOST('help', 'alpha'),
241 GETPOST('computed_value', 'alpha'),
242 (GETPOST('entitycurrentorall', 'alpha') ? 0 : ''),
243 GETPOST('langfile', 'alpha'),
244 '1',
245 (GETPOST('totalizable', 'alpha') ? 1 : 0),
246 GETPOSTINT('printable'),
247 array('css' => $css, 'cssview' => $cssview, 'csslist' => $csslist),
248 GETPOST("ai_prompt"),
249 (GETPOST('emptyonclone', 'alpha') ? 1 : 0),
250 (GETPOST('showintooltip', 'int') ? 1 : 0),
251 GETPOSTINT('personal_data')
252 );
253 if ($result > 0) {
254 setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
255 header("Location: ".$_SERVER["PHP_SELF"]);
256 exit;
257 } else {
258 $error++;
259 $mesg = $extrafields->error;
260 $mesgs = array_merge($mesgs, $extrafields->errors);
261 setEventMessages($mesg, $mesgs, 'errors');
262 }
263 } else {
264 $error++;
265 $langs->load("errors");
266 $mesg = $langs->trans("ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities("AttributeCode"));
267 setEventMessages($mesg, $mesgs, 'errors');
268 $action = 'create';
269 }
270 } else {
271 setEventMessages($mesg, $mesgs, 'errors');
272 }
273 }
274}
275
276// Rename field
277if ($action == 'update') {
278 if (GETPOST("button") != $langs->trans("Cancel")) {
279 // Check values
280 if (!$type) {
281 $error++;
282 $langs->load("errors");
283 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
284 $action = 'edit';
285 }
286 if ($type == 'varchar' && $extrasize <= 0) {
287 $error++;
288 $langs->load("errors");
289 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size"));
290 $action = 'edit';
291 }
292 if ($type == 'varchar' && $extrasize > $maxsizestring) {
293 $error++;
294 $langs->load("errors");
295 $mesgs[] = $langs->trans("ErrorSizeTooLongForVarcharType", $maxsizestring);
296 $action = 'edit';
297 }
298 if ($type == 'int' && $extrasize > $maxsizeint) {
299 $error++;
300 $langs->load("errors");
301 $mesgs[] = $langs->trans("ErrorSizeTooLongForIntType", $maxsizeint);
302 $action = 'edit';
303 }
304 if ($type == 'select' && !$param) {
305 $error++;
306 $langs->load("errors");
307 $mesgs[] = $langs->trans("ErrorNoValueForSelectType");
308 $action = 'edit';
309 }
310 if ($type == 'sellist' && !$param) {
311 $error++;
312 $langs->load("errors");
313 $mesgs[] = $langs->trans("ErrorNoValueForSelectListType");
314 $action = 'edit';
315 }
316 if ($type == 'stars' && ($extrasize < 1 || $extrasize > 10)) {
317 $error++;
318 $langs->load("errors");
319 $mesgs[] = $langs->trans("ErrorSizeForStarsType");
320 $action = 'edit';
321 }
322 if ($type == 'checkbox' && !$param) {
323 $error++;
324 $langs->load("errors");
325 $mesgs[] = $langs->trans("ErrorNoValueForCheckBoxType");
326 $action = 'edit';
327 }
328 if ($type == 'radio' && !$param) {
329 $error++;
330 $langs->load("errors");
331 $mesgs[] = $langs->trans("ErrorNoValueForRadioType");
332 $action = 'edit';
333 }
334 if ((($type == 'radio') || ($type == 'checkbox')) && $param) {
335 // Construct array for parameter (value of select list)
336 $parameters = $param;
337 $parameters_array = explode("\r\n", $parameters);
338 foreach ($parameters_array as $param_ligne) {
339 if (!empty($param_ligne)) {
340 if (preg_match_all('/,/', $param_ligne, $matches)) {
341 if (count($matches[0]) > 1) {
342 $error++;
343 $langs->load("errors");
344 $mesgs[] = $langs->trans("ErrorBadFormatValueList", $param_ligne);
345 $action = 'edit';
346 }
347 } else {
348 $error++;
349 $langs->load("errors");
350 $mesgs[] = $langs->trans("ErrorBadFormatValueList", $param_ligne);
351 $action = 'edit';
352 }
353 }
354 }
355 }
356
357 if (!$error) {
358 if (strlen(GETPOST('attrname', 'aZ09')) < 3 && !getDolGlobalString('MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE')) {
359 $error++;
360 $langs->load("errors");
361 $mesgs[] = $langs->trans("ErrorValueLength", $langs->transnoentitiesnoconv("AttributeCode"), 3);
362 $action = 'edit';
363 }
364 }
365
366 // Check reserved keyword with more than 3 characters
367 if (!$error) {
368 if (in_array(strtoupper(GETPOST('attrname', 'aZ09')), $listofreservedwords) && !getDolGlobalString('MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE')) {
369 $error++;
370 $langs->load("errors");
371 $mesgs[] = $langs->trans("ErrorReservedKeyword", GETPOST('attrname', 'aZ09'));
372 $action = 'edit';
373 }
374 }
375
376 if (!$error) {
377 if (GETPOSTISSET("attrname") && preg_match("/^\w[a-zA-Z0-9-_]*$/", GETPOST('attrname', 'aZ09')) && !is_numeric(GETPOST('attrname', 'aZ09'))) {
378 $pos = GETPOSTINT('pos');
379 // Construct array for parameter (value of select list)
380 $parameters = $param;
381 $parameters_array = explode("\r\n", $parameters);
382 $params = array();
383 //In sellist we have only one line and it can have come to do SQL expression
384 if ($type == 'sellist' || $type == 'chkbxlst') {
385 foreach ($parameters_array as $param_ligne) {
386 $params['options'] = array($parameters => null);
387 }
388 } else {
389 //Else it's separated key/value and coma list
390 foreach ($parameters_array as $param_ligne) {
391 $tmp = explode(',', $param_ligne);
392 $key = $tmp[0];
393 if (!empty($tmp[1])) {
394 $value = $tmp[1];
395 }
396 if (!array_key_exists('options', $params)) {
397 $params['options'] = array();
398 }
399 $params['options'][$key] = $value;
400 }
401 }
402
403 // $params['options'][$key] can be 'Facture:/compta/facture/class/facture.class.php' => '/custom'
404
405 // Visibility: -1=not visible by default in list, 1=visible, 0=hidden
406 $visibility = GETPOST('list', 'alpha');
407 if (in_array($type, ['separate', 'point', 'linestrg', 'polygon'])) {
408 $visibility = 3;
409 }
410
411 // Example: is_object($object) ? ($object->id < 10 ? round($object->id / 2, 2) : (2 * $user->id) * (int) substr($mysoc->zip, 1, 2)) : 'objnotdefined'
412 $computedvalue = GETPOST('computed_value', 'nohtml');
413
414 $result = $extrafields->update(
415 GETPOST('attrname', 'aZ09'),
416 GETPOST('label', 'alpha'),
417 $type,
418 $extrasize,
419 $elementtype,
420 (GETPOST('unique', 'alpha') ? 1 : 0),
421 (GETPOST('required', 'alpha') ? 1 : 0),
422 $pos,
423 $params,
424 (GETPOST('alwayseditable', 'alpha') ? 1 : 0),
425 (GETPOST('perms', 'alpha') ? GETPOST('perms', 'alpha') : ''),
426 $visibility,
427 GETPOST('help', 'alpha'),
428 GETPOST('default_value', 'alpha'),
429 $computedvalue,
430 (GETPOST('entitycurrentorall', 'alpha') ? 0 : ''),
431 GETPOST('langfile'),
432 GETPOST('enabled', 'nohtml'),
433 (GETPOST('totalizable', 'alpha') ? 1 : 0),
434 GETPOSTINT('printable'),
435 array('css' => $css, 'cssview' => $cssview, 'csslist' => $csslist),
436 GETPOST("ai_prompt"),
437 (GETPOST('emptyonclone', 'alpha') ? 1 : 0),
438 (GETPOST('showintooltip', 'int') ? 1 : 0),
439 GETPOSTINT('personal_data')
440 );
441 if ($result > 0) {
442 setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
443 header("Location: ".$_SERVER["PHP_SELF"]);
444 exit;
445 } else {
446 $error++;
447 $mesg = $extrafields->error;
448 $mesgs = array_merge($mesgs, $extrafields->errors);
449 setEventMessages($mesg, $mesgs, 'errors');
450 }
451 } else {
452 $error++;
453 $langs->load("errors");
454 $mesg = $langs->trans("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("AttributeCode"));
455 setEventMessages($mesg, null, 'errors');
456 }
457 } else {
458 setEventMessages($mesg, $mesgs, 'errors');
459 }
460 }
461}
462
463// Delete attribute
464if ($action == 'confirm_delete' && $confirm == "yes") {
465 if (GETPOSTISSET("attrname") && preg_match("/^\w[a-zA-Z0-9-_]*$/", GETPOST("attrname", 'aZ09'))) {
466 $attributekey = GETPOST('attrname', 'aZ09');
467
468 $result = $extrafields->delete($attributekey, $elementtype);
469 if ($result >= 0) {
470 setEventMessages($langs->trans("ExtrafieldsDeleted", $attributekey), null, 'mesgs');
471
472 header("Location: ".$_SERVER["PHP_SELF"]);
473 exit;
474 } else {
475 $mesg = $extrafields->error;
476 $mesgs = array_merge($mesgs, $extrafields->errors);
477 }
478 } else {
479 $error++;
480 $langs->load("errors");
481 $mesg = $langs->trans("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("AttributeCode"));
482 }
483}
484
485// Recrypt data password
486if ($action == 'encrypt') {
487 // Load $extrafields->attributes
488 $extrafields->fetch_name_optionals_label($elementtype);
489 $attributekey = GETPOST('attrname', 'aZ09');
490
491 if (!empty($extrafields->attributes[$elementtype]['type'][$attributekey]) && $extrafields->attributes[$elementtype]['type'][$attributekey] == 'password') {
492 if (!empty($extrafields->attributes[$elementtype]['param'][$attributekey]['options'])) {
493 if (array_key_exists('dolcrypt', $extrafields->attributes[$elementtype]['param'][$attributekey]['options'])) {
494 // We can encrypt data with dolCrypt()
495 $arrayofelement = getElementProperties($elementtype);
496 if (!empty($arrayofelement['table_element'])) {
497 if ($extrafields->attributes[$elementtype]['entityid'][$attributekey] == $conf->entity || empty($extrafields->attributes[$elementtype]['entityid'][$attributekey])) {
498 dol_syslog("Loop on each extafields of table ".$arrayofelement['table_element']);
499
500 $sql = "SELECT te.rowid, te.".$db->sanitize($attributekey);
501 $sql .= " FROM ".MAIN_DB_PREFIX.$db->sanitize($arrayofelement['table_element'])." as t, ".MAIN_DB_PREFIX.$db->sanitize($arrayofelement['table_element']).'_extrafields as te';
502 $sql .= " WHERE te.fk_object = t.rowid";
503 $sql .= " AND te.".$db->sanitize($attributekey)." NOT LIKE 'dolcrypt:%'";
504 $sql .= " AND te.".$db->sanitize($attributekey)." IS NOT NULL";
505 $sql .= " AND te.".$db->sanitize($attributekey)." <> ''";
506 if ($extrafields->attributes[$elementtype]['entityid'][$attributekey] == $conf->entity) {
507 $sql .= " AND t.entity = ".getEntity($arrayofelement['element'], 0);
508 }
509
510 //print $sql;
511 $nbupdatedone = 0;
512 $resql = $db->query($sql);
513 if ($resql) {
514 $num_rows = $db->num_rows($resql);
515 $i = 0;
516 while ($i < $num_rows) {
517 $objtmp = $db->fetch_object($resql);
518 $id = $objtmp->rowid;
519 $pass = $objtmp->$attributekey;
520 if ($pass) {
521 $newpassword = dolEncrypt($pass);
522
523 $sqlupdate = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($arrayofelement['table_element']).'_extrafields';
524 $sqlupdate .= " SET ".$attributekey." = '".$db->escape($newpassword)."'";
525 $sqlupdate .= " WHERE rowid = ".((int) $id);
526
527 $resupdate = $db->query($sqlupdate);
528 if ($resupdate) {
529 $nbupdatedone++;
530 } else {
531 setEventMessages($db->lasterror(), null, 'errors');
532 $error++;
533 break;
534 }
535 }
536
537 $i++;
538 }
539 }
540
541 if ($nbupdatedone > 0) {
542 setEventMessages($langs->trans("PasswordFieldEncrypted", $nbupdatedone), null, 'mesgs');
543 } else {
544 setEventMessages($langs->trans("PasswordFieldEncrypted", $nbupdatedone), null, 'warnings');
545 }
546 }
547 }
548 }
549 }
550 }
551}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
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.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.