xref: /plugin/bez/syntax/nav.php (revision 2106ae3bda7f866f86f737c14bd176000dea05bd)
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";
1565cfcae3Sghi/**
1665cfcae3Sghi * All DokuWiki plugins to extend the parser/rendering mechanism
1765cfcae3Sghi * need to inherit from this class
1865cfcae3Sghi */
1965cfcae3Sghiclass syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin {
207f226579Sghi	private $value = array();
2105c9d3bcSghi	private $lang_code = '';
2215487902Sghi	private $default_lang = 'pl';
2365cfcae3Sghi
245536eef6Sghi    function getPType() { return 'block'; }
2565cfcae3Sghi    function getType() { return 'substition'; }
2665cfcae3Sghi    function getSort() { return 99; }
2765cfcae3Sghi
2865cfcae3Sghi
2965cfcae3Sghi    function connectTo($mode) {
3065cfcae3Sghi		$this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav');
3165cfcae3Sghi    }
3265cfcae3Sghi
337f226579Sghi	function __construct() {
3415487902Sghi		global $conf;
3515487902Sghi
3615487902Sghi		$id = $_GET['id'];
3715487902Sghi
3815487902Sghi		/*usuń : z początku id - link bezwzględny*/
3915487902Sghi		if ($id[0] == ':')
4015487902Sghi			$id = substr($id, 1);
417f226579Sghi
427f226579Sghi		$ex = explode(':', $_GET['id']);
4315487902Sghi
4405c9d3bcSghi		//wielojęzyczność
4505c9d3bcSghi		if ($ex[1] == 'bez') {
4615487902Sghi			$this->lang_code = $ex[0];
4705c9d3bcSghi			$ex = array_slice($ex, 1);
4815487902Sghi
4915487902Sghi			$old_lang = $conf['lang'];
5015487902Sghi			$conf['lang'] = $this->lang_code;
5115487902Sghi			$this->setupLocale();
5215487902Sghi			$conf['lang'] = $old_lang;
5315487902Sghi
5415487902Sghi		} else {
5515487902Sghi			$this->lang_code = $conf['lang'];
5605c9d3bcSghi		}
5705c9d3bcSghi
587f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
597f226579Sghi			$this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
607f226579Sghi	}
617f226579Sghi
6265cfcae3Sghi    function handle($match, $state, $pos, &$handler)
6365cfcae3Sghi    {
6465cfcae3Sghi		return true;
6565cfcae3Sghi    }
6665cfcae3Sghi
6708e8ea12Sghi    function render($mode, &$R, $pass) {
6808e8ea12Sghi		global $INFO;
6965cfcae3Sghi
705536eef6Sghi		$helper = $this->loadHelper('bez');
7108e8ea12Sghi		if ($mode != 'xhtml' || !$helper->user_viewer()) return false;
7265cfcae3Sghi
7308e8ea12Sghi        $R->info['cache'] = false;
7408e8ea12Sghi
7508e8ea12Sghi		$data = array(
76a6dcc2a9Sghi			'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')),
7708e8ea12Sghi		);
7865cfcae3Sghi
795536eef6Sghi		if ($helper->user_editor())
80a6dcc2a9Sghi			$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report'));
81a6dcc2a9Sghi
8227712358Sghi		$data['bez:issues'] = array('id' => 'bez:issues:year:'.date('Y'), 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bds_issues'));
8327712358Sghi
8427712358Sghi		$task_pages = array('issue_tasks', 'task_form', 'issue_task');
859fbfe943Sghi		$cause_pages = array('issue_causes', 'issue_cause', 'cause_form', 'issue_cause_task');
869a30fd19Sghi		$issue_pages = array_merge(array('issue', 'rr', '8d'), $task_pages, $cause_pages);
8727712358Sghi
887ffa8289Sghi		if (in_array($this->value['bez'], $issue_pages) || ($this->value[bez] == 'issue_report' && isset($this->value[id]))) {
8927712358Sghi			$data['bez:issues']['open'] = true;
9027712358Sghi			$id = (int)$this->value[id];
9127712358Sghi
929a30fd19Sghi			$isso = new Issues();
939a30fd19Sghi			$issue_opened = $isso->opened($id);
949a30fd19Sghi
9527712358Sghi			$tasko = new Tasks();
9627712358Sghi			$causo = new Causes();
9727712358Sghi
9827712358Sghi			$pid = "bez:issue:id:$id";
9927712358Sghi			$data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 3,
10027712358Sghi												'title' => "#$id", 'open' => true);
10127712358Sghi
10227712358Sghi			$pid = "bez:issue_tasks:id:$id";
10327712358Sghi			$data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4,
1049fbfe943Sghi								'title' => $this->getLang('correction_nav'));
1059fbfe943Sghi			if (in_array($this->value['bez'], $task_pages) && $this->value[cid] == '') {
10627712358Sghi				$data[$pid][open] = true;
1079a30fd19Sghi
1089a30fd19Sghi				if ($issue_opened) {
10927712358Sghi					$rpid = "bez:task_form:id:$id";
11027712358Sghi					$data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5,
11127712358Sghi											'title' => $this->getLang('add_correction'));
1129a30fd19Sghi				}
1139fbfe943Sghi				$res = $tasko->get_filtered(array('issue' => $id, 'action' => '0'));
11427712358Sghi				foreach ($res as $r) {
11527712358Sghi					$rpid = "bez:issue_task:id:$id:tid:$r[id]";
11627712358Sghi					$data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5,
11727712358Sghi										'title' => '#z'.$r[id]);
11827712358Sghi				}
11927712358Sghi			}
12027712358Sghi
12127712358Sghi			$pid = "bez:issue_causes:id:$id";
12227712358Sghi			$data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4,
12327712358Sghi								'title' => $this->getLang('causes'));
1249fbfe943Sghi			if (in_array($this->value['bez'], $cause_pages) || $this->value[cid] != '') {
12527712358Sghi				$data[$pid][open] = true;
1269a30fd19Sghi				if ($issue_opened) {
12727712358Sghi					$rpid = "bez:cause_form:id:$id";
12827712358Sghi					$data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5,
12927712358Sghi											'title' => $this->getLang('add_cause'));
1309a30fd19Sghi				}
1319fbfe943Sghi				$res = $causo->get($id);
13227712358Sghi				foreach ($res as $r) {
13327712358Sghi					$rpid = "bez:issue_cause:id:$id:cid:$r[id]";
1349fbfe943Sghi					$data[$rpid] = array('id' => $rpid, 'type' => 'd', 'level' => 5,
13527712358Sghi										'title' => '#p'.$r[id]);
1369fbfe943Sghi
13727712358Sghi					if ((int)$this->value['cid'] == $r[id]) {
13827712358Sghi						$data[$rpid][open] = true;
13927712358Sghi
14027712358Sghi						$pres = $tasko->get($id, $r['id']);
14127712358Sghi						foreach ($pres as $pr) {
1429fbfe943Sghi							$rptid = "bez:issue_cause_task:id:$id:cid:$r[id]:tid:$pr[id]";
1439fbfe943Sghi							$data[$rptid] = array('id' => $rptid, 'type' => 'f', 'level' => 6,
1449fbfe943Sghi										'title' => '#z'.$pr[id]);
1459fbfe943Sghi
14627712358Sghi						}
14727712358Sghi					}
1489fbfe943Sghi				}
14927712358Sghi
15027712358Sghi			}
15127712358Sghi
15227712358Sghi		}
153bb615297Sghi		$data['bez:tasks'] = array('id' => 'bez:tasks:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks'));
15465cfcae3Sghi
15597183698Sghi		$data['bez:report_open'] = array('id' => 'bez:report_open', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report_open'));
1567e9a45a9Sghi
1577f853d3aSghi		$isso = new Issues();
15897183698Sghi		$year_now = (int)date('Y');
15997183698Sghi		$mon_now = (int)date('n');
16097183698Sghi
16197183698Sghi		if ($this->value['bez'] == 'report_open') {
16297183698Sghi			$data['bez:report_open']['open'] = true;
16397183698Sghi
16497183698Sghi			$oldest = $isso->get_oldest_open_date();
16597183698Sghi			$year_old = (int)date('Y', $oldest);
16697183698Sghi			$mon_old = (int)date('n', $oldest);
16797183698Sghi
16897183698Sghi			$mon = $mon_old;
16997183698Sghi			for ($year = $year_old; $year <= $year_now; $year++) {
17097183698Sghi				$y_key = 'bez:report_open:year:'.$year;
17197183698Sghi				$data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year);
17297183698Sghi
17397183698Sghi				if (isset($this->value['year']) && (int)$this->value['year'] == $year) {
17497183698Sghi					$data['bez:report_open:year:'.$year]['open'] = true;
17597183698Sghi
17697183698Sghi					if ($year == $year_now)
17797183698Sghi						$mon_max = $mon_now;
17897183698Sghi					else
17997183698Sghi						$mon_max = 12;
18097183698Sghi					for ( ; $mon <= $mon_max; $mon++) {
18197183698Sghi						$m_key = $y_key.':month:'.$mon;
18297183698Sghi						$data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4,
18397183698Sghi						'title' => $mon < 10 ? '0'.$mon : $mon);
18497183698Sghi					}
18597183698Sghi				}
18697183698Sghi				$mon = 1;
18797183698Sghi			}
18897183698Sghi		}
18997183698Sghi
19097183698Sghi		$data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report'));
1917f226579Sghi		if ($this->value['bez'] == 'report') {
1927f226579Sghi			$data['bez:report']['open'] = true;
1937f226579Sghi
194bb615297Sghi			$oldest = $isso->get_oldest_close_date();
1957e9a45a9Sghi			$year_old = (int)date('Y', $oldest);
1967e9a45a9Sghi			$mon_old = (int)date('n', $oldest);
1977e9a45a9Sghi
1987e9a45a9Sghi			$mon = $mon_old;
1997e9a45a9Sghi			for ($year = $year_old; $year <= $year_now; $year++) {
2007f226579Sghi
2017f226579Sghi				$y_key = 'bez:report:year:'.$year;
20238b5c5c4Sghi				$data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year);
2037f226579Sghi
2047f226579Sghi				if (isset($this->value['year']) && (int)$this->value['year'] == $year) {
2057f226579Sghi					$data['bez:report:year:'.$year]['open'] = true;
2067f226579Sghi
2077e9a45a9Sghi					if ($year == $year_now)
2087e9a45a9Sghi						$mon_max = $mon_now;
2097e9a45a9Sghi					else
2107e9a45a9Sghi						$mon_max = 12;
2117e9a45a9Sghi					for ( ; $mon <= $mon_max; $mon++) {
2127e9a45a9Sghi						$m_key = $y_key.':month:'.$mon;
21338b5c5c4Sghi						$data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4,
2147e9a45a9Sghi						'title' => $mon < 10 ? '0'.$mon : $mon);
2157e9a45a9Sghi					}
2167f226579Sghi				}
2177e9a45a9Sghi				$mon = 1;
2187e9a45a9Sghi			}
2197f226579Sghi		}
2203cc1f839Sghi
22108e8ea12Sghi
222f01326efSghi
2237f226579Sghi		if (isset($this->value['bez'])) {
224a42d0169Sghi			$data['bez:start']['open'] = true;
22508e8ea12Sghi		} else {
226a42d0169Sghi			$data['bez:start']['open'] = false;
22708e8ea12Sghi			array_splice($data, 1);
22808e8ea12Sghi		}
22908e8ea12Sghi
23080487b8aSghi		if ($helper->user_admin() && $data['bez:start']['open'] == true) {
23180487b8aSghi			$data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' =>
23280487b8aSghi				$this->getLang('types_manage'));
23380487b8aSghi			$data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' =>
23480487b8aSghi				$this->getLang('root_causes'));
23580487b8aSghi		}
2367f226579Sghi
23708e8ea12Sghi        $R->doc .= '<div class="plugin__bez">';
23808e8ea12Sghi        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
23908e8ea12Sghi        $R->doc .= '</div>';
24008e8ea12Sghi
2415536eef6Sghi		return true;
24208e8ea12Sghi	}
243da9ebf75Sghi
24408e8ea12Sghi	function _bezlink($id, $title) {
2457f226579Sghi		//$uri = wl($id);
2467f226579Sghi		$uri = DOKU_URL . 'doku.php?id='.$id;
247a6dcc2a9Sghi		return '<a href="'.$uri.'">'.($title).'</a>';
24808e8ea12Sghi	}
24908e8ea12Sghi
25008e8ea12Sghi    function _list($item){
25108e8ea12Sghi
2527f226579Sghi		$ex = explode(':', $item['id']);
25305c9d3bcSghi
2547f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
2557f226579Sghi			$item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
2567f226579Sghi
2577f226579Sghi		//pola brane pod uwagę przy określaniu aktualnej strony
258*2106ae3bSghi		$fields = array('bez', 'tid', 'cid');
25997183698Sghi		if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') {
2607f226579Sghi			$fields[] = 'month';
2617f226579Sghi			$fields[] = 'year';
2627f226579Sghi		}
2639fbfe943Sghi		if ($this->value[bez] == 'task_form' && isset($this->value[cid]))
2649fbfe943Sghi			unset($fields[0]);
2657f226579Sghi
2667f226579Sghi		$actual_page = true;
2677f226579Sghi		foreach ($fields as $field)
2687f226579Sghi			if ($item_value[$field] != $this->value[$field])
2697f226579Sghi				$actual_page = false;
2707f226579Sghi
2717f226579Sghi
2727f226579Sghi
2737f226579Sghi        if(($item['type'] == 'd' && $item['open']) ||  $actual_page) {
27415487902Sghi			$id = $item['id'];
27515487902Sghi			if ($this->lang_code != $this->default_lang)
27615487902Sghi				$id = $this->lang_code.':'.$id;
27715487902Sghi            return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>';
27808e8ea12Sghi        }else{
27915487902Sghi			$id = $item['id'];
28015487902Sghi			if ($this->lang_code != $this->default_lang)
28115487902Sghi				$id = $this->lang_code.':'.$id;
28215487902Sghi            return $this->_bezlink($id, $item['title']);
28308e8ea12Sghi        }
28408e8ea12Sghi
28508e8ea12Sghi    }
28608e8ea12Sghi
28708e8ea12Sghi    function _li($item){
28808e8ea12Sghi        if($item['type'] == "f"){
28908e8ea12Sghi            return '<li class="level'.$item['level'].'">';
29008e8ea12Sghi        }elseif($item['open']){
29108e8ea12Sghi            return '<li class="open">';
29208e8ea12Sghi        }else{
29308e8ea12Sghi            return '<li class="closed">';
29408e8ea12Sghi        }
29565cfcae3Sghi    }
29665cfcae3Sghi}
297