emailcollector_card.php 28 KB

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