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