Files
CRM/MonitoringVmPotentialite.php
BACHIR SOULDI 2794e62571 first commit
2025-09-28 08:49:37 +01:00

147 lines
6.2 KiB
PHP

<?php
require_once 'MonitoringVMHeader.php';
require_once 'MonitoringDBRequest.php';
$userId = $current_user->get('id');
$NomWilaya = "ALL";
if(isset($_POST['NomWilaya']))
$NomWilaya = $_POST['NomWilaya'];
$result = getResultatVMPotentialites($NomWilaya ,$roleid ,$userId);
$wilayas = getWilayas();
$ratings = getRatings();
$result = convertArray($result);
function search($array, $search_list) {
// Create the result array
$result = array();
// Iterate over each array element
foreach ($array as $key => $value) {
// Iterate over each search condition
foreach ($search_list as $k => $v) {
if (!isset($value[$k]) || $value[$k] != $v)
{
// Skip two loops
continue 2;
}
}
$result[] = $value;
}
return $result;
}
function convertArray($result){
$a = array();
$b = array();
$c = array();
$ratings = getRatings();
for($i = 0 ; $i < sizeof($result) ; $i++){
$d = array();
if(in_array($result[$i]['usersid'], $a) == false){
if(isDR($result[$i]['role']))
$role="DIRECTEUR REGIONAL";
$tempRole = $result[$i]['role'];
if(isSuperviseur($tempRole))
$role="SUPERVISEUR";
if(isDM($tempRole))
$role="DELEGUE MEDICAL";
if($tempRole=="DIRECTEUR DE LA PROMOTION MEDICALE"){
$role="DIRECTEUR DE LA PROMOTION MEDICALE";
$region="OUEST";
}
if(isOuestVMText($tempRole))
$region="OUEST";
if(isCentreVMText($tempRole))
$region="CENTRE";
if(isEstVMText($tempRole))
$region="EST";
for($b = 0 ; $b < sizeof($ratings); $b++){
$search_items = array('usersid'=>$result[$i]['usersid'], 'rating'=>$ratings[$b]['rating']);
$val = search($result, $search_items);
if($val[0]['nbr'] == null){
$d = $d + [$ratings[$b]['rating']=>0];
}else{
$d = $d + [$ratings[$b]['rating']=>$val[0]['nbr']];
}
}
$b = ['usersid'=>$result[$i]['usersid']
,'wilaya_account'=>$result[$i]['wilaya_account']
,'region_account'=>$result[$i]['region_account']
,'fullname'=>$result[$i]['fullname']
,'role'=>$result[$i]['role']
,'rolevm'=>$role
,'regionvm'=>$region];
$b = $b + $d;
array_push($c,$b);
}
array_push($a,$result[$i]['usersid']);
}
return $c;
}
echo getMonitoringMainBar(4,$roleid).
'<div class="main-container main-container-Accounts">
<div id="scrollbar" style="margin:15px 15px 15px 15px; border:1px solid #ecf0f1; overflow-y: scroll; overflow-x: scroll; height:462.709px ;border:1px solid #bdc3c7;">'.
getWilayaSelect($wilayas, $NomWilaya).
'<hr>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputCity">Nom & Prénom</label>
<input class="form-control mb-4 w-20" type="text" name="nomprenom" placeholder="Rechercher" onKeyUp="fullNameChange(this)">
</div>'.getRegionSelectSubmit($roleid,false).getRolesSelect().'
</div>';
echo '<table id="tabcenter" class="table table-bordered table-striped" >
<tr class="center borderline">
<th id="role" >Poste</th>
<th id="region">Region</th>
<th id="fullname" > Nom & Prenom</th>';
for($p = 0 ; $p < sizeof($ratings); $p++){
echo '<th>'.$ratings[$p]['rating'].'</th>';
}
echo'<th>Total</th>
</tr>
<tbody id="values"></tbody>
</table>
</div></div>';
$viewer->view('CustomDashboardFooter.tpl');
?>
<script>
function loadTable(data) {
$('#tabcenter tr').slice(1).remove();
var temp=[];
var temp4 = [];
var ratings = <?php echo json_encode($ratings); ?>;
if(data.length > 0) {
for(var i = 0; i < data.length; i++) {
var row = data[i];
var sum = 0;
var temp5 = [];
for(var f = 0; f < ratings.length; f++) {
var arrayData = ratings[f]['rating'].split("");
if(arrayData[1] == "+"){ arrayData[1] = "%2B"; }else if(arrayData[1] == "-"){ arrayData[1] = "%2D"; }
temp[f] = "<td onclick=\"location.href='?module=Accounts&view=List&search_params=[[[%22assigned_user_id%22,%22c%22,%22"+row['fullname']+"%22],[%22rating%22,%22e%22,%22"+arrayData[0]+arrayData[1]+"%22]]]'\">"+row[ratings[f]['rating']]+"</td>";
temp5[f] = parseInt(row[ratings[f]['rating']]);
//total colonnes
sum = sum + temp5[f];
if(f+1 == ratings.length){
temp[f+1]="<td style=' background:#7f8fa6; color: #ffffff;'>"+sum+"</td>";
temp5[f+1]=sum;
}
}
temp4.push(temp5);
var temp2=["<td>"+row['rolevm']+"</td>" , "<td>"+row['regionvm']+"</td>" , "<td >"+row['fullname']+"</td>"];
var temp3=temp2+temp
$('#tabcenter').append("<tr>"+temp3.toString()+"</tr>");
}
//total lignes
var temp6= [];
for(var a = 0; a < ratings.length +1 ; a++) {
var totalligne = 0;
for(var b = 0; b < temp4.length; b++) {
totalligne = totalligne + temp4[b][a];
}
temp6[a] = "<td>"+totalligne+"</td>";
}
var temp7 = ["<td colspan='3'>Total</td>"] + temp6;
$('#tabcenter').append("<tfoot><tr style=' background:#7f8fa6; color: #ffffff;'>"+temp7.toString()+"</tr></tfoot>");
}
}
//filtre nom/prenom
function fullNameChange(e) {
document.getElementById("role").value = "All";
document.getElementById("region").value = "All";
var res = result.filter(a => a.fullname.toUpperCase().includes(e.value.toUpperCase()) );
loadTable(res);
}
function regionChange(e) {
document.getElementById("role").value = "All";
var res = result.filter(a => a.regionvm == e);
if(e == "All"){ res = result;}
loadTable(res);
}
function roleChange(e) {
document.getElementById("region").value = "All";
var res = result.filter(a => a.rolevm == e);
if(e == "All"){ res = result;}
loadTable(res);
}
var result = <?php echo json_encode($result); ?>;
loadTable(result);
</script>
</body>
</html>