emailcollector_card.php 28 KB

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