diff --git a/admin/index.php b/admin/index.php index 4de2eaa622a..ecbed498b82 100644 --- a/admin/index.php +++ b/admin/index.php @@ -411,6 +411,8 @@ " ".get_string("adminhelplogs")); $table->data[] = array("id\">".get_string("sitefiles")."", " ".get_string("adminhelpsitefiles")); + $table->data[] = array("".get_string('mymoodle','my')."", + " ".get_string("adminhelpmymoodle")); if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) { $table->data[] = array("dbtype/frame.php\">".get_string("managedatabase")."", " ".get_string("adminhelpmanagedatabase")); diff --git a/admin/mymoodle.php b/admin/mymoodle.php new file mode 100644 index 00000000000..7c0d9cadaba --- /dev/null +++ b/admin/mymoodle.php @@ -0,0 +1,65 @@ +dirroot.'/my/pagelib.php'); + require_once($CFG->dirroot.'/lib/blocklib.php'); + + require_login(); + + if (!isadmin()) { + error("Only the admin can use this page"); + } + + define('OVERRIDE_PAGE_TYPE',PAGE_MY_MOODLE); + + $PAGE = page_create_object(PAGE_MY_MOODLE,0); + + $blockaction = optional_param('blockaction'); + + $blocks = blocks_get_pinned($PAGE); + + if (!empty($blockaction)) { + blocks_execute_url_action($PAGE, $blocks,true); + // This re-query could be eliminated by judicious programming in blocks_execute_action(), + // but I 'm not sure if it's worth the complexity increase... + $blocks = blocks_get_pinned($PAGE); + } + + + $strtitle = get_string('pinblocks','my'); + + print_header($strtitle,$strtitle,''. + get_string('admin').' -> '.$strtitle); + + echo ''; + echo ''; + + + $blocks_preferred_width = bounded_number(180, blocks_preferred_width($blocks[BLOCK_POS_LEFT]), 210); + + + echo ''; + + echo ''; + + + echo ''; + + echo '
'; + blocks_print_group($PAGE, $blocks, BLOCK_POS_LEFT); + echo ''; + print_simple_box_start('center'); + print_heading($strtitle); + print_string('pinblocksexplan','my'); + print_simple_box_end(); + echo ''; + blocks_print_group($PAGE, $blocks, BLOCK_POS_RIGHT); + echo '
'; + + print_footer(); + + +} + + +?> \ No newline at end of file diff --git a/blocks/activity_modules/block_activity_modules.php b/blocks/activity_modules/block_activity_modules.php index 89baf13f8da..0a5e42c5c9b 100644 --- a/blocks/activity_modules/block_activity_modules.php +++ b/blocks/activity_modules/block_activity_modules.php @@ -32,6 +32,11 @@ class block_activity_modules extends block_list { return $this->content; } + + function applicable_formats() { + require_once($GLOBALS['CFG']->dirroot.'/my/pagelib.php'); + return array('all' => true, 'mod' => false, MY_MOODLE_FORMAT => false); + } } ?> diff --git a/blocks/admin/block_admin.php b/blocks/admin/block_admin.php index 2a7338364b4..66008755dd1 100644 --- a/blocks/admin/block_admin.php +++ b/blocks/admin/block_admin.php @@ -195,6 +195,11 @@ class block_admin extends block_list { } } } + + function applicable_formats() { + require_once($GLOBALS['CFG']->dirroot.'/my/pagelib.php'); + return array('all' => true, 'mod' => false, MY_MOODLE_FORMAT => false); + } } ?> diff --git a/blocks/calendar_month/block_calendar_month.php b/blocks/calendar_month/block_calendar_month.php index ec1ce544703..c8a00fb55c8 100644 --- a/blocks/calendar_month/block_calendar_month.php +++ b/blocks/calendar_month/block_calendar_month.php @@ -31,8 +31,12 @@ class block_calendar_month extends block_base { $filtercourse = array(); } else { - - $courseshown = $this->instance->pageid; + if (!empty($this->instance->pageid)) { + $courseshown = $this->instance->pageid; + } + else { + $courseshown = SITEID; + } if($courseshown == SITEID) { // Being displayed at site level. This will cause the filter to fall back to auto-detecting diff --git a/blocks/calendar_upcoming/block_calendar_upcoming.php b/blocks/calendar_upcoming/block_calendar_upcoming.php index b9354ac3c04..8be39db96fb 100644 --- a/blocks/calendar_upcoming/block_calendar_upcoming.php +++ b/blocks/calendar_upcoming/block_calendar_upcoming.php @@ -27,8 +27,12 @@ class block_calendar_upcoming extends block_base { $this->content->footer = ''; } else { - - $courseshown = $this->instance->pageid; + if (!empty($this->instance->pageid)) { + $courseshown = $this->instance->pageid; + } + else { + $courseshown = SITEID; + } $this->content->footer = '
'. get_string('gotocalendar', 'calendar').'...'; diff --git a/blocks/course_list/block_course_list.php b/blocks/course_list/block_course_list.php index c18a06fed1f..9e9f962eed2 100644 --- a/blocks/course_list/block_course_list.php +++ b/blocks/course_list/block_course_list.php @@ -1,5 +1,7 @@ dirroot . '/course/lib.php'); + class block_course_list extends block_list { function init() { $this->title = get_string('courses'); diff --git a/blocks/course_summary/block_course_summary.php b/blocks/course_summary/block_course_summary.php index 1ba126e3f6f..d86982243d0 100644 --- a/blocks/course_summary/block_course_summary.php +++ b/blocks/course_summary/block_course_summary.php @@ -23,6 +23,9 @@ class block_course_summary extends block_base { return ''; } + if (empty($this->instance->pageid)) { + $this->instance->pageid = SITEID; + } $course = get_record('course', 'id', $this->instance->pageid); $this->content = New stdClass; diff --git a/blocks/db/mysql.php b/blocks/db/mysql.php index 6df523e9667..1944ff6810f 100644 --- a/blocks/db/mysql.php +++ b/blocks/db/mysql.php @@ -143,6 +143,19 @@ global $CFG; } } + if ($oldversion < 2005081600) { + $result = $result && modify_database('',"CREATE TABLE `prefix_block_pinned` ( + `id` int(10) not null auto_increment, + `blockid` int(10) not null default '0', + `pagetype` varchar(20) not null default '', + `position` varchar(10) not null default '', + `weight` tinyint(3) not null default '0', + `visible` tinyint(1) not null default '0', + `configdata` text not null default '', + PRIMARY KEY(`id`) + ) TYPE=MyISAM;"); + } + //Finally, return result return $result; } diff --git a/blocks/db/mysql.sql b/blocks/db/mysql.sql index 6dfae52caba..6d9282ffa21 100644 --- a/blocks/db/mysql.sql +++ b/blocks/db/mysql.sql @@ -26,4 +26,18 @@ CREATE TABLE `prefix_block_instance` ( PRIMARY KEY(`id`), INDEX pageid(`pageid`) ) TYPE=MyISAM; + +CREATE TABLE `prefix_block_pinned` ( + `id` int(10) not null auto_increment, + `blockid` int(10) not null default '0', + `pagetype` varchar(20) not null default '', + `position` varchar(10) not null default '', + `weight` tinyint(3) not null default '0', + `visible` tinyint(1) not null default '0', + `configdata` text not null default '', + PRIMARY KEY(`id`) +) TYPE=MyISAM; + + + # -------------------------------------------------------- diff --git a/blocks/db/postgres7.php b/blocks/db/postgres7.php index f44ccc86503..e893f1e90cf 100644 --- a/blocks/db/postgres7.php +++ b/blocks/db/postgres7.php @@ -146,6 +146,18 @@ global $CFG; modify_database('','ALTER TABLE prefix_block_instance ALTER position SET NOT NULL'); } + if ($oldversion < 2005081600) { + $result = $result && modify_database('',"CREATE TABLE prefix_block_pinned ( + id SERIAL8 PRIMARY KEY, + blockid INT8 NOT NULL default 0, + pagetype varchar(20) NOT NULL default '', + position varchar(10) NOT NULL default '', + weight INT NOT NULL default 0, + visible INT NOT NULL default 0, + configdata text NOT NULL default 0 + );"); + } + //Finally, return result return $result; } diff --git a/blocks/db/postgres7.sql b/blocks/db/postgres7.sql index 9fc97c909a9..d5acafa17d9 100644 --- a/blocks/db/postgres7.sql +++ b/blocks/db/postgres7.sql @@ -23,7 +23,16 @@ CREATE TABLE prefix_block_instance ( visible int not null default '0', configdata text not null default '' ) ; - CREATE INDEX prefix_block_instance_pageid_idx ON prefix_block_instance (pageid); + +CREATE TABLE prefix_block_pinned ( + id SERIAL8 PRIMARY KEY, + blockid INT8 NOT NULL default 0, + pagetype varchar(20) NOT NULL default '', + position varchar(10) NOT NULL default '', + weight INT NOT NULL default 0, + visible INT NOT NULL default 0, + configdata text NOT NULL default 0 +) ; # -------------------------------------------------------- diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index f6d58159eb0..2a1e7f90cc8 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -411,7 +411,8 @@ class block_base { */ function applicable_formats() { // Default case: the block can be used in courses and site index, but not in activities - return array('all' => true, 'mod' => false); + require_once($GLOBALS['CFG']->dirroot.'/my/pagelib.php'); + return array('all' => true, 'mod' => false, MY_MOODLE_FORMAT => true); } @@ -529,10 +530,14 @@ class block_base { * @return boolean * @todo finish documenting this function */ - function instance_config_save($data) { + function instance_config_save($data,$pinned=false) { $data = stripslashes_recursive($data); $this->config = $data; - return set_field('block_instance', 'configdata', base64_encode(serialize($data)), 'id', $this->instance->id); + $table = 'block_instance'; + if (!empty($pinned)) { + $table = 'block_pinned'; + } + return set_field($table, 'configdata', base64_encode(serialize($data)), 'id', $this->instance->id); } /** @@ -540,8 +545,12 @@ class block_base { * @return boolean * @todo finish documenting this function */ - function instance_config_commit() { - return set_field('block_instance', 'configdata', base64_encode(serialize($this->config)), 'id', $this->instance->id); + function instance_config_commit($pinned=false) { + $table = 'block_instance'; + if (!empty($pinned)) { + $table = 'block_pinned'; + } + return set_field($table, 'configdata', base64_encode(serialize($this->config)), 'id', $this->instance->id); } /** diff --git a/blocks/news_items/block_news_items.php b/blocks/news_items/block_news_items.php index bfac2683aff..a928809aa4e 100644 --- a/blocks/news_items/block_news_items.php +++ b/blocks/news_items/block_news_items.php @@ -22,6 +22,9 @@ class block_news_items extends block_base { } + if ($this->instance->pageid == 0) { + $this->instance->pageid = SITEID; + } $course = get_record('course', 'id', $this->instance->pageid); if ($course->newsitems) { // Create a nice listing of recent postings diff --git a/blocks/participants/block_participants.php b/blocks/participants/block_participants.php index 1465368246e..135ad8d0a48 100644 --- a/blocks/participants/block_participants.php +++ b/blocks/participants/block_participants.php @@ -23,6 +23,10 @@ class block_participants extends block_list { $this->content->footer = ''; + if (empty($this->instance->pageid)) { + $this->instance->pageid = SITEID; + } + if ($this->instance->pageid != SITEID || $CFG->showsiteparticipantslist > 1 || ($CFG->showsiteparticipantslist == 1 && isteacherinanycourse()) || @@ -37,6 +41,12 @@ class block_participants extends block_list { return $this->content; } + + // my moodle can only have SITEID and it's redundant here, so take it away + function applicable_formats() { + require_once($GLOBALS['CFG']->dirroot.'/my/pagelib.php'); + return array('all' => true, MY_MOODLE_FORMAT => false); + } } ?> diff --git a/blocks/search_forums/block_search_forums.php b/blocks/search_forums/block_search_forums.php index e09d8f1d606..deffb33031b 100644 --- a/blocks/search_forums/block_search_forums.php +++ b/blocks/search_forums/block_search_forums.php @@ -1,5 +1,8 @@ dirroot.'/mod/forum/lib.php'); + class block_search_forums extends block_base { function init() { $this->title = get_string('blocktitle', 'block_search_forums'); @@ -34,6 +37,10 @@ class block_search_forums extends block_base { return $this->content; } + + function applicable_formats() { + return array('site' => true, 'course' => true); + } } ?> diff --git a/calendar/lib.php b/calendar/lib.php index cc170f831eb..7f5a2588d3a 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -1057,7 +1057,10 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU // The first time we get in here, retrieve all groupmodes at once if($groupmodes === NULL) { - $groupmodes = get_records_list('course', 'id', implode(',', $groupcourses), '', 'id, groupmode, groupmodeforce'); + $count = count($groupcourses); + if ($count && ($count != 1 || !empty($count[0]))) { + $groupmodes = get_records_list('course', 'id', implode(',', $groupcourses), '', 'id, groupmode, groupmodeforce'); + } } // If this course has groups, show events from all of them diff --git a/course/lib.php b/course/lib.php index 724c00f4a53..584df1a661b 100644 --- a/course/lib.php +++ b/course/lib.php @@ -648,6 +648,34 @@ function print_log_graph($course, $userid=0, $type="course.png", $date=0) { } +function print_overview($course) { + + global $CFG, $USER; + + if (!$lastaccess = get_record("user_teachers","userid",$USER->id,"course",$course->id)) { + if (!$lastaccess = get_record("user_students","userid",$USER->id,"course",$course->id)) { + return false; + } + } + $lastaccess = $lastaccess->timeaccess; + + print_simple_box_start("center", '400', '', 5, "coursebox"); + print_heading(''.$course->fullname.''); + if ($mods = get_course_mods($course->id)) { + foreach ($mods as $mod) { + if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->modname.'/lib.php')) { + require_once(dirname(dirname(__FILE__)).'/mod/'.$mod->modname.'/lib.php'); + $fname = $mod->modname.'_print_overview'; + if (function_exists($fname)) { + $fname($course,$mod,$lastaccess); + } + } + } + } + print_simple_box_end(); +} + + function print_recent_activity($course) { // $course is an object diff --git a/lang/en/forum.php b/lang/en/forum.php index 8e582dbee27..b6b876449aa 100644 --- a/lang/en/forum.php +++ b/lang/en/forum.php @@ -113,6 +113,8 @@ $string['oldertopics'] = 'Older topics'; $string['openmode0'] = 'No discussions, no replies'; $string['openmode1'] = 'No discussions, but replies are allowed'; $string['openmode2'] = 'Discussions and replies are allowed'; +$string['overviewnumpostssince'] = '$a posts since last login'; +$string['overviewnumunread'] = '$a total unread'; $string['parent'] = 'Show parent'; $string['parentofthispost'] = 'Parent of this post'; $string['postadded'] = '

Your post was successfully added.

diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 2743c17f46d..97a4b014654 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -53,6 +53,7 @@ $string['adminhelpmanageblocks'] = 'Manage installed blocks and their settings'; $string['adminhelpmanagedatabase'] = 'Access the database directly (be careful!)'; $string['adminhelpmanagefilters'] = 'Choose text filters and related settings'; $string['adminhelpmanagemodules'] = 'Manage installed modules and their settings'; +$string['adminhelpmymoodle'] = 'Configure the my moodle blocks for users'; $string['adminhelpsitefiles'] = 'For publishing general files or uploading external backups'; $string['adminhelpsitesettings'] = 'Define how the front page of the site looks'; $string['adminhelpthemes'] = 'Choose how the site looks (colours, fonts etc)'; @@ -1070,6 +1071,8 @@ $string['up'] = 'Up'; $string['update'] = 'Update'; $string['updated'] = 'Updated $a'; $string['updatemyprofile'] = 'Update profile'; +$string['updatemymoodleon'] = 'Edit this page'; +$string['updatemymoodleoff'] = 'Normal mode'; $string['updatesevery'] = 'Updates every $a seconds'; $string['updatethis'] = 'Update this $a'; $string['updatethiscourse'] = 'Update this course'; diff --git a/lang/en/my.php b/lang/en/my.php new file mode 100644 index 00000000000..bf68e10ef2c --- /dev/null +++ b/lang/en/my.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/lib/blocklib.php b/lib/blocklib.php index 0f50035e0ce..6b798ebaa79 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -180,7 +180,7 @@ function blocks_name_allowed_in_format($name, $pageformat) { return $accept; } -function blocks_delete_instance($instance) { +function blocks_delete_instance($instance,$pinned=false) { global $CFG; // Get the block object and call instance_delete() first @@ -193,13 +193,20 @@ function blocks_delete_instance($instance) { // Return value ignored $obj->instance_delete(); - - // Now kill the db record; - delete_records('block_instance', 'id', $instance->id); - // And now, decrement the weight of all blocks after this one - execute_sql('UPDATE '.$CFG->prefix.'block_instance SET weight = weight - 1 WHERE pagetype = \''.$instance->pagetype. - '\' AND pageid = '.$instance->pageid.' AND position = \''.$instance->position. - '\' AND weight > '.$instance->weight, false); + if (!empty($pinned)) { + delete_records('block_pinned', 'id', $instance->id); + // And now, decrement the weight of all blocks after this one + execute_sql('UPDATE '.$CFG->prefix.'block_pinned SET weight = weight - 1 WHERE pagetype = \''.$instance->pagetype. + '\' AND position = \''.$instance->position. + '\' AND weight > '.$instance->weight, false); + } else { + // Now kill the db record; + delete_records('block_instance', 'id', $instance->id); + // And now, decrement the weight of all blocks after this one + execute_sql('UPDATE '.$CFG->prefix.'block_instance SET weight = weight - 1 WHERE pagetype = \''.$instance->pagetype. + '\' AND pageid = '.$instance->pageid.' AND position = \''.$instance->position. + '\' AND weight > '.$instance->weight, false); + } return true; } @@ -207,6 +214,10 @@ function blocks_delete_instance($instance) { // (causing them to calculate their content in the process). Returns true or false. Parameter passed // by reference for speed; the array is actually not modified. function blocks_have_content(&$pageblocks, $position) { + + if (empty($pageblocks) || !is_array($pageblocks) || !array_key_exists($position,$pageblocks)) { + return false; + } foreach($pageblocks[$position] as $instance) { if(!$instance->visible) { continue; @@ -251,7 +262,11 @@ function blocks_print_group(&$page, &$pageblocks, $position) { continue; } - if ($isediting) { + if (method_exists($page,'edit_always')) { + $editalways = $page->edit_always(); + } + + if (($isediting && empty($instance->pinned)) || !empty($editalways)) { $options = 0; // The block can be moved up if it's NOT the first one in its position. If it is, we look at the OR clause: // the first block might still be able to move up if the page says so (i.e., it will change position) @@ -295,6 +310,12 @@ function blocks_preferred_width(&$instances) { $blocks = blocks_get_record(); + foreach ($instances as $instance) { + if (!empty($instance->pinned)) { + $maxweight--; + } + } + foreach($instances as $instance) { if(!$instance->visible) { continue; @@ -329,7 +350,13 @@ function blocks_get_record($blockid = NULL, $invalidate = false) { } function blocks_find_block($blockid, $blocksarray) { + if (empty($blocksarray)) { + return false; + } foreach($blocksarray as $blockgroup) { + if (empty($blockgroup)) { + continue; + } foreach($blockgroup as $instance) { if($instance->blockid == $blockid) { return $instance; @@ -357,7 +384,7 @@ function blocks_setup(&$PAGE) { return $pageblocks; } -function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) { +function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid, $pinned=false) { global $CFG; if (is_int($instanceorid)) { @@ -399,7 +426,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) foreach($remove as $item) { unset($data->$item); } - if(!$blockobject->instance_config_save($data)) { + if(!$blockobject->instance_config_save($data,$pinned)) { error('Error saving block configuration'); } // And nothing more, continue with displaying the page @@ -426,13 +453,17 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) error('Invalid block instance for '.$blockaction); } $instance->visible = ($instance->visible) ? 0 : 1; - update_record('block_instance', $instance); + if (!empty($pinned)) { + update_record('block_pinned', $instance); + } else { + update_record('block_instance', $instance); + } break; case 'delete': if(empty($instance)) { error('Invalid block instance for '. $blockaction); } - blocks_delete_instance($instance); + blocks_delete_instance($instance, $pinned); break; case 'moveup': if(empty($instance)) { @@ -445,7 +476,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) $newpos = $page->blocks_move_position($instance, BLOCK_MOVE_UP); $newweight = (empty($pageblocks[$newpos]) ? 0 : max(array_keys($pageblocks[$newpos])) + 1); - blocks_execute_repositioning($instance, $newpos, $newweight); + blocks_execute_repositioning($instance, $newpos, $newweight, $pinned); } else { // The block is just moving upwards in the same position. @@ -457,10 +488,18 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) } if(!empty($other)) { ++$other->weight; - update_record('block_instance', $other); + if (!empty($pinned)) { + update_record('block_pinned', $other); + } else { + update_record('block_instance', $other); + } } --$instance->weight; - update_record('block_instance', $instance); + if (!empty($pinned)) { + update_record('block_pinned', $instance); + } else { + update_record('block_instance', $instance); + } } break; case 'movedown': @@ -474,7 +513,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) $newpos = $page->blocks_move_position($instance, BLOCK_MOVE_DOWN); $newweight = (empty($pageblocks[$newpos]) ? 0 : max(array_keys($pageblocks[$newpos])) + 1); - blocks_execute_repositioning($instance, $newpos, $newweight); + blocks_execute_repositioning($instance, $newpos, $newweight, $pinned); } else { // The block is just moving downwards in the same position. @@ -486,10 +525,18 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) } if(!empty($other)) { --$other->weight; - update_record('block_instance', $other); + if (!empty($pinned)) { + update_record('block_pinned', $other); + } else { + update_record('block_instance', $other); + } } ++$instance->weight; - update_record('block_instance', $instance); + if (!empty($pinned)) { + update_record('block_pinned', $instance); + } else { + update_record('block_instance', $instance); + } } break; case 'moveleft': @@ -501,7 +548,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) $newpos = $page->blocks_move_position($instance, BLOCK_MOVE_LEFT); $newweight = (empty($pageblocks[$newpos]) ? 0 : max(array_keys($pageblocks[$newpos])) + 1); - blocks_execute_repositioning($instance, $newpos, $newweight); + blocks_execute_repositioning($instance, $newpos, $newweight, $pinned); break; case 'moveright': if(empty($instance)) { @@ -512,7 +559,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) $newpos = $page->blocks_move_position($instance, BLOCK_MOVE_RIGHT); $newweight = (empty($pageblocks[$newpos]) ? 0 : max(array_keys($pageblocks[$newpos])) + 1); - blocks_execute_repositioning($instance, $newpos, $newweight); + blocks_execute_repositioning($instance, $newpos, $newweight, $pinned); break; case 'add': // Add a new instance of this block, if allowed @@ -529,17 +576,30 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) } $newpos = $page->blocks_default_position(); - $weight = get_record_sql('SELECT 1, max(weight) + 1 AS nextfree FROM '. $CFG->prefix .'block_instance WHERE pageid = '. $page->get_id() .' AND pagetype = \''. $page->get_type() .'\' AND position = \''. $newpos .'\''); + if (!empty($pinned)) { + $sql = 'SELECT 1, max(weight) + 1 AS nextfree FROM '. $CFG->prefix .'block_pinned WHERE ' + .' pagetype = \''. $page->get_type() .'\' AND position = \''. $newpos .'\''; + } else { + $sql = 'SELECT 1, max(weight) + 1 AS nextfree FROM '. $CFG->prefix .'block_instance WHERE pageid = '. $page->get_id() + .' AND pagetype = \''. $page->get_type() .'\' AND position = \''. $newpos .'\''; + } + $weight = get_record_sql($sql); $newinstance = new stdClass; $newinstance->blockid = $blockid; - $newinstance->pageid = $page->get_id(); + if (empty($pinned)) { + $newinstance->pageid = $page->get_id(); + } $newinstance->pagetype = $page->get_type(); $newinstance->position = $newpos; $newinstance->weight = empty($weight->nextfree) ? 0 : $weight->nextfree; $newinstance->visible = 1; $newinstance->configdata = ''; - $newinstance->id = insert_record('block_instance', $newinstance); + if (!empty($pinned)) { + $newinstance->id = insert_record('block_pinned', $newinstance); + } else { + $newinstance->id = insert_record('block_instance', $newinstance); + } // If the new instance was created, allow it to do additional setup if($newinstance && ($obj = block_instance($block->name, $newinstance))) { @@ -555,7 +615,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) } // You can use this to get the blocks to respond to URL actions without much hassle -function blocks_execute_url_action(&$PAGE, &$pageblocks) { +function blocks_execute_url_action(&$PAGE, &$pageblocks,$pinned=false) { $blockaction = optional_param('blockaction'); if (empty($blockaction) || !$PAGE->user_allowed_editing() || !confirm_sesskey()) { @@ -566,18 +626,18 @@ function blocks_execute_url_action(&$PAGE, &$pageblocks) { $blockid = optional_param('blockid', 0, PARAM_INT); if (!empty($blockid)) { - blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $blockid); + blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $blockid, $pinned); } else if (!empty($instanceid)) { $instance = blocks_find_instance($instanceid, $pageblocks); - blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance); + blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance, $pinned); } } // This shouldn't be used externally at all, it's here for use by blocks_execute_action() // in order to reduce code repetition. -function blocks_execute_repositioning(&$instance, $newpos, $newweight) { +function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=false) { global $CFG; // If it's staying where it is, don't do anything @@ -586,15 +646,82 @@ function blocks_execute_repositioning(&$instance, $newpos, $newweight) { } // Close the weight gap we 'll leave behind - execute_sql('UPDATE '. $CFG->prefix .'block_instance SET weight = weight - 1 WHERE pagetype = \''. $instance->pagetype. + if (!empty($pinned)) { + $sql = 'UPDATE '. $CFG->prefix .'block_instance SET weight = weight - 1 WHERE pagetype = \''. $instance->pagetype. + '\' AND position = \'' .$instance->position. + '\' AND weight > '. $instance->weight; + } else { + $sql = 'UPDATE '. $CFG->prefix .'block_instance SET weight = weight - 1 WHERE pagetype = \''. $instance->pagetype. '\' AND pageid = '. $instance->pageid .' AND position = \'' .$instance->position. - '\' AND weight > '. $instance->weight, - false); + '\' AND weight > '. $instance->weight; + } + execute_sql($sql,false); $instance->position = $newpos; $instance->weight = $newweight; - update_record('block_instance', $instance); + if (!empty($pinned)) { + update_record('block_pinned', $instance); + } else { + update_record('block_instance', $instance); + } +} + +function blocks_get_pinned($page) { + + $visible = true; + + if (method_exists($page,'edit_always')) { + if ($page->edit_always()) { + $visible = false; + } + } + + $blocks = get_records_select('block_pinned', 'pagetype = \''. $page->get_type() .'\''.(($visible) ? 'AND visible = 1' : ''), 'position, weight'); + + $positions = $page->blocks_get_positions(); + $arr = array(); + + foreach($positions as $key => $position) { + $arr[$position] = array(); + } + + if(empty($blocks)) { + return $arr; + } + + foreach($blocks as $block) { + $block->pinned = true; // so we know we can't move it. + $arr[$block->position][$block->weight] = $block; + } + + return $arr; +} + + +function blocks_get_by_page_pinned($page) { + $pinned = blocks_get_pinned($page); + $user = blocks_get_by_page($page); + + $weights = array(); + + foreach ($pinned as $pos => $arr) { + $weights[$pos] = count($arr); + } + + foreach ($user as $pos => $blocks) { + if (!array_key_exists($pos,$pinned)) { + $pinned[$pos] = array(); + } + if (!array_key_exists($pos,$weights)) { + $weights[$pos] = 0; + } + foreach ($blocks as $block) { + $pinned[$pos][$weights[$pos]] = $block; + $weights[$pos]++; + } + } + return $pinned; } function blocks_get_by_page($page) { diff --git a/lib/weblib.php b/lib/weblib.php index 4c047428d38..0cf4132b45d 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -2246,14 +2246,15 @@ function user_login_string($course=NULL, $user=NULL) { * @param string $navigation The breadcrumbs string to be printed */ function print_navigation ($navigation) { - global $CFG; + global $CFG, $USER; if ($navigation) { if (! $site = get_site()) { $site->shortname = get_string('home'); } $navigation = str_replace('->', '»', $navigation); - echo ''. $site->shortname .' » '. $navigation; + echo ''. $site->shortname .' » '. $navigation; + } } @@ -3100,6 +3101,31 @@ function update_studentview_button($courseid) { } } +/** + * Returns a turn edit on/off button for course in a self contained form. + * Used to be an icon, but it's now a simple form button + * + * @uses $CFG + * @uses $USER + * @param int $courseid The course to update by id as found in 'course' table + * @return string + */ +function update_mymoodle_icon() { + + global $CFG, $USER; + + if (!empty($USER->editing)) { + $string = get_string('updatemymoodleoff'); + $edit = 'off'; + } else { + $string = get_string('updatemymoodleon'); + $edit = 'on'; + } + return "
framename\" method=\"get\" action=\"$CFG->wwwroot/my/index.php\">". + "". + "
"; +} + /** * Prints the editing button on a module "view" page * diff --git a/login/index.php b/login/index.php index 5a436307ea6..5c6f6066d1d 100644 --- a/login/index.php +++ b/login/index.php @@ -148,7 +148,10 @@ unset($SESSION->wantsurl); } else { - $urltogo = $CFG->wwwroot.'/'; /// Go to the standard home page + $urltogo = $CFG->wwwroot.'/my'; /// Go to the standard home page + if (isadmin()) { + $urltogo = $CFG->wwwroot; /// not needed by admins. + } unset($SESSION->wantsurl); /// Just in case } @@ -188,7 +191,10 @@ /// First, let's remember where the user was trying to get to before they got here if (empty($SESSION->wantsurl)) { - $SESSION->wantsurl = array_key_exists('HTTP_REFERER',$_SERVER) ? $_SERVER["HTTP_REFERER"] : $CFG->wwwroot; + $SESSION->wantsurl = (array_key_exists('HTTP_REFERER',$_SERVER) && + $_SERVER["HTTP_REFERER"] != $CFG->wwwroot && + $_SERVER["HTTP_REFERER"] != $CFG->wwwroot.'/') + ? $_SERVER["HTTP_REFERER"] : NULL; } if (!empty($loginurl)) { // We don't want the standard forms, go elsewhere diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 70efb7d9a22..8c75269547d 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -734,6 +734,33 @@ function forum_user_complete($course, $user, $mod, $forum) { } } +function forum_print_overview($course, $cm,$lastaccess) { + global $USER, $CFG; + $forum = get_record("forum","id","$cm->instance"); + $str = '' + .get_string('forum','forum').': '.$forum->name.'
'; + if ($numnew = count_records_select("log","time > $lastaccess AND " + ." course = $course->id AND " + ." module = 'forum' AND cmid = $cm->id " + ." AND action LIKE 'add %' AND userid != $USER->id")) { + $str .= get_string('overviewnumpostssince','forum',$numnew)."
"; + $p = 1; + } + if ($CFG->forum_trackreadposts) { + $groupid = ($groupmode==SEPARATEGROUPS && !isteacheredit($course->id)) ? $currentgroup : false; + $unread = forum_tp_count_forum_posts($forum->id, $groupid) - + forum_tp_count_forum_read_records($USER->id, $forum->id, $groupid); + if ($unread > 0) { + $a->unread = $unread; + $str .= get_string('overviewnumunread','forum',$unread).'
'; + $p = 1; + } + } + if (!empty($p)) { + echo $str; + } +} + function forum_print_recent_activity($course, $isteacher, $timestart) { /// Given a course and a date, prints a summary of all the new /// messages posted in the course since that date diff --git a/my/index.php b/my/index.php new file mode 100644 index 00000000000..5f640466283 --- /dev/null +++ b/my/index.php @@ -0,0 +1,67 @@ +libdir.'/blocklib.php'); + require_once('pagelib.php'); + + require_login(); + + $edit = optional_param('edit', ''); + $blockaction = optional_param('blockaction'); + + $PAGE = page_create_instance($USER->id); + + $pageblocks = blocks_get_by_page_pinned($PAGE); + if (!empty($blockaction)) { + blocks_execute_url_action($PAGE, $pageblocks); + // This re-query could be eliminated by judicious programming in blocks_execute_action(), + // but I 'm not sure if it's worth the complexity increase... + $pageblocks = blocks_get_by_page_pinned($PAGE); + } + + + if (!empty($edit) && $PAGE->user_allowed_editing()) { + if ($edit == 'on') { + $USER->editing = true; + } else if ($edit == 'off') { + $USER->editing = false; + } + } + + $PAGE->print_header(get_string('mymoodle','my')); + + echo ''; + echo ''; + + + $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210); + + if(blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing()) { + echo ''; + } + + echo ''; + + $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210); + + if(blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing()) { + echo ''; + } + + + /// Finish the page + echo '
'; + blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); + echo ''; + include('overview.php'); + echo ''; + blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT); + echo '
'; + + print_footer(); + + + +?> \ No newline at end of file diff --git a/my/overview.php b/my/overview.php new file mode 100644 index 00000000000..22cbe3524ba --- /dev/null +++ b/my/overview.php @@ -0,0 +1,23 @@ +id); +$site = get_site(); + +if (array_key_exists($site->id,$courses)) { + unset($courses[$site->id]); +} + +if (empty($courses)) { + print_simple_box(get_string('nocourses','my'),'center'); +} +else { + foreach ($courses as $course) { + print_overview($course); + } +} + +?> \ No newline at end of file diff --git a/my/pagelib.php b/my/pagelib.php new file mode 100644 index 00000000000..82a20479990 --- /dev/null +++ b/my/pagelib.php @@ -0,0 +1,89 @@ +libdir.'/pagelib.php'); + +class page_my_moodle extends page_base { + + function get_type() { + return PAGE_MY_MOODLE; + } + + function user_allowed_editing() { + page_id_and_class($id,$class); + if (isadmin() && $id == PAGE_ADMIN_MY_MOODLE) { + return true; + } elseif ($id == PAGE_MY_MOODLE) { + return true; + } + return false; + } + + function edit_always() { + page_id_and_class($id,$class); + return ($id == PAGE_ADMIN_MY_MOODLE && isadmin()); + } + + function user_is_editing() { + global $USER; + page_id_and_class($id,$class); + if (isadmin() && $id == PAGE_ADMIN_MY_MOODLE) { + return true; + } + return (!empty($USER->editing)); + } + + function print_header($title) { + + global $USER; + + $site = get_site(); + + $button = update_mymoodle_icon($USER->id); + $header = get_string('mymoodle','my'); + $nav = $header; + + $loggedinas = '

'. user_login_string($site) .'

'; + print_header($title, $header,$nav,'','',true, $button, $loggedinas); + + } + + function url_get_path() { + page_id_and_class($id,$class); + if ($id == PAGE_ADMIN_MY_MOODLE) { + return $GLOBALS['CFG']->wwwroot.'/admin/mymoodle.php'; + } + return $GLOBALS['CFG']->wwwroot.'/my/index.php'; + } + + function blocks_default_position() { + return BLOCK_POS_LEFT; + } + + function blocks_move_position(&$instance, $move) { + if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) { + return BLOCK_POS_RIGHT; + } else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) { + return BLOCK_POS_LEFT; + } + return $instance->position; + } + + function get_format_name() { + return MY_MOODLE_FORMAT; + } +} + + +define('PAGE_MY_MOODLE', 'my-index'); +define('PAGE_ADMIN_MY_MOODLE', 'admin-mymoodle'); +define('MY_MOODLE_FORMAT', 'my'); //doing this so we don't run into problems with applicable formats. + +page_map_class(PAGE_MY_MOODLE, 'page_my_moodle'); +page_map_class(PAGE_ADMIN_MY_MOODLE,'page_my_moodle'); + + + + +?> \ No newline at end of file