New module: Label.

This is a sort of "dummy" activity that allows HTML to be placed
anywhere in the course sections ...
This commit is contained in:
moodler 2003-09-14 12:30:09 +00:00
parent c9f6251ea8
commit 2c5c3e62a7
10 changed files with 227 additions and 0 deletions

12
mod/label/db/mysql.php Normal file
View File

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

7
mod/label/db/mysql.sql Normal file
View File

@ -0,0 +1,7 @@
CREATE TABLE `prefix_label` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL default '',
`content` text NOT NULL,
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
) COMMENT='Defines labels';

View File

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

View File

@ -0,0 +1,6 @@
CREATE TABLE prefix_label (
id SERIAL PRIMARY KEY,
name varchar(255) default NULL,
content text,
timemodified integer NOT NULL default '0'
);

BIN
mod/label/icon.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

10
mod/label/index.php Normal file
View File

@ -0,0 +1,10 @@
<?PHP // $Id$
require_once("../../config.php");
require_once("lib.php");
require_variable($id); // course
redirect("$CFG->wwwroot/course/view.php?id=$id");
?>

75
mod/label/lib.php Normal file
View File

@ -0,0 +1,75 @@
<?PHP // $Id$
/// Library of functions and constants for module label
define("LABEL_MAX_NAME_LENGTH", 50);
function label_add_instance($label) {
/// 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.
$label->name = strip_tags($label->content);
if (strlen($label->name) > LABEL_MAX_NAME_LENGTH) {
$label->name = substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."...";
}
$label->timemodified = time();
return insert_record("label", $label);
}
function label_update_instance($label) {
/// 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.
$label->name = strip_tags($label->content);
if (strlen($label->name) > LABEL_MAX_NAME_LENGTH) {
$label->name = substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."...";
}
$label->timemodified = time();
$label->id = $label->instance;
return update_record("label", $label);
}
function label_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 (! $label = get_record("label", "id", "$id")) {
return false;
}
$result = true;
if (! delete_records("label", "id", "$label->id")) {
$result = false;
}
return $result;
}
function label_user_outline($course, $user, $mod, $label) {
/// Return a small object with summary information about what a
/// user has done with a given particular instance of this module
/// Used for user activity reports.
/// $return->time = the time they did it
/// $return->info = a short text description
return NULL;
}
function label_user_complete($course, $user, $mod, $label) {
/// Print a detailed representation of what a user has done with
/// a given particular instance of this module, for user activity reports.
return false;
}
?>

56
mod/label/mod.html Normal file
View File

@ -0,0 +1,56 @@
<!-- This page defines the form to create or edit an instance of this module -->
<!-- It is used from /course/mod.php. The whole instance is available as $form. -->
<?php
if ($usehtmleditor = can_use_richtext_editor()) {
$defaultformat = FORMAT_HTML;
$onsubmit = "onsubmit=\"copyrichtext(document.form.content);\"";
} else {
$defaultformat = FORMAT_MOODLE;
$onsubmit = "";
}
?>
<form name="form" method="post" <?php echo $onsubmit ?> action="mod.php">
<center>
<table cellpadding=5>
<tr valign=top>
<td align=right><p><b><?php print_string("labeltext", "label") ?>:</b></p>
<font size="1">
<?php
helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
echo "<br />";
if ($usehtmleditor) {
helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
} else {
emoticonhelpbutton("form", "description");
}
?>
<br />
</font>
</td>
<td>
<?php
print_textarea($usehtmleditor, 20, 60, 680, 400, "content", $form->content);
?>
</td>
</tr>
</table>
<!-- these hidden variables are always the same -->
<input type="hidden" name=course value="<?php p($form->course) ?>">
<input type="hidden" name=coursemodule value="<?php p($form->coursemodule) ?>">
<input type="hidden" name=section value="<?php p($form->section) ?>">
<input type="hidden" name=module value="<?php p($form->module) ?>">
<input type="hidden" name=modulename value="<?php p($form->modulename) ?>">
<input type="hidden" name=instance value="<?php p($form->instance) ?>">
<input type="hidden" name=mode value="<?php p($form->mode) ?>">
<input type="submit" value="<?php print_string("savechanges") ?>">
</center>
</form>
<?php
if ($usehtmleditor) {
print_richedit_javascript("form", "content", "yes");
}
?>

11
mod/label/version.php Normal file
View File

@ -0,0 +1,11 @@
<?PHP // $Id$
/////////////////////////////////////////////////////////////////////////////////
/// Code fragment to define the version of label
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
$module->version = 2003091300; // The current module version (Date: YYYYMMDDXX)
$module->cron = 0; // Period for cron to check this module (secs)
?>

38
mod/label/view.php Normal file
View File

@ -0,0 +1,38 @@
<?PHP // $Id$
require_once("../../config.php");
optional_variable($id); // Course Module ID, or
optional_variable($l); // Label ID
if ($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 (! $label = get_record("label", "id", $cm->instance)) {
error("Course module is incorrect");
}
} else {
if (! $label = get_record("label", "id", $l)) {
error("Course module is incorrect");
}
if (! $course = get_record("course", "id", $label->course)) {
error("Course is misconfigured");
}
if (! $cm = get_coursemodule_from_instance("label", $label->id, $course->id)) {
error("Course Module ID was incorrect");
}
}
require_login($course->id);
redirect("$CFG->wwwroot/course/view.php?id=$course->id");
?>