emailcollector_card.php 27 KB

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