dolibarr  17.0.4
actions_datapolicy.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseom.com>
3  * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
29 {
33  public $db;
34 
38  public $error = '';
39 
43  public $errors = array();
44 
48  public $results = array();
49 
53  public $resprints;
54 
60  public function __construct($db)
61  {
62  $this->db = $db;
63  }
64 
75  public function getNomUrl($parameters, &$object, &$action)
76  {
77  global $db, $langs, $conf, $user;
78  $this->resprints = '';
79  return 0;
80  }
81 
91  public function doActions($parameters, &$object, &$action, $hookmanager)
92  {
93  global $conf, $user, $langs;
94  $langs->load('datapolicy@datapolicy');
95  $error = 0; // Error counter
96 
97  if (GETPOST('socid') && $parameters['currentcontext'] == 'thirdpartycard' && !empty($object)) {
98  $object->fetch(GETPOST('socid'));
99  }
100 
101  // FIXME Removed hard coded id, use codes
102  if ($parameters['currentcontext'] == 'thirdpartycard' && $action == 'anonymiser' && (in_array($object->forme_juridique_code, array(11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005)) || $object->typent_id == 8)) {
103  // on verifie si l'objet est utilisé
104  if ($object->isObjectUsed(GETPOST('socid'))) {
105  $object->name = $langs->trans('ANONYME');
106  $object->name_bis = '';
107  $object->name_alias = '';
108  $object->address = '';
109  $object->town = '';
110  $object->zip = '';
111  $object->phone = '';
112  $object->email = '';
113  $object->url = '';
114  $object->fax = '';
115  $object->state = '';
116  $object->country = '';
117  $object->state_id = '';
118  $object->skype = '';
119  $object->country_id = '';
120  $object->note_private = $object->note_private.'<br>'.$langs->trans('ANONYMISER_AT', dol_print_date(time()));
121 
122  if ($object->update($object->id, $user, 0)) {
123  // On supprime les contacts associé
124  $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".((int) $object->id);
125  $this->db->query($sql);
126 
127  setEventMessages($langs->trans('ANONYMISER_SUCCESS'), array());
128  header('Location:'.$_SERVER["PHP_SELF"]."?socid=".$object->id);
129  }
130  }
131  } elseif ($parameters['currentcontext'] == 'thirdpartycard' && $action == 'datapolicy_portabilite') {
132  header('Content-Type: application/csv');
133  header('Content-Disposition: attachment; filename=datapolicy_portabilite.csv');
134  header('Pragma: no-cache');
135  $object->fetch(GETPOST('socid'));
136  echo 'Name;Firstname;Civility;Thirdparty;Function;Address;ZipCode;City;Department;Country;Email;Pro Phone;Perso Phone;Mobile Phone;Instant Mail;Birthday;'.PHP_EOL;
137  echo $object->name.';';
138  echo ';';
139  echo ';';
140  echo ';';
141  echo ';';
142  echo $object->address.';';
143  echo $object->zip.';';
144  echo $object->town.';';
145  echo $object->state.';';
146  echo $object->country.';';
147  echo $object->email.';';
148  echo $object->phone.';';
149  echo ';';
150  echo ';';
151  echo $object->skype.';';
152  echo ';';
153  exit;
154  } elseif ($parameters['currentcontext'] == 'membercard' && $action == 'datapolicy_portabilite') {
155  header('Content-Type: application/csv');
156  header('Content-Disposition: attachment; filename=datapolicy_portabilite.csv');
157  header('Pragma: no-cache');
158  $soc = $object->fetch_thirdparty();
159 
160  echo 'Name;Firstname;Civility;Thirdparty;Function;Address;ZipCode;City;Department;Country;Email;Pro Phone;Perso Phone;Mobile Phone;Instant Mail;Birthday;'.PHP_EOL;
161  echo $object->lastname.';';
162  echo $object->firstname.';';
163  echo $object->getCivilityLabel().';';
164  echo ($soc != -1 ? $object->thirdparty->name : '').';';
165  echo ';';
166  echo $object->address.';';
167  echo $object->zip.';';
168  echo $object->town.';';
169  echo $object->state.';';
170  echo $object->country.';';
171  echo $object->email.';';
172  echo $object->phone.';';
173  echo $object->phone_perso.';';
174  echo $object->phone_mobile.';';
175  echo $object->skype.';';
176  echo dol_print_date($object->birth).';';
177  exit;
178  } elseif ($parameters['currentcontext'] == 'contactcard' && $action == 'datapolicy_portabilite') {
179  $object->fetch(GETPOST('id'));
180  header('Content-Type: application/csv');
181  header('Content-Disposition: attachment; filename=datapolicy_portabilite.csv');
182  header('Pragma: no-cache');
183  $soc = $object->fetch_thirdparty();
184  echo 'Name;Firstname;Civility;Thirdparty;Function;Address;ZipCode;City;Department;Country;Email;Pro Phone;Perso Phone;Mobile Phone;Instant Mail;Birthday;'.PHP_EOL;
185  echo $object->lastname.';';
186  echo $object->firstname.';';
187  echo $object->getCivilityLabel().';';
188  echo ($soc != -1 ? $object->thirdparty->name : '').';';
189  echo $object->poste.';';
190  echo $object->address.';';
191  echo $object->zip.';';
192  echo $object->town.';';
193  echo $object->state.';';
194  echo $object->country.';';
195  echo $object->email.';';
196  echo $object->phone_pro.';';
197  echo $object->phone_perso.';';
198  echo $object->phone_mobile.';';
199  echo dol_print_date($object->birth).';';
200  exit;
201  } elseif ($parameters['currentcontext'] == 'contactcard' && $action == 'send_datapolicy') {
202  $object->fetch(GETPOST('id'));
203 
204  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
205  require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicy.class.php';
207  } elseif ($parameters['currentcontext'] == 'membercard' && $action == 'send_datapolicy') {
208  $object->fetch(GETPOST('id'));
209  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
210  require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicy.class.php';
212  } elseif ($parameters['currentcontext'] == 'thirdpartycard' && $action == 'send_datapolicy') {
213  $object->fetch(GETPOST('socid'));
214  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
215  require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicy.class.php';
217  }
218 
219 
220  if (!$error) {
221  $this->results = array('myreturn' => 999);
222  $this->resprints = 'A text to show';
223  return 0; // or return 1 to replace standard code
224  } else {
225  $this->errors[] = 'Error message';
226  return -1;
227  }
228  }
229 
239  public function doMassActions($parameters, &$object, &$action, $hookmanager)
240  {
241  global $conf, $user, $langs;
242 
243  $error = 0; // Error counter
244 
245  /* print_r($parameters); print_r($object); echo "action: " . $action; */
246  //if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) {
247  // // do something only for the context 'somecontext1' or 'somecontext2'
248  // foreach ($parameters['toselect'] as $objectid) {
249  // // Do action on each object id
250  // }
251  //}
252 
253  if (!$error) {
254  $this->results = array('myreturn' => 999);
255  $this->resprints = 'A text to show';
256  return 0; // or return 1 to replace standard code
257  } else {
258  $this->errors[] = 'Error message';
259  return -1;
260  }
261  }
262 
272  public function addMoreMassActions($parameters, &$object, &$action, $hookmanager)
273  {
274  global $conf, $user, $langs;
275 
276  $error = 0; // Error counter
277 
278  /* print_r($parameters); print_r($object); echo "action: " . $action; */
279  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
280  $this->resprints = '<option value="0"'.($disabled ? ' disabled="disabled"' : '').'>'.$langs->trans("datapolicyMassAction").'</option>';
281  }
282 
283  if (!$error) {
284  return 0; // or return 1 to replace standard code
285  } else {
286  $this->errors[] = 'Error message';
287  return -1;
288  }
289  }
290 
301  public function beforePDFCreation($parameters, &$object, &$action)
302  {
303  global $conf, $user, $langs;
304  global $hookmanager;
305 
306  $outputlangs = $langs;
307 
308  $ret = 0;
309  $deltemp = array();
310  dol_syslog(get_class($this).'::executeHooks action='.$action);
311 
312  /* print_r($parameters); print_r($object); echo "action: " . $action; */
313  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
314  }
315 
316  return $ret;
317  }
318 
319 
329  public function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager)
330  {
331  global $conf, $user, $langs;
332  $langs->load('datapolicy@datapolicy');
333 
334  if (!empty($conf->global->DATAPOLICY_ENABLE_EMAILS)) {
335  $dialog = '<div id="dialogdatapolicy" style="display:none;" title="'.$langs->trans('DATAPOLICY_PORTABILITE_TITLE').'">';
336  $dialog .= '<div class="confirmmessage">'.img_help('', '').' '.$langs->trans('DATAPOLICY_PORTABILITE_CONFIRMATION').'</div>';
337  $dialog .= "</div>";
338  $dialog .= '<script>
339  $( function() {
340  $("#rpgpdbtn").on("click", function(){
341  var href = $(this).attr("href");
342  $( "#dialogdatapolicy" ).dialog({
343  modal: true,
344  buttons: {
345  "OK": function() {
346  window.open(href);
347  $( this ).dialog( "close" );
348  },
349  "' . $langs->trans("Cancel").'": function() {
350  $( this ).dialog( "close" );
351  }
352  }
353  });
354 
355 
356  return false;
357  });
358  } );
359  </script>';
360  echo $dialog;
361  if ($parameters['currentcontext'] == 'thirdpartycard' && in_array($object->forme_juridique_code, array(11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005)) || $object->typent_id == 8) {
362  echo '<div class="inline-block divButAction"><a target="_blank" rel="noopener noreferrer" id="rpgpdbtn" class="butAction" href="'.$_SERVER["PHP_SELF"]."?socid=".$object->id.'&action=datapolicy_portabilite" title="'.$langs->trans('DATAPOLICY_PORTABILITE_TITLE').'">'.$langs->trans("DATAPOLICY_PORTABILITE").'</a></div>';
363  } elseif ($parameters['currentcontext'] == 'membercard') {
364  echo '<div class="inline-block divButAction"><a target="_blank" rel="noopener noreferrer" id="rpgpdbtn" class="butAction" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id.'&action=datapolicy_portabilite" title="'.$langs->trans('DATAPOLICY_PORTABILITE_TITLE').'">'.$langs->trans("DATAPOLICY_PORTABILITE").'</a></div>';
365  } elseif ($parameters['currentcontext'] == 'contactcard') {
366  echo '<div class="inline-block divButAction"><a target="_blank" rel="noopener noreferrer" id="rpgpdbtn" class="butAction" href="'.$_SERVER["PHP_SELF"]."?id=".$object->id.'&action=datapolicy_portabilite" title="'.$langs->trans('DATAPOLICY_PORTABILITE_TITLE').'">'.$langs->trans("DATAPOLICY_PORTABILITE").'</a></div>';
367  }
368  if (!empty($object->mail) && empty($object->array_options['options_datapolicy_send']) && $parameters['currentcontext'] == 'thirdpartycard' && in_array($object->forme_juridique_code, array(11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005)) || $object->typent_id == 8) {
369  echo '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"]."?socid=".$object->id.'&action=send_datapolicy" title="'.$langs->trans('DATAPOLICY_SEND').'">'.$langs->trans("DATAPOLICY_SEND").'</a></div>';
370  } elseif (!empty($object->mail) && empty($object->array_options['options_datapolicy_send']) && $parameters['currentcontext'] == 'membercard') {
371  echo '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id.'&action=send_datapolicy" title="'.$langs->trans('DATAPOLICY_SEND').'">'.$langs->trans("DATAPOLICY_SEND").'</a></div>';
372  } elseif (!empty($object->mail) && empty($object->array_options['options_datapolicy_send']) && $parameters['currentcontext'] == 'contactcard') {
373  echo '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"]."?id=".$object->id.'&action=send_datapolicy" title="'.$langs->trans('DATAPOLICY_SEND').'">'.$langs->trans("DATAPOLICY_SEND").'</a></div>';
374  }
375  }
376  }
377 
387  public function printCommonFooter($parameters, &$object, &$action, $hookmanager)
388  {
389  global $conf, $user, $langs;
390 
391  $jsscript = '';
392  if ($parameters['currentcontext'] == 'thirdpartycard') {
393  if (GETPOST('action') == 'create' || GETPOST('action') == 'edit' || GETPOST('action') == '') {
394  $jsscript .= '<script>';
395  $jsscript .= "var elementToHide = 'tr.societe_extras_datapolicy_consentement, tr.societe_extras_datapolicy_opposition_traitement, tr.societe_extras_datapolicy_opposition_prospection';".PHP_EOL;
396  $jsscript .= "var forme_juridique = [".PHP_EOL;
397  $jsscript .= "11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005".PHP_EOL;
398  $jsscript .= "];".PHP_EOL;
399  $jsscript .= "function hideRgPD() {".PHP_EOL;
400  $jsscript .= " if ($('#typent_id').val() == 8 || forme_juridique.indexOf(parseInt($('#forme_juridique_code').val())) > -1) {".PHP_EOL;
401  $jsscript .= " console.log(elementToHide);".PHP_EOL;
402  $jsscript .= " $('tr.societe_extras_datapolicy_consentement, tr.societe_extras_datapolicy_opposition_traitement, tr.societe_extras_datapolicy_opposition_prospection').show(); } else { $('tr.societe_extras_datapolicy_consentement, tr.societe_extras_datapolicy_opposition_traitement, tr.societe_extras_datapolicy_opposition_prospection').hide(); }}".PHP_EOL;
403  $jsscript .= "hideRgPD();".PHP_EOL;
404  $jsscript .= "$('#forme_juridique_code, #typent_id').change(function(){ hideRgPD(); });".PHP_EOL;
405  $jsscript .= '</script>';
406  } elseif (GETPOST('action') == 'confirm_delete' && GETPOST('confirm') == 'yes' && GETPOST('socid') > 0) {
407  // La suppression n'a pas été possible
408  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
409  $societe = new Societe($this->db);
410  $societe->fetch(GETPOST('socid'));
411  // On vérifie si il est utilisé
412  if ((in_array($object->forme_juridique_code, array(11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005)) || $societe->typent_id == 8) && $societe->isObjectUsed(GETPOST('socid'))) {
413  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
414  $form = new Form($this->db);
415  echo $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".GETPOST('socid'), substr($langs->trans("DATAPOLICY_POPUP_ANONYME_TITLE"), 0, strlen($langs->trans("DATAPOLICY_POPUP_ANONYME_TITLE")) - 2), $langs->trans("DATAPOLICY_POPUP_ANONYME_TEXTE"), 'anonymiser', '', '', 1);
416  }
417  }
418 
419  if (GETPOST('socid')) {
420  /* Removed due to awful harcoded values
421  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
422  $societe = new Societe($this->db);
423  $societe->fetch(GETPOST('socid'));
424 
425  if (!empty($object->forme_juridique_code) && !in_array($object->forme_juridique_code, array(11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005)) && $societe->typent_id != 8) {
426  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
427  $jsscript .= '<script>';
428  $jsscript .= "var elementToHide = 'td.societe_extras_datapolicy_opposition_traitement, td.societe_extras_datapolicy_opposition_prospection, td.societe_extras_datapolicy_consentement';".PHP_EOL;
429  $jsscript .= "$(elementToHide).parent('tr').hide();".PHP_EOL;
430  $jsscript .= '</script>';
431  }
432  */
433  }
434  } elseif ($parameters['currentcontext'] == 'contactcard') {
435  if (GETPOST('action') == 'create' || GETPOST('action') == 'edit') {
436  $jsscript .= '<script>';
437  $jsscript .= "$('#options_datapolicy_opposition_traitement, #options_datapolicy_opposition_prospection, input[name=\"options_datapolicy_opposition_traitement\"], input[name=\"options_datapolicy_opposition_prospection\"]').change(function(){
438  if($('#options_datapolicy_opposition_traitement').prop('checked') == true || $('input[name=options_datapolicy_opposition_traitement]').prop('checked') || $('#options_datapolicy_opposition_prospection').prop('checked') || $('input[name=options_datapolicy_opposition_prospection]').prop('checked')) {
439  $('#no_email').val(1);
440  }
441  });";
442  $jsscript .= '</script>';
443  }
444  }
445 
446  $this->resprint = $jsscript;
447 
448  return 0;
449  }
450 }
Class ActionsDatapolicy.
getNomUrl($parameters, &$object, &$action)
Execute action.
doActions($parameters, &$object, &$action, $hookmanager)
Overloading the doActions function : replacing the parent's function with the one below.
doMassActions($parameters, &$object, &$action, $hookmanager)
Overloading the doActions function : replacing the parent's function with the one below.
beforePDFCreation($parameters, &$object, &$action)
Execute action.
__construct($db)
Constructor.
addMoreActionsButtons($parameters, &$object, &$action, $hookmanager)
addMoreActionsButtons
addMoreMassActions($parameters, &$object, &$action, $hookmanager)
Overloading the addMoreMassActions function : replacing the parent's function with the one below.
printCommonFooter($parameters, &$object, &$action, $hookmanager)
printCommonFooter
static sendMailDataPolicyAdherent($adherent)
sendMailDataPolicyAdherent
static sendMailDataPolicyContact($contact)
sendMailDataPolicyContact
static sendMailDataPolicyCompany($societe)
sendMailDataPolicyCompany
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.
Definition: inc.php:41