]> git.mjollnir.org Git - moodle.git/commitdiff
Additions to cope with richtext editor being used in some forms.
authormoodler <moodler>
Thu, 10 Oct 2002 07:26:10 +0000 (07:26 +0000)
committermoodler <moodler>
Thu, 10 Oct 2002 07:26:10 +0000 (07:26 +0000)
admin/config.html
admin/index.php
lib/db/mysql.php
lib/db/mysql.sql
lib/defaults.php
lib/javascript.php
lib/moodlelib.php
lib/weblib.php

index 97fc89ad8798ace59315ed669375e4339b711cb7..645a409ecb5cb8ab90cae751551b31d70f6f20c2 100644 (file)
     <? print_string("configgdversion") ?>
     </TD>
 </TR>
+<TR VALIGN=TOP>
+    <TD ALIGN=RIGHT><P>htmleditor:</TD>
+    <TD>
+    <? unset($options);
+       $options[0] = get_string("allownot");
+       $options[1] = get_string("allow");
+       choose_from_menu ($options, "htmleditor", $config->htmleditor, "", "", "");
+       formerr($err["htmleditor"]);
+    ?>
+    </TD>
+    <TD>
+    <? print_string("confightmleditor") ?>
+    </TD>
+</TR>
 <TR VALIGN=TOP>
        <TD ALIGN=RIGHT><P>maxeditingtime:</TD>
        <TD>
index af56326a5d711f8d43ffc963def65af2b42e04ca..cc6fc72ca9628d633a530b94f161ca482a162da1 100644 (file)
 
     print_heading("Moodle $CFG->release ($CFG->version)", "CENTER", 1);
 
-    print_footer();
+    print_footer($site);
 
 ?>
 
index 79987e67c3796c2a8918b50c14ee3259626246b0..ac1b900583c5859d039655f6630da7050ea6194d 100644 (file)
@@ -74,6 +74,9 @@ function upgrade_moodle($oldversion=0) {
     if ($oldversion < 2002092100) {
         execute_sql(" ALTER TABLE `user` ADD `deleted` TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL AFTER `confirmed` ");
     }
+    if ($oldversion < 2002101001) {
+        execute_sql(" ALTER TABLE `user` ADD `htmleditor` TINYINT(1) UNSIGNED DEFAULT '1' NOT NULL AFTER `maildisplay` ");
+    }
 
     return true;
 }
index 6c4508853c11d4880784f893553f6b382e075ae1..692e557cd8099f006edadc0a3f5527d7640bc897 100644 (file)
@@ -175,6 +175,7 @@ CREATE TABLE `user` (
   `description` text,
   `mailformat` tinyint(1) unsigned NOT NULL default '1',
   `maildisplay` tinyint(2) unsigned NOT NULL default '2',
+  `htmleditor` tinyint(1) unsigned NOT NULL default '1',
   `timemodified` int(10) unsigned NOT NULL default '0',
   PRIMARY KEY  (`id`),
   UNIQUE KEY `id` (`id`),
index f107ae1ec2cd17b66c1ca65e6e47ac8bbd1646ad..010d2ff0e6d0eb85caa9c8ab8c5ee6c3487c8ac4 100644 (file)
@@ -13,7 +13,8 @@
        "longtimenosee"  =>  100,
        "zip"            => "/usr/bin/zip",
        "unzip"          => "/usr/bin/unzip",
-       "slasharguments" =>  true,
+       "slasharguments" =>  1,
+       "htmleditor"     =>  true,
        "proxyhost"      => "",
        "proxyport"      => "",
        "maxeditingtime" =>  1800
index 44d84bbe1e575ca95f920263db0180ab507d0b05..e8e15d16b9de21976409af03069c2672fcb0a777 100644 (file)
@@ -2,14 +2,19 @@
 <SCRIPT LANGUAGE="JavaScript">\r
 <!-- //hide\r
 function fillmessagebox(text) {\r
 document.form.message.value = text;\r
+ document.form.message.value = text;\r
 }\r
 \r
 function openpopup(url,name,height,width) {\r
-fullurl = "<?=$CFG->wwwroot ?>" + url;\r
-options = "menubar=0,location=0,scrollbars,resizable,width="+width+",height="+height;\r
-windowobj = window.open(fullurl,name, options);\r
-windowobj.focus();\r
+ fullurl = "<?=$CFG->wwwroot ?>" + url;\r
+ options = "menubar=0,location=0,scrollbars,resizable,width="+width+",height="+height;\r
+ windowobj = window.open(fullurl,name, options);\r
+ windowobj.focus();\r
+}\r
+\r
+function copyrichtext(textname) { \r
+ textname.value = document.richedit.docHtml;\r
+ return true;\r
 }\r
 \r
 <? if ($focus) { echo "function setfocus() { document.$focus.focus() }\n"; } ?>\r
index 0219cd4411b3a1a2b97bd7871f864c0565ad0b44..26e5a3b93abea6b817b49245bb62fa8efde8c1d1 100644 (file)
@@ -8,7 +8,6 @@
 // Martin Dougiamas, 2000
 //
 
-
 /// STANDARD WEB PAGE PARTS ///////////////////////////////////////////////////
 
 function print_header ($title="", $heading="", $navigation="", $focus="", $meta="", $cache=true, $button="") {
@@ -769,8 +768,26 @@ function get_record_sql($sql) {
     }
 }
 
-function get_records($table, $selector, $value, $sort="") {
+function get_records($table, $selector, $value, $sort="", $fields="*") {
+// Get a number of records as an array of objects
+// Can optionally be sorted eg "time ASC" or "time DESC"
+// If "fields" is specified, only those fields are returned
+// The "key" is the first column returned, eg usually "id"
+    global $db;
+
+    if ($sort) {
+        $sortorder = "ORDER BY $sort";
+    }
+    $sql = "SELECT $fields FROM $table WHERE $selector = '$value' $sortorder";
+
+    return get_records_sql($sql);
+}
+
+
+function get_records_list($table, $selector, $values, $sort="", $fields="*") {
 // Get a number of records as an array of objects
+// Differs from get_records() in that the values variable 
+// can be a comma-separated list of values eg  "4,5,6,10"
 // Can optionally be sorted eg "time ASC" or "time DESC"
 // The "key" is the first column returned, eg usually "id"
     global $db;
@@ -778,11 +795,12 @@ function get_records($table, $selector, $value, $sort="") {
     if ($sort) {
         $sortorder = "ORDER BY $sort";
     }
-    $sql = "SELECT * FROM $table WHERE $selector = '$value' $sortorder";
+    $sql = "SELECT $fields FROM $table WHERE $selector in ($values) $sortorder";
 
     return get_records_sql($sql);
 }
 
+
 function get_records_sql($sql) {
 // Get a number of records as an array of objects
 // The "key" is the first column returned, eg usually "id"
@@ -1928,6 +1946,33 @@ function check_php_version($version="4.1.0") {
     return ($curversion >= $minversion);
 }
 
+function check_browser_version($brand="MSIE", $version=5.5) {
+// Checks to see if is a browser matches the specified
+// brand and is equal or better version.
+    global $HTTP_USER_AGENT;
+
+    if (!$HTTP_USER_AGENT) {
+        return false;
+    }
+    $string = explode(";", $HTTP_USER_AGENT);
+    if (!isset($string[1])) {
+        return false;
+    }
+    $string = explode(" ", trim($string[1]));
+    if (!isset($string[0]) and !isset($string[1])) {
+        return false;
+    }
+    if ($string[0] == $brand and (float)$string[1] >= $version ) {
+        return true;
+    }
+    return false;
+}
+
+function can_use_richtext_editor() {
+    global $USER, $CFG;
+    return (check_browser_version("MSIE", 5.5) and $USER->htmleditor and $CFG->htmleditor);
+}
+
 
 function check_gd_version() {
     ob_start();
@@ -1952,4 +1997,6 @@ function check_gd_version() {
     return $gdversion;   // 1, 2 or 0
 }
 
+
+
 ?>
index 6eb20cea4ac28f2798a8aa7ed25550879239ae35..5cef38469958ef420c58a3210d3a416d65399003 100644 (file)
@@ -2,10 +2,19 @@
 
 // weblib.php
 //
-// Library of useful PHP functions related to web pages.
+// Library of useful PHP functions and constants related to web pages.
 //
 //
 
+/// Constants
+
+// Define text formatting types ... eventually we can add Wiki, BBcode etc
+define("FORMAT_MOODLE", "0");
+define("FORMAT_HTML", "1");
+
+
+/// Functions
+
 function s($var) {
 // returns $var with HTML characters (like "<", ">", etc.) properly quoted,
 // or if $var is empty, will return an empty string. 
@@ -259,15 +268,47 @@ function get_slash_arguments($i=0) {
     }
 }
 
+function format_text_menu() {
+    return array (FORMAT_MOODLE => get_string("formattext"), 
+                  FORMAT_HTML   => get_string("formathtml") );
+}
+
+function format_text($text, $format, $options=NULL) {
+// Given text in a variety of format codings, this function returns 
+// the text as safe HTML.
+//
+// $text is raw text (originally from a user)
+// $format is one of the format constants, defined above
+
+    switch ($format) {
+        case FORMAT_MOODLE:
+            return text_to_html($text, $options->smiley, $options->para);
+            break;
 
-function cleantext($text) {
+        case FORMAT_HTML:
+            return $text;   // Is re-cleaning needed?
+            break;
+    }
+}
+
+
+function clean_text($text, $format) {
 // Given raw text (eg typed in by a user), this function cleans it up 
 // and removes any nasty tags that could mess up Moodle pages.
 
-    return strip_tags($text, '<b><i><u><font><ol><ul><dl><li><dt><dd><h1><h2><h3><hr>');
+    switch ($format) {
+        case FORMAT_MOODLE:
+            return strip_tags($text, '<b><i><u><font><ol><ul><dl><li><dt><dd><h1><h2><h3><hr>');
+            break;
+
+        case FORMAT_HTML:
+            return $text;   // XX May want to add some cleaning on this. 
+            break;
+    }
 }
 
 
+
 function text_to_html($text, $smiley=true, $para=true) {
 // Given plain text, makes it into HTML as nicely as possible.