165cfcae3Sghi<?php 265cfcae3Sghi/** 365cfcae3Sghi * Plugin Now: Inserts a timestamp. 465cfcae3Sghi * 565cfcae3Sghi */ 665cfcae3Sghi 765cfcae3Sghi// must be run within DokuWiki 865cfcae3Sghiif(!defined('DOKU_INC')) die(); 965cfcae3Sghi 1065cfcae3Sghiif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 1165cfcae3Sghirequire_once DOKU_PLUGIN.'syntax.php'; 12a6dcc2a9Sghiinclude_once DOKU_PLUGIN."bez/models/issues.php"; 1327712358Sghiinclude_once DOKU_PLUGIN."bez/models/causes.php"; 1427712358Sghiinclude_once DOKU_PLUGIN."bez/models/tasks.php"; 15168ecf58Sghiinclude_once DOKU_PLUGIN."bez/models/taskactions.php"; 165c4f5b95SSzymon Olewniczak 175c4f5b95SSzymon Olewniczakinclude_once DOKU_PLUGIN."bez/mdl/model.php"; 185c4f5b95SSzymon Olewniczak 1965cfcae3Sghi/** 2065cfcae3Sghi * All DokuWiki plugins to extend the parser/rendering mechanism 2165cfcae3Sghi * need to inherit from this class 2265cfcae3Sghi */ 2365cfcae3Sghiclass syntax_plugin_bez_nav extends DokuWiki_Syntax_Plugin { 247f226579Sghi private $value = array(); 2505c9d3bcSghi private $lang_code = ''; 2615487902Sghi private $default_lang = 'pl'; 2765cfcae3Sghi 285c4f5b95SSzymon Olewniczak private $auth, $model, $validator; 295c4f5b95SSzymon Olewniczak 305536eef6Sghi function getPType() { return 'block'; } 3165cfcae3Sghi function getType() { return 'substition'; } 3265cfcae3Sghi function getSort() { return 99; } 3365cfcae3Sghi 3465cfcae3Sghi 3565cfcae3Sghi function connectTo($mode) { 3665cfcae3Sghi $this->Lexer->addSpecialPattern('~~BEZNAV~~',$mode,'plugin_bez_nav'); 3765cfcae3Sghi } 3865cfcae3Sghi 397f226579Sghi function __construct() { 405c4f5b95SSzymon Olewniczak global $conf, $INFO, $auth; 4115487902Sghi 4215487902Sghi $id = $_GET['id']; 4315487902Sghi 4415487902Sghi /*usuń : z początku id - link bezwzględny*/ 4515487902Sghi if ($id[0] == ':') 4615487902Sghi $id = substr($id, 1); 477f226579Sghi 487f226579Sghi $ex = explode(':', $_GET['id']); 4915487902Sghi 5005c9d3bcSghi //wielojęzyczność 5105c9d3bcSghi if ($ex[1] == 'bez') { 5215487902Sghi $this->lang_code = $ex[0]; 5305c9d3bcSghi $ex = array_slice($ex, 1); 5415487902Sghi 5515487902Sghi $old_lang = $conf['lang']; 5615487902Sghi $conf['lang'] = $this->lang_code; 5715487902Sghi $this->setupLocale(); 5815487902Sghi $conf['lang'] = $old_lang; 5915487902Sghi 6015487902Sghi } else { 6115487902Sghi $this->lang_code = $conf['lang']; 6205c9d3bcSghi } 6305c9d3bcSghi 647f226579Sghi for ($i = 0; $i < count($ex); $i += 2) 657f226579Sghi $this->value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 665c4f5b95SSzymon Olewniczak 675c4f5b95SSzymon Olewniczak $this->model = new BEZ_mdl_Model($auth, $INFO['client'], $this->lang_code); 687f226579Sghi } 697f226579Sghi 703b3e3ab0Sghi function handle($match, $state, $pos, Doku_Handler $handler) 7165cfcae3Sghi { 7265cfcae3Sghi return true; 7365cfcae3Sghi } 7465cfcae3Sghi 753b3e3ab0Sghi function render($mode, Doku_Renderer $R, $pass) { 765c4f5b95SSzymon Olewniczak global $INFO, $auth; 7765cfcae3Sghi 785536eef6Sghi $helper = $this->loadHelper('bez'); 7908e8ea12Sghi if ($mode != 'xhtml' || !$helper->user_viewer()) return false; 8065cfcae3Sghi 8108e8ea12Sghi $R->info['cache'] = false; 8208e8ea12Sghi 8308e8ea12Sghi $data = array( 84a6dcc2a9Sghi 'bez:start' => array('id' => 'bez:start', 'type' => 'd', 'level' => 1, 'title' => $this->getLang('bez')), 8508e8ea12Sghi ); 8665cfcae3Sghi 87919e4830Sghi 884fb0d798Sghi $data['bez:issues'] = array('id' => 'bez:issues', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bds_issues')); 8927712358Sghi 9027712358Sghi $task_pages = array('issue_tasks', 'task_form', 'issue_task'); 919fbfe943Sghi $cause_pages = array('issue_causes', 'issue_cause', 'cause_form', 'issue_cause_task'); 929a30fd19Sghi $issue_pages = array_merge(array('issue', 'rr', '8d'), $task_pages, $cause_pages); 9327712358Sghi 946c94eb49Sghi if ($this->value['bez'] == 'issues' || $this->value['bez'] == 'issue_report') { 956c94eb49Sghi if ($helper->user_editor()) { 966c94eb49Sghi $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 3, 'title' => $this->getLang('bds_issue_report')); 976c94eb49Sghi } 986c94eb49Sghi $data['bez:issues']['open'] = true; 996c94eb49Sghi } 100168ecf58Sghi if (in_array($this->value['bez'], $issue_pages) || ($this->value['bez'] == 'issue_report' && isset($this->value['id']))) { 1016c94eb49Sghi if ($helper->user_editor()) { 1026c94eb49Sghi $data['bez:issue_report'] = array('id' => 'bez:issue_report', 'type' => 'f', 'level' => 3, 'title' => $this->getLang('bds_issue_report')); 1036c94eb49Sghi } 10427712358Sghi $data['bez:issues']['open'] = true; 10527712358Sghi $id = (int)$this->value[id]; 10627712358Sghi 1079a30fd19Sghi $isso = new Issues(); 1089a30fd19Sghi $issue_opened = $isso->opened($id); 109489061b8Sghi $issue_proposal = $isso->is_proposal($id); 1109a30fd19Sghi 11127712358Sghi $tasko = new Tasks(); 11227712358Sghi $causo = new Causes(); 11327712358Sghi 114ed77b00cSSzymon Olewniczak $causes = $causo->get($id); 115ed77b00cSSzymon Olewniczak $tasks = $tasko->get_corrections_ids($id); 116ed77b00cSSzymon Olewniczak 117ed77b00cSSzymon Olewniczak $type = 'd'; 118ed77b00cSSzymon Olewniczak if (count($causes) + count($tasks) == 0) { 119ed77b00cSSzymon Olewniczak $type = 'f'; 120ed77b00cSSzymon Olewniczak } 121ed77b00cSSzymon Olewniczak 12227712358Sghi $pid = "bez:issue:id:$id"; 123ed77b00cSSzymon Olewniczak $data[$pid] = array('id' => $pid, 'type' => $type, 'level' => 3, 12427712358Sghi 'title' => "#$id", 'open' => true); 12527712358Sghi 126ed77b00cSSzymon Olewniczak if (count($tasks) > 0) { 12727712358Sghi $pid = "bez:issue_tasks:id:$id"; 12827712358Sghi $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 1299fbfe943Sghi 'title' => $this->getLang('correction_nav')); 1309fbfe943Sghi if (in_array($this->value['bez'], $task_pages) && $this->value[cid] == '') { 13127712358Sghi $data[$pid][open] = true; 1329a30fd19Sghi 1339a30fd19Sghi if ($issue_opened) { 13427712358Sghi $rpid = "bez:task_form:id:$id"; 135489061b8Sghi if ($helper->user_admin() && !$issue_proposal) 13627712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 13727712358Sghi 'title' => $this->getLang('add_correction')); 1389a30fd19Sghi } 139ed77b00cSSzymon Olewniczak foreach ($tasks as $r) { 14027712358Sghi $rpid = "bez:issue_task:id:$id:tid:$r[id]"; 14127712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 142ed77b00cSSzymon Olewniczak 'title' => '#z'.$r['id']); 143ed77b00cSSzymon Olewniczak } 14427712358Sghi } 14527712358Sghi } 14627712358Sghi 147ed77b00cSSzymon Olewniczak if (count($causes) > 0) { 14827712358Sghi $pid = "bez:issue_causes:id:$id"; 14927712358Sghi $data[$pid] = array('id' => $pid, 'type' => 'd', 'level' => 4, 15027712358Sghi 'title' => $this->getLang('causes')); 1519fbfe943Sghi if (in_array($this->value['bez'], $cause_pages) || $this->value[cid] != '') { 15227712358Sghi $data[$pid][open] = true; 1539a30fd19Sghi if ($issue_opened) { 15427712358Sghi $rpid = "bez:cause_form:id:$id"; 155489061b8Sghi if ($helper->user_admin() && !$issue_proposal) 15627712358Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'f', 'level' => 5, 15727712358Sghi 'title' => $this->getLang('add_cause')); 1589a30fd19Sghi } 159ed77b00cSSzymon Olewniczak 160ed77b00cSSzymon Olewniczak foreach ($causes as $r) { 16127712358Sghi $rpid = "bez:issue_cause:id:$id:cid:$r[id]"; 1629fbfe943Sghi $data[$rpid] = array('id' => $rpid, 'type' => 'd', 'level' => 5, 16327712358Sghi 'title' => '#p'.$r[id]); 1649fbfe943Sghi 16527712358Sghi if ((int)$this->value['cid'] == $r[id]) { 16627712358Sghi $data[$rpid][open] = true; 16727712358Sghi 16827712358Sghi $pres = $tasko->get($id, $r['id']); 16927712358Sghi foreach ($pres as $pr) { 1709fbfe943Sghi $rptid = "bez:issue_cause_task:id:$id:cid:$r[id]:tid:$pr[id]"; 1719fbfe943Sghi $data[$rptid] = array('id' => $rptid, 'type' => 'f', 'level' => 6, 1729fbfe943Sghi 'title' => '#z'.$pr[id]); 1739fbfe943Sghi 17427712358Sghi } 17527712358Sghi } 1769fbfe943Sghi } 17727712358Sghi 17827712358Sghi } 179ed77b00cSSzymon Olewniczak } 18027712358Sghi 18127712358Sghi } 182919e4830Sghi 183919e4830Sghi 184168ecf58Sghi $data['bez:tasks'] = array('id' => 'bez:tasks', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('bez_tasks')); 185168ecf58Sghi 186168ecf58Sghi if ($this->value['bez'] == 'tasks' || $this->value['bez'] == 'show_task' 187168ecf58Sghi || $this->value['bez'] == 'task_form_plan' 188168ecf58Sghi || $this->value['bez'] == 'issue_task' 189d6002863Sghi || $this->value['bez'] == 'task_form' 1906c94eb49Sghi || $this->value['bez'] == 'task_report' 191168ecf58Sghi || $this->value['bez'] == 'issue_cause_task') { 192168ecf58Sghi $data['bez:tasks']['open'] = true; 193168ecf58Sghi 194168ecf58Sghi if (isset($this->value['year'])) 195168ecf58Sghi $year = $this->value['year']; 196168ecf58Sghi else 197168ecf58Sghi $year = date('Y'); 198168ecf58Sghi 199168ecf58Sghi 200168ecf58Sghi if (isset($this->value['tid'])) { 201168ecf58Sghi $tasko = new Tasks(); 202168ecf58Sghi $this->value['tasktype'] = $tasko->get_type($this->value['tid']); 203168ecf58Sghi } 204168ecf58Sghi 205168ecf58Sghi 206b609bf0aSghi $page_id = "bez:tasks:tasktype:-none:year:$year"; 207168ecf58Sghi if (isset($this->value['tid']) && $this->value['tasktype'] == '') { 208b609bf0aSghi $data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 3, 'title' => $this->getLang('tasks_no_type'), 'open' => true); 209168ecf58Sghi 21066f0c416SSzymon Olewniczak $page_id = 'bez:show_task:tid:'.$this->value['tid']; 21166f0c416SSzymon Olewniczak //$page_id = $_GET['id']; 212b609bf0aSghi $data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => '#z'.$this->value['tid']); 213168ecf58Sghi 214168ecf58Sghi } else { 215b609bf0aSghi $data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 3, 'title' => $this->getLang('tasks_no_type')); 216168ecf58Sghi } 217168ecf58Sghi 2185c4f5b95SSzymon Olewniczak $tasktypes = $this->model->tasktypes->get_all(); 2195c4f5b95SSzymon Olewniczak foreach ($tasktypes as $tasktype) { 2205c4f5b95SSzymon Olewniczak $page_id = "bez:tasks:tasktype:".$tasktype->id.":year:$year"; 221168ecf58Sghi 2225c4f5b95SSzymon Olewniczak if ($this->value['tasktype'] == $tasktype->id) { 2235c4f5b95SSzymon Olewniczak $data[$page_id] = array('id' => $page_id, 'type' => 'd', 'level' => 3, 'title' => $tasktype->type, 'open' => true); 2245c4f5b95SSzymon Olewniczak 225*00746146SSzymon Olewniczak //~ if ($tasktype->get_level() >= 15) { 2265c4f5b95SSzymon Olewniczak $report_id = "bez:task_report:tasktype:".$tasktype->id; 2275c4f5b95SSzymon Olewniczak $data[$report_id] = array('id' => $report_id, 'type' => 'f', 'level' => 4, 'title' => $this->getLang('bds_task_report')); 228*00746146SSzymon Olewniczak //~ } 2295c4f5b95SSzymon Olewniczak if (isset($this->value['tid'])) { 23066f0c416SSzymon Olewniczak $page_id = 'bez:show_task:tid:'.$this->value['tid']; 23166f0c416SSzymon Olewniczak //$page_id = $_GET['id']; 232b609bf0aSghi $data[$page_id.':perspective:task'] = array('id' => $page_id, 'type' => 'f', 'level' => 4, 'title' => '#z'.$this->value['tid']); 2335c4f5b95SSzymon Olewniczak } 2345c4f5b95SSzymon Olewniczak } else { 2355c4f5b95SSzymon Olewniczak $data[$page_id] = array('id' => $page_id, 'type' => 'f', 'level' => 3, 'title' => $tasktype->type); 2365c4f5b95SSzymon Olewniczak } 237168ecf58Sghi } 238168ecf58Sghi } 23965cfcae3Sghi 2407f853d3aSghi $isso = new Issues(); 24197183698Sghi $year_now = (int)date('Y'); 24297183698Sghi $mon_now = (int)date('n'); 24397183698Sghi 24497183698Sghi $data['bez:report'] = array('id' => 'bez:report', 'type' => 'd', 'level' => 2, 'title' => $this->getLang('report')); 2457f226579Sghi if ($this->value['bez'] == 'report') { 2467f226579Sghi $data['bez:report']['open'] = true; 2477f226579Sghi 248bb615297Sghi $oldest = $isso->get_oldest_close_date(); 2497e9a45a9Sghi $year_old = (int)date('Y', $oldest); 2507e9a45a9Sghi $mon_old = (int)date('n', $oldest); 2517e9a45a9Sghi 2527e9a45a9Sghi $mon = $mon_old; 2537e9a45a9Sghi for ($year = $year_old; $year <= $year_now; $year++) { 2547f226579Sghi 2557f226579Sghi $y_key = 'bez:report:year:'.$year; 25638b5c5c4Sghi $data[$y_key] = array('id' => $y_key, 'type' => 'd', 'level' => 3, 'title' => $year); 2577f226579Sghi 2587f226579Sghi if (isset($this->value['year']) && (int)$this->value['year'] == $year) { 2597f226579Sghi $data['bez:report:year:'.$year]['open'] = true; 2607f226579Sghi 2617e9a45a9Sghi if ($year == $year_now) 2627e9a45a9Sghi $mon_max = $mon_now; 2637e9a45a9Sghi else 2647e9a45a9Sghi $mon_max = 12; 2657e9a45a9Sghi for ( ; $mon <= $mon_max; $mon++) { 2667e9a45a9Sghi $m_key = $y_key.':month:'.$mon; 26738b5c5c4Sghi $data[$m_key] = array('id' => $m_key, 'type' => 'f', 'level' => 4, 2687e9a45a9Sghi 'title' => $mon < 10 ? '0'.$mon : $mon); 2697e9a45a9Sghi } 2707f226579Sghi } 2717e9a45a9Sghi $mon = 1; 2727e9a45a9Sghi } 2737f226579Sghi } 2743cc1f839Sghi 27508e8ea12Sghi 276f01326efSghi 2777f226579Sghi if (isset($this->value['bez'])) { 278a42d0169Sghi $data['bez:start']['open'] = true; 27908e8ea12Sghi } else { 280a42d0169Sghi $data['bez:start']['open'] = false; 28108e8ea12Sghi array_splice($data, 1); 28208e8ea12Sghi } 28308e8ea12Sghi 28480487b8aSghi if ($helper->user_admin() && $data['bez:start']['open'] == true) { 28580487b8aSghi $data['bez:types'] = array('id' => 'bez:types', 'type' => 'f', 'level' => 2, 'title' => 28680487b8aSghi $this->getLang('types_manage')); 28780487b8aSghi $data['bez:root_causes'] = array('id' => 'bez:root_causes', 'type' => 'f', 'level' => 2, 'title' => 28880487b8aSghi $this->getLang('root_causes')); 289168ecf58Sghi $data['bez:task_types'] = array('id' => 'bez:task_types', 'type' => 'f', 'level' => 2, 'title' => 290168ecf58Sghi $this->getLang('task_types')); 29180487b8aSghi } 2927f226579Sghi 29308e8ea12Sghi $R->doc .= '<div class="plugin__bez">'; 29408e8ea12Sghi $R->doc .= html_buildlist($data,'idx',array($this,'_list'),array($this,'_li')); 29508e8ea12Sghi $R->doc .= '</div>'; 29608e8ea12Sghi 2975536eef6Sghi return true; 29808e8ea12Sghi } 299da9ebf75Sghi 30008e8ea12Sghi function _bezlink($id, $title) { 3017f226579Sghi //$uri = wl($id); 3027f226579Sghi $uri = DOKU_URL . 'doku.php?id='.$id; 303a6dcc2a9Sghi return '<a href="'.$uri.'">'.($title).'</a>'; 30408e8ea12Sghi } 30508e8ea12Sghi 30608e8ea12Sghi function _list($item){ 30708e8ea12Sghi 3087f226579Sghi $ex = explode(':', $item['id']); 30905c9d3bcSghi 3107f226579Sghi for ($i = 0; $i < count($ex); $i += 2) 3117f226579Sghi $item_value[urldecode($ex[$i])] = urldecode($ex[$i+1]); 3127f226579Sghi 3137f226579Sghi //pola brane pod uwagę przy określaniu aktualnej strony 314168ecf58Sghi $fields = array('bez', 'tid', 'cid', 'tasktype', 'taskstate'); 31597183698Sghi if ($item_value['bez'] == 'report' || $item_value['bez'] == 'report_open') { 3167f226579Sghi $fields[] = 'month'; 3177f226579Sghi $fields[] = 'year'; 3187f226579Sghi } 3199fbfe943Sghi if ($this->value[bez] == 'task_form' && isset($this->value[cid])) 3209fbfe943Sghi unset($fields[0]); 3217f226579Sghi 3227f226579Sghi $actual_page = true; 3237f226579Sghi foreach ($fields as $field) 3247f226579Sghi if ($item_value[$field] != $this->value[$field]) 3257f226579Sghi $actual_page = false; 3267f226579Sghi 327168ecf58Sghi //specjalny hak dla zadań, boję się ruszać całej procedury 328168ecf58Sghi if ($item_value['bez'] == 'issue_task' || 329168ecf58Sghi $item_value['bez'] == 'issue_cause_task' || 330d6002863Sghi $item_value['bez'] == 'task_form' || 331168ecf58Sghi $item_value['bez'] == 'show_task') 332168ecf58Sghi if ($item_value['tid'] == $this->value['tid']) 333168ecf58Sghi $actual_page = true; 3347f226579Sghi 3357f226579Sghi if(($item['type'] == 'd' && $item['open']) || $actual_page) { 33615487902Sghi $id = $item['id']; 33715487902Sghi if ($this->lang_code != $this->default_lang) 33815487902Sghi $id = $this->lang_code.':'.$id; 33915487902Sghi return '<strong>'.$this->_bezlink($id, $item['title']).'</strong>'; 34008e8ea12Sghi }else{ 34115487902Sghi $id = $item['id']; 34215487902Sghi if ($this->lang_code != $this->default_lang) 34315487902Sghi $id = $this->lang_code.':'.$id; 34415487902Sghi return $this->_bezlink($id, $item['title']); 34508e8ea12Sghi } 34608e8ea12Sghi 34708e8ea12Sghi } 34808e8ea12Sghi 34908e8ea12Sghi function _li($item){ 35008e8ea12Sghi if($item['type'] == "f"){ 35108e8ea12Sghi return '<li class="level'.$item['level'].'">'; 35208e8ea12Sghi }elseif($item['open']){ 35308e8ea12Sghi return '<li class="open">'; 35408e8ea12Sghi }else{ 35508e8ea12Sghi return '<li class="closed">'; 35608e8ea12Sghi } 35765cfcae3Sghi } 35865cfcae3Sghi} 359