54 global $conf, $langs, $user;
56 $langs->load(
'datapolicy@datapolicy');
60 $nbupdated = $nbdeleted = 0;
63 $arrayofparameters = array(
64 'DATAPOLICY_TIERS_CLIENT' => array(
66 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
70 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
72 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
75 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
79 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
80 'fields_anonym' => array(
81 'name' =>
'MAKEANONYMOUS',
94 'socialnetworks' =>
'',
98 'DATAPOLICY_TIERS_PROSPECT' => array(
100 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
103 AND s.fournisseur = 0
104 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
106 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
109 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
112 "class" =>
"Societe",
113 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
114 'fields_anonym' => array(
115 'name' =>
'MAKEANONYMOUS',
128 'socialnetworks' =>
'',
132 'DATAPOLICY_TIERS_PROSPECT_CLIENT' => array(
134 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
137 AND s.fournisseur = 0
138 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
140 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
143 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
146 "class" =>
"Societe",
147 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
148 'fields_anonym' => array(
149 'name' =>
'MAKEANONYMOUS',
162 'socialnetworks' =>
'',
166 'DATAPOLICY_TIERS_NIPROSPECT_NICLIENT' => array(
168 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
171 AND s.fournisseur = 0
172 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
174 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
177 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
180 "class" =>
"Societe",
181 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
182 'fields_anonym' => array(
183 'name' =>
'MAKEANONYMOUS',
196 'socialnetworks' =>
'',
200 'DATAPOLICY_TIERS_FOURNISSEUR' => array(
202 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
204 AND s.fournisseur = 1
205 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
207 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
210 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
213 "class" =>
"Societe",
214 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
215 'fields_anonym' => array(
216 'name' =>
'MAKEANONYMOUS',
229 'socialnetworks' =>
'',
233 'DATAPOLICY_CONTACT_CLIENT' => array(
235 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
236 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
238 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
240 AND s.fournisseur = 0
242 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
245 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
248 "class" =>
"Contact",
249 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
250 'fields_anonym' => array(
251 'lastname' =>
'MAKEANONYMOUS',
260 'phone_mobile' =>
'',
267 'socialnetworks' =>
'',
271 'DATAPOLICY_CONTACT_PROSPECT' => array(
273 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
274 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
276 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
278 AND s.fournisseur = 0
280 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
283 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
286 "class" =>
"Contact",
287 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
288 'fields_anonym' => array(
289 'lastname' =>
'MAKEANONYMOUS',
298 'phone_mobile' =>
'',
305 'socialnetworks' =>
'',
309 'DATAPOLICY_CONTACT_PROSPECT_CLIENT' => array(
311 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
312 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
314 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
316 AND s.fournisseur = 0
318 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
321 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
324 "class" =>
"Contact",
325 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
326 'fields_anonym' => array(
327 'lastname' =>
'MAKEANONYMOUS',
336 'phone_mobile' =>
'',
343 'socialnetworks' =>
'',
347 'DATAPOLICY_CONTACT_NIPROSPECT_NICLIENT' => array(
349 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
350 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
352 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
354 AND s.fournisseur = 0
356 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
359 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
362 "class" =>
"Contact",
363 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
364 'fields_anonym' => array(
365 'lastname' =>
'MAKEANONYMOUS',
374 'phone_mobile' =>
'',
381 'socialnetworks' =>
'',
385 'DATAPOLICY_CONTACT_FOURNISSEUR' => array(
387 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
388 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
390 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
391 AND s.fournisseur = 1
393 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
396 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
399 "class" =>
"Contact",
400 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
401 'fields_anonym' => array(
402 'lastname' =>
'MAKEANONYMOUS',
411 'phone_mobile' =>
'',
418 'socialnetworks' =>
'',
422 'DATAPOLICY_ADHERENT' => array(
424 SELECT a.rowid FROM ".MAIN_DB_PREFIX.
"adherent as a
426 AND a.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
428 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_element = a.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH) AND a.elementtype LIKE 'member'
431 "class" =>
"Adherent",
432 "file" => DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php',
433 'fields_anonym' => array(
434 'lastname' =>
'MAKEANONYMOUS',
435 'firstname' =>
'MAKEANONYMOUS',
443 'phone_mobile' =>
'',
450 'socialnetworks' =>
'',
458 foreach ($arrayofparameters as $key => $params) {
462 $resql = $this->db->query($sql);
464 if ($resql && $this->db->num_rows($resql) > 0) {
465 $num = $this->db->num_rows($resql);
468 require_once $params[
'file'];
469 $object =
new $params[
'class']($this->db);
471 while ($i < $num && !$error) {
472 $obj = $this->db->fetch_object($resql);
474 $object->fetch($obj->rowid);
475 $object->id = $obj->rowid;
477 $action =
'anonymize';
479 if ($action ==
'anonymize') {
480 if ($object->isObjectUsed($obj->rowid) == 0) {
481 foreach ($params[
'fields_anonym'] as $fields => $val) {
482 if ($val ==
'MAKEANONYMOUS') {
483 $object->$fields = $fields.
'-anonymous-'.$obj->rowid;
485 $object->$fields = $val;
488 $result = $object->update($obj->rowid, $user);
490 $errormsg = $object->error;
497 if ($action ==
'delete') {
498 if ($object->element ==
'adherent') {
499 $result = $object->delete($obj->rowid, $user);
501 $result = $object->delete($user);
504 $errormsg = $object->error;
520 $this->output = $nbupdated.
' record updated, '.$nbdeleted.
' record deleted';
522 $this->error = $errormsg;