xref: /plugin/bez/syntax/nav.php (revision 05c9d3bc9b772f5572ae110000a17e18ec941f20)
165cfcae3Sghi<?php
265cfcae3Sghi/**
365cfcae3Sghi * Plugin Now: Inserts a timestamp.
465cfcae3Sghi *
565cfcae3Sghi * @license    GPL 3 (http://www.gnu.org/licenses/gpl.html)
665cfcae3Sghi */
765cfcae3Sghi
865cfcae3Sghi// must be run within DokuWiki
965cfcae3Sghiif(!defined('DOKU_INC')) die();
1065cfcae3Sghi
1165cfcae3Sghiif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
1265cfcae3Sghirequire_once DOKU_PLUGIN.'syntax.php';
13a6dcc2a9Sghiinclude_once DOKU_PLUGIN."bez/models/issues.php";
1465cfcae3Sghi/**
1565cfcae3Sghi * All DokuWiki plugins to extend the parser/rendering mechanism
1665cfcae3Sghi * need to inherit from this class
1765cfcae3Sghi */
1865cfcae3Sghiclass syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin {
197f226579Sghi	private $value = array();
20*05c9d3bcSghi	private $lang_code = '';
2165cfcae3Sghi
225536eef6Sghi    function getPType() { return 'block'; }
2365cfcae3Sghi    function getType() { return 'substition'; }
2465cfcae3Sghi    function getSort() { return 99; }
2565cfcae3Sghi
2665cfcae3Sghi
2765cfcae3Sghi    function connectTo($mode) {
2865cfcae3Sghi		$this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav');
2965cfcae3Sghi    }
3065cfcae3Sghi
317f226579Sghi	function __construct() {
327f226579Sghi
337f226579Sghi		$ex = explode(':', $_GET['id']);
34*05c9d3bcSghi		//wielojęzyczność
35*05c9d3bcSghi		if ($ex[1] == 'bez') {
36*05c9d3bcSghi			$this->lang_code = $ex[0].':';
37*05c9d3bcSghi			$ex = array_slice($ex, 1);
38*05c9d3bcSghi		}
39*05c9d3bcSghi
407f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
417f226579Sghi			$this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
427f226579Sghi	}
437f226579Sghi
4465cfcae3Sghi    function handle($match, $state, $pos, &$handler)
4565cfcae3Sghi    {
4665cfcae3Sghi		return true;
4765cfcae3Sghi    }
4865cfcae3Sghi
4908e8ea12Sghi    function render($mode, &$R, $pass) {
5008e8ea12Sghi		global $INFO;
5165cfcae3Sghi
525536eef6Sghi		$helper = $this->loadHelper('bez');
5308e8ea12Sghi		if ($mode != 'xhtml' || !$helper->user_viewer()) return false;
5465cfcae3Sghi
5508e8ea12Sghi        $R->info['cache'] = false;
5608e8ea12Sghi
5708e8ea12Sghi		$data = array(
58a6dcc2a9Sghi			'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')),
5908e8ea12Sghi		);
6065cfcae3Sghi
615536eef6Sghi		if ($helper->user_editor())
62a6dcc2a9Sghi			$data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report'));
63a6dcc2a9Sghi
64bb615297Sghi		$data['bez:issues'] = array('id' => 'bez:issues:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issues'));
65bb615297Sghi		$data['bez:tasks'] = array('id' => 'bez:tasks:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks'));
6665cfcae3Sghi
67d21fa58cSghi		$data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report'));
68f01326efSghi
697e9a45a9Sghi
707e9a45a9Sghi
717e9a45a9Sghi
727f853d3aSghi		$isso = new Issues();
737f226579Sghi		if ($this->value['bez'] == 'report') {
747f226579Sghi			$data['bez:report']['open'] = true;
757f226579Sghi
76bb615297Sghi			$oldest = $isso->get_oldest_close_date();
777e9a45a9Sghi			$year_old = (int)date('Y', $oldest);
787e9a45a9Sghi			$mon_old = (int)date('n', $oldest);
797e9a45a9Sghi			$year_now = (int)date('Y');
807e9a45a9Sghi			$mon_now = (int)date('n');
817e9a45a9Sghi
827e9a45a9Sghi			$entity = '';
837f226579Sghi			if (array_key_exists('entity', $this->value)) {
847f226579Sghi				$entity = ':entity:'.urlencode($this->value['entity']);
857e9a45a9Sghi			}
867e9a45a9Sghi
877e9a45a9Sghi			$mon = $mon_old;
887e9a45a9Sghi			for ($year = $year_old; $year <= $year_now; $year++) {
897f226579Sghi
907f226579Sghi				$y_key = 'bez:report:year:'.$year;
917f226579Sghi				$data[$y_key] = array('id' => $y_key.$entity, 'type' => 'd', 'level' => 3, 'title' => $year);
927f226579Sghi
937f226579Sghi				if (isset($this->value['year']) && (int)$this->value['year'] == $year) {
947f226579Sghi					$data['bez:report:year:'.$year]['open'] = true;
957f226579Sghi
967e9a45a9Sghi					if ($year == $year_now)
977e9a45a9Sghi						$mon_max = $mon_now;
987e9a45a9Sghi					else
997e9a45a9Sghi						$mon_max = 12;
1007e9a45a9Sghi					for ( ; $mon <= $mon_max; $mon++) {
1017e9a45a9Sghi						$m_key = $y_key.':month:'.$mon;
1027f226579Sghi						$data[$m_key] = array('id' => $m_key.$entity, 'type' => 'f', 'level' => 4,
1037e9a45a9Sghi						'title' => $mon < 10 ? '0'.$mon : $mon);
1047e9a45a9Sghi					}
1057f226579Sghi				}
1067e9a45a9Sghi				$mon = 1;
1077e9a45a9Sghi			}
1087f226579Sghi		}
1093cc1f839Sghi
11008e8ea12Sghi
111f01326efSghi
1127f226579Sghi		if (isset($this->value['bez'])) {
113a42d0169Sghi			$data['bez:start']['open'] = true;
11408e8ea12Sghi		} else {
115a42d0169Sghi			$data['bez:start']['open'] = false;
11608e8ea12Sghi			array_splice($data, 1);
11708e8ea12Sghi		}
11808e8ea12Sghi
1197f226579Sghi		if ($helper->user_admin() && $data['bez:start']['open'] == true)
1207f226579Sghi			$data['bez:entity'] = array('id' => 'bez:entity', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('entity_manage'));
1217f226579Sghi
12208e8ea12Sghi        $R->doc .= '<div class="plugin__bez">';
12308e8ea12Sghi        $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li'));
12408e8ea12Sghi        $R->doc .= '</div>';
12508e8ea12Sghi
1265536eef6Sghi		return true;
12708e8ea12Sghi	}
128da9ebf75Sghi
12908e8ea12Sghi	function _bezlink($id, $title) {
1307f226579Sghi		//$uri = wl($id);
1317f226579Sghi		$uri = DOKU_URL . 'doku.php?id='.$id;
132a6dcc2a9Sghi		return '<a href="'.$uri.'">'.($title).'</a>';
13308e8ea12Sghi	}
13408e8ea12Sghi
13508e8ea12Sghi    function _list($item){
13608e8ea12Sghi
1377f226579Sghi		$ex = explode(':', $item['id']);
138*05c9d3bcSghi
1397f226579Sghi		for ($i = 0; $i < count($ex); $i += 2)
1407f226579Sghi			$item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]);
1417f226579Sghi
1427f226579Sghi		//pola brane pod uwagę przy określaniu aktualnej strony
1437f226579Sghi		$fields = array('bez');
1447f226579Sghi		if ($item_value['bez'] == 'report') {
1457f226579Sghi			$fields[] = 'month';
1467f226579Sghi			$fields[] = 'year';
1477f226579Sghi		}
1487f226579Sghi
1497f226579Sghi		$actual_page = true;
1507f226579Sghi		foreach ($fields as $field)
1517f226579Sghi			if ($item_value[$field] != $this->value[$field])
1527f226579Sghi				$actual_page = false;
1537f226579Sghi
1547f226579Sghi
1557f226579Sghi
1567f226579Sghi        if(($item['type'] == 'd' && $item['open']) ||  $actual_page) {
157*05c9d3bcSghi            return '<strong>'.$this->_bezlink($this->lang_code.$item['id'], $item['title']).'</strong>';
15808e8ea12Sghi        }else{
159*05c9d3bcSghi            return $this->_bezlink($this->lang_code.$item['id'], $item['title']);
16008e8ea12Sghi        }
16108e8ea12Sghi
16208e8ea12Sghi    }
16308e8ea12Sghi
16408e8ea12Sghi    function _li($item){
16508e8ea12Sghi        if($item['type'] == "f"){
16608e8ea12Sghi            return '<li class="level'.$item['level'].'">';
16708e8ea12Sghi        }elseif($item['open']){
16808e8ea12Sghi            return '<li class="open">';
16908e8ea12Sghi        }else{
17008e8ea12Sghi            return '<li class="closed">';
17108e8ea12Sghi        }
17265cfcae3Sghi    }
17365cfcae3Sghi}
174