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