function Update() { if (CSupportUpdate::CurrentVersionLowerThanUpdateVersion()) { $dbType = CSupportUpdate::GetBD(); $res = self::AlterTables($dbType); if (!$res) { return false; } $res = self::SeparateSLAandTimeTable($dbType); if (!$res) { return false; } CSupportTimetableCache::toCache(); CTicketReminder::RecalculateSupportDeadline(); CTicketReminder::StartAgent(); CSupportUpdate::ChangeCurrentVersion(); self::SetHotKeys(); } }
function Set($arFields, $arFieldsShedule) { global $DB, $APPLICATION; $err_mess = self::err_mess() . "<br>Function: Set<br>Line: "; $isDemo = null; $isSupportClient = null; $isSupportTeam = null; $isAdmin = null; $isAccess = null; $userID = null; CTicket::GetRoles($isDemo, $isSupportClient, $isSupportTeam, $isAdmin, $isAccess, $userID); if (!$isAdmin) { $arMsg = array(); $arMsg[] = array("id" => "PERMISSION", "text" => GetMessage("SUP_ERROR_ACCESS_DENIED")); $e = new CAdminException($arMsg); $APPLICATION->ThrowException($e); return false; } if (is_array($arFields)) { $f = new CSupportTableFields(self::$fieldsTypes); $f->FromArray($arFields); } else { $f = $arFields; } if (is_array($arFieldsShedule)) { $f_s = new CSupportTableFields(self::$fieldsTypesShedule, CSupportTableFields::C_Table); $f_s->FromTable($arFieldsShedule); } else { $f_s = $arFieldsShedule; } $table = self::TABLE; $table_shedule = self::TABLE_SHEDULE; $id = $f->ID; $isNew = $f->ID <= 0; if (strlen($f->NAME) <= 0) { $APPLICATION->ThrowException(GetMessage('SUP_ERROR_EMPTY_NAME')); return false; } $arFields_i = $f->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL, CSupportTableFields::NOT_DEFAULT), true); $res = 0; if (count($arFields_i) > 0) { if ($isNew) { $res = $DB->Insert($table, $arFields_i, $err_mess . __LINE__); } else { $res = $DB->Update($table, $arFields_i, "WHERE ID=" . $id . "", $err_mess . __LINE__); } } if (intval($res) <= 0) { $APPLICATION->ThrowException(GetMessage('SUP_ERROR_DB_ERROR')); return false; } if ($isNew) { $id = $res; } $DB->Query("DELETE FROM {$table_shedule} WHERE TIMETABLE_ID = {$id}", false, $err_mess . __LINE__); $noWrite = array(); $f_s->ResetNext(); while ($f_s->Next()) { $f_s->TIMETABLE_ID = $id; if (isset($noWrite[$f_s->WEEKDAY_NUMBER]) && ($noWrite[$f_s->WEEKDAY_NUMBER] != "CUSTOM" || $f_s->OPEN_TIME != "CUSTOM")) { continue; } if ($f_s->OPEN_TIME == "CUSTOM" && $f_s->MINUTE_FROM <= 0 && $f_s->MINUTE_TILL <= 0) { continue; } $DB->Insert($table_shedule, $f_s->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL), true), $err_mess . __LINE__); $noWrite[$f_s->WEEKDAY_NUMBER] = $f_s->OPEN_TIME; } for ($i = 0; $i <= 6; $i++) { $a = array("SLA_ID" => 0, "TIMETABLE_ID" => intval($id), "WEEKDAY_NUMBER" => intval($i), "OPEN_TIME" => "'CLOSED'", "MINUTE_FROM" => null, "MINUTE_TILL" => null); if (!isset($noWrite[$i])) { $DB->Insert($table_shedule, $a, $err_mess . __LINE__); } } // recalculate only affected sla $affected_sla = array(); $res = $DB->Query("SELECT ID FROM b_ticket_sla WHERE TIMETABLE_ID = {$id}"); while ($row = $res->Fetch()) { $affected_sla[] = $row['ID']; } CSupportTimetableCache::toCache(array('SLA_ID' => $affected_sla)); return $id; }
public static function Set($arFields, $id, $checkRights = true) { $err_mess = CAllTicketSLA::err_mess() . "<br>Function: Set<br>Line: "; global $DB, $USER, $APPLICATION; $id = intval($id); $table = "b_ticket_sla"; $isDemo = $isSupportClient = $isSupportTeam = $isAdmin = $isAccess = $userID = null; CTicket::GetRoles($isDemo, $isSupportClient, $isSupportTeam, $isAdmin, $isAccess, $userID, $checkRights); if ($isAdmin) { $validDeadlineSource = !isset($arFields['DEADLINE_SOURCE']) || in_array($arFields['DEADLINE_SOURCE'], array('', 'DATE_CREATE'), true); if (CTicket::CheckFields($arFields, $id, array("NAME", "TIMETABLE_ID")) && $validDeadlineSource) { $arFields_i = CTicket::PrepareFields($arFields, $table, $id); if (intval($id) > 0) { $DB->Update($table, $arFields_i, "WHERE ID=" . intval($id), $err_mess . __LINE__); } else { $id = $DB->Insert($table, $arFields_i, $err_mess . __LINE__); } if (intval($id) > 0) { if (is_set($arFields, "arGROUPS")) { $DB->Query("DELETE FROM b_ticket_sla_2_user_group WHERE SLA_ID = {$id}", false, $err_mess . __LINE__); if (is_array($arFields["arGROUPS"]) && count($arFields["arGROUPS"]) > 0) { foreach ($arFields["arGROUPS"] as $groupID) { $groupID = intval($groupID); if ($groupID > 0) { $strSql = "INSERT INTO b_ticket_sla_2_user_group (SLA_ID, GROUP_ID) VALUES ({$id}, {$groupID})"; $DB->Query($strSql, false, $err_mess . __LINE__); } } } } if (is_set($arFields, "arSITES")) { $DB->Query("DELETE FROM b_ticket_sla_2_site WHERE SLA_ID = {$id}", false, $err_mess . __LINE__); if (is_array($arFields["arSITES"]) && count($arFields["arSITES"]) > 0) { foreach ($arFields["arSITES"] as $siteID) { //if (strlen($FIRST_SITE_ID)<=0) $FIRST_SITE_ID = $siteID; $FIRST_SITE_ID = $siteID; $siteID = $DB->ForSql($siteID); $strSql = "INSERT INTO b_ticket_sla_2_site (SLA_ID, SITE_ID) VALUES ({$id}, '{$siteID}')"; $DB->Query($strSql, false, $err_mess . __LINE__); } } } if (is_set($arFields, "arCATEGORIES")) { $DB->Query("DELETE FROM b_ticket_sla_2_category WHERE SLA_ID = {$id}", false, $err_mess . __LINE__); if (is_array($arFields["arCATEGORIES"]) && count($arFields["arCATEGORIES"]) > 0) { foreach ($arFields["arCATEGORIES"] as $categoryID) { $categoryID = intval($categoryID); $strSql = "INSERT INTO b_ticket_sla_2_category (SLA_ID, CATEGORY_ID) VALUES ({$id}, {$categoryID})"; $DB->Query($strSql, false, $err_mess . __LINE__); } } } if (is_set($arFields, "arCRITICALITIES")) { $DB->Query("DELETE FROM b_ticket_sla_2_criticality WHERE SLA_ID = {$id}", false, $err_mess . __LINE__); if (is_array($arFields["arCRITICALITIES"]) && count($arFields["arCRITICALITIES"]) > 0) { foreach ($arFields["arCRITICALITIES"] as $criticalityID) { $criticalityID = intval($criticalityID); $strSql = "INSERT INTO b_ticket_sla_2_criticality (SLA_ID, CRITICALITY_ID) VALUES ({$id}, {$criticalityID})"; $DB->Query($strSql, false, $err_mess . __LINE__); } } } if (is_set($arFields, "arMARKS")) { $DB->Query("DELETE FROM b_ticket_sla_2_mark WHERE SLA_ID = {$id}", false, $err_mess . __LINE__); if (is_array($arFields["arMARKS"]) && count($arFields["arMARKS"]) > 0) { foreach ($arFields["arMARKS"] as $markID) { $markID = intval($markID); $strSql = "INSERT INTO b_ticket_sla_2_mark (SLA_ID, MARK_ID) VALUES ({$id}, {$markID})"; $DB->Query($strSql, false, $err_mess . __LINE__); } } } /* if (is_set($arFields, "arSHEDULE")) { $DB->Query("DELETE FROM b_ticket_sla_shedule WHERE SLA_ID = $id", false, $err_mess.__LINE__); if (is_array($arFields["arSHEDULE"]) && count($arFields["arSHEDULE"])>0) { while(list($weekday, $arSHEDULE) = each($arFields["arSHEDULE"])) { $arF = array( "SLA_ID" => $id, "WEEKDAY_NUMBER" => intval($weekday), "OPEN_TIME" => "'".$DB->ForSql($arSHEDULE["OPEN_TIME"], 10)."'", ); if ($arSHEDULE["OPEN_TIME"]=="CUSTOM" && is_array($arSHEDULE["CUSTOM_TIME"]) && count($arSHEDULE["CUSTOM_TIME"])>0) { foreach($arSHEDULE["CUSTOM_TIME"] as $ar) { if (strlen(trim($ar["MINUTE_FROM"]))>0 || strlen(trim($ar["MINUTE_TILL"]))>0) { $minute_from = strlen($ar["MINUTE_FROM"])>0 ? $ar["MINUTE_FROM"] : "00:00"; $a = explode(":",$minute_from); $minute_from = intval($a[0]*60 + $a[1]); $arF["MINUTE_FROM"] = $minute_from; $minute_till = strlen($ar["MINUTE_TILL"])>0 ? $ar["MINUTE_TILL"] : "23:59"; $a = explode(":",$minute_till); $minute_till = intval($a[0]*60 + $a[1]); $arF["MINUTE_TILL"] = $minute_till; $DB->Insert("b_ticket_sla_shedule", $arF, $err_mess.__LINE__); } } } else $DB->Insert("b_ticket_sla_shedule", $arF, $err_mess.__LINE__); } } } */ $FIRST_SITE_ID = strlen($FIRST_SITE_ID) > 0 ? "'" . $DB->ForSql($FIRST_SITE_ID) . "'" : "null"; $DB->Update($table, array("FIRST_SITE_ID" => $FIRST_SITE_ID), "WHERE ID=" . intval($id), $err_mess . __LINE__); } } } else { //$APPLICATION->ThrowException(GetMessage("SUP_ERROR_ACCESS_DENIED")); $arMsg = array(); $arMsg[] = array("id" => "PERMISSION", "text" => GetMessage("SUP_ERROR_ACCESS_DENIED")); $e = new CAdminException($arMsg); $APPLICATION->ThrowException($e); } CSupportTimetableCache::toCache(array("SLA_ID" => $id)); return $id; }
function Delete($id, $checkRights = true) { $err_mess = self::err_mess() . "<br>Function: Delete<br>Line: "; global $DB, $USER, $APPLICATION; $id = intval($id); $table = self::TABLE; $tableShedule = self::TABLE_SHEDULE; if ($id <= 0) { return false; } $isDemo = null; $isSupportClient = null; $isSupportTeam = null; $isAdmin = null; $isAccess = null; $userID = null; CTicket::GetRoles($isDemo, $isSupportClient, $isSupportTeam, $isAdmin, $isAccess, $userID, $checkRights); if (!$isAdmin) { $arMsg = array(); $arMsg[] = array("id" => "PERMISSION", "text" => GetMessage("SUP_ERROR_ACCESS_DENIED")); $e = new CAdminException($arMsg); $APPLICATION->ThrowException($e); return false; } $strSql = "SELECT DISTINCT 'x' FROM b_ticket WHERE SLA_ID = {$id}"; $rs = $DB->Query($strSql, false, $err_mess . __LINE__); if (!$rs->Fetch()) { $DB->Query("DELETE FROM {$table} WHERE ID = {$id}", false, $err_mess . __LINE__); $DB->Query("DELETE FROM {$tableShedule} WHERE TIMETABLE_ID = {$id}", false, $err_mess . __LINE__); CSupportTimetableCache::toCache(); return true; } else { $APPLICATION->ThrowException(str_replace("#ID#", "{$id}", GetMessage("SUP_ERROR_TIMETABLE_HAS_SLA"))); } return false; }
function Delete($id, $checkRights = true) { $err_mess = CAllTicketSLA::err_mess() . "<br>Function: Delete<br>Line: "; global $DB, $USER, $APPLICATION; $id = intval($id); if ($id < 1) { return false; } if ($id == 1) { $APPLICATION->ThrowException(GetMessage("SUP_ERROR_SLA_1")); return false; } CTicket::GetRoles($isDemo, $isSupportClient, $isSupportTeam, $isAdmin, $isAccess, $userID, $checkRights); if ($isAdmin) { $strSql = "SELECT DISTINCT 'x' FROM b_ticket WHERE SLA_ID = {$id}"; $rs = $DB->Query($strSql, false, $err_mess . __LINE__); if (!$rs->Fetch()) { $DB->Query("DELETE FROM b_ticket_sla_2_site WHERE SLA_ID = {$id}", false, $err_mess . __LINE__); $DB->Query("DELETE FROM b_ticket_sla_2_category WHERE SLA_ID = {$id}", false, $err_mess . __LINE__); $DB->Query("DELETE FROM b_ticket_sla_2_criticality WHERE SLA_ID = {$id}", false, $err_mess . __LINE__); $DB->Query("DELETE FROM b_ticket_sla_2_mark WHERE SLA_ID = {$id}", false, $err_mess . __LINE__); $DB->Query("DELETE FROM b_ticket_sla_2_user_group WHERE SLA_ID = {$id}", false, $err_mess . __LINE__); //$DB->Query("DELETE FROM b_ticket_sla_shedule WHERE SLA_ID = $id", false, $err_mess.__LINE__); $DB->Query("DELETE FROM b_ticket_sla_2_holidays WHERE SLA_ID = {$id}", false, $err_mess . __LINE__); $DB->Query("DELETE FROM b_ticket_sla WHERE ID = {$id}", false, $err_mess . __LINE__); CSupportTimetableCache::toCache(); return true; } else { $APPLICATION->ThrowException(str_replace("#ID#", "{$id}", GetMessage("SUP_ERROR_SLA_HAS_TICKET"))); } } else { $APPLICATION->ThrowException(GetMessage("SUP_ERROR_ACCESS_DENIED")); } return false; }
function RecalculateSupportDeadlineForOneTicket($arTicket, $arFields = array(), $dateType = array("EVENT"=>array(CTicket::IGNORE))) { global $DB; $err_mess = (CAllTicketReminder::err_mess())."<br>Function: RecalculateSupportDeadlineForOneTicket<br>Line: "; $currDateTS = time() + CTimeZone::GetOffset(); $ts2010 = mktime(0, 0, 0, 1, 1, 2010); $supportDeadlineNotify = 0; $ticketID = intval($arTicket["ID"]); $slaID = intval($arTicket["SLA_ID"]); $periodMin = self::ConvertResponseTimeUnit($arTicket["RESPONSE_TIME"], $arTicket["RESPONSE_TIME_UNIT"]); $periodNMin = 0; if($ticketID <= 0 || $slaID <= 0 || $periodMin <= 0 || intval($arTicket["D_1_USER_M_AFTER_SUP_M"]) <= 0) { if($ticketID > 0 && count($arFields) > 0) { $DB->Update("b_ticket", $arFields, "WHERE ID='" . $ticketID . "'", $err_mess . __LINE__); } return; } $periodNMinMinus = self::ConvertResponseTimeUnit($arTicket["NOTICE_TIME"], $arTicket["NOTICE_TIME_UNIT"]); if($periodNMinMinus > 0 && $periodNMinMinus < $periodMin) { $periodNMin = $periodMin - $periodNMinMinus; } $newDate1UserMessAfterSupMessTS = MakeTimeStamp($arTicket["D_1_USER_M_AFTER_SUP_M"]); $deadlineSourceDate = MakeTimeStamp($arTicket["DEADLINE_SOURCE_DATE"]); if($deadlineSourceDate <= $ts2010) { if($newDate1UserMessAfterSupMessTS <= $ts2010) { $deadlineSourceDate = $currDateTS; } else { $deadlineSourceDate = $newDate1UserMessAfterSupMessTS; } $arFields["DEADLINE_SOURCE_DATE"] = $DB->CharToDateFunction(GetTime($deadlineSourceDate,"FULL")); } $oldPeriodMin = null; if(isset($dateType["EVENT"]) && in_array(CTicket::UPDATE, $dateType["EVENT"])) { if(isset($dateType["OLD_SLA_RESPONSE_TIME"]) && isset($dateType["OLD_SLA_RESPONSE_TIME_UNIT"])) { $oldPeriodMin = self::ConvertResponseTimeUnit($dateType["OLD_SLA_RESPONSE_TIME"], $dateType["OLD_SLA_RESPONSE_TIME_UNIT"]); } if( in_array(CTicket::REOPEN, $dateType["EVENT"]) || ( in_array(CTicket::NEW_SLA, $dateType["EVENT"]) && ($arTicket["IS_OVERDUE"] != "Y") && ($oldPeriodMin != null) && ($oldPeriodMin > $periodMin) ) ) { $deadlineSourceDate = $currDateTS; $arFields["DEADLINE_SOURCE_DATE"] = $DB->CharToDateFunction(GetTime($deadlineSourceDate,"FULL")); } elseif(($arTicket["IS_OVERDUE"] != "Y") && ($newDate1UserMessAfterSupMessTS > $deadlineSourceDate)) { $deadlineSourceDate = $newDate1UserMessAfterSupMessTS; $arFields["DEADLINE_SOURCE_DATE"] = $arFields["D_1_USER_M_AFTER_SUP_M"]; } } $supportDeadlineTS = CSupportTimetableCache::getEndDate($slaID, $periodMin, GetTime($deadlineSourceDate,"FULL")); $arFields["SUPPORT_DEADLINE"] = $DB->CharToDateFunction(GetTime($supportDeadlineTS, "FULL")); $arFields["IS_OVERDUE"] = (($supportDeadlineTS <= $currDateTS) ? "'Y'" : "'N'"); if($periodNMin > 0) { $supportDeadlineNotifyTS = CSupportTimetableCache::getEndDate($slaID, $periodNMin, GetTime($deadlineSourceDate,"FULL")); $arFields["SUPPORT_DEADLINE_NOTIFY"] = $DB->CharToDateFunction(GetTime($supportDeadlineNotifyTS, "FULL")); $arFields["IS_NOTIFIED"] = (($supportDeadlineNotifyTS <= $currDateTS) ? "'Y'" : "'N'"); } $DB->Update("b_ticket", $arFields, "WHERE ID='" . $ticketID . "'", $err_mess . __LINE__); }
public static function RecalculateSupportDeadlineForOneTicket($arTicket, $arFields = array(), $dateType = array("EVENT" => array(CTicket::IGNORE))) { global $DB; $err_mess = CAllTicketReminder::err_mess() . "<br>Function: RecalculateSupportDeadlineForOneTicket<br>Line: "; $currDateTS = time() + CTimeZone::GetOffset(); $ts2010 = mktime(0, 0, 0, 1, 1, 2010); $supportDeadlineNotify = 0; $ticketID = intval($arTicket["ID"]); $slaID = intval($arTicket["SLA_ID"]); $periodMin = self::ConvertResponseTimeUnit($arTicket["RESPONSE_TIME"], $arTicket["RESPONSE_TIME_UNIT"]); $periodNMin = 0; if ($ticketID <= 0 || $slaID <= 0 || $periodMin <= 0 || intval($arTicket["D_1_USER_M_AFTER_SUP_M"]) <= 0) { if ($ticketID > 0 && count($arFields) > 0) { $DB->Update("b_ticket", $arFields, "WHERE ID='" . $ticketID . "'", $err_mess . __LINE__); } return; } $periodNMinMinus = self::ConvertResponseTimeUnit($arTicket["NOTICE_TIME"], $arTicket["NOTICE_TIME_UNIT"]); if ($periodNMinMinus > 0 && $periodNMinMinus < $periodMin) { $periodNMin = $periodMin - $periodNMinMinus; } $newDate1UserMessAfterSupMessTS = MakeTimeStamp($arTicket["D_1_USER_M_AFTER_SUP_M"]); $deadlineSourceDate = MakeTimeStamp($arTicket["DEADLINE_SOURCE_DATE"]); if ($deadlineSourceDate <= $ts2010) { if ($newDate1UserMessAfterSupMessTS <= $ts2010) { $deadlineSourceDate = $currDateTS; } else { $deadlineSourceDate = $newDate1UserMessAfterSupMessTS; } $arFields["DEADLINE_SOURCE_DATE"] = $DB->CharToDateFunction(GetTime($deadlineSourceDate, "FULL")); } $oldPeriodMin = null; if (isset($dateType["EVENT"]) && in_array(CTicket::UPDATE, $dateType["EVENT"])) { if (isset($dateType["OLD_SLA_RESPONSE_TIME"]) && isset($dateType["OLD_SLA_RESPONSE_TIME_UNIT"])) { $oldPeriodMin = self::ConvertResponseTimeUnit($dateType["OLD_SLA_RESPONSE_TIME"], $dateType["OLD_SLA_RESPONSE_TIME_UNIT"]); } if (in_array(CTicket::REOPEN, $dateType["EVENT"]) || in_array(CTicket::NEW_SLA, $dateType["EVENT"]) && $arTicket["IS_OVERDUE"] != "Y" && $oldPeriodMin != null && $oldPeriodMin > $periodMin) { $deadlineSourceDate = $currDateTS; $arFields["DEADLINE_SOURCE_DATE"] = $DB->CharToDateFunction(GetTime($deadlineSourceDate, "FULL")); } elseif ($arTicket["IS_OVERDUE"] != "Y" && $newDate1UserMessAfterSupMessTS > $deadlineSourceDate) { $sla = CTicketSLA::getById($slaID)->Fetch(); if (empty($sla['DEADLINE_SOURCE'])) { // default deadline calculation // date of first client message after support message $deadlineSourceDate = $newDate1UserMessAfterSupMessTS; $arFields["DEADLINE_SOURCE_DATE"] = $arFields["D_1_USER_M_AFTER_SUP_M"]; } } } $supportDeadlineTS = CSupportTimetableCache::getEndDate($slaID, $periodMin, GetTime($deadlineSourceDate, "FULL")); $arFields["SUPPORT_DEADLINE"] = $DB->CharToDateFunction(GetTime($supportDeadlineTS, "FULL")); $arFields["IS_OVERDUE"] = $supportDeadlineTS <= $currDateTS ? "'Y'" : "'N'"; // exec event and confirm if overdue if ($arTicket['IS_OVERDUE'] == "N" && $arFields['IS_OVERDUE'] == "'Y'") { $rs = GetModuleEvents('support', 'OnBeforeTicketExpire'); while ($arr = $rs->Fetch()) { $arFields = ExecuteModuleEventEx($arr, array($ticketID, $arFields)); if (!$arFields) { return false; } } } if ($periodNMin > 0) { $supportDeadlineNotifyTS = CSupportTimetableCache::getEndDate($slaID, $periodNMin, GetTime($deadlineSourceDate, "FULL")); $arFields["SUPPORT_DEADLINE_NOTIFY"] = $DB->CharToDateFunction(GetTime($supportDeadlineNotifyTS, "FULL")); $arFields["IS_NOTIFIED"] = $supportDeadlineNotifyTS <= $currDateTS ? "'Y'" : "'N'"; // exec event and confirm if set notified if ($arTicket['IS_NOTIFIED'] == "N" && $arFields['IS_NOTIFIED'] == "'Y'") { $rs = GetModuleEvents('support', 'OnBeforeTicketNotify'); while ($arr = $rs->Fetch()) { $arFields = ExecuteModuleEventEx($arr, array($ticketID, $arFields)); if (!$arFields) { return false; } } } } $DB->Update("b_ticket", $arFields, "WHERE ID='" . $ticketID . "'", $err_mess . __LINE__); }
function RecalculateSupportDeadlineForOneTicket($arTicket, $arFields = array(), $dateType = CTicket::IGNORE) { global $DB; $err_mess = CAllTicketReminder::err_mess() . "<br>Function: RecalculateSupportDeadlineForOneTicket<br>Line: "; $currDateTS = time() + CTimeZone::GetOffset(); $supportDeadlineNotify = 0; $ticketID = intval($arTicket["ID"]); $slaID = intval($arTicket["SLA_ID"]); $periodMin = self::ConvertResponseTimeUnit($arTicket["RESPONSE_TIME"], $arTicket["RESPONSE_TIME_UNIT"]); $periodNMin = 0; if ($ticketID <= 0 || $slaID <= 0 || $periodMin <= 0 || intval($arTicket["D_1_USER_M_AFTER_SUP_M"]) <= 0) { if ($ticketID > 0 && count($arFields) > 0) { $DB->Update("b_ticket", $arFields, "WHERE ID='" . $ticketID . "'", $err_mess . __LINE__); } return; } $periodNMinMinus = self::ConvertResponseTimeUnit($arTicket["NOTICE_TIME"], $arTicket["NOTICE_TIME_UNIT"]); if ($periodNMinMinus > 0 && $periodNMinMinus < $periodMin) { $periodNMin = $periodMin - $periodNMinMinus; } $newDateTS = MakeTimeStamp($arTicket["D_1_USER_M_AFTER_SUP_M"]); if ($dateType == CTicket::CURRENT_DATE) { $arTicket["D_1_USER_M_AFTER_SUP_M"] = GetTime($currDateTS - $periodNMin * 60, "FULL"); $arFields["D_1_USER_M_AFTER_SUP_M"] = $DB->CharToDateFunction($arTicket["D_1_USER_M_AFTER_SUP_M"]); } elseif ($dateType == CTicket::ADD) { $oldDateTS = MakeTimeStamp($arTicket["DATE_OLD"]); if ($oldDateTS > $newDateTS) { $arTicket["D_1_USER_M_AFTER_SUP_M"] = $arTicket["DATE_OLD"]; $arFields["D_1_USER_M_AFTER_SUP_M"] = $DB->CharToDateFunction($arTicket["D_1_USER_M_AFTER_SUP_M"]); } } $supportDeadlineTS = CSupportTimetableCache::getEndDate($slaID, $periodMin, $arTicket["D_1_USER_M_AFTER_SUP_M"]); $arFields["SUPPORT_DEADLINE"] = $DB->CharToDateFunction(GetTime($supportDeadlineTS, "FULL")); $arFields["IS_OVERDUE"] = $supportDeadlineTS <= $currDateTS ? "'Y'" : "'N'"; if ($periodNMin > 0) { $supportDeadlineNotifyTS = CSupportTimetableCache::getEndDate($slaID, $periodNMin, $arTicket["D_1_USER_M_AFTER_SUP_M"]); $arFields["SUPPORT_DEADLINE_NOTIFY"] = $DB->CharToDateFunction(GetTime($supportDeadlineNotifyTS, "FULL")); $arFields["IS_NOTIFIED"] = $supportDeadlineNotifyTS <= $currDateTS ? "'Y'" : "'N'"; } $DB->Update("b_ticket", $arFields, "WHERE ID='" . $ticketID . "'", $err_mess . __LINE__); }
public static function ToCache($arFilter = array(), $RSD = true, $arFromGetEndDate = null) { /* $arFilter( SLA => array() ) */ global $DB; $currD = time(); $uniq = ""; $dbType = strtolower($DB->type); if ($dbType === "mysql") { $DB->StartUsingMasterOnly(); $uniq = COption::GetOptionString("main", "server_uniq_id", ""); if (strlen($uniq) <= 0) { $uniq = md5(uniqid(rand(), true)); COption::SetOptionString("main", "server_uniq_id", $uniq); } $db_lock = $DB->Query("SELECT GET_LOCK('" . $uniq . "_supportToCache', 0) as L"); $ar_lock = $db_lock->Fetch(); if ($ar_lock["L"] !== "1") { return; } //Перед пересчетом проверить в центральной базе что данных действительно нет, на случй здержки передачм данных в дочернюю базу(только для MYSQL) if (is_array($arFromGetEndDate)) { $res = self::getEndDate($arFromGetEndDate["SLA"], $arFromGetEndDate["PERIOD_MIN"], $arFromGetEndDate["DATE_FROM"], true); if ($res !== null) { return $res; } } } $err_mess = self::err_mess() . "<br>Function: toCache<br>Line: "; $timetable_cache = self::TIMETABLE_CACHE; $ndF = self::GetNumberOfDaysForward(); $ndB = self::GetNumberOfDaysBackward(); $dateF = self::GetDayBegin($currD - $ndB * 24 * 60 * 60); $dateT = self::GetDayEnd($currD + $ndF * 24 * 60 * 60); self::$arrS = self::GetShedule($arFilter); if (count(self::$arrS) <= 0) { return null; } self::$arrH = self::GetHolidays($dateF - 24 * 60 * 60, $dateT + 24 * 60 * 60, self::$arrS, $arFilter); $arrSLA = array_keys(self::$arrS); $arSqlSearch = array(); foreach ($arFilter as $key => $val) { if (is_array($val) && count($val) <= 0 || !is_array($val) && strlen($val) <= 0) { continue; } $key = strtoupper($key); if (is_array($val)) { $val = implode(" | ", $val); } switch ($key) { case "SLA_ID": $arSqlSearch[] = GetFilterQuery("SLA_ID", $val, "N"); break; } } $strSqlSearch = GetFilterSqlSearch($arSqlSearch); $DB->Query("DELETE FROM {$timetable_cache} WHERE {$strSqlSearch}", false, $err_mess . __LINE__); $f = new CSupportTableFields(self::$cache); $colNames = null; $strList = ""; $coma = ""; foreach ($arrSLA as $k => $sla) { $dateC = $dateF; $sum = 0; while ($dateC <= $dateT) { if (isset(self::$arrH[$sla]) && array_key_exists($dateC, self::$arrH[$sla])) { $a = self::$arrH[$sla][$dateC]; } else { $a = self::$arrS[$sla][self::GetDayNom($dateC)]; } foreach ($a as $k2 => $v2) { $sum = $sum + $v2["T"] - $v2["F"]; $f->SLA_ID = $sla; $f->DATE_FROM = $dateC + $v2["F"]; $f->DATE_TILL = $dateC + $v2["T"]; $f->W_TIME = $v2["T"] - $v2["F"]; $f->W_TIME_INC = $sum; CTimeZone::Disable(); if ($dbType === "mysql") { $arCurrTicketFields = $f->ToArray(CSupportTableFields::ALL, array(), true); if ($colNames === null) { $colNames = implode(", ", array_keys($arCurrTicketFields)); } $strCurrTicketFields = "(" . implode(",", $arCurrTicketFields) . ")"; if (strlen($strList . ", " . $strCurrTicketFields) > 2000) { $strSql = "INSERT INTO " . $timetable_cache . " (" . $colNames . ") VALUES " . $strList; $strList = $strCurrTicketFields; } else { $strList .= $coma . $strCurrTicketFields; $coma = ", "; continue; } $DB->Query($strSql, false, $err_mess . __LINE__); } else { $DB->Insert($timetable_cache, $f->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL), true), $err_mess . __LINE__); } CTimeZone::Enable(); } $dateC = self::GetDayBegin($dateC + 25 * 60 * 60); } } if ($dbType === "mysql") { if (strlen($strList) > 0) { $strSql = "INSERT INTO " . $timetable_cache . " (" . $colNames . ") VALUES " . $strList; $DB->Query($strSql, false, $err_mess . __LINE__); } $DB->Query("SELECT RELEASE_LOCK('" . $uniq . "_supportToCache')"); $DB->StopUsingMasterOnly(); //CAgent::AddAgent("CSupportTimetableCache::UpdateDiscardedTickets(" . $currD . ");", "support", "N", 5*60); } if ($RSD) { CTicketReminder::RecalculateSupportDeadline($arFilter); } return null; }
function Delete($id, $checkRights = true) { $err_mess = self::err_mess() . "<br>Function: Delete<br>Line: "; global $DB, $USER, $APPLICATION; $id = intval($id); $table = self::table; $table_s2h = self::table_s2h; if ($id <= 0) { return false; } $isDemo = null; $isSupportClient = null; $isSupportTeam = null; $isAdmin = null; $isAccess = null; $userID = null; CTicket::GetRoles($isDemo, $isSupportClient, $isSupportTeam, $isAdmin, $isAccess, $userID, $checkRights); if (!$isAdmin) { $arMsg = array(); $arMsg[] = array("id" => "PERMISSION", "text" => GetMessage("SUP_ERROR_ACCESS_DENIED")); $e = new CAdminException($arMsg); $APPLICATION->ThrowException($e); return false; } // get affected sla $affected_sla = array(); $res = $DB->Query("SELECT SLA_ID FROM b_ticket_sla_2_holidays WHERE HOLIDAYS_ID = {$id}"); while ($row = $res->Fetch()) { $affected_sla[] = $row['SLA_ID']; } // delete $DB->Query("DELETE FROM {$table} WHERE ID = {$id}", false, $err_mess . __LINE__); $DB->Query("DELETE FROM {$table_s2h} WHERE HOLIDAYS_ID = {$id}", false, $err_mess . __LINE__); // recalculate only affected sla CSupportTimetableCache::toCache(array("SLA_ID" => $affected_sla)); return true; }
function Delete($id, $checkRights = true) { $err_mess = self::err_mess() . "<br>Function: Delete<br>Line: "; global $DB, $USER, $APPLICATION; $id = intval($id); $table = self::table; $table_s2h = self::table_s2h; if ($id <= 0) { return false; } $isDemo = null; $isSupportClient = null; $isSupportTeam = null; $isAdmin = null; $isAccess = null; $userID = null; CTicket::GetRoles($isDemo, $isSupportClient, $isSupportTeam, $isAdmin, $isAccess, $userID, $checkRights); if (!$isAdmin) { $arMsg = array(); $arMsg[] = array("id" => "PERMISSION", "text" => GetMessage("SUP_ERROR_ACCESS_DENIED")); $e = new CAdminException($arMsg); $APPLICATION->ThrowException($e); return false; } $DB->Query("DELETE FROM {$table} WHERE ID = {$id}", false, $err_mess . __LINE__); $DB->Query("DELETE FROM {$table_s2h} WHERE HOLIDAYS_ID = {$id}", false, $err_mess . __LINE__); CSupportTimetableCache::toCache(); return true; }
static function ToCache($arFilter = array()) { /* $arFilter( SLA => array() ) */ global $DB; $err_mess = self::err_mess() . "<br>Function: toCache<br>Line: "; $timetable_cache = self::TIMETABLE_CACHE; $ndF = self::GetNumberOfDaysForward(); $ndB = self::GetNumberOfDaysBackward(); $currD = time(); $dateF = self::GetDayBegin($currD - $ndB * 24 * 60 * 60); $dateT = self::GetDayEnd($currD + $ndF * 24 * 60 * 60); self::$arrS = self::GetShedule($arFilter); if (count(self::$arrS) <= 0) { return; } self::$arrH = self::GetHolidays($dateF - 24 * 60 * 60, $dateT + 24 * 60 * 60, self::$arrS, $arFilter); $arrSLA = array_keys(self::$arrS); $arSqlSearch = array(); foreach ($arFilter as $key => $val) { if (is_array($val) && count($val) <= 0 || !is_array($val) && strlen($val) <= 0) { continue; } $key = strtoupper($key); if (is_array($val)) { $val = implode(" | ", $val); } switch ($key) { case "SLA_ID": $arSqlSearch[] = GetFilterQuery("SLA_ID", $val, "N"); break; } } $strSqlSearch = GetFilterSqlSearch($arSqlSearch); $DB->Query("DELETE FROM {$timetable_cache} WHERE {$strSqlSearch}", false, $err_mess . __LINE__); $f = new CSupportTableFields(self::$cache); foreach ($arrSLA as $k => $sla) { $dateC = $dateF; $sum = 0; while ($dateC <= $dateT) { if (isset(self::$arrH[$sla]) && array_key_exists($dateC, self::$arrH[$sla])) { $a = self::$arrH[$sla][$dateC]; } else { $a = self::$arrS[$sla][self::GetDayNom($dateC)]; } foreach ($a as $k2 => $v2) { $sum = $sum + $v2["T"] - $v2["F"]; $f->SLA_ID = $sla; $f->DATE_FROM = $dateC + $v2["F"]; $f->DATE_TILL = $dateC + $v2["T"]; $f->W_TIME = $v2["T"] - $v2["F"]; $f->W_TIME_INC = $sum; CTimeZone::Disable(); $DB->Insert($timetable_cache, $f->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL), true), $err_mess . __LINE__); CTimeZone::Enable(); } $dateC += 24 * 60 * 60; } } CTicketReminder::RecalculateSupportDeadline($arFilter); }