xref: /plugin/bez/syntax/nav.php (revision d6002863ed649bcc6a7301ca988622c05c6727b3)
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";
16168ecf58Sghiinclude_once DOKU_PLUGIN."bez/models/tasktypes.php";
1765cfcae3Sghi/**
1865cfcae3Sghi * All DokuWiki plugins to extend the parser/rendering mechanism
1965cfcae3Sghi * need to inherit from this class
2065cfcae3Sghi */
2165cfcae3Sghiclass syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin {
227f226579Sghi	private $value = array();
2305c9d3bcSghi	private $lang_code = '';
2415487902Sghi	private $default_lang = 'pl';
2565cfcae3Sghi
265536eef6Sghi    function getPType() { return 'block'; }
2765cfcae3Sghi    function getType() { return 'substition'; }
2865cfcae3Sghi    function getSort() { return 99; }
2965cfcae3Sghi
3065cfcae3Sghi
3165cfcae3Sghi    function connectTo($mode) {
3265cfcae3Sghi		$this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav');
3365cfcae3Sghi    }
3465cfcae3Sghi
357f226579Sghi	function __construct() {
3615487902Sghi		global $conf;
3715487902Sghi
3815487902Sghi		$id = $_GET['id'];
3915487902Sghi
4015487902Sghi		/*usuń : z początku id - link bezwzględny*/
4115487902Sghi		if ($id[0] == ':')
4215487902Sghi			$id = substr($id, 1);
437f226579Sghi
447f226579Sghi		$ex = explode(':', $_GET['id']);
4515487902Sghi
4605c9d3bcSghi		//wielojęzyczność
4705c9d3bcSghi		if ($ex[1] == 'bez') {
4815487902Sghi			$this->lang_code = $ex[0];
4905c9d3bcSghi			$ex = array_slice($ex, 1);
5015487902Sghi
5115487902Sghi			$old_lang = $conf['lang'];
5215487902Sghi			$conf['lang'] = $this->lang_code;
5315487902Sghi			$this->setupLocale();
5415487902Sghi			$conf['lang'] = $old_lang;
5515487902Sghi
5615487902Sghi		} else {
5715487902Sghi			$this->lang_code = $conf['lang'];
5805c9d3bcSghi		}
5905c9d3bcSghi
607f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
617f226579Sghi			$this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
627f226579Sghi	}
637f226579Sghi
643b3e3ab0Sghi    function handle($match, $state, $pos, Doku_Handler $handler)
6565cfcae3Sghi    {
6665cfcae3Sghi		return true;
6765cfcae3Sghi    }
6865cfcae3Sghi
693b3e3ab0Sghi    function render($mode, Doku_Renderer $R, $pass) {
7008e8ea12Sghi		global $INFO;
7165cfcae3Sghi
725536eef6Sghi		$helper = $this->loadHelper('bez');
7308e8ea12Sghi		if ($mode != 'xhtml' || !$helper->user_viewer()) return false;
7465cfcae3Sghi
7508e8ea12Sghi        $R->info['cache'] = false;
7608e8ea12Sghi
7708e8ea12Sghi		$data = array(
78a6dcc2a9Sghi			'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')),
7908e8ea12Sghi		);
8065cfcae3Sghi
81ecefc57aSghi		if ($helper->user_editor()) {
82a6dcc2a9Sghi			$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report'));
83ecefc57aSghi			$data['bez:task_report'] = array('id' => 'bez:task_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_task_report'));
84a6dcc2a9Sghi
85ecefc57aSghi		}
864fb0d798Sghi		$data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bds_issues'));
8727712358Sghi
8827712358Sghi		$task_pages = array('issue_tasks', 'task_form', 'issue_task');
899fbfe943Sghi		$cause_pages = array('issue_causes', 'issue_cause', 'cause_form', 'issue_cause_task');
909a30fd19Sghi		$issue_pages = array_merge(array('issue', 'rr', '8d'), $task_pages, $cause_pages);
9127712358Sghi
92168ecf58Sghi		if (in_array($this->value['bez'], $issue_pages) || ($this->value['bez'] == 'issue_report' && isset($this->value['id']))) {
9327712358Sghi			$data['bez:issues']['open'] = true;
9427712358Sghi			$id = (int)$this->value[id];
9527712358Sghi
969a30fd19Sghi			$isso = new Issues();
979a30fd19Sghi			$issue_opened = $isso->opened($id);
98489061b8Sghi			$issue_proposal = $isso->is_proposal($id);
999a30fd19Sghi
10027712358Sghi			$tasko = new Tasks();
10127712358Sghi			$causo = new Causes();
10227712358Sghi
10327712358Sghi			$pid = "bez:issue:id:$id";
10427712358Sghi			$data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 3,
10527712358Sghi												'title' => "#$id", 'open' => true);
10627712358Sghi
10727712358Sghi			$pid = "bez:issue_tasks:id:$id";
10827712358Sghi			$data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4,
1099fbfe943Sghi								'title' => $this->getLang('correction_nav'));
1109fbfe943Sghi			if (in_array($this->value['bez'], $task_pages) && $this->value[cid] == '') {
11127712358Sghi				$data[$pid][open] = true;
1129a30fd19Sghi
1139a30fd19Sghi				if ($issue_opened) {
11427712358Sghi					$rpid = "bez:task_form:id:$id";
115489061b8Sghi					if ($helper->user_admin() && !$issue_proposal)
11627712358Sghi						$data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5,
11727712358Sghi											'title' => $this->getLang('add_correction'));
1189a30fd19Sghi				}
1199fbfe943Sghi				$res = $tasko->get_filtered(array('issue' => $id, 'action' => '0'));
12027712358Sghi				foreach ($res as $r) {
12127712358Sghi					$rpid = "bez:issue_task:id:$id:tid:$r[id]";
12227712358Sghi					$data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5,
12327712358Sghi										'title' => '#z'.$r[id]);
12427712358Sghi				}
12527712358Sghi			}
12627712358Sghi
12727712358Sghi			$pid = "bez:issue_causes:id:$id";
12827712358Sghi			$data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4,
12927712358Sghi								'title' => $this->getLang('causes'));
1309fbfe943Sghi			if (in_array($this->value['bez'], $cause_pages) || $this->value[cid] != '') {
13127712358Sghi				$data[$pid][open] = true;
1329a30fd19Sghi				if ($issue_opened) {
13327712358Sghi					$rpid = "bez:cause_form:id:$id";
134489061b8Sghi					if ($helper->user_admin() && !$issue_proposal)
13527712358Sghi						$data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5,
13627712358Sghi											'title' => $this->getLang('add_cause'));
1379a30fd19Sghi				}
1389fbfe943Sghi				$res = $causo->get($id);
13927712358Sghi				foreach ($res as $r) {
14027712358Sghi					$rpid = "bez:issue_cause:id:$id:cid:$r[id]";
1419fbfe943Sghi					$data[$rpid] = array('id' => $rpid, 'type' => 'd', 'level' => 5,
14227712358Sghi										'title' => '#p'.$r[id]);
1439fbfe943Sghi
14427712358Sghi					if ((int)$this->value['cid'] == $r[id]) {
14527712358Sghi						$data[$rpid][open] = true;
14627712358Sghi
14727712358Sghi						$pres = $tasko->get($id, $r['id']);
14827712358Sghi						foreach ($pres as $pr) {
1499fbfe943Sghi							$rptid = "bez:issue_cause_task:id:$id:cid:$r[id]:tid:$pr[id]";
1509fbfe943Sghi							$data[$rptid] = array('id' => $rptid, 'type' => 'f', 'level' => 6,
1519fbfe943Sghi										'title' => '#z'.$pr[id]);
1529fbfe943Sghi
15327712358Sghi						}
15427712358Sghi					}
1559fbfe943Sghi				}
15627712358Sghi
15727712358Sghi			}
15827712358Sghi
15927712358Sghi		}
160168ecf58Sghi		$data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bez_tasks'));
161168ecf58Sghi
162168ecf58Sghi		if ($this->value['bez'] == 'tasks' || $this->value['bez'] == 'show_task'
163168ecf58Sghi			|| $this->value['bez'] == 'task_form_plan'
164168ecf58Sghi			|| $this->value['bez'] == 'issue_task'
165*d6002863Sghi			|| $this->value['bez'] == 'task_form'
166168ecf58Sghi			|| $this->value['bez'] == 'issue_cause_task') {
167168ecf58Sghi			$data['bez:tasks']['open'] = true;
168168ecf58Sghi
169168ecf58Sghi
170168ecf58Sghi			if (isset($this->value['year']))
171168ecf58Sghi				$year = $this->value['year'];
172168ecf58Sghi			else
173168ecf58Sghi				$year = date('Y');
174168ecf58Sghi
175168ecf58Sghi			//plan i realizacja
176168ecf58Sghi			$plan_id = "bez:tasks:taskstate:0$tasktype:year:$year";
177168ecf58Sghi			$data[$plan_id] = array('id' => $plan_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('task_opened'));
178168ecf58Sghi
179168ecf58Sghi			if (isset($this->value['tid'])) {
180168ecf58Sghi				$tasko = new Tasks();
181168ecf58Sghi				$this->value['tasktype']  = $tasko->get_type($this->value['tid']);
182168ecf58Sghi				$tasko = new Tasks();
183168ecf58Sghi				$this->value['taskstate'] = $tasko->get_state($this->value['tid']);
184168ecf58Sghi			}
185168ecf58Sghi
186168ecf58Sghi			if (isset($this->value['taskstate'])) {
187168ecf58Sghi				if ($this->value['taskstate'] == '0') {
188168ecf58Sghi					$data[$plan_id]['open'] = true;
189168ecf58Sghi				} elseif ($this->value['taskstate'] == '1') {
190168ecf58Sghi					$realization_id = "bez:tasks:taskstate:1:year:$year";
191168ecf58Sghi					$data[$realization_id] = array('id' => $realization_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('task_done'), 'open' => true);
192168ecf58Sghi				} elseif ($this->value['taskstate'] == '2') {
193168ecf58Sghi					$realization_id = "bez:tasks:taskstate:1:year:$year";
194168ecf58Sghi					$data[$realization_id] = array('id' => $realization_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('task_done'), 'open' => false);
195168ecf58Sghi					$rejected_id = "bez:tasks:taskstate:2:year:$year";
196168ecf58Sghi					$data[$rejected_id] = array('id' => $rejected_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('task_rejected'), 'open' => true);
197168ecf58Sghi				}
198168ecf58Sghi
199168ecf58Sghi			} else {
200168ecf58Sghi				$realization_id = "bez:tasks:taskstate:1:year:$year";
201168ecf58Sghi				$data[$realization_id] = array('id' => $realization_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('task_done'), 'open' => false);
202168ecf58Sghi				$rejected_id = "bez:tasks:taskstate:2:year:$year";
203168ecf58Sghi				$data[$rejected_id] = array('id' => $rejected_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('task_rejected'), 'open' => false);
204168ecf58Sghi			}
205168ecf58Sghi
206168ecf58Sghi
207168ecf58Sghi
208168ecf58Sghi			if (isset($this->value['taskstate'])) {
209168ecf58Sghi				$taskstate = ':taskstate:'.$this->value['taskstate'];
210168ecf58Sghi				$tasktypeso = new Tasktypes();
211168ecf58Sghi				$tasktypes = $tasktypeso->get();
212168ecf58Sghi				$page_id = "bez:tasks$taskstate:tasktype:-none:year:$year";
213168ecf58Sghi				if (isset($this->value['tid']) && $this->value['tasktype'] == '') {
214168ecf58Sghi					$data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 4, 'title' => $this->getLang('tasks_no_type'), 'open' => true);
215168ecf58Sghi
216168ecf58Sghi					//$page_id = 'bez:show_task:tid:'.$this->value['tid'];
217168ecf58Sghi					$page_id = $_GET['id'];
218168ecf58Sghi					$data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 5, 'title' => '#z'.$this->value['tid']);
219168ecf58Sghi
220168ecf58Sghi				} else {
221168ecf58Sghi					$data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => $this->getLang('tasks_no_type'));
222168ecf58Sghi				}
223168ecf58Sghi
224168ecf58Sghi
225168ecf58Sghi				foreach ($tasktypes as $id => $tasktype) {
226168ecf58Sghi					$page_id = "bez:tasks$taskstate:tasktype:$id:year:$year";
227168ecf58Sghi					if (isset($this->value['tid']) && $this->value['tasktype'] == $id) {
228168ecf58Sghi						$data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 4, 'title' => $tasktype, 'open' => true);
229168ecf58Sghi						//$page_id = 'bez:show_task:tid:'.$this->value['tid'];
230168ecf58Sghi						$page_id = $_GET['id'];
231168ecf58Sghi						$data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 5, 'title' => '#z'.$this->value['tid']);
232168ecf58Sghi					} else
233168ecf58Sghi						$data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => $tasktype);
234168ecf58Sghi				}
235168ecf58Sghi
236168ecf58Sghi				if ($this->value['taskstate'] == '0') {
237168ecf58Sghi					$realization_id = "bez:tasks:taskstate:1:year:$year";
238168ecf58Sghi					$data[$realization_id] = array('id' => $realization_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('task_done'), 'open' => false);
239168ecf58Sghi					$rejected_id = "bez:tasks:taskstate:2:year:$year";
240168ecf58Sghi					$data[$rejected_id] = array('id' => $rejected_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('task_rejected'), 'open' => false);
241168ecf58Sghi				} else if ($this->value['taskstate'] == '1') {
242168ecf58Sghi					$rejected_id = "bez:tasks:taskstate:2:year:$year";
243168ecf58Sghi					$data[$rejected_id] = array('id' => $rejected_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('task_rejected'), 'open' => false);
244168ecf58Sghi				}
245168ecf58Sghi			}
246168ecf58Sghi
247168ecf58Sghi		}
24865cfcae3Sghi
2497f853d3aSghi		$isso = new Issues();
25097183698Sghi		$year_now = (int)date('Y');
25197183698Sghi		$mon_now = (int)date('n');
25297183698Sghi
25397183698Sghi		$data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report'));
2547f226579Sghi		if ($this->value['bez'] == 'report') {
2557f226579Sghi			$data['bez:report']['open'] = true;
2567f226579Sghi
257bb615297Sghi			$oldest = $isso->get_oldest_close_date();
2587e9a45a9Sghi			$year_old = (int)date('Y', $oldest);
2597e9a45a9Sghi			$mon_old = (int)date('n', $oldest);
2607e9a45a9Sghi
2617e9a45a9Sghi			$mon = $mon_old;
2627e9a45a9Sghi			for ($year = $year_old; $year <= $year_now; $year++) {
2637f226579Sghi
2647f226579Sghi				$y_key = 'bez:report:year:'.$year;
26538b5c5c4Sghi				$data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year);
2667f226579Sghi
2677f226579Sghi				if (isset($this->value['year']) && (int)$this->value['year'] == $year) {
2687f226579Sghi					$data['bez:report:year:'.$year]['open'] = true;
2697f226579Sghi
2707e9a45a9Sghi					if ($year == $year_now)
2717e9a45a9Sghi						$mon_max = $mon_now;
2727e9a45a9Sghi					else
2737e9a45a9Sghi						$mon_max = 12;
2747e9a45a9Sghi					for ( ; $mon <= $mon_max; $mon++) {
2757e9a45a9Sghi						$m_key = $y_key.':month:'.$mon;
27638b5c5c4Sghi						$data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4,
2777e9a45a9Sghi						'title' => $mon < 10 ? '0'.$mon : $mon);
2787e9a45a9Sghi					}
2797f226579Sghi				}
2807e9a45a9Sghi				$mon = 1;
2817e9a45a9Sghi			}
2827f226579Sghi		}
2833cc1f839Sghi
28408e8ea12Sghi
285f01326efSghi
2867f226579Sghi		if (isset($this->value['bez'])) {
287a42d0169Sghi			$data['bez:start']['open'] = true;
28808e8ea12Sghi		} else {
289a42d0169Sghi			$data['bez:start']['open'] = false;
29008e8ea12Sghi			array_splice($data, 1);
29108e8ea12Sghi		}
29208e8ea12Sghi
29380487b8aSghi		if ($helper->user_admin() && $data['bez:start']['open'] == true) {
29480487b8aSghi			$data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' =>
29580487b8aSghi				$this->getLang('types_manage'));
29680487b8aSghi			$data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' =>
29780487b8aSghi				$this->getLang('root_causes'));
298168ecf58Sghi			$data['bez:task_types'] = array('id' => 'bez:task_types', 'type' => 'f', 'level' => 2, 'title' =>
299168ecf58Sghi				$this->getLang('task_types'));
30080487b8aSghi		}
3017f226579Sghi
30208e8ea12Sghi        $R->doc .= '<div class="plugin__bez">';
30308e8ea12Sghi        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
30408e8ea12Sghi        $R->doc .= '</div>';
30508e8ea12Sghi
3065536eef6Sghi		return true;
30708e8ea12Sghi	}
308da9ebf75Sghi
30908e8ea12Sghi	function _bezlink($id, $title) {
3107f226579Sghi		//$uri = wl($id);
3117f226579Sghi		$uri = DOKU_URL . 'doku.php?id='.$id;
312a6dcc2a9Sghi		return '<a href="'.$uri.'">'.($title).'</a>';
31308e8ea12Sghi	}
31408e8ea12Sghi
31508e8ea12Sghi    function _list($item){
31608e8ea12Sghi
3177f226579Sghi		$ex = explode(':', $item['id']);
31805c9d3bcSghi
3197f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
3207f226579Sghi			$item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
3217f226579Sghi
3227f226579Sghi		//pola brane pod uwagę przy określaniu aktualnej strony
323168ecf58Sghi		$fields = array('bez', 'tid', 'cid', 'tasktype', 'taskstate');
32497183698Sghi		if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') {
3257f226579Sghi			$fields[] = 'month';
3267f226579Sghi			$fields[] = 'year';
3277f226579Sghi		}
3289fbfe943Sghi		if ($this->value[bez] == 'task_form' && isset($this->value[cid]))
3299fbfe943Sghi			unset($fields[0]);
3307f226579Sghi
3317f226579Sghi		$actual_page = true;
3327f226579Sghi		foreach ($fields as $field)
3337f226579Sghi			if ($item_value[$field] != $this->value[$field])
3347f226579Sghi				$actual_page = false;
3357f226579Sghi
336168ecf58Sghi		//specjalny hak dla zadań, boję się ruszać całej procedury
337168ecf58Sghi		if ($item_value['bez'] == 'issue_task' ||
338168ecf58Sghi			$item_value['bez'] == 'issue_cause_task' ||
339*d6002863Sghi			$item_value['bez'] == 'task_form' ||
340168ecf58Sghi			$item_value['bez'] == 'show_task')
341168ecf58Sghi				if ($item_value['tid'] == $this->value['tid'])
342168ecf58Sghi					$actual_page = true;
3437f226579Sghi
3447f226579Sghi        if(($item['type'] == 'd' && $item['open']) ||  $actual_page) {
34515487902Sghi			$id = $item['id'];
34615487902Sghi			if ($this->lang_code != $this->default_lang)
34715487902Sghi				$id = $this->lang_code.':'.$id;
34815487902Sghi            return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>';
34908e8ea12Sghi        }else{
35015487902Sghi			$id = $item['id'];
35115487902Sghi			if ($this->lang_code != $this->default_lang)
35215487902Sghi				$id = $this->lang_code.':'.$id;
35315487902Sghi            return $this->_bezlink($id, $item['title']);
35408e8ea12Sghi        }
35508e8ea12Sghi
35608e8ea12Sghi    }
35708e8ea12Sghi
35808e8ea12Sghi    function _li($item){
35908e8ea12Sghi        if($item['type'] == "f"){
36008e8ea12Sghi            return '<li class="level'.$item['level'].'">';
36108e8ea12Sghi        }elseif($item['open']){
36208e8ea12Sghi            return '<li class="open">';
36308e8ea12Sghi        }else{
36408e8ea12Sghi            return '<li class="closed">';
36508e8ea12Sghi        }
36665cfcae3Sghi    }
36765cfcae3Sghi}
368