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(); 2005c9d3bcSghi private $lang_code = ''; 2115487902Sghi private $default_lang = 'pl'; 2265cfcae3Sghi 235536eef6Sghi function getPType() { return 'block'; } 2465cfcae3Sghi function getType() { return 'substition'; } 2565cfcae3Sghi function getSort() { return 99; } 2665cfcae3Sghi 2765cfcae3Sghi 2865cfcae3Sghi function connectTo($mode) { 2965cfcae3Sghi $this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav'); 3065cfcae3Sghi } 3165cfcae3Sghi 327f226579Sghi function __construct() { 3315487902Sghi global $conf; 3415487902Sghi 3515487902Sghi $id = $_GET['id']; 3615487902Sghi 3715487902Sghi /*usuń : z początku id - link bezwzględny*/ 3815487902Sghi if ($id[0] == ':') 3915487902Sghi $id = substr($id, 1); 407f226579Sghi 417f226579Sghi $ex = explode(':', $_GET['id']); 4215487902Sghi 4305c9d3bcSghi //wielojęzyczność 4405c9d3bcSghi if ($ex[1] == 'bez') { 4515487902Sghi $this->lang_code = $ex[0]; 4605c9d3bcSghi $ex = array_slice($ex, 1); 4715487902Sghi 4815487902Sghi $old_lang = $conf['lang']; 4915487902Sghi $conf['lang'] = $this->lang_code; 5015487902Sghi $this->setupLocale(); 5115487902Sghi $conf['lang'] = $old_lang; 5215487902Sghi 5315487902Sghi } else { 5415487902Sghi $this->lang_code = $conf['lang']; 5505c9d3bcSghi } 5605c9d3bcSghi 577f226579Sghi for ($i = 0; $i < count($ex); $i += 2) 587f226579Sghi $this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 597f226579Sghi } 607f226579Sghi 6165cfcae3Sghi function handle($match, $state, $pos, &$handler) 6265cfcae3Sghi { 6365cfcae3Sghi return true; 6465cfcae3Sghi } 6565cfcae3Sghi 6608e8ea12Sghi function render($mode, &$R, $pass) { 6708e8ea12Sghi global $INFO; 6865cfcae3Sghi 695536eef6Sghi $helper = $this->loadHelper('bez'); 7008e8ea12Sghi if ($mode != 'xhtml' || !$helper->user_viewer()) return false; 7165cfcae3Sghi 7208e8ea12Sghi $R->info['cache'] = false; 7308e8ea12Sghi 7408e8ea12Sghi $data = array( 75a6dcc2a9Sghi 'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')), 7608e8ea12Sghi ); 7765cfcae3Sghi 785536eef6Sghi if ($helper->user_editor()) 79a6dcc2a9Sghi $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report')); 80a6dcc2a9Sghi 81bb615297Sghi $data['bez:issues'] = array('id' => 'bez:issues:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issues')); 82bb615297Sghi $data['bez:tasks'] = array('id' => 'bez:tasks:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks')); 8365cfcae3Sghi 84*97183698Sghi $data['bez:report_open'] = array('id' => 'bez:report_open', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report_open')); 857e9a45a9Sghi 867f853d3aSghi $isso = new Issues(); 87*97183698Sghi $year_now = (int)date('Y'); 88*97183698Sghi $mon_now = (int)date('n'); 89*97183698Sghi 90*97183698Sghi if ($this->value['bez'] == 'report_open') { 91*97183698Sghi $data['bez:report_open']['open'] = true; 92*97183698Sghi 93*97183698Sghi $oldest = $isso->get_oldest_open_date(); 94*97183698Sghi $year_old = (int)date('Y', $oldest); 95*97183698Sghi $mon_old = (int)date('n', $oldest); 96*97183698Sghi 97*97183698Sghi $mon = $mon_old; 98*97183698Sghi for ($year = $year_old; $year <= $year_now; $year++) { 99*97183698Sghi $y_key = 'bez:report_open:year:'.$year; 100*97183698Sghi $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 101*97183698Sghi 102*97183698Sghi if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 103*97183698Sghi $data['bez:report_open:year:'.$year]['open'] = true; 104*97183698Sghi 105*97183698Sghi if ($year == $year_now) 106*97183698Sghi $mon_max = $mon_now; 107*97183698Sghi else 108*97183698Sghi $mon_max = 12; 109*97183698Sghi for ( ; $mon <= $mon_max; $mon++) { 110*97183698Sghi $m_key = $y_key.':month:'.$mon; 111*97183698Sghi $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 112*97183698Sghi 'title' => $mon < 10 ? '0'.$mon : $mon); 113*97183698Sghi } 114*97183698Sghi } 115*97183698Sghi $mon = 1; 116*97183698Sghi } 117*97183698Sghi } 118*97183698Sghi 119*97183698Sghi $data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report')); 1207f226579Sghi if ($this->value['bez'] == 'report') { 1217f226579Sghi $data['bez:report']['open'] = true; 1227f226579Sghi 123bb615297Sghi $oldest = $isso->get_oldest_close_date(); 1247e9a45a9Sghi $year_old = (int)date('Y', $oldest); 1257e9a45a9Sghi $mon_old = (int)date('n', $oldest); 1267e9a45a9Sghi 1277e9a45a9Sghi $mon = $mon_old; 1287e9a45a9Sghi for ($year = $year_old; $year <= $year_now; $year++) { 1297f226579Sghi 1307f226579Sghi $y_key = 'bez:report:year:'.$year; 13138b5c5c4Sghi $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 1327f226579Sghi 1337f226579Sghi if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 1347f226579Sghi $data['bez:report:year:'.$year]['open'] = true; 1357f226579Sghi 1367e9a45a9Sghi if ($year == $year_now) 1377e9a45a9Sghi $mon_max = $mon_now; 1387e9a45a9Sghi else 1397e9a45a9Sghi $mon_max = 12; 1407e9a45a9Sghi for ( ; $mon <= $mon_max; $mon++) { 1417e9a45a9Sghi $m_key = $y_key.':month:'.$mon; 14238b5c5c4Sghi $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 1437e9a45a9Sghi 'title' => $mon < 10 ? '0'.$mon : $mon); 1447e9a45a9Sghi } 1457f226579Sghi } 1467e9a45a9Sghi $mon = 1; 1477e9a45a9Sghi } 1487f226579Sghi } 1493cc1f839Sghi 15008e8ea12Sghi 151f01326efSghi 1527f226579Sghi if (isset($this->value['bez'])) { 153a42d0169Sghi $data['bez:start']['open'] = true; 15408e8ea12Sghi } else { 155a42d0169Sghi $data['bez:start']['open'] = false; 15608e8ea12Sghi array_splice($data, 1); 15708e8ea12Sghi } 15808e8ea12Sghi 1597f226579Sghi if ($helper->user_admin() && $data['bez:start']['open'] == true) 160eb950a4cSghi $data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('types_manage')); 1617f226579Sghi 16208e8ea12Sghi $R->doc .= '<div class="plugin__bez">'; 16308e8ea12Sghi $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 16408e8ea12Sghi $R->doc .= '</div>'; 16508e8ea12Sghi 1665536eef6Sghi return true; 16708e8ea12Sghi } 168da9ebf75Sghi 16908e8ea12Sghi function _bezlink($id, $title) { 1707f226579Sghi //$uri = wl($id); 1717f226579Sghi $uri = DOKU_URL . 'doku.php?id='.$id; 172a6dcc2a9Sghi return '<a href="'.$uri.'">'.($title).'</a>'; 17308e8ea12Sghi } 17408e8ea12Sghi 17508e8ea12Sghi function _list($item){ 17608e8ea12Sghi 1777f226579Sghi $ex = explode(':', $item['id']); 17805c9d3bcSghi 1797f226579Sghi for ($i = 0; $i < count($ex); $i += 2) 1807f226579Sghi $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 1817f226579Sghi 1827f226579Sghi //pola brane pod uwagę przy określaniu aktualnej strony 1837f226579Sghi $fields = array('bez'); 184*97183698Sghi if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') { 1857f226579Sghi $fields[] = 'month'; 1867f226579Sghi $fields[] = 'year'; 1877f226579Sghi } 1887f226579Sghi 1897f226579Sghi $actual_page = true; 1907f226579Sghi foreach ($fields as $field) 1917f226579Sghi if ($item_value[$field] != $this->value[$field]) 1927f226579Sghi $actual_page = false; 1937f226579Sghi 1947f226579Sghi 1957f226579Sghi 1967f226579Sghi if(($item['type'] == 'd' && $item['open']) || $actual_page) { 19715487902Sghi $id = $item['id']; 19815487902Sghi if ($this->lang_code != $this->default_lang) 19915487902Sghi $id = $this->lang_code.':'.$id; 20015487902Sghi return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 20108e8ea12Sghi }else{ 20215487902Sghi $id = $item['id']; 20315487902Sghi if ($this->lang_code != $this->default_lang) 20415487902Sghi $id = $this->lang_code.':'.$id; 20515487902Sghi return $this->_bezlink($id, $item['title']); 20608e8ea12Sghi } 20708e8ea12Sghi 20808e8ea12Sghi } 20908e8ea12Sghi 21008e8ea12Sghi function _li($item){ 21108e8ea12Sghi if($item['type'] == "f"){ 21208e8ea12Sghi return '<li class="level'.$item['level'].'">'; 21308e8ea12Sghi }elseif($item['open']){ 21408e8ea12Sghi return '<li class="open">'; 21508e8ea12Sghi }else{ 21608e8ea12Sghi return '<li class="closed">'; 21708e8ea12Sghi } 21865cfcae3Sghi } 21965cfcae3Sghi} 220