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 * 4603962179SAndreas Gohr * @param string $pattern A page assignment pattern 47f09444ffSAndreas Gohr */ 4803962179SAndreas 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 5503962179SAndreas Gohr $pages = $helper->getPagesMatchingPattern($pattern); 5603962179SAndreas Gohr $acknowledgements = []; 5703962179SAndreas Gohr 5803962179SAndreas Gohr foreach ($pages as $pattern) { 59*b6817aacSAndreas Gohr $acknowledgements = array_merge($acknowledgements, $helper->getPageAcknowledgements($pattern, 1000)); 60*b6817aacSAndreas Gohr if(count($acknowledgements) > 1000) { 61*b6817aacSAndreas Gohr // don't show too many 62*b6817aacSAndreas Gohr msg($this->getLang('toomanyresults'), 0); 63*b6817aacSAndreas Gohr break; 64*b6817aacSAndreas Gohr } 6503962179SAndreas Gohr } 6603962179SAndreas Gohr 67f09444ffSAndreas Gohr if (!$acknowledgements) { 68f09444ffSAndreas Gohr echo '<p>' . $lang['nothingfound'] . '</p>'; 69f09444ffSAndreas Gohr return; 70f09444ffSAndreas Gohr } 71f09444ffSAndreas Gohr 7203962179SAndreas Gohr $this->htmlTable($acknowledgements); 73f09444ffSAndreas Gohr } 74f09444ffSAndreas Gohr 75f09444ffSAndreas Gohr /** 76f09444ffSAndreas Gohr * Show what a given user should sign and has 77f09444ffSAndreas Gohr * 78f09444ffSAndreas Gohr * @param string $user 79f09444ffSAndreas Gohr */ 80f09444ffSAndreas Gohr protected function htmlUserStatus($user) 81f09444ffSAndreas Gohr { 82f09444ffSAndreas Gohr /** @var AuthPlugin $auth */ 83f09444ffSAndreas Gohr global $auth; 84f09444ffSAndreas Gohr global $lang; 85f09444ffSAndreas Gohr 86f09444ffSAndreas Gohr $user = $auth->cleanUser($user); 87f09444ffSAndreas Gohr $userinfo = $auth->getUserData($user, true); 88f09444ffSAndreas Gohr if (!$userinfo) { 89f09444ffSAndreas Gohr echo '<p>' . $lang['nothingfound'] . '</p>'; 90f09444ffSAndreas Gohr return; 91f09444ffSAndreas Gohr } 92f09444ffSAndreas Gohr 93f09444ffSAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 94f09444ffSAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 95f09444ffSAndreas Gohr 96f09444ffSAndreas Gohr $assignments = $helper->getUserAcknowledgements($user, $userinfo['grps']); 97f09444ffSAndreas Gohr $count = $this->htmlTable($assignments); 98f09444ffSAndreas Gohr echo '<p>' . sprintf($this->getLang('count'), hsc($user), $count, count($assignments)) . '</p>'; 99f09444ffSAndreas Gohr } 100f09444ffSAndreas Gohr 101f09444ffSAndreas Gohr /** 102f09444ffSAndreas Gohr * Show the latest 100 acknowledgements 103f09444ffSAndreas Gohr */ 104f09444ffSAndreas Gohr protected function htmlLatest() 105f09444ffSAndreas Gohr { 106f09444ffSAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 107f09444ffSAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 108f09444ffSAndreas Gohr $acks = $helper->getAcknowledgements(); 109f09444ffSAndreas Gohr $this->htmlTable($acks); 110f09444ffSAndreas Gohr echo '<p>' . $this->getLang('overviewHistory') . '</p>'; 111f09444ffSAndreas Gohr } 112f09444ffSAndreas Gohr 113f09444ffSAndreas Gohr /** 114f09444ffSAndreas Gohr * @return void 115f09444ffSAndreas Gohr */ 116f09444ffSAndreas Gohr protected function htmlForms() 117f09444ffSAndreas Gohr { 118f09444ffSAndreas Gohr global $ID; 119f09444ffSAndreas Gohr 120f09444ffSAndreas Gohr echo '<nav>'; 121f09444ffSAndreas Gohr echo $this->homeLink(); 122f09444ffSAndreas Gohr 123f09444ffSAndreas Gohr $form = new dokuwiki\Form\Form(['method' => 'GET']); 124f09444ffSAndreas Gohr $form->setHiddenField('do', 'admin'); 125f09444ffSAndreas Gohr $form->setHiddenField('page', 'acknowledge_report'); 126f09444ffSAndreas Gohr $form->addTextInput('user', $this->getLang('overviewUser')); 127f09444ffSAndreas Gohr $form->addButton('', '>'); 128f09444ffSAndreas Gohr echo $form->toHTML(); 129f09444ffSAndreas Gohr 130f09444ffSAndreas Gohr $form = new dokuwiki\Form\Form(['method' => 'GET']); 131f09444ffSAndreas Gohr $form->setHiddenField('do', 'admin'); 132f09444ffSAndreas Gohr $form->setHiddenField('page', 'acknowledge_report'); 13303962179SAndreas Gohr $form->addTextInput('pg', $this->getLang('pattern'))->val($ID); 134f09444ffSAndreas Gohr $form->addButton('', '>'); 135f09444ffSAndreas Gohr echo $form->toHTML(); 136f09444ffSAndreas Gohr echo '</nav>'; 137f09444ffSAndreas Gohr } 138f09444ffSAndreas Gohr 139f09444ffSAndreas Gohr /** 140f09444ffSAndreas Gohr * Print the given acknowledge data 141f09444ffSAndreas Gohr * 142f09444ffSAndreas Gohr * @param array $data 143f09444ffSAndreas Gohr * @return int number of acknowledged entries 144f09444ffSAndreas Gohr */ 145f09444ffSAndreas Gohr protected function htmlTable($data) 146f09444ffSAndreas Gohr { 147f09444ffSAndreas Gohr echo '<table>'; 148f09444ffSAndreas Gohr echo '<tr>'; 149f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewPage') . '</th>'; 150f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewUser') . '</th>'; 151f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewMod') . '</th>'; 152f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewTime') . '</th>'; 153f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewCurrent') . '</th>'; 154f09444ffSAndreas Gohr echo '</tr>'; 155f09444ffSAndreas Gohr 156f09444ffSAndreas Gohr $count = 0; 157f09444ffSAndreas Gohr foreach ($data as $item) { 158f09444ffSAndreas Gohr $current = $item['ack'] >= $item['lastmod']; 159f09444ffSAndreas Gohr if ($current) $count++; 160f09444ffSAndreas Gohr 161f09444ffSAndreas Gohr echo '<tr>'; 162f09444ffSAndreas Gohr echo '<td>' . $this->pageLink($item['page']) . '</td>'; 163f09444ffSAndreas Gohr echo '<td>' . $this->userLink($item['user']) . '</td>'; 164f09444ffSAndreas Gohr echo '<td>' . html_wikilink(':' . $item['page'], 165f09444ffSAndreas Gohr ($item['lastmod'] ? dformat($item['lastmod']) : '?')) . '</td>'; 166f09444ffSAndreas Gohr echo '<td>' . ($item['ack'] ? dformat($item['ack']) : '') . '</td>'; 167f09444ffSAndreas Gohr echo '<td>' . ($current ? $this->getLang('yes') : '') . '</td>'; 168f09444ffSAndreas Gohr echo '</tr>'; 169f09444ffSAndreas Gohr } 170f09444ffSAndreas Gohr echo '</table>'; 171f09444ffSAndreas Gohr 172f09444ffSAndreas Gohr return $count; 173f09444ffSAndreas Gohr } 174f09444ffSAndreas Gohr 175f09444ffSAndreas Gohr protected function homeLink() 176f09444ffSAndreas Gohr { 177f09444ffSAndreas Gohr global $ID; 178f09444ffSAndreas Gohr 179f09444ffSAndreas Gohr $url = wl( 180f09444ffSAndreas Gohr $ID, 181f09444ffSAndreas Gohr [ 182f09444ffSAndreas Gohr 'do' => 'admin', 183f09444ffSAndreas Gohr 'page' => 'acknowledge_report', 184f09444ffSAndreas Gohr ] 185f09444ffSAndreas Gohr ); 186f09444ffSAndreas Gohr 187f09444ffSAndreas Gohr return '<a href="' . $url . '">' . $this->getLang('home') . '</a>'; 188f09444ffSAndreas Gohr } 189f09444ffSAndreas Gohr 190f09444ffSAndreas Gohr /** 191f09444ffSAndreas Gohr * Link to the user overview 192f09444ffSAndreas Gohr * 193f09444ffSAndreas Gohr * @param string $user 194f09444ffSAndreas Gohr * @return string 195f09444ffSAndreas Gohr */ 196f09444ffSAndreas Gohr protected function userLink($user) 197f09444ffSAndreas Gohr { 198f09444ffSAndreas Gohr global $ID; 199f09444ffSAndreas Gohr 200f09444ffSAndreas Gohr $url = wl( 201f09444ffSAndreas Gohr $ID, 202f09444ffSAndreas Gohr [ 203f09444ffSAndreas Gohr 'do' => 'admin', 204f09444ffSAndreas Gohr 'page' => 'acknowledge_report', 205f09444ffSAndreas Gohr 'user' => $user, 206f09444ffSAndreas Gohr ] 207f09444ffSAndreas Gohr ); 208f09444ffSAndreas Gohr 209f09444ffSAndreas Gohr return '<a href="' . $url . '">' . hsc($user) . '</a>'; 210f09444ffSAndreas Gohr } 211f09444ffSAndreas Gohr 212f09444ffSAndreas Gohr /** 213f09444ffSAndreas Gohr * Link to the page overview 214f09444ffSAndreas Gohr * 215f09444ffSAndreas Gohr * @param string $page 216f09444ffSAndreas Gohr * @return string 217f09444ffSAndreas Gohr */ 218f09444ffSAndreas Gohr protected function pageLink($page) 219f09444ffSAndreas Gohr { 220f09444ffSAndreas Gohr global $ID; 221f09444ffSAndreas Gohr 222f09444ffSAndreas Gohr $url = wl( 223f09444ffSAndreas Gohr $ID, 224f09444ffSAndreas Gohr [ 225f09444ffSAndreas Gohr 'do' => 'admin', 226f09444ffSAndreas Gohr 'page' => 'acknowledge_report', 227f09444ffSAndreas Gohr 'pg' => $page, 228f09444ffSAndreas Gohr ] 229f09444ffSAndreas Gohr ); 230f09444ffSAndreas Gohr 231f09444ffSAndreas Gohr return '<a href="' . $url . '">' . hsc($page) . '</a>'; 232f09444ffSAndreas Gohr } 233f09444ffSAndreas Gohr 234f09444ffSAndreas Gohr /** @inheritdoc */ 235f09444ffSAndreas Gohr public function getTOC() 236f09444ffSAndreas Gohr { 237f09444ffSAndreas Gohr global $ID; 238f09444ffSAndreas Gohr return [ 239f09444ffSAndreas Gohr html_mktocitem( 240f09444ffSAndreas Gohr wl($ID, ['do' => 'admin', 'page' => 'acknowledge_report']), 241f09444ffSAndreas Gohr $this->getLang('menu'), 0, '' 242f09444ffSAndreas Gohr ), 243f09444ffSAndreas Gohr html_mktocitem( 244f09444ffSAndreas Gohr wl($ID, ['do' => 'admin', 'page' => 'acknowledge_assign']), 245f09444ffSAndreas Gohr $this->getLang('menu_assign'), 0, '' 246f09444ffSAndreas Gohr ), 247f09444ffSAndreas Gohr ]; 248f09444ffSAndreas Gohr } 249f09444ffSAndreas Gohr} 250