emailcollector_card.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. /**
  18. * \file htdocs/admin/emailcollector_card.php
  19. * \ingroup emailcollector
  20. * \brief Page to create/edit/view emailcollector
  21. */
  22. require '../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php';
  26. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  27. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. include_once DOL_DOCUMENT_ROOT.'/emailcollector/class/emailcollector.class.php';
  29. include_once DOL_DOCUMENT_ROOT.'/emailcollector/class/emailcollectorfilter.class.php';
  30. include_once DOL_DOCUMENT_ROOT.'/emailcollector/class/emailcollectoraction.class.php';
  31. include_once DOL_DOCUMENT_ROOT.'/emailcollector/lib/emailcollector.lib.php';
  32. if (!$user->admin) accessforbidden();
  33. if (empty($conf->emailcollector->enabled)) accessforbidden();
  34. // Load traductions files required by page
  35. $langs->loadLangs(array("admin", "mails", "other"));
  36. // Get parameters
  37. $id = GETPOST('id', 'int');
  38. $ref = GETPOST('ref', 'alpha');
  39. $action = GETPOST('action', 'aZ09');
  40. $confirm = GETPOST('confirm', 'alpha');
  41. $cancel = GETPOST('cancel', 'aZ09');
  42. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search
  43. $backtopage = GETPOST('backtopage', 'alpha');
  44. $operationid = GETPOST('operationid', 'int');
  45. // Initialize technical objects
  46. $object = new EmailCollector($db);
  47. $extrafields = new ExtraFields($db);
  48. $diroutputmassaction = $conf->emailcollector->dir_output.'/temp/massgeneration/'.$user->id;
  49. $hookmanager->initHooks(array('emailcollectorcard')); // Note that conf->hooks_modules contains array
  50. // Fetch optionals attributes and labels
  51. $extrafields->fetch_name_optionals_label($object->table_element);
  52. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  53. // Initialize array of search criterias
  54. $search_all = GETPOST("search_all", 'alpha');
  55. $search = array();
  56. foreach ($object->fields as $key => $val) {
  57. if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha');
  58. }
  59. if (GETPOST('saveoperation2')) $action = 'updateoperation';
  60. if (empty($action) && empty($id) && empty($ref)) $action = 'view';
  61. // Load object
  62. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  63. // Security check - Protection if external user
  64. //if ($user->socid > 0) accessforbidden();
  65. //if ($user->socid > 0) $socid = $user->socid;
  66. //$isdraft = (($object->statut == MyObject::STATUS_DRAFT) ? 1 : 0);
  67. //$result = restrictedArea($user, 'mymodule', $object->id, '', '', 'fk_soc', 'rowid', $isdraft);
  68. $permissionnote = $user->rights->emailcollector->write; // Used by the include of actions_setnotes.inc.php
  69. $permissiondellink = $user->rights->emailcollector->write; // Used by the include of actions_dellink.inc.php
  70. $permissiontoadd = $user->rights->emailcollector->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  71. $debuginfo = '';
  72. /*
  73. * Actions
  74. */
  75. $parameters = array();
  76. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  77. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  78. if (empty($reshook))
  79. {
  80. $error = 0;
  81. $permissiontoadd = 1;
  82. $permissiontodelete = 1;
  83. if (empty($backtopage)) $backtopage = DOL_URL_ROOT.'/admin/emailcollector_card.php?id='.($id > 0 ? $id : '__ID__');
  84. $backurlforlist = DOL_URL_ROOT.'/admin/emailcollector_list.php';
  85. // Actions cancel, add, update, delete or clone
  86. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  87. // Actions when linking object each other
  88. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  89. // Actions when printing a doc from card
  90. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  91. }
  92. if (GETPOST('addfilter', 'alpha'))
  93. {
  94. $emailcollectorfilter = new EmailCollectorFilter($db);
  95. $emailcollectorfilter->type = GETPOST('filtertype', 'aZ09');
  96. $emailcollectorfilter->rulevalue = GETPOST('rulevalue', 'alpha');
  97. $emailcollectorfilter->fk_emailcollector = $object->id;
  98. $emailcollectorfilter->status = 1;
  99. $result = $emailcollectorfilter->create($user);
  100. if ($result > 0)
  101. {
  102. $object->fetchFilters();
  103. } else {
  104. setEventMessages($emailcollectorfilter->errors, $emailcollectorfilter->error, 'errors');
  105. }
  106. }
  107. if ($action == 'deletefilter')
  108. {
  109. $emailcollectorfilter = new EmailCollectorFilter($db);
  110. $emailcollectorfilter->fetch(GETPOST('filterid', 'int'));
  111. $result = $emailcollectorfilter->delete($user);
  112. if ($result > 0)
  113. {
  114. $object->fetchFilters();
  115. } else {
  116. setEventMessages($emailcollectorfilter->errors, $emailcollectorfilter->error, 'errors');
  117. }
  118. }
  119. if (GETPOST('addoperation', 'alpha'))
  120. {
  121. $emailcollectoroperation = new EmailCollectorAction($db);
  122. $emailcollectoroperation->type = GETPOST('operationtype', 'aZ09');
  123. $emailcollectoroperation->actionparam = GETPOST('operationparam', 'restricthtml');
  124. $emailcollectoroperation->fk_emailcollector = $object->id;
  125. $emailcollectoroperation->status = 1;
  126. $emailcollectoroperation->position = 50;
  127. $result = $emailcollectoroperation->create($user);
  128. if ($result > 0)
  129. {
  130. $object->fetchActions();
  131. } else {
  132. setEventMessages($emailcollectoroperation->errors, $emailcollectoroperation->error, 'errors');
  133. }
  134. }
  135. if ($action == 'updateoperation')
  136. {
  137. $emailcollectoroperation = new EmailCollectorAction($db);
  138. $emailcollectoroperation->fetch(GETPOST('rowidoperation2', 'int'));
  139. $emailcollectoroperation->actionparam = GETPOST('operationparam2', 'restricthtml');
  140. $result = $emailcollectoroperation->update($user);
  141. if ($result > 0)
  142. {
  143. $object->fetchActions();
  144. } else {
  145. setEventMessages($emailcollectoroperation->errors, $emailcollectoroperation->error, 'errors');
  146. }
  147. }
  148. if ($action == 'deleteoperation')
  149. {
  150. $emailcollectoroperation = new EmailCollectorAction($db);
  151. $emailcollectoroperation->fetch(GETPOST('operationid', 'int'));
  152. $result = $emailcollectoroperation->delete($user);
  153. if ($result > 0)
  154. {
  155. $object->fetchActions();
  156. } else {
  157. setEventMessages($emailcollectoroperation->errors, $emailcollectoroperation->error, 'errors');
  158. }
  159. }
  160. if ($action == 'confirm_collect')
  161. {
  162. dol_include_once('/emailcollector/class/emailcollector.class.php');
  163. $res = $object->doCollectOneCollector();
  164. if ($res > 0)
  165. {
  166. $debuginfo = $object->debuginfo;
  167. setEventMessages($object->lastresult, null, 'mesgs');
  168. } else {
  169. $debuginfo = $object->debuginfo;
  170. setEventMessages($object->error, null, 'errors');
  171. }
  172. $action = '';
  173. }
  174. /*
  175. * View
  176. */
  177. $form = new Form($db);
  178. $formfile = new FormFile($db);
  179. $help_url = "EN:Module_EMail_Collector|FR:Module_Collecteur_de_courrier_électronique|ES:Module_EMail_Collector";
  180. llxHeader('', 'EmailCollector', $help_url);
  181. // Example : Adding jquery code
  182. print '<script type="text/javascript" language="javascript">
  183. jQuery(document).ready(function() {
  184. function init_myfunc()
  185. {
  186. jQuery("#myid").removeAttr(\'disabled\');
  187. jQuery("#myid").attr(\'disabled\',\'disabled\');
  188. }
  189. init_myfunc();
  190. jQuery("#mybutton").click(function() {
  191. init_myfunc();
  192. });
  193. });
  194. </script>';
  195. // Part to create
  196. if ($action == 'create') {
  197. print load_fiche_titre($langs->trans("NewEmailCollector", $langs->transnoentitiesnoconv("EmailCollector")));
  198. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  199. print '<input type="hidden" name="token" value="'.newToken().'">';
  200. print '<input type="hidden" name="action" value="add">';
  201. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  202. dol_fiche_head(array(), '');
  203. print '<table class="border centpercent tableforfield">'."\n";
  204. //unset($fields[]);
  205. // Common attributes
  206. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  207. // Other attributes
  208. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  209. print '</table>'."\n";
  210. dol_fiche_end();
  211. print '<div class="center">';
  212. print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
  213. print '&nbsp; ';
  214. print '<input type="'.($backtopage ? "submit" : "button").'" class="button" 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
  215. print '</div>';
  216. print '</form>';
  217. }
  218. // Part to edit record
  219. if (($id || $ref) && $action == 'edit')
  220. {
  221. print load_fiche_titre($langs->trans("EmailCollector"));
  222. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  223. print '<input type="hidden" name="token" value="'.newToken().'">';
  224. print '<input type="hidden" name="action" value="update">';
  225. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  226. print '<input type="hidden" name="id" value="'.$object->id.'">';
  227. dol_fiche_head();
  228. print '<table class="border centpercent tableforfield">'."\n";
  229. // Common attributes
  230. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  231. // Other attributes
  232. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  233. print '</table>';
  234. dol_fiche_end();
  235. print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  236. print ' &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  237. print '</div>';
  238. print '</form>';
  239. }
  240. // Part to show record
  241. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create')))
  242. {
  243. $res = $object->fetch_optionals();
  244. $object->fetchFilters();
  245. $object->fetchActions();
  246. $head = emailcollectorPrepareHead($object);
  247. dol_fiche_head($head, 'card', $langs->trans("EmailCollector"), -1, 'email');
  248. $formconfirm = '';
  249. // Confirmation to delete
  250. if ($action == 'delete')
  251. {
  252. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteEmailCollector'), $langs->trans('ConfirmDeleteEmailCollector'), 'confirm_delete', '', 0, 1);
  253. }
  254. // Clone confirmation
  255. if ($action == 'clone') {
  256. // Create an array for form
  257. $formquestion = array();
  258. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneEmailCollector', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  259. }
  260. // Confirmation of action process
  261. if ($action == 'collect') {
  262. $formquestion = array(
  263. 'text' => $langs->trans("EmailCollectorConfirmCollect"),
  264. );
  265. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('EmailCollectorConfirmCollectTitle'), $text, 'confirm_collect', $formquestion, 0, 1, 220);
  266. }
  267. // Call Hook formConfirm
  268. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  269. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  270. if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
  271. elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
  272. // Print form confirm
  273. print $formconfirm;
  274. // Object card
  275. // ------------------------------------------------------------
  276. $linkback = '<a href="'.dol_buildpath('/admin/emailcollector_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  277. $morehtmlref = '<div class="refidno">';
  278. /*
  279. // Ref bis
  280. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->emailcollector->creer, 'string', '', 0, 1);
  281. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->emailcollector->creer, 'string', '', null, null, '', 1);
  282. // Thirdparty
  283. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
  284. // Project
  285. if (! empty($conf->projet->enabled))
  286. {
  287. $langs->load("projects");
  288. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  289. if ($user->rights->emailcollector->creer)
  290. {
  291. if ($action != 'classify')
  292. {
  293. $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  294. if ($action == 'classify') {
  295. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  296. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  297. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  298. $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
  299. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  300. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  301. $morehtmlref.='</form>';
  302. } else {
  303. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  304. }
  305. }
  306. } else {
  307. if (! empty($object->fk_project)) {
  308. $proj = new Project($db);
  309. $proj->fetch($object->fk_project);
  310. $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  311. $morehtmlref.=$proj->ref;
  312. $morehtmlref.='</a>';
  313. } else {
  314. $morehtmlref.='';
  315. }
  316. }
  317. }
  318. */
  319. $morehtmlref .= '</div>';
  320. $morehtml = $langs->trans("NbOfEmailsInInbox").' : ';
  321. $sourcedir = $object->source_directory;
  322. $targetdir = ($object->target_directory ? $object->target_directory : ''); // Can be '[Gmail]/Trash' or 'mytag'
  323. $connection = null;
  324. $connectstringserver = '';
  325. $connectstringsource = '';
  326. $connectstringtarget = '';
  327. if (function_exists('imap_open'))
  328. {
  329. $connectstringserver = $object->getConnectStringIMAP();
  330. try {
  331. if ($sourcedir) {
  332. //$connectstringsource = $connectstringserver.imap_utf7_encode($sourcedir);
  333. $connectstringsource = $connectstringserver.$object->getEncodedUtf7($sourcedir);
  334. }
  335. if ($targetdir) {
  336. //$connectstringtarget = $connectstringserver.imap_utf7_encode($targetdir);
  337. $connectstringtarget = $connectstringserver.$object->getEncodedUtf7($targetdir);
  338. }
  339. $connection = imap_open($connectstringsource, $object->login, $object->password);
  340. } catch (Exception $e)
  341. {
  342. print $e->getMessage();
  343. }
  344. $morehtml .= $form->textwithpicto('', 'connect string '.$connectstringserver);
  345. } else {
  346. $morehtml .= 'IMAP functions not available on your PHP';
  347. }
  348. if (!$connection)
  349. {
  350. $morehtml .= 'Failed to open IMAP connection '.$connectstringsource;
  351. } else {
  352. $morehtml .= imap_num_msg($connection);
  353. }
  354. if ($connection)
  355. {
  356. imap_close($connection);
  357. }
  358. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref.'<div class="refidno">'.$morehtml.'</div>', '', 0, '', '', 0, '');
  359. print '<div class="fichecenter">';
  360. print '<div class="fichehalfleft">';
  361. print '<div class="underbanner clearboth"></div>';
  362. print '<table class="border centpercent tableforfield">'."\n";
  363. // Common attributes
  364. //$keyforbreak='fieldkeytoswithonsecondcolumn';
  365. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  366. // Other attributes
  367. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  368. print '</table>';
  369. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  370. print '<input type="hidden" name="token" value="'.newToken().'">';
  371. print '<input type="hidden" name="action" value="updatefiltersactions">';
  372. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  373. print '<input type="hidden" name="id" value="'.$object->id.'">';
  374. // Filters
  375. print '<div class="div-table-responsive">';
  376. print '<table class="border centpercent tableforfield">';
  377. print '<tr class="liste_titre">';
  378. print '<td>'.$langs->trans("Filters").'</td><td></td><td></td>';
  379. print '</tr>';
  380. // Add filter
  381. print '<tr class="oddeven">';
  382. print '<td>';
  383. $arrayoftypes = array(
  384. 'from'=>array('label'=>'MailFrom', 'data-placeholder'=>$langs->trans('SearchString')),
  385. 'to'=>array('label'=>'MailTo', 'data-placeholder'=>$langs->trans('SearchString')),
  386. 'cc'=>array('label'=>'Cc', 'data-placeholder'=>$langs->trans('SearchString')),
  387. 'bcc'=>array('label'=>'Bcc', 'data-placeholder'=>$langs->trans('SearchString')),
  388. 'subject'=>array('label'=>'Subject', 'data-placeholder'=>$langs->trans('SearchString')),
  389. 'body'=>array('label'=>'Body', 'data-placeholder'=>$langs->trans('SearchString')),
  390. // disabled because PHP imap_search is not compatible IMAPv4, only IMAPv2
  391. //'header'=>array('label'=>'Header', 'data-placeholder'=>'HeaderKey SearchString'), // HEADER key value
  392. //'X1'=>'---',
  393. //'notinsubject'=>array('label'=>'SubjectNotIn', 'data-placeholder'=>'SearchString'),
  394. //'notinbody'=>array('label'=>'BodyNotIn', 'data-placeholder'=>'SearchString'),
  395. 'X2'=>'---',
  396. 'seen'=>array('label'=>'AlreadyRead', 'data-noparam'=>1),
  397. 'unseen'=>array('label'=>'NotRead', 'data-noparam'=>1),
  398. 'unanswered'=>array('label'=>'Unanswered', 'data-noparam'=>1),
  399. 'answered'=>array('label'=>'Answered', 'data-noparam'=>1),
  400. 'smaller'=>array('label'=>'SmallerThan', 'data-placeholder'=>$langs->trans('NumberOfBytes')),
  401. 'larger'=>array('label'=>'LargerThan', 'data-placeholder'=>$langs->trans('NumberOfBytes')),
  402. 'X3'=>'---',
  403. 'withtrackingid'=>array('label'=>'WithDolTrackingID', 'data-noparam'=>1),
  404. 'withouttrackingid'=>array('label'=>'WithoutDolTrackingID', 'data-noparam'=>1),
  405. 'X4'=>'---',
  406. 'isnotanswer'=>array('label'=>'IsNotAnAnswer', 'data-noparam'=>1),
  407. 'isanswer'=>array('label'=>'IsAnAnswer', 'data-noparam'=>1)
  408. );
  409. print $form->selectarray('filtertype', $arrayoftypes, '', 1, 0, 0, '', 1, 0, 0, '', 'maxwidth500', 0, '', 2);
  410. print "\n";
  411. print '<script>';
  412. print 'jQuery("#filtertype").change(function() {
  413. console.log("We change a filter");
  414. if (jQuery("#filtertype option:selected").attr("data-noparam")) {
  415. jQuery("#rulevalue").attr("placeholder", "");
  416. jQuery("#rulevalue").text(""); jQuery("#rulevalue").prop("disabled", true);
  417. }
  418. else { jQuery("#rulevalue").prop("disabled", false); }
  419. jQuery("#rulevalue").attr("placeholder", (jQuery("#filtertype option:selected").attr("data-placeholder")));
  420. ';
  421. /*$noparam = array();
  422. foreach ($arrayoftypes as $key => $value)
  423. {
  424. if ($value['noparam']) $noparam[] = $key;
  425. }*/
  426. print '})';
  427. print '</script>'."\n";
  428. print '</td><td>';
  429. print '<input type="text" name="rulevalue" id="rulevalue">';
  430. print '</td>';
  431. print '<td class="right"><input type="submit" name="addfilter" id="addfilter" class="flat button" value="'.$langs->trans("Add").'"></td>';
  432. print '</tr>';
  433. // List filters
  434. foreach ($object->filters as $rulefilter)
  435. {
  436. $rulefilterobj = new EmailCollectorFilter($db);
  437. $rulefilterobj->fetch($rulefilter['id']);
  438. print '<tr class="oddeven">';
  439. print '<td>';
  440. print $langs->trans($arrayoftypes[$rulefilter['type']]['label']);
  441. print '</td>';
  442. print '<td>'.$rulefilter['rulevalue'].'</td>';
  443. print '<td class="right">';
  444. print ' <a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deletefilter&filterid='.$rulefilter['id'].'">'.img_delete().'</a>';
  445. print '</td>';
  446. print '</tr>';
  447. }
  448. print '</tr>';
  449. print '</table>';
  450. print '</div>';
  451. print '<div class="clearboth"></div><br>';
  452. // Operations
  453. print '<div class="div-table-responsive">';
  454. print '<table id="tablelines" class="noborder noshadow tableforfield">';
  455. print '<tr class="liste_titre">';
  456. print '<td>'.$langs->trans("EmailcollectorOperations").'</td><td></td><td></td><td></td>';
  457. print '</tr>';
  458. // Add operation
  459. print '<tr class="oddeven">';
  460. print '<td>';
  461. $arrayoftypes = array(
  462. 'loadthirdparty'=>$langs->trans('LoadThirdPartyFromName', $langs->transnoentities("ThirdPartyName")),
  463. 'loadandcreatethirdparty'=>$langs->trans('LoadThirdPartyFromNameOrCreate', $langs->transnoentities("ThirdPartyName")),
  464. 'recordevent'=>'RecordEvent');
  465. if ($conf->projet->enabled) $arrayoftypes['project'] = 'CreateLeadAndThirdParty';
  466. if ($conf->ticket->enabled) $arrayoftypes['ticket'] = 'CreateTicketAndThirdParty';
  467. if ($conf->recruitment->enabled) $arrayoftypes['candidature'] = 'CreateCandidature';
  468. // support hook for add action
  469. $parameters = array('arrayoftypes' => $arrayoftypes);
  470. $res = $hookmanager->executeHooks('addMoreActionsEmailCollector', $parameters, $object, $action);
  471. if ($res)
  472. $arrayoftypes = $hookmanager->resArray;
  473. else foreach ($hookmanager->resArray as $k=>$desc)
  474. $arrayoftypes[$k] = $desc;
  475. print $form->selectarray('operationtype', $arrayoftypes, '', 1, 0, 0, '', 1, 0, 0, '', 'maxwidth300');
  476. print '</td><td>';
  477. print '<input type="text" name="operationparam">';
  478. print '</td>';
  479. print '<td>';
  480. $htmltext = $langs->transnoentitiesnoconv("OperationParamDesc");
  481. print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'operationparamtt');
  482. print '</td>';
  483. print '<td class="right"><input type="submit" name="addoperation" id="addoperation" class="flat button" value="'.$langs->trans("Add").'"></td>';
  484. print '</tr>';
  485. // List operations
  486. $nboflines = count($object->actions);
  487. $table_element_line = 'emailcollector_emailcollectoraction';
  488. $fk_element = 'position';
  489. $i = 0;
  490. foreach ($object->actions as $ruleaction)
  491. {
  492. $ruleactionobj = new EmailcollectorAction($db);
  493. $ruleactionobj->fetch($ruleaction['id']);
  494. print '<tr class="drag drop oddeven" id="row-'.$ruleaction['id'].'">';
  495. print '<td>';
  496. print '<!-- type of action: '.$ruleaction['type'].' -->';
  497. print $langs->trans($arrayoftypes[$ruleaction['type']]);
  498. if (in_array($ruleaction['type'], array('recordevent')))
  499. {
  500. print $form->textwithpicto('', $langs->transnoentitiesnoconv('IfTrackingIDFoundEventWillBeLinked'));
  501. } elseif (in_array($ruleaction['type'], array('loadthirdparty', 'loadandcreatethirdparty'))) {
  502. print $form->textwithpicto('', $langs->transnoentitiesnoconv('EmailCollectorLoadThirdPartyHelp'));
  503. }
  504. print '</td>';
  505. print '<td class="wordbreak">';
  506. if ($action == 'editoperation' && $ruleaction['id'] == $operationid)
  507. {
  508. print '<input type="text" class="quatrevingtquinzepercent" name="operationparam2" value="'.$ruleaction['actionparam'].'"><br>';
  509. print '<input type="hidden" name="rowidoperation2" value="'.$ruleaction['id'].'"><br>';
  510. print '<input type="submit" class="button" name="saveoperation2" value="'.$langs->trans("Save").'"> <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  511. } else {
  512. print $ruleaction['actionparam'];
  513. }
  514. print '</td>';
  515. // Move up/down
  516. print '<td class="center linecolmove tdlineupdown">';
  517. if ($i > 0)
  518. {
  519. print '<a class="lineupdown" href="'.$_SERVER['PHP_SELF'].'?action=up&amp;rowid='.$ruleaction['id'].'">'.img_up('default', 0, 'imgupforline').'</a>';
  520. }
  521. if ($i < count($object->actions) - 1) {
  522. print '<a class="lineupdown" href="'.$_SERVER['PHP_SELF'].'?action=down&amp;rowid='.$ruleaction['id'].'">'.img_down('default', 0, 'imgdownforline').'</a>';
  523. }
  524. print '</td>';
  525. // Delete
  526. print '<td class="right nowraponall">';
  527. print '<a class="editfielda marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editoperation&operationid='.$ruleaction['id'].'">'.img_edit().'</a>';
  528. print ' <a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deleteoperation&operationid='.$ruleaction['id'].'">'.img_delete().'</a>';
  529. print '</td>';
  530. print '</tr>';
  531. $i++;
  532. }
  533. print '</tr>';
  534. print '</table>';
  535. print '</div>';
  536. if (!empty($conf->use_javascript_ajax)) {
  537. $urltorefreshaftermove = DOL_URL_ROOT.'/admin/emailcollector_card.php?id='.$id;
  538. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  539. }
  540. print '</form>';
  541. print '</div>';
  542. print '</div>'; // End <div class="fichecenter">
  543. print '<div class="clearboth"></div><br>';
  544. dol_fiche_end();
  545. // Buttons for actions
  546. if ($action != 'presend' && $action != 'editline') {
  547. print '<div class="tabsAction">'."\n";
  548. $parameters = array();
  549. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  550. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  551. if (empty($reshook))
  552. {
  553. // Edit
  554. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Edit").'</a></div>';
  555. // Clone
  556. 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>';
  557. // Collect now
  558. if (count($object->actions) > 0) {
  559. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=collect">'.$langs->trans("CollectNow").'</a></div>';
  560. } else {
  561. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoOperations")).'">'.$langs->trans("CollectNow").'</a></div>';
  562. }
  563. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a></div>';
  564. }
  565. print '</div>'."\n";
  566. }
  567. if (!empty($debuginfo))
  568. {
  569. print info_admin($debuginfo);
  570. }
  571. // Select mail models is same action as presend
  572. if (GETPOST('modelselected')) {
  573. $action = 'presend';
  574. }
  575. /*
  576. if ($action != 'presend') {
  577. print '<div class="fichecenter"><div class="fichehalfleft">';
  578. print '<a name="builddoc"></a>'; // ancre
  579. */
  580. // Documents
  581. /*$objref = dol_sanitizeFileName($object->ref);
  582. $relativepath = $comref . '/' . $comref . '.pdf';
  583. $filedir = $conf->emailcollector->dir_output . '/' . $objref;
  584. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  585. $genallowed = $user->rights->emailcollector->read; // If you can read, you can build the PDF to read content
  586. $delallowed = $user->rights->emailcollector->create; // If you can create/edit, you can remove a file on card
  587. print $formfile->showdocuments('emailcollector', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  588. */
  589. /*
  590. // Show links to link elements
  591. $linktoelem = $form->showLinkToObjectBlock($object, null, array('emailcollector'));
  592. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  593. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  594. $MAXEVENT = 10;
  595. $morehtmlright = '<a href="' . dol_buildpath('/emailcollector/emailcollector_info.php', 1) . '?id=' . $object->id . '">';
  596. $morehtmlright .= $langs->trans("SeeAll");
  597. $morehtmlright .= '</a>';
  598. // List of actions on element
  599. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  600. $formactions = new FormActions($db);
  601. $somethingshown = $formactions->showactions($object, 'emailcollector_emailcollector', $socid, 1, '', $MAXEVENT, '', $morehtmlright);
  602. print '</div></div></div>';
  603. }
  604. */
  605. //Select mail models is same action as presend
  606. /*
  607. if (GETPOST('modelselected')) $action = 'presend';
  608. // Presend form
  609. $modelmail='inventory';
  610. $defaulttopic='InformationMessage';
  611. $diroutput = $conf->product->dir_output.'/inventory';
  612. $trackid = 'stockinv'.$object->id;
  613. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  614. */
  615. }
  616. // End of page
  617. llxFooter();
  618. $db->close();