dolibarr 19.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-2023 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
24require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php';
25
30{
34 public $db;
35
39 public $error = '';
40
44 public $errors = array();
45
49 public $results = array();
50
54 public $resprints;
55
61 public function __construct($db)
62 {
63 $this->db = $db;
64 }
65
76 public function getNomUrl($parameters, &$object, &$action)
77 {
78 $this->resprints = '';
79
80 return 0;
81 }
82
92 public function doActions($parameters, &$object, &$action, $hookmanager)
93 {
94 global $user, $langs;
95
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 exit;
131 }
132 }
133 } elseif ($parameters['currentcontext'] == 'contactcard' && $action == 'send_datapolicy') {
134 $object->fetch(GETPOST('id'));
135
136 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
137 require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicy.class.php';
139 } elseif ($parameters['currentcontext'] == 'membercard' && $action == 'send_datapolicy') {
140 $object->fetch(GETPOST('id'));
141 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
142 require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicy.class.php';
144 } elseif ($parameters['currentcontext'] == 'thirdpartycard' && $action == 'send_datapolicy') {
145 $object->fetch(GETPOST('socid'));
146 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
147 require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicy.class.php';
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 addMoreActionsButtons($parameters, &$object, &$action, $hookmanager)
171 {
172 global $conf, $langs;
173 $langs->load('datapolicy@datapolicy');
174
175 if (getDolGlobalString('DATAPOLICY_ENABLE_EMAILS')) {
176 $dialog = '<div id="dialogdatapolicy" style="display:none;" title="'.$langs->trans('DATAPOLICY_PORTABILITE_TITLE').'">';
177 $dialog .= '<div class="confirmmessage">'.img_help('', '').' '.$langs->trans('DATAPOLICY_PORTABILITE_CONFIRMATION').'</div>';
178 $dialog .= "</div>";
179 $dialog .= '<script>
180 $( function() {
181 $("#rpgpdbtn").on("click", function(){
182 var href = $(this).attr("href");
183 $( "#dialogdatapolicy" ).dialog({
184 modal: true,
185 buttons: {
186 "OK": function() {
187 window.open(href);
188 $( this ).dialog( "close" );
189 },
190 "' . $langs->trans("Cancel").'": function() {
191 $( this ).dialog( "close" );
192 }
193 }
194 });
195
196
197 return false;
198 });
199 } );
200 </script>';
201 echo $dialog;
202 // TODO Replace test of hardcoded values
203 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) {
204 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>';
205 } elseif (!empty($object->mail) && empty($object->array_options['options_datapolicy_send']) && $parameters['currentcontext'] == 'membercard') {
206 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>';
207 } elseif (!empty($object->mail) && empty($object->array_options['options_datapolicy_send']) && $parameters['currentcontext'] == 'contactcard') {
208 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>';
209 }
210 }
211 }
212
222 public function printCommonFooter($parameters, &$object, &$action, $hookmanager)
223 {
224 global $langs;
225
226 $jsscript = '';
227 if ($parameters['currentcontext'] == 'thirdpartycard') {
228 if (GETPOST('action') == 'create' || GETPOST('action') == 'edit' || GETPOST('action') == '') {
229 $jsscript .= '<script>';
230 $jsscript .= "var elementToHide = 'tr.societe_extras_datapolicy_consentement, tr.societe_extras_datapolicy_opposition_traitement, tr.societe_extras_datapolicy_opposition_prospection';".PHP_EOL;
231 $jsscript .= "var forme_juridique = [".PHP_EOL;
232 $jsscript .= "11, 12, 13, 15, 17, 18, 19, 35, 60, 200, 311, 312, 316, 401, 600, 700, 1005".PHP_EOL;
233 $jsscript .= "];".PHP_EOL;
234 $jsscript .= "function hideRgPD() {".PHP_EOL;
235 $jsscript .= " if ($('#typent_id').val() == 8 || forme_juridique.indexOf(parseInt($('#forme_juridique_code').val())) > -1) {".PHP_EOL;
236 $jsscript .= " console.log(elementToHide);".PHP_EOL;
237 $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;
238 $jsscript .= "hideRgPD();".PHP_EOL;
239 $jsscript .= "$('#forme_juridique_code, #typent_id').change(function(){ hideRgPD(); });".PHP_EOL;
240 $jsscript .= '</script>';
241 } elseif (GETPOST('action') == 'confirm_delete' && GETPOST('confirm') == 'yes' && GETPOST('socid') > 0) {
242 // La suppression n'a pas été possible
243 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
244 $societe = new Societe($this->db);
245 $societe->fetch(GETPOST('socid'));
246 // On vérifie si il est utilisé
247 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'))) {
248 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
249 $form = new Form($this->db);
250 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);
251 }
252 }
253
254 if (GETPOST('socid')) {
255 /* Removed due to awful harcoded values
256 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
257 $societe = new Societe($this->db);
258 $societe->fetch(GETPOST('socid'));
259
260 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) {
261 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
262 $jsscript .= '<script>';
263 $jsscript .= "var elementToHide = 'td.societe_extras_datapolicy_opposition_traitement, td.societe_extras_datapolicy_opposition_prospection, td.societe_extras_datapolicy_consentement';".PHP_EOL;
264 $jsscript .= "$(elementToHide).parent('tr').hide();".PHP_EOL;
265 $jsscript .= '</script>';
266 }
267 */
268 }
269 } elseif ($parameters['currentcontext'] == 'contactcard') {
270 if (GETPOST('action') == 'create' || GETPOST('action') == 'edit') {
271 $jsscript .= '<script>';
272 $jsscript .= "$('#options_datapolicy_opposition_traitement, #options_datapolicy_opposition_prospection, input[name=\"options_datapolicy_opposition_traitement\"], input[name=\"options_datapolicy_opposition_prospection\"]').change(function(){
273 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')) {
274 $('#no_email').val(1);
275 }
276 });";
277 $jsscript .= '</script>';
278 }
279 }
280
281 $this->resprints = $jsscript;
282
283 return 0;
284 }
285}
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.
addMoreActionsButtons($parameters, &$object, &$action, $hookmanager)
addMoreActionsButtons
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...)
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.