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(7, 0);
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)) {
112 $conf->emailcollector =
new stdClass();
113 $conf->emailcollector->enabled = 0;
118 $this->tabs = array();
147 $this->dictionaries = array();
152 $this->boxes = array(
161 $this->cronjobs = array(
162 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')
167 $this->rights = array();
170 $this->menu = array();
173 $this->menu[$r] = array(
'fk_menu'=>
'fk_mainmenu=home,fk_leftmenu=admintools',
175 'titre'=>
'EmailCollectors',
176 'url'=>
'/admin/emailcollector_list.php?leftmenu=admintools',
179 'enabled'=>
'$conf->emailcollector->enabled && preg_match(\'/^(admintools|all)/\', $leftmenu)',
180 'perms'=>
'$user->admin',
194 public function init($options =
'')
196 global $conf, $user, $langs;
197 $langs->load(
"admin");
201 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requests' and entity = ".$conf->entity;
202 $tmpresql = $this->
db->query($tmpsql);
204 if ($this->
db->num_rows($tmpresql) == 0) {
205 $descriptionA1 = $langs->trans(
'EmailCollectorExampleToCollectTicketRequestsDesc');
206 $label = $langs->trans(
'EmailCollectorExampleToCollectTicketRequests');
207 $sqlforexampleA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
208 $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)";
210 $sqlforexampleFilterA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
211 $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)";
214 $sqlforexampleFilterA3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
215 $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)";
217 $sqlforexampleActionA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
218 $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)";
220 $sql[] = $sqlforexampleA1;
222 $sql[] = $sqlforexampleFilterA1;
224 $sql[] = $sqlforexampleFilterA3;
226 $sql[] = $sqlforexampleActionA1;
232 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Responses_Out' and entity = ".$conf->entity;
233 $tmpresql = $this->
db->query($tmpsql);
235 if ($this->
db->num_rows($tmpresql) == 0) {
236 $descriptionA1 = $langs->trans(
'EmailCollectorExampleToCollectAnswersFromExternalEmailSoftware');
237 $label = $langs->trans(
'EmailCollectorExampleToCollectAnswersFromExternalEmailSoftware');
238 $sqlforexampleA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
239 $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)";
241 $sqlforexampleFilterA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
242 $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)";
243 $sqlforexampleFilterA2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
244 $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)";
246 $sqlforexampleActionA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
247 $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)";
249 $sql[] = $sqlforexampleA1;
251 $sql[] = $sqlforexampleFilterA1;
252 $sql[] = $sqlforexampleFilterA2;
254 $sql[] = $sqlforexampleActionA1;
258 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Responses_In' and entity = ".((int) $conf->entity);
259 $tmpresql = $this->
db->query($tmpsql);
261 if ($this->
db->num_rows($tmpresql) == 0) {
262 $descriptionB1 = $langs->trans(
'EmailCollectorExampleToCollectDolibarrAnswersDesc');
263 $label = $langs->trans(
'EmailCollectorExampleToCollectDolibarrAnswers');
264 $sqlforexampleB1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
265 $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)";
267 $sqlforexampleFilterB2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
268 $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)";
270 $sqlforexampleActionB3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
271 $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)";
273 $sql[] = $sqlforexampleB1;
275 $sql[] = $sqlforexampleFilterB2;
277 $sql[] = $sqlforexampleActionB3;
283 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".((int) $conf->entity);
284 $tmpresql = $this->
db->query($tmpsql);
286 if ($this->
db->num_rows($tmpresql) == 0) {
287 $descriptionC1 = $langs->trans(
"EmailCollectorExampleToCollectLeadsDesc");
288 $label = $langs->trans(
'EmailCollectorExampleToCollectLeads');
289 $sqlforexampleC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
290 $sqlforexampleC1 .=
" VALUES (".$conf->entity.
", 'Collect_Leads', '".$this->
db->escape($label).
"', '".$this->
db->escape($descriptionC1).
"', 'INBOX', '".$this->
db->idate(
dol_now()).
"', ".((
int) $user->id).
", 0)";
292 $sqlforexampleFilterC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
293 $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)";
296 $sqlforexampleFilterC3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
297 $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)";
299 $sqlforexampleActionC4 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, actionparam, date_creation, fk_user_creat, status)";
300 $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)";
302 $sql[] = $sqlforexampleC1;
304 $sql[] = $sqlforexampleFilterC1;
306 $sql[] = $sqlforexampleFilterC3;
308 $sql[] = $sqlforexampleActionC4;
314 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".((int) $conf->entity);
315 $tmpresql = $this->
db->query($tmpsql);
317 if ($this->
db->num_rows($tmpresql) == 0) {
318 $descriptionC1 = $langs->trans(
"EmailCollectorExampleToCollectJobCandidaturesDesc");
319 $label = $langs->trans(
'EmailCollectorExampleToCollectJobCandidatures');
320 $sqlforexampleC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
321 $sqlforexampleC1 .=
" VALUES (".$conf->entity.
", 'Collect_Candidatures', '".$this->
db->escape($label).
"', '".$this->
db->escape($descriptionC1).
"', 'INBOX', '".$this->
db->idate(
dol_now()).
"', ".((
int) $user->id).
", 0)";
323 $sqlforexampleFilterC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
324 $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)";
327 $sqlforexampleFilterC3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
328 $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)";
330 $sqlforexampleActionC4 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, actionparam, date_creation, fk_user_creat, status)";
331 $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)";
333 $sql[] = $sqlforexampleC1;
335 $sql[] = $sqlforexampleFilterC1;
337 $sql[] = $sqlforexampleFilterC3;
339 $sql[] = $sqlforexampleActionC4;
345 return $this->
_init($sql, $options);
356 public function remove($options =
'')
360 return $this->
_remove($sql, $options);
_init($array_sql, $options='')
Enables a module.
_remove($array_sql, $options='')
Disable function.
Description and activation class for module emailcollector.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.