<?php

Lib::loadClass('View');

class ProcesLogMenuView extends View {

	function render() {
		$user_groups_out = '';
		$user_new_proces_list_out = '';
		$user_list_out = '';
		$proces_current_out = '';

		$user_groups = $this->get('user_groups');
		if (empty($user_groups)) {
			$user_groups_out = '<span title="' . "Brak przypisanego stanowiska - pilnie skontaktuj się z przełożonym!" . '">' . "Brak!" . '</span>';
		} else {
			$out_groups_arr = array();
			foreach ($user_groups as $v_group) {
				$out_groups_arr []= '<span title="' . htmlspecialchars($v_group->DESC) . '">' . $v_group->ID . '</span>';
			}
			$user_groups_out = '<b>' . implode(",", $out_groups_arr) . '</b>';
			unset($out_groups_arr);
		}

		$user_new_proces_list = $this->get('user_new_proces_list');
		if (empty($user_new_proces_list)) {
			$user_new_proces_list_out = '<b style="color:red" title="' . "Brak przypisanych procesów!" . '">' . "Brak!" . '</b>';
		} else {
			$proces_list_select = array();
			foreach ($user_new_proces_list as $v_proces) {
				$proces_list_select [$v_proces->ID] = $v_proces->ID . ': ' . $v_proces->DESC;
				if (strlen($proces_list_select [$v_proces->ID]) > 100) {
					$proces_list_select [$v_proces->ID] = substr($proces_list_select[$v_proces->ID], 0, 100) . '...';
				}
			}
			$cur_proces_init = null;
			//if ($p_log != null) {
			//	$cur_proces_init = $p_log->ID_PROCES_INIT;
			//}
			$user_new_proces_list_out .= '<option>' . " " . '</option>';
			foreach ($proces_list_select as $k_value => $v_label) {
				$sel = ($cur_proces_init == $k_value)? ' selected="selected"' : '';
				$user_new_proces_list_out .= '<option value="' . $k_value . '"'.$sel.'>' . $v_label . '</option>';
			}
			$user_new_proces_list_out = '<select name="' . "proces_init_id" . '" style="width:120px">' . $user_new_proces_list_out . '</select>';
//			$tmpl->proces_select .= '<input type="hidden" name="' . "FUNCTION_INIT" . '" value="' . "PROCES_INIT" . '" />';
			$user_new_proces_list_out .= '<input type="hidden" name="' . "PROCES_INIT_task" . '" value="' . "proces_log_init" . '" />';
			$user_new_proces_list_out .= '<input type="submit" value="' . "Start" . '" />';
			$user_new_proces_list_out = '<form action="" method="POST">' . $user_new_proces_list_out . '</form>';
		}

		$user_list_count = $this->get('user_list_count');
		$user_list_count_out = '';
		if ($user_list_count) {
			$user_list_count_out = " <b>(" . $user_list_count . ")</b>";
		}
		$user_list_out = '<a href="' . "?PROCES_INIT_task=proces_log_select" . '">' . "Moje procesy" . $user_list_count_out . '</a>';

		$proces_current = $this->get('proces_current');
		if ($proces_current) {
			$proces_current_out = "Aktualny proces " . '<b style="color:red">' . $proces_current . '</b>';
		}

		$out = '<div id="proces-panel">'
			. '<a href="' . "?PROCES_INIT_task=clear_log" . '">' . "SE" . '</a>' . " | "
			. $this->get('user_name')
			. " <b>(" . $user_groups_out . ")</b> "
			. " | "
			. (($proces_current_out)? $proces_current_out . " | " : "")
			. "Nowy proces: ". $user_new_proces_list_out
			. " | "
			. $user_list_out
			. " | "
		. '</div>';
		return $out;
	}

}
