<?//require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/header.php");?>

<?/*
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");?>
<?
	$_POST = $_POST ? : json_decode(file_get_contents('php://input'),true);
	CModule::IncludeModule('iblock');
	if ($_POST["TYPE"]=="LOAD_DATA"){
		$infoSection = array();
		$resSection = CIBlockSection::GetList(array(), array("IBLOCK_ID" => 102, "ACTIVE"=>"Y"), false, array("NAME", "ID"));
		while($obSection = $resSection->GetNext()){
			$infoSection[$obSection["ID"]]=$obSection;
		}
		$arSelect = Array("ID", "IBLOCK_SECTION_ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM", "PROPERTY_*");
		$arFilter = Array("IBLOCK_ID"=>array(102), "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y");
		$res = CIBlockElement::GetList(Array(), $arFilter, false, Array(), $arSelect);
		while($ob = $res->GetNextElement()){ 
			$arFields = $ob->GetFields();  
			$arFields["PROPS"] = $ob->GetProperties();
			$infoSection[$arFields["IBLOCK_SECTION_ID"]]["ITEMS"][] = $arFields;
		}
		echo json_encode(array_values($infoSection));
	}
	if ($_POST["TYPE"]=="GET_ELEMENTS"){
		$arSelect = Array("ID", "IBLOCK_SECTION_ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM", "PREVIEW_TEXT", "PROPERTY_*");
		$arFilter = Array("IBLOCK_ID"=>array(94, 95, 96, 97, 98, 99, 100, 102), "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y");
		$res = CIBlockElement::GetList(Array(), $arFilter, false, Array(), $arSelect);
		$category = array(
			94 => "Маршрут",
			95 => "Объект",
			96 => "Процесс",
			97 => "Событие",
			98 => "Работодатель",
			99 => "Требования",
			100 => "Ресурс",
			102 => "Инфо"
		);
		$result = array();
		while($ob = $res->GetNextElement()){ 
			$arFields = $ob->GetFields();  
			$arFields["PROPS"] = $ob->GetProperties();
			foreach ($arFields["PROPS"] as $key => $value) {
				if($value["PROPERTY_TYPE"]=="F" && $value["VALUE"]){
					if(is_array($value["VALUE"])){
						foreach ($value["VALUE"] as $keyF => $valueF) {
							$rsFile = CFile::GetByID($valueF);
							$arFile = $rsFile->Fetch();
							$arFields["PROPS"][$key]["VALUE"][$keyF] = CFile::GetPath($valueF);
							$arFields["PROPS"][$key]["FILE_INFO"][$keyF] = $arFile;
						}
					}
				}
			}
			$result[] = $arFields;
		}
		echo json_encode($result);
	}
	if ($_POST) {
		die();
	}
?>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://api-maps.yandex.ru/2.1/?apikey=ВАШ_API_КЛЮЧ&lang=ru_RU" type="text/javascript"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<style>
	#map {
		width: 100%; 
		height: 100%;
	}
	.link {
		cursor:pointer;
		color:blue;
		text-decoration:underline;
	}
</style>
<div id="app">
	<div id="map"></div>
	<div class="card left-block" style="width: 20rem; position: absolute; left: 2.9em; top: 2.5em; border: 1px solid; background: #fff;">
		<template v-for="section in leftNav">
			<div class="card-header text-bg-info"><b>{{section.NAME}}</b></div>
	  		<div class="card-body">
			<div class="card-text">
				<div v-for="element in section.ITEMS">
					<span @click="showInfo(element.ID)" class="link">{{element.NAME}}</span>
				</div>
			</div></div>
		</template>
	</div>
	<div class="card description" style="position: absolute;right: 0;bottom: 0; background: #fff; width: 36rem;" v-if="thisElement && thisElement.PREVIEW_TEXT">
	<h5 class="card-header">{{thisElement.NAME}}</h5>  
	<div class="card-body" style="max-height: 740px; overflow: auto;">
		<div class="card-title"><b>Описание</b></div>
		<div class="card-text" v-html="thisElement.PREVIEW_TEXT"></div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.address && thisElement.PROPS.address.VALUE"><b>Адрес</b>: {{thisElement.PROPS.address.VALUE}}</div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.rutube && thisElement.PROPS.rutube.VALUE"><b>Видео с рутуба</b>: 
			<template v-for="el in thisElement.PROPS.rutube.VALUE">
				<iframe width="100%" height="405" :src='"https://rutube.ru/play/embed/"+el+"/"' frameBorder="0" allow="clipboard-write; autoplay" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
			</template>
		</div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.video && thisElement.PROPS.video.VALUE"><b>Видео из файла</b>: 
			<template v-for="el in thisElement.PROPS.video.VALUE">
				<video controls :src="el" width="100%"></video>
			</template>
		</div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.date && thisElement.PROPS.date.VALUE"><b>Дата для карточки</b>: 
			{{thisElement.PROPS.date.VALUE}}
		</div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.link && thisElement.PROPS.link.VALUE"><b>Ссылка в интернет</b>: 
			<a :href="thisElement.PROPS.link.VALUE">{{thisElement.PROPS.link.VALUE}}</a>
		</div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.file && thisElement.PROPS.file.VALUE"><b>Файл</b>: 
			<template v-for="(el, key) in thisElement.PROPS.file.VALUE">
				<a :href="el" target="_blank">{{thisElement.PROPS.file.FILE_INFO[key].ORIGINAL_NAME}}</a><br>
			</template>
		</div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.photo && thisElement.PROPS.photo.VALUE"><b>Фотографии</b>: 
			<template v-for="el in thisElement.PROPS.photo.VALUE">
				<img style="max-width:100%" :src="el" alt="">
			</template>
		</div>
		<hr>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.connection94 && thisElement.PROPS.connection94.VALUE"><b>Маршрут</b>: 
			<span @click="showInfo(thisElement.PROPS.connection94.VALUE)">название маршрута{{thisElement.PROPS.connection94.VALUE}}</span>
		</div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.connection95 && thisElement.PROPS.connection95.VALUE"><b>Объект</b>: 
			<span @click="showInfo(thisElement.PROPS.connection95.VALUE)">название объекта{{thisElement.PROPS.connection95.VALUE}}</span>
		</div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.connection96 && thisElement.PROPS.connection96.VALUE"><b>Процесс</b>: 
			<span @click="showInfo(thisElement.PROPS.connection96.VALUE)">название процесса{{thisElement.PROPS.connection96.VALUE}}</span>
		</div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.connection97 && thisElement.PROPS.connection97.VALUE"><b>Событие</b>: 
			<span @click="showInfo(thisElement.PROPS.connection97.VALUE)">название события{{thisElement.PROPS.connection97.VALUE}}</span>
		</div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.connection98 && thisElement.PROPS.connection98.VALUE"><b>Работодатель</b>: 
			<span @click="showInfo(thisElement.PROPS.connection98.VALUE)">название работодателя{{thisElement.PROPS.connection98.VALUE}}</span>
		</div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.connection99 && thisElement.PROPS.connection99.VALUE"><b>Требования</b>: 
			<span @click="showInfo(thisElement.PROPS.connection99.VALUE)">название требования{{thisElement.PROPS.connection99.VALUE}}</span>
		</div>
		<div class="card-title" v-if="thisElement.PROPS && thisElement.PROPS.connection100 && thisElement.PROPS.connection100.VALUE"><b>Ресурс</b>: 
			<span @click="showInfo(thisElement.PROPS.connection10.VALUE)">название ресурса{{thisElement.PROPS.connection10.VALUE}}</span>
		</div>
	  </div>
	</div>
</div>
<script>
	const app = new Vue({
		el: '#app',
		name: 'App',
		data() {
			return {
				map: null,
				regions: [],
				leftNav: [],
				thisElement: null,
				elements: [],
				geometry: []
			}
		},
		mounted() {
			this.loadData()
			ymaps.ready(this.mapInit);
		},
		methods: {
			async loadData() {
				const res = await fetch('test.php', {
					method: 'POST',
					body: JSON.stringify({'TYPE' : 'LOAD_DATA'})
				})
				const json = await res.json()
				this.leftNav = json;
			},
			mapInit() {
				this.map = new ymaps.Map("map", {
					center: [46.3497, 48.0408],
					zoom: 9
				});
				this.loadRegions()
				this.getElements()
			},
			loadRegions() {
				ymaps.borders.load('RU', {
					lang: 'ru',
					quality: 2
				}).then((result) => {
					this.regions = result.features
				});
			},
			async showInfo(id){
				this.thisElement = this.elements.filter(el => el.ID == id)[0]

				if(this.thisElement.PROPS && this.thisElement.PROPS.map && this.thisElement.PROPS.map.VALUE){
					this.map.geoObjects.removeAll()
					this.showElementsByID();
				}
				if(this.thisElement.PROPS.action && this.thisElement.PROPS.actionIB && this.thisElement.PROPS.action.VALUE=="Показать метки инфоблока" && this.thisElement.PROPS.actionIB.VALUE){
					this.map.geoObjects.removeAll()
					this.showElementsByIB(this.thisElement.PROPS.actionIB.VALUE);
				}
				if(this.thisElement.PROPS.action && this.thisElement.PROPS.action.VALUE=="Показать Астраханскую область"){
					this.map.geoObjects.removeAll()
					this.showAO()
				}else{
					this.showAOBorder()
				}
			},
			showElementsByID() {
				this.geometry = new ymaps.Placemark(this.thisElement.PROPS.map.VALUE.split(','), {
				}, {
					preset: 'islands#dotIcon',
					iconColor: '#735184'
				})
				this.map.geoObjects.add(this.geometry);
				this.map.setCenter(this.geometry.geometry.getCoordinates(), 17);

			},
			showElementsByIB(IB) {
				const IBelements = this.elements.filter(el => el.IBLOCK_ID == IB)
				this.geometry = IBelements.map(el => {
					const placemark =  new ymaps.Placemark(el.PROPS.map.VALUE.split(','), {
					}, {
						preset: 'islands#dotIcon',
						iconColor: '#735184'
					})
					placemark.events.add('click', () => {
						this.showInfo(el.ID);
					});
					return placemark
				})
				this.geometry.map(el => {
					this.map.geoObjects.add(el);
				})
				this.map.setBounds(app.map.geoObjects.getBounds());

			},
			async getElements(){
				const res = await fetch('test.php', {
					method: 'POST',
					body: JSON.stringify({'TYPE' : 'GET_ELEMENTS'})
				})
				const json = await res.json()
				this.elements = json;
			},
			showAO(){
				var region = this.regions.filter(function (feature) {
                    return feature.properties.name === 'Астраханская область';
                })[0];
                var regionPolygon = new ymaps.GeoObject({
                    geometry: {
                        type: 'Polygon',
                        coordinates: region.geometry.coordinates,
                        fillRule: 'nonZero'
                    },
                    properties: {
                        hintContent: 'Астраханская область'
                    }
                }, {
                    fillColor: '#00ceff0d', 
                    strokeColor: '#00ceff',
                    strokeWidth: 2          
                });
				this.map.geoObjects.add(regionPolygon);
				this.map.setBounds(regionPolygon.geometry.getBounds());

			},
			showAOBorder(){
				var region = this.regions.filter(function (feature) {
                    return feature.properties.name === 'Астраханская область';
                })[0];
                var regionPolygon = new ymaps.GeoObject({
                    geometry: {
                        type: 'Polygon',
                        coordinates: region.geometry.coordinates,
                        fillRule: 'nonZero'
                    },
                }, {
                    fillColor: '#00ceff00',
                    strokeColor: '#00ceff',
                    strokeWidth: 2         
                });
				this.map.geoObjects.add(regionPolygon);
			},
		}
	})
</script>

<?/*
<div class="description" style="position: absolute;right: 0;bottom: 0; background: #fff;">
<?
	if(isset($_GET["id"]) && $_GET["id"]>0){
		$detailID = $_GET["id"];
		viewElement($detailID);
	}
	function viewElement($id){
		$detailID = $id;
		CModule::IncludeModule('iblock');
		$res = CIBlockElement::GetByID($detailID);
		$category = array(
			94 => "Маршрут",
			95 => "Объект",
			96 => "Процесс",
			97 => "Событие",
			98 => "Работодатель",
			99 => "Требования",
			100 => "Ресурс"
		);
		if($ar_res = $res->GetNextElement()){
			$arFields = $ar_res->GetFields();
			if($category[$arFields["IBLOCK_ID"]] || $arFields["IBLOCK_ID"]==102){
				$arFields["PROP"] = $ar_res->GetProperties();
				?><p>Название: <b><?=$arFields["NAME"]?></b></p><?
				if($category[$arFields["IBLOCK_ID"]]){
					?><p>Категория: <b><?=$category[$arFields["IBLOCK_ID"]]?></b></p><?
				}
				?><p>Описание: <b><?=$arFields["PREVIEW_TEXT"]?></b></p><?
				foreach ($category as $keyСategory => $valueСategory) {
					if($arFields["PROP"]["connection".$keyСategory]["VALUE"]){
						if(is_array($arFields["PROP"]["connection".$keyСategory]["VALUE"])){
							?><p><b><?=$category[$keyСategory]?></b></p><?
							foreach ($arFields["PROP"]["connection".$keyСategory]["VALUE"] as $keyProp => $valueProp) {
								linkDop($valueProp);
								?><div class="description-<?=$valueProp?>">
									<?viewElement($valueProp);?>
								</div><?
							}
						}else{
							?><p><b><?=$category[$keyСategory]?></b></p><?
							linkDop($arFields["PROP"]["connection".$keyСategory]["VALUE"]);
							?><div class="description-<?=$arFields["PROP"]["connection".$keyСategory]["VALUE"]?>">
								<?viewElement($arFields["PROP"]["connection".$keyСategory]["VALUE"]);?>
							</div><?
						}
					}
				}
			}
		}
		
	}
	function linkDop($id){
		$category = array(
			94 => "Маршрут",
			95 => "Объект",
			96 => "Процесс",
			97 => "Событие",
			98 => "Работодатель",
			99 => "Требования",
			100 => "Ресурс"
		);
		CModule::IncludeModule('iblock');
		$res = CIBlockElement::GetByID($id);
		if($ar_res = $res->GetNextElement()){
			$arFields = $ar_res->GetFields();
			if(!$category[$arFields["IBLOCK_ID"]]){return;}
			?><p><a href="/test.php?id=<?=$arFields["ID"]?>"><?=$arFields["NAME"]?></a></p><?
		}
	}
?>
</div>*/?>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");?>
*/?>
<?die()?>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");?>
<?
$url = 'http://192.168.3.18/Col/hs/workload/get';

$data = json_encode([
    "year" => "000000038",
    "dep" => "000000013",
    "funding" => "",
    "pt_work" => "Штатный",
    "teacher" => "000737",
    "group" => "",
    "type" => "Общая"
]);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_USERPWD, "lka:123");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data)
]);

$response = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Ошибка cURL: ' . curl_error($ch);
} else {
	$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $jsonResponse = json_decode($response, true);
    echo '<pre>';
    print_r($jsonResponse);
    echo '</pre>';
}
//
?>

<?
foreach ($jsonResponse['data']['workload'] as $key => $tab_value) {
	foreach($tab_value as $keys => $value) {
        if ($keys=="funding") {
  		    print_r($value);
        }
	}
}
?>
//
<?
curl_close($ch);
?>
<!--
https://cdnjs.com/libraries/font-awesome
https://docs.fontawesome.com/web/setup/get-started
https://html5book.ru/shrift-awesome/
<div class="fa fa-rotate-270">всего в неделю</div>
(!) https://lysenka.net/web/8/
-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.1/css/fontawesome.min.css">

    <table style="width: 100%;" border="1" width="100%" cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
            <td rowspan="4">НАИМЕНОВАНИЕ ПРЕДМЕТА</td>
            <td rowspan="4">ПРЕПОДАВАТЕЛЬ</td>
            <td style="text-align: left; vertical-align: top;" rowspan="4">П<br />О<br />Д<br />Г<br />Р<br />У<br />П<br />П<br />А</td>
            <td style="text-align: center;" colspan="26">Количество часов</td>
            <td rowspan="4">Всего за год</td>
        </tr>
        <tr>
            <td style="text-align: left; vertical-align: top;" rowspan="3">В<br />С<br />Е<br />Г<br />О</td>
            <td style="text-align: center;" colspan="12">I семестр (_)</td>
            <td rowspan="3">В<br />С<br />Е<br />Г<br />О</td>
            <td style="text-align: center;" colspan="12">II семестр (_)</td>
        </tr>
        <tr>
            <td style="text-align: center;" colspan="12">всего из них</td>
            <td style="text-align: center;" colspan="12">всего из них</td>
        </tr>
        <tr>
            <td style="text-align: center; vertical-align: top;">всего в неделю</td>
            <td style="text-align: center; vertical-align: top;">ауд. занятий</td>
            <td style="text-align: center; vertical-align: top;">практи- ческие</td>
            <td style="text-align: center; vertical-align: top;">практи- ческая подг-ка</td>
            <td style="text-align: center; vertical-align: top;">лекции</td>
            <td style="text-align: center; vertical-align: top;">дистанц. обуч.*</td>
            <td style="text-align: center; vertical-align: top;">прием КП</td>
            <td style="text-align: center; vertical-align: top;">консуль КП</td>
            <td style="text-align: center; vertical-align: top;">консуль- тации</td>
            <td style="text-align: center; vertical-align: top;">индив. проект</td>
            <td style="text-align: center; vertical-align: top;">промеж. аттест.</td>
            <td style="text-align: center; vertical-align: top;">экза- мены</td>
            <td style="text-align: center; vertical-align: top;">всего в неделю</td>
            <td style="text-align: center; vertical-align: top;">ауд. занятий</td>
            <td style="text-align: center; vertical-align: top;">практи- ческие</td>
            <td style="text-align: center; vertical-align: top;">практи- ческая подг-ка</td>
            <td style="text-align: center; vertical-align: top;">лекции</td>
            <td style="text-align: center; vertical-align: top;">дистанц. обуч.*</td>
            <td style="text-align: center; vertical-align: top;">прием КП</td>
            <td style="text-align: center; vertical-align: top;">консуль КП</td>
            <td style="text-align: center; vertical-align: top;">консуль- тации</td>
            <td style="text-align: center; vertical-align: top;">индив. проект</td>
            <td style="text-align: center; vertical-align: top;">промеж. аттест.</td>
            <td style="text-align: center; vertical-align: top;">экза- мены</td>
        </tr>
        <tr>
            <td colspan="30">Бюджетное обучение</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        </tbody>
    </table>
<?//require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/footer.php");?>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");?>