|
Server IP : 10.128.40.6 / Your IP : 216.73.216.233 Web Server : Apache System : Linux webd006.cluster128.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : logmcpe ( 111175) PHP Version : 7.3.33 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/logmcpe/www/TEST/www/../../MCPRO/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
include_once 'code/init.php';
// print_r($_GET);
print_header ();
$month = date('m')-6;
$year = date('Y') ;
$from = sprintf("%04d%02d%02d", $year, $month, 1) ;
if ($month < 1)
{
$month += 12 ;
$year -- ;
}
$sem = array ('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi') ;
// print_r($_GET);
// print_r($_POST);
isset($_POST['ad']) ? $add = $_POST['ad'] : $add = '' ;
isset($_POST['ded']) ? $ded = $_POST['ded'] : $ded = '' ;
isset($_POST['hf']) ? $Nduree = (($_POST['hf'] - $_POST['hs'])*60+$_POST['mf']-$_POST['ms'] ) - $_POST['presta_Hduree'] : $Nduree = 0;
if (isset($Nduree) && $Nduree < 0)
$Nduree = -( $Nduree );
function jour_jouren2($jour,$get)
{
static $presta_jour ;
$from = $get ;
$presta_jour = array('nynnnnn' => $get, 'nnynnnn' => date("Ymd", strtotime("+1 day", strtotime($from))), 'nnnynnn' => date("Ymd", strtotime("+2 day", strtotime($from))), 'nnnnynn' => date("Ymd", strtotime("+3 day", strtotime($from))), 'nnnnnyn' => date("Ymd", strtotime("+4 day", strtotime($from))), 'nnnnnny' => date("Ymd", strtotime("+5 day", strtotime($from))), 'ynnnnnn' => date("Ymd", strtotime("+6 day", strtotime($from)))) ;
// echo '<br/>'." +++++++++++++ ";
// print_r($presta_jour);
return $presta_jour[$jour] ;
}
function get_prest_sem( $pre,$from ,$to,$agence)
{
$id=0;
$p=array();
$db=debutsem(date('Y', strtotime($from)),date('m', strtotime($from)),date('d', strtotime($from)));
$dbto=debutsem(date('Y', strtotime($to)),date('m', strtotime($to)),date('d', strtotime($to)));
$fin=date("Ymd", strtotime("+6 day", strtotime($dbto)));
while($db < $fin )
{
$and = date("Ymd", strtotime("+6 day", strtotime($db)));
// date('Ymd',int2time($db)+6*24*3600 );
$presta_jour1 = array('nynnnnn' => '1', 'nnynnnn' => '2', 'nnnynnn' => '3', 'nnnnynn' => '4', 'nnnnnyn' => '5', 'nnnnnny' => '6', 'ynnnnnn' => '0') ;
$presta_jour2 = array('1' => 'nynnnnn', '2' => 'nnynnnn', '3' => 'nnnynnn', '4' => 'nnnnynn', '5' => 'nnnnnyn', '6' => 'nnnnnny', '0' => 'ynnnnnn') ;
$q2 = dbi_query("SELECT * FROM ".TABLE_PREST." p WHERE p.presta_id = ".$pre." AND agence_id=$agence") ;
// $q2 = dbi_query("SELECT p.* FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE p.client_id=c.client_id and p.agence_id=$agence AND presta_date_debut <= $and AND (p.presta_date_fin >= $db OR p.presta_date_fin IS NULL) ");
while($prest = dbi_fetch_row($q2))
{
if($prest['presta_jour']== 'nnnnnnn' || $prest['presta_jour']== '' || $prest['presta_jour']== NULL )
$prest['presta_jour']=$presta_jour2[date("w",strtotime($prest['presta_date_fin']))];
$data = array('jour' => $prest['presta_jour'], 'deb' => $prest['presta_Hdeb'], 'duree' => $prest['presta_Hduree'], 'inter' => $prest['inter_id'], 'taux' => $prest['presta_forfait']) ;
$q1 = dbi_query("SELECT * FROM ".TABLE_PRESTA_MODIF." WHERE presta_id = ".$prest['presta_id']." AND start <= $and order by `start`, `date`") ;
while (($m = dbi_fetch_row($q1)) )
{
$data['jour'] = $m['jour'] === NULL ? $data['jour'] : $m['jour'] ;
$data['deb'] = $m['Hdeb'] === NULL ? $data['deb'] : $m['Hdeb'] ;
$data['duree'] = $m['Hduree'] === NULL ? $data['duree'] : $m['Hduree'] ;
$data['inter'] = $m['inter_id'] === NULL ? $data['inter'] : $m['inter_id'] ;
$data['taux'] = $m['taux'] === NULL ? $data['taux'] : $m['taux'] ;
}
$jour=$data['jour'];
$heurefin=addDuree($data['deb'],$data['duree']);
$qexcept=dbi_query("SELECT * FROM ".TABLE_EXCEPT." WHERE (date BETWEEN ".$db." AND ".$and.") AND presta_id=".$prest['presta_id']." ");
if($rr = dbi_fetch_row($qexcept)){
}
else{
$datep=jour_jouren2($jour,$db);
if($datep>=$from && $datep<=$to )
{
$presta=array("presta_id" => $prest['presta_id'],"presta_desc" => $prest['presta_desc'] , "presta_date_debut" => $prest['presta_date_debut'] , "presta_Hdeb" => $data['deb'] , "presta_Hduree" => $data['duree'] , "presta_recur" => $prest['presta_recur'] , "presta_date_fin" => $prest['presta_date_fin'] , "presta_jour" => $jour , "presta_forfait" => $prest['presta_jour'] , "presta_forfaitHT" => $prest['presta_forfaitHT'], "presta_status" => $prest['presta_status'] , "presta_sem" => $prest['presta_sem'] , "client_id" => $prest['client_id'] , "inter_id" => $data['inter'] , "agence_id" => $prest['agence_id'], "date" => $datep);
$p[$id]= $presta;
++$id;
}
}
// }
}
// echo " !! $db !! ";
// echo " ?? $db ?? ";
$time=$db;
// $db = date('Ymd',$time+7*24*3600 );
$db = date("Ymd", strtotime("+7 day", strtotime($time)));
}
return $p;
}
if(!empty($_GET['client_id']))
{
if(isset($_GET['del'], $_GET['id']))
switch ($_GET['del']) {
case 'modif' :{
$d = date('d', strtotime($_GET['start']));
$m = date('m', strtotime($_GET['start']));
$y = date('Y', strtotime($_GET['start']));
$dayOfWeek = date("l",mktime(0,0,0, $m, $d,$y));
if ($dayOfWeek=="Sunday") $presjour=0;
if ($dayOfWeek=="Monday") $presjour=1;
if ($dayOfWeek=="Tuesday") $presjour=2;
if ($dayOfWeek=="Wednesday") $presjour=3;
if ($dayOfWeek=="Thursday") $presjour=4;
if ($dayOfWeek=="Friday") $presjour=5;
if ($dayOfWeek=="Saturday") $presjour=6;
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
$prestat_id=$_GET['presta_id'];
$plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to ");
//debut du code
if ($d = dbi_fetch_row($plng))
{
{
$dat = date("Ymd");
$i=0;
$from = isset($_GET['date']) ? $_GET['date'] : time2int(time()-(date('w')-1)*24*3600) ;
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND presta_id=".$_GET['presta_id']." AND presta_jour>=$presjour ");
$tablo1= array();
$tablo2= array();
$tablo3= array();
while ($p = dbi_fetch_row($plng1))
{
$tablo1[$i]=$p['inter_id'];
$tablo2[$i]=$p['date_debutpln'];
$tablo3[$i]=$p['date_finpln'];
$i++;
}
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln>$to AND presta_id=".$_GET['presta_id']." ");
while ($p = dbi_fetch_row($plng1))
{
$tablo1[$i]=$p['inter_id'];
$tablo2[$i]=$p['date_debutpln'];
$tablo3[$i]=$p['date_finpln'];
$i++;
}
$j=0;
while ($j<count($tablo1) ){
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$_GET['presta_id']." AND date_debutpln=".$tablo2[$j]." AND date_finpln=".$tablo3[$j]." ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
}
dbi_query("DELETE FROM ".TABLE_PRESTA_MODIF." WHERE presta_id in (SELECT presta_id FROM ".TABLE_PREST." WHERE client_id = ".$_GET['client_id']." AND agence_id = $agence) AND id = ".(int)$_GET['id']) ;
{// RECALCULE
$t=0;
while ($t<count($tablo1) ){
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id='$prestat_id' AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$tablo1[$t]." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$tablo1[$t]." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")))") ;
$offset = 0 ;
$indic=0;
$from =$tablo2[$t];
$to = $tablo3[$t] ;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $tablo1[$t])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$from =$tablo2[$t];
$to = $tablo3[$t] ;
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$tablo1[$t] ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$tablo1[$t]','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}// RECALCULE
}
//dbi_fetch_row(dbi_query("SELECT * FROM ".TABLE_PRESTA_MODIF." WHERE `id` = (SELECT MAX(`id`) FROM ".TABLE_PRESTA_MODIF." WHERE presta_id = ".$prest['presta_id']." ")));
$q1 = dbi_query("SELECT * FROM ".TABLE_PRESTA_MODIF." WHERE `id` = ( SELECT MAX(`id`) FROM ".TABLE_PRESTA_MODIF." WHERE presta_id = ".$prestat_id." AND inter_id is not null) ");
if($ma = dbi_fetch_row($q1) )
{
$d = date('d', strtotime($_GET['start']));
$m = date('m', strtotime($_GET['start']));
$y = date('Y', strtotime($_GET['start']));
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
$dat = date("Ymd");
$i=0;
$plng1 = dbi_query("SELECT DISTINCT date_debutpln,date_finpln FROM ".TABLE_PLNG." WHERE inter_id=".$ma['inter_id']." AND date_debutpln=$from AND date_finpln=$to ");
$tablo11= array();
$tablo22= array();
$tablo33= array();
while ($p = dbi_fetch_row($plng1))
{
$tablo22[$i]=$p['date_debutpln'];
$tablo33[$i]=$p['date_finpln'];
$i++;
}
$plngh = dbi_query("SELECT DISTINCT date_debutpln,date_finpln FROM ".TABLE_PLNG." WHERE date_debutpln>$to AND inter_id=".$ma['inter_id']." ");
while ($p = dbi_fetch_row($plngh))
{
$tablo22[$i]=$p['date_debutpln'];
$tablo33[$i]=$p['date_finpln'];
$i++;
}
$j=0;
{// RECALCULE
$t=0;
while ($t<count($tablo22) ){
/* $plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE inter_id=".$tablo11[$t]." AND date_debutpln=".$tablo22[$t]." AND date_finpln=".$tablo33[$t]." ");
*//* if ($d = dbi_fetch_row($plng)){
$t++;
} */{
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id = ".$prestat_id." AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$ma['inter_id']." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$ma['inter_id'].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$ma['inter_id']." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$ma['inter_id'].")))") ;
$offset = 0 ;
$indic=0;
$from =$tablo22[$t];
$to = $tablo33[$t] ;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $ma['inter_id'])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$from =$tablo22[$t];
$to = $tablo33[$t] ;
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id='".$ma['inter_id']."' ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','".$ma['inter_id']."','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}
}// RECALCULE
}
else {
$presti = dbi_query("SELECT * FROM ".TABLE_PREST." WHERE presta_id=".$prestat_id." ");
if($ma = dbi_fetch_row($presti)) {
$dat = date("Ymd");
$i=0;
$from = isset($_GET['date']) ? $_GET['date'] : time2int(time()-(date('w')-1)*24*3600) ;
$plng1 = dbi_query("SELECT DISTINCT date_debutpln,date_finpln FROM ".TABLE_PLNG." WHERE inter_id=".$ma['inter_id']." AND ".$_GET['start']."<= date_finpln ");
$tablo22= array();
$tablo33= array();
while ($p = dbi_fetch_row($plng1))
{
$tablo22[$i]=$p['date_debutpln'];
$tablo33[$i]=$p['date_finpln'];
$i++;
}
$j=0;
while ($j<count($tablo22) )
{
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$prestat_id." AND date_debutpln=".$tablo22[$j]." AND date_finpln=".$tablo33[$j]." ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
}
{// RECALCULE
$t=0;
while ($t<count($tablo22) ){
/* $plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE inter_id=".$tablo11[$t]." AND date_debutpln=".$tablo22[$t]." AND date_finpln=".$tablo33[$t]." ");
if ($d = dbi_fetch_row($plng)){
$t++;
} */
{
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id=".$prestat_id." AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$ma['inter_id']." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$ma['inter_id'].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$ma['inter_id']." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$ma['inter_id'].")))") ;
$offset = 0 ;
$indic=0;
$from =$tablo22[$t];
$to = $tablo33[$t] ;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $ma['inter_id'])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$from =$tablo22[$t];
$to = $tablo33[$t] ;
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=".$ma['inter_id']." ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','".$ma['inter_id']."','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}
}// RECALCULE
}
}
break ;
}
//fin du code
else
{
dbi_query("DELETE FROM ".TABLE_PRESTA_MODIF." WHERE presta_id in (SELECT presta_id FROM ".TABLE_PREST." WHERE client_id = ".$_GET['client_id']." AND agence_id = $agence) AND id = ".(int)$_GET['id']) ;
break ;
}
}
case 'excpt' :{
{
$datefin=$_GET['presta_dat'];
$d1 = date('d', strtotime($datefin));
$m1 = date('m', strtotime($datefin));
$y1 = date('Y', strtotime($datefin));
$db1=debutsem($y1,$m1,$d1);
$from1 = isset($db1) ? $db1 : time2int(time()-(date('w')-1)*24*3600) ;
$to1 = time2int(int2time($from1)+6*24*3600) ;
$prestat=$_GET['presta_id'];
$newpresta=$_GET['new_presta_id'];
$inter_id=$_GET['inter_id'];
if ($prestat!=null){
$dad= dbi_query("SELECT inter_id FROM ".TABLE_PREST." WHERE presta_id = ".$prestat." ");
if ($dep = dbi_fetch_row($dad))
$interd=$dep['inter_id'];
}
$dateprest=$_GET['date'];
$d = date('d', strtotime($_GET['date']));
$m = date('m', strtotime($_GET['date']));
$y = date('Y', strtotime($_GET['date']));
$dayOfWeek = date("l",mktime(0,0,0, $m, $d,$y));
if ($dayOfWeek=="Sunday") $presjour=0;
if ($dayOfWeek=="Monday") $presjour=1;
if ($dayOfWeek=="Tuesday") $presjour=2;
if ($dayOfWeek=="Wednesday") $presjour=3;
if ($dayOfWeek=="Thursday") $presjour=4;
if ($dayOfWeek=="Friday") $presjour=5;
if ($dayOfWeek=="Saturday") $presjour=6;
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
//new_presta_id
//aaaaaaaaaaaaaaaaaaaaaaaaaaa a revoire
//ppppppppppppppppp
$dat = date("Ymd");
$i=0;
if ($prestat!=null){
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from1 AND date_finpln=$to1 AND presta_id=".$_GET['presta_id']." ");
$tablo11= array();
$tablo22= array();
$tablo33= array();
while ($p = dbi_fetch_row($plng1))
{
$tablo11[$i]=$p['inter_id'];
$tablo22[$i]=$p['date_debutpln'];
$tablo33[$i]=$p['date_finpln'];
$i++;
}
}
$j=0;
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$_GET['presta_id']." AND date_debutpln=$from1 AND date_finpln=$to1 ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=$newpresta AND date_debutpln=$from1 AND date_finpln=$to1 ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
//rajoute la mem chose pr presta_id
//bbbbbbbbbbbbbbbbbbbbbbbbbbb
dbi_query("DELETE FROM ".TABLE_PREST." WHERE presta_id in (SELECT new_presta_id FROM ".TABLE_EXCEPT." WHERE excpt_id = ".(int)$_GET['id']." and new_presta_id is not null) AND client_id = ".$_GET['client_id']." AND agence_id = $agence") ;
dbi_query("DELETE FROM ".TABLE_EXCEPT." WHERE presta_id in (SELECT presta_id FROM ".TABLE_PREST." WHERE client_id = ".$_GET['client_id']." AND agence_id = $agence) AND excpt_id = ".(int)$_GET['id']) ;
if ($tablo11[0]!=0) {// RECALCULE
$plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND inter_id=$tablo11[0] AND date_finpln=$to ");
if ($pres = dbi_fetch_row($plng))
{
$t=0;
if ($t<count($tablo22) ){
if ($prestat!=null) {
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id=$prestat AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$tablo11[$t]." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo11[$t].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$tablo11[$t]." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo11[$t].")))") ;
$offset = 0 ;
$indic=0;
if ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
if ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $tablo11[$t])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$tablo11[$t] ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$tablo11[$t]','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}
}
}// RECALCULE
{// RECALCULE
$t=0;
if ($t<count($tablo22)){
if ($prestat!=null) {
$from =$tablo22[$t];
$to = $tablo33[$t] ;
$plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=$prestat AND date_debutpln=$from AND date_finpln=$to ");
if ($pres = dbi_fetch_row($plng))
{}
else {
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id=$prestat AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$tablo11[$t]." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo11[$t].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$tablo11[$t]." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo11[$t].")))") ;
$offset = 0 ;
$indic=0;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
if ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $tablo11[$t])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$tablo11[$t] ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$tablo11[$t]','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}
}
}// RECALCULE
{// RECALCULE
$t=0;
while ($t<count($tablo1) ){
if ($newpresta!=null) {
$from =$tablo2[$t];
$to = $tablo3[$t] ;
$plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND inter_id=$tablo1[0] AND date_finpln=$to ");
if ($pres = dbi_fetch_row($plng))
{
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id=$newpresta AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$tablo1[$t]." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$tablo1[$t]." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")))") ;
$offset = 0 ;
$indic=0;
$from =$tablo2[$t];
$to = $tablo3[$t] ;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $tablo1[$t])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$tablo1[$t] ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$tablo1[$t]','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}
}
}// RECALCULE
$plnga = dbi_query("SELECT DISTINCT date_debutpln FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to ");
if ($tablo1[0]==null and $tablo11[0]==null and $sa = dbi_fetch_row($plnga) ){
$q1 = dbi_query("SELECT * FROM ".TABLE_PRESTA_MODIF." WHERE `id` = ( SELECT MAX(`id`) FROM ".TABLE_PRESTA_MODIF." WHERE presta_id = ".$prestat." and inter_id is not null ) ");
if($ma = dbi_fetch_row($q1))
{
$ma=$ma['inter_id'];
}
else {
$presti = dbi_query("SELECT * FROM ".TABLE_PREST." WHERE presta_id=".$prestat." ");
if($ma = dbi_fetch_row($presti)) {
$ma=$ma['inter_id'];
}
}
$t=0;
if ($prestat!=null) {//RECALCULE
$plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND inter_id=$ma ");
if ($pres = dbi_fetch_row($plng))
{
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id=$prestat AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$ma." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$ma.")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$ma." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$ma.")))") ;
$offset = 0 ;
$indic=0;
if ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
if ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $ma)
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id='".$ma."' ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','".$ma."','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}
}
//$q2 = dbi_query("SELECT * FROM ".TABLE_EXCEPT." e LEFT JOIN ".TABLE_PREST." p ON new_presta_id is not null and new_presta_id = p.presta_id WHERE e.presta_id = ".$prest['presta_id']." ORDER BY date, en_cours, excpt_id") ;
break ;
}
}
}
?>
<style type="text/css">
<!--
.first {
border:solid thin #000000 ;
}
-->
</style>
<div id="choixfils" style="position:absolute;top:25%;left:25%; width:50%; height:50%;background-color:#FFFFFF; border:solid grey thin; -moz-border-radius:10; text-align:center; display:none;">
<form action="aac3.php" target="edit" name="choixPresta">
<input type="hidden" name="presta_id">
<input type="hidden" name="recur">
<div style="font-weight:bold; font-size:xx-large; padding:50;">Quelle prestation modifier ?</div>
<div id="choixPresta" style="text-align:left ; margin-left:25%"></div>
<div style="padding:50;"><input type="submit" value="Modifier" onClick="document.getElementById('choixfils').style.display = 'none'"> <input type="button" value="Annuler" onClick="document.getElementById('choixfils').style.display = 'none'"></div>
</form>
</div>
<div class="onglet_dotted">
<table width="100%" cellspacing="0">
<tr>
<td valign="top" width="50%">
<?php
//$q = dbi_query("SELECT * FROM ".TABLE_PREST." p where p.agence_id=$agence AND client_id=".$_GET['client_id']." AND p.presta_id NOT IN (select new_presta_id from ".TABLE_EXCEPT." WHERE new_presta_id IS not null) AND (p.presta_date_fin is NULL OR p.presta_date_fin >= CURDATE()+0 OR EXISTS (SELECT * from ".TABLE_EXCEPT." e, ".TABLE_PREST." pe WHERE e.presta_id = p.presta_id AND e.new_presta_id = pe.presta_id AND pe.presta_date_debut >= CURDATE()+0 AND e.en_cours = '1' AND agence_id=$agence)) AND presta_recur = '1' ORDER BY presta_recur DESC, presta_jour DESC, presta_date_debut, presta_date_fin");
$q = dbi_query("SELECT *, IF((p.presta_date_fin is NULL OR p.presta_date_fin >= CURDATE()+0 OR EXISTS (SELECT * from ".TABLE_EXCEPT." e, ".TABLE_PREST." pe WHERE e.presta_id = p.presta_id AND e.new_presta_id = pe.presta_id AND pe.presta_date_debut >= CURDATE()+0 AND e.en_cours = '1' AND agence_id=$agence)),0,1) as finie FROM ".TABLE_PREST." p where p.agence_id=$agence AND client_id=".$_GET['client_id']." AND p.presta_id NOT IN (select new_presta_id from ".TABLE_EXCEPT." WHERE new_presta_id IS not null) AND (p.presta_date_fin is NULL OR p.presta_date_fin >= SUBDATE(CURDATE()+0, INTERVAL 1 YEAR) OR EXISTS (SELECT * from ".TABLE_EXCEPT." e, ".TABLE_PREST." pe WHERE e.presta_id = p.presta_id AND e.new_presta_id = pe.presta_id AND pe.presta_date_debut >= CURDATE()+0 AND e.en_cours = '1' AND agence_id=$agence)) AND presta_recur = '1' ORDER BY finie, presta_recur DESC, presta_jour DESC, presta_date_debut, presta_date_fin");
$print_p_r = (mysql_num_rows($q)>0);
if ($print_p_r) {
?>
<table cellpadding="2" cellspacing="0">
<?php
$jour = date('w') ;
$time = time() ;
while($jour != 0)
{
$jour = ++$jour %7 ;
$time += 24*3600 ;
}
$date = time2int($time) ;
while($prest = dbi_fetch_row($q))
{
$data = array('jour' => $prest['presta_jour'], 'deb' => $prest['presta_Hdeb'], 'duree' => $prest['presta_Hduree'], 'inter' => $prest['inter_id'], 'taux' => $prest['presta_forfait']) ;
$q1 = dbi_query("SELECT * FROM ".TABLE_PRESTA_MODIF." WHERE presta_id = ".$prest['presta_id']." order by `start`, `date`") ;
while (($m = dbi_fetch_row($q1)) && $date >= $m['start'])
{
$data['jour'] = $m['jour'] === NULL ? $data['jour'] : $m['jour'] ;
$data['deb'] = $m['Hdeb'] === NULL ? $data['deb'] : $m['Hdeb'] ;
$data['duree'] = $m['Hduree'] === NULL ? $data['duree'] : $m['Hduree'] ;
$data['inter'] = $m['inter_id'] === NULL ? $data['inter'] : $m['inter_id'] ;
$data['taux'] = $m['taux'] === NULL ? $data['taux'] : $m['taux'] ;
}
$inter = dbi_fetch_row(dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id = '".$data['inter']."' AND agence_id = $agence")) ;
$type = dbi_fetch_row(dbi_query("SELECT * FROM ".prestation_type." WHERE prestation_type_id = '".$prest['prestation_type']."' ")) ;
$jour = '' ;
foreach($sem as $i => $s)
if($data['jour'][$i] == 'y')
$jour .= $s ;
if ($prest['finie']) echo '<tr bgcolor="#CCCCCC">';
else echo '<tr>';
?>
<td width="70%"><iframe frameborder="0" allowtransparency width="100%" id="cal<?=$prest['presta_id']?>" src="cal2.php?presta_id=<?=$prest['presta_id']?>" height="180" scrolling="no"></iframe></td>
<td width="30%" valign="top"><a href="aac3.php?presta_id=<?=$prest['presta_id']?>" target="edit" style="cursor:pointer; font-weight:bold;color: white; text-decoration:none;" class="bigbutton">Editer</a><br /><br />
<b><?=$jour?> de <?=int2heure($data['deb'])?> à <?=int2heure(addDuree($data['deb'], $data['duree']))?></b><br /><br />
<b><?=($inter ? sprintf("%s %s %s", $inter['inter_genre'], $inter['inter_nom'], $inter['inter_pnom']) : '<span style="color:red;">Pas d\'intervenant choisi</span>')?></b><br><br>
Débute le <?=int2date($prest['presta_date_debut'])?><br />
Type de prestation : <?=($type['prestation_type_intitul'] ? sprintf("%s", $type['prestation_type_intitul']) : '<span style="color:red;">Pas de type choisi</span>')?><br />
<?=$prest['presta_date_fin'] ? '<b style="color:red">Fini le '.int2date($prest['presta_date_fin']).'</b>' : 'Pas de date de fin'?>
<br />
<a href="aac3.php?presta_id=<?=$prest['presta_id']?>&sup=date&recur" target="edit" style="cursor:pointer; font-weight:bold">Supprimer entre 2 dates</a>
</tr>
<tr>
<td colspan="2" align="left" style="font-size:10px">
<?php
$data = array('jour' => $prest['presta_jour'], 'deb' => $prest['presta_Hdeb'], 'duree' => $prest['presta_Hduree'], 'inter' => $prest['inter_id'], 'taux' => $prest['presta_forfait']) ;
list($data['inter']) = dbi_fetch_row(dbi_query("SELECT concat(inter_nom, ' ', inter_pnom) FROM ".TABLE_INTERV." WHERE inter_id = '".$data['inter']."' AND agence_id = $agence")) ;
$q1 = dbi_query("SELECT * FROM ".TABLE_PRESTA_MODIF." WHERE presta_id = ".$prest['presta_id']." order by `start`, `date`") ;
$q2 = dbi_query("SELECT * FROM ".TABLE_EXCEPT." e LEFT JOIN ".TABLE_PREST." p ON new_presta_id is not null and new_presta_id = p.presta_id WHERE e.presta_id = ".$prest['presta_id']." ORDER BY date, en_cours, excpt_id") ;
if (mysql_num_rows($q1)||mysql_num_rows($q2))
{
?>
<a href="#" onclick="hs('bc<?=$prest['presta_id']?>');return false;"><u><div id="bc<?=$prest['presta_id']?>_text" style="margin-top:0">Voir les modifications [+]</div></u></a><br />
<div style="display: none;" id="bc<?=$prest['presta_id']?>">
<?
if (mysql_num_rows($q1))
{
?>
<b>Modifications</b><br />
La prestation d'origine a lieu le <?=$sem[strpos($data['jour'], 'y')]?>, de <?=int2heure($data['deb'])?> à <?=int2heure(addDuree($data['deb'], $data['duree']))?> avec <?=$data['inter']?> au taux <?=$data['taux']?><br />
<?php
while ($m = dbi_fetch_row($q1))
{
if($m['inter_id'] !== NULL)
list($m['inter']) = dbi_fetch_row(dbi_query("SELECT concat(inter_nom, ' ', inter_pnom) FROM ".TABLE_INTERV." WHERE inter_id = '".$m['inter_id']."' AND agence_id = $agence")) ;
//v2
if($m['inter_id'] !== NULL)
?>
A partir du <?=int2date($m['start'])?>, la prestation <?=($m['jour'] != NULL || $m['Hdeb'] != NULL || $m['Hduree'] != NULL ? 'a lieu '.($m['jour'] === NULL ? '' : 'le '.$sem[strpos($m['jour'], 'y')]).($m['Hdeb'] === NULL ? '' : ' de '.int2heure($m['Hdeb'])).($m['Hduree'] === NULL ? '' : ' a '.int2heure(addDuree($m['Hdeb'], $m['Hduree']))).($m['inter'] === NULL ? '' :' et ') : '').(($m['inter'] === NULL ? '' : 'se fera avec '.$m['inter'])).(($m['taux'] === NULL ? '' : ' au taux '.$m['taux']))?> - <?php printf('<a href="aac3.php?del=modif&id=%d&client_id=%d&presta_id=%d&start=%d&interv_id=%d&" onClick="if(!confirm(\'Voulez-vous vraiement supprimer cette modification ?\')) return false ;">Supprimer</a><br>', $m['id'], $_GET['client_id'], $m['presta_id'], $m['start'], $m['inter_id'] ) ; ?>
<?php
}
}
if (mysql_num_rows($q2))
{
?>
<b>Exceptions</b><br />
<?php
while($e = dbi_fetch_row($q2)){
$inter = '' ;
if($e['new_presta_id'] !== NULL)
list($inter) = dbi_fetch_row(dbi_query("SELECT concat(inter_nom, ' ', inter_pnom) FROM ".TABLE_INTERV." WHERE inter_id = '".$e['inter_id']."' AND agence_id = $agence")) ;
?>
<!-- v2 -->
La prestation du <?=int2date($e['date']).($e['presta_date_debut'] != NULL && $e['date'] != $e['presta_date_debut'] ? ' est déplacée au '.int2date($e['presta_date_debut']).' et ' : ' est annulée').($e['presta_Hdeb'] === NULL ? '' : ' aura lieu de '.int2heure($e['presta_Hdeb'])).($e['presta_Hdeb'] === NULL ? '' : ' à ' . int2heure(addDuree($e['presta_Hdeb'], $e['presta_Hduree']))) . ($e['inter_id'] === NULL ? '' : ' avec ' . $inter) . ($e['presta_forfait'] === NULL ? '' : ' au taux ' . $e['presta_forfait']) . ($e['inter_abs'] == 1 ? ' (absence de l\'intervenant)' : '').($e['facture'] != 1 ? '' : ' (prestation d’origine facturée au client)')?> - <?php printf('<a href="aac3.php?del=excpt&id=%d&client_id=%d&presta_id=%d&new_presta_id=%d&date=%d&presta_dat=%d&inter_id=%d&" onClick="if(!confirm(\'Voulez-vous vraiement supprimer cette exception ?\')) return false ;">Supprimer</a><br>', $e['excpt_id'], $_GET['client_id'], $prest['presta_id'],$e['new_presta_id'], $e['date'], $e['presta_date_debut'], $e['inter_id']) ; ?>
<?php
}
}
?>
<br /><a href="#" onclick="hs('bc<?=$prest['presta_id']?>');return false;"><u>Cacher les modifications</u></a>
</div><br />
<?
}
?>
</td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
<?php
$q = dbi_query("SELECT * FROM ".TABLE_PREST." p LEFT JOIN ".TABLE_INTERV." i on p.inter_id = i.inter_id where presta_recur = '' AND presta_date_debut >= CURDATE()+0 AND p.agence_id=$agence AND client_id=".$_GET['client_id']." AND p.presta_id NOT IN (select new_presta_id from ".TABLE_EXCEPT." WHERE new_presta_id IS not null) ORDER BY presta_date_debut");
$print_p = (mysql_num_rows($q)>0);
if ($print_p) {
while($prest = dbi_fetch_row($q))
{
$type = dbi_fetch_row(dbi_query("SELECT * FROM ".prestation_type." WHERE prestation_type_id = '".$prest['prestation_type']."' ")) ;
printf('<p><a href="aac3.php?presta_id=%d" target="edit" style="cursor:pointer; font-weight:bold;">Editer</a><br />Prestation le %s de %s à %s<br />avec %s pour %s € / h <br/>Type de prestation : %s </p>',
$prest['presta_id'],
int2date($prest['presta_date_debut']),
int2heure($prest['presta_Hdeb']),
int2heure(addDuree($prest['presta_Hdeb'], $prest['presta_Hduree'])),
$prest['inter_nom'] ? sprintf("%s %s %s", $prest['inter_genre'], $prest['inter_nom'], $prest['inter_pnom']) : '<span style="color:red;">Pas d\'intervenant choisi</span>',
number_format($prest['presta_forfait'], 2, ',', ' '),$type['prestation_type_intitul'] ? $type['prestation_type_intitul'] : '<span style="color:red;">Pas de type choisi</span>') ;
}
}
echo (!$print_p && !$print_p_r) ? '<h2 align="center">Aucune prestation future</h2>' : '' ;
?>
</td>
<td valign="top" width="50%">
<iframe id="edit" name="edit"<?=!empty($_GET['presta_id']) ? ' src="aac3.php?presta_id='.$_GET['presta_id'].(!empty($_GET['recur']) ? '&recur='.$_GET['recur'] : '').'"' : ''?> width="100%" height="450" frameborder="0" allowtransparency></iframe>
</td>
</tr>
</table>
<?php
}
elseif (!empty($_POST['presta_id']))
{
if(isset($_POST['sup'])){
$from = sprintf("%04d%02d%02d", $_POST['debutyear'], $_POST['debutmonth'], $_POST['debutday']) ;
$to = sprintf("%04d%02d%02d", $_POST['finyear'], $_POST['finmonth'], $_POST['finday']) ;
$info = dbi_fetch_row(dbi_query("SELECT * FROM ".TABLE_PREST." WHERE presta_id=".$_POST['presta_id']."")) ;
$pre=array();
$pre=get_prest_sem( $_POST['presta_id'],$from ,$to,$agence);
// echo '<pre>';
// print_r($pre);
// echo '</pre>';
for($i=0;$i<count($pre);$i++)
{
// echo '// '.$pre[$i]['date'];
create_exception($_POST['presta_id'], $pre[$i]['date'], $_POST['modif'] == 2, NULL, NULL, NULL, NULL, NULL, $_POST['modif'] == 3 ,$add ,$ded,$Nduree ) ;
}
$update = true ;
}
else
{
$q = dbi_query("SELECT * FROM ".TABLE_PREST." p WHERE p.presta_id = ".$_POST['presta_id']." AND agence_id=$agence") ;
if(!$prest = dbi_fetch_row($q))
die('Numéro de prestation invalide</body></html>') ;
$update = false ;
if ($_POST['maj'])
{
$heure = sprintf('%02d%02d00', getPostValue('hs'), getPostValue('ms')) ;
$duree = ($_POST['hf'] - $_POST['hs'])*60+$_POST['mf']-$_POST['ms'] ;
$taux = (real)str_replace(',', '.', $_POST['taux']) ;
switch($_POST['type'])
{
case 0 : {//modification d'une prestation ponctuele
$date = getPostDate('recur');
$i=0;
$da = getPostDate('recur');
$d = date('d', strtotime($da));
$m = date('m', strtotime($da));
$y = date('Y', strtotime($da));
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
$plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND presta_id=".$_POST['presta_id']." ");
if ($pres = dbi_fetch_row($plng))
{
$presta_id=$_POST['presta_id'];
$da = getPostDate('recur');
$date = getPostDate('recur');
$i=0;
$d = date('d', strtotime($da));
$m = date('m', strtotime($da));
$y = date('Y', strtotime($da));
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
{
$plng1 = dbi_query("SELECT DISTINCT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND presta_id=".$_POST['presta_id']." ");
$tablo1= array();
$tablo2= array();
$tablo3= array();
while ($p = dbi_fetch_row($plng1))
{
$tablo1[$i]=$p['inter_id'];
$tablo2[$i]=$p['date_debutpln'];
$tablo3[$i]=$p['date_finpln'];
$i++;
}
$j=0;
while ($j<count($tablo1) )
{
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$_POST['presta_id']." AND inter_id=".$tablo1[$j]." AND date_debutpln=".$tablo2[$j]." AND date_finpln=".$tablo3[$j]." ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
}
//la nouvelle intervenante
}
if ($_POST['interv']!=$tablo1[0])
{ $dat = date("Ymd");
$j = date('d', strtotime($date));
$m = date('m', strtotime($date));
$a = date('Y', strtotime($date));
$dayOfWeek = date("l",mktime(0,0,0, $m, $j,$a));
if ($dayOfWeek=="Sunday") $presjour=0;
if ($dayOfWeek=="Monday") $presjour=1;
if ($dayOfWeek=="Tuesday") $presjour=2;
if ($dayOfWeek=="Wednesday") $presjour=3;
if ($dayOfWeek=="Thursday") $presjour=4;
if ($dayOfWeek=="Friday") $presjour=5;
if ($dayOfWeek=="Saturday") $presjour=6;
$i=0;
$db=debutsem($a,$m,$j);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND inter_id=".$_POST['interv']." AND presta_jour=$presjour ");
$tablo11= array();
$tablo22= array();
$tablo33= array();
if ($kl = dbi_fetch_row($plng1)){
$plng11 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND inter_id=".$_POST['interv']." AND presta_jour=$presjour ");
while ($p = dbi_fetch_row($plng11))
{
$tablo11[$i]=$p['inter_id'];
$tablo22[$i]=$p['date_debutpln'];
$tablo33[$i]=$p['date_finpln'];
$i++;
}
} else {
$plng44 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND inter_id=".$_POST['interv']." ");
if ($pa = dbi_fetch_row($plng44)){
$tablo11[$i]=$_POST['interv'];
$tablo22[$i]=$from;
$tablo33[$i]=$to;
}
}
$tablo11=array_unique ($tablo11);
$tablo22=array_unique ($tablo22);
$tablo33=array_unique ($tablo33);
$j=0;
while ($j<count($tablo11) )
{
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE inter_id=".$tablo11[$j]." AND date_debutpln=".$tablo22[$j]." AND date_finpln=".$tablo33[$j]." AND presta_jour=$presjour ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
}
}
// echo ' ==== ';
$update = dbi_query("UPDATE ".TABLE_PREST." SET presta_date_debut = ".getPostDate('recur').", prestation_type = '".$_POST['type_pre_id']."', chantier_id = '".$_POST['chantier_id']."',presta_date_fin = ".getPostDate('recur').", presta_Hdeb = $heure, presta_Hduree = $duree, presta_forfait = $taux, inter_id=".$_POST['interv'].", presta_desc = '".($_POST['presta_desc'])."' WHERE presta_id = ".$_POST['presta_id']) ;
if ($tablo1[0]!=0){// RECALCULE
$plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE inter_id=$tablo1[0] AND date_debutpln=$from AND date_finpln=$to ");
if ($pres = dbi_fetch_row($plng))
{
$t=0;
while ($t<count($tablo1) ){
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id=".$prest['presta_id']." AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$tablo1[$t]." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$tablo1[$t]." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")))") ;
$offset = 0 ;
$indic=0;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
if($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $tablo1[$t])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$tablo1[$t] ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$tablo1[$t]','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}
}// RECALCULE
{// RECALCULE
$t=0;
while ($t<count($tablo11) ){
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND inter_id=".$_POST['interv']." ");
if ($kl = dbi_fetch_row($plng1))
{
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$tablo11[$t]." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo11[$t].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$tablo11[$t]." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo11[$t].")))") ;
$offset = 0 ;
$indic=0;
$from =$tablo22[$t];
$to = $tablo33[$t] ;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $tablo11[$t])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($jour==$presjour)
{
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$from =$tablo22[$t];
$to = $tablo33[$t] ;
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$tablo11[$t] ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$tablo11[$t]','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}
}// RECALCULE
break;
}
else {
// echo ' +++++++++++++++++++++++++++++++++++ ';
$update = dbi_query("UPDATE ".TABLE_PREST." SET presta_date_debut = ".getPostDate('recur').", prestation_type = '".$_POST['type_pre_id']."', chantier_id = '".$_POST['chantier_id']."',presta_date_fin = ".getPostDate('recur').", presta_Hdeb = $heure, presta_Hduree = $duree, presta_forfait = $taux, inter_id=".$_POST['interv'].", presta_desc = '".($_POST['presta_desc'])."' WHERE presta_id = ".$_POST['presta_id']) ;
break ;
}
}
case 1 : $debut = getPostDate('debut') ;
$dat = date("Ymd");
$fin = isset($_POST['inconnue']) ? 'NULL' : getPostDate('fin');
$start = getPostDate('apartir') ;
if ($start=='00000000') $start=$dat;
$d = date('d', strtotime($start));
$m = date('m', strtotime($start));
$y = date('Y', strtotime($start));
$dayOfWeek = date("l",mktime(0,0,0, $m, $d,$y));
if ($dayOfWeek=="Sunday") $presjour=0;
if ($dayOfWeek=="Monday") $presjour=1;
if ($dayOfWeek=="Tuesday") $presjour=2;
if ($dayOfWeek=="Wednesday") $presjour=3;
if ($dayOfWeek=="Thursday") $presjour=4;
if ($dayOfWeek=="Friday") $presjour=5;
if ($dayOfWeek=="Saturday") $presjour=6;
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
/////
///// cree la semaine qui n'existe pas
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND presta_id=".$_POST['presta_id']." ");
if ($p = dbi_fetch_row($plng1))
{
}
else {
$req = dbi_query("SELECT * FROM ".TABLE_PREST." p where ( p.agence_id ='".$agence."' and presta_id=".$_POST['presta_id']." ) ");
$reqt = dbi_query("SELECT * FROM ".TABLE_PRESTA_MODIF." WHERE `id` = ( SELECT MAX(`id`) FROM ".TABLE_PRESTA_MODIF." WHERE presta_id = ".$_POST['presta_id']." AND inter_id is not null) ");
if ($gor = dbi_fetch_row($req))
$inter=$gor['inter_id'];
if ($gore = dbi_fetch_row($reqt))
$inter=$gore['inter_id'];
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE p.client_id=c.client_id AND p.presta_date_debut<=$dat AND (p.presta_date_fin >= $dat OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=$inter OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = $inter)) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = $inter OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = $inter)))") ;
$offset = 0 ;
$indic=0;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $inter)
{
//aaa
$j = date('d', strtotime($date['date']));
$m = date('m', strtotime($date['date']));
$a = date('Y', strtotime($date['date']));
$dayOfWeek = date("l",mktime(0,0,0, $m, $j,$a));
if ($dayOfWeek=="Sunday") $presjour=0;
if ($dayOfWeek=="Monday") $presjour=1;
if ($dayOfWeek=="Tuesday") $presjour=2;
if ($dayOfWeek=="Wednesday") $presjour=3;
if ($dayOfWeek=="Thursday") $presjour=4;
if ($dayOfWeek=="Friday") $presjour=5;
if ($dayOfWeek=="Saturday") $presjour=6;
sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = $date['recurrente'] ? $presjour : date('w', int2time($date['date'])) ;
for ($i = 0 ; $i < $date['duree']/15 && $deb+$i <= HEND ; $i++)
{
switch ($tab[$inter]['jours'][$jour][$deb+$i])
{
case 0 : $tab[$inter]['jours'][$jour][$deb+$i] = ($date['recurrente']+1)*2 ;
break ;
case 1 : $tab[$inter]['jours'][$jour][$deb+$i] = ($date['recurrente']+1)*2+1;
break ;
case 2 :
case 3 :
case 4 :
case 5 : $tab[$inter]['jours'][$jour][$deb+$i] = 6 ;
}
}
//aaa
//enregistre dans le planinge
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$inter ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['$client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$inter','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
//enregistre dans le planinge
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
}
////fin de la creation semaine
////
$plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id = ".$_POST['presta_id']." and date_debutpln=$from AND date_finpln=$to ");
if ($d = dbi_fetch_row($plng))
{
if($_POST['application'])
{ //echo "Modification sur les prestations a parti de la date de donnée";
$start = getPostDate('apartir') ;
//ssssssssssssssss
//supprime dans le planning et mise a joure
{ $dat = date("Ymd");
$i=0;
$d = date('d', strtotime($start));
$m = date('m', strtotime($start));
$y = date('Y', strtotime($start));
$dayOfWeek = date("l",mktime(0,0,0, $m, $d,$y));
if ($dayOfWeek=="Sunday") $presjour=0;
if ($dayOfWeek=="Monday") $presjour=1;
if ($dayOfWeek=="Tuesday") $presjour=2;
if ($dayOfWeek=="Wednesday") $presjour=3;
if ($dayOfWeek=="Thursday") $presjour=4;
if ($dayOfWeek=="Friday") $presjour=5;
if ($dayOfWeek=="Saturday") $presjour=6;
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
/////
////
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND presta_id=".$_POST['presta_id']." AND presta_jour>=$presjour ");
$tablo1= array();
$tablo2= array();
$tablo3= array();
while ($p = dbi_fetch_row($plng1))
{
$tablo1[$i]=$p['inter_id'];
$tablo2[$i]=$p['date_debutpln'];
$tablo3[$i]=$p['date_finpln'];
$i++;
}
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln>$to AND presta_id=".$_POST['presta_id']." ");
while ($p = dbi_fetch_row($plng1))
{
$tablo1[$i]=$p['inter_id'];
$tablo2[$i]=$p['date_debutpln'];
$tablo3[$i]=$p['date_finpln'];
$i++;
}
$j=0;
while ($j<count($tablo1) )
{
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$_POST['presta_id']." AND inter_id=".$tablo1[$j]." AND date_debutpln=".$tablo2[$j]." AND date_finpln=".$tablo3[$j]." ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
}
//la nouvelle intervenante }
}
//la nouvelle intervenante
//la nouvelle intervenante
// echo ' ---------------------- ';
$update = dbi_query("UPDATE ".TABLE_PREST." SET presta_date_debut=$debut, prestation_type = '".$_POST['type_pre_id']."',chantier_id = '".$_POST['chantier_id']."',presta_desc = '".$_POST['presta_desc']."', presta_date_fin=$fin WHERE presta_id = ".$_POST['presta_id']) ;
$jour = $h = $d = $inter = $tauxH = 'NULL' ;
$data = array('jour' => $prest['presta_jour'], 'deb' => $prest['presta_Hdeb'], 'duree' => $prest['presta_Hduree'], 'inter' => $prest['inter_id'], 'taux' => $prest['presta_forfait']) ;
$q = dbi_query("SELECT * FROM ".TABLE_PRESTA_MODIF." WHERE presta_id = ".$prest['presta_id']." order by `start`, `date`") ;
while (($m = dbi_fetch_row($q)) && $start >= $m['start'])
{
$data['jour'] = $m['jour'] === NULL ? $data['jour'] : $m['jour'] ;
$data['deb'] = $m['Hdeb'] === NULL ? $data['deb'] : $m['Hdeb'] ;
$data['duree'] = $m['Hduree'] === NULL ? $data['duree'] : $m['Hduree'] ;
$data['inter'] = $m['inter_id'] === NULL ? $data['inter'] : $m['inter_id'] ;
$data['taux'] = $m['taux'] === NULL ? $data['taux'] : $m['taux'] ;
}
if(jour2presta_jour($_POST['day']) != $data['jour'])
$jour = "'".jour2presta_jour($_POST['day'])."'" ;
if($heure != $data['deb'])
$h = $heure ;
if($duree != $data['duree'])
$d = $duree ;
if($_POST['interv'] != $data['inter'])
$inter = $_POST['interv'] ;
if($taux != $data['taux'])
$tauxH = $taux ;
if($jour != 'NULL' || $h != 'NULL' || $d != 'NULL' || $inter != 'NULL' || $tauxH != 'NULL')
$update += dbi_query("INSERT INTO ".TABLE_PRESTA_MODIF." (presta_id, `date`, start, jour, Hdeb, Hduree, inter_id, taux,ad,ded) VALUES (".$_POST['presta_id'].", NOW(), $start, $jour, $h, $d, $inter, $tauxH,'$add','$ded')") ;
$jour=strpos($jour, 'y');
{// RECALCULE
$t=0;
while ($t<count($tablo1) ){
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id='".$_POST['presta_id']."' AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$tablo1[$t]." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$tablo1[$t]." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")))") ;
$offset = 0 ;
$indic=0;
$from =$tablo2[$t];
$to = $tablo3[$t] ;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $tablo1[$t])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$from =$tablo2[$t];
$to = $tablo3[$t] ;
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$tablo1[$t] ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$tablo1[$t]','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}// RECALCULE
{// RECALCULE
$plog = dbi_query("SELECT DISTINCT date_debutpln,date_finpln FROM ".TABLE_PLNG." WHERE inter_id=$inter ");
while ($ko = dbi_fetch_row($plog))
{
if ($start<=$ko['date_finpln'])
{
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id='".$_POST['presta_id']."' AND p.client_id=c.client_id AND (p.presta_date_fin >= ".$start." OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=$inter OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = $inter)) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = $inter OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = $inter)))") ;
$offset = 0 ;
$indic=0;
$from =$ko['date_debutpln'];
$to = $ko['date_finpln'] ;
while ($d = dbi_fetch_row($dispo) )
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $inter)
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$inter ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$inter','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
}
}
}// RECALCULE
}
else{ //echo "Modification sur les prestations a parti de la date de debut";
$dat = date("Ymd");
$d = date('d', strtotime($dat));
$m = date('m', strtotime($dat));
$y = date('Y', strtotime($dat));
$dayOfWeek = date("l",mktime(0,0,0, $m, $d,$y));
if ($dayOfWeek=="Sunday") $presjour=0;
if ($dayOfWeek=="Monday") $presjour=1;
if ($dayOfWeek=="Tuesday") $presjour=2;
if ($dayOfWeek=="Wednesday") $presjour=3;
if ($dayOfWeek=="Thursday") $presjour=4;
if ($dayOfWeek=="Friday") $presjour=5;
if ($dayOfWeek=="Saturday") $presjour=6;
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
$i=0;
///////
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND presta_id=".$_POST['presta_id']." ");
$tablo1= array();
$tablo2= array();
$tablo3= array();
while ($p = dbi_fetch_row($plng1))
{
$tablo1[$i]=$p['inter_id'];
$tablo2[$i]=$p['date_debutpln'];
$tablo3[$i]=$p['date_finpln'];
$i++;
}
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln>$to AND presta_id=".$_POST['presta_id']." ");
while ($p = dbi_fetch_row($plng1))
{
$tablo1[$i]=$p['inter_id'];
$tablo2[$i]=$p['date_debutpln'];
$tablo3[$i]=$p['date_finpln'];
$i++;
}
$j=0;
while ($j<count($tablo1) )
{
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$_POST['presta_id']." AND inter_id=".$tablo1[$j]." AND date_debutpln=".$tablo2[$j]." AND date_finpln=".$tablo3[$j]." ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
}
///////
// echo ' !!!!!!!!!!!!!!!!!!!! ';
$update = dbi_query("UPDATE ".TABLE_PREST." SET presta_date_debut=$debut, prestation_type = '".$_POST['type_pre_id']."',chantier_id = '".$_POST['chantier_id']."', presta_date_fin=$fin, presta_desc='".($_POST['presta_desc'])."', presta_Hdeb = $heure, presta_Hduree = $duree, presta_forfait = $taux, inter_id = '".$_POST['interv']."', client_id=".$prest['client_id'].", presta_desc='".$_POST['presta_desc']."' , presta_jour = '".jour2presta_jour($_POST['day'])."' WHERE presta_id = ".$_POST['presta_id']) ;
// echo "UPDATE ".TABLE_PREST." SET presta_date_debut=$debut,chantier_id = ".getPostDate('chantier_id').", presta_date_fin=$fin, presta_desc='".($_POST['note'])."', presta_Hdeb = $heure, presta_Hduree = $duree, presta_forfait = $taux, inter_id = '".$_POST['interv']."', client_id=".$prest['client_id'].", presta_jour = '".jour2presta_jour($_POST['day'])."' WHERE presta_id = ".$_POST['presta_id'];
$jour=strpos(jour2presta_jour($_POST['day']), 'y');
{// RECALCULE
$t=0;
while ($t<count($tablo1) ){
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id='".$_POST['presta_id']."' AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$tablo1[$t]." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$tablo1[$t]." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")))") ;
$offset = 0 ;
$indic=0;
$from =$tablo2[$t];
$to = $tablo3[$t] ;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $tablo1[$t])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$from =$tablo2[$t];
$to = $tablo3[$t] ;
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$tablo1[$t] ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$tablo1[$t]','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}// RECALCULE
{// RECALCULE
$inter=$_POST['interv'];
$plog = dbi_query("SELECT DISTINCT date_debutpln,date_finpln FROM ".TABLE_PLNG." WHERE inter_id=$inter ");
while ($ko = dbi_fetch_row($plog))
{
if ($debut<=$ko['date_finpln'])
{
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id='".$_POST['presta_id']."' AND p.client_id=c.client_id AND (p.presta_date_fin >= ".$debut." OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=$inter OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = $inter)) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = $inter OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = $inter)))") ;
$offset = 0 ;
$indic=0;
$from =$ko['date_debutpln'];
$to = $ko['date_finpln'] ;
while ($d = dbi_fetch_row($dispo) )
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $inter)
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$inter ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$inter','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
}
}
}// RECALCULE
}
break ;
}
else
{
if($_POST['application'])
{
$start = getPostDate('apartir') ;
// echo ' ??????????????? ';
$update = dbi_query("UPDATE ".TABLE_PREST." SET presta_date_debut=$debut, presta_date_fin=$fin, prestation_type = '".$_POST['type_pre_id']."',chantier_id = '".$_POST['chantier_id']."', presta_desc='".($_POST['presta_desc'])."' WHERE presta_id = ".$_POST['presta_id']) ;
$jour = $h = $d = $inter = $tauxH = 'NULL' ;
$data = array('jour' => $prest['presta_jour'], 'deb' => $prest['presta_Hdeb'], 'duree' => $prest['presta_Hduree'], 'inter' => $prest['inter_id'], 'taux' => $prest['presta_forfait']) ;
$q = dbi_query("SELECT * FROM ".TABLE_PRESTA_MODIF." WHERE presta_id = ".$prest['presta_id']." order by `start`, `date`") ;
while (($m = dbi_fetch_row($q)) && $start >= $m['start'])
{
$data['jour'] = $m['jour'] === NULL ? $data['jour'] : $m['jour'] ;
$data['deb'] = $m['Hdeb'] === NULL ? $data['deb'] : $m['Hdeb'] ;
$data['duree'] = $m['Hduree'] === NULL ? $data['duree'] : $m['Hduree'] ;
$data['inter'] = $m['inter_id'] === NULL ? $data['inter'] : $m['inter_id'] ;
$data['taux'] = $m['taux'] === NULL ? $data['taux'] : $m['taux'] ;
}
if(jour2presta_jour($_POST['day']) != $data['jour'])
$jour = "'".jour2presta_jour($_POST['day'])."'" ;
if($heure != $data['deb'])
$h = $heure ;
if($duree != $data['duree'])
$d = $duree ;
if($_POST['interv'] != $data['inter'])
$inter = $_POST['interv'] ;
if($taux != $data['taux'])
$tauxH = $taux ;
// echo " $h ||| $d";
if($jour != 'NULL' || $h != 'NULL' || $d != 'NULL' || $inter != 'NULL' || $tauxH != 'NULL')
$update += dbi_query("INSERT INTO ".TABLE_PRESTA_MODIF." (presta_id, `date`, start, jour, Hdeb, Hduree, inter_id, taux,ad ,ded) VALUES (".$_POST['presta_id'].", NOW(), $start, $jour, $h, $d, $inter, $tauxH,'$ad','$ded')") ;
}
else
{
// echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// echo ' |||||| ';
$update = dbi_query("UPDATE ".TABLE_PREST." SET presta_date_debut=$debut, presta_date_fin=$fin, prestation_type = '".$_POST['type_pre_id']."', chantier_id = '".$_POST['chantier_id']."',presta_desc='".($_POST['presta_desc'])."', presta_Hdeb = $heure, presta_Hduree = $duree, presta_forfait = $taux, inter_id = '".$_POST['interv']."', client_id=".$prest['client_id'].", presta_jour = '".jour2presta_jour($_POST['day'])."' WHERE presta_id = ".$_POST['presta_id']) ;
// echo "UPDATE ".TABLE_PREST." SET presta_date_debut=$debut, presta_date_fin=$fin, chantier_id = ".getPostDate('chantier_id').",presta_desc='".($_POST['note'])."', presta_Hdeb = $heure, presta_Hduree = $duree, presta_forfait = $taux, inter_id = '".$_POST['interv']."', client_id=".$prest['client_id'].", presta_jour = '".jour2presta_jour($_POST['day'])."' WHERE presta_id = ".$_POST['presta_id'];
}
break ;
}
case 2 :
{ //echo "Modification sur une prestation";
$date1=$presta_date_debut;
$d1 = date('d', strtotime($date1));
$m1 = date('m', strtotime($date1));
$y1 = date('Y', strtotime($date1));
$db1=debutsem($y1,$m1,$d1);
$from1 = isset($db1) ? $db1 : time2int(time()-(date('w')-1)*24*3600) ;
$to1 = time2int(int2time($from1)+6*24*3600) ;
$date = getPostDate('recur');
$d = date('d', strtotime($date));
$m = date('m', strtotime($date));
$y = date('Y', strtotime($date));
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
$plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE date_debutpln=$from1 AND date_finpln=$to1 AND presta_id=".$prest['presta_id']." ");
{ $dat = date("Ymd");
$i=0;
$date = getPostDate('recur');
$d = date('d', strtotime($date));
$m = date('m', strtotime($date));
$y = date('Y', strtotime($date));
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
$plng1 = dbi_query("SELECT DISTINCT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from1 AND date_finpln=$to1 AND presta_id=".$prest['presta_id']." ");
$tablo1= array();
$tablo2= array();
$tablo3= array();
while ($p = dbi_fetch_row($plng1))
{
$tablo1[$i]=$p['inter_id'];
$tablo2[$i]=$p['date_debutpln'];
$tablo3[$i]=$p['date_finpln'];
$i++;
}
$j=0;
while ($j<count($tablo1) )
{
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$prest['presta_id']." AND inter_id=".$tablo1[$j]." AND date_debutpln=".$tablo2[$j]." AND date_finpln=".$tablo3[$j]." ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
}
//la nouvelle intervenante
}
if ($_POST['interv']!=$tablo1[0])
{ $dat = date("Ymd");
$j = date('d', strtotime($date));
$m = date('m', strtotime($date));
$a = date('Y', strtotime($date));
$dayOfWeek = date("l",mktime(0,0,0, $m, $j,$a));
if ($dayOfWeek=="Sunday") $presjour=0;
if ($dayOfWeek=="Monday") $presjour=1;
if ($dayOfWeek=="Tuesday") $presjour=2;
if ($dayOfWeek=="Wednesday") $presjour=3;
if ($dayOfWeek=="Thursday") $presjour=4;
if ($dayOfWeek=="Friday") $presjour=5;
if ($dayOfWeek=="Saturday") $presjour=6;
$i=0;
$db=debutsem($a,$m,$j);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND inter_id=".$_POST['interv']." AND presta_jour=$presjour ");
$tablo11= array();
$tablo22= array();
$tablo33= array();
if ($kl = dbi_fetch_row($plng1)){
$plng11 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND inter_id=".$_POST['interv']." AND presta_jour=$presjour ");
while ($p = dbi_fetch_row($plng11))
{
$tablo11[$i]=$p['inter_id'];
$tablo22[$i]=$p['date_debutpln'];
$tablo33[$i]=$p['date_finpln'];
$i++;
}
} else {
$plng44 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND inter_id=".$_POST['interv']." ");
if ($pa = dbi_fetch_row($plng44)){
$tablo11[$i]=$_POST['interv'];
$tablo22[$i]=$from;
$tablo33[$i]=$to;
}
}
$tablo11=array_unique ($tablo11);
$tablo22=array_unique ($tablo22);
$tablo33=array_unique ($tablo33);
$j=0;
while ($j<count($tablo11) )
{
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE inter_id=".$tablo11[$j]." AND date_debutpln=".$tablo22[$j]." AND date_finpln=".$tablo33[$j]." AND presta_jour=$presjour ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
}
}
// $duree = ($_POST['hf'] - $_POST['hs'])*60+$_POST['mf']-$_POST['ms'] ;
// echo " $duree || ";
// $duree = $duree
$update = create_exception($prest['presta_id'], $_POST['recur'], $_POST['modif']==2, $date, $heure, $duree, $taux, $_POST['interv'], $_POST['modif']==3 ,$add ,$ded ,$Nduree ,$_POST['chantier_id'] ,$_POST['type_pre_id'],$_POST['presta_desc']) ;
if ($tablo1[0]!=0){// RECALCULE
$plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE inter_id=$tablo1[0] AND date_debutpln=$from AND date_finpln=$to ");
if ($pres = dbi_fetch_row($plng))
{
$t=0;
while ($t<count($tablo1) ){
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id=".$prest['presta_id']." AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$tablo1[$t]." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$tablo1[$t]." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")))") ;
$offset = 0 ;
$indic=0;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
if($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $tablo1[$t])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$tablo1[$t] ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$tablo1[$t]','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}
}// RECALCULE
{// RECALCULE
$t=0;
while ($t<count($tablo11) ){
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND inter_id=".$_POST['interv']." ");
if ($kl = dbi_fetch_row($plng1))
{
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$tablo11[$t]." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo11[$t].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$tablo11[$t]." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo11[$t].")))") ;
$offset = 0 ;
$indic=0;
$from =$tablo22[$t];
$to = $tablo33[$t] ;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $tablo11[$t])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($jour==$presjour)
{
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$from =$tablo22[$t];
$to = $tablo33[$t] ;
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$tablo11[$t] ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$tablo11[$t]','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}
}// RECALCULE
break ;
}
case 3 : {//echo "Modification"
//echo "µµµµµµµµµµdate de fin de prestation";
$p = get_occurence($prest['presta_id'], $_POST['offset'], $_POST['recur']) ;
$e = dbi_fetch_row(dbi_query("SELECT date FROM ".TABLE_EXCEPT." e WHERE excpt_id=".$p['except'])) ;
$date = getPostDate('recur');
$abs = $_POST['modif'] == 3 ;
$fact = $_POST['modif'] == 2 ;
$update = create_exception($prest['presta_id'], $e['date'], $fact, $date, $heure, $duree, $taux, $_POST['interv'], $abs,$add ,$ded ,$Nduree ,$_POST['chantier_id'] ,$_POST['type_pre_id'],$_POST['presta_desc']) ;
break ;
}
}
}
else
{
switch (@$_POST['type'])
{
case 0 : {//supression d'une prestation ponctuele
$presta_id=$_POST['presta_id'];
$dat = date("Ymd");
$i=0;
$from = isset($_GET['date']) ? $_GET['date'] : time2int(time()-(date('w')-1)*24*3600) ;
$plng1 = dbi_query("SELECT DISTINCT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln>=$from AND presta_id=".$_POST['presta_id']." ");
$tablo1= array();
$tablo2= array();
$tablo3= array();
while ($p = dbi_fetch_row($plng1))
{
$tablo1[$i]=$p['inter_id'];
$tablo2[$i]=$p['date_debutpln'];
$tablo3[$i]=$p['date_finpln'];
$i++;
}
$j=0;
while ($j<count($tablo1) )
{
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$_POST['presta_id']." AND inter_id=".$tablo1[$j]." AND date_debutpln=".$tablo2[$j]." AND date_finpln=".$tablo3[$j]." ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
}
$update = dbi_query('DELETE FROM '.TABLE_PREST.' WHERE presta_id = '.$_POST['presta_id']) ;
{// RECALCULE
$t=0;
while ($t<count($tablo1) ){
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id='$prestat_id' AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$tablo1[$t]." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$tablo1[$t]." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")))") ;
$offset = 0 ;
$indic=0;
$from =$tablo2[$t];
$to = $tablo3[$t] ;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $tablo1[$t])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$from =$tablo2[$t];
$to = $tablo3[$t] ;
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$tablo1[$t] ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$tablo1[$t]','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}// RECALCULE
//create_alerte ("Annulation d'un presatation ponctuelle", sprintf("La prestation ponctuelle du %s de %s à %s a été annulée", int2date($prest['presta_date_debut']), int2heure($prest['presta_Hdeb']), int2heure(addDuree($prest['presta_Hdeb'], $prest['presta_Hduree']))), $prest['client_id'], NULL, NULL, $prest['inter_id']) ;
break;
}
case 1 :
$fin = getPostDate('apartir') ;
$dat = date("Ymd");
$i=0;
$d = date('d', strtotime($fin));
$m = date('m', strtotime($fin));
$y = date('Y', strtotime($fin));
$dayOfWeek = date("l",mktime(0,0,0, $m, $d,$y));
if ($dayOfWeek=="Sunday") $presjour=0;
if ($dayOfWeek=="Monday") $presjour=1;
if ($dayOfWeek=="Tuesday") $presjour=2;
if ($dayOfWeek=="Wednesday") $presjour=3;
if ($dayOfWeek=="Thursday") $presjour=4;
if ($dayOfWeek=="Friday") $presjour=5;
if ($dayOfWeek=="Saturday") $presjour=6;
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
$plng = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$_POST['presta_id']." ");
if ($d = dbi_fetch_row($plng))
{
if ($_POST['application'])
{//suprime ensemble de prestation a partire de la date actuele
$fin = getPostDate('apartir') ;
$dat = date("Ymd");
$i=0;
$d = date('d', strtotime($fin));
$m = date('m', strtotime($fin));
$y = date('Y', strtotime($fin));
$dayOfWeek = date("l",mktime(0,0,0, $m, $d,$y));
if ($dayOfWeek=="Sunday") $presjour=0;
if ($dayOfWeek=="Monday") $presjour=1;
if ($dayOfWeek=="Tuesday") $presjour=2;
if ($dayOfWeek=="Wednesday") $presjour=3;
if ($dayOfWeek=="Thursday") $presjour=4;
if ($dayOfWeek=="Friday") $presjour=5;
if ($dayOfWeek=="Saturday") $presjour=6;
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
//dd
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln=$from AND date_finpln=$to AND presta_id=".$_POST['presta_id']." AND presta_jour>$presjour ");
$tablo1= array();
$tablo2= array();
$tablo3= array();
while ($p = dbi_fetch_row($plng1))
{
$tablo1[$i]=$p['inter_id'];
$tablo2[$i]=$p['date_debutpln'];
$tablo3[$i]=$p['date_finpln'];
$i++;
}
$plng1 = dbi_query("SELECT date_debutpln,date_finpln,presta_id,inter_id FROM ".TABLE_PLNG." WHERE date_debutpln>$to AND presta_id=".$_POST['presta_id']." ");
while ($p = dbi_fetch_row($plng1))
{
$tablo1[$i]=$p['inter_id'];
$tablo2[$i]=$p['date_debutpln'];
$tablo3[$i]=$p['date_finpln'];
$i++;
}
$j=0;
while ($j<count($tablo1) )
{
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$_POST['presta_id']." AND inter_id=".$tablo1[$j]." AND date_debutpln=".$tablo2[$j]." AND date_finpln=".$tablo3[$j]." ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
}
//ddd
dbi_query("DELETE FROM ".TABLE_PREST." WHERE presta_id IN (SELECT new_presta_id FROM ".TABLE_EXCEPT." e WHERE e.presta_id=".$_POST['presta_id']." AND new_presta_id is not null) AND presta_date_debut >= $fin") ;
dbi_query("DELETE FROM ".TABLE_PRESTA_MODIF." WHERE start >= $fin AND presta_id = ".$_POST['presta_id']) ;
if(get_occurence($_POST['presta_id'], -1))
{
// echo " ---------- ";
$update = dbi_query('UPDATE '.TABLE_PREST." SET presta_date_fin = $fin-1 WHERE presta_id = ".$_POST['presta_id']) ;
dbi_query("UPDATE ".TABLE_EXCEPT." SET new_presta_id = NULL, inter_abs='$absence' WHERE new_presta_id NOT IN (SELECT presta_id FROM ".TABLE_PREST.")") ;
}
else
{
dbi_query("DELETE FROM ".TABLE_EXCEPT." WHERE presta_id = ".$_POST['presta_id']) ;
$update = dbi_query('DELETE FROM '.TABLE_PREST." WHERE presta_id = ".$_POST['presta_id']) ;
}
}
else
{ //suprime ensemble des prestation des le premier jour de la prestation
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$_POST['presta_id']." ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
dbi_query("DELETE FROM ".TABLE_PREST." WHERE presta_id IN (SELECT new_presta_id FROM ".TABLE_EXCEPT." e WHERE e.presta_id=".$_POST['presta_id']." AND new_presta_id is not null)") ;
dbi_query("DELETE FROM ".TABLE_EXCEPT." WHERE presta_id = ".$_POST['presta_id']) ;
dbi_query("DELETE FROM ".TABLE_PRESTA_MODIF." WHERE presta_id = ".$_POST['presta_id']) ;
$update = dbi_query('DELETE FROM '.TABLE_PREST." WHERE presta_id = ".$_POST['presta_id']) ;
}
break ;
}
else
{
if($_POST['application'])
{
dbi_query("DELETE FROM ".TABLE_PREST." WHERE presta_id IN (SELECT new_presta_id FROM ".TABLE_EXCEPT." e WHERE e.presta_id=".$_POST['presta_id']." AND new_presta_id is not null) AND presta_date_debut >= $fin") ;
dbi_query("DELETE FROM ".TABLE_PRESTA_MODIF." WHERE start >= $fin AND presta_id = ".$_POST['presta_id']) ;
if(get_occurence($_POST['presta_id'], -1))
{
// echo "++++++++";
$update = dbi_query('UPDATE '.TABLE_PREST." SET presta_date_fin = $fin-1 WHERE presta_id = ".$_POST['presta_id']) ;
dbi_query("UPDATE ".TABLE_EXCEPT." SET new_presta_id = NULL, inter_abs='$absence' WHERE new_presta_id NOT IN (SELECT presta_id FROM ".TABLE_PREST.")") ;
}
else
{
dbi_query("DELETE FROM ".TABLE_EXCEPT." WHERE presta_id = ".$_POST['presta_id']) ;
$update = dbi_query('DELETE FROM '.TABLE_PREST." WHERE presta_id = ".$_POST['presta_id']) ;
}
}
else
{
dbi_query("DELETE FROM ".TABLE_PREST." WHERE presta_id IN (SELECT new_presta_id FROM ".TABLE_EXCEPT." e WHERE e.presta_id=".$_POST['presta_id']." AND new_presta_id is not null)") ;
dbi_query("DELETE FROM ".TABLE_EXCEPT." WHERE presta_id = ".$_POST['presta_id']) ;
dbi_query("DELETE FROM ".TABLE_PRESTA_MODIF." WHERE presta_id = ".$_POST['presta_id']) ;
$update = dbi_query('DELETE FROM '.TABLE_PREST." WHERE presta_id = ".$_POST['presta_id']) ;
}
break ;
}
case 2 : {//echo "supression UNE prestation";
{
$date1=$presta_date_debut;
$d1 = date('d', strtotime($date1));
$m1 = date('m', strtotime($date1));
$y1 = date('Y', strtotime($date1));
$db1=debutsem($y1,$m1,$d1);
$from = isset($db1) ? $db1 : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
$inetvenen='';
$i=0;
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$_POST['presta_id']." AND date_debutpln=".$from." AND date_finpln=".$to." ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
$update = create_exception($_POST['presta_id'], $_POST['recur'], $_POST['modif'] == 2, NULL, NULL, NULL, NULL, NULL, $_POST['modif'] == 3,$add ,$ded ,$Nduree,$_POST['chantier_id'] ,$_POST['type_pre_id'],$_POST['presta_desc']) ;
/*{// RECALCULE
$t=0;
while ($t<count($tablo1) ){
$dispo = dbi_query("SELECT * FROM ".TABLE_PREST." p, ".TABLE_CLIENT." c WHERE presta_id=".$_POST['presta_id']." AND p.client_id=c.client_id AND (p.presta_date_fin >= $from OR p.presta_date_fin is null) AND p.agence_id=$agence AND (p.inter_id=".$tablo1[$t]." OR EXISTS( SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")) AND p.presta_id NOT IN (SELECT DISTINCT new_presta_id FROM ".TABLE_EXCEPT." e, ".TABLE_PREST." p WHERE e.new_presta_id is not null AND e.presta_id=p.presta_id AND (inter_id = ".$tablo1[$t]." OR EXISTS(SELECT * FROM ".TABLE_PRESTA_MODIF." pm WHERE pm.inter_id is not null AND p.presta_id = pm.presta_id AND inter_id = ".$tablo1[$t].")))") ;
$offset = 0 ;
$indic=0;
$from =$tablo2[$t];
$to = $tablo3[$t] ;
while ($d = dbi_fetch_row($dispo))
{
$date = get_occurence($d['presta_id'], 0, $from,0,"plan") ;
$last = 0 ;
//echo "<br>///////////////////////////////////////".$indic;
$indic++;
while ($date && $date['date'] <= $to && $date['date'] >= $from)
{
if($date['inter'] == $tablo1[$t])
{
//sscanf(sprintf("%06d", $date['deb']), "%02d%02d00", $h, $m) ;
$deb = $h*4+$m/15 ;
$jour = date('w', int2time($date['date'])) ;
if ($date['deb']==null){
$prestdebut=$d['presta_Hdeb'];
$prestfin=$d['presta_Hduree'];
}
else {
$prestdebut=$date['deb'];
$prestfin=$date['duree'];
}
$dat = date("Ymd");
$timestamp = date('His');
$from =$tablo2[$t];
$to = $tablo3[$t] ;
$reqint = dbi_query("SELECT * FROM ".TABLE_INTERV." WHERE inter_id=$tablo1[$t] ");
if ($int = dbi_fetch_row($reqint)){
$inter_genre=$int['inter_genre'];
$inter_nom=addslashes($int['inter_nom']);
$inter_pnom=addslashes($int['inter_pnom']);
$inter_adr1=addslashes($int['inter_adr1']);
$inter_cp=$int['inter_cp'];
$inter_ville=addslashes($int['inter_ville']);
$inter_teldomi=$int['inter_teldomi'];
$inter_telport=$int['inter_telport'];
$inter_zones_id=$int['inter_zones_id'];
$inter_chien=$int['inter_chien'];
$inter_chat=$int['inter_chat'];
$inter_vehicule=$int['inter_vehicule'];
$inter_repass=$int['inter_repass'];
$inter_menage=$int['inter_menage'];
}
$client_adr1=addslashes($d['client_adr1']);
$client_nom=addslashes($d['client_nom']);
$client_pnom=addslashes($d['client_pnom']);
$client_ville=addslashes($d['client_ville']);
list($heures_contrat)=dbi_fetch_row(dbi_query("SELECT contrat_heure FROM ".TABLE_CONTRAT." WHERE inter_id = ".$tablo1[$t]." AND agence_id = ".$agence." AND contrat_debut<=".$from." AND ( contrat_fin IS NULL OR contrat_fin >".$from." ) ORDER BY contrat_debut DESC"));
$a = heuresSemaine($tablo1[$t] , $from, $to, &$sem);
//,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`
// enregistrement dans planning
$sql = "INSERT INTO ".TABLE_PLNG." ( `client_id`,`client_nom` , `client_pnom` , `client_adr1` , `client_cp` , `client_ville`, `client_teldom` , `client_telport1` , `client_telport2` , `client_telpro`, `client_zones_id` , agence_id,`presta_id`,`presta_date_debut`,`presta_Hdeb`,`presta_Hduree`,`presta_recur`, `presta_date_fin`,`presta_jour`,`presta_forfait`,`presta_forfaitHT`,`inter_id`,`date_debutpln`,`date_finpln`,`date_pln`,`pln_Hdeb`,`inter_genre`,`inter_nom`,`inter_pnom`,`inter_adr1`,`inter_cp`,`inter_ville`,`inter_teldomi`,`inter_telport`,`inter_zones_id`,`inter_chien`,`inter_chat`,`inter_vehicule`,`inter_repass`,`inter_menage`,`heur_semain`,`contrat_heure`)
VALUES (
'".$d['client_id']."','$client_nom', '$client_pnom', '$client_adr1', '".$d['client_cp']."', '$client_ville', '".$d['client_teldom']."', '".$d['client_telport1']."', '".$d['client_telport2']."', '".$d['client_telpro']."', '".$d['client_zones_id']."', '$agence','".$d['presta_id']."','".$d['presta_date_debut']."','".$prestdebut."','".$prestfin."','".$d['presta_recur']."','".$d['presta_date_fin']."','$jour','".$d['presta_forfait']."','".$d['presta_forfaitHT']."','$tablo1[$t]','$from','$to','$dat','$timestamp','$inter_genre','$inter_nom','$inter_pnom','$inter_adr1','$inter_cp','$inter_ville','$inter_teldomi','$inter_telport','$inter_zones_id','$inter_chien','$inter_chat','$inter_vehicule','$inter_repass','$inter_menage','".$sem['ht']."','$heures_contrat')";
dbi_query ( $sql );
}
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$date = get_occurence($d['presta_id'], 1+$offset, $date['date'],0,"plan") ;
//echo "<br> // date=".$date['date']." last=".$last;
//echo "<br> test date=<pre>".print_r($date)."</pre>";
}
}
//aaaaaaaaaaaaaaaaaaaaaaaaa
$t++;
}
}// RECALCULE*/
}
break ;
}
case 3 : {// supression une prestation en date ulterieur
$q = get_occurence($prest['presta_id'], $_POST['offset'], $_POST['recur']) ;
$q = dbi_fetch_row(dbi_query("SELECT date FROM ".TABLE_EXCEPT." e WHERE en_cours='1' AND e.excpt_id = ".$q['except'])) ;
$da=$q['date'];
$d = date('d', strtotime($da));
$m = date('m', strtotime($da));
$y = date('Y', strtotime($da));
$db=debutsem($y,$m,$d);
$from = isset($db) ? $db : time2int(time()-(date('w')-1)*24*3600) ;
$to = time2int(int2time($from)+6*24*3600) ;
$plnga = dbi_query("SELECT * FROM ".TABLE_PLNG." WHERE presta_id=".$_POST['presta_id']." AND date_debutpln=$from AND date_finpln=$to ");
while ($pa = dbi_fetch_row($plnga)){
dbi_query("DELETE FROM ".TABLE_PLNG." WHERE planning_id=".$pa['planning_id']." ") ;
}
$j++;
$update = create_exception($_POST['presta_id'], $q['date'], $_POST['modif'] == 2, NULL, NULL, NULL, NULL, NULL, $_POST['modif'] == 3 ,$add ,$ded ,$Nduree ,$_POST['chantier_id'] ,$_POST['type_pre_id'],$_POST['presta_desc']) ;
}
}
}
}
if($update)
echo '<script language="javascript">
<!--
parent.location.replace(parent.location);
-->
</script>
' ;
die();
}
if(!empty($_GET['presta_id']))
{
if (!empty($_POST['presta_id']))
$_GET = array_merge($_GET, $_POST) ;
$q = dbi_query("SELECT * FROM ".TABLE_PREST." p WHERE agence_id=$agence AND p.presta_id = ".$_GET['presta_id']) ;
if(!$prest = dbi_fetch_row($q))
die('Numéro de prestation invalide</body></html>') ;
$hs = $hf = $ms = $mf = 0 ;
$excpt = 0 ;
if($prest['presta_recur'])
{
$jour = date('w') ;
$time = time() ;
while($jour != 0)
{
$jour = ++$jour %7 ;
$time += 24*3600 ;
}
$date = time2int($time) ;
$q1 = dbi_query("SELECT * FROM ".TABLE_PRESTA_MODIF." WHERE presta_id = ".$prest['presta_id']." order by `start`, `date`") ;
while (($m = dbi_fetch_row($q1)) && $date >= $m['start'])
{
$prest['presta_jour'] = $m['jour'] === NULL ? $prest['presta_jour'] : $m['jour'] ;
$prest['presta_Hdeb'] = $m['Hdeb'] === NULL ? $prest['presta_Hdeb'] : $m['Hdeb'] ;
$prest['presta_Hduree'] = $m['Hduree'] === NULL ? $prest['presta_Hduree'] : $m['Hduree'] ;
$prest['inter_id'] = $m['inter_id'] === NULL ? $prest['inter_id'] : $m['inter_id'] ;
$prest['presta_forfait'] = $m['taux'] === NULL ? $prest['presta_forfait'] : $m['taux'] ;
}
}
// echo $prest['presta_Hduree'].' /// ';
list($hs,$ms) = explode('h',int2heure($prest['presta_Hdeb'])) ;
list($hf,$mf) = explode('h',int2heure(addDuree($prest['presta_Hdeb'], $prest['presta_Hduree']))) ;
$jour = strpos($prest['presta_jour'], 'y') ;
$salarie = $prest['inter_id'] ;
$forfait = $prest['presta_forfait'] ;
$presta_Hduree = $prest['presta_Hduree'] ;
$chantier_id=$prest['chantier_id'];
$type_pre_id=$prest['prestation_type'];
$presta_desc = $prest['presta_desc'];
// echo "$hs ++++++++++++++";
if (!empty($_GET['recur']) && $prest['presta_recur'])
{
// echo "/// ";
$e = get_occurence($prest['presta_id'], $_GET['offset'], $_GET['recur']) ;
sscanf(sprintf('%06d', $e['deb']), "%02d%02d00", $hs,$ms) ;
// echo "$hs ++++++++++++++";
sscanf(sprintf('%06d', addDuree($e['deb'], $e['duree'])), "%02d%02d00",$hf,$mf) ;
$presta_Hduree = $e['duree'];
$jour = int2date($e['date'],'w') ;
$salarie = $e['inter'] ;
$forfait = $e['taux'] ;
$excpt = $e['except'] ;
$chantier_id=$e['chantier_id'];
$type_pre_id=$e['prestation_type'];
$presta_desc = $e['presta_desc'];
// echo ' //////// $type_pre_id';
// print_r($e);
// print_r($e['date']);
// echo " ?? ".$prest['presta_id'];
$qex = dbi_fetch_row(dbi_query("SELECT excpt_id FROM ".TABLE_EXCEPT." WHERE en_cours='1' AND new_presta_id IS NOT NULL AND date = ".$e['date']." AND presta_id = ".$prest['presta_id'])) ;
}
$type = $prest['presta_recur']+(!empty($_GET['recur']))+($excpt!=0) ;
$client_id=$prest['client_id'];
// print_r($prest);
// echo " +++++++++++++++++++++++ $presta_desc $chantier_id";
function get_chantier_drop_down($name = '', $param = '', $value ='', $choose = 'auto')
{
global $agence ;
global $client_id;
if(!is_array($value))
$value = array($value) ;
$ret = "<select onchange='GetIdBureau()'; name=\"$name\" $param>".((in_array('', $value) || in_array('0', $value)) && count($value) == 1 && $choose == 'auto' || $choose === true ? '<option value="" selected style="font-weight:bold"></option>' : '') ;
$q = dbi_query("SELECT * FROM chantier c, fact_chantier fc WHERE agence_id=".$agence." AND Client_ID=".$client_id." AND c.Chantier_ID=fc.Chantier_ID") ;
while($res = dbi_fetch_row($q)) {
$ret .= sprintf('<option value="%s"%s>%s </option>', $res['ID'], in_array($res['ID'], $value) ? ' selected' : '', $res['Chantier_designation']) ;
}
return $ret."</select>" ;
}
function get_type_pre_drop_down($name = '', $param = '', $value ='', $choose = 'auto')
{
global $agence ;
global $client_id;
if(!is_array($value))
$value = array($value) ;
$ret = "<select onchange='GetIdBureau()'; name=\"$name\" $param>".((in_array('', $value) || in_array('0', $value)) && count($value) == 1 && $choose == 'auto' || $choose === true ? '<option value="" selected style="font-weight:bold"></option>' : '') ;
$q = dbi_query("SELECT * FROM prestation_type") ;
while($res = dbi_fetch_row($q)) {
$ret .= sprintf('<option value="%s"%s>%s </option>', $res['prestation_type_id'], in_array($res['prestation_type_id'], $value) ? ' selected' : '', $res['prestation_type_intitul']) ;
}
return $ret."</select>" ;
}
?>
<script language="javascript" type="text/javascript">
<!--
function changes (form)
{
form.hs.value = /^[0-9]{1,2}$/.test(form.hs.value) ? form.hs.value : 0 ;
form.ms.value = /^[0-9]{1,2}$/.test(form.ms.value) ? form.ms.value : 0 ;
form.hf.value = /^[0-9]{1,2}$/.test(form.hf.value) ? form.hf.value : 0 ;
form.mf.value = /^[0-9]{1,2}$/.test(form.mf.value) ? form.mf.value : 0 ;
}
function difheure(heuredeb,heurefin)
{
hd=heuredeb.split(":");
hf=heurefin.split(":");
hd[0]=eval(hd[0]);hd[1]=eval(hd[1]);hd[2]=eval(hd[2]);
hf[0]=eval(hf[0]);hf[1]=eval(hf[1]);hf[2]=eval(hf[2]);
if(hf[2]<hd[2]){hf[1]=hf[1]-1;hf[2]=hf[2]+60;}
if(hf[1]<hd[1]){hf[0]=hf[0]-1;hf[1]=hf[1]+60;}
if(hf[0]<hd[0]){hf[0]=hf[0]+24;}
//return((hf[0]-hd[0]) + ":" + (hf[1]-hd[1])); // + ":" + (hf[2]-hd[2]));
return((hf[0]-hd[0])*60 + (hf[1]-hd[1]));
}
function question(MoiMeme)
{
var form = MoiMeme.form ;
var modif = form.maj[0].checked ;
var type = <?=$type?> ;
var content = "" ;
if(!modif && !form.maj[1].checked)
{
alert('Vous devez choisir une action') ;
return ;
}
if(type == 1 && !form.application[0].checked && !form.application[1].checked)
{
alert("Vous devez choisir une date d'application") ;
return ;
}
if(modif)
{
var newduree;
var cont = "" ;
var hf = form.hf.value;
var mf = form.mf.value;
var hs = form.hs.value;
var ms = form.ms.value;
var deb,fin,d,excpt;
deb=hs+':'+ms;
fin=hf+':'+mf;
newduree = difheure(deb,fin);
// alert(d+' / '+form.presta_Hduree.value);
// var k = Integer.valueOf(String.valueOf(form.hs.value) + String.valueOf(form.ms.value));
// newduree = (((form.hf.value*100)+form.mf.value ) - ((form.hs.value*100)+form.ms.value));
// alert(newduree+' / '+form.presta_Hduree.value+' //// '+l);
//
excpt = form.excpt.value;
if(excpt>0)
{
alert('Vous tentez de modifier une prestation qui a déjà été modifiée, merci de supprimer la première exception avant de continuer');
return ;
}
else
if( newduree != form.presta_Hduree.value)
{
if(newduree < form.presta_Hduree.value)
{
cont = 'La nouvelle durée de la prestation est inférieure à la durée de la prestation initiale ';
document.getElementById('recap2').innerHTML = cont ;
document.getElementById('first').style.display = 'none' ;
document.getElementById('secondd').style.display = '' ;
document.getElementById('second3').style.display = '' ;
document.getElementById("3").disabled=true;
document.getElementById("4").disabled=true;
// document.form.ad.disabled = true;
}
else
{
cont = 'La nouvelle durée est supérieure à la durée de la prestation initiale ';
document.getElementById('recap2').innerHTML = cont ;
document.getElementById('first').style.display = 'none' ;
document.getElementById('secondd').style.display = '' ;
document.getElementById('second4').style.display = '' ;
document.getElementById("1").disabled=true;
document.getElementById("2").disabled=true;
// document.form.ded.disabled = true;
}
}
if(type != 1 && (!form.recurday.options[form.recurday.selectedIndex].defaultSelected || !form.recurmonth.options[form.recurmonth.selectedIndex].defaultSelected || !form.recuryear.options[form.recuryear.selectedIndex].defaultSelected))
content += '<br>Date de la prestation modifiée au '+form.recurday.options[form.recurday.selectedIndex].text+' '+form.recurmonth.options[form.recurmonth.selectedIndex].text+' '+form.recuryear.options[form.recuryear.selectedIndex].text ;
else if (type == 1)
{
if(!form.type_pre_id.options[form.type_pre_id.selectedIndex].defaultSelected)
content += '<br>type prestation remplacé par '+form.type_pre_id.options[form.type_pre_id.selectedIndex].text;
if(!form.chantier_id.options[form.chantier_id.selectedIndex].defaultSelected)
content += '<br>Chantier remplacé par '+form.chantier_id.options[form.chantier_id.selectedIndex].text;
if(form.presta_desc.defaultValue != form.presta_desc.value)
content += '<br>Infos complémentaires remplacés par '+form.presta_desc.value;
if(!form.debutday.options[form.debutday.selectedIndex].defaultSelected || !form.debutmonth.options[form.debutmonth.selectedIndex].defaultSelected || !form.debutyear.options[form.debutyear.selectedIndex].defaultSelected)
content += '<br>Date de début des prestations modifiée au '+form.debutday.options[form.debutday.selectedIndex].text+' '+form.debutmonth.options[form.debutmonth.selectedIndex].text+' '+form.debutyear.options[form.debutyear.selectedIndex].text ;
if(form.inconnue.defaultChecked != form.inconnue.checked || !form.finday.options[form.finday.selectedIndex].defaultSelected || !form.finmonth.options[form.finmonth.selectedIndex].defaultSelected || !form.finyear.options[form.finyear.selectedIndex].defaultSelected)
{
if(form.inconnue.defaultChecked != form.inconnue.checked)
{
if(form.inconnue.checked) {
content += '<br>Date de fin des prestations supprimée' ;
} else { content += '<br>Date de fin des prestations modifiée' ; }
}
else if(!form.inconnue.checked)
content += '<br>Date de fin des prestations '+(form.inconnue.defaultChecked ? 'placée' : 'modifiée')+' au '+form.finday.options[form.finday.selectedIndex].text+' '+form.finmonth.options[form.finmonth.selectedIndex].text+' '+form.finyear.options[form.finyear.selectedIndex].text ;
}
if(!form.day.options[form.day.selectedIndex].defaultSelected)
content += '<br>Jour des prestations décalé au '+form.day.options[form.day.selectedIndex].text;
}
if (parseInt(form.hs.defaultValue) != parseInt(form.hs.value) ||parseInt(form.ms.defaultValue) != parseInt(form.ms.value) || parseInt(form.hf.defaultValue) != parseInt(form.hf.value) || parseInt(form.mf.defaultValue) != parseInt(form.mf.value))
if (type == 1)
content += '<br>Heure des prestations modifiée de '+form.hs.value+'h'+form.ms.value+' à '+form.hf.value+'h'+form.mf.value ;
else
content += '<br>Heure de la prestation modifiée de '+form.hs.value+'h'+form.ms.value+' à '+form.hf.value+'h'+form.mf.value ;
if(parseFloat(form.taux.value.replace(/,/, '.')) != parseFloat(form.taux.defaultValue.replace(/,/, '.')))
if (type == 1)
content += '<br>Taux horaire des prestations modifiée à '+parseFloat(form.taux.value.replace(/,/, '.'))+' €' ;
else
content += '<br>Taux horaire de la prestation modifiée à '+parseFloat(form.taux.value.replace(/,/, '.'))+' €' ;
if(!form.interv.options[form.interv.selectedIndex].defaultSelected)
content += '<br>Intervanant remplacé par '+form.interv.options[form.interv.selectedIndex].text;
if(!form.type_pre_id.options[form.type_pre_id.selectedIndex].defaultSelected)
content += '<br>type prestation remplacé par '+form.type_pre_id.options[form.type_pre_id.selectedIndex].text;
if(!form.chantier_id.options[form.chantier_id.selectedIndex].defaultSelected)
content += '<br>Chantier remplacé par '+form.chantier_id.options[form.chantier_id.selectedIndex].text;
if(form.presta_desc.defaultValue != form.presta_desc.value)
content += '<br>Infos complémentaires remplacés par '+form.presta_desc.value;
if (content == "") {
alert ('Aucune modification') ;
return ;
}
}
else
{
content = 'Vous souhaitez supprimer ';
switch (type) {
case 1 :
content += ' toutes les prestations, exceptions et modifications de la prestation récurrente ?' ;
break ;
case 3 :
content += ' cette exception ?' ;
break ;
default :
content += ' la prestation du '+form.recurday.options[form.recurday.selectedIndex].text+' '+form.recurmonth.options[form.recurmonth.selectedIndex].text+' '+form.recuryear.options[form.recuryear.selectedIndex].text ;
document.getElementById('second2').style.display = '' ;
}
}
document.getElementById('recap').innerHTML = content ;
document.getElementById('first').style.display = 'none' ;
document.getElementById('second').style.display = '' ;
}
function question2(MoiMeme)
{
var content = "" ;
content = 'Voulez-vous vraiment supprimer ces prestations ';
document.getElementById('recap').innerHTML = content ;
document.getElementById('first').style.display = 'none' ;
document.getElementById('second').style.display = '' ;
document.getElementById('second2').style.display = '' ;
}
-->
</script>
<?php if($_GET['sup']) { ?>
<form action="aac3.php" method="POST" name="edit">
<input type="hidden" name="presta_id" value="<?=$_GET['presta_id']?>">
<input type="hidden" name="type" value="3">
<input type="hidden" name="recur" value="">
<input type="hidden" name="offset" value="">
<input type="hidden" name="sup" value="date">
<!-- <div align="center">Edition</div>
--> <table id="first" width="100%">
<tr>
<td>Date Début :</td>
<td><?php print_date_selection("debut", '')?></td>
</tr>
<tr>
<td>Date fin :</td>
<td><?php print_date_selection("fin", '')?></td>
</tr>
</tr>
<tr>
<td nowrap>Heure : </td>
<td nowrap><input type="text" name="hs" size="2" maxlength="2" onchange="changes(this.form);" onkeyup="changes(this.form); if(this.value.length == 2 && event.keyCode >= 48 && event.keyCode <= 58) this.form.ms.focus();" onfocus="select();" value="<?=$hs?>">H<input type="text" name="ms" size="2" maxlength="2" onchange="changes(this.form)" onkeyup="changes(this.form);if(this.value.length == 2 && event.keyCode >= 48 && event.keyCode <= 58) this.form.hf.focus();" onfocus="select()" value="<?=$ms?>"> à <input type="text" name="hf" size="2" maxlength="2" onchange="changes(this.form)" onkeyup="if(this.value.length == 2 && event.keyCode >= 48 && event.keyCode <= 58) this.form.mf.focus();" onfocus="this.select();" value="<?=$hf?>">H<input type="text" name="mf" size="2" maxlength="2" onchange="changes(this.form)" onfocus="this.select();" value="<?=$mf?>"></td>
</tr>
<tr>
<td nowrap>Taux H :</td>
<td><input type="text" name="taux" value="<?=$forfait?>" size="6">
<?php
$forfaits = dbi_query('SELECT * FROM '.TABLE_FORFAITS.' WHERE taux = '.$forfait) ;
if($f = dbi_fetch_row($forfaits))
echo "(forfait {$f['libelle']})" ;
else
echo '<span style="color:red;font-weight:bold">*</span>' ;
?>
</td>
</tr>
<tr>
<td nowrap>Intervenant :</td>
<td nowrap><?=get_intervenants_drop_down('interv', '', $salarie)?> <a href="g.php?inter[]=<?=$salarie?>" onclick="open('g.php?type=1&dispo=2&date_c=<?=$_GET['recur']?>&rec=&pon=&inter[]='+document.forms[0].interv.value, 'planning', 'width='+screen.width+',height=160,top='+((screen.height-160)/2)+',left=0,status=0,resizable=1,scrollbars=yes').focus(); return false;" target="main">(Fiche)</a></td>
</tr>
<tr>
<td nowrap>Chantier :</td>
<td nowrap><?=get_chantier_drop_down('chantier_id', 'id="chantier_id"', $chantier_id)?> </td>
</tr>
<tr>
<td nowrap>Type prestation :</td>
<td nowrap><?=get_type_pre_drop_down('type_pre_id', 'id="type_pre_id"', $type_pre_id)?> </td>
</tr>
<tr>
<td nowrap>Infos complémentaires :</td>
<td nowrap> <input type="text" name="presta_desc" value="<?=$presta_desc;?>" size="60" maxlength="200" /> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="button" value="Valider" onclick="question2(this);"></td>
</tr>
</table>
<table style="display:none;" width="100%" id="second">
<tr>
<td colspan="2" id="recap"></td>
</tr>
<tr>
<td colspan="2" style="display:none;" id="second2">
<ul style="list-style:none; margin:0; padding:5px;" >
<li><label><input name="modif" type="radio" value="1" checked="checked">Déduire la prestation de la facture</label></li>
<li><label><input name="modif" type="radio" value="2">Ne pas déduire la prestation de la facture</label></li>
</ul>
</td>
</tr>
<tr>
<td align="center"><input type="submit" value="Valider"></td>
<td align="center"><input type="button" value="Retour" onclick="document.getElementById('first').style.display = '' ;document.getElementById('second').style.display = 'none' ;document.getElementById('second2').style.display = 'none' ;document.getElementById('second3').style.display = 'none' ;document.getElementById('second4').style.display = 'none' ;"></td>
</tr>
</table>
</form>
<?php
}
else {
?>
<form action="aac3.php" method="POST" name="edit">
<input type="hidden" name="presta_id" value="<?=$_GET['presta_id']?>">
<input type="hidden" name="presta_date_debut" value="<?=$_GET['recur']?>">
<input type="hidden" name="type" value="<?=$type?>">
<!-- <div align="center">Edition</div>
--> <table id="first" width="100%">
<tr>
<?php
if(!empty($_GET['recur']))
echo '<input type="hidden" name="recur" value="'.$_GET['recur'].'">' ;
elseif(!$prest['presta_recur'])
echo '<input type="hidden" name="recur" value="'.$prest['presta_date_debut'].'">' ;
if($type == 3)
echo '<input type="hidden" name="offset" value="'.$_GET['offset'].'">' ;
if(!empty($_GET['recur']))
echo '<td>Date :</td><td>'.date_selection_html("recur", $_GET['recur']).'</td>' ;
elseif(!$prest['presta_recur'])
echo '<td>Date :</td><td>'.date_selection_html("recur", $prest['presta_date_debut']).'</td>' ;
else
{
?>
<td>Début :</td>
<td><?php print_date_selection("debut", $prest['presta_date_debut'])?></td>
</tr>
<tr>
<td valign="top">Fin :</td>
<td><label for="inconnue"><input type="checkbox" name="inconnue" id="inconnue" onclick="this.form.finday.disabled = this.form.finmonth.disabled = this.form.finyear.disabled = this.form.finbutton.disabled = this.checked ;"<?=$prest['presta_date_fin'] === NULL ? ' checked' : ''?>> Inconnue</label><br>
<?=$prest['presta_date_fin'] === NULL ? ( preg_replace('/<(select|input)([^>]*)>/i', '<\1\2 disabled>', date_selection_html("fin", $prest['presta_date_fin'], $prest['presta_date_fin'] === NULL ? -5 : min(0, date('Y')-date('Y', int2time($prest['presta_date_fin']))), '10', $prest['presta_date_fin'] !== NULL)) ) : (date_selection_html("fin", $prest['presta_date_fin'], $prest['presta_date_fin'] === NULL ? -5 : min(0, date('Y')-date('Y', int2time($prest['presta_date_fin']))), '10', $prest['presta_date_fin'] !== NULL) );?></td>
</tr>
<tr>
<td width="1px" nowrap>Jour :</td>
<td><?=get_drop_down_jours('day', 'onchange="changes(this.form)"', substr(presta_jour2jour($prest['presta_jour']), 0, 3))?></td>
<?php
}
?>
</tr>
<tr>
<td nowrap>Heure : </td>
<td nowrap><input type="text" name="hs" size="2" maxlength="2" onchange="changes(this.form);" onkeyup="changes(this.form); if(this.value.length == 2 && event.keyCode >= 48 && event.keyCode <= 58) this.form.ms.focus();" onfocus="select();" value="<?=$hs?>">H<input type="text" name="ms" size="2" maxlength="2" onchange="changes(this.form)" onkeyup="changes(this.form);if(this.value.length == 2 && event.keyCode >= 48 && event.keyCode <= 58) this.form.hf.focus();" onfocus="select()" value="<?=$ms?>"> à <input type="text" name="hf" size="2" maxlength="2" onchange="changes(this.form)" onkeyup="if(this.value.length == 2 && event.keyCode >= 48 && event.keyCode <= 58) this.form.mf.focus();" onfocus="this.select();" value="<?=$hf?>">H<input type="text" name="mf" size="2" maxlength="2" onchange="changes(this.form)" onfocus="this.select();" value="<?=$mf?>"></td>
</tr>
<tr>
<td nowrap>Taux H :</td>
<td><input type="text" name="taux" value="<?=$forfait?>" size="6">
<?php
$forfaits = dbi_query('SELECT * FROM '.TABLE_FORFAITS.' WHERE taux = '.$forfait) ;
if($f = dbi_fetch_row($forfaits))
echo "(forfait {$f['libelle']})" ;
else
echo '<span style="color:red;font-weight:bold">*</span>' ;
?>
</td>
</tr>
<tr>
<td nowrap>Intervenant :</td>
<td nowrap><?=get_intervenants_drop_down('interv', '', $salarie)?> <a href="g.php?inter[]=<?=$salarie?>" onclick="open('g.php?type=1&dispo=2&date_c=<?=$_GET['recur']?>&rec=&pon=&inter[]='+document.forms[0].interv.value, 'planning', 'width='+screen.width+',height=160,top='+((screen.height-160)/2)+',left=0,status=0,resizable=1,scrollbars=yes').focus(); return false;" target="main">(Fiche)</a></td>
</tr>
<tr>
<td nowrap>Chantier :</td>
<td nowrap><?=get_chantier_drop_down('chantier_id', 'id="chantier_id"', $chantier_id)?> </td>
</tr>
<tr>
<td nowrap>Infos complémentaires :</td>
<td nowrap> <input type="text" name="presta_desc" value="<?=$presta_desc;?>" size="60" maxlength="200" /> </td>
</tr>
<tr>
<td nowrap>Type prestation :</td>
<td nowrap><?=get_type_pre_drop_down('type_pre_id', 'id="type_pre_id"', $type_pre_id)?> </td>
</tr>
<?php
// echo " vvvvvvvvvvvvvvv $type_pre_id ";
/*
if($type > 1)
{
?>
<tr>
<td colspan="2">
<fieldset>
<legend>Raison :</legend>
<ul style="list-style:none; margin:0; padding:5px;">
<li><label><input name="modif" type="radio" value="1" checked="checked">Supprimer et ne pas facturer</label></li>
<li><label><input name="modif" type="radio" value="2">Supprimer et facturer</label></li>
<!----<li><label><input name="modif" type="radio" value="3">Absence d'un intervenant</label></li> --->
</ul>
</fieldset></td>
</tr>
<?php
}
*/
?>
<tr>
<td colspan="2" align="center">
<fieldset>
<legend>Type de modification :</legend>
<ul style="list-style:none; margin:0; padding:0;">
<li style="display:inline;"><label><input type="radio" name="maj" value="1"> Modifier</label></li>
<li style="margin-left:15px; display:inline;"><label><input type="radio" name="maj" value="0"> Supprimer</label></li>
</ul>
</fieldset>
</td>
</tr>
<?php
// echo "SELECT * FROM ".TABLE_PREST." WHERE presta_id = ".$prestat_id." agence_id=$agence ".$_GET['presta_id'];
// $d = dbi_query("SELECT * FROM ".TABLE_PREST." WHERE presta_id = ".$_GET['presta_id']." AND agence_id=$agence ") ;
// $dd = dbi_fetch_row($d);
// echo ' ///////////// '.$dd['presta_Hduree'].' '.$presta_Hduree;
// if($dd['presta_Hduree'])
// $presta_Hduree = $dd['presta_Hduree'];
?>
<input type="hidden" name="presta_Hduree" value="<?=$presta_Hduree?>" size="6" />
<input type="hidden" name="excpt" value="<?=$qex['excpt_id']?>" size="10" />
<?php
// print_r($qex);
if($type == 1)
{
?>
<tr>
<td colspan="2">
<fieldset>
<legend>Date d’application </legend>
<ul style="list-style:none; margin:0; padding:5px;">
<li><label><input name="application" type="radio" value="0" onchange="this.form.apartirday.disabled = this.form.apartirmonth.disabled = this.form.apartiryear.disabled = this.form.apartirbutton.disabled = this.checked ;">A partir de la première prestation</label></li>
<li><label><input name="application" type="radio" value="1" onchange="this.form.apartirday.disabled = this.form.apartirmonth.disabled = this.form.apartiryear.disabled = this.form.apartirbutton.disabled = !this.checked ;">A partir du </label><?php print_date_selection('apartir', date('Ymd'), -5, 10, false)?></li>
</ul>
</fieldset>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="2" align="center"><input type="button" value="Valider" onclick="question(this);"></td>
</tr>
</table>
<table style="display:none;" width="100%" id="secondd">
<tr>
<td colspan="2" id="recap2"></td>
</tr>
<tr>
<td colspan="2" style="display:none;" id="second3">
<ul style="list-style:none; margin:0; padding:5px;" >
<li><label><input name="ded" id="1" type="radio" value="1" checked="checked">Déduire la différence de la facture</label></li>
<li><label><input name="ded" id="2" type="radio" value="0" >Ne pas déduire la différence de la facture </label></li>
</ul>
</td>
</tr>
<div style="display:none;" >
<tr >
<td colspan="2" style="display:none;" id="second4">
<ul style="list-style:none; margin:0; padding:5px;" >
<li><label><input name="ad" id="3" type="radio" value="1" checked="checked">Ajouter la différence à la facture</label></li>
<li><label><input name="ad" id="4" type="radio" value="0" >Ne pas Ajouter la différence à la facture </label></li>
</ul>
</td>
</tr>
</div>
</table>
<table style="display:none;" width="100%" id="second">
<tr>
<td colspan="2" id="recap"></td>
</tr>
<tr>
<td colspan="2" style="display:none;" id="second2">
<ul style="list-style:none; margin:0; padding:5px;" >
<li><label><input name="modif" type="radio" value="1" checked="checked">Déduire la prestation de la facture</label></li>
<li><label><input name="modif" type="radio" value="2">Ne pas déduire la prestation de la facture</label></li>
</ul>
</td>
</tr>
<?php
// if(!empty($_GET['recur']) || $prest['presta_recur']) {
// echo " ????????????? ".$prest['presta_recur'];
?>
<?php
// }
?>
<tr>
<td align="center"><input type="submit" value="Valider"></td>
<td align="center"><input type="button" value="Retour" onclick="document.getElementById('first').style.display = '' ;document.getElementById('second').style.display = 'none' ;document.getElementById('second2').style.display = 'none' ;document.getElementById('second3').style.display = 'none' ;document.getElementById('second4').style.display = 'none' ;"></td>
</tr>
</table>
</form>
<?php
}
}
?>
</div>
<a onclick="hs('ht');return false;" href="#"><u><div style="margin-top:0" id="ht_text">Voir l'historique des prestations [+]</div></u></a><br>
<div style="display: none;" id="ht">
<div id="ht" style="">
<h1>Historique des prestations</h1>
<table width="100%">
<tr>
<td width="50%" valign="top">
<?php
$q = dbi_query("SELECT * FROM ".TABLE_PREST." WHERE client_id=".$_GET['client_id']." AND presta_recur = '1' AND agence_id=$agence ORDER BY presta_jour DESC") ;
$sem = array ('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi') ;
//error_reporting(E_ALL);
$print_p_r = (mysql_num_rows($q)>0);
if ($print_p_r) {
?>
<h2 align="center">Récurrentes</h2>
<fieldset>
<?
}
while ($p = dbi_fetch_row($q))
{
$date = get_occurence($p['presta_id'], 0, $from) ;
$mois = int2date($date['date'], 'm') ;
$last = 0 ;
$offset = 0 ;
$annule = dbi_query("SELECT * FROM ".TABLE_EXCEPT." WHERE new_presta_id is null AND en_cours='1' AND presta_id=".$p['presta_id']." order by date Desc");
$a = dbi_fetch_row($annule) ;
if ($a !== false)
$mois = max($mois, int2date($a['date'], 'm'));
//printf (" %s>%04d%02d%02d", $p['presta_id'], $year, $month, 1);
if($date && $date['date'] <= date("Ymd"))
{
printf ('<fieldset><legend>%s</legend>', $sem[strpos($p['presta_jour'], 'y')]) ;
while($date && $date['date'] <= date("Ymd"))
{
while($a !== false && $a['date'] > $date['date'])
{
if ($mois != int2date($date['date'], 'm'))
echo "<hr>";
printf("%s annulée<br>", int2date($a['date'])) ;
$mois = int2date($a['date'], 'm') ;
$a = dbi_fetch_row($annule) ;
}
if ($mois != int2date($date['date'], 'm'))
echo "<hr>";
printf("%s à %s<br>", int2date($date['date']), int2heure($date['deb'])) ;
if($last == $date['date'])
$offset ++ ;
else
$offset = 0 ;
$last = $date['date'] ;
$mois = int2date($date['date'], 'm') ;
$date = get_occurence($p['presta_id'], 1+$offset, $date['date']) ;
}
while($a !== false && $a['date'] > $date['date'])
{
if ($mois != int2date($date['date'], 'm'))
echo "<hr>";
printf("%s annulée<br>", int2date($a['date'])) ;
$mois = int2date($a['date'], 'm') ;
$a = dbi_fetch_row($annule) ;
}
echo '</fieldset>' ;
}
}
if ($print_p_r) {
?>
</fieldset>
<?
}
?>
</td>
<td width="50%" valign="top">
<?php
$q = dbi_query("SELECT * FROM ".TABLE_PREST." WHERE client_id=".$_GET['client_id']." AND agence_id=$agence AND presta_recur = '' AND presta_id NOT IN (SELECT new_presta_id FROM ".TABLE_EXCEPT." WHERE new_presta_id is not NULL) ORDER BY presta_date_debut DESC, presta_Hdeb DESC") ;
$print_p = (mysql_num_rows($q)>0);
if ($print_p) {
?>
<h2 align="center">Prestations ponctuelles</h2>
<fieldset>
<?
}
while ($p = dbi_fetch_row($q)) {
$date = get_occurence($p['presta_id'], -1);
printf('<a href="top.php?page=aac2&link=client&id=%d&presta_id=%d">Le %s de %s à %s</a><br>', $_GET['client_id'], $p['presta_id'], int2date($date['date']), int2heure($p['presta_Hdeb']), int2heure(addDuree($p['presta_Hdeb'], $p['presta_Hduree']))) ;
}
if ($print_p) {
?>
</fieldset>
<?
}
?>
</td>
</tr>
</table>
<? if (!$print_p && !$print_p_r) echo '<h2 align="center">Aucune prestation effectuée</h2>'; ?>
<a onclick="hs('ht');return false;" href="#"><u>Cacher l'historique des prestations</u></a>
</div><br>
</body>
</html>