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"; 15include_once DOKU_PLUGIN."bez/models/taskactions.php"; 16include_once DOKU_PLUGIN."bez/models/tasktypes.php"; 17/** 18 * All DokuWiki plugins to extend the parser/rendering mechanism 19 * need to inherit from this class 20 */ 21class syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin { 22 private $value = array(); 23 private $lang_code = ''; 24 private $default_lang = 'pl'; 25 26 function getPType() { return 'block'; } 27 function getType() { return 'substition'; } 28 function getSort() { return 99; } 29 30 31 function connectTo($mode) { 32 $this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav'); 33 } 34 35 function __construct() { 36 global $conf; 37 38 $id = $_GET['id']; 39 40 /*usuń : z początku id - link bezwzględny*/ 41 if ($id[0] == ':') 42 $id = substr($id, 1); 43 44 $ex = explode(':', $_GET['id']); 45 46 //wielojęzyczność 47 if ($ex[1] == 'bez') { 48 $this->lang_code = $ex[0]; 49 $ex = array_slice($ex, 1); 50 51 $old_lang = $conf['lang']; 52 $conf['lang'] = $this->lang_code; 53 $this->setupLocale(); 54 $conf['lang'] = $old_lang; 55 56 } else { 57 $this->lang_code = $conf['lang']; 58 } 59 60 for ($i = 0; $i < count($ex); $i += 2) 61 $this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 62 } 63 64 function handle($match, $state, $pos, Doku_Handler $handler) 65 { 66 return true; 67 } 68 69 function render($mode, Doku_Renderer $R, $pass) { 70 global $INFO; 71 72 $helper = $this->loadHelper('bez'); 73 if ($mode != 'xhtml' || !$helper->user_viewer()) return false; 74 75 $R->info['cache'] = false; 76 77 $data = array( 78 'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')), 79 ); 80 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 ($this->value['bez'] == 'issues' || $this->value['bez'] == 'issue_report') { 89 if ($helper->user_editor()) { 90 $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 3, 'title' => $this->getLang('bds_issue_report')); 91 } 92 $data['bez:issues']['open'] = true; 93 } 94 if (in_array($this->value['bez'], $issue_pages) || ($this->value['bez'] == 'issue_report' && isset($this->value['id']))) { 95 if ($helper->user_editor()) { 96 $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 3, 'title' => $this->getLang('bds_issue_report')); 97 } 98 $data['bez:issues']['open'] = true; 99 $id = (int)$this->value[id]; 100 101 $isso = new Issues(); 102 $issue_opened = $isso->opened($id); 103 $issue_proposal = $isso->is_proposal($id); 104 105 $tasko = new Tasks(); 106 $causo = new Causes(); 107 108 $pid = "bez:issue:id:$id"; 109 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 3, 110 'title' => "#$id", 'open' => true); 111 112 $pid = "bez:issue_tasks:id:$id"; 113 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 114 'title' => $this->getLang('correction_nav')); 115 if (in_array($this->value['bez'], $task_pages) && $this->value[cid] == '') { 116 $data[$pid][open] = true; 117 118 if ($issue_opened) { 119 $rpid = "bez:task_form:id:$id"; 120 if ($helper->user_admin() && !$issue_proposal) 121 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 122 'title' => $this->getLang('add_correction')); 123 } 124 $res = $tasko->get_filtered(array('issue' => $id, 'action' => '0')); 125 foreach ($res as $r) { 126 $rpid = "bez:issue_task:id:$id:tid:$r[id]"; 127 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 128 'title' => '#z'.$r[id]); 129 } 130 } 131 132 $pid = "bez:issue_causes:id:$id"; 133 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 134 'title' => $this->getLang('causes')); 135 if (in_array($this->value['bez'], $cause_pages) || $this->value[cid] != '') { 136 $data[$pid][open] = true; 137 if ($issue_opened) { 138 $rpid = "bez:cause_form:id:$id"; 139 if ($helper->user_admin() && !$issue_proposal) 140 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 141 'title' => $this->getLang('add_cause')); 142 } 143 $res = $causo->get($id); 144 foreach ($res as $r) { 145 $rpid = "bez:issue_cause:id:$id:cid:$r[id]"; 146 $data[$rpid] = array('id' => $rpid, 'type' => 'd', 'level' => 5, 147 'title' => '#p'.$r[id]); 148 149 if ((int)$this->value['cid'] == $r[id]) { 150 $data[$rpid][open] = true; 151 152 $pres = $tasko->get($id, $r['id']); 153 foreach ($pres as $pr) { 154 $rptid = "bez:issue_cause_task:id:$id:cid:$r[id]:tid:$pr[id]"; 155 $data[$rptid] = array('id' => $rptid, 'type' => 'f', 'level' => 6, 156 'title' => '#z'.$pr[id]); 157 158 } 159 } 160 } 161 162 } 163 164 } 165 166 167 $data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bez_tasks')); 168 169 if ($this->value['bez'] == 'tasks' || $this->value['bez'] == 'show_task' 170 || $this->value['bez'] == 'task_form_plan' 171 || $this->value['bez'] == 'issue_task' 172 || $this->value['bez'] == 'task_form' 173 || $this->value['bez'] == 'task_report' 174 || $this->value['bez'] == 'issue_cause_task') { 175 $data['bez:tasks']['open'] = true; 176 177 if ($helper->user_editor()) { 178 $data['bez:task_report'] = array('id' => 'bez:task_report', 'type' => 'f', 'level' => 3, 'title' => $this->getLang('bds_task_report')); 179 } 180 181 182 if (isset($this->value['year'])) 183 $year = $this->value['year']; 184 else 185 $year = date('Y'); 186 187 188 if (isset($this->value['tid'])) { 189 $tasko = new Tasks(); 190 $this->value['tasktype'] = $tasko->get_type($this->value['tid']); 191 } 192 193 194 $tasktypeso = new Tasktypes(); 195 $tasktypes = $tasktypeso->get(); 196 $page_id = "bez:tasks:tasktype:-none:year:$year"; 197 if (isset($this->value['tid']) && $this->value['tasktype'] == '') { 198 $data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('tasks_no_type'), 'open' => true); 199 200 //$page_id = 'bez:show_task:tid:'.$this->value['tid']; 201 $page_id = $_GET['id']; 202 $data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => '#z'.$this->value['tid']); 203 204 } else { 205 $data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 3, 'title' => $this->getLang('tasks_no_type')); 206 } 207 208 209 foreach ($tasktypes as $id => $tasktype) { 210 $page_id = "bez:tasks:tasktype:$id:year:$year"; 211 if (isset($this->value['tid']) && $this->value['tasktype'] == $id) { 212 $data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 3, 'title' => $tasktype, 'open' => true); 213 //$page_id = 'bez:show_task:tid:'.$this->value['tid']; 214 $page_id = $_GET['id']; 215 $data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => '#z'.$this->value['tid']); 216 } else 217 $data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 3, 'title' => $tasktype); 218 } 219 } 220 221 $isso = new Issues(); 222 $year_now = (int)date('Y'); 223 $mon_now = (int)date('n'); 224 225 $data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report')); 226 if ($this->value['bez'] == 'report') { 227 $data['bez:report']['open'] = true; 228 229 $oldest = $isso->get_oldest_close_date(); 230 $year_old = (int)date('Y', $oldest); 231 $mon_old = (int)date('n', $oldest); 232 233 $mon = $mon_old; 234 for ($year = $year_old; $year <= $year_now; $year++) { 235 236 $y_key = 'bez:report:year:'.$year; 237 $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 238 239 if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 240 $data['bez:report:year:'.$year]['open'] = true; 241 242 if ($year == $year_now) 243 $mon_max = $mon_now; 244 else 245 $mon_max = 12; 246 for ( ; $mon <= $mon_max; $mon++) { 247 $m_key = $y_key.':month:'.$mon; 248 $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 249 'title' => $mon < 10 ? '0'.$mon : $mon); 250 } 251 } 252 $mon = 1; 253 } 254 } 255 256 257 258 if (isset($this->value['bez'])) { 259 $data['bez:start']['open'] = true; 260 } else { 261 $data['bez:start']['open'] = false; 262 array_splice($data, 1); 263 } 264 265 if ($helper->user_admin() && $data['bez:start']['open'] == true) { 266 $data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' => 267 $this->getLang('types_manage')); 268 $data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' => 269 $this->getLang('root_causes')); 270 $data['bez:task_types'] = array('id' => 'bez:task_types', 'type' => 'f', 'level' => 2, 'title' => 271 $this->getLang('task_types')); 272 } 273 274 $R->doc .= '<div class="plugin__bez">'; 275 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 276 $R->doc .= '</div>'; 277 278 return true; 279 } 280 281 function _bezlink($id, $title) { 282 //$uri = wl($id); 283 $uri = DOKU_URL . 'doku.php?id='.$id; 284 return '<a href="'.$uri.'">'.($title).'</a>'; 285 } 286 287 function _list($item){ 288 289 $ex = explode(':', $item['id']); 290 291 for ($i = 0; $i < count($ex); $i += 2) 292 $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 293 294 //pola brane pod uwagę przy określaniu aktualnej strony 295 $fields = array('bez', 'tid', 'cid', 'tasktype', 'taskstate'); 296 if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') { 297 $fields[] = 'month'; 298 $fields[] = 'year'; 299 } 300 if ($this->value[bez] == 'task_form' && isset($this->value[cid])) 301 unset($fields[0]); 302 303 $actual_page = true; 304 foreach ($fields as $field) 305 if ($item_value[$field] != $this->value[$field]) 306 $actual_page = false; 307 308 //specjalny hak dla zadań, boję się ruszać całej procedury 309 if ($item_value['bez'] == 'issue_task' || 310 $item_value['bez'] == 'issue_cause_task' || 311 $item_value['bez'] == 'task_form' || 312 $item_value['bez'] == 'show_task') 313 if ($item_value['tid'] == $this->value['tid']) 314 $actual_page = true; 315 316 if(($item['type'] == 'd' && $item['open']) || $actual_page) { 317 $id = $item['id']; 318 if ($this->lang_code != $this->default_lang) 319 $id = $this->lang_code.':'.$id; 320 return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 321 }else{ 322 $id = $item['id']; 323 if ($this->lang_code != $this->default_lang) 324 $id = $this->lang_code.':'.$id; 325 return $this->_bezlink($id, $item['title']); 326 } 327 328 } 329 330 function _li($item){ 331 if($item['type'] == "f"){ 332 return '<li class="level'.$item['level'].'">'; 333 }elseif($item['open']){ 334 return '<li class="open">'; 335 }else{ 336 return '<li class="closed">'; 337 } 338 } 339} 340