59 global $conf, $langs, $user;
61 $langs->load(
'datapolicy@datapolicy');
65 $nbupdated = $nbdeleted = 0;
68 $arrayofparameters = array(
69 'DATAPOLICY_TIERS_CLIENT' => array(
71 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
75 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
77 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
80 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
84 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
85 'fields_anonym' => array(
86 'name' =>
'MAKEANONYMOUS',
99 'socialnetworks' =>
'',
103 'DATAPOLICY_TIERS_PROSPECT' => array(
105 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
108 AND s.fournisseur = 0
109 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
111 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
114 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
117 "class" =>
"Societe",
118 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
119 'fields_anonym' => array(
120 'name' =>
'MAKEANONYMOUS',
133 'socialnetworks' =>
'',
137 'DATAPOLICY_TIERS_PROSPECT_CLIENT' => array(
139 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
142 AND s.fournisseur = 0
143 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
145 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
148 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
151 "class" =>
"Societe",
152 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
153 'fields_anonym' => array(
154 'name' =>
'MAKEANONYMOUS',
167 'socialnetworks' =>
'',
171 'DATAPOLICY_TIERS_NIPROSPECT_NICLIENT' => array(
173 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
176 AND s.fournisseur = 0
177 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
179 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
182 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
185 "class" =>
"Societe",
186 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
187 'fields_anonym' => array(
188 'name' =>
'MAKEANONYMOUS',
201 'socialnetworks' =>
'',
205 'DATAPOLICY_TIERS_FOURNISSEUR' => array(
207 SELECT s.rowid FROM ".MAIN_DB_PREFIX.
"societe as s
209 AND s.fournisseur = 1
210 AND s.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
212 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_soc = s.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
215 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
218 "class" =>
"Societe",
219 "file" => DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php',
220 'fields_anonym' => array(
221 'name' =>
'MAKEANONYMOUS',
234 'socialnetworks' =>
'',
238 'DATAPOLICY_CONTACT_CLIENT' => array(
240 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
241 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
243 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
245 AND s.fournisseur = 0
247 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
250 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
253 "class" =>
"Contact",
254 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
255 'fields_anonym' => array(
256 'lastname' =>
'MAKEANONYMOUS',
265 'phone_mobile' =>
'',
272 'socialnetworks' =>
'',
276 'DATAPOLICY_CONTACT_PROSPECT' => array(
278 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
279 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
281 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
283 AND s.fournisseur = 0
285 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
288 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
291 "class" =>
"Contact",
292 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
293 'fields_anonym' => array(
294 'lastname' =>
'MAKEANONYMOUS',
303 'phone_mobile' =>
'',
310 'socialnetworks' =>
'',
314 'DATAPOLICY_CONTACT_PROSPECT_CLIENT' => array(
316 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
317 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
319 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
321 AND s.fournisseur = 0
323 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
326 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
329 "class" =>
"Contact",
330 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
331 'fields_anonym' => array(
332 'lastname' =>
'MAKEANONYMOUS',
341 'phone_mobile' =>
'',
348 'socialnetworks' =>
'',
352 'DATAPOLICY_CONTACT_NIPROSPECT_NICLIENT' => array(
354 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
355 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
357 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
359 AND s.fournisseur = 0
361 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
364 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
367 "class" =>
"Contact",
368 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
369 'fields_anonym' => array(
370 'lastname' =>
'MAKEANONYMOUS',
379 'phone_mobile' =>
'',
386 'socialnetworks' =>
'',
390 'DATAPOLICY_CONTACT_FOURNISSEUR' => array(
392 SELECT c.rowid FROM ".MAIN_DB_PREFIX.
"socpeople as c
393 INNER JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = c.fk_soc
395 AND c.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
396 AND s.fournisseur = 1
398 SELECT id FROM ".MAIN_DB_PREFIX.
"actioncomm as a WHERE a.fk_contact = c.rowid AND a.tms > DATE_SUB(NOW(), INTERVAL %d MONTH)
401 SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.fk_soc = s.rowid
404 "class" =>
"Contact",
405 "file" => DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php',
406 'fields_anonym' => array(
407 'lastname' =>
'MAKEANONYMOUS',
416 'phone_mobile' =>
'',
423 'socialnetworks' =>
'',
427 'DATAPOLICY_ADHERENT' => array(
429 SELECT a.rowid FROM ".MAIN_DB_PREFIX.
"adherent as a
431 AND a.tms < DATE_SUB(NOW(), INTERVAL %d MONTH)
433 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'
436 "class" =>
"Adherent",
437 "file" => DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php',
438 'fields_anonym' => array(
439 'lastname' =>
'MAKEANONYMOUS',
440 'firstname' =>
'MAKEANONYMOUS',
448 'phone_mobile' =>
'',
455 'socialnetworks' =>
'',
463 foreach ($arrayofparameters as $key => $params) {
467 $resql = $this->db->query($sql);
469 if ($resql && $this->db->num_rows($resql) > 0) {
470 $num = $this->db->num_rows($resql);
473 require_once $params[
'file'];
474 $object =
new $params[
'class']($this->db);
476 while ($i < $num && !$error) {
477 $obj = $this->db->fetch_object($resql);
479 $object->fetch($obj->rowid);
480 $object->id = $obj->rowid;
482 $action =
'anonymize';
484 if ($action ==
'anonymize') {
485 if ($object->isObjectUsed($obj->rowid) == 0) {
486 foreach ($params[
'fields_anonym'] as $fields => $val) {
487 if ($val ==
'MAKEANONYMOUS') {
488 $object->$fields = $fields.
'-anonymous-'.$obj->rowid;
490 $object->$fields = $val;
493 $result = $object->update($obj->rowid, $user);
495 $errormsg = $object->error;
502 if ($action ==
'delete') {
503 if ($object->element ==
'adherent') {
504 $result = $object->delete($obj->rowid, $user);
506 $result = $object->delete($user);
509 $errormsg = $object->error;
525 $this->output = $nbupdated.
' record updated, '.$nbdeleted.
' record deleted';
527 $this->error = $errormsg;