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"; 13*27712358Sghiinclude_once DOKU_PLUGIN."bez/models/causes.php"; 14*27712358Sghiinclude_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 6265cfcae3Sghi function handle($match, $state, $pos, &$handler) 6365cfcae3Sghi { 6465cfcae3Sghi return true; 6565cfcae3Sghi } 6665cfcae3Sghi 6708e8ea12Sghi function render($mode, &$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 795536eef6Sghi if ($helper->user_editor()) 80a6dcc2a9Sghi $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report')); 81a6dcc2a9Sghi 82*27712358Sghi $data['bez:issues'] = array('id' => 'bez:issues:year:'.date('Y'), 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bds_issues')); 83*27712358Sghi 84*27712358Sghi $task_pages = array('issue_tasks', 'task_form', 'issue_task'); 85*27712358Sghi $cause_pages = array('issue_causes', 'issue_cause', 'cause_form'); 86*27712358Sghi $issue_pages = array_merge(array('issue'), $task_pages, $cause_pages); 87*27712358Sghi 88*27712358Sghi if (in_array($this->value['bez'], $issue_pages)) { 89*27712358Sghi $data['bez:issues']['open'] = true; 90*27712358Sghi $id = (int)$this->value[id]; 91*27712358Sghi 92*27712358Sghi $tasko = new Tasks(); 93*27712358Sghi $causo = new Causes(); 94*27712358Sghi 95*27712358Sghi $pid = "bez:issue:id:$id"; 96*27712358Sghi $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 3, 97*27712358Sghi 'title' => "#$id", 'open' => true); 98*27712358Sghi 99*27712358Sghi $pid = "bez:issue_tasks:id:$id"; 100*27712358Sghi $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 101*27712358Sghi 'title' => $this->getLang('tasks')); 102*27712358Sghi if (in_array($this->value['bez'], $task_pages)) { 103*27712358Sghi $data[$pid][open] = true; 104*27712358Sghi $rpid = "bez:task_form:id:$id"; 105*27712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 106*27712358Sghi 'title' => $this->getLang('add_correction')); 107*27712358Sghi $res = $tasko->get_filtered(array('issue' => $id)); 108*27712358Sghi foreach ($res as $r) { 109*27712358Sghi $rpid = "bez:issue_task:id:$id:tid:$r[id]"; 110*27712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 111*27712358Sghi 'title' => '#z'.$r[id]); 112*27712358Sghi } 113*27712358Sghi } 114*27712358Sghi 115*27712358Sghi $pid = "bez:issue_causes:id:$id"; 116*27712358Sghi $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 117*27712358Sghi 'title' => $this->getLang('causes')); 118*27712358Sghi if (in_array($this->value['bez'], $cause_pages)) { 119*27712358Sghi $data[$pid][open] = true; 120*27712358Sghi $rpid = "bez:cause_form:id:$id"; 121*27712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 122*27712358Sghi 'title' => $this->getLang('add_cause')); 123*27712358Sghi /*$res = $causo->get($id); 124*27712358Sghi foreach ($res as $r) { 125*27712358Sghi $rpid = "bez:issue_cause:id:$id:cid:$r[id]"; 126*27712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 127*27712358Sghi 'title' => '#p'.$r[id]); 128*27712358Sghi/* 129*27712358Sghi if ((int)$this->value['cid'] == $r[id]) { 130*27712358Sghi $data[$rpid][open] = true; 131*27712358Sghi 132*27712358Sghi $pres = $tasko->get($id, $r['id']); 133*27712358Sghi foreach ($pres as $pr) { 134*27712358Sghi } 135*27712358Sghi } 136*27712358Sghi }*/ 137*27712358Sghi 138*27712358Sghi } 139*27712358Sghi 140*27712358Sghi } 141bb615297Sghi $data['bez:tasks'] = array('id' => 'bez:tasks:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks')); 14265cfcae3Sghi 14397183698Sghi $data['bez:report_open'] = array('id' => 'bez:report_open', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report_open')); 1447e9a45a9Sghi 1457f853d3aSghi $isso = new Issues(); 14697183698Sghi $year_now = (int)date('Y'); 14797183698Sghi $mon_now = (int)date('n'); 14897183698Sghi 14997183698Sghi if ($this->value['bez'] == 'report_open') { 15097183698Sghi $data['bez:report_open']['open'] = true; 15197183698Sghi 15297183698Sghi $oldest = $isso->get_oldest_open_date(); 15397183698Sghi $year_old = (int)date('Y', $oldest); 15497183698Sghi $mon_old = (int)date('n', $oldest); 15597183698Sghi 15697183698Sghi $mon = $mon_old; 15797183698Sghi for ($year = $year_old; $year <= $year_now; $year++) { 15897183698Sghi $y_key = 'bez:report_open:year:'.$year; 15997183698Sghi $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 16097183698Sghi 16197183698Sghi if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 16297183698Sghi $data['bez:report_open:year:'.$year]['open'] = true; 16397183698Sghi 16497183698Sghi if ($year == $year_now) 16597183698Sghi $mon_max = $mon_now; 16697183698Sghi else 16797183698Sghi $mon_max = 12; 16897183698Sghi for ( ; $mon <= $mon_max; $mon++) { 16997183698Sghi $m_key = $y_key.':month:'.$mon; 17097183698Sghi $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 17197183698Sghi 'title' => $mon < 10 ? '0'.$mon : $mon); 17297183698Sghi } 17397183698Sghi } 17497183698Sghi $mon = 1; 17597183698Sghi } 17697183698Sghi } 17797183698Sghi 17897183698Sghi $data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report')); 1797f226579Sghi if ($this->value['bez'] == 'report') { 1807f226579Sghi $data['bez:report']['open'] = true; 1817f226579Sghi 182bb615297Sghi $oldest = $isso->get_oldest_close_date(); 1837e9a45a9Sghi $year_old = (int)date('Y', $oldest); 1847e9a45a9Sghi $mon_old = (int)date('n', $oldest); 1857e9a45a9Sghi 1867e9a45a9Sghi $mon = $mon_old; 1877e9a45a9Sghi for ($year = $year_old; $year <= $year_now; $year++) { 1887f226579Sghi 1897f226579Sghi $y_key = 'bez:report:year:'.$year; 19038b5c5c4Sghi $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 1917f226579Sghi 1927f226579Sghi if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 1937f226579Sghi $data['bez:report:year:'.$year]['open'] = true; 1947f226579Sghi 1957e9a45a9Sghi if ($year == $year_now) 1967e9a45a9Sghi $mon_max = $mon_now; 1977e9a45a9Sghi else 1987e9a45a9Sghi $mon_max = 12; 1997e9a45a9Sghi for ( ; $mon <= $mon_max; $mon++) { 2007e9a45a9Sghi $m_key = $y_key.':month:'.$mon; 20138b5c5c4Sghi $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 2027e9a45a9Sghi 'title' => $mon < 10 ? '0'.$mon : $mon); 2037e9a45a9Sghi } 2047f226579Sghi } 2057e9a45a9Sghi $mon = 1; 2067e9a45a9Sghi } 2077f226579Sghi } 2083cc1f839Sghi 20908e8ea12Sghi 210f01326efSghi 2117f226579Sghi if (isset($this->value['bez'])) { 212a42d0169Sghi $data['bez:start']['open'] = true; 21308e8ea12Sghi } else { 214a42d0169Sghi $data['bez:start']['open'] = false; 21508e8ea12Sghi array_splice($data, 1); 21608e8ea12Sghi } 21708e8ea12Sghi 2187f226579Sghi if ($helper->user_admin() && $data['bez:start']['open'] == true) 219eb950a4cSghi $data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('types_manage')); 2207f226579Sghi 22108e8ea12Sghi $R->doc .= '<div class="plugin__bez">'; 22208e8ea12Sghi $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 22308e8ea12Sghi $R->doc .= '</div>'; 22408e8ea12Sghi 2255536eef6Sghi return true; 22608e8ea12Sghi } 227da9ebf75Sghi 22808e8ea12Sghi function _bezlink($id, $title) { 2297f226579Sghi //$uri = wl($id); 2307f226579Sghi $uri = DOKU_URL . 'doku.php?id='.$id; 231a6dcc2a9Sghi return '<a href="'.$uri.'">'.($title).'</a>'; 23208e8ea12Sghi } 23308e8ea12Sghi 23408e8ea12Sghi function _list($item){ 23508e8ea12Sghi 2367f226579Sghi $ex = explode(':', $item['id']); 23705c9d3bcSghi 2387f226579Sghi for ($i = 0; $i < count($ex); $i += 2) 2397f226579Sghi $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 2407f226579Sghi 2417f226579Sghi //pola brane pod uwagę przy określaniu aktualnej strony 242*27712358Sghi $fields = array('bez', 'year', 'tid'); 24397183698Sghi if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') { 2447f226579Sghi $fields[] = 'month'; 2457f226579Sghi $fields[] = 'year'; 2467f226579Sghi } 2477f226579Sghi 2487f226579Sghi $actual_page = true; 2497f226579Sghi foreach ($fields as $field) 2507f226579Sghi if ($item_value[$field] != $this->value[$field]) 2517f226579Sghi $actual_page = false; 2527f226579Sghi 2537f226579Sghi 2547f226579Sghi 2557f226579Sghi if(($item['type'] == 'd' && $item['open']) || $actual_page) { 25615487902Sghi $id = $item['id']; 25715487902Sghi if ($this->lang_code != $this->default_lang) 25815487902Sghi $id = $this->lang_code.':'.$id; 25915487902Sghi return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 26008e8ea12Sghi }else{ 26115487902Sghi $id = $item['id']; 26215487902Sghi if ($this->lang_code != $this->default_lang) 26315487902Sghi $id = $this->lang_code.':'.$id; 26415487902Sghi return $this->_bezlink($id, $item['title']); 26508e8ea12Sghi } 26608e8ea12Sghi 26708e8ea12Sghi } 26808e8ea12Sghi 26908e8ea12Sghi function _li($item){ 27008e8ea12Sghi if($item['type'] == "f"){ 27108e8ea12Sghi return '<li class="level'.$item['level'].'">'; 27208e8ea12Sghi }elseif($item['open']){ 27308e8ea12Sghi return '<li class="open">'; 27408e8ea12Sghi }else{ 27508e8ea12Sghi return '<li class="closed">'; 27608e8ea12Sghi } 27765cfcae3Sghi } 27865cfcae3Sghi} 279