Work on email collector

This commit is contained in:
Laurent Destailleur 2019-04-09 13:23:30 +02:00
parent 3cfeba0113
commit f9860e1425
4 changed files with 34 additions and 17 deletions

View File

@ -554,10 +554,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
}
print '</td>';
print '<td>'.$ruleaction['actionparam'].'</td>';
print '<td class="right">';
//print $ruleactionobj->getLibStatut(3);
print ' <a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deleteoperation&operationid='.$ruleaction['id'].'">'.img_delete().'</a>';
print '</td>';
// Move up/down
print '<td class="center linecolmove tdlineupdown">';
if ($i > 0)
{
@ -567,6 +564,10 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<a class="lineupdown" href="'.$_SERVER['PHP_SELF'].'?action=down&amp;rowid='.$ruleaction['id'].'">'.img_down('default', 0, 'imgdownforline').'</a>';
}
print '</td>';
// Delete
print '<td class="right">';
print ' <a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deleteoperation&operationid='.$ruleaction['id'].'">'.img_delete().'</a>';
print '</td>';
print '</tr>';
$i++;
}
@ -575,6 +576,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '</table>';
if (! empty($conf->use_javascript_ajax)) {
$urltorefreshaftermove = DOL_URL_ROOT.'/admin/emailcollector_card.php?id='.$id;
include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
}

View File

@ -77,8 +77,8 @@ $(document).ready(function(){
function() {
console.log("tableDND end of ajax call");
if (reloadpage == 1) {
//console.log('<?php echo dol_escape_js($_SERVER['QUERY_STRING']); ?>');
location.href = '<?php echo dol_escape_js($_SERVER['PHP_SELF']).'?'.dol_escape_js($_SERVER['QUERY_STRING']); ?>';
//console.log('<?php echo $urltorefreshaftermove.' - '.$_SERVER['PHP_SELF'].' - '.dol_escape_js($_SERVER['QUERY_STRING']); ?>');
location.href = '<?php echo dol_escape_js(empty($urltorefreshaftermove) ? ($_SERVER['PHP_SELF'].'?'.dol_escape_js($_SERVER['QUERY_STRING'])) : $urltorefreshaftermove); ?>';
} else {
$("#<?php echo $tagidfortablednd; ?> .drag").each(
function( intIndex ) {

View File

@ -734,9 +734,10 @@ class EmailCollector extends CommonObject
* @param string $actionparam Action parameters
* @param string $messagetext Body
* @param string $subject Subject
* @param string $header Header
* @return int 0=OK, Nb of error if error
*/
private function overwritePropertiesOfObject(&$object, $actionparam, $messagetext, $subject)
private function overwritePropertiesOfObject(&$object, $actionparam, $messagetext, $subject, $header)
{
$errorforthisaction = 0;
@ -776,21 +777,35 @@ class EmailCollector extends CommonObject
$sourcefield=$regforregex[1];
$regexstring=$regforregex[2];
}
if (! empty($sourcefield) && ! empty($regexstring))
{
if (strtolower($sourcefield) == 'body') $sourcestring=$messagetext;
elseif (strtolower($sourcefield) == 'subject') $sourcestring=$subject;
elseif (strtolower($sourcefield) == 'header') $sourcestring=$header;
$regforval=array();
if (preg_match('/'.preg_quote($regexstring, '/').'/', $sourcestring, $regforval))
if ($sourcestring)
{
// Overwrite param $tmpproperty
$object->$tmpproperty = $regforval[1];
$regforval=array();
//var_dump($regexstring);var_dump($sourcestring);
if (preg_match('/'.$regexstring.'/ms', $sourcestring, $regforval))
{
//var_dump($regforval[1]);exit;
// Overwrite param $tmpproperty
$object->$tmpproperty = isset($regforval[1])?trim($regforval[1]):null;
}
else
{
// Regex not found
$object->$tmpproperty = null;
}
//var_dump($object->$tmpproperty);exit;
}
else
{
// Nothing can be done for this param
$errorforthisaction++;
$this->errors = 'The extract rule to use has on an unknown source (must be HEADER, SUBJECT or BODY)';
$this->errors[] = $this->error;
}
}
elseif (preg_match('/^SET:(.*)$/', $valueforproperty, $reg))
@ -1360,7 +1375,7 @@ class EmailCollector extends CommonObject
$thirdpartystatic->email = $from;
// Overwrite values with values extracted from source email
$errorforthisaction = $this->overwritePropertiesOfObject($thirdpartystatic, $operation['actionparam'], $messagetext, $subject);
$errorforthisaction = $this->overwritePropertiesOfObject($thirdpartystatic, $operation['actionparam'], $messagetext, $subject, $header);
if ($errorforthisaction)
{
@ -1441,7 +1456,7 @@ class EmailCollector extends CommonObject
//$actioncomm->extraparams = $extraparams;
// Overwrite values with values extracted from source email
$errorforthisaction = $this->overwritePropertiesOfObject($actioncommn, $operation['actionparam'], $messagetext, $subject);
$errorforthisaction = $this->overwritePropertiesOfObject($actioncommn, $operation['actionparam'], $messagetext, $subject, $header);
if ($errorforthisaction)
{
@ -1513,7 +1528,7 @@ class EmailCollector extends CommonObject
$projecttocreate->ref = $defaultref;
// Overwrite values with values extracted from source email
$errorforthisaction = $this->overwritePropertiesOfObject($projecttocreate, $operation['actionparam'], $messagetext, $subject);
$errorforthisaction = $this->overwritePropertiesOfObject($projecttocreate, $operation['actionparam'], $messagetext, $subject, $header);
if ($errorforthisaction)
{
@ -1597,7 +1612,7 @@ class EmailCollector extends CommonObject
$tickettocreate->ref = $defaultref;
// Overwrite values with values extracted from source email
$errorforthisaction = $this->overwritePropertiesOfObject($tickettocreate, $operation['actionparam'], $messagetext, $subject);
$errorforthisaction = $this->overwritePropertiesOfObject($tickettocreate, $operation['actionparam'], $messagetext, $subject, $header);
if ($errorforthisaction)
{

View File

@ -1849,7 +1849,7 @@ WithoutDolTrackingID=Dolibarr Tracking ID not found
FormatZip=Zip
MainMenuCode=Menu entry code (mainmenu)
ECMAutoTree=Show automatic ECM tree
OperationParamDesc=Define values to use for action, or how to extract values. For example:<br>objproperty1=SET:abc<br>objproperty2=EXTRACT:HEADER:X-Myheaderkey.*[^\s]+(.*)<br>objproperty3=EXTRACT:SUBJECT:([^\s]*)<br>object.objproperty4=EXTRACT:BODY:My company name is\s([^\s]*)<br><br>Use a ; char as separator to extract or set several properties.
OperationParamDesc=Define values to use for action, or how to extract values. For example:<br>objproperty1=SET:abc<br>objproperty2=EXTRACT:HEADER:X-Myheaderkey.*[^\s]+(.*)<br>options_myextrafield=EXTRACT:SUBJECT:([^\s]*)<br>object.objproperty4=EXTRACT:BODY:My company name is\s([^\s]*)<br><br>Use a ; char as separator to extract or set several properties.
OpeningHours=Opening hours
OpeningHoursDesc=Enter here the regular opening hours of your company.
ResourceSetup=Configuration of Resource module