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 95 $tasko = new Tasks(); 96 $causo = new Causes(); 97 98 $pid = "bez:issue:id:$id"; 99 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 3, 100 'title' => "#$id", 'open' => true); 101 102 $pid = "bez:issue_tasks:id:$id"; 103 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 104 'title' => $this->getLang('correction_nav')); 105 if (in_array($this->value['bez'], $task_pages) && $this->value[cid] == '') { 106 $data[$pid][open] = true; 107 108 if ($issue_opened) { 109 $rpid = "bez:task_form:id:$id"; 110 if ($helper->user_admin()) 111 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 112 'title' => $this->getLang('add_correction')); 113 } 114 $res = $tasko->get_filtered(array('issue' => $id, 'action' => '0')); 115 foreach ($res as $r) { 116 $rpid = "bez:issue_task:id:$id:tid:$r[id]"; 117 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 118 'title' => '#z'.$r[id]); 119 } 120 } 121 122 $pid = "bez:issue_causes:id:$id"; 123 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 124 'title' => $this->getLang('causes')); 125 if (in_array($this->value['bez'], $cause_pages) || $this->value[cid] != '') { 126 $data[$pid][open] = true; 127 if ($issue_opened) { 128 $rpid = "bez:cause_form:id:$id"; 129 if ($helper->user_admin()) 130 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 131 'title' => $this->getLang('add_cause')); 132 } 133 $res = $causo->get($id); 134 foreach ($res as $r) { 135 $rpid = "bez:issue_cause:id:$id:cid:$r[id]"; 136 $data[$rpid] = array('id' => $rpid, 'type' => 'd', 'level' => 5, 137 'title' => '#p'.$r[id]); 138 139 if ((int)$this->value['cid'] == $r[id]) { 140 $data[$rpid][open] = true; 141 142 $pres = $tasko->get($id, $r['id']); 143 foreach ($pres as $pr) { 144 $rptid = "bez:issue_cause_task:id:$id:cid:$r[id]:tid:$pr[id]"; 145 $data[$rptid] = array('id' => $rptid, 'type' => 'f', 'level' => 6, 146 'title' => '#z'.$pr[id]); 147 148 } 149 } 150 } 151 152 } 153 154 } 155 $data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bez_tasks')); 156 157 $data['bez:report_open'] = array('id' => 'bez:report_open', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report_open')); 158 159 $isso = new Issues(); 160 $year_now = (int)date('Y'); 161 $mon_now = (int)date('n'); 162 163 if ($this->value['bez'] == 'report_open') { 164 $data['bez:report_open']['open'] = true; 165 166 $oldest = $isso->get_oldest_open_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 $y_key = 'bez:report_open:year:'.$year; 173 $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 174 175 if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 176 $data['bez:report_open:year:'.$year]['open'] = true; 177 178 if ($year == $year_now) 179 $mon_max = $mon_now; 180 else 181 $mon_max = 12; 182 for ( ; $mon <= $mon_max; $mon++) { 183 $m_key = $y_key.':month:'.$mon; 184 $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 185 'title' => $mon < 10 ? '0'.$mon : $mon); 186 } 187 } 188 $mon = 1; 189 } 190 } 191 192 $data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report')); 193 if ($this->value['bez'] == 'report') { 194 $data['bez:report']['open'] = true; 195 196 $oldest = $isso->get_oldest_close_date(); 197 $year_old = (int)date('Y', $oldest); 198 $mon_old = (int)date('n', $oldest); 199 200 $mon = $mon_old; 201 for ($year = $year_old; $year <= $year_now; $year++) { 202 203 $y_key = 'bez:report:year:'.$year; 204 $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 205 206 if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 207 $data['bez:report:year:'.$year]['open'] = true; 208 209 if ($year == $year_now) 210 $mon_max = $mon_now; 211 else 212 $mon_max = 12; 213 for ( ; $mon <= $mon_max; $mon++) { 214 $m_key = $y_key.':month:'.$mon; 215 $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 216 'title' => $mon < 10 ? '0'.$mon : $mon); 217 } 218 } 219 $mon = 1; 220 } 221 } 222 223 224 225 if (isset($this->value['bez'])) { 226 $data['bez:start']['open'] = true; 227 } else { 228 $data['bez:start']['open'] = false; 229 array_splice($data, 1); 230 } 231 232 if ($helper->user_admin() && $data['bez:start']['open'] == true) { 233 $data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' => 234 $this->getLang('types_manage')); 235 $data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' => 236 $this->getLang('root_causes')); 237 } 238 239 $R->doc .= '<div class="plugin__bez">'; 240 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 241 $R->doc .= '</div>'; 242 243 return true; 244 } 245 246 function _bezlink($id, $title) { 247 //$uri = wl($id); 248 $uri = DOKU_URL . 'doku.php?id='.$id; 249 return '<a href="'.$uri.'">'.($title).'</a>'; 250 } 251 252 function _list($item){ 253 254 $ex = explode(':', $item['id']); 255 256 for ($i = 0; $i < count($ex); $i += 2) 257 $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 258 259 //pola brane pod uwagę przy określaniu aktualnej strony 260 $fields = array('bez', 'tid', 'cid'); 261 if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') { 262 $fields[] = 'month'; 263 $fields[] = 'year'; 264 } 265 if ($this->value[bez] == 'task_form' && isset($this->value[cid])) 266 unset($fields[0]); 267 268 $actual_page = true; 269 foreach ($fields as $field) 270 if ($item_value[$field] != $this->value[$field]) 271 $actual_page = false; 272 273 274 275 if(($item['type'] == 'd' && $item['open']) || $actual_page) { 276 $id = $item['id']; 277 if ($this->lang_code != $this->default_lang) 278 $id = $this->lang_code.':'.$id; 279 return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 280 }else{ 281 $id = $item['id']; 282 if ($this->lang_code != $this->default_lang) 283 $id = $this->lang_code.':'.$id; 284 return $this->_bezlink($id, $item['title']); 285 } 286 287 } 288 289 function _li($item){ 290 if($item['type'] == "f"){ 291 return '<li class="level'.$item['level'].'">'; 292 }elseif($item['open']){ 293 return '<li class="open">'; 294 }else{ 295 return '<li class="closed">'; 296 } 297 } 298} 299