<?php


function task_USER() {
	User_procesy5_check_access();

	if (!User::logged()) {
		return;
	}
	echo'<p>';
		echo "Jesteś zalogowany jako: <b>".User::get('ADM_NAME')."</b> (".'<code>'.User::getName().'</code>'.")";
		echo " " . App::link("Ocena pracownika", array('task'=>"USER_OCENA"));
	echo'</p>';

	// Stanowiska powiazane z userem
	$stanowiska = User::getGroups();
	DBG::log($stanowiska, 'array', '$stanowiska');
	?>
	<?php if (empty($stanowiska)) : ?>
		<p class="red">Nie jestes przypisany do żadnego stanowiska - pilnie skontaktuj się z przełożonym!</p>
		<?php if (User::hasAccess('user_add_group')) : ?>
			<a class="btn btn-xs btn-primary" href="index.php?_route=Users&_task=userGroups&usrLogin=<?php echo User::getLogin(); ?>">przydziel stanowisko</a>
		<?php endif; ?>
	<?php else : ?>
		<div class="">
		<p style="margin-bottom:0;">Stanowisko:
			<?php if (count($stanowiska) > 0) : ?>
				<?php echo App::link("obowiązki", array('task'=>'CRM_WYSWIETL_OBOWIAZKI', 'z'=>array_keys($stanowiska))); ?>
			<?php endif; ?>
			<?php if (User::hasAccess('user_add_group')) : ?>
				<a class="btn btn-xs btn-primary" href="index.php?_route=Users&_task=userGroups&usrLogin=<?php echo User::getLogin(); ?>">przydziel stanowisko</a>
			<?php endif; ?>
		</p>
		<ul style="margin-top:0;">
		<?php foreach ($stanowiska as $k_id => $v_zasob) : ?>
			<li>[<?php echo App::link($k_id, array('task'=>'CRM_WYSWIETL_OBOWIAZKI', 'z'=>array($k_id))); ?>] <?php echo $v_zasob->DESC; ?></li>
		<?php endforeach; ?>
		</ul>
		</div>
	<?php endif; ?>

	<?php
	$db = DB::getDB();
	Lib::loadClass('ProcesLogDao');
	Lib::loadClass('ProcesLogSelectView');

	$procesLogDao = new ProcesLogDao($db);
	$cnt = new ProcesLogSelectView();

	$proces_log_list_count = $procesLogDao->get_user_log_list_count(User::getID(), User::getGroupsIds());
	$cnt->set('title', "Moje procesy" . (($proces_log_list_count)? " (" . $proces_log_list_count . ")" : ''));
	$cnt->set('procesLogDao', $procesLogDao);

	$proces_log_list = $procesLogDao->get_user_log_list(User::getID(), User::getGroupsIds());
	$cnt->set('proces_log_list_count', $proces_log_list_count);
	$cnt->set('proces_log_list', $proces_log_list);
	DEBUG_S(4, "All process log list", $proces_log_list, __FILE__, __FUNCTION__, __LINE__);

	echo $cnt->render();
}


function task_USERS() {
	User_procesy5_check_access();

	if (!User::logged()) {
		return;
	}

	// login session info:
	//$_SESSION['ADM_PASSWD']=$ADM_PASSWD;
	//$_SESSION['AUTHORIZE_USER']="$h->ADM_ACCOUNT";
	//$_SESSION['ADM_ACCOUNT']="$h->ADM_ACCOUNT";
	//$_SESSION['ADM_AREA']="$h->ADM_AREA";
	//$_SESSION['ADM_NAME']="$h->ADM_NAME";
	//$_SESSION['ADM_TECH_WORKER']="$h->ADM_TECH_WORKER";
	//$_SESSION['ADM_COMPANY']="$h->ADM_COMPANY";
	//$_SESSION['ADM_ADMIN_LEVEL']="$h->ADM_ADMIN_LEVEL";
	//$_SESSION['ADM_PHONE']="$h->ADM_PHONE";
	//$_SESSION['ADM_ADMIN_EXPIRE']="$h->ADM_ADMIN_EXPIRE";
	//$_SESSION['ADM_ADMIN_DESC']="$h->ADM_ADMIN_DESC";

	Lib::loadClass('UsersHelper');

	// TODO: add filters

	$items = array();
	$params = array();// sql params

	$page_nav = new stdClass();
	$page_nav->total = 0;
	$page_nav->page_total = 0;
	$page_nav->base_link = "?task=USERS";// TODO: not used!
	$page_nav->page_limit = 20;
	$page_nav->page_nr = V::get('_p', 0, $_REQUEST, 'int');
	if ($page_nav->page_nr > 0) {
		$page_nav->base_link .= "&_p=" . $page_nav->page_nr;
	}
	$params['p'] = V::get('_p', 0, $_REQUEST, 'int');
	$params['group'] = V::get('_group', 0, $_REQUEST, 'int');
	if ($params['group'] > 0) {
		$page_nav->base_link .= "&_group=" . $params['group'];
	}

	$page_nav->total = UsersHelper::get_users_total( $params );
	$page_nav->last_page_nr = floor($page_nav->total / $page_nav->page_limit);

	$items = UsersHelper::get_users_list($params, $page_nav->page_limit, $page_nav->page_nr * $page_nav->page_limit, 'ID', 'DESC');
	$page_nav->page_total = count($items);

	UsersHelper::add_groups_to_user_list( $items );

	//if ($page_nav->total > 0) {
		task_USERS_show_items( $params, $page_nav, $items );
	//}
}


function task_USERS_show_items( $params, &$page_nav, &$items ) {
	User_procesy5_check_access();

	$page_nav->links = array();
	$base_params = array('task'=>"USERS");
	if (!empty($params['group'])) $base_params['_group'] = $params['group'];

	$page_nav->links[] = App::link("|&lt;&lt;", $base_params, array('title'=>"Pierwsza strona"));
	if ($page_nav->page_nr > 0) {
		$page_nav->links[] = App::link("&lt;&lt;", V::extend($base_params, array('_p'=>($page_nav->page_nr - 1))), array('title'=>"Poprzednia strona (-" . $page_nav->page_limit . ")"));
	} else {
		$page_nav->links[] = " &lt;&lt; ";
	}
	$page_nav->links[] = '<span>'.($page_nav->page_nr * $page_nav->page_limit).'</span>';
	$page_nav->links[] = '<span title="'."Znaleziono ".$page_nav->total." rekordów".'">'."(".$page_nav->total.") ".'</span>';
	if ($page_nav->last_page_nr > $page_nav->page_nr) {
		$page_nav->links[] = App::link("&gt;&gt;", V::extend($base_params, array('_p'=>($page_nav->page_nr + 1))), array('title'=>"Nastepna strona (+" . $page_nav->page_limit . ")"));
	} else {
		$page_nav->links[] = " &gt;&gt; ";
	}
	$page_nav->links[] = App::link("&gt;&gt;|", V::extend($base_params, array('_p'=>$page_nav->last_page_nr)), array('title'=>"Ostatnia strona"));

	echo'<div class="tbl-page-nav">';
	echo implode(" ", $page_nav->links);
	echo'</div>';

	$tbl_filters_selected = false;
	if ($params['group'] > 0) {
		$tbl_filters_selected = true;
	}

	echo '<form action="" method="get">';
	echo '<input type="hidden" name="' . "task" . '" value="' . App::get_task() . '" />';
	echo '<input type="hidden" name="' . "_p" . '" value="' . $params['p'] . '" />';
	echo'<table class="tbl-view" border="1" cellspacing="0" cellpaddin="0">';
	echo'<thead>';
		echo'<tr>';
			echo'<th>'."&nbsp;".'</th>';
			echo'<th>'."ID".'</th>';
			echo'<th>'."login".'</th>';
			echo'<th>'."imie i nazwisko".'</th>';
			echo'<th>'."telefon".'</th>';
			echo'<th>'."email".'</th>';
			echo'<th>'."stanowisko".'</th>';
			echo'<th>'."status".'</th>';
			echo'<th>'."lokalizacja".'</th>';
		echo'</tr>';
		echo'<tr class="find">';
			echo'<td>';
				echo '<input type="image" value="Szukaj" src="icon/search.png" title="Szukaj">';
				echo App::link("x", array('task'=>App::get_task(), '_p'=>$page_nav->page_nr), array('title'=>"Wyczyść filtr", 'ico'=>'del.png'));
			echo '</td>';
			echo'<td>'."".'</td>';
			echo'<td>'."".'</td>';
			echo'<td>'."".'</td>';
			echo'<td>'."".'</td>';
			echo'<td>'."".'</td>';
			$cls = ($params['group'] > 0)? ' class="selected"' : '';
			echo'<td'.$cls.'>';
				$sel_group_options = array();
				$groups = UsersHelper::get_group_list();
				foreach ($groups as $k_group_id => $v_group) {
					$sel_group_options [$v_group->ID] = $v_group->DESC;
				}
				echo'<select name="'."_group".'" onchange="this.form.submit();">';
					echo'<option value="">' . "&nbsp;" . '</option>';
					foreach ($sel_group_options as $k_value => $v_label) {
						$sel = ($k_value == $params['group'])? ' selected="selected"' : '';
						echo'<option value="' . $k_value . '"'.$sel.'>' . $v_label . " (" . $k_value . ")" . '</option>';
					}
				echo'</select>';
			echo '</td>';
			echo'<td>'."".'</td>';
		echo'</tr>';
	echo'</thead>';
	echo'<tbody>';
	if (empty($items)) {
		echo'<td colspan="7">';
			echo '<span style="color:red">' . "Brak danych" . '</span>';
			if ($tbl_filters_selected) {
				echo ' - wyczyść filtry ' . App::link("x", array('task'=>App::get_task(), '_p'=>$page_nav->page_nr), array('title'=>"Wyczyść filtr", 'ico'=>'del.png'));
			} else if ($page_nav->last_page_nr > 0 && $page_nav->page_nr > 0) {
				echo ' - wróć do ' . App::link("pierwszej strony", $base_params, array('title'=>"pierwsza strona"));
			} else
		echo '</td>';
	}
	else {
		$t = 0;
		foreach ($items as $k_id => $r) {
			if(TableAcl::canReadRecord($r)) { //@2014-04-24 TODO jest blad przewijania ekranow, ale musialem zabezpieczyc pokazywanie! z reszta ekran przechodzi na domyslny interfejs soon?
			echo'<tr class="row-'.($t = 1 - $t).'">';
				echo'<td>';
					if (User::hasAccess('procesy_admin')) {
						echo App::link("E", array('task'=>"USER_EDIT", '_user_id'=>$k_id, '_p'=>$page_nav->page_nr), array('ico'=>'edit.png', 'title'=>"Edit"));
						echo " ";
					}
					echo App::link("Ocena", array('task'=>"USER_OCENA", '_user_id'=>$k_id), array('ico'=>'print', 'title'=>"Ocena pracownika"));
				echo'</td>';
				echo'<td>';
					echo $k_id;
				echo'</td>';
				echo'<td>';
					echo $r->ADM_ACCOUNT;
				echo'</td>';
				echo'<td>';
					echo $r->ADM_NAME;
				echo'</td>';
				echo'<td>';
					echo $r->ADM_PHONE;
				echo'</td>';
				echo'<td>';
					//echo $r->ADM_EMAIL;
					$emails = trim($r->EMAIL);

					if (!empty($emails)) {

						$emails_arr = array();
						$emails_tmp = explode(',', $emails);
						foreach ($emails_tmp as $v) {
							$v = trim($v);
							if (!empty($v)) {
								//$emails_arr[] = '<a href="' . "mailto:" . $v . '">' . $v . '</a>';
								$emails_arr[] = $v;
							}
						}
						if (!empty($emails_arr)) {
							echo '<span title="' . implode(', '."\n", $emails_arr). '">';
								echo reset($emails_arr);
								if (count($emails_arr) > 1) echo ' ...';
							echo '</span>';
						}
					}
				echo'</td>';
				echo'<td>';
					if (!empty($r->groups)) {
						foreach ($r->groups as $k_zasob_id => $v_zasob_desc) {
							echo ' <b style="color:green" title="' . htmlspecialchars($v_zasob_desc) . '">' . $k_zasob_id . '</b>';
						}
					} else {
						echo '<b style="color:red" title="' . "Brak przypisanego stanowiska!" . '">' . "Brak!" . '</b>';
					}
					echo " <em>(" . $r->ADM_ADMIN_DESC . ")</em>";
				echo'</td>';
				echo'<td>';
					echo $r->A_STATUS;
				echo'</td>';
				echo'<td>';
					echo $r->T_TELBOX_NEIGHBOUR_IN_ID_NAME;
				echo'</td>';
			echo'</tr>';
		    }
		}
	}
	echo'</tbody>';
	echo'</table>';
	echo '</form>';
}


function task_USER_EDIT() {
	User_procesy5_check_access();

	if (!User::hasAccess('procesy_admin')) {
		echo'<p>'."Brak dostepu!".'</p>';
		return;
	}

	$user_id = V::get('_user_id', 0, $_REQUEST, 'int');

	Lib::loadClass('UsersHelper');
	$user_data = UsersHelper::get_user_by_id( $user_id );
	if (!$user_data) {
		echo'<p>'."User nie istnieje.".'</p>';
		return;
	}

	$groups = UsersHelper::get_group_list();
	$get_localisation_list = UsersHelper::get_localisation_list();
	$user_data->groups = UsersHelper::get_group_by_user( $user_data->ID, array('T_TELBOX_NAME'=>1) );

	$user_cols = array();
	$user_cols['ID'] = "ID";
	$user_cols['A_STATUS'] = "status";
	$user_cols['ADM_ACCOUNT'] = "login";
	$user_cols['ADM_ADMIN_LEVEL'] = "admin level";
	$user_cols['ADM_NAME'] = "imie i nazwisko";
	$user_cols['ADM_PHONE'] = "numer telefonu";
	$user_cols['EMAIL'] = "adres email";
	$user_cols['ADM_PESEL'] = "pesel";
	$user_cols['ADM_NIP'] = "nip";
	$user_cols['ADM_ADMIN_DESC'] = "stanowisko";

	$user_types = array();
	$user_types['ID'] = "";
	$user_types['A_STATUS'] = "enum('WAITING','NORMAL','MONITOR','WARNING','OFF_SOFT','OFF_HARD','DELETED')";
	$user_types['ADM_ACCOUNT'] = "";
	$user_types['ADM_ADMIN_LEVEL'] = "enum('0', '1', '2', '3', '4', '5', '6')";
	$user_types['ADM_NAME'] = "varchar(100)";
	$user_types['ADM_PHONE'] = "varchar(100)";
	$user_types['EMAIL'] = "varchar(100)";
	$user_types['ADM_PESEL'] = "varchar(30)";
	$user_types['ADM_NIP'] = "varchar(100)";
	$user_types['ADM_ADMIN_DESC'] = "varchar(100)";

	$values = array();
	foreach (get_object_vars($user_data) as $k_field => $v_value) {
		$values[$k_field] = V::get($k_field, $v_value, $_POST);
	}

	if (1 == V::get('save', 0, $_POST, 'int')) {
		// TODO: use DB::UPDATE_OBJ
		$sql_arr = array();
		$sql_arr_hist = array();
		foreach (get_object_vars($user_data) as $k_field => $v_value) {
			if ($values[$k_field] != $v_value) {
				$sql_field = $k_field;
//				if ($k_field == 'EMAIL') $sql_field = "EMAIL";
				$sql_arr[] = "`".$sql_field."`='".$values[$k_field]."'";
				$sql_arr_hist["`".$sql_field."`"] = "'".$values[$k_field]."'";
			}
		}
		if (!empty($sql_arr)) {
			$sql = "update `ADMIN_USERS` set ".implode(",", $sql_arr)." where `ID`='".$user_data->ID."' limit 1 ";
			DB::query( $sql );
			$affected = DB::affected_rows();
			if ($affected) {
				echo'<p class="green">'."Zmieniono rekord".'</p>';
				// add HIST data
				$sql_arr_hist["`ID_USERS2`"] = "'".$user_data->ID."'";
				$sql_hist = "insert into `ADMIN_USERS_HIST` (".implode(",", array_keys($sql_arr_hist)).") values(".implode(",", array_values($sql_arr_hist)).");";
				DB::query( $sql_hist );
				$insert_id = DB::insert_id();
				if ($insert_id) {
					echo'<p class="green">'."Dodano dane historyczne".'</p>';
				} else {
					echo'<p class="red">'."Nie wprowadzono danych HIST".'</p>';
				}
			} else {
				echo'<p class="red">'."Nic nie zmieniono".'</p>';
			}
		} else {
			echo'<p class="red">'."Nie ma nic do zmiany".'</p>';
		}

		// add stanowiska
		if ('' != ($add_group = V::get('add_group', '', $_POST))) {
			$add_localisation = V::get('add_localisation', '', $_POST);
			$ret_id = UsersHelper::add_group( $user_data->ID, $add_group, $add_localisation );
			if ($ret_id <= 0) {
				echo'<p class="red">' . "Blad podczas dodawania stanowiska" . '</p>';
			} else {
				echo'<p class="green">' . "Dodano stanowisko" . '</p>';
				$user_data->groups[$add_group] = $groups[$add_group];
				$user_data->groups[$add_group]->T_TELBOX_NAME = $get_localisation_list[$add_localisation]->T_TELBOX_NAME;// przypisanie do swiezo dodanego rekordu nazwy dodanej lokalizacji
			}
		}

		// remove stanowiska
		if ('' != ($del_group = V::get('del_group', '', $_POST))) {
			$ret_code = UsersHelper::remove_group( $user_data->ID, $del_group );
			if ($ret_code <= 0) {
				echo'<p class="red">' . "Blad podczas usuwania stanowiska ($ret_code)" . '</p>';
			} else {
				echo'<p class="green">' . "Usunieto stanowisko" . '</p>';
				unset($user_data->groups[$del_group]);
			}
		}
	}

	echo'<h1>';
		echo App::link("Users", array('task'=>"USERS", '_p'=>V::get('_p', 0, $_GET, 'int')));
		echo ' &raquo; ' . App::link("Edycja użytkownika [".$user_data->ID."]", array('task'=>'USER_EDIT', '_user_id'=>$user_data->ID));
	echo'</h1>';

	echo'<div class="box box-blue">';
	echo'<form action="" method="post">';
	echo'<input type="hidden" name="'."save".'" value="'."1".'" />';
	foreach ($user_cols as $k_field => $v_label) {
		echo '<label style="color:#666;" for="'.$k_field.'">' . $v_label . '</label>' . ": ";
		if ($user_types[$k_field] == '') {
			echo $user_data->$k_field;
		} else {
			echo App::field($k_field, $user_types[$k_field], $values[$k_field]);
		}
		echo'<br />';
	}

		echo'<div style="padding:0 0 0 30px;">';
		echo '<input type="hidden" name="' . "del_group" . '" value="" />';
		if (empty($user_data->groups)) {
			echo'<b class="red">'."Brak przypisanego stanowiska!".'</b><br />';
		}
		else {
			foreach ($user_data->groups as $k_group_id => $v_group) {
				echo "[" . $v_group->ID . "] " . '<span title="'.$v_group->OPIS.'">' . $v_group->DESC . '</span>' . " [" . $v_group->T_TELBOX_NAME  . "] ";
				$js = "if(confirm('Czy jestes pewien ze chcesz usunac stanowisko: ".$v_group->DESC."?')){ this.form.del_group.value='".$v_group->ID."'; this.form.submit(); } return false;";
				echo ' <input type="image" src="' . "stuff/i/del.png". '" alt="' . "Usuń stanowisko" . '" title="' . "Usuń stanowisko" . '" onclick="'.$js.'" />';
				echo'<br />';
			}
		}
		$add_group_options = array();
		foreach ($groups as $k_group_id => $v_group) {
			$add_group_options [$v_group->ID] = $v_group->DESC;
		}

		$add_get_localisation_list = array();
		foreach ($get_localisation_list as $k_group_id => $v_group) {
			$add_get_localisation_list [$v_group->ID] = $v_group->DESC." ".$v_group->T_TELBOX_NAME;
		}
		echo'<img src="icon/add.gif" title="Dodaj">';
		echo " Dodaj nowe stanowisko: ";
		echo'<select name="'."add_group".'">';
			echo'<option value="">' . "&nbsp;" . '</option>';
			foreach ($add_group_options as $k_value => $v_label) {
				echo'<option value="' . $k_value . '">' . $v_label . " (" . $k_value . ")" . '</option>';
			}
		echo'</select>';

		echo " Ustal lokalizacje:  ";
		echo'<select name="'."add_localisation".'">';
			echo'<option value="">' . "&nbsp;" . '</option>';
			foreach ($add_get_localisation_list as $k_value => $v_label) {
				echo'<option value="' . $k_value . '">' . $v_label . " (" . $k_value . ")" . '</option>';
			}
		echo'</select>';

		echo'</div>';
		echo'<input type="submit" value="'."zapisz".'" />';
	echo'</form>';
	echo'</div>';// .box-blue
}


function fun_USER_OCENA_EXPORT() {
	$_user_id = V::get('_user_id', '', $_GET, 'int');

	$user = new stdClass();
	$user->ID = User::getID();
	$user->ADM_NAME = User::get('ADM_NAME');

	Lib::loadClass('UsersHelper');
	if ($_user_id > 0) {
		$user = UsersHelper::get_user_by_id($_user_id);
		if (!$user) {
			echo '<p class="red">' . "Brak użytkownika o ID = " . $_user_id . '</p>';
			return;
		}
	}

	header('Content-Type: text/plain; charset=UTF-8');

	// Stanowiska powiazane z userem
	$stanowiska = UsersHelper::get_group_by_user($user->ID,array('SHOW_IN_PERIOD_MARK'=>'YES'));
	if (empty($stanowiska)) {
		echo '<p class="red">' . "Brak przypisanego stanowiska do pracownika " . $user->ADM_NAME . "" . '</p>';
		return;
	}

	Lib::loadClass('ProcesHelper');
	$procesy_list = ProcesHelper::get_procesy_by_stanowiska( array_keys($stanowiska) );
	// update proces_list data
	foreach ($procesy_list as $k => $p) {
		$procesy_list[$k]->stanowisko = '';
		if (array_key_exists($p->z__ID, $stanowiska)) {
			$procesy_list[$k]->stanowisko = $stanowiska[$p->z__ID]->DESC;
		}
	}

	echo "{$user->ADM_NAME};;;;;;;;;" . "data: " . date("Y-m-d") . ";;\n";

	echo "id;nazwa;stanowisko;ocena pracownika;;ocena kierownika;;ocena specjalisty ds. jakości;;ocena prezesa;;" . "\n";
	echo ";;;%;uwagi;%;uwagi;%;uwagi;%;uwagi;" . "\n";
	foreach ($procesy_list as $p) {
		echo '"' . "{$p->ID}" . '";"' . "{$p->DESC}" . '";"';
		echo "{$p->stanowisko}";
		if (!empty($p->w__OPIS_ZASOB)) {
			echo " (" . str_replace(array("\n","\r"), ' ', $p->w__OPIS_ZASOB) . ")";
		}
		echo '";" ";" ";" ";" ";" ";" ";" ";" ";' . "\n";
	}
	exit;
}

function task_USER_OCENA() {
	User_procesy5_check_access();

	$_print = ('1' == V::get('_print', '', $_GET));
	$_user_id = V::get('_user_id', '', $_GET, 'int');

	$user = new stdClass();
	$user->ID = User::getID();
	$user->ADM_NAME = User::get('ADM_NAME');

	Lib::loadClass('UsersHelper');
	if ($_user_id > 0) {
		$user = UsersHelper::get_user_by_id($_user_id);
		if (!$user) {
			echo '<p class="red">' . "Brak użytkownika o ID = " . $_user_id . '</p>';
			return;
		}
	}

	// Stanowiska powiazane z userem

	$stanowiska = UsersHelper::get_group_by_user($user->ID,array('SHOW_IN_PERIOD_MARK'=>'YES'));
	if (empty($stanowiska)) {
		echo '<p class="red">' . "Brak przypisanego stanowiska do pracownika " . $user->ADM_NAME . "" . '</p>';
		return;
	}

	Lib::loadClass('ProcesHelper');
	$procesy_list = ProcesHelper::get_procesy_by_stanowiska( array_keys($stanowiska) );
	// update proces_list data
	foreach ($procesy_list as $k => $p) {
		$procesy_list[$k]->stanowisko = '';
		if (array_key_exists($p->z__ID, $stanowiska)) {
			$procesy_list[$k]->stanowisko = $stanowiska[$p->z__ID]->DESC;
		}
	}

	echo '<h3>';
		echo $user->ADM_NAME;
		echo '<span style="float:right">' . "data: " . date("Y-m-d") . '</span>';
	echo '</h3>';

	if (!$_print) {
		echo App::link("Drukuj", array('task'=>'USER_OCENA', '_user_id'=>$user->ID, '_print'=>1, 'HIDE_PANEL'=>1), array('ico_after_text'=>'print', 'target'=>'_blank'));
		echo ' | ';
		echo App::link("Export", array('function_init'=>'fun_USER_OCENA_EXPORT', '_user_id'=>$user->ID, 'HIDE_PANEL'=>1), array('ico_after_text'=>'excel.gif', 'target'=>'_blank'));
		echo ' | ';
		echo App::link("Ustal kolejność testów", array('task'=>'TEST_SORT'), array('target'=>'_blank'));
		echo ' | ';
		echo "<font size=-1><a href=index.php?FUNCTION_INIT=GRAPH_VIEW_PROCES&id_proces={$id_proces}&PROCES_INIT_SCAN=1&PROCES_INIT_SCAN_USER={$user->ID} target=blank>Widok mapy</a></font>";

	}

	echo '<table cellspacing="0" cellpadding="0" border="1" class="tbl-view">';
	echo '<thead>';
	echo '<tr>';
		echo '<th rowspan="2" style="width:2%;">' . "id" . '</th>';
		echo '<th rowspan="2" style="width:14%;">' . "nazwa" . '</th>';
		echo '<th rowspan="2" style="width:20%;">' . "stanowisko" . '</th>';
		echo '<th colspan="2">' . "ocena pracownika" . '</th>';
		echo '<th colspan="2">' . "ocena kierownika" . '</th>';
		echo '<th colspan="2">' . "ocena specjalisty ds. jakości" . '</th>';
		echo '<th colspan="2">' . "ocena prezesa" . '</th>';
	echo '</tr>';
	echo '<tr>';
		echo '<th>' . "%" . '</th>';
		echo '<th>' . "uwagi" . '</th>';
		echo '<th>' . "%" . '</th>';
		echo '<th>' . "uwagi" . '</th>';
		echo '<th>' . "%" . '</th>';
		echo '<th>' . "uwagi" . '</th>';
		echo '<th>' . "%" . '</th>';
		echo '<th>' . "uwagi" . '</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody>';
	foreach ($procesy_list as $p) {
		echo '<tr>';
			echo '<td>' . $p->ID . '</td>';
			echo '<td>' . $p->DESC . '</td>';
			echo '<td>' . $p->stanowisko;
				if (!empty($p->w__OPIS_ZASOB)) {
					echo '<br />' . '<em style="font-size:x-small;">' . "(" . $p->w__OPIS_ZASOB . ")" . '</em>';
				}
			echo '</td>';
			echo '<td>' . "" . '</td>';
			echo '<td>' . "" . '</td>';
			echo '<td>' . "" . '</td>';
			echo '<td>' . "" . '</td>';
			echo '<td>' . "" . '</td>';
			echo '<td>' . "" . '</td>';
			echo '<td>' . "" . '</td>';
			echo '<td>' . "" . '</td>';
		echo '</tr>';
	}
	echo '</tbody>';
	echo '</table>';

}
