*/ class admin_plugin_acknowledge_report extends AdminPlugin { /** @inheritdoc */ public function forAdminOnly() { return false; } /** @inheritdoc */ public function handle() { } /** @inheritdoc */ public function html() { global $INPUT; echo '
'; echo $this->locale_xhtml('report'); $this->htmlForms(); $user = $INPUT->str('user'); $pg = $INPUT->str('pg'); if ($pg) { $this->htmlPageStatus($pg, $user); } elseif ($user) { $this->htmlUserStatus($user); } else { $this->htmlLatest(); } echo '
'; } /** * Show which users have or need ot acknowledge a specific page * * @param string $pattern A page assignment pattern * @param string $user Optional user */ protected function htmlPageStatus($pattern, $user = '') { global $lang; global $INPUT; /** @var helper_plugin_acknowledge $helper */ $helper = plugin_load('helper', 'acknowledge'); $status = $INPUT->str('status'); $pages = $helper->getPagesMatchingPattern($pattern); $acknowledgements = []; foreach ($pages as $pattern) { $acknowledgements = array_merge( $acknowledgements, $helper->getPageAcknowledgements($pattern, $user, $status, 1000) ); if (count($acknowledgements) > 1000) { // don't show too many msg($this->getLang('toomanyresults'), 0); break; } } if (!$acknowledgements) { echo '

' . $lang['nothingfound'] . '

'; return; } $this->htmlTable($acknowledgements); } /** * Show what a given user should sign and has * * @param string $user */ protected function htmlUserStatus($user) { /** @var AuthPlugin $auth */ global $auth; global $lang; global $INPUT; $user = $auth->cleanUser($user); $userinfo = $auth->getUserData($user, true); if (!$userinfo) { echo '

' . $lang['nothingfound'] . '

'; return; } /** @var helper_plugin_acknowledge $helper */ $helper = plugin_load('helper', 'acknowledge'); $status = $INPUT->str('status'); if ($status === 'current') { $assignments = $helper->getUserAcknowledgements($user, $userinfo['grps'], 'current'); } elseif ($status === 'due') { $assignments = $helper->getUserAcknowledgements($user, $userinfo['grps'], 'due'); } else { $assignments = $helper->getUserAcknowledgements($user, $userinfo['grps'], 'all'); } $count = $this->htmlTable($assignments); echo '

' . sprintf($this->getLang('count'), hsc($user), $count, count($assignments)) . '

'; } /** * Show the latest 100 acknowledgements */ protected function htmlLatest() { /** @var helper_plugin_acknowledge $helper */ $helper = plugin_load('helper', 'acknowledge'); $acks = $helper->getAcknowledgements(); $this->htmlTable($acks); echo '

' . $this->getLang('overviewHistory') . '

'; } /** * @return void */ protected function htmlForms() { echo ''; } /** * Print the given acknowledge data * * @param array $data * @return int number of acknowledged entries */ protected function htmlTable($data) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $count = 0; $i = 0; foreach ($data as $item) { $current = $item['ack'] >= $item['lastmod']; if ($current) $count++; $i++; echo ''; echo ""; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
#' . $this->getLang('overviewPage') . '' . $this->getLang('overviewUser') . '' . $this->getLang('overviewMod') . '' . $this->getLang('overviewTime') . '' . $this->getLang('overviewCurrent') . '
$i' . $this->pageLink($item['page']) . '' . $this->userLink($item['user']) . '' . html_wikilink( ':' . $item['page'], ($item['lastmod'] ? dformat($item['lastmod']) : '?') ) . '' . ($item['ack'] ? dformat($item['ack']) : '') . '' . ($current ? $this->getLang('yes') : '') . '
'; return $count; } protected function homeLink() { global $ID; $url = wl( $ID, [ 'do' => 'admin', 'page' => 'acknowledge_report', ] ); return '' . $this->getLang('home') . ''; } /** * Link to the user overview * * @param string $user * @return string */ protected function userLink($user) { global $ID; $url = wl( $ID, [ 'do' => 'admin', 'page' => 'acknowledge_report', 'user' => $user, ] ); return '' . hsc($user) . ''; } /** * Link to the page overview * * @param string $page * @return string */ protected function pageLink($page) { global $ID; $url = wl( $ID, [ 'do' => 'admin', 'page' => 'acknowledge_report', 'pg' => $page, ] ); return '' . hsc($page) . ''; } /** @inheritdoc */ public function getTOC() { global $ID; return [ html_mktocitem( wl($ID, ['do' => 'admin', 'page' => 'acknowledge_report']), $this->getLang('menu'), 0, '' ), html_mktocitem( wl($ID, ['do' => 'admin', 'page' => 'acknowledge_assign']), $this->getLang('menu_assign'), 0, '' ), ]; } }