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'=>
'isModEnabled("emailcollector") && 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 $paramstring =
'tmp_from=EXTRACT:HEADER:^From:(.*)'.
"\n".
'socid=SETIFEMPTY:1'.
"\n".
'usage_opportunity=SET:1'.
"\n".
'description=EXTRACT:BODY:(.*)'.
"\n".
'title=SET:Lead or message from __tmp_from__ received by email';
300 $sqlforexampleActionC4 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, actionparam, date_creation, fk_user_creat, status)";
301 $sqlforexampleActionC4 .=
" VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".((int) $conf->entity).
"), 'project', '".$this->db->escape($paramstring).
"', '".$this->db->idate(
dol_now()).
"', ".((
int) $user->id).
", 1)";
303 $sql[] = $sqlforexampleC1;
305 $sql[] = $sqlforexampleFilterC1;
307 $sql[] = $sqlforexampleFilterC3;
309 $sql[] = $sqlforexampleActionC4;
315 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".((int) $conf->entity);
316 $tmpresql = $this->db->query($tmpsql);
318 if ($this->db->num_rows($tmpresql) == 0) {
319 $descriptionC1 = $langs->trans(
"EmailCollectorExampleToCollectJobCandidaturesDesc");
320 $label = $langs->trans(
'EmailCollectorExampleToCollectJobCandidatures');
321 $sqlforexampleC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
322 $sqlforexampleC1 .=
" VALUES (".$conf->entity.
", 'Collect_Candidatures', '".$this->db->escape($label).
"', '".$this->db->escape($descriptionC1).
"', 'INBOX', '".$this->db->idate(
dol_now()).
"', ".((int) $user->id).
", 0)";
324 $sqlforexampleFilterC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
325 $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)";
328 $sqlforexampleFilterC3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
329 $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)";
331 $paramstring =
'tmp_from=EXTRACT:HEADER:^From:(.*)(<.*>)?'.
"\n".
'fk_recruitmentjobposition=EXTRACT:HEADER:^To:[^\n]*\+([^\n]*)'.
"\n".
'description=EXTRACT:BODY:(.*)'.
"\n".
'lastname=SET:__tmp_from__';
332 $sqlforexampleActionC4 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, actionparam, date_creation, fk_user_creat, status)";
333 $sqlforexampleActionC4 .=
" VALUES ((SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".((int) $conf->entity).
"), 'candidature', '".$this->db->escape($paramstring).
"', '".$this->db->idate(
dol_now()).
"', ".((
int) $user->id).
", 1)";
335 $sql[] = $sqlforexampleC1;
337 $sql[] = $sqlforexampleFilterC1;
339 $sql[] = $sqlforexampleFilterC3;
341 $sql[] = $sqlforexampleActionC4;
347 return $this->
_init($sql, $options);