diff --git a/blog/blogpage.php b/blog/blogpage.php index e2cddaeed2f..78013076f2d 100644 --- a/blog/blogpage.php +++ b/blog/blogpage.php @@ -9,7 +9,6 @@ define('PAGE_BLOG_VIEW', 'blog-view'); class page_blog extends page_base { var $editing = false; - var $bloginfo = NULL; var $courserecord = NULL; var $courseid = NULL; @@ -49,7 +48,7 @@ class page_blog extends page_base { } // I need to determine how best to utilize this function. Most init // is already done before we get here in blogFilter and blogInfo - //$this->bloginfo =& new BlogInfo($this->id); + if ($this->courseid == 0 || $this->courseid == 1 || !is_numeric($this->courseid) ) { $this->courseid = ''; $courserecord = NULL; @@ -64,8 +63,6 @@ class page_blog extends page_base { // For this test page, only admins are going to be allowed editing (for simplicity). function user_allowed_editing() { if (isloggedin() && !isguest()) { - - //if (isadmin() || ((isset($this->bloginfo) && blog_user_has_rights($this->bloginfo))) || ($this->courseid != '' && isteacher($this->courseid)) ) { return true; } return false; @@ -76,7 +73,6 @@ class page_blog extends page_base { function user_is_editing() { if (isloggedin() && !isguest()) { - //if (isadmin() || ((isset($this->bloginfo) && blog_user_has_rights($this->bloginfo))) || ($this->courseid != '' && isteacher($this->courseid)) ) { global $SESSION; if (empty($SESSION->blog_editing_enabled)) { $SESSION->blog_editing_enabled = false; @@ -168,7 +164,7 @@ class page_blog extends page_base { global $SESSION, $CFG, $USER; $editformstring = ''; - if (blog_isLoggedin()) { + if (isloggedin() && !isguest()) { if (!empty($SESSION->blog_editing_enabled) && ($SESSION->blog_editing_enabled)) { $editingString = get_string('turneditingoff'); } else { diff --git a/blog/edit.php b/blog/edit.php index 2ad0277e6ad..9f408038581 100755 --- a/blog/edit.php +++ b/blog/edit.php @@ -23,39 +23,31 @@ if (isguest()) { } $userid = optional_param('userid', 0, PARAM_INT); -$editid = optional_param('editid', 0, PARAM_INT); + +// make sure that the person trying to edit have access right +if ($editid = optional_param('editid', 0, PARAM_INT)) { + + $blogEntry = get_record('post', 'id', $editid); + + if (!blog_user_can_edit_post($blogEntry)) { + error( get_string('notallowedtoedit', 'blog'), $CFG->wwwroot .'/login/index.php'); + } + +} //check to see if there is a requested blog to edit -if (!empty($userid) && $userid != 0) { - if (blog_isLoggedIn() && $userid == $USER->id ) { - ; // Daryl Hawes note: is this a placeholder for missing functionality? - } -} else if ( blog_isLoggedIn() ) { +if (isloggedin() && !isguest()) { //the user is logged in and have not specified a blog - so they will be editing their own //$tempBlogInfo = blog_user_bloginfo(); - $userid = $USER->id;//$tempBlogInfo->userid; + $userid = $USER->id; //$tempBlogInfo->userid; //unset($tempBlogInfo); //free memory from temp object - bloginfo will be created again in the included header } else { error(get_string('noblogspecified', 'blog') .'' .get_string('viewentries', 'blog') .''); } $pageNavigation = 'edit'; - include($CFG->dirroot .'/blog/header.php'); -//check if user is in blog's acl -if ( !blog_user_has_rights($editid) ) { - if ($editid != '') { - $blogEntry = get_record('post','id',$editid); - if (! (isteacher($blogEntry->$entryCourseId)) ) { -// error( get_string('notallowedtoedit'.' You do not teach in this course.', 'blog'), $CFG->wwwroot .'/login/index.php'); - error( get_string('notallowedtoedit', 'blog'), $CFG->wwwroot .'/login/index.php'); - } - } else { - error( get_string('notallowedtoedit', 'blog'), $CFG->wwwroot .'/login/index.php'); - } -} - //////////// SECURITY AND SETUP COMPLETE - NOW PAGE LOGIC /////////////////// if (isset($act) && ($act == 'del') && confirm_sesskey()) @@ -64,16 +56,17 @@ if (isset($act) && ($act == 'del') && confirm_sesskey()) if (optional_param('confirm',0,PARAM_INT)) { do_delete($postid); } else { + /// prints blog entry and what confirmation form echo '