Scrutinizer Auto-Fixes
This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
This commit is contained in:
parent
cb352407eb
commit
057ab6a059
@ -39,7 +39,7 @@ $action = GETPOST('action', 'alpha');
|
||||
$value = GETPOST('value', 'alpha');
|
||||
$label = GETPOST('label', 'alpha');
|
||||
$scandir = GETPOST('scan_dir', 'alpha');
|
||||
$type='contract';
|
||||
$type = 'contract';
|
||||
|
||||
if (empty($conf->global->HOLIDAY_ADDON))
|
||||
{
|
||||
@ -56,12 +56,12 @@ include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
|
||||
if ($action == 'updateMask')
|
||||
{
|
||||
$maskconst = GETPOST('maskconstholiday', 'alpha');
|
||||
$maskvalue = GETPOST('maskholiday', 'alpha');
|
||||
$maskvalue = GETPOST('maskholiday', 'alpha');
|
||||
if ($maskconst) $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
|
||||
|
||||
if (! $res > 0) $error++;
|
||||
if (!$res > 0) $error++;
|
||||
|
||||
if (! $error)
|
||||
if (!$error)
|
||||
{
|
||||
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
|
||||
}
|
||||
@ -73,20 +73,20 @@ if ($action == 'updateMask')
|
||||
|
||||
elseif ($action == 'specimen') // For contract
|
||||
{
|
||||
$modele= GETPOST('module', 'alpha');
|
||||
$modele = GETPOST('module', 'alpha');
|
||||
|
||||
$holiday = new Holiday($db);
|
||||
$holiday->initAsSpecimen();
|
||||
|
||||
// Search template files
|
||||
$file=''; $classname=''; $filefound=0;
|
||||
$dirmodels=array_merge(array('/'), (array) $conf->modules_parts['models']);
|
||||
foreach($dirmodels as $reldir)
|
||||
$file = ''; $classname = ''; $filefound = 0;
|
||||
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
|
||||
foreach ($dirmodels as $reldir)
|
||||
{
|
||||
$file=dol_buildpath($reldir."core/modules/holiday/doc/pdf_".$modele.".modules.php", 0);
|
||||
$file = dol_buildpath($reldir."core/modules/holiday/doc/pdf_".$modele.".modules.php", 0);
|
||||
if (file_exists($file))
|
||||
{
|
||||
$filefound=1;
|
||||
$filefound = 1;
|
||||
$classname = "pdf_".$modele;
|
||||
break;
|
||||
}
|
||||
@ -159,15 +159,15 @@ elseif ($action == 'setmod')
|
||||
|
||||
elseif ($action == 'set_other')
|
||||
{
|
||||
$freetext= GETPOST('HOLIDAY_FREE_TEXT', 'none'); // No alpha here, we want exact string
|
||||
$freetext = GETPOST('HOLIDAY_FREE_TEXT', 'none'); // No alpha here, we want exact string
|
||||
$res1 = dolibarr_set_const($db, "HOLIDAY_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
|
||||
|
||||
$draft= GETPOST('HOLIDAY_DRAFT_WATERMARK', 'alpha');
|
||||
$draft = GETPOST('HOLIDAY_DRAFT_WATERMARK', 'alpha');
|
||||
$res2 = dolibarr_set_const($db, "HOLIDAY_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
|
||||
|
||||
if (! $res1 > 0 || ! $res2 > 0) $error++;
|
||||
if (!$res1 > 0 || !$res2 > 0) $error++;
|
||||
|
||||
if (! $error)
|
||||
if (!$error)
|
||||
{
|
||||
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
|
||||
}
|
||||
@ -182,16 +182,16 @@ elseif ($action == 'set_other')
|
||||
* View
|
||||
*/
|
||||
|
||||
$dirmodels=array_merge(array('/'), (array) $conf->modules_parts['models']);
|
||||
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
|
||||
|
||||
llxHeader();
|
||||
|
||||
$form=new Form($db);
|
||||
$form = new Form($db);
|
||||
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||
print load_fiche_titre($langs->trans("HolidaySetup"), $linkback, 'title_setup');
|
||||
|
||||
$head=holiday_admin_prepare_head();
|
||||
$head = holiday_admin_prepare_head();
|
||||
|
||||
dol_fiche_head($head, 'holiday', $langs->trans("Holidays"), -1, 'holiday');
|
||||
|
||||
@ -222,18 +222,18 @@ foreach ($dirmodels as $reldir)
|
||||
$handle = opendir($dir);
|
||||
if (is_resource($handle))
|
||||
{
|
||||
while (($file = readdir($handle))!==false)
|
||||
while (($file = readdir($handle)) !== false)
|
||||
{
|
||||
if (substr($file, 0, 12) == 'mod_holiday_' && substr($file, dol_strlen($file)-3, 3) == 'php')
|
||||
if (substr($file, 0, 12) == 'mod_holiday_' && substr($file, dol_strlen($file) - 3, 3) == 'php')
|
||||
{
|
||||
$file = substr($file, 0, dol_strlen($file)-4);
|
||||
$file = substr($file, 0, dol_strlen($file) - 4);
|
||||
|
||||
require_once $dir.$file.'.php';
|
||||
|
||||
$module = new $file($db);
|
||||
|
||||
// Show modules according to features level
|
||||
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
|
||||
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
|
||||
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
|
||||
|
||||
if ($module->isEnabled())
|
||||
@ -244,9 +244,9 @@ foreach ($dirmodels as $reldir)
|
||||
|
||||
// Show example of numbering model
|
||||
print '<td class="nowrap">';
|
||||
$tmp=$module->getExample();
|
||||
$tmp = $module->getExample();
|
||||
if (preg_match('/^Error/', $tmp)) { $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>'; }
|
||||
elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
|
||||
elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
|
||||
else print $tmp;
|
||||
print '</td>'."\n";
|
||||
|
||||
@ -263,21 +263,21 @@ foreach ($dirmodels as $reldir)
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
$holiday=new Holiday($db);
|
||||
$holiday = new Holiday($db);
|
||||
$holiday->initAsSpecimen();
|
||||
|
||||
// Info
|
||||
$htmltooltip='';
|
||||
$htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
|
||||
$nextval=$module->getNextValue($mysoc, $holiday);
|
||||
$htmltooltip = '';
|
||||
$htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
|
||||
$nextval = $module->getNextValue($mysoc, $holiday);
|
||||
if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
|
||||
$htmltooltip.=''.$langs->trans("NextValue").': ';
|
||||
$htmltooltip .= ''.$langs->trans("NextValue").': ';
|
||||
if ($nextval) {
|
||||
if (preg_match('/^Error/', $nextval) || $nextval=='NotConfigured')
|
||||
if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
|
||||
$nextval = $langs->trans($nextval);
|
||||
$htmltooltip.=$nextval.'<br>';
|
||||
$htmltooltip .= $nextval.'<br>';
|
||||
} else {
|
||||
$htmltooltip.=$langs->trans($module->error).'<br>';
|
||||
$htmltooltip .= $langs->trans($module->error).'<br>';
|
||||
}
|
||||
}
|
||||
|
||||
@ -317,14 +317,14 @@ print load_fiche_titre($langs->trans("TemplatePDFHolidays"), '', '');
|
||||
// Defined model definition table
|
||||
$def = array();
|
||||
$sql = "SELECT nom";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."document_model";
|
||||
$sql.= " WHERE type = '".$type."'";
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
$resql=$db->query($sql);
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
|
||||
$sql .= " WHERE type = '".$type."'";
|
||||
$sql .= " AND entity = ".$conf->entity;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$i = 0;
|
||||
$num_rows=$db->num_rows($resql);
|
||||
$num_rows = $db->num_rows($resql);
|
||||
while ($i < $num_rows)
|
||||
{
|
||||
$array = $db->fetch_array($resql);
|
||||
@ -353,42 +353,42 @@ clearstatcache();
|
||||
|
||||
foreach ($dirmodels as $reldir)
|
||||
{
|
||||
foreach (array('','/doc') as $valdir)
|
||||
foreach (array('', '/doc') as $valdir)
|
||||
{
|
||||
$dir = dol_buildpath($reldir."core/modules/holiday".$valdir);
|
||||
|
||||
if (is_dir($dir))
|
||||
{
|
||||
$handle=opendir($dir);
|
||||
$handle = opendir($dir);
|
||||
if (is_resource($handle))
|
||||
{
|
||||
while (($file = readdir($handle))!==false)
|
||||
while (($file = readdir($handle)) !== false)
|
||||
{
|
||||
$filelist[]=$file;
|
||||
$filelist[] = $file;
|
||||
}
|
||||
closedir($handle);
|
||||
arsort($filelist);
|
||||
|
||||
foreach($filelist as $file)
|
||||
foreach ($filelist as $file)
|
||||
{
|
||||
if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
|
||||
{
|
||||
if (file_exists($dir.'/'.$file))
|
||||
{
|
||||
$name = substr($file, 4, dol_strlen($file) -16);
|
||||
$classname = substr($file, 0, dol_strlen($file) -12);
|
||||
$name = substr($file, 4, dol_strlen($file) - 16);
|
||||
$classname = substr($file, 0, dol_strlen($file) - 12);
|
||||
|
||||
require_once $dir.'/'.$file;
|
||||
$module = new $classname($db);
|
||||
|
||||
$modulequalified=1;
|
||||
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
|
||||
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
|
||||
$modulequalified = 1;
|
||||
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0;
|
||||
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0;
|
||||
|
||||
if ($modulequalified)
|
||||
{
|
||||
print '<tr class="oddeven"><td width="100">';
|
||||
print (empty($module->name)?$name:$module->name);
|
||||
print (empty($module->name) ? $name : $module->name);
|
||||
print "</td><td>\n";
|
||||
if (method_exists($module, 'info')) print $module->info($langs);
|
||||
else print $module->description;
|
||||
@ -423,18 +423,18 @@ foreach ($dirmodels as $reldir)
|
||||
print '</td>';
|
||||
|
||||
// Info
|
||||
$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
|
||||
$htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
|
||||
$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
|
||||
$htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
|
||||
if ($module->type == 'pdf')
|
||||
{
|
||||
$htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
|
||||
$htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
|
||||
}
|
||||
$htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
|
||||
$htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
|
||||
$htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
|
||||
$htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
|
||||
$htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
|
||||
$htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
|
||||
$htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
|
||||
$htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
|
||||
$htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
|
||||
$htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
|
||||
$htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
|
||||
$htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
|
||||
|
||||
|
||||
print '<td align="center">';
|
||||
@ -485,16 +485,16 @@ print '<td>'.$langs->trans("Parameter").'</td>';
|
||||
print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
$substitutionarray=pdf_getSubstitutionArray($langs, array('objectamount'), null, 2);
|
||||
$substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
|
||||
$substitutionarray = pdf_getSubstitutionArray($langs, array('objectamount'), null, 2);
|
||||
$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
|
||||
$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
|
||||
foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
|
||||
$htmltext.='</i>';
|
||||
foreach ($substitutionarray as $key => $val) $htmltext .= $key.'<br>';
|
||||
$htmltext .= '</i>';
|
||||
|
||||
print '<tr class="oddeven"><td colspan="2">';
|
||||
print $form->textwithpicto($langs->trans("FreeLegalTextOnHolidays"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'tooltiphelp');
|
||||
print '<br>';
|
||||
$variablename='HOLIDAY_FREE_TEXT';
|
||||
$variablename = 'HOLIDAY_FREE_TEXT';
|
||||
if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
|
||||
{
|
||||
print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
|
||||
@ -502,7 +502,7 @@ if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
|
||||
else
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
|
||||
$doleditor=new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes');
|
||||
$doleditor = new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes');
|
||||
print $doleditor->Create();
|
||||
}
|
||||
print '</td></tr>'."\n";
|
||||
|
||||
@ -38,24 +38,24 @@ function dol_encode($chain, $key = '1')
|
||||
{
|
||||
if (is_numeric($key) && $key == '1') // rule 1 is offset of 17 for char
|
||||
{
|
||||
$output_tab=array();
|
||||
$strlength=dol_strlen($chain);
|
||||
for ($i=0; $i < $strlength; $i++)
|
||||
$output_tab = array();
|
||||
$strlength = dol_strlen($chain);
|
||||
for ($i = 0; $i < $strlength; $i++)
|
||||
{
|
||||
$output_tab[$i] = chr(ord(substr($chain, $i, 1))+17);
|
||||
$output_tab[$i] = chr(ord(substr($chain, $i, 1)) + 17);
|
||||
}
|
||||
$chain = implode("", $output_tab);
|
||||
}
|
||||
elseif ($key)
|
||||
{
|
||||
$result='';
|
||||
$strlength=dol_strlen($chain);
|
||||
for ($i=0; $i < $strlength; $i++)
|
||||
$result = '';
|
||||
$strlength = dol_strlen($chain);
|
||||
for ($i = 0; $i < $strlength; $i++)
|
||||
{
|
||||
$keychar = substr($key, ($i % strlen($key))-1, 1);
|
||||
$result.= chr(ord(substr($chain, $i, 1))+(ord($keychar)-65));
|
||||
$keychar = substr($key, ($i % strlen($key)) - 1, 1);
|
||||
$result .= chr(ord(substr($chain, $i, 1)) + (ord($keychar) - 65));
|
||||
}
|
||||
$chain=$result;
|
||||
$chain = $result;
|
||||
}
|
||||
|
||||
return base64_encode($chain);
|
||||
@ -76,25 +76,25 @@ function dol_decode($chain, $key = '1')
|
||||
|
||||
if (is_numeric($key) && $key == '1') // rule 1 is offset of 17 for char
|
||||
{
|
||||
$output_tab=array();
|
||||
$strlength=dol_strlen($chain);
|
||||
for ($i=0; $i < $strlength;$i++)
|
||||
$output_tab = array();
|
||||
$strlength = dol_strlen($chain);
|
||||
for ($i = 0; $i < $strlength; $i++)
|
||||
{
|
||||
$output_tab[$i] = chr(ord(substr($chain, $i, 1))-17);
|
||||
$output_tab[$i] = chr(ord(substr($chain, $i, 1)) - 17);
|
||||
}
|
||||
|
||||
$chain = implode("", $output_tab);
|
||||
}
|
||||
elseif ($key)
|
||||
{
|
||||
$result='';
|
||||
$strlength=dol_strlen($chain);
|
||||
for ($i=0; $i < $strlength; $i++)
|
||||
$result = '';
|
||||
$strlength = dol_strlen($chain);
|
||||
for ($i = 0; $i < $strlength; $i++)
|
||||
{
|
||||
$keychar = substr($key, ($i % strlen($key))-1, 1);
|
||||
$result.= chr(ord(substr($chain, $i, 1))-(ord($keychar)-65));
|
||||
$keychar = substr($key, ($i % strlen($key)) - 1, 1);
|
||||
$result .= chr(ord(substr($chain, $i, 1)) - (ord($keychar) - 65));
|
||||
}
|
||||
$chain=$result;
|
||||
$chain = $result;
|
||||
}
|
||||
|
||||
return $chain;
|
||||
@ -116,21 +116,21 @@ function dol_hash($chain, $type = '0')
|
||||
global $conf;
|
||||
|
||||
// No need to add salt for password_hash
|
||||
if (($type == '0' || $type == 'auto') && ! empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'password_hash' && function_exists('password_hash'))
|
||||
if (($type == '0' || $type == 'auto') && !empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'password_hash' && function_exists('password_hash'))
|
||||
{
|
||||
return password_hash($chain, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
// Salt value
|
||||
if (! empty($conf->global->MAIN_SECURITY_SALT)) $chain=$conf->global->MAIN_SECURITY_SALT.$chain;
|
||||
if (!empty($conf->global->MAIN_SECURITY_SALT)) $chain = $conf->global->MAIN_SECURITY_SALT.$chain;
|
||||
|
||||
if ($type == '1' || $type == 'sha1') return sha1($chain);
|
||||
elseif ($type == '2' || $type == 'sha1md5') return sha1(md5($chain));
|
||||
elseif ($type == '3' || $type == 'md5') return md5($chain);
|
||||
elseif ($type == '4' || $type == 'md5openldap') return '{md5}'.base64_encode(mhash(MHASH_MD5, $chain)); // For OpenLdap with md5 (based on an unencrypted password in base)
|
||||
elseif ($type == '5') return hash('sha256', $chain);
|
||||
elseif (! empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'sha1') return sha1($chain);
|
||||
elseif (! empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'sha1md5') return sha1(md5($chain));
|
||||
elseif (!empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'sha1') return sha1($chain);
|
||||
elseif (!empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'sha1md5') return sha1(md5($chain));
|
||||
|
||||
// No particular encoding defined, use default
|
||||
return md5($chain);
|
||||
@ -151,10 +151,10 @@ function dol_verifyHash($chain, $hash, $type = '0')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if ($type == '0' && ! empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'password_hash' && function_exists('password_verify')) {
|
||||
if ($type == '0' && !empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'password_hash' && function_exists('password_verify')) {
|
||||
if ($hash[0] == '$') return password_verify($chain, $hash);
|
||||
elseif(strlen($hash) == 32) return dol_verifyHash($chain, $hash, '3'); // md5
|
||||
elseif(strlen($hash) == 40) return dol_verifyHash($chain, $hash, '2'); // sha1md5
|
||||
elseif (strlen($hash) == 32) return dol_verifyHash($chain, $hash, '3'); // md5
|
||||
elseif (strlen($hash) == 40) return dol_verifyHash($chain, $hash, '2'); // sha1md5
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -189,9 +189,9 @@ function restrictedArea($user, $features, $objectid = 0, $tableandshare = '', $f
|
||||
//print ", perm: ".$features."->".$feature2."=".($user->rights->$features->$feature2->lire)."<br>";
|
||||
|
||||
// Get more permissions checks from hooks
|
||||
$parameters=array('features'=>$features, 'objectid'=>$objectid, 'idtype'=>$dbt_select);
|
||||
$reshook=$hookmanager->executeHooks('restrictedArea', $parameters);
|
||||
if (! empty($hookmanager->resArray['result'])) return true;
|
||||
$parameters = array('features'=>$features, 'objectid'=>$objectid, 'idtype'=>$dbt_select);
|
||||
$reshook = $hookmanager->executeHooks('restrictedArea', $parameters);
|
||||
if (!empty($hookmanager->resArray['result'])) return true;
|
||||
if ($reshook > 0) return false;
|
||||
|
||||
if ($dbt_select != 'rowid' && $dbt_select != 'id') $objectid = "'".$objectid."'";
|
||||
@ -202,227 +202,227 @@ function restrictedArea($user, $features, $objectid = 0, $tableandshare = '', $f
|
||||
elseif (preg_match('/\|/', $features)) $featuresarray = explode("|", $features);
|
||||
|
||||
// More subfeatures to check
|
||||
if (! empty($feature2)) $feature2 = explode("|", $feature2);
|
||||
if (!empty($feature2)) $feature2 = explode("|", $feature2);
|
||||
|
||||
// More parameters
|
||||
$params = explode('&', $tableandshare);
|
||||
$dbtablename=(! empty($params[0]) ? $params[0] : '');
|
||||
$sharedelement=(! empty($params[1]) ? $params[1] : $dbtablename);
|
||||
$dbtablename = (!empty($params[0]) ? $params[0] : '');
|
||||
$sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
|
||||
|
||||
$listofmodules=explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
|
||||
$listofmodules = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
|
||||
|
||||
// Check read permission from module
|
||||
$readok=1; $nbko=0;
|
||||
$readok = 1; $nbko = 0;
|
||||
foreach ($featuresarray as $feature) // first we check nb of test ko
|
||||
{
|
||||
$featureforlistofmodule=$feature;
|
||||
if ($featureforlistofmodule == 'produit') $featureforlistofmodule='product';
|
||||
if (! empty($user->socid) && ! empty($conf->global->MAIN_MODULES_FOR_EXTERNAL) && ! in_array($featureforlistofmodule, $listofmodules)) // If limits on modules for external users, module must be into list of modules for external users
|
||||
$featureforlistofmodule = $feature;
|
||||
if ($featureforlistofmodule == 'produit') $featureforlistofmodule = 'product';
|
||||
if (!empty($user->socid) && !empty($conf->global->MAIN_MODULES_FOR_EXTERNAL) && !in_array($featureforlistofmodule, $listofmodules)) // If limits on modules for external users, module must be into list of modules for external users
|
||||
{
|
||||
$readok=0; $nbko++;
|
||||
$readok = 0; $nbko++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($feature == 'societe')
|
||||
{
|
||||
if (! $user->rights->societe->lire && ! $user->rights->fournisseur->lire) { $readok=0; $nbko++; }
|
||||
if (!$user->rights->societe->lire && !$user->rights->fournisseur->lire) { $readok = 0; $nbko++; }
|
||||
}
|
||||
elseif ($feature == 'contact')
|
||||
{
|
||||
if (! $user->rights->societe->contact->lire) { $readok=0; $nbko++; }
|
||||
if (!$user->rights->societe->contact->lire) { $readok = 0; $nbko++; }
|
||||
}
|
||||
elseif ($feature == 'produit|service')
|
||||
{
|
||||
if (! $user->rights->produit->lire && ! $user->rights->service->lire) { $readok=0; $nbko++; }
|
||||
if (!$user->rights->produit->lire && !$user->rights->service->lire) { $readok = 0; $nbko++; }
|
||||
}
|
||||
elseif ($feature == 'prelevement')
|
||||
{
|
||||
if (! $user->rights->prelevement->bons->lire) { $readok=0; $nbko++; }
|
||||
if (!$user->rights->prelevement->bons->lire) { $readok = 0; $nbko++; }
|
||||
}
|
||||
elseif ($feature == 'cheque')
|
||||
{
|
||||
if (! $user->rights->banque->cheque) { $readok=0; $nbko++; }
|
||||
if (!$user->rights->banque->cheque) { $readok = 0; $nbko++; }
|
||||
}
|
||||
elseif ($feature == 'projet')
|
||||
{
|
||||
if (! $user->rights->projet->lire && ! $user->rights->projet->all->lire) { $readok=0; $nbko++; }
|
||||
if (!$user->rights->projet->lire && !$user->rights->projet->all->lire) { $readok = 0; $nbko++; }
|
||||
}
|
||||
elseif (! empty($feature2)) // This is for permissions on 2 levels
|
||||
elseif (!empty($feature2)) // This is for permissions on 2 levels
|
||||
{
|
||||
$tmpreadok=1;
|
||||
foreach($feature2 as $subfeature)
|
||||
$tmpreadok = 1;
|
||||
foreach ($feature2 as $subfeature)
|
||||
{
|
||||
if ($subfeature == 'user' && $user->id == $objectid) continue; // A user can always read its own card
|
||||
if (! empty($subfeature) && empty($user->rights->$feature->$subfeature->lire) && empty($user->rights->$feature->$subfeature->read)) { $tmpreadok=0; }
|
||||
elseif (empty($subfeature) && empty($user->rights->$feature->lire) && empty($user->rights->$feature->read)) { $tmpreadok=0; }
|
||||
else { $tmpreadok=1; break; } // Break is to bypass second test if the first is ok
|
||||
if (!empty($subfeature) && empty($user->rights->$feature->$subfeature->lire) && empty($user->rights->$feature->$subfeature->read)) { $tmpreadok = 0; }
|
||||
elseif (empty($subfeature) && empty($user->rights->$feature->lire) && empty($user->rights->$feature->read)) { $tmpreadok = 0; }
|
||||
else { $tmpreadok = 1; break; } // Break is to bypass second test if the first is ok
|
||||
}
|
||||
if (! $tmpreadok) // We found a test on feature that is ko
|
||||
if (!$tmpreadok) // We found a test on feature that is ko
|
||||
{
|
||||
$readok=0; // All tests are ko (we manage here the and, the or will be managed later using $nbko).
|
||||
$readok = 0; // All tests are ko (we manage here the and, the or will be managed later using $nbko).
|
||||
$nbko++;
|
||||
}
|
||||
}
|
||||
elseif (! empty($feature) && ($feature!='user' && $feature!='usergroup')) // This is permissions on 1 level
|
||||
elseif (!empty($feature) && ($feature != 'user' && $feature != 'usergroup')) // This is permissions on 1 level
|
||||
{
|
||||
if (empty($user->rights->$feature->lire)
|
||||
&& empty($user->rights->$feature->read)
|
||||
&& empty($user->rights->$feature->run)) { $readok=0; $nbko++; }
|
||||
&& empty($user->rights->$feature->run)) { $readok = 0; $nbko++; }
|
||||
}
|
||||
}
|
||||
|
||||
// If a or and at least one ok
|
||||
if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) $readok=1;
|
||||
if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) $readok = 1;
|
||||
|
||||
if (! $readok) accessforbidden();
|
||||
if (!$readok) accessforbidden();
|
||||
//print "Read access is ok";
|
||||
|
||||
// Check write permission from module (we need to know write permission to create but also to delete drafts record)
|
||||
$createok=1; $nbko=0;
|
||||
if (GETPOST('action', 'aZ09') == 'create' || GETPOST('action', 'aZ09') == 'update' || ((GETPOST("action", "aZ09") == 'confirm_delete' && GETPOST("confirm", "aZ09") == 'yes') || GETPOST("action", "aZ09") == 'delete'))
|
||||
$createok = 1; $nbko = 0;
|
||||
if (GETPOST('action', 'aZ09') == 'create' || GETPOST('action', 'aZ09') == 'update' || ((GETPOST("action", "aZ09") == 'confirm_delete' && GETPOST("confirm", "aZ09") == 'yes') || GETPOST("action", "aZ09") == 'delete'))
|
||||
{
|
||||
foreach ($featuresarray as $feature)
|
||||
{
|
||||
if ($feature == 'contact')
|
||||
{
|
||||
if (! $user->rights->societe->contact->creer) { $createok=0; $nbko++; }
|
||||
if (!$user->rights->societe->contact->creer) { $createok = 0; $nbko++; }
|
||||
}
|
||||
elseif ($feature == 'produit|service')
|
||||
{
|
||||
if (! $user->rights->produit->creer && ! $user->rights->service->creer) { $createok=0; $nbko++; }
|
||||
if (!$user->rights->produit->creer && !$user->rights->service->creer) { $createok = 0; $nbko++; }
|
||||
}
|
||||
elseif ($feature == 'prelevement')
|
||||
{
|
||||
if (! $user->rights->prelevement->bons->creer) { $createok=0; $nbko++; }
|
||||
if (!$user->rights->prelevement->bons->creer) { $createok = 0; $nbko++; }
|
||||
}
|
||||
elseif ($feature == 'commande_fournisseur')
|
||||
{
|
||||
if (! $user->rights->fournisseur->commande->creer) { $createok=0; $nbko++; }
|
||||
if (!$user->rights->fournisseur->commande->creer) { $createok = 0; $nbko++; }
|
||||
}
|
||||
elseif ($feature == 'banque')
|
||||
{
|
||||
if (! $user->rights->banque->modifier) { $createok=0; $nbko++; }
|
||||
if (!$user->rights->banque->modifier) { $createok = 0; $nbko++; }
|
||||
}
|
||||
elseif ($feature == 'cheque')
|
||||
{
|
||||
if (! $user->rights->banque->cheque) { $createok=0; $nbko++; }
|
||||
if (!$user->rights->banque->cheque) { $createok = 0; $nbko++; }
|
||||
}
|
||||
elseif (! empty($feature2)) // This is for permissions on one level
|
||||
elseif (!empty($feature2)) // This is for permissions on one level
|
||||
{
|
||||
foreach($feature2 as $subfeature)
|
||||
foreach ($feature2 as $subfeature)
|
||||
{
|
||||
if (empty($user->rights->$feature->$subfeature->creer)
|
||||
&& empty($user->rights->$feature->$subfeature->write)
|
||||
&& empty($user->rights->$feature->$subfeature->create)) {
|
||||
$createok=0;
|
||||
$createok = 0;
|
||||
$nbko++;
|
||||
} else {
|
||||
$createok=1;
|
||||
$createok = 1;
|
||||
// Break to bypass second test if the first is ok
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (! empty($feature)) // This is for permissions on 2 levels ('creer' or 'write')
|
||||
elseif (!empty($feature)) // This is for permissions on 2 levels ('creer' or 'write')
|
||||
{
|
||||
//print '<br>feature='.$feature.' creer='.$user->rights->$feature->creer.' write='.$user->rights->$feature->write;
|
||||
if (empty($user->rights->$feature->creer)
|
||||
&& empty($user->rights->$feature->write)
|
||||
&& empty($user->rights->$feature->create)) {
|
||||
$createok=0;
|
||||
$createok = 0;
|
||||
$nbko++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If a or and at least one ok
|
||||
if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) $createok=1;
|
||||
if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) $createok = 1;
|
||||
|
||||
if ((GETPOST('action', 'aZ09') == 'create' || GETPOST('action', 'aZ09') == 'update') && ! $createok) accessforbidden();
|
||||
if ((GETPOST('action', 'aZ09') == 'create' || GETPOST('action', 'aZ09') == 'update') && !$createok) accessforbidden();
|
||||
//print "Write access is ok";
|
||||
}
|
||||
|
||||
// Check create user permission
|
||||
$createuserok=1;
|
||||
$createuserok = 1;
|
||||
if (GETPOST('action', 'aZ09') == 'confirm_create_user' && GETPOST("confirm", 'aZ09') == 'yes')
|
||||
{
|
||||
if (! $user->rights->user->user->creer) $createuserok=0;
|
||||
if (!$user->rights->user->user->creer) $createuserok = 0;
|
||||
|
||||
if (! $createuserok) accessforbidden();
|
||||
if (!$createuserok) accessforbidden();
|
||||
//print "Create user access is ok";
|
||||
}
|
||||
|
||||
// Check delete permission from module
|
||||
$deleteok=1; $nbko=0;
|
||||
if ((GETPOST("action", "aZ09") == 'confirm_delete' && GETPOST("confirm", "aZ09") == 'yes') || GETPOST("action", "aZ09") == 'delete')
|
||||
$deleteok = 1; $nbko = 0;
|
||||
if ((GETPOST("action", "aZ09") == 'confirm_delete' && GETPOST("confirm", "aZ09") == 'yes') || GETPOST("action", "aZ09") == 'delete')
|
||||
{
|
||||
foreach ($featuresarray as $feature)
|
||||
{
|
||||
if ($feature == 'contact')
|
||||
{
|
||||
if (! $user->rights->societe->contact->supprimer) $deleteok=0;
|
||||
if (!$user->rights->societe->contact->supprimer) $deleteok = 0;
|
||||
}
|
||||
elseif ($feature == 'produit|service')
|
||||
{
|
||||
if (! $user->rights->produit->supprimer && ! $user->rights->service->supprimer) $deleteok=0;
|
||||
if (!$user->rights->produit->supprimer && !$user->rights->service->supprimer) $deleteok = 0;
|
||||
}
|
||||
elseif ($feature == 'commande_fournisseur')
|
||||
{
|
||||
if (! $user->rights->fournisseur->commande->supprimer) $deleteok=0;
|
||||
if (!$user->rights->fournisseur->commande->supprimer) $deleteok = 0;
|
||||
}
|
||||
elseif ($feature == 'banque')
|
||||
{
|
||||
if (! $user->rights->banque->modifier) $deleteok=0;
|
||||
if (!$user->rights->banque->modifier) $deleteok = 0;
|
||||
}
|
||||
elseif ($feature == 'cheque')
|
||||
{
|
||||
if (! $user->rights->banque->cheque) $deleteok=0;
|
||||
if (!$user->rights->banque->cheque) $deleteok = 0;
|
||||
}
|
||||
elseif ($feature == 'ecm')
|
||||
{
|
||||
if (! $user->rights->ecm->upload) $deleteok=0;
|
||||
if (!$user->rights->ecm->upload) $deleteok = 0;
|
||||
}
|
||||
elseif ($feature == 'ftp')
|
||||
{
|
||||
if (! $user->rights->ftp->write) $deleteok=0;
|
||||
if (!$user->rights->ftp->write) $deleteok = 0;
|
||||
}elseif ($feature == 'salaries')
|
||||
{
|
||||
if (! $user->rights->salaries->delete) $deleteok=0;
|
||||
if (!$user->rights->salaries->delete) $deleteok = 0;
|
||||
}
|
||||
elseif ($feature == 'salaries')
|
||||
{
|
||||
if (! $user->rights->salaries->delete) $deleteok=0;
|
||||
if (!$user->rights->salaries->delete) $deleteok = 0;
|
||||
}
|
||||
elseif (! empty($feature2)) // This is for permissions on 2 levels
|
||||
elseif (!empty($feature2)) // This is for permissions on 2 levels
|
||||
{
|
||||
foreach($feature2 as $subfeature)
|
||||
foreach ($feature2 as $subfeature)
|
||||
{
|
||||
if (empty($user->rights->$feature->$subfeature->supprimer) && empty($user->rights->$feature->$subfeature->delete)) $deleteok=0;
|
||||
else { $deleteok=1; break; } // For bypass the second test if the first is ok
|
||||
if (empty($user->rights->$feature->$subfeature->supprimer) && empty($user->rights->$feature->$subfeature->delete)) $deleteok = 0;
|
||||
else { $deleteok = 1; break; } // For bypass the second test if the first is ok
|
||||
}
|
||||
}
|
||||
elseif (! empty($feature)) // This is used for permissions on 1 level
|
||||
elseif (!empty($feature)) // This is used for permissions on 1 level
|
||||
{
|
||||
//print '<br>feature='.$feature.' creer='.$user->rights->$feature->supprimer.' write='.$user->rights->$feature->delete;
|
||||
if (empty($user->rights->$feature->supprimer)
|
||||
&& empty($user->rights->$feature->delete)
|
||||
&& empty($user->rights->$feature->run)) $deleteok=0;
|
||||
&& empty($user->rights->$feature->run)) $deleteok = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// If a or and at least one ok
|
||||
if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) $deleteok=1;
|
||||
if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) $deleteok = 1;
|
||||
|
||||
if (! $deleteok && ! ($isdraft && $createok)) accessforbidden();
|
||||
if (!$deleteok && !($isdraft && $createok)) accessforbidden();
|
||||
//print "Delete access is ok";
|
||||
}
|
||||
|
||||
// If we have a particular object to check permissions on, we check this object
|
||||
// is linked to a company allowed to $user.
|
||||
if (! empty($objectid) && $objectid > 0)
|
||||
if (!empty($objectid) && $objectid > 0)
|
||||
{
|
||||
$ok = checkUserAccessToObject($user, $featuresarray, $objectid, $tableandshare, $feature2, $dbt_keyfield, $dbt_select);
|
||||
$params=array('objectid' => $objectid, 'features' => join(',', $featuresarray), 'features2' => $feature2);
|
||||
$params = array('objectid' => $objectid, 'features' => join(',', $featuresarray), 'features2' => $feature2);
|
||||
return $ok ? 1 : accessforbidden('', 1, 1, 0, $params);
|
||||
}
|
||||
|
||||
@ -449,65 +449,65 @@ function checkUserAccessToObject($user, $featuresarray, $objectid = 0, $tableand
|
||||
|
||||
// More parameters
|
||||
$params = explode('&', $tableandshare);
|
||||
$dbtablename=(! empty($params[0]) ? $params[0] : '');
|
||||
$sharedelement=(! empty($params[1]) ? $params[1] : $dbtablename);
|
||||
$dbtablename = (!empty($params[0]) ? $params[0] : '');
|
||||
$sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
|
||||
|
||||
foreach ($featuresarray as $feature)
|
||||
{
|
||||
$sql='';
|
||||
$sql = '';
|
||||
|
||||
// For backward compatibility
|
||||
if ($feature == 'member') $feature='adherent';
|
||||
if ($feature == 'project') $feature='projet';
|
||||
if ($feature == 'task') $feature='projet_task';
|
||||
if ($feature == 'member') $feature = 'adherent';
|
||||
if ($feature == 'project') $feature = 'projet';
|
||||
if ($feature == 'task') $feature = 'projet_task';
|
||||
|
||||
$check = array('adherent','banque','bom','don','user','usergroup','product','produit','service','produit|service','categorie','resource','expensereport','holiday'); // Test on entity only (Objects with no link to company)
|
||||
$checksoc = array('societe'); // Test for societe object
|
||||
$checkother = array('contact','agenda'); // Test on entity and link to third party. Allowed if link is empty (Ex: contacts...).
|
||||
$checkproject = array('projet','project'); // Test for project object
|
||||
$check = array('adherent', 'banque', 'bom', 'don', 'user', 'usergroup', 'product', 'produit', 'service', 'produit|service', 'categorie', 'resource', 'expensereport', 'holiday'); // Test on entity only (Objects with no link to company)
|
||||
$checksoc = array('societe'); // Test for societe object
|
||||
$checkother = array('contact', 'agenda'); // Test on entity and link to third party. Allowed if link is empty (Ex: contacts...).
|
||||
$checkproject = array('projet', 'project'); // Test for project object
|
||||
$checktask = array('projet_task');
|
||||
$nocheck = array('barcode','stock'); // No test
|
||||
$nocheck = array('barcode', 'stock'); // No test
|
||||
//$checkdefault = 'all other not already defined'; // Test on entity and link to third party. Not allowed if link is empty (Ex: invoice, orders...).
|
||||
|
||||
// If dbtablename not defined, we use same name for table than module name
|
||||
if (empty($dbtablename))
|
||||
{
|
||||
$dbtablename = $feature;
|
||||
$sharedelement = (! empty($params[1]) ? $params[1] : $dbtablename); // We change dbtablename, so we set sharedelement too.
|
||||
$sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename); // We change dbtablename, so we set sharedelement too.
|
||||
}
|
||||
|
||||
// Check permission for object with entity
|
||||
if (in_array($feature, $check))
|
||||
{
|
||||
$sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
if (($feature == 'user' || $feature == 'usergroup') && ! empty($conf->multicompany->enabled))
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
if (($feature == 'user' || $feature == 'usergroup') && !empty($conf->multicompany->enabled))
|
||||
{
|
||||
if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
|
||||
if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
|
||||
{
|
||||
if ($conf->entity == 1 && $user->admin && ! $user->entity)
|
||||
if ($conf->entity == 1 && $user->admin && !$user->entity)
|
||||
{
|
||||
$sql.= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql.= " AND dbt.entity IS NOT NULL";
|
||||
$sql .= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql .= " AND dbt.entity IS NOT NULL";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug";
|
||||
$sql.= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql.= " AND ((ug.fk_user = dbt.rowid";
|
||||
$sql.= " AND ug.entity IN (".getEntity('usergroup')."))";
|
||||
$sql.= " OR dbt.entity = 0)"; // Show always superadmin
|
||||
$sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug";
|
||||
$sql .= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql .= " AND ((ug.fk_user = dbt.rowid";
|
||||
$sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
|
||||
$sql .= " OR dbt.entity = 0)"; // Show always superadmin
|
||||
}
|
||||
}
|
||||
else {
|
||||
$sql.= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql.= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
$sql .= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql.= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql.= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
$sql .= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
}
|
||||
}
|
||||
elseif (in_array($feature, $checksoc)) // We check feature = checksoc
|
||||
@ -518,23 +518,23 @@ function checkUserAccessToObject($user, $featuresarray, $objectid = 0, $tableand
|
||||
if ($user->socid <> $objectid) return false;
|
||||
}
|
||||
// If internal user: Check permission for internal users that are restricted on their objects
|
||||
elseif (! empty($conf->societe->enabled) && ($user->rights->societe->lire && ! $user->rights->societe->client->voir))
|
||||
elseif (!empty($conf->societe->enabled) && ($user->rights->societe->lire && !$user->rights->societe->client->voir))
|
||||
{
|
||||
$sql = "SELECT COUNT(sc.fk_soc) as nb";
|
||||
$sql.= " FROM (".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."societe as s)";
|
||||
$sql.= " WHERE sc.fk_soc IN (".$objectid.")";
|
||||
$sql.= " AND sc.fk_user = ".$user->id;
|
||||
$sql.= " AND sc.fk_soc = s.rowid";
|
||||
$sql.= " AND s.entity IN (".getEntity($sharedelement, 1).")";
|
||||
$sql .= " FROM (".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe as s)";
|
||||
$sql .= " WHERE sc.fk_soc IN (".$objectid.")";
|
||||
$sql .= " AND sc.fk_user = ".$user->id;
|
||||
$sql .= " AND sc.fk_soc = s.rowid";
|
||||
$sql .= " AND s.entity IN (".getEntity($sharedelement, 1).")";
|
||||
}
|
||||
// If multicompany and internal users with all permissions, check user is in correct entity
|
||||
elseif (! empty($conf->multicompany->enabled))
|
||||
elseif (!empty($conf->multicompany->enabled))
|
||||
{
|
||||
$sql = "SELECT COUNT(s.rowid) as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " WHERE s.rowid IN (".$objectid.")";
|
||||
$sql.= " AND s.entity IN (".getEntity($sharedelement, 1).")";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= " WHERE s.rowid IN (".$objectid.")";
|
||||
$sql .= " AND s.entity IN (".getEntity($sharedelement, 1).")";
|
||||
}
|
||||
}
|
||||
elseif (in_array($feature, $checkother)) // Test on entity and link to societe. Allowed if link is empty (Ex: contacts...).
|
||||
@ -543,110 +543,110 @@ function checkUserAccessToObject($user, $featuresarray, $objectid = 0, $tableand
|
||||
if ($user->socid > 0)
|
||||
{
|
||||
$sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql.= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql.= " AND dbt.fk_soc = ".$user->socid;
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql .= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql .= " AND dbt.fk_soc = ".$user->socid;
|
||||
}
|
||||
// If internal user: Check permission for internal users that are restricted on their objects
|
||||
elseif (! empty($conf->societe->enabled) && ($user->rights->societe->lire && ! $user->rights->societe->client->voir))
|
||||
elseif (!empty($conf->societe->enabled) && ($user->rights->societe->lire && !$user->rights->societe->client->voir))
|
||||
{
|
||||
$sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON dbt.fk_soc = sc.fk_soc AND sc.fk_user = '".$user->id."'";
|
||||
$sql.= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql.= " AND (dbt.fk_soc IS NULL OR sc.fk_soc IS NOT NULL)"; // Contact not linked to a company or to a company of user
|
||||
$sql.= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON dbt.fk_soc = sc.fk_soc AND sc.fk_user = '".$user->id."'";
|
||||
$sql .= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql .= " AND (dbt.fk_soc IS NULL OR sc.fk_soc IS NOT NULL)"; // Contact not linked to a company or to a company of user
|
||||
$sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
}
|
||||
// If multicompany and internal users with all permissions, check user is in correct entity
|
||||
elseif (! empty($conf->multicompany->enabled))
|
||||
elseif (!empty($conf->multicompany->enabled))
|
||||
{
|
||||
$sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql.= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql.= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql .= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
}
|
||||
}
|
||||
elseif (in_array($feature, $checkproject))
|
||||
{
|
||||
if (! empty($conf->projet->enabled) && empty($user->rights->projet->all->lire))
|
||||
if (!empty($conf->projet->enabled) && empty($user->rights->projet->all->lire))
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
$projectstatic=new Project($db);
|
||||
$tmps=$projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
|
||||
$tmparray=explode(',', $tmps);
|
||||
if (! in_array($objectid, $tmparray)) return false;
|
||||
$projectstatic = new Project($db);
|
||||
$tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
|
||||
$tmparray = explode(',', $tmps);
|
||||
if (!in_array($objectid, $tmparray)) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql.= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql.= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql .= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
}
|
||||
}
|
||||
elseif (in_array($feature, $checktask))
|
||||
{
|
||||
if (! empty($conf->projet->enabled) && empty($user->rights->projet->all->lire))
|
||||
if (!empty($conf->projet->enabled) && empty($user->rights->projet->all->lire))
|
||||
{
|
||||
$task = new Task($db);
|
||||
$task->fetch($objectid);
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
$projectstatic=new Project($db);
|
||||
$tmps=$projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
|
||||
$tmparray=explode(',', $tmps);
|
||||
if (! in_array($task->fk_project, $tmparray)) return false;
|
||||
$projectstatic = new Project($db);
|
||||
$tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
|
||||
$tmparray = explode(',', $tmps);
|
||||
if (!in_array($task->fk_project, $tmparray)) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql.= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql.= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql .= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
}
|
||||
}
|
||||
elseif (! in_array($feature, $nocheck)) // By default (case of $checkdefault), we check on object entity + link to third party on field $dbt_keyfield
|
||||
elseif (!in_array($feature, $nocheck)) // By default (case of $checkdefault), we check on object entity + link to third party on field $dbt_keyfield
|
||||
{
|
||||
// If external user: Check permission for external users
|
||||
if ($user->socid > 0)
|
||||
{
|
||||
if (empty($dbt_keyfield)) dol_print_error('', 'Param dbt_keyfield is required but not defined');
|
||||
$sql = "SELECT COUNT(dbt.".$dbt_keyfield.") as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql.= " WHERE dbt.rowid IN (".$objectid.")";
|
||||
$sql.= " AND dbt.".$dbt_keyfield." = ".$user->socid;
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql .= " WHERE dbt.rowid IN (".$objectid.")";
|
||||
$sql .= " AND dbt.".$dbt_keyfield." = ".$user->socid;
|
||||
}
|
||||
// If internal user: Check permission for internal users that are restricted on their objects
|
||||
elseif (! empty($conf->societe->enabled) && ($user->rights->societe->lire && ! $user->rights->societe->client->voir))
|
||||
elseif (!empty($conf->societe->enabled) && ($user->rights->societe->lire && !$user->rights->societe->client->voir))
|
||||
{
|
||||
if (empty($dbt_keyfield)) dol_print_error('', 'Param dbt_keyfield is required but not defined');
|
||||
$sql = "SELECT COUNT(sc.fk_soc) as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql.= " AND sc.fk_soc = dbt.".$dbt_keyfield;
|
||||
$sql.= " AND dbt.".$dbt_keyfield." = s.rowid";
|
||||
$sql.= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
$sql.= " AND sc.fk_user = ".$user->id;
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql .= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql .= " AND sc.fk_soc = dbt.".$dbt_keyfield;
|
||||
$sql .= " AND dbt.".$dbt_keyfield." = s.rowid";
|
||||
$sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
$sql .= " AND sc.fk_user = ".$user->id;
|
||||
}
|
||||
// If multicompany and internal users with all permissions, check user is in correct entity
|
||||
elseif (! empty($conf->multicompany->enabled))
|
||||
elseif (!empty($conf->multicompany->enabled))
|
||||
{
|
||||
$sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql.= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql.= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
|
||||
$sql .= " WHERE dbt.".$dbt_select." IN (".$objectid.")";
|
||||
$sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
|
||||
}
|
||||
}
|
||||
|
||||
if ($sql)
|
||||
{
|
||||
$resql=$db->query($sql);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
if (! $obj || $obj->nb < count(explode(',', $objectid))) return false;
|
||||
if (!$obj || $obj->nb < count(explode(',', $objectid))) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -671,10 +671,10 @@ function checkUserAccessToObject($user, $featuresarray, $objectid = 0, $tableand
|
||||
function accessforbidden($message = '', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params = null)
|
||||
{
|
||||
global $conf, $db, $user, $langs, $hookmanager;
|
||||
if (! is_object($langs))
|
||||
if (!is_object($langs))
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
|
||||
$langs=new Translate('', $conf);
|
||||
$langs = new Translate('', $conf);
|
||||
$langs->setDefaultLang();
|
||||
}
|
||||
|
||||
@ -686,7 +686,7 @@ function accessforbidden($message = '', $printheader = 1, $printfooter = 1, $sho
|
||||
elseif (function_exists("llxHeaderVierge")) llxHeaderVierge('');
|
||||
}
|
||||
print '<div class="error">';
|
||||
if (! $message) print $langs->trans("ErrorForbidden");
|
||||
if (!$message) print $langs->trans("ErrorForbidden");
|
||||
else print $message;
|
||||
print '</div>';
|
||||
print '<br>';
|
||||
@ -700,7 +700,7 @@ function accessforbidden($message = '', $printheader = 1, $printfooter = 1, $sho
|
||||
$hookmanager->initHooks(array('main'));
|
||||
}
|
||||
$parameters = array('message'=>$message, 'params'=>$params);
|
||||
$reshook=$hookmanager->executeHooks('getAccessForbiddenMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
|
||||
$reshook = $hookmanager->executeHooks('getAccessForbiddenMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
|
||||
print $hookmanager->resPrint;
|
||||
if (empty($reshook))
|
||||
{
|
||||
|
||||
@ -64,11 +64,11 @@ class EmailCollector extends CommonObject
|
||||
/**
|
||||
* @var array List of child tables. To test if we can delete object.
|
||||
*/
|
||||
protected $childtables=array();
|
||||
protected $childtables = array();
|
||||
/**
|
||||
* @var array List of child tables. To know object to delete on cascade.
|
||||
*/
|
||||
protected $childtablesoncascade=array('emailcollector_emailcollectorfilter','emailcollector_emailcollectoraction');
|
||||
protected $childtablesoncascade = array('emailcollector_emailcollectorfilter', 'emailcollector_emailcollectoraction');
|
||||
|
||||
|
||||
/**
|
||||
@ -94,10 +94,10 @@ class EmailCollector extends CommonObject
|
||||
/**
|
||||
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
|
||||
*/
|
||||
public $fields=array(
|
||||
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID','visible'=>2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1),
|
||||
'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
|
||||
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'help'=>'Example: MyCollector1'),
|
||||
public $fields = array(
|
||||
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1),
|
||||
'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
|
||||
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'help'=>'Example: MyCollector1'),
|
||||
'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'notnull'=>-1, 'searchall'=>1, 'help'=>'Example: My Email collector'),
|
||||
'description' => array('type'=>'text', 'label'=>'Description', 'visible'=>-1, 'enabled'=>1, 'position'=>60, 'notnull'=>-1),
|
||||
'host' => array('type'=>'varchar(255)', 'label'=>'EMailHost', 'visible'=>1, 'enabled'=>1, 'position'=>100, 'notnull'=>1, 'searchall'=>1, 'comment'=>"IMAP server", 'help'=>'Example: imap.gmail.com'),
|
||||
@ -107,7 +107,7 @@ class EmailCollector extends CommonObject
|
||||
//'filter' => array('type'=>'text', 'label'=>'Filter', 'visible'=>1, 'enabled'=>1, 'position'=>105),
|
||||
//'actiontodo' => array('type'=>'varchar(255)', 'label'=>'ActionToDo', 'visible'=>1, 'enabled'=>1, 'position'=>106),
|
||||
'target_directory' => array('type'=>'varchar(255)', 'label'=>'MailboxTargetDirectory', 'visible'=>1, 'enabled'=>1, 'position'=>110, 'notnull'=>0, 'comment'=>"Where to store messages once processed"),
|
||||
'maxemailpercollect' => array('type'=>'integer', 'label'=>'MaxEmailCollectPerCollect','visible'=>-1, 'enabled'=>1, 'position'=>111, 'default'=>100),
|
||||
'maxemailpercollect' => array('type'=>'integer', 'label'=>'MaxEmailCollectPerCollect', 'visible'=>-1, 'enabled'=>1, 'position'=>111, 'default'=>100),
|
||||
'datelastresult' => array('type'=>'datetime', 'label'=>'DateLastCollectResult', 'visible'=>1, 'enabled'=>'$action != "create" && $action != "edit"', 'position'=>121, 'notnull'=>-1,),
|
||||
'codelastresult' => array('type'=>'varchar(16)', 'label'=>'CodeLastResult', 'visible'=>1, 'enabled'=>'$action != "create" && $action != "edit"', 'position'=>122, 'notnull'=>-1,),
|
||||
'lastresult' => array('type'=>'varchar(255)', 'label'=>'LastResult', 'visible'=>1, 'enabled'=>'$action != "create" && $action != "edit"', 'position'=>123, 'notnull'=>-1,),
|
||||
@ -222,13 +222,13 @@ class EmailCollector extends CommonObject
|
||||
}
|
||||
|
||||
// Translate some data of arrayofkeyval
|
||||
foreach($this->fields as $key => $val)
|
||||
foreach ($this->fields as $key => $val)
|
||||
{
|
||||
if (is_array($val['arrayofkeyval']))
|
||||
{
|
||||
foreach($val['arrayofkeyval'] as $key2 => $val2)
|
||||
foreach ($val['arrayofkeyval'] as $key2 => $val2)
|
||||
{
|
||||
$this->fields[$key]['arrayofkeyval'][$key2]=$langs->trans($val2);
|
||||
$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -279,10 +279,10 @@ class EmailCollector extends CommonObject
|
||||
if (is_array($object->array_options) && count($object->array_options) > 0)
|
||||
{
|
||||
$extrafields->fetch_name_optionals_label($this->table_element);
|
||||
foreach($object->array_options as $key => $option)
|
||||
foreach ($object->array_options as $key => $option)
|
||||
{
|
||||
$shortkey = preg_replace('/options_/', '', $key);
|
||||
if (! empty($extrafields->attributes[$this->element]['unique'][$shortkey]))
|
||||
if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey]))
|
||||
{
|
||||
//var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
|
||||
unset($object->array_options[$key]);
|
||||
@ -437,38 +437,38 @@ class EmailCollector extends CommonObject
|
||||
{
|
||||
global $conf, $langs, $hookmanager;
|
||||
|
||||
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
|
||||
if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
|
||||
|
||||
$result = '';
|
||||
|
||||
$label = '<u>' . $langs->trans("EmailCollector") . '</u>';
|
||||
$label.= '<br>';
|
||||
$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
|
||||
$label = '<u>'.$langs->trans("EmailCollector").'</u>';
|
||||
$label .= '<br>';
|
||||
$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
|
||||
|
||||
$url = dol_buildpath('/admin/emailcollector_card.php', 1).'?id='.$this->id;
|
||||
|
||||
if ($option != 'nolink')
|
||||
{
|
||||
// Add param to save lastsearch_values or not
|
||||
$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
|
||||
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
|
||||
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
|
||||
$add_save_lastsearch_values=1;
|
||||
$add_save_lastsearch_values = 1;
|
||||
}
|
||||
if ($add_save_lastsearch_values) {
|
||||
$url.='&save_lastsearch_values=1';
|
||||
$url .= '&save_lastsearch_values=1';
|
||||
}
|
||||
}
|
||||
|
||||
$linkclose='';
|
||||
$linkclose = '';
|
||||
if (empty($notooltip))
|
||||
{
|
||||
if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
|
||||
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
|
||||
{
|
||||
$label=$langs->trans("ShowEmailCollector");
|
||||
$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
|
||||
$label = $langs->trans("ShowEmailCollector");
|
||||
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
|
||||
}
|
||||
$linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
|
||||
$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
|
||||
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
|
||||
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
|
||||
|
||||
/*
|
||||
$hookmanager->initHooks(array('myobjectdao'));
|
||||
@ -681,7 +681,7 @@ class EmailCollector extends CommonObject
|
||||
$flags .= '/novalidate-cert';
|
||||
//$flags.='/readonly';
|
||||
//$flags.='/debug';
|
||||
if ($norsh || ! empty($conf->global->IMPA_FORCE_NORSH)) $flags .= '/norsh';
|
||||
if ($norsh || !empty($conf->global->IMPA_FORCE_NORSH)) $flags .= '/norsh';
|
||||
|
||||
$connectstringserver = '{'.$this->host.':993'.$flags.'}';
|
||||
|
||||
@ -698,13 +698,13 @@ class EmailCollector extends CommonObject
|
||||
{
|
||||
if (function_exists('mb_convert_encoding')) {
|
||||
// change spaces by entropy because mb_convert fail with spaces
|
||||
$str=preg_replace("/ /", "xyxy", $str);
|
||||
$str = preg_replace("/ /", "xyxy", $str);
|
||||
// if mb_convert work
|
||||
if ($str = mb_convert_encoding($str, "UTF-7")) {
|
||||
// change characters
|
||||
$str=preg_replace("/\+A/", "&A", $str);
|
||||
$str = preg_replace("/\+A/", "&A", $str);
|
||||
// change to spaces again
|
||||
$str=preg_replace("/xyxy/", " ", $str);
|
||||
$str = preg_replace("/xyxy/", " ", $str);
|
||||
return $str;
|
||||
} else {
|
||||
// print error and return false
|
||||
@ -762,59 +762,59 @@ class EmailCollector extends CommonObject
|
||||
// Overwrite values with values extracted from source email
|
||||
// $this->actionparam = 'opportunity_status=123;abc=EXTRACT:BODY:....'
|
||||
$arrayvaluetouse = dolExplodeIntoArray($actionparam, ';', '=');
|
||||
foreach($arrayvaluetouse as $propertytooverwrite => $valueforproperty)
|
||||
foreach ($arrayvaluetouse as $propertytooverwrite => $valueforproperty)
|
||||
{
|
||||
$tmpclass=''; $tmpproperty='';
|
||||
$tmparray=explode('.', $propertytooverwrite);
|
||||
$tmpclass = ''; $tmpproperty = '';
|
||||
$tmparray = explode('.', $propertytooverwrite);
|
||||
if (count($tmparray) == 2)
|
||||
{
|
||||
$tmpclass=$tmparray[0];
|
||||
$tmpproperty=$tmparray[1];
|
||||
$tmpclass = $tmparray[0];
|
||||
$tmpproperty = $tmparray[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmpproperty=$tmparray[0];
|
||||
$tmpproperty = $tmparray[0];
|
||||
}
|
||||
if ($tmpclass && ($tmpclass != $object->element)) continue; // Property is for another type of object
|
||||
if ($tmpclass && ($tmpclass != $object->element)) continue; // Property is for another type of object
|
||||
|
||||
//if (property_exists($object, $tmpproperty) || preg_match('/^options_/', $tmpproperty))
|
||||
if ($tmpproperty)
|
||||
{
|
||||
$sourcestring='';
|
||||
$sourcefield='';
|
||||
$regexstring='';
|
||||
$sourcestring = '';
|
||||
$sourcefield = '';
|
||||
$regexstring = '';
|
||||
//$transformationstring='';
|
||||
$regforregex=array();
|
||||
$regforregex = array();
|
||||
if (preg_match('/^EXTRACT:([a-zA-Z0-9]+):(.*):([^:])$/', $valueforproperty, $regforregex))
|
||||
{
|
||||
$sourcefield=$regforregex[1];
|
||||
$regexstring=$regforregex[2];
|
||||
$sourcefield = $regforregex[1];
|
||||
$regexstring = $regforregex[2];
|
||||
//$transofrmationstring=$regforregex[3];
|
||||
}
|
||||
elseif (preg_match('/^EXTRACT:([a-zA-Z0-9]+):(.*)$/', $valueforproperty, $regforregex))
|
||||
{
|
||||
$sourcefield=$regforregex[1];
|
||||
$regexstring=$regforregex[2];
|
||||
$sourcefield = $regforregex[1];
|
||||
$regexstring = $regforregex[2];
|
||||
}
|
||||
if (! empty($sourcefield) && ! empty($regexstring))
|
||||
if (!empty($sourcefield) && !empty($regexstring))
|
||||
{
|
||||
if (strtolower($sourcefield) == 'body') $sourcestring=$messagetext;
|
||||
elseif (strtolower($sourcefield) == 'subject') $sourcestring=$subject;
|
||||
elseif (strtolower($sourcefield) == 'header') $sourcestring=$header;
|
||||
if (strtolower($sourcefield) == 'body') $sourcestring = $messagetext;
|
||||
elseif (strtolower($sourcefield) == 'subject') $sourcestring = $subject;
|
||||
elseif (strtolower($sourcefield) == 'header') $sourcestring = $header;
|
||||
|
||||
if ($sourcestring)
|
||||
{
|
||||
$regforval=array();
|
||||
$regexoptions='';
|
||||
if (strtolower($sourcefield) == 'body') $regexoptions='ms'; // The m means ^ and $ char is valid at each new line. The s means the char '.' is valid for new lines char too
|
||||
if (strtolower($sourcefield) == 'header') $regexoptions='m'; // The m means ^ and $ char is valid at each new line.
|
||||
$regforval = array();
|
||||
$regexoptions = '';
|
||||
if (strtolower($sourcefield) == 'body') $regexoptions = 'ms'; // The m means ^ and $ char is valid at each new line. The s means the char '.' is valid for new lines char too
|
||||
if (strtolower($sourcefield) == 'header') $regexoptions = 'm'; // The m means ^ and $ char is valid at each new line.
|
||||
|
||||
//var_dump($tmpproperty.' - '.$regexstring.' - '.$regexoptions.' - '.$sourcestring);
|
||||
if (preg_match('/'.$regexstring.'/'.$regexoptions, $sourcestring, $regforval))
|
||||
{
|
||||
//var_dump($regforval[1]);exit;
|
||||
// Overwrite param $tmpproperty
|
||||
$object->$tmpproperty = isset($regforval[1])?trim($regforval[1]):null;
|
||||
$object->$tmpproperty = isset($regforval[1]) ?trim($regforval[1]) : null;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -832,24 +832,24 @@ class EmailCollector extends CommonObject
|
||||
}
|
||||
elseif (preg_match('/^(SET|SETIFEMPTY):(.*)$/', $valueforproperty, $regforregex))
|
||||
{
|
||||
$valuecurrent='';
|
||||
$valuecurrent = '';
|
||||
if (preg_match('/^options_/', $tmpproperty)) $valuecurrent = $object->array_options[preg_replace('/^options_/', '', $tmpproperty)];
|
||||
else $valuecurrent = $object->$tmpproperty;
|
||||
|
||||
if ($regforregex[1] == 'SET' || empty($valuecurrent))
|
||||
{
|
||||
$valuetouse = $regforregex[2];
|
||||
$substitutionarray=array();
|
||||
$matcharray=array();
|
||||
$substitutionarray = array();
|
||||
$matcharray = array();
|
||||
preg_match_all('/__([a-z0-9]+(?:_[a-z0-9]+)?)__/i', $valuetouse, $matcharray);
|
||||
//var_dump($tmpproperty.' - '.$object->$tmpproperty.' - '.$valuetouse); var_dump($matcharray);
|
||||
if (is_array($matcharray[1])) // $matcharray[1] is array with list of substitution key found without the __
|
||||
{
|
||||
foreach($matcharray[1] as $keytoreplace)
|
||||
foreach ($matcharray[1] as $keytoreplace)
|
||||
{
|
||||
if ($keytoreplace && isset($object->$keytoreplace))
|
||||
{
|
||||
$substitutionarray['__'.$keytoreplace.'__']=$object->$keytoreplace;
|
||||
$substitutionarray['__'.$keytoreplace.'__'] = $object->$keytoreplace;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -921,73 +921,73 @@ class EmailCollector extends CommonObject
|
||||
$this->fetchActions();
|
||||
|
||||
$sourcedir = $this->source_directory;
|
||||
$targetdir = ($this->target_directory ? $this->target_directory : ''); // Can be '[Gmail]/Trash' or 'mytag'
|
||||
$targetdir = ($this->target_directory ? $this->target_directory : ''); // Can be '[Gmail]/Trash' or 'mytag'
|
||||
|
||||
$connectstringserver = $this->getConnectStringIMAP();
|
||||
$connectstringsource = $connectstringserver.imap_utf7_encode($sourcedir);
|
||||
$connectstringtarget = $connectstringserver.imap_utf7_encode($targetdir);
|
||||
|
||||
$connection = imap_open($connectstringsource, $this->login, $this->password);
|
||||
if (! $connection)
|
||||
if (!$connection)
|
||||
{
|
||||
$this->error = 'Failed to open IMAP connection '.$connectstringsource;
|
||||
return -3;
|
||||
}
|
||||
imap_errors(); // Clear stack of errors.
|
||||
imap_errors(); // Clear stack of errors.
|
||||
|
||||
// $conf->global->MAIL_PREFIX_FOR_EMAIL_ID must be defined
|
||||
$host=dol_getprefix('email');
|
||||
$host = dol_getprefix('email');
|
||||
|
||||
// Define the IMAP search string
|
||||
// See https://tools.ietf.org/html/rfc3501#section-6.4.4 for IMAPv4 (PHP not yet compatible)
|
||||
// See https://tools.ietf.org/html/rfc1064 page 13 for IMAPv2
|
||||
//$search='ALL';
|
||||
$search='UNDELETED'; // Seems not supported by some servers
|
||||
$searchhead='';
|
||||
$searchfilterdoltrackid=0;
|
||||
$searchfilternodoltrackid=0;
|
||||
foreach($this->filters as $rule)
|
||||
$search = 'UNDELETED'; // Seems not supported by some servers
|
||||
$searchhead = '';
|
||||
$searchfilterdoltrackid = 0;
|
||||
$searchfilternodoltrackid = 0;
|
||||
foreach ($this->filters as $rule)
|
||||
{
|
||||
if (empty($rule['status'])) continue;
|
||||
|
||||
if ($rule['type'] == 'to') $search.=($search?' ':'').'TO "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'bcc') $search.=($search?' ':'').'BCC';
|
||||
if ($rule['type'] == 'cc') $search.=($search?' ':'').'CC';
|
||||
if ($rule['type'] == 'from') $search.=($search?' ':'').'FROM "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'subject') $search.=($search?' ':'').'SUBJECT "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'body') $search.=($search?' ':'').'BODY "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'header') $search.=($search?' ':'').'HEADER '.$rule['rulevalue'];
|
||||
if ($rule['type'] == 'to') $search .= ($search ? ' ' : '').'TO "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'bcc') $search .= ($search ? ' ' : '').'BCC';
|
||||
if ($rule['type'] == 'cc') $search .= ($search ? ' ' : '').'CC';
|
||||
if ($rule['type'] == 'from') $search .= ($search ? ' ' : '').'FROM "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'subject') $search .= ($search ? ' ' : '').'SUBJECT "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'body') $search .= ($search ? ' ' : '').'BODY "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'header') $search .= ($search ? ' ' : '').'HEADER '.$rule['rulevalue'];
|
||||
|
||||
if ($rule['type'] == 'notinsubject') $search.=($search?' ':'').'SUBJECT NOT "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'notinbody') $search.=($search?' ':'').'BODY NOT "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'notinsubject') $search .= ($search ? ' ' : '').'SUBJECT NOT "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'notinbody') $search .= ($search ? ' ' : '').'BODY NOT "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
|
||||
if ($rule['type'] == 'seen') $search.=($search?' ':'').'SEEN';
|
||||
if ($rule['type'] == 'unseen') $search.=($search?' ':'').'UNSEEN';
|
||||
if ($rule['type'] == 'unanswered') $search.=($search?' ':'').'UNANSWERED';
|
||||
if ($rule['type'] == 'answered') $search.=($search?' ':'').'ANSWERED';
|
||||
if ($rule['type'] == 'smaller') $search.=($search?' ':'').'SMALLER "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'larger') $search.=($search?' ':'').'LARGER "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'seen') $search .= ($search ? ' ' : '').'SEEN';
|
||||
if ($rule['type'] == 'unseen') $search .= ($search ? ' ' : '').'UNSEEN';
|
||||
if ($rule['type'] == 'unanswered') $search .= ($search ? ' ' : '').'UNANSWERED';
|
||||
if ($rule['type'] == 'answered') $search .= ($search ? ' ' : '').'ANSWERED';
|
||||
if ($rule['type'] == 'smaller') $search .= ($search ? ' ' : '').'SMALLER "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
if ($rule['type'] == 'larger') $search .= ($search ? ' ' : '').'LARGER "'.str_replace('"', '', $rule['rulevalue']).'"';
|
||||
|
||||
if ($rule['type'] == 'withtrackingid') { $searchfilterdoltrackid++; $searchhead.='/References.*@'.preg_quote($host, '/').'/'; }
|
||||
if ($rule['type'] == 'withouttrackingid') { $searchfilternodoltrackid++; $searchhead.='! /References.*@'.preg_quote($host, '/').'/';}
|
||||
if ($rule['type'] == 'withtrackingid') { $searchfilterdoltrackid++; $searchhead .= '/References.*@'.preg_quote($host, '/').'/'; }
|
||||
if ($rule['type'] == 'withouttrackingid') { $searchfilternodoltrackid++; $searchhead .= '! /References.*@'.preg_quote($host, '/').'/'; }
|
||||
}
|
||||
|
||||
if (empty($targetdir)) // Use last date as filter if there is no targetdir defined.
|
||||
{
|
||||
$fromdate=0;
|
||||
$fromdate = 0;
|
||||
if ($this->datelastok) $fromdate = $this->datelastok;
|
||||
if ($fromdate > 0) $search.=($search?' ':'').'SINCE '.date('j-M-Y', $fromdate - 1); // SENTSINCE not supported. Date must be X-Abc-9999 (X on 1 digit if < 10)
|
||||
if ($fromdate > 0) $search .= ($search ? ' ' : '').'SINCE '.date('j-M-Y', $fromdate - 1); // SENTSINCE not supported. Date must be X-Abc-9999 (X on 1 digit if < 10)
|
||||
//$search.=($search?' ':'').'SINCE 8-Apr-2018';
|
||||
}
|
||||
dol_syslog("IMAP search string = ".$search);
|
||||
//var_dump($search);
|
||||
|
||||
$nbemailprocessed=0;
|
||||
$nbemailok=0;
|
||||
$nbactiondone=0;
|
||||
$nbemailprocessed = 0;
|
||||
$nbemailok = 0;
|
||||
$nbactiondone = 0;
|
||||
|
||||
// Scan IMAP inbox
|
||||
$arrayofemail= imap_search($connection, $search, null, "UTF-8");
|
||||
$arrayofemail = imap_search($connection, $search, null, "UTF-8");
|
||||
if ($arrayofemail === false)
|
||||
{
|
||||
// Nothing found or search string not understood
|
||||
@ -1001,7 +1001,7 @@ class EmailCollector extends CommonObject
|
||||
}
|
||||
|
||||
// Loop on each email found
|
||||
if (! $error && ! empty($arrayofemail) && count($arrayofemail) > 0)
|
||||
if (!$error && !empty($arrayofemail) && count($arrayofemail) > 0)
|
||||
{
|
||||
// Loop to get part html and plain
|
||||
/*
|
||||
@ -1078,15 +1078,15 @@ class EmailCollector extends CommonObject
|
||||
|
||||
dol_syslog("Start of loop on email", LOG_INFO, 1);
|
||||
|
||||
foreach($arrayofemail as $imapemail)
|
||||
foreach ($arrayofemail as $imapemail)
|
||||
{
|
||||
if ($nbemailprocessed > 1000)
|
||||
{
|
||||
break; // Do not process more than 1000 email per launch (this is a different protection than maxnbcollectedpercollect
|
||||
break; // Do not process more than 1000 email per launch (this is a different protection than maxnbcollectedpercollect
|
||||
}
|
||||
|
||||
$header = imap_fetchheader($connection, $imapemail, 0);
|
||||
$matches=array();
|
||||
$matches = array();
|
||||
preg_match_all('/([^: ]+): (.+?(?:\r\n\s(?:.+?))*)\r\n/m', $header, $matches);
|
||||
$headers = array_combine($matches[1], $matches[2]);
|
||||
//var_dump($headers);
|
||||
@ -1206,26 +1206,26 @@ class EmailCollector extends CommonObject
|
||||
//print $messagetext;
|
||||
//exit;
|
||||
|
||||
$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;
|
||||
$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();
|
||||
$reg = array();
|
||||
if (preg_match('/^(.*)<(.*)>$/', $fromstring, $reg))
|
||||
{
|
||||
$from=$reg[2];
|
||||
$fromtext=$reg[1];
|
||||
$from = $reg[2];
|
||||
$fromtext = $reg[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$from = $fromstring;
|
||||
$fromtext='';
|
||||
$fromtext = '';
|
||||
}
|
||||
$fk_element_id = 0; $fk_element_type = '';
|
||||
|
||||
@ -1375,10 +1375,10 @@ class EmailCollector extends CommonObject
|
||||
else $descriptiontitle = $langs->trans("ActionAC_".$actioncode).' - '.$langs->trans("MailFrom").' '.$from;
|
||||
|
||||
$descriptionmeta = dol_concatdesc($descriptionmeta, $langs->trans("MailTopic").' : '.dol_escape_htmltag($subject));
|
||||
$descriptionmeta = dol_concatdesc($descriptionmeta, $langs->trans("MailFrom").($langs->trans("MailFrom") != 'From' ? ' (From)':'').' : '.dol_escape_htmltag($fromstring));
|
||||
if ($sender) $descriptionmeta = dol_concatdesc($descriptionmeta, $langs->trans("Sender").($langs->trans("Sender") != 'Sender' ? ' (Sender)':'').' : '.dol_escape_htmltag($sender));
|
||||
$descriptionmeta = dol_concatdesc($descriptionmeta, $langs->trans("MailTo").($langs->trans("MailTo") != 'To' ? ' (To)':'').' : '.dol_escape_htmltag($to));
|
||||
if ($sendtocc) $descriptionmeta = dol_concatdesc($descriptionmeta, $langs->trans("MailCC").($langs->trans("MailCC") != 'CC' ? ' (CC)':'').' : '.dol_escape_htmltag($sendtocc));
|
||||
$descriptionmeta = dol_concatdesc($descriptionmeta, $langs->trans("MailFrom").($langs->trans("MailFrom") != 'From' ? ' (From)' : '').' : '.dol_escape_htmltag($fromstring));
|
||||
if ($sender) $descriptionmeta = dol_concatdesc($descriptionmeta, $langs->trans("Sender").($langs->trans("Sender") != 'Sender' ? ' (Sender)' : '').' : '.dol_escape_htmltag($sender));
|
||||
$descriptionmeta = dol_concatdesc($descriptionmeta, $langs->trans("MailTo").($langs->trans("MailTo") != 'To' ? ' (To)' : '').' : '.dol_escape_htmltag($to));
|
||||
if ($sendtocc) $descriptionmeta = dol_concatdesc($descriptionmeta, $langs->trans("MailCC").($langs->trans("MailCC") != 'CC' ? ' (CC)' : '').' : '.dol_escape_htmltag($sendtocc));
|
||||
//if ($bcc) $descriptionmeta = dol_concatdesc($descriptionmeta, $langs->trans("Bcc").' : '.dol_escape_htmltag($bcc));
|
||||
}
|
||||
|
||||
@ -1394,38 +1394,38 @@ class EmailCollector extends CommonObject
|
||||
else
|
||||
{
|
||||
$actionparam = $operation['actionparam'];
|
||||
$nametouseforthirdparty='';
|
||||
$nametouseforthirdparty = '';
|
||||
|
||||
// $this->actionparam = 'SET:aaa' or 'EXTRACT:BODY:....'
|
||||
$arrayvaluetouse = dolExplodeIntoArray($actionparam, ';', '=');
|
||||
foreach($arrayvaluetouse as $propertytooverwrite => $valueforproperty)
|
||||
foreach ($arrayvaluetouse as $propertytooverwrite => $valueforproperty)
|
||||
{
|
||||
$sourcestring='';
|
||||
$sourcefield='';
|
||||
$regexstring='';
|
||||
$regforregex=array();
|
||||
$sourcestring = '';
|
||||
$sourcefield = '';
|
||||
$regexstring = '';
|
||||
$regforregex = array();
|
||||
|
||||
if (preg_match('/^EXTRACT:([a-zA-Z0-9]+):(.*)$/', $valueforproperty, $regforregex))
|
||||
{
|
||||
$sourcefield=$regforregex[1];
|
||||
$regexstring=$regforregex[2];
|
||||
$sourcefield = $regforregex[1];
|
||||
$regexstring = $regforregex[2];
|
||||
}
|
||||
|
||||
if (! empty($sourcefield) && ! empty($regexstring))
|
||||
if (!empty($sourcefield) && !empty($regexstring))
|
||||
{
|
||||
if (strtolower($sourcefield) == 'body') $sourcestring=$messagetext;
|
||||
elseif (strtolower($sourcefield) == 'subject') $sourcestring=$subject;
|
||||
elseif (strtolower($sourcefield) == 'header') $sourcestring=$header;
|
||||
if (strtolower($sourcefield) == 'body') $sourcestring = $messagetext;
|
||||
elseif (strtolower($sourcefield) == 'subject') $sourcestring = $subject;
|
||||
elseif (strtolower($sourcefield) == 'header') $sourcestring = $header;
|
||||
|
||||
if ($sourcestring)
|
||||
{
|
||||
$regforval=array();
|
||||
$regforval = array();
|
||||
//var_dump($regexstring);var_dump($sourcestring);
|
||||
if (preg_match('/'.$regexstring.'/ms', $sourcestring, $regforval))
|
||||
{
|
||||
//var_dump($regforval[1]);exit;
|
||||
// Overwrite param $tmpproperty
|
||||
$nametouseforthirdparty = isset($regforval[1])?trim($regforval[1]):null;
|
||||
$nametouseforthirdparty = isset($regforval[1]) ?trim($regforval[1]) : null;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1515,7 +1515,7 @@ class EmailCollector extends CommonObject
|
||||
// TODO Check if $msg ID already in database for $conf->entity
|
||||
|
||||
|
||||
if (! $alreadycreated)
|
||||
if (!$alreadycreated)
|
||||
{
|
||||
if ($projectstatic->id > 0)
|
||||
{
|
||||
@ -1542,30 +1542,30 @@ class EmailCollector extends CommonObject
|
||||
|
||||
// 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->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
|
||||
$actioncomm->code = 'AC_'.$actioncode;
|
||||
$actioncomm->label = $langs->trans("ActionAC_".$actioncode).' - '.$langs->trans("MailFrom").' '.$from;
|
||||
$actioncomm->note_private= $descriptionfull;
|
||||
$actioncomm->note_private = $descriptionfull;
|
||||
$actioncomm->fk_project = $projectstatic->id;
|
||||
$actioncomm->datep = $date;
|
||||
$actioncomm->datef = $date;
|
||||
$actioncomm->percentage = -1; // Not applicable
|
||||
$actioncomm->percentage = -1; // Not applicable
|
||||
$actioncomm->socid = $thirdpartystatic->id;
|
||||
$actioncomm->contactid = $contactstatic->id;
|
||||
$actioncomm->socpeopleassigned = (!empty($contactstatic->id) ? array($contactstatic->id => '') : array());
|
||||
$actioncomm->authorid = $user->id; // User saving action
|
||||
$actioncomm->userownerid = $user->id; // Owner of action
|
||||
$actioncomm->authorid = $user->id; // User saving action
|
||||
$actioncomm->userownerid = $user->id; // Owner of action
|
||||
// Fields when action is an email (content should be added into note)
|
||||
$actioncomm->email_msgid = $msgid;
|
||||
$actioncomm->email_from = $fromstring;
|
||||
$actioncomm->email_sender= $sender;
|
||||
$actioncomm->email_sender = $sender;
|
||||
$actioncomm->email_to = $to;
|
||||
$actioncomm->email_tocc = $sendtocc;
|
||||
$actioncomm->email_tobcc = $sendtobcc;
|
||||
$actioncomm->email_subject = $subject;
|
||||
$actioncomm->errors_to = '';
|
||||
|
||||
if (! in_array($fk_element_type, array('societe','contact','project','user')))
|
||||
if (!in_array($fk_element_type, array('societe', 'contact', 'project', 'user')))
|
||||
{
|
||||
$actioncomm->fk_element = $fk_element_id;
|
||||
$actioncomm->elementtype = $fk_element_type;
|
||||
@ -1637,18 +1637,18 @@ class EmailCollector extends CommonObject
|
||||
if (empty($projecttocreate->ref))
|
||||
{
|
||||
// Get next project Ref
|
||||
$defaultref='';
|
||||
$modele = empty($conf->global->PROJECT_ADDON)?'mod_project_simple':$conf->global->PROJECT_ADDON;
|
||||
$defaultref = '';
|
||||
$modele = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON;
|
||||
|
||||
// Search template files
|
||||
$file=''; $classname=''; $filefound=0; $reldir='';
|
||||
$dirmodels=array_merge(array('/'), (array) $conf->modules_parts['models']);
|
||||
foreach($dirmodels as $reldir)
|
||||
$file = ''; $classname = ''; $filefound = 0; $reldir = '';
|
||||
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
|
||||
foreach ($dirmodels as $reldir)
|
||||
{
|
||||
$file=dol_buildpath($reldir."core/modules/project/".$modele.'.php', 0);
|
||||
$file = dol_buildpath($reldir."core/modules/project/".$modele.'.php', 0);
|
||||
if (file_exists($file))
|
||||
{
|
||||
$filefound=1;
|
||||
$filefound = 1;
|
||||
$classname = $modele;
|
||||
break;
|
||||
}
|
||||
@ -1656,7 +1656,7 @@ class EmailCollector extends CommonObject
|
||||
|
||||
if ($filefound)
|
||||
{
|
||||
$result=dol_include_once($reldir."core/modules/project/".$modele.'.php');
|
||||
$result = dol_include_once($reldir."core/modules/project/".$modele.'.php');
|
||||
$modProject = new $classname;
|
||||
|
||||
if ($savesocid > 0)
|
||||
@ -1752,18 +1752,18 @@ class EmailCollector extends CommonObject
|
||||
if (empty($tickettocreate->ref))
|
||||
{
|
||||
// Get next project Ref
|
||||
$defaultref='';
|
||||
$modele = empty($conf->global->TICKET_ADDON)?'mod_ticket_simple':$conf->global->TICKET_ADDON;
|
||||
$defaultref = '';
|
||||
$modele = empty($conf->global->TICKET_ADDON) ? 'mod_ticket_simple' : $conf->global->TICKET_ADDON;
|
||||
|
||||
// Search template files
|
||||
$file=''; $classname=''; $filefound=0; $reldir='';
|
||||
$dirmodels=array_merge(array('/'), (array) $conf->modules_parts['models']);
|
||||
foreach($dirmodels as $reldir)
|
||||
$file = ''; $classname = ''; $filefound = 0; $reldir = '';
|
||||
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
|
||||
foreach ($dirmodels as $reldir)
|
||||
{
|
||||
$file=dol_buildpath($reldir."core/modules/ticket/".$modele.'.php', 0);
|
||||
$file = dol_buildpath($reldir."core/modules/ticket/".$modele.'.php', 0);
|
||||
if (file_exists($file))
|
||||
{
|
||||
$filefound=1;
|
||||
$filefound = 1;
|
||||
$classname = $modele;
|
||||
break;
|
||||
}
|
||||
@ -1771,7 +1771,7 @@ class EmailCollector extends CommonObject
|
||||
|
||||
if ($filefound)
|
||||
{
|
||||
$result=dol_include_once($reldir."core/modules/ticket/".$modele.'.php');
|
||||
$result = dol_include_once($reldir."core/modules/ticket/".$modele.'.php');
|
||||
$modTicket = new $classname;
|
||||
|
||||
if ($savesocid > 0)
|
||||
@ -1878,16 +1878,16 @@ class EmailCollector extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
$output=$langs->trans('XEmailsDoneYActionsDone', $nbemailprocessed, $nbemailok, $nbactiondone);
|
||||
$output = $langs->trans('XEmailsDoneYActionsDone', $nbemailprocessed, $nbemailok, $nbactiondone);
|
||||
|
||||
dol_syslog("End of loop on emails", LOG_INFO, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$output=$langs->trans('NoNewEmailToProcess');
|
||||
$output = $langs->trans('NoNewEmailToProcess');
|
||||
}
|
||||
|
||||
imap_expunge($connection); // To validate any move
|
||||
imap_expunge($connection); // To validate any move
|
||||
|
||||
imap_close($connection);
|
||||
|
||||
@ -1896,7 +1896,7 @@ class EmailCollector extends CommonObject
|
||||
$this->debuginfo = 'IMAP search string used : '.$search;
|
||||
if ($searchhead) $this->debuginfo .= '<br>Then search string into email header : '.$searchhead;
|
||||
|
||||
if (! $error) $this->datelastok = $now;
|
||||
if (!$error) $this->datelastok = $now;
|
||||
|
||||
if (!empty($this->errors)) $this->lastresult .= " - ".join(" - ", $this->errors);
|
||||
$this->codelastresult = ($error ? 'KO' : 'OK');
|
||||
@ -1922,7 +1922,7 @@ class EmailCollector extends CommonObject
|
||||
{
|
||||
// input $mbox = IMAP stream, $mid = message id
|
||||
// output all the following:
|
||||
global $charset,$htmlmsg,$plainmsg,$attachments;
|
||||
global $charset, $htmlmsg, $plainmsg, $attachments;
|
||||
$htmlmsg = $plainmsg = $charset = '';
|
||||
$attachments = array();
|
||||
|
||||
@ -1935,11 +1935,11 @@ class EmailCollector extends CommonObject
|
||||
|
||||
if (!$s->parts) {
|
||||
// simple
|
||||
$this->getpart($mbox, $mid, $s, 0); // pass 0 as part-number
|
||||
$this->getpart($mbox, $mid, $s, 0); // pass 0 as part-number
|
||||
} else {
|
||||
// multipart: cycle through each part
|
||||
foreach ($s->parts as $partno0 => $p) {
|
||||
$this->getpart($mbox, $mid, $p, $partno0+1);
|
||||
$this->getpart($mbox, $mid, $p, $partno0 + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1971,16 +1971,16 @@ class EmailCollector extends CommonObject
|
||||
private function getpart($mbox, $mid, $p, $partno)
|
||||
{
|
||||
// $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple
|
||||
global $htmlmsg,$plainmsg,$charset,$attachments;
|
||||
global $htmlmsg, $plainmsg, $charset, $attachments;
|
||||
|
||||
// DECODE DATA
|
||||
$data = ($partno)?
|
||||
imap_fetchbody($mbox, $mid, $partno): // multipart
|
||||
imap_body($mbox, $mid); // simple
|
||||
$data = ($partno) ?
|
||||
imap_fetchbody($mbox, $mid, $partno) : // multipart
|
||||
imap_body($mbox, $mid); // simple
|
||||
// Any part may be encoded, even plain text messages, so check everything.
|
||||
if ($p->encoding==4)
|
||||
if ($p->encoding == 4)
|
||||
$data = quoted_printable_decode($data);
|
||||
elseif ($p->encoding==3)
|
||||
elseif ($p->encoding == 3)
|
||||
$data = base64_decode($data);
|
||||
|
||||
// PARAMETERS
|
||||
@ -2006,20 +2006,20 @@ class EmailCollector extends CommonObject
|
||||
// so an attached text file (type 0) is not mistaken as the message.
|
||||
if ($params['filename'] || $params['name']) {
|
||||
// filename may be given as 'Filename' or 'Name' or both
|
||||
$filename = ($params['filename'])? $params['filename'] : $params['name'];
|
||||
$filename = ($params['filename']) ? $params['filename'] : $params['name'];
|
||||
// filename may be encoded, so see imap_mime_header_decode()
|
||||
$attachments[$filename] = $data; // this is a problem if two files have same name
|
||||
$attachments[$filename] = $data; // this is a problem if two files have same name
|
||||
}
|
||||
|
||||
// TEXT
|
||||
if ($p->type==0 && $data) {
|
||||
if ($p->type == 0 && $data) {
|
||||
// Messages may be split in different parts because of inline attachments,
|
||||
// so append parts together with blank row.
|
||||
if (strtolower($p->subtype)=='plain')
|
||||
$plainmsg .= trim($data) ."\n\n";
|
||||
if (strtolower($p->subtype) == 'plain')
|
||||
$plainmsg .= trim($data)."\n\n";
|
||||
else
|
||||
$htmlmsg .= $data ."<br><br>";
|
||||
$charset = $params['charset']; // assume all parts are same charset
|
||||
$htmlmsg .= $data."<br><br>";
|
||||
$charset = $params['charset']; // assume all parts are same charset
|
||||
}
|
||||
|
||||
// EMBEDDED MESSAGE
|
||||
@ -2027,7 +2027,7 @@ class EmailCollector extends CommonObject
|
||||
// but AOL uses type 1 (multipart), which is not handled here.
|
||||
// There are no PHP functions to parse embedded messages,
|
||||
// so this just appends the raw source to the main message.
|
||||
elseif ($p->type==2 && $data) {
|
||||
elseif ($p->type == 2 && $data) {
|
||||
$plainmsg .= $data."\n\n";
|
||||
}
|
||||
|
||||
@ -2035,7 +2035,7 @@ class EmailCollector extends CommonObject
|
||||
if ($p->parts) {
|
||||
foreach ($p->parts as $partno0=>$p2)
|
||||
{
|
||||
$this->getpart($mbox, $mid, $p2, $partno.'.'.($partno0+1)); // 1.2, 1.2.1, etc.
|
||||
$this->getpart($mbox, $mid, $p2, $partno.'.'.($partno0 + 1)); // 1.2, 1.2.1, etc.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user