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->warnings_activation = array();
95 $this->warnings_activation_ext = array();
104 $this->
const = array(
109 if (!isset($conf->emailcollector) || !isset($conf->emailcollector->enabled)) {
110 $conf->emailcollector =
new stdClass();
111 $conf->emailcollector->enabled = 0;
116 $this->tabs = array();
145 $this->dictionaries = array();
150 $this->boxes = array(
159 $this->cronjobs = array(
160 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'=>
'isModEnabled("emailcollector")')
165 $this->rights = array();
168 $this->menu = array();
171 $this->menu[$r] = array(
'fk_menu'=>
'fk_mainmenu=home,fk_leftmenu=admintools',
173 'titre'=>
'EmailCollectors',
174 'url'=>
'/admin/emailcollector_list.php?leftmenu=admintools',
177 'enabled'=>
'isModEnabled("emailcollector") && preg_match(\'/^(admintools|all)/\', $leftmenu)',
178 'perms'=>
'$user->admin',
192 public function init($options =
'')
194 global $conf, $user, $langs;
195 $langs->load(
"admin");
199 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requests' and entity = ".$conf->entity;
200 $tmpresql = $this->db->query($tmpsql);
202 if ($this->db->num_rows($tmpresql) == 0) {
203 $descriptionA1 = $langs->trans(
'EmailCollectorExampleToCollectTicketRequestsDesc');
204 $label = $langs->trans(
'EmailCollectorExampleToCollectTicketRequests');
205 $sqlforexampleA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
206 $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)";
208 $sqlforexampleFilterA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
209 $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)";
212 $sqlforexampleFilterA3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
213 $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)";
215 $sqlforexampleActionA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
216 $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)";
218 $sql[] = $sqlforexampleA1;
220 $sql[] = $sqlforexampleFilterA1;
222 $sql[] = $sqlforexampleFilterA3;
224 $sql[] = $sqlforexampleActionA1;
230 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Responses_Out' and entity = ".$conf->entity;
231 $tmpresql = $this->db->query($tmpsql);
233 if ($this->db->num_rows($tmpresql) == 0) {
234 $descriptionA1 = $langs->trans(
'EmailCollectorExampleToCollectAnswersFromExternalEmailSoftware');
235 $label = $langs->trans(
'EmailCollectorExampleToCollectAnswersFromExternalEmailSoftware');
236 $sqlforexampleA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
237 $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)";
239 $sqlforexampleFilterA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
240 $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)";
241 $sqlforexampleFilterA2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
242 $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)";
244 $sqlforexampleActionA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
245 $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)";
247 $sql[] = $sqlforexampleA1;
249 $sql[] = $sqlforexampleFilterA1;
250 $sql[] = $sqlforexampleFilterA2;
252 $sql[] = $sqlforexampleActionA1;
256 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Responses_In' and entity = ".((int) $conf->entity);
257 $tmpresql = $this->db->query($tmpsql);
259 if ($this->db->num_rows($tmpresql) == 0) {
260 $descriptionB1 = $langs->trans(
'EmailCollectorExampleToCollectDolibarrAnswersDesc');
261 $label = $langs->trans(
'EmailCollectorExampleToCollectDolibarrAnswers');
262 $sqlforexampleB1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
263 $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)";
265 $sqlforexampleFilterB2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
266 $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)";
268 $sqlforexampleActionB3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
269 $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)";
271 $sql[] = $sqlforexampleB1;
273 $sql[] = $sqlforexampleFilterB2;
275 $sql[] = $sqlforexampleActionB3;
281 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".((int) $conf->entity);
282 $tmpresql = $this->db->query($tmpsql);
284 if ($this->db->num_rows($tmpresql) == 0) {
285 $descriptionC1 = $langs->trans(
"EmailCollectorExampleToCollectLeadsDesc");
286 $label = $langs->trans(
'EmailCollectorExampleToCollectLeads');
287 $sqlforexampleC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
288 $sqlforexampleC1 .=
" VALUES (".$conf->entity.
", 'Collect_Leads', '".$this->db->escape($label).
"', '".$this->db->escape($descriptionC1).
"', 'INBOX', '".$this->db->idate(
dol_now()).
"', ".((int) $user->id).
", 0)";
290 $sqlforexampleFilterC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
291 $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)";
294 $sqlforexampleFilterC3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
295 $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)";
297 $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';
298 $sqlforexampleActionC4 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, actionparam, date_creation, fk_user_creat, status)";
299 $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)";
301 $sql[] = $sqlforexampleC1;
303 $sql[] = $sqlforexampleFilterC1;
305 $sql[] = $sqlforexampleFilterC3;
307 $sql[] = $sqlforexampleActionC4;
313 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".((int) $conf->entity);
314 $tmpresql = $this->db->query($tmpsql);
316 if ($this->db->num_rows($tmpresql) == 0) {
317 $descriptionC1 = $langs->trans(
"EmailCollectorExampleToCollectJobCandidaturesDesc");
318 $label = $langs->trans(
'EmailCollectorExampleToCollectJobCandidatures');
319 $sqlforexampleC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
320 $sqlforexampleC1 .=
" VALUES (".$conf->entity.
", 'Collect_Candidatures', '".$this->db->escape($label).
"', '".$this->db->escape($descriptionC1).
"', 'INBOX', '".$this->db->idate(
dol_now()).
"', ".((int) $user->id).
", 0)";
322 $sqlforexampleFilterC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
323 $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)";
326 $sqlforexampleFilterC3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
327 $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)";
329 $paramstring =
'tmp_from=EXTRACT:HEADER:^From:(.*)(<.*>)?'.
"\n".
'fk_recruitmentjobposition=EXTRACT:HEADER:^To:[^\n]*\+([^\n]*)'.
"\n".
'description=EXTRACT:BODY:(.*)'.
"\n".
'lastname=SET:__tmp_from__';
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', '".$this->db->escape($paramstring).
"', '".$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);