Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('php/config.php');
- require_once("php/functions.php");
- require_once($GLOBALS['cfg']['lpath'].'php/sesion.php');
- require_once($GLOBALS['cfg']['lpath'].'php/bd.php');
- if (!isset($_GET['op'])) {
- echo "Bad parameter";
- exit;
- }
- //make sure we have a correct timezone
- date_default_timezone_set('Europe/Madrid');
- ini_set('date.timezone','Europe/Madrid');
- ob_start('ot2');//el ajax espera utf-8
- if (isset($_GET['opmail'])) {
- send_mail();
- } else if ($_GET['op'] == 'get_events') {
- get_events();
- } else if ($_GET['op'] == 'add_event') {
- add_event();
- } else if ($_GET['op'] == 'delete_event') {
- delete_event();
- } else if ($_GET['op'] == 'update_event') {
- update_event();
- } else if ($_GET['op'] == 'get_ldaptelefono') {
- get_ldaptelefono();
- }
- //
- // FUNCTIONS
- //
- function update_event() {
- //comprobar que otro usuario no haya metido al mismo tiempo desde otra sesion en el mismo rango de fecha
- $fini = date('Y-m-d H:i:s',$_GET['start']);
- $ffin = date('Y-m-d H:i:s',$_GET['end']);
- $sql = "select id from eventos where id <> ".$_GET['evid']." and ((fini >= '" . $fini . "' and fini < '" . $ffin . "')";
- $sql .= " or (ffin > '" . $fini . "' and ffin <= '" . $ffin . "')";
- $sql .= " or (fini <= '" . $fini . "' and ffin >= '" . $ffin . "'))";
- $tot = db_select($sql,$rs);
- if ($tot) {
- echo 'TAKEN';
- exit;
- }
- if ($GLOBALS['cfg']['browser'] == 'gk') {//firefox se comporta distinto a ie y chrome
- $_GET['body'] = utf8_decode($_GET['body']);
- $_GET['title'] = utf8_decode($_GET['title']);
- }
- //update the event
- $sql = "update eventos set fini = '" . $fini . "',ffin = '" . $ffin . "',";
- $sql .= " obs = '" . $_GET['body'] . "', motivo = '" . $_GET['title'] . "'";
- $sql .= " where id = " . $_GET['evid'];
- $ret = db_query($sql);
- echo (int) $ret;
- }
- function delete_event() {
- $tot = db_select('select usuario from eventos where id = ' . $_GET['evid'],$rs);
- $affected = db_query('delete from eventos where id = ' . $_GET['evid']);
- echo (int) $affected;
- echo '|' . $rs[0]['usuario'];
- }
- function add_event() {
- //comprobar que otro usuario no haya metido al mismo tiempo desde otra sesion en el mismo rango de fecha
- $fini = date('Y-m-d H:i:s',$_GET['start']);
- $ffin = date('Y-m-d H:i:s',$_GET['end']);
- $sql = "select id from eventos where (fini >= '" . $fini . "' and fini < '" . $ffin . "')";
- $sql .= " or (ffin > '" . $fini . "' and ffin <= '" . $ffin . "')";
- $sql .= " or (fini <= '" . $fini . "' and ffin >= '" . $ffin . "')";
- $tot = db_select($sql,$rs);
- if ($tot) {
- echo 'TAKEN';
- exit;
- }
- if ($GLOBALS['cfg']['browser'] == 'gk') {//firefox se comporta distinto a ie y chrome
- $_GET['body'] = utf8_decode($_GET['body']);
- $_GET['title'] = utf8_decode($_GET['title']);
- }
- //insert the event
- $sql = 'insert into eventos(fini,ffin,usuario,obs,motivo) values (';
- $sql .= "'" . $fini . "','" . $ffin;
- $sql .= "','" . $_SESSION['usu'] . "','" . $_GET['body'] . "','" . $_GET['title'] . "')";
- $ret = db_query($sql);
- echo (int) $ret . '|' . $_SESSION['usu'];
- }
- function get_events() {
- //$lastyear = time() - (365 * 60 * 60 * 24);//Cargar eventos solo de un año hacia atras
- //$fini = date('Y-m-d H:i:s',$lastyear);
- $fini = date('Y-m-d H:i:s',$_GET['start']);
- $ffin = date('Y-m-d H:i:s',$_GET['end']);
- $tot = db_select("select * from eventos where fini >= '" . $fini . "' and fini <= '" . $ffin . "'", $rs);
- db_select("select val from config where name='dominio_mail'", $rsi);
- echo '{"events":['."\n";
- $ronly = '';
- $esadmin = $_SESSION['perfil'] == 'ADM';
- $ultimo = $tot - 1;
- for ($i=0;$i<$tot;$i++) {
- if (!$esadmin) {
- $ronly = $_SESSION['usu'] == $rs[$i]['usuario'] ? '' : ',readOnly : true';
- }
- echo '{
- "id":'.$rs[$i]['id'].',
- "start": "'.date('c', strtotime($rs[$i]['fini'])).'",
- "end": "'.date('c', strtotime($rs[$i]['ffin'])).'",
- "title":"'.$rs[$i]['motivo'].'",
- "usermail":"'.$rs[$i]['usuario']. $rsi[0]['val'].'",
- "body":"'.$rs[$i]['obs'].'"
- '.$ronly.'}';
- if ($i != $ultimo) {
- echo ',';
- }
- }
- echo ']}';
- }
- function ot2($s) {
- return utf8_encode($s);
- }
- function get_ldaptelefono() {
- $newrep = array('telephonenumber' => '', 'agedateofbirth' => '', 'ageorganizationdesc' => '', 'email' => '', 'givenname' => '', 'sn' => '', 'initials' => '' , 'mdslinktocv' => '');
- get_ldap_fields ($_GET['user'], $newrep);
- echo $newrep['telephonenumber'];
- }
- function send_mail() {//función para enviar email en el alta, update y delete de una reserva:
- $tot = db_select("select val from config where name='dominio_mail'", $rs);
- $mail=$rs[0]['val'];
- if ($_GET['op'] == 'add_event') {//ALTA RESERVA
- $fini = date('Y-m-d H:i:s',$_GET['start']);
- $ffin = date('Y-m-d H:i:s',$_GET['end']);
- $hi = explode(" ", $fini);
- $hf = explode(" ", $ffin);
- $hi=substr($hi[1],0,5);
- $hf=substr($hf[1],0,5);
- if ($GLOBALS['cfg']['browser'] == 'gk') {//firefox se comporta distinto a ie y chrome
- $_GET['body'] = utf8_decode($_GET['body']);
- $_GET['title'] = utf8_decode($_GET['title']);
- }
- $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'];
- $sb="Nueva Reserva de la Sala de Reuniones";
- $ema = $_SESSION['usu'].$mail;
- phpmail($ema, $sb, $message);
- $tot = db_select("select * from email where email != '" . $ema . "'", $rs);
- for ($i=0;$i<$tot;$i++) {
- phpmail($rs[$i]['email'], $sb, $message);
- }
- } else if ($_GET['op'] == 'delete_event') {//BORRADO RESERVA
- $fini = date('Y-m-d H:i:s',$_GET['start']);
- $ffin = date('Y-m-d H:i:s',$_GET['end']);
- $hi = explode(" ", $fini);
- $hf = explode(" ", $ffin);
- $hi=substr($hi[1],0,5);
- $hf=substr($hf[1],0,5);
- if ($GLOBALS['cfg']['browser'] == 'gk') {//firefox se comporta distinto a ie y chrome
- $_GET['body'] = utf8_decode($_GET['body']);
- $_GET['title'] = utf8_decode($_GET['title']);
- }
- $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'];
- $sb="Eliminación de Reserva de la Sala de Reuniones";
- $ema = $_SESSION['usu'].$mail;
- phpmail($ema, $sb, $message);
- $tot = db_select("select * from email where email != '" . $ema . "'", $rs);
- for ($i=0;$i<$tot;$i++) {
- phpmail($rs[$i]['email'], $sb, $message);
- }
- } else if ($_GET['op'] == 'update_event') {//ACTUALIZACIÓN RESERVA
- $fini = date('Y-m-d H:i:s',$_GET['start']);
- $ffin = date('Y-m-d H:i:s',$_GET['end']);
- $hi = explode(" ", $fini);
- $hf = explode(" ", $ffin);
- $hi=substr($hi[1],0,5);
- $hf=substr($hf[1],0,5);
- if ($GLOBALS['cfg']['browser'] == 'gk') {//firefox se comporta distinto a ie y chrome
- $_GET['body'] = utf8_decode($_GET['body']);
- $_GET['title'] = utf8_decode($_GET['title']);
- }
- $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'];
- $sb="Actualización de Reserva de la Sala de Reuniones";
- $tot = db_select("select usuario from eventos where id=".$_GET['evid'], $rs);
- $ema = $_SESSION['usu'].$mail;
- phpmail($ema, $sb, $message);
- $tot = db_select("select * from email where email != '" . $ema . "'", $rs);
- for ($i=0;$i<$tot;$i++) {
- phpmail($rs[$i]['email'], $sb, $message);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment