diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index 583aea55739..0cf4aca1e0f 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -106,7 +106,7 @@ class AdherentStats extends Stats public function getNbByMonth($year, $format = 0) { $sql = "SELECT date_format(p.dateadh,'%m') as dm, count(*)"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE ".dolSqlDateFilter('p.dateadh', 0, 0, (int) $year, 1); $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -123,7 +123,7 @@ class AdherentStats extends Stats public function getNbByYear() { $sql = "SELECT date_format(p.dateadh,'%Y') as dm, count(*)"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE ".$this->where; $sql .= " GROUP BY dm"; $sql .= $this->db->order('dm', 'DESC'); @@ -140,8 +140,8 @@ class AdherentStats extends Stats */ public function getAmountByMonth($year, $format = 0) { - $sql = "SELECT date_format(p.dateadh,'%m') as dm, sum(p.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(p.dateadh,'%m') as dm, sum(p.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE ".dolSqlDateFilter('p.dateadh', 0, 0, (int) $year, 1); $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -158,8 +158,8 @@ class AdherentStats extends Stats */ public function getAverageByMonth($year) { - $sql = "SELECT date_format(p.dateadh,'%m') as dm, avg(p.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(p.dateadh,'%m') as dm, avg(p.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE ".dolSqlDateFilter('p.dateadh', 0, 0, (int) $year, 1); $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -176,8 +176,8 @@ class AdherentStats extends Stats */ public function getAllByYear() { - $sql = "SELECT date_format(p.dateadh,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(p.dateadh,'%Y') as year, count(*) as nb, sum(".$this->db->sanitize($this->field).") as total, avg(".$this->db->sanitize($this->field).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE ".$this->where; $sql .= " GROUP BY year"; $sql .= $this->db->order('year', 'DESC'); diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index 78e4035d67c..a24bfe6c2b0 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -148,8 +148,8 @@ class PropaleStats extends Stats { global $user; - $sql = "SELECT date_format(".$this->field_date.",'%m') as dm, COUNT(*) as nb"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(".$this->db->sanitize($this->field_date).", '%m') as dm, COUNT(*) as nb"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -172,8 +172,8 @@ class PropaleStats extends Stats { global $user; - $sql = "SELECT date_format(".$this->field_date.",'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(".$this->db->sanitize($this->field_date).", '%Y') as dm, COUNT(*) as nb, SUM(c.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -196,8 +196,8 @@ class PropaleStats extends Stats { global $user; - $sql = "SELECT date_format(".$this->field_date.",'%m') as dm, SUM(p.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(".$this->db->sanitize($this->field_date).", '%m') as dm, SUM(p.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -221,8 +221,8 @@ class PropaleStats extends Stats { global $user; - $sql = "SELECT date_format(".$this->field_date.",'%m') as dm, AVG(p.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(".$this->db->sanitize($this->field_date).", '%m') as dm, AVG(p.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -244,8 +244,8 @@ class PropaleStats extends Stats { global $user; - $sql = "SELECT date_format(".$this->field_date.",'%Y') as year, COUNT(*) as nb, SUM(".$this->field.") as total, AVG(".$this->field.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(".$this->db->sanitize($this->field_date).", '%Y') as year, COUNT(*) as nb, SUM(".$this->db->sanitize($this->field).") as total, AVG(".$this->db->sanitize($this->field).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -269,8 +269,8 @@ class PropaleStats extends Stats { global $user; - $sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->db->sanitize($this->field_line).") as total, AVG(tl.".$this->db->sanitize($this->field_line).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " INNER JOIN ".$this->db->sanitize($this->from_line, 0, 0, 1)." ON p.rowid = tl.fk_propal"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."product as product ON tl.fk_product = product.rowid"; if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { diff --git a/htdocs/commande/class/commandestats.class.php b/htdocs/commande/class/commandestats.class.php index db23b29f624..8c4db32ccb8 100644 --- a/htdocs/commande/class/commandestats.class.php +++ b/htdocs/commande/class/commandestats.class.php @@ -161,8 +161,8 @@ class CommandeStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_commande,'%m') as dm, COUNT(*) as nb"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_commande, '%m') as dm, COUNT(*) as nb"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -186,8 +186,8 @@ class CommandeStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_commande,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_commande, '%Y') as dm, COUNT(*) as nb, SUM(c.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -210,8 +210,8 @@ class CommandeStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_commande,'%m') as dm, SUM(c.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_commande, '%m') as dm, SUM(c.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -235,8 +235,8 @@ class CommandeStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_commande,'%m') as dm, AVG(c.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_commande, '%m') as dm, AVG(c.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -258,8 +258,8 @@ class CommandeStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_commande,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_commande, '%Y') as year, COUNT(*) as nb, SUM(c.".$this->db->sanitize($this->field).") as total, AVG(".$this->db->sanitize($this->field).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -282,9 +282,9 @@ class CommandeStats extends Stats { global $user; - $sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); - $sql .= " INNER JOIN ".$this->db->sanitize($this->from_line, 0, 0, 1)." ON c.rowid = tl.fk_commande"; + $sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->db->sanitize($this->field_line).") as total, AVG(tl.".$this->db->sanitize($this->field_line).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); + $sql .= " INNER JOIN ".$this->db->sanitize($this->from_line, 0, 1, 1)." ON c.rowid = tl.fk_commande"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."product as product ON tl.fk_product = product.rowid"; if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); diff --git a/htdocs/compta/deplacement/class/deplacementstats.class.php b/htdocs/compta/deplacement/class/deplacementstats.class.php index 81db6d25d8e..0d6f64e875a 100644 --- a/htdocs/compta/deplacement/class/deplacementstats.class.php +++ b/htdocs/compta/deplacement/class/deplacementstats.class.php @@ -99,7 +99,7 @@ class DeplacementStats extends Stats public function getNbByYear() { $sql = "SELECT YEAR(dated) as dm, count(*)"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " GROUP BY dm DESC"; $sql .= " WHERE ".$this->where; @@ -117,7 +117,7 @@ class DeplacementStats extends Stats public function getNbByMonth($year, $format = 0) { $sql = "SELECT MONTH(dated) as dm, count(*)"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE YEAR(dated) = ".((int) $year); $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -138,8 +138,8 @@ class DeplacementStats extends Stats */ public function getAmountByMonth($year, $format = 0) { - $sql = "SELECT date_format(dated,'%m') as dm, sum(".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(dated,'%m') as dm, sum(".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE date_format(dated,'%Y') = '".$this->db->escape((string) $year)."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -158,8 +158,8 @@ class DeplacementStats extends Stats */ public function getAverageByMonth($year) { - $sql = "SELECT date_format(dated,'%m') as dm, avg(".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(dated,'%m') as dm, avg(".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE date_format(dated,'%Y') = '".$this->db->escape((string) $year)."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -175,8 +175,8 @@ class DeplacementStats extends Stats */ public function getAllByYear() { - $sql = "SELECT date_format(dated,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(dated,'%Y') as year, count(*) as nb, sum(".$this->db->sanitize($this->field).") as total, avg(".$this->db->sanitize($this->field).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE ".$this->where; $sql .= " GROUP BY year"; $sql .= $this->db->order('year', 'DESC'); diff --git a/htdocs/compta/facture/class/facturestats.class.php b/htdocs/compta/facture/class/facturestats.class.php index 38c360fb0a3..b2b1135a6ea 100644 --- a/htdocs/compta/facture/class/facturestats.class.php +++ b/htdocs/compta/facture/class/facturestats.class.php @@ -79,8 +79,6 @@ class FactureStats extends Stats */ public function __construct(DoliDB $db, $socid, $mode, $userid = 0, $typentid = 0, $categid = 0) { - global $user, $conf; - $this->db = $db; $this->socid = ($socid > 0 ? $socid : 0); $this->userid = $userid; @@ -152,7 +150,8 @@ class FactureStats extends Stats global $user; $sql = "SELECT date_format(f.datef,'%m') as dm, COUNT(*) as nb"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); + if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -177,8 +176,8 @@ class FactureStats extends Stats { global $user; - $sql = "SELECT date_format(f.datef,'%Y') as dm, COUNT(*), SUM(c.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(f.datef,'%Y') as dm, COUNT(*), SUM(c.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -202,8 +201,8 @@ class FactureStats extends Stats { global $user; - $sql = "SELECT date_format(datef,'%m') as dm, SUM(f.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(datef,'%m') as dm, SUM(f.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -228,8 +227,8 @@ class FactureStats extends Stats { global $user; - $sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -251,8 +250,8 @@ class FactureStats extends Stats { global $user; - $sql = "SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(f.".$this->field.") as total, AVG(f.".$this->field.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(f.".$this->db->sanitize($this->field).") as total, AVG(f.".$this->db->sanitize($this->field).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -275,9 +274,9 @@ class FactureStats extends Stats { global $user; - $sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); - $sql .= " INNER JOIN ".$this->db->sanitize($this->from_line, 0, 0, 1)." ON f.rowid = tl.fk_facture"; + $sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->db->sanitize($this->field_line).") as total, AVG(tl.".$this->db->sanitize($this->field_line).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); + $sql .= " INNER JOIN ".$this->db->sanitize($this->from_line, 0, 1, 1)." ON f.rowid = tl.fk_facture"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."product as product ON tl.fk_product = product.rowid"; if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); @@ -304,8 +303,8 @@ class FactureStats extends Stats $endYear = (int) date('Y'); $startYear = $endYear - $numberYears; - $sql = "SELECT date_format(datef,'%Y') as dm, SUM(f.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(datef,'%Y') as dm, SUM(f.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } diff --git a/htdocs/don/class/donstats.class.php b/htdocs/don/class/donstats.class.php index 456593cb4af..c3d32a85f7e 100644 --- a/htdocs/don/class/donstats.class.php +++ b/htdocs/don/class/donstats.class.php @@ -126,7 +126,7 @@ class DonationStats extends Stats public function getNbByMonth($year, $format = 0) { $sql = "SELECT date_format(d.datedon,'%m') as dm, COUNT(*) as nb"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= $this->join; $sql .= " WHERE d.datedon BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql .= " AND ".$this->where; @@ -144,7 +144,7 @@ class DonationStats extends Stats public function getNbByYear() { $sql = "SELECT date_format(d.datedon,'%Y') as dm, COUNT(*) as nb, SUM(d.".$this->db->sanitize($this->field).")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= $this->join; $sql .= " WHERE ".$this->where; $sql .= " GROUP BY dm"; @@ -163,7 +163,7 @@ class DonationStats extends Stats public function getAmountByMonth($year, $format = 0) { $sql = "SELECT date_format(d.datedon,'%m') as dm, sum(d.".$this->db->sanitize($this->field).")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= $this->join; $sql .= " WHERE ".dolSqlDateFilter('d.datedon', 0, 0, (int) $year, 1); $sql .= " AND ".$this->where; @@ -182,7 +182,7 @@ class DonationStats extends Stats public function getAverageByMonth($year) { $sql = "SELECT date_format(d.datedon,'%m') as dm, avg(d.".$this->db->sanitize($this->field).")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= $this->join; $sql .= " WHERE ".dolSqlDateFilter('d.datedon', 0, 0, (int) $year, 1); $sql .= " AND ".$this->where; @@ -199,8 +199,8 @@ class DonationStats extends Stats */ public function getAllByYear() { - $sql = "SELECT date_format(d.datedon,'%Y') as year, COUNT(*) as nb, SUM(d.".$this->db->sanitize($this->field).") as total, AVG(".$this->field.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(d.datedon,'%Y') as year, COUNT(*) as nb, SUM(d.".$this->db->sanitize($this->field).") as total, AVG(".$this->db->sanitize($this->field).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= $this->join; $sql .= " WHERE ".$this->where; $sql .= " GROUP BY year"; diff --git a/htdocs/expedition/class/expeditionstats.class.php b/htdocs/expedition/class/expeditionstats.class.php index be55760089d..9eab90336d6 100644 --- a/htdocs/expedition/class/expeditionstats.class.php +++ b/htdocs/expedition/class/expeditionstats.class.php @@ -119,7 +119,7 @@ class ExpeditionStats extends Stats global $user; $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -142,8 +142,8 @@ class ExpeditionStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -165,8 +165,8 @@ class ExpeditionStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_valid,'%m') as dm, SUM(c.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_valid,'%m') as dm, SUM(c.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -189,8 +189,8 @@ class ExpeditionStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_valid,'%m') as dm, AVG(c.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_valid,'%m') as dm, AVG(c.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -211,8 +211,8 @@ class ExpeditionStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->db->sanitize($this->field).") as total, AVG(".$this->db->sanitize($this->field).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } diff --git a/htdocs/expensereport/class/expensereportstats.class.php b/htdocs/expensereport/class/expensereportstats.class.php index 5290d0a8678..e181f5ef09b 100644 --- a/htdocs/expensereport/class/expensereportstats.class.php +++ b/htdocs/expensereport/class/expensereportstats.class.php @@ -118,8 +118,8 @@ class ExpenseReportStats extends Stats */ public function getNbByYear() { - $sql = "SELECT YEAR(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).") as dm, count(*)"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT YEAR(".$this->db->ifsql("e.".$this->db->sanitize($this->datetouse)." IS NULL", "e.date_create", "e.".$this->db->sanitize($this->datetouse)).") as dm, count(*)"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " GROUP BY dm DESC"; $sql .= " WHERE ".$this->where; @@ -136,8 +136,8 @@ class ExpenseReportStats extends Stats */ public function getNbByMonth($year, $format = 0) { - $sql = "SELECT MONTH(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).") as dm, count(*)"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT MONTH(".$this->db->ifsql("e.".$this->db->sanitize($this->datetouse)." IS NULL", "e.date_create", "e.".$this->db->sanitize($this->datetouse)).") as dm, count(*)"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE YEAR(e.".$this->datetouse.") = ".((int) $year); $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -158,9 +158,9 @@ class ExpenseReportStats extends Stats */ public function getAmountByMonth($year, $format = 0) { - $sql = "SELECT date_format(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).",'%m') as dm, sum(".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); - $sql .= " WHERE date_format(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).",'%Y') = '".$this->db->escape((string) $year)."'"; + $sql = "SELECT date_format(".$this->db->ifsql("e.".$this->db->sanitize($this->datetouse)." IS NULL", "e.date_create", "e.".$this->db->sanitize($this->datetouse)).",'%m') as dm, sum(".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); + $sql .= " WHERE date_format(".$this->db->ifsql("e.".$this->db->sanitize($this->datetouse)." IS NULL", "e.date_create", "e.".$this->db->sanitize($this->datetouse)).",'%Y') = '".$this->db->escape((string) $year)."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; $sql .= $this->db->order('dm', 'DESC'); @@ -178,9 +178,9 @@ class ExpenseReportStats extends Stats */ public function getAverageByMonth($year) { - $sql = "SELECT date_format(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).",'%m') as dm, avg(".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); - $sql .= " WHERE date_format(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).",'%Y') = '".$this->db->escape((string) $year)."'"; + $sql = "SELECT date_format(".$this->db->ifsql("e.".$this->db->sanitize($this->datetouse)." IS NULL", "e.date_create", "e.".$this->db->sanitize($this->datetouse)).",'%m') as dm, avg(".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); + $sql .= " WHERE date_format(".$this->db->ifsql("e.".$this->db->sanitize($this->datetouse)." IS NULL", "e.date_create", "e.".$this->db->sanitize($this->datetouse)).",'%Y') = '".$this->db->escape((string) $year)."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; $sql .= $this->db->order('dm', 'DESC'); @@ -195,8 +195,8 @@ class ExpenseReportStats extends Stats */ public function getAllByYear() { - $sql = "SELECT date_format(".$this->db->ifsql("e.".$this->datetouse." IS NULL", "e.date_create", "e.".$this->datetouse).",'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(".$this->db->ifsql("e.".$this->db->sanitize($this->datetouse)." IS NULL", "e.date_create", "e.".$this->db->sanitize($this->datetouse)).",'%Y') as year, count(*) as nb, sum(".$this->db->sanitize($this->field).") as total, avg(".$this->db->sanitize($this->field).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE ".$this->where; $sql .= " GROUP BY year"; $sql .= $this->db->order('year', 'DESC'); diff --git a/htdocs/fichinter/class/fichinterstats.class.php b/htdocs/fichinter/class/fichinterstats.class.php index 27ac78a4f94..1e38081aa92 100644 --- a/htdocs/fichinter/class/fichinterstats.class.php +++ b/htdocs/fichinter/class/fichinterstats.class.php @@ -112,7 +112,7 @@ class FichinterStats extends Stats global $user; $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -136,7 +136,7 @@ class FichinterStats extends Stats global $user; $sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, 0"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -159,7 +159,7 @@ class FichinterStats extends Stats global $user; $sql = "SELECT date_format(c.date_valid,'%m') as dm, 0"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -183,7 +183,7 @@ class FichinterStats extends Stats global $user; $sql = "SELECT date_format(c.date_valid,'%m') as dm, 0"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -205,7 +205,7 @@ class FichinterStats extends Stats global $user; $sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, 0 as total, 0 as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) { $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } @@ -226,7 +226,9 @@ class FichinterStats extends Stats public function getAllByProduct($year, $limit = 0) { $sql = "SELECT product.ref, COUNT(product.ref) as nb, 0 as total, 0 as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1).", ".$this->db->sanitize($this->from_line, 0, 0, 1).", ".MAIN_DB_PREFIX."product as product"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1).","; + $sql .= " ".$this->db->sanitize($this->from_line, 0, 1, 1).","; + $sql .= " ".MAIN_DB_PREFIX."product as product"; //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " WHERE ".$this->where; $sql .= " AND c.rowid = tl.fk_fichinter AND tl.fk_product = product.rowid"; diff --git a/htdocs/projet/class/projectstats.class.php b/htdocs/projet/class/projectstats.class.php index 0c725f6d667..c54b76caf26 100644 --- a/htdocs/projet/class/projectstats.class.php +++ b/htdocs/projet/class/projectstats.class.php @@ -561,8 +561,8 @@ class ProjectStats extends Stats */ protected function getAverageByMonth($year) { - $sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; diff --git a/htdocs/projet/class/taskstats.class.php b/htdocs/projet/class/taskstats.class.php index 67632d80e8d..4774af6c0f6 100644 --- a/htdocs/projet/class/taskstats.class.php +++ b/htdocs/projet/class/taskstats.class.php @@ -220,8 +220,8 @@ class TaskStats extends Stats */ protected function getAverageByMonth($year) { - $sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; diff --git a/htdocs/reception/class/receptionstats.class.php b/htdocs/reception/class/receptionstats.class.php index d604d1ac2ca..96a509b7314 100644 --- a/htdocs/reception/class/receptionstats.class.php +++ b/htdocs/reception/class/receptionstats.class.php @@ -112,7 +112,7 @@ class ReceptionStats extends Stats global $user; $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } @@ -135,8 +135,8 @@ class ReceptionStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } @@ -158,8 +158,8 @@ class ReceptionStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_valid,'%m') as dm, SUM(c.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_valid,'%m') as dm, SUM(c.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } @@ -182,8 +182,8 @@ class ReceptionStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_valid,'%m') as dm, AVG(c.".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_valid,'%m') as dm, AVG(c.".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } @@ -204,8 +204,8 @@ class ReceptionStats extends Stats { global $user; - $sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->db->sanitize($this->field).") as total, AVG(".$this->db->sanitize($this->field).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); if (!$user->hasRight('societe', 'client', 'voir')) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } diff --git a/htdocs/salaries/class/salariesstats.class.php b/htdocs/salaries/class/salariesstats.class.php index 20a6f975c70..2cbcae0be29 100644 --- a/htdocs/salaries/class/salariesstats.class.php +++ b/htdocs/salaries/class/salariesstats.class.php @@ -87,7 +87,7 @@ class SalariesStats extends Stats public function getNbByYear() { $sql = "SELECT YEAR(dateep) as dm, count(*)"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE ".$this->where; $sql .= " GROUP BY dm DESC"; @@ -105,7 +105,7 @@ class SalariesStats extends Stats public function getNbByMonth($year, $format = 0) { $sql = "SELECT MONTH(dateep) as dm, count(*)"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE YEAR(dateep) = ".((int) $year); $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -126,8 +126,8 @@ class SalariesStats extends Stats */ public function getAmountByMonth($year, $format = 0) { - $sql = "SELECT date_format(dateep,'%m') as dm, sum(".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(dateep,'%m') as dm, sum(".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE date_format(dateep,'%Y') = '".((int) $year)."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -146,8 +146,8 @@ class SalariesStats extends Stats */ public function getAverageByMonth($year) { - $sql = "SELECT date_format(dateep,'%m') as dm, avg(".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(dateep,'%m') as dm, avg(".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE date_format(dateep,'%Y') = '".((int) $year)."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -163,8 +163,8 @@ class SalariesStats extends Stats */ public function getAllByYear() { - $sql = "SELECT date_format(dateep,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(dateep,'%Y') as year, count(*) as nb, sum(".$this->db->sanitize($this->field).") as total, avg(".$this->db->sanitize($this->field).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE ".$this->where; $sql .= " GROUP BY year"; $sql .= $this->db->order('year', 'DESC'); diff --git a/htdocs/ticket/class/ticketstats.class.php b/htdocs/ticket/class/ticketstats.class.php index 823eb676031..3439e5c7407 100644 --- a/htdocs/ticket/class/ticketstats.class.php +++ b/htdocs/ticket/class/ticketstats.class.php @@ -86,7 +86,7 @@ class TicketStats extends Stats public function getNbByYear() { $sql = "SELECT YEAR(datec) as dm, count(*)"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " GROUP BY dm DESC"; $sql .= " WHERE ".$this->where; @@ -103,7 +103,7 @@ class TicketStats extends Stats public function getNbByMonth($year, $format = 0) { $sql = "SELECT MONTH(datec) as dm, count(*)"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE YEAR(datec) = ".((int) $year); $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -123,8 +123,8 @@ class TicketStats extends Stats */ public function getAmountByMonth($year, $format = 0) { - $sql = "SELECT date_format(datec,'%m') as dm, sum(".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(datec,'%m') as dm, sum(".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE date_format(datec,'%Y') = '".$this->db->escape((string) $year)."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -143,8 +143,8 @@ class TicketStats extends Stats */ public function getAverageByMonth($year) { - $sql = "SELECT date_format(datec,'%m') as dm, avg(".$this->field.")"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(datec,'%m') as dm, avg(".$this->db->sanitize($this->field).")"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE date_format(datec,'%Y') = '".$this->db->escape((string) $year)."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -160,8 +160,8 @@ class TicketStats extends Stats */ public function getAllByYear() { - $sql = "SELECT date_format(datec,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; - $sql .= " FROM ".$this->db->sanitize($this->from, 0, 0, 1); + $sql = "SELECT date_format(datec,'%Y') as year, count(*) as nb, sum(".$this->db->sanitize($this->field).") as total, avg(".$this->db->sanitize($this->field).") as avg"; + $sql .= " FROM ".$this->db->sanitize($this->from, 0, 1, 1); $sql .= " WHERE ".$this->where; $sql .= " GROUP BY year"; $sql .= $this->db->order('year', 'DESC');