<?php

include 'dbconnection.php';

$Email2 = $_GET["Email"]; 



$DB = mysqli_query($mysql,"SELECT dbname FROM tb_users WHERE email ='$Email2'");
while($row7 = mysqli_fetch_array($DB)){
$dbname = $row7 ['dbname'];}


$hostname2 = "localhost";
$username2 = "tempdpe5_nicolas";
$password2= "(Made7575)";
$conn = mysqli_connect($hostname2,$username2,$password2,$dbname);
if (mysqli_connect_errno()){
  printf("Connect failed: %s\n", mysqli_connect_error());
  exit();
} 
mysqli_set_charset($conn ,"utf8");


// Perform queries
mysqli_query($conn,"UPDATE calendar SET description = CONCAT(Condominio,' | ',Residencia) WHERE status ='Deposito Pagado' AND DATEDIFF(STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p'), STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p'))<=0 AND TIMESTAMPDIFF(MINUTE,STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p'), STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p'))>0 ");

mysqli_query($conn,"UPDATE calendar SET tipomodulo = 'Programacion' WHERE status IN ('Programar Actividad', 'Deposito Pagado') AND DATEDIFF(STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p'), STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p'))<=0 AND TIMESTAMPDIFF(MINUTE,STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p'), STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p'))>0");  

mysqli_query($conn,"UPDATE calendar SET status = 'Programada' WHERE status IN ('Programar Actividad', 'Deposito Pagado') AND DATEDIFF(STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p'), STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p'))<=0 AND TIMESTAMPDIFF(MINUTE,STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p'), STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p'))>0");

mysqli_query($conn,"UPDATE calendar SET start = STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p') , end = STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p') WHERE status = 'Programada' AND DATEDIFF(STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p'), STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p'))<=0 AND TIMESTAMPDIFF(MINUTE,STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p'), STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p'))>0");

mysqli_query($conn,"UPDATE calendar SET start2 = DATE_FORMAT(start,'%Y-%m-%d') WHERE status = 'Programada' AND DATEDIFF(STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p'), STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p'))<=0 AND TIMESTAMPDIFF(MINUTE,STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p'), STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p'))>0 ");

mysqli_query($conn,"UPDATE calendar SET end2 = DATE_FORMAT(end,'%Y-%m-%d') WHERE status = 'Programada' AND DATEDIFF(STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p'), STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p'))<=0 AND TIMESTAMPDIFF(MINUTE,STR_TO_DATE(fechadeinicio, '%Y-%m-%d %h:%i %p'), STR_TO_DATE(fechafinal, '%Y-%m-%d %h:%i %p'))>0");




mysqli_close($conn);
mysqli_close($mysql);
echo "<script>window.location.href='programaciondeactividades';</script>";
?>