function saveVacationSettings($smarty, $module_name, $local_templates_dir, $pDB, $arrConf) { global $arrCredentials; $objAntispam = new paloSantoAntispam($arrConf['path_postfix'], $arrConf['path_spamassassin'], $arrConf['file_master_cf'], $arrConf['file_local_cf']); $pVacations = new paloMyVacation($pDB, $arrCredentials['idUser']); $jsonObject = new PaloSantoJSON(); $myVacation['init_date'] = getParameter('intiDate'); $myVacation['end_date'] = getParameter('endDate'); $myVacation['email_subject'] = getParameter('emailSubject'); $myVacation['email_body'] = getParameter('emailBody'); $email = $_SESSION['elastix_user']; $subject = $myVacation['email_subject']; $body = $myVacation['email_body']; $ini_date = $myVacation['init_date']; $end_date = $myVacation['end_date']; $timestamp0 = mktime(0, 0, 0, date("m"), date("d"), date("Y")); $timestamp1 = mktime(0, 0, 0, date("m", strtotime($ini_date)), date("d", strtotime($ini_date)), date("Y", strtotime($ini_date))); $timeSince = $timestamp0 - $timestamp1; if ($timeSince >= 0) { $myVacation['vacation'] = "yes"; } else { $myVacation['vacation'] = "no"; } $scripts = $objAntispam->existScriptSieve($email, "scriptTest.sieve"); $spamCapture = false; // si CapturaSpam=OFF y Vacations=OFF if ($scripts['actived'] != "") { // hay un script activo if (preg_match("/scriptTest.sieve/", $scripts['actived'])) { // si CapturaSpam=ON y Vacations=OFF $spamCapture = true; } // si CapturaSpam=ON y Vacations=OFF } $pVacations->_DB->beginTransaction(); if (!$pVacations->editVacation($myVacation)) { $pVacations->_DB->rollBack(); $jsonObject->set_error($pVacations->getErrorMsg()); return $jsonObject->createJSON(); } else { //mandamos a actualizar el script del sieve if ($timeSince >= 0) { $body = str_replace("{END_DATE}", $end_date, $body); $result = $pVacations->uploadVacationScript($email, $subject, $body, $objAntispam, $spamCapture); } else { $result = true; } if ($result) { $pVacations->_DB->commit(); $jsonObject->set_message("Changes were saved succefully"); } else { $pVacations->_DB->rollBack(); $jsonObject->set_error($pVacations->getErrorMsg()); } return $jsonObject->createJSON(); } }
$day_ini = date("d", strtotime($ini_date)); $month_ini = date("m", strtotime($ini_date)); $year_ini = date("Y", strtotime($ini_date)); $day_end = date("d", strtotime($end_date)); $month_end = date("m", strtotime($end_date)); $year_end = date("Y", strtotime($end_date)); $timestamp0 = mktime(0, 0, 0, $month_ini, $day_ini, $year_ini); $timestamp2 = mktime(0, 0, 0, $month_end, $day_end, $year_end); $spamCapture = false; $seconds0 = $timestamp1 - $timestamp0; //resto a una fecha la otra $seconds = $timestamp1 - $timestamp2; $dias = $seconds / (60 * 60 * 24); $dias = abs($dias); $dias = floor($dias); $scripts = $objAntispam->existScriptSieve($email, "scriptTest.sieve"); // verifica que usuarios no tienen activado el script de vacaciones if ($seconds0 >= 0 && $seconds <= 0) { // si la fecha inicial >= fecha actual entonces se debe subir el script $spamCapture0 = false; if (preg_match("/scriptTest.sieve/", $scripts['actived']) && $scripts['status']) { // si CapturaSpam=? y Vacations=ON $spamCapture0 = true; } $body = str_replace("{END_DATE}", $end_date, $body); $status = $pVacations->uploadVacationScript($email, $subject, $body, $objAntispam, $spamCapture0); } // elimina el script de vacaciones si el tiempo de sus vacaciones ya expiro if ($scripts['actived'] != "") { if (preg_match("/vacations.sieve/", $scripts['actived']) && $scripts['status']) { // si CapturaSpam=? y Vacations=ON
function disactivateEmailVacations($smarty, $module_name, $local_templates_dir, &$pDB, &$pDBACL, $arrConf, $arrLang) { $pVacations = new paloSantoVacations($pDB); $pACL = new paloACL($pDBACL); $objAntispam = new paloSantoAntispam($arrConf['path_postfix'], $arrConf['path_spamassassin'], $arrConf['file_master_cf'], $arrConf['file_local_cf']); $arrFormVacations = createFieldForm($arrLang); $oForm = new paloForm($smarty, $arrFormVacations); $id = getParameter("id"); $email = getParameter("email"); $subject = getParameter("subject"); $body = getParameter("body"); $ini_date = getParameter("ini_date"); $end_date = getParameter("end_date"); $result = ""; $userAccount = isset($_SESSION['elastix_user']) ? $_SESSION['elastix_user'] : ""; $idUserInt = $pACL->getIdUser($userAccount); $emails = $pVacations->getAccountByIdUser($idUserInt, $pDBACL); if (!$oForm->validateForm($_POST)) { // Falla la validación básica del formulario $strErrorMsg = "<b>" . _tr('The following fields contain errors') . ":</b><br/>"; $arrErrores = $oForm->arrErroresValidacion; if (is_array($arrErrores) && count($arrErrores) > 0) { foreach ($arrErrores as $k => $v) { $strErrorMsg .= "{$k}: [{$v['mensaje']}] <br /> "; } } $smarty->assign("mb_title", _tr("Validation Error")); $smarty->assign("mb_message", $strErrorMsg); return viewFormVacations($smarty, $module_name, $local_templates_dir, $pDB, $pDBACL, $arrConf, $arrLang); } if (!preg_match("/^[a-z0-9]+([\\._\\-]?[a-z0-9]+[_\\-]?)*@[a-z0-9]+([\\._\\-]?[a-z0-9]+)*(\\.[a-z0-9]{2,6})+\$/", $email)) { $smarty->assign("mb_title", _tr("Error")); $smarty->assign("mb_message", _tr('Email is empty or is not correct. Please write the email account.')); return viewFormVacations($smarty, $module_name, $local_templates_dir, $pDB, $pDBACL, $arrConf, $arrLang); } if ($email != $emails) { if (!$pACL->isUserAdministratorGroup($userAccount)) { $smarty->assign("mb_title", _tr("Error")); $smarty->assign("mb_message", _tr('Email is not correct. Please write the email assigned to your elastix account.')); return viewFormVacations($smarty, $module_name, $local_templates_dir, $pDB, $pDBACL, $arrConf, $arrLang); } } $timestamp0 = mktime(0, 0, 0, date("m"), date("d"), date("Y")); $timestamp1 = mktime(0, 0, 0, date("m", strtotime($ini_date)), date("d", strtotime($ini_date)), date("Y", strtotime($ini_date))); $timestamp2 = mktime(0, 0, 0, date("m", strtotime($end_date)), date("d", strtotime($end_date)), date("Y", strtotime($end_date))); $timeSince = $timestamp0 - $timestamp1; //resto a una fecha la otra $seconds = $timestamp2 - $timestamp1; $dias = $seconds / (60 * 60 * 24); $dias = floor($dias); $smarty->assign("num_days", $dias); if ($seconds < 0) { $smarty->assign("mb_title", _tr("Alert")); $smarty->assign("mb_message", _tr("End date should be greater than the initial date")); return viewFormVacations($smarty, $module_name, $local_templates_dir, $pDB, $pDBACL, $arrConf, $arrLang); } $statusSieve = $pVacations->verifySieveStatus($arrLang); if (!$statusSieve['response']) { $smarty->assign("mb_title", _tr("Alert")); $smarty->assign("mb_message", $statusSieve['message']); return viewFormVacations($smarty, $module_name, $local_templates_dir, $pDB, $pDBACL, $arrConf, $arrLang); } $pDB->beginTransaction(); $scripts = $objAntispam->existScriptSieve($email, "scriptTest.sieve"); $spamCapture = false; // si CapturaSpam=OFF y Vacations=OFF if ($scripts['actived'] != "") { // hay un script activo if (preg_match("/vacations.sieve/", $scripts['actived']) && $scripts['status']) { // si CapturaSpam=? y Vacations=ON $spamCapture = true; } // si CapturaSpam=ON y Vacations=OFF $band = $pVacations->existMessage($email); $res = ""; if ($band) { //actualizacion $arr_Vaca = $pVacations->getMessageVacationByUser($email); if (count($arr_Vaca) > 1) { $pVacations->deleteMessagesByUser($email, $subject, $body, $ini_date, $end_date); $res = $pVacations->insertMessageByUser($email, $subject, $body, $ini_date, $end_date, "no"); } else { $res = $pVacations->updateMessageByUser($email, $subject, $body, $ini_date, $end_date, "no"); } } else { // insersion $res = $pVacations->insertMessageByUser($email, $subject, $body, $ini_date, $end_date, "no"); } if ($res) { if ($timeSince >= 0) { $result = $pVacations->deleteVacationScript($email, $objAntispam, $spamCapture, $arrLang); } else { $result = true; } } else { $result = false; } } if ($result) { $pDB->commit(); $smarty->assign("mb_message", _tr("Email's Vacations have been disabled")); } else { $msgError = $pVacations->errMsg; $pDB->rollBack(); $smarty->assign("mb_message", $msgError); } return viewFormVacations($smarty, $module_name, $local_templates_dir, $pDB, $pDBACL, $arrConf, $arrLang); }