Merge branch '7.0' of git@github.com:Dolibarr/dolibarr.git into 7.0

This commit is contained in:
Laurent Destailleur 2018-04-06 00:02:06 +02:00
commit 723ac6fba0
16 changed files with 104 additions and 52 deletions

View File

@ -55,8 +55,7 @@ $search_lang=GETPOST('search_lang','alpha');
$search_fk_user=GETPOST('search_fk_user','intcomma'); $search_fk_user=GETPOST('search_fk_user','intcomma');
$search_topic=GETPOST('search_topic','alpha'); $search_topic=GETPOST('search_topic','alpha');
$allowed=1; if (! empty($user->socid)) accessforbidden();
if (! $allowed) accessforbidden();
$acts[0] = "activate"; $acts[0] = "activate";
$acts[1] = "disable"; $acts[1] = "disable";

View File

@ -234,7 +234,7 @@ $sql.= ' a.fk_user_author,a.fk_user_action,';
$sql.= " a.fk_contact, a.note, a.percent as percent,"; $sql.= " a.fk_contact, a.note, a.percent as percent,";
$sql.= " a.fk_element, a.elementtype,"; $sql.= " a.fk_element, a.elementtype,";
$sql.= " c.code as type_code, c.libelle as type_label,"; $sql.= " c.code as type_code, c.libelle as type_label,";
$sql.= " sp.lastname, sp.firstname"; $sql.= " sp.lastname, sp.firstname, sp.email, sp.phone, sp.address, sp.phone as phone_pro, sp.phone_mobile, sp.phone_perso, sp.fk_pays as country_id";
// Add fields from extrafields // Add fields from extrafields
foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
$sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
@ -606,9 +606,14 @@ if ($resql)
print '<td>'; print '<td>';
if ($obj->fk_contact > 0) if ($obj->fk_contact > 0)
{ {
$contactstatic->id=$obj->fk_contact;
$contactstatic->email=$obj->email;
$contactstatic->lastname=$obj->lastname; $contactstatic->lastname=$obj->lastname;
$contactstatic->firstname=$obj->firstname; $contactstatic->firstname=$obj->firstname;
$contactstatic->id=$obj->fk_contact; $contactstatic->phone_pro=$obj->phone_pro;
$contactstatic->phone_mobile=$obj->phone_mobile;
$contactstatic->phone_perso=$obj->phone_perso;
$contactstatic->country_id=$obj->country_id;
print $contactstatic->getNomUrl(1,'',28); print $contactstatic->getNomUrl(1,'',28);
} }
else else

View File

@ -746,10 +746,16 @@ class Facture extends CommonInvoice
} }
else if ($reshook < 0) $error++;*/ else if ($reshook < 0) $error++;*/
// Call trigger if (! $error)
$result=$this->call_trigger('BILL_CREATE',$user); {
if ($result < 0) $error++; if (! $notrigger)
// End call triggers {
// Call trigger
$result=$this->call_trigger('BILL_CREATE',$user);
if ($result < 0) $error++;
// End call triggers
}
}
if (! $error) if (! $error)
{ {

View File

@ -1358,19 +1358,24 @@ abstract class CommonObject
if (empty($format)) $format='text'; if (empty($format)) $format='text';
if (empty($id_field)) $id_field='rowid'; if (empty($id_field)) $id_field='rowid';
$fk_user_field = 'fk_user_modif';
$error=0; $error=0;
$this->db->begin(); $this->db->begin();
// Special case // Special case
if ($table == 'product' && $field == 'note_private') $field='note'; if ($table == 'product' && $field == 'note_private') $field='note';
if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) {
$fk_user_field = 'fk_user_mod';
}
$sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET ";
if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'";
else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value);
else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null");
if (! empty($fuser) && is_object($fuser)) $sql.=", fk_user_modif = ".$fuser->id; if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id;
elseif (empty($fuser) || $fuser != 'none') $sql.=", fk_user_modif = ".$user->id; elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id;
$sql.= " WHERE ".$id_field." = ".$id; $sql.= " WHERE ".$id_field." = ".$id;
dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG);

View File

@ -175,7 +175,7 @@ class HookManager
'formatEvent', 'formatEvent',
'printObjectLine', 'printObjectLine',
'printObjectSubLine', 'printObjectSubLine',
'createDictionaryFieldList', 'createDictionaryFieldlist',
'editDictionaryFieldlist', 'editDictionaryFieldlist',
'getFormMail', 'getFormMail',
'showLinkToObjectBlock' 'showLinkToObjectBlock'

View File

@ -772,6 +772,7 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
$form = new Form($db); $form = new Form($db);
$optioncss = GETPOST('optioncss', 'alpha');
$sortfield = GETPOST("sortfield",'alpha'); $sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha'); $sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST('page','int'); $page = GETPOST('page','int');
@ -823,7 +824,7 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
{ {
if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha'); if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha');
} }
$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
// Purge search criteria // Purge search criteria
if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
@ -870,9 +871,12 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print "\n".'<table class="tagtable liste">'."\n"; print "\n".'<table class="tagtable liste">'."\n";
$param="socid=".$object->id; $param="socid=".urlencode($object->id);
if ($search_status != '') $param.='&amp;search_status='.$search_status; if ($search_status != '') $param.='&search_status='.urlencode($search_status);
if ($search_name != '') $param.='&amp;search_name='.urlencode($search_name); if ($search_name != '') $param.='&search_name='.urlencode($search_name);
if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
// Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
$sql = "SELECT t.rowid, t.lastname, t.firstname, t.fk_pays as country_id, t.civility, t.poste, t.phone as phone_pro, t.phone_mobile, t.phone_perso, t.fax, t.email, t.skype, t.statut, t.photo,"; $sql = "SELECT t.rowid, t.lastname, t.firstname, t.fk_pays as country_id, t.civility, t.poste, t.phone as phone_pro, t.phone_mobile, t.phone_perso, t.fax, t.email, t.skype, t.statut, t.photo,";
$sql .= " t.civility as civility_id, t.address, t.zip, t.town"; $sql .= " t.civility as civility_id, t.address, t.zip, t.town";
@ -880,7 +884,9 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (t.rowid = ef.fk_object)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (t.rowid = ef.fk_object)";
$sql .= " WHERE t.fk_soc = ".$object->id; $sql .= " WHERE t.fk_soc = ".$object->id;
if ($search_status!='' && $search_status != '-1') $sql .= " AND t.statut = ".$db->escape($search_status); if ($search_status!='' && $search_status != '-1') $sql .= " AND t.statut = ".$db->escape($search_status);
if ($search_name) $sql .= " AND (t.lastname LIKE '%".$db->escape($search_name)."%' OR t.firstname LIKE '%".$db->escape($search_name)."%')"; if ($search_name) $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name);
// Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
if ($sortfield == "t.name") $sql.=" ORDER BY t.lastname $sortorder, t.firstname $sortorder"; if ($sortfield == "t.name") $sql.=" ORDER BY t.lastname $sortorder, t.firstname $sortorder";
else $sql.= " ORDER BY $sortfield $sortorder"; else $sql.= " ORDER BY $sortfield $sortorder";
@ -1044,7 +1050,7 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
// Edit // Edit
if ($user->rights->societe->contact->creer) if ($user->rights->societe->contact->creer)
{ {
print '<a href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&amp;id='.$obj->rowid.'&amp;backtopage='.urlencode($backtopage).'">'; print '<a href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&id='.$obj->rowid.'&backtopage='.urlencode($backtopage).'">';
print img_edit(); print img_edit();
print '</a>'; print '</a>';
} }

View File

@ -311,7 +311,7 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->categorie->enabled', __HANDLER__, 'left', 3804__+MAX_llx_menu__, 'project', 'cat', 7__+MAX_llx_menu__, '/categories/index.php?leftmenu=cat&amp;type=6', 'Categories', 0, 'categories', '$user->rights->categorie->lire', '', 2, 4, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->categorie->enabled', __HANDLER__, 'left', 3804__+MAX_llx_menu__, 'project', 'cat', 7__+MAX_llx_menu__, '/categories/index.php?leftmenu=cat&amp;type=6', 'Categories', 0, 'categories', '$user->rights->categorie->lire', '', 2, 4, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->categorie->enabled', __HANDLER__, 'left', 3805__+MAX_llx_menu__, 'project', '', 3804__+MAX_llx_menu__, '/categories/card.php?action=create&amp;type=6', 'NewCategory', 1, 'categories', '$user->rights->categorie->creer', '', 2, 0, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->categorie->enabled', __HANDLER__, 'left', 3805__+MAX_llx_menu__, 'project', '', 3804__+MAX_llx_menu__, '/categories/card.php?action=create&amp;type=6', 'NewCategory', 1, 'categories', '$user->rights->categorie->creer', '', 2, 0, __ENTITY__);
-- Tools -- Tools
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '', __HANDLER__, 'left', 3900__+MAX_llx_menu__, 'tools', 'email_templates', 8__+MAX_llx_menu__, '/admin/mails_templates.php?leftmenu=email_templates', 'EMailTemplates', 0, '', '', '', 0, 0, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', 'empty($user->socid)', __HANDLER__, 'left', 3900__+MAX_llx_menu__, 'tools', 'email_templates', 8__+MAX_llx_menu__, '/admin/mails_templates.php?leftmenu=email_templates', 'EMailTemplates', 0, '', '', '', 0, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->mailing->enabled', __HANDLER__, 'left', 3910__+MAX_llx_menu__, 'tools', 'mailing', 8__+MAX_llx_menu__, '/comm/mailing/index.php?leftmenu=mailing', 'EMailings', 0, 'mails', '$user->rights->mailing->lire', '', 0, 0, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->mailing->enabled', __HANDLER__, 'left', 3910__+MAX_llx_menu__, 'tools', 'mailing', 8__+MAX_llx_menu__, '/comm/mailing/index.php?leftmenu=mailing', 'EMailings', 0, 'mails', '$user->rights->mailing->lire', '', 0, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->mailing->enabled', __HANDLER__, 'left', 3911__+MAX_llx_menu__, 'tools', '', 3910__+MAX_llx_menu__, '/comm/mailing/card.php?leftmenu=mailing&amp;action=create', 'NewMailing', 1, 'mails', '$user->rights->mailing->creer', '', 0, 0, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->mailing->enabled', __HANDLER__, 'left', 3911__+MAX_llx_menu__, 'tools', '', 3910__+MAX_llx_menu__, '/comm/mailing/card.php?leftmenu=mailing&amp;action=create', 'NewMailing', 1, 'mails', '$user->rights->mailing->creer', '', 0, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->mailing->enabled', __HANDLER__, 'left', 3912__+MAX_llx_menu__, 'tools', '', 3910__+MAX_llx_menu__, '/comm/mailing/list.php?leftmenu=mailing', 'List', 1, 'mails', '$user->rights->mailing->lire', '', 0, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->mailing->enabled', __HANDLER__, 'left', 3912__+MAX_llx_menu__, 'tools', '', 3910__+MAX_llx_menu__, '/comm/mailing/list.php?leftmenu=mailing', 'List', 1, 'mails', '$user->rights->mailing->lire', '', 0, 1, __ENTITY__);

View File

@ -1418,8 +1418,11 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
*/ */
if ($mainmenu == 'tools') if ($mainmenu == 'tools')
{ {
$langs->load("mails"); if (empty($user->socid)) // limit to internal users
$newmenu->add("/admin/mails_templates.php?leftmenu=email_templates", $langs->trans("EMailTemplates"), 0, 1, '', $mainmenu, 'email_templates'); {
$langs->load("mails");
$newmenu->add("/admin/mails_templates.php?leftmenu=email_templates", $langs->trans("EMailTemplates"), 0, 1, '', $mainmenu, 'email_templates');
}
if (! empty($conf->mailing->enabled)) if (! empty($conf->mailing->enabled))
{ {

View File

@ -1313,6 +1313,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
{ {
foreach ($this->cronjobs as $key => $value) foreach ($this->cronjobs as $key => $value)
{ {
$entity = isset($this->cronjobs[$key]['entity'])?$this->cronjobs[$key]['entity']:$conf->entity;
$label = isset($this->cronjobs[$key]['label'])?$this->cronjobs[$key]['label']:''; $label = isset($this->cronjobs[$key]['label'])?$this->cronjobs[$key]['label']:'';
$jobtype = isset($this->cronjobs[$key]['jobtype'])?$this->cronjobs[$key]['jobtype']:''; $jobtype = isset($this->cronjobs[$key]['jobtype'])?$this->cronjobs[$key]['jobtype']:'';
$class = isset($this->cronjobs[$key]['class'])?$this->cronjobs[$key]['class']:''; $class = isset($this->cronjobs[$key]['class'])?$this->cronjobs[$key]['class']:'';
@ -1334,7 +1335,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
if ($objectname) $sql.= " AND objectname = '".$this->db->escape($objectname)."'"; if ($objectname) $sql.= " AND objectname = '".$this->db->escape($objectname)."'";
if ($method) $sql.= " AND methodename = '".$this->db->escape($method)."'"; if ($method) $sql.= " AND methodename = '".$this->db->escape($method)."'";
if ($command) $sql.= " AND command = '".$this->db->escape($command)."'"; if ($command) $sql.= " AND command = '".$this->db->escape($command)."'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$entity; // Must be exact entity
$now=dol_now(); $now=dol_now();
@ -1371,7 +1372,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
if(is_int($unitfrequency)){ $sql.= "'".$this->db->escape($unitfrequency)."', "; } if(is_int($unitfrequency)){ $sql.= "'".$this->db->escape($unitfrequency)."', "; }
if(is_int($priority)) {$sql.= "'".$this->db->escape($priority)."', ";} if(is_int($priority)) {$sql.= "'".$this->db->escape($priority)."', ";}
if(is_int($status)){ $sql.= "'".$this->db->escape($status)."', "; } if(is_int($status)){ $sql.= "'".$this->db->escape($status)."', "; }
$sql.= $conf->entity.","; $sql.= $entity.",";
$sql.= "'".$this->db->escape($test)."'"; $sql.= "'".$this->db->escape($test)."'";
$sql.= ")"; $sql.= ")";

View File

@ -97,9 +97,9 @@ class modCron extends DolibarrModules
// Cronjobs // Cronjobs
$this->cronjobs = array( $this->cronjobs = array(
0=>array('label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>2, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>50, 'status'=>1, 'test'=>true), 0=>array('entity'=>0, 'label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>2, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>50, 'status'=>1, 'test'=>true),
1=>array('label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'none,auto,1,auto,10', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>90, 'status'=>0, 'test'=>in_array($db->type, array('mysql', 'mysqli'))), 1=>array('entity'=>0, 'label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'none,auto,1,auto,10', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>90, 'status'=>0, 'test'=>in_array($db->type, array('mysql', 'mysqli'))),
// 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24) // 1=>array('entity'=>0, 'label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
); );
// Permissions // Permissions

View File

@ -614,6 +614,22 @@ else
print $langs->trans($object->note); print $langs->trans($object->note);
print "</td></tr>"; print "</td></tr>";
if (! empty($conf->multicompany->enabled))
{
print '<tr><td>';
print $langs->trans('Entity')."</td><td>";
if (! $object->entity)
{
print $langs->trans("AllEntities");
}
else
{
$mc->getInfo($obj->entity);
print $mc->label;
}
print "</td></tr>";
}
print '</table>'; print '</table>';
print '</div>'; print '</div>';

View File

@ -34,6 +34,7 @@ class Cronjob extends CommonObject
public $table_element='cronjob'; //!< Name of table without prefix where object is stored public $table_element='cronjob'; //!< Name of table without prefix where object is stored
public $picto = 'cron'; public $picto = 'cron';
public $entity;
public $jobtype; public $jobtype;
public $tms=''; public $tms='';
public $datec=''; public $datec='';
@ -153,7 +154,7 @@ class Cronjob extends CommonObject
// Insert request // Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob(";
$sql.= "entity,";
$sql.= "datec,"; $sql.= "datec,";
$sql.= "jobtype,"; $sql.= "jobtype,";
$sql.= "label,"; $sql.= "label,";
@ -183,6 +184,7 @@ class Cronjob extends CommonObject
$sql.= "libname,"; $sql.= "libname,";
$sql.= "test"; $sql.= "test";
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= " ".(! isset($this->entity)?$conf->entity:$this->db->escape($this->entity)).",";
$sql.= " '".$this->db->idate($now)."',"; $sql.= " '".$this->db->idate($now)."',";
$sql.= " ".(! isset($this->jobtype)?'NULL':"'".$this->db->escape($this->jobtype)."'").","; $sql.= " ".(! isset($this->jobtype)?'NULL':"'".$this->db->escape($this->jobtype)."'").",";
$sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").","; $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").",";
@ -265,8 +267,8 @@ class Cronjob extends CommonObject
function fetch($id) function fetch($id)
{ {
$sql = "SELECT"; $sql = "SELECT";
$sql.= " t.rowid,"; $sql.= " t.rowid,";
$sql.= " t.entity,";
$sql.= " t.tms,"; $sql.= " t.tms,";
$sql.= " t.datec,"; $sql.= " t.datec,";
$sql.= " t.jobtype,"; $sql.= " t.jobtype,";
@ -310,7 +312,7 @@ class Cronjob extends CommonObject
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->ref = $obj->rowid; $this->ref = $obj->rowid;
$this->entity = $obj->entity;
$this->tms = $this->db->jdate($obj->tms); $this->tms = $this->db->jdate($obj->tms);
$this->datec = $this->db->jdate($obj->datec); $this->datec = $this->db->jdate($obj->datec);
$this->label = $obj->label; $this->label = $obj->label;
@ -417,7 +419,7 @@ class Cronjob extends CommonObject
} }
} }
$sql.= " ORDER BY $sortfield $sortorder "; $sql.= $this->db->order($sortfield,$sortorder);
if (!empty($limit) && !empty($offset)) { if (!empty($limit) && !empty($offset)) {
$sql.= $this->db->plimit($limit + 1,$offset); $sql.= $this->db->plimit($limit + 1,$offset);
} }
@ -445,7 +447,6 @@ class Cronjob extends CommonObject
$line->id = $obj->rowid; $line->id = $obj->rowid;
$line->ref = $obj->rowid; $line->ref = $obj->rowid;
$line->entity = $obj->entity; $line->entity = $obj->entity;
$line->tms = $this->db->jdate($obj->tms); $line->tms = $this->db->jdate($obj->tms);
$line->datec = $this->db->jdate($obj->datec); $line->datec = $this->db->jdate($obj->datec);
@ -575,7 +576,7 @@ class Cronjob extends CommonObject
// Update request // Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET";
$sql.= " entity=".(isset($this->entity)?$this->db->escape($this->entity):$conf->entity).",";
$sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").","; $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
$sql.= " jobtype=".(isset($this->jobtype)?"'".$this->db->escape($this->jobtype)."'":"null").","; $sql.= " jobtype=".(isset($this->jobtype)?"'".$this->db->escape($this->jobtype)."'":"null").",";
$sql.= " command=".(isset($this->command)?"'".$this->db->escape($this->command)."'":"null").","; $sql.= " command=".(isset($this->command)?"'".$this->db->escape($this->command)."'":"null").",";
@ -773,7 +774,7 @@ class Cronjob extends CommonObject
{ {
$this->id=0; $this->id=0;
$this->ref=0; $this->ref=0;
$this->entity=0;
$this->tms=''; $this->tms='';
$this->datec=''; $this->datec='';
$this->label=''; $this->label='';
@ -930,6 +931,16 @@ class Cronjob extends CommonObject
return -1; return -1;
} }
// Force the environment of running to the environment declared for job, so jobs launched from command line will run into correct environment
// When job is ran from GUI, the environment should already be same, except if job has entity 0 (visible into all environments)
if ($conf->entity != $this->entity && $this->entity > 0)
{
dol_syslog("We try to run a job in entity ".$this->entity." when we are in entity ".$conf->entity, LOG_WARNING);
}
$savcurrententity = $conf->entity;
$conf->entity = $this->entity;
dol_syslog(get_class($this)."::run_jobs entity for running job is ".$conf->entity);
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$user=new User($this->db); $user=new User($this->db);
$result=$user->fetch('',$userlogin); $result=$user->fetch('',$userlogin);
@ -937,6 +948,7 @@ class Cronjob extends CommonObject
{ {
$this->error="User Error:".$user->error; $this->error="User Error:".$user->error;
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
return -1; return -1;
} }
else else
@ -945,6 +957,7 @@ class Cronjob extends CommonObject
{ {
$this->error=" User user login:".$userlogin." do not exists"; $this->error=" User user login:".$userlogin." do not exists";
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
return -1; return -1;
} }
} }
@ -976,6 +989,7 @@ class Cronjob extends CommonObject
$result = $this->update($user); // This include begin/commit $result = $this->update($user); // This include begin/commit
if ($result<0) { if ($result<0) {
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
return -1; return -1;
} }
@ -1073,6 +1087,7 @@ class Cronjob extends CommonObject
{ {
$this->error = $langs->trans('CronCannotLoadLib') . ': ' . $libpath; $this->error = $langs->trans('CronCannotLoadLib') . ': ' . $libpath;
dol_syslog(get_class($this) . "::run_jobs " . $this->error, LOG_ERR); dol_syslog(get_class($this) . "::run_jobs " . $this->error, LOG_ERR);
$conf->entity = $savcurrententity;
return -1; return -1;
} }
// Load langs // Load langs
@ -1080,6 +1095,7 @@ class Cronjob extends CommonObject
if ($result<0) if ($result<0)
{ {
dol_syslog(get_class($this) . "::run_jobs Cannot load module langs" . $langs->error, LOG_ERR); dol_syslog(get_class($this) . "::run_jobs Cannot load module langs" . $langs->error, LOG_ERR);
$conf->entity = $savcurrententity;
return -1; return -1;
} }
dol_syslog(get_class($this) . "::run_jobs " . $this->libname . "::" . $this->methodename."(" . $this->params . ");", LOG_DEBUG); dol_syslog(get_class($this) . "::run_jobs " . $this->libname . "::" . $this->methodename."(" . $this->params . ");", LOG_DEBUG);
@ -1142,13 +1158,12 @@ class Cronjob extends CommonObject
if ($result < 0) if ($result < 0)
{ {
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
return -1; return -1;
} }
else
{
return $error?-1:1;
}
$conf->entity = $savcurrententity;
return $error?-1:1;
} }

View File

@ -187,7 +187,7 @@ $sql.= " t.nbrun,";
$sql.= " t.libname,"; $sql.= " t.libname,";
$sql.= " t.test"; $sql.= " t.test";
$sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t"; $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t";
$sql.= " WHERE 1 = 1"; $sql.= " WHERE entity IN (0,".$conf->entity.")";
if ($status >= 0 && $status < 2) $sql.= " AND t.status = ".(empty($status)?'0':'1'); if ($status >= 0 && $status < 2) $sql.= " AND t.status = ".(empty($status)?'0':'1');
if ($status == 2) $sql.= " AND t.status = 2"; if ($status == 2) $sql.= " AND t.status = 2";
//Manage filter //Manage filter

View File

@ -77,6 +77,7 @@ $duration_unit = GETPOST('duration_unit');
if (! empty($user->societe_id)) $socid=$user->societe_id; if (! empty($user->societe_id)) $socid=$user->societe_id;
$object = new Product($db); $object = new Product($db);
$object->type = $type; // so test later to fill $usercancxxx is correct
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
// fetch optionals attributes and labels // fetch optionals attributes and labels

View File

@ -2582,21 +2582,16 @@ class Societe extends CommonObject
if (! empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) if (! empty($conf->global->SOCIETE_CODECOMPTA_ADDON))
{ {
$file=''; $res=false;
$dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
foreach ($dirsociete as $dirroot) foreach ($dirsociete as $dirroot)
{ {
if (file_exists(DOL_DOCUMENT_ROOT.'/'.$dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.".php")) $res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php');
{ if ($res) break;
$file=$dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.".php";
break;
}
} }
if (! empty($file)) if ($res)
{ {
dol_include_once($file);
$classname = $conf->global->SOCIETE_CODECOMPTA_ADDON; $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON;
$mod = new $classname; $mod = new $classname;

View File

@ -85,7 +85,7 @@ if ($key != $conf->global->CRON_KEY)
// If param userlogin is reserved word 'firstadmin' // If param userlogin is reserved word 'firstadmin'
if ($userlogin == 'firstadmin') if ($userlogin == 'firstadmin')
{ {
$sql='SELECT login from '.MAIN_DB_PREFIX.'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1'; $sql='SELECT login, entity from '.MAIN_DB_PREFIX.'user WHERE admin = 1 and statut = 1 ORDER BY entity LIMIT 1';
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
@ -93,7 +93,7 @@ if ($userlogin == 'firstadmin')
if ($obj) if ($obj)
{ {
$userlogin = $obj->login; $userlogin = $obj->login;
echo "First admin user found is login '".$userlogin."'\n"; echo "First admin user found is login '".$userlogin."', entity ".$obj->entity."\n";
} }
} }
else dol_print_error($db); else dol_print_error($db);
@ -132,7 +132,7 @@ if (! empty($id)) {
$filter['t.rowid']=$id; $filter['t.rowid']=$id;
} }
$result = $object->fetch_all('DESC','t.rowid', 0, 0, 1, $filter, 0); $result = $object->fetch_all('ASC,ASC,ASC','t.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
if ($result<0) if ($result<0)
{ {
echo "Error: ".$object->error; echo "Error: ".$object->error;
@ -159,8 +159,8 @@ if(is_array($qualifiedjobs) && (count($qualifiedjobs)>0))
// Loop over job // Loop over job
foreach($qualifiedjobs as $line) foreach($qualifiedjobs as $line)
{ {
dol_syslog("cron_run_jobs.php cronjobid: ".$line->id, LOG_DEBUG); dol_syslog("cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label, LOG_DEBUG);
echo "cron_run_jobs.php cronjobid: ".$line->id."\n"; echo "cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label."\n";
//If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database //If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database
if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now)) if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now))