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();
103 $this->
const = array(
108 if (!isset(
$conf->emailcollector) || !isset(
$conf->emailcollector->enabled)) {
110 $conf->emailcollector->enabled = 0;
115 $this->tabs = array();
144 $this->dictionaries = array();
149 $this->boxes = array(
158 $this->cronjobs = array(
159 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")')
164 $this->rights = array();
167 $this->menu = array();
170 $this->menu[$r] = array(
'fk_menu'=>
'fk_mainmenu=home,fk_leftmenu=admintools',
172 'titre'=>
'EmailCollectors',
173 'url'=>
'/admin/emailcollector_list.php?leftmenu=admintools',
176 'enabled'=>
'isModEnabled("emailcollector") && preg_match(\'/^(admintools|all)/\', $leftmenu)',
177 'perms'=>
'$user->admin',
191 public function init($options =
'')
193 global
$conf, $user, $langs;
194 $langs->load(
"admin");
198 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Ticket_Requests' and entity = ".
$conf->entity;
199 $tmpresql = $this->db->query($tmpsql);
201 if ($this->db->num_rows($tmpresql) == 0) {
202 $descriptionA1 = $langs->trans(
'EmailCollectorExampleToCollectTicketRequestsDesc');
203 $label = $langs->trans(
'EmailCollectorExampleToCollectTicketRequests');
204 $sqlforexampleA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
205 $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)";
207 $sqlforexampleFilterA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
208 $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)";
211 $sqlforexampleFilterA3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
212 $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)";
214 $sqlforexampleActionA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
215 $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)";
217 $sql[] = $sqlforexampleA1;
219 $sql[] = $sqlforexampleFilterA1;
221 $sql[] = $sqlforexampleFilterA3;
223 $sql[] = $sqlforexampleActionA1;
229 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Responses_Out' and entity = ".
$conf->entity;
230 $tmpresql = $this->db->query($tmpsql);
232 if ($this->db->num_rows($tmpresql) == 0) {
233 $descriptionA1 = $langs->trans(
'EmailCollectorExampleToCollectAnswersFromExternalEmailSoftware');
234 $label = $langs->trans(
'EmailCollectorExampleToCollectAnswersFromExternalEmailSoftware');
235 $sqlforexampleA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
236 $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)";
238 $sqlforexampleFilterA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
239 $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)";
240 $sqlforexampleFilterA2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
241 $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)";
243 $sqlforexampleActionA1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
244 $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)";
246 $sql[] = $sqlforexampleA1;
248 $sql[] = $sqlforexampleFilterA1;
249 $sql[] = $sqlforexampleFilterA2;
251 $sql[] = $sqlforexampleActionA1;
255 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Responses_In' and entity = ".((int)
$conf->entity);
256 $tmpresql = $this->db->query($tmpsql);
258 if ($this->db->num_rows($tmpresql) == 0) {
259 $descriptionB1 = $langs->trans(
'EmailCollectorExampleToCollectDolibarrAnswersDesc');
260 $label = $langs->trans(
'EmailCollectorExampleToCollectDolibarrAnswers');
261 $sqlforexampleB1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
262 $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)";
264 $sqlforexampleFilterB2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
265 $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)";
267 $sqlforexampleActionB3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, date_creation, fk_user_creat, status)";
268 $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)";
270 $sql[] = $sqlforexampleB1;
272 $sql[] = $sqlforexampleFilterB2;
274 $sql[] = $sqlforexampleActionB3;
280 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Leads' and entity = ".((int)
$conf->entity);
281 $tmpresql = $this->db->query($tmpsql);
283 if ($this->db->num_rows($tmpresql) == 0) {
284 $descriptionC1 = $langs->trans(
"EmailCollectorExampleToCollectLeadsDesc");
285 $label = $langs->trans(
'EmailCollectorExampleToCollectLeads');
286 $sqlforexampleC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
287 $sqlforexampleC1 .=
" VALUES (".$conf->entity.
", 'Collect_Leads', '".$this->db->escape($label).
"', '".$this->db->escape($descriptionC1).
"', 'INBOX', '".$this->db->idate(
dol_now()).
"', ".((int) $user->id).
", 0)";
289 $sqlforexampleFilterC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
290 $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)";
293 $sqlforexampleFilterC3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
294 $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)";
296 $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';
297 $sqlforexampleActionC4 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, actionparam, date_creation, fk_user_creat, status)";
298 $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)";
300 $sql[] = $sqlforexampleC1;
302 $sql[] = $sqlforexampleFilterC1;
304 $sql[] = $sqlforexampleFilterC3;
306 $sql[] = $sqlforexampleActionC4;
312 $tmpsql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"emailcollector_emailcollector WHERE ref = 'Collect_Candidatures' and entity = ".((int)
$conf->entity);
313 $tmpresql = $this->db->query($tmpsql);
315 if ($this->db->num_rows($tmpresql) == 0) {
316 $descriptionC1 = $langs->trans(
"EmailCollectorExampleToCollectJobCandidaturesDesc");
317 $label = $langs->trans(
'EmailCollectorExampleToCollectJobCandidatures');
318 $sqlforexampleC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollector (entity, ref, label, description, source_directory, date_creation, fk_user_creat, status)";
319 $sqlforexampleC1 .=
" VALUES (".$conf->entity.
", 'Collect_Candidatures', '".$this->db->escape($label).
"', '".$this->db->escape($descriptionC1).
"', 'INBOX', '".$this->db->idate(
dol_now()).
"', ".((int) $user->id).
", 0)";
321 $sqlforexampleFilterC1 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, date_creation, fk_user_creat, status)";
322 $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)";
325 $sqlforexampleFilterC3 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectorfilter (fk_emailcollector, type, rulevalue, date_creation, fk_user_creat, status)";
326 $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)";
328 $paramstring =
'tmp_from=EXTRACT:HEADER:^From:(.*)(<.*>)?'.
"\n".
'fk_recruitmentjobposition=EXTRACT:HEADER:^To:[^\n]*\+([^\n]*)'.
"\n".
'description=EXTRACT:BODY:(.*)'.
"\n".
'lastname=SET:__tmp_from__';
329 $sqlforexampleActionC4 =
"INSERT INTO ".MAIN_DB_PREFIX.
"emailcollector_emailcollectoraction (fk_emailcollector, type, actionparam, date_creation, fk_user_creat, status)";
330 $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)";
332 $sql[] = $sqlforexampleC1;
334 $sql[] = $sqlforexampleFilterC1;
336 $sql[] = $sqlforexampleFilterC3;
338 $sql[] = $sqlforexampleActionC4;
344 return $this->
_init($sql, $options);