From: moodler Date: Sun, 8 Aug 2004 14:33:23 +0000 (+0000) Subject: Lots of little cleanups and these new things: X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3d30a455cb13593a4a4fc67d1c1dee01580d293e;p=moodle.git Lots of little cleanups and these new things: - Reference resources are now history -> converted to HTML pages (the backup/restore has been taken care of, Eloy) - HTML pages and Text pages can now have popups! - Summaries are not shown when they should be blank (eg if they just contain a
as the HTML editor usually inserts. - Fixed some notices for PHP 5 --- diff --git a/mod/resource/db/mysql.php b/mod/resource/db/mysql.php index f9de3de57a..be5020bbde 100644 --- a/mod/resource/db/mysql.php +++ b/mod/resource/db/mysql.php @@ -46,7 +46,10 @@ function resource_upgrade($oldversion) { modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='7';"); modify_database("", "UPDATE prefix_resource SET type='text', options='3' WHERE type='8';"); modify_database("", "UPDATE prefix_resource SET type='directory' WHERE type='9';"); + } + if ($oldversion < 2004080801) { + modify_database("", "UPDATE prefix_resource SET alltext=reference,type='html' WHERE type='reference';"); rebuild_course_cache(); } diff --git a/mod/resource/db/postgres7.php b/mod/resource/db/postgres7.php index 7162c43902..1caea28dd5 100644 --- a/mod/resource/db/postgres7.php +++ b/mod/resource/db/postgres7.php @@ -42,7 +42,10 @@ function resource_upgrade($oldversion) { modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='7';"); modify_database("", "UPDATE prefix_resource SET type='text', options='3' WHERE type='8';"); modify_database("", "UPDATE prefix_resource SET type='directory' WHERE type='9';"); + } + if ($oldversion < 2004080801) { + modify_database("", "UPDATE prefix_resource SET alltext=reference,type='html' WHERE type='reference';"); rebuild_course_cache(); } diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 2100411589..99b9006e95 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -20,13 +20,13 @@ if (!isset($CFG->resource_secretphrase)) { set_config("resource_secretphrase", random_string(20)); } -$RESOURCE_WINDOW_OPTIONS = array("resizable", "scrollbars", "directories", "location", - "menubar", "toolbar", "status", "height", "width"); - if (!isset($CFG->resource_popup)) { set_config("resource_popup", ""); } +$RESOURCE_WINDOW_OPTIONS = array("resizable", "scrollbars", "directories", "location", + "menubar", "toolbar", "status", "height", "width"); + foreach ($RESOURCE_WINDOW_OPTIONS as $popupoption) { $popupoption = "resource_popup$popupoption"; if (!isset($CFG->$popupoption)) { @@ -484,7 +484,7 @@ function resource_get_resource_types() { $resources = array(); /// Standard resource types - $standardresources = array('text','html','file','directory','reference'); + $standardresources = array('text','html','file','directory'); foreach ($standardresources as $resourcetype) { $resources[$resourcetype] = get_string("resourcetype$resourcetype", 'resource'); } diff --git a/mod/resource/restorelib.php b/mod/resource/restorelib.php index 1f8ce293ab..15c2d1f5b3 100644 --- a/mod/resource/restorelib.php +++ b/mod/resource/restorelib.php @@ -53,9 +53,15 @@ $resource->popup = $resource->alltext; $resource->alltext = ''; } + //Move reference to alltext for references + if ($resource->type == 1) { + $resource->popup = ''; + $resource->alltext = $resource->reference; + $resource->reference = ''; + } //Reencode the type field to its new values and fill the options field as needed //Array 1-9 of new types - $types = array ('','reference','file','file','text','file', + $types = array ('','html','file','file','text','file', 'html','file','text','directory'); //Array 1-9 of corresponding options $options = array ('','','frame','','0','', @@ -65,6 +71,12 @@ $resource->type = $types[$oldtype]; $resource->options = $options[$oldtype]; } + + if ($resource->type == 'reference') { // Obsolete type of resource + $resource->type == 'html'; + $resource->alltext = $resource->reference; + $resource->reference = ''; + } //The structure is equal to the db, so insert the resource $newid = insert_record ("resource",$resource); diff --git a/mod/resource/type/directory/resource.class.php b/mod/resource/type/directory/resource.class.php index 97865ab01e..97ff68d7ba 100644 --- a/mod/resource/type/directory/resource.class.php +++ b/mod/resource/type/directory/resource.class.php @@ -70,7 +70,7 @@ function display() { get_string("editfiles")."..."; } - if (trim($this->resource->summary)) { + if (trim(strip_tags($this->resource->summary))) { print_simple_box(text_to_html($this->resource->summary), "center"); print_spacer(10,10); } diff --git a/mod/resource/type/file/resource.class.php b/mod/resource/type/file/resource.class.php index 5b52e83daa..5933fb0b5c 100644 --- a/mod/resource/type/file/resource.class.php +++ b/mod/resource/type/file/resource.class.php @@ -290,7 +290,7 @@ function display() { echo "\n-->\n"; echo ''; - if (trim($this->resource->summary)) { + if (trim(strip_tags($this->resource->summary))) { print_simple_box(text_to_html($this->resource->summary), "center"); } @@ -446,6 +446,8 @@ function display() { function setup($form) { global $CFG, $usehtmleditor, $RESOURCE_WINDOW_OPTIONS; + parent::setup($form); + $this->set_parameters(); // set the parameter array for the form @@ -518,8 +520,6 @@ function setup($form) { } - parent::setup($form); - include("$CFG->dirroot/mod/resource/type/file/file.html"); parent::setup_end(); diff --git a/mod/resource/type/html/html.html b/mod/resource/type/html/html.html index 53a279ea89..ce32d708ea 100644 --- a/mod/resource/type/html/html.html +++ b/mod/resource/type/html/html.html @@ -12,3 +12,67 @@ +
+ + + +

:

+ + + + + onClick="document.form.windowpopup.checked=false; return lockoptions('form', 'windowpopup', popupitems);"> + + + + + + +

:

+ + + + + + + + + + diff --git a/mod/resource/type/html/resource.class.php b/mod/resource/type/html/resource.class.php index 2e532fc1af..6c5b69fabe 100644 --- a/mod/resource/type/html/resource.class.php +++ b/mod/resource/type/html/resource.class.php @@ -7,6 +7,60 @@ function resource_html($cmid=0) { parent::resource_base($cmid); } +function 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. + + global $RESOURCE_WINDOW_OPTIONS; + + $resource->timemodified = time(); + + if (isset($resource->windowpopup)) { + $optionlist = array(); + foreach ($RESOURCE_WINDOW_OPTIONS as $option) { + if (isset($resource->$option)) { + $optionlist[] = $option."=".$resource->$option; + } + } + $resource->popup = implode(',', $optionlist); + + } else if (isset($resource->windowpage)) { + $resource->popup = ""; + } + + return insert_record("resource", $resource); +} + + +function 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. + + global $RESOURCE_WINDOW_OPTIONS; + + $resource->id = $resource->instance; + $resource->timemodified = time(); + + if (isset($resource->windowpopup)) { + $optionlist = array(); + foreach ($RESOURCE_WINDOW_OPTIONS as $option) { + if (isset($resource->$option)) { + $optionlist[] = $option."=".$resource->$option; + } + } + $resource->popup = implode(',', $optionlist); + + } else if (isset($resource->windowpage)) { + $resource->popup = ""; + } + + return update_record("resource", $resource); +} + + function display() { global $CFG, $THEME; @@ -21,28 +75,116 @@ function display() { $navigation = "framename}\" href=\"../../course/view.php?id={$this->course->id}\">{$this->course->shortname} -> framename}\" href=\"index.php?id={$this->course->id}\">$strresources ->"; } else { - $navigation = "framename}\" href=\"index.php?id={$this->course->id}\">$strresources ->"; } - + $navigation = "framename}\" href=\"index.php?id={$this->course->id}\">$strresources ->"; + } - add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id); $pagetitle = strip_tags($this->course->shortname.': '.$this->resource->name); - print_header($pagetitle, $this->course->fullname, "$navigation {$this->resource->name}", - "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), navmenu($this->course, $this->cm)); - print_simple_box(format_text($this->resource->alltext, FORMAT_HTML), "center", "", "$THEME->cellcontent", "20"); + $inpopup = !empty($_GET["inpopup"]); + + if ($this->resource->popup) { + if ($inpopup) { /// Popup only + add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id); + print_header(); + print_simple_box(format_text($this->resource->alltext, FORMAT_HTML), "center", "", "$THEME->cellcontent", "20"); + } else { /// Make a page and a pop-up window - echo "

$strlastmodified: ".userdate($this->resource->timemodified)."

"; + print_header($pagetitle, $this->course->fullname, "$navigation {$this->resource->name}", + "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), + navmenu($this->course, $this->cm)); - print_footer($this->course); + echo "\n'; + + if (trim(strip_tags($this->resource->summary))) { + print_simple_box(format_text($this->resource->summary, FORMAT_HTML), "center"); + } + + $link = "wwwroot/mod/resource/view.php?inpopup=true&id={$this->cm->id}\" target=\"resource{$this->resource->id}\" onClick=\"return openpopup('/mod/resource/view.php?inpopup=true&id={$this->cm->id}', 'resource{$this->resource->id}','{$this->resource->popup}');\">{$this->resource->name}"; + + echo "

 

"; + echo '

'; + print_string('popupresource', 'resource'); + echo '
'; + print_string('popupresourcelink', 'resource', $link); + echo "

"; + + print_footer($this->course); + } + } else { /// not a popup at all + + add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id); + print_header($pagetitle, $this->course->fullname, "$navigation {$this->resource->name}", + "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), + navmenu($this->course, $this->cm)); + + print_simple_box(format_text($this->resource->alltext, FORMAT_HTML), "center", "", "$THEME->cellcontent", "20"); + + echo "

$strlastmodified: ".userdate($this->resource->timemodified)."

"; + + print_footer($this->course); + } } function setup($form) { - global $CFG, $usehtmleditor; + global $CFG, $usehtmleditor, $RESOURCE_WINDOW_OPTIONS; parent::setup($form); + + $strfilename = get_string("filename", "resource"); + $strnote = get_string("note", "resource"); + $strchooseafile = get_string("chooseafile", "resource"); + $strnewwindow = get_string("newwindow", "resource"); + $strnewwindowopen = get_string("newwindowopen", "resource"); + $strsearch = get_string("searchweb", "resource"); + + foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { + $stringname = "str$optionname"; + $$stringname = get_string("new$optionname", "resource"); + $window->$optionname = ""; + $jsoption[] = "\"$optionname\""; + } + + $frameoption = "\"framepage\""; + $popupoptions = implode(",", $jsoption); + $jsoption[] = $frameoption; + $alloptions = implode(",", $jsoption); + + if ($form->instance) { // Re-editing + if (!$form->popup) { + $windowtype = "page"; // No popup text => in page + } else { + $windowtype = "popup"; + $rawoptions = explode(',', $form->popup); + foreach ($rawoptions as $rawoption) { + $option = explode('=', trim($rawoption)); + $optionname = $option[0]; + $optionvalue = $option[1]; + if ($optionname == "height" or $optionname == "width") { + $window->$optionname = $optionvalue; + } else if ($optionvalue) { + $window->$optionname = "checked"; + } + } + } + } else { + foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { + $defaultvalue = "resource_popup$optionname"; + $window->$optionname = $CFG->$defaultvalue; + } + + $windowtype = ($CFG->resource_popup) ? 'popup' : 'page'; + if (!isset($form->options)) { + $form->options = ''; + } + } + include("$CFG->dirroot/mod/resource/type/html/html.html"); parent::setup_end(); diff --git a/mod/resource/type/reference/reference.html b/mod/resource/type/reference/reference.html deleted file mode 100644 index d6e19710a7..0000000000 --- a/mod/resource/type/reference/reference.html +++ /dev/null @@ -1,17 +0,0 @@ - - -

:

- - - - - - - -

()

- - -

- - - diff --git a/mod/resource/type/reference/resource.class.php b/mod/resource/type/reference/resource.class.php deleted file mode 100644 index 178d4dd0ae..0000000000 --- a/mod/resource/type/reference/resource.class.php +++ /dev/null @@ -1,60 +0,0 @@ -course->category) { - require_login($this->course->id); - $navigation = "framename}\" href=\"../../course/view.php?id={$this->course->id}\">{$this->course->shortname} -> - framename}\" href=\"index.php?id={$this->course->id}\">$strresources ->"; - } else { - $navigation = "framename}\" href=\"index.php?id={$this->course->id}\">$strresources ->"; } - - - add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id); - $pagetitle = strip_tags($this->course->shortname.': '.$this->resource->name); - print_header($pagetitle, $this->course->fullname, "$navigation {$this->resource->name}", - "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), navmenu($this->course, $this->cm)); - - print_simple_box($this->resource->reference, "center"); - echo "

"; - echo text_to_html($this->resource->summary); - echo "

"; - echo "

 

"; - echo "

$strlastmodified: ".userdate($this->resource->timemodified)."

"; - echo "
"; - print_footer($this->course); -} - - - -function setup($form) { - global $CFG; - - global $editorfields; - $editorfields = 'summary'; - - parent::setup($form); - - include("$CFG->dirroot/mod/resource/type/reference/reference.html"); - - parent::setup_end(); -} - - -} - -?> diff --git a/mod/resource/type/text/resource.class.php b/mod/resource/type/text/resource.class.php index 4177537599..dd845bae06 100644 --- a/mod/resource/type/text/resource.class.php +++ b/mod/resource/type/text/resource.class.php @@ -8,6 +8,58 @@ function resource_text($cmid=0) { } +function 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. + + global $RESOURCE_WINDOW_OPTIONS; + + $resource->timemodified = time(); + + if (isset($resource->windowpopup)) { + $optionlist = array(); + foreach ($RESOURCE_WINDOW_OPTIONS as $option) { + if (isset($resource->$option)) { + $optionlist[] = $option."=".$resource->$option; + } + } + $resource->popup = implode(',', $optionlist); + + } else if (isset($resource->windowpage)) { + $resource->popup = ""; + } + + return insert_record("resource", $resource); +} + +function 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. + + global $RESOURCE_WINDOW_OPTIONS; + + $resource->id = $resource->instance; + $resource->timemodified = time(); + + if (isset($resource->windowpopup)) { + $optionlist = array(); + foreach ($RESOURCE_WINDOW_OPTIONS as $option) { + if (isset($resource->$option)) { + $optionlist[] = $option."=".$resource->$option; + } + } + $resource->popup = implode(',', $optionlist); + + } else if (isset($resource->windowpage)) { + $resource->popup = ""; + } + + return update_record("resource", $resource); +} + function display() { global $CFG, $THEME; @@ -23,30 +75,118 @@ function display() { } else { $navigation = "framename}\" href=\"index.php?id={$this->course->id}\">$strresources ->"; } - - add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id); $pagetitle = strip_tags($this->course->shortname.': '.$this->resource->name); - print_header($pagetitle, $this->course->fullname, "$navigation {$this->resource->name}", - "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), navmenu($this->course, $this->cm)); - - print_simple_box(format_text($this->resource->alltext, $this->resource->options), "center", "", "$THEME->cellcontent", "20"); - - echo "

$strlastmodified: ".userdate($this->resource->timemodified)."

"; + $inpopup = !empty($_GET["inpopup"]); + + if ($this->resource->popup) { + if ($inpopup) { /// Popup only + add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", + $this->resource->id, $this->cm->id); + print_header(); + print_simple_box(format_text($this->resource->alltext, $this->resource->options), + "center", "", "$THEME->cellcontent", "20"); + } else { /// Make a page and a pop-up window + + print_header($pagetitle, $this->course->fullname, "$navigation {$this->resource->name}", + "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), + navmenu($this->course, $this->cm)); + + echo "\n'; + + if (trim(strip_tags($this->resource->summary))) { + print_simple_box(format_text($this->resource->summary, FORMAT_HTML), "center"); + } + + $link = "wwwroot/mod/resource/view.php?inpopup=true&id={$this->cm->id}\" target=\"resource{$this->resource->id}\" onClick=\"return openpopup('/mod/resource/view.php?inpopup=true&id={$this->cm->id}', 'resource{$this->resource->id}','{$this->resource->popup}');\">{$this->resource->name}"; + + echo "

 

"; + echo '

'; + print_string('popupresource', 'resource'); + echo '
'; + print_string('popupresourcelink', 'resource', $link); + echo "

"; + + print_footer($this->course); + } + } else { /// not a popup at all + + add_to_log($this->course->id, "resource", "view", "view.php?id={$this->cm->id}", $this->resource->id, $this->cm->id); + print_header($pagetitle, $this->course->fullname, "$navigation {$this->resource->name}", + "", "", true, update_module_button($this->cm->id, $this->course->id, $strresource), + navmenu($this->course, $this->cm)); + + print_simple_box(format_text($this->resource->alltext, $this->resource->options), + "center", "", "$THEME->cellcontent", "20"); + + echo "

$strlastmodified: ".userdate($this->resource->timemodified)."

"; + + print_footer($this->course); + } - print_footer($this->course); } function setup($form) { - global $CFG; - - global $editorfields; + global $CFG, $editorfields, $RESOURCE_WINDOW_OPTIONS; + $editorfields = 'summary'; parent::setup($form); + $strfilename = get_string("filename", "resource"); + $strnote = get_string("note", "resource"); + $strchooseafile = get_string("chooseafile", "resource"); + $strnewwindow = get_string("newwindow", "resource"); + $strnewwindowopen = get_string("newwindowopen", "resource"); + $strsearch = get_string("searchweb", "resource"); + + foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { + $stringname = "str$optionname"; + $$stringname = get_string("new$optionname", "resource"); + $window->$optionname = ""; + $jsoption[] = "\"$optionname\""; + } + + $frameoption = "\"framepage\""; + $popupoptions = implode(",", $jsoption); + $jsoption[] = $frameoption; + $alloptions = implode(",", $jsoption); + + if ($form->instance) { // Re-editing + if (!$form->popup) { + $windowtype = "page"; // No popup text => in page + } else { + $windowtype = "popup"; + $rawoptions = explode(',', $form->popup); + foreach ($rawoptions as $rawoption) { + $option = explode('=', trim($rawoption)); + $optionname = $option[0]; + $optionvalue = $option[1]; + if ($optionname == "height" or $optionname == "width") { + $window->$optionname = $optionvalue; + } else if ($optionvalue) { + $window->$optionname = "checked"; + } + } + } + } else { + foreach ($RESOURCE_WINDOW_OPTIONS as $optionname) { + $defaultvalue = "resource_popup$optionname"; + $window->$optionname = $CFG->$defaultvalue; + } + + $windowtype = ($CFG->resource_popup) ? 'popup' : 'page'; + if (!isset($form->options)) { + $form->options = ''; + } + } + $format_array = format_text_menu(); unset($format_array[FORMAT_HTML]); include("$CFG->dirroot/mod/resource/type/text/text.html"); diff --git a/mod/resource/type/text/text.html b/mod/resource/type/text/text.html index ae2334de12..a639aa50cc 100644 --- a/mod/resource/type/text/text.html +++ b/mod/resource/type/text/text.html @@ -15,10 +15,74 @@

:


- options, '') ?> - -
-
+ options, ''); + helpbutton("textformat", get_string("formattexttype")); + ?> +
+ + + +

:

+ + + + + onClick="document.form.windowpopup.checked=false; return lockoptions('form', 'windowpopup', popupitems);"> + + + + + + +

:

+ + + + + + +
    + $value) { + if ($name == "height" or $name == "width") { + continue; + } + echo ""; + echo "$name.">"; + $stringname = "str$name"; + echo $$stringname."
    "; + } + ?> + + + +
    + + + +
    + "; + echo "lockoptions('form','windowpopup', popupitems);"; + echo "document.form.windowpage.checked=true;"; + echo "document.form.windowpopup.checked=false;"; + echo ""; + } else { + echo ""; + } + ?> +
+ + + diff --git a/mod/resource/version.php b/mod/resource/version.php index 33a1bb93c4..2d3595a7c1 100644 --- a/mod/resource/version.php +++ b/mod/resource/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2004073000; +$module->version = 2004080801; $module->requires = 2004073000; // Requires this Moodle version $module->cron = 0;