***NOTE NOTE NOTE **********************************************************

THIS IS A BIG CHANGE!

I've renamed the "reading" module to "resource".

This meant changing quite a few references throughout Moodle.

The automatic upgrade process should work OK (it worked OK on my
development server) and there shouldn't be any problems.

BUT PLEASE PROCEED WITH CAUTION AND KEEP BACKUPS OF EVERYTHING
UNTIL I HAVE A FEW MORE TESTS!   If you upgrade please let me know.

One thing that will break are any hard-coded links within forum messages.

What I will be doing to fix this on my apache server is to add this to
httpd.conf:

Redirect /mod/reading/ http://moodle.com/mod/resource/

Sorry about any inconvenience, but it's better this is done sooner than later.
This commit is contained in:
moodler 2002-10-17 14:03:59 +00:00
parent e1ac42728d
commit 2a439ba7f6
21 changed files with 680 additions and 26 deletions

12
mod/resource/db/mysql.php Normal file
View file

@ -0,0 +1,12 @@
<?PHP // $Id$
function resource_upgrade($oldversion) {
// This function does anything necessary to upgrade
// older versions to match current functionality
return true;
}
?>

35
mod/resource/db/mysql.sql Executable file
View file

@ -0,0 +1,35 @@
# phpMyAdmin MySQL-Dump
# version 2.2.1
# http://phpwizard.net/phpMyAdmin/
# http://phpmyadmin.sourceforge.net/ (download page)
#
# Host: localhost
# Generation Time: Nov 14, 2001 at 04:43 PM
# Server version: 3.23.36
# PHP Version: 4.0.6
# Database : `moodle`
# --------------------------------------------------------
#
# Table structure for table `resource`
#
CREATE TABLE resource (
id int(10) unsigned NOT NULL auto_increment,
course tinyint(10) unsigned NOT NULL default '0',
name varchar(255) NOT NULL default '',
type tinyint(4) NOT NULL default '0',
reference varchar(255) default NULL,
summary text NOT NULL,
alltext text NOT NULL,
timemodified int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY id (id)
) TYPE=MyISAM;
#
# Dumping data for table `log_display`
#
INSERT INTO log_display VALUES ('resource', 'view', 'resource', 'name');

194
mod/resource/details.php Normal file
View file

@ -0,0 +1,194 @@
<?PHP // $Id$
require("../../config.php");
require("lib.php");
require_login();
$usehtmleditor = can_use_richtext_editor();
if (match_referer("$destination") && isset($HTTP_POST_VARS)) { // form submitted
$form = (object)$HTTP_POST_VARS;
if (! $course = get_record("course", "id", $form->course)) {
error("This course doesn't exist");
}
require_login($course->id);
if (!isteacher($course->id)) {
error("You can't modify this course!");
}
$strediting = get_string("editingaresource", "resource");
$strname = get_string("name");
print_header("$course->shortname: $strediting", "$course->shortname: $strediting",
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> $strediting");
if (!$form->name or !$form->type or !$form->summary) {
error(get_string("filloutallfields"), $HTTP_REFERER);
}
print_simple_box_start("center", "", "$THEME->cellheading");
if ($usehtmleditor and $form->type == HTML) {
$onsubmit = "onsubmit=\"copyrichtext(theform.alltext);\"";
}
echo "<FORM NAME=theform METHOD=post $onsubmit ACTION=\"$form->destination\">";
echo "<TABLE CELLPADDING=5 ALIGN=CENTER>";
echo "<TR><TD ALIGN=right NOWRAP><P><B>$strname:</B></P></TD><TD><P>$form->name</P></A></TD></TR>";
$strtypename = $RESOURCE_TYPE["$form->type"];
$strexample = get_string("example", "resource");
switch ($form->type) {
case REFERENCE:
$strexamplereference = get_string("examplereference", "resource");
?>
<TR VALIGN=top>
<TD ALIGN=right NOWRAP>
<P><B><?=$strtypename?>:</B></P>
</TD>
<TD>
<TEXTAREA NAME="reference" ROWS=3 COLS=50 WRAP="virtual"><? p($form->reference) ?></TEXTAREA>
</TD>
</TR>
<TR VALIGN=top>
<TD ALIGN=right NOWRAP>
<P><B>(<?=$strexample?>)</B></P>
</TD>
<TD>
<P><?=$strexamplereference?></P>
</TD>
</TR>
<?
break;
case WEBPAGE:
case WEBLINK:
$strexampleurl = get_string("exampleurl", "resource");
?>
<TR VALIGN=top>
<TD ALIGN=right NOWRAP>
<P><B><?=$strtypename?>:</B></P>
</TD>
<TD>
<INPUT NAME="reference" SIZE=60 VALUE="<? p($form->reference) ?>">
</TD>
</TR>
<TR VALIGN=top>
<TD ALIGN=right NOWRAP>
<P><B>(<?=$strexample?>)</B></P>
</TD>
<TD>
<P><?=$strexampleurl?>
</P>
</TD>
</TR>
<?
break;
case UPLOADEDFILE:
$strfilename = get_string("filename", "resource");
$strnote = get_string("note", "resource");
$strnotefile = get_string("notefile", "resource", "$CFG->wwwroot/files/index.php?id=$course->id");
?>
<TR VALIGN=top>
<TD ALIGN=right NOWRAP>
<P><B><?=$strfilename?>:</B></P>
</TD>
<TD>
<?
$rootdir = $CFG->dataroot."/".$course->id;
$coursedirs = get_directory_list($rootdir, $CFG->moddata);
foreach ($coursedirs as $dir) {
$options["$dir"] = $dir;
}
choose_from_menu ($options, "reference", $form->reference);
?>
</TD>
</TR>
<TR VALIGN=top>
<TD ALIGN=right NOWRAP>
<P><B><?=$strnote?>:</B></P>
</TD>
<TD>
<P><?=$strnotefile?>
</P>
</TD>
</TR>
<?
break;
case PLAINTEXT:
$strfulltext = get_string("fulltext", "resource");
?>
<TR VALIGN=top>
<TD ALIGN=right NOWRAP>
<P><B><?=$strfulltext?>:</B></P>
<BR><? helpbutton("text", get_string("helptext")) ?>
</TD>
<TD>
<TEXTAREA NAME="alltext" ROWS=20 COLS=50 WRAP="virtual"><? p($form->alltext) ?></TEXTAREA>
</TD>
</TR>
<?
break;
case HTML:
$strhtmlfragment = get_string("htmlfragment", "resource");
?>
<TR VALIGN=top>
<TD ALIGN=right NOWRAP>
<P><B><?=$strhtmlfragment?>:</B></P>
<? if ($usehtmleditor) { ?>
<BR><? helpbutton("richtext", get_string("helprichtext")) ?>
<? } else { ?>
<BR><? helpbutton("html", get_string("helphtml")) ?>
<? } ?>
</TD>
<TD>
<? print_textarea($usehtmleditor, 20, 50, 680, 400, "alltext", $form->alltext); ?>
</TD>
</TR>
<?
break;
default:
error(get_string("notypechosen", "resource"), $HTTP_REFERER);
break;
}
?>
</TABLE>
<input type="hidden" name=summary value="<? p($form->summary) ?>">
<input type="hidden" name=type value="<? p($form->type) ?>">
<input type="hidden" name=name value="<? p($form->name) ?>">
<input type="hidden" name=course value="<? p($form->course) ?>">
<input type="hidden" name=coursemodule value="<? p($form->coursemodule) ?>">
<input type="hidden" name=section value="<? p($form->section) ?>">
<input type="hidden" name=module value="<? p($form->module) ?>">
<input type="hidden" name=modulename value="<? p($form->modulename) ?>">
<input type="hidden" name=instance value="<? p($form->instance) ?>">
<input type="hidden" name=mode value="<? p($form->mode) ?>">
<CENTER>
<input type="submit" value="<? print_string("savechanges") ?>">
<input type="submit" name=cancel value="<? print_string("cancel") ?>">
</CENTER>
</FORM>
<?
if ($usehtmleditor) {
print_richedit_javascript("theform", "alltext", "yes");
}
print_simple_box_end();
print_footer($course);
} else {
error("This script was called incorrectly");
}
?>

BIN
mod/resource/icon.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

72
mod/resource/index.php Normal file
View file

@ -0,0 +1,72 @@
<?PHP // $Id$
require("../../config.php");
require_variable($id); // course
if (! $course = get_record("course", "id", $id)) {
error("Course ID is incorrect");
}
if ($course->category) {
require_login($course->id);
$navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
}
add_to_log($course->id, "resource", "view all", "index.php?id=$course->id", "");
$strresource = get_string("modulename", "resource");
$strresources = get_string("modulenameplural", "resource");
$strweek = get_string("week");
$strtopic = get_string("topic");
$strname = get_string("name");
$strsummary = get_string("summary");
$strlastmodified = get_string("lastmodified");
print_header("$course->shortname: $strresources", "$course->fullname", "$navigation $strresources");
if ($course->format == "weeks" or $course->format == "topics") {
$sortorder = "cw.section ASC";
} else {
$sortorder = "m.timemodified DESC";
}
if (! $resources = get_all_instances_in_course("resource", $course->id, $sortorder)) {
notice("There are no resources", "../../course/view.php?id=$course->id");
exit;
}
if ($course->format == "weeks") {
$table->head = array ($strweek, $strname, $strsummary);
$table->align = array ("CENTER", "LEFT", "LEFT");
} else if ($course->format == "topics") {
$table->head = array ($strtopic, $strname, $strsummary);
$table->align = array ("CENTER", "LEFT", "LEFT");
} else {
$table->head = array ($strlastmodified, $strname, $strsummary);
$table->align = array ("LEFT", "LEFT", "LEFT");
}
foreach ($resources as $resource) {
$tt = "";
if ($course->format == "weeks" or $course->format == "topics") {
if ($resource->section) {
$tt = "$resource->section";
}
} else {
$tt = "<FONT SIZE=1>".userdate($resource->timemodified);
}
$table->data[] = array ($tt, "<A HREF=\"view.php?id=$resource->coursemodule\">$resource->name</A>",
text_to_html($resource->summary) );
}
echo "<BR>";
print_table($table);
print_footer($course);
?>

135
mod/resource/lib.php Normal file
View file

@ -0,0 +1,135 @@
<?PHP // $Id$
define("REFERENCE", "1");
define("WEBPAGE", "2");
define("UPLOADEDFILE","3");
define("PLAINTEXT", "4");
define("WEBLINK", "5");
define("HTML", "6");
$RESOURCE_TYPE = array (REFERENCE => get_string("resourcetype1", "resource"),
WEBPAGE => get_string("resourcetype2", "resource"),
UPLOADEDFILE => get_string("resourcetype3", "resource"),
PLAINTEXT => get_string("resourcetype4", "resource"),
WEBLINK => get_string("resourcetype5", "resource"),
HTML => get_string("resourcetype6", "resource") );
function resource_list_all_resources($courseid=0, $sort="name ASC", $recent=0) {
// Returns list of all resource links in an array of strings
global $CFG, $USER;
if ($courseid) {
if (! $course = get_record("course", "id", $courseid)) {
error("Could not find the specified course");
}
require_login($course->id);
} else {
if (! $course = get_record("course", "category", 0)) {
error("Could not find a top-level course!");
}
}
if ($resources = get_all_instances_in_course("resource", $course->id, $sort)) {
foreach ($resources as $resource) {
$link = "<A HREF=\"$CFG->wwwroot/mod/resource/view.php?id=$resource->coursemodule\">$resource->name</A>";
if ($USER->editing) {
$link .= "&nbsp; &nbsp;
<A HREF=\"$CFG->wwwroot/course/mod.php?delete=$resource->coursemodule\"><IMG
SRC=\"$CFG->wwwroot/pix/t/delete.gif\" BORDER=0 ALT=Delete></A>
<A HREF=\"$CFG->wwwroot/course/mod.php?update=$resource->coursemodule\"><IMG
SRC=\"$CFG->wwwroot/pix/t/edit.gif\" BORDER=0 ALT=Update></A>";
}
$links[] = $link;
}
}
return $links;
}
function resource_user_outline($course, $user, $mod, $resource) {
if ($logs = get_records_sql("SELECT * FROM log
WHERE user='$user->id' AND module='resource'
AND action='view' AND info='$resource->id'
ORDER BY time ASC")) {
$numviews = count($logs);
$lastlog = array_pop($logs);
$result->info = get_string("numviews", "", $numviews);
$result->time = $lastlog->time;
return $result;
}
return NULL;
}
function resource_user_complete($course, $user, $mod, $resource) {
global $CFG, $THEME;
if ($logs = get_records_sql("SELECT * FROM log
WHERE user='$user->id' AND module='resource'
AND action='view' AND info='$resource->id'
ORDER BY 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("neverread", "resource");
}
}
function resource_add_instance($resource) {
// Given an object containing all the necessary data,
// (defined by the form in mod.html) this function
// will create a new instance and return the id number
// of the new instance.
$resource->timemodified = time();
return insert_record("resource", $resource);
}
function resource_update_instance($resource) {
// Given an object containing all the necessary data,
// (defined by the form in mod.html) this function
// will update an existing instance with new data.
$resource->id = $resource->instance;
$resource->timemodified = time();
return update_record("resource", $resource);
}
function resource_delete_instance($id) {
// Given an ID of an instance of this module,
// this function will permanently delete the instance
// and any data that depends on it.
if (! $resource = get_record("resource", "id", "$id")) {
return false;
}
$result = true;
if (! delete_records("resource", "id", "$resource->id")) {
$result = false;
}
return $result;
}
?>

46
mod/resource/mod.html Normal file
View file

@ -0,0 +1,46 @@
<form name="form" method="post" action="<?=$CFG->wwwroot?>/mod/resource/details.php">
<table cellpadding=5>
<tr valign=top>
<td align=right><P><B><? print_string("name") ?>:</B></P></TD>
<td>
<input type="text" name="name" size=50 value="<? p($form->name) ?>">
</td>
</tr>
<tr valign=top>
<td align=right><P><B><? print_string("resourcetype", "resource") ?>:</B></P></TD>
<td>
<?
require("$CFG->dirroot/mod/resource/lib.php");
asort($RESOURCE_TYPE);
if (!$form->type) {
$form->type = 4;
}
choose_from_menu($RESOURCE_TYPE, "type", $form->type, "");
helpbutton("resourcetype", get_string("resourcetype", "resource"), "resource");
?>
</td>
</tr>
<tr valign=top>
<td align=right><P><B><? print_string("summary") ?>:</B></P></TD>
<td>
<textarea name="summary" rows=5 cols=50 wrap="virtual"><? p($form->summary) ?></textarea>
<? helpbutton("summary", get_string("summary"), "resource"); ?>
</td>
</tr>
</table>
<CENTER>
<input type="hidden" name=reference value="<? p($form->reference) ?>">
<input type="hidden" name=alltext value="<? p($form->alltext) ?>">
<input type="hidden" name=course value="<? p($form->course) ?>">
<input type="hidden" name=coursemodule value="<? p($form->coursemodule) ?>">
<input type="hidden" name=section value="<? p($form->section) ?>">
<input type="hidden" name=module value="<? p($form->module) ?>">
<input type="hidden" name=modulename value="<? p($form->modulename) ?>">
<input type="hidden" name=instance value="<? p($form->instance) ?>">
<input type="hidden" name=mode value="<? p($form->mode) ?>">
<input type="hidden" name=destination value="<?=$ME ?>">
<input type="submit" value="<? print_string("continue") ?>">
</CENTER>
</FORM>

11
mod/resource/version.php Normal file
View file

@ -0,0 +1,11 @@
<?PHP // $Id$
////////////////////////////////////////////////////////////////////////////////
// Code fragment to define the module version etc.
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2002101700;
$module->cron = 0;
?>

131
mod/resource/view.php Normal file
View file

@ -0,0 +1,131 @@
<?PHP // $Id$
require("../../config.php");
require("lib.php");
require_variable($id); // Course Module ID
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course is misconfigured");
}
if (! $resource = get_record("resource", "id", $cm->instance)) {
error("Resource ID was incorrect");
}
$strresource = get_string("modulename", "resource");
$strresources = get_string("modulenameplural", "resource");
$strlastmodified = get_string("lastmodified");
if ($course->category) {
require_login($course->id);
$navigation = "<A TARGET=_top HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->
<A TARGET=_top HREF=\"index.php?id=$course->id\">$strresources</A> ->";
} else {
$navigation = "<A TARGET=_top HREF=\"index.php?id=$course->id\">$strresources</A> ->";
}
switch ($resource->type) {
case 1: // Reference (eg Journal or Book etc)
add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
"", "", true, update_module_button($cm->id, $course->id, $strresource));
print_simple_box($resource->reference, "center");
echo "<CENTER><P>";
echo text_to_html($resource->summary);
echo "</P>";
echo "<P>&nbsp</P>";
echo "<P><FONT SIZE=1>$strlastmodified: ".userdate($resource->timemodified)."</P>";
echo "</CENTER>";
print_footer($course);
break;
case 5: // Web Link
add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
redirect($resource->reference);
break;
case 2: // Web Page
if ($frameset) {
print_header("$course->shortname: $resource->name", "$course->fullname",
"$navigation <A TARGET=_top HREF=\"$resource->reference\" TITLE=\"$resource->reference\">$resource->name</A>",
"", "", true, update_module_button($cm->id, $course->id, $strresource));
echo "<CENTER><FONT SIZE=-1>".text_to_html($resource->summary, true, false)."</FONT></CENTER>";
} else {
add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
echo "<HEAD><TITLE>$course->shortname: $resource->name</TITLE></HEAD>\n";
echo "<FRAMESET ROWS=130,*>";
echo "<FRAME SRC=\"view.php?id=$cm->id&frameset=true\">";
echo "<FRAME SRC=\"$resource->reference\">";
echo "</FRAMESET>";
}
break;
case 3: // Uploaded File
if ($frameset) {
print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
"", "", true, update_module_button($cm->id, $course->id, $strresource));
echo "<CENTER><FONT SIZE=-1>".text_to_html($resource->summary, true, false)."</FONT></CENTER>";
} else {
add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
if ($CFG->slasharguments) {
$ffurl = "file.php/$course->id/$resource->reference";
} else {
$ffurl = "file.php?file=/$course->id/$resource->reference";
}
echo "<HEAD><TITLE>$course->shortname: $resource->name</TITLE></HEAD>\n";
echo "<FRAMESET ROWS=130,*>";
echo "<FRAME SRC=\"view.php?id=$cm->id&frameset=true\">";
echo "<FRAME SRC=\"$CFG->wwwroot/$ffurl\">";
echo "</FRAMESET>";
}
break;
case 4: // Plain text
add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
"", "", true, update_module_button($cm->id, $course->id, $strresource));
print_simple_box(text_to_html($resource->alltext), "CENTER", "", "$THEME->cellcontent", "20");
echo "<CENTER><P><FONT SIZE=1>$strlastmodified: ".userdate($resource->timemodified)."</P></CENTER>";
print_footer($course);
break;
case 6: // HTML text
add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id");
print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
"", "", true, update_module_button($cm->id, $course->id, $strresource));
print_simple_box_start("CENTER", "", "$THEME->cellcontent", "20");
echo $resource->alltext;
print_simple_box_end();
echo "<CENTER><P><FONT SIZE=1>$strlastmodified: ".userdate($resource->timemodified)."</P></CENTER>";
print_footer($course);
break;
default:
print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name",
"", "", true, update_module_button($cm->id, $course->id, $strresource));
print_heading($resource->name);
print_simple_box("Error: unknown type of resource", "center");
print_footer($course);
break;
}
?>