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; }
function Set($arFields, $arFieldsSLA) { 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::$holidays); $f->FromArray($arFields); } else { $f = $arFields; } if (is_array($arFieldsSLA)) { $f_s = new CSupportTableFields(self::$sla2holidays, CSupportTableFields::C_Table); $f_s->FromTable($arFieldsSLA); } else { $f_s = $arFieldsSLA; } $table = self::table; $table_s2h = self::table_s2h; $isNew = $f->ID <= 0; $objError = new CAdminException(array()); if (strlen($f->NAME) <= 0) { $objError->AddMessage(array("text" => GetMessage('SUP_ERROR_EMPTY_NAME'))); } if (strlen($f->OPEN_TIME) <= 0) { $objError->AddMessage(array("text" => GetMessage('SUP_ERROR_EMPTY_OPEN_TIME'))); } $zd = mktime(0, 0, 0, 1, 1, 2010); if ($f->DATE_FROM < $zd || $f->DATE_FROM === null || $f->DATE_TILL < $zd || $f->DATE_TILL === null || $f->DATE_FROM > $f->DATE_TILL) { if ($f->DATE_FROM < $zd || $f->DATE_FROM === null) { $f->DATE_FROM = time() + CTimeZone::GetOffset(); } if ($f->DATE_TILL < $zd || $f->DATE_TILL === null) { $f->DATE_TILL = time() + CTimeZone::GetOffset(); } $objError->AddMessage(array("text" => GetMessage('SUP_ERROR_EMPTY_DATE'))); } if (count($objError->GetMessages()) > 0) { $APPLICATION->ThrowException($objError); return false; } $arFields_i = $f->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL), true); $res = 0; if (count($arFields_i) > 0) { if ($isNew) { $res = $DB->Insert($table, $arFields_i, $err_mess . __LINE__); $f->ID = $res; } else { $res = $DB->Update($table, $arFields_i, "WHERE ID=" . $f->ID . "", $err_mess . __LINE__); } } if (intval($res) <= 0) { $APPLICATION->ThrowException(GetMessage('SUP_ERROR_DB_ERROR')); return false; } $DB->Query("DELETE FROM {$table_s2h} WHERE HOLIDAYS_ID = " . $f->ID, false, $err_mess . __LINE__); $f_s->ResetNext(); while ($f_s->Next()) { $f_s->HOLIDAYS_ID = $f->ID; if ($f_s->SLA_ID > 0) { $strSql = "INSERT INTO " . $table_s2h . "(SLA_ID, HOLIDAYS_ID) VALUES (" . $f_s->SLA_ID . ", " . $f_s->HOLIDAYS_ID . ")"; $res = $DB->Query($strSql, false, $err_mess . __LINE__); } } CSupportTimetableCache::toCache(array("SLA_ID" => $f_s->getColumn("SLA_ID"))); return $f->ID; }