<?php

/**
 * @see procesy5.php?task=USER_EDIT&_user_id=4865&_p=0
 */
function USER_OCENA_PRACOWNIKA() {

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

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

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

	// Stanowiska powiazane z userem
	$stanowiska = UsersHelper::get_group_by_user($user->ID);
	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;
		}
	}

	// TODO: _task=EXPORT  exit;


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

	if (!$_print) {
		?>
		<a href="index.php?MENU_INIT=USER_OCENA_PRACOWNIKA&usrLogin=<?php echo $usrLogin; ?>&_print=1&HIDE_PANEL=1" target="_blank">Drukuj <img src="icon/print.gif" height="16" alt="Drukuj"></a>
		|
		<a href="index.php?MENU_INIT=USER_OCENA_PRACOWNIKA&usrLogin=<?php echo $usrLogin; ?>&_task=EXPORT&HIDE_PANEL=1" target="_blank">Export <img src="icon/excel.gif" height="16" alt="Export"></a>
		|
		<a href="procesy5.php?task=TEST_SORT" target="_blank">Ustal kolejność testów</a>
		<?php
	}

	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>';

}
