1<?php 2/** 3 * Plugin Now: Inserts a timestamp. 4 * 5 */ 6 7// must be run within DokuWiki 8if(!defined('DOKU_INC')) die(); 9 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once DOKU_PLUGIN.'syntax.php'; 12include_once DOKU_PLUGIN."bez/models/issues.php"; 13include_once DOKU_PLUGIN."bez/models/causes.php"; 14include_once DOKU_PLUGIN."bez/models/tasks.php"; 15/** 16 * All DokuWiki plugins to extend the parser/rendering mechanism 17 * need to inherit from this class 18 */ 19class syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin { 20 private $value = array(); 21 private $lang_code = ''; 22 private $default_lang = 'pl'; 23 24 function getPType() { return 'block'; } 25 function getType() { return 'substition'; } 26 function getSort() { return 99; } 27 28 29 function connectTo($mode) { 30 $this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav'); 31 } 32 33 function __construct() { 34 global $conf; 35 36 $id = $_GET['id']; 37 38 /*usuń : z początku id - link bezwzględny*/ 39 if ($id[0] == ':') 40 $id = substr($id, 1); 41 42 $ex = explode(':', $_GET['id']); 43 44 //wielojęzyczność 45 if ($ex[1] == 'bez') { 46 $this->lang_code = $ex[0]; 47 $ex = array_slice($ex, 1); 48 49 $old_lang = $conf['lang']; 50 $conf['lang'] = $this->lang_code; 51 $this->setupLocale(); 52 $conf['lang'] = $old_lang; 53 54 } else { 55 $this->lang_code = $conf['lang']; 56 } 57 58 for ($i = 0; $i < count($ex); $i += 2) 59 $this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 60 } 61 62 function handle($match, $state, $pos, Doku_Handler $handler) 63 { 64 return true; 65 } 66 67 function render($mode, Doku_Renderer $R, $pass) { 68 global $INFO; 69 70 $helper = $this->loadHelper('bez'); 71 if ($mode != 'xhtml' || !$helper->user_viewer()) return false; 72 73 $R->info['cache'] = false; 74 75 $data = array( 76 'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')), 77 ); 78 79 if ($helper->user_editor()) 80 $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report')); 81 82 $data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bds_issues')); 83 84 $task_pages = array('issue_tasks', 'task_form', 'issue_task'); 85 $cause_pages = array('issue_causes', 'issue_cause', 'cause_form', 'issue_cause_task'); 86 $issue_pages = array_merge(array('issue', 'rr', '8d'), $task_pages, $cause_pages); 87 88 if (in_array($this->value['bez'], $issue_pages) || ($this->value[bez] == 'issue_report' && isset($this->value[id]))) { 89 $data['bez:issues']['open'] = true; 90 $id = (int)$this->value[id]; 91 92 $isso = new Issues(); 93 $issue_opened = $isso->opened($id); 94 $issue_proposal = $isso->is_proposal($id); 95 96 $tasko = new Tasks(); 97 $causo = new Causes(); 98 99 $pid = "bez:issue:id:$id"; 100 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 3, 101 'title' => "#$id", 'open' => true); 102 103 $pid = "bez:issue_tasks:id:$id"; 104 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 105 'title' => $this->getLang('correction_nav')); 106 if (in_array($this->value['bez'], $task_pages) && $this->value[cid] == '') { 107 $data[$pid][open] = true; 108 109 if ($issue_opened) { 110 $rpid = "bez:task_form:id:$id"; 111 if ($helper->user_admin() && !$issue_proposal) 112 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 113 'title' => $this->getLang('add_correction')); 114 } 115 $res = $tasko->get_filtered(array('issue' => $id, 'action' => '0')); 116 foreach ($res as $r) { 117 $rpid = "bez:issue_task:id:$id:tid:$r[id]"; 118 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 119 'title' => '#z'.$r[id]); 120 } 121 } 122 123 $pid = "bez:issue_causes:id:$id"; 124 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 125 'title' => $this->getLang('causes')); 126 if (in_array($this->value['bez'], $cause_pages) || $this->value[cid] != '') { 127 $data[$pid][open] = true; 128 if ($issue_opened) { 129 $rpid = "bez:cause_form:id:$id"; 130 if ($helper->user_admin() && !$issue_proposal) 131 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 132 'title' => $this->getLang('add_cause')); 133 } 134 $res = $causo->get($id); 135 foreach ($res as $r) { 136 $rpid = "bez:issue_cause:id:$id:cid:$r[id]"; 137 $data[$rpid] = array('id' => $rpid, 'type' => 'd', 'level' => 5, 138 'title' => '#p'.$r[id]); 139 140 if ((int)$this->value['cid'] == $r[id]) { 141 $data[$rpid][open] = true; 142 143 $pres = $tasko->get($id, $r['id']); 144 foreach ($pres as $pr) { 145 $rptid = "bez:issue_cause_task:id:$id:cid:$r[id]:tid:$pr[id]"; 146 $data[$rptid] = array('id' => $rptid, 'type' => 'f', 'level' => 6, 147 'title' => '#z'.$pr[id]); 148 149 } 150 } 151 } 152 153 } 154 155 } 156 $data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks')); 157 158 $isso = new Issues(); 159 $year_now = (int)date('Y'); 160 $mon_now = (int)date('n'); 161 162 $data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report')); 163 if ($this->value['bez'] == 'report') { 164 $data['bez:report']['open'] = true; 165 166 $oldest = $isso->get_oldest_close_date(); 167 $year_old = (int)date('Y', $oldest); 168 $mon_old = (int)date('n', $oldest); 169 170 $mon = $mon_old; 171 for ($year = $year_old; $year <= $year_now; $year++) { 172 173 $y_key = 'bez:report:year:'.$year; 174 $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 175 176 if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 177 $data['bez:report:year:'.$year]['open'] = true; 178 179 if ($year == $year_now) 180 $mon_max = $mon_now; 181 else 182 $mon_max = 12; 183 for ( ; $mon <= $mon_max; $mon++) { 184 $m_key = $y_key.':month:'.$mon; 185 $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 186 'title' => $mon < 10 ? '0'.$mon : $mon); 187 } 188 } 189 $mon = 1; 190 } 191 } 192 193 194 195 if (isset($this->value['bez'])) { 196 $data['bez:start']['open'] = true; 197 } else { 198 $data['bez:start']['open'] = false; 199 array_splice($data, 1); 200 } 201 202 if ($helper->user_admin() && $data['bez:start']['open'] == true) { 203 $data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' => 204 $this->getLang('types_manage')); 205 $data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' => 206 $this->getLang('root_causes')); 207 } 208 209 $R->doc .= '<div class="plugin__bez">'; 210 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 211 $R->doc .= '</div>'; 212 213 return true; 214 } 215 216 function _bezlink($id, $title) { 217 //$uri = wl($id); 218 $uri = DOKU_URL . 'doku.php?id='.$id; 219 return '<a href="'.$uri.'">'.($title).'</a>'; 220 } 221 222 function _list($item){ 223 224 $ex = explode(':', $item['id']); 225 226 for ($i = 0; $i < count($ex); $i += 2) 227 $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 228 229 //pola brane pod uwagę przy określaniu aktualnej strony 230 $fields = array('bez', 'tid', 'cid'); 231 if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') { 232 $fields[] = 'month'; 233 $fields[] = 'year'; 234 } 235 if ($this->value[bez] == 'task_form' && isset($this->value[cid])) 236 unset($fields[0]); 237 238 $actual_page = true; 239 foreach ($fields as $field) 240 if ($item_value[$field] != $this->value[$field]) 241 $actual_page = false; 242 243 244 245 if(($item['type'] == 'd' && $item['open']) || $actual_page) { 246 $id = $item['id']; 247 if ($this->lang_code != $this->default_lang) 248 $id = $this->lang_code.':'.$id; 249 return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 250 }else{ 251 $id = $item['id']; 252 if ($this->lang_code != $this->default_lang) 253 $id = $this->lang_code.':'.$id; 254 return $this->_bezlink($id, $item['title']); 255 } 256 257 } 258 259 function _li($item){ 260 if($item['type'] == "f"){ 261 return '<li class="level'.$item['level'].'">'; 262 }elseif($item['open']){ 263 return '<li class="open">'; 264 }else{ 265 return '<li class="closed">'; 266 } 267 } 268} 269