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 $data['bez:report_open'] = array('id' => 'bez:report_open', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report_open')); 159 160 $isso = new Issues(); 161 $year_now = (int)date('Y'); 162 $mon_now = (int)date('n'); 163 164 if ($this->value['bez'] == 'report_open') { 165 $data['bez:report_open']['open'] = true; 166 167 $oldest = $isso->get_oldest_open_date(); 168 $year_old = (int)date('Y', $oldest); 169 $mon_old = (int)date('n', $oldest); 170 171 $mon = $mon_old; 172 for ($year = $year_old; $year <= $year_now; $year++) { 173 $y_key = 'bez:report_open: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_open: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 $data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report')); 194 if ($this->value['bez'] == 'report') { 195 $data['bez:report']['open'] = true; 196 197 $oldest = $isso->get_oldest_close_date(); 198 $year_old = (int)date('Y', $oldest); 199 $mon_old = (int)date('n', $oldest); 200 201 $mon = $mon_old; 202 for ($year = $year_old; $year <= $year_now; $year++) { 203 204 $y_key = 'bez:report:year:'.$year; 205 $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 206 207 if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 208 $data['bez:report:year:'.$year]['open'] = true; 209 210 if ($year == $year_now) 211 $mon_max = $mon_now; 212 else 213 $mon_max = 12; 214 for ( ; $mon <= $mon_max; $mon++) { 215 $m_key = $y_key.':month:'.$mon; 216 $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 217 'title' => $mon < 10 ? '0'.$mon : $mon); 218 } 219 } 220 $mon = 1; 221 } 222 } 223 224 225 226 if (isset($this->value['bez'])) { 227 $data['bez:start']['open'] = true; 228 } else { 229 $data['bez:start']['open'] = false; 230 array_splice($data, 1); 231 } 232 233 if ($helper->user_admin() && $data['bez:start']['open'] == true) { 234 $data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' => 235 $this->getLang('types_manage')); 236 $data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' => 237 $this->getLang('root_causes')); 238 } 239 240 $R->doc .= '<div class="plugin__bez">'; 241 $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 242 $R->doc .= '</div>'; 243 244 return true; 245 } 246 247 function _bezlink($id, $title) { 248 //$uri = wl($id); 249 $uri = DOKU_URL . 'doku.php?id='.$id; 250 return '<a href="'.$uri.'">'.($title).'</a>'; 251 } 252 253 function _list($item){ 254 255 $ex = explode(':', $item['id']); 256 257 for ($i = 0; $i < count($ex); $i += 2) 258 $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 259 260 //pola brane pod uwagę przy określaniu aktualnej strony 261 $fields = array('bez', 'tid', 'cid'); 262 if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') { 263 $fields[] = 'month'; 264 $fields[] = 'year'; 265 } 266 if ($this->value[bez] == 'task_form' && isset($this->value[cid])) 267 unset($fields[0]); 268 269 $actual_page = true; 270 foreach ($fields as $field) 271 if ($item_value[$field] != $this->value[$field]) 272 $actual_page = false; 273 274 275 276 if(($item['type'] == 'd' && $item['open']) || $actual_page) { 277 $id = $item['id']; 278 if ($this->lang_code != $this->default_lang) 279 $id = $this->lang_code.':'.$id; 280 return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 281 }else{ 282 $id = $item['id']; 283 if ($this->lang_code != $this->default_lang) 284 $id = $this->lang_code.':'.$id; 285 return $this->_bezlink($id, $item['title']); 286 } 287 288 } 289 290 function _li($item){ 291 if($item['type'] == "f"){ 292 return '<li class="level'.$item['level'].'">'; 293 }elseif($item['open']){ 294 return '<li class="open">'; 295 }else{ 296 return '<li class="closed">'; 297 } 298 } 299} 300