--- /dev/null
+<?php
+
+$string['content'] = 'Page content';
+$string['contentheader'] = 'Content';
+$string['displayoptions'] = 'Available display options';
+$string['configdisplayoptions'] = 'Select all options that should be available, existing settings are not modified. Hold CTRL key to select multiple fields.';
+$string['displayselect'] = 'Display';
+$string['displayselectexplain'] = 'Select display type.';
+$string['displaynew'] = 'New window';
+$string['displayopen'] = 'Open';
+$string['legacyfiles'] = 'Migration of old course file';
+$string['legacyfilesactive'] = 'Active';
+$string['legacyfilesdone'] = 'Finished';
+$string['modulename'] = 'Page';
+$string['modulenameplural'] = 'Pages';
+$string['popupheight'] = 'Popup height (in pixels)';
+$string['popupheightexplain'] = 'Specifies default height of popup windows.';
+$string['popupwidth'] = 'Popup width (in pixels)';
+$string['popupwidthexplain'] = 'Specifies default width of popup windows.';
+$string['optionsheader'] = 'Options';
+$string['printheading'] = 'Display page name';
+$string['printheadingexplain'] = 'Display page name above content?';
+$string['printintro'] = 'Display page description';
+$string['printintroexplain'] = 'Display page description above content?';
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Page module capability definition
+ *
+ * @package mod-page
+ * @copyright 2009 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$mod_page_capabilities = array(
+/* TODO: review public portfolio API first!
+ 'mod/page:portfolioexport' => array(
+
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'legacy' => array(
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ )
+ ),
+*/
+);
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Page module post install function
+ *
+ * This file replaces:
+ * - STATEMENTS section in db/install.xml
+ * - lib.php/modulename_install() post installation hook
+ * - partially defaults.php
+ *
+ * @package mod-page
+ * @copyright 2009 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+function xmldb_page_install() {
+ global $CFG;
+
+ // Install logging support
+ update_log_display_entry('page', 'view', 'page', 'name');
+ update_log_display_entry('page', 'view all', 'page', 'name');
+ update_log_display_entry('page', 'update', 'page', 'name');
+ update_log_display_entry('page', 'add', 'page', 'name');
+
+ // Upgrade from old resource module type if needed
+ require_once("$CFG->dirroot/mod/page/db/upgradelib.php");
+ page_20_migrate();
+
+}
+
+function xmldb_page_install_recovery() {
+ global $CFG;
+
+ // Upgrade from old resource module type if needed
+ require_once("$CFG->dirroot/mod/page/db/upgradelib.php");
+ page_20_migrate();
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<XMLDB PATH="mod/page/db" VERSION="20090722" COMMENT="XMLDB file for Page module"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
+>
+ <TABLES>
+ <TABLE NAME="page" COMMENT="Each record is one page and its config data">
+ <FIELDS>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="course"/>
+ <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="name"/>
+ <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="course" NEXT="intro"/>
+ <FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="introformat"/>
+ <FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="intro" NEXT="content"/>
+ <FIELD NAME="content" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" PREVIOUS="introformat" NEXT="contentformat"/>
+ <FIELD NAME="contentformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="content" NEXT="legacyfiles"/>
+ <FIELD NAME="legacyfiles" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="contentformat" NEXT="legacyfileslast"/>
+ <FIELD NAME="legacyfileslast" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="legacyfiles" NEXT="display"/>
+ <FIELD NAME="display" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="legacyfileslast" NEXT="displayoptions"/>
+ <FIELD NAME="displayoptions" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="display" NEXT="revision"/>
+ <FIELD NAME="revision" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="incremented when after each file changes, solves browser caching issues" PREVIOUS="displayoptions" NEXT="timemodified"/>
+ <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="revision"/>
+ </FIELDS>
+ <KEYS>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+ </KEYS>
+ <INDEXES>
+ <INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
+ </INDEXES>
+ </TABLE>
+ </TABLES>
+</XMLDB>
\ No newline at end of file
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Page module upgrade code
+ *
+ * This file keeps track of upgrades to
+ * the resource module
+ *
+ * Sometimes, changes between versions involve
+ * alterations to database structures and other
+ * major things that may break installations.
+ *
+ * The upgrade function in this file will attempt
+ * to perform all the necessary actions to upgrade
+ * your older installtion to the current version.
+ *
+ * If there's something it cannot do itself, it
+ * will tell you what you need to do.
+ *
+ * The commands in here will all be database-neutral,
+ * using the methods of database_manager class
+ *
+ * Please do not forget to use upgrade_set_timeout()
+ * before any action that may take longer time to finish.
+ *
+ * @package mod-page
+ * @copyright 2009 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+function xmldb_page_upgrade($oldversion) {
+ global $CFG, $DB;
+ require_once("$CFG->dirroot/mod/page/db/upgradelib.php");
+
+ $dbman = $DB->get_manager();
+ $result = true;
+
+
+ return $result;
+}
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Folder module upgrade related helper functions
+ *
+ * @package mod-page
+ * @copyright 2009 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * Migrate page module data from 1.9 resource_old table to new page table
+ * @return void
+ */
+function page_20_migrate() {
+ global $CFG, $DB;
+ require_once("$CFG->libdir/filelib.php");
+ require_once("$CFG->libdir/resourcelib.php");
+ require_once("$CFG->dirroot/course/lib.php");
+
+ if (!file_exists("$CFG->dirroot/mod/resource/db/upgradelib.php")) {
+ // bad luck, somebody deleted resource module
+ return;
+ }
+
+ require_once("$CFG->dirroot/mod/resource/db/upgradelib.php");
+
+ // create resource_old table and copy resource table there if needed
+ if (!resource_20_prepare_migration()) {
+ // no modules or fresh install
+ return;
+ }
+
+ $fs = get_file_storage();
+
+ if ($candidates = $DB->get_recordset('resource_old', array('type'=>'html', 'migrated'=>0))) {
+ foreach ($candidates as $candidate) {
+ page_20_migrate_candidate($candidate, $fs, FORMAT_HTML);
+ }
+ $candidates->close();
+ }
+
+ if ($candidates = $DB->get_recordset('resource_old', array('type'=>'text', 'migrated'=>0))) {
+ foreach ($candidates as $candidate) {
+ page_20_migrate_candidate($candidate, $fs, $candidate->reference);
+ }
+ $candidates->close();
+ }
+
+ // clear all course modinfo caches
+ rebuild_course_cache(0, true);
+
+}
+
+function page_20_migrate_candidate($candidate, $fs, $format) {
+ global $CFG, $DB;
+ upgrade_set_timeout();
+
+ $page = new object();
+ $page->course = $candidate->course;
+ $page->name = $candidate->name;
+ $page->intro = $candidate->intro;
+ $page->introformat = $candidate->introformat;
+ $page->content = $candidate->alltext;
+ $page->contentformat = $format;
+ $page->revision = 1;
+ $page->timemodified = time();
+
+ // convert links to old course files - let the automigration do the actual job
+ $usedfiles = array("$CFG->wwwroot/file.php/$page->course/", "$CFG->wwwroot/file.php?file=/$page->course/");
+ $page->content = str_ireplace($usedfiles, '@@PLUGINFILE@@/', $page->content);
+ if (strpos($page->content, '@@PLUGINFILE@@/') === false) {
+ $page->legacyfiles = RESOURCELIB_LEGACYFILES_NO;
+ } else {
+ $page->legacyfiles = RESOURCELIB_LEGACYFILES_ACTIVE;
+ }
+
+ $options = array('printheading'=>0, 'printintro'=>0);
+ if ($candidate->popup) {
+ $page->display = RESOURCELIB_DISPLAY_POPUP;
+ if ($candidate->popup) {
+ $rawoptions = explode(',', $candidate->popup);
+ foreach ($rawoptions as $rawoption) {
+ list($name, $value) = explode('=', trim($rawoption), 2);
+ if ($value > 0 and ($name == 'width' or $name == 'height')) {
+ $options['popup'.$name] = $value;
+ continue;
+ }
+ }
+ }
+ } else {
+ $page->display = RESOURCELIB_DISPLAY_OPEN;
+ }
+ $page->displayoptions = serialize($options);
+
+ $page = resource_migrate_to_module('page', $candidate, $page);
+
+ // now try to migrate files from site files
+ // noite: this can not work for html pages or files with other relatively linked files :-(
+ $siteid = get_site()->id;
+ if (preg_match_all("|$CFG->wwwroot/file.php(\?file=)?/$siteid(/[^\s'\"&\?#]+)|", $page->content, $matches)) {
+ $context = get_context_instance(CONTEXT_MODULE, $candidate->cmid);
+ $sitecontext = get_context_instance(CONTEXT_COURSE, $siteid);
+ $file_record = array('contextid'=>$context->id, 'filearea'=>'page_content', 'itemid'=>0);
+ $fs = get_file_storage();
+ foreach ($matches[2] as $i=>$sitefile) {
+ if (!$file = $fs->get_file_by_hash(sha1($sitecontext->id.'course_content0'.$sitefile))) {
+ continue;
+ }
+ try {
+ $fs->create_file_from_storedfile($file_record, $file);
+ $page->content = str_replace($matches[0][$i], '@@PLUGINFILE@@'.$sitefile, $page->content);
+ } catch (Exception $x) {
+ }
+ }
+ $DB->update_record('page', $page);
+ }
+}
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * List of all pages in course
+ *
+ * @package mod-page
+ * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require('../../config.php');
+
+$id = required_param('id', PARAM_INT); // course id
+
+$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
+
+require_course_login($course, true);
+
+add_to_log($course->id, 'page', 'view all', "index.php?id=$course->id", '');
+
+$strpage = get_string('modulename', 'page');
+$strpages = get_string('modulenameplural', 'page');
+$strweek = get_string('week');
+$strtopic = get_string('topic');
+$strname = get_string('name');
+$strintro = get_string('moduleintro');
+$strlastmodified = get_string('lastmodified');
+
+$PAGE->set_url('mod/page/index.php', array('id' => $course->id));
+$PAGE->set_title($course->shortname.': '.$strpages);
+$PAGE->set_heading($course->fullname);
+$navlinks = array(array('name' => $strpages, 'link' => '', 'type' => 'activityinstance'));
+echo $OUTPUT->header(build_navigation($navlinks), navmenu($course));
+
+if (!$pages = get_all_instances_in_course('page', $course)) {
+ notice(get_string('thereareno', 'moodle', $strpages), "$CFG->wwwroot/course/view.php?id=$course->id");
+ exit;
+}
+
+$table = new html_table();
+$table->set_classes(array('generaltable', 'mod_index'));
+
+if ($course->format == 'weeks') {
+ $table->head = array ($strweek, $strname, $strintro);
+ $table->align = array ('center', 'left', 'left');
+} else if ($course->format == 'topics') {
+ $table->head = array ($strtopic, $strname, $strintro);
+ $table->align = array ('center', 'left', 'left');
+} else {
+ $table->head = array ($strlastmodified, $strname, $strintro);
+ $table->align = array ('left', 'left', 'left');
+}
+
+$modinfo = get_fast_modinfo($course);
+$currentsection = '';
+foreach ($pages as $page) {
+ $cm = $modinfo->cms[$page->coursemodule];
+ if ($course->format == 'weeks' or $course->format == 'topics') {
+ $printsection = '';
+ if ($page->section !== $currentsection) {
+ if ($page->section) {
+ $printsection = $page->section;
+ }
+ if ($currentsection !== '') {
+ $table->data[] = 'hr';
+ }
+ $currentsection = $page->section;
+ }
+ } else {
+ $printsection = '<span class="smallinfo">'.userdate($page->timemodified)."</span>";
+ }
+
+ $class = $page->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
+
+ $table->data[] = array (
+ $printsection,
+ "<a $class href=\"view.php?id=$cm->id\">".format_string($page->name)."</a>",
+ format_module_intro('page', $page, $cm->id));
+}
+
+echo $OUTPUT->table($table);
+
+echo $OUTPUT->footer();
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package mod-page
+ * @copyright 2009 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * List of features supported in Page module
+ * @param string $feature FEATURE_xx constant for requested feature
+ * @return mixed True if module supports feature, false if not, null if doesn't know
+ */
+function page_supports($feature) {
+ switch($feature) {
+ case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE;
+ case FEATURE_GROUPS: return false;
+ case FEATURE_GROUPINGS: return false;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MOD_INTRO: return true;
+ case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
+ case FEATURE_GRADE_HAS_GRADE: return false;
+ case FEATURE_GRADE_OUTCOMES: return false;
+
+ default: return null;
+ }
+}
+
+/**
+ * Returns all other caps used in module
+ * @return array
+ */
+function page_get_extra_capabilities() {
+ return array('moodle/site:accessallgroups');
+}
+
+/**
+ * This function is used by the reset_course_userdata function in moodlelib.
+ * @param $data the data submitted from the reset course.
+ * @return array status array
+ */
+function page_reset_userdata($data) {
+ return array();
+}
+
+/**
+ * List of view style log actions
+ * @return array
+ */
+function page_get_view_actions() {
+ return array('view','view all');
+}
+
+/**
+ * List of update style log actions
+ * @return array
+ */
+function page_get_post_actions() {
+ return array('update', 'add');
+}
+
+/**
+ * Add page instance.
+ * @param object $data
+ * @param object $mform
+ * @return int new resoruce instance id
+ */
+function page_add_instance($data, $mform) {
+ global $CFG, $DB;
+ require_once("$CFG->libdir/resourcelib.php");
+
+ $cmid = $data->coursemodule;
+ $draftitemid = $data->page['itemid'];
+
+ $data->timemodified = time();
+ $displayoptions = array();
+ if ($data->display == RESOURCELIB_DISPLAY_POPUP) {
+ $displayoptions['popupwidth'] = $data->popupwidth;
+ $displayoptions['popupheight'] = $data->popupheight;
+ }
+ $displayoptions['printheading'] = $data->printheading;
+ $displayoptions['printintro'] = $data->printintro;
+ $data->displayoptions = serialize($displayoptions);
+
+ $data->content = $data->page['text'];
+ $data->contentformat = $data->page['format'];
+
+ $data->id = $DB->insert_record('page', $data);
+
+ // we need to use context now, so we need to make sure all needed info is already in db
+ $DB->set_field('course_modules', 'instance', $data->id, array('id'=>$cmid));
+ $context = get_context_instance(CONTEXT_MODULE, $cmid);
+
+ if ($draftitemid) {
+ $data->content = file_save_draft_area_files($draftitemid, $context->id, 'page_content', 0, page_get_editor_options($context), $data->content);
+ $DB->update_record('page', $data);
+ }
+
+ return $data->id;
+}
+
+/**
+ * Update page instance.
+ * @param object $data
+ * @param object $mform
+ * @return bool true
+ */
+function page_update_instance($data, $mform) {
+ global $CFG, $DB;
+ require_once("$CFG->libdir/resourcelib.php");
+
+ $cmid = $data->coursemodule;
+ $draftitemid = $data->page['itemid'];
+
+ $data->timemodified = time();
+ $data->id = $data->instance;
+ $data->revision++;
+
+ $displayoptions = array();
+ if ($data->display == RESOURCELIB_DISPLAY_POPUP) {
+ $displayoptions['popupwidth'] = $data->popupwidth;
+ $displayoptions['popupheight'] = $data->popupheight;
+ }
+ $displayoptions['printheading'] = $data->printheading;
+ $displayoptions['printintro'] = $data->printintro;
+ $data->displayoptions = serialize($displayoptions);
+
+ $data->content = $data->page['text'];
+ $data->contentformat = $data->page['format'];
+
+ $DB->update_record('page', $data);
+
+ $context = get_context_instance(CONTEXT_MODULE, $cmid);
+ if ($draftitemid) {
+ $data->content = file_save_draft_area_files($draftitemid, $context->id, 'page_content', 0, page_get_editor_options($context), $data->content);
+ $DB->update_record('page', $data);
+ }
+
+ return true;
+}
+
+/**
+ * Delete page instance.
+ * @param int $id
+ * @return bool true
+ */
+function page_delete_instance($id) {
+ global $DB;
+
+ if (!$page = $DB->get_record('page', array('id'=>$id))) {
+ return false;
+ }
+
+ // note: all context files are deleted automatically
+
+ $DB->delete_records('page', array('id'=>$page->id));
+
+ return true;
+}
+
+/**
+ * Return use outline
+ * @param object $course
+ * @param object $user
+ * @param object $mod
+ * @param object $page
+ * @return object|null
+ */
+function page_user_outline($course, $user, $mod, $page) {
+ global $DB;
+
+ if ($logs = $DB->get_records('log', array('userid'=>$user->id, 'module'=>'page',
+ 'action'=>'view', 'info'=>$page->id), 'time ASC')) {
+
+ $numviews = count($logs);
+ $lastlog = array_pop($logs);
+
+ $result = new object();
+ $result->info = get_string('numviews', '', $numviews);
+ $result->time = $lastlog->time;
+
+ return $result;
+ }
+ return NULL;
+}
+
+/**
+ * Return use complete
+ * @param object $course
+ * @param object $user
+ * @param object $mod
+ * @param object $page
+ */
+function page_user_complete($course, $user, $mod, $page) {
+ global $CFG, $DB;
+
+ if ($logs = $DB->get_records('log', array('userid'=>$user->id, 'module'=>'page',
+ 'action'=>'view', 'info'=>$page->id), 'time ASC')) {
+ $numviews = count($logs);
+ $lastlog = array_pop($logs);
+
+ $strmostrecently = get_string('mostrecently');
+ $strnumviews = get_string('numviews', '', $numviews);
+
+ echo "$strnumviews - $strmostrecently ".userdate($lastlog->time);
+
+ } else {
+ print_string('neverseen', 'page');
+ }
+}
+
+/**
+ * Returns the users with data in one page
+ *
+ * @param int $pageid
+ * @return bool false
+ */
+function page_get_participants($pageid) {
+ return false;
+}
+
+/**
+ * Given a course_module object, this function returns any
+ * "extra" information that may be needed when printing
+ * this activity in a course listing.
+ *
+ * See {@link get_array_of_activities()} in course/lib.php
+ *
+ * @param object $coursemodule
+ * @return object info
+ */
+function page_get_coursemodule_info($coursemodule) {
+ global $CFG, $DB;
+ require_once("$CFG->libdir/resourcelib.php");
+
+ if (!$page = $DB->get_record('page', array('id'=>$coursemodule->instance), 'id, name, display, displayoptions')) {
+ return NULL;
+ }
+
+ if ($page->display != RESOURCELIB_DISPLAY_POPUP) {
+ return null;
+ }
+
+ $info = new object();
+ $info->name = $page->name;
+
+ $fullurl = "$CFG->wwwroot/mod/page/view.php?id=$coursemodule->id&inpopup=1";
+ $options = empty($page->displayoptions) ? array() : unserialize($page->displayoptions);
+ $width = empty($options['popupwidth']) ? 620 : $options['popupwidth'];
+ $height = empty($options['popupheight']) ? 450 : $options['popupheight'];
+ $wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
+ $info->extra = urlencode("onclick=\"window.open('$fullurl', '', '$wh'); return false;\"");
+
+ return $info;
+}
+
+
+/**
+ * Lists all browsable file areas
+ * @param object $course
+ * @param object $cm
+ * @param object $context
+ * @return array
+ */
+function page_get_file_areas($course, $cm, $context) {
+ $areas = array();
+ if (has_capability('moodle/course:managefiles', $context)) {
+ $areas['page_content'] = get_string('pagecontent', 'page');
+ }
+ return $areas;
+}
+
+/**
+ * File browsing support for page module ontent area.
+ * @param object $browser
+ * @param object $areas
+ * @param object $course
+ * @param object $cm
+ * @param object $context
+ * @param string $filearea
+ * @param int $itemid
+ * @param string $filepath
+ * @param string $filename
+ * @return object file_info instance or null if not found
+ */
+function page_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
+ global $CFG;
+
+ $canwrite = has_capability('moodle/course:managefiles', $context);
+
+ $fs = get_file_storage();
+
+ if ($filearea === 'page_content') {
+ $filepath = is_null($filepath) ? '/' : $filepath;
+ $filename = is_null($filename) ? '.' : $filename;
+
+ $urlbase = $CFG->wwwroot.'/pluginfile.php';
+ if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) {
+ if ($filepath === '/' and $filename === '.') {
+ $storedfile = new virtual_root_file($context->id, $filearea, 0);
+ } else {
+ // not found
+ return null;
+ }
+ }
+ require_once("$CFG->dirroot/mod/page/locallib.php");
+ return new page_content_file_info($browser, $context, $storedfile, $urlbase, $areas[$filearea], true, true, $canwrite, false);
+ }
+
+ // note: page_intro handled in file_browser automatically
+
+ return null;
+}
+
+/**
+ * Serves the page files.
+ * @param object $course
+ * @param object $cminfo
+ * @param object $context
+ * @param string $filearea
+ * @param array $args
+ * @param bool $forcedownload
+ * @return bool false if file not found, does not return if found - justsend the file
+ */
+function page_pluginfile($course, $cminfo, $context, $filearea, $args, $forcedownload) {
+ global $CFG, $DB;
+ require_once("$CFG->libdir/resourcelib.php");
+
+ if (!$cminfo->uservisible) {
+ return false;
+ }
+
+ if ($filearea !== 'page_content') {
+ // intro is handled automatically in pluginfile.php
+ return false;
+ }
+
+ if (!$cm = get_coursemodule_from_instance('page', $cminfo->instance, $course->id)) {
+ return false;
+ }
+
+ require_course_login($course, true, $cm);
+
+ array_shift($args); // ignore revision - designed to prevent caching problems only
+
+ $fs = get_file_storage();
+ $relativepath = '/'.implode('/', $args);
+ $fullpath = $context->id.$filearea.'0'.$relativepath;
+ if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
+ $page = $DB->get_record('page', array('id'=>$cminfo->instance), 'id, legacyfiles', MUST_EXIST);
+ if ($page->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) {
+ return false;
+ }
+ require_once("$CFG->dirroot/mod/resource/db/upgradelib.php");
+ if (!$file = resource_try_file_migration($relativepath, $cminfo->id, $cminfo->course, 'page_content', 0)) {
+ return false;
+ }
+ //file migrate - update flag
+ $page->legacyfileslast = time();
+ $DB->update_record('page', $page);
+ }
+
+ // finally send the file
+ send_stored_file($file, 86400, 0, $forcedownload);
+}
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Private page module utility functions
+ *
+ * @package mod-page
+ * @copyright 2009 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once("$CFG->libdir/filelib.php");
+require_once("$CFG->libdir/resourcelib.php");
+require_once("$CFG->dirroot/mod/page/lib.php");
+
+
+/**
+ * File browsing support class
+ */
+class page_content_file_info extends file_info_stored {
+ public function get_parent() {
+ if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') {
+ return $this->browser->get_file_info($this->context);
+ }
+ return parent::get_parent();
+ }
+ public function get_visible_name() {
+ if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') {
+ return $this->topvisiblename;
+ }
+ return parent::get_visible_name();
+ }
+}
+
+function page_get_editor_options($context) {
+ return array('subdirs'=>1, 'maxbytes'=>0, 'maxfiles'=>-1, 'changeformat'=>1, 'context'=>$context, 'noclean'=>1, 'trusttext'=>0);
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Page configuration form
+ *
+ * @package mod-page
+ * @copyright 2009 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once($CFG->dirroot.'/course/moodleform_mod.php');
+require_once($CFG->dirroot.'/mod/page/locallib.php');
+require_once($CFG->libdir.'/filelib.php');
+
+class mod_page_mod_form extends moodleform_mod {
+ function definition() {
+ global $CFG, $DB;
+ $mform =& $this->_form;
+
+ $config = get_config('page');
+
+ //-------------------------------------------------------
+ $mform->addElement('header', 'general', get_string('general', 'form'));
+ $mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
+ if (!empty($CFG->formatstringstriptags)) {
+ $mform->setType('name', PARAM_TEXT);
+ } else {
+ $mform->setType('name', PARAM_CLEAN);
+ }
+ $mform->addRule('name', null, 'required', null, 'client');
+ $this->add_intro_editor($config->requiremodintro);
+
+ //-------------------------------------------------------
+ $mform->addElement('header', 'contentsection', get_string('contentheader', 'page'));
+ $mform->addElement('editor', 'page', get_string('content', 'page'), null, page_get_editor_options($this->context));
+ $mform->addElement('static', 'note', '', '<i>(TODO: The format switching is not implemented yet, sorry...)</i>');
+
+ //-------------------------------------------------------
+ $mform->addElement('header', 'optionssection', get_string('optionsheader', 'page'));
+
+ if ($this->current->instance) {
+ $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions), $this->current->display);
+ } else {
+ $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions));
+ }
+ if (count($options) == 1) {
+ $mform->addElement('hidden', 'display');
+ reset($options);
+ $mform->setDefault('display', key($options));
+ } else {
+ $mform->addElement('select', 'display', get_string('displayselect', 'page'), $options);
+ $mform->setDefault('display', $config->display);
+ $mform->setAdvanced('display', $config->display_adv);
+ }
+
+ if (array_key_exists(RESOURCELIB_DISPLAY_POPUP, $options)) {
+ $mform->addElement('text', 'popupwidth', get_string('popupwidth', 'page'), array('size'=>3));
+ if (count($options) > 1) {
+ $mform->disabledIf('popupwidth', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
+ }
+ $mform->setType('popupwidth', PARAM_INT);
+ $mform->setDefault('popupwidth', $config->popupwidth);
+ $mform->setAdvanced('popupwidth', $config->popupwidth_adv);
+
+ $mform->addElement('text', 'popupheight', get_string('popupheight', 'page'), array('size'=>3));
+ if (count($options) > 1) {
+ $mform->disabledIf('popupheight', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
+ }
+ $mform->setType('popupheight', PARAM_INT);
+ $mform->setDefault('popupheight', $config->popupheight);
+ $mform->setAdvanced('popupheight', $config->popupheight_adv);
+ }
+
+ $mform->addElement('advcheckbox', 'printheading', get_string('printheading', 'page'));
+ $mform->setDefault('printheading', $config->printheading);
+ $mform->setAdvanced('printintro', $config->printheading_adv);
+ $mform->addElement('advcheckbox', 'printintro', get_string('printintro', 'page'));
+ $mform->setDefault('printintro', $config->printintro);
+ $mform->setAdvanced('printintro', $config->printintro_adv);
+
+ // add legacy files flag only if used
+ if (isset($this->current->legacyfiles) and $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) {
+ $options = array(RESOURCE_LEGACYYFILES_DONE => get_string('legacyfilesdone', 'page'),
+ RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'page'));
+ $mform->addElement('select', 'legacyfiles', get_string('legacyfiles', 'page'), $options);
+ $mform->setAdvanced('legacyfiles', 1);
+ }
+
+ //-------------------------------------------------------
+ $this->standard_coursemodule_elements();
+
+ //-------------------------------------------------------
+ $this->add_action_buttons();
+
+ //-------------------------------------------------------
+ $mform->addElement('hidden', 'revision');
+ $mform->setType('revision', PARAM_INT);
+ $mform->setDefault('revision', 1);
+ }
+
+ function data_preprocessing(&$default_values) {
+ if ($this->current->instance) {
+ $draftitemid = file_get_submitted_draft_itemid('page');
+ $default_values['page']['format'] = $default_values['contentformat'];
+ $default_values['page']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'page_content', 0, page_get_editor_options($this->context), $default_values['content']);
+ $default_values['page']['itemid'] = $draftitemid;
+ }
+ if (!empty($default_values['displayoptions'])) {
+ $displayoptions = unserialize($default_values['displayoptions']);
+ if (isset($displayoptions['printintro'])) {
+ $default_values['printintro'] = $displayoptions['printintro'];
+ }
+ if (isset($displayoptions['printheading'])) {
+ $default_values['printheading'] = $displayoptions['printheading'];
+ }
+ if (!empty($displayoptions['popupwidth'])) {
+ $default_values['popupwidth'] = $displayoptions['popupwidth'];
+ }
+ if (!empty($displayoptions['popupheight'])) {
+ $default_values['popupheight'] = $displayoptions['popupheight'];
+ }
+ }
+ }
+}
+
--- /dev/null
+This file is part of Moodle - http://moodle.org/
+
+Moodle is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Moodle is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+copyright 2009 Petr Skoda (http://skodak.org)
+license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+
+
+Page module
+=============
+
+Page module is a successor to original 'html' and 'text' type plugins of Resource module.
+
+
+TODO:
+ * reimplement portfolio support (?)
+ * implement format switching in formslib editor element (skodak)
+ * new backup/restore (Eloy)
+ * old restore support (Eloy)
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Page module admin settings and defaults
+ *
+ * @package mod-page
+ * @copyright 2009 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+if ($ADMIN->fulltree) {
+ require_once("$CFG->libdir/resourcelib.php");
+
+ $displayoptions = resourcelib_get_displayoptions(array(RESOURCELIB_DISPLAY_OPEN, RESOURCELIB_DISPLAY_POPUP));
+ $defaultdisplayoptions = array(RESOURCELIB_DISPLAY_OPEN);
+
+ //--- general settings -----------------------------------------------------------------------------------
+ $settings->add(new admin_setting_configcheckbox('page/requiremodintro',
+ get_string('requiremodintro', 'admin'), get_string('configrequiremodintro', 'admin'), 1));
+ $settings->add(new admin_setting_configmultiselect('page/displayoptions',
+ get_string('displayoptions', 'page'), get_string('configdisplayoptions', 'page'),
+ $defaultdisplayoptions, $displayoptions));
+
+ //--- modedit defaults -----------------------------------------------------------------------------------
+ $settings->add(new admin_setting_heading('pagemodeditdefaults', get_string('modeditdefaults', 'admin'), get_string('condifmodeditdefaults', 'admin')));
+
+ $settings->add(new admin_setting_configcheckbox_with_advanced('page/printheading',
+ get_string('printheading', 'page'), get_string('printheadingexplain', 'page'),
+ array('value'=>1, 'adv'=>false)));
+ $settings->add(new admin_setting_configcheckbox_with_advanced('page/printintro',
+ get_string('printintro', 'page'), get_string('printintroexplain', 'page'),
+ array('value'=>0, 'adv'=>false)));
+ $settings->add(new admin_setting_configselect_with_advanced('page/display',
+ get_string('displayselect', 'page'), get_string('displayselectexplain', 'page'),
+ array('value'=>RESOURCELIB_DISPLAY_OPEN, 'adv'=>true), $displayoptions));
+ $settings->add(new admin_setting_configtext_with_advanced('page/popupwidth',
+ get_string('popupwidth', 'page'), get_string('popupwidthexplain', 'page'),
+ array('value'=>620, 'adv'=>true), PARAM_INT, 7));
+ $settings->add(new admin_setting_configtext_with_advanced('page/popupheight',
+ get_string('popupheight', 'page'), get_string('popupheightexplain', 'page'),
+ array('value'=>450, 'adv'=>true), PARAM_INT, 7));
+}
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Page module version information
+ *
+ * @package mod-page
+ * @copyright 2009 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$module->version = 2009080500;
+$module->requires = 2009073101; // Requires this Moodle version
+$module->cron = 0;
+
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Page module version information
+ *
+ * @package mod-page
+ * @copyright 2009 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require('../../config.php');
+require_once($CFG->dirroot.'/mod/page/locallib.php');
+
+$id = optional_param('id', 0, PARAM_INT); // Course Module ID
+$p = optional_param('p', 0, PARAM_INT); // Page instance ID
+$inpopup = optional_param('inpopup', 0, PARAM_BOOL);
+
+if ($p) {
+ if (!$page = $DB->get_record('page', array('id'=>$p))) {
+ page_redirect_if_migrated($r, 0);
+ print_error('invalidaccessparameter');
+ }
+ $cm = get_coursemodule_from_instance('page', $page->id, $page->course, false, MUST_EXIST);
+
+} else {
+ if (!$cm = get_coursemodule_from_id('page', $id)) {
+ page_redirect_if_migrated(0, $id);
+ print_error('invalidcoursemodule');
+ }
+ $page = $DB->get_record('page', array('id'=>$cm->instance), '*', MUST_EXIST);
+}
+
+$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
+
+require_course_login($course, true, $cm);
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+add_to_log($course->id, 'page', 'view', 'view.php?id='.$cm->id, $page->id, $cm->id);
+
+$PAGE->set_url('mod/page/view.php', array('id' => $cm->id));
+
+$options = empty($page->displayoptions) ? array() : unserialize($page->displayoptions);
+
+if ($inpopup and $page->display == RESOURCELIB_DISPLAY_POPUP) {
+ $PAGE->set_generaltype('popup');
+ $PAGE->set_title($course->shortname.': '.$page->name);
+ if (!empty($options['printheading'])) {
+ $PAGE->set_heading($page->name);
+ } else {
+ $PAGE->set_heading('');
+ }
+ echo $OUTPUT->header();
+
+} else {
+ $PAGE->set_title($course->shortname.': '.$page->name);
+ $PAGE->set_heading($course->fullname);
+ $PAGE->set_activity_record($page);
+ $PAGE->set_button(update_module_button($cm->id, '', get_string('modulename', 'page')));
+ echo $OUTPUT->header(build_navigation('', $cm), navmenu($course, $cm));
+
+ if (!empty($options['printheading'])) {
+ echo $OUTPUT->heading(format_string($page->name), 2, 'main', 'pageheading');
+ }
+}
+
+if (!empty($options['printintro'])) {
+ if (trim(strip_tags($page->intro))) {
+ echo $OUTPUT->box_start('mod_introbox', 'pageintro');
+ echo format_module_intro('page', $page, $cm->id);
+ echo $OUTPUT->box_end();
+ }
+}
+
+$content = file_rewrite_pluginfile_urls($page->content, 'pluginfile.php', $context->id, 'page_content', $page->revision);
+$formatoptions = (object)array('noclean'=>true);
+$content = format_text($content, $page->contentformat, $formatoptions, $course->id);
+echo $OUTPUT->box($content, "generalbox center clearfix");
+
+$strlastmodified = get_string("lastmodified");
+echo "<div class=\"modified\">$strlastmodified: ".userdate($page->timemodified)."</div>";
+
+echo $OUTPUT->footer();