Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
inputs.php
1<?php
2
4
5require_once __DIR__.'/../internals/input.php';
6
11
12Loc::loadMessages(__FILE__);
13
14class Period extends Input\Base
15{
16 public static function getViewHtmlSingle(array $input, $values)
17 {
18 if(!is_array($values))
19 throw new ArgumentTypeException('values', 'array');
20
21 self::checkArgs($input, $values);
22
23 return $input["ITEMS"]["FROM"]["NAME"].": ".Input\Manager::getViewHtml($input["ITEMS"]["FROM"], $values["FROM"]).
24 $input["ITEMS"]["TO"]["NAME"].": ".Input\Manager::getViewHtml($input["ITEMS"]["TO"], $values["TO"]).
25 " ".Input\Manager::getViewHtml($input["ITEMS"]["TYPE"], $values["TYPE"]);
26 }
27
28 public static function getEditHtmlSingle($name, array $input, $values)
29 {
30 if (!isset($input["ITEMS"]))
31 {
32 $input["ITEMS"] = [
33 "FROM" => [
34 "TYPE" => "STRING",
35 "NAME" => ""
36 ],
37 "TO" => [
38 "TYPE" => "STRING",
39 "NAME" => "&nbsp;-&nbsp;"
40 ],
41 "TYPE" => [
42 "TYPE" => "ENUM",
43 "OPTIONS" => [
44 "H" => "HOURS", //Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_HOUR"),
45 "D" => "DAYS", //Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_DAY"),
46 "M" => "MONTHS"
47 ]
48 ]
49 ];
50 }
51
52 return
53 $input["ITEMS"]["FROM"]["NAME"]
54 . Input\Manager::getEditHtml($name . "[FROM]", $input["ITEMS"]["FROM"], $values["FROM"] ?? null)
55 . $input["ITEMS"]["TO"]["NAME"]
56 . Input\Manager::getEditHtml($name . "[TO]", $input["ITEMS"]["TO"], $values["TO"] ?? null)
57 . ' '
58 . Input\Manager::getEditHtml($name . "[TYPE]", $input["ITEMS"]["TYPE"], $values["TYPE"] ?? null)
59 ;
60 }
61
62 public static function getError(array $input, $values)
63 {
64 if(!is_array($values))
65 throw new ArgumentTypeException('values', 'array');
66
67 return self::getErrorSingle($input, $values);
68 }
69
70 public static function getErrorSingle(array $input, $values)
71 {
72 if(!is_array($values))
73 throw new ArgumentTypeException('values', 'array');
74
75 self::checkArgs($input, $values);
76
77 $errors = array();
78
79 if ($error = Input\Manager::getError($input["ITEMS"]["FROM"], $values["FROM"]))
80 $errors = $error;
81
82 if ($error = Input\Manager::getError($input["ITEMS"]["TO"], $values["TO"]))
83 $errors = array_merge($errors, $error);
84
85 if ($error = Input\Manager::getError($input["ITEMS"]["TYPE"], $values["TYPE"]))
86 $errors = array_merge($errors, $error);
87
88 return $errors;
89 }
90
91 public static function getValueSingle(array $input, $userValue)
92 {
93 return $userValue;
94 }
95
96 public static function getSettings(array $input, $reload)
97 {
98 return array();
99 }
100
101 protected static function checkArgs(array $input, array $values)
102 {
103 if(!isset($input["ITEMS"]["FROM"]) || !isset($input["ITEMS"]["TO"]) || !isset($input["ITEMS"]["TYPE"]))
104 throw new ArgumentException("Wrong argument structure!", "input");
105
106 if(!isset($values["FROM"]) || !isset($values["TO"]) || !isset($values["TYPE"]))
107 throw new \Bitrix\Main\ArgumentException("Wrong argument structure!", "values");
108
109 return true;
110 }
111}
112
113Input\Manager::register('DELIVERY_PERIOD', array(
114 'CLASS' => __NAMESPACE__.'\\Period',
115 'NAME' => Loc::getMessage('INPUT_DELIVERY_PERIOD')
116));
117
118class ReadOnlyField extends Input\Base
119{
120 public static function getViewHtmlSingle(array $input, $value)
121 {
122 $result = '<span';
123
124 if(!empty($input['ID']))
125 $result .= ' id="'.$input['ID'].'_view"';
126
127 $result .= '>';
128 $result .= isset($input["VALUE_VIEW"]) ? $input["VALUE_VIEW"] : $value;
129 $result .= '</span>';
130 return $result;
131 }
132
133 public static function getEditHtmlSingle($name, array $input, $value)
134 {
135 $value = str_replace('"', "'", $value);
136 $res = self::getViewHtml($input, $value).'<input type="hidden" value="'.htmlspecialcharsbx($value).'" name="'.htmlspecialcharsbx($name).'"';
137
138 if(!empty($input['ID']))
139 $res .= ' id="'.$input['ID'].'"';
140
141 $res .= '>';
142 return $res;
143 }
144
145
146 public static function getError(array $input, $values)
147 {
148 return self::getErrorSingle($input, $values);
149 }
150
151 public static function getErrorSingle(array $input, $values)
152 {
153 return array();
154 }
155
156 public static function getValueSingle(array $input, $userValue)
157 {
158 return $userValue;
159 }
160
161 public static function getSettings(array $input, $reload)
162 {
163 return array();
164 }
165}
166
167Input\Manager::register('DELIVERY_READ_ONLY', array(
168 'CLASS' => __NAMESPACE__.'\\ReadOnlyField',
169 'NAME' => Loc::getMessage('INPUT_DELIVERY_READ_ONLY')
170));
171
172class MultiControlString extends Input\Base
173{
174 protected $items = array();
175 protected $myParams = array();
176 protected $myKey = array();
177
178 public function addItem($key, array $control)
179 {
180 $this->items[$key] = $control;
181 }
182
183 public function setParams($key, array $params)
184 {
185 $this->myParams = $params;
186 $this->setKey($key);
187 }
188
189 public function getParams()
190 {
191 $result = $this->myParams;
192 $result["ITEMS"] = $this->items;
193 return $result;
194 }
195
196 public function setKey($key)
197 {
198 $this->myKey = $key;
199 }
200
201 public function getKey()
202 {
203 return $this->myKey;
204 }
205
206 public function isClean()
207 {
208 return empty($this->myParams);
209 }
210
211 public function clean()
212 {
213 $this->myParams = $this->items = $this->myKey = array();
214 }
215
216 public static function getViewHtmlSingle(array $input, $values)
217 {
218 $result = "";
219
220 foreach($input["ITEMS"] as $key => $item)
221 $result .=
222 isset($item["NAME"]) ? $item["NAME"] : "".
223 Input\Manager::getViewHtml($item, isset($values[$key]) ? $values[$key] : null).
224 " ";
225
226 return $result;
227 }
228
229 public static function getEditHtmlSingle($name, array $input, $values)
230 {
231 $result = "";
232
233 foreach($input["ITEMS"] as $key => $item)
234 $result .=
235 isset($item["NAME"]) ? $item["NAME"] : "".
236 Input\Manager::getEditHtml($name."[".$key."]", $item, isset($values[$key]) ? $values[$key] : null).
237 " ";
238
239 return $result;
240 }
241
242 public static function getErrorSingle(array $input, $values)
243 {
244 if(!is_array($values))
245 throw new ArgumentTypeException('values', 'array');
246
247 $errors = array();
248
249 foreach($input["ITEMS"] as $key => $item)
250 if ($error = Input\Manager::getError($item, isset($values[$key]) ? $values[$key] : null))
251 $errors[$key] = $error;
252
253 return $errors;
254 }
255
256 public static function getValueSingle(array $input, $userValue)
257 {
258 return $userValue;
259 }
260
261 public static function getSettings(array $input, $reload)
262 {
263 return array();
264 }
265
270 static function asSingle($value)
271 {
272 return $value;
273 }
274
279 public static function getError(array $input, $value)
280 {
281 $errors = [];
282
283 foreach($input["ITEMS"] as $key => $item)
284 {
285 $errors = array_merge($errors, Input\Manager::getError($item, $value[$key]));
286 }
287
288 return $errors;
289
290 }
291
295 public static function getRequiredError(array $input, $value)
296 {
297 $errors = [];
298
299 foreach($input["ITEMS"] as $key => $item)
300 {
301 $errors = array_merge($errors, Input\Manager::getRequiredError($item, $value[$key]));
302 }
303
304 return $errors;
305 }
306}
307
308Input\Manager::register('DELIVERY_MULTI_CONTROL_STRING', array(
309 'CLASS' => __NAMESPACE__.'\\MultiControlString',
310 'NAME' => Loc::getMessage('INPUT_DELIVERY_MULTI_CONTROL_STRING')
311));
312
313class LocationMulti extends Input\Base
314{
315 protected static $d2LClass = '\Bitrix\Sale\Delivery\DeliveryLocationTable';
316
317 public static function getViewHtml(array $input, $value = null)
318 {
319 $result = "";
320 $class = static::$d2LClass;
321
322 $res = $class::getConnectedLocations(
323 $input["DELIVERY_ID"],
324 array(
325 'select' => array('LNAME' => 'NAME.NAME'),
326 'filter' => array('NAME.LANGUAGE_ID' => LANGUAGE_ID)
327 )
328 );
329
330 while($loc = $res->fetch())
331 $result .= htmlspecialcharsbx($loc["LNAME"])."<br>\n";
332
333 $res = $class::getConnectedGroups(
334 $input["DELIVERY_ID"],
335 array(
336 'select' => array('LNAME' => 'NAME.NAME'),
337 'filter' => array('NAME.LANGUAGE_ID' => LANGUAGE_ID)
338 )
339 );
340
341 while($loc = $res->fetch())
342 $result .= htmlspecialcharsbx($loc["LNAME"])."<br>\n";
343
344 return $result;
345 }
346
347 public static function getEditHtml($name, array $input, $values = null)
348 {
349 global $APPLICATION;
350
351 ob_start();
352
353 $APPLICATION->IncludeComponent(
354 "bitrix:sale.location.selector.system",
355 "",
356 array(
357 "ENTITY_PRIMARY" => $input["DELIVERY_ID"],
358 "LINK_ENTITY_NAME" => mb_substr(static::$d2LClass, 0, -5),
359 "INPUT_NAME" => $name,
360 'FILTER_BY_SITE' => 'N',
361 ),
362 false
363 );
364
365 $result = ob_get_contents();
366 $result = '
367 <script type="text/javascript">
368 var bxInputdeliveryLocMultiStep3 = function()
369 {
370 BX.loadScript("/bitrix/components/bitrix/sale.location.selector.system/templates/.default/script.js", function(){
371 BX.onCustomEvent("deliveryGetRestrictionHtmlScriptsReady");
372 });
373 };
374
375 var bxInputdeliveryLocMultiStep2 = function()
376 {
377 BX.load([
378 "/bitrix/js/sale/core_ui_etc.js",
379 "/bitrix/js/sale/core_ui_autocomplete.js",
380 "/bitrix/js/sale/core_ui_itemtree.js"
381 ],
382 bxInputdeliveryLocMultiStep3
383 );
384 };
385
386 BX.loadScript("/bitrix/js/sale/core_ui_widget.js", bxInputdeliveryLocMultiStep2);
387
388 //at first we must load some scripts in the right order
389 window["deliveryGetRestrictionHtmlScriptsLoadingStarted"] = true;
390
391 </script>
392
393 <link rel="stylesheet" type="text/css" href="/bitrix/panel/main/adminstyles_fixed.css">
394 <link rel="stylesheet" type="text/css" href="/bitrix/panel/main/admin.css">
395 <link rel="stylesheet" type="text/css" href="/bitrix/panel/main/admin-public.css">
396 <link rel="stylesheet" type="text/css" href="/bitrix/components/bitrix/sale.location.selector.system/templates/.default/style.css">
397 '.
398 $result;
399 ob_end_clean();
400 return $result;
401 }
402
403 public static function getError(array $input, $values)
404 {
405 return array();
406 }
407
408
409 public static function getValueSingle(array $input, $userValue)
410 {
411 return $userValue;
412 }
413
414 public static function getSettings(array $input, $reload)
415 {
416 return array();
417 }
418}
419
420Input\Manager::register('LOCATION_MULTI', array(
421 'CLASS' => __NAMESPACE__.'\\LocationMulti',
422 'NAME' => Loc::getMessage('INPUT_DELIVERY_LOCATION_MULTI')
423));
424
426{
427 protected static $d2LClass = '\Bitrix\Sale\Delivery\DeliveryLocationExcludeTable';
428}
429
430Input\Manager::register('LOCATION_MULTI_EXCLUDE', array(
431 'CLASS' => __NAMESPACE__.'\\LocationMultiExclude',
432 'NAME' => Loc::getMessage('INPUT_DELIVERY_LOCATION_MULTI_EXCLUDE')
433));
434
435class ProductCategories extends Input\ProductCategories {}
436
437// Deprecated type
438Input\Manager::register('DELIVERY_PRODUCT_CATEGORIES', array(
439 'CLASS' => __NAMESPACE__.'\\ProductCategories',
440 'NAME' => Loc::getMessage('INPUT_DELIVERY_PRODUCT_CATEGORIES')
441));
442
443class ButtonSelector extends Input\Base
444{
445 public static function getViewHtmlSingle(array $input, $values)
446 {
447 if(!is_array($values))
448 throw new ArgumentTypeException('values', 'array');
449
450 $itemName = ($values['NAME'] <> '' ? htmlspecialcharsbx($values['NAME']) : '');
451
452 if($itemName == '' && $input['NAME_DEFAULT'] <> '')
453 {
454 $itemName = htmlspecialcharsbx($input['NAME_DEFAULT']);
455 }
456
457 return $itemName;
458 }
459
460 public static function getEditHtmlSingle($name, array $input, $values)
461 {
462 $input['NAME_DEFAULT'] = trim((string)($input['NAME_DEFAULT'] ?? ''));
463 $input['VALUE_DEFAULT'] = trim((string)($input['VALUE_DEFAULT'] ?? ''));
464
465 if (!is_array($values))
466 {
467 $values = [];
468 }
469 $values['NAME'] = trim((string)($values['NAME'] ?? ''));
470 $values['VALUE'] = trim((string)($values['VALUE'] ?? ''));
471
472 $itemName = htmlspecialcharsbx($values['NAME'] ?: $input['NAME_DEFAULT']);
473 $itemValue = htmlspecialcharsbx($values['VALUE'] ?: $input['VALUE_DEFAULT']);
474
475 return '<div>'.
476 '<div id="'.$input['READONLY_NAME_ID'].'">'.htmlspecialcharsbx($itemName).'</div>'.
477 ' <input type="button" value="'.$input['BUTTON']['NAME'].'" onclick="'.$input['BUTTON']['ONCLICK'].' return false;" style="margin-top: 20px;">'.
478 '<input type="hidden" name="'.$name.'[NAME]" value="'.$itemName.'">'.
479 '<input type="hidden" name="'.$name.'[VALUE]" value="'.$itemValue.'">'.
480 '</div>';
481 }
482
483 public static function getValueSingle(array $input, $userValue)
484 {
485 return $userValue;
486 }
487
488 public static function getSettings(array $input, $reload)
489 {
490 return array();
491 }
492
493 public static function getError(array $input, $values)
494 {
495 return self::getErrorSingle($input, $values);
496 }
497
498 public static function getErrorSingle(array $input, $values)
499 {
500 return array();
501 }
502
503 static function asSingle($value)
504 {
505 return $value;
506 }
507}
508Input\Manager::register('DELIVERY_BUTTON_SELECTOR', array(
509 'CLASS' => __NAMESPACE__.'\\ButtonSelector',
510 'NAME' => Loc::getMessage('INPUT_DELIVERY_BUTTON_SELECTOR')
511));
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getSettings(array $input, $reload)
Definition inputs.php:488
static getErrorSingle(array $input, $values)
Definition inputs.php:498
static getViewHtmlSingle(array $input, $values)
Definition inputs.php:445
static getValueSingle(array $input, $userValue)
Definition inputs.php:483
static getError(array $input, $values)
Definition inputs.php:493
static getEditHtmlSingle($name, array $input, $values)
Definition inputs.php:460
static getSettings(array $input, $reload)
Definition inputs.php:414
static getValueSingle(array $input, $userValue)
Definition inputs.php:409
static getEditHtml($name, array $input, $values=null)
Definition inputs.php:347
static getError(array $input, $values)
Definition inputs.php:403
static getViewHtml(array $input, $value=null)
Definition inputs.php:317
static getSettings(array $input, $reload)
Definition inputs.php:261
static getErrorSingle(array $input, $values)
Definition inputs.php:242
static getViewHtmlSingle(array $input, $values)
Definition inputs.php:216
static getRequiredError(array $input, $value)
Definition inputs.php:295
static getValueSingle(array $input, $userValue)
Definition inputs.php:256
static getEditHtmlSingle($name, array $input, $values)
Definition inputs.php:229
static getError(array $input, $value)
Definition inputs.php:279
static getSettings(array $input, $reload)
Definition inputs.php:96
static getErrorSingle(array $input, $values)
Definition inputs.php:70
static getViewHtmlSingle(array $input, $values)
Definition inputs.php:16
static getValueSingle(array $input, $userValue)
Definition inputs.php:91
static getError(array $input, $values)
Definition inputs.php:62
static getEditHtmlSingle($name, array $input, $values)
Definition inputs.php:28
static checkArgs(array $input, array $values)
Definition inputs.php:101
static getSettings(array $input, $reload)
Definition inputs.php:161
static getViewHtmlSingle(array $input, $value)
Definition inputs.php:120
static getErrorSingle(array $input, $values)
Definition inputs.php:151
static getEditHtmlSingle($name, array $input, $value)
Definition inputs.php:133
static getValueSingle(array $input, $userValue)
Definition inputs.php:156
static getError(array $input, $values)
Definition inputs.php:146
static getRequiredError(array $input, $value)
Definition input.php:141
static getError(array $input, $value)
Definition input.php:123