dolibarr 22.0.5
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$maxsizestring = 255;
40$maxsizeint = 10;
41$mesg = '';
42$mesgs = array();
43
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');
51
52if ($type == 'double' && strpos($extrasize, ',') === false) {
53 $extrasize = '24,8';
54}
55if ($type == 'date') {
56 $extrasize = '';
57}
58if ($type == 'datetime') {
59 $extrasize = '';
60}
61if ($type == 'select') {
62 $extrasize = '';
63}
64
65// List of reserved words for databases
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'
77);
78
79// Add attribute
80if ($action == 'add') {
81 if (GETPOST("button") != $langs->trans("Cancel")) {
82 // Check values
83 if (!$type) {
84 $error++;
85 $langs->load("errors");
86 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
87 $action = 'create';
88 }
89 if ($type == 'varchar' && $extrasize <= 0) {
90 $error++;
91 $langs->load("errors");
92 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size"));
93 $action = 'edit';
94 }
95 if ($type == 'varchar' && $extrasize > $maxsizestring) {
96 $error++;
97 $langs->load("errors");
98 $mesgs[] = $langs->trans("ErrorSizeTooLongForVarcharType", $maxsizestring);
99 $action = 'create';
100 }
101 if ($type == 'int' && $extrasize > $maxsizeint) {
102 $error++;
103 $langs->load("errors");
104 $mesgs[] = $langs->trans("ErrorSizeTooLongForIntType", $maxsizeint);
105 $action = 'create';
106 }
107 if ($type == 'stars' && ($extrasize < 1 || $extrasize > 10)) {
108 $error++;
109 $langs->load("errors");
110 $mesgs[] = $langs->trans("ErrorSizeForStarsType");
111 $action = 'create';
112 }
113 if ($type == 'select' && !$param) {
114 $error++;
115 $langs->load("errors");
116 $mesgs[] = $langs->trans("ErrorNoValueForSelectType");
117 $action = 'create';
118 }
119 if ($type == 'sellist' && !$param) {
120 $error++;
121 $langs->load("errors");
122 $mesgs[] = $langs->trans("ErrorNoValueForSelectListType");
123 $action = 'create';
124 }
125 if ($type == 'checkbox' && !$param) {
126 $error++;
127 $langs->load("errors");
128 $mesgs[] = $langs->trans("ErrorNoValueForCheckBoxType");
129 $action = 'create';
130 }
131 if ($type == 'link' && !$param) {
132 $error++;
133 $langs->load("errors");
134 $mesgs[] = $langs->trans("ErrorNoValueForLinkType");
135 $action = 'create';
136 }
137 if ($type == 'link' && $param) {
138 // $param is 'ObjectName:classPath'. Check the class file really exists, a wrong path
139 // makes the link render as a raw id later, with nothing shown to the user.
140 $tmplink = explode(':', $param);
141 if (empty($tmplink[1]) || !file_exists(dol_buildpath($tmplink[1]))) {
142 $error++;
143 $langs->load("errors");
144 $mesgs[] = $langs->trans("ErrorFileNotFound", empty($tmplink[1]) ? $param : $tmplink[1]);
145 $action = 'create';
146 }
147 }
148 if ($type == 'radio' && !$param) {
149 $error++;
150 $langs->load("errors");
151 $mesgs[] = $langs->trans("ErrorNoValueForRadioType");
152 $action = 'create';
153 }
154 if ((($type == 'radio') || ($type == 'checkbox')) && $param) {
155 // Construct array for parameter (value of select list)
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) {
162 $error++;
163 $langs->load("errors");
164 $mesgs[] = $langs->trans("ErrorBadFormatValueList", $param_ligne);
165 $action = 'create';
166 }
167 } else {
168 $error++;
169 $langs->load("errors");
170 $mesgs[] = $langs->trans("ErrorBadFormatValueList", $param_ligne);
171 $action = 'create';
172 }
173 }
174 }
175 }
176
177 if (!$error) {
178 if (strlen(GETPOST('attrname', 'aZ09')) < 3) {
179 $error++;
180 $langs->load("errors");
181 $mesgs[] = $langs->trans("ErrorValueLength", $langs->transnoentitiesnoconv("AttributeCode"), 3);
182 $action = 'create';
183 }
184 }
185
186 // Check reserved keyword with more than 3 characters
187 if (!$error) {
188 if (in_array(strtoupper(GETPOST('attrname', 'aZ09')), $listofreservedwords)) {
189 $error++;
190 $langs->load("errors");
191 $mesgs[] = $langs->trans("ErrorReservedKeyword", GETPOST('attrname', 'aZ09'));
192 $action = 'create';
193 }
194 }
195
196 if (!$error) {
197 // attrname must be alphabetical and lower case only
198 if (GETPOSTISSET("attrname") && preg_match("/^[a-z0-9_]+$/", GETPOST('attrname', 'aZ09')) && !is_numeric(GETPOST('attrname', 'aZ09'))) {
199 // Construct array for parameter (value of select list)
200 $default_value = GETPOST('default_value', 'alpha');
201 $parameters = $param;
202 $parameters_array = explode("\r\n", $parameters);
203 $params = array();
204 //In sellist we have only one line and it can have come to do SQL expression
205 if ($type == 'sellist' || $type == 'chkbxlst') {
206 foreach ($parameters_array as $param_ligne) {
207 $params['options'] = array($parameters => null);
208 }
209 } else {
210 // Else it's separated key/value and coma list
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();
216 }
217 } else {
218 $key = $param_ligne;
219 $value = null;
220 }
221 $params['options'][$key] = $value;
222 }
223 }
224
225 // Visibility: -1=not visible by default in list, 1=visible, 0=hidden
226 $visibility = GETPOST('list', 'alpha');
227 if (in_array($type, ['separate', 'point', 'linestrg', 'polygon'])) {
228 $visibility = 3;
229 }
230
231 $result = $extrafields->addExtraField(
232 GETPOST('attrname', 'aZ09'),
233 GETPOST('label', 'alpha'),
234 $type,
235 GETPOSTINT('pos'),
236 $extrasize,
237 $elementtype,
238 (GETPOST('unique', 'alpha') ? 1 : 0),
239 (GETPOST('required', 'alpha') ? 1 : 0),
240 $default_value,
241 $params,
242 (GETPOST('alwayseditable', 'alpha') ? 1 : 0),
243 (GETPOST('perms', 'alpha') ? GETPOST('perms', 'alpha') : ''),
244 $visibility,
245 GETPOST('help', 'alpha'),
246 GETPOST('computed_value', 'alpha'),
247 (GETPOST('entitycurrentorall', 'alpha') ? 0 : ''),
248 GETPOST('langfile', 'alpha'),
249 '1',
250 (GETPOST('totalizable', 'alpha') ? 1 : 0),
251 GETPOSTINT('printable'),
252 array('css' => $css, 'cssview' => $cssview, 'csslist' => $csslist),
253 GETPOST("ai_prompt")
254 );
255 if ($result > 0) {
256 setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
257 header("Location: ".$_SERVER["PHP_SELF"]);
258 exit;
259 } else {
260 $error++;
261 $mesg = $extrafields->error;
262 $mesgs = array_merge($mesgs, $extrafields->errors);
263 setEventMessages($mesg, $mesgs, 'errors');
264 }
265 } else {
266 $error++;
267 $langs->load("errors");
268 $mesg = $langs->trans("ErrorFieldCanNotContainSpecialNorUpperCharacters", $langs->transnoentities("AttributeCode"));
269 setEventMessages($mesg, $mesgs, 'errors');
270 $action = 'create';
271 }
272 } else {
273 setEventMessages($mesg, $mesgs, 'errors');
274 }
275 }
276}
277
278// Rename field
279if ($action == 'update') {
280 if (GETPOST("button") != $langs->trans("Cancel")) {
281 // Check values
282 if (!$type) {
283 $error++;
284 $langs->load("errors");
285 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"));
286 $action = 'edit';
287 }
288 if ($type == 'varchar' && $extrasize <= 0) {
289 $error++;
290 $langs->load("errors");
291 $mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size"));
292 $action = 'edit';
293 }
294 if ($type == 'varchar' && $extrasize > $maxsizestring) {
295 $error++;
296 $langs->load("errors");
297 $mesgs[] = $langs->trans("ErrorSizeTooLongForVarcharType", $maxsizestring);
298 $action = 'edit';
299 }
300 if ($type == 'int' && $extrasize > $maxsizeint) {
301 $error++;
302 $langs->load("errors");
303 $mesgs[] = $langs->trans("ErrorSizeTooLongForIntType", $maxsizeint);
304 $action = 'edit';
305 }
306 if ($type == 'select' && !$param) {
307 $error++;
308 $langs->load("errors");
309 $mesgs[] = $langs->trans("ErrorNoValueForSelectType");
310 $action = 'edit';
311 }
312 if ($type == 'sellist' && !$param) {
313 $error++;
314 $langs->load("errors");
315 $mesgs[] = $langs->trans("ErrorNoValueForSelectListType");
316 $action = 'edit';
317 }
318 if ($type == 'stars' && ($extrasize < 1 || $extrasize > 10)) {
319 $error++;
320 $langs->load("errors");
321 $mesgs[] = $langs->trans("ErrorSizeForStarsType");
322 $action = 'edit';
323 }
324 if ($type == 'checkbox' && !$param) {
325 $error++;
326 $langs->load("errors");
327 $mesgs[] = $langs->trans("ErrorNoValueForCheckBoxType");
328 $action = 'edit';
329 }
330 if ($type == 'radio' && !$param) {
331 $error++;
332 $langs->load("errors");
333 $mesgs[] = $langs->trans("ErrorNoValueForRadioType");
334 $action = 'edit';
335 }
336 if ($type == 'link' && $param) {
337 // $param is 'ObjectName:classPath'. Check the class file really exists, a wrong path
338 // makes the link render as a raw id later, with nothing shown to the user.
339 $tmplink = explode(':', $param);
340 if (empty($tmplink[1]) || !file_exists(dol_buildpath($tmplink[1]))) {
341 $error++;
342 $langs->load("errors");
343 $mesgs[] = $langs->trans("ErrorFileNotFound", empty($tmplink[1]) ? $param : $tmplink[1]);
344 $action = 'edit';
345 }
346 }
347 if ((($type == 'radio') || ($type == 'checkbox')) && $param) {
348 // Construct array for parameter (value of select list)
349 $parameters = $param;
350 $parameters_array = explode("\r\n", $parameters);
351 foreach ($parameters_array as $param_ligne) {
352 if (!empty($param_ligne)) {
353 if (preg_match_all('/,/', $param_ligne, $matches)) {
354 if (count($matches[0]) > 1) {
355 $error++;
356 $langs->load("errors");
357 $mesgs[] = $langs->trans("ErrorBadFormatValueList", $param_ligne);
358 $action = 'edit';
359 }
360 } else {
361 $error++;
362 $langs->load("errors");
363 $mesgs[] = $langs->trans("ErrorBadFormatValueList", $param_ligne);
364 $action = 'edit';
365 }
366 }
367 }
368 }
369
370 if (!$error) {
371 if (strlen(GETPOST('attrname', 'aZ09')) < 3 && !getDolGlobalString('MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE')) {
372 $error++;
373 $langs->load("errors");
374 $mesgs[] = $langs->trans("ErrorValueLength", $langs->transnoentitiesnoconv("AttributeCode"), 3);
375 $action = 'edit';
376 }
377 }
378
379 // Check reserved keyword with more than 3 characters
380 if (!$error) {
381 if (in_array(strtoupper(GETPOST('attrname', 'aZ09')), $listofreservedwords) && !getDolGlobalString('MAIN_DISABLE_EXTRAFIELDS_CHECK_FOR_UPDATE')) {
382 $error++;
383 $langs->load("errors");
384 $mesgs[] = $langs->trans("ErrorReservedKeyword", GETPOST('attrname', 'aZ09'));
385 $action = 'edit';
386 }
387 }
388
389 if (!$error) {
390 if (GETPOSTISSET("attrname") && preg_match("/^\w[a-zA-Z0-9-_]*$/", GETPOST('attrname', 'aZ09')) && !is_numeric(GETPOST('attrname', 'aZ09'))) {
391 $pos = GETPOSTINT('pos');
392 // Construct array for parameter (value of select list)
393 $parameters = $param;
394 $parameters_array = explode("\r\n", $parameters);
395 $params = array();
396 //In sellist we have only one line and it can have come to do SQL expression
397 if ($type == 'sellist' || $type == 'chkbxlst') {
398 foreach ($parameters_array as $param_ligne) {
399 $params['options'] = array($parameters => null);
400 }
401 } else {
402 //Else it's separated key/value and coma list
403 foreach ($parameters_array as $param_ligne) {
404 $tmp = explode(',', $param_ligne);
405 $key = $tmp[0];
406 if (!empty($tmp[1])) {
407 $value = $tmp[1];
408 }
409 if (!array_key_exists('options', $params)) {
410 $params['options'] = array();
411 }
412 $params['options'][$key] = $value;
413 }
414 }
415
416 // $params['options'][$key] can be 'Facture:/compta/facture/class/facture.class.php' => '/custom'
417
418 // Visibility: -1=not visible by default in list, 1=visible, 0=hidden
419 $visibility = GETPOST('list', 'alpha');
420 if (in_array($type, ['separate', 'point', 'linestrg', 'polygon'])) {
421 $visibility = 3;
422 }
423
424 // Example: is_object($object) ? ($object->id < 10 ? round($object->id / 2, 2) : (2 * $user->id) * (int) substr($mysoc->zip, 1, 2)) : 'objnotdefined'
425 $computedvalue = GETPOST('computed_value', 'nohtml');
426
427 $result = $extrafields->update(
428 GETPOST('attrname', 'aZ09'),
429 GETPOST('label', 'alpha'),
430 $type,
431 $extrasize,
432 $elementtype,
433 (GETPOST('unique', 'alpha') ? 1 : 0),
434 (GETPOST('required', 'alpha') ? 1 : 0),
435 $pos,
436 $params,
437 (GETPOST('alwayseditable', 'alpha') ? 1 : 0),
438 (GETPOST('perms', 'alpha') ? GETPOST('perms', 'alpha') : ''),
439 $visibility,
440 GETPOST('help', 'alpha'),
441 GETPOST('default_value', 'alpha'),
442 $computedvalue,
443 (GETPOST('entitycurrentorall', 'alpha') ? 0 : ''),
444 GETPOST('langfile'),
445 GETPOST('enabled', 'nohtml'),
446 (GETPOST('totalizable', 'alpha') ? 1 : 0),
447 GETPOSTINT('printable'),
448 array('css' => $css, 'cssview' => $cssview, 'csslist' => $csslist),
449 GETPOST("ai_prompt")
450 );
451 if ($result > 0) {
452 setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
453 header("Location: ".$_SERVER["PHP_SELF"]);
454 exit;
455 } else {
456 $error++;
457 $mesg = $extrafields->error;
458 $mesgs = array_merge($mesgs, $extrafields->errors);
459 setEventMessages($mesg, $mesgs, 'errors');
460 }
461 } else {
462 $error++;
463 $langs->load("errors");
464 $mesg = $langs->trans("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("AttributeCode"));
465 setEventMessages($mesg, null, 'errors');
466 }
467 } else {
468 setEventMessages($mesg, $mesgs, 'errors');
469 }
470 }
471}
472
473// Delete attribute
474if ($action == 'confirm_delete' && $confirm == "yes") {
475 if (GETPOSTISSET("attrname") && preg_match("/^\w[a-zA-Z0-9-_]*$/", GETPOST("attrname", 'aZ09'))) {
476 $attributekey = GETPOST('attrname', 'aZ09');
477
478 $result = $extrafields->delete($attributekey, $elementtype);
479 if ($result >= 0) {
480 setEventMessages($langs->trans("ExtrafieldsDeleted", $attributekey), null, 'mesgs');
481
482 header("Location: ".$_SERVER["PHP_SELF"]);
483 exit;
484 } else {
485 $mesg = $extrafields->error;
486 $mesgs = array_merge($mesgs, $extrafields->errors);
487 }
488 } else {
489 $error++;
490 $langs->load("errors");
491 $mesg = $langs->trans("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("AttributeCode"));
492 }
493}
494
495// Recrypt data password
496if ($action == 'encrypt') {
497 // Load $extrafields->attributes
498 $extrafields->fetch_name_optionals_label($elementtype);
499 $attributekey = GETPOST('attrname', 'aZ09');
500
501 if (!empty($extrafields->attributes[$elementtype]['type'][$attributekey]) && $extrafields->attributes[$elementtype]['type'][$attributekey] == 'password') {
502 if (!empty($extrafields->attributes[$elementtype]['param'][$attributekey]['options'])) {
503 if (array_key_exists('dolcrypt', $extrafields->attributes[$elementtype]['param'][$attributekey]['options'])) {
504 // We can encrypt data with dolCrypt()
505 $arrayofelement = getElementProperties($elementtype);
506 if (!empty($arrayofelement['table_element'])) {
507 if ($extrafields->attributes[$elementtype]['entityid'][$attributekey] == $conf->entity || empty($extrafields->attributes[$elementtype]['entityid'][$attributekey])) {
508 dol_syslog("Loop on each extafields of table ".$arrayofelement['table_element']);
509
510 $sql = "SELECT te.rowid, te.".$attributekey;
511 $sql .= " FROM ".MAIN_DB_PREFIX.$arrayofelement['table_element']." as t, ".MAIN_DB_PREFIX.$arrayofelement['table_element'].'_extrafields as te';
512 $sql .= " WHERE te.fk_object = t.rowid";
513 $sql .= " AND te.".$attributekey." NOT LIKE 'dolcrypt:%'";
514 $sql .= " AND te.".$attributekey." IS NOT NULL";
515 $sql .= " AND te.".$attributekey." <> ''";
516 if ($extrafields->attributes[$elementtype]['entityid'][$attributekey] == $conf->entity) {
517 $sql .= " AND t.entity = ".getEntity($arrayofelement['element'], 0);
518 }
519
520 //print $sql;
521 $nbupdatedone = 0;
522 $resql = $db->query($sql);
523 if ($resql) {
524 $num_rows = $db->num_rows($resql);
525 $i = 0;
526 while ($i < $num_rows) {
527 $objtmp = $db->fetch_object($resql);
528 $id = $objtmp->rowid;
529 $pass = $objtmp->$attributekey;
530 if ($pass) {
531 $newpassword = dolEncrypt($pass);
532
533 $sqlupdate = "UPDATE ".MAIN_DB_PREFIX.$arrayofelement['table_element'].'_extrafields';
534 $sqlupdate .= " SET ".$attributekey." = '".$db->escape($newpassword)."'";
535 $sqlupdate .= " WHERE rowid = ".((int) $id);
536
537 $resupdate = $db->query($sqlupdate);
538 if ($resupdate) {
539 $nbupdatedone++;
540 } else {
541 setEventMessages($db->lasterror(), null, 'errors');
542 $error++;
543 break;
544 }
545 }
546
547 $i++;
548 }
549 }
550
551 if ($nbupdatedone > 0) {
552 setEventMessages($langs->trans("PasswordFieldEncrypted", $nbupdatedone), null, 'mesgs');
553 } else {
554 setEventMessages($langs->trans("PasswordFieldEncrypted", $nbupdatedone), null, 'warnings');
555 }
556 }
557 }
558 }
559 }
560 }
561}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
dolEncrypt($chain, $key='', $ciphering='', $forceseed='')
Encode a string with a symmetric encryption.