ソースを参照

#41 Zasoby menu wróć do ostatniego filtra

Piotr Labudda 11 年 前
コミット
e98cc822c1
7 ファイル変更440 行追加409 行削除
  1. 3 1
      SE/procesy/ajax.php
  2. 4 2
      SE/procesy/proces.php
  3. 4 2
      SE/procesy/zasob.php
  4. 0 139
      SE/procesy5.php
  5. 256 265
      SE/se-lib/Filter.php
  6. 145 0
      SE/se-lib/FilterFactory.php
  7. 28 0
      SE/se-lib/ProcesMenu.php

+ 3 - 1
SE/procesy/ajax.php

@@ -8,7 +8,9 @@ function ajax_get_subtree() {
 	$id = V::get('id', '', $_GET);
 	$tbl = V::get('tbl', '', $_GET);
 
-	$tree_filter = get_filter_for_table($tbl);
+	Lib::loadClass('FilterFactory');
+	$tree_filter = FilterFactory::build($tbl);
+	$tree_filter->setArgs($_GET);
 
 	$clbk = 'tree_callback__show_item_from_'.$tbl;
 	if (!function_exists($clbk)) {

+ 4 - 2
SE/procesy/proces.php

@@ -92,8 +92,10 @@ function task_CRM_PROCES() {
 	{// TREE - Filter
 		$tbl = 'CRM_PROCES';
 
-		$tree_procesy_filter = get_filter_for_table( $tbl );
-		$tree_procesy_filter->set_trash( 'filtr_id', -1 );
+		Lib::loadClass('FilterFactory');
+		$tree_procesy_filter = FilterFactory::build($tbl);
+		$tree_procesy_filter->setArgs($_GET);
+		$tree_procesy_filter->set_trash('filtr_id', -1);
 
 		{// zapisz stan - ajax function to save filters stan and opened tree nodes, etc.
 			$filtr_ses_key = $tree_procesy_filter->_key;

+ 4 - 2
SE/procesy/zasob.php

@@ -93,8 +93,10 @@ function task_CRM_LISTA_ZASOBOW() {
 	{// TREE - Filter
 		$tbl = 'CRM_LISTA_ZASOBOW';
 
-		$tree_zasoby_filter = get_filter_for_table( $tbl );
-		$tree_zasoby_filter->set_trash( 'filtr_id', -1 );
+		Lib::loadClass('FilterFactory');
+		$tree_zasoby_filter = FilterFactory::build($tbl);
+		$tree_zasoby_filter->setArgs($_GET);
+		$tree_zasoby_filter->set_trash('filtr_id', -1);
 
 		{// zapisz stan - ajax function to save filters stan and opened tree nodes, etc.
 			$filtr_ses_key = $tree_zasoby_filter->_key;

+ 0 - 139
SE/procesy5.php

@@ -688,145 +688,6 @@ function task_CRM_DEL_CRM_WSKAZNIK() {
 	echo'</p>';// .box
 }
 
-
-function &get_filter_for_table( $tbl ) {
-	Lib::loadClass('Filter');
-	$tree_filter = new Filter( $_GET, $tbl, 'session' );
-
-	// TODO: add trigger: on clear all filters - remove cookie, on tree key
-	//$tree_filter->
-
-	if ($tbl == 'CRM_PROCES') {
-		{// filtry
-			$filtr = array();
-			if (User_is_admin()) { // filtr_edit, only for admins
-				$filtr = array();
-				$filtr['TAK'] = '1';
-				$filtr['NIE'] = '0';
-				$tree_filter->add_filter( 'filtr_edit', $filtr, 'NIE', 'Edytuj' );
-			}
-			{ // filtr_drzewo - TODO: czy uzywane?
-				$filtr = array();
-				$filtr['ZWIN'] = '0';
-				$filtr['ROZWIN'] = '1';
-				//TODO: add js, onclick - remove cookie to hide tree
-				$tree_filter->add_filter( 'filtr_drzewo', $filtr, 'ROZWIN', 'Drzewo' );
-			}
-			{ // filtr_procesy
-				$filtr = array();
-				$filtr['-'] = '0';
-				$filtr['+'] = '1';
-				$tree_filter->add_filter( 'filtr_procesy', $filtr, '-', 'Procesy' );
-			}
-			{ // filtr_zasoby
-				$filtr = array();
-				$filtr['-'] = '0';
-				$filtr['+'] = '1';
-				$tree_filter->add_filter( 'filtr_zasoby', $filtr, '-', 'Zasoby' );
-			}
-			{ // filtr_opis
-				$filtr = array();
-				$filtr['-'] = '0';
-				$filtr['+'] = '1';
-				$tree_filter->add_filter( 'filtr_opis', $filtr, '-', 'Opisy' );
-			}
-			{ // filtr_img
-				$filtr = array();
-				$filtr['-'] = '0';
-				$filtr['+'] = '1';
-				$tree_filter->add_filter( 'filtr_img', $filtr, '-', 'IMG' );
-			}
-			{ // filtr_id
-				$filtr = array('search');
-				$tree_filter->add_filter( 'filtr_id', $filtr, '', 'Filtruj ID' );
-			}
-			{ // filtr_search_id
-				$filtr = array('search');
-				// TODO: add js search without page reload, add #TREE{ID}
-				$tree_filter->add_filter( 'filtr_search_id', $filtr, '', 'Wyszukaj ID' );
-			}
-			{ // filtr_view
-				$filtr = array();
-				$filtr['NOWY'] = '1';
-				$filtr['STARY'] = '0';
-				$tree_filter->add_filter( 'filtr_view', $filtr, 'NOWY', 'Widok' );
-			}
-			{ // filtr_ajax
-				$filtr = array();
-				$filtr['NIE'] = '0';
-				$filtr['TAK'] = '1';
-				$tree_filter->add_filter( 'filtr_ajax', $filtr, 'TAK', 'Ajax' );
-			}
-		}
-	}
-	else if ($tbl == 'CRM_LISTA_ZASOBOW') {
-		{// filtry
-			$filtr = array();
-			if (User_is_admin()) { // filtr_edit, only for admins
-				$filtr = array();
-				$filtr['TAK'] = '1';
-				$filtr['NIE'] = '0';
-				$tree_filter->add_filter( 'filtr_edit', $filtr, 'NIE', 'Edytuj' );
-			}
-			{ // filtr_drzewo
-				$filtr = array();
-				$filtr['ZWIN'] = '0';
-				$filtr['ROZWIN'] = '1';
-				$tree_filter->add_filter( 'filtr_drzewo', $filtr, 'ZWIN', 'Drzewo' );
-			}
-			{ // filtr_ob
-				$filtr = array();
-				$filtr['-'] = '0';
-				$filtr['+'] = '1';
-				$tree_filter->add_filter( 'filtr_ob', $filtr, '-', 'OB' );
-			}
-			{ // filtr_img
-				$filtr = array();
-				$filtr['-'] = '0';
-				$filtr['+'] = '1';
-				$tree_filter->add_filter( 'filtr_img', $filtr, '-', 'IMG' );
-			}
-			{ // filtr_opis
-				$filtr = array();
-				$filtr['-'] = '0';
-				$filtr['+'] = '1';
-				$tree_filter->add_filter( 'filtr_opis', $filtr, '-', 'Opisy' );
-			}
-			{ // filtr_ids
-				$filtr = array();
-				$filtr['-'] = '0';
-				$filtr['+'] = '1';
-				$tree_filter->add_filter( 'filtr_ids', $filtr, '-', 'IDS' );
-			}
-			{ // filtr_id
-				$filtr = array('search');
-				$tree_filter->add_filter( 'filtr_id', $filtr, '', 'Filtruj ID' );
-			}
-			{ // filtr_search_id
-				$filtr = array('search');
-				$tree_filter->add_filter( 'filtr_search_id', $filtr, '', 'Wyszukaj ID' );
-			}
-			{ // filtr_view
-				$filtr = array();
-				$filtr['NOWY'] = '1';
-				$filtr['STARY'] = '0';
-				$tree_filter->add_filter( 'filtr_view', $filtr, 'NOWY', 'Widok' );
-			}
-			{ // filtr_ajax
-				$filtr = array();
-				$filtr['TAK'] = '1';
-				$filtr['NIE'] = '0';
-				$tree_filter->add_filter( 'filtr_ajax', $filtr, 'TAK', 'Ajax' );
-			}
-		}
-	}
-	else {
-		// unknown table
-	}
-	return $tree_filter;
-}
-
-
 function fun_USERS_COLUMN() {
 	$arg = V::get('arg', '', $_GET);
 	$col_id = V::get('col_id', '', $_GET);

+ 256 - 265
SE/se-lib/Filter.php

@@ -1,322 +1,313 @@
 <?php
 
 
-Class Filter {
-
-
-var $args;
-var $args_default;
-var $filters;
-var $labels;
-var $callbacks;
-var $_key;
-var $_storage;// enum('session', 'cookie')
-var $_trash_filtr;// Tree trash
-
-
-/**
- * @param $args - args table: $_GET, $_POST, $_REQUEST, etc
- * @param $key - kay to store values in @storage, if not set then args not saved
- * @param $storage - where to store state - cookie or session, default is cookie
- */
-function __construct($args, $key = null, $storage = 'cookie') {
-	$this->args = $args;
-	$this->args_default = array();
-	$this->filters = array();
-	$this->labels = array();
-	$this->callbacks = array();
-	$this->_key = 'filter-'.$key;
-	$this->_storage = $storage;
-	$this->_init_args();
-	$this->_trash_filtr = null;
-}
-
-
-function get_arg($name) {
-	// try load from @storage and save
-	if (array_key_exists($name, $this->args)) {
-		return $this->args[$name];
-	} else if (array_key_exists($name, $this->args_default)) {
-		return $this->args_default[$name];
+class Filter {
+
+	var $args;
+	var $args_default;
+	var $filters;
+	var $labels;
+	var $callbacks;
+	var $_key;
+	var $_storage;// enum('session', 'cookie')
+	var $_trash_filtr;// Tree trash
+
+	/**
+	 * @param $args - args table: $_GET, $_POST, $_REQUEST, etc
+	 * @param $key - kay to store values in @storage, if not set then args not saved
+	 * @param $storage - where to store state - cookie or session, default is cookie
+	 */
+	function __construct($args, $key = null, $storage = 'cookie') {
+		$this->args = $args;
+		$this->args_default = array();
+		$this->filters = array();
+		$this->labels = array();
+		$this->callbacks = array();
+		$this->_key = 'filter-'.$key;
+		$this->_storage = $storage;
+		$this->_init_args();
+		$this->_trash_filtr = null;
 	}
-	return null;
-}
-
 
-function _init_args() {
-	if (array_key_exists('filtr_clear', $this->args) && $this->args['filtr_clear'] == 1) {
-		$this->args = array();
-	} else {
-		$this->_read_args();
+	public function get_arg($name) {
+		// TODO: allow only keys from $this->filters
+		// try load from @storage and save
+		if (array_key_exists($name, $this->args)) {
+			return $this->args[$name];
+		} else if (array_key_exists($name, $this->args_default)) {
+			return $this->args_default[$name];
+		}
+		return null;
 	}
-}
-
 
-function add_filter($name, $values, $default, $label = '', $callback = null) {
-	$this->filters[$name] = $values;
-	$this->labels[$name] = ($label)? $label : $name;
-	$this->args_default[$name] = $default;
-	if ($callback) $this->callbacks[$name] = $callback;
-}
+	public function setArgs($args) {
+		foreach ($args as $k => $v) {
+			if (!array_key_exists($k, $this->filters)) continue;
+			$this->args[$k] = $v;
+		}
+	}
 
+	private function _init_args() {
+		if (array_key_exists('filtr_clear', $this->args) && $this->args['filtr_clear'] == 1) {
+			$this->args = array();
+		} else {
+			$this->_read_args();
+		}
+	}
 
-function _save_args() {
-	if (!$this->_key) { return; }
-	if ($this->_storage == 'cookie') {
-		$this->_save_args_in_cookie();
-	} else {
-		$this->_save_args_in_session();
+	function add_filter($name, $values, $default, $label = '', $callback = null) {
+		$this->filters[$name] = $values;
+		$this->labels[$name] = ($label)? $label : $name;
+		$this->args_default[$name] = $default;
+		if ($callback) $this->callbacks[$name] = $callback;
 	}
-}
 
+	public function _save_args() {
+		if (!$this->_key) { return; }
+		if ($this->_storage == 'cookie') {
+			$this->_save_args_in_cookie();
+		} else {
+			$this->_save_args_in_session();
+		}
+	}
 
-function _save_args_in_session() {
-	if (!$this->_key) { return; }
+	private function _save_args_in_session() {
+		if (!$this->_key) { return; }
 
-	$save_args = array();
-	foreach ($this->filters as $name => $options) {
-		$arg = (isset($this->args[$name]))? $this->args[$name] : '';
-		if (count($options) == 1 && reset($options) == 'search') {
-			if ($arg != $this->args_default[$name]) {
-				$option = $arg;
-				$save_args[] = ''.urlencode($name).'='.urlencode($option);
-			}
-		} else {
-			foreach($options as $option => $field_name) {
-				if (isset($this->args[$name]) && $this->args[$name] == $option) {
+		$save_args = array();
+		foreach ($this->filters as $name => $options) {
+			$arg = (isset($this->args[$name]))? $this->args[$name] : '';
+			if (count($options) == 1 && reset($options) == 'search') {
+				if ($arg != $this->args_default[$name]) {
+					$option = $arg;
 					$save_args[] = ''.urlencode($name).'='.urlencode($option);
 				}
+			} else {
+				foreach($options as $option => $field_name) {
+					if (isset($this->args[$name]) && $this->args[$name] == $option) {
+						$save_args[] = ''.urlencode($name).'='.urlencode($option);
+					}
+				}
 			}
 		}
-	}
-
-	$save_args = implode(',', $save_args);
-	$_SESSION[$this->_key] = $save_args;
-}
 
+		$save_args = implode(',', $save_args);
+		$_SESSION[$this->_key] = $save_args;
+	}
 
-function _save_args_in_cookie() {
-	if (!$this->_key) { return; }
+	private function _save_args_in_cookie() {
+		if (!$this->_key) { return; }
 
-	$save_args = array();
-	foreach ($this->filters as $name => $options) {
-		$arg = (isset($this->args[$name]))? $this->args[$name] : '';
-		if (count($options) == 1 && reset($options) == 'search') {
-			if ($arg != $this->args_default[$name]) {
-				$option = $arg;
-				$save_args[] = ''.urlencode($name).'='.urlencode($option);
-			}
-		} else {
-			foreach($options as $option => $field_name) {
-				if (isset($this->args[$name]) && $this->args[$name] == $option) {
+		$save_args = array();
+		foreach ($this->filters as $name => $options) {
+			$arg = (isset($this->args[$name]))? $this->args[$name] : '';
+			if (count($options) == 1 && reset($options) == 'search') {
+				if ($arg != $this->args_default[$name]) {
+					$option = $arg;
 					$save_args[] = ''.urlencode($name).'='.urlencode($option);
 				}
+			} else {
+				foreach($options as $option => $field_name) {
+					if (isset($this->args[$name]) && $this->args[$name] == $option) {
+						$save_args[] = ''.urlencode($name).'='.urlencode($option);
+					}
+				}
 			}
 		}
+	//	if ($save_args) {
+			$save_args = implode(',', $save_args);
+			echo'<script type="text/javascript">';echo"
+				(function(){
+					var exdate=new Date()
+						, exdays = 14
+						, c_name='".$this->_key."'
+						, value='".$save_args."'
+					;
+					exdate.setDate(exdate.getDate() + exdays);
+					var c_value=escape(value) + ((exdays==null) ? '' : '; expires='+exdate.toUTCString());
+					document.cookie=c_name + '=' + c_value;
+				})();
+			";echo'</script>';
+	//	}
 	}
-//	if ($save_args) {
-		$save_args = implode(',', $save_args);
-		echo'<script type="text/javascript">';echo"
-			(function(){
-				var exdate=new Date()
-					, exdays = 14
-					, c_name='".$this->_key."'
-					, value='".$save_args."'
-				;
-				exdate.setDate(exdate.getDate() + exdays);
-				var c_value=escape(value) + ((exdays==null) ? '' : '; expires='+exdate.toUTCString());
-				document.cookie=c_name + '=' + c_value;
-			})();
-		";echo'</script>';
-//	}
-}
-
 
-function _read_args($force = false) {
-	if (!$this->_key) { return; }
-	if ($this->_storage == 'cookie') {
-		$this->_read_args_from_cookie($force);
-	} else {
-		$this->_read_args_from_session($force);
+	public function _read_args($force = false) {
+		if (!$this->_key) { return; }
+		if ($this->_storage == 'cookie') {
+			$this->_read_args_from_cookie($force);
+		} else {
+			$this->_read_args_from_session($force);
+		}
 	}
-}
 
-
-function _read_args_from_session($force = false) {
-	if (!$this->_key) { return; }
-	if (!array_key_exists($this->_key, $_SESSION)) { return; }
-	$c_args = explode(',', $_SESSION[$this->_key]);
-//echo'<p>read from session c_args: '.$_SESSION[$this->_key].'</p>';
-	foreach ($c_args as $c_val) {
-		$c_val = explode('=', $c_val);
-		if (count($c_val) != 2) continue;
-		$name = urldecode($c_val[0]);
-		$option = urldecode($c_val[1]);
-		if ($force || !array_key_exists($name, $this->args)) {
-//echo'<p>read from session: '.$name.' / '.$this->args[$name].' / set '.$option.'</p>';
-			$this->args[$name] = $option;
+	private function _read_args_from_session($force = false) {
+		if (!$this->_key) { return; }
+		if (!array_key_exists($this->_key, $_SESSION)) { return; }
+		$c_args = explode(',', $_SESSION[$this->_key]);
+	//echo'<p>read from session c_args: '.$_SESSION[$this->_key].'</p>';
+		foreach ($c_args as $c_val) {
+			$c_val = explode('=', $c_val);
+			if (count($c_val) != 2) continue;
+			$name = urldecode($c_val[0]);
+			$option = urldecode($c_val[1]);
+			if ($force || !array_key_exists($name, $this->args)) {
+	//echo'<p>read from session: '.$name.' / '.$this->args[$name].' / set '.$option.'</p>';
+				$this->args[$name] = $option;
+			}
 		}
 	}
-}
 
-
-/**
- * Read args from cookie.
- */
-function _read_args_from_cookie($force = false) {
-	if (!$this->_key) { return; }
-	if (!array_key_exists($this->_key, $_COOKIE)) { return; }
-	$c_args = explode(',', $_COOKIE[$this->_key]);
-	foreach ($c_args as $c_val) {
-		$c_val = explode('=', $c_val);
-		if (count($c_val) != 2) continue;
-		$name = urldecode($c_val[0]);
-		$option = urldecode($c_val[1]);
-		if ($force || !array_key_exists($name, $this->args)) {
-			$this->args[$name] = $option;
+	/**
+	 * Read args from cookie.
+	 */
+	private function _read_args_from_cookie($force = false) {
+		if (!$this->_key) { return; }
+		if (!array_key_exists($this->_key, $_COOKIE)) { return; }
+		$c_args = explode(',', $_COOKIE[$this->_key]);
+		foreach ($c_args as $c_val) {
+			$c_val = explode('=', $c_val);
+			if (count($c_val) != 2) continue;
+			$name = urldecode($c_val[0]);
+			$option = urldecode($c_val[1]);
+			if ($force || !array_key_exists($name, $this->args)) {
+				$this->args[$name] = $option;
+			}
 		}
 	}
-}
 
+	/**
+	 * Print form fields. Must be inside <form> tag.
+	 */
+	public function show_filters() {
+		// read args from cookie if exists
+		$selected_defaults = true;
 
-/**
- * Print form fields. Must be inside <form> tag.
- */
-function show_filters() {
-	// read args from cookie if exists
-	$selected_defaults = true;
-
-	// bug fix in browser, run onclick action on first submit/image/button element in html code
-	echo'<nobr style="float:right;margin:-9999px 0 0 -9999px;">';
-		echo'<input type="submit" value="'."submit".'" />';
-	echo'</nobr>';
-
-	// show trash if exists
-	echo $this->show_trash();
-
-	// show filters
-	foreach ($this->filters as $name => $options) {
-		$out = new stdClass();
-		$out->cls = '';// class
-		$out->cnt = '';// content
-
-		$selected_option = (isset($this->args[$name]))? $this->args[$name] : $this->args_default[$name];
-		if (count($options) == 1 && reset($options) == 'search') {
-			$size = strlen($selected_option); $size = ($size < 4)? 4 : $size + 2;// size min 4
-			$out->cnt .= '<input type="text" name="'.$name.'" value="'.$selected_option.'" class="i" size="'.$size.'" />';
-			if ($selected_option != $this->args_default[$name]) {
-				$selected_defaults = false;
-				$out->cls = 'active';
-				//echo' <input type="submit" value="'."x".'" onclick="'."this.form.".$name.".value='';".'" title="'."Usuń".'" />';
-				// po kliknięciu ENTER w polu wymuszało usuwanie zawartości pola - 1st submit btn in form
-				$out->cnt .= '<input type="button" value="'."x".'" onclick="'."this.form.".$name.".value='';this.form.submit();".'" title="'."Usuń".'" />';
-			}
-			//$out->cnt .= '<input type="submit" value="'."Szukaj".'" />';
-			$out->cnt .= '<input type="image" src="' . "icon/search.png" . '" ale="'."Szukaj".'" title="'."Szukaj".'" />';
-		}
-		else if (count($options) == 2) {// 2 opcje do wyboru to button
-			$selected_button = $selected_option;
-			if (!array_key_exists($selected_button, $options)) {
-				$selected_button = $this->args_default[$name];
-			}
-			if ($selected_button != $this->args_default[$name]) {
-				$selected_defaults = false;
-				$out->cls = 'active';
-			}
-			foreach ($options as $option => $val) {
-				if ($selected_button != $option) {
-					$out->cnt .= '<input type="submit" name="'.$name.'" value="'.$option.'" />';
+		// bug fix in browser, run onclick action on first submit/image/button element in html code
+		echo'<nobr style="float:right;margin:-9999px 0 0 -9999px;">';
+			echo'<input type="submit" value="'."submit".'" />';
+		echo'</nobr>';
+
+		// show trash if exists
+		echo $this->show_trash();
+
+		// show filters
+		foreach ($this->filters as $name => $options) {
+			$out = new stdClass();
+			$out->cls = '';// class
+			$out->cnt = '';// content
+
+			$selected_option = (isset($this->args[$name]))? $this->args[$name] : $this->args_default[$name];
+			if (count($options) == 1 && reset($options) == 'search') {
+				$size = strlen($selected_option); $size = ($size < 4)? 4 : $size + 2;// size min 4
+				$out->cnt .= '<input type="text" name="'.$name.'" value="'.$selected_option.'" class="i" size="'.$size.'" />';
+				if ($selected_option != $this->args_default[$name]) {
+					$selected_defaults = false;
+					$out->cls = 'active';
+					//echo' <input type="submit" value="'."x".'" onclick="'."this.form.".$name.".value='';".'" title="'."Usuń".'" />';
+					// po kliknięciu ENTER w polu wymuszało usuwanie zawartości pola - 1st submit btn in form
+					$out->cnt .= '<input type="button" value="'."x".'" onclick="'."this.form.".$name.".value='';this.form.submit();".'" title="'."Usuń".'" />';
 				}
+				//$out->cnt .= '<input type="submit" value="'."Szukaj".'" />';
+				$out->cnt .= '<input type="image" src="' . "icon/search.png" . '" ale="'."Szukaj".'" title="'."Szukaj".'" />';
 			}
-		}
-		else {// ponad 2 opcje to select
-			$out->cnt .= '<select name="'.$name.'" onchange="this.form.submit();">';
-			if ($selected_option != $this->args_default[$name]) {
-				$selected_defaults = false;
-				$out->cls = 'active';
+			else if (count($options) == 2) {// 2 opcje do wyboru to button
+				$selected_button = $selected_option;
+				if (!array_key_exists($selected_button, $options)) {
+					$selected_button = $this->args_default[$name];
+				}
+				if ($selected_button != $this->args_default[$name]) {
+					$selected_defaults = false;
+					$out->cls = 'active';
+				}
+				foreach ($options as $option => $val) {
+					if ($selected_button != $option) {
+						$out->cnt .= '<input type="submit" name="'.$name.'" value="'.$option.'" />';
+					}
+				}
 			}
-			foreach ($options as $option => $field_name) {
-				$sel = ($selected_option == $option)? 'selected' : '';
-				$out->cnt .= '<option value="'.$option.'" '.$sel.'>'.$option.'</option>';
+			else {// ponad 2 opcje to select
+				$out->cnt .= '<select name="'.$name.'" onchange="this.form.submit();">';
+				if ($selected_option != $this->args_default[$name]) {
+					$selected_defaults = false;
+					$out->cls = 'active';
+				}
+				foreach ($options as $option => $field_name) {
+					$sel = ($selected_option == $option)? 'selected' : '';
+					$out->cnt .= '<option value="'.$option.'" '.$sel.'>'.$option.'</option>';
+				}
+				$out->cnt .= '</select>';
 			}
-			$out->cnt .= '</select>';
+
+			echo' <nobr'.(($out->cls)? ' class="'.$out->cls.'"' : '').'>';
+				echo $this->labels[$name];
+				echo $out->cnt;
+			echo'</nobr>';
+			echo $this->separator();
+			unset($out);
 		}
 
-		echo' <nobr'.(($out->cls)? ' class="'.$out->cls.'"' : '').'>';
-			echo $this->labels[$name];
-			echo $out->cnt;
-		echo'</nobr>';
-		echo $this->separator();
-		unset($out);
+		if (!$selected_defaults) {
+			echo'<nobr>';
+			echo'<input type="hidden" name="filtr_clear" value="0" />';
+			echo' <input type="button" value="'."Wyczyść filtr".'" onclick="this.form.filtr_clear.value=1;this.form.submit()" /> ';
+			echo'</nobr>';
+		}
+		$this->_save_args();
 	}
 
-	if (!$selected_defaults) {
-		echo'<nobr>';
-		echo'<input type="hidden" name="filtr_clear" value="0" />';
-		echo' <input type="button" value="'."Wyczyść filtr".'" onclick="this.form.filtr_clear.value=1;this.form.submit()" /> ';
-		echo'</nobr>';
+	public function set_trash($filtr_key = '', $value = 0) {
+		$this->_trash_filtr = array('filtr_key'=>$filtr_key, 'value'=>$value);
 	}
-	$this->_save_args();
-}
-
-
-function set_trash($filtr_key = '', $value = 0) {
-	$this->_trash_filtr = array('filtr_key'=>$filtr_key, 'value'=>$value);
-}
 
+	public function is_trash() {
+		if ($this->_trash_filtr === null) {
+			return false;
+		}
 
-function is_trash() {
-	if ($this->_trash_filtr === null) {
+		$trash_filtr_key = $this->_trash_filtr['filtr_key'];
+		$trash_filtr_value = $this->_trash_filtr['value'];
+		$filtr_value = $this->get_arg($trash_filtr_key);
+		if ($filtr_value === null) {
+			return false;
+		}
+		if ($filtr_value == $trash_filtr_value) {
+			return true;
+		}
 		return false;
 	}
 
-	$trash_filtr_key = $this->_trash_filtr['filtr_key'];
-	$trash_filtr_value = $this->_trash_filtr['value'];
-	$filtr_value = $this->get_arg($trash_filtr_key);
-	if ($filtr_value === null) {
-		return false;
-	}
-	if ($filtr_value == $trash_filtr_value) {
-		return true;
-	}
-	return false;
-}
+	public function show_trash() {
+		$out = '';
+		if ($this->_trash_filtr === null) {
+			return $out;
+		}
 
+		$trash_filtr_key = $this->_trash_filtr['filtr_key'];
+		$trash_filtr_value = $this->_trash_filtr['value'];
+		$filtr_value = $this->get_arg($trash_filtr_key);
+		if ($filtr_value === null) {// filtr not exists, TODO: throw error?
+			return $out;
+		}
+		$out .= '<nobr>';
+			if ($this->is_trash()) {
+				//echo App::link("Drzewo", array('task'=>App::get_task()), array('ico'=>'trash_out.gif', 'title'=>'Wroc do drzewa'));
+				$trash_ico = 'icon/trash_out.gif';
+				$onclick = ' onclick="'."this.form.".$trash_filtr_key.".value='';this.form.submit();".'"';
+				$out .= '<input type="image" src="'.$trash_ico.'" value="'."Drzewo".'" class="i"'.$onclick.' title="'."Wroc do drzewa".'" />';
+			} else {
+				//echo App::link("Kosz", array('task'=>App::get_task(), 'filtr_id'=>"-1"), array('ico'=>'trash.gif', 'title'=>'Kosz'));
+				$trash_ico = 'icon/trash.gif';
+				$onclick = ' onclick="'."this.form.".$trash_filtr_key.".value='".$trash_filtr_value."';this.form.submit();".'"';
+				$out .= '<input type="image" src="'.$trash_ico.'" value="'."Kosz".'" class="i"'.$onclick.' title="'."Kosz".'" />';
+			}
+		$out .= '</nobr>';
+		$out .= $this->separator();
 
-function show_trash() {
-	$out = '';
-	if ($this->_trash_filtr === null) {
 		return $out;
 	}
 
-	$trash_filtr_key = $this->_trash_filtr['filtr_key'];
-	$trash_filtr_value = $this->_trash_filtr['value'];
-	$filtr_value = $this->get_arg($trash_filtr_key);
-	if ($filtr_value === null) {// filtr not exists, TODO: throw error?
-		return $out;
+	function separator() {
+		return '<div class="btnseparator"></div>';// separator
 	}
-	$out .= '<nobr>';
-		if ($this->is_trash()) {
-			//echo App::link("Drzewo", array('task'=>App::get_task()), array('ico'=>'trash_out.gif', 'title'=>'Wroc do drzewa'));
-			$trash_ico = 'icon/trash_out.gif';
-			$onclick = ' onclick="'."this.form.".$trash_filtr_key.".value='';this.form.submit();".'"';
-			$out .= '<input type="image" src="'.$trash_ico.'" value="'."Drzewo".'" class="i"'.$onclick.' title="'."Wroc do drzewa".'" />';
-		} else {
-			//echo App::link("Kosz", array('task'=>App::get_task(), 'filtr_id'=>"-1"), array('ico'=>'trash.gif', 'title'=>'Kosz'));
-			$trash_ico = 'icon/trash.gif';
-			$onclick = ' onclick="'."this.form.".$trash_filtr_key.".value='".$trash_filtr_value."';this.form.submit();".'"';
-			$out .= '<input type="image" src="'.$trash_ico.'" value="'."Kosz".'" class="i"'.$onclick.' title="'."Kosz".'" />';
-		}
-	$out .= '</nobr>';
-	$out .= $this->separator();
-
-	return $out;
-}
-
-
-function separator() {
-	return '<div class="btnseparator"></div>';// separator
-}
-
 
 }

+ 145 - 0
SE/se-lib/FilterFactory.php

@@ -0,0 +1,145 @@
+<?php
+
+Lib::loadClass('Filter');
+
+class FilterFactory {
+
+	public static function build($tbl) {
+		Lib::loadClass('Filter');
+		$args = array();
+		$tree_filter = new Filter($args, $tbl, 'session');
+
+		// TODO: add trigger: on clear all filters - remove cookie, on tree key
+		//$tree_filter->
+
+		if ($tbl == 'CRM_PROCES') {
+			{// filtry
+				$filtr = array();
+				if (User_is_admin()) { // filtr_edit, only for admins
+					$filtr = array();
+					$filtr['TAK'] = '1';
+					$filtr['NIE'] = '0';
+					$tree_filter->add_filter('filtr_edit', $filtr, 'NIE', 'Edytuj');
+				}
+				{ // filtr_drzewo - TODO: czy uzywane?
+					$filtr = array();
+					$filtr['ZWIN'] = '0';
+					$filtr['ROZWIN'] = '1';
+					//TODO: add js, onclick - remove cookie to hide tree
+					$tree_filter->add_filter('filtr_drzewo', $filtr, 'ROZWIN', 'Drzewo');
+				}
+				{ // filtr_procesy
+					$filtr = array();
+					$filtr['-'] = '0';
+					$filtr['+'] = '1';
+					$tree_filter->add_filter('filtr_procesy', $filtr, '-', 'Procesy');
+				}
+				{ // filtr_zasoby
+					$filtr = array();
+					$filtr['-'] = '0';
+					$filtr['+'] = '1';
+					$tree_filter->add_filter('filtr_zasoby', $filtr, '-', 'Zasoby');
+				}
+				{ // filtr_opis
+					$filtr = array();
+					$filtr['-'] = '0';
+					$filtr['+'] = '1';
+					$tree_filter->add_filter('filtr_opis', $filtr, '-', 'Opisy');
+				}
+				{ // filtr_img
+					$filtr = array();
+					$filtr['-'] = '0';
+					$filtr['+'] = '1';
+					$tree_filter->add_filter('filtr_img', $filtr, '-', 'IMG');
+				}
+				{ // filtr_id
+					$filtr = array('search');
+					$tree_filter->add_filter('filtr_id', $filtr, '', 'Filtruj ID');
+				}
+				{ // filtr_search_id
+					$filtr = array('search');
+					// TODO: add js search without page reload, add #TREE{ID}
+					$tree_filter->add_filter('filtr_search_id', $filtr, '', 'Wyszukaj ID');
+				}
+				{ // filtr_view
+					$filtr = array();
+					$filtr['NOWY'] = '1';
+					$filtr['STARY'] = '0';
+					$tree_filter->add_filter('filtr_view', $filtr, 'NOWY', 'Widok');
+				}
+				{ // filtr_ajax
+					$filtr = array();
+					$filtr['NIE'] = '0';
+					$filtr['TAK'] = '1';
+					$tree_filter->add_filter('filtr_ajax', $filtr, 'TAK', 'Ajax');
+				}
+			}
+		}
+		else if ($tbl == 'CRM_LISTA_ZASOBOW') {
+			{// filtry
+				$filtr = array();
+				if (User_is_admin()) { // filtr_edit, only for admins
+					$filtr = array();
+					$filtr['TAK'] = '1';
+					$filtr['NIE'] = '0';
+					$tree_filter->add_filter('filtr_edit', $filtr, 'NIE', 'Edytuj');
+				}
+				{ // filtr_drzewo
+					$filtr = array();
+					$filtr['ZWIN'] = '0';
+					$filtr['ROZWIN'] = '1';
+					$tree_filter->add_filter('filtr_drzewo', $filtr, 'ZWIN', 'Drzewo');
+				}
+				{ // filtr_ob
+					$filtr = array();
+					$filtr['-'] = '0';
+					$filtr['+'] = '1';
+					$tree_filter->add_filter('filtr_ob', $filtr, '-', 'OB');
+				}
+				{ // filtr_img
+					$filtr = array();
+					$filtr['-'] = '0';
+					$filtr['+'] = '1';
+					$tree_filter->add_filter('filtr_img', $filtr, '-', 'IMG');
+				}
+				{ // filtr_opis
+					$filtr = array();
+					$filtr['-'] = '0';
+					$filtr['+'] = '1';
+					$tree_filter->add_filter('filtr_opis', $filtr, '-', 'Opisy');
+				}
+				{ // filtr_ids
+					$filtr = array();
+					$filtr['-'] = '0';
+					$filtr['+'] = '1';
+					$tree_filter->add_filter('filtr_ids', $filtr, '-', 'IDS');
+				}
+				{ // filtr_id
+					$filtr = array('search');
+					$tree_filter->add_filter('filtr_id', $filtr, '', 'Filtruj ID');
+				}
+				{ // filtr_search_id
+					$filtr = array('search');
+					$tree_filter->add_filter('filtr_search_id', $filtr, '', 'Wyszukaj ID');
+				}
+				{ // filtr_view
+					$filtr = array();
+					$filtr['NOWY'] = '1';
+					$filtr['STARY'] = '0';
+					$tree_filter->add_filter('filtr_view', $filtr, 'NOWY', 'Widok');
+				}
+				{ // filtr_ajax
+					$filtr = array();
+					$filtr['TAK'] = '1';
+					$filtr['NIE'] = '0';
+					$tree_filter->add_filter('filtr_ajax', $filtr, 'TAK', 'Ajax');
+				}
+			}
+		}
+		else {
+			// unknown table
+		}
+		return $tree_filter;
+	}
+
+}

+ 28 - 0
SE/se-lib/ProcesMenu.php

@@ -8,6 +8,7 @@ Lib::loadClass('TypespecialVariable');
 Lib::loadClass('UsersHelper');
 Lib::loadClass('DB');
 Lib::loadClass('UserBookmarks');
+Lib::loadClass('FilterFactory');
 
 class ProcesMenu {
 
@@ -366,6 +367,9 @@ class ProcesMenu {
 		}
 		$typeSpecialZasob = TypespecialVariable::getInstance(-1, '__ZASOB');
 
+		$treeZasobyFilter = FilterFactory::build('CRM_LISTA_ZASOBOW');
+		$lastZasobyFiltrIds = $treeZasobyFilter->get_arg('filtr_id');
+
 		?>
 <div id="SE-menu" class="navbar navbar-inverse" style="position: static;">
 	<div class="navbar-inner">
@@ -405,6 +409,30 @@ class ProcesMenu {
 					<li class="dropdown <?php if ($active == 'zasoby') echo "active"; ?>">
 						<a id="ProcesMenuZasobDropdownLink" href="#" class="dropdown-toggle" data-toggle="dropdown">Zasoby <b class="caret"></b></a>
 						<ul class="dropdown-menu">
+							<?php if (!empty($lastZasobyFiltrIds)) : ?>
+								<li class="nav-header"><nobr>Wróć do ostatniego wyszukiwania:</nobr></li>
+								<li>
+									<a href="procesy5.php?task=CRM_LISTA_ZASOBOW<?php echo "&filtr_id={$lastZasobyFiltrIds}&filtr_ids=%2B&filtr_ob=%2B&filtr_img=%2B";  ?>"><?php
+											//echo $lastZasobyFiltrIdsLabels;
+											if (!empty($lastZasobyFiltrIds)) {
+												$lastZasobyFiltrIds = explode(',', $lastZasobyFiltrIds);
+												$labels = array();
+												$labelsLimit = 4;
+												$labelsInd = 0;
+												foreach ($lastZasobyFiltrIds as $lastFltr) {
+													$labels[] = '<span class="badge badge-inverse">' . $lastFltr . '</span>';
+													if (++$labelsInd >= $labelsLimit) {
+														$labels[] = '...';
+														break;
+													}
+												}
+												$lastZasobyFiltrIdsLabels = implode(' ', $labels);
+											}
+											echo $lastZasobyFiltrIdsLabels;
+										?></a>
+								</li>
+								<li class="divider"></li>
+							<?php endif; ?>
 							<li>
 								<a href="procesy5.php?task=CRM_LISTA_ZASOBOW<?php echo "&filtr_id={$userGroupIdsCSV}&filtr_ids=%2B&filtr_ob=%2B&filtr_img=%2B";  ?>" title="Moje Zasoby">Moje Zasoby</a>
 							</li>