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"; 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 623b3e3ab0Sghi function handle($match, $state, $pos, Doku_Handler $handler) 6365cfcae3Sghi { 6465cfcae3Sghi return true; 6565cfcae3Sghi } 6665cfcae3Sghi 673b3e3ab0Sghi function render($mode, Doku_Renderer $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 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 887ffa8289Sghi if (in_array($this->value['bez'], $issue_pages) || ($this->value[bez] == 'issue_report' && isset($this->value[id]))) { 8927712358Sghi $data['bez:issues']['open'] = true; 9027712358Sghi $id = (int)$this->value[id]; 9127712358Sghi 929a30fd19Sghi $isso = new Issues(); 939a30fd19Sghi $issue_opened = $isso->opened($id); 94*489061b8Sghi $issue_proposal = $isso->is_proposal($id); 959a30fd19Sghi 9627712358Sghi $tasko = new Tasks(); 9727712358Sghi $causo = new Causes(); 9827712358Sghi 9927712358Sghi $pid = "bez:issue:id:$id"; 10027712358Sghi $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 3, 10127712358Sghi 'title' => "#$id", 'open' => true); 10227712358Sghi 10327712358Sghi $pid = "bez:issue_tasks:id:$id"; 10427712358Sghi $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 1059fbfe943Sghi 'title' => $this->getLang('correction_nav')); 1069fbfe943Sghi if (in_array($this->value['bez'], $task_pages) && $this->value[cid] == '') { 10727712358Sghi $data[$pid][open] = true; 1089a30fd19Sghi 1099a30fd19Sghi if ($issue_opened) { 11027712358Sghi $rpid = "bez:task_form:id:$id"; 111*489061b8Sghi if ($helper->user_admin() && !$issue_proposal) 11227712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 11327712358Sghi 'title' => $this->getLang('add_correction')); 1149a30fd19Sghi } 1159fbfe943Sghi $res = $tasko->get_filtered(array('issue' => $id, 'action' => '0')); 11627712358Sghi foreach ($res as $r) { 11727712358Sghi $rpid = "bez:issue_task:id:$id:tid:$r[id]"; 11827712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 11927712358Sghi 'title' => '#z'.$r[id]); 12027712358Sghi } 12127712358Sghi } 12227712358Sghi 12327712358Sghi $pid = "bez:issue_causes:id:$id"; 12427712358Sghi $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 12527712358Sghi 'title' => $this->getLang('causes')); 1269fbfe943Sghi if (in_array($this->value['bez'], $cause_pages) || $this->value[cid] != '') { 12727712358Sghi $data[$pid][open] = true; 1289a30fd19Sghi if ($issue_opened) { 12927712358Sghi $rpid = "bez:cause_form:id:$id"; 130*489061b8Sghi if ($helper->user_admin() && !$issue_proposal) 13127712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 13227712358Sghi 'title' => $this->getLang('add_cause')); 1339a30fd19Sghi } 1349fbfe943Sghi $res = $causo->get($id); 13527712358Sghi foreach ($res as $r) { 13627712358Sghi $rpid = "bez:issue_cause:id:$id:cid:$r[id]"; 1379fbfe943Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'd', 'level' => 5, 13827712358Sghi 'title' => '#p'.$r[id]); 1399fbfe943Sghi 14027712358Sghi if ((int)$this->value['cid'] == $r[id]) { 14127712358Sghi $data[$rpid][open] = true; 14227712358Sghi 14327712358Sghi $pres = $tasko->get($id, $r['id']); 14427712358Sghi foreach ($pres as $pr) { 1459fbfe943Sghi $rptid = "bez:issue_cause_task:id:$id:cid:$r[id]:tid:$pr[id]"; 1469fbfe943Sghi $data[$rptid] = array('id' => $rptid, 'type' => 'f', 'level' => 6, 1479fbfe943Sghi 'title' => '#z'.$pr[id]); 1489fbfe943Sghi 14927712358Sghi } 15027712358Sghi } 1519fbfe943Sghi } 15227712358Sghi 15327712358Sghi } 15427712358Sghi 15527712358Sghi } 1564fb0d798Sghi $data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks')); 15765cfcae3Sghi 15897183698Sghi $data['bez:report_open'] = array('id' => 'bez:report_open', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report_open')); 1597e9a45a9Sghi 1607f853d3aSghi $isso = new Issues(); 16197183698Sghi $year_now = (int)date('Y'); 16297183698Sghi $mon_now = (int)date('n'); 16397183698Sghi 16497183698Sghi if ($this->value['bez'] == 'report_open') { 16597183698Sghi $data['bez:report_open']['open'] = true; 16697183698Sghi 16797183698Sghi $oldest = $isso->get_oldest_open_date(); 16897183698Sghi $year_old = (int)date('Y', $oldest); 16997183698Sghi $mon_old = (int)date('n', $oldest); 17097183698Sghi 17197183698Sghi $mon = $mon_old; 17297183698Sghi for ($year = $year_old; $year <= $year_now; $year++) { 17397183698Sghi $y_key = 'bez:report_open:year:'.$year; 17497183698Sghi $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 17597183698Sghi 17697183698Sghi if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 17797183698Sghi $data['bez:report_open:year:'.$year]['open'] = true; 17897183698Sghi 17997183698Sghi if ($year == $year_now) 18097183698Sghi $mon_max = $mon_now; 18197183698Sghi else 18297183698Sghi $mon_max = 12; 18397183698Sghi for ( ; $mon <= $mon_max; $mon++) { 18497183698Sghi $m_key = $y_key.':month:'.$mon; 18597183698Sghi $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 18697183698Sghi 'title' => $mon < 10 ? '0'.$mon : $mon); 18797183698Sghi } 18897183698Sghi } 18997183698Sghi $mon = 1; 19097183698Sghi } 19197183698Sghi } 19297183698Sghi 19397183698Sghi $data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report')); 1947f226579Sghi if ($this->value['bez'] == 'report') { 1957f226579Sghi $data['bez:report']['open'] = true; 1967f226579Sghi 197bb615297Sghi $oldest = $isso->get_oldest_close_date(); 1987e9a45a9Sghi $year_old = (int)date('Y', $oldest); 1997e9a45a9Sghi $mon_old = (int)date('n', $oldest); 2007e9a45a9Sghi 2017e9a45a9Sghi $mon = $mon_old; 2027e9a45a9Sghi for ($year = $year_old; $year <= $year_now; $year++) { 2037f226579Sghi 2047f226579Sghi $y_key = 'bez:report:year:'.$year; 20538b5c5c4Sghi $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 2067f226579Sghi 2077f226579Sghi if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 2087f226579Sghi $data['bez:report:year:'.$year]['open'] = true; 2097f226579Sghi 2107e9a45a9Sghi if ($year == $year_now) 2117e9a45a9Sghi $mon_max = $mon_now; 2127e9a45a9Sghi else 2137e9a45a9Sghi $mon_max = 12; 2147e9a45a9Sghi for ( ; $mon <= $mon_max; $mon++) { 2157e9a45a9Sghi $m_key = $y_key.':month:'.$mon; 21638b5c5c4Sghi $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 2177e9a45a9Sghi 'title' => $mon < 10 ? '0'.$mon : $mon); 2187e9a45a9Sghi } 2197f226579Sghi } 2207e9a45a9Sghi $mon = 1; 2217e9a45a9Sghi } 2227f226579Sghi } 2233cc1f839Sghi 22408e8ea12Sghi 225f01326efSghi 2267f226579Sghi if (isset($this->value['bez'])) { 227a42d0169Sghi $data['bez:start']['open'] = true; 22808e8ea12Sghi } else { 229a42d0169Sghi $data['bez:start']['open'] = false; 23008e8ea12Sghi array_splice($data, 1); 23108e8ea12Sghi } 23208e8ea12Sghi 23380487b8aSghi if ($helper->user_admin() && $data['bez:start']['open'] == true) { 23480487b8aSghi $data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' => 23580487b8aSghi $this->getLang('types_manage')); 23680487b8aSghi $data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' => 23780487b8aSghi $this->getLang('root_causes')); 23880487b8aSghi } 2397f226579Sghi 24008e8ea12Sghi $R->doc .= '<div class="plugin__bez">'; 24108e8ea12Sghi $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 24208e8ea12Sghi $R->doc .= '</div>'; 24308e8ea12Sghi 2445536eef6Sghi return true; 24508e8ea12Sghi } 246da9ebf75Sghi 24708e8ea12Sghi function _bezlink($id, $title) { 2487f226579Sghi //$uri = wl($id); 2497f226579Sghi $uri = DOKU_URL . 'doku.php?id='.$id; 250a6dcc2a9Sghi return '<a href="'.$uri.'">'.($title).'</a>'; 25108e8ea12Sghi } 25208e8ea12Sghi 25308e8ea12Sghi function _list($item){ 25408e8ea12Sghi 2557f226579Sghi $ex = explode(':', $item['id']); 25605c9d3bcSghi 2577f226579Sghi for ($i = 0; $i < count($ex); $i += 2) 2587f226579Sghi $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 2597f226579Sghi 2607f226579Sghi //pola brane pod uwagę przy określaniu aktualnej strony 2612106ae3bSghi $fields = array('bez', 'tid', 'cid'); 26297183698Sghi if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') { 2637f226579Sghi $fields[] = 'month'; 2647f226579Sghi $fields[] = 'year'; 2657f226579Sghi } 2669fbfe943Sghi if ($this->value[bez] == 'task_form' && isset($this->value[cid])) 2679fbfe943Sghi unset($fields[0]); 2687f226579Sghi 2697f226579Sghi $actual_page = true; 2707f226579Sghi foreach ($fields as $field) 2717f226579Sghi if ($item_value[$field] != $this->value[$field]) 2727f226579Sghi $actual_page = false; 2737f226579Sghi 2747f226579Sghi 2757f226579Sghi 2767f226579Sghi if(($item['type'] == 'd' && $item['open']) || $actual_page) { 27715487902Sghi $id = $item['id']; 27815487902Sghi if ($this->lang_code != $this->default_lang) 27915487902Sghi $id = $this->lang_code.':'.$id; 28015487902Sghi return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 28108e8ea12Sghi }else{ 28215487902Sghi $id = $item['id']; 28315487902Sghi if ($this->lang_code != $this->default_lang) 28415487902Sghi $id = $this->lang_code.':'.$id; 28515487902Sghi return $this->_bezlink($id, $item['title']); 28608e8ea12Sghi } 28708e8ea12Sghi 28808e8ea12Sghi } 28908e8ea12Sghi 29008e8ea12Sghi function _li($item){ 29108e8ea12Sghi if($item['type'] == "f"){ 29208e8ea12Sghi return '<li class="level'.$item['level'].'">'; 29308e8ea12Sghi }elseif($item['open']){ 29408e8ea12Sghi return '<li class="open">'; 29508e8ea12Sghi }else{ 29608e8ea12Sghi return '<li class="closed">'; 29708e8ea12Sghi } 29865cfcae3Sghi } 29965cfcae3Sghi} 300