예제 #1
0
파일: sla.php 프로젝트: rasuldev/torino
 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;
 }