/**
  * Display subscribe options.
  * @param forum $forum Forum
  * @param string $text Textual note
  * @param int $subscribed
  * @param bool $button True if subscribe/unsubscribe button should be shown
  * @param bool $viewlink True if 'view subscribers' link should be shown
  * @return string HTML code for this area
  */
 public function display_subscribe_options($forum, $text, $subscribed, $button, $viewlink)
 {
     $out = '<div class="forumng-subscribe-options">' . '<h3>' . get_string('subscription', 'forumng') . '</h3>' . '<p>' . $text . '</p>';
     $cm = $forum->get_course_module();
     if ($button) {
         $outsubmit = '';
         $currentgroupid = forum::get_activity_group($cm, true);
         if ($currentgroupid == forum::NO_GROUPS) {
             $currentgroupid = 0;
         }
         if ($subscribed == forum::FULLY_SUBSCRIBED || $subscribed == forum::FULLY_SUBSCRIBED_GROUPMODE) {
             $outsubmit .= '<input type="submit" name="submitunsubscribe" value="' . get_string('unsubscribeshort', 'forumng') . '" />';
         } else {
             if ($subscribed == forum::PARTIALLY_SUBSCRIBED) {
                 //print both subscribe button and unsubscribe button
                 $outsubmit .= '<input type="submit" name="submitsubscribe" value="' . get_string('subscribelong', 'forumng') . '" />' . '<input type="submit" name="submitunsubscribe" value="' . get_string('unsubscribelong', 'forumng') . '" />';
             } else {
                 if ($subscribed == forum::NOT_SUBSCRIBED) {
                     //default unsubscribed, print subscribe button
                     $outsubmit .= '<input type="submit" name="submitsubscribe" value="' . get_string('subscribeshort', 'forumng') . '" />';
                 } else {
                     if ($subscribed == forum::THIS_GROUP_PARTIALLY_SUBSCRIBED) {
                         $outsubmit .= '<input type="submit" name="submitsubscribe_thisgroup" value="' . get_string('subscribegroup', 'forumng') . '" />' . '<input type="submit" name="submitunsubscribe_thisgroup" value="' . get_string('unsubscribegroup_partial', 'forumng') . '" />' . '<input type="hidden" name="g" value="' . $currentgroupid . '" />';
                     } else {
                         if ($subscribed == forum::THIS_GROUP_SUBSCRIBED) {
                             $outsubmit .= '<input type="submit" name="submitunsubscribe_thisgroup" value="' . get_string('unsubscribegroup', 'forumng') . '" />' . '<input type="hidden" name="g" value="' . $currentgroupid . '" />';
                         } else {
                             if ($subscribed == forum::THIS_GROUP_NOT_SUBSCRIBED) {
                                 $outsubmit .= '<input type="submit" name="submitsubscribe_thisgroup" value="' . get_string('subscribegroup', 'forumng') . '" />' . '<input type="hidden" name="g" value="' . $currentgroupid . '" />';
                             }
                         }
                     }
                 }
             }
         }
         $out .= '<form action="subscribe.php" method="post"><div>' . $forum->get_link_params(forum::PARAM_FORM) . '<input type="hidden" name="back" value="view" />' . $outsubmit . '</div></form>';
     }
     if ($viewlink) {
         $out .= ' <div class="forumng-subscribe-admin">' . '<a href="subscribers.php?' . $forum->get_link_params(forum::PARAM_HTML) . '">' . get_string('viewsubscribers', 'forumng') . '</a></div>';
     }
     $out .= '</div>';
     return $out;
 }
 /**
  * 
  * @param forum $forum Forum
  * @param object $cm Course-module object
  * @param object $context Context object
  * @param object $course Course object
  */
 function next_forum(&$forum, &$cm, &$context, &$course)
 {
     // Skip if required to get to new forum
     while ($this->forum != null) {
         $this->next_discussion($discussion);
     }
     // Get record
     if ($this->storedrecord) {
         $record = $this->storedrecord;
         $this->storedrecord = null;
     } else {
         if (!$this->rs) {
             // Already used entire list and closed recordset
             return false;
         } else {
             $record = rs_fetch_next_record($this->rs);
             if (!$record) {
                 // End of the line. Mark everything as mailed
                 $this->mark_mailed($this->time);
                 rs_close($this->rs);
                 $this->rs = null;
                 return false;
             }
         }
     }
     // Set data
     $this->storedrecord = clone $record;
     $cm = forum_utils::extract_subobject($record, 'cm_');
     $course = forum_utils::extract_subobject($record, 'c_');
     $context = forum_utils::extract_subobject($record, 'x_');
     $forum = new forum($course, $cm, $context, forum_utils::extract_subobject($record, 'f_'));
     if ($forum->is_shared()) {
         $forum->set_clone_reference($record->cloneid);
         $cm = $forum->get_course_module();
         $course = $forum->get_course();
         $context = $forum->get_context();
     }
     $this->forum = $forum;
     return true;
 }