<?php
session_start();
require('../45789417/ref4780.php');
if (!isset($_SESSION['userid'])) {
  echo "<script language='Javascript'> location.href='../login.php';</script>";
    exit();
  };
$name = $_POST['name'];
$title = $_POST['title'];
$start = $_POST['start'];
$description = $_POST['description'];
$SCH = $_POST['SCH']; // Camara Hiperbarica
$ST = $_POST['ST']; // Terapia
$CMF = $_POST['CMF']; // Consulta MF - CMF
$CEL = $_POST['CEL']; // Exámenes Médicos - CEL
$CM = $_POST['CM']; // Consulta Control - CM
$SEF = $_POST['SEF']; // Facial - SEF
$SEV = $_POST['SEV']; // V-shape - SEV
$SEH = $_POST['SEH']; // Hidro terapia - SEH
$SETT = $_POST['SETT']; // Tonificación - SET
$SEG = $_POST['SEG']; // Gluteos - SEG
$SEP = $_POST['SEP']; // Post-Operatorios - SEP
$SEC = $_POST['SEC']; // CELULITIS - SEC
$SEL = $_POST['SEL']; // LIPOSOFT - SEL
$CHC = $_POST['CHC']; // Historía Clinica - CHC
$CMD = $_POST['CMD']; // Medidas - CMD
$CMT = $_POST['CMT']; // Mantra- CMT
$CTO = $_POST['CTO']; // Terapia Ortomolecular -CTO
$CAT = $_POST['CAT']; // Auriculoterapia - 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
$pay = $_POST['pay'];
$cell = $_POST['cell'];
$como_entero = $_POST['como_entero'];
$tipo_cc = $_POST['tipo_cc'];
$atendido = $_POST['atendido'];
$t_servicio = $_POST['t_servicio'];
$comments = $_POST['comments'];


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)) { $scc_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 = 30;};
if (isset($MG)) { $mg_minutes = 30;};

$end_minutes = $sch_minutes + $st_minutes + $scm_minutes + $cel_minutes + $scc_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');

// insert the records
$sql = "INSERT INTO se_evenement (nametitledescriptionstartendSCHSTCMFCELCMSEFSEVSEHSETTSEGSEPSECSELCHCCMDCMTCTOCATCPACAFCMApaycellcomo_enterotipo_ccatendidot_serviciocommentsLABCMGMG) VALUES (: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:pay:cell:como_entero:tipo_cc:atendido:t_servicio:comments:LAB:CMG:MG)";
$q = $bdd->prepare($sql);
$q->execute(array(':name'=>$name':title'=>$title':description'=>$description':start'=>$start':end'=>$end':SCH'=>$SCH':ST'=>$ST':CMF'=>$CMF':CEL'=>$CEL':CM'=>$CM':SEF'=>$SEF':SEV'=>$SEV ':SEH'=>$SEH':SETT'=>$SETT':SEG'=>$SEG':SEP'=>$SEP':SEC'=>$SEC':SEL'=>$SEL':CHC'=>$CHC':CMD'=>$CMD ':CMT'=>$CMT':CTO'=>$CTO':CAT'=>$CAT':CPA'=>$CPA':CAF'=>$CAF':CMA'=>$CMA':pay'=>$pay':cell'=>$cell':como_entero'=>$como_entero':tipo_cc'=>$tipo_cc':atendido'=>$atendido':t_servicio'=>$t_servicio':comments'=>$comments':LAB'=>$LAB':CMG'=>$CMG':MG'=>$MG));

// update url
$rs = mysqli_query($con,"SELECT MAX(id) AS id FROM se_evenement");
if ($row = mysqli_fetch_row($rs)) {
$id = trim($row[0]);
}
$url = "view_event.php?id=".$id;
$query = mysqli_query($con,"UPDATE se_evenement SET url='$url' WHERE id = '$id'");

/*
$result = mysqli_query($con,"SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'losrobles_app_hc'  AND TABLE_NAME = 'se_evenement'");  
$row = mysqli_fetch_row($result); 

// Values received via ajax
*/
	echo "<script type='text/javascript'>  
		window.location='agenda.php';
		</script>";
	
?>
