26 include_once DOL_DOCUMENT_ROOT.
'/core/modules/DolibarrModules.class.php';
47 $this->numero = 50320;
49 $this->rights_class =
'emailcollector';
53 $this->family =
"interface";
55 $this->module_position =
'23';
60 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
64 $this->descriptionlong =
"EmailCollectorDescription";
67 $this->version =
'dolibarr';
69 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
73 $this->picto =
'email';
79 $this->module_parts = array();
83 $this->dirs = array();
86 $this->config_page_url = array(
"emailcollector_list.php");
89 $this->hidden =
false;
90 $this->depends = array(
'always'=>
'modCron');
91 $this->requiredby = array();
92 $this->conflictwith = array();
93 $this->langfiles = array(
"admin");
94 $this->phpmin = array(5, 4);
95 $this->need_dolibarr_version = array(7, 0);
96 $this->warnings_activation = array();
97 $this->warnings_activation_ext = array();
106 $this->
const = array(
111 if (!isset($conf->emailcollector) || !isset($conf->emailcollector->enabled))
113 $conf->emailcollector =
new stdClass();
114 $conf->emailcollector->enabled = 0;
119 $this->tabs = array();
148 $this->dictionaries = array();
167 $this->boxes = array(
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')
182 $this->rights = array();
208 $this->menu = array();
265 public function init($options =
'')
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);
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.';
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)";
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)";
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)";
301 $sql[] = $sqlforexampleA1;
302 $sql[] = $sqlforexampleFilterA1;
303 $sql[] = $sqlforexampleFilterA2;
304 $sql[] = $sqlforexampleFilterA3;
305 $sql[] = $sqlforexampleA4;
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);
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.';
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)";
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)";
325 $sql[] = $sqlforexampleA1;
326 $sql[] = $sqlforexampleFilterA1;
327 $sql[] = $sqlforexampleFilterA2;
328 $sql[] = $sqlforexampleActionA1;
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);
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.';
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)";
345 $sql[] = $sqlforexampleB1;
346 $sql[] = $sqlforexampleB2;
347 $sql[] = $sqlforexampleB3;
351 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".$conf->entity;
352 $tmpresql = $this->
db->query($tmpsql);
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.";
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)";
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)";
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)";
372 $sql[] = $sqlforexampleC1;
373 $sql[] = $sqlforexampleFilterC1;
374 $sql[] = $sqlforexampleFilterC2;
375 $sql[] = $sqlforexampleFilterC3;
376 $sql[] = $sqlforexampleC4;
380 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".$conf->entity;
381 $tmpresql = $this->
db->query($tmpsql);
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.";
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)";
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)";
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)";
400 $sql[] = $sqlforexampleC1;
401 $sql[] = $sqlforexampleFilterC1;
402 $sql[] = $sqlforexampleFilterC2;
403 $sql[] = $sqlforexampleFilterC3;
404 $sql[] = $sqlforexampleC4;
408 return $this->
_init($sql, $options);
419 public function remove($options =
'')
423 return $this->
_remove($sql, $options);
</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.
dol_now($mode= 'auto')
Return date for now.
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.
_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.