xref: /plugin/bez/syntax/nav.php (revision 7f226579b5ebd86ad26e5e9d7c71f3a38b5bb2a0)
1<?php
2/**
3 * Plugin Now: Inserts a timestamp.
4 *
5 * @license    GPL 3 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Szymon Olewniczak <szymon.olewniczak@rid.pl>
7 */
8
9// must be run within DokuWiki
10if(!defined('DOKU_INC')) die();
11
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once DOKU_PLUGIN.'syntax.php';
14include_once DOKU_PLUGIN."bez/models/tasks.php";
15include_once DOKU_PLUGIN."bez/models/issues.php";
16/**
17 * All DokuWiki plugins to extend the parser/rendering mechanism
18 * need to inherit from this class
19 */
20class syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin {
21	private $value = array();
22
23    function getPType() { return 'block'; }
24    function getType() { return 'substition'; }
25    function getSort() { return 99; }
26
27
28    function connectTo($mode) {
29		$this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav');
30    }
31
32	function __construct() {
33
34		$ex = explode(':', $_GET['id']);
35		for ($i = 0; $i < count($ex); $i += 2)
36			$this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
37	}
38
39    function handle($match, $state, $pos, &$handler)
40    {
41		return true;
42    }
43
44    function render($mode, &$R, $pass) {
45		global $INFO;
46
47		$helper = $this->loadHelper('bez');
48		if ($mode != 'xhtml' || !$helper->user_viewer()) return false;
49
50        $R->info['cache'] = false;
51
52		$data = array(
53			'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')),
54		);
55
56		if ($helper->user_editor())
57			$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report'));
58
59		$isso = new Issues();
60		$no = count($isso->get_close_issue());
61		$title = str_replace('%d', $no, $this->getLang('menu_close_issue'));
62		$data['bez:close_issue'] = array('id' => 'bez:close_issue', 'type' => 'f', 'level' => 2, 'title' => $title);
63
64		$tasko = new Tasks();
65		$no = count($tasko->get_close_task());
66		$title = str_replace('%d', $no, $this->getLang('menu_close_task'));
67		$data['bez:close_task'] = array('id' => 'bez:close_task', 'type' => 'f', 'level' => 2, 'title' => $title);
68
69		$data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issues'));
70		$data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks'));
71
72		$data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report'));
73
74
75
76
77		if ($this->value['bez'] == 'report') {
78			$data['bez:report']['open'] = true;
79
80			$oldest = $isso->get_oldest_date();
81			$year_old = (int)date('Y', $oldest);
82			$mon_old = (int)date('n', $oldest);
83			$year_now = (int)date('Y');
84			$mon_now = (int)date('n');
85
86			$entity = '';
87			if (array_key_exists('entity', $this->value)) {
88				$entity = ':entity:'.urlencode($this->value['entity']);
89			}
90
91			$mon = $mon_old;
92			for ($year = $year_old; $year <= $year_now; $year++) {
93
94				$y_key = 'bez:report:year:'.$year;
95				$data[$y_key] = array('id' => $y_key.$entity, 'type' => 'd', 'level' => 3, 'title' => $year);
96
97				if (isset($this->value['year']) && (int)$this->value['year'] == $year) {
98					$data['bez:report:year:'.$year]['open'] = true;
99
100					if ($year == $year_now)
101						$mon_max = $mon_now;
102					else
103						$mon_max = 12;
104					for ( ; $mon <= $mon_max; $mon++) {
105						$m_key = $y_key.':month:'.$mon;
106						$data[$m_key] = array('id' => $m_key.$entity, 'type' => 'f', 'level' => 4,
107						'title' => $mon < 10 ? '0'.$mon : $mon);
108					}
109				}
110				$mon = 1;
111			}
112		}
113
114
115
116		if (isset($this->value['bez'])) {
117			$data['bez:start']['open'] = true;
118		} else {
119			$data['bez:start']['open'] = false;
120			array_splice($data, 1);
121		}
122
123		if ($helper->user_admin() && $data['bez:start']['open'] == true)
124			$data['bez:entity'] = array('id' => 'bez:entity', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('entity_manage'));
125
126        $R->doc .= '<div class="plugin__bez">';
127        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
128        $R->doc .= '</div>';
129
130		return true;
131	}
132
133	function _bezlink($id, $title) {
134		//$uri = wl($id);
135		$uri = DOKU_URL . 'doku.php?id='.$id;
136		return '<a href="'.$uri.'">'.($title).'</a>';
137	}
138
139    function _list($item){
140
141		$ex = explode(':', $item['id']);
142		for ($i = 0; $i < count($ex); $i += 2)
143			$item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
144
145		//pola brane pod uwagę przy określaniu aktualnej strony
146		$fields = array('bez');
147		if ($item_value['bez'] == 'report') {
148			$fields[] = 'month';
149			$fields[] = 'year';
150		}
151
152		$actual_page = true;
153		foreach ($fields as $field)
154			if ($item_value[$field] != $this->value[$field])
155				$actual_page = false;
156
157
158
159        if(($item['type'] == 'd' && $item['open']) ||  $actual_page) {
160            return '<strong>'.$this->_bezlink($item['id'], $item['title']).'</strong>';
161        }else{
162            return $this->_bezlink($item['id'], $item['title']);
163        }
164
165    }
166
167    function _li($item){
168        if($item['type'] == "f"){
169            return '<li class="level'.$item['level'].'">';
170        }elseif($item['open']){
171            return '<li class="open">';
172        }else{
173            return '<li class="closed">';
174        }
175    }
176}
177