dolibarr  19.0.0-dev
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 
25 require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php';
26 
31 {
35  public $db;
36 
40  public $error = '';
41 
45  public $errors = array();
46 
50  public $results = array();
51 
55  public $resprints;
56 
62  public function __construct($db)
63  {
64  $this->db = $db;
65  }
66 
77  public function getNomUrl($parameters, &$object, &$action)
78  {
79  global $db, $langs, $conf, $user;
80  $this->resprints = '';
81  return 0;
82  }
83 
93  public function doActions($parameters, &$object, &$action, $hookmanager)
94  {
95  global $conf, $user, $langs;
96  $langs->load('datapolicy@datapolicy');
97  $error = 0; // Error counter
98 
99  if (GETPOST('socid') && $parameters['currentcontext'] == 'thirdpartycard' && !empty($object)) {
100  $object->fetch(GETPOST('socid'));
101  }
102 
103  // FIXME Removed hard coded id, use codes
104  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)) {
105  // on verifie si l'objet est utilisé
106  if ($object->isObjectUsed(GETPOST('socid'))) {
107  $object->name = $langs->trans('ANONYME');
108  $object->name_alias = '';
109  $object->address = '';
110  $object->town = '';
111  $object->zip = '';
112  $object->phone = '';
113  $object->email = '';
114  $object->url = '';
115  $object->fax = '';
116  $object->state = '';
117  $object->country = '';
118  $object->state_id = '';
119  $object->socialnetworks = '';
120  $object->country_id = '';
121  $object->note_private = dol_concatdesc($object->note_private, $langs->trans('ANONYMISER_AT', dol_print_date(dol_now())));
122 
123  if ($object->update($object->id, $user, 0)) {
124  // On supprime les contacts associé
125  $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".((int) $object->id);
126  $this->db->query($sql);
127 
128  setEventMessages($langs->trans('ANONYMISER_SUCCESS'), array());
129  header('Location:'.$_SERVER["PHP_SELF"]."?socid=".$object->id);
130  }
131  }
132  } elseif ($parameters['currentcontext'] == 'contactcard' && $action == 'send_datapolicy') {
133  $object->fetch(GETPOST('id'));
134 
135  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
136  require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicy.class.php';
138  } elseif ($parameters['currentcontext'] == 'membercard' && $action == 'send_datapolicy') {
139  $object->fetch(GETPOST('id'));
140  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
141  require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicy.class.php';
143  } elseif ($parameters['currentcontext'] == 'thirdpartycard' && $action == 'send_datapolicy') {
144  $object->fetch(GETPOST('socid'));
145  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
146  require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicy.class.php';
148  }
149 
150 
151  if (!$error) {
152  $this->results = array('myreturn' => 999);
153  $this->resprints = 'A text to show';
154  return 0; // or return 1 to replace standard code
155  } else {
156  $this->errors[] = 'Error message';
157  return -1;
158  }
159  }
160 
170  public function doMassActions($parameters, &$object, &$action, $hookmanager)
171  {
172  global $conf, $user, $langs;
173 
174  $error = 0; // Error counter
175 
176  /* print_r($parameters); print_r($object); echo "action: " . $action; */
177  //if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) {
178  // // do something only for the context 'somecontext1' or 'somecontext2'
179  // foreach ($parameters['toselect'] as $objectid) {
180  // // Do action on each object id
181  // }
182  //}
183 
184  if (!$error) {
185  $this->results = array('myreturn' => 999);
186  $this->resprints = 'A text to show';
187  return 0; // or return 1 to replace standard code
188  } else {
189  $this->errors[] = 'Error message';
190  return -1;
191  }
192  }
193 
203  public function addMoreMassActions($parameters, &$object, &$action, $hookmanager)
204  {
205  global $conf, $user, $langs;
206 
207  $error = 0; // Error counter
208 
209  /* print_r($parameters); print_r($object); echo "action: " . $action; */
210  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
211  $this->resprints = '<option value="0"'.($disabled ? ' disabled="disabled"' : '').'>'.$langs->trans("datapolicyMassAction").'</option>';
212  }
213 
214  if (!$error) {
215  return 0; // or return 1 to replace standard code
216  } else {
217  $this->errors[] = 'Error message';
218  return -1;
219  }
220  }
221 
232  public function beforePDFCreation($parameters, &$object, &$action)
233  {
234  global $conf, $user, $langs;
235  global $hookmanager;
236 
237  $outputlangs = $langs;
238 
239  $ret = 0;
240  $deltemp = array();
241  dol_syslog(get_class($this).'::executeHooks action='.$action);
242 
243  /* print_r($parameters); print_r($object); echo "action: " . $action; */
244  if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
245  }
246 
247  return $ret;
248  }
249 
250 
260  public function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager)
261  {
262  global $conf, $user, $langs;
263  $langs->load('datapolicy@datapolicy');
264 
265  if (!empty($conf->global->DATAPOLICY_ENABLE_EMAILS)) {
266  $dialog = '<div id="dialogdatapolicy" style="display:none;" title="'.$langs->trans('DATAPOLICY_PORTABILITE_TITLE').'">';
267  $dialog .= '<div class="confirmmessage">'.img_help('', '').' '.$langs->trans('DATAPOLICY_PORTABILITE_CONFIRMATION').'</div>';
268  $dialog .= "</div>";
269  $dialog .= '<script>
270  $( function() {
271  $("#rpgpdbtn").on("click", function(){
272  var href = $(this).attr("href");
273  $( "#dialogdatapolicy" ).dialog({
274  modal: true,
275  buttons: {
276  "OK": function() {
277  window.open(href);
278  $( this ).dialog( "close" );
279  },
280  "' . $langs->trans("Cancel").'": function() {
281  $( this ).dialog( "close" );
282  }
283  }
284  });
285 
286 
287  return false;
288  });
289  } );
290  </script>';
291  echo $dialog;
292  // TODO Replace test of hardcoded values
293  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) {
294  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>';
295  } elseif (!empty($object->mail) && empty($object->array_options['options_datapolicy_send']) && $parameters['currentcontext'] == 'membercard') {
296  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>';
297  } elseif (!empty($object->mail) && empty($object->array_options['options_datapolicy_send']) && $parameters['currentcontext'] == 'contactcard') {
298  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>';
299  }
300  }
301  }
302 
312  public function printCommonFooter($parameters, &$object, &$action, $hookmanager)
313  {
314  global $conf, $user, $langs;
315 
316  $jsscript = '';
317  if ($parameters['currentcontext'] == 'thirdpartycard') {
318  if (GETPOST('action') == 'create' || GETPOST('action') == 'edit' || GETPOST('action') == '') {
319  $jsscript .= '<script>';
320  $jsscript .= "var elementToHide = 'tr.societe_extras_datapolicy_consentement, tr.societe_extras_datapolicy_opposition_traitement, tr.societe_extras_datapolicy_opposition_prospection';".PHP_EOL;
321  $jsscript .= "var forme_juridique = [".PHP_EOL;
322  $jsscript .= "11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005".PHP_EOL;
323  $jsscript .= "];".PHP_EOL;
324  $jsscript .= "function hideRgPD() {".PHP_EOL;
325  $jsscript .= " if ($('#typent_id').val() == 8 || forme_juridique.indexOf(parseInt($('#forme_juridique_code').val())) > -1) {".PHP_EOL;
326  $jsscript .= " console.log(elementToHide);".PHP_EOL;
327  $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;
328  $jsscript .= "hideRgPD();".PHP_EOL;
329  $jsscript .= "$('#forme_juridique_code, #typent_id').change(function(){ hideRgPD(); });".PHP_EOL;
330  $jsscript .= '</script>';
331  } elseif (GETPOST('action') == 'confirm_delete' && GETPOST('confirm') == 'yes' && GETPOST('socid') > 0) {
332  // La suppression n'a pas été possible
333  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
334  $societe = new Societe($this->db);
335  $societe->fetch(GETPOST('socid'));
336  // On vérifie si il est utilisé
337  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'))) {
338  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
339  $form = new Form($this->db);
340  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);
341  }
342  }
343 
344  if (GETPOST('socid')) {
345  /* Removed due to awful harcoded values
346  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
347  $societe = new Societe($this->db);
348  $societe->fetch(GETPOST('socid'));
349 
350  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) {
351  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
352  $jsscript .= '<script>';
353  $jsscript .= "var elementToHide = 'td.societe_extras_datapolicy_opposition_traitement, td.societe_extras_datapolicy_opposition_prospection, td.societe_extras_datapolicy_consentement';".PHP_EOL;
354  $jsscript .= "$(elementToHide).parent('tr').hide();".PHP_EOL;
355  $jsscript .= '</script>';
356  }
357  */
358  }
359  } elseif ($parameters['currentcontext'] == 'contactcard') {
360  if (GETPOST('action') == 'create' || GETPOST('action') == 'edit') {
361  $jsscript .= '<script>';
362  $jsscript .= "$('#options_datapolicy_opposition_traitement, #options_datapolicy_opposition_prospection, input[name=\"options_datapolicy_opposition_traitement\"], input[name=\"options_datapolicy_opposition_prospection\"]').change(function(){
363  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')) {
364  $('#no_email').val(1);
365  }
366  });";
367  $jsscript .= '</script>';
368  }
369  }
370 
371  $this->resprints = $jsscript;
372 
373  return 0;
374  }
375 }
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
Parent class of all other hook actions classes.
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(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.