]> git.mjollnir.org Git - moodle.git/commitdiff
New module: Label.
authormoodler <moodler>
Sun, 14 Sep 2003 12:30:09 +0000 (12:30 +0000)
committermoodler <moodler>
Sun, 14 Sep 2003 12:30:09 +0000 (12:30 +0000)
This is a sort of "dummy" activity that allows HTML to be placed
anywhere in the course sections ...

mod/label/db/mysql.php [new file with mode: 0644]
mod/label/db/mysql.sql [new file with mode: 0644]
mod/label/db/postgres7.php [new file with mode: 0644]
mod/label/db/postgres7.sql [new file with mode: 0644]
mod/label/icon.gif [new file with mode: 0755]
mod/label/index.php [new file with mode: 0644]
mod/label/lib.php [new file with mode: 0644]
mod/label/mod.html [new file with mode: 0644]
mod/label/version.php [new file with mode: 0644]
mod/label/view.php [new file with mode: 0644]

diff --git a/mod/label/db/mysql.php b/mod/label/db/mysql.php
new file mode 100644 (file)
index 0000000..dbcb913
--- /dev/null
@@ -0,0 +1,12 @@
+<?PHP\r
+\r
+function label_upgrade($oldversion) {\r
+/// This function does anything necessary to upgrade \r
+/// older versions to match current functionality \r
+\r
+    global $CFG;\r
+\r
+    return true;\r
+}\r
+\r
+?>\r
diff --git a/mod/label/db/mysql.sql b/mod/label/db/mysql.sql
new file mode 100644 (file)
index 0000000..aa8beb6
--- /dev/null
@@ -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';
diff --git a/mod/label/db/postgres7.php b/mod/label/db/postgres7.php
new file mode 100644 (file)
index 0000000..dbcb913
--- /dev/null
@@ -0,0 +1,12 @@
+<?PHP\r
+\r
+function label_upgrade($oldversion) {\r
+/// This function does anything necessary to upgrade \r
+/// older versions to match current functionality \r
+\r
+    global $CFG;\r
+\r
+    return true;\r
+}\r
+\r
+?>\r
diff --git a/mod/label/db/postgres7.sql b/mod/label/db/postgres7.sql
new file mode 100644 (file)
index 0000000..2ec33ec
--- /dev/null
@@ -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'
+);
diff --git a/mod/label/icon.gif b/mod/label/icon.gif
new file mode 100755 (executable)
index 0000000..2653d97
Binary files /dev/null and b/mod/label/icon.gif differ
diff --git a/mod/label/index.php b/mod/label/index.php
new file mode 100644 (file)
index 0000000..0ee6428
--- /dev/null
@@ -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");
+
+?>
diff --git a/mod/label/lib.php b/mod/label/lib.php
new file mode 100644 (file)
index 0000000..2dbf56f
--- /dev/null
@@ -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;
+}
+
+?>
diff --git a/mod/label/mod.html b/mod/label/mod.html
new file mode 100644 (file)
index 0000000..cb811ea
--- /dev/null
@@ -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");
+   }
+?>
diff --git a/mod/label/version.php b/mod/label/version.php
new file mode 100644 (file)
index 0000000..44252ff
--- /dev/null
@@ -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)
+
+?>
diff --git a/mod/label/view.php b/mod/label/view.php
new file mode 100644 (file)
index 0000000..8e115c6
--- /dev/null
@@ -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");
+
+?>
+