dolibarr  13.0.2
modEmailCollector.class.php
Go to the documentation of this file.
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 
26 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
27 
28 
33 {
39  public function __construct($db)
40  {
41  global $langs, $conf;
42 
43  $this->db = $db;
44 
45  // Id for module (must be unique).
46  // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
47  $this->numero = 50320;
48  // Key text used to identify module (for permissions, menus, etc...)
49  $this->rights_class = 'emailcollector';
50 
51  // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
52  // It is used to group modules by family in module setup page
53  $this->family = "interface";
54  // Module position in the family on 2 digits ('01', '10', '20', ...)
55  $this->module_position = '23';
56  // 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)
57  //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
58 
59  // Module label (no space allowed), used if translation string 'ModuledavName' not found (MyModue is name of module).
60  $this->name = preg_replace('/^mod/i', '', get_class($this));
61  // Module description, used if translation string 'ModuledavDesc' not found (MyModue is name of module).
62  $this->description = "EmailCollectorDescription";
63  // Used only if file README.md and README-LL.md not found.
64  $this->descriptionlong = "EmailCollectorDescription";
65 
66  // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
67  $this->version = 'dolibarr';
68  // Key used in llx_const table to save module status enabled/disabled (where DAV is value of property name of module in uppercase)
69  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
70  // Name of image file used for this module.
71  // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
72  // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
73  $this->picto = 'email';
74 
75  // Defined all module parts (triggers, login, substitutions, menus, css, etc...)
76  // for default path (eg: /dav/core/xxxxx) (0=disable, 1=enable)
77  // for specific path of parts (eg: /dav/core/modules/barcode)
78  // for specific css file (eg: /dav/css/dav.css.php)
79  $this->module_parts = array();
80 
81  // Data directories to create when module is enabled.
82  // Example: this->dirs = array("/dav/temp","/dav/subdir");
83  $this->dirs = array();
84 
85  // Config pages. Put here list of php page, stored into dav/admin directory, to use to setup module.
86  $this->config_page_url = array("emailcollector_list.php");
87 
88  // Dependencies
89  $this->hidden = false; // A condition to hide module
90  $this->depends = array('always'=>'modCron'); // List of module class names as string that must be enabled if this module is enabled
91  $this->requiredby = array(); // List of module ids to disable if this one is disabled
92  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
93  $this->langfiles = array("admin");
94  $this->phpmin = array(5, 4); // Minimum version of PHP required by module
95  $this->need_dolibarr_version = array(7, 0); // Minimum version of Dolibarr required by module
96  $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
97  $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
98  //$this->automatic_activation = array('FR'=>'davWasAutomaticallyActivatedBecauseOfYourCountryChoice');
99  //$this->always_enabled = true; // If true, can't be disabled
100 
101  // Constants
102  // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
103  // Example: $this->const=array(0=>array('DAV_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
104  // 1=>array('DAV_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
105  // );
106  $this->const = array(
107  //1=>array('DAV_MYCONSTANT', 'chaine', 'avalue', 'This is a constant to add', 1, 'allentities', 1)
108  );
109 
110 
111  if (!isset($conf->emailcollector) || !isset($conf->emailcollector->enabled))
112  {
113  $conf->emailcollector = new stdClass();
114  $conf->emailcollector->enabled = 0;
115  }
116 
117 
118  // Array to add new pages in new tabs
119  $this->tabs = array();
120  // Example:
121  // $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
122  // $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.
123  // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
124  //
125  // Where objecttype can be
126  // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
127  // 'contact' to add a tab in contact view
128  // 'contract' to add a tab in contract view
129  // 'group' to add a tab in group view
130  // 'intervention' to add a tab in intervention view
131  // 'invoice' to add a tab in customer invoice view
132  // 'invoice_supplier' to add a tab in supplier invoice view
133  // 'member' to add a tab in fundation member view
134  // 'opensurveypoll' to add a tab in opensurvey poll view
135  // 'order' to add a tab in customer order view
136  // 'order_supplier' to add a tab in supplier order view
137  // 'payment' to add a tab in payment view
138  // 'payment_supplier' to add a tab in supplier payment view
139  // 'product' to add a tab in product view
140  // 'propal' to add a tab in propal view
141  // 'project' to add a tab in project view
142  // 'stock' to add a tab in stock view
143  // 'thirdparty' to add a tab in third party view
144  // 'user' to add a tab in user view
145 
146 
147  // Dictionaries
148  $this->dictionaries = array();
149  /* Example:
150  $this->dictionaries=array(
151  'langs'=>'mylangfile@dav',
152  'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"), // List of tables we want to see into dictonnary editor
153  'tablib'=>array("Table1","Table2","Table3"), // Label of tables
154  'tabsql'=>array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'), // Request to select fields
155  'tabsqlsort'=>array("label ASC","label ASC","label ASC"), // Sort order
156  'tabfield'=>array("code,label","code,label","code,label"), // List of fields (result of select to show dictionary)
157  'tabfieldvalue'=>array("code,label","code,label","code,label"), // List of fields (list of fields to edit a record)
158  'tabfieldinsert'=>array("code,label","code,label","code,label"), // List of fields (list of fields for insert)
159  'tabrowid'=>array("rowid","rowid","rowid"), // Name of columns with primary key (try to always name it 'rowid')
160  'tabcond'=>array($conf->dav->enabled,$conf->dav->enabled,$conf->dav->enabled) // Condition to show each dictionary
161  );
162  */
163 
164 
165  // Boxes/Widgets
166  // Add here list of php file(s) stored in dav/core/boxes that contains class to show a widget.
167  $this->boxes = array(
168  //0=>array('file'=>'davwidget1.php@dav','note'=>'Widget provided by dav','enabledbydefaulton'=>'Home'),
169  //1=>array('file'=>'davwidget2.php@dav','note'=>'Widget provided by dav'),
170  //2=>array('file'=>'davwidget3.php@dav','note'=>'Widget provided by dav')
171  );
172 
173 
174  // Cronjobs (List of cron jobs entries to add when module is enabled)
175  // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
176  $this->cronjobs = array(
177  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')
178  );
179 
180 
181  // Permissions
182  $this->rights = array(); // Permission array used by this module
183 
184  /*
185  $r=0;
186  $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
187  $this->rights[$r][1] = 'Read myobject of dav'; // Permission label
188  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
189  $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2)
190  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2)
191 
192  $r++;
193  $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
194  $this->rights[$r][1] = 'Create/Update myobject of dav'; // Permission label
195  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
196  $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2)
197  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2)
198 
199  $r++;
200  $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
201  $this->rights[$r][1] = 'Delete myobject of dav'; // Permission label
202  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
203  $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2)
204  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2)
205  */
206 
207  // Main menu entries
208  $this->menu = array(); // List of menus to add
209  $r = 0;
210 
211  // Add here entries to declare new menus
212 
213  /* BEGIN MODULEBUILDER TOPMENU */
214  /*$this->menu[$r++]=array('fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
215  'type'=>'top', // This is a Top menu entry
216  'titre'=>'dav',
217  'mainmenu'=>'dav',
218  'leftmenu'=>'',
219  'url'=>'/dav/davindex.php',
220  'langs'=>'dav@dav', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
221  'position'=>1000+$r,
222  'enabled'=>'$conf->dav->enabled', // Define condition to show or hide menu entry. Use '$conf->dav->enabled' if entry must be visible if module is enabled.
223  'perms'=>'1', // Use 'perms'=>'$user->rights->dav->level1->level2' if you want your menu with a permission rules
224  'target'=>'',
225  'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
226  */
227  /* END MODULEBUILDER TOPMENU */
228 
229  /* BEGIN MODULEBUILDER LEFTMENU MYOBJECT
230  $this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=dav', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
231  'type'=>'left', // This is a Left menu entry
232  'titre'=>'List MyObject',
233  'mainmenu'=>'dav',
234  'leftmenu'=>'dav_myobject_list',
235  'url'=>'/dav/myobject_list.php',
236  'langs'=>'dav@dav', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
237  'position'=>1000+$r,
238  'enabled'=>'$conf->dav->enabled', // Define condition to show or hide menu entry. Use '$conf->dav->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
239  'perms'=>'1', // Use 'perms'=>'$user->rights->dav->level1->level2' if you want your menu with a permission rules
240  'target'=>'',
241  'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
242  $this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=dav,fk_leftmenu=dav', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
243  'type'=>'left', // This is a Left menu entry
244  'titre'=>'New MyObject',
245  'mainmenu'=>'dav',
246  'leftmenu'=>'dav_myobject_new',
247  'url'=>'/dav/myobject_page.php?action=create',
248  'langs'=>'dav@dav', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
249  'position'=>1000+$r,
250  'enabled'=>'$conf->dav->enabled', // Define condition to show or hide menu entry. Use '$conf->dav->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
251  'perms'=>'1', // Use 'perms'=>'$user->rights->dav->level1->level2' if you want your menu with a permission rules
252  'target'=>'',
253  'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
254  END MODULEBUILDER LEFTMENU MYOBJECT */
255  }
256 
265  public function init($options = '')
266  {
267  global $conf, $user;
268  //$this->_load_tables('/dav/sql/');
269 
270  // Create extrafields
271  //include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
272  //$extrafields = new ExtraFields($this->db);
273  //$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled');
274  //$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled');
275  //$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled');
276  //$result4=$extrafields->addExtraField('myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1 '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled');
277  //$result5=$extrafields->addExtraField('myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled');
278 
279  $sql = array();
280 
281  $tmpsql = "SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requests' and entity = ".$conf->entity;
282  $tmpresql = $this->db->query($tmpsql);
283  if ($tmpresql) {
284  if ($this->db->num_rows($tmpresql) == 0) {
285  $descriptionA1 = 'This collector will scan your mailbox to find emails that match some rules and create automatically a ticket (Module Ticket must be enabled) with the email informations. You can use this collector if you provide some support by email, so your ticket request will be automatically generated.';
286  $descriptionA1 .= ' If the collector Collect_Responses is also enabled, when you send an email from the ticket, you may also see answers of your customers or partners directly on the ticket view.';
287 
288  $sqlforexampleA1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
289  $sqlforexampleA1 .= " VALUES (".$conf->entity.", 'Collect_Ticket_Requets', 'Example to collect ticket requests', '".$this->db->escape($descriptionA1)."', 'INBOX', '".$this->db->idate(dol_now())."', ".$user->id.", 0)";
290 
291  $sqlforexampleFilterA1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
292  $sqlforexampleFilterA1 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requets' and entity = ".$conf->entity."), 'isnotanswer', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
293  $sqlforexampleFilterA2 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
294  $sqlforexampleFilterA2 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requets' and entity = ".$conf->entity."), 'withouttrackingid', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
295  $sqlforexampleFilterA3 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
296  $sqlforexampleFilterA3 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requets' and entity = ".$conf->entity."), 'to', 'support@example.com', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
297 
298  $sqlforexampleA4 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
299  $sqlforexampleA4 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requets' and entity = ".$conf->entity."), 'ticket', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
300 
301  $sql[] = $sqlforexampleA1;
302  $sql[] = $sqlforexampleFilterA1;
303  $sql[] = $sqlforexampleFilterA2;
304  $sql[] = $sqlforexampleFilterA3;
305  $sql[] = $sqlforexampleA4;
306  }
307  } else dol_print_error($this->db);
308 
309  $tmpsql = "SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_Out' and entity = ".$conf->entity;
310  $tmpresql = $this->db->query($tmpsql);
311  if ($tmpresql) {
312  if ($this->db->num_rows($tmpresql) == 0) {
313  $descriptionA1 = 'This collector will scan your mailbox "Sent" directory to find emails that was sent as an answer of another email directly from your email software and not from Dolibarr. If such an email is found, the event of answer is recorded into Dolibarr.';
314 
315  $sqlforexampleA1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
316  $sqlforexampleA1 .= " VALUES (".$conf->entity.", 'Collect_Responses_Out', 'Example to collect answers to emails done from your external email software', '".$this->db->escape($descriptionA1)."', 'Sent', '".$this->db->idate(dol_now())."', ".$user->id.", 0)";
317 
318  $sqlforexampleFilterA1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
319  $sqlforexampleFilterA1 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_Out' and entity = ".$conf->entity."), 'isanswer', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
320  $sqlforexampleFilterA2 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
321  $sqlforexampleFilterA2 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_Out' and entity = ".$conf->entity."), 'withouttrackingidinmsgid', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
322  $sqlforexampleActionA1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
323  $sqlforexampleActionA1 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_Out' and entity = ".$conf->entity."), 'recordevent', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
324 
325  $sql[] = $sqlforexampleA1;
326  $sql[] = $sqlforexampleFilterA1;
327  $sql[] = $sqlforexampleFilterA2;
328  $sql[] = $sqlforexampleActionA1;
329  }
330  }
331 
332  $tmpsql = "SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_In' and entity = ".$conf->entity;
333  $tmpresql = $this->db->query($tmpsql);
334  if ($tmpresql) {
335  if ($this->db->num_rows($tmpresql) == 0) {
336  $descriptionB1 = 'This collector will scan your mailbox to find all emails that are an answer of an email sent from your application. An event (Module Agenda must be enabled) with the email response will be recorded at the good place. For example, if your send a commercial proposal, order, invoice or message for a ticket by email from the application, and your customer answers your email, the system will automatically catch the answer and add it into your ERP.';
337 
338  $sqlforexampleB1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
339  $sqlforexampleB1 .= " VALUES (".$conf->entity.", 'Collect_Responses_In', 'Example to collect any received email that is a response of an email sent from Dolibarr', '".$this->db->escape($descriptionB1)."', 'INBOX', '".$this->db->idate(dol_now())."', ".$user->id.", 0)";
340  $sqlforexampleB2 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
341  $sqlforexampleB2 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_In' and entity = ".$conf->entity."), 'isanswer', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
342  $sqlforexampleB3 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
343  $sqlforexampleB3 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Responses_In' and entity = ".$conf->entity."), 'recordevent', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
344 
345  $sql[] = $sqlforexampleB1;
346  $sql[] = $sqlforexampleB2;
347  $sql[] = $sqlforexampleB3;
348  }
349  } else dol_print_error($this->db);
350 
351  $tmpsql = "SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".$conf->entity;
352  $tmpresql = $this->db->query($tmpsql);
353  if ($tmpresql) {
354  if ($this->db->num_rows($tmpresql) == 0) {
355  $descriptionC1 = "This collector will scan your mailbox to find emails that match some rules and create automatically a lead (Module Project must be enabled) with the email informations. You can use this collector if you want to follow your lead using the module Project (1 lead = 1 project), so your leads will be automatically generated.";
356  $descriptionC1 .= " If the collector Collect_Responses is also enabled, when you send an email from your leads, proposals or any other object, you may also see answers of your customers or partners directly on the application.<br>";
357  $descriptionC1 .= "Note: With this initial example, the title of the lead is generated including the email. If the thirdparty can't be found in database (new customer), the lead will be attached to the thirdparty with ID 1.";
358 
359  $sqlforexampleC1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
360  $sqlforexampleC1 .= " VALUES (".$conf->entity.", 'Collect_Leads', 'Example to collect leads', '".$this->db->escape($descriptionC1)."', 'INBOX', '".$this->db->idate(dol_now())."', ".$user->id.", 0)";
361 
362  $sqlforexampleFilterC1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
363  $sqlforexampleFilterC1 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".$conf->entity."), 'isnotanswer', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
364  $sqlforexampleFilterC2 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
365  $sqlforexampleFilterC2 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".$conf->entity."), 'withouttrackingid', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
366  $sqlforexampleFilterC3 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
367  $sqlforexampleFilterC3 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".$conf->entity."), 'to', 'sales@example.com', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
368 
369  $sqlforexampleC4 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectoraction (fk_emailcollector, type, actionparam, date_creation, fk_user_creat, status)";
370  $sqlforexampleC4 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".$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())."', ".$user->id.", 1)";
371 
372  $sql[] = $sqlforexampleC1;
373  $sql[] = $sqlforexampleFilterC1;
374  $sql[] = $sqlforexampleFilterC2;
375  $sql[] = $sqlforexampleFilterC3;
376  $sql[] = $sqlforexampleC4;
377  }
378  } else dol_print_error($this->db);
379 
380  $tmpsql = "SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".$conf->entity;
381  $tmpresql = $this->db->query($tmpsql);
382  if ($tmpresql) {
383  if ($this->db->num_rows($tmpresql) == 0) {
384  $descriptionC1 = "This collector will scan your mailbox to find emails send for a recruitment (Module Recruitment must be enabled). You can complete this collector if you want to automaticallycreate a candidature for a job request.";
385  $descriptionC1 .= "Note: With this initial example, the title of the candidature is generated including the email.";
386 
387  $sqlforexampleC1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
388  $sqlforexampleC1 .= " VALUES (".$conf->entity.", 'Collect_Candidatures', 'Example to collect email for job candidatures', '".$this->db->escape($descriptionC1)."', 'INBOX', '".$this->db->idate(dol_now())."', ".$user->id.", 0)";
389 
390  $sqlforexampleFilterC1 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
391  $sqlforexampleFilterC1 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".$conf->entity."), 'isnotanswer', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
392  $sqlforexampleFilterC2 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
393  $sqlforexampleFilterC2 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".$conf->entity."), 'withouttrackingid', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
394  $sqlforexampleFilterC3 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
395  $sqlforexampleFilterC3 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".$conf->entity."), 'to', 'jobs@example.com', '".$this->db->idate(dol_now())."', ".$user->id.", 1)";
396 
397  $sqlforexampleC4 = "INSERT INTO ".MAIN_DB_PREFIX."emailcollector_emailcollectoraction (fk_emailcollector, type, actionparam, date_creation, fk_user_creat, status)";
398  $sqlforexampleC4 .= " VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX."emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".$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())."', ".$user->id.", 1)";
399 
400  $sql[] = $sqlforexampleC1;
401  $sql[] = $sqlforexampleFilterC1;
402  $sql[] = $sqlforexampleFilterC2;
403  $sql[] = $sqlforexampleFilterC3;
404  $sql[] = $sqlforexampleC4;
405  }
406  } else dol_print_error($this->db);
407 
408  return $this->_init($sql, $options);
409  }
410 
419  public function remove($options = '')
420  {
421  $sql = array();
422 
423  return $this->_remove($sql, $options);
424  }
425 }
Class DolibarrModules.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
dol_now($mode= 'auto')
Return date for now.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
_remove($array_sql, $options= '')
Disable function.
__construct($db)
Constructor.
_init($array_sql, $options= '')
Enables a module.
Description and activation class for module emailcollector.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
init($options= '')
Function called when module is enabled.