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