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