function comments_display_main

6.x comments.module comments_display_main()
4.x comments.module comments_display_main()
5.x comments.module comments_display_main()

This displays the primary Comments tab, where we see past comments and can enter a new one (with the right permissions).

File

modules/comments/comments.module, line 248

Code

function comments_display_main() {
  global $current_student_id, $screen, $user;
  $rtn = "";

  fp_add_js(fp_get_module_path("comments") . "/js/comments.js");
  fp_add_css(fp_get_module_path("comments") . "/css/comments.css");

  if (user_has_permission("can_save_comments")) {

    $form = fp_render_form("comments_comment_form");

    $rtn .= fp_render_c_fieldset($form, t("Click to enter comment"), true, " new-comment-fs");
  }

  fp_set_title('');

  $access_types = (user_has_permission("view_faculty_comments")) ? array("faculty", "public") : array("public");

  $comments = comments_get_comments($current_student_id, FALSE, $access_types);

  foreach ($comments as $comment) {

    $delete_link = "";
    // Should we present a "delete link" to the user for this comment?
    if (user_has_permission("can_delete_own_comments_3_months") && $comment ['faculty_id'] == $user->cwid) {
      // See if this comment is younger than 3 months.
      $del_range = strtotime("now -3 months");
      $then = intval($comment ["posted"]);


      if ($then > $del_range) {

        $delete_link = "<a href='javascript:deleteComment(\"{$comment ["id"]}\");' class='button'>" . t("Delete") . "</a>";
      }
    }


    $rtn .= comments_render_comment($comment, $delete_link);
  }

  // Let's set our breadcrumbs
  $db = get_global_database_handler();
  $crumbs = array();
  $crumbs [] = array(
    'text' => 'Students',
    'path' => 'student-search',
  );
  $crumbs [] = array(
    'text' => $db->get_student_name($current_student_id) . " ({$current_student_id})",
    'path' => 'student-profile',
    'query' => "current_student_id={$current_student_id}",
  );
  fp_set_breadcrumbs($crumbs);

  watchdog("comments", "view all $current_student_id", array(), WATCHDOG_DEBUG);

  return $rtn;
}