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