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">'; 32f09444ffSAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 33f09444ffSAndreas Gohr $this->htmlForms(); 34*5966046cSAnna Dabrowska $user = $INPUT->str('user'); 35*5966046cSAnna Dabrowska $pg = $INPUT->str('pg'); 36*5966046cSAnna Dabrowska if ($user) { 37*5966046cSAnna Dabrowska $this->htmlUserStatus($user); 38*5966046cSAnna Dabrowska } elseif ($pg) { 39*5966046cSAnna Dabrowska $this->htmlPageStatus($pg, $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 50*5966046cSAnna Dabrowska * @param string $user Optional user 51f09444ffSAndreas Gohr */ 52*5966046cSAnna Dabrowska protected function htmlPageStatus($pattern, $user = '') 53f09444ffSAndreas Gohr { 54f09444ffSAndreas Gohr global $lang; 55f09444ffSAndreas Gohr 56f09444ffSAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 57f09444ffSAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 58f09444ffSAndreas Gohr 5903962179SAndreas Gohr $pages = $helper->getPagesMatchingPattern($pattern); 6003962179SAndreas Gohr $acknowledgements = []; 6103962179SAndreas Gohr 6203962179SAndreas Gohr foreach ($pages as $pattern) { 63*5966046cSAnna Dabrowska $acknowledgements = array_merge($acknowledgements, $helper->getPageAcknowledgements($pattern, 1000, $user)); 64b6817aacSAndreas Gohr if (count($acknowledgements) > 1000) { 65b6817aacSAndreas Gohr // don't show too many 66b6817aacSAndreas Gohr msg($this->getLang('toomanyresults'), 0); 67b6817aacSAndreas Gohr break; 68b6817aacSAndreas Gohr } 6903962179SAndreas Gohr } 7003962179SAndreas Gohr 71f09444ffSAndreas Gohr if (!$acknowledgements) { 72f09444ffSAndreas Gohr echo '<p>' . $lang['nothingfound'] . '</p>'; 73f09444ffSAndreas Gohr return; 74f09444ffSAndreas Gohr } 75f09444ffSAndreas Gohr 7603962179SAndreas Gohr $this->htmlTable($acknowledgements); 77f09444ffSAndreas Gohr } 78f09444ffSAndreas Gohr 79f09444ffSAndreas Gohr /** 80f09444ffSAndreas Gohr * Show what a given user should sign and has 81f09444ffSAndreas Gohr * 82f09444ffSAndreas Gohr * @param string $user 83f09444ffSAndreas Gohr */ 84f09444ffSAndreas Gohr protected function htmlUserStatus($user) 85f09444ffSAndreas Gohr { 86f09444ffSAndreas Gohr /** @var AuthPlugin $auth */ 87f09444ffSAndreas Gohr global $auth; 88f09444ffSAndreas Gohr global $lang; 89*5966046cSAnna Dabrowska global $INPUT; 90f09444ffSAndreas Gohr 91f09444ffSAndreas Gohr $user = $auth->cleanUser($user); 92f09444ffSAndreas Gohr $userinfo = $auth->getUserData($user, true); 93f09444ffSAndreas Gohr if (!$userinfo) { 94f09444ffSAndreas Gohr echo '<p>' . $lang['nothingfound'] . '</p>'; 95f09444ffSAndreas Gohr return; 96f09444ffSAndreas Gohr } 97f09444ffSAndreas Gohr 98f09444ffSAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 99f09444ffSAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 100f09444ffSAndreas Gohr 101*5966046cSAnna Dabrowska $status = $INPUT->str('status'); 102*5966046cSAnna Dabrowska 103*5966046cSAnna Dabrowska if ($status === 'current') { 104*5966046cSAnna Dabrowska $assignments = $helper->getUserAcknowledgements($user, $userinfo['grps'], 'current'); 105*5966046cSAnna Dabrowska } elseif ($status === 'due') { 106*5966046cSAnna Dabrowska $assignments = $helper->getUserAcknowledgements($user, $userinfo['grps'], 'due'); 107*5966046cSAnna Dabrowska } else { 108*5966046cSAnna Dabrowska $assignments = $helper->getUserAcknowledgements($user, $userinfo['grps'], 'all'); 109*5966046cSAnna Dabrowska } 110f09444ffSAndreas Gohr $count = $this->htmlTable($assignments); 111f09444ffSAndreas Gohr echo '<p>' . sprintf($this->getLang('count'), hsc($user), $count, count($assignments)) . '</p>'; 112f09444ffSAndreas Gohr } 113f09444ffSAndreas Gohr 114f09444ffSAndreas Gohr /** 115f09444ffSAndreas Gohr * Show the latest 100 acknowledgements 116f09444ffSAndreas Gohr */ 117f09444ffSAndreas Gohr protected function htmlLatest() 118f09444ffSAndreas Gohr { 119f09444ffSAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 120f09444ffSAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 121f09444ffSAndreas Gohr $acks = $helper->getAcknowledgements(); 122f09444ffSAndreas Gohr $this->htmlTable($acks); 123f09444ffSAndreas Gohr echo '<p>' . $this->getLang('overviewHistory') . '</p>'; 124f09444ffSAndreas Gohr } 125f09444ffSAndreas Gohr 126f09444ffSAndreas Gohr /** 127f09444ffSAndreas Gohr * @return void 128f09444ffSAndreas Gohr */ 129f09444ffSAndreas Gohr protected function htmlForms() 130f09444ffSAndreas Gohr { 131f09444ffSAndreas Gohr echo '<nav>'; 132f09444ffSAndreas Gohr echo $this->homeLink(); 133f09444ffSAndreas Gohr 1343b76424dSannda $form = new Form(['method' => 'GET']); 13545240794SAnna Dabrowska $form->id('acknowledge__user-autocomplete'); 136f09444ffSAndreas Gohr $form->setHiddenField('do', 'admin'); 137f09444ffSAndreas Gohr $form->setHiddenField('page', 'acknowledge_report'); 138*5966046cSAnna Dabrowska $form->addTextInput('pg', $this->getLang('pattern')); 13945240794SAnna Dabrowska $form->addTextInput('user', $this->getLang('overviewUser')) 14045240794SAnna Dabrowska ->attr('type', 'search'); 141*5966046cSAnna Dabrowska $form->addDropdown( 142*5966046cSAnna Dabrowska 'status', 143*5966046cSAnna Dabrowska [ 144*5966046cSAnna Dabrowska 'all' => $this->getLang('all'), 145*5966046cSAnna Dabrowska 'current' => $this->getLang('current'), 146*5966046cSAnna Dabrowska 'due' => $this->getLang('due'), 147*5966046cSAnna Dabrowska ], 148*5966046cSAnna Dabrowska $this->getLang('status') 149*5966046cSAnna Dabrowska ); 150f09444ffSAndreas Gohr $form->addButton('', '>'); 151f09444ffSAndreas Gohr echo $form->toHTML(); 152f09444ffSAndreas Gohr echo '</nav>'; 153f09444ffSAndreas Gohr } 154f09444ffSAndreas Gohr 155f09444ffSAndreas Gohr /** 156f09444ffSAndreas Gohr * Print the given acknowledge data 157f09444ffSAndreas Gohr * 158f09444ffSAndreas Gohr * @param array $data 159f09444ffSAndreas Gohr * @return int number of acknowledged entries 160f09444ffSAndreas Gohr */ 161f09444ffSAndreas Gohr protected function htmlTable($data) 162f09444ffSAndreas Gohr { 163f09444ffSAndreas Gohr echo '<table>'; 164f09444ffSAndreas Gohr echo '<tr>'; 165f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewPage') . '</th>'; 166f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewUser') . '</th>'; 167f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewMod') . '</th>'; 168f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewTime') . '</th>'; 169f09444ffSAndreas Gohr echo '<th>' . $this->getLang('overviewCurrent') . '</th>'; 170f09444ffSAndreas Gohr echo '</tr>'; 171f09444ffSAndreas Gohr 172f09444ffSAndreas Gohr $count = 0; 173f09444ffSAndreas Gohr foreach ($data as $item) { 174f09444ffSAndreas Gohr $current = $item['ack'] >= $item['lastmod']; 175f09444ffSAndreas Gohr if ($current) $count++; 176f09444ffSAndreas Gohr 177f09444ffSAndreas Gohr echo '<tr>'; 178f09444ffSAndreas Gohr echo '<td>' . $this->pageLink($item['page']) . '</td>'; 179f09444ffSAndreas Gohr echo '<td>' . $this->userLink($item['user']) . '</td>'; 1803b76424dSannda echo '<td>' . html_wikilink( 1813b76424dSannda ':' . $item['page'], 1823b76424dSannda ($item['lastmod'] ? dformat($item['lastmod']) : '?') 1833b76424dSannda ) . '</td>'; 184f09444ffSAndreas Gohr echo '<td>' . ($item['ack'] ? dformat($item['ack']) : '') . '</td>'; 185f09444ffSAndreas Gohr echo '<td>' . ($current ? $this->getLang('yes') : '') . '</td>'; 186f09444ffSAndreas Gohr echo '</tr>'; 187f09444ffSAndreas Gohr } 188f09444ffSAndreas Gohr echo '</table>'; 189f09444ffSAndreas Gohr 190f09444ffSAndreas Gohr return $count; 191f09444ffSAndreas Gohr } 192f09444ffSAndreas Gohr 193f09444ffSAndreas Gohr protected function homeLink() 194f09444ffSAndreas Gohr { 195f09444ffSAndreas Gohr global $ID; 196f09444ffSAndreas Gohr 197f09444ffSAndreas Gohr $url = wl( 198f09444ffSAndreas Gohr $ID, 199f09444ffSAndreas Gohr [ 200f09444ffSAndreas Gohr 'do' => 'admin', 201f09444ffSAndreas Gohr 'page' => 'acknowledge_report', 202f09444ffSAndreas Gohr ] 203f09444ffSAndreas Gohr ); 204f09444ffSAndreas Gohr 205f09444ffSAndreas Gohr return '<a href="' . $url . '">' . $this->getLang('home') . '</a>'; 206f09444ffSAndreas Gohr } 207f09444ffSAndreas Gohr 208f09444ffSAndreas Gohr /** 209f09444ffSAndreas Gohr * Link to the user overview 210f09444ffSAndreas Gohr * 211f09444ffSAndreas Gohr * @param string $user 212f09444ffSAndreas Gohr * @return string 213f09444ffSAndreas Gohr */ 214f09444ffSAndreas Gohr protected function userLink($user) 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 'user' => $user, 224f09444ffSAndreas Gohr ] 225f09444ffSAndreas Gohr ); 226f09444ffSAndreas Gohr 227f09444ffSAndreas Gohr return '<a href="' . $url . '">' . hsc($user) . '</a>'; 228f09444ffSAndreas Gohr } 229f09444ffSAndreas Gohr 230f09444ffSAndreas Gohr /** 231f09444ffSAndreas Gohr * Link to the page overview 232f09444ffSAndreas Gohr * 233f09444ffSAndreas Gohr * @param string $page 234f09444ffSAndreas Gohr * @return string 235f09444ffSAndreas Gohr */ 236f09444ffSAndreas Gohr protected function pageLink($page) 237f09444ffSAndreas Gohr { 238f09444ffSAndreas Gohr global $ID; 239f09444ffSAndreas Gohr 240f09444ffSAndreas Gohr $url = wl( 241f09444ffSAndreas Gohr $ID, 242f09444ffSAndreas Gohr [ 243f09444ffSAndreas Gohr 'do' => 'admin', 244f09444ffSAndreas Gohr 'page' => 'acknowledge_report', 245f09444ffSAndreas Gohr 'pg' => $page, 246f09444ffSAndreas Gohr ] 247f09444ffSAndreas Gohr ); 248f09444ffSAndreas Gohr 249f09444ffSAndreas Gohr return '<a href="' . $url . '">' . hsc($page) . '</a>'; 250f09444ffSAndreas Gohr } 251f09444ffSAndreas Gohr 252f09444ffSAndreas Gohr /** @inheritdoc */ 253f09444ffSAndreas Gohr public function getTOC() 254f09444ffSAndreas Gohr { 255f09444ffSAndreas Gohr global $ID; 256f09444ffSAndreas Gohr return [ 257f09444ffSAndreas Gohr html_mktocitem( 258f09444ffSAndreas Gohr wl($ID, ['do' => 'admin', 'page' => 'acknowledge_report']), 2593b76424dSannda $this->getLang('menu'), 2603b76424dSannda 0, 2613b76424dSannda '' 262f09444ffSAndreas Gohr ), 263f09444ffSAndreas Gohr html_mktocitem( 264f09444ffSAndreas Gohr wl($ID, ['do' => 'admin', 'page' => 'acknowledge_assign']), 2653b76424dSannda $this->getLang('menu_assign'), 2663b76424dSannda 0, 2673b76424dSannda '' 268f09444ffSAndreas Gohr ), 269f09444ffSAndreas Gohr ]; 270f09444ffSAndreas Gohr } 271f09444ffSAndreas Gohr} 272