1f09444ffSAndreas Gohr<?php 2f09444ffSAndreas Gohr 3f09444ffSAndreas Gohruse dokuwiki\Extension\AuthPlugin; 4f09444ffSAndreas Gohr 5f09444ffSAndreas Gohr/** 6f09444ffSAndreas Gohr * DokuWiki Plugin acknowledge (Admin Component) 7f09444ffSAndreas Gohr * 8f09444ffSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 9f09444ffSAndreas Gohr * @author Andreas Gohr, Anna Dabrowska <dokuwiki@cosmocode.de> 10f09444ffSAndreas Gohr */ 11f09444ffSAndreas Gohrclass admin_plugin_acknowledge_report extends DokuWiki_Admin_Plugin 12f09444ffSAndreas Gohr{ 13f09444ffSAndreas Gohr 14f09444ffSAndreas Gohr /** @inheritdoc */ 15f09444ffSAndreas Gohr public function forAdminOnly() 16f09444ffSAndreas Gohr { 17f09444ffSAndreas Gohr return false; 18f09444ffSAndreas Gohr } 19f09444ffSAndreas Gohr 20f09444ffSAndreas Gohr /** @inheritdoc */ 21f09444ffSAndreas Gohr public function handle() 22f09444ffSAndreas Gohr { 23f09444ffSAndreas Gohr } 24f09444ffSAndreas Gohr 25f09444ffSAndreas Gohr /** @inheritdoc */ 26f09444ffSAndreas Gohr public function html() 27f09444ffSAndreas Gohr { 28f09444ffSAndreas Gohr global $INPUT; 29f09444ffSAndreas Gohr 30f09444ffSAndreas Gohr echo '<div class="plugin_acknowledgement_admin">'; 31f09444ffSAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 32f09444ffSAndreas Gohr $this->htmlForms(); 33f09444ffSAndreas Gohr if ($INPUT->has('user')) { 34f09444ffSAndreas Gohr $this->htmlUserStatus($INPUT->str('user')); 35f09444ffSAndreas Gohr } elseif ($INPUT->has('pg')) { 36f09444ffSAndreas Gohr $this->htmlPageStatus($INPUT->str('pg')); 37f09444ffSAndreas Gohr } else { 38f09444ffSAndreas Gohr $this->htmlLatest(); 39f09444ffSAndreas Gohr } 40f09444ffSAndreas Gohr echo '</div>'; 41f09444ffSAndreas Gohr } 42f09444ffSAndreas Gohr 43f09444ffSAndreas Gohr /** 44f09444ffSAndreas Gohr * Show which users have or need ot acknowledge a specific page 45f09444ffSAndreas Gohr * 46*03962179SAndreas Gohr * @param string $pattern A page assignment pattern 47f09444ffSAndreas Gohr */ 48*03962179SAndreas Gohr protected function htmlPageStatus($pattern) 49f09444ffSAndreas Gohr { 50f09444ffSAndreas Gohr global $lang; 51f09444ffSAndreas Gohr 52f09444ffSAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 53f09444ffSAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 54f09444ffSAndreas Gohr 55*03962179SAndreas Gohr $pages = $helper->getPagesMatchingPattern($pattern); 56*03962179SAndreas Gohr $acknowledgements = []; 57*03962179SAndreas Gohr 58*03962179SAndreas Gohr foreach ($pages as $pattern) { 59*03962179SAndreas Gohr $acknowledgements = array_merge($acknowledgements, $helper->getPageAcknowledgements($pattern)); 60*03962179SAndreas Gohr if(count($acknowledgements) > 1000) break; // don't show too many 61*03962179SAndreas Gohr } 62*03962179SAndreas Gohr 63f09444ffSAndreas Gohr if (!$acknowledgements) { 64f09444ffSAndreas Gohr echo '<p>' . $lang['nothingfound'] . '</p>'; 65f09444ffSAndreas Gohr return; 66f09444ffSAndreas Gohr } 67f09444ffSAndreas Gohr 68*03962179SAndreas Gohr $this->htmlTable($acknowledgements); 69f09444ffSAndreas Gohr } 70f09444ffSAndreas Gohr 71f09444ffSAndreas Gohr /** 72f09444ffSAndreas Gohr * Show what a given user should sign and has 73f09444ffSAndreas Gohr * 74f09444ffSAndreas Gohr * @param string $user 75f09444ffSAndreas Gohr */ 76f09444ffSAndreas Gohr protected function htmlUserStatus($user) 77f09444ffSAndreas Gohr { 78f09444ffSAndreas Gohr /** @var AuthPlugin $auth */ 79f09444ffSAndreas Gohr global $auth; 80f09444ffSAndreas Gohr global $lang; 81f09444ffSAndreas Gohr 82f09444ffSAndreas Gohr $user = $auth->cleanUser($user); 83f09444ffSAndreas Gohr $userinfo = $auth->getUserData($user, true); 84f09444ffSAndreas Gohr if (!$userinfo) { 85f09444ffSAndreas Gohr echo '<p>' . $lang['nothingfound'] . '</p>'; 86f09444ffSAndreas Gohr return; 87f09444ffSAndreas Gohr } 88f09444ffSAndreas Gohr 89f09444ffSAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 90f09444ffSAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 91f09444ffSAndreas Gohr 92f09444ffSAndreas Gohr $assignments = $helper->getUserAcknowledgements($user, $userinfo['grps']); 93f09444ffSAndreas Gohr $count = $this->htmlTable($assignments); 94f09444ffSAndreas Gohr echo '<p>' . sprintf($this->getLang('count'), hsc($user), $count, count($assignments)) . '</p>'; 95f09444ffSAndreas Gohr } 96f09444ffSAndreas Gohr 97f09444ffSAndreas Gohr /** 98f09444ffSAndreas Gohr * Show the latest 100 acknowledgements 99f09444ffSAndreas Gohr */ 100f09444ffSAndreas Gohr protected function htmlLatest() 101f09444ffSAndreas Gohr { 102f09444ffSAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 103f09444ffSAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 104f09444ffSAndreas Gohr $acks = $helper->getAcknowledgements(); 105f09444ffSAndreas Gohr $this->htmlTable($acks); 106f09444ffSAndreas Gohr echo '<p>' . $this->getLang('overviewHistory') . '</p>'; 107f09444ffSAndreas Gohr } 108f09444ffSAndreas Gohr 109f09444ffSAndreas Gohr /** 110f09444ffSAndreas Gohr * @return void 111f09444ffSAndreas Gohr */ 112f09444ffSAndreas Gohr protected function htmlForms() 113f09444ffSAndreas Gohr { 114f09444ffSAndreas Gohr global $ID; 115f09444ffSAndreas Gohr 116f09444ffSAndreas Gohr echo '<nav>'; 117f09444ffSAndreas Gohr echo $this->homeLink(); 118f09444ffSAndreas Gohr 119f09444ffSAndreas Gohr $form = new dokuwiki\Form\Form(['method' => 'GET']); 120f09444ffSAndreas Gohr $form->setHiddenField('do', 'admin'); 121f09444ffSAndreas Gohr $form->setHiddenField('page', 'acknowledge_report'); 122f09444ffSAndreas Gohr $form->addTextInput('user', $this->getLang('overviewUser')); 123f09444ffSAndreas Gohr $form->addButton('', '>'); 124f09444ffSAndreas Gohr echo $form->toHTML(); 125f09444ffSAndreas Gohr 126f09444ffSAndreas Gohr $form = new dokuwiki\Form\Form(['method' => 'GET']); 127f09444ffSAndreas Gohr $form->setHiddenField('do', 'admin'); 128f09444ffSAndreas Gohr $form->setHiddenField('page', 'acknowledge_report'); 129*03962179SAndreas Gohr $form->addTextInput('pg', $this->getLang('pattern'))->val($ID); 130f09444ffSAndreas Gohr $form->addButton('', '>'); 131f09444ffSAndreas Gohr echo $form->toHTML(); 132f09444ffSAndreas Gohr echo '</nav>'; 133f09444ffSAndreas Gohr } 134f09444ffSAndreas Gohr 135f09444ffSAndreas Gohr /** 136f09444ffSAndreas Gohr * Print the given acknowledge data 137f09444ffSAndreas Gohr * 138f09444ffSAndreas Gohr * @param array $data 139f09444ffSAndreas Gohr * @return int number of acknowledged entries 140f09444ffSAndreas Gohr */ 141f09444ffSAndreas Gohr protected function htmlTable($data) 142f09444ffSAndreas Gohr { 143f09444ffSAndreas Gohr echo '<table>'; 144f09444ffSAndreas Gohr echo '<tr>'; 145f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewPage') . '</th>'; 146f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewUser') . '</th>'; 147f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewMod') . '</th>'; 148f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewTime') . '</th>'; 149f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewCurrent') . '</th>'; 150f09444ffSAndreas Gohr echo '</tr>'; 151f09444ffSAndreas Gohr 152f09444ffSAndreas Gohr $count = 0; 153f09444ffSAndreas Gohr foreach ($data as $item) { 154f09444ffSAndreas Gohr $current = $item['ack'] >= $item['lastmod']; 155f09444ffSAndreas Gohr if ($current) $count++; 156f09444ffSAndreas Gohr 157f09444ffSAndreas Gohr echo '<tr>'; 158f09444ffSAndreas Gohr echo '<td>' . $this->pageLink($item['page']) . '</td>'; 159f09444ffSAndreas Gohr echo '<td>' . $this->userLink($item['user']) . '</td>'; 160f09444ffSAndreas Gohr echo '<td>' . html_wikilink(':' . $item['page'], 161f09444ffSAndreas Gohr ($item['lastmod'] ? dformat($item['lastmod']) : '?')) . '</td>'; 162f09444ffSAndreas Gohr echo '<td>' . ($item['ack'] ? dformat($item['ack']) : '') . '</td>'; 163f09444ffSAndreas Gohr echo '<td>' . ($current ? $this->getLang('yes') : '') . '</td>'; 164f09444ffSAndreas Gohr echo '</tr>'; 165f09444ffSAndreas Gohr } 166f09444ffSAndreas Gohr echo '</table>'; 167f09444ffSAndreas Gohr 168f09444ffSAndreas Gohr return $count; 169f09444ffSAndreas Gohr } 170f09444ffSAndreas Gohr 171f09444ffSAndreas Gohr protected function homeLink() 172f09444ffSAndreas Gohr { 173f09444ffSAndreas Gohr global $ID; 174f09444ffSAndreas Gohr 175f09444ffSAndreas Gohr $url = wl( 176f09444ffSAndreas Gohr $ID, 177f09444ffSAndreas Gohr [ 178f09444ffSAndreas Gohr 'do' => 'admin', 179f09444ffSAndreas Gohr 'page' => 'acknowledge_report', 180f09444ffSAndreas Gohr ] 181f09444ffSAndreas Gohr ); 182f09444ffSAndreas Gohr 183f09444ffSAndreas Gohr return '<a href="' . $url . '">' . $this->getLang('home') . '</a>'; 184f09444ffSAndreas Gohr } 185f09444ffSAndreas Gohr 186f09444ffSAndreas Gohr /** 187f09444ffSAndreas Gohr * Link to the user overview 188f09444ffSAndreas Gohr * 189f09444ffSAndreas Gohr * @param string $user 190f09444ffSAndreas Gohr * @return string 191f09444ffSAndreas Gohr */ 192f09444ffSAndreas Gohr protected function userLink($user) 193f09444ffSAndreas Gohr { 194f09444ffSAndreas Gohr global $ID; 195f09444ffSAndreas Gohr 196f09444ffSAndreas Gohr $url = wl( 197f09444ffSAndreas Gohr $ID, 198f09444ffSAndreas Gohr [ 199f09444ffSAndreas Gohr 'do' => 'admin', 200f09444ffSAndreas Gohr 'page' => 'acknowledge_report', 201f09444ffSAndreas Gohr 'user' => $user, 202f09444ffSAndreas Gohr ] 203f09444ffSAndreas Gohr ); 204f09444ffSAndreas Gohr 205f09444ffSAndreas Gohr return '<a href="' . $url . '">' . hsc($user) . '</a>'; 206f09444ffSAndreas Gohr } 207f09444ffSAndreas Gohr 208f09444ffSAndreas Gohr /** 209f09444ffSAndreas Gohr * Link to the page overview 210f09444ffSAndreas Gohr * 211f09444ffSAndreas Gohr * @param string $page 212f09444ffSAndreas Gohr * @return string 213f09444ffSAndreas Gohr */ 214f09444ffSAndreas Gohr protected function pageLink($page) 215f09444ffSAndreas Gohr { 216f09444ffSAndreas Gohr global $ID; 217f09444ffSAndreas Gohr 218f09444ffSAndreas Gohr $url = wl( 219f09444ffSAndreas Gohr $ID, 220f09444ffSAndreas Gohr [ 221f09444ffSAndreas Gohr 'do' => 'admin', 222f09444ffSAndreas Gohr 'page' => 'acknowledge_report', 223f09444ffSAndreas Gohr 'pg' => $page, 224f09444ffSAndreas Gohr ] 225f09444ffSAndreas Gohr ); 226f09444ffSAndreas Gohr 227f09444ffSAndreas Gohr return '<a href="' . $url . '">' . hsc($page) . '</a>'; 228f09444ffSAndreas Gohr } 229f09444ffSAndreas Gohr 230f09444ffSAndreas Gohr /** @inheritdoc */ 231f09444ffSAndreas Gohr public function getTOC() 232f09444ffSAndreas Gohr { 233f09444ffSAndreas Gohr global $ID; 234f09444ffSAndreas Gohr return [ 235f09444ffSAndreas Gohr html_mktocitem( 236f09444ffSAndreas Gohr wl($ID, ['do' => 'admin', 'page' => 'acknowledge_report']), 237f09444ffSAndreas Gohr $this->getLang('menu'), 0, '' 238f09444ffSAndreas Gohr ), 239f09444ffSAndreas Gohr html_mktocitem( 240f09444ffSAndreas Gohr wl($ID, ['do' => 'admin', 'page' => 'acknowledge_assign']), 241f09444ffSAndreas Gohr $this->getLang('menu_assign'), 0, '' 242f09444ffSAndreas Gohr ), 243f09444ffSAndreas Gohr ]; 244f09444ffSAndreas Gohr } 245f09444ffSAndreas Gohr} 246