dolibarr 18.0.6
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_alias = '';
107 $object->address = '';
108 $object->town = '';
109 $object->zip = '';
110 $object->phone = '';
111 $object->email = '';
112 $object->url = '';
113 $object->fax = '';
114 $object->state = '';
115 $object->country = '';
116 $object->state_id = '';
117 $object->socialnetworks = '';
118 $object->country_id = '';
119 $object->note_private = dol_concatdesc($object->note_private, $langs->trans('ANONYMISER_AT', dol_print_date(dol_now())));
120
121 if ($object->update($object->id, $user, 0)) {
122 // On supprime les contacts associé
123 $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".((int) $object->id);
124 $this->db->query($sql);
125
126 setEventMessages($langs->trans('ANONYMISER_SUCCESS'), array());
127 header('Location:'.$_SERVER["PHP_SELF"]."?socid=".$object->id);
128 }
129 }
130 } elseif ($parameters['currentcontext'] == 'contactcard' && $action == 'send_datapolicy') {
131 $object->fetch(GETPOST('id'));
132
133 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
134 require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicy.class.php';
136 } elseif ($parameters['currentcontext'] == 'membercard' && $action == 'send_datapolicy') {
137 $object->fetch(GETPOST('id'));
138 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
139 require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicy.class.php';
141 } elseif ($parameters['currentcontext'] == 'thirdpartycard' && $action == 'send_datapolicy') {
142 $object->fetch(GETPOST('socid'));
143 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
144 require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicy.class.php';
146 }
147
148
149 if (!$error) {
150 $this->results = array('myreturn' => 999);
151 $this->resprints = 'A text to show';
152 return 0; // or return 1 to replace standard code
153 } else {
154 $this->errors[] = 'Error message';
155 return -1;
156 }
157 }
158
168 public function doMassActions($parameters, &$object, &$action, $hookmanager)
169 {
170 global $conf, $user, $langs;
171
172 $error = 0; // Error counter
173
174 /* print_r($parameters); print_r($object); echo "action: " . $action; */
175 //if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) {
176 // // do something only for the context 'somecontext1' or 'somecontext2'
177 // foreach ($parameters['toselect'] as $objectid) {
178 // // Do action on each object id
179 // }
180 //}
181
182 if (!$error) {
183 $this->results = array('myreturn' => 999);
184 $this->resprints = 'A text to show';
185 return 0; // or return 1 to replace standard code
186 } else {
187 $this->errors[] = 'Error message';
188 return -1;
189 }
190 }
191
201 public function addMoreMassActions($parameters, &$object, &$action, $hookmanager)
202 {
203 global $conf, $user, $langs;
204
205 $error = 0; // Error counter
206
207 /* print_r($parameters); print_r($object); echo "action: " . $action; */
208 if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
209 $this->resprints = '<option value="0"'.($disabled ? ' disabled="disabled"' : '').'>'.$langs->trans("datapolicyMassAction").'</option>';
210 }
211
212 if (!$error) {
213 return 0; // or return 1 to replace standard code
214 } else {
215 $this->errors[] = 'Error message';
216 return -1;
217 }
218 }
219
230 public function beforePDFCreation($parameters, &$object, &$action)
231 {
232 global $conf, $user, $langs;
233 global $hookmanager;
234
235 $outputlangs = $langs;
236
237 $ret = 0;
238 $deltemp = array();
239 dol_syslog(get_class($this).'::executeHooks action='.$action);
240
241 /* print_r($parameters); print_r($object); echo "action: " . $action; */
242 if (in_array($parameters['currentcontext'], array('somecontext1', 'somecontext2'))) { // do something only for the context 'somecontext1' or 'somecontext2'
243 }
244
245 return $ret;
246 }
247
248
258 public function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager)
259 {
260 global $conf, $user, $langs;
261 $langs->load('datapolicy@datapolicy');
262
263 if (!empty($conf->global->DATAPOLICY_ENABLE_EMAILS)) {
264 $dialog = '<div id="dialogdatapolicy" style="display:none;" title="'.$langs->trans('DATAPOLICY_PORTABILITE_TITLE').'">';
265 $dialog .= '<div class="confirmmessage">'.img_help('', '').' '.$langs->trans('DATAPOLICY_PORTABILITE_CONFIRMATION').'</div>';
266 $dialog .= "</div>";
267 $dialog .= '<script>
268 $( function() {
269 $("#rpgpdbtn").on("click", function(){
270 var href = $(this).attr("href");
271 $( "#dialogdatapolicy" ).dialog({
272 modal: true,
273 buttons: {
274 "OK": function() {
275 window.open(href);
276 $( this ).dialog( "close" );
277 },
278 "' . $langs->trans("Cancel").'": function() {
279 $( this ).dialog( "close" );
280 }
281 }
282 });
283
284
285 return false;
286 });
287 } );
288 </script>';
289 echo $dialog;
290 // TODO Replace test of hardcoded values
291 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) {
292 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>';
293 } elseif (!empty($object->mail) && empty($object->array_options['options_datapolicy_send']) && $parameters['currentcontext'] == 'membercard') {
294 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>';
295 } elseif (!empty($object->mail) && empty($object->array_options['options_datapolicy_send']) && $parameters['currentcontext'] == 'contactcard') {
296 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>';
297 }
298 }
299 }
300
310 public function printCommonFooter($parameters, &$object, &$action, $hookmanager)
311 {
312 global $conf, $user, $langs;
313
314 $jsscript = '';
315 if ($parameters['currentcontext'] == 'thirdpartycard') {
316 if (GETPOST('action') == 'create' || GETPOST('action') == 'edit' || GETPOST('action') == '') {
317 $jsscript .= '<script>';
318 $jsscript .= "var elementToHide = 'tr.societe_extras_datapolicy_consentement, tr.societe_extras_datapolicy_opposition_traitement, tr.societe_extras_datapolicy_opposition_prospection';".PHP_EOL;
319 $jsscript .= "var forme_juridique = [".PHP_EOL;
320 $jsscript .= "11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005".PHP_EOL;
321 $jsscript .= "];".PHP_EOL;
322 $jsscript .= "function hideRgPD() {".PHP_EOL;
323 $jsscript .= " if ($('#typent_id').val() == 8 || forme_juridique.indexOf(parseInt($('#forme_juridique_code').val())) > -1) {".PHP_EOL;
324 $jsscript .= " console.log(elementToHide);".PHP_EOL;
325 $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;
326 $jsscript .= "hideRgPD();".PHP_EOL;
327 $jsscript .= "$('#forme_juridique_code, #typent_id').change(function(){ hideRgPD(); });".PHP_EOL;
328 $jsscript .= '</script>';
329 } elseif (GETPOST('action') == 'confirm_delete' && GETPOST('confirm') == 'yes' && GETPOST('socid') > 0) {
330 // La suppression n'a pas été possible
331 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
332 $societe = new Societe($this->db);
333 $societe->fetch(GETPOST('socid'));
334 // On vérifie si il est utilisé
335 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'))) {
336 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
337 $form = new Form($this->db);
338 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);
339 }
340 }
341
342 if (GETPOST('socid')) {
343 /* Removed due to awful harcoded values
344 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
345 $societe = new Societe($this->db);
346 $societe->fetch(GETPOST('socid'));
347
348 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) {
349 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
350 $jsscript .= '<script>';
351 $jsscript .= "var elementToHide = 'td.societe_extras_datapolicy_opposition_traitement, td.societe_extras_datapolicy_opposition_prospection, td.societe_extras_datapolicy_consentement';".PHP_EOL;
352 $jsscript .= "$(elementToHide).parent('tr').hide();".PHP_EOL;
353 $jsscript .= '</script>';
354 }
355 */
356 }
357 } elseif ($parameters['currentcontext'] == 'contactcard') {
358 if (GETPOST('action') == 'create' || GETPOST('action') == 'edit') {
359 $jsscript .= '<script>';
360 $jsscript .= "$('#options_datapolicy_opposition_traitement, #options_datapolicy_opposition_prospection, input[name=\"options_datapolicy_opposition_traitement\"], input[name=\"options_datapolicy_opposition_prospection\"]').change(function(){
361 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')) {
362 $('#no_email').val(1);
363 }
364 });";
365 $jsscript .= '</script>';
366 }
367 }
368
369 $this->resprints = $jsscript;
370
371 return 0;
372 }
373}
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.
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...)
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.