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 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 8227712358Sghi $data['bez:issues'] = array('id' => 'bez:issues:year:'.date('Y'), 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bds_issues')); 8327712358Sghi 8427712358Sghi $task_pages = array('issue_tasks', 'task_form', 'issue_task'); 8527712358Sghi $cause_pages = array('issue_causes', 'issue_cause', 'cause_form'); 869a30fd19Sghi $issue_pages = array_merge(array('issue', 'rr', '8d'), $task_pages, $cause_pages); 8727712358Sghi 88*7ffa8289Sghi 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); 949a30fd19Sghi 9527712358Sghi $tasko = new Tasks(); 9627712358Sghi $causo = new Causes(); 9727712358Sghi 9827712358Sghi $pid = "bez:issue:id:$id"; 9927712358Sghi $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 3, 10027712358Sghi 'title' => "#$id", 'open' => true); 10127712358Sghi 10227712358Sghi $pid = "bez:issue_tasks:id:$id"; 10327712358Sghi $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 10427712358Sghi 'title' => $this->getLang('tasks')); 10527712358Sghi if (in_array($this->value['bez'], $task_pages)) { 10627712358Sghi $data[$pid][open] = true; 1079a30fd19Sghi 1089a30fd19Sghi if ($issue_opened) { 10927712358Sghi $rpid = "bez:task_form:id:$id"; 11027712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 11127712358Sghi 'title' => $this->getLang('add_correction')); 1129a30fd19Sghi } 11327712358Sghi $res = $tasko->get_filtered(array('issue' => $id)); 11427712358Sghi foreach ($res as $r) { 11527712358Sghi $rpid = "bez:issue_task:id:$id:tid:$r[id]"; 11627712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 11727712358Sghi 'title' => '#z'.$r[id]); 11827712358Sghi } 11927712358Sghi } 12027712358Sghi 12127712358Sghi $pid = "bez:issue_causes:id:$id"; 12227712358Sghi $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 12327712358Sghi 'title' => $this->getLang('causes')); 12427712358Sghi if (in_array($this->value['bez'], $cause_pages)) { 12527712358Sghi $data[$pid][open] = true; 1269a30fd19Sghi if ($issue_opened) { 12727712358Sghi $rpid = "bez:cause_form:id:$id"; 12827712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 12927712358Sghi 'title' => $this->getLang('add_cause')); 1309a30fd19Sghi } 13127712358Sghi /*$res = $causo->get($id); 13227712358Sghi foreach ($res as $r) { 13327712358Sghi $rpid = "bez:issue_cause:id:$id:cid:$r[id]"; 13427712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 13527712358Sghi 'title' => '#p'.$r[id]); 13627712358Sghi/* 13727712358Sghi if ((int)$this->value['cid'] == $r[id]) { 13827712358Sghi $data[$rpid][open] = true; 13927712358Sghi 14027712358Sghi $pres = $tasko->get($id, $r['id']); 14127712358Sghi foreach ($pres as $pr) { 14227712358Sghi } 14327712358Sghi } 14427712358Sghi }*/ 14527712358Sghi 14627712358Sghi } 14727712358Sghi 14827712358Sghi } 149bb615297Sghi $data['bez:tasks'] = array('id' => 'bez:tasks:year:'.date('Y'), 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks')); 15065cfcae3Sghi 15197183698Sghi $data['bez:report_open'] = array('id' => 'bez:report_open', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report_open')); 1527e9a45a9Sghi 1537f853d3aSghi $isso = new Issues(); 15497183698Sghi $year_now = (int)date('Y'); 15597183698Sghi $mon_now = (int)date('n'); 15697183698Sghi 15797183698Sghi if ($this->value['bez'] == 'report_open') { 15897183698Sghi $data['bez:report_open']['open'] = true; 15997183698Sghi 16097183698Sghi $oldest = $isso->get_oldest_open_date(); 16197183698Sghi $year_old = (int)date('Y', $oldest); 16297183698Sghi $mon_old = (int)date('n', $oldest); 16397183698Sghi 16497183698Sghi $mon = $mon_old; 16597183698Sghi for ($year = $year_old; $year <= $year_now; $year++) { 16697183698Sghi $y_key = 'bez:report_open:year:'.$year; 16797183698Sghi $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 16897183698Sghi 16997183698Sghi if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 17097183698Sghi $data['bez:report_open:year:'.$year]['open'] = true; 17197183698Sghi 17297183698Sghi if ($year == $year_now) 17397183698Sghi $mon_max = $mon_now; 17497183698Sghi else 17597183698Sghi $mon_max = 12; 17697183698Sghi for ( ; $mon <= $mon_max; $mon++) { 17797183698Sghi $m_key = $y_key.':month:'.$mon; 17897183698Sghi $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 17997183698Sghi 'title' => $mon < 10 ? '0'.$mon : $mon); 18097183698Sghi } 18197183698Sghi } 18297183698Sghi $mon = 1; 18397183698Sghi } 18497183698Sghi } 18597183698Sghi 18697183698Sghi $data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report')); 1877f226579Sghi if ($this->value['bez'] == 'report') { 1887f226579Sghi $data['bez:report']['open'] = true; 1897f226579Sghi 190bb615297Sghi $oldest = $isso->get_oldest_close_date(); 1917e9a45a9Sghi $year_old = (int)date('Y', $oldest); 1927e9a45a9Sghi $mon_old = (int)date('n', $oldest); 1937e9a45a9Sghi 1947e9a45a9Sghi $mon = $mon_old; 1957e9a45a9Sghi for ($year = $year_old; $year <= $year_now; $year++) { 1967f226579Sghi 1977f226579Sghi $y_key = 'bez:report:year:'.$year; 19838b5c5c4Sghi $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 1997f226579Sghi 2007f226579Sghi if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 2017f226579Sghi $data['bez:report:year:'.$year]['open'] = true; 2027f226579Sghi 2037e9a45a9Sghi if ($year == $year_now) 2047e9a45a9Sghi $mon_max = $mon_now; 2057e9a45a9Sghi else 2067e9a45a9Sghi $mon_max = 12; 2077e9a45a9Sghi for ( ; $mon <= $mon_max; $mon++) { 2087e9a45a9Sghi $m_key = $y_key.':month:'.$mon; 20938b5c5c4Sghi $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 2107e9a45a9Sghi 'title' => $mon < 10 ? '0'.$mon : $mon); 2117e9a45a9Sghi } 2127f226579Sghi } 2137e9a45a9Sghi $mon = 1; 2147e9a45a9Sghi } 2157f226579Sghi } 2163cc1f839Sghi 21708e8ea12Sghi 218f01326efSghi 2197f226579Sghi if (isset($this->value['bez'])) { 220a42d0169Sghi $data['bez:start']['open'] = true; 22108e8ea12Sghi } else { 222a42d0169Sghi $data['bez:start']['open'] = false; 22308e8ea12Sghi array_splice($data, 1); 22408e8ea12Sghi } 22508e8ea12Sghi 2267f226579Sghi if ($helper->user_admin() && $data['bez:start']['open'] == true) 227eb950a4cSghi $data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('types_manage')); 2287f226579Sghi 22908e8ea12Sghi $R->doc .= '<div class="plugin__bez">'; 23008e8ea12Sghi $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 23108e8ea12Sghi $R->doc .= '</div>'; 23208e8ea12Sghi 2335536eef6Sghi return true; 23408e8ea12Sghi } 235da9ebf75Sghi 23608e8ea12Sghi function _bezlink($id, $title) { 2377f226579Sghi //$uri = wl($id); 2387f226579Sghi $uri = DOKU_URL . 'doku.php?id='.$id; 239a6dcc2a9Sghi return '<a href="'.$uri.'">'.($title).'</a>'; 24008e8ea12Sghi } 24108e8ea12Sghi 24208e8ea12Sghi function _list($item){ 24308e8ea12Sghi 2447f226579Sghi $ex = explode(':', $item['id']); 24505c9d3bcSghi 2467f226579Sghi for ($i = 0; $i < count($ex); $i += 2) 2477f226579Sghi $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 2487f226579Sghi 2497f226579Sghi //pola brane pod uwagę przy określaniu aktualnej strony 25027712358Sghi $fields = array('bez', 'year', 'tid'); 25197183698Sghi if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') { 2527f226579Sghi $fields[] = 'month'; 2537f226579Sghi $fields[] = 'year'; 2547f226579Sghi } 2557f226579Sghi 2567f226579Sghi $actual_page = true; 2577f226579Sghi foreach ($fields as $field) 2587f226579Sghi if ($item_value[$field] != $this->value[$field]) 2597f226579Sghi $actual_page = false; 2607f226579Sghi 2617f226579Sghi 2627f226579Sghi 2637f226579Sghi if(($item['type'] == 'd' && $item['open']) || $actual_page) { 26415487902Sghi $id = $item['id']; 26515487902Sghi if ($this->lang_code != $this->default_lang) 26615487902Sghi $id = $this->lang_code.':'.$id; 26715487902Sghi return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 26808e8ea12Sghi }else{ 26915487902Sghi $id = $item['id']; 27015487902Sghi if ($this->lang_code != $this->default_lang) 27115487902Sghi $id = $this->lang_code.':'.$id; 27215487902Sghi return $this->_bezlink($id, $item['title']); 27308e8ea12Sghi } 27408e8ea12Sghi 27508e8ea12Sghi } 27608e8ea12Sghi 27708e8ea12Sghi function _li($item){ 27808e8ea12Sghi if($item['type'] == "f"){ 27908e8ea12Sghi return '<li class="level'.$item['level'].'">'; 28008e8ea12Sghi }elseif($item['open']){ 28108e8ea12Sghi return '<li class="open">'; 28208e8ea12Sghi }else{ 28308e8ea12Sghi return '<li class="closed">'; 28408e8ea12Sghi } 28565cfcae3Sghi } 28665cfcae3Sghi} 287