Merge branch 'develop' into patch-92

This commit is contained in:
Laurent Destailleur
2018-11-15 16:22:45 +01:00
committed by GitHub
16 changed files with 455 additions and 107 deletions

View File

@@ -466,7 +466,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<td>';
$arrayoftypes=array('recordevent'=>'RecordEvent');
if ($conf->projet->enabled) $arrayoftypes['project']='CreateLeadAndThirdParty';
print $form->selectarray('operationtype', $arrayoftypes, '', 0, 0, 0, '', 1);
print $form->selectarray('operationtype', $arrayoftypes, '', 1, 0, 0, '', 1);
print '</td><td>';
print '<input type="text" name="operationparam">';
print '</td>';

View File

@@ -232,13 +232,13 @@ print '</td>';
print '</tr>';
//EntToEnd
print '<tr class="pair"><td class="fieldrequired">'.$langs->trans("END_TO_END").'</td>';
print '<tr class="pair"><td>'.$langs->trans("END_TO_END").'</td>';
print '<td align="left">';
print '<input type="text" name="PRELEVEMENT_END_TO_END" value="'.$conf->global->END_TO_END.'" size="15" ></td>';
print '</td></tr>';
//USTRD
print '<tr class="pair"><td class="fieldrequired">'.$langs->trans("USTRD").'</td>';
print '<tr class="pair"><td>'.$langs->trans("USTRD").'</td>';
print '<td align="left">';
print '<input type="text" name="PRELEVEMENT_USTRD" value="'.$conf->global->USTRD.'" size="15" ></td>';
print '</td></tr>';

View File

@@ -87,17 +87,17 @@ class Contact extends CommonObject
/**
* @deprecated
* @see state_id
* @see $state_id
*/
public $fk_departement;
/**
* @deprecated
* @see state_code
* @see $state_code
*/
public $departement_code;
/**
* @deprecated
* @see state
* @see $state
*/
public $departement;
public $state_id; // Id of department
@@ -682,12 +682,13 @@ class Contact extends CommonObject
/**
* Load object contact
*
* @param int $id id du contact
* @param User $user Utilisateur (abonnes aux alertes) qui veut les alertes de ce contact
* @param string $ref_ext External reference, not given by Dolibarr
* @return int -1 if KO, 0 if OK but not found, 1 if OK
* @param int $id id du contact
* @param User $user Utilisateur (abonnes aux alertes) qui veut les alertes de ce contact
* @param string $ref_ext External reference, not given by Dolibarr
* @param string $email Email
* @return int -1 if KO, 0 if OK but not found, 1 if OK
*/
function fetch($id, $user=0, $ref_ext='')
function fetch($id, $user=null, $ref_ext='', $email='')
{
global $langs;
@@ -721,9 +722,15 @@ class Contact extends CommonObject
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
if ($id) $sql.= " WHERE c.rowid = ". $id;
elseif ($ref_ext) {
else
{
$sql .= " WHERE c.entity IN (".getEntity($this->element).")";
$sql .= " AND c.ref_ext = '".$this->db->escape($ref_ext)."'";
if ($ref_ext) {
$sql .= " AND c.ref_ext = '".$this->db->escape($ref_ext)."'";
}
if ($email) {
$sql .= " AND c.email = '".$this->db->escape($email)."'";
}
}
$resql=$this->db->query($sql);

View File

@@ -427,8 +427,9 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$object->socid = $sendtosocid; // To link to a company
$object->sendtoid = $sendtoid; // To link to contact addresses. This is an array.
$object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
$object->actionmsg = $actionmsg; // Long text
$object->actionmsg2 = $actionmsg2; // Short text
$object->actionmsg = $actionmsg; // Long text (@TODO Replace this with $message, we already have details of email in dedicated properties)
$object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...);
$object->trackid = $trackid;
$object->fk_element = $object->id;
$object->elementtype = $object->element;
@@ -439,9 +440,14 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$object->sendtouserid = $sendtouserid;
}
// TODO Set object->email_xxx properties
$object->email_msgid = $mailfile->msgid; // @TODO Set msgid into $mailfile after sending
$object->email_from = $from;
$object->email_subject = $subject;
$object->email_to = $sendto;
$object->email_tocc = $sendtocc;
$object->email_tobcc = $sendtobcc;
$object->email_subject = $subject;
$object->email_msgid = $mailfile->msgid;
//...
// Call of triggers
if (! empty($trigger_name))

View File

@@ -1731,7 +1731,7 @@ function email_admin_prepare_head()
$h = 0;
$head = array();
if ($user->admin && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates'))
if (! empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates'))
{
$head[$h][0] = DOL_URL_ROOT."/admin/mails.php";
$head[$h][1] = $langs->trans("OutGoingEmailSetup");
@@ -1752,7 +1752,7 @@ function email_admin_prepare_head()
$head[$h][2] = 'templates';
$h++;
if ($conf->global->MAIN_FEATURES_LEVEL >= 1)
if ($conf->global->MAIN_FEATURES_LEVEL >= 1 && ! empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates'))
{
$head[$h][0] = DOL_URL_ROOT."/admin/mails_senderprofile_list.php";
$head[$h][1] = $langs->trans("EmailSenderProfiles");

View File

@@ -2837,35 +2837,50 @@ function isValidPhone($phone)
* @param string $stringencoding Encoding of string
* @return int Length of string
*/
function dol_strlen($string,$stringencoding='UTF-8')
function dol_strlen($string, $stringencoding='UTF-8')
{
if (function_exists('mb_strlen')) return mb_strlen($string,$stringencoding);
else return strlen($string);
}
/**
* Make a substring. Works even in mbstring module is not enabled.
* Make a substring. Works even if mbstring module is not enabled for better compatibility.
*
* @param string $string String to scan
* @param string $start Start position
* @param int $length Length
* @param int $length Length (in nb of characters or nb of bytes depending on trunconbytes param)
* @param string $stringencoding Page code used for input string encoding
* @param int $trunconbytes 1=Length is max of bytes instead of max of characters
* @return string substring
*/
function dol_substr($string,$start,$length,$stringencoding='')
function dol_substr($string, $start, $length, $stringencoding='', $trunconbytes=0)
{
global $langs;
if (empty($stringencoding)) $stringencoding=$langs->charset_output;
$ret='';
if (function_exists('mb_substr'))
if (empty($trunconbytes))
{
$ret=mb_substr($string,$start,$length,$stringencoding);
if (function_exists('mb_substr'))
{
$ret=mb_substr($string, $start, $length, $stringencoding);
}
else
{
$ret=substr($string, $start, $length);
}
}
else
{
$ret=substr($string,$start,$length);
if (function_exists('mb_strcut'))
{
$ret=mb_strcut($string, $start, $length, $stringencoding);
}
else
{
$ret=substr($string, $start, $length);
}
}
return $ret;
}
@@ -3063,7 +3078,7 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',
* @param string $trunc Where to trunc: right, left, middle (size must be a 2 power), wrap
* @param string $stringencoding Tell what is source string encoding
* @param int $nodot Truncation do not add ... after truncation. So it's an exact truncation.
* @param int $display Trunc is use to display and can be changed for small screen. TODO Remove this param (must be dealt with CSS)
* @param int $display Trunc is used to display data and can be changed for small screen. TODO Remove this param (must be dealt with CSS)
* @return string Truncated string. WARNING: length is never higher than $size if $nodot is set, but can be 3 chars higher otherwise.
*/
function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodot=0, $display=0)
@@ -6782,26 +6797,27 @@ function dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id
if ($key == '') return '';
// Check in cache
if (isset($cache_codes[$tablename][$key])) // Can be defined to 0 or ''
if (isset($cache_codes[$tablename][$key][$fieldid])) // Can be defined to 0 or ''
{
return $cache_codes[$tablename][$key]; // Found in cache
return $cache_codes[$tablename][$key][$fieldid]; // Found in cache
}
dol_syslog('dol_getIdFromCode (value not found into cache)', LOG_DEBUG);
$sql = "SELECT ".$fieldid." as valuetoget";
$sql.= " FROM ".MAIN_DB_PREFIX.$tablename;
$sql.= " WHERE ".$fieldkey." = '".$db->escape($key)."'";
if (! empty($entityfilter))
$sql.= " AND entity IN (" . getEntity($tablename) . ")";
dol_syslog('dol_getIdFromCode', LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
if ($obj) $cache_codes[$tablename][$key]=$obj->valuetoget;
else $cache_codes[$tablename][$key]='';
if ($obj) $cache_codes[$tablename][$key][$fieldid]=$obj->valuetoget;
else $cache_codes[$tablename][$key][$fieldid]='';
$db->free($resql);
return $cache_codes[$tablename][$key];
return $cache_codes[$tablename][$key][$fieldid];
}
else
{
@@ -6889,8 +6905,6 @@ function picto_from_langcode($codelang, $moreatt = '')
if (empty($codelang)) return '';
if (empty($codelang)) return '';
if ($codelang == 'auto')
{
return '<span class="fa fa-globe"></span>';
@@ -7061,6 +7075,7 @@ function printCommonFooter($zone='private')
if (! empty($conf->use_javascript_ajax))
{
print '<script type="text/javascript" language="javascript">'."\n";
print 'jQuery(document).ready(function() {'."\n";
if ($zone == 'private' && empty($conf->dol_use_jmobile))
{
@@ -7143,6 +7158,8 @@ function printCommonFooter($zone='private')
}
}
print '});'."\n";
// Google Analytics
// TODO Add a hook here
if (! empty($conf->google->enabled) && ! empty($conf->global->MAIN_GOOGLE_AN_ID))

View File

@@ -244,7 +244,7 @@ class modAgenda extends DolibarrModules
// Calendar
$this->menu[$r]=array('fk_menu'=>'r=1',
'type'=>'left',
'titre'=>'Agenda',
'titre'=>'Calendar',
'mainmenu'=>'agenda',
'url'=>'/comm/action/index.php?action=default&amp;mainmenu=agenda&amp;leftmenu=agenda',
'langs'=>'agenda',

View File

@@ -122,7 +122,7 @@ class mod_project_simple extends ModeleNumRefProjects
* @param Project $project Object project
* @return string Value if OK, 0 if KO
*/
function getNextValue($objsoc,$project)
function getNextValue($objsoc, $project)
{
global $db,$conf;
@@ -167,9 +167,9 @@ class mod_project_simple extends ModeleNumRefProjects
* @param Project $project Object project
* @return string Next not used reference
*/
function project_get_num($objsoc=0,$project='')
function project_get_num($objsoc=0, $project='')
{
// phpcs:enable
return $this->getNextValue($objsoc,$project);
return $this->getNextValue($objsoc, $project);
}
}

View File

@@ -123,7 +123,7 @@ class mod_project_universal extends ModeleNumRefProjects
* @param Project $project Object project
* @return string Value if OK, 0 if KO
*/
function getNextValue($objsoc,$project)
function getNextValue($objsoc, $project)
{
global $db,$conf;
@@ -139,7 +139,7 @@ class mod_project_universal extends ModeleNumRefProjects
}
$date=empty($project->date_c)?dol_now():$project->date_c;
$numFinal=get_next_value($db,$mask,'projet','ref','',$objsoc->code_client,$date);
$numFinal=get_next_value($db, $mask, 'projet', 'ref', '', (is_object($objsoc) ? $objsoc->code_client : ''), $date);
return $numFinal;
}
@@ -153,9 +153,9 @@ class mod_project_universal extends ModeleNumRefProjects
* @param Project $project Object project
* @return string Next not used reference
*/
function project_get_num($objsoc=0,$project='')
function project_get_num($objsoc=0, $project='')
{
// phpcs:enable
return $this->getNextValue($objsoc,$project);
return $this->getNextValue($objsoc, $project);
}
}

View File

@@ -23,8 +23,11 @@
// Put here all includes required by your class file
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
/**
* Class for EmailCollector
@@ -647,6 +650,25 @@ class EmailCollector extends CommonObject
}
/**
* Return the connectstring to use with IMAP connection function
*
* @return string
*/
function getConnectStringIMAP()
{
// Connect to IMAP
$flags ='/service=imap'; // IMAP
$flags.='/ssl'; // '/tls'
$flags.='/novalidate-cert';
//$flags.='/readonly';
//$flags.='/debug';
$connectstringserver = '{'.$this->host.':993'.$flags.'}';
return $connectstringserver;
}
/**
* Action executed by scheduler
* CAN BE A CRON TASK. In such a case, paramerts come from the schedule job setup field 'Parameters'
@@ -688,12 +710,12 @@ class EmailCollector extends CommonObject
dol_syslog("EmailCollector::doCollectOneCollector start", LOG_DEBUG);
$langs->loadLangs(array("project", "companies", "errors"));
$error = 0;
$this->output = '';
$this->error='';
dol_syslog(__METHOD__, LOG_DEBUG);
$now = dol_now();
if (empty($this->host))
@@ -757,13 +779,18 @@ class EmailCollector extends CommonObject
if ($fromdate > 0) $search.=($search?' ':'').'SINCE '.dol_print_date($fromdate - 1,'dayhourrfc');
}
dol_syslog("search string = ".$search);
//var_dump($search);exit;
//var_dump($search);
$nbemailprocessed=0; $nbactiondone=0;
$nbemailprocessed=0;
$nbemailok=0;
$nbactiondone=0;
$projectstatic=new Project($this->db);
$thirdpartystatic=new Societe($this->db);
$contactstatic=new Contact($this->db);
// Scan IMAP inbox
$arrayofemail= imap_search($connection, $search);
//var_dump($arrayofemail);
//var_dump($arrayofemail);exit;
// Loop on each email found
if (! empty($arrayofemail) && count($arrayofemail) > 0)
@@ -772,59 +799,342 @@ class EmailCollector extends CommonObject
{
if ($nbemailprocessed > 100) break; // Do not process more than 100 email per launch
$nbactiondoneforemail = 0;
$errorforemail = 0;
$errorforactions = 0;
$thirdpartyfoundby = '';
$contactfoundby = '';
$projectfoundby = '';
$this->db->begin();
$overview = imap_fetch_overview($connection, $imapemail, 0);
$header = imap_fetchheader($connection, $imapemail, 0);
$message = imap_body($connection, $imapemail, 0);
// imap_fetchstructure($connection, $imapemail, 0);
// imap_fetchbody($connection, $imapemail, 1) may be text/plain, 2 may be text/html
//$message = imap_body($connection, $imapemail, 0);
$structure = imap_fetchstructure($connection, $imapemail, 0);
$partplain = $parthtml = -1;
// Loop to get part html and plain
foreach($structure->parts as $key => $part)
{
if ($part->subtype == 'HTML') $parthtml=$key;
if ($part->subtype == 'PLAIN') $partplain=$key;
}
/*var_dump($overview);
var_dump($header);
var_dump($message);
*/
$matches=array();
preg_match_all('/([^: ]+): (.+?(?:\r\n\s(?:.+?))*)\r\n/m', $header, $matches);
$headers = array_combine($matches[1], $matches[2]);
//var_dump($headers);
// Do operationss
$messagetext = imap_fetchbody($connection, $imapemail, ($parthtml >= 0 ? $parthtml : ($partplain >= 0 ? $partplain : 0)));
//var_dump($overview);
//var_dump($header);
//var_dump($message);
//var_dump($messagetext);
$fromstring=$overview[0]->from;
$sender=$overview[0]->sender;
$to=$overview[0]->to;
$sendtocc=$overview[0]->cc;
$sendtobcc=$overview[0]->bcc;
$date=$overview[0]->udate;
$msgid=str_replace(array('<','>'), '', $overview[0]->message_id);
$subject=$overview[0]->subject;
//var_dump($msgid);exit;
$reg=array();
if (preg_match('/^(.*)<(.*)>$/', $fromstring, $reg))
{
$from=$reg[1];
$fromtext=$reg[0];
}
else
{
$from = $fromstring;
$fromtext='';
}
$fk_element_id = 0; $fk_element_type = '';
$contactid = 0; $thirdpartyid = 0; $projectid = 0;
// Analyze TrackId
$trackid = '';
$reg=array();
if (! empty($headers['X-Dolibarr-TrackId']) && preg_match('/:\s*([a-z]+)([0-9]+)$/', $headers['X-Dolibarr-TrackId'], $reg))
{
$trackid = $reg[0].$reg[1];
$objectid = 0;
$objectemail = null;
if ($reg[0] == 'inv')
{
$objectid = $reg[1];
$objectemail = new Facture($this->db);
}
if ($reg[0] == 'proj')
{
$objectid = $reg[1];
$objectemail = new Project($this->db);
}
if ($reg[0] == 'con')
{
$objectid = $reg[1];
$objectemail = new Contact($this->db);
}
if ($reg[0] == 'thi')
{
$objectid = $reg[1];
$objectemail = new Societe($this->db);
}
if ($reg[0] == 'use')
{
$objectid = $reg[1];
$objectemail = new User($this->db);
}
$result = $objectemail->fetch($objectid);
if ($result > 0)
{
$fk_element_id = $objectemail->id;
$fk_element_type = $objectemail->element;
// Fix fk_element_type
if ($fk_element_type == 'facture') $fk_element_type = 'invoice';
$thirdpartyid = $objectemail->fk_soc;
$contactid = $objectemail->fk_socpeople;
$projectid = isset($objectemail->fk_project)?$objectemail->fk_project:$objectemail->fk_projet;
}
}
// Project
$projectstatic->id=0;
if ($projectid > 0)
{
$result = $projectstatic->fetch($projectid);
if ($result <= 0) $projectstatic->id = 0;
else $projectfoundby = 'Trackid ('.$trackid.')';
}
// Contact
$contactstatic->id=0;
if ($contactid > 0)
{
$result = $contactstatic->fetch($contactid);
if ($result <= 0) $contactstatic->id = 0;
else $contactfoundby = 'Trackid ('.$trackid.')';
}
else // Try to find contact using email
{
$result = $contactstatic->fetch(0, null, '', $from);
if ($result > 0) $contactfoundby = 'email ('.$from.')';
}
// Thirdparty
$thirdpartystatic->id=0;
if ($thirdpartyid > 0)
{
$result = $thirdpartystatic->fetch($thirdpartyid);
if ($result <= 0) $thirdpartystatic->id = 0;
else $thirdpartyfoundby = 'Trackid ('.$trackid.')';
}
else // Try to find thirdparty using email
{
$result = $thirdpartystatic->fetch(0, '', '', '', '', '', '', '', '', '', $from);
if ($result > 0) $thirdpartyfoundby = 'email ('.$from.')';
}
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
// Do operations
foreach($this->actions as $operation)
{
if ($errorforactions) break;
if (empty($operation['status'])) continue;
// Make Operation
if ($operation['type'] == 'recordevent')
{
$actioncode = 'EMAIL_IN';
// Insert record of emails sent
$actioncomm = new ActionComm($this->db);
$actioncomm->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
$actioncomm->code = 'AC_'.$actioncode;
$actioncomm->label = $langs->trans("EmailReceived").' - '.$langs->trans("From").' '.$from;
$actioncomm->note = $messagetext;
$actioncomm->fk_project = $projectstatic->id;
$actioncomm->datep = $date;
$actioncomm->datef = $date;
$actioncomm->percentage = -1; // Not applicable
$actioncomm->socid = $thirdpartystatic->id;
$actioncomm->contactid = $contactstatic->id;
$actioncomm->authorid = $user->id; // User saving action
$actioncomm->userownerid = $user->id; // Owner of action
// Fields when action is en email (content should be added into note)
$actioncomm->email_msgid = $msgid;
$actioncomm->email_from = $fromstring;
$actioncomm->email_sender= $sender;
$actioncomm->email_to = $to;
$actioncomm->email_tocc = $sendtocc;
$actioncomm->email_tobcc = $sendtobcc;
$actioncomm->email_subject = $subject;
$actioncomm->errors_to = '';
$object->email_msgid = $mailfile->msgid; // @TODO Set msgid into $mailfile after sending to have it defined here
$object->email_from = $from;
$object->email_subject = $subject;
$object->email_to = $to;
$object->email_tocc = $sendtocc;
$object->email_tobcc = $sendtobcc;
$object->email_subject = $subject;
$actioncomm->fk_element = $fk_element_id;
$actioncomm->elementtype = $fk_element_type;
//$actioncomm->extraparams = $extraparams;
$result = $actioncomm->create($user);
if ($result <= 0)
{
$errorforactions++;
$this->errors = $actioncomm->errors;
}
}
elseif ($operation['type'] == 'project')
{
// @TODO Check project not alreayd created using ref_ext=msg_id
$note_private = $langs->trans("ProjectCreatedByEmailCollector", $msgid);
$projecttocreate = new Project($this->db);
if ($thirdpartystatic->id > 0)
{
$projecttocreate->fk_soc = $thirdpartystatic->id;
if ($thirdpartyfoundby) $note_private .= ' - Third party found from '.$thirdpartyfoundby;
}
if ($contactstatic->id > 0)
{
$projecttocreate->contact_id = $contactstatic->id;
if ($contactfoundby) $note_private .= ' - Contact/address found from '.$contactfoundby;
}
$id_opp_status = dol_getIdFromCode($this->db, 'PROSP', 'c_lead_status', 'code', 'rowid');
$percent_opp_status = dol_getIdFromCode($this->db, 'PROSP', 'c_lead_status', 'code', 'percent');
$projecttocreate->title = $subject;
$projecttocreate->date_start = $now;
$projecttocreate->opp_status = $id_opp_status;
$projecttocreate->opp_percent = $percent_opp_status;
$projecttocreate->description = ($note_private?$note_private."\n":'').$messagetext;
$projecttocreate->note_private = $note_private;
// Overwrite values with values extracted from source email
$arrayvaluetouse = array();
foreach($arrayvaluetouse as $propertytooverwrite => $valueforproperty)
{
// Example: $propertytooverwrite = 'project.opportunity_status', $valueforproperty = '123' or 'REGEX:BODY:...(.*)...'
}
// Get next project Ref
$defaultref='';
$modele = empty($conf->global->PROJECT_ADDON)?'mod_project_simple':$conf->global->PROJECT_ADDON;
// Search template files
$file=''; $classname=''; $filefound=0;
$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
foreach($dirmodels as $reldir)
{
$file=dol_buildpath($reldir."core/modules/project/".$modele.'.php',0);
if (file_exists($file))
{
$filefound=1;
$classname = $modele;
break;
}
}
if ($filefound)
{
$result=dol_include_once($reldir."core/modules/project/".$modele.'.php');
$modProject = new $classname;
$defaultref = $modProject->getNextValue(($thirdpartystatic->id > 0 ? $thirdpartystatic : null), $projecttocreate);
}
if (is_numeric($defaultref) && $defaultref <= 0)
{
$errorforactions++;
$this->error = 'Failed to create project: Can\'t get a free project Ref';
}
else
{
$projecttocreate->ref = $defaultref;
// Create project
$result = $projecttocreate->create($user);
if ($result <= 0)
{
$errorforactions++;
$this->error = 'Failed to create project: '.$langs->trans($projecttocreate->error);
$this->errors = $projecttocreate->errors;
}
}
}
if (! $errorforactions)
{
$nbactiondone++;
$nbactiondoneforemail++;
}
}
// Move email
if (! $errorforactions && $targetdir)
// Error for email or not ?
if (! $errorforactions)
{
dol_syslog("EmailCollector::doCollectOneCollector move message ".$imapemail." to ".$connectstringtarget, LOG_DEBUG);
$res = imap_mail_move($connection, $imapemail, $targetdir, 0);
if ($res == false) {
$error++;
$this->error = imap_last_error();
dol_syslog(imap_last_error());
if ($targetdir)
{
dol_syslog("EmailCollector::doCollectOneCollector move message ".$imapemail." to ".$connectstringtarget, LOG_DEBUG);
$res = imap_mail_move($connection, $imapemail, $targetdir, 0);
if ($res == false) {
$errorforemail++;
$this->error = imap_last_error();
$this->errors[] = $this->error;
dol_syslog(imap_last_error());
}
}
else
{
dol_syslog("EmailCollector::doCollectOneCollector message ".$imapemail." to ".$connectstringtarget." was set to read", LOG_DEBUG);
}
}
else
{
$errorforemail++;
}
if (! $errorforemail)
{
$nbactiondone += $nbactiondoneforemail;
$nbemailok++;
$this->db->commit();
}
else
{
$error++;
$this->db->rollback();
}
$nbemailprocessed++;
$this->db->commit();
unset($objectemail);
}
$this->output=$langs->trans('XEmailsDoneYActionsDone', $nbemailprocessed, $nbactiondone);
$output=$langs->trans('XEmailsDoneYActionsDone', $nbemailprocessed, $nbemailok, $nbactiondone);
}
else
{
$this->output=$langs->trans('NoNewEmailToProcess');
$output=$langs->trans('NoNewEmailToProcess');
}
imap_expunge($connection); // To validate any move
@@ -832,7 +1142,8 @@ class EmailCollector extends CommonObject
imap_close($connection);
$this->datelastresult = $now;
$this->lastresult = $this->output;
$this->lastresult = $output;
if (! empty($this->errors)) $this->lastresult.= " - ".join(" - ", $this->errors);
$this->codelastresult = ($error ? 'KO' : 'OK');
$this->update($user);
@@ -840,23 +1151,4 @@ class EmailCollector extends CommonObject
return $error?-1:1;
}
/**
* Return the connectstring to use with IMAP connection function
*
* @return string
*/
function getConnectStringIMAP()
{
// Connect to IMAP
$flags ='/service=imap'; // IMAP
$flags.='/ssl'; // '/tls'
$flags.='/novalidate-cert';
//$flags.='/readonly';
//$flags.='/debug';
$connectstringserver = '{'.$this->host.':993'.$flags.'}';
return $connectstringserver;
}
}

View File

@@ -55,7 +55,7 @@ ALTER TABLE llx_product_fournisseur_price ADD COLUMN desc_fourn text after ref_f
ALTER TABLE llx_user ADD COLUMN dateemploymentend date after dateemployment;
ALTER TABLE llx_stock_mouvement ADD COLUMN fk_project integer;
Alter tABLE llx_c_action_trigger MODIFY COLUMN elementtype varchar(32);
ALTER TABLE llx_c_action_trigger MODIFY COLUMN elementtype varchar(32);
ALTER TABLE llx_c_field_list ADD COLUMN visible tinyint DEFAULT 1 NOT NULL AFTER search;

View File

@@ -1833,7 +1833,7 @@ EmailCollectorConfirmCollectTitle=Email collect confirmation
EmailCollectorConfirmCollect=Do you want to run the collect for this collector now ?
NoNewEmailToProcess=No new email (matching filters) to process
NothingProcessed=Nothing done
XEmailsDoneYActionsDone=%s emails analyzed, %s record/actions done by collector
XEmailsDoneYActionsDone=%s emails analyzed, %s emails successfuly processed (for %s record/actions done) by collector
RecordEvent=Record event
CreateLeadAndThirdParty=Create lead (and thirdparty if necessary)
CodeLastResult=Result code of last collect

View File

@@ -244,6 +244,9 @@ YourPasswordHasBeenReset=Your password has been reset successfully
ApplicantIpAddress=IP address of applicant
SMSSentTo=SMS sent to %s
MissingIds=Missing ids
ThirdPartyCreatedByEmailCollector=Third party created by email collector from email ID %s
ContactCreatedByEmailCollector=Contact/address created by email collector from email ID %s
ProjectCreatedByEmailCollector=Project created by email collector from email ID %s
##### Export #####
ExportsArea=Exports area

View File

@@ -179,6 +179,10 @@ class Project extends CommonObject
$now=dol_now();
// Clean parameters
$this->note_private = dol_substr($this->note_private, 0, 65535);
$this->note_public = dol_substr($this->note_public, 0, 65535);
// Check parameters
if (!trim($this->ref))
{
@@ -193,6 +197,7 @@ class Project extends CommonObject
return -1;
}
// Create project
$this->db->begin();
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "projet (";
@@ -211,6 +216,8 @@ class Project extends CommonObject
$sql.= ", opp_amount";
$sql.= ", budget_amount";
$sql.= ", bill_time";
$sql.= ", note_private";
$sql.= ", note_public";
$sql.= ", entity";
$sql.= ") VALUES (";
$sql.= "'" . $this->db->escape($this->ref) . "'";
@@ -228,6 +235,8 @@ class Project extends CommonObject
$sql.= ", " . (strcmp($this->opp_amount,'') ? price2num($this->opp_amount) : 'null');
$sql.= ", " . (strcmp($this->budget_amount,'') ? price2num($this->budget_amount) : 'null');
$sql.= ", " . ($this->bill_time ? 1 : 0);
$sql.= ", ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : 'null');
$sql.= ", ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : 'null');
$sql.= ", ".$conf->entity;
$sql.= ")";

View File

@@ -261,15 +261,18 @@ print '<div class="div-table-responsive">';
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Module").'</td>';
if ($caneditperms && empty($objMod->rights_admin_allowed) || empty($object->admin))
if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->admin))
{
print '<td align="center" class="nowrap">';
print '<a class="reposition" title="'.dol_escape_htmltag($langs->trans("All")).'" alt="'.dol_escape_htmltag($langs->trans("All")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addrights&amp;entity='.$entity.'&amp;module=allmodules">'.$langs->trans("All")."</a>";
print '/';
print '<a class="reposition" title="'.dol_escape_htmltag($langs->trans("None")).'" alt="'.dol_escape_htmltag($langs->trans("None")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delrights&amp;entity='.$entity.'&amp;module=allmodules">'.$langs->trans("None")."</a>";
print '</td>';
if ($caneditperms)
{
print '<td align="center" class="nowrap">';
print '<a class="reposition" title="'.dol_escape_htmltag($langs->trans("All")).'" alt="'.dol_escape_htmltag($langs->trans("All")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addrights&amp;entity='.$entity.'&amp;module=allmodules">'.$langs->trans("All")."</a>";
print '/';
print '<a class="reposition" title="'.dol_escape_htmltag($langs->trans("None")).'" alt="'.dol_escape_htmltag($langs->trans("None")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delrights&amp;entity='.$entity.'&amp;module=allmodules">'.$langs->trans("None")."</a>";
print '</td>';
}
print '<td align="center" width="24">&nbsp;</td>';
}
print '<td align="center" width="24">&nbsp;</td>';
print '<td>'.$langs->trans("Permissions").'</td>';
print '</tr>'."\n";
@@ -310,21 +313,31 @@ if ($result)
print '<tr class="oddeven trforbreak">';
print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">'.img_object('',$picto,'class="pictoobjectwidth"').' '.$objMod->getName();
print '<a name="'.$objMod->getName().'"></a></td>';
print '<td align="center" class="nowrap">';
if ($caneditperms && empty($objMod->rights_admin_allowed) || empty($object->admin))
if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->admin))
{
print '<a class="reposition" title="'.dol_escape_htmltag($langs->trans("All")).'" alt="'.dol_escape_htmltag($langs->trans("All")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addrights&amp;entity='.$entity.'&amp;module='.$obj->module.'">'.$langs->trans("All")."</a>";
print '/';
print '<a class="reposition" title="'.dol_escape_htmltag($langs->trans("None")).'" alt="'.dol_escape_htmltag($langs->trans("None")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delrights&amp;entity='.$entity.'&amp;module='.$obj->module.'">'.$langs->trans("None")."</a>";
if ($caneditperms)
{
print '<td align="center" class="nowrap">';
print '<a class="reposition" title="'.dol_escape_htmltag($langs->trans("All")).'" alt="'.dol_escape_htmltag($langs->trans("All")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=addrights&amp;entity='.$entity.'&amp;module='.$obj->module.'">'.$langs->trans("All")."</a>";
print '/';
print '<a class="reposition" title="'.dol_escape_htmltag($langs->trans("None")).'" alt="'.dol_escape_htmltag($langs->trans("None")).'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delrights&amp;entity='.$entity.'&amp;module='.$obj->module.'">'.$langs->trans("None")."</a>";
print '</td>';
}
}
else
{
if ($caneditperms)
{
print '<td></td>';
}
}
print '</td>';
print '<td colspan="2">&nbsp;</td>';
print '</tr>'."\n";
}
print '<tr class="oddeven">';
// Picto and label of permission
// Picto and label of module
print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">'.img_object('',$picto,'class="pictoobjectwidth"').' '.$objMod->getName().'</td>';
// Permission and tick
@@ -383,6 +396,7 @@ if ($result)
print '<td>&nbsp</td>';
}
// Label
$permlabel=($conf->global->MAIN_USE_ADVANCED_PERMS && ($langs->trans("PermissionAdvanced".$obj->id)!=("PermissionAdvanced".$obj->id))?$langs->trans("PermissionAdvanced".$obj->id):(($langs->trans("Permission".$obj->id)!=("Permission".$obj->id))?$langs->trans("Permission".$obj->id):$langs->trans($obj->libelle)));
print '<td class="maxwidthonsmartphone">'.$permlabel.'</td>';

View File

@@ -37,7 +37,7 @@ require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
$langs->loadLangs(array("admin","other","website"));
if (! $user->admin) accessforbidden();
if (! $user->rights->website->read) accessforbidden();
if (! ((GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)))
{