<?php

require_once dirname(__FILE__) . '/' . 'Lib.php';
Lib::loadClass('V');
Lib::loadClass('User');

class ProcesMenu {

	var $MENU_SELECT_PROCES;
	var $CRM_PROCES_USERA_UZYTY_MAP = null;
	var $CRM_PROCES_USERA_UZYTY_MAP_PROCES_INIT;
	var $CRM_PROCES_USERA_WYKONANE_TESTY;
	var $_wynik_testu;
	var $_wynik_testu_unactual;
	var $error;// errory niedopuszczajace do uruchomienia
	var $warning;// uwagi
	var $CRM_PROCES_USERA_UZYTY;
	var $_user_id;
	var $_acl;

	function __construct() {
		$this->MENU_SELECT_PROCES_DATA = V::get('MENU_SELECT_PROCES_DATA', null, $_SESSION);// URL

		$this->_user_id = User::getID();
		if (User::isAdmin()) {
			$this->_user_id = V::get('_user_id', 0, $_POST, 'int');
			if (!$this->_user_id) {
				$this->_user_id = User::getID();
			}
		}

		Lib::loadClass('UsersHelper');
		$this->_acl = UsersHelper::getUserAcl($this->_user_id);
		if (!$this->_acl) {
			die('Error Acl');
		}

		// TODO: TEST
		if ('' != V::get('DBG', '', $_GET)) {
			echo '<div style="background:#eeefef;border:2px solid blue;padding:10px;">';
			//$this->_acl->old();
			echo '</div>';
			echo '<div style="background:#eeefef;border:2px solid green;padding:10px;">';
			$this->_acl->old_fixed();
			echo '</div>';
		}

		$this->CRM_PROCES_USERA_UZYTY_MAP = $this->_acl->getUsedProcesMap();

		// TODO: run only if needed
		$this->_generate_wyniki_testow();
	}

	static function getInstance() {
		static $_instance = null;
		if (!$_instance) {
			$_instance = new ProcesMenu();
		}
		return $_instance;
	}

	function show() {
		static $_menu_showed = false;
		if (!$_menu_showed) {
			$actionName = V::get('_action', 'menu', $_REQUEST);

			// podglad testów pracownika
			if (User::isAdmin() && $this->_user_id != User::getID()) {
				$actionName = 'showMyTests';
			}

			$actionName .= 'Action';
			if (method_exists($this, $actionName)) {
				$this->{$actionName}();
			}

			//$this->show_menu_with_process();

			$_menu_showed = true;
		}
	}

	/**
	 * @return Array
	 */
	function get_wykonane_testy() {
		$testy_arr = array();
		if ($this->_user_id > 0) {
			$ses_cache_key = 'CRM_PROCES_USERA_WYKONANE_TESTY-' . $this->_user_id;
			if (!isset($_SESSION[$ses_cache_key])) {
				$proces_map = $this->_acl->getUsedProcesMap();
				if (!empty($proces_map)) {
					Lib::loadClass('ProcesTestyHelper');
					$testy_arr = ProcesTestyHelper::get_tetsy_stats($this->_user_id, 0, array_keys($proces_map));// 30000000 => 0

					// check if tests are actual - proces steps may change
					if (!empty($testy_arr)) {
						$procesy_steps = array();
						foreach ($testy_arr as $v_test) {
							$procesy_steps[$v_test->ID_PROCES_INIT] = V::get($v_test->ID_PROCES_INIT, null, $proces_map);
						}

						foreach ($procesy_steps as $k_proces_id => $v_steps_arr) {
							$last_test = null;
							foreach ($testy_arr as $k_ind => $v_test) {
								if ($v_test->ID_PROCES_INIT == $k_proces_id) {
									$last_test = $v_test;
									$last_test->test_ind = $k_ind;
									break;
								}
							}
							if (!$last_test || $last_test->TEST_END == '0000-00-00') {
								continue;
							}
							$max_update_date = ProcesTestyHelper::get_max_update_date($v_steps_arr);
							if ($max_update_date) {
								$max_update_date = substr($max_update_date, 0, 10);
								$test_end = substr($last_test->TEST_END, 0, 10);
								//echo '<p>' . "P_INIT($k_proces_id) max_update_date({$max_update_date}) TEST_END({$last_test->TEST_END}) not actual(" . ($max_update_date > $last_test->TEST_END) . ")" . '</p>';
								if ($max_update_date > $test_end) {
									$testy_arr[$last_test->test_ind]->unactual = $max_update_date;
								}
							}
						}
					}
				}
				$_SESSION[$ses_cache_key] = $testy_arr;
			}
			return $_SESSION[$ses_cache_key];
		}
		return $testy_arr;
	}

	function setError($error) {
		$this->error[] = $error;
	}

	function ifError() {// TODO: RMME
		if (!empty($this->error)) {
			return true;
		}
		else {
		 DEBUG_S(-1,'Wydarzyły się błędy uniemożliwiające kontynuacje pracy modułu',$this->error,__FILE__,__FUNCTION__,__LINE__);
		 die();
		 return false;
		}
	}

	function set_current_menu($new_menu) {
		$this->MENU_SELECT_PROCES = $new_menu;
	}

	/**
	 * Set $_SESSION['MENU_SELECT_PROCES_DATA'] from $this->MENU_SELECT_PROCES_DATA
	 */
	function set_current_menu_data() {
		$_SESSION['MENU_SELECT_PROCES_DATA'] = array();
		foreach ($this->MENU_SELECT_PROCES_DATA as $k_ind => $v_arr) {
			if (!empty($v_arr)) {
				$_SESSION['MENU_SELECT_PROCES_DATA'][$k_ind] = $v_arr;
			}
		}
	}

	function showMyTestsAction() {
		$this->menuAction();
		$userAcl = User::getAcl();

		$map = $this->_acl->getUsedProcesMap();
		$menu_to_show = array_keys($map);
		if (empty($menu_to_show)) {
			echo '<p>' . "Brak przypisanych procesów." . '</p>';
			return;
		}

		$procesy_init_ids = array();
		Lib::loadClass('DB');
		$db = DB::getDB();
		$sql = "select `ID`,`DESC` from `CRM_PROCES` where `TYPE`='PROCES_INIT' and `ID` in (".implode(",", $menu_to_show).") ";
		$res = $db->query($sql);
		while ($r = $db->fetch($res)) {
			$procesy_init_ids[$r->ID] = $r->DESC;
		}

		echo '<style type="text/css">' . "
.tbl-wyniki-testow {}
 .tbl-wyniki-testow td {vertical-align:top;font-size:small;}
 .tbl-wyniki-testow .proces-box {padding:0 6px;background:#f00;color:#fff;font-weight:bold;font-family:arial;text-decoration:none}
 .tbl-wyniki-testow .proces-desc {padding:0 3px;}
 .tbl-wyniki-testow .wynik-cell .wyniki-cell-header {height:56px;overflow:hidden;}

 .tbl-wyniki-testow .wynik-cell {padding:0 3px;background-color:#f7f7f7;}
 .tbl-wyniki-testow .wynik-BRAK_TESTU .proces-box {background-color:silver;}
 .tbl-wyniki-testow .wynik-BRAK_PYTAN .proces-box {background-color:#51B7D5;}
 .tbl-wyniki-testow .wynik-DOBRY .proces-box {background-color:lightgreen;}
 .tbl-wyniki-testow .wynik-DOSTATECZNY .proces-box {background-color:#FFFFB1; color:#777;}
 .tbl-wyniki-testow .wynik-NIEDOSTATECZNY .proces-box {background-color:#FC5151;}
 .tbl-wyniki-testow .wynik-IDEALNY .proces-box {background-color:gold;}
 .tbl-wyniki-testow .wynik-NIEAKTUALNY .proces-box {background-color:silver;}
 .tbl-wyniki-testow .row-fluid {margin-bottom:20px;}
		" . '</style>';

		$userGroups = $this->_acl->fetchGroups();
		$idZasobowUsera = array_keys($userGroups);
		$idZasobowUsera = reset($idZasobowUsera);
		?>
<div class="container-fluid tbl-wyniki-testow">
	<div class="row-fluid">
	<?php $i = 0; foreach ($procesy_init_ids as $proces_id => $proces_desc) : ?>
		<?php
			$wynik_teoretyczny = $this->get_ocena_testu($proces_id, 'TEORETYCZNY');
			$wynik_teoretyczny_value = $this->get_ocena_testu_value($proces_id, 'TEORETYCZNY');
			if ($wynik_teoretyczny == 'BRAK_PYTAN') {
				$wynik_teoretyczny_value = '';
			}
			$wynik_praktyczny = $this->get_ocena_testu($proces_id, 'PRAKTYCZNY');
			$wynik_unactual = $this->isTestUnactual($proces_id, 'TEORETYCZNY');
		?>
		<div class="span3 wynik-cell wynik-<?php echo $wynik_teoretyczny; ?>">
			<div class="wyniki-cell-header">
				<a class="proces-box" href="procesy5.php?task=PROCES_VIEW&id_proces=<?php echo $proces_id; ?>" title="zobacz instrukcję do procesu <?php echo $proces_id; ?>" target="_blank"><?php echo $proces_id; ?></a>
				<span class="proces-desc"><?php echo $proces_desc; ?></span>
			</div>

			<li>
				<?php if ($userAcl->getPermsProcesId() == $proces_id) : ?>
					<b><a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsAll"> Wyłącz filtr uprawnien dla </a></b>
				<?php else : ?>
					<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=<?php echo $proces_id; ?>"> Uruchom filtr uprawnien dla </a>
				<?php endif; ?>
				<?php echo $proces_id; ?>
			</li>

			<?php if (!in_array($wynik_teoretyczny, array('DOBRY', 'IDEALNY')) || $wynik_unactual) : ?>
				<li>
					<a href="procesy5.php?task=CRM_TESTY__ADD_TEST&function_init=fun_CRM_TESTY_ADD&stanowisko_id=<?php echo $idZasobowUsera; ?>&proces_id=<?php echo $proces_id; ?>&test_type=TEORETYCZNY"> Wykonaj test teoretyczny dla </a>
					<?php echo $proces_id; ?>
				</li>
			<?php endif; ?>
			<li>Test teoretyczny: <span class="proces-box"><?php echo $wynik_teoretyczny; ?>
					<?php if ($wynik_teoretyczny_value) : ?> <em>(<?php echo $wynik_teoretyczny_value; ?>)</em><?php endif; ?>
				</span>
			</li>
			<li class="wynik-<?php echo $wynik_praktyczny; ?>">Test praktyczny: <?php echo $wynik_praktyczny; ?></li>

			<?php if ($wynik_unactual) : ?>
				<div class="alert alert-error">
					<b>Uwaga! Test nieaktualny:</b>
					<br /><?php echo $wynik_unactual->TEST_END; ?> - zakończenie testu
					<br /><?php echo $wynik_unactual->unactual; ?> - ostatnia zmiana w procesie
				</div>
			<?php endif; ?>
		</div>
		<?php if (++$i >= 4) : $i = 0; ?>
				</div><div class="row-fluid">
		<?php endif; ?>
	<?php endforeach; ?>
	</div>
</div>
		<?php
	}

	function menuAction() {
		$testy_teoretyczne = $this->get_actual_tests_count('TEORETYCZNY');
		$testy_praktyczne = $this->get_actual_tests_count('PRAKTYCZNY');
		$procesy_init_arr = $this->_acl->getUsedProcesInitIds();
		$proces_cnt = count($procesy_init_arr);
		$testy_ok = $this->get_actual_tests_count();
		$MojeTestyTitle = "Ilość Procesów: {$proces_cnt}, Aktualnych testów: {$testy_ok},  Teoretycznych: {$testy_teoretyczne}, Praktycznych: {$testy_praktyczne}";

		$userAcl = User::getAcl();
		$tbls = $userAcl->getTablesAcl();
		$urls = $userAcl->getUrls();

		$outMenus = array();
		$outBtnsMenus = array();
		if (!empty($tbls)) {
			foreach ($tbls as $kZasobID => $vTblAcl) {
				$outMenus[$kZasobID] = $vTblAcl->getLongLabel();
				if ($userAcl->getPermsProcesId()) {
					$outBtnsMenus[$kZasobID] = $vTblAcl->getRawLabel();
				}
			}
		}
		asort($outMenus);
		if ($userAcl->getPermsProcesId()) {
			asort($outBtnsMenus);
		}

		$outUrls = array();
		if (!empty($urls)) {
			/**
			 * 	[147] => Array(
       *       [TYPE] => URL
       *       [DESC] => ?MENU_INIT=DODAJ_REKORDY_MIESZKAN_FUNC
       *       [OPIS] => Narzedzie do wprowadzania zasobow mieszkan indywidualnych
			 */
			foreach ($urls as $kZasobID => $vTitle) {
				$outUrls[$kZasobID] = $vTitle;
			}
		}
		asort($outUrls);

		$active = '';
		$script_name = V::get('SCRIPT_NAME', '', $_SERVER);
		if (false !== strpos($script_name, 'index.php')) {
			$menu_init = V::get('MENU_INIT', '', $_GET);
			switch ($menu_init) {
				case 'VIEWTABLE_AJAX': $active = 'menu'; break;
				case 'VIEWTABLE_KONTAKTY': $active = 'kontakty'; break;
				default: {
					$fun_init = V::get('FUNCTION_INIT', '', $_GET);
					switch ($fun_init) {
						case 'MENU_SELECT_PROCES': $active = 'testy_moje'; break;
						case 'PRZYPOMNIJ_FUNC': $active = 'przypomnij'; break;
						case 'PRZYPOMNIJ': $active = 'przypomnij'; break;
						default:
					}
				}
			}
		}
		else if (false !== strpos($script_name, 'procesy5.php')) {
			$task = V::get('task', '', $_GET);
			switch ($task) {
				case 'CRM_PROCES': $active = 'procesy'; break;
				case 'CRM_LISTA_ZASOBOW': $active = 'zasoby'; break;
				case 'CRM_WYSWIETL_OBOWIAZKI': $active = 'obowiazki'; break;
				case 'CRM_TESTY': $active = 'testy'; break;
				case 'CRM_TESTY_WYNIKI': $active = 'testy_wyniki'; break;
				case 'CRM_SEARCH': $active = 'search'; break;
				default:
				// testy_moje		?FUNCTION_INIT=MENU_SELECT_PROCES&MENU_SELECT_PROCES=show_menu_with_process => _action=showMyTests
			}
		}

/*
 * $_SESSION['USER_PROFILE'][section][key] = val;
 */
		Lib::loadClass('UserBookmarks');
		$userBookmarks = UserBookmarks::getInstance();

		$bookmarksJson = array();
		$bookmarks = $userBookmarks->getBookmarks();
		foreach ($bookmarks as $kZasobID => $vClass) {
			if (array_key_exists($kZasobID, $tbls)) {
				$bookmarksJson[] = (object)array('id'=>$kZasobID, 'name'=>$tbls[$kZasobID]->getName(), 'label'=>$tbls[$kZasobID]->getRawLabel(), 'opis'=>$tbls[$kZasobID]->getOpis(), 'type'=>'menu', 'class'=>$vClass);
			}
			else if (array_key_exists($kZasobID, $urls)) {
				$bookmarksJson[] = (object)array('id'=>$kZasobID, 'name'=>$urls[$kZasobID], 'type'=>'url', 'class'=>$vClass);
			}
		}

		?>
<div id="SE-menu" class="navbar navbar-inverse" style="position: static;">
	<div class="navbar-inner">
		<div class="container">
			<div class="nav-collapse collapse navbar-inverse-collapse">
				<ul class="nav">
					<li class="dropdown<?php if ($active == 'menu') echo ' active'; ?>">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown">Menu <b class="caret"></b></a>
						<ul class="dropdown-menu" id="SE-menu-tables">
							<?php foreach ($outMenus as $kZasobID => $vName) : ?>
								<li>
									<a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $kZasobID; ?>">
										<i class="bookmark-item-add-<?php echo $kZasobID; ?> bookmark-item-add icon-star-empty" title="Add to favorites" data-zasobid="<?php echo $kZasobID; ?>"></i>
										<i class="bookmark-item-rem-<?php echo $kZasobID; ?> bookmark-item-rem icon-star" style="display:none" title="Remove from favorites" data-zasobid="<?php echo $kZasobID; ?>"></i>
										<?php echo $vName; ?>
									</a>
								</li>
							<?php endforeach; ?>
						</ul>
					</li>
					<li class="dropdown">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown">Narzędzia <b class="caret"></b></a>
						<ul class="dropdown-menu">
							<?php foreach ($outUrls as $kZasobID => $vTitle) : ?>
								<li>
									<a href="index.php?FUNCTION_INIT=URL_INIT&ZASOB_ID=<?php echo $kZasobID; ?>" target="_blank" title="<?php echo $vTitle; ?>">
										<i class="bookmark-item-add-<?php echo $kZasobID; ?> bookmark-item-add icon-star-empty" title="Add to favorites" data-zasobid="<?php echo $kZasobID; ?>"></i>
										<i class="bookmark-item-rem-<?php echo $kZasobID; ?> bookmark-item-rem icon-star" style="display:none" title="Remove from favorites" data-zasobid="<?php echo $kZasobID; ?>"></i>
										<code><?php echo $kZasobID; ?></code>
										<?php echo (mb_strlen($vTitle, 'utf-8') > 100)? mb_substr($vTitle, 0, 100, 'utf-8') . '...' : $vTitle; ?>
									</a>
								</li>
							<?php endforeach; ?>
						</ul>
					</li>
					<li<?php if ($active == 'procesy') echo ' class="active"'; ?>><a href="procesy5.php?task=CRM_PROCES&ID=x" title="Wyswietlenie procesow">Procesy</a></li>
					<li<?php if ($active == 'zasoby') echo ' class="active"'; ?>><a href="procesy5.php?task=CRM_LISTA_ZASOBOW<?php if(!empty($_REQUEST['ZASOB_ID'])) echo "&filtr_id=".$_REQUEST['ZASOB_ID']."&ID=x&filtr_ids=%2B&filtr_ob=%2B";  ?>" title="Wyswietlenie zasobow">Zasoby</a></li>
					<li<?php if ($active == 'obowiazki') echo ' class="active"'; ?>><a href="procesy5.php?task=CRM_WYSWIETL_OBOWIAZKI" title="Wyswietlenie OBOWIAZKOW">Obowiązki</a></li>
					<li<?php if ($active == 'testy') echo ' class="active"'; ?>><a href="procesy5.php?task=CRM_TESTY" title="Wyswietlenie testów">Testy</a></li>
					<li<?php if ($active == 'testy_moje') echo ' class="active"'; ?>><a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=showMyTests" title="<?php echo $MojeTestyTitle; ?>">Moje (<?php echo "{$testy_ok} z {$proces_cnt}: T {$testy_teoretyczne}, P {$testy_praktyczne}"; ?>)</a></li>
					<?php if (User::get('ADM_ADMIN_LEVEL') <= 2) : ?>
						<li<?php if ($active == 'testy_wyniki') echo ' class="active"'; ?>><a href="procesy5.php?task=CRM_TESTY_WYNIKI" title="Wyswietlenie wyników testów">Wyniki</a></li>
					<?php endif; ?>
					<li<?php if ($active == 'kontakty') echo ' class="active"'; ?>><a href="index.php?MENU_INIT=VIEWTABLE_KONTAKTY" title="Kontakty">Kontakty</a></li>
					<li<?php if ($active == 'przypomnij') echo ' class="active"'; ?>><a href="index.php?MENU_INIT=PRZYPOMNIJ&KTO=<?php echo User::getLogin(); ?>" title="Przypomnij">Przypomnij</a></li>
				</ul>
				<ul class="nav pull-right">
					<li<?php if ($active == 'search') echo ' class="active"'; ?>>
						<form action="procesy5.php?task=CRM_SEARCH" method="post" class="navbar-search">
							<input type="text" name="q" value="" class="q search-query span2">
							<input type="image" src="icon/search.png" class="s">
						</form>
					</li>
					<li class="divider-vertical"></li>
					<li style="padding:8px 0;"><?php S::show_session_timer(); ?></li>
					<li class="divider-vertical"></li>

					<li class="dropdown">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo User::getName(); ?> <b class="caret"></b></a>
						<ul class="dropdown-menu">
							<?php if (file_exists('/Library/Server/Web/Data/Sites/Default/')) : ?>
								<li><a href="/webcal" target="_blank"><i class="icon-calendar"></i> Kalendarz</a></li>
								<?php if (file_exists('/Library/Server/Web/Data/Sites/Default/webmail/loginFromSE.php')) : ?>
									<li><a href="/webmail" target="_blank" onclick="jQuery(this).next('form').submit(); return false;"><i class="icon-envelope"></i> Poczta</a>
										<form action="https://<?php echo $_SERVER['SERVER_NAME']; ?>/webmail/loginFromSE.php" method="post" style="display:none;">
											<input type="hidden" name="_timezone" value="Europe/Berlin">
											<input type="hidden" name="_token" value="">
											<input type="hidden" name="_action" value="login">
											<input type="hidden" name="_task" value="login">
											<input type="hidden" name="_url" value="">
											<input type="hidden" name="_user" value="<?php echo User::getName(); ?>">
											<input type="hidden" name="_pass" value="<?php echo User::get('ADM_PASS_HASH'); ?>">
											<input type="hidden" name="EMAIL_IMAP_IMPORT_USERNAME" value="<?php  echo V::get('EMAIL_IMAP_IMPORT_USERNAME', '', $_SESSION); ?>">
											<input type="hidden" name="EMAIL_IMAP_IMPORT_HOST" value="<?php  echo V::get('EMAIL_IMAP_IMPORT_HOST', '', $_SESSION); ?>">
											<input type="hidden" name="EMAIL_IMAP_IMPORT_PASSWD_HASH" value="<?php  echo V::get('EMAIL_IMAP_IMPORT_PASSWD_HASH', '', $_SESSION); ?>">
											<input type="hidden" name="loginFromSE" value="1">
											<input type="submit" class="btn" value="P" />
										</form>
									</li>
								<?php elseif (file_exists('/Library/Server/Web/Data/Sites/Default/webmail')) : ?>
									<li><a href="/webmail" target="_blank"><i class="icon-envelope"></i> Poczta</a></li>
								<?php endif; ?>
								<li><a href="https://<?php echo $_SERVER['SERVER_ADDR']; ?>/changepassword" target="_blank">Zmień hasło</a></li>
								<li><a href="/profilemanager" target="_blank"><i class="icon-user"></i> Apple Profile Manager</a></li>
								<li class="divider"></li>
							<?php else: ?>
								<li><a href="index.php?LOGIN=PASSEDIT">Zmień hasło</a></li>
							<?php endif; ?>

							<li><a href="procesy5.php?task=USER" title="<?php echo User::getName(); ?>"><i class="icon-user"></i> Profil</a></li>
							<li><a href="index.php?LOGIN=PERMS_RELOAD" title="Przeładuj uprawnienia"><i class="icon-refresh"></i> Przeładuj uprawnienia</a></li>
							<?php if (User::isAdmin()) : ?>
								<li class="divider"></li>
								<li class="nav-header">Pokaż testy pracownika:</li>
								<li>
									<?php
										Lib::loadClass('UsersHelper');
										$users = UsersHelper::get_users_list(null, 100, 0, 'ADM_NAME', 'ASC');
										$user_sel = array();
										foreach ($users as $r) {
											$user_sel [$r->ID] = "{$r->ID}: {$r->ADM_NAME} ({$r->ADM_ACCOUNT}, {$r->EMAIL}, {$r->ADM_PHONE})";
										}

										if (!empty($user_sel)) {
											echo '<form action="index.php" method="POST">';
											echo '<input type="hidden" name="FUNCTION_INIT" value="MENU_SELECT_PROCES">';
											echo '<input type="hidden" name="_action" value="showMyTests">';
											echo '<select name="_user_id">';
											foreach ($user_sel as $k_option => $v_label) {
												$sel = ($k_option == $this->_user_id)? ' selected="selected"' : '';
												echo '<option value="' . $k_option . '"' . $sel . '>' . $v_label . '</option>';
											}
											echo '</select>';
											echo ' ';
											echo '<input type="submit" value="Wybierz" />';
											echo '</form>';
										}
									?>
								</li>
							<?php endif; ?>
							<li class="divider"></li>
							<li><a href="index.php?LOGIN=LOGOUT"><i class="icon-off"></i> Wyloguj</a></li>
						</ul>
					</li>
				</ul>
			</div><!-- /.nav-collapse -->
		</div>
	</div><!-- /navbar-inner -->
	<?php if ($userAcl->getPermsProcesId()) : ?>
		<div id="SE-menu-sub">
			<a class="btn btn-mini btn-danger" href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsAll" title="Wyłącz filtr uprawnień dla procesu <?php echo $userAcl->getPermsProcesId(); ?>">Wyłącz filtr uprawnień: <?php echo $userAcl->getPermsProcesId(); ?></a>
			<?php foreach ($outBtnsMenus as $kZasobID => $vName) : ?>
				<a class="btn btn-mini" href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $kZasobID; ?>" title="<?php echo $vName; ?>"><?php echo V::strShortUtf8($vName, 20); ?></a>
			<?php endforeach; ?>
			<?php foreach ($outUrls as $kZasobID => $vTitle) : ?>
				<a class="btn btn-mini" href="index.php?FUNCTION_INIT=URL_INIT&ZASOB_ID=<?php echo $kZasobID; ?>" target="_blank" title="<?php echo $vTitle; ?>"><?php echo V::strShortUtf8($vTitle, 20); ?></a>
			<?php endforeach; ?>
		</div>
	<?php else : ?>
		<div id="SE-menu-sub"></div>
<script>
(function ($, undefined) {
	var UserBookmarks = function() {
		var priv = {}; //private api
		var publ = {}; //public api

		priv.options = {};
		var defaults = {
			url: '',  //webservice url
			urlInit: true, // try to load services on init
			preloadData: null,
			menuid: '',
			debug: false
		};

		var _cont; // container holding table
		var _menu; // container holding stars
		var _stateEdit = false;

		/*
		 initialize the plugin.
		 */
		priv.init = function() {
			_cont = $(priv.options.id);
			_menu = $(priv.options.menuid);

			_menu.find('.bookmark-item-add').click(function(e){
				e.preventDefault();
				e.stopPropagation();
				var zasobid = jQuery(this).data('zasobid');
				priv.update('add_bookmark', zasobid);

				var item = $('#bookmark-item-' + zasobid);
				if (item) {
					item.addClass('has_bookmark');
				}
			});
			_menu.find('.bookmark-item-rem').click(function(e){
				e.preventDefault();
				e.stopPropagation();
				var zasobid = jQuery(this).data('zasobid');
				priv.update('remove_bookmark', zasobid);
			});

			if (priv.options.urlInit) priv.update();
			if (priv.options.preloadData) priv.setData(priv.options.preloadData);
		};

		priv.setData = function(data) {
			_cont.empty();
			$.each(data, function(ind, item){
				if ('type' in item) {
					var l = $('<a></a>');
					l.data('id', item.id);
					l.addClass('btn');
					l.addClass('btn-mini');
					var label = item.name, title = '';
					if ('class' in item) {
						l.addClass(item.class);
					}
					if (item.type == 'menu') {
						l.attr('href', 'index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=' + item.id);
						if ('label' in item && item.label.length > 0) {
							label = item.label;
							title = item.label + ' (' + item.name + ')';
						}
						else if ('opis' in item && item.opis.length > 0) {
							label = item.opis;
							title = item.opis + ' (' + item.name + ')';
						}
					} else if (item.type == 'url') {
						l.attr('href', 'index.php?FUNCTION_INIT=URL_INIT&ZASOB_ID=' + item.id);
						l.attr('target', '_blank');
					}
					if (label.length > 20) {
						var pos = label.indexOf(' - ');
						if (pos > 20 || pos < 5) {
							pos = 20;
							l.text(label.substring(0, pos) + ' ...');
						} else {
							l.text(label.substring(0, pos));
						}
					} else {
						l.text(label);
					}
					if (title == '') title = label;
					l.attr('title', title);
					l.appendTo(_cont);

					if (_stateEdit) {
						priv.addEditBtns(l);
					}
				}

				// stars visibility
				$('.bookmark-item-rem-' + item.id).show();
				$('.bookmark-item-add-' + item.id).hide();
			});

			if (data.length > 0) {
				var editBtn = $('<button class="btn btn-mini btn-inverse" style="float:right" title="Edit Bookmarks"><i class="icon-cog icon-white"></i></button>')
				editBtn.on('click', priv.edit);
				editBtn.prependTo(_cont);
			}
		};

		priv.update = function(task, zasobID, argsAdd) {
			task = task || '';
			zasobID = zasobID || '';
			argsAdd = argsAdd || '';
			$.ajax({
				url: priv.options.url + '&_task=' + task + '&_zasobID=' + zasobID + argsAdd,
				type: 'GET',
				dataType: 'json',
				contentType: "application/json; charset=utf-8",
				data: null,
				async: true,
				success: function (data) {
					$('.bookmark-item-rem').hide();
					$('.bookmark-item-add').show();

					priv.setData(data);
				},
				error: function (err) {
					console.log('Error');
					console.log(err);
				}
			});
		};

		priv.changed = function(e) {
			if (priv.options.debug) console.log(e.data);
			if (priv.options.debug) console.log('id(' + e.data.id + ') cls(' + e.data.cls + ')');
			priv.update('change_bookmark', e.data.id, '&btnCls=' + e.data.cls);
			return false;
		};

		priv.removed = function(e) {
			if (priv.options.debug) console.log(e.data);
			if (priv.options.debug) console.log('id(' + e.data.id + ')');
			priv.update('remove_bookmark', e.data.id);
			return false;
		};

		priv.addEditBtns = function(el) {
			var next, btn;
			el.wrap('<div></div>');
			next = $('<span><em> Change color:</em> </span>');
			$.each(['btn-default', 'btn-primary', 'btn-info', 'btn-success', 'btn-warning', 'btn-danger'], function(btnInd, btnClass){
				btn = $('<button class="btn btn-mini ' + btnClass + '"> &nbsp; </button>');
				btn.on('click', {id: el.data('id'), cls: btnClass}, priv.changed);
				btn.appendTo(next);
			});

			btn = $('<button class="btn btn-mini"> remove </button>');
			btn.on('click', {id: el.data('id')}, priv.removed);
			btn.appendTo(next);

			next.insertAfter(el);
		};

		priv.edit = function(e) {
			_stateEdit = !_stateEdit;
			var el;
			_cont.find('a').each(function(ind, n){
				if (priv.options.debug) console.log(n);
				el = $(n);
				if (_stateEdit) {
					priv.addEditBtns(el);
				} else {
					el.next().remove();
					el.unwrap();
				}
			});
		}

		publ.init = function(options) {
			if (priv.options.debug) console.log('UserBookmarks initialization...');
			//merge supplied options with defaults
			$.extend(priv.options, defaults, options);
			priv.init();
			return publ;
		};
		return publ;
	};

	$.fn.UserBookmarks = function(options) {
		options = options || {};
		return this.each(function() {
			options.id = this;
			$(this).data('UserBookmarks', new UserBookmarks().init(options));
		});
	};
})(jQuery);
</script>
		<script>
		jQuery(document).ready(function(){
			jQuery('#SE-menu-sub').UserBookmarks({
				url: 'index-ajax.php?_cls=UserBookmarks',
				urlInit: false,
				preloadData: <?php echo json_encode($bookmarksJson); ?>,
				menuid: '#SE-menu',
				debug: false
			});
		});
		</script>
	<?php endif; ?>
</div>
		<?php
	}

	/**
	 * Generates wyniki
	 */
	function _generate_wyniki_testow() {
		$this->_wynik_testu = array();// WYNIK_TESTU_PROCESU
		$this->_wynik_testu_unactual = array();
		$this_CRM_PROCES_USERA_WYKONANE_TESTY = $this->get_wykonane_testy();
		foreach ($this_CRM_PROCES_USERA_WYKONANE_TESTY as $v_test) {
			if (isset($this->_wynik_testu[$v_test->ID_PROCES_INIT][$v_test->TEST_TYPE])) {
				continue;// only first
			}

			$this->_wynik_testu[$v_test->ID_PROCES_INIT][$v_test->TEST_TYPE] = $v_test->OCENA;

			if (!empty($v_test->unactual)) {
				$x_test = new stdClass();
				$x_test->TEST_END = substr($v_test->TEST_END, 0, 10);
				$x_test->unactual = substr($v_test->unactual, 0, 10);
				$this->_wynik_testu_unactual[$v_test->ID_PROCES_INIT][$v_test->TEST_TYPE] = $x_test;
			}
		}
	}

	function get_ocena_testu($proces_id, $typ) {
		$ocena = $this->get_ocena_testu_value($proces_id, $typ);
		if (!$ocena) {
			return 'BRAK_TESTU';
		}
		else if ($ocena == -1) {
			return 'BRAK_PYTAN';
		}
		else if ($ocena == 3) {
			return 'IDEALNY';
		}
		else if ($ocena < 2) {
			return 'NIEDOSTATECZNY';
		}
		else if($ocena < 2.5) {
			return 'DOSTATECZNY';
		}
		else {
			return 'DOBRY';
		}
	}

	function get_ocena_testu_value($proces_id, $typ) {
		if (isset($this->_wynik_testu[$proces_id][$typ])) {
			return $this->_wynik_testu[$proces_id][$typ];
		}
		return null;
	}

	function isTestUnactual($proces_id, $typ) {
		if (isset($this->_wynik_testu_unactual[$proces_id][$typ])) {
			return $this->_wynik_testu_unactual[$proces_id][$typ];
		}
		return false;
	}

	function get_actual_tests_count($type = null) {
		$this_CRM_PROCES_USERA_WYKONANE_TESTY = $this->get_wykonane_testy();
		if ($type == 'TEORETYCZNY') {
			$testy_teoretyczne = 0;
			foreach ($this_CRM_PROCES_USERA_WYKONANE_TESTY as $int => $v_test) {
				if ($v_test->TEST_TYPE=='TEORETYCZNY') {
					if ($v_test->OCENA > 2.5) $testy_teoretyczne++;
				}
			}
			return $testy_teoretyczne;
		}
		else if ($type == 'PRAKTYCZNY') {
			$testy_praktyczne = 0;
			foreach ($this_CRM_PROCES_USERA_WYKONANE_TESTY as $int => $v_test) {
				if ($v_test->TEST_TYPE=='PRAKTYCZNY') {
					if ($v_test->OCENA > 2.5) $testy_praktyczne++;
				}
			}
			return $testy_praktyczne;
		}
		else if ($type ==  null) {
			return count($this_CRM_PROCES_USERA_WYKONANE_TESTY);
		}
		return 0;
	}

	function wylacz_filtr_uprawnien_dla_procesu() {// TODO: RMME => _action=setPermsAll
		unset($this->MENU_SELECT_PROCES_DATA['uruchom_filtr_uprawnien_dla_procesu']);// usun tryb jednego procesu
		$this->set_current_menu_data();// zapisz do sesji
		$this->set_perms_for_process();// domyslnie pusty włącza
	}

	function uruchom_filtr_uprawnien_dla_procesu() {// TODO: RMME => _action=setPermsByProces
		$proces_to_filter = V::get('ID_PROCES', '', $_REQUEST);
		$map = $this->_acl->getUsedProcesMap();
		if (!in_array($proces_to_filter, $map)) {// TODO: chyba array_key_exists ?
			$this->setError(" Nie ma takiego procesu dla usera aby ustawic dla niego filtry");
		}
		$this->ifError();// ? // TODO: RMME

		//szukam tabeli do ustalenia permow
		$this->unset_all_perms();

		$this->MENU_SELECT_PROCES_DATA['uruchom_filtr_uprawnien_dla_procesu'] = $proces_to_filter;
		$this->set_current_menu_data();
		$this->set_perms_for_process($proces_to_filter);
		$this->set_current_menu_data();
		//$this->set_current_menu('show_menu_with_process');
		//$this->show_menu_with_process();
	}

	function unset_all_perms() {
		$dbg_czysc_permy = true;// @from USERS_FIELDS_PROFILE_INIT()
		foreach ($_SESSION as $ses_col_name => $col_vars) {
			if (!is_array($col_vars) || empty($col_vars)) continue;
			if ('_COLUMN' != substr($ses_col_name, -1 * strlen('_COLUMN'))) {
				continue;
			}
			if (empty($col_vars['PERMEDIT'])) continue;
			if ($dbg_czysc_permy) {
				foreach ($col_vars['PERMEDIT'] as $col_perm_ind => $col_perm_value) {
					if ($col_perm_ind != 'ID') {
						$_SESSION[$ses_col_name]['PERMEDIT'][$col_perm_ind] = "";
					}
				}
			}
		}

		if (isset($_SESSION['MENU_SELECT_PROCES_DATA']['MENU_COLUMN'])) {
			foreach ($_SESSION['MENU_SELECT_PROCES_DATA']['MENU_COLUMN'] as $zasob => $val) {
				unset($this->MENU_SELECT_PROCES_DATA['MENU_COLUMN'][$zasob]);
				unset($_SESSION['MENU_SELECT_PROCES_DATA']['MENU_COLUMN'][$zasob]);
			}
		}
	}

	function set_perms_for_process($proces_to_filter = null) {// => setPermsByProcesAction
		if ($proces_to_filter) {
			$map = $this->_acl->getUsedProcesMap();
			if (array_key_exists($proces_to_filter, $map)) {
				$CRM_PROCES_USERA_UZYTY = $map[$proces_to_filter];
			} else {
				$CRM_PROCES_USERA_UZYTY = array();
			}
		}
		else {
			$CRM_PROCES_USERA_UZYTY = $this->_acl->getUsedProcesIds();
		}

		if (!empty($CRM_PROCES_USERA_UZYTY)) {
			return;
		}
		// ! @2013-02-11 zerzniete z USERS_FIELDS_PROFILE_INIT !

		$CRM_WSKAZNIK_PROCES_WSKAZNIK_TREE = array();
		$CRM_TREE_WSKAZNIK_NARZEDZIE = array();
		$TREE_CRM_WSKAZNIK_CONF = array();
		$TREE_CRM_WSKAZNIK_SORT_PRIO = array();

		$db = DB::getDB();
		//kopiuje tabele ze wskaznikow
		$sql = "select t1.`ID_PROCES`
				, t1.`ID_ZASOB`
				, replace(t2.`FORM_TREAT`, ',', '') as FORM_TREAT 
				, t3.`DESC` as ZASOB_DESC
				, t3.`TYPE`
				, t4.`DESC` as PARENT_ZASOB_DESC
				, t4.`TYPE` as PARENT_TYPE
				, t3.`SORT_PRIO` as z__SORT_PRIO
				, t3.`OPIS` as ZASOB_OPIS , t1.`ID` as ID_WSKAZNIK
			from `CRM_WSKAZNIK` as t1
				left join `CRM_PRZYPADEK` as t2 on (t1.ID_PRZYPADEK=t2.ID)
				left join `CRM_LISTA_ZASOBOW` as t3 on (t3.ID=t1.ID_ZASOB)
				left join `CRM_LISTA_ZASOBOW` as t4 on (t4.ID=t3.PARENT_ID)
			where
				(
					( t3.`TYPE`='KOMORKA' and t4.`TYPE`='TABELA' )
					or (t3.`TYPE`='NARZEDZIE') or (t3.`TYPE`='URL')
				)
				and t1.`A_STATUS` in('NORMAL', 'WAITING')
				and t1.`ID_PROCES` in(" . implode(",", $CRM_PROCES_USERA_UZYTY) . ")
		";
		$res = $db->query($sql);
		if (!$res) {
			return;
		}
		while ($r = $db->fetch($res)) {
			if ($r->TYPE == 'NARZEDZIE') {
				if (isset($CRM_TREE_WSKAZNIK_NARZEDZIE[$r->ID_ZASOB])) {
					$CRM_TREE_WSKAZNIK_NARZEDZIE[$r->ID_ZASOB] .= $r->FORM_TREAT;
				}
				else {
					$CRM_TREE_WSKAZNIK_NARZEDZIE[$r->ID_ZASOB] = $r->FORM_TREAT;
				}
				$CRM_WSKAZNIK_PROCES_WSKAZNIK_TREE[$r->ID_PROCES][] = $r->ID_WSKAZNIK;//ustawiam wskaznik od procesu, jak user wybierze proces do roboty, to ja poznam co moze mu sie pojawic
			}
			else if ($r->TYPE == 'URL') {
				$CRM_WSKAZNIK_PROCES_WSKAZNIK_TREE[$r->ID_PROCES][] = $r->ID_WSKAZNIK;//ustawiam wskaznik od procesu, jak user wybierze proces do roboty, to ja poznam co moze mu sie pojawic
				$_SESSION['MENU_SELECT_PROCES_DATA']['MENU_COLUMN'][$r->ID_ZASOB]['TYPE'] = $r->TYPE;
				$_SESSION['MENU_SELECT_PROCES_DATA']['MENU_COLUMN'][$r->ID_ZASOB]['DESC'] = $r->ZASOB_DESC;
				$_SESSION['MENU_SELECT_PROCES_DATA']['MENU_COLUMN'][$r->ID_ZASOB]['OPIS'] = $r->ZASOB_OPIS;
			}
			else {
				if ($r->PARENT_TYPE == 'TABELA') {
					$CRM_WSKAZNIK_PROCES_WSKAZNIK_TREE[$r->ID_PROCES][] = $r->ID_WSKAZNIK;//ustawiam wskaznik od procesu, jak user wybierze proces do roboty, to ja poznam co moze mu sie pojawic
					if (isset($r->FORM_TREAT)) {
						if (isset($TREE_CRM_WSKAZNIK_CONF[$r->PARENT_ZASOB_DESC][$r->ZASOB_DESC])) {
							$TREE_CRM_WSKAZNIK_CONF[$r->PARENT_ZASOB_DESC][$r->ZASOB_DESC] .= $r->FORM_TREAT;
						}
						else {
							$TREE_CRM_WSKAZNIK_CONF[$r->PARENT_ZASOB_DESC][$r->ZASOB_DESC] = $r->FORM_TREAT;
						}
						// echo "<br. . . Dodaje dla:".$r->PARENT_ZASOB_DESC." ".$r->ZASOB_DESC." = ".$r->FORM_TREAT;
					}
					$TREE_CRM_WSKAZNIK_SORT_PRIO[$r->PARENT_ZASOB_DESC][$r->ZASOB_DESC] = $r->z__SORT_PRIO;

					//@2012-10-10 by SQIX : dodajemy opus kolumny z opisu zasobow
					if ($r->ZASOB_OPIS) {
						$_SESSION[$r->PARENT_ZASOB_DESC."_COLUMN"]['DESC_TO_LANG'][$r->ZASOB_DESC] = $r->ZASOB_OPIS;
					}
					else if (isset($_SESSION[$r->PARENT_ZASOB_DESC."_COLUMN"]['DESC_TO_LANG'][$r->ZASOB_DESC])
						&& strlen($_SESSION[$r->PARENT_ZASOB_DESC."_COLUMN"]['DESC_TO_LANG'][$r->ZASOB_DESC]) > 1
					) {
						echo "<BR> DODAJ opis dla zasobu ".$r->ID_ZASOB." w postaci <pre>".$_SESSION[$r->PARENT_ZASOB_DESC."_COLUMN"]['DESC_TO_LANG'][$r->ZASOB_DESC]."</pre>";
					}
				}
			}
		}

		// ! nizej uruchamiamy permy na podstawie wynikow co umozliwialy procesy
		foreach ($TREE_CRM_WSKAZNIK_CONF as $ses_column_name => $field_perms_arr) {
			foreach ($field_perms_arr as $k_name => $v_perm) {
				$v_perm = str_split($v_perm);
				$v_perm = array_unique($v_perm);
				$v_perm = implode("", $v_perm);

				//if(isset($_SESSION[$ses_column_name."_COLUMN"]['PERMEDIT'][$k_name]))
				$_SESSION[$ses_column_name."_COLUMN"]['PERMEDIT'][$k_name] = $v_perm;
				//else $_SESSION[$ses_column_name."_COLUMN"]['PERMEDIT'][$k_name] = $v_perm."RWX"; //dokladamy permy do istniejacych!!! @2012-10-21- najlepsze na okres przejsciowy do generowania procesow!
				$debug_perms[]="_SESSION['".$ses_column_name."_COLUMN']['PERMEDIT'][".$k_name."]']=".$v_perm;

				//jezeli jest w kolumnie ID==W , to znaczy, ze mozna dodawac nowy rekord
				if ($k_name == 'ID' && strstr($v_perm, 'W')) {
					$_SESSION[$ses_column_name."_COLUMN"]['FUNCPERMEDIT']['NEW_RECORD'] = "RWXC";
					$_SESSION[$ses_column_name."_COLUMN"]['FUNCPERMEDIT']['TABLE_INSERTDB'] = "RWXC";
				}

				//jezeli jest funkcja powiazana to uprawnienia dostajemy takie same jak z komorki do tej funkcji!
				if (isset($_SESSION[$ses_column_name."_COLUMN"]['TYPESPECIAL'][$k_name])) {
					$debug_perms[]="_SESSION['".$ses_column_name."_COLUMN']['FUNCPERMEDIT']['".$_SESSION[$ses_column_name."_COLUMN"]['TYPESPECIAL'][$k_name]."']=".$v_perm;
					$_SESSION[$ses_column_name."_COLUMN"]['FUNCPERMEDIT'][$_SESSION[$ses_column_name."_COLUMN"]['TYPESPECIAL'][$k_name]] = $v_perm;
				}
			}

			{// sort DESC by ZASOB.SORT_PRIO
				$desc_to_sort = array();
				if (!isset($_SESSION[$ses_column_name."_COLUMN"]['DESC'])) {
					//echo "<br><font color=red>L2375 Brak definicji w systemie opisanej procesami tabeli <b>".$ses_column_name."</b></font>";
				}
				else 
				foreach ($_SESSION[$ses_column_name."_COLUMN"]['DESC'] as $k_ind => $v_val) {
					$desc_to_sort[$v_val] = $k_ind;
				}

				$TREE_CRM_WSKAZNIK_SORT_PRIO[$ses_column_name];
				asort($TREE_CRM_WSKAZNIK_SORT_PRIO[$ses_column_name]);

				$new_desc = array();
				foreach ($TREE_CRM_WSKAZNIK_SORT_PRIO[$ses_column_name] as $k_name => $v_sort_prio) {
					if (!isset($desc_to_sort[$k_name])) {
						//echo "<br><font color=red>Brak spojnosci definicji dla kolumny : ".$ses_column_name."[<b>".$k_name."</b>] </font>";
					}
					else {
						$new_desc[$desc_to_sort[$k_name]] = $k_name;
					}
				}

				// add columns
				foreach ($desc_to_sort as $k_name => $v_ind) {
					$new_desc[$v_ind] = $k_name;
				}

				$_SESSION[$ses_column_name."_COLUMN"]['DESC'] = $new_desc;
			}// sort DESC by ZASOB.SORT_PRIO
		}
	}

	/**
	 * URL: _action=setPermsAll
	 */
	function setPermsAllAction() {
		$userAcl = User::getAcl();

		$userAcl->fetchAllPerms(true);

		$this->menuAction();
	}

	/**
	 * URL: _action=setPermsByProces
	 */
	function setPermsByProcesAction() {
		$procesID = V::get('id_proces', 0, $_GET, 'int');
		if ($procesID <= 0) {
			echo '<div class="alert alert-error">' . "Brak ID Procesu" . '</div>';
			return;
		}

		$userAcl = User::getAcl();
		if ($userAcl->getPermsProcesId() == $procesID) {
			$this->menuAction();
			echo '<div class="alert alert-info">' . "Uprawnienia dla ID Procesu {$procesID} już zostały ustawione" . '</div>';
			return;
		}

		$db = DB::getDB();
		$proces = $db->get_by_id('CRM_PROCES', $procesID);

		if ($proces->TYPE != 'PROCES_INIT') {
			$this->menuAction();
			echo '<div class="alert alert-error">' . "Proces nie jest typu PROCES_INIT" . '</div>';
			return;
		}

		$userAcl = User::getAcl();
		$procesStepList = $userAcl->getUsedProcesIds($procesID);
		if (empty($procesStepList)) {
			$this->menuAction();
			echo '<div class="alert alert-error">' . "Nie ma takiego procesu dla usera aby ustawic dla niego filtry" . '</div>';
			return;
		}

		$userAcl->fetchProcesPerms($procesID, true);

		$this->menuAction();
	}

	function show_url_menu() {// TODO: raneme; show all tables and actions by selected proces if in proces perm
		if (isset($_SESSION['MENU_SELECT_PROCES_DATA']['MENU_COLUMN'])) {
?>
<div class="btn-group">
	<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
		Narzędzia <span class="caret"></span>
	</a>
	<ul class="dropdown-menu">
		<?php foreach ($_SESSION['MENU_SELECT_PROCES_DATA']['MENU_COLUMN'] as $id_zasob => $value_zasob) : ?>
			<?php if ($value_zasob['TYPE'] == 'URL') : ?>
				<li>
					<a href="<?php echo $value_zasob['DESC']; ?>" target="_blank">
						<?php echo '' . $value_zasob['OPIS'] . ' <em>(' . $value_zasob['DESC'] . ')</em>'; ?>
					</a>
				</li>
			<?php endif; ?>
		<?php endforeach; ?>
	</ul>
</div>
<?php
		}
	}

	function move_test_from_kandydat_to_pracownik($id_kanydata, $id_pracownika) {
		//4673->4680
		//$sql='update CRM_TESTY set A_RECORD_CREATE_AUTHOR='smagielm' where A_RECORD_CREATE_AUTHOR='Kandydat.4673';
		//$sql='update CRM_TESTY set A_RECORD_UPDATE_AUTHOR='smagielm' where A_RECORD_UPDATE_AUTHOR='Kandydat.4673';
		//$sql="update CRM_TESTY set ID_TESTER='4680' where ID_TESTER='4673'";
	}

}
