1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
dictionary.php
См. документацию.
1<?php
2
4
6{
7 public static function GetDefault($type, $siteID=SITE_ID)
8 {
9 if ($siteID=="all")
10 {
11 $siteID = "";
12 }
13 $arFilter = array("DEFAULT" => "Y", "TYPE" => $type, "SITE" => $siteID);
14 $rs = CTicketDictionary::GetList("s_dropdown", '', $arFilter);
15 $ar = $rs->Fetch();
16 return $ar["ID"];
17 }
18
19 public static function GetNextSort($typeID)
20 {
21 global $DB;
22 $strSql = "SELECT max(C_SORT) MAX_SORT FROM b_ticket_dictionary WHERE C_TYPE='".$DB->ForSql($typeID,5)."'";
23 $z = $DB->Query($strSql);
24 $zr = $z->Fetch();
25 return intval($zr["MAX_SORT"])+100;
26 }
27
28 public static function GetDropDown($type="C", $siteID=false, $sla_id=false)
29 {
30 global $DB;
31 if ($siteID==false || $siteID=="all")
32 {
33 $siteID = "";
34 }
35 $arFilter = array("TYPE" => $type, "SITE" => $siteID);
36 $rs = CTicketDictionary::GetList("s_dropdown", '', $arFilter);
37
38 $oldFunctionality = COption::GetOptionString( "support", "SUPPORT_OLD_FUNCTIONALITY", "Y" );
39 if( intval($sla_id) <= 0 || $oldFunctionality != "Y" || ( $type != "C" && $type!="K" && $type!="M" ) ) return $rs;
40
41 switch($type)
42 {
43 case "C": $strSql = "SELECT CATEGORY_ID as DID FROM b_ticket_sla_2_category WHERE SLA_ID=" . intval($sla_id); break;
44 case "K": $strSql = "SELECT CRITICALITY_ID as DID FROM b_ticket_sla_2_criticality WHERE SLA_ID=" . intval($sla_id); break;
45 case "M": $strSql = "SELECT MARK_ID as DID FROM b_ticket_sla_2_mark WHERE SLA_ID=" . intval($sla_id); break;
46 }
47 $r = $DB->Query($strSql);
48 while( $a = $r->Fetch() ) $arDID[] = $a["DID"];
49 $arRecords = array();
50 while( $ar = $rs->Fetch() ) if( is_array( $arDID ) && ( in_array( $ar["ID"], $arDID ) || in_array( 0,$arDID ) ) ) $arRecords[] = $ar;
51
52 $rs = new CDBResult;
53 $rs->InitFromArray($arRecords);
54
55 return $rs;
56 }
57
58 public static function GetDropDownArray($siteID = false, $SLA_ID = false, $arUnsetType = Array("F"))
59 {
60 //M, C, K, S, SR, D, F
61 global $DB;
62
63 if ($siteID == false || $siteID == "all")
64 $siteID = "";
65
66 $arFilter = Array("SITE" => $siteID);
67
68 $arReturn = Array();
69 $rs = CTicketDictionary::GetList("s_dropdown", '', $arFilter);
70 while ($ar = $rs->Fetch())
71 {
72 if (in_array($ar["C_TYPE"], $arUnsetType))
73 continue;
74
75 $arReturn[$ar["C_TYPE"]][$ar["ID"]] = $ar;
76 }
77
78 $oldFunctionality = COption::GetOptionString( "support", "SUPPORT_OLD_FUNCTIONALITY", "Y" );
79 if( intval($SLA_ID) > 0 && $oldFunctionality == "Y" )
80 {
81 $SLA_ID = intval($SLA_ID);
82
83 $strSql = "SELECT 'M' as C_TYPE, SLA_ID, MARK_ID as DIC_ID FROM b_ticket_sla_2_mark WHERE SLA_ID = ".$SLA_ID."
84 UNION ALL
85 SELECT 'K' as C_TYPE, SLA_ID, CRITICALITY_ID as DIC_ID FROM b_ticket_sla_2_criticality WHERE SLA_ID = ".$SLA_ID."
86 UNION ALL
87 SELECT 'C' as C_TYPE, SLA_ID, CATEGORY_ID as DIC_ID FROM b_ticket_sla_2_category WHERE SLA_ID = ".$SLA_ID;
88
89 $r = $DB->Query($strSql);
90
91 $arUnset = Array();
92 while ($ar = $r->Fetch())
93 {
94 if ($ar["DIC_ID"] == 0)
95 continue;
96 else
97 $arUnset[$ar["C_TYPE"]][] = $ar["DIC_ID"];
98 }
99
100 if (!empty($arUnset) && !empty($arReturn))
101 {
102 foreach ($arReturn as $type => $arID)
103 {
104 if (!array_key_exists($type, $arUnset))
105 continue;
106
107 $arID = array_keys($arID);
108 $arID = array_diff($arID, $arUnset[$type]);
109 foreach ($arID as $val)
110 unset($arReturn[$type][$val]);
111 }
112 }
113 }
114
115 return $arReturn;
116 }
117
118 // get array of languages related to contract
119 public static function GetSiteArray($DICTIONARY_ID)
120 {
121 global $DB;
122 $DICTIONARY_ID = intval($DICTIONARY_ID);
123 if ($DICTIONARY_ID<=0) return false;
124 $arrRes = array();
125 $strSql = "
126 SELECT
127 DS.SITE_ID
128 FROM
129 b_ticket_dictionary_2_site DS
130 WHERE
131 DS.DICTIONARY_ID = $DICTIONARY_ID
132 ";
133
134 $rs = $DB->Query($strSql);
135 while ($ar = $rs->Fetch()) $arrRes[] = $ar["SITE_ID"];
136 return $arrRes;
137 }
138
139 public static function GetSiteArrayForAllDictionaries()
140 {
141 static $GetSiteArrayForAllDictCache;
142 if(is_array($GetSiteArrayForAllDictCache))
143 {
144 return $GetSiteArrayForAllDictCache;
145 }
146
147 global $DB;
148 $GetSiteArrayForAllDictCache = array();
149 $strSql = "
150 SELECT
151 DS.SITE_ID,
152 DS.DICTIONARY_ID
153 FROM
154 b_ticket_dictionary_2_site DS
155 ";
156 $rs = $DB->Query($strSql);
157 while ($ar = $rs->Fetch())
158 {
159 $GetSiteArrayForAllDictCache[$ar["DICTIONARY_ID"]][] = $ar["SITE_ID"];
160 }
161 return $GetSiteArrayForAllDictCache;
162 }
163
164 public static function GetTypeList()
165 {
166 $arr = array(
167 "reference"=>array(
168 GetMessage("SUP_CATEGORY"),
169 GetMessage("SUP_CRITICALITY"),
170 GetMessage("SUP_STATUS"),
171 GetMessage("SUP_MARK"),
172 GetMessage("SUP_FUA"),
173 GetMessage("SUP_SOURCE"),
174 GetMessage("SUP_DIFFICULTY")
175 ),
176 "reference_id"=>array(
177 "C",
178 "K",
179 "S",
180 "M",
181 "F",
182 "SR",
183 "D")
184 );
185 return $arr;
186 }
187
188 public static function GetTypeNameByID($id)
189 {
191 $KEY = array_search($id, $arr["reference_id"]);
192 return $arr["reference"][$KEY];
193 }
194
195 public static function GetByID($id)
196 {
197 global $DB;
198 $id = intval($id);
199 if ($id<=0)
200 {
201 return;
202 }
203 $res = CTicketDictionary::GetList('', '', array("ID" => $id));
204 return $res;
205 }
206
207 public static function GetBySID($sid, $type, $siteID=SITE_ID)
208 {
209 $rs = CTicketDictionary::GetList('', '', array("SITE_ID"=>$siteID, "TYPE"=>$type, "SID"=>$sid));
210 return $rs;
211 }
212
213 public static function Delete($id, $CHECK_RIGHTS="Y")
214 {
215 global $DB, $APPLICATION;
216 $id = intval($id);
217 if ($id<=0)
218 {
219 return;
220 }
221 $bAdmin = "N";
222 if ($CHECK_RIGHTS=="Y")
223 {
224 $bAdmin = (CTicket::IsAdmin()) ? "Y" : "N";
225 }
226 else
227 {
228 $bAdmin = "Y";
229 }
230 if ($bAdmin=="Y")
231 {
232 $DB->Query("DELETE FROM b_ticket_dictionary WHERE ID='$id'");
233 $DB->Query('DELETE FROM b_ticket_dictionary_2_site WHERE DICTIONARY_ID=' . $id);
234 }
235 }
236
237 public static function CheckFields($arFields, $id = false)
238 {
239 $arMsg = Array();
240
241 if ( $id ===false && !(array_key_exists('NAME', $arFields) && $arFields['NAME'] <> '') )
242 {
243 $arMsg[] = array("id"=>"NAME", "text"=> GetMessage("SUP_FORGOT_NAME"));
244 }
245
246 if ($id !== false)
247 {
249 if (!$rs->Fetch())
250 {
251 $arMsg[] = array("id"=>"ID", "text"=> GetMessage("SUP_UNKNOWN_ID", array('#ID#' => $id)));
252 }
253 }
254
255 if ( array_key_exists('SID', $arFields) && preg_match("#[^A-Za-z_0-9]#", $arFields['SID']) )
256 {
257 $arMsg[] = array("id"=>"SID", "text"=> GetMessage("SUP_INCORRECT_SID"));
258 }
259 elseif (
260 $arFields['SID'] <> '' && array_key_exists('arrSITE', $arFields) &&
261 is_array($arFields['arrSITE']) && count($arFields['arrSITE']) > 0
262 )
263 {
265 "TYPE" => $arFields['C_TYPE'],
266 "SID" => $arFields['SID'],
267 "SITE" => $arFields['arrSITE'],
268 );
269 if (intval($id) > 0)
270 {
271 $arFilter['ID'] = '~'.intval($id);
272 }
273
275 if ($zr = $z->Fetch())
276 {
277 $arMsg[] = array(
278 "id"=>"SID",
279 "text"=> GetMessage(
280 'SUP_SID_ALREADY_IN_USE',
281 array(
282 '#TYPE#' => CTicketDictionary::GetTypeNameByID($arFields['C_TYPE']),
283 '#LANG#' => $zr['LID'] <> ''? $zr['LID']: $zr['SITE_ID'],
284 '#RECORD_ID#' => $zr['ID'],
285 )
286 )
287 );
288 }
289 }
290
291 if (count($arMsg) > 0)
292 {
293 $e = new CAdminException($arMsg);
294 $GLOBALS['APPLICATION']->ThrowException($e);
295 return false;
296 }
297
298 return true;
299 }
300
301 public static function Add($arFields)
302 {
303 global $DB;
304 $DB->StartTransaction();
306 {
307 $DB->Rollback();
308 return false;
309 }
310
312
313 $id = intval($DB->Add('b_ticket_dictionary', $arFields));
314 if ($id > 0)
315 {
317 $DB->Commit();
318 return $id;
319 }
320
321 $DB->Rollback();
322 $GLOBALS['APPLICATION']->ThrowException(GetMessage('SUP_ERROR_ADD_DICTONARY'));
323 return false;
324 }
325
326 public static function Update($id, $arFields)
327 {
328 global $DB;
329 $DB->StartTransaction();
330 $id = intval($id);
332 {
333 $DB->Rollback();
334 return false;
335 }
336
338
339 $strUpdate = $DB->PrepareUpdate('b_ticket_dictionary', $arFields);
340 $rs = $DB->Query('UPDATE b_ticket_dictionary SET ' . $strUpdate . ' WHERE ID=' . $id);
341 if ($rs->AffectedRowsCount() > 0)
342 {
344 $DB->Commit();
345 return true;
346 }
347
348 $DB->Rollback();
349 $GLOBALS['APPLICATION']->ThrowException(GetMessage('SUP_ERROR_UPDATE_DICTONARY'));
350 return false;
351 }
352
353 public static function __CleanDefault(&$arFields)
354 {
355 if (
356 array_key_exists('SET_AS_DEFAULT', $arFields) && $arFields['SET_AS_DEFAULT'] == 'Y' &&
357 array_key_exists('arrSITE', $arFields) && array_key_exists('C_TYPE', $arFields)
358 )
359 {
360 global $DB;
362 'TYPE' => $arFields['C_TYPE'],
363 'SITE' => $arFields['arrSITE']
364 );
366 while ($zr = $z->Fetch())
367 {
368 $DB->Update('b_ticket_dictionary', array('SET_AS_DEFAULT' => "'N'"), 'WHERE ID=' . $zr['ID'], '', false, false, false);
369 }
370 }
371 elseif (array_key_exists('SET_AS_DEFAULT', $arFields))
372 {
373 $arFields['SET_AS_DEFAULT'] = 'N';
374 }
375 }
376
377 public static function __SetSites($id, $arFields)
378 {
379 global $DB;
380 if (!array_key_exists('arrSITE', $arFields))
381 {
382 return ;
383 }
384 $id = intval($id);
385 $DB->Query('DELETE FROM b_ticket_dictionary_2_site WHERE DICTIONARY_ID=' . $id);
386 if (is_array($arFields['arrSITE']) && count($arFields['arrSITE']) > 0)
387 {
388 foreach($arFields['arrSITE'] as $sid)
389 {
390 $strSql = "INSERT INTO b_ticket_dictionary_2_site (DICTIONARY_ID, SITE_ID) VALUES ($id, '".$DB->ForSql($sid, 2)."')";
391 $DB->Query($strSql);
392 }
393 }
394 }
395}
$type
Определения options.php:106
global $APPLICATION
Определения include.php:80
static __SetSites($id, $arFields)
Определения dictionary.php:377
static CheckFields($arFields, $id=false)
Определения dictionary.php:237
static Delete($id, $CHECK_RIGHTS="Y")
Определения dictionary.php:213
static GetSiteArrayForAllDictionaries()
Определения dictionary.php:139
static GetByID($id)
Определения dictionary.php:195
static Add($arFields)
Определения dictionary.php:301
static GetTypeList()
Определения dictionary.php:164
static GetDropDown($type="C", $siteID=false, $sla_id=false)
Определения dictionary.php:28
static GetDropDownArray($siteID=false, $SLA_ID=false, $arUnsetType=Array("F"))
Определения dictionary.php:58
static GetTypeNameByID($id)
Определения dictionary.php:188
static GetDefault($type, $siteID=SITE_ID)
Определения dictionary.php:7
static GetBySID($sid, $type, $siteID=SITE_ID)
Определения dictionary.php:207
static GetNextSort($typeID)
Определения dictionary.php:19
static Update($id, $arFields)
Определения dictionary.php:326
static __CleanDefault(&$arFields)
Определения dictionary.php:353
static GetSiteArray($DICTIONARY_ID)
Определения dictionary.php:119
static IsAdmin($userID=false)
Определения support.php:94
static GetList($by='s_c_sort', $order='asc', $arFilter=[])
Определения dictionary.php:7
$arFields
Определения dblapprove.php:5
$arr
Определения file_new.php:624
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
while($group=$gr->Fetch()) $bAdmin
Определения file_new.php:154
$res
Определения filter_act.php:7
$zr
Определения options.php:5
global $DB
Определения cron_frame.php:29
$siteID
Определения cron_frame.php:12
$z
Определения options.php:31
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
else $a
Определения template.php:137
$val
Определения options.php:1793
const SITE_ID
Определения sonet_set_content_view.php:12
$rs
Определения action.php:82
$GLOBALS['_____370096793']
Определения update_client.php:1
$arFilter
Определения user_search.php:106