xref: /plugin/bez/syntax/nav.php (revision 66f0c416552a26059347e383fdc37be05c8b9ebb)
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
81919e4830Sghi
824fb0d798Sghi		$data['bez:issues'] = array('id' => 'bez:issues', '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
886c94eb49Sghi		if ($this->value['bez'] == 'issues' || $this->value['bez'] == 'issue_report') {
896c94eb49Sghi			if ($helper->user_editor()) {
906c94eb49Sghi				$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 3, 'title' => $this->getLang('bds_issue_report'));
916c94eb49Sghi			}
926c94eb49Sghi			$data['bez:issues']['open'] = true;
936c94eb49Sghi		}
94168ecf58Sghi		if (in_array($this->value['bez'], $issue_pages) || ($this->value['bez'] == 'issue_report' && isset($this->value['id']))) {
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			}
9827712358Sghi			$data['bez:issues']['open'] = true;
9927712358Sghi			$id = (int)$this->value[id];
10027712358Sghi
1019a30fd19Sghi			$isso = new Issues();
1029a30fd19Sghi			$issue_opened = $isso->opened($id);
103489061b8Sghi			$issue_proposal = $isso->is_proposal($id);
1049a30fd19Sghi
10527712358Sghi			$tasko = new Tasks();
10627712358Sghi			$causo = new Causes();
10727712358Sghi
108ed77b00cSSzymon Olewniczak			$causes = $causo->get($id);
109ed77b00cSSzymon Olewniczak			$tasks = $tasko->get_corrections_ids($id);
110ed77b00cSSzymon Olewniczak
111ed77b00cSSzymon Olewniczak			$type = 'd';
112ed77b00cSSzymon Olewniczak			if (count($causes) + count($tasks) == 0) {
113ed77b00cSSzymon Olewniczak				$type = 'f';
114ed77b00cSSzymon Olewniczak			}
115ed77b00cSSzymon Olewniczak
11627712358Sghi			$pid = "bez:issue:id:$id";
117ed77b00cSSzymon Olewniczak			$data[$pid] = array('id' => $pid, 'type' => $type, 'level' => 3,
11827712358Sghi												'title' => "#$id", 'open' => true);
11927712358Sghi
120ed77b00cSSzymon Olewniczak			if (count($tasks) > 0) {
12127712358Sghi				$pid = "bez:issue_tasks:id:$id";
12227712358Sghi				$data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4,
1239fbfe943Sghi									'title' => $this->getLang('correction_nav'));
1249fbfe943Sghi				if (in_array($this->value['bez'], $task_pages) && $this->value[cid] == '') {
12527712358Sghi					$data[$pid][open] = true;
1269a30fd19Sghi
1279a30fd19Sghi					if ($issue_opened) {
12827712358Sghi						$rpid = "bez:task_form:id:$id";
129489061b8Sghi						if ($helper->user_admin() && !$issue_proposal)
13027712358Sghi							$data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5,
13127712358Sghi												'title' => $this->getLang('add_correction'));
1329a30fd19Sghi					}
133ed77b00cSSzymon Olewniczak					foreach ($tasks as $r) {
13427712358Sghi						$rpid = "bez:issue_task:id:$id:tid:$r[id]";
13527712358Sghi						$data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5,
136ed77b00cSSzymon Olewniczak											'title' => '#z'.$r['id']);
137ed77b00cSSzymon Olewniczak					}
13827712358Sghi				}
13927712358Sghi			}
14027712358Sghi
141ed77b00cSSzymon Olewniczak			if (count($causes) > 0) {
14227712358Sghi				$pid = "bez:issue_causes:id:$id";
14327712358Sghi				$data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4,
14427712358Sghi									'title' => $this->getLang('causes'));
1459fbfe943Sghi				if (in_array($this->value['bez'], $cause_pages) || $this->value[cid] != '') {
14627712358Sghi					$data[$pid][open] = true;
1479a30fd19Sghi					if ($issue_opened) {
14827712358Sghi						$rpid = "bez:cause_form:id:$id";
149489061b8Sghi						if ($helper->user_admin() && !$issue_proposal)
15027712358Sghi							$data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5,
15127712358Sghi												'title' => $this->getLang('add_cause'));
1529a30fd19Sghi					}
153ed77b00cSSzymon Olewniczak
154ed77b00cSSzymon Olewniczak					foreach ($causes as $r) {
15527712358Sghi						$rpid = "bez:issue_cause:id:$id:cid:$r[id]";
1569fbfe943Sghi						$data[$rpid] = array('id' => $rpid, 'type' => 'd', 'level' => 5,
15727712358Sghi											'title' => '#p'.$r[id]);
1589fbfe943Sghi
15927712358Sghi						if ((int)$this->value['cid'] == $r[id]) {
16027712358Sghi							$data[$rpid][open] = true;
16127712358Sghi
16227712358Sghi							$pres = $tasko->get($id, $r['id']);
16327712358Sghi							foreach ($pres as $pr) {
1649fbfe943Sghi								$rptid = "bez:issue_cause_task:id:$id:cid:$r[id]:tid:$pr[id]";
1659fbfe943Sghi								$data[$rptid] = array('id' => $rptid, 'type' => 'f', 'level' => 6,
1669fbfe943Sghi											'title' => '#z'.$pr[id]);
1679fbfe943Sghi
16827712358Sghi							}
16927712358Sghi						}
1709fbfe943Sghi					}
17127712358Sghi
17227712358Sghi				}
173ed77b00cSSzymon Olewniczak			}
17427712358Sghi
17527712358Sghi		}
176919e4830Sghi
177919e4830Sghi
178168ecf58Sghi		$data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bez_tasks'));
179168ecf58Sghi
180168ecf58Sghi		if ($this->value['bez'] == 'tasks' || $this->value['bez'] == 'show_task'
181168ecf58Sghi			|| $this->value['bez'] == 'task_form_plan'
182168ecf58Sghi			|| $this->value['bez'] == 'issue_task'
183d6002863Sghi			|| $this->value['bez'] == 'task_form'
1846c94eb49Sghi			|| $this->value['bez'] == 'task_report'
185168ecf58Sghi			|| $this->value['bez'] == 'issue_cause_task') {
186168ecf58Sghi			$data['bez:tasks']['open'] = true;
187168ecf58Sghi
188*66f0c416SSzymon Olewniczak			if ($helper->user_admin()) {
1896c94eb49Sghi				$data['bez:task_report'] = array('id' => 'bez:task_report', 'type' => 'f', 'level' => 3, 'title' => $this->getLang('bds_task_report'));
1906c94eb49Sghi			}
1916c94eb49Sghi
192168ecf58Sghi
193168ecf58Sghi			if (isset($this->value['year']))
194168ecf58Sghi				$year = $this->value['year'];
195168ecf58Sghi			else
196168ecf58Sghi				$year = date('Y');
197168ecf58Sghi
198168ecf58Sghi
199168ecf58Sghi			if (isset($this->value['tid'])) {
200168ecf58Sghi				$tasko = new Tasks();
201168ecf58Sghi				$this->value['tasktype']  = $tasko->get_type($this->value['tid']);
202168ecf58Sghi			}
203168ecf58Sghi
204168ecf58Sghi
205168ecf58Sghi			$tasktypeso = new Tasktypes();
206168ecf58Sghi			$tasktypes = $tasktypeso->get();
207b609bf0aSghi			$page_id = "bez:tasks:tasktype:-none:year:$year";
208168ecf58Sghi			if (isset($this->value['tid']) && $this->value['tasktype'] == '') {
209b609bf0aSghi				$data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('tasks_no_type'), 'open' => true);
210168ecf58Sghi
211*66f0c416SSzymon Olewniczak				$page_id = 'bez:show_task:tid:'.$this->value['tid'];
212*66f0c416SSzymon Olewniczak				//$page_id = $_GET['id'];
213b609bf0aSghi				$data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => '#z'.$this->value['tid']);
214168ecf58Sghi
215168ecf58Sghi			} else {
216b609bf0aSghi				$data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 3, 'title' => $this->getLang('tasks_no_type'));
217168ecf58Sghi			}
218168ecf58Sghi
219168ecf58Sghi
220168ecf58Sghi			foreach ($tasktypes as $id => $tasktype) {
221b609bf0aSghi				$page_id = "bez:tasks:tasktype:$id:year:$year";
222168ecf58Sghi				if (isset($this->value['tid']) && $this->value['tasktype'] == $id) {
223b609bf0aSghi					$data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 3, 'title' => $tasktype, 'open' => true);
224*66f0c416SSzymon Olewniczak					$page_id = 'bez:show_task:tid:'.$this->value['tid'];
225*66f0c416SSzymon Olewniczak					//$page_id = $_GET['id'];
226b609bf0aSghi					$data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => '#z'.$this->value['tid']);
227168ecf58Sghi				} else
228b609bf0aSghi					$data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 3, 'title' => $tasktype);
229168ecf58Sghi			}
230168ecf58Sghi		}
23165cfcae3Sghi
2327f853d3aSghi		$isso = new Issues();
23397183698Sghi		$year_now = (int)date('Y');
23497183698Sghi		$mon_now = (int)date('n');
23597183698Sghi
23697183698Sghi		$data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report'));
2377f226579Sghi		if ($this->value['bez'] == 'report') {
2387f226579Sghi			$data['bez:report']['open'] = true;
2397f226579Sghi
240bb615297Sghi			$oldest = $isso->get_oldest_close_date();
2417e9a45a9Sghi			$year_old = (int)date('Y', $oldest);
2427e9a45a9Sghi			$mon_old = (int)date('n', $oldest);
2437e9a45a9Sghi
2447e9a45a9Sghi			$mon = $mon_old;
2457e9a45a9Sghi			for ($year = $year_old; $year <= $year_now; $year++) {
2467f226579Sghi
2477f226579Sghi				$y_key = 'bez:report:year:'.$year;
24838b5c5c4Sghi				$data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year);
2497f226579Sghi
2507f226579Sghi				if (isset($this->value['year']) && (int)$this->value['year'] == $year) {
2517f226579Sghi					$data['bez:report:year:'.$year]['open'] = true;
2527f226579Sghi
2537e9a45a9Sghi					if ($year == $year_now)
2547e9a45a9Sghi						$mon_max = $mon_now;
2557e9a45a9Sghi					else
2567e9a45a9Sghi						$mon_max = 12;
2577e9a45a9Sghi					for ( ; $mon <= $mon_max; $mon++) {
2587e9a45a9Sghi						$m_key = $y_key.':month:'.$mon;
25938b5c5c4Sghi						$data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4,
2607e9a45a9Sghi						'title' => $mon < 10 ? '0'.$mon : $mon);
2617e9a45a9Sghi					}
2627f226579Sghi				}
2637e9a45a9Sghi				$mon = 1;
2647e9a45a9Sghi			}
2657f226579Sghi		}
2663cc1f839Sghi
26708e8ea12Sghi
268f01326efSghi
2697f226579Sghi		if (isset($this->value['bez'])) {
270a42d0169Sghi			$data['bez:start']['open'] = true;
27108e8ea12Sghi		} else {
272a42d0169Sghi			$data['bez:start']['open'] = false;
27308e8ea12Sghi			array_splice($data, 1);
27408e8ea12Sghi		}
27508e8ea12Sghi
27680487b8aSghi		if ($helper->user_admin() && $data['bez:start']['open'] == true) {
27780487b8aSghi			$data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' =>
27880487b8aSghi				$this->getLang('types_manage'));
27980487b8aSghi			$data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' =>
28080487b8aSghi				$this->getLang('root_causes'));
281168ecf58Sghi			$data['bez:task_types'] = array('id' => 'bez:task_types', 'type' => 'f', 'level' => 2, 'title' =>
282168ecf58Sghi				$this->getLang('task_types'));
28380487b8aSghi		}
2847f226579Sghi
28508e8ea12Sghi        $R->doc .= '<div class="plugin__bez">';
28608e8ea12Sghi        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
28708e8ea12Sghi        $R->doc .= '</div>';
28808e8ea12Sghi
2895536eef6Sghi		return true;
29008e8ea12Sghi	}
291da9ebf75Sghi
29208e8ea12Sghi	function _bezlink($id, $title) {
2937f226579Sghi		//$uri = wl($id);
2947f226579Sghi		$uri = DOKU_URL . 'doku.php?id='.$id;
295a6dcc2a9Sghi		return '<a href="'.$uri.'">'.($title).'</a>';
29608e8ea12Sghi	}
29708e8ea12Sghi
29808e8ea12Sghi    function _list($item){
29908e8ea12Sghi
3007f226579Sghi		$ex = explode(':', $item['id']);
30105c9d3bcSghi
3027f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
3037f226579Sghi			$item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
3047f226579Sghi
3057f226579Sghi		//pola brane pod uwagę przy określaniu aktualnej strony
306168ecf58Sghi		$fields = array('bez', 'tid', 'cid', 'tasktype', 'taskstate');
30797183698Sghi		if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') {
3087f226579Sghi			$fields[] = 'month';
3097f226579Sghi			$fields[] = 'year';
3107f226579Sghi		}
3119fbfe943Sghi		if ($this->value[bez] == 'task_form' && isset($this->value[cid]))
3129fbfe943Sghi			unset($fields[0]);
3137f226579Sghi
3147f226579Sghi		$actual_page = true;
3157f226579Sghi		foreach ($fields as $field)
3167f226579Sghi			if ($item_value[$field] != $this->value[$field])
3177f226579Sghi				$actual_page = false;
3187f226579Sghi
319168ecf58Sghi		//specjalny hak dla zadań, boję się ruszać całej procedury
320168ecf58Sghi		if ($item_value['bez'] == 'issue_task' ||
321168ecf58Sghi			$item_value['bez'] == 'issue_cause_task' ||
322d6002863Sghi			$item_value['bez'] == 'task_form' ||
323168ecf58Sghi			$item_value['bez'] == 'show_task')
324168ecf58Sghi				if ($item_value['tid'] == $this->value['tid'])
325168ecf58Sghi					$actual_page = true;
3267f226579Sghi
3277f226579Sghi        if(($item['type'] == 'd' && $item['open']) ||  $actual_page) {
32815487902Sghi			$id = $item['id'];
32915487902Sghi			if ($this->lang_code != $this->default_lang)
33015487902Sghi				$id = $this->lang_code.':'.$id;
33115487902Sghi            return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>';
33208e8ea12Sghi        }else{
33315487902Sghi			$id = $item['id'];
33415487902Sghi			if ($this->lang_code != $this->default_lang)
33515487902Sghi				$id = $this->lang_code.':'.$id;
33615487902Sghi            return $this->_bezlink($id, $item['title']);
33708e8ea12Sghi        }
33808e8ea12Sghi
33908e8ea12Sghi    }
34008e8ea12Sghi
34108e8ea12Sghi    function _li($item){
34208e8ea12Sghi        if($item['type'] == "f"){
34308e8ea12Sghi            return '<li class="level'.$item['level'].'">';
34408e8ea12Sghi        }elseif($item['open']){
34508e8ea12Sghi            return '<li class="open">';
34608e8ea12Sghi        }else{
34708e8ea12Sghi            return '<li class="closed">';
34808e8ea12Sghi        }
34965cfcae3Sghi    }
35065cfcae3Sghi}
351