function saveEvent($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $arrLang) { $pCalendar = new paloSantoCalendar($pDB); $user = isset($_SESSION['elastix_user']) ? $_SESSION['elastix_user'] : ""; $uid = Obtain_UID_From_User($user, $arrConf); $pDB3 = new paloDB($arrConf['dsn_conn_database1']); $ext = $pCalendar->obtainExtension($pDB3, $uid); $_DATA = $_POST; $action = getParameter("action"); $id = getParameter("id_event"); $event = getParameter("event"); $description = getParameter("description"); $date_ini = getParameter("date"); $date_end = getParameter("to"); $color = getParameter("colorHex"); // options call reminder $reminder = getParameter("reminder"); // puede ser on o off $call_to = getParameter("call_to"); // elemento Call to $remainerTime = getParameter("ReminderTime"); // tiempo de recordatorio 10, 20, 30 minutos antes $recording = getParameter("tts"); // options email notification $notification = getParameter("notification"); // puede ser on o off $notification_email = getParameter("notification_email"); // si es notification==off => no se toma en cuenta esta variable $list = getParameter("emails"); $hora = date('H', strtotime($date_ini)); $minuto = date('i', strtotime($date_ini)); $hora2 = date('H', strtotime($date_end)); $minuto2 = date('i', strtotime($date_end)); $asterisk_calls = ""; $each_repeat = 1; $repeat = "none"; $event_type = 0; if (!ctype_digit($id)) { $id = NULL; } if (!preg_match("/^#\\w{3,6}\$/", $color)) { $color = "#3366CC"; } $_GET['event_date'] = date("Y-m-d", strtotime($date_ini)); $start_event = strtotime($date_ini); $end_event = strtotime($date_end); $end_event2 = $end_event; //validar si la primera fecha es menor que la segunda if ($event != "") { if ($start_event <= $end_event) { if ($reminder == "on") { //Configure a phone call reminder $asterisk_calls = $reminder; if ($asterisk_calls == "on") { // si es on entonces el campo call_to es vacio if ($call_to == null || $call_to == "") { $link = "<a href='?menu=userlist'>" . $arrLang['user_list'] . "</a>"; $smarty->assign("mb_message", $arrLang['error_ext'] . $link); $content = viewForm_NewEvent($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang); return $content; } } else { // se asigna una extension cualquiera if ($call_to == "") { $smarty->assign("mb_message", $arrLang['error_call_to']); $content = viewForm_NewEvent($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang); return $content; } } // Número a llamar sólo puede ser numérico if (!preg_match('/^\\d+$/', $call_to)) { $smarty->assign("mb_message", _tr('Invalid extension to call for reminder')); $content = viewForm_NewEvent($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang); return $content; } // Texto a generar no debe contener saltos de línea if (count(preg_split("/[\r\n]+/", $recording)) > 1) { $smarty->assign("mb_message", _tr('Reminder text may not have newlines')); $content = viewForm_NewEvent($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang); return $content; } } else { $call_to = ""; $asterisk_calls = "off"; $recording = ""; $remainerTime = ""; } if ($notification == "on") { // si ingresa emails o contactos $list = htmlspecialchars_decode($list); // codifica los caracteres especiales $notification_email = $list; } else { $notification_email = ""; $notification = "off"; } $start = date('Y-m-d', $start_event); $end = date('Y-m-d', $end_event); $checkbox_days = getConvertDay($start_event); $starttime = date('Y-m-d', $start_event) . " " . $hora . ":" . $minuto; $endtime = date('Y-m-d', $end_event2) . " " . $hora2 . ":" . $minuto2; $day_repeat = explode(',', $checkbox_days); $event_type = 1; $num_frec = 0; if ($repeat == "none") { //solo un dia $event_type = 1; $num_frec = 0; } if ($repeat == "each_day") { //dias que se repiten durante un numero de semanas $event_type = 5; $num_frec = 7; } if ($repeat == "each_month") { //dias que se repiten durante un numero de meses $event_type = 6; $num_frec = 30; } // dataToSendEmail $data_Send['emails_notification'] = $notification_email; $data_Send['startdate'] = $start; $data_Send['enddate'] = $end; $data_Send['starttime'] = $starttime; $data_Send['eventtype'] = $event_type; $data_Send['subject'] = $event; $data_Send['description'] = $description; $data_Send['endtime'] = $endtime; if (getParameter("save_edit")) { // si se va modificar un evento existente $dataUp = $pCalendar->getEventById($id, $uid); if ($dataUp != "" && isset($dataUp)) { $val = $pCalendar->updateEvent($id, $start, $end, $starttime, $event_type, $event, $description, $asterisk_calls, $recording, $call_to, $notification, $notification_email, $endtime, $each_repeat, $checkbox_days, $remainerTime, $color); } else { $val = false; } if ($val == true) { if ($notification_email != "") { sendMails($data_Send, $arrLang, "UPDATE", $arrConf, $pDB, $module_name, $id); } if ($reminder == "on") { createRepeatAudioFile($each_repeat, $day_repeat, $starttime, $endtime, $num_frec, $asterisk_calls, $ext, $call_to, $pDB, $id, $arrLang, $arrConf, $recording, $remainerTime); } else { //borra los .call que existan asociados a este evento $dir_outgoing = $arrConf['dir_outgoing']; system("rm -f {$dir_outgoing}/event_{$id}_*.call"); // si existen lo archivos los elimina } $smarty->assign("mb_message", $arrLang['update_successful']); $content = viewCalendar($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang); return $content; } else { $smarty->assign("mb_message", $arrLang['error_update']); $content = viewCalendar($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang); return $content; } } else { if (getParameter("save_new")) { // si se va a ingresar un nuevo evento $val = $pCalendar->insertEvent($uid, $start, $end, $starttime, $event_type, $event, $description, $asterisk_calls, $recording, $call_to, $notification, $notification_email, $endtime, $each_repeat, $checkbox_days, $remainerTime, $color); $id = $pDB->getLastInsertId(); if ($val == true) { if ($notification_email != "") { sendMails($data_Send, $arrLang, "NEW", $arrConf, $pDB, $module_name, $id); } if ($reminder == "on") { createRepeatAudioFile($each_repeat, $day_repeat, $starttime, $endtime, $num_frec, $asterisk_calls, $ext, $call_to, $pDB, $id, $arrLang, $arrConf, $recording, $remainerTime); } $smarty->assign("mb_message", $arrLang['insert_successful']); $content = viewCalendar($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang); return $content; } else { $smarty->assign("mb_message", $arrLang['error_insert']); $content = viewCalendar($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang); return $content; } } else { $smarty->assign("mb_message", $arrLang['error_insert']); $content = viewCalendar($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang); return $content; } } } else { $smarty->assign("mb_message", $arrLang['error_date']); $content = viewCalendar($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang); return $content; } } else { $smarty->assign("mb_message", $arrLang['error_eventName']); $content = viewCalendar($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang); return $content; } }