<?php
date_default_timezone_set('America/Bogota');
$id = $_POST['id'];
$name = $_POST['name'];
$title = $_POST['title'];
$description = $_POST['description'];
$start = $_POST['start'];
$pay = $_POST['pay'];
$SCH = $_POST['SCH'];
$ST = $_POST['ST'];
$CMF = $_POST['CMF'];
$CEL = $_POST['CEL'];
$CM = $_POST['CM'];
$SEF = $_POST['SEF'];
$SEV = $_POST['SEV'];
$SEH = $_POST['SEH'];
$SETT = $_POST['SETT'];
$SEG = $_POST['SEG'];
$SEP = $_POST['SEP'];
$SEC = $_POST['SEC'];
$SEL = $_POST['SEL'];
$CHC = $_POST['CHC'];
$CMD = $_POST['CMD'];
$CMT = $_POST['CMT'];
$CTO = $_POST['CTO'];
$CAT = $_POST['CAT']; // 
$CPA = $_POST['CPA']; // Plan de Alimentación  - CPA
$CAF = $_POST['CAF']; // Actividad Física - CAF
$CMA = $_POST['CMA']; // Médico Alimentación - CMA
$LAB = $_POST['LAB']; // LABORATORIO LAB
$CMG = $_POST['CMG']; // Consulta Medico General - CMG
$MG = $_POST['MG']; // Control Medico General - MG
$status = $_POST['status'];
$cell = $_POST['cell'];
$continua = $_POST['continua'];
$como_entero = $_POST['como_entero'];
$tipo_cc = $_POST['tipo_cc'];
$atendido = $_POST['atendido'];
$t_servicio = $_POST['t_servicio'];
$comments = $_POST['comments'];
$last_modified	= date("Y-m-d H:i:s");

if (isset($SCH)) { $sch_minutes = 20;};
if (isset($ST)) { $st_minutes = 30;};
if (isset($CMF)) { $scm_minutes = 20;};
if (isset($CEL)) { $cel_minutes = 10;};
if (isset($CM)) { $cm_minutes = 20;};
if (isset($SEF)) { $sef_minutes = 60;};
if (isset($SEV)) { $sev_minutes = 60;};
if (isset($SEH)) { $seh_minutes = 60;};
if (isset($SETT)) { $sett_minutes = 60;};
if (isset($SEG)) { $seg_minutes = 60;};
if (isset($SEP)) { $sep_minutes = 60;};
if (isset($SEC)) { $sec_minutes = 60;};
if (isset($SEL)) { $sel_minutes = 60;};
if (isset($CHC)) { $chc_minutes = 10;};
if (isset($CMD)) { $cmd_minutes = 5;};
if (isset($CMT)) { $cmt_minutes = 25;};
if (isset($CTO)) { $cto_minutes = 10;};
if (isset($CAT)) { $cat_minutes = 10;};
if (isset($CPA)) { $cpa_minutes = 15;};
if (isset($CAF)) { $caf_minutes = 60;};
if (isset($CMA)) { $cma_minutes = 15;};
if (isset($LAB)) { $lab_minutes = 10;};
if (isset($CMG)) { $cmg_minutes = 10;};
if (isset($MG)) { $mg_minutes = 10;};
$end_minutes = $sch_minutes + $st_minutes + $scm_minutes + $cel_minutes + $cm_minutes + $sef_minutes + $sev_minutes + $seh_minutes + $sett_minutes +$seg_minutes + $sep_minutes + $sec_minutes + $sel_minutes + $chc_minutes + $cmd_minutes + $cmt_minutes + $cto_minutes + $cat_minutes + $cpa_minutes + $caf_minutes + $cma_minutes + $lab_minutes + $cmg_minutes + $mg_minutes;
$fecha = $start; //inicializo la fecha con la hora
$nuevafecha = strtotime ( '+0 hour' , strtotime ( $fecha ) ) ;
$nuevafecha = strtotime ( '+'.$end_minutes.' minute' , $nuevafecha ) ; // utilizo "nuevafecha"
$nuevafecha = strtotime ( '+0 second' , $nuevafecha ) ; // utilizo "nuevafecha"
$nuevafecha = date ( 'Y-m-d H:i:s' , $nuevafecha );
$end = $nuevafecha;

// connection to the database
require_once('4798945.php');

 // update the records
if($status != 'Reagendado'){
	//update para todos menos reagendado
	$sql = "UPDATE se_evenement SET name=?, title=?, description=?, start=?, end=?, SCH=?, ST=?, CMF=?, CEL=?, CM=?, SEF=?, SEV=?, SEH=?, SETT=?, SEG=?, SEP=?, SEC=?, SEL=?, CHC=?, CMD=?, CMT=?, CTO=?, CAT=?, CPA=?, CAF=?, CMA=?, status=?, pay=?, cell=?, continua=?, como_entero=?, tipo_cc=?, atendido=?, last_modified=?, LAB=?, CMG=?, MG=? WHERE id=?";
	$q = $bdd->prepare($sql);
	$q->execute(array($name,$title,$description,$start,$end,$SCH,$ST,$CMF,$CEL,$CM,$SEF,$SEV,$SEH,$SETT,$SEG,$SEP,$SEC,$SEL,$CHC,$CMD,$CMT,$CTO,$CAT,$CPA,$CAF,$CMA,$status,$pay,$cell,$continua,$como_entero,$tipo_cc,$atendido,$last_modified,$LAB,$CMG,$MG,$id));
} else {
	// update para reagendado
	$sql = "UPDATE se_evenement SET name=?, title=?, description=?, SCH=?, ST=?, CMF=?, CEL=?, CM=?, SEF=?, SEV=?, SEH=?, SETT=?, SEG=?, SEP=?, SEC=?, SEL=?, CHC=?, CMD=?, CMT=?, CTO=?, CAT=?, CPA=?, CAF=?, CMA=?, status=?, pay=?, cell=?, continua=?, como_entero=?, tipo_cc=?, atendido=?, LAB=?, CMG=?, MG=?  WHERE id=?";
	$q = $bdd->prepare($sql);
	$q->execute(array($name,$title,$description,$SCH,$ST,$CMF,$CEL,$CM,$SEF,$SEV,$SEH,$SETT,$SEG,$SEP,$SEC,$SEL,$CHC,$CMD,$CMT,$CTO,$CAT,$CPA,$CAF,$CMA,$status,$pay,$cell,$continua,$como_entero,$tipo_cc,$atendido,$LAB,$CMG,$MG,$id));
	// insert the records new event if is reagendado
	echo "<form action='add_events2.php' method='POST'>
		<input type='hidden' name='name' value='".$name."'> 
		<input type='hidden' name='title' value='".$title."'> 
		<input type='hidden' name='description' value='".$description."'> 
		<input type='hidden' name='start' value='".$start."'> 
		<input type='hidden' name='pay' value='".$pay."'> 
			<input type='hidden' name='SCH' value='".$SCH."'> 
			<input type='hidden' name='ST' value='".$ST."'> 
			<input type='hidden' name='CMF' value='".$CMF."'> 
			<input type='hidden' name='CEL' value='".$CEL."'> 
			<input type='hidden' name='CM' value='".$CM."'> 
			<input type='hidden' name='SEF' value='".$SEF."'> 
			<input type='hidden' name='SEV' value='".$SEV."'> 
			<input type='hidden' name='SEH' value='".$SEH."'> 
			<input type='hidden' name='SETT' value='".$SETT."'> 
			<input type='hidden' name='SEG' value='".$SEG."'> 
			<input type='hidden' name='SEP' value='".$SEP."'> 
			<input type='hidden' name='SEC' value='".$SEC."'> 
			<input type='hidden' name='SEL' value='".$SEL."'> 
			<input type='hidden' name='CHC' value='".$CHC."'> 
			<input type='hidden' name='CMD' value='".$CMD."'> 
			<input type='hidden' name='CMT' value='".$CMT."'> 
			<input type='hidden' name='CTO' value='".$CTO."'> 
			<input type='hidden' name='CAT' value='".$CAT."'> 
			<input type='hidden' name='CPA' value='".$CPA."'> 
			<input type='hidden' name='CAF' value='".$CAF."'> 
			<input type='hidden' name='LAB' value='".$LAB."'> 
			<input type='hidden' name='CMA' value='".$CMA."'>
			<input type='hidden' name='CMG' value='".$CMG."'> 
			<input type='hidden' name='MG' value='".$MG."'> 
		<input type='hidden' name='cell' value='".$cell."'> 
		<input type='hidden' name='continua' value='".$continua."'> 
		<input type='hidden' name='como_entero' value='".$como_entero."'> 
		<input type='hidden' name='tipo_cc' value='".$tipo_cc."'> 
		<input type='hidden' name='atendido' value='".$atendido."'> 
		<input type='hidden' name='t_servicio' value='".$t_servicio."'> 
		<input type='hidden' name='comments' value='".$comments."'> 
		</form>    
	<script language='JavaScript'>
	document.forms[0].submit();
	</script>";
};
if($status == 'Reagendado'){
	} else { 
	echo "<script type='text/javascript'>  
				location.href='index.php';
			</script>";	
}
?>
