Work on emailcollector
This commit is contained in:
parent
a976dd74db
commit
c4db549f94
@ -1,6 +1,5 @@
|
||||
<?php
|
||||
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) ---Put here your own copyright and developer email---
|
||||
/* Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -17,7 +16,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/admin/emailcollectore/emailcollector_card.php
|
||||
* \file htdocs/admin/emailcollector_card.php
|
||||
* \ingroup emailcollector
|
||||
* \brief Page to create/edit/view emailcollector
|
||||
*/
|
||||
@ -27,10 +26,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php';
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
|
||||
dol_include_once('/emailcollector/class/emailcollector.class.php');
|
||||
dol_include_once('/emailcollector/lib/emailcollector.lib.php');
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/emailcollector/class/emailcollector.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/emailcollector/class/emailcollectorfilter.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/emailcollector/class/emailcollectoraction.lib.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/emailcollector/lib/emailcollector.lib.php';
|
||||
|
||||
if (!$user->admin)
|
||||
accessforbidden();
|
||||
@ -219,6 +220,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
{
|
||||
$res = $object->fetch_optionals();
|
||||
|
||||
$object->fetchFilters();
|
||||
$object->fetchActions();
|
||||
|
||||
$head = emailcollectorPrepareHead($object);
|
||||
dol_fiche_head($head, 'card', $langs->trans("EmailCollector"), -1, 'emailcollector');
|
||||
|
||||
@ -318,6 +322,72 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
|
||||
print '</table>';
|
||||
|
||||
// Filters
|
||||
print '<table class="border centpercent">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Filters").'</td><td></td><td></td>';
|
||||
print '</tr>';
|
||||
// Add filter
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>';
|
||||
$arrayoftypes=array('to'=>'To', 'cc'=>'Cc', 'bcc'=>'Bcc', 'from'=>'From', 'subject'=>'Subject', 'body'=>'Body', 'seen'=>'AlreadyRead', 'unseen'=>'NotRead');
|
||||
print $form->selectarray('filtertype', $arrayoftypes, '', 1);
|
||||
print '</td><td>';
|
||||
print '<input type="text" name="rulevalue">';
|
||||
print '</td>';
|
||||
print '<td align="right"><input type="submit" name="addfilter" id="addfilter" class="flat button" value="'.$langs->trans("Add").'"></td>';
|
||||
print '</tr>';
|
||||
// List filters
|
||||
foreach($object->filters as $rulefilter)
|
||||
{
|
||||
$rulefilterobj=new EmailCollectorFilter($db);
|
||||
$rulefilterobj->fetch($rulefilter['id']);
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$rulefilter['type'].'</td>';
|
||||
print '<td>'.$rulefilter['rulevalue'].'</td>';
|
||||
print '<td>'.$rulefilterobj->getLibStatut(3).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
print '</tr>';
|
||||
print '</table>';
|
||||
|
||||
print '<div class="clearboth"></div><br>';
|
||||
|
||||
// Operations
|
||||
print '<table class="border centpercent">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("EmailcollectorOperations").'</td><td></td><td></td>';
|
||||
print '</tr>';
|
||||
// Add operation
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>';
|
||||
$arrayoftypes=array('recordevent'=>'RecordEvent');
|
||||
if ($conf->projet->enabled) $arrayoftypes['project']='CreateLeadAndThirdParty';
|
||||
print $form->selectarray('operationtype', $arrayoftypes, '', 1);
|
||||
print '</td><td>';
|
||||
print '<input type="text" name="operationparam">';
|
||||
print '</td>';
|
||||
print '<td align="right"><input type="submit" name="addoperation" id="addoperation" class="flat button" value="'.$langs->trans("Add").'"></td>';
|
||||
print '</tr>';
|
||||
// List operations
|
||||
foreach($object->actions as $ruleaction)
|
||||
{
|
||||
$ruleactionobj=new EmailcollectorAction($db);
|
||||
$ruleactionobj->fetch($ruleaction['id']);
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$ruleactionobj['type'].'</td>';
|
||||
print '<td>'.$ruleactionobj['actionparam'].'</td>';
|
||||
print '<td>'.$ruleactionobj->getLibStatut(3).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
print '</tr>';
|
||||
print '</table>';
|
||||
|
||||
|
||||
print '</div>';
|
||||
print '</div>';
|
||||
|
||||
|
||||
@ -155,7 +155,7 @@ class EmailCollector extends CommonObject
|
||||
public $lastresult;
|
||||
// END MODULEBUILDER PROPERTIES
|
||||
|
||||
public $rules;
|
||||
public $filters;
|
||||
public $actions;
|
||||
|
||||
|
||||
@ -613,15 +613,15 @@ class EmailCollector extends CommonObject
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch rules
|
||||
* Fetch filters
|
||||
*
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function fetch_rules()
|
||||
public function fetchFilters()
|
||||
{
|
||||
$this->rules = array();
|
||||
|
||||
$sql='SELECT type, rulevalue FROM '.MAIN_DB_PREFIX.'emailcollector_emailcollectorfilter WHERE status = 1 AND fk_emailcollector = '.$this->id;
|
||||
$sql='SELECT rowid, type, rulevalue, status FROM '.MAIN_DB_PREFIX.'emailcollector_emailcollectorfilter WHERE fk_emailcollector = '.$this->id;
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
@ -631,7 +631,7 @@ class EmailCollector extends CommonObject
|
||||
while($i < $num)
|
||||
{
|
||||
$obj=$this->db->fetch_object($resql);
|
||||
$this->rules[]=array('type'=>$obj->type, 'rulevalue'=>$obj->rulevalue);
|
||||
$this->filters[$obj->rowid]=array('id'=>$obj->rowid, 'type'=>$obj->type, 'rulevalue'=>$obj->rulevalue, 'status'=>$obj->status);
|
||||
}
|
||||
$this->db->free($resql);
|
||||
}
|
||||
@ -644,11 +644,11 @@ class EmailCollector extends CommonObject
|
||||
*
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function fetch_actions()
|
||||
public function fetchActions()
|
||||
{
|
||||
$this->actions = array();
|
||||
|
||||
$sql='SELECT type, actionparam FROM '.MAIN_DB_PREFIX.'emailcollector_emailcollectoraction WHERE status = 1 AND fk_emailcollector = '.$this->id;
|
||||
$sql='SELECT rowid, type, actionparam, status FROM '.MAIN_DB_PREFIX.'emailcollector_emailcollectoraction WHERE fk_emailcollector = '.$this->id;
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
@ -658,7 +658,7 @@ class EmailCollector extends CommonObject
|
||||
while($i < $num)
|
||||
{
|
||||
$obj=$this->db->fetch_object($resql);
|
||||
$this->rules[]=array('type'=>$obj->type, 'actionparam'=>$obj->actionparam);
|
||||
$this->rules[$obj->rowid]=array('id'=>$obj->rowid, 'type'=>$obj->type, 'actionparam'=>$obj->actionparam, 'status'=>$obj->status);
|
||||
}
|
||||
$this->db->free($resql);
|
||||
}
|
||||
@ -709,8 +709,8 @@ class EmailCollector extends CommonObject
|
||||
return -2;
|
||||
}
|
||||
|
||||
$this->fetch_rules();
|
||||
$this->fetch_actions();
|
||||
$this->fetchFilters();
|
||||
$this->fetchActions();
|
||||
|
||||
$sourcedir = $this->source_directory;
|
||||
$targetdir = ($this->target_directory ? $server.$this->target_directory : ''); // Can be '[Gmail]/Trash' or 'mytag'
|
||||
@ -735,16 +735,18 @@ class EmailCollector extends CommonObject
|
||||
|
||||
//$search='ALL';
|
||||
$search='UNDELETED';
|
||||
foreach($this->rules as $key => $rulevalue)
|
||||
foreach($this->filters as $rule)
|
||||
{
|
||||
if ($key == 'to') $search=($search?' ':'').'TO "'.str_replace('"', '', $rulevalue).'"';
|
||||
if ($key == 'bcc') $search=($search?' ':'').'BCC';
|
||||
if ($key == 'cc') $search=($search?' ':'').'CC';
|
||||
if ($key == 'from') $search=($search?' ':'').'FROM "'.str_replace('"', '', $rulevalue).'"';
|
||||
if ($key == 'subject') $search=($search?' ':'').'SUBJECT "'.str_replace('"', '', $rulevalue).'"';
|
||||
if ($key == 'body') $search=($search?' ':'').'BODY "'.str_replace('"', '', $rulevalue).'"';
|
||||
if ($key == 'seen') $search=($search?' ':'').'SEEN';
|
||||
if ($key == 'unseen') $search=($search?' ':'').'UNSEEN';
|
||||
if (empty($rule['status'])) continue;
|
||||
|
||||
if ($rule['key'] == 'to') $search=($search?' ':'').'TO "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['key'] == 'bcc') $search=($search?' ':'').'BCC';
|
||||
if ($rule['key'] == 'cc') $search=($search?' ':'').'CC';
|
||||
if ($rule['key'] == 'from') $search=($search?' ':'').'FROM "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['key'] == 'subject') $search=($search?' ':'').'SUBJECT "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['key'] == 'body') $search=($search?' ':'').'BODY "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['key'] == 'seen') $search=($search?' ':'').'SEEN';
|
||||
if ($rule['key'] == 'unseen') $search=($search?' ':'').'UNSEEN';
|
||||
}
|
||||
|
||||
if (empty($targetdir)) // Use last date as filter if there is no targetdir defined.
|
||||
@ -783,12 +785,14 @@ class EmailCollector extends CommonObject
|
||||
var_dump($message);
|
||||
*/
|
||||
|
||||
// Record email
|
||||
foreach($this->actions as $actionkey => $actionvalue)
|
||||
// Do operationss
|
||||
foreach($this->actions as $operation)
|
||||
{
|
||||
if ($errorforactions) break;
|
||||
if (empty($operation['status'])) continue;
|
||||
|
||||
// Make Operation
|
||||
|
||||
// Make action
|
||||
|
||||
|
||||
if (! $errorforactions)
|
||||
|
||||
@ -1819,6 +1819,7 @@ NewEmailCollector=New Email Collector
|
||||
EMailHost=Host of email IMAP server
|
||||
MailboxSourceDirectory=Mailbox source directory
|
||||
MailboxTargetDirectory=Mailbox target directory
|
||||
EmailcollectorOperations=Operations done by collector
|
||||
CollectNow=Collect now
|
||||
DateLastResult=Date last collect
|
||||
LastResult=Last result
|
||||
|
||||
Loading…
Reference in New Issue
Block a user