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