1f09444ffSAndreas Gohr<?php 2f09444ffSAndreas Gohr 33b76424dSanndause dokuwiki\Extension\AdminPlugin; 43b76424dSanndause dokuwiki\Form\Form; 5f09444ffSAndreas Gohruse dokuwiki\Extension\AuthPlugin; 6f09444ffSAndreas Gohr 7f09444ffSAndreas Gohr/** 8f09444ffSAndreas Gohr * DokuWiki Plugin acknowledge (Admin Component) 9f09444ffSAndreas Gohr * 10f09444ffSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 11f09444ffSAndreas Gohr * @author Andreas Gohr, Anna Dabrowska <dokuwiki@cosmocode.de> 12f09444ffSAndreas Gohr */ 133b76424dSanndaclass admin_plugin_acknowledge_report extends AdminPlugin 14f09444ffSAndreas Gohr{ 15f09444ffSAndreas Gohr /** @inheritdoc */ 16f09444ffSAndreas Gohr public function forAdminOnly() 17f09444ffSAndreas Gohr { 18f09444ffSAndreas Gohr return false; 19f09444ffSAndreas Gohr } 20f09444ffSAndreas Gohr 21f09444ffSAndreas Gohr /** @inheritdoc */ 22f09444ffSAndreas Gohr public function handle() 23f09444ffSAndreas Gohr { 24f09444ffSAndreas Gohr } 25f09444ffSAndreas Gohr 26f09444ffSAndreas Gohr /** @inheritdoc */ 27f09444ffSAndreas Gohr public function html() 28f09444ffSAndreas Gohr { 29f09444ffSAndreas Gohr global $INPUT; 30f09444ffSAndreas Gohr 31f09444ffSAndreas Gohr echo '<div class="plugin_acknowledgement_admin">'; 3227e79df0SAnna Dabrowska echo $this->locale_xhtml('report'); 33f09444ffSAndreas Gohr $this->htmlForms(); 345966046cSAnna Dabrowska $user = $INPUT->str('user'); 355966046cSAnna Dabrowska $pg = $INPUT->str('pg'); 36dee5618cSAnna Dabrowska if ($pg) { 375966046cSAnna Dabrowska $this->htmlPageStatus($pg, $user); 38dee5618cSAnna Dabrowska } elseif ($user) { 39dee5618cSAnna Dabrowska $this->htmlUserStatus($user); 40f09444ffSAndreas Gohr } else { 41f09444ffSAndreas Gohr $this->htmlLatest(); 42f09444ffSAndreas Gohr } 43f09444ffSAndreas Gohr echo '</div>'; 44f09444ffSAndreas Gohr } 45f09444ffSAndreas Gohr 46f09444ffSAndreas Gohr /** 47f09444ffSAndreas Gohr * Show which users have or need ot acknowledge a specific page 48f09444ffSAndreas Gohr * 4903962179SAndreas Gohr * @param string $pattern A page assignment pattern 505966046cSAnna Dabrowska * @param string $user Optional user 51f09444ffSAndreas Gohr */ 525966046cSAnna Dabrowska protected function htmlPageStatus($pattern, $user = '') 53f09444ffSAndreas Gohr { 54f09444ffSAndreas Gohr global $lang; 55dee5618cSAnna Dabrowska global $INPUT; 56f09444ffSAndreas Gohr 57f09444ffSAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 58f09444ffSAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 59f09444ffSAndreas Gohr 60dee5618cSAnna Dabrowska $status = $INPUT->str('status'); 6103962179SAndreas Gohr $pages = $helper->getPagesMatchingPattern($pattern); 6203962179SAndreas Gohr $acknowledgements = []; 6303962179SAndreas Gohr 6403962179SAndreas Gohr foreach ($pages as $pattern) { 65*675b1549SAnna Dabrowska $acknowledgements = array_merge( 66*675b1549SAnna Dabrowska $acknowledgements, 67*675b1549SAnna Dabrowska $helper->getPageAcknowledgements($pattern, $user, $status, 1000) 68*675b1549SAnna Dabrowska ); 69b6817aacSAndreas Gohr if (count($acknowledgements) > 1000) { 70b6817aacSAndreas Gohr // don't show too many 71b6817aacSAndreas Gohr msg($this->getLang('toomanyresults'), 0); 72b6817aacSAndreas Gohr break; 73b6817aacSAndreas Gohr } 7403962179SAndreas Gohr } 7503962179SAndreas Gohr 76f09444ffSAndreas Gohr if (!$acknowledgements) { 77f09444ffSAndreas Gohr echo '<p>' . $lang['nothingfound'] . '</p>'; 78f09444ffSAndreas Gohr return; 79f09444ffSAndreas Gohr } 80f09444ffSAndreas Gohr 8103962179SAndreas Gohr $this->htmlTable($acknowledgements); 82f09444ffSAndreas Gohr } 83f09444ffSAndreas Gohr 84f09444ffSAndreas Gohr /** 85f09444ffSAndreas Gohr * Show what a given user should sign and has 86f09444ffSAndreas Gohr * 87f09444ffSAndreas Gohr * @param string $user 88f09444ffSAndreas Gohr */ 89f09444ffSAndreas Gohr protected function htmlUserStatus($user) 90f09444ffSAndreas Gohr { 91f09444ffSAndreas Gohr /** @var AuthPlugin $auth */ 92f09444ffSAndreas Gohr global $auth; 93f09444ffSAndreas Gohr global $lang; 945966046cSAnna Dabrowska global $INPUT; 95f09444ffSAndreas Gohr 96f09444ffSAndreas Gohr $user = $auth->cleanUser($user); 97f09444ffSAndreas Gohr $userinfo = $auth->getUserData($user, true); 98f09444ffSAndreas Gohr if (!$userinfo) { 99f09444ffSAndreas Gohr echo '<p>' . $lang['nothingfound'] . '</p>'; 100f09444ffSAndreas Gohr return; 101f09444ffSAndreas Gohr } 102f09444ffSAndreas Gohr 103f09444ffSAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 104f09444ffSAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 105f09444ffSAndreas Gohr 1065966046cSAnna Dabrowska $status = $INPUT->str('status'); 1075966046cSAnna Dabrowska 1085966046cSAnna Dabrowska if ($status === 'current') { 1095966046cSAnna Dabrowska $assignments = $helper->getUserAcknowledgements($user, $userinfo['grps'], 'current'); 1105966046cSAnna Dabrowska } elseif ($status === 'due') { 1115966046cSAnna Dabrowska $assignments = $helper->getUserAcknowledgements($user, $userinfo['grps'], 'due'); 1125966046cSAnna Dabrowska } else { 1135966046cSAnna Dabrowska $assignments = $helper->getUserAcknowledgements($user, $userinfo['grps'], 'all'); 1145966046cSAnna Dabrowska } 115f09444ffSAndreas Gohr $count = $this->htmlTable($assignments); 116f09444ffSAndreas Gohr echo '<p>' . sprintf($this->getLang('count'), hsc($user), $count, count($assignments)) . '</p>'; 117f09444ffSAndreas Gohr } 118f09444ffSAndreas Gohr 119f09444ffSAndreas Gohr /** 120f09444ffSAndreas Gohr * Show the latest 100 acknowledgements 121f09444ffSAndreas Gohr */ 122f09444ffSAndreas Gohr protected function htmlLatest() 123f09444ffSAndreas Gohr { 124f09444ffSAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 125f09444ffSAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 126f09444ffSAndreas Gohr $acks = $helper->getAcknowledgements(); 127f09444ffSAndreas Gohr $this->htmlTable($acks); 128f09444ffSAndreas Gohr echo '<p>' . $this->getLang('overviewHistory') . '</p>'; 129f09444ffSAndreas Gohr } 130f09444ffSAndreas Gohr 131f09444ffSAndreas Gohr /** 132f09444ffSAndreas Gohr * @return void 133f09444ffSAndreas Gohr */ 134f09444ffSAndreas Gohr protected function htmlForms() 135f09444ffSAndreas Gohr { 136f09444ffSAndreas Gohr echo '<nav>'; 137f09444ffSAndreas Gohr echo $this->homeLink(); 138f09444ffSAndreas Gohr 1393b76424dSannda $form = new Form(['method' => 'GET']); 14045240794SAnna Dabrowska $form->id('acknowledge__user-autocomplete'); 141f09444ffSAndreas Gohr $form->setHiddenField('do', 'admin'); 142f09444ffSAndreas Gohr $form->setHiddenField('page', 'acknowledge_report'); 1435966046cSAnna Dabrowska $form->addTextInput('pg', $this->getLang('pattern')); 14445240794SAnna Dabrowska $form->addTextInput('user', $this->getLang('overviewUser')) 14545240794SAnna Dabrowska ->attr('type', 'search'); 1465966046cSAnna Dabrowska $form->addDropdown( 1475966046cSAnna Dabrowska 'status', 1485966046cSAnna Dabrowska [ 1495966046cSAnna Dabrowska 'all' => $this->getLang('all'), 1505966046cSAnna Dabrowska 'current' => $this->getLang('current'), 1515966046cSAnna Dabrowska 'due' => $this->getLang('due'), 1525966046cSAnna Dabrowska ], 1535966046cSAnna Dabrowska $this->getLang('status') 1545966046cSAnna Dabrowska ); 155f09444ffSAndreas Gohr $form->addButton('', '>'); 156f09444ffSAndreas Gohr echo $form->toHTML(); 157f09444ffSAndreas Gohr echo '</nav>'; 158f09444ffSAndreas Gohr } 159f09444ffSAndreas Gohr 160f09444ffSAndreas Gohr /** 161f09444ffSAndreas Gohr * Print the given acknowledge data 162f09444ffSAndreas Gohr * 163f09444ffSAndreas Gohr * @param array $data 164f09444ffSAndreas Gohr * @return int number of acknowledged entries 165f09444ffSAndreas Gohr */ 166f09444ffSAndreas Gohr protected function htmlTable($data) 167f09444ffSAndreas Gohr { 168f09444ffSAndreas Gohr echo '<table>'; 169f09444ffSAndreas Gohr echo '<tr>'; 170dee5618cSAnna Dabrowska echo '<th>#</th>'; 171f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewPage') . '</th>'; 172f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewUser') . '</th>'; 173f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewMod') . '</th>'; 174f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewTime') . '</th>'; 175f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewCurrent') . '</th>'; 176f09444ffSAndreas Gohr echo '</tr>'; 177f09444ffSAndreas Gohr 178f09444ffSAndreas Gohr $count = 0; 179dee5618cSAnna Dabrowska $i = 0; 180f09444ffSAndreas Gohr foreach ($data as $item) { 181f09444ffSAndreas Gohr $current = $item['ack'] >= $item['lastmod']; 182f09444ffSAndreas Gohr if ($current) $count++; 183dee5618cSAnna Dabrowska $i++; 184f09444ffSAndreas Gohr echo '<tr>'; 185dee5618cSAnna Dabrowska echo "<td>$i</td>"; 186f09444ffSAndreas Gohr echo '<td>' . $this->pageLink($item['page']) . '</td>'; 187f09444ffSAndreas Gohr echo '<td>' . $this->userLink($item['user']) . '</td>'; 1883b76424dSannda echo '<td>' . html_wikilink( 1893b76424dSannda ':' . $item['page'], 1903b76424dSannda ($item['lastmod'] ? dformat($item['lastmod']) : '?') 1913b76424dSannda ) . '</td>'; 192f09444ffSAndreas Gohr echo '<td>' . ($item['ack'] ? dformat($item['ack']) : '') . '</td>'; 193f09444ffSAndreas Gohr echo '<td>' . ($current ? $this->getLang('yes') : '') . '</td>'; 194f09444ffSAndreas Gohr echo '</tr>'; 195f09444ffSAndreas Gohr } 196f09444ffSAndreas Gohr echo '</table>'; 197f09444ffSAndreas Gohr 198f09444ffSAndreas Gohr return $count; 199f09444ffSAndreas Gohr } 200f09444ffSAndreas Gohr 201f09444ffSAndreas Gohr protected function homeLink() 202f09444ffSAndreas Gohr { 203f09444ffSAndreas Gohr global $ID; 204f09444ffSAndreas Gohr 205f09444ffSAndreas Gohr $url = wl( 206f09444ffSAndreas Gohr $ID, 207f09444ffSAndreas Gohr [ 208f09444ffSAndreas Gohr 'do' => 'admin', 209f09444ffSAndreas Gohr 'page' => 'acknowledge_report', 210f09444ffSAndreas Gohr ] 211f09444ffSAndreas Gohr ); 212f09444ffSAndreas Gohr 213f09444ffSAndreas Gohr return '<a href="' . $url . '">' . $this->getLang('home') . '</a>'; 214f09444ffSAndreas Gohr } 215f09444ffSAndreas Gohr 216f09444ffSAndreas Gohr /** 217f09444ffSAndreas Gohr * Link to the user overview 218f09444ffSAndreas Gohr * 219f09444ffSAndreas Gohr * @param string $user 220f09444ffSAndreas Gohr * @return string 221f09444ffSAndreas Gohr */ 222f09444ffSAndreas Gohr protected function userLink($user) 223f09444ffSAndreas Gohr { 224f09444ffSAndreas Gohr global $ID; 225f09444ffSAndreas Gohr 226f09444ffSAndreas Gohr $url = wl( 227f09444ffSAndreas Gohr $ID, 228f09444ffSAndreas Gohr [ 229f09444ffSAndreas Gohr 'do' => 'admin', 230f09444ffSAndreas Gohr 'page' => 'acknowledge_report', 231f09444ffSAndreas Gohr 'user' => $user, 232f09444ffSAndreas Gohr ] 233f09444ffSAndreas Gohr ); 234f09444ffSAndreas Gohr 235f09444ffSAndreas Gohr return '<a href="' . $url . '">' . hsc($user) . '</a>'; 236f09444ffSAndreas Gohr } 237f09444ffSAndreas Gohr 238f09444ffSAndreas Gohr /** 239f09444ffSAndreas Gohr * Link to the page overview 240f09444ffSAndreas Gohr * 241f09444ffSAndreas Gohr * @param string $page 242f09444ffSAndreas Gohr * @return string 243f09444ffSAndreas Gohr */ 244f09444ffSAndreas Gohr protected function pageLink($page) 245f09444ffSAndreas Gohr { 246f09444ffSAndreas Gohr global $ID; 247f09444ffSAndreas Gohr 248f09444ffSAndreas Gohr $url = wl( 249f09444ffSAndreas Gohr $ID, 250f09444ffSAndreas Gohr [ 251f09444ffSAndreas Gohr 'do' => 'admin', 252f09444ffSAndreas Gohr 'page' => 'acknowledge_report', 253f09444ffSAndreas Gohr 'pg' => $page, 254f09444ffSAndreas Gohr ] 255f09444ffSAndreas Gohr ); 256f09444ffSAndreas Gohr 257f09444ffSAndreas Gohr return '<a href="' . $url . '">' . hsc($page) . '</a>'; 258f09444ffSAndreas Gohr } 259f09444ffSAndreas Gohr 260f09444ffSAndreas Gohr /** @inheritdoc */ 261f09444ffSAndreas Gohr public function getTOC() 262f09444ffSAndreas Gohr { 263f09444ffSAndreas Gohr global $ID; 264f09444ffSAndreas Gohr return [ 265f09444ffSAndreas Gohr html_mktocitem( 266f09444ffSAndreas Gohr wl($ID, ['do' => 'admin', 'page' => 'acknowledge_report']), 2673b76424dSannda $this->getLang('menu'), 2683b76424dSannda 0, 2693b76424dSannda '' 270f09444ffSAndreas Gohr ), 271f09444ffSAndreas Gohr html_mktocitem( 272f09444ffSAndreas Gohr wl($ID, ['do' => 'admin', 'page' => 'acknowledge_assign']), 2733b76424dSannda $this->getLang('menu_assign'), 2743b76424dSannda 0, 2753b76424dSannda '' 276f09444ffSAndreas Gohr ), 277f09444ffSAndreas Gohr ]; 278f09444ffSAndreas Gohr } 279f09444ffSAndreas Gohr} 280