xref: /plugin/bez/syntax/nav.php (revision aa89e6f87daa9b559eea182b8567d772dfa4ce7f)
165cfcae3Sghi<?php
265cfcae3Sghi/**
365cfcae3Sghi * Plugin Now: Inserts a timestamp.
465cfcae3Sghi *
565cfcae3Sghi */
665cfcae3Sghi
765cfcae3Sghi// must be run within DokuWiki
865cfcae3Sghiif(!defined('DOKU_INC')) die();
965cfcae3Sghi
1065cfcae3Sghiif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
1165cfcae3Sghirequire_once DOKU_PLUGIN.'syntax.php';
12a6dcc2a9Sghiinclude_once DOKU_PLUGIN."bez/models/issues.php";
1327712358Sghiinclude_once DOKU_PLUGIN."bez/models/causes.php";
1427712358Sghiinclude_once DOKU_PLUGIN."bez/models/tasks.php";
15168ecf58Sghiinclude_once DOKU_PLUGIN."bez/models/taskactions.php";
165c4f5b95SSzymon Olewniczak
175c4f5b95SSzymon Olewniczakinclude_once DOKU_PLUGIN."bez/mdl/model.php";
185c4f5b95SSzymon Olewniczak
1965cfcae3Sghi/**
2065cfcae3Sghi * All DokuWiki plugins to extend the parser/rendering mechanism
2165cfcae3Sghi * need to inherit from this class
2265cfcae3Sghi */
2365cfcae3Sghiclass syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin {
247f226579Sghi	private $value = array();
2505c9d3bcSghi	private $lang_code = '';
2615487902Sghi	private $default_lang = 'pl';
2765cfcae3Sghi
285c4f5b95SSzymon Olewniczak	private $auth, $model, $validator;
295c4f5b95SSzymon Olewniczak
305536eef6Sghi    function getPType() { return 'block'; }
3165cfcae3Sghi    function getType() { return 'substition'; }
3265cfcae3Sghi    function getSort() { return 99; }
3365cfcae3Sghi
3465cfcae3Sghi
3565cfcae3Sghi    function connectTo($mode) {
3665cfcae3Sghi		$this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav');
3765cfcae3Sghi    }
3865cfcae3Sghi
397f226579Sghi	function __construct() {
405c4f5b95SSzymon Olewniczak		global $conf, $INFO, $auth;
4115487902Sghi
4215487902Sghi		$id = $_GET['id'];
4315487902Sghi
4415487902Sghi		/*usuń : z początku id - link bezwzględny*/
4515487902Sghi		if ($id[0] == ':')
4615487902Sghi			$id = substr($id, 1);
477f226579Sghi
487f226579Sghi		$ex = explode(':', $_GET['id']);
4915487902Sghi
5005c9d3bcSghi		//wielojęzyczność
5105c9d3bcSghi		if ($ex[1] == 'bez') {
5215487902Sghi			$this->lang_code = $ex[0];
5305c9d3bcSghi			$ex = array_slice($ex, 1);
5415487902Sghi
5515487902Sghi			$old_lang = $conf['lang'];
5615487902Sghi			$conf['lang'] = $this->lang_code;
5715487902Sghi			$this->setupLocale();
5815487902Sghi			$conf['lang'] = $old_lang;
5915487902Sghi
6015487902Sghi		} else {
6115487902Sghi			$this->lang_code = $conf['lang'];
6205c9d3bcSghi		}
6305c9d3bcSghi
647f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
657f226579Sghi			$this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
665c4f5b95SSzymon Olewniczak
675c4f5b95SSzymon Olewniczak		$this->model = new BEZ_mdl_Model($auth, $INFO['client'], $this->lang_code);
687f226579Sghi	}
697f226579Sghi
703b3e3ab0Sghi    function handle($match, $state, $pos, Doku_Handler $handler)
7165cfcae3Sghi    {
7265cfcae3Sghi		return true;
7365cfcae3Sghi    }
7465cfcae3Sghi
753b3e3ab0Sghi    function render($mode, Doku_Renderer $R, $pass) {
765c4f5b95SSzymon Olewniczak		global $INFO, $auth;
7765cfcae3Sghi
785536eef6Sghi		$helper = $this->loadHelper('bez');
7908e8ea12Sghi		if ($mode != 'xhtml' || !$helper->user_viewer()) return false;
8065cfcae3Sghi
8108e8ea12Sghi        $R->info['cache'] = false;
8208e8ea12Sghi
8308e8ea12Sghi		$data = array(
84a6dcc2a9Sghi			'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')),
8508e8ea12Sghi		);
8665cfcae3Sghi
87919e4830Sghi
884fb0d798Sghi		$data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bds_issues'));
8927712358Sghi
9027712358Sghi		$task_pages = array('issue_tasks', 'task_form', 'issue_task');
919fbfe943Sghi		$cause_pages = array('issue_causes', 'issue_cause', 'cause_form', 'issue_cause_task');
929a30fd19Sghi		$issue_pages = array_merge(array('issue', 'rr', '8d'), $task_pages, $cause_pages);
9327712358Sghi
946c94eb49Sghi		if ($this->value['bez'] == 'issues' || $this->value['bez'] == 'issue_report') {
956c94eb49Sghi			if ($helper->user_editor()) {
966c94eb49Sghi				$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 3, 'title' => $this->getLang('bds_issue_report'));
976c94eb49Sghi			}
986c94eb49Sghi			$data['bez:issues']['open'] = true;
996c94eb49Sghi		}
100168ecf58Sghi		if (in_array($this->value['bez'], $issue_pages) || ($this->value['bez'] == 'issue_report' && isset($this->value['id']))) {
1016c94eb49Sghi			if ($helper->user_editor()) {
1026c94eb49Sghi				$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 3, 'title' => $this->getLang('bds_issue_report'));
1036c94eb49Sghi			}
10427712358Sghi			$data['bez:issues']['open'] = true;
10527712358Sghi			$id = (int)$this->value[id];
10627712358Sghi
1079a30fd19Sghi			$isso = new Issues();
1089a30fd19Sghi			$issue_opened = $isso->opened($id);
109489061b8Sghi			$issue_proposal = $isso->is_proposal($id);
1109a30fd19Sghi
111ed77b00cSSzymon Olewniczak			$type = 'f';
112ed77b00cSSzymon Olewniczak
11327712358Sghi			$pid = "bez:issue:id:$id";
114ed77b00cSSzymon Olewniczak			$data[$pid] = array('id' => $pid, 'type' => $type, 'level' => 3,
11527712358Sghi												'title' => "#$id", 'open' => true);
11627712358Sghi		}
117919e4830Sghi
118919e4830Sghi
119168ecf58Sghi		$data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bez_tasks'));
120168ecf58Sghi
121168ecf58Sghi		if ($this->value['bez'] == 'tasks' || $this->value['bez'] == 'show_task'
122168ecf58Sghi			|| $this->value['bez'] == 'task_form_plan'
123168ecf58Sghi			|| $this->value['bez'] == 'issue_task'
124d6002863Sghi			|| $this->value['bez'] == 'task_form'
125*aa89e6f8SSzymon Olewniczak			|| $this->value['bez'] == 'task_form'
126168ecf58Sghi			|| $this->value['bez'] == 'issue_cause_task') {
127168ecf58Sghi			$data['bez:tasks']['open'] = true;
128168ecf58Sghi
129168ecf58Sghi			if (isset($this->value['year']))
130168ecf58Sghi				$year = $this->value['year'];
131168ecf58Sghi			else
132168ecf58Sghi				$year = date('Y');
133168ecf58Sghi
134168ecf58Sghi
135168ecf58Sghi			if (isset($this->value['tid'])) {
136168ecf58Sghi				$tasko = new Tasks();
137168ecf58Sghi				$this->value['tasktype']  = $tasko->get_type($this->value['tid']);
138168ecf58Sghi			}
139168ecf58Sghi
140168ecf58Sghi
141b609bf0aSghi			$page_id = "bez:tasks:tasktype:-none:year:$year";
142168ecf58Sghi			if (isset($this->value['tid']) && $this->value['tasktype'] == '') {
143b609bf0aSghi				$data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('tasks_no_type'), 'open' => true);
144168ecf58Sghi
14566f0c416SSzymon Olewniczak				$page_id = 'bez:show_task:tid:'.$this->value['tid'];
14666f0c416SSzymon Olewniczak				//$page_id = $_GET['id'];
147b609bf0aSghi				$data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => '#z'.$this->value['tid']);
148168ecf58Sghi
149168ecf58Sghi			} else {
150b609bf0aSghi				$data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 3, 'title' => $this->getLang('tasks_no_type'));
151168ecf58Sghi			}
152168ecf58Sghi
1535c4f5b95SSzymon Olewniczak			$tasktypes = $this->model->tasktypes->get_all();
1545c4f5b95SSzymon Olewniczak			foreach ($tasktypes as $tasktype) {
1555c4f5b95SSzymon Olewniczak				$page_id = "bez:tasks:tasktype:".$tasktype->id.":year:$year";
156168ecf58Sghi
1575c4f5b95SSzymon Olewniczak				if ($this->value['tasktype'] == $tasktype->id) {
1585c4f5b95SSzymon Olewniczak					$data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 3, 'title' => $tasktype->type, 'open' => true);
1595c4f5b95SSzymon Olewniczak
16000746146SSzymon Olewniczak					//~ if ($tasktype->get_level() >= 15) {
161*aa89e6f8SSzymon Olewniczak					$report_id = "bez:task_form:tasktype:".$tasktype->id;
1625c4f5b95SSzymon Olewniczak					$data[$report_id] = array('id' => $report_id, 'type' => 'f', 'level' => 4, 'title' => $this->getLang('bds_task_report'));
16300746146SSzymon Olewniczak					//~ }
1645c4f5b95SSzymon Olewniczak					if (isset($this->value['tid'])) {
16566f0c416SSzymon Olewniczak						$page_id = 'bez:show_task:tid:'.$this->value['tid'];
16666f0c416SSzymon Olewniczak						//$page_id = $_GET['id'];
167b609bf0aSghi						$data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => '#z'.$this->value['tid']);
1685c4f5b95SSzymon Olewniczak					}
1695c4f5b95SSzymon Olewniczak				} else {
1705c4f5b95SSzymon Olewniczak					$data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 3, 'title' => $tasktype->type);
1715c4f5b95SSzymon Olewniczak				}
172168ecf58Sghi			}
173168ecf58Sghi		}
17465cfcae3Sghi
1757f853d3aSghi		$isso = new Issues();
17697183698Sghi		$year_now = (int)date('Y');
17797183698Sghi		$mon_now = (int)date('n');
17897183698Sghi
17997183698Sghi		$data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report'));
1807f226579Sghi		if ($this->value['bez'] == 'report') {
1817f226579Sghi			$data['bez:report']['open'] = true;
1827f226579Sghi
183bb615297Sghi			$oldest = $isso->get_oldest_close_date();
1847e9a45a9Sghi			$year_old = (int)date('Y', $oldest);
1857e9a45a9Sghi			$mon_old = (int)date('n', $oldest);
1867e9a45a9Sghi
1877e9a45a9Sghi			$mon = $mon_old;
1887e9a45a9Sghi			for ($year = $year_old; $year <= $year_now; $year++) {
1897f226579Sghi
1907f226579Sghi				$y_key = 'bez:report:year:'.$year;
19138b5c5c4Sghi				$data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year);
1927f226579Sghi
1937f226579Sghi				if (isset($this->value['year']) && (int)$this->value['year'] == $year) {
1947f226579Sghi					$data['bez:report:year:'.$year]['open'] = true;
1957f226579Sghi
1967e9a45a9Sghi					if ($year == $year_now)
1977e9a45a9Sghi						$mon_max = $mon_now;
1987e9a45a9Sghi					else
1997e9a45a9Sghi						$mon_max = 12;
2007e9a45a9Sghi					for ( ; $mon <= $mon_max; $mon++) {
2017e9a45a9Sghi						$m_key = $y_key.':month:'.$mon;
20238b5c5c4Sghi						$data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4,
2037e9a45a9Sghi						'title' => $mon < 10 ? '0'.$mon : $mon);
2047e9a45a9Sghi					}
2057f226579Sghi				}
2067e9a45a9Sghi				$mon = 1;
2077e9a45a9Sghi			}
2087f226579Sghi		}
2093cc1f839Sghi
2107c304d96SSzymon Olewniczak		$data['bez:activity_report'] = array('id' => 'bez:activity_report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('activity_report'));
2117c304d96SSzymon Olewniczak		if ($this->value['bez'] == 'activity_report') {
2127c304d96SSzymon Olewniczak			$data['bez:activity_report']['open'] = true;
2137c304d96SSzymon Olewniczak
2147c304d96SSzymon Olewniczak			$oldest = $isso->get_oldest_close_date();
2157c304d96SSzymon Olewniczak			$year_old = (int)date('Y', $oldest);
2167c304d96SSzymon Olewniczak			$mon_old = (int)date('n', $oldest);
2177c304d96SSzymon Olewniczak
2187c304d96SSzymon Olewniczak			$mon = $mon_old;
2197c304d96SSzymon Olewniczak			for ($year = $year_old; $year <= $year_now; $year++) {
2207c304d96SSzymon Olewniczak
2217c304d96SSzymon Olewniczak				$y_key = 'bez:activity_report:year:'.$year;
2227c304d96SSzymon Olewniczak				$data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year);
2237c304d96SSzymon Olewniczak
2247c304d96SSzymon Olewniczak				if (isset($this->value['year']) && (int)$this->value['year'] == $year) {
2257c304d96SSzymon Olewniczak					$data['bez:activity_report:year:'.$year]['open'] = true;
2267c304d96SSzymon Olewniczak
2277c304d96SSzymon Olewniczak					if ($year == $year_now)
2287c304d96SSzymon Olewniczak						$mon_max = $mon_now;
2297c304d96SSzymon Olewniczak					else
2307c304d96SSzymon Olewniczak						$mon_max = 12;
2317c304d96SSzymon Olewniczak					for ( ; $mon <= $mon_max; $mon++) {
2327c304d96SSzymon Olewniczak						$m_key = $y_key.':month:'.$mon;
2337c304d96SSzymon Olewniczak						$data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4,
2347c304d96SSzymon Olewniczak						'title' => $mon < 10 ? '0'.$mon : $mon);
2357c304d96SSzymon Olewniczak					}
2367c304d96SSzymon Olewniczak				}
2377c304d96SSzymon Olewniczak				$mon = 1;
2387c304d96SSzymon Olewniczak			}
2397c304d96SSzymon Olewniczak		}
2407c304d96SSzymon Olewniczak
24108e8ea12Sghi
242f01326efSghi
2437f226579Sghi		if (isset($this->value['bez'])) {
244a42d0169Sghi			$data['bez:start']['open'] = true;
24508e8ea12Sghi		} else {
246a42d0169Sghi			$data['bez:start']['open'] = false;
24708e8ea12Sghi			array_splice($data, 1);
24808e8ea12Sghi		}
24908e8ea12Sghi
25080487b8aSghi		if ($helper->user_admin() && $data['bez:start']['open'] == true) {
25180487b8aSghi			$data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' =>
25280487b8aSghi				$this->getLang('types_manage'));
2532cee2e45SSzymon Olewniczak			//~ $data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' =>
2542cee2e45SSzymon Olewniczak				//~ $this->getLang('root_causes'));
255168ecf58Sghi			$data['bez:task_types'] = array('id' => 'bez:task_types', 'type' => 'f', 'level' => 2, 'title' =>
256168ecf58Sghi				$this->getLang('task_types'));
25780487b8aSghi		}
2587f226579Sghi
25908e8ea12Sghi        $R->doc .= '<div class="plugin__bez">';
26008e8ea12Sghi        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
26108e8ea12Sghi        $R->doc .= '</div>';
26208e8ea12Sghi
2635536eef6Sghi		return true;
26408e8ea12Sghi	}
265da9ebf75Sghi
26608e8ea12Sghi	function _bezlink($id, $title) {
2677f226579Sghi		//$uri = wl($id);
2687f226579Sghi		$uri = DOKU_URL . 'doku.php?id='.$id;
269a6dcc2a9Sghi		return '<a href="'.$uri.'">'.($title).'</a>';
27008e8ea12Sghi	}
27108e8ea12Sghi
27208e8ea12Sghi    function _list($item){
27308e8ea12Sghi
2747f226579Sghi		$ex = explode(':', $item['id']);
27505c9d3bcSghi
2767f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
2777f226579Sghi			$item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
2787f226579Sghi
2797f226579Sghi		//pola brane pod uwagę przy określaniu aktualnej strony
280168ecf58Sghi		$fields = array('bez', 'tid', 'cid', 'tasktype', 'taskstate');
2817c304d96SSzymon Olewniczak		if ($item_value['bez'] == 'report' || $item_value['bez'] == 'activity_report') {
2827f226579Sghi			$fields[] = 'month';
2837f226579Sghi			$fields[] = 'year';
2847f226579Sghi		}
285*aa89e6f8SSzymon Olewniczak//		if ($this->value[bez] == 'task_form' && isset($this->value[cid]))
286*aa89e6f8SSzymon Olewniczak//			unset($fields[0]);
2877f226579Sghi
2887f226579Sghi		$actual_page = true;
2897f226579Sghi		foreach ($fields as $field)
2907f226579Sghi			if ($item_value[$field] != $this->value[$field])
2917f226579Sghi				$actual_page = false;
2927f226579Sghi
293168ecf58Sghi		//specjalny hak dla zadań, boję się ruszać całej procedury
294168ecf58Sghi		if ($item_value['bez'] == 'issue_task' ||
295168ecf58Sghi			$item_value['bez'] == 'issue_cause_task' ||
296d6002863Sghi			$item_value['bez'] == 'task_form' ||
297168ecf58Sghi			$item_value['bez'] == 'show_task')
298168ecf58Sghi				if ($item_value['tid'] == $this->value['tid'])
299168ecf58Sghi					$actual_page = true;
3007f226579Sghi
3017f226579Sghi        if(($item['type'] == 'd' && $item['open']) ||  $actual_page) {
30215487902Sghi			$id = $item['id'];
30315487902Sghi			if ($this->lang_code != $this->default_lang)
30415487902Sghi				$id = $this->lang_code.':'.$id;
30515487902Sghi            return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>';
30608e8ea12Sghi        }else{
30715487902Sghi			$id = $item['id'];
30815487902Sghi			if ($this->lang_code != $this->default_lang)
30915487902Sghi				$id = $this->lang_code.':'.$id;
31015487902Sghi            return $this->_bezlink($id, $item['title']);
31108e8ea12Sghi        }
31208e8ea12Sghi
31308e8ea12Sghi    }
31408e8ea12Sghi
31508e8ea12Sghi    function _li($item){
31608e8ea12Sghi        if($item['type'] == "f"){
31708e8ea12Sghi            return '<li class="level'.$item['level'].'">';
31808e8ea12Sghi        }elseif($item['open']){
31908e8ea12Sghi            return '<li class="open">';
32008e8ea12Sghi        }else{
32108e8ea12Sghi            return '<li class="closed">';
32208e8ea12Sghi        }
32365cfcae3Sghi    }
32465cfcae3Sghi}
325