jb-data.de/scripts/ajax/rs.php
2025-08-11 22:23:30 +02:00

198 lines
No EOL
7.6 KiB
PHP

<?php
//-------------------- wiederkehrende abfragen
$a_touren = $GLOBALS['a_touren'];
$a_fahrzg = $GLOBALS['a_fahrzg'];
$a_fahrer = $GLOBALS['a_fahrer'];
//--------------------
if(isset($_GET['a']))
$action=$_GET['a'];
else
$action='load_free_cars';
switch($action):
case 'car_save';
$GLOBALS['mysql']->insert("UPDATE tourenliste SET auto='".$_POST['car']."' WHERE id='".$_POST['tourID']."'");
$row_tourl = $GLOBALS['mysql']->query_single("SELECT * FROM tourenliste WHERE id='".$_POST['tourID']."'");
$ttemp=$row_tourl['tour']; $ta_id= array_search($ttemp, array_column($a_touren, 'id'));
$atemp=$_POST['car']; $aa_id= array_search($atemp, array_column($a_fahrzg, 'id'));
$back['lastnote']="Fahrzeug ".$a_fahrzg[$aa_id]['kz']." für Tour ".$row_tourx['tour']." gespeichert.";
$back['success'] = true;
$back['zeile'] = $_POST['tourID'];
$back['alt'] = 5;
echo json_encode($back);
break;
case 'user_save';
// $ttemp=$row['tour']; $ta_id= array_search($ttemp, array_column($a_touren, 'id'));
// $atemp=$row['auto']; $aa_id= array_search($atemp, array_column($a_fahrzg, 'id'));
// $mtemp=$row['fahrer']; $ma_id= array_search($mtemp, array_column($a_fahrer, 'id'));
$GLOBALS['mysql']->insert("UPDATE tourenliste SET fahrer='".$_POST['user']."' WHERE id='".$_POST['tourID']."'");
$row_tourl = $GLOBALS['mysql']->query_single("SELECT * FROM tourenliste WHERE id='".$_POST['tourID']."'");
$ttemp=$row_tourl['tour']; $ta_id= array_search($ttemp, array_column($a_touren, 'id'));
$atemp=$_POST['car']; $aa_id= array_search($atemp, array_column($a_fahrzg, 'id'));
$back['lastnote']="Fahrer ".$a_fahrer[$ma_id]['name']." für Tour ".$row_tourx['tour']." gespeichert.";
$back['success'] = true;
$back['zeile'] = $_POST['tourID'];
$back['alt'] = 5;
echo json_encode($back);
break;
case 'load_car_icon';
//echo $_POST['tourID'];
$touri = $GLOBALS['mysql']->query_single("SELECT * FROM tourenliste WHERE id='".$_POST['tourID']."'");
//$unixdate=mktime(0,0,0, $touri['monat'],$touri['tag'],$touri['jahr']);
if($touri['auto']==0) { $anzeige=1;
} else {
$cari = $GLOBALS['mysql']->query_single("SELECT * FROM fahrzeuge WHERE id='".$touri['auto']."'");
if($cari['aktiv']==0) { $anzeige=1;
} else {
//$plani = $GLOBALS['mysql']->query_single("SELECT * FROM fplaner WHERE timestamp LIKE '".$unixdate." %' and fid='".$touri['auto']."'");
$plani = $GLOBALS['mysql']->query_single("SELECT * FROM fplaner WHERE
tag='".$touri['tag']."' and
monat='".$touri['monat']."' and
jahr='".$touri['jahr']."' and
fid='".$touri['auto']."'");
if($plani['num_rows']== 0) {
if($cari['besitz']<3) {
$ttest = $GLOBALS['mysql']->query_single("SELECT * FROM tourenliste WHERE
tag='".$touri['tag']."' and
monat='".$touri['monat']."' and
jahr='".$touri['jahr']."' and
auto='".$touri['auto']."' and
typ='".$touri['typ']."'");
if($ttest['num_rows']>1) {
$anzeige=2;
} else {
$anzeige=3;
}
} else {
$anzeige=5;
}
} else {
$fplani = $GLOBALS['mysql']->query_single("SELECT * FROM fplaner_bez WHERE id='".$plani['grund']."'");
if($fplani['aktiv']== 0) { $anzeige=1; } //fahrzeug nicht verfügbar
if($fplani['aktiv']== 1) { $anzeige=2; } //fahrzeug verfügbar, aber Eintrag
if($fplani['aktiv']== 2) { $anzeige=4; } //an Druckhaus bzw fremder standort
}
}
}
if($anzeige==0) {
$back['htmlresult']='<td nowrap id="caricon" style="width:25px;font-size:11pt;text-align:right;color:gray">
<i class="fa fa-truck" id="caricon"></i></td>';
}
if($anzeige==1) {
$back['htmlresult']='<td nowrap id="caricon" style="width:25px;font-size:11pt;text-align:right;color:red">
<i class="fa fa-truck" id="caricon"></i></td>';
}
if($anzeige==2) {
$back['htmlresult']='<td nowrap id="caricon" style="width:25px;font-size:11pt;text-align:right;color:orange">
<i class="fa fa-truck" id="caricon"></i></td>';
}
if($anzeige==3) {
$back['htmlresult']='<td nowrap id="caricon" style="width:25px;font-size:11pt;text-align:right;color:green">
<i class="fa fa-truck" id="caricon"></i></td>';
}
if($anzeige==4) {
$back['htmlresult']='<td nowrap id="caricon" style="width:25px;font-size:11pt;text-align:right;color:#045FB4">
<i class="fa fa-truck" id="caricon"></i></td>';
}
if($anzeige==5) {
$back['htmlresult']='<td nowrap id="caricon" style="width:25px;font-size:11pt;text-align:right;color:#A5DF00">
<i class="fa fa-truck" id="caricon"></i></td>';
}
$back['zeile'] = $_POST['tourID'];
$back['alt'] = 5;
echo json_encode($back);
break;
//--------------------- user icon nachladen
case 'load_user_icon';
//echo $_POST['tourID'];
$touri2 = $GLOBALS['mysql']->query_single("SELECT * FROM tourenliste WHERE id='".$_POST['tourID']."'");
if($touri2['fahrer']==0) { $anzeige=1;
} else {
$useri2 = $GLOBALS['mysql']->query_single("SELECT * FROM mitarbeiter WHERE id='".$touri2['fahrer']."'");
if($useri2['aktiv']==0) { $anzeige=1; //Fahrer nicht aktiv / ausgeschieden
} else {
$plani = $GLOBALS['mysql']->query_single("SELECT * FROM planer WHERE
tag='".$touri2['tag']."' and
monat='".$touri2['monat']."' and
jahr='".$touri2['jahr']."' and
mid='".$touri2['fahrer']."'");
if($plani['num_rows']== 0) {
if($useri2['rs']>0) {
$mtest = $GLOBALS['mysql']->query_single("SELECT * FROM tourenliste WHERE
tag='".$touri2['tag']."' and
monat='".$touri2['monat']."' and
jahr='".$touri2['jahr']."' and
fahrer='".$touri2['fahrer']."' and
typ='".$touri2['typ']."'");
if($mtest['num_rows']>1) {
$anzeige=2;
} else {
$anzeige=3;
}
} else {
$anzeige=2;
}
} else {
$plani = $GLOBALS['mysql']->query_single("SELECT * FROM planer_bez WHERE id='".$plani['grund']."'");
if($plani['nichtda']== 1) { $anzeige=1; }
elseif($plani['nichtda']== 8) { $anzeige=1; }
elseif($plani['nichtda']==19) { $anzeige=1; }
else { $anzeige=2; }
}
}
}
if($anzeige==0) {
$back['htmlresult']='<td nowrap id="caricon" style="width:25px;font-size:11pt;text-align:right;color:gray">
<i class="fa fa-user" id="caricon"></i></td>';
}
if($anzeige==1) {
$back['htmlresult']='<td nowrap id="caricon" style="width:25px;font-size:11pt;text-align:right;color:red">
<i class="fa fa-user" id="caricon"></i></td>';
}
if($anzeige==2) {
$back['htmlresult']='<td nowrap id="caricon" style="width:25px;font-size:11pt;text-align:right;color:orange">
<i class="fa fa-user" id="caricon"></i></td>';
}
if($anzeige==3) {
$back['htmlresult']='<td nowrap id="caricon" style="width:25px;font-size:11pt;text-align:right;color:green">
<i class="fa fa-user" id="caricon"></i></td>';
}
$back['zeile'] = $_POST['tourID'];
$back['alt'] = 5;
echo json_encode($back);
break;
case 'load_free_cars';
default:
//--------------------- freie Fahrzeuge Nachts
$key=0;
//-- trp nachts
$tempcar = $GLOBALS['mysql']->query("SELECT * FROM fahrzeuge WHERE aktiv=1 and besitz<3 and typ>2 ORDER BY id");
while($row = $tempcar->fetch_assoc()) {
$istabfrage = $GLOBALS['mysql']->query_single("SELECT * FROM tourenliste WHERE timestamp LIKE '".$_POST['date']." %' AND auto='".$row['id']."' and typ>5 and typ!=18");
$pauto = $GLOBALS['mysql']->query_single("SELECT * FROM fplaner WHERE timestamp LIKE '".$_POST['date']." %' and fid='".$row['id']."'");
if($istabfrage['num_rows']== 0) {
if($pauto['num_rows']== 0) {
$seite['trp'][$key]=$row['kz']." (".$row['hersteller']." ".$row['name'].")"; $key++;
}
}
}
echo json_encode($seite);
endswitch;
?>