Advertisement
Guest User

file1.php

a guest
Nov 27th, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.60 KB | None | 0 0
  1. <?php
  2.  
  3.  global $content; // discussion content
  4.  
  5. // This file is part of Moodle - http://moodle.org/
  6. //
  7. // Moodle is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // Moodle is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. /**
  21.  * Displays a post, and all the posts below it.
  22.  * If no post is given, displays all posts in a discussion
  23.  *
  24.  * @package mod-forum
  25.  * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
  26.  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27.  */
  28.  
  29. // Report all PHP errors (see changelog)
  30.  
  31.     require_once('../../config.php');
  32.  
  33.     $d      = required_param('d', PARAM_INT);                // Discussion ID
  34.     $parent = optional_param('parent', 0, PARAM_INT);        // If set, then display this post and all children.
  35.     $mode   = optional_param('mode', 0, PARAM_INT);          // If set, changes the layout of the thread
  36.     $move   = optional_param('move', 0, PARAM_INT);          // If set, moves this discussion to another forum
  37.     $mark   = optional_param('mark', '', PARAM_ALPHA);       // Used for tracking read posts if user initiated.
  38.     $postid = optional_param('postid', 0, PARAM_INT);        // Used for tracking read posts if user initiated.
  39.  
  40.     $url = new moodle_url('/mod/forum/discuss.php', array('d'=>$d));
  41.     if ($parent !== 0) {
  42.         $url->param('parent', $parent);
  43.     }
  44.     $PAGE->set_url($url);
  45.  
  46.     $discussion = $DB->get_record('forum_discussions', array('id' => $d), '*', MUST_EXIST);
  47.     $course = $DB->get_record('course', array('id' => $discussion->course), '*', MUST_EXIST);
  48.     $forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST);
  49.     $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
  50.  
  51.     require_course_login($course, true, $cm);
  52.  
  53.     // move this down fix for MDL-6926
  54.     require_once($CFG->dirroot.'/mod/forum/lib.php');
  55.  
  56.     $modcontext = context_module::instance($cm->id);
  57.     require_capability('mod/forum:viewdiscussion', $modcontext, NULL, true, 'noviewdiscussionspermission', 'forum');
  58.  
  59.     if (!empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds) && $forum->rsstype && $forum->rssarticles) {
  60.         require_once("$CFG->libdir/rsslib.php");
  61.  
  62.         $rsstitle = format_string($course->shortname, true, array('context' => context_course::instance($course->id))) . ': ' . format_string($forum->name);
  63.         rss_add_http_header($modcontext, 'mod_forum', $forum, $rsstitle);
  64.     }
  65.  
  66. /// move discussion if requested
  67.     if ($move > 0 and confirm_sesskey()) {
  68.         $return = $CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->id;
  69.  
  70.         require_capability('mod/forum:movediscussions', $modcontext);
  71.  
  72.         if ($forum->type == 'single') {
  73.             print_error('cannotmovefromsingleforum', 'forum', $return);
  74.         }
  75.  
  76.         if (!$forumto = $DB->get_record('forum', array('id' => $move))) {
  77.             print_error('cannotmovetonotexist', 'forum', $return);
  78.         }
  79.  
  80.         if ($forumto->type == 'single') {
  81.             print_error('cannotmovetosingleforum', 'forum', $return);
  82.         }
  83.  
  84.         if (!$cmto = get_coursemodule_from_instance('forum', $forumto->id, $course->id)) {
  85.             print_error('cannotmovetonotfound', 'forum', $return);
  86.         }
  87.  
  88.         if (!coursemodule_visible_for_user($cmto)) {
  89.             print_error('cannotmovenotvisible', 'forum', $return);
  90.         }
  91.  
  92.         require_capability('mod/forum:startdiscussion', context_module::instance($cmto->id));
  93.  
  94.         if (!forum_move_attachments($discussion, $forum->id, $forumto->id)) {
  95.             echo $OUTPUT->notification("Errors occurred while moving attachment directories - check your file permissions");
  96.         }
  97.         $DB->set_field('forum_discussions', 'forum', $forumto->id, array('id' => $discussion->id));
  98.         $DB->set_field('forum_read', 'forumid', $forumto->id, array('discussionid' => $discussion->id));
  99.         add_to_log($course->id, 'forum', 'move discussion', "discuss.php?d=$discussion->id", $discussion->id, $cmto->id);
  100.  
  101.         // Delete the RSS files for the 2 forums to force regeneration of the feeds
  102.         require_once($CFG->dirroot.'/mod/forum/rsslib.php');
  103.         forum_rss_delete_file($forum);
  104.         forum_rss_delete_file($forumto);
  105.  
  106.         redirect($return.'&moved=-1&sesskey='.sesskey());
  107.     }
  108.  
  109.     add_to_log($course->id, 'forum', 'view discussion', "discuss.php?d=$discussion->id", $discussion->id, $cm->id);
  110.  
  111.     unset($SESSION->fromdiscussion);
  112.  
  113.     if ($mode) {
  114.         set_user_preference('forum_displaymode', $mode);
  115.     }
  116.  
  117.     $displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode);
  118.  
  119.     if ($parent) {
  120.         // If flat AND parent, then force nested display this time
  121.         if ($displaymode == FORUM_MODE_FLATOLDEST or $displaymode == FORUM_MODE_FLATNEWEST) {
  122.             $displaymode = FORUM_MODE_NESTED;
  123.         }
  124.     } else {
  125.         $parent = $discussion->firstpost;
  126.     }
  127.  
  128.     if (! $post = forum_get_post_full($parent)) {
  129.         print_error("notexists", 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
  130.     }
  131.  
  132.     if (!forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
  133.         print_error('noviewdiscussionspermission', 'forum', "$CFG->wwwroot/mod/forum/view.php?id=$forum->id");
  134.     }
  135.  
  136.     if ($mark == 'read' or $mark == 'unread') {
  137.         if ($CFG->forum_usermarksread && forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
  138.             if ($mark == 'read') {
  139.                 forum_tp_add_read_record($USER->id, $postid);
  140.             } else {
  141.                 // unread
  142.                 forum_tp_delete_read_records($USER->id, $postid);
  143.             }
  144.         }
  145.     }
  146.  
  147.     $searchform = forum_search_form($course);
  148.  
  149.     $forumnode = $PAGE->navigation->find($cm->id, navigation_node::TYPE_ACTIVITY);
  150.     if (empty($forumnode)) {
  151.         $forumnode = $PAGE->navbar;
  152.     } else {
  153.         $forumnode->make_active();
  154.     }
  155.     $node = $forumnode->add(format_string($discussion->name), new moodle_url('/mod/forum/discuss.php', array('d'=>$discussion->id)));
  156.     $node->display = false;
  157.     if ($node && $post->id != $discussion->firstpost) {
  158.         $node->add(format_string($post->subject), $PAGE->url);
  159.     }
  160.  
  161.     $PAGE->set_title("$course->shortname: ".format_string($discussion->name));
  162.     $PAGE->set_heading($course->fullname);
  163.     $PAGE->set_button($searchform);
  164.    
  165. // added by girish
  166. // load the fb like js
  167.    
  168.    echo 'global scope'.$content;
  169.  
  170.      
  171.   echo '<input type="hidden" maxlength="3" name="value" id="val" value= "https://www.google.com"/>'; // can we get values from lib.php here?
  172.   echo '<input type="hidden" maxlength="30" name="value1" id="title" value= "Testing"/>';
  173.   echo '<input type="hidden" maxlength="15" name="value2" id="sum" value= "Testing Summary-New"/>';
  174.    
  175. $PAGE->requires->yui_module('moodle-block_fruit-fruitbowl', 'M.block_fruit.fruitbowl.init',array("document.getElementById('txtValue').value",'Testing','Testing Summary','http://moodle.pgcps.org/file.php/1/images/mosiac-moodle.jpg'));
  176. $PAGE->requires->string_for_js('example', 'block_fruit');
  177.  
  178.     echo $OUTPUT->header();
  179.  
  180. /// Check to see if groups are being used in this forum
  181. /// If so, make sure the current person is allowed to see this discussion
  182. /// Also, if we know they should be able to reply, then explicitly set $canreply for performance reasons
  183.  
  184.     $canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
  185.     if (!$canreply and $forum->type !== 'news') {
  186.         if (isguestuser() or !isloggedin()) {
  187.             $canreply = true;
  188.         }
  189.         if (!is_enrolled($modcontext) and !is_viewing($modcontext)) {
  190.             // allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link
  191.             // normal users with temporary guest access see this link too, they are asked to enrol instead
  192.             $canreply = enrol_selfenrol_available($course->id);
  193.         }
  194.     }
  195.  
  196. /// Print the controls across the top
  197.     echo '<div class="discussioncontrols clearfix">';
  198.  
  199.     if (!empty($CFG->enableportfolios) && has_capability('mod/forum:exportdiscussion', $modcontext)) {
  200.         require_once($CFG->libdir.'/portfoliolib.php');
  201.         $button = new portfolio_add_button();
  202.         $button->set_callback_options('forum_portfolio_caller', array('discussionid' => $discussion->id), 'mod_forum');
  203.         $button = $button->to_html(PORTFOLIO_ADD_FULL_FORM, get_string('exportdiscussion', 'mod_forum'));
  204.         $buttonextraclass = '';
  205.         if (empty($button)) {
  206.             // no portfolio plugin available.
  207.             $button = '&nbsp;';
  208.             $buttonextraclass = ' noavailable';
  209.         }
  210.         echo html_writer::tag('div', $button, array('class' => 'discussioncontrol exporttoportfolio'.$buttonextraclass));
  211.     } else {
  212.         echo html_writer::tag('div', '&nbsp;', array('class'=>'discussioncontrol nullcontrol'));
  213.     }
  214.  
  215.     // groups selector not needed here
  216.     echo '<div class="discussioncontrol displaymode">';
  217.     forum_print_mode_form($discussion->id, $displaymode);
  218.     echo "</div>";
  219.  
  220.     if ($forum->type != 'single'
  221.                 && has_capability('mod/forum:movediscussions', $modcontext)) {
  222.  
  223.         echo '<div class="discussioncontrol movediscussion">';
  224.         // Popup menu to move discussions to other forums. The discussion in a
  225.         // single discussion forum can't be moved.
  226.         $modinfo = get_fast_modinfo($course);
  227.         if (isset($modinfo->instances['forum'])) {
  228.             $forummenu = array();
  229.             // Check forum types and eliminate simple discussions.
  230.             $forumcheck = $DB->get_records('forum', array('course' => $course->id),'', 'id, type');
  231.             foreach ($modinfo->instances['forum'] as $forumcm) {
  232.                 if (!$forumcm->uservisible || !has_capability('mod/forum:startdiscussion',
  233.                     context_module::instance($forumcm->id))) {
  234.                     continue;
  235.                 }
  236.                 $section = $forumcm->sectionnum;
  237.                 $sectionname = get_section_name($course, $section);
  238.                 if (empty($forummenu[$section])) {
  239.                     $forummenu[$section] = array($sectionname => array());
  240.                 }
  241.                 $forumidcompare = $forumcm->instance != $forum->id;
  242.                 $forumtypecheck = $forumcheck[$forumcm->instance]->type !== 'single';
  243.                 if ($forumidcompare and $forumtypecheck) {
  244.                     $url = "/mod/forum/discuss.php?d=$discussion->id&move=$forumcm->instance&sesskey=".sesskey();
  245.                     $forummenu[$section][$sectionname][$url] = format_string($forumcm->name);
  246.                 }
  247.             }
  248.             if (!empty($forummenu)) {
  249.                 echo '<div class="movediscussionoption">';
  250.                 $select = new url_select($forummenu, '',
  251.                         array(''=>get_string("movethisdiscussionto", "forum")),
  252.                         'forummenu', get_string('move'));
  253.                 echo $OUTPUT->render($select);
  254.                 echo "</div>";
  255.             }
  256.         }
  257.         echo "</div>";
  258.     }
  259.     echo '<div class="clearfloat">&nbsp;</div>';
  260.     echo "</div>";
  261.  
  262.     if (!empty($forum->blockafter) && !empty($forum->blockperiod)) {
  263.         $a = new stdClass();
  264.         $a->blockafter  = $forum->blockafter;
  265.         $a->blockperiod = get_string('secondstotime'.$forum->blockperiod);
  266.         echo $OUTPUT->notification(get_string('thisforumisthrottled','forum',$a));
  267.     }
  268.  
  269.     if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) &&
  270.                 !forum_user_has_posted($forum->id,$discussion->id,$USER->id)) {
  271.         echo $OUTPUT->notification(get_string('qandanotify','forum'));
  272.     }
  273.  
  274.     if ($move == -1 and confirm_sesskey()) {
  275.         echo $OUTPUT->notification(get_string('discussionmoved', 'forum', format_string($forum->name,true)));
  276.     }
  277.  
  278.     $canrate = has_capability('mod/forum:rate', $modcontext);
  279.     forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate);
  280.  
  281.     echo $OUTPUT->footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement