28 $this->_table_name = strtolower($table_name);
35 if(!
$DB->TableExists($this->_table_name))
48 $this->_sessid = substr($sess_id, 0, 32);
57 "VALUE" =>
ConvertDateTime(ConvertTimeStamp(
false,
"FULL"),
"YYYY-MM-DD HH:MI:SS"),
68 $rs =
$DB->Query(
"SELECT ID MID from ".$this->_table_name.
" WHERE SESS_ID = '".
$DB->ForSQL($this->_sessid).
"' AND PARENT_ID = 0");
78 $expired =
ConvertDateTime(ConvertTimeStamp(time()-3600,
"FULL"),
"YYYY-MM-DD HH:MI:SS");
80 $rs =
$DB->Query(
"select ID, SESS_ID, VALUE from ".$this->_table_name.
" where PARENT_ID = -1 AND NAME = 'SESS_ID' ORDER BY ID");
83 if(
$ar[
"SESS_ID"] == $this->_sessid ||
$ar[
"VALUE"] < $expired)
85 $DB->Query(
"DELETE from ".$this->_table_name.
" WHERE SESS_ID = '".
$DB->ForSQL(
$ar[
"SESS_ID"]).
"'");
94 $rs =
$DB->Query(
"SELECT ID MID from ".$this->_table_name.
" WHERE PARENT_ID = 0");
102 $isNeedCreate =
false;
113 $isNeedCreate =
true;
118 $isNeedCreate =
true;
133 if (
$connection->isTableExists($this->_table_name))
151 if (
$connection->isTableExists($this->_table_name))
163 if (
$connection->isTableExists($this->_table_name))
170 && defined(
'MYSQL_TABLE_TYPE')
171 && MYSQL_TABLE_TYPE !==
''
177 $connection->query(
'SET default_storage_engine = \'' . MYSQL_TABLE_TYPE .
'\'');
183 $connection->query(
'SET storage_engine = \''.MYSQL_TABLE_TYPE.
'\'');
210 if (defined(
'BX_XML_CREATE_INDEXES_IMMEDIATELY'))
220 if (!isset($this) || !is_object($this) || $this->_table_name ==
'')
230 return $connection->isTableExists($this->_table_name);
238 $tableFields =
$connection->getTableFields($this->_table_name);
241 empty($tableFields[
'ID'])
242 || ($withSessId && empty($tableFields[
'SESS_ID']))
243 || empty($tableFields[
'PARENT_ID'])
244 || empty($tableFields[
'LEFT_MARGIN'])
245 || empty($tableFields[
'RIGHT_MARGIN'])
246 || empty($tableFields[
'DEPTH_LEVEL'])
247 || empty($tableFields[
'NAME'])
248 || empty($tableFields[
'VALUE'])
249 || empty($tableFields[
'ATTRIBUTES'])
262 $parentID = (int)$parentID;
264 if (!isset($this) || !is_object($this) || $this->_table_name ==
'')
271 $parentID = (int)$parentID;
272 $rs =
$DB->Query(
"select count(*) C from ".$this->_table_name.
" where PARENT_ID = ".$parentID);
292 if (!
$connection->isIndexExists($this->_table_name, [
'SESS_ID',
'PARENT_ID']))
294 $connection->createIndex($this->_table_name,
'ix_' . $this->_table_name .
'_parent', [
'SESS_ID',
'PARENT_ID']);
297 if (!
$connection->isIndexExists($this->_table_name, [
'SESS_ID',
'LEFT_MARGIN']))
299 $connection->createIndex($this->_table_name,
'ix_' . $this->_table_name .
'_left', [
'SESS_ID',
'LEFT_MARGIN']);
304 if (!
$connection->isIndexExists($this->_table_name, [
'PARENT_ID']))
306 $connection->createIndex($this->_table_name,
'ix_' . $this->_table_name .
'_parent', [
'PARENT_ID']);
309 if (!
$connection->isIndexExists($this->_table_name, [
'LEFT_MARGIN']))
311 $connection->createIndex($this->_table_name,
'ix_' . $this->_table_name .
'_left', [
'LEFT_MARGIN']);
322 $strSql1 =
"PARENT_ID, LEFT_MARGIN, RIGHT_MARGIN, DEPTH_LEVEL, NAME";
323 $strSql2 = (int)
$arFields[
"PARENT_ID"] .
", "
325 . (int)(
$arFields[
"RIGHT_MARGIN"] ?? 0) .
", "
326 . (int)(
$arFields[
"DEPTH_LEVEL"] ?? 0) .
", '"
333 $strSql1 .=
", ATTRIBUTES";
334 $strSql2 .=
", '".$DB->ForSQL(
$arFields[
"ATTRIBUTES"]).
"'";
339 $strSql1 .=
", VALUE";
340 $strSql2 .=
", '".$DB->ForSQL(
$arFields[
"VALUE"]).
"'";
345 $strSql1 .=
", SESS_ID";
346 $strSql2 .=
", '".$DB->ForSQL($this->_sessid).
"'";
349 $strSql =
"INSERT INTO ".$this->_table_name.
" (".$strSql1.
") VALUES (".$strSql2.
")";
353 return $DB->LastID();
377 if(!array_key_exists(
"charset",
$NS))
378 $NS[
"charset"] =
false;
379 $this->charset = &
$NS[
"charset"];
381 if(!array_key_exists(
"element_stack",
$NS))
383 $this->element_stack = &
$NS[
"element_stack"];
385 if(!array_key_exists(
"file_position",
$NS))
386 $NS[
"file_position"] = 0;
387 $this->file_position = &
$NS[
"file_position"];
391 $this->buf_position = 0;
396 $end_time = time() + $time_limit;
398 $end_time = time() + 365*24*3600;
401 fseek($fp, $this->file_position);
409 if($xmlChunk[0] ==
"/")
412 if(time() > $end_time)
415 elseif($xmlChunk[0] ==
"!" || $xmlChunk[0] ==
"?")
417 if(strncmp($xmlChunk,
"?xml", 4) === 0)
419 if(preg_match(
'#encoding[\s]*=[\s]*"(.*?)"#i', $xmlChunk, $arMatch))
421 $this->charset = $arMatch[1];
422 if(strtoupper($this->charset) === strtoupper(
LANG_CHARSET))
423 $this->charset =
false;
447 if($this->buf_position >= $this->buf_len)
451 $this->buf = fread($fp, $this->read_size);
452 $this->buf_position = 0;
453 $this->buf_len = strlen($this->buf);
460 $xml_position = strpos($this->buf,
"<", $this->buf_position);
461 while($xml_position === $this->buf_position)
463 $this->buf_position++;
464 $this->file_position++;
466 if($this->buf_position >= $this->buf_len)
470 $this->buf = fread($fp, $this->read_size);
471 $this->buf_position = 0;
472 $this->buf_len = strlen($this->buf);
477 $xml_position = strpos($this->buf,
"<", $this->buf_position);
481 while($xml_position===
false)
487 $this->buf .= fread($fp, $this->read_size);
488 $this->buf_len = strlen($this->buf);
494 $xml_position = strpos($this->buf,
"<", $next_search);
496 if($xml_position===
false)
497 $xml_position = $this->buf_len+1;
500 $this->file_position += $len;
501 $result = substr($this->buf, $this->buf_position, $len);
502 $this->buf_position = $xml_position;
517 if($this->buf_position >= $this->buf_len)
521 $this->buf = fread($fp, $this->read_size);
522 $this->buf_position = 0;
523 $this->buf_len = mb_orig_strlen($this->buf);
530 $xml_position = mb_orig_strpos($this->buf,
"<", $this->buf_position);
531 while($xml_position === $this->buf_position)
533 $this->buf_position++;
534 $this->file_position++;
536 if($this->buf_position >= $this->buf_len)
540 $this->buf = fread($fp, $this->read_size);
541 $this->buf_position = 0;
542 $this->buf_len = mb_orig_strlen($this->buf);
547 $xml_position = mb_orig_strpos($this->buf,
"<", $this->buf_position);
551 while($xml_position===
false)
557 $this->buf .= fread($fp, $this->read_size);
558 $this->buf_len = mb_orig_strlen($this->buf);
564 $xml_position = mb_orig_strpos($this->buf,
"<", $next_search);
566 if($xml_position===
false)
567 $xml_position = $this->buf_len+1;
570 $this->file_position += $len;
571 $result = mb_orig_substr($this->buf, $this->buf_position, $len);
572 $this->buf_position = $xml_position;
587 if($this->buf_position >= $this->buf_len)
591 $this->buf = fread($fp, $this->read_size);
592 $this->buf_position = 0;
593 $this->buf_len = strlen($this->buf);
600 $xml_position = strpos($this->buf,
"<", $this->buf_position);
601 while($xml_position === $this->buf_position)
603 $this->buf_position++;
604 $this->file_position++;
606 if($this->buf_position >= $this->buf_len)
610 $this->buf = fread($fp, $this->read_size);
611 $this->buf_position = 0;
612 $this->buf_len = strlen($this->buf);
617 $xml_position = strpos($this->buf,
"<", $this->buf_position);
621 while($xml_position===
false)
627 $this->buf .= fread($fp, $this->read_size);
628 $this->buf_len = strlen($this->buf);
634 $xml_position = strpos($this->buf,
"<", $next_search);
636 if($xml_position===
false)
637 $xml_position = $this->buf_len+1;
640 $this->file_position += $len;
641 $result = substr($this->buf, $this->buf_position, $len);
642 $this->buf_position = $xml_position;
653 static $search =
array(
660 static $replace =
array(
667 $p = strpos($xmlChunk,
">");
670 if(substr($xmlChunk,
$p - 1, 1) ==
"/")
672 $bHaveChildren =
false;
673 $elementName = substr($xmlChunk, 0,
$p - 1);
674 $DBelementValue =
false;
678 $bHaveChildren =
true;
679 $elementName = substr($xmlChunk, 0,
$p);
680 $elementValue = substr($xmlChunk,
$p + 1);
681 if(preg_match(
"/^\s*$/", $elementValue))
682 $DBelementValue =
false;
683 elseif(strpos($elementValue,
"&") ===
false)
684 $DBelementValue = $elementValue;
686 $DBelementValue = preg_replace($search, $replace, $elementValue);
689 if(($ps = strpos($elementName,
" "))!==
false)
692 $elementAttrs = substr($elementName, $ps + 1);
693 $elementName = substr($elementName, 0, $ps);
694 preg_match_all(
"/(\\S+)\\s*=\\s*[\"](.*?)[\"]/su", $elementAttrs, $attrs_tmp);
696 if(!str_contains($elementAttrs,
"&"))
698 foreach($attrs_tmp[1] as
$i=>$attrs_tmp_1)
699 $attrs[$attrs_tmp_1] = $attrs_tmp[2][
$i];
703 foreach($attrs_tmp[1] as
$i=>$attrs_tmp_1)
704 $attrs[$attrs_tmp_1] = preg_replace($search, $replace, $attrs_tmp[2][
$i]);
706 $DBelementAttrs = serialize($attrs);
709 $DBelementAttrs =
false;
711 if($c =
count($this->element_stack))
712 $parent = $this->element_stack[$c-1];
714 $parent =
array(
"ID"=>
"NULL",
"L"=>0,
"R"=>1);
716 $left = $parent[
"R"];
720 "PARENT_ID" => $parent[
"ID"],
721 "LEFT_MARGIN" => $left,
724 "NAME" => $elementName,
726 if($DBelementValue !==
false)
730 if($DBelementAttrs !==
false)
732 $arFields[
"ATTRIBUTES"] = $DBelementAttrs;
740 $this->element_stack[$c-1][
"R"] =
$right+1;
752 $child = array_pop($this->element_stack);
753 $this->element_stack[
count($this->element_stack)-1][
"R"] = $child[
"R"]+1;
754 if($child[
"R"] != $child[
"RO"])
755 $DB->Query(
"UPDATE ".$this->_table_name.
" SET RIGHT_MARGIN = ".(
int)$child[
"R"].
" WHERE ID = ".(
int)$child[
"ID"]);
780 if(!is_array($arParent))
784 array(
"ID" => $arParent),
785 array(
"ID",
"LEFT_MARGIN",
"RIGHT_MARGIN"),
788 $arParent =
$rs->Fetch();
797 array(
"ID" =>
"asc"),
798 array(
"><LEFT_MARGIN" =>
array($arParent[
"LEFT_MARGIN"]+1, $arParent[
"RIGHT_MARGIN"]-1)),
805 (
int)
$ar[
'PARENT_ID'] === 0
806 && (
int)
$ar[
'RIGHT_MARGIN'] === 0
807 && (
int)
$ar[
'DEPTH_LEVEL'] === 0
808 &&
$ar[
'NAME'] ===
''
813 if(isset(
$ar[
"VALUE_CLOB"]))
814 $ar[
"VALUE"] =
$ar[
"VALUE_CLOB"];
816 if(isset($arSalt[
$ar[
"PARENT_ID"]][
$ar[
"NAME"]]))
818 $salt = ++$arSalt[
$ar[
"PARENT_ID"]][
$ar[
"NAME"]];
819 $ar[
"NAME"] .= $salt;
823 $arSalt[
$ar[
"PARENT_ID"]][
$ar[
"NAME"]] = 0;
826 if(
$ar[
"PARENT_ID"] == $arParent[
"ID"])
833 $parent_id =
$ar[
"PARENT_ID"];
834 if (!is_array($arIndex[$parent_id]))
836 $arIndex[$parent_id] = [];
838 $arIndex[$parent_id][
$ar[
"NAME"]] =
$ar[
"VALUE"];
839 $arIndex[
$ar[
"ID"]] = &$arIndex[$parent_id][
$ar[
"NAME"]];
856 "ATTRIBUTES" =>
"ATTRIBUTES",
857 "LEFT_MARGIN" =>
"LEFT_MARGIN",
858 "RIGHT_MARGIN" =>
"RIGHT_MARGIN",
862 foreach($arSelect as
$i => $field)
866 unset($arSelect[
$i]);
869 if (empty($arSelect))
874 $arSQLWhere =
array();
877 if($field ==
"ID" && is_array($value) && !empty($value))
882 $arSQLWhere[$field] = $field .
" in (" . implode(
",", $value) .
")";
885 elseif($field ==
"ID" || $field ==
"LEFT_MARGIN")
886 $arSQLWhere[$field] = $field.
" = ".(int)$value;
887 elseif($field ==
"PARENT_ID" || $field ==
"PARENT_ID+0")
888 $arSQLWhere[$field] = $field.
" = ".(int)$value;
890 $arSQLWhere[$field] =
"ID > ".(int)$value;
891 elseif($field ==
"><LEFT_MARGIN")
892 $arSQLWhere[$field] =
"LEFT_MARGIN between ".(int)$value[0].
" AND ".(
int)$value[1];
894 $arSQLWhere[$field] = $field.
" = ".
"'".$DB->ForSQL($value).
"'";
897 $arSQLWhere[] =
"SESS_ID = '".$DB->ForSQL($this->_sessid).
"'";
899 foreach($arOrder as $field => $by)
903 unset($arSelect[$field]);
907 $arOrder[$field] = $field .
" " . ($by ==
"desc" ?
"desc" :
"asc");
913 ".implode(
", ", $arSelect).
"
915 ".$this->_table_name.
"
916 ".(
count($arSQLWhere)?
"where (".implode(
") and (", $arSQLWhere).
")":
"").
"
917 ".(
count($arOrder)?
"order by ".implode(
", ", $arOrder):
"").
"
920 if ($handleAttributes)
934 return $DB->Query(
"delete from ".$this->_table_name.
" where ID = ".(
int)
$ID);
943 public static function safeUnZip(
string $fileName, ?
int $lastIndex =
null,
int $interval = 0):
array
946 'STATUS' => self::UNPACK_STATUS_FINAL,
955 if (mb_strlen($dirName) <= mb_strlen(
$_SERVER[
'DOCUMENT_ROOT']))
957 $result[
'STATUS'] = self::UNPACK_STATUS_ERROR;
964 if (!($archiver instanceof IBXArchive))
966 $result[
'STATUS'] = self::UNPACK_STATUS_ERROR;
971 if ($lastIndex !==
null && $lastIndex < 0)
976 $archiveProperties = $archiver->GetProperties();
977 if (!is_array($archiveProperties))
979 $result[
'STATUS'] = self::UNPACK_STATUS_ERROR;
983 if (!isset($archiveProperties[
'nb']))
985 $result[
'STATUS'] = self::UNPACK_STATUS_ERROR;
989 $entries = (int)$archiveProperties[
'nb'];
990 for ($index = 0; $index < $entries; $index++)
992 if ($lastIndex !==
null)
994 if ($lastIndex >= $index)
1000 $archiver->SetOptions([
1011 $stepResult = $archiver->Unpack($dirName);
1012 if ($stepResult ===
true)
1016 if ($stepResult ===
false)
1018 $result[
'STATUS'] = self::UNPACK_STATUS_ERROR;
1023 if ($interval > 0 && (time() -
$startTime) > $interval)
1025 $result[
'STATUS'] = self::UNPACK_STATUS_CONTINUE;
1026 $result[
'DATA'][
'LAST_INDEX'] = $index;
1047 $last_zip_entry = (string)$last_zip_entry;
1048 if ($last_zip_entry ===
'')
1050 $last_zip_entry =
null;
1054 $last_zip_entry = (int)$last_zip_entry;
1057 $internalResult = static::safeUnZip((
string)$file_name, $last_zip_entry, (
int)$interval);
1059 switch ($internalResult[
'STATUS'])
1061 case self::UNPACK_STATUS_ERROR:
1064 case self::UNPACK_STATUS_CONTINUE:
1065 $result = $internalResult[
'DATA'][
'LAST_INDEX'];
1067 case self::UNPACK_STATUS_FINAL:
static getConnection($name="")
static convertEncoding($data, $charsetFrom, $charsetTo)
static normalizeArrayValuesByInt(&$map, $sorted=true)
static GetArchive($strArcName, $strType="")
const UNPACK_STATUS_CONTINUE
IndexTemporaryTables($with_sess_id=false)
GetList($arOrder=array(), $arFilter=array(), $arSelect=array(), $handleAttributes=false)
isTableStructureCorrect($withSessId=false)
_get_xml_chunk_mb_orig($fp)
GetCountItemsWithParent($parentID)
const UNPACK_STATUS_FINAL
static UnZip($file_name, $last_zip_entry="", $start_time=0, $interval=0)
GetAllChildrenArray($arParent, $handleAttributes=false)
CreateTemporaryTables($with_sess_id=false)
__construct($table_name="b_xml_tree")
truncateTemporaryTables()
_start_element($xmlChunk)
ReadXMLToDatabase($fp, &$NS, $time_limit=0, $read_size=1024)
const UNPACK_STATUS_ERROR
initializeTemporaryTables()
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]
if(!defined('NOT_CHECK_PERMISSIONS')) $NS
ConvertDateTime($datetime, $to_format=false, $from_site=false, $bSearchInSitesOnly=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
</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."%"