From d426ce8a86f5db302fc79527969ed9d6b5eda54e Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Thu, 11 May 2017 10:23:01 +0100
Subject: [PATCH] FIX #5496 rm hasData control + rm count in loop

---
 .../reports/get_report_by_period_val.php      |  5 +-
 .../reports/get_user_logs_stats_val.php       |  5 +-
 modules/entities/get_entity_late_mail.php     | 18 ++---
 modules/entities/get_entity_process_delay.php | 72 ++++++++-----------
 .../get_entity_response_rate_stat.php         | 18 ++---
 modules/entities/get_entity_vol.php           | 18 ++---
 6 files changed, 60 insertions(+), 76 deletions(-)
 mode change 100644 => 100755 apps/maarch_entreprise/reports/get_user_logs_stats_val.php

diff --git a/apps/maarch_entreprise/reports/get_report_by_period_val.php b/apps/maarch_entreprise/reports/get_report_by_period_val.php
index 164c5eb34ca..4d5716736c0 100644
--- a/apps/maarch_entreprise/reports/get_report_by_period_val.php
+++ b/apps/maarch_entreprise/reports/get_report_by_period_val.php
@@ -260,8 +260,7 @@ else
 
 		$totalDocTypes = count($doctypes);
 
-
-		for($i=0; $i<count($doctypes);$i++)
+		for($i=0; $i<$totalDocTypes;$i++)
 		{
 			$arrayPDO = array_merge($arrayPDO, array(":doctypeId" => $doctypes[$i]['ID']));
 			$stmt = $db->query("SELECT doctypes_second_level_label,".$req->get_date_diff('closing_date', 'creation_date' )." AS delay FROM ".$view
@@ -369,7 +368,7 @@ else
 		else
 		{
 			$error = _NO_DATA_MESSAGE;
-echo "{status : 2, error_txt : '".addslashes(functions::xssafe($error))."'}";
+			echo "{status : 2, error_txt : '".addslashes(functions::xssafe($error))."'}";
 		}
 
 	}
diff --git a/apps/maarch_entreprise/reports/get_user_logs_stats_val.php b/apps/maarch_entreprise/reports/get_user_logs_stats_val.php
old mode 100644
new mode 100755
index 364696924ea..2ed2fbc664b
--- a/apps/maarch_entreprise/reports/get_user_logs_stats_val.php
+++ b/apps/maarch_entreprise/reports/get_user_logs_stats_val.php
@@ -50,9 +50,10 @@ if(isset($_REQUEST['user']) && $_REQUEST['user'] != '')
 	$req = new request();
 	$tab = $req->PDOselect($select, $where, $arrayPDO, " ORDER BY ".$_SESSION['tablename']['history'].".event_date DESC ", $_SESSION['config']['databasetype'], $limit="500",false);
 
-	if (count($tab) > 0)
+	$tabCount = count($tab);
+	if ($tabCount > 0)
 	{
-		for ($i=0;$i<count($tab);$i++)
+		for ($i=0;$i<$tabCount;$i++)
 		{
 			for ($j=0;$j<count($tab[$i]);$j++)
 			{
diff --git a/modules/entities/get_entity_late_mail.php b/modules/entities/get_entity_late_mail.php
index 8d71ceda9a4..395ec2776c3 100755
--- a/modules/entities/get_entity_late_mail.php
+++ b/modules/entities/get_entity_late_mail.php
@@ -65,15 +65,15 @@ if (!empty($_POST['priority_chosen'])  || $_POST['priority_chosen'] === "0") {
     $where_priority = ' AND priority in (' . $priority_chosen . ') ';
 }
 
-$period_type = $_REQUEST['period_type'];
-$status_obj = new manage_status();
-$ind_coll = $sec->get_ind_collection('letterbox_coll');
-$table = $_SESSION['collections'][$ind_coll]['table'];
-$view = $_SESSION['collections'][$ind_coll]['view'];
+$period_type   = $_REQUEST['period_type'];
+$status_obj    = new manage_status();
+$ind_coll      = $sec->get_ind_collection('letterbox_coll');
+$table         = $_SESSION['collections'][$ind_coll]['table'];
+$view          = $_SESSION['collections'][$ind_coll]['view'];
 $search_status = $status_obj->get_searchable_status();
-$default_year = date('Y');
-$report_type = $_REQUEST['report_type'];
-$core_tools = new core_tools();
+$default_year  = date('Y');
+$report_type   = $_REQUEST['report_type'];
+$core_tools    = new core_tools();
 $core_tools->load_lang();
 
 //$title = _ENTITY_LATE_MAIL.' '.$date_title ;
@@ -245,7 +245,7 @@ if ($where_clause)
 $totalCourrier=array();
 $totalEntities = count($entities);
 
-for($i=0; $i<count($entities);$i++)
+for($i=0; $i<$totalEntities;$i++)
 {
     $valid = true;
 
diff --git a/modules/entities/get_entity_process_delay.php b/modules/entities/get_entity_process_delay.php
index 2659ac98cd9..e21f5e1066d 100755
--- a/modules/entities/get_entity_process_delay.php
+++ b/modules/entities/get_entity_process_delay.php
@@ -9,9 +9,9 @@ $_ENV['date_pattern'] = "/^[0-3][0-9]-[0-1][0-9]-[1-2][0-9][0-9][0-9]$/";
 
 
 $graph = new graphics();
-$req = new request();
-$sec = new security();
-$db = new Database();
+$req   = new request();
+$sec   = new security();
+$db    = new Database();
 
 //var_dump($_POST['entities_chosen']);
 $entities_chosen = explode("#", $_POST['entities_chosen']);
@@ -46,15 +46,15 @@ if (!empty($_POST['priority_chosen']) || $_POST['priority_chosen'] === "0") {
     $where_priority = ' AND priority in (' . $priority_chosen . ') ';
 }
 
-$period_type = $_REQUEST['period_type'];
-$status_obj = new manage_status();
-$ind_coll = $sec->get_ind_collection('letterbox_coll');
-$table = $_SESSION['collections'][$ind_coll]['table'];
-$view = $_SESSION['collections'][$ind_coll]['view'];
+$period_type   = $_REQUEST['period_type'];
+$status_obj    = new manage_status();
+$ind_coll      = $sec->get_ind_collection('letterbox_coll');
+$table         = $_SESSION['collections'][$ind_coll]['table'];
+$view          = $_SESSION['collections'][$ind_coll]['view'];
 $search_status = $status_obj->get_searchable_status();
-$default_year = date('Y');
-$report_type = $_REQUEST['report_type'];
-$core_tools = new core_tools();
+$default_year  = date('Y');
+$report_type   = $_REQUEST['report_type'];
+$core_tools    = new core_tools();
 $core_tools->load_lang();
 
 //Récupération de l'ensemble des types de documents
@@ -161,7 +161,6 @@ else if($period_type == 'custom_period')
 		exit();
 	}
 	
-	
 	if( preg_match($_ENV['date_pattern'],$_REQUEST['date_start'])==false  && $_REQUEST['date_start'] <> ''  )
 	{
 		
@@ -202,7 +201,6 @@ else
 	exit();
 }
 
-
 //$title = _ENTITY_PROCESS_DELAY.' '.$date_title ;
 $db = new Database();
 
@@ -220,13 +218,13 @@ $has_data = false;
 //Utilisation de la clause de sécurité de Maarch
 
 $where_clause = $sec->get_where_clause_from_coll_id('letterbox_coll');
-//var_dump($where_clause);
+
 if ($where_clause)
     $where_clause = " and ".$where_clause;
 	
 $totalEntities = count($entities);
 	
-for($i=0; $i<count($entities);$i++)
+for($i=0; $i<$totalEntities;$i++)
 {
     //Permet d'afficher ou non les entités dont le nombre de courrier est égal à 0
 	$valid = true;
@@ -295,14 +293,10 @@ if($report_type == 'graph')
     }
 
     $src1 = $_SESSION['config']['businessappurl']."index.php?display=true&module=reports&page=graphs&type=histo&largeur=$largeur&hauteur=600&marge_bas=300&title=".$title."&labelY="._N_DAYS;
-    for($i=0;$i<count($_SESSION['labels1']);$i++)
-    {
-        //$src1 .= "&labels[]=".$_SESSION['labels1'][$i];
-    }
+
     $_SESSION['GRAPH']['VALUES']='';
     for($i=0;$i<count($val_an);$i++)
     {
-        //$src1 .= "&values[]=".$val_an[$i];
         $_SESSION['GRAPH']['VALUES'][$i]=$val_an[$i];
     }
 }
@@ -311,30 +305,20 @@ elseif($report_type == 'array')
     array_unshift($data, array('LABEL' => _DOCTYPE, 'VALUE' => _PROCESS_DELAY));
 }
 
-if ( $has_data)
-{
-    if($report_type == 'graph')
-    {
-        $labels1 = "'".implode("','", $_SESSION['labels1'])."'";
-        echo "{label: [".$labels1."] ".
-            ", data: ['".utf8_encode(str_replace(",", "','", addslashes(implode(",", $_SESSION['GRAPH']['VALUES']))))."']".
-            ", title: '".addslashes($title)."'}";
-        exit;
-     }
-    elseif($report_type == 'array')
-    {
-		$data2 = urlencode(json_encode($data));
-		$form =	"<input type='button' class='button' value='Exporter les données' onclick='record_data(\"" . $_SESSION['config']['businessappurl']."index.php?display=true&dir=reports&page=record_data \",\"".$data2."\")' style='float:right;'/>";
-		echo $form;
-		
-        $graph->show_stats_array($title, $data);
-    }
-}
-else
-{
-    $error = _NO_DATA_MESSAGE;
-    echo "{status : 2, error_txt : '".addslashes(functions::xssafe($error))."'}";
+if($report_type == 'graph') {
+    $labels1 = "'".implode("','", $_SESSION['labels1'])."'";
+    echo "{label: [".$labels1."] ".
+        ", data: ['".utf8_encode(str_replace(",", "','", addslashes(implode(",", $_SESSION['GRAPH']['VALUES']))))."']".
+        ", title: '".addslashes($title)."'}";
+    exit;
+
+} elseif($report_type == 'array') {
+	$data2 = urlencode(json_encode($data));
+	$form =	"<input type='button' class='button' value='Exporter les données' onclick='record_data(\"" . $_SESSION['config']['businessappurl']."index.php?display=true&dir=reports&page=record_data \",\"".$data2."\")' style='float:right;'/>";
+	echo $form;
+	
+    $graph->show_stats_array($title, $data);
 }
+
 exit();
 
-?>
diff --git a/modules/entities/get_entity_response_rate_stat.php b/modules/entities/get_entity_response_rate_stat.php
index cce0062ce27..2e70dd882e0 100755
--- a/modules/entities/get_entity_response_rate_stat.php
+++ b/modules/entities/get_entity_response_rate_stat.php
@@ -46,15 +46,15 @@ if (!empty($_POST['priority_chosen'])  || $_POST['priority_chosen'] === "0") {
     $where_priority = ' AND priority in (' . $priority_chosen . ') ';
 }
 
-$period_type = $_REQUEST['period_type'];
-$status_obj = new manage_status();
-$ind_coll = $sec->get_ind_collection('letterbox_coll');
-$table = $_SESSION['collections'][$ind_coll]['table'];
-$view = $_SESSION['collections'][$ind_coll]['view'];
+$period_type   = $_REQUEST['period_type'];
+$status_obj    = new manage_status();
+$ind_coll      = $sec->get_ind_collection('letterbox_coll');
+$table         = $_SESSION['collections'][$ind_coll]['table'];
+$view          = $_SESSION['collections'][$ind_coll]['view'];
 $search_status = $status_obj->get_searchable_status();
-$default_year = date('Y');
-$report_type = $_REQUEST['report_type'];
-$core_tools = new core_tools();
+$default_year  = date('Y');
+$report_type   = $_REQUEST['report_type'];
+$core_tools    = new core_tools();
 $core_tools->load_lang();
 
 
@@ -230,7 +230,7 @@ if ($where_clause)
 $totalCourrier = [];
 $totalEntities = count($entities);	
 	
-for($i=0; $i<count($entities); $i++)
+for($i=0; $i<$totalEntities; $i++)
 {
 	//NB RES INCOMING
 	$stmt = $db->query("select count(res_id) as nb_res_incoming from ".$view." where destination = ? and status not in ('DEL','BAD') AND admission_date is not null AND category_id = 'incoming'".$where_date." ".$where_status." ".$where_priority . $where_clause,array($entities[$i]['ID']));
diff --git a/modules/entities/get_entity_vol.php b/modules/entities/get_entity_vol.php
index 36de2e5ba21..36eb53c3f6f 100755
--- a/modules/entities/get_entity_vol.php
+++ b/modules/entities/get_entity_vol.php
@@ -43,15 +43,15 @@ if (!empty($_POST['priority_chosen'])  || $_POST['priority_chosen'] === "0") {
     $where_priority = ' AND priority in (' . $priority_chosen . ') ';
 }
 
-$period_type = $_REQUEST['period_type'];
-$status_obj = new manage_status();
-$ind_coll = $sec->get_ind_collection('letterbox_coll');
-$table = $_SESSION['collections'][$ind_coll]['table'];
-$view = $_SESSION['collections'][$ind_coll]['view'];
+$period_type   = $_REQUEST['period_type'];
+$status_obj    = new manage_status();
+$ind_coll      = $sec->get_ind_collection('letterbox_coll');
+$table         = $_SESSION['collections'][$ind_coll]['table'];
+$view          = $_SESSION['collections'][$ind_coll]['view'];
 $search_status = $status_obj->get_searchable_status();
-$default_year = date('Y');
-$report_type = $_REQUEST['report_type'];
-$core_tools = new core_tools();
+$default_year  = date('Y');
+$report_type   = $_REQUEST['report_type'];
+$core_tools    = new core_tools();
 $core_tools->load_lang();
 
 
@@ -214,7 +214,7 @@ if ($where_clause) {
 $totalCourrier=array();
 $totalEntities = count($entities);
 
-for ($i=0; $i<count($entities);$i++) {
+for ($i=0; $i<$totalEntities;$i++) {
     $stmt = $db->query("select count(*) as total from ".$view." inner join mlb_coll_ext on ".$view.".res_id = mlb_coll_ext.res_id where destination = ? and ".$view.".status not in ('DEL','BAD') ".$where_date." ".$where_status." ".$where_priority . $where_clause." ", array($entities[$i]['ID']));
     //$db->show();
     $res = $stmt->fetchObject();
-- 
GitLab