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