<?php


function VIEWTREE_AJAX( $params = array() ) {

	SE_Layout::menu();

	$zasobID = V::get('ZASOB_ID', 0, $_GET, 'int');
	if ($zasobID <= 0) {
		echo 'Wrong param ZASOB_ID';
		return;
	}

	Lib::loadClass('ProcesHelper');

	$zasobObj = ProcesHelper::getZasobTableInfo($zasobID);
	if (!$zasobObj) {
		echo "Zasob TABELA ID={$zasobID} nie istnieje";
		return;
	}

	//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">zasobObj (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($zasobObj);echo'</pre>';

	$userAcl = User::getAcl();
	$userAcl->fetchGroups();
	//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;display:none;">$userAcl (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($userAcl);echo'</pre>';

	if (!$userAcl->hasTableAcl($zasobObj->ID)) {
		die("Brak uprawnień do tabeli ID={$zasobObj->ID}");
	}

	$tblAcl = $userAcl->getTableAcl($zasobObj->ID);
	//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">tblAcl (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($tblAcl);echo'</pre>';

	$forceTblAclInit = ('1' == V::get('_force', '', $_GET));
	$tblAcl->init($forceTblAclInit);

	Lib::loadClass('TreeAjax');

	$tbl = new TreeAjax($tblAcl);
	$tbl->setLabel($zasobObj->OPIS);
//	$tbl->addRowFunction('edit');
//	$tbl->addRowFunction('hist');
//	$tbl->addRowFunction('files');
//	$tbl->addRowFunction('cp');
	echo $tbl->render();
}
