modEmailCollector.class.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <?php
  2. /* Copyright (C) 2004-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. * \defgroup emailcollector Module emailcollector
  19. * \brief emailcollector module descriptor.
  20. *
  21. * \file htdocs/core/modules/modEmailCollector.class.php
  22. * \ingroup emailcollector
  23. * \brief Description and activation file for the module emailcollector
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  26. /**
  27. * Description and activation class for module emailcollector
  28. */
  29. class modEmailCollector extends DolibarrModules
  30. {
  31. /**
  32. * Constructor. Define names, constants, directories, boxes, permissions
  33. *
  34. * @param DoliDB $db Database handler
  35. */
  36. public function __construct($db)
  37. {
  38. global $langs, $conf;
  39. $this->db = $db;
  40. // Id for module (must be unique).
  41. // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
  42. $this->numero = 50320;
  43. // Key text used to identify module (for permissions, menus, etc...)
  44. $this->rights_class = 'emailcollector';
  45. // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
  46. // It is used to group modules by family in module setup page
  47. $this->family = "interface";
  48. // Module position in the family on 2 digits ('01', '10', '20', ...)
  49. $this->module_position = '23';
  50. // Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
  51. //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
  52. // Module label (no space allowed), used if translation string 'ModuledavName' not found (MyModue is name of module).
  53. $this->name = preg_replace('/^mod/i', '', get_class($this));
  54. // Module description, used if translation string 'ModuledavDesc' not found (MyModue is name of module).
  55. $this->description = "EmailCollectorDescription";
  56. // Used only if file README.md and README-LL.md not found.
  57. $this->descriptionlong = "EmailCollectorDescription";
  58. // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
  59. $this->version = 'dolibarr';
  60. // Key used in llx_const table to save module status enabled/disabled (where DAV is value of property name of module in uppercase)
  61. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  62. // Name of image file used for this module.
  63. // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
  64. // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
  65. $this->picto = 'email';
  66. // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
  67. // for default path (eg: /dav/core/xxxxx) (0=disable, 1=enable)
  68. // for specific path of parts (eg: /dav/core/modules/barcode)
  69. // for specific css file (eg: /dav/css/dav.css.php)
  70. $this->module_parts = array();
  71. // Data directories to create when module is enabled.
  72. // Example: this->dirs = array("/dav/temp","/dav/subdir");
  73. $this->dirs = array();
  74. // Config pages. Put here list of php page, stored into dav/admin directory, to use to setup module.
  75. $this->config_page_url = array("emailcollector_list.php");
  76. // Dependencies
  77. $this->hidden = false; // A condition to hide module
  78. $this->depends = array('always'=>'modCron'); // List of module class names as string that must be enabled if this module is enabled
  79. $this->requiredby = array(); // List of module ids to disable if this one is disabled
  80. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  81. $this->langfiles = array("admin");
  82. $this->phpmin = array(5, 6); // Minimum version of PHP required by module
  83. $this->need_dolibarr_version = array(7, 0); // Minimum version of Dolibarr required by module
  84. $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
  85. $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
  86. //$this->automatic_activation = array('FR'=>'davWasAutomaticallyActivatedBecauseOfYourCountryChoice');
  87. //$this->always_enabled = true; // If true, can't be disabled
  88. // Constants
  89. // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
  90. // Example: $this->const=array(0=>array('DAV_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
  91. // 1=>array('DAV_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
  92. // );
  93. $this->const = array(
  94. //1=>array('DAV_MYCONSTANT', 'chaine', 'avalue', 'This is a constant to add', 1, 'allentities', 1)
  95. );
  96. if (!isset($conf->emailcollector) || !isset($conf->emailcollector->enabled)) {
  97. $conf->emailcollector = new stdClass();
  98. $conf->emailcollector->enabled = 0;
  99. }
  100. // Array to add new pages in new tabs
  101. $this->tabs = array();
  102. // Example:
  103. // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@dav:$user->rights->dav->read:/dav/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1
  104. // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@dav:$user->rights->othermodule->read:/dav/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
  105. // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
  106. //
  107. // Where objecttype can be
  108. // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
  109. // 'contact' to add a tab in contact view
  110. // 'contract' to add a tab in contract view
  111. // 'group' to add a tab in group view
  112. // 'intervention' to add a tab in intervention view
  113. // 'invoice' to add a tab in customer invoice view
  114. // 'invoice_supplier' to add a tab in supplier invoice view
  115. // 'member' to add a tab in fundation member view
  116. // 'opensurveypoll' to add a tab in opensurvey poll view
  117. // 'order' to add a tab in customer order view
  118. // 'order_supplier' to add a tab in supplier order view
  119. // 'payment' to add a tab in payment view
  120. // 'payment_supplier' to add a tab in supplier payment view
  121. // 'product' to add a tab in product view
  122. // 'propal' to add a tab in propal view
  123. // 'project' to add a tab in project view
  124. // 'stock' to add a tab in stock view
  125. // 'thirdparty' to add a tab in third party view
  126. // 'user' to add a tab in user view
  127. // Dictionaries
  128. $this->dictionaries = array();
  129. // Boxes/Widgets
  130. // Add here list of php file(s) stored in dav/core/boxes that contains class to show a widget.
  131. $this->boxes = array(
  132. //0=>array('file'=>'davwidget1.php@dav','note'=>'Widget provided by dav','enabledbydefaulton'=>'Home'),
  133. //1=>array('file'=>'davwidget2.php@dav','note'=>'Widget provided by dav'),
  134. //2=>array('file'=>'davwidget3.php@dav','note'=>'Widget provided by dav')
  135. );
  136. // Cronjobs (List of cron jobs entries to add when module is enabled)
  137. // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
  138. $this->cronjobs = array(
  139. 0=>array('label'=>'Email collector', 'priority'=>50, 'jobtype'=>'method', 'class'=>'/emailcollector/class/emailcollector.class.php', 'objectname'=>'EmailCollector', 'method'=>'doCollect', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>5, 'unitfrequency'=>60, 'status'=>1, 'test'=>'$conf->emailcollector->enabled')
  140. );
  141. // Permissions
  142. $this->rights = array(); // Permission array used by this module
  143. // Main menu entries
  144. $this->menu = array(); // List of menus to add
  145. $r = 0;
  146. $this->menu[$r] = array('fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
  147. 'type'=>'left', // This is a Left menu entry
  148. 'titre'=>'EmailCollectors',
  149. 'url'=>'/admin/emailcollector_list.php?leftmenu=admintools',
  150. 'langs'=>'admin', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  151. 'position'=>201,
  152. 'enabled'=>'$conf->emailcollector->enabled && preg_match(\'/^(admintools|all)/\', $leftmenu)', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
  153. 'perms'=>'$user->admin', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
  154. 'target'=>'',
  155. 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
  156. $r++;
  157. }
  158. /**
  159. * Function called when module is enabled.
  160. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  161. * It also creates data directories
  162. *
  163. * @param string $options Options when enabling module ('', 'noboxes')
  164. * @return int 1 if OK, 0 if KO
  165. */
  166. public function init($options = '')
  167. {
  168. global $conf, $user, $langs;
  169. $langs->load("admin");
  170. $sql = array();
  171. $tmpsql = "SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requests' and entity = ".$conf->entity;
  172. $tmpresql = $this->db->query($tmpsql);
  173. if ($tmpresql) {
  174. if ($this->db->num_rows($tmpresql) == 0) {
  175. $descriptionA1 = $langs->trans('EmailCollectorExampleToCollectTicketRequestsDesc');
  176. $label = $langs->trans('EmailCollectorExampleToCollectTicketRequests');
  177. $sqlforexampleA1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
  178. $sqlforexampleA1 .= " VALUES (".$conf->entity.", 'Collect_Ticket_Requests', '".$this->db->escape($label)."', '".$this->db->escape($descriptionA1)."', 'INBOX', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 0)";
  179. $sqlforexampleFilterA1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
  180. $sqlforexampleFilterA1 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requests' and entity = ".$conf->entity."), 'isnotanswer', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  181. //$sqlforexampleFilterA2 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
  182. //$sqlforexampleFilterA2 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requests' and entity = ".$conf->entity."), 'withouttrackingid', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  183. $sqlforexampleFilterA3 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
  184. $sqlforexampleFilterA3 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requests' and entity = ".$conf->entity."), 'to', 'support@example.com', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  185. $sqlforexampleActionA1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
  186. $sqlforexampleActionA1 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requests' and entity = ".$conf->entity."), 'ticket', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  187. $sql[] = $sqlforexampleA1;
  188. $sql[] = $sqlforexampleFilterA1;
  189. //$sql[] = $sqlforexampleFilterA2;
  190. $sql[] = $sqlforexampleFilterA3;
  191. $sql[] = $sqlforexampleActionA1;
  192. }
  193. } else {
  194. dol_print_error($this->db);
  195. }
  196. $tmpsql = "SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_Out' and entity = ".$conf->entity;
  197. $tmpresql = $this->db->query($tmpsql);
  198. if ($tmpresql) {
  199. if ($this->db->num_rows($tmpresql) == 0) {
  200. $descriptionA1 = $langs->trans('EmailCollectorExampleToCollectAnswersFromExternalEmailSoftware');
  201. $label = $langs->trans('EmailCollectorExampleToCollectAnswersFromExternalEmailSoftware');
  202. $sqlforexampleA1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
  203. $sqlforexampleA1 .= " VALUES (".$conf->entity.", 'Collect_Responses_Out', '".$this->db->escape($label)."', '".$this->db->escape($descriptionA1)."', 'Sent', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 0)";
  204. $sqlforexampleFilterA1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
  205. $sqlforexampleFilterA1 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_Out' and entity = ".((int) $conf->entity)."), 'isanswer', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  206. $sqlforexampleFilterA2 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
  207. $sqlforexampleFilterA2 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_Out' and entity = ".((int) $conf->entity)."), 'withouttrackingidinmsgid', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  208. $sqlforexampleActionA1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
  209. $sqlforexampleActionA1 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_Out' and entity = ".((int) $conf->entity)."), 'recordevent', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  210. $sql[] = $sqlforexampleA1;
  211. $sql[] = $sqlforexampleFilterA1;
  212. $sql[] = $sqlforexampleFilterA2;
  213. $sql[] = $sqlforexampleActionA1;
  214. }
  215. }
  216. $tmpsql = "SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_In' and entity = ".((int) $conf->entity);
  217. $tmpresql = $this->db->query($tmpsql);
  218. if ($tmpresql) {
  219. if ($this->db->num_rows($tmpresql) == 0) {
  220. $descriptionB1 = $langs->trans('EmailCollectorExampleToCollectDolibarrAnswersDesc');
  221. $label = $langs->trans('EmailCollectorExampleToCollectDolibarrAnswers');
  222. $sqlforexampleB1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
  223. $sqlforexampleB1 .= " VALUES (".$conf->entity.", 'Collect_Responses_In', '".$this->db->escape($label)."', '".$this->db->escape($descriptionB1)."', 'INBOX', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 0)";
  224. $sqlforexampleFilterB2 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
  225. $sqlforexampleFilterB2 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_In' and entity = ".((int) $conf->entity)."), 'isanswer', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  226. $sqlforexampleActionB3 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
  227. $sqlforexampleActionB3 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_In' and entity = ".((int) $conf->entity)."), 'recordevent', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  228. $sql[] = $sqlforexampleB1;
  229. $sql[] = $sqlforexampleFilterB2;
  230. $sql[] = $sqlforexampleActionB3;
  231. }
  232. } else {
  233. dol_print_error($this->db);
  234. }
  235. $tmpsql = "SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".((int) $conf->entity);
  236. $tmpresql = $this->db->query($tmpsql);
  237. if ($tmpresql) {
  238. if ($this->db->num_rows($tmpresql) == 0) {
  239. $descriptionC1 = $langs->trans("EmailCollectorExampleToCollectLeadsDesc");
  240. $label = $langs->trans('EmailCollectorExampleToCollectLeads');
  241. $sqlforexampleC1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
  242. $sqlforexampleC1 .= " VALUES (".$conf->entity.", 'Collect_Leads', '".$this->db->escape($label)."', '".$this->db->escape($descriptionC1)."', 'INBOX', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 0)";
  243. $sqlforexampleFilterC1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
  244. $sqlforexampleFilterC1 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".((int) $conf->entity)."), 'isnotanswer', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  245. //$sqlforexampleFilterC2 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
  246. //$sqlforexampleFilterC2 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".((int) $conf->entity)."), 'withouttrackingid', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  247. $sqlforexampleFilterC3 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
  248. $sqlforexampleFilterC3 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".((int) $conf->entity)."), 'to', 'sales@example.com', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  249. $sqlforexampleActionC4 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectoraction (fk_emailcollector, type, actionparam, date_creation, fk_user_creat, status)";
  250. $sqlforexampleActionC4 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".((int) $conf->entity)."), 'project', 'tmp_from=EXTRACT:HEADER:^From:(.*);socid=SETIFEMPTY:1;usage_opportunity=SET:1;description=EXTRACT:BODY:(.*);title=SET:Lead or message from __tmp_from__ received by email', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  251. $sql[] = $sqlforexampleC1;
  252. $sql[] = $sqlforexampleFilterC1;
  253. //$sql[] = $sqlforexampleFilterC2;
  254. $sql[] = $sqlforexampleFilterC3;
  255. $sql[] = $sqlforexampleActionC4;
  256. }
  257. } else {
  258. dol_print_error($this->db);
  259. }
  260. $tmpsql = "SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".((int) $conf->entity);
  261. $tmpresql = $this->db->query($tmpsql);
  262. if ($tmpresql) {
  263. if ($this->db->num_rows($tmpresql) == 0) {
  264. $descriptionC1 = $langs->trans("EmailCollectorExampleToCollectJobCandidaturesDesc");
  265. $label = $langs->trans('EmailCollectorExampleToCollectJobCandidatures');
  266. $sqlforexampleC1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
  267. $sqlforexampleC1 .= " VALUES (".$conf->entity.", 'Collect_Candidatures', '".$this->db->escape($label)."', '".$this->db->escape($descriptionC1)."', 'INBOX', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 0)";
  268. $sqlforexampleFilterC1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
  269. $sqlforexampleFilterC1 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".((int) $conf->entity)."), 'isnotanswer', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  270. //$sqlforexampleFilterC2 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
  271. //$sqlforexampleFilterC2 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".((int) $conf->entity)."), 'withouttrackingid', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  272. $sqlforexampleFilterC3 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
  273. $sqlforexampleFilterC3 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".((int) $conf->entity)."), 'to', 'jobs@example.com', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  274. $sqlforexampleActionC4 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectoraction (fk_emailcollector, type, actionparam, date_creation, fk_user_creat, status)";
  275. $sqlforexampleActionC4 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".((int) $conf->entity)."), 'candidature', 'tmp_from=EXTRACT:HEADER:^From:(.*)(<.*>)?;fk_recruitmentjobposition=EXTRACT:HEADER:^To:[^\n]*\+([^\n]*);description=EXTRACT:BODY:(.*);lastname=SET:__tmp_from__', '".$this->db->idate(dol_now())."', ".((int) $user->id).", 1)";
  276. $sql[] = $sqlforexampleC1;
  277. $sql[] = $sqlforexampleFilterC1;
  278. //$sql[] = $sqlforexampleFilterC2;
  279. $sql[] = $sqlforexampleFilterC3;
  280. $sql[] = $sqlforexampleActionC4;
  281. }
  282. } else {
  283. dol_print_error($this->db);
  284. }
  285. return $this->_init($sql, $options);
  286. }
  287. /**
  288. * Function called when module is disabled.
  289. * Remove from database constants, boxes and permissions from Dolibarr database.
  290. * Data directories are not deleted
  291. *
  292. * @param string $options Options when enabling module ('', 'noboxes')
  293. * @return int 1 if OK, 0 if KO
  294. */
  295. public function remove($options = '')
  296. {
  297. $sql = array();
  298. return $this->_remove($sql, $options);
  299. }
  300. }