Exemple #1
0
 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();
     }
 }
Exemple #2
0
 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;
 }
Exemple #3
0
 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;
 }
Exemple #5
0
 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;
 }
Exemple #6
0
 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;
 }