xref: /plugin/bez/syntax/nav.php (revision ecefc57ad5e0b2065849fd2c839ae00b2dc393c1)
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
623b3e3ab0Sghi    function handle($match, $state, $pos, Doku_Handler $handler)
6365cfcae3Sghi    {
6465cfcae3Sghi		return true;
6565cfcae3Sghi    }
6665cfcae3Sghi
673b3e3ab0Sghi    function render($mode, Doku_Renderer $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
79*ecefc57aSghi		if ($helper->user_editor()) {
80a6dcc2a9Sghi			$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report'));
81*ecefc57aSghi			$data['bez:task_report'] = array('id' => 'bez:task_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_task_report'));
82a6dcc2a9Sghi
83*ecefc57aSghi		}
844fb0d798Sghi		$data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bds_issues'));
8527712358Sghi
8627712358Sghi		$task_pages = array('issue_tasks', 'task_form', 'issue_task');
879fbfe943Sghi		$cause_pages = array('issue_causes', 'issue_cause', 'cause_form', 'issue_cause_task');
889a30fd19Sghi		$issue_pages = array_merge(array('issue', 'rr', '8d'), $task_pages, $cause_pages);
8927712358Sghi
907ffa8289Sghi		if (in_array($this->value['bez'], $issue_pages) || ($this->value[bez] == 'issue_report' && isset($this->value[id]))) {
9127712358Sghi			$data['bez:issues']['open'] = true;
9227712358Sghi			$id = (int)$this->value[id];
9327712358Sghi
949a30fd19Sghi			$isso = new Issues();
959a30fd19Sghi			$issue_opened = $isso->opened($id);
96489061b8Sghi			$issue_proposal = $isso->is_proposal($id);
979a30fd19Sghi
9827712358Sghi			$tasko = new Tasks();
9927712358Sghi			$causo = new Causes();
10027712358Sghi
10127712358Sghi			$pid = "bez:issue:id:$id";
10227712358Sghi			$data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 3,
10327712358Sghi												'title' => "#$id", 'open' => true);
10427712358Sghi
10527712358Sghi			$pid = "bez:issue_tasks:id:$id";
10627712358Sghi			$data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4,
1079fbfe943Sghi								'title' => $this->getLang('correction_nav'));
1089fbfe943Sghi			if (in_array($this->value['bez'], $task_pages) && $this->value[cid] == '') {
10927712358Sghi				$data[$pid][open] = true;
1109a30fd19Sghi
1119a30fd19Sghi				if ($issue_opened) {
11227712358Sghi					$rpid = "bez:task_form:id:$id";
113489061b8Sghi					if ($helper->user_admin() && !$issue_proposal)
11427712358Sghi						$data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5,
11527712358Sghi											'title' => $this->getLang('add_correction'));
1169a30fd19Sghi				}
1179fbfe943Sghi				$res = $tasko->get_filtered(array('issue' => $id, 'action' => '0'));
11827712358Sghi				foreach ($res as $r) {
11927712358Sghi					$rpid = "bez:issue_task:id:$id:tid:$r[id]";
12027712358Sghi					$data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5,
12127712358Sghi										'title' => '#z'.$r[id]);
12227712358Sghi				}
12327712358Sghi			}
12427712358Sghi
12527712358Sghi			$pid = "bez:issue_causes:id:$id";
12627712358Sghi			$data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4,
12727712358Sghi								'title' => $this->getLang('causes'));
1289fbfe943Sghi			if (in_array($this->value['bez'], $cause_pages) || $this->value[cid] != '') {
12927712358Sghi				$data[$pid][open] = true;
1309a30fd19Sghi				if ($issue_opened) {
13127712358Sghi					$rpid = "bez:cause_form:id:$id";
132489061b8Sghi					if ($helper->user_admin() && !$issue_proposal)
13327712358Sghi						$data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5,
13427712358Sghi											'title' => $this->getLang('add_cause'));
1359a30fd19Sghi				}
1369fbfe943Sghi				$res = $causo->get($id);
13727712358Sghi				foreach ($res as $r) {
13827712358Sghi					$rpid = "bez:issue_cause:id:$id:cid:$r[id]";
1399fbfe943Sghi					$data[$rpid] = array('id' => $rpid, 'type' => 'd', 'level' => 5,
14027712358Sghi										'title' => '#p'.$r[id]);
1419fbfe943Sghi
14227712358Sghi					if ((int)$this->value['cid'] == $r[id]) {
14327712358Sghi						$data[$rpid][open] = true;
14427712358Sghi
14527712358Sghi						$pres = $tasko->get($id, $r['id']);
14627712358Sghi						foreach ($pres as $pr) {
1479fbfe943Sghi							$rptid = "bez:issue_cause_task:id:$id:cid:$r[id]:tid:$pr[id]";
1489fbfe943Sghi							$data[$rptid] = array('id' => $rptid, 'type' => 'f', 'level' => 6,
1499fbfe943Sghi										'title' => '#z'.$pr[id]);
1509fbfe943Sghi
15127712358Sghi						}
15227712358Sghi					}
1539fbfe943Sghi				}
15427712358Sghi
15527712358Sghi			}
15627712358Sghi
15727712358Sghi		}
1584fb0d798Sghi		$data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks'));
15965cfcae3Sghi
1607f853d3aSghi		$isso = new Issues();
16197183698Sghi		$year_now = (int)date('Y');
16297183698Sghi		$mon_now = (int)date('n');
16397183698Sghi
16497183698Sghi		$data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report'));
1657f226579Sghi		if ($this->value['bez'] == 'report') {
1667f226579Sghi			$data['bez:report']['open'] = true;
1677f226579Sghi
168bb615297Sghi			$oldest = $isso->get_oldest_close_date();
1697e9a45a9Sghi			$year_old = (int)date('Y', $oldest);
1707e9a45a9Sghi			$mon_old = (int)date('n', $oldest);
1717e9a45a9Sghi
1727e9a45a9Sghi			$mon = $mon_old;
1737e9a45a9Sghi			for ($year = $year_old; $year <= $year_now; $year++) {
1747f226579Sghi
1757f226579Sghi				$y_key = 'bez:report:year:'.$year;
17638b5c5c4Sghi				$data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year);
1777f226579Sghi
1787f226579Sghi				if (isset($this->value['year']) && (int)$this->value['year'] == $year) {
1797f226579Sghi					$data['bez:report:year:'.$year]['open'] = true;
1807f226579Sghi
1817e9a45a9Sghi					if ($year == $year_now)
1827e9a45a9Sghi						$mon_max = $mon_now;
1837e9a45a9Sghi					else
1847e9a45a9Sghi						$mon_max = 12;
1857e9a45a9Sghi					for ( ; $mon <= $mon_max; $mon++) {
1867e9a45a9Sghi						$m_key = $y_key.':month:'.$mon;
18738b5c5c4Sghi						$data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4,
1887e9a45a9Sghi						'title' => $mon < 10 ? '0'.$mon : $mon);
1897e9a45a9Sghi					}
1907f226579Sghi				}
1917e9a45a9Sghi				$mon = 1;
1927e9a45a9Sghi			}
1937f226579Sghi		}
1943cc1f839Sghi
19508e8ea12Sghi
196f01326efSghi
1977f226579Sghi		if (isset($this->value['bez'])) {
198a42d0169Sghi			$data['bez:start']['open'] = true;
19908e8ea12Sghi		} else {
200a42d0169Sghi			$data['bez:start']['open'] = false;
20108e8ea12Sghi			array_splice($data, 1);
20208e8ea12Sghi		}
20308e8ea12Sghi
20480487b8aSghi		if ($helper->user_admin() && $data['bez:start']['open'] == true) {
20580487b8aSghi			$data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' =>
20680487b8aSghi				$this->getLang('types_manage'));
20780487b8aSghi			$data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' =>
20880487b8aSghi				$this->getLang('root_causes'));
20980487b8aSghi		}
2107f226579Sghi
21108e8ea12Sghi        $R->doc .= '<div class="plugin__bez">';
21208e8ea12Sghi        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
21308e8ea12Sghi        $R->doc .= '</div>';
21408e8ea12Sghi
2155536eef6Sghi		return true;
21608e8ea12Sghi	}
217da9ebf75Sghi
21808e8ea12Sghi	function _bezlink($id, $title) {
2197f226579Sghi		//$uri = wl($id);
2207f226579Sghi		$uri = DOKU_URL . 'doku.php?id='.$id;
221a6dcc2a9Sghi		return '<a href="'.$uri.'">'.($title).'</a>';
22208e8ea12Sghi	}
22308e8ea12Sghi
22408e8ea12Sghi    function _list($item){
22508e8ea12Sghi
2267f226579Sghi		$ex = explode(':', $item['id']);
22705c9d3bcSghi
2287f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
2297f226579Sghi			$item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
2307f226579Sghi
2317f226579Sghi		//pola brane pod uwagę przy określaniu aktualnej strony
2322106ae3bSghi		$fields = array('bez', 'tid', 'cid');
23397183698Sghi		if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') {
2347f226579Sghi			$fields[] = 'month';
2357f226579Sghi			$fields[] = 'year';
2367f226579Sghi		}
2379fbfe943Sghi		if ($this->value[bez] == 'task_form' && isset($this->value[cid]))
2389fbfe943Sghi			unset($fields[0]);
2397f226579Sghi
2407f226579Sghi		$actual_page = true;
2417f226579Sghi		foreach ($fields as $field)
2427f226579Sghi			if ($item_value[$field] != $this->value[$field])
2437f226579Sghi				$actual_page = false;
2447f226579Sghi
2457f226579Sghi
2467f226579Sghi
2477f226579Sghi        if(($item['type'] == 'd' && $item['open']) ||  $actual_page) {
24815487902Sghi			$id = $item['id'];
24915487902Sghi			if ($this->lang_code != $this->default_lang)
25015487902Sghi				$id = $this->lang_code.':'.$id;
25115487902Sghi            return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>';
25208e8ea12Sghi        }else{
25315487902Sghi			$id = $item['id'];
25415487902Sghi			if ($this->lang_code != $this->default_lang)
25515487902Sghi				$id = $this->lang_code.':'.$id;
25615487902Sghi            return $this->_bezlink($id, $item['title']);
25708e8ea12Sghi        }
25808e8ea12Sghi
25908e8ea12Sghi    }
26008e8ea12Sghi
26108e8ea12Sghi    function _li($item){
26208e8ea12Sghi        if($item['type'] == "f"){
26308e8ea12Sghi            return '<li class="level'.$item['level'].'">';
26408e8ea12Sghi        }elseif($item['open']){
26508e8ea12Sghi            return '<li class="open">';
26608e8ea12Sghi        }else{
26708e8ea12Sghi            return '<li class="closed">';
26808e8ea12Sghi        }
26965cfcae3Sghi    }
27065cfcae3Sghi}
271