'; + blocks_print_group($PAGE, $blocks, BLOCK_POS_LEFT); + echo ' | '; + + echo ''; + print_simple_box_start('center'); + print_heading($strtitle); + print_string('pinblocksexplan','my'); + print_simple_box_end(); + echo ' | '; + + + echo ''; + blocks_print_group($PAGE, $blocks, BLOCK_POS_RIGHT); + echo ' | '; + + echo '
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 ""; +} + /** * 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.''; + blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); + echo ' | '; + } + + echo ''; + include('overview.php'); + 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 ''; + blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT); + echo ' | '; + } + + + /// Finish the page + echo '
'. 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