dolibarr  16.0.5
emailcollector_card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2022 Charlene Benke <charlene@patas-monkey.com>
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 '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php';
29 
30 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
31 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32 include_once DOL_DOCUMENT_ROOT.'/emailcollector/class/emailcollector.class.php';
33 include_once DOL_DOCUMENT_ROOT.'/emailcollector/class/emailcollectorfilter.class.php';
34 include_once DOL_DOCUMENT_ROOT.'/emailcollector/class/emailcollectoraction.class.php';
35 include_once DOL_DOCUMENT_ROOT.'/emailcollector/lib/emailcollector.lib.php';
36 
37 if (!$user->admin) {
39 }
40 if (empty($conf->emailcollector->enabled)) {
42 }
43 
44 // Load traductions files required by page
45 $langs->loadLangs(array("admin", "mails", "other"));
46 
47 // Get parameters
48 $id = GETPOST('id', 'int');
49 $ref = GETPOST('ref', 'alpha');
50 $action = GETPOST('action', 'aZ09');
51 $confirm = GETPOST('confirm', 'alpha');
52 $cancel = GETPOST('cancel', 'aZ09');
53 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'emailcollectorcard'; // To manage different context of search
54 $backtopage = GETPOST('backtopage', 'alpha');
55 
56 $operationid = GETPOST('operationid', 'int');
57 
58 // Initialize technical objects
59 $object = new EmailCollector($db);
60 $extrafields = new ExtraFields($db);
61 $diroutputmassaction = $conf->emailcollector->dir_output.'/temp/massgeneration/'.$user->id;
62 $hookmanager->initHooks(array('emailcollectorcard')); // Note that conf->hooks_modules contains array
63 
64 // Fetch optionals attributes and labels
65 $extrafields->fetch_name_optionals_label($object->table_element);
66 
67 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
68 
69 // Initialize array of search criterias
70 $search_all = GETPOST("search_all", 'alpha');
71 $search = array();
72 foreach ($object->fields as $key => $val) {
73  if (GETPOST('search_'.$key, 'alpha')) {
74  $search[$key] = GETPOST('search_'.$key, 'alpha');
75  }
76 }
77 
78 if (GETPOST('saveoperation2')) {
79  $action = 'updateoperation';
80 }
81 if (empty($action) && empty($id) && empty($ref)) {
82  $action = 'view';
83 }
84 
85 // Load object
86 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
87 
88 // Security check - Protection if external user
89 //if ($user->socid > 0) accessforbidden();
90 //if ($user->socid > 0) $socid = $user->socid;
91 //$isdraft = (($object->statut == MyObject::STATUS_DRAFT) ? 1 : 0);
92 //$result = restrictedArea($user, 'mymodule', $object->id, '', '', 'fk_soc', 'rowid', $isdraft);
93 
94 $permissionnote = $user->rights->emailcollector->write; // Used by the include of actions_setnotes.inc.php
95 $permissiondellink = $user->rights->emailcollector->write; // Used by the include of actions_dellink.inc.php
96 $permissiontoadd = $user->rights->emailcollector->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
97 
98 $debuginfo = '';
99 
100 
101 /*
102  * Actions
103  */
104 
105 $parameters = array();
106 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
107 
108 if ($reshook < 0) {
109  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
110 }
111 
112 if (empty($reshook)) {
113  $error = 0;
114 
115  $permissiontoadd = 1;
116  $permissiontodelete = 1;
117  if (empty($backtopage)) {
118  $backtopage = DOL_URL_ROOT.'/admin/emailcollector_card.php?id='.($id > 0 ? $id : '__ID__');
119  }
120  $backurlforlist = DOL_URL_ROOT.'/admin/emailcollector_list.php';
121 
122  // Actions cancel, add, update, delete or clone
123  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
124 
125  // Actions when linking object each other
126  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
127 
128  // Actions when printing a doc from card
129  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
130 }
131 
132 if (GETPOST('addfilter', 'alpha')) {
133  $emailcollectorfilter = new EmailCollectorFilter($db);
134  $emailcollectorfilter->type = GETPOST('filtertype', 'aZ09');
135  $emailcollectorfilter->rulevalue = GETPOST('rulevalue', 'alpha');
136  $emailcollectorfilter->fk_emailcollector = $object->id;
137  $emailcollectorfilter->status = 1;
138  $result = $emailcollectorfilter->create($user);
139 
140  if ($result > 0) {
141  $object->fetchFilters();
142  } else {
143  setEventMessages($emailcollectorfilter->errors, $emailcollectorfilter->error, 'errors');
144  }
145 }
146 
147 if ($action == 'deletefilter') {
148  $emailcollectorfilter = new EmailCollectorFilter($db);
149  $emailcollectorfilter->fetch(GETPOST('filterid', 'int'));
150  if ($emailcollectorfilter->id > 0) {
151  $result = $emailcollectorfilter->delete($user);
152  if ($result > 0) {
153  $object->fetchFilters();
154  } else {
155  setEventMessages($emailcollectorfilter->errors, $emailcollectorfilter->error, 'errors');
156  }
157  }
158 }
159 
160 if (GETPOST('addoperation', 'alpha')) {
161  $emailcollectoroperation = new EmailCollectorAction($db);
162  $emailcollectoroperation->type = GETPOST('operationtype', 'aZ09');
163  $emailcollectoroperation->actionparam = GETPOST('operationparam', 'restricthtml');
164  $emailcollectoroperation->fk_emailcollector = $object->id;
165  $emailcollectoroperation->status = 1;
166  $emailcollectoroperation->position = 50;
167 
168  if ($emailcollectoroperation->type == '-1') {
169  $error++;
170  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Operation")), null, 'errors');
171  }
172 
173  if (in_array($emailcollectoroperation->type, array('loadthirdparty', 'loadandcreatethirdparty'))
174  && empty($emailcollectoroperation->actionparam)) {
175  $error++;
176  setEventMessages($langs->trans("ErrorAParameterIsRequiredForThisOperation"), null, 'errors');
177  }
178 
179  if (!$error) {
180  $result = $emailcollectoroperation->create($user);
181 
182  if ($result > 0) {
183  $object->fetchActions();
184  } else {
185  $error++;
186  setEventMessages($emailcollectoroperation->errors, $emailcollectoroperation->error, 'errors');
187  }
188  }
189 }
190 
191 if ($action == 'updateoperation') {
192  $emailcollectoroperation = new EmailCollectorAction($db);
193  $emailcollectoroperation->fetch(GETPOST('rowidoperation2', 'int'));
194 
195  $emailcollectoroperation->actionparam = GETPOST('operationparam2', 'restricthtml');
196 
197  if (in_array($emailcollectoroperation->type, array('loadthirdparty', 'loadandcreatethirdparty'))
198  && empty($emailcollectoroperation->actionparam)) {
199  $error++;
200  setEventMessages($langs->trans("ErrorAParameterIsRequiredForThisOperation"), null, 'errors');
201  }
202 
203  if (!$error) {
204  $result = $emailcollectoroperation->update($user);
205 
206  if ($result > 0) {
207  $object->fetchActions();
208  } else {
209  $error++;
210  setEventMessages($emailcollectoroperation->errors, $emailcollectoroperation->error, 'errors');
211  }
212  }
213 }
214 if ($action == 'deleteoperation') {
215  $emailcollectoroperation = new EmailCollectorAction($db);
216  $emailcollectoroperation->fetch(GETPOST('operationid', 'int'));
217  if ($emailcollectoroperation->id > 0) {
218  $result = $emailcollectoroperation->delete($user);
219  if ($result > 0) {
220  $object->fetchActions();
221  } else {
222  setEventMessages($emailcollectoroperation->errors, $emailcollectoroperation->error, 'errors');
223  }
224  }
225 }
226 
227 if ($action == 'confirm_collect') {
228  dol_include_once('/emailcollector/class/emailcollector.class.php');
229 
230  $res = $object->doCollectOneCollector();
231  if ($res > 0) {
232  $debuginfo = $object->debuginfo;
233  setEventMessages($object->lastresult, null, 'mesgs');
234  } else {
235  $debuginfo = $object->debuginfo;
236  setEventMessages($object->error, null, 'errors');
237  }
238 
239  $action = '';
240 }
241 
242 
243 
244 /*
245  * View
246  */
247 
248 $form = new Form($db);
249 $formfile = new FormFile($db);
250 
251 $help_url = "EN:Module_EMail_Collector|FR:Module_Collecteur_de_courrier_électronique|ES:Module_EMail_Collector";
252 
253 llxHeader('', 'EmailCollector', $help_url);
254 
255 // Part to create
256 if ($action == 'create') {
257  print load_fiche_titre($langs->trans("NewEmailCollector", $langs->transnoentitiesnoconv("EmailCollector")));
258 
259  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
260  print '<input type="hidden" name="token" value="'.newToken().'">';
261  print '<input type="hidden" name="action" value="add">';
262  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
263 
264  print dol_get_fiche_head(array(), '');
265 
266  print '<table class="border centpercent tableforfield">'."\n";
267 
268  //unset($fields[]);
269 
270  // Common attributes
271  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
272 
273  // Other attributes
274  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
275 
276  print '</table>'."\n";
277 
278  print dol_get_fiche_end();
279 
280  print $form->buttonsSaveCancel("Create");
281 
282  print '</form>';
283 }
284 
285 // Part to edit record
286 if (($id || $ref) && $action == 'edit') {
287  print load_fiche_titre($langs->trans("EmailCollector"));
288 
289  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
290  print '<input type="hidden" name="token" value="'.newToken().'">';
291  print '<input type="hidden" name="action" value="update">';
292  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
293  print '<input type="hidden" name="id" value="'.$object->id.'">';
294 
295  print dol_get_fiche_head();
296 
297  print '<table class="border centpercent tableforfield">'."\n";
298 
299  // Common attributes
300  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
301 
302  // Other attributes
303  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
304 
305  print '</table>';
306 
307  print dol_get_fiche_end();
308 
309  print $form->buttonsSaveCancel();
310 
311  print '</form>';
312 }
313 
314 // Part to show record
315 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
316  $res = $object->fetch_optionals();
317 
318  $object->fetchFilters();
319  $object->fetchActions();
320 
321  $head = emailcollectorPrepareHead($object);
322  print dol_get_fiche_head($head, 'card', $langs->trans("EmailCollector"), -1, 'email');
323 
324  $formconfirm = '';
325 
326  // Confirmation to delete
327  if ($action == 'delete') {
328  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteEmailCollector'), $langs->trans('ConfirmDeleteEmailCollector'), 'confirm_delete', '', 0, 1);
329  }
330 
331  // Clone confirmation
332  if ($action == 'clone') {
333  // Create an array for form
334  $formquestion = array();
335  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneEmailCollector', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
336  }
337 
338  // Confirmation of action process
339  if ($action == 'collect') {
340  $formquestion = array(
341  'text' => $langs->trans("EmailCollectorConfirmCollect"),
342  );
343  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('EmailCollectorConfirmCollectTitle'), $text, 'confirm_collect', $formquestion, 0, 1, 220);
344  }
345 
346  // Call Hook formConfirm
347  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
348  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
349  if (empty($reshook)) {
350  $formconfirm .= $hookmanager->resPrint;
351  } elseif ($reshook > 0) {
352  $formconfirm = $hookmanager->resPrint;
353  }
354 
355  // Print form confirm
356  print $formconfirm;
357 
358  // Object card
359  // ------------------------------------------------------------
360  $linkback = '<a href="'.DOL_URL_ROOT.'/admin/emailcollector_list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
361 
362  $morehtmlref = '<div class="refidno">';
363  $morehtmlref .= '</div>';
364 
365  $morehtml = $langs->trans("NbOfEmailsInInbox").' : ';
366 
367  $sourcedir = $object->source_directory;
368  $targetdir = ($object->target_directory ? $object->target_directory : ''); // Can be '[Gmail]/Trash' or 'mytag'
369 
370  $connection = null;
371  $connectstringserver = '';
372  $connectstringsource = '';
373  $connectstringtarget = '';
374 
375  if (function_exists('imap_open')) {
376  // Note: $object->host has been loaded by the fetch
377  $usessl = 1;
378 
379  $connectstringserver = $object->getConnectStringIMAP($usessl);
380 
381  if ($action == 'scan') {
382  try {
383  if ($sourcedir) {
384  //$connectstringsource = $connectstringserver.imap_utf7_encode($sourcedir);
385  $connectstringsource = $connectstringserver.$object->getEncodedUtf7($sourcedir);
386  }
387  if ($targetdir) {
388  //$connectstringtarget = $connectstringserver.imap_utf7_encode($targetdir);
389  $connectstringtarget = $connectstringserver.$object->getEncodedUtf7($targetdir);
390  }
391 
392  $timeoutconnect = empty($conf->global->MAIN_USE_CONNECT_TIMEOUT) ? 5 : $conf->global->MAIN_USE_CONNECT_TIMEOUT;
393  $timeoutread = empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT) ? 20 : $conf->global->MAIN_USE_RESPONSE_TIMEOUT;
394 
395  dol_syslog("imap_open connectstring=".$connectstringsource." login=".$object->login." password=".$object->password." timeoutconnect=".$timeoutconnect." timeoutread=".$timeoutread);
396 
397  $result1 = imap_timeout(IMAP_OPENTIMEOUT, $timeoutconnect); // timeout seems ignored with ssl connect
398  $result2 = imap_timeout(IMAP_READTIMEOUT, $timeoutread);
399  $result3 = imap_timeout(IMAP_WRITETIMEOUT, 5);
400  $result4 = imap_timeout(IMAP_CLOSETIMEOUT, 5);
401 
402  dol_syslog("result1=".$result1." result2=".$result2." result3=".$result3." result4=".$result4);
403 
404  $connection = imap_open($connectstringsource, $object->login, $object->password);
405 
406  //dol_syslog("end imap_open connection=".var_export($connection, true));
407  } catch (Exception $e) {
408  print $e->getMessage();
409  }
410 
411  if (!$connection) {
412  $morehtml .= 'Failed to open IMAP connection '.$connectstringsource;
413  if (function_exists('imap_last_error')) {
414  $morehtml .= '<br>'.imap_last_error();
415  }
416  dol_syslog("Error ".$morehtml, LOG_WARNING);
417  //var_dump(imap_errors())
418  } else {
419  dol_syslog("Imap connected. Now we call imap_num_msg()");
420  $morehtml .= imap_num_msg($connection);
421  }
422 
423  if ($connection) {
424  dol_syslog("Imap close");
425  imap_close($connection);
426  }
427  } else {
428  $morehtml .= '<a class="flat" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=scan&token='.newToken().'">'.img_picto('', 'refresh', 'class="paddingrightonly"').$langs->trans("Refresh").'</a>';
429  }
430 
431  $morehtml .= $form->textwithpicto('', 'connect string '.$connectstringserver);
432  } else {
433  $morehtml .= 'IMAP functions not available on your PHP. ';
434  }
435 
436  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref.'<div class="refidno">'.$morehtml.'</div>', '', 0, '', '', 0, '');
437 
438  print '<div class="fichecenter">';
439  print '<div class="fichehalfleft">';
440  print '<div class="underbanner clearboth"></div>';
441  print '<table class="border centpercent tableforfield">'."\n";
442 
443  // Common attributes
444  //$keyforbreak='fieldkeytoswithonsecondcolumn';
445  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
446 
447  // Other attributes
448  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
449 
450  print '</table>';
451 
452 
453  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
454  print '<input type="hidden" name="token" value="'.newToken().'">';
455  print '<input type="hidden" name="action" value="updatefiltersactions">';
456  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
457  print '<input type="hidden" name="id" value="'.$object->id.'">';
458 
459  // Filters
460  print '<div class="div-table-responsive-no-min">';
461  print '<table id="tablelineoffilters" class="noborder margintable noshadow">';
462  print '<tr class="liste_titre nodrag nodrop">';
463  print '<td>'.img_picto('', 'filter', 'class="pictofixedwidth opacitymedium"').$form->textwithpicto($langs->trans("Filters"), $langs->trans("EmailCollectorFilterDesc")).'</td><td></td><td></td>';
464  print '</tr>';
465  // Add filter
466  print '<tr class="oddeven nodrag nodrop">';
467  print '<td>';
468  $arrayoftypes = array(
469  'from'=>array('label'=>'MailFrom', 'data-placeholder'=>$langs->trans('SearchString')),
470  'to'=>array('label'=>'MailTo', 'data-placeholder'=>$langs->trans('SearchString')),
471  'cc'=>array('label'=>'Cc', 'data-placeholder'=>$langs->trans('SearchString')),
472  'bcc'=>array('label'=>'Bcc', 'data-placeholder'=>$langs->trans('SearchString')),
473  'subject'=>array('label'=>'Subject', 'data-placeholder'=>$langs->trans('SearchString')),
474  'body'=>array('label'=>'Body', 'data-placeholder'=>$langs->trans('SearchString')),
475  // disabled because PHP imap_search is not compatible IMAPv4, only IMAPv2
476  //'header'=>array('label'=>'Header', 'data-placeholder'=>'HeaderKey SearchString'), // HEADER key value
477  //'X1'=>'---',
478  //'notinsubject'=>array('label'=>'SubjectNotIn', 'data-placeholder'=>'SearchString'),
479  //'notinbody'=>array('label'=>'BodyNotIn', 'data-placeholder'=>'SearchString'),
480  'X2'=>'---',
481  'seen'=>array('label'=>'AlreadyRead', 'data-noparam'=>1),
482  'unseen'=>array('label'=>'NotRead', 'data-noparam'=>1),
483  'unanswered'=>array('label'=>'Unanswered', 'data-noparam'=>1),
484  'answered'=>array('label'=>'Answered', 'data-noparam'=>1),
485  'smaller'=>array('label'=>'SmallerThan', 'data-placeholder'=>$langs->trans('NumberOfBytes')),
486  'larger'=>array('label'=>'LargerThan', 'data-placeholder'=>$langs->trans('NumberOfBytes')),
487  'X3'=>'---',
488  'withtrackingid'=>array('label'=>'WithDolTrackingID', 'data-noparam'=>1),
489  'withouttrackingid'=>array('label'=>'WithoutDolTrackingID', 'data-noparam'=>1),
490  'withtrackingidinmsgid'=>array('label'=>'WithDolTrackingIDInMsgId', 'data-noparam'=>1),
491  'withouttrackingidinmsgid'=>array('label'=>'WithoutDolTrackingIDInMsgId', 'data-noparam'=>1),
492  'X4'=>'---',
493  'isnotanswer'=>array('label'=>'IsNotAnAnswer', 'data-noparam'=>1),
494  'isanswer'=>array('label'=>'IsAnAnswer', 'data-noparam'=>1)
495  );
496  print $form->selectarray('filtertype', $arrayoftypes, '', 1, 0, 0, '', 1, 0, 0, '', 'maxwidth300', 1, '', 2);
497 
498  print "\n";
499  print '<script>';
500  print 'jQuery("#filtertype").change(function() {
501  console.log("We change a filter");
502  if (jQuery("#filtertype option:selected").attr("data-noparam")) {
503  jQuery("#rulevalue").attr("placeholder", "");
504  jQuery("#rulevalue").text(""); jQuery("#rulevalue").prop("disabled", true);
505  }
506  else { jQuery("#rulevalue").prop("disabled", false); }
507  jQuery("#rulevalue").attr("placeholder", (jQuery("#filtertype option:selected").attr("data-placeholder")));
508  ';
509  /*$noparam = array();
510  foreach ($arrayoftypes as $key => $value)
511  {
512  if ($value['noparam']) $noparam[] = $key;
513  }*/
514  print '})';
515  print '</script>'."\n";
516 
517  print '</td><td>';
518  print '<input type="text" name="rulevalue" id="rulevalue">';
519  print '</td>';
520  print '<td class="right"><input type="submit" name="addfilter" id="addfilter" class="flat button small" value="'.$langs->trans("Add").'"></td>';
521  print '</tr>';
522  // List filters
523  foreach ($object->filters as $rulefilter) {
524  $rulefilterobj = new EmailCollectorFilter($db);
525  $rulefilterobj->fetch($rulefilter['id']);
526 
527  print '<tr class="oddeven">';
528  print '<td title="'.dol_escape_htmltag($langs->trans("Filter").': '.$rulefilter['type']).'">';
529  print $langs->trans($arrayoftypes[$rulefilter['type']]['label']);
530  print '</td>';
531  print '<td>'.$rulefilter['rulevalue'].'</td>';
532  print '<td class="right">';
533  print ' <a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deletefilter&token='.urlencode(newToken()).'&filterid='.$rulefilter['id'].'">'.img_delete().'</a>';
534  print '</td>';
535  print '</tr>';
536  }
537 
538  print '</tr>';
539  print '</table>';
540  print '</div>';
541 
542  print '<div class="clearboth"></div><br>';
543 
544  // Operations
545  print '<div class="div-table-responsive">';
546  print '<table id="tablelines" class="noborder margintable noshadow">';
547  print '<tr class="liste_titre nodrag nodrop">';
548  print '<td>'.img_picto('', 'technic', 'class="pictofixedwidth"').$form->textwithpicto($langs->trans("EmailcollectorOperations"), $langs->trans("EmailcollectorOperationsDesc")).'</td><td></td><td></td><td></td>';
549  print '</tr>';
550 
551  $arrayoftypes = array(
552  'loadthirdparty'=>$langs->trans('LoadThirdPartyFromName', $langs->transnoentities("ThirdPartyName")),
553  'loadandcreatethirdparty'=>$langs->trans('LoadThirdPartyFromNameOrCreate', $langs->transnoentities("ThirdPartyName")),
554  'recordjoinpiece'=>'AttachJoinedDocumentsToObject',
555  'recordevent'=>'RecordEvent');
556  $arrayoftypesnocondition = $arrayoftypes;
557  if (!empty($conf->project->enabled)) {
558  $arrayoftypes['project'] = 'CreateLeadAndThirdParty';
559  }
560  $arrayoftypesnocondition['project'] = 'CreateLeadAndThirdParty';
561  if (!empty($conf->ticket->enabled)) {
562  $arrayoftypes['ticket'] = 'CreateTicketAndThirdParty';
563  }
564  $arrayoftypesnocondition['ticket'] = 'CreateTicketAndThirdParty';
565  if (!empty($conf->recruitment->enabled)) {
566  $arrayoftypes['candidature'] = 'CreateCandidature';
567  }
568  $arrayoftypesnocondition['candidature'] = 'CreateCandidature';
569 
570  // support hook for add action
571  $parameters = array('arrayoftypes' => $arrayoftypes);
572  $res = $hookmanager->executeHooks('addMoreActionsEmailCollector', $parameters, $object, $action);
573 
574  if ($res) {
575  $arrayoftypes = $hookmanager->resArray;
576  } else {
577  foreach ($hookmanager->resArray as $k => $desc) {
578  $arrayoftypes[$k] = $desc;
579  }
580  }
581 
582  // Add operation
583  print '<tr class="oddeven nodrag nodrop">';
584  print '<td>';
585  print $form->selectarray('operationtype', $arrayoftypes, '', 1, 0, 0, '', 1, 0, 0, '', 'maxwidth300', 1);
586  print '</td><td>';
587  print '<input type="text" name="operationparam">';
588  print '</td>';
589  print '<td>';
590  $htmltext = $langs->transnoentitiesnoconv("OperationParamDesc");
591  print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'operationparamtt');
592  print '</td>';
593  print '<td class="right"><input type="submit" name="addoperation" id="addoperation" class="flat button small" value="'.$langs->trans("Add").'"></td>';
594  print '</tr>';
595  // List operations
596  $nboflines = count($object->actions);
597  $table_element_line = 'emailcollector_emailcollectoraction';
598  $fk_element = 'position';
599  $i = 0;
600  foreach ($object->actions as $ruleaction) {
601  $ruleactionobj = new EmailcollectorAction($db);
602  $ruleactionobj->fetch($ruleaction['id']);
603 
604  print '<tr class="drag drop oddeven" id="row-'.$ruleaction['id'].'">';
605  print '<td title="'.dol_escape_htmltag($langs->trans("Operation").': '.$ruleaction['type']).'">';
606  print '<!-- type of action: '.$ruleaction['type'].' -->';
607  if (array_key_exists($ruleaction['type'], $arrayoftypes)) {
608  print $langs->trans($arrayoftypes[$ruleaction['type']]);
609  } else {
610  if (array_key_exists($ruleaction['type'], $arrayoftypesnocondition)) {
611  print '<span class="opacitymedium">'.$langs->trans($arrayoftypesnocondition[$ruleaction['type']]).' - '.$langs->trans("Disabled").'</span>';
612  }
613  }
614 
615  if (in_array($ruleaction['type'], array('recordevent'))) {
616  print $form->textwithpicto('', $langs->transnoentitiesnoconv('IfTrackingIDFoundEventWillBeLinked'));
617  } elseif (in_array($ruleaction['type'], array('loadthirdparty', 'loadandcreatethirdparty'))) {
618  print $form->textwithpicto('', $langs->transnoentitiesnoconv('EmailCollectorLoadThirdPartyHelp'));
619  }
620  print '</td>';
621  print '<td class="wordbreak minwidth300 small">';
622  if ($action == 'editoperation' && $ruleaction['id'] == $operationid) {
623  print '<input type="text" class="quatrevingtquinzepercent" name="operationparam2" value="'.$ruleaction['actionparam'].'"><br>';
624  print '<input type="hidden" name="rowidoperation2" value="'.$ruleaction['id'].'">';
625  print '<input type="submit" class="button small button-save" name="saveoperation2" value="'.$langs->trans("Save").'">';
626  print '<input type="submit" class="button small button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
627  } else {
628  print $ruleaction['actionparam'];
629  }
630  print '</td>';
631  // Move up/down
632  print '<td class="center linecolmove tdlineupdown">';
633  if ($i > 0) {
634  print '<a class="lineupdown" href="'.$_SERVER['PHP_SELF'].'?action=up&amp;rowid='.$ruleaction['id'].'">'.img_up('default', 0, 'imgupforline').'</a>';
635  }
636  if ($i < count($object->actions) - 1) {
637  print '<a class="lineupdown" href="'.$_SERVER['PHP_SELF'].'?action=down&amp;rowid='.$ruleaction['id'].'">'.img_down('default', 0, 'imgdownforline').'</a>';
638  }
639  print '</td>';
640  // Delete
641  print '<td class="right nowraponall">';
642  print '<a class="editfielda marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editoperation&token='.newToken().'&operationid='.$ruleaction['id'].'">'.img_edit().'</a>';
643  print ' <a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deleteoperation&token='.newToken().'&operationid='.$ruleaction['id'].'">'.img_delete().'</a>';
644  print '</td>';
645  print '</tr>';
646  $i++;
647  }
648 
649  print '</tr>';
650  print '</table>';
651  print '</div>';
652 
653  if (!empty($conf->use_javascript_ajax)) {
654  $urltorefreshaftermove = DOL_URL_ROOT.'/admin/emailcollector_card.php?id='.$id;
655  include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
656  }
657 
658  print '</form>';
659 
660  print '</div>';
661  print '</div>'; // End <div class="fichecenter">
662 
663 
664  print '<div class="clearboth"></div><br>';
665 
666  print dol_get_fiche_end();
667 
668  // Buttons for actions
669  if ($action != 'presend' && $action != 'editline') {
670  print '<div class="tabsAction">'."\n";
671  $parameters = array();
672  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
673  if ($reshook < 0) {
674  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
675  }
676 
677  if (empty($reshook)) {
678  // Edit
679  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Edit").'</a></div>';
680 
681  // Clone
682  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken().'&object=order">'.$langs->trans("ToClone").'</a></div>';
683 
684  // Collect now
685  if (count($object->actions) > 0) {
686  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=collect&token='.newToken().'">'.$langs->trans("CollectNow").'</a></div>';
687  } else {
688  print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoOperations")).'">'.$langs->trans("CollectNow").'</a></div>';
689  }
690 
691  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.urlencode(newToken()).'">'.$langs->trans('Delete').'</a></div>';
692  }
693  print '</div>'."\n";
694  }
695 
696  if (!empty($debuginfo)) {
697  print info_admin($debuginfo);
698  }
699 }
700 
701 // End of page
702 llxFooter();
703 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
EmailCollectorAction
Class for EmailCollectorAction.
Definition: emailcollectoraction.class.php:33
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1033
EmailCollectorFilter
Class for EmailCollectorFilter.
Definition: emailcollectorfilter.class.php:33
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4389
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
img_up
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
Definition: functions.lib.php:4615
Exception
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4429
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:576
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
img_down
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
Definition: functions.lib.php:4596
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4800
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
EmailCollector
Class for EmailCollector.
Definition: emailcollector.class.php:49
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
emailcollectorPrepareHead
emailcollectorPrepareHead($object)
Prepare array of tabs for EmailCollector.
Definition: emailcollector.lib.php:31
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59