FIX We should be able to insert data with value '0' into const

This commit is contained in:
Laurent Destailleur 2017-06-30 11:08:40 +02:00
parent 4c1c361a15
commit ea504a0516

View File

@ -50,13 +50,13 @@ class DolibarrModules // Can not be abstract, because we need to insta
* @since 4.0.0 * @since 4.0.0
*/ */
public $editor_name; public $editor_name;
/** /**
* @var string URL of module at publisher site * @var string URL of module at publisher site
* @since 4.0.0 * @since 4.0.0
*/ */
public $editor_url; public $editor_url;
/** /**
* @var string Family * @var string Family
* @see familyinfo * @see familyinfo
@ -80,13 +80,13 @@ class DolibarrModules // Can not be abstract, because we need to insta
* *
*/ */
public $familyinfo; public $familyinfo;
/** /**
* @var int Module position * @var int Module position
* @since 3.9.0 * @since 3.9.0
*/ */
public $module_position=500; public $module_position=500;
/** /**
* @var string Module name * @var string Module name
* *
@ -214,7 +214,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
* HTML content supported. * HTML content supported.
*/ */
public $descriptionlong; public $descriptionlong;
/** /**
* @var string[] Module language files * @var string[] Module language files
*/ */
@ -254,7 +254,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
* @var bool Module is enabled globally (Multicompany support) * @var bool Module is enabled globally (Multicompany support)
*/ */
public $core_enabled; public $core_enabled;
/** /**
* @var string Relative path to module style sheet * @var string Relative path to module style sheet
* @deprecated * @deprecated
@ -573,9 +573,9 @@ class DolibarrModules // Can not be abstract, because we need to insta
{ {
global $langs; global $langs;
$langs->load("admin"); $langs->load("admin");
if (empty($this->descriptionlong)) return ''; if (empty($this->descriptionlong)) return '';
// If module description translation does not exist using its unique id, we can use its name to find translation // If module description translation does not exist using its unique id, we can use its name to find translation
if (is_array($this->langfiles)) if (is_array($this->langfiles))
{ {
@ -586,7 +586,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
} }
return $langs->trans($this->descriptionlong); return $langs->trans($this->descriptionlong);
} }
/** /**
* Gives the publisher name * Gives the publisher name
* *
@ -596,7 +596,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
{ {
return $this->editor_name; return $this->editor_name;
} }
/** /**
* Gives the publisher url * Gives the publisher url
* *
@ -606,7 +606,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
{ {
return $this->editor_url; return $this->editor_url;
} }
/** /**
* Gives module version (translated if param $translated is on) * Gives module version (translated if param $translated is on)
* For 'experimental' modules, gives 'experimental' translation * For 'experimental' modules, gives 'experimental' translation
@ -709,7 +709,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
} }
} }
/** /**
* Gives the last date of activation * Gives the last date of activation
* *
@ -718,11 +718,11 @@ class DolibarrModules // Can not be abstract, because we need to insta
function getLastActivationDate() function getLastActivationDate()
{ {
global $conf; global $conf;
$sql = "SELECT tms FROM ".MAIN_DB_PREFIX."const"; $sql = "SELECT tms FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."'"; $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."'";
$sql.= " AND entity IN (0, ".$conf->entity.")"; $sql.= " AND entity IN (0, ".$conf->entity.")";
dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG); dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) $err++; if (! $resql) $err++;
@ -731,11 +731,11 @@ class DolibarrModules // Can not be abstract, because we need to insta
$obj=$this->db->fetch_object($resql); $obj=$this->db->fetch_object($resql);
if ($obj) return $this->db->jdate($obj->tms); if ($obj) return $this->db->jdate($obj->tms);
} }
return ''; return '';
} }
/** /**
* Insert constants for module activation * Insert constants for module activation
* *
@ -836,7 +836,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$files[] = $file; $files[] = $file;
} }
sort($files); sort($files);
foreach ($files as $file) foreach ($files as $file)
{ {
if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data') if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data')
{ {
@ -854,7 +854,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$files[] = $file; $files[] = $file;
} }
sort($files); sort($files);
foreach ($files as $file) foreach ($files as $file)
{ {
if (preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data') if (preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data')
{ {
@ -872,7 +872,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$files[] = $file; $files[] = $file;
} }
sort($files); sort($files);
foreach ($files as $file) foreach ($files as $file)
{ {
if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'data') if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'data')
{ {
@ -890,7 +890,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$files[] = $file; $files[] = $file;
} }
sort($files); sort($files);
foreach ($files as $file) foreach ($files as $file)
{ {
if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,6) == 'update') if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,6) == 'update')
{ {
@ -1030,19 +1030,19 @@ class DolibarrModules // Can not be abstract, because we need to insta
//$titre = $this->boxes[$key][0]; //$titre = $this->boxes[$key][0];
$file = $this->boxes[$key]['file']; $file = $this->boxes[$key]['file'];
//$note = $this->boxes[$key][2]; //$note = $this->boxes[$key][2];
// TODO If the box is also included by another module and the other module is still on, we should not remove it. // TODO If the box is also included by another module and the other module is still on, we should not remove it.
// For the moment, we manage this with hard coded exception // For the moment, we manage this with hard coded exception
//print "Remove box ".$file.'<br>'; //print "Remove box ".$file.'<br>';
if ($file == 'box_graph_product_distribution.php') if ($file == 'box_graph_product_distribution.php')
{ {
if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled)) if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled))
{ {
dol_syslog("We discard disabling of module ".$file." because another module still active require it."); dol_syslog("We discard disabling of module ".$file." because another module still active require it.");
continue; continue;
} }
} }
if (empty($file)) $file = isset($this->boxes[$key][1])?$this->boxes[$key][1]:''; // For backward compatibility if (empty($file)) $file = isset($this->boxes[$key][1])?$this->boxes[$key][1]:''; // For backward compatibility
if ($this->db->type == 'sqlite3') { if ($this->db->type == 'sqlite3') {
@ -1117,7 +1117,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$status = isset($this->cronjobs[$key]['status'])?$this->cronjobs[$key]['status']:''; $status = isset($this->cronjobs[$key]['status'])?$this->cronjobs[$key]['status']:'';
$priority = isset($this->cronjobs[$key]['priority'])?$this->cronjobs[$key]['priority']:''; $priority = isset($this->cronjobs[$key]['priority'])?$this->cronjobs[$key]['priority']:'';
$test = isset($this->cronjobs[$key]['test'])?$this->cronjobs[$key]['test']:''; // Line must be visible $test = isset($this->cronjobs[$key]['test'])?$this->cronjobs[$key]['test']:''; // Line must be visible
// Search if boxes def already present // Search if boxes def already present
$sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."cronjob"; $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."cronjob";
$sql.= " WHERE module_name = '".$this->db->escape($this->rights_class)."'"; $sql.= " WHERE module_name = '".$this->db->escape($this->rights_class)."'";
@ -1329,11 +1329,11 @@ class DolibarrModules // Can not be abstract, because we need to insta
// Clean // Clean
if (empty($visible)) $visible='0'; if (empty($visible)) $visible='0';
if (empty($val)) $val=''; if (empty($val) && $val != '0') $val='';
$sql = "SELECT count(*)"; $sql = "SELECT count(*)";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name')." = '".$name."'"; $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($name)."'";
$sql.= " AND entity = ".$entity; $sql.= " AND entity = ".$entity;
$result=$this->db->query($sql); $result=$this->db->query($sql);
@ -1347,7 +1347,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
$sql.= " VALUES ("; $sql.= " VALUES (";
$sql.= $this->db->encrypt($name,1); $sql.= $this->db->encrypt($name,1);
$sql.= ",'".$type."'"; $sql.= ",'".$type."'";
$sql.= ",".($val?$this->db->encrypt($val,1):"''"); $sql.= ",".(($val != '')?$this->db->encrypt($val,1):"''");
$sql.= ",".($note?"'".$this->db->escape($note)."'":"null"); $sql.= ",".($note?"'".$this->db->escape($note)."'":"null");
$sql.= ",'".$visible."'"; $sql.= ",'".$visible."'";
$sql.= ",".$entity; $sql.= ",".$entity;
@ -1552,7 +1552,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
/** /**
* Removes access rights * Removes access rights
* *
* @return int Error count (0 if OK) * @return int Error count (0 if OK)
*/ */
function delete_permissions() function delete_permissions()
@ -1585,7 +1585,7 @@ class DolibarrModules // Can not be abstract, because we need to insta
global $user; global $user;
if (! is_array($this->menu) || empty($this->menu)) return 0; if (! is_array($this->menu) || empty($this->menu)) return 0;
require_once DOL_DOCUMENT_ROOT . '/core/class/menubase.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/menubase.class.php';
$err=0; $err=0;