Guest User

Example Mysql Jquery week calendar (2) (calendar.php)

a guest
Mar 23rd, 2011
2,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.65 KB | None | 0 0
  1. <?php
  2. require_once('php/config.php');
  3. require_once("php/functions.php");
  4. require_once($GLOBALS['cfg']['lpath'].'php/sesion.php');
  5. require_once($GLOBALS['cfg']['lpath'].'php/bd.php');
  6.  
  7. if (!isset($_GET['op'])) {
  8.     echo "Bad parameter";
  9.     exit;
  10. }
  11. //make sure we have a correct timezone
  12. date_default_timezone_set('Europe/Madrid');
  13. ini_set('date.timezone','Europe/Madrid');
  14. ob_start('ot2');//el ajax espera utf-8
  15.  
  16. if (isset($_GET['opmail'])) {
  17.     send_mail();
  18. } else if ($_GET['op'] == 'get_events') {
  19.     get_events();
  20. } else if ($_GET['op'] == 'add_event') {
  21.     add_event();
  22. } else if ($_GET['op'] == 'delete_event') {
  23.     delete_event();
  24. } else if ($_GET['op'] == 'update_event') {
  25.     update_event();
  26. } else if ($_GET['op'] == 'get_ldaptelefono') {
  27.     get_ldaptelefono();
  28. }
  29.  
  30. //
  31. // FUNCTIONS
  32. //
  33.  
  34. function update_event() {
  35.     //comprobar que otro usuario no haya metido al mismo tiempo desde otra sesion en el mismo rango de fecha
  36.     $fini = date('Y-m-d H:i:s',$_GET['start']);
  37.     $ffin = date('Y-m-d H:i:s',$_GET['end']);
  38.     $sql = "select id from eventos where id <> ".$_GET['evid']." and ((fini >= '" . $fini . "' and fini < '" . $ffin . "')";
  39.     $sql .= " or (ffin > '" . $fini . "' and ffin <= '" . $ffin . "')";
  40.     $sql .= " or (fini <= '" . $fini . "' and ffin >= '" . $ffin . "'))";
  41.     $tot = db_select($sql,$rs);
  42.     if ($tot) {
  43.         echo 'TAKEN';
  44.         exit;
  45.     }
  46.     if ($GLOBALS['cfg']['browser'] == 'gk') {//firefox se comporta distinto a ie y chrome
  47.         $_GET['body'] = utf8_decode($_GET['body']);
  48.         $_GET['title'] = utf8_decode($_GET['title']);
  49.     }
  50.     //update the event
  51.     $sql = "update eventos set fini = '" . $fini . "',ffin = '" . $ffin . "',";
  52.     $sql .= " obs = '" . $_GET['body'] . "', motivo = '" . $_GET['title'] . "'";
  53.     $sql .= " where id = " . $_GET['evid'];
  54.     $ret = db_query($sql);
  55.     echo (int) $ret;   
  56. }
  57.  
  58. function delete_event() {
  59.     $tot = db_select('select usuario from eventos where id = ' . $_GET['evid'],$rs);
  60.     $affected = db_query('delete from eventos where id = ' . $_GET['evid']);
  61.     echo (int) $affected;
  62.     echo '|' . $rs[0]['usuario'];
  63. }
  64.  
  65. function add_event() {
  66.     //comprobar que otro usuario no haya metido al mismo tiempo desde otra sesion en el mismo rango de fecha
  67.     $fini = date('Y-m-d H:i:s',$_GET['start']);
  68.     $ffin = date('Y-m-d H:i:s',$_GET['end']);
  69.     $sql = "select id from eventos where (fini >= '" . $fini . "' and fini < '" . $ffin . "')";
  70.     $sql .= " or (ffin > '" . $fini . "' and ffin <= '" . $ffin . "')";
  71.     $sql .= " or (fini <= '" . $fini . "' and ffin >= '" . $ffin . "')";
  72.     $tot = db_select($sql,$rs);
  73.     if ($tot) {
  74.         echo 'TAKEN';
  75.         exit;
  76.     }
  77.     if ($GLOBALS['cfg']['browser'] == 'gk') {//firefox se comporta distinto a ie y chrome
  78.         $_GET['body'] = utf8_decode($_GET['body']);
  79.         $_GET['title'] = utf8_decode($_GET['title']);
  80.     }
  81.     //insert the event
  82.     $sql = 'insert into eventos(fini,ffin,usuario,obs,motivo) values (';
  83.     $sql .= "'" . $fini . "','" . $ffin;
  84.     $sql .= "','" . $_SESSION['usu'] . "','" . $_GET['body'] . "','" . $_GET['title'] . "')";
  85.     $ret = db_query($sql); 
  86.     echo (int) $ret . '|' . $_SESSION['usu'];  
  87. }
  88.  
  89. function get_events() {
  90.     //$lastyear = time() - (365 * 60 * 60 * 24);//Cargar eventos solo de un año hacia atras
  91.     //$fini = date('Y-m-d H:i:s',$lastyear);
  92.     $fini = date('Y-m-d H:i:s',$_GET['start']);
  93.     $ffin = date('Y-m-d H:i:s',$_GET['end']);
  94.     $tot = db_select("select * from eventos where fini >= '" . $fini . "' and fini <= '" . $ffin . "'", $rs);
  95.     db_select("select val from config where name='dominio_mail'", $rsi);
  96.     echo '{"events":['."\n";
  97.     $ronly = '';
  98.     $esadmin = $_SESSION['perfil'] == 'ADM';
  99.     $ultimo = $tot - 1;
  100.     for ($i=0;$i<$tot;$i++) {
  101.         if (!$esadmin) {
  102.             $ronly = $_SESSION['usu'] == $rs[$i]['usuario'] ? '' : ',readOnly : true';
  103.         }
  104.         echo '{
  105. "id":'.$rs[$i]['id'].',
  106. "start": "'.date('c', strtotime($rs[$i]['fini'])).'",
  107. "end": "'.date('c', strtotime($rs[$i]['ffin'])).'",
  108. "title":"'.$rs[$i]['motivo'].'",
  109. "usermail":"'.$rs[$i]['usuario']. $rsi[0]['val'].'",
  110. "body":"'.$rs[$i]['obs'].'"
  111. '.$ronly.'}';
  112.         if ($i != $ultimo) {
  113.             echo ',';
  114.         }
  115.     }
  116.     echo ']}';
  117. }
  118.  
  119. function ot2($s) {
  120.     return utf8_encode($s);
  121. }
  122.  
  123. function get_ldaptelefono() {
  124.     $newrep = array('telephonenumber' => '', 'agedateofbirth' => '', 'ageorganizationdesc' => '', 'email' => '', 'givenname' => '', 'sn' => '', 'initials' => '' , 'mdslinktocv' => '');
  125.     get_ldap_fields ($_GET['user'], $newrep);
  126.     echo $newrep['telephonenumber'];
  127. }
  128.  
  129. function send_mail() {//función para enviar email en el alta, update y delete de una reserva:
  130.     $tot = db_select("select val from config where name='dominio_mail'", $rs);
  131.     $mail=$rs[0]['val'];   
  132.     if ($_GET['op'] == 'add_event') {//ALTA RESERVA
  133.         $fini = date('Y-m-d H:i:s',$_GET['start']);
  134.         $ffin = date('Y-m-d H:i:s',$_GET['end']);
  135.         $hi = explode(" ", $fini);
  136.         $hf = explode(" ", $ffin);
  137.         $hi=substr($hi[1],0,5);
  138.         $hf=substr($hf[1],0,5);
  139.         if ($GLOBALS['cfg']['browser'] == 'gk') {//firefox se comporta distinto a ie y chrome
  140.             $_GET['body'] = utf8_decode($_GET['body']);
  141.             $_GET['title'] = utf8_decode($_GET['title']);
  142.         }
  143.         $message="Se ha reservado la sala de reuniones con los siguientes datos:\n<br>\n<br><b>Fecha de Inicio:</b> ". date_in($fini) . " ".$hi . "\n<br><b>Fecha de Fin:</b> " . date_in($ffin)." ". $hf . "\n<br><b>Motivo</b>: " .$_GET['title'] . "\n<br><b>Observaciones:</b> " .$_GET['body'];
  144.         $sb="Nueva Reserva de la Sala de Reuniones";
  145.         $ema = $_SESSION['usu'].$mail;
  146.         phpmail($ema, $sb, $message);
  147.         $tot = db_select("select * from email where email != '" . $ema . "'", $rs);
  148.         for ($i=0;$i<$tot;$i++) {
  149.             phpmail($rs[$i]['email'], $sb, $message);
  150.         }
  151.     } else if ($_GET['op'] == 'delete_event') {//BORRADO RESERVA       
  152.         $fini = date('Y-m-d H:i:s',$_GET['start']);
  153.         $ffin = date('Y-m-d H:i:s',$_GET['end']);
  154.         $hi = explode(" ", $fini);
  155.         $hf = explode(" ", $ffin);
  156.         $hi=substr($hi[1],0,5);
  157.         $hf=substr($hf[1],0,5);
  158.         if ($GLOBALS['cfg']['browser'] == 'gk') {//firefox se comporta distinto a ie y chrome
  159.             $_GET['body'] = utf8_decode($_GET['body']);
  160.             $_GET['title'] = utf8_decode($_GET['title']);
  161.         }
  162.         $message="Se ha eliminado la siguiente reserva:\n<br>\n<br><b>Fecha de Inicio:</b> ". date_in($fini) . " ".$hi . "\n<br><b>Fecha de Fin:</b> " . date_in($ffin)." ". $hf . "\n<br><b>Motivo</b>: " .$_GET['title'] . "\n<br><b>Observaciones:</b> " .$_GET['body'];
  163.         $sb="Eliminación de Reserva de la Sala de Reuniones";
  164.         $ema = $_SESSION['usu'].$mail;
  165.         phpmail($ema, $sb, $message);
  166.         $tot = db_select("select * from email where email != '" . $ema . "'", $rs);
  167.         for ($i=0;$i<$tot;$i++) {
  168.             phpmail($rs[$i]['email'], $sb, $message);
  169.         }  
  170.        
  171.     } else if ($_GET['op'] == 'update_event') {//ACTUALIZACIÓN RESERVA    
  172.         $fini = date('Y-m-d H:i:s',$_GET['start']);
  173.         $ffin = date('Y-m-d H:i:s',$_GET['end']);
  174.         $hi = explode(" ", $fini);
  175.         $hf = explode(" ", $ffin);
  176.         $hi=substr($hi[1],0,5);
  177.         $hf=substr($hf[1],0,5);
  178.         if ($GLOBALS['cfg']['browser'] == 'gk') {//firefox se comporta distinto a ie y chrome
  179.             $_GET['body'] = utf8_decode($_GET['body']);
  180.             $_GET['title'] = utf8_decode($_GET['title']);
  181.         }
  182.         $message="Se ha actualizado una Reserva, a continuación mostramos los datos ya actualizados:\n<br>\n<br><b>Fecha de Inicio:</b> ". date_in($fini) . " ".$hi . "\n<br><b>Fecha de Fin:</b> " . date_in($ffin)." ". $hf . "\n<br><b>Motivo</b>: " .$_GET['title'] . "\n<br><b>Observaciones:</b> " .$_GET['body'];
  183.         $sb="Actualización de Reserva de la Sala de Reuniones";
  184.         $tot = db_select("select usuario from eventos where id=".$_GET['evid'], $rs);
  185.         $ema = $_SESSION['usu'].$mail;
  186.         phpmail($ema, $sb, $message);
  187.         $tot = db_select("select * from email where email != '" . $ema . "'", $rs);
  188.         for ($i=0;$i<$tot;$i++) {
  189.             phpmail($rs[$i]['email'], $sb, $message);
  190.         }  
  191.     }
  192. }
  193.  
  194.  
  195.  
  196. ?>
Advertisement
Add Comment
Please, Sign In to add comment