diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php index 1f466db1877..3187319af69 100644 --- a/lib/portfoliolib.php +++ b/lib/portfoliolib.php @@ -135,12 +135,16 @@ define('PORTFOLIO_TIME_HIGH', 'high'); * back to the callback functions (passed by reference) * these MUST be primatives to be added as hidden form fields. * and the values get cleaned to PARAM_ALPHAEXT or PARAM_NUMBER or PARAM_PATH +* @param string $callbackfile this can be autodetected if it's in the same file as your caller, +* but more often, the caller is a script.php and the class in a lib.php +* so you can pass it here if necessary. +* this path should be relative (ie, not include) dirroot * @param boolean $fullform either display the fullform with the dropmenu of available instances * or just a small icon (which will trigger instance selection in a new screen) * optional, defaults to true. * @param boolean $return whether to echo or return content (optional defaults to false (echo) */ -function portfolio_add_button($callbackclass, $callbackargs, $fullform=true, $return=false) { +function portfolio_add_button($callbackclass, $callbackargs, $callbackfile=null, $fullform=true, $return=false) { global $SESSION, $CFG, $COURSE, $USER; @@ -148,13 +152,20 @@ function portfolio_add_button($callbackclass, $callbackargs, $fullform=true, $re return; } - $backtrace = debug_backtrace(); - if (!array_key_exists(0, $backtrace) || !array_key_exists('file', $backtrace[0]) || !is_readable($backtrace[0]['file'])) { - debugging(get_string('nocallbackfile', 'portfolio')); - return; - } + if (empty($callbackfile)) { + $backtrace = debug_backtrace(); + if (!array_key_exists(0, $backtrace) || !array_key_exists('file', $backtrace[0]) || !is_readable($backtrace[0]['file'])) { + debugging(get_string('nocallbackfile', 'portfolio')); + return; + } - $callbackfile = substr($backtrace[0]['file'], strlen($CFG->dirroot)); + $callbackfile = substr($backtrace[0]['file'], strlen($CFG->dirroot)); + } else { + if (!is_readable($CFG->dirroot . $callbackfile)) { + debugging(get_string('nocallbackfile', 'portfolio')); + return; + } + } require_once($CFG->dirroot . $callbackfile); diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index c4d32032ce2..b0efd129fe6 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -1712,13 +1712,13 @@ class assignment_base { ''.$file.''; if ($this->portfolio_exportable() && true) { // @todo replace with capability check $p['file'] = $file; - $output .= portfolio_add_button('assignment_portfolio_caller', $p, false, true); + $output .= portfolio_add_button('assignment_portfolio_caller', $p, null, false, true); } $output .= '
'; } if ($this->portfolio_exportable() && true) { //@todo replace with check capability unset($p['file']);// for all files - $output .= '
' . portfolio_add_button('assignment_portfolio_caller', $p, true, true); + $output .= '
' . portfolio_add_button('assignment_portfolio_caller', $p, null, true, true); } } } @@ -3154,7 +3154,7 @@ class assignment_portfolio_caller extends portfolio_caller_base { return $status; } $filearea = $CFG->dataroot . '/' . $this->assignment->file_area_name($this->userid); - //@todo this is a dreadful thing to have to call. + //@todo penny this is a dreadful thing to have to call (replace with files api anyway) require_once($CFG->dirroot . '/backup/lib.php'); if ($this->file) { return backup_copy_file($filearea . '/' . $this->file, $tempdir . '/' . $this->file); diff --git a/mod/assignment/type/online/assignment.class.php b/mod/assignment/type/online/assignment.class.php index b7c9ca56940..b5316370ac0 100644 --- a/mod/assignment/type/online/assignment.class.php +++ b/mod/assignment/type/online/assignment.class.php @@ -101,13 +101,13 @@ class assignment_online extends assignment_base { $mform->display(); } else { print_box_start('generalbox boxwidthwide boxaligncenter', 'online'); - if ($submission) { + if ($submission && true) { // @todo penny replace with capability check later echo format_text($submission->data1, $submission->data2); $p = array( 'userid' => $USER->id, 'assignmentid' => $this->cm->id, ); - portfolio_add_button('assignment_portfolio_caller', $p); + portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php')); } else if (!has_capability('mod/assignment:submit', $context)) { //fix for #4604 echo '
'. get_string('guestnosubmit', 'assignment').'
'; } else if ($this->isopen()){ //fix for #4206 diff --git a/mod/assignment/type/upload/assignment.class.php b/mod/assignment/type/upload/assignment.class.php index c9753d2b857..1d68566c336 100644 --- a/mod/assignment/type/upload/assignment.class.php +++ b/mod/assignment/type/upload/assignment.class.php @@ -377,15 +377,15 @@ class assignment_upload extends assignment_base { $output .= ' ' .' '; } - if (true) { // @todo replace with capability check + if (true) { // @todo penny replace with capability check $p['file'] = $file; - $output .= portfolio_add_button('assignment_portfolio_caller', $p, false, true); + $output .= portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php', false, true); } $output .= '
'; } - if (true) { //@todo replace with check capability + if (true) { //@todo penny replace with check capability unset($p['file']);// for all files - $output .= '
' . portfolio_add_button('assignment_portfolio_caller', $p, true, true); + $output .= '
' . portfolio_add_button('assignment_portfolio_caller', $p, '/mod/assignment/lib.php', true, true); } } }