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 if ($helper->user_editor()) { 82 $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_issue_report')); 83 } 84 85 $data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bds_issues')); 86 87 $task_pages = array('issue_tasks', 'task_form', 'issue_task'); 88 $cause_pages = array('issue_causes', 'issue_cause', 'cause_form', 'issue_cause_task'); 89 $issue_pages = array_merge(array('issue', 'rr', '8d'), $task_pages, $cause_pages); 90 91 if (in_array($this->value['bez'], $issue_pages) || ($this->value['bez'] == 'issue_report' && isset($this->value['id']))) { 92 $data['bez:issues']['open'] = true; 93 $id = (int)$this->value[id]; 94 95 $isso = new Issues(); 96 $issue_opened = $isso->opened($id); 97 $issue_proposal = $isso->is_proposal($id); 98 99 $tasko = new Tasks(); 100 $causo = new Causes(); 101 102 $pid = "bez:issue:id:$id"; 103 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 3, 104 'title' => "#$id", 'open' => true); 105 106 $pid = "bez:issue_tasks:id:$id"; 107 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 108 'title' => $this->getLang('correction_nav')); 109 if (in_array($this->value['bez'], $task_pages) && $this->value[cid] == '') { 110 $data[$pid][open] = true; 111 112 if ($issue_opened) { 113 $rpid = "bez:task_form:id:$id"; 114 if ($helper->user_admin() && !$issue_proposal) 115 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 116 'title' => $this->getLang('add_correction')); 117 } 118 $res = $tasko->get_filtered(array('issue' => $id, 'action' => '0')); 119 foreach ($res as $r) { 120 $rpid = "bez:issue_task:id:$id:tid:$r[id]"; 121 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 122 'title' => '#z'.$r[id]); 123 } 124 } 125 126 $pid = "bez:issue_causes:id:$id"; 127 $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 128 'title' => $this->getLang('causes')); 129 if (in_array($this->value['bez'], $cause_pages) || $this->value[cid] != '') { 130 $data[$pid][open] = true; 131 if ($issue_opened) { 132 $rpid = "bez:cause_form:id:$id"; 133 if ($helper->user_admin() && !$issue_proposal) 134 $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 135 'title' => $this->getLang('add_cause')); 136 } 137 $res = $causo->get($id); 138 foreach ($res as $r) { 139 $rpid = "bez:issue_cause:id:$id:cid:$r[id]"; 140 $data[$rpid] = array('id' => $rpid, 'type' => 'd', 'level' => 5, 141 'title' => '#p'.$r[id]); 142 143 if ((int)$this->value['cid'] == $r[id]) { 144 $data[$rpid][open] = true; 145 146 $pres = $tasko->get($id, $r['id']); 147 foreach ($pres as $pr) { 148 $rptid = "bez:issue_cause_task:id:$id:cid:$r[id]:tid:$pr[id]"; 149 $data[$rptid] = array('id' => $rptid, 'type' => 'f', 'level' => 6, 150 'title' => '#z'.$pr[id]); 151 152 } 153 } 154 } 155 156 } 157 158 } 159 160 161 if ($helper->user_editor()) { 162 $data['bez:task_report'] = array('id' => 'bez:task_report', 'type' => 'f', 'level' => 2, 'title' => $this->getLang('bds_task_report')); 163 } 164 165 $data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bez_tasks')); 166 167 if ($this->value['bez'] == 'tasks' || $this->value['bez'] == 'show_task' 168 || $this->value['bez'] == 'task_form_plan' 169 || $this->value['bez'] == 'issue_task' 170 || $this->value['bez'] == 'task_form' 171 || $this->value['bez'] == 'issue_cause_task') { 172 $data['bez:tasks']['open'] = true; 173 174 175 if (isset($this->value['year'])) 176 $year = $this->value['year']; 177 else 178 $year = date('Y'); 179 180 181 if (isset($this->value['tid'])) { 182 $tasko = new Tasks(); 183 $this->value['tasktype'] = $tasko->get_type($this->value['tid']); 184 } 185 186 187 $tasktypeso = new Tasktypes(); 188 $tasktypes = $tasktypeso->get(); 189 $page_id = "bez:tasks:tasktype:-none:year:$year"; 190 if (isset($this->value['tid']) && $this->value['tasktype'] == '') { 191 $data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('tasks_no_type'), 'open' => true); 192 193 //$page_id = 'bez:show_task:tid:'.$this->value['tid']; 194 $page_id = $_GET['id']; 195 $data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => '#z'.$this->value['tid']); 196 197 } else { 198 $data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 3, 'title' => $this->getLang('tasks_no_type')); 199 } 200 201 202 foreach ($tasktypes as $id => $tasktype) { 203 $page_id = "bez:tasks:tasktype:$id:year:$year"; 204 if (isset($this->value['tid']) && $this->value['tasktype'] == $id) { 205 $data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 3, 'title' => $tasktype, 'open' => true); 206 //$page_id = 'bez:show_task:tid:'.$this->value['tid']; 207 $page_id = $_GET['id']; 208 $data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => '#z'.$this->value['tid']); 209 } else 210 $data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 3, 'title' => $tasktype); 211 } 212 } 213 214 $isso = new Issues(); 215 $year_now = (int)date('Y'); 216 $mon_now = (int)date('n'); 217 218 $data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report')); 219 if ($this->value['bez'] == 'report') { 220 $data['bez:report']['open'] = true; 221 222 $oldest = $isso->get_oldest_close_date(); 223 $year_old = (int)date('Y', $oldest); 224 $mon_old = (int)date('n', $oldest); 225 226 $mon = $mon_old; 227 for ($year = $year_old; $year <= $year_now; $year++) { 228 229 $y_key = 'bez:report:year:'.$year; 230 $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 231 232 if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 233 $data['bez:report:year:'.$year]['open'] = true; 234 235 if ($year == $year_now) 236 $mon_max = $mon_now; 237 else 238 $mon_max = 12; 239 for ( ; $mon <= $mon_max; $mon++) { 240 $m_key = $y_key.':month:'.$mon; 241 $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 242 'title' => $mon < 10 ? '0'.$mon : $mon); 243 } 244 } 245 $mon = 1; 246 } 247 } 248 249 250 251 if (isset($this->value['bez'])) { 252 $data['bez:start']['open'] = true; 253 } else { 254 $data['bez:start']['open'] = false; 255 array_splice($data, 1); 256 } 257 258 if ($helper->user_admin() && $data['bez:start']['open'] == true) { 259 $data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' => 260 $this->getLang('types_manage')); 261 $data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' => 262 $this->getLang('root_causes')); 263 $data['bez:task_types'] = array('id' => 'bez:task_types', 'type' => 'f', 'level' => 2, 'title' => 264 $this->getLang('task_types')); 265 } 266 267 $R->doc .= '<div class="plugin__bez">'; 268 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 269 $R->doc .= '</div>'; 270 271 return true; 272 } 273 274 function _bezlink($id, $title) { 275 //$uri = wl($id); 276 $uri = DOKU_URL . 'doku.php?id='.$id; 277 return '<a href="'.$uri.'">'.($title).'</a>'; 278 } 279 280 function _list($item){ 281 282 $ex = explode(':', $item['id']); 283 284 for ($i = 0; $i < count($ex); $i += 2) 285 $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 286 287 //pola brane pod uwagę przy określaniu aktualnej strony 288 $fields = array('bez', 'tid', 'cid', 'tasktype', 'taskstate'); 289 if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') { 290 $fields[] = 'month'; 291 $fields[] = 'year'; 292 } 293 if ($this->value[bez] == 'task_form' && isset($this->value[cid])) 294 unset($fields[0]); 295 296 $actual_page = true; 297 foreach ($fields as $field) 298 if ($item_value[$field] != $this->value[$field]) 299 $actual_page = false; 300 301 //specjalny hak dla zadań, boję się ruszać całej procedury 302 if ($item_value['bez'] == 'issue_task' || 303 $item_value['bez'] == 'issue_cause_task' || 304 $item_value['bez'] == 'task_form' || 305 $item_value['bez'] == 'show_task') 306 if ($item_value['tid'] == $this->value['tid']) 307 $actual_page = true; 308 309 if(($item['type'] == 'd' && $item['open']) || $actual_page) { 310 $id = $item['id']; 311 if ($this->lang_code != $this->default_lang) 312 $id = $this->lang_code.':'.$id; 313 return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 314 }else{ 315 $id = $item['id']; 316 if ($this->lang_code != $this->default_lang) 317 $id = $this->lang_code.':'.$id; 318 return $this->_bezlink($id, $item['title']); 319 } 320 321 } 322 323 function _li($item){ 324 if($item['type'] == "f"){ 325 return '<li class="level'.$item['level'].'">'; 326 }elseif($item['open']){ 327 return '<li class="open">'; 328 }else{ 329 return '<li class="closed">'; 330 } 331 } 332} 333