month = $_REQUEST['rec_month']; } else { $this->month = date('Y-m'); } $log = new helper_plugin_recommend_log($this->month); $this->entries = $log->getEntries(); $this->logs = $log->getLogs(); global $INPUT; global $ID; /** @var helper_plugin_recommend_assignment $assignmentsHelper */ $assignmentsHelper = plugin_load('helper', 'recommend_assignment'); if ($INPUT->str('action') && $INPUT->arr('assignment') && checkSecurityToken()) { $assignment = $INPUT->arr('assignment'); if ($INPUT->str('action') === 'delete') { $ok = $assignmentsHelper->removeAssignment($assignment); if (!$ok) { msg('failed to remove pattern', -1); } } elseif ($INPUT->str('action') === 'add') { if ($assignment['pattern'][0] == '/') { if (@preg_match($assignment['pattern'], null) === false) { msg('Invalid regular expression. Pattern not saved', -1); } else { $ok = $assignmentsHelper->addAssignment($assignment); if (!$ok) { msg('failed to add pattern', -1); } } } else { $ok = $assignmentsHelper->addAssignment($assignment); if (!$ok) { msg('failed to add pattern', -1); } } } send_redirect(wl($ID, array('do' => 'admin', 'page' => 'recommend'), true, '&')); } } public function getTOC() { return array_map([$this, 'recommendMakeTOC'], $this->logs); } public function html() { echo $this->locale_xhtml('intro'); if (!$this->logs) { echo 'No recommendations.'; } if (!$this->entries) { echo 'No recommendations were made in ' . $this->month . '.'; } echo '

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

'; echo $this->getForm(); echo '

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

'; echo '

In ' . $this->month . ', your users made the following ' . count($this->entries) . ' recommendations:

'; echo ''; } protected function getForm() { global $ID; $assignments = helper_plugin_recommend_assignment::getAssignments(); $form = '
'; $form .= ''; $form .= ''; $form .= ''; $form .= ''; // header $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; // existing assignments foreach ($assignments as $assignment) { $pattern = $assignment['pattern']; $user = $assignment['user']; $subject = $assignment['subject']; $message = $assignment['message']; $link = wl( $ID, [ 'do' => 'admin', 'page' => 'recommend', 'action' => 'delete', 'sectok' => getSecurityToken(), 'assignment[pattern]' => $pattern, 'assignment[user]' => $user, 'assignment[subject]' => $subject, 'assignment[message]' => $message, ] ); $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; } // new assignment form $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= ''; $form .= '
' . $this->getLang('assign_pattern') . '' . $this->getLang('assign_user') . '' . $this->getLang('assign_subject') . '' . $this->getLang('assign_message') . '
' . hsc($pattern) . '' . hsc($user) . '' . hsc($subject) . '' . nl2br($message) . '' . $this->getLang('assign_del') . '
'; $form .= '
'; return $form; } protected function recommendMakeTOC($month) { global $ID; return html_mktocitem('?do=admin&page=recommend&id=' . $ID . '&rec_month=' . $month, $month, 2, ''); } }