function test_set_formats() { $button = new portfolio_add_button(); $button->set_callback_options('assignment_portfolio_caller', array('id' => 6), '/mod/assignment/lib.php'); $formats = array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_IMAGE); $button->set_formats($formats); $this->assertEqual(2, count($button->get_formats())); }
public function apply($discussion, $all, $selected, $formdata) { global $COURSE, $USER, $CFG; if (!$CFG->enableportfolios) { return ''; } /* * It is necessary to encode the array of selected discussion posts as text in order to * pass the data in the button callback options because it gets filtered as PARAM_ALPHA */ if (is_array($selected) && !empty($selected)) { $seltext = implode('x', $selected); $letters = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'); $posts = ''; $selarray = str_split($seltext); foreach ($selarray as $char) { $posts .= $char == 'x' ? $char : $letters[$char]; } } else { $posts = ''; } // get the id of the forum $forumobj = $discussion->get_forum(); $forumngid = $forumobj->get_id(); require_once $CFG->libdir . '/portfoliolib.php'; // check if the forum is shared and pass the cloneid in the callback options $linkparams = $discussion->get_link_params_array(); if (array_key_exists('clone', $linkparams)) { $cloneid = $linkparams['clone']; } else { $cloneid = 0; } $button = new portfolio_add_button(); $button->set_callback_options('forumng_all_portfolio_caller', array('forumngid' => $forumngid, 'cloneid' => $cloneid, 'posts' => $posts, 'discussionid' => $discussion->get_id()), 'mod_forumng'); $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); // redirect to the export page redirect($button->to_html(PORTFOLIO_ADD_FAKE_URL)); }
/** * Produces a list of portfolio links to the file recorded byuser * * @param $submissionid this submission's id * @return string the portfolio export link */ public function get_p_links($submissionid) { global $CFG, $OUTPUT, $DB; $output = ""; $fs = get_file_storage(); $files = $fs->get_area_files($this->assignment->get_context()->id, ASSIGNSUBMISSION_ONLINEPOODLL_COMPONENT, ASSIGNSUBMISSION_ONLINEPOODLL_FILEAREA, $submissionid, "id", false); if (!empty($files)) { require_once $CFG->dirroot . '/mod/assignment/locallib.php'; if ($CFG->enableportfolios) { require_once $CFG->libdir . '/portfoliolib.php'; } //Add portfolio download links if appropriate foreach ($files as $file) { if ($CFG->enableportfolios && has_capability('mod/assign:exportownsubmission', $this->assignment->get_context())) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('assign_portfolio_caller', array('cmid' => $this->assignment->get_course_module()->id, 'component' => "assignsubmission_onlinepoodll", 'area' => ASSIGNSUBMISSION_ONLINEPOODLL_FILEAREA, 'sid' => $submissionid), '/mod/assign/portfolio_callback.php'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_TEXT_LINK); } $output .= '<br />'; } } $output = '<div class="files" style="float:left;margin-left:5px;">' . $output . '</div><br clear="all" />'; return $output; }
if (empty($data->listtemplate)) { echo $OUTPUT->notification(get_string('nolisttemplate', 'data')); data_generate_default_template($data, 'listtemplate', 0, false, false); } echo $data->listtemplateheader; data_print_template('listtemplate', $records, $data, $search, $page); echo $data->listtemplatefooter; echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl); } } } $search = trim($search); if (empty($records)) { $records = array(); } if ($mode == '' && !empty($CFG->enableportfolios)) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id), '/mod/data/locallib.php'); if (data_portfolio_caller::has_files($data)) { $button->set_formats(array(PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_LEAP2A)); // no plain html for us } echo $button->to_html(PORTFOLIO_ADD_FULL_FORM); } //Advanced search form doesn't make sense for single (redirects list view) if (($maxcount || $mode == 'asearch') && $mode != 'single') { data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode); } } echo $OUTPUT->footer();
/** * Render the content in editor that is often used by plugin. * * @param string $filearea * @param int $submissionid * @param string $plugintype * @param string $editor * @param string $component * @return string */ public function render_editor_content($filearea, $submissionid, $plugintype, $editor, $component) { global $CFG; $result = ''; $plugin = $this->get_submission_plugin_by_type($plugintype); $text = $plugin->get_editor_text($editor, $submissionid); $format = $plugin->get_editor_format($editor, $submissionid); $finaltext = file_rewrite_pluginfile_urls($text, 'pluginfile.php', $this->get_context()->id, $component, $filearea, $submissionid); $params = array('overflowdiv' => true, 'context' => $this->get_context()); $result .= format_text($finaltext, $format, $params); if ($CFG->enableportfolios) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $portfolioparams = array('cmid' => $this->get_course_module()->id, 'sid' => $submissionid, 'plugin' => $plugintype, 'editor' => $editor, 'area' => $filearea); $button->set_callback_options('assign_portfolio_caller', $portfolioparams, 'mod_assign'); $fs = get_file_storage(); if ($files = $fs->get_area_files($this->context->id, $component, $filearea, $submissionid, 'timemodified', false)) { $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); } else { $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); } $result .= $button->to_html(); } return $result; }
/** * Produces a list of links to the files uploaded by a user * * @param $userid int optional id of the user. If 0 then $USER->id is used. * @param $return boolean optional defaults to false. If true the list is returned rather than printed * @return string optional */ function print_user_files($userid = 0, $return = false) { global $CFG, $USER, $OUTPUT; if (!$userid) { if (!isloggedin()) { return ''; } $userid = $USER->id; } $output = ''; $fs = get_file_storage(); $browser = get_file_browser(); $found = false; if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) { $button = new portfolio_add_button(); foreach ($files as $file) { $filename = $file->get_filename(); $found = true; $mimetype = $file->get_mimetype(); $path = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $this->context->id . '/assignment_submission/' . $userid . '/' . $filename); $output .= '<a href="' . $path . '" ><img src="' . $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)) . '" class="icon" alt="' . $mimetype . '" />' . s($filename) . '</a>'; if ($this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) { $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id())); $button->set_formats(portfolio_format_from_file($file)); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= '<br />'; } if (count($files) > 1 && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) { $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id)); $button->set_formats(PORTFOLIO_PORMAT_FILE); $output .= '<br />' . $button->to_html(); } } $output = '<div class="files">' . $output . '</div>'; if ($return) { return $output; } echo $output; }
} if ($iscomplete) { $completesessions++; } $sessionend = $message->timestamp; $sessionusers = array(); $sessionusers[$message->userid] = 1; } $lasttime = $message->timestamp; } echo '</div>'; if (!empty($CFG->enableportfolios) && $canexportsess) { require_once($CFG->libdir . '/portfoliolib.php'); $button = new portfolio_add_button(); $button->set_callback_options('chat_portfolio_caller', array('id' => $cm->id), 'mod_chat'); $button->render(null, get_string('addalltoportfolio', 'portfolio')); } if (!$showall and $completesessions == 0) { echo html_writer::start_tag('p'); echo get_string('no_complete_sessions_found', 'chat') . ' '; echo html_writer::link('report.php?id='.$cm->id.'&show_all=1', get_string('list_all_sessions', 'chat')); echo html_writer::end_tag('p'); } // Finish the page. echo $OUTPUT->footer();
/** * takes a list of records, the current data, a search string, * and mode to display prints the translated template * * @global object * @global object * @param string $template * @param array $records * @param object $data * @param string $search * @param int $page * @param bool $return * @param object $jumpurl a moodle_url by which to jump back to the record list (can be null) * @return mixed */ function data_print_template($template, $records, $data, $search = '', $page = 0, $return = false, moodle_url $jumpurl = null) { global $CFG, $DB, $OUTPUT; $cm = get_coursemodule_from_instance('data', $data->id); $context = context_module::instance($cm->id); static $fields = NULL; static $isteacher; static $dataid = NULL; if (empty($dataid)) { $dataid = $data->id; } else { if ($dataid != $data->id) { $fields = NULL; } } if (empty($fields)) { $fieldrecords = $DB->get_records('data_fields', array('dataid' => $data->id)); foreach ($fieldrecords as $fieldrecord) { $fields[] = data_get_field($fieldrecord, $data); } $isteacher = has_capability('mod/data:managetemplates', $context); } if (empty($records)) { return; } if (!$jumpurl) { $jumpurl = new moodle_url('/mod/data/view.php', array('d' => $data->id)); } $jumpurl = new moodle_url($jumpurl, array('page' => $page, 'sesskey' => sesskey())); // Check whether this activity is read-only at present $readonly = data_in_readonly_period($data); foreach ($records as $record) { // Might be just one for the single template // Replacing tags $patterns = array(); $replacement = array(); // Then we generate strings to replace for normal tags foreach ($fields as $field) { $patterns[] = '[[' . $field->field->name . ']]'; $replacement[] = highlight($search, $field->display_browse_field($record->id, $template)); } $canmanageentries = has_capability('mod/data:manageentries', $context); // Replacing special tags (##Edit##, ##Delete##, ##More##) $patterns[] = '##edit##'; $patterns[] = '##delete##'; if ($canmanageentries || !$readonly && data_isowner($record->id)) { $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/edit.php?d=' . $data->id . '&rid=' . $record->id . '&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="' . get_string('edit') . '" title="' . get_string('edit') . '" /></a>'; $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&delete=' . $record->id . '&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="' . get_string('delete') . '" title="' . get_string('delete') . '" /></a>'; } else { $replacement[] = ''; $replacement[] = ''; } $moreurl = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&rid=' . $record->id; if ($search) { $moreurl .= '&filter=1'; } $patterns[] = '##more##'; $replacement[] = '<a href="' . $moreurl . '"><img src="' . $OUTPUT->pix_url('t/preview') . '" class="iconsmall" alt="' . get_string('more', 'data') . '" title="' . get_string('more', 'data') . '" /></a>'; $patterns[] = '##moreurl##'; $replacement[] = $moreurl; $patterns[] = '##delcheck##'; if ($canmanageentries) { $replacement[] = html_writer::checkbox('delcheck[]', $record->id, false, '', array('class' => 'recordcheckbox')); } else { $replacement[] = ''; } $patterns[] = '##user##'; $replacement[] = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $record->userid . '&course=' . $data->course . '">' . fullname($record) . '</a>'; $patterns[] = '##userpicture##'; $ruser = user_picture::unalias($record, null, 'userid'); $replacement[] = $OUTPUT->user_picture($ruser, array('courseid' => $data->course)); $patterns[] = '##export##'; if (!empty($CFG->enableportfolios) && ($template == 'singletemplate' || $template == 'listtemplate') && (has_capability('mod/data:exportentry', $context) || data_isowner($record->id) && has_capability('mod/data:exportownentry', $context))) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'recordid' => $record->id), 'mod_data'); list($formats, $files) = data_portfolio_caller::formats($fields, $record); $button->set_formats($formats); $replacement[] = $button->to_html(PORTFOLIO_ADD_ICON_LINK); } else { $replacement[] = ''; } $patterns[] = '##timeadded##'; $replacement[] = userdate($record->timecreated); $patterns[] = '##timemodified##'; $replacement[] = userdate($record->timemodified); $patterns[] = '##approve##'; if (has_capability('mod/data:approve', $context) && $data->approval && !$record->approved) { $approveurl = new moodle_url($jumpurl, array('approve' => $record->id)); $approveicon = new pix_icon('t/approve', get_string('approve', 'data'), '', array('class' => 'iconsmall')); $replacement[] = html_writer::tag('span', $OUTPUT->action_icon($approveurl, $approveicon), array('class' => 'approve')); } else { $replacement[] = ''; } $patterns[] = '##disapprove##'; if (has_capability('mod/data:approve', $context) && $data->approval && $record->approved) { $disapproveurl = new moodle_url($jumpurl, array('disapprove' => $record->id)); $disapproveicon = new pix_icon('t/block', get_string('disapprove', 'data'), '', array('class' => 'iconsmall')); $replacement[] = html_writer::tag('span', $OUTPUT->action_icon($disapproveurl, $disapproveicon), array('class' => 'disapprove')); } else { $replacement[] = ''; } $patterns[] = '##comments##'; if ($template == 'listtemplate' && $data->comments) { if (!empty($CFG->usecomments)) { require_once $CFG->dirroot . '/comment/lib.php'; list($context, $course, $cm) = get_context_info_array($context->id); $cmt = new stdClass(); $cmt->context = $context; $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'database_entry'; $cmt->itemid = $record->id; $cmt->showcount = true; $cmt->component = 'mod_data'; $comment = new comment($cmt); $replacement[] = $comment->output(true); } } else { $replacement[] = ''; } // actual replacement of the tags $newtext = str_ireplace($patterns, $replacement, $data->{$template}); // no more html formatting and filtering - see MDL-6635 if ($return) { return $newtext; } else { echo $newtext; // hack alert - return is always false in singletemplate anyway ;-) /********************************** * Printing Ratings Form * *********************************/ if ($template == 'singletemplate') { //prints ratings options data_print_ratings($data, $record); } /********************************** * Printing Comments Form * *********************************/ if ($template == 'singletemplate' && $data->comments) { if (!empty($CFG->usecomments)) { require_once $CFG->dirroot . '/comment/lib.php'; list($context, $course, $cm) = get_context_info_array($context->id); $cmt = new stdClass(); $cmt->context = $context; $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'database_entry'; $cmt->itemid = $record->id; $cmt->showcount = true; $cmt->component = 'mod_data'; $comment = new comment($cmt); $comment->output(false); } } } } }
/** * * @global object * @global object * @global object * @param object $course * @param object $cm * @param object $glossary * @param object $entry * @param string $mode * @param string $hook * @param string $type * @return string|void */ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$hook='', $type = 'print') { global $USER, $CFG, $DB, $OUTPUT; $context = get_context_instance(CONTEXT_MODULE, $cm->id); $output = false; //To decide if we must really return text in "return". Activate when needed only! $importedentry = ($entry->sourceglossaryid == $glossary->id); $ismainglossary = $glossary->mainglossary; $return = '<span class="commands">'; // Differentiate links for each entry. $altsuffix = ': '.strip_tags(format_text($entry->concept)); if (!$entry->approved) { $output = true; $return .= get_string('entryishidden','glossary'); } $iscurrentuser = ($entry->userid == $USER->id); if (has_capability('mod/glossary:manageentries', $context) or (isloggedin() and has_capability('mod/glossary:write', $context) and $iscurrentuser)) { // only teachers can export entries so check it out if (has_capability('mod/glossary:export', $context) and !$ismainglossary and !$importedentry) { $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1,'course'=>$course->id)); if ( $mainglossary ) { // if there is a main glossary defined, allow to export the current entry $output = true; $return .= ' <a title="'.get_string('exporttomainglossary','glossary') . '" href="exportentry.php?id='.$entry->id.'&prevmode='.$mode.'&hook='.urlencode($hook).'"><img src="'.$OUTPUT->pix_url('export', 'glossary').'" class="iconsmall" alt="'.get_string('exporttomainglossary','glossary').$altsuffix.'" /></a>'; } } if ( $entry->sourceglossaryid ) { $icon = $OUTPUT->pix_url('minus', 'glossary'); // graphical metaphor (minus) for deleting an imported entry } else { $icon = $OUTPUT->pix_url('t/delete'); } //Decide if an entry is editable: // -It isn't a imported entry (so nobody can edit a imported (from secondary to main) entry)) and // -The user is teacher or he is a student with time permissions (edit period or editalways defined). $ineditperiod = ((time() - $entry->timecreated < $CFG->maxeditingtime) || $glossary->editalways); if ( !$importedentry and (has_capability('mod/glossary:manageentries', $context) or ($entry->userid == $USER->id and ($ineditperiod and has_capability('mod/glossary:write', $context))))) { $output = true; $return .= " <a title=\"" . get_string("delete") . "\" href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&prevmode=$mode&hook=".urlencode($hook)."\"><img src=\""; $return .= $icon; $return .= "\" class=\"iconsmall\" alt=\"" . get_string("delete") .$altsuffix."\" /></a> "; $return .= " <a title=\"" . get_string("edit") . "\" href=\"edit.php?cmid=$cm->id&id=$entry->id&mode=$mode&hook=".urlencode($hook)."\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" class=\"iconsmall\" alt=\"" . get_string("edit") .$altsuffix. "\" /></a>"; } elseif ( $importedentry ) { $return .= " <font size=\"-1\">" . get_string("exportedentry","glossary") . "</font>"; } } if (!empty($CFG->enableportfolios) && (has_capability('mod/glossary:exportentry', $context) || ($iscurrentuser && has_capability('mod/glossary:exportownentry', $context)))) { require_once($CFG->libdir . '/portfoliolib.php'); $button = new portfolio_add_button(); $button->set_callback_options('glossary_entry_portfolio_caller', array('id' => $cm->id, 'entryid' => $entry->id), '/mod/glossary/locallib.php'); $filecontext = $context; if ($entry->sourceglossaryid == $cm->instance) { if ($maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) { $filecontext = get_context_instance(CONTEXT_MODULE, $maincm->id); } } $fs = get_file_storage(); if ($files = $fs->get_area_files($filecontext->id, 'mod_glossary', 'attachment', $entry->id, "timemodified", false)) { $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); } else { $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); } $return .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $return .= " "; // just to make up a little the output in Mozilla ;) $return .= '</span>'; if (!empty($CFG->usecomments) && has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) { require_once($CFG->dirroot . '/comment/lib.php'); $cmt = new stdClass(); $cmt->component = 'mod_glossary'; $cmt->context = $context; $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'glossary_entry'; $cmt->itemid = $entry->id; $cmt->showcount = true; $comment = new comment($cmt); $return .= '<div>'.$comment->output(true).'</div>'; $output = true; } //If we haven't calculated any REAL thing, delete result ($return) if (!$output) { $return = ''; } //Print or get if ($type == 'print') { echo $return; } else { return $return; } }
/** * Returns attachments as formated text/html optionally with separate images * * @global object * @global object * @global object * @param object $post * @param object $cm * @param string $type html/text/separateimages * @return mixed string or array of (html text withouth images and image HTML) */ function forum_print_attachments($post, $cm, $type) { global $CFG, $DB, $USER, $OUTPUT; if (empty($post->attachment)) { return $type !== 'separateimages' ? '' : array('', ''); } if (!in_array($type, array('separateimages', 'html', 'text'))) { return $type !== 'separateimages' ? '' : array('', ''); } if (!($context = get_context_instance(CONTEXT_MODULE, $cm->id))) { return $type !== 'separateimages' ? '' : array('', ''); } $strattachment = get_string('attachment', 'forum'); $fs = get_file_storage(); $imagereturn = ''; $output = ''; $canexport = has_capability('mod/forum:exportpost', $context) || $post->userid == $USER->id && has_capability('mod/forum:exportownpost', $context); require_once $CFG->libdir . '/portfoliolib.php'; if ($files = $fs->get_area_files($context->id, 'mod_forum', 'attachment', $post->id, "timemodified", false)) { $button = new portfolio_add_button(); foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = '<img src="' . $OUTPUT->pix_url(file_mimetype_icon($mimetype)) . '" class="icon" alt="' . $mimetype . '" />'; $path = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $context->id . '/mod_forum/attachment/' . $post->id . '/' . $filename); if ($type == 'html') { $output .= "<a href=\"{$path}\">{$iconimage}</a> "; $output .= "<a href=\"{$path}\">" . s($filename) . "</a>"; if ($canexport) { $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), '/mod/forum/locallib.php'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= "<br />"; } else { if ($type == 'text') { $output .= "{$strattachment} " . s($filename) . ":\n{$path}\n"; } else { //'returnimages' if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // Image attachments don't get printed as links $imagereturn .= "<br /><img src=\"{$path}\" alt=\"\" />"; if ($canexport) { $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), '/mod/forum/locallib.php'); $button->set_format_by_file($file); $imagereturn .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } } else { $output .= "<a href=\"{$path}\">{$iconimage}</a> "; $output .= format_text("<a href=\"{$path}\">" . s($filename) . "</a>", FORMAT_HTML, array('context' => $context)); if ($canexport) { $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), '/mod/forum/locallib.php'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= '<br />'; } } } } } if ($type !== 'separateimages') { return $output; } else { return array($output, $imagereturn); } }
/** * Returns attachments as formated text/html optionally with separate images * * @global object * @global object * @global object * @param object $post * @param object $cm * @param string $type html/text/separateimages * @return mixed string or array of (html text withouth images and image HTML) */ function quora_print_attachments($post, $cm, $type) { global $CFG, $DB, $USER, $OUTPUT; if (empty($post->attachment)) { return $type !== 'separateimages' ? '' : array('', ''); } if (!in_array($type, array('separateimages', 'html', 'text'))) { return $type !== 'separateimages' ? '' : array('', ''); } if (!($context = context_module::instance($cm->id))) { return $type !== 'separateimages' ? '' : array('', ''); } $strattachment = get_string('attachment', 'quora'); $fs = get_file_storage(); $imagereturn = ''; $output = ''; $canexport = !empty($CFG->enableportfolios) && (has_capability('mod/quora:exportpost', $context) || $post->userid == $USER->id && has_capability('mod/quora:exportownpost', $context)); if ($canexport) { require_once $CFG->libdir . '/portfoliolib.php'; } // We retrieve all files according to the time that they were created. In the case that several files were uploaded // at the sametime (e.g. in the case of drag/drop upload) we revert to using the filename. $files = $fs->get_area_files($context->id, 'mod_quora', 'attachment', $post->id, "filename", false); if ($files) { if ($canexport) { $button = new portfolio_add_button(); } foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')); $path = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $context->id . '/mod_quora/attachment/' . $post->id . '/' . $filename); if ($type == 'html') { $output .= "<a href=\"{$path}\">{$iconimage}</a> "; $output .= "<a href=\"{$path}\">" . s($filename) . "</a>"; if ($canexport) { $button->set_callback_options('quora_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), 'mod_quora'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= "<br />"; } else { if ($type == 'text') { $output .= "{$strattachment} " . s($filename) . ":\n{$path}\n"; } else { //'returnimages' if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // Image attachments don't get printed as links $imagereturn .= "<br /><img src=\"{$path}\" alt=\"\" />"; if ($canexport) { $button->set_callback_options('quora_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), 'mod_quora'); $button->set_format_by_file($file); $imagereturn .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } } else { $output .= "<a href=\"{$path}\">{$iconimage}</a> "; $output .= format_text("<a href=\"{$path}\">" . s($filename) . "</a>", FORMAT_HTML, array('context' => $context)); if ($canexport) { $button->set_callback_options('quora_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), 'mod_quora'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= '<br />'; } } } if (!empty($CFG->enableplagiarism)) { require_once $CFG->libdir . '/plagiarismlib.php'; $output .= plagiarism_get_links(array('userid' => $post->userid, 'file' => $file, 'cmid' => $cm->id, 'course' => $cm->course, 'quora' => $cm->instance)); $output .= '<br />'; } } } if ($type !== 'separateimages') { return $output; } else { return array($output, $imagereturn); } }
function view() { global $USER; $edit = optional_param('edit', 0, PARAM_BOOL); $saved = optional_param('saved', 0, PARAM_BOOL); $context = get_context_instance(CONTEXT_MODULE, $this->cm->id); require_capability('mod/assignment:view', $context); $submission = $this->get_submission(); //Guest can not submit nor edit an assignment (bug: 4604) if (!has_capability('mod/assignment:submit', $context)) { $editable = null; } else { $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked); } $editmode = ($editable and $edit); if ($editmode) { //guest can not edit or submit assignment if (!has_capability('mod/assignment:submit', $context)) { print_error('guestnosubmit', 'assignment'); } } add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id); /// prepare form and process submitted data $mform = new mod_assignment_online_edit_form(); $defaults = new object(); $defaults->id = $this->cm->id; if (!empty($submission)) { if ($this->usehtmleditor) { $options = new object(); $options->smiley = false; $options->filter = false; $defaults->text = format_text($submission->data1, $submission->data2, $options); $defaults->format = FORMAT_HTML; } else { $defaults->text = $submission->data1; $defaults->format = $submission->data2; } } $mform->set_data($defaults); if ($mform->is_cancelled()) { redirect('view.php?id=' . $this->cm->id); } if ($data = $mform->get_data()) { // No incoming data? if ($editable && $this->update_submission($data)) { //TODO fix log actions - needs db upgrade $submission = $this->get_submission(); add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id); $this->email_teachers($submission); //redirect to get updated submission date and word count redirect('view.php?id=' . $this->cm->id . '&saved=1'); } else { // TODO: add better error message notify(get_string("error")); //submitting not allowed! } } /// print header, etc. and display form if needed if ($editmode) { $this->view_header(get_string('editmysubmission', 'assignment')); } else { $this->view_header(); } $this->view_intro(); $this->view_dates(); if ($saved) { notify(get_string('submissionsaved', 'assignment'), 'notifysuccess'); } if (has_capability('mod/assignment:submit', $context)) { if ($editmode) { print_box_start('generalbox', 'online'); $mform->display(); } else { print_box_start('generalbox boxwidthwide boxaligncenter', 'online'); if ($submission && has_capability('mod/assignment:exportownsubmission', $this->context)) { echo format_text($submission->data1, $submission->data2); $button = new portfolio_add_button(); $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/lib.php'); $button->render(); } else { if (!has_capability('mod/assignment:submit', $context)) { //fix for #4604 echo '<div style="text-align:center">' . get_string('guestnosubmit', 'assignment') . '</div>'; } else { if ($this->isopen()) { //fix for #4206 echo '<div style="text-align:center">' . get_string('emptysubmission', 'assignment') . '</div>'; } } } } print_box_end(); if (!$editmode && $editable) { echo "<div style='text-align:center'>"; print_single_button('view.php', array('id' => $this->cm->id, 'edit' => '1'), get_string('editmysubmission', 'assignment')); echo "</div>"; } } $this->view_feedback(); $this->view_footer(); }
if ($canoverride) { $displayassessment->add_action($workshop->assess_url($assessment->id), get_string('assessmentsettings', 'workshop')); } echo $output->render($displayassessment); if ($workshop->phase == workshop::PHASE_CLOSED and has_capability('mod/workshop:viewallassessments', $workshop->context)) { if (strlen(trim($assessment->feedbackreviewer)) > 0) { echo $output->render(new workshop_feedback_reviewer($assessment)); } } } } if (!$edit and $canoverride) { // display a form to override the submission grade $feedbackform->display(); } // If portfolios are enabled and we are not on the edit/removal confirmation screen, display a button to export this page. // The export is not offered if the submission is seen as a published one (it has no relation to the current user. if (!empty($CFG->enableportfolios)) { if (!$delete and !$edit and !$seenaspublished and $submission->id and ($ownsubmission or $canviewall or $isreviewer)) { if (has_capability('mod/workshop:exportsubmissions', $workshop->context)) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('mod_workshop_portfolio_caller', array('id' => $workshop->cm->id, 'submissionid' => $submission->id), 'mod_workshop'); $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); echo html_writer::start_tag('div', array('class' => 'singlebutton')); echo $button->to_html(PORTFOLIO_ADD_FULL_FORM, get_string('exportsubmission', 'workshop')); echo html_writer::end_tag('div'); } } } echo $output->footer();
public static function add_button($resource, $format = null, $return = false) { if (!has_capability('mod/resource:exportresource', get_context_instance(CONTEXT_MODULE, $resource->cm->id))) { return; } if (!is_callable(array($resource, 'portfolio_prepare_package')) || !is_callable(array($resource, 'portfolio_get_sha1'))) { debugging(get_string('portfolionotimplemented', 'resource')); return false; } $callersupports = array(self::type_to_format($resource->resource->type)); if ($resource->resource->type == 'file') { // $callersupports = array(portfolio_format_from_file($file); } $button = new portfolio_add_button(); $button->set_callback_options('resource_portfolio_caller', array('id' => $resource->cm->instance), '/mod/resource/lib.php'); $button->set_formats($callersupports); if ($return) { return $button->to_html($format); } $button->render($format); }
/** * Print a single blog post * * @param object $oublog Blog object * @param object $post Structure containing all post info and comments * @param string $baseurl Base URL of current page * @param string $blogtype Blog level ie course or above * @param bool $canmanageposts Has capability toggle * @param bool $canaudit Has capability toggle * @param bool $cancomment Has capability toggle * @param bool $forexport Export output rendering toggle * @param bool $email Email output rendering toggle * @return bool */ public function render_post($cm, $oublog, $post, $baseurl, $blogtype, $canmanageposts = false, $canaudit = false, $commentcount = true, $forexport = false, $format = false, $email = false) { global $CFG, $USER; $output = ''; $modcontext = context_module::instance($cm->id); // Get rid of any existing tag from the URL as we only support one at a time. $baseurl = preg_replace('~&tag=[^&]*~', '', $baseurl); $strcomment = get_string('comment', 'oublog'); $strtags = get_string('tags', 'oublog'); $stredit = get_string('edit', 'oublog'); $strdelete = get_string('delete', 'oublog'); $strpermalink = get_string('permalink', 'oublog'); $row = ''; if (isset($post->row)) { $row = $post->row % 2 ? 'oublog-odd' : 'oublog-even'; } $extraclasses = $post->deletedby ? ' oublog-deleted' : ''; $extraclasses .= ' oublog-hasuserpic'; $extraclasses .= ' ' . $row; $output .= html_writer::start_tag('div', array('class' => 'oublog-post' . $extraclasses)); $output .= html_writer::start_tag('div', array('class' => 'oublog-post-top')); $fs = get_file_storage(); if ($files = $fs->get_area_files($modcontext->id, 'mod_oublog', 'attachment', $post->id, "timemodified", false)) { $output .= html_writer::start_tag('div', array('class' => 'oublog-post-attachments')); $output .= get_string('attachments', 'mod_oublog') . ': '; foreach ($files as $file) { if (!$forexport && !$email) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = html_writer::empty_tag('img', array('src' => $this->output->pix_url(file_mimetype_icon($mimetype)), 'alt' => $mimetype, 'class' => 'icon')); if ($post->visibility == OUBLOG_VISIBILITY_PUBLIC) { $fileurlbase = '/mod/oublog/pluginfile.php'; } else { $fileurlbase = '/pluginfile.php'; } $filepath = '/' . $modcontext->id . '/mod_oublog/attachment/' . $post->id . '/' . $filename; $path = moodle_url::make_file_url($fileurlbase, $filepath, true); $output .= html_writer::start_tag('div', array('class' => 'oublog-post-attachment')); $output .= html_writer::tag('a', $iconimage, array('href' => $path)); $output .= html_writer::tag('a', s($filename), array('href' => $path)); $output .= html_writer::end_tag('div'); } else { $filename = $file->get_filename(); if (is_object($format)) { $output .= $format->file_output($file) . ' '; } else { $output .= $filename . ' '; } } } $output .= html_writer::end_tag('div'); } $output .= html_writer::start_tag('div', array('class' => 'oublog-post-top-content')); if (!$forexport) { $output .= html_writer::start_tag('div', array('class' => 'oublog-userpic')); $postuser = new object(); $postuser->id = $post->userid; $postuser->firstname = $post->firstname; $postuser->lastname = $post->lastname; $postuser->email = $post->email; $postuser->imagealt = $post->imagealt; $postuser->picture = $post->picture; $postuser->firstnamephonetic = $post->firstnamephonetic; $postuser->lastnamephonetic = $post->lastnamephonetic; $postuser->middlename = $post->middlename; $postuser->alternatename = $post->alternatename; $output .= $this->output->user_picture($postuser, array('courseid' => $oublog->course, 'size' => 70)); $output .= html_writer::end_tag('div'); } $output .= html_writer::start_tag('div', array('class' => 'oublog-post-top-details')); $formattedtitle = format_string($post->title); if (trim($formattedtitle) !== '') { $output .= html_writer::tag('h2', format_string($post->title), array('class' => 'oublog-title')); } else { if (!$forexport) { $posttitle = get_accesshide(get_string('newpost', 'mod_oublog', oublog_get_displayname($oublog))); $output .= html_writer::tag('h2', $posttitle, array('class' => 'oublog-title')); } } if ($post->deletedby) { $deluser = new stdClass(); // Get user name fields. $delusernamefields = get_all_user_name_fields(false, null, 'del'); foreach ($delusernamefields as $namefield => $retnamefield) { $deluser->{$namefield} = $post->{$retnamefield}; } $a = new stdClass(); $a->fullname = html_writer::tag('a', fullname($deluser), array('href' => $CFG->wwwroot . '/user/view.php?id=' . $post->deletedby)); $a->timedeleted = oublog_date($post->timedeleted); $output .= html_writer::tag('div', get_string('deletedby', 'oublog', $a), array('class' => 'oublog-post-deletedby')); } $output .= html_writer::start_tag('div', array('class' => 'oublog-post-date')); $output .= oublog_date($post->timeposted); $output .= html_writer::empty_tag('br', array()); $output .= ' '; if ($blogtype == 'course' || strpos($_SERVER['REQUEST_URI'], 'allposts.php') != 0) { $output .= html_writer::start_tag('div', array('class' => 'oublog-postedby')); if (!$forexport) { $output .= get_string('postedby', 'oublog', '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $post->userid . '&course=' . $oublog->course . '">' . fullname($post) . '</a>'); } else { $output .= get_string('postedby', 'oublog', fullname($post)); } $output .= html_writer::end_tag('div'); } $output .= html_writer::end_tag('div'); if (!$oublog->individual) { $output .= html_writer::start_tag('div', array('class' => 'oublog-post-visibility')); $output .= oublog_get_visibility_string($post->visibility, $blogtype == 'personal'); $output .= html_writer::end_tag('div'); } if (isset($post->edits) && ($canaudit || $post->userid == $USER->id)) { $output .= html_writer::start_tag('div', array('class' => 'oublog-post-editsummary')); foreach ($post->edits as $edit) { $a = new stdClass(); $a->editby = fullname($edit); $a->editdate = oublog_date($edit->timeupdated); if (!$forexport && !$email) { if ($edit->userid == $post->userid) { $output .= '- ' . html_writer::tag('a', get_string('editsummary', 'oublog', $a), array('href' => $CFG->wwwroot . '/mod/oublog/viewedit.php?edit=' . $edit->id)); } else { $output .= '- ' . html_writer::tag('a', get_string('editonsummary', 'oublog', $a), array('href' => $CFG->wwwroot . '/mod/oublog/viewedit.php?edit=' . $edit->id)); } } else { if ($edit->userid == $post->userid) { $output .= '- ' . get_string('editsummary', 'oublog', $a); } else { $output .= '- ' . get_string('editonsummary', 'oublog', $a); } } $output .= html_writer::empty_tag('br', array()); } $output .= html_writer::end_tag('div'); } else { if ($post->lasteditedby) { $edit = new StdClass(); // Get user name fields. $editusernamefields = get_all_user_name_fields(false, null, 'ed'); foreach ($editusernamefields as $namefield => $retnamefield) { $edit->{$namefield} = $post->{$retnamefield}; } $a = new stdClass(); $a->editby = fullname($edit); $a->editdate = oublog_date($post->timeupdated); $output .= html_writer::tag('div', get_string('editsummary', 'oublog', $a), array('class' => 'oublog-post-editsummary')); } } $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div'); $output .= html_writer::start_tag('div', array('class' => 'oublog-post-content')); if (!$forexport) { if ($post->visibility == OUBLOG_VISIBILITY_PUBLIC || $email) { $fileurlbase = 'mod/oublog/pluginfile.php'; } else { $fileurlbase = 'pluginfile.php'; } $post->message = file_rewrite_pluginfile_urls($post->message, $fileurlbase, $modcontext->id, 'mod_oublog', 'message', $post->id); } else { require_once $CFG->libdir . '/portfoliolib.php'; $post->message = portfolio_rewrite_pluginfile_urls($post->message, $modcontext->id, 'mod_oublog', 'message', $post->id, $format); } $posttextoptions = new stdClass(); if (trusttext_active() && has_capability('moodle/site:trustcontent', $modcontext, $post->userid)) { // Support trusted text when initial author is safe (post editors are not checked!). $posttextoptions->trusted = true; $posttextoptions->context = $modcontext; } $output .= format_text($post->message, FORMAT_HTML, $posttextoptions); $output .= html_writer::end_tag('div'); $output .= html_writer::start_tag('div', array('class' => 'oublog-post-bottom')); if (isset($post->tags)) { $output .= html_writer::start_tag('div', array('class' => 'oublog-post-tags')) . $strtags . ': '; $tagcounter = 1; foreach ($post->tags as $taglink) { $taglinktext = $taglink; if ($tagcounter < count($post->tags)) { $taglinktext .= ','; } if (!$forexport && !$email) { $output .= html_writer::tag('a', $taglinktext, array('href' => $baseurl . '&tag=' . urlencode($taglink))) . ' '; } else { $output .= $taglinktext . ' '; } $tagcounter++; } $output .= html_writer::end_tag('div'); } $output .= html_writer::start_tag('div', array('class' => 'oublog-post-links')); if (!$forexport && !$email) { $output .= html_writer::tag('a', $strpermalink, array('href' => $CFG->wwwroot . '/mod/oublog/viewpost.php?post=' . $post->id)) . ' '; } if (!$post->deletedby) { if ($post->userid == $USER->id || $canmanageposts) { if (!$forexport && !$email) { $output .= html_writer::tag('a', $stredit, array('href' => $CFG->wwwroot . '/mod/oublog/editpost.php?blog=' . $post->oublogid . '&post=' . $post->id)) . ' '; if ($post->userid !== $USER->id) { // Add email and 'oublog_deleteandemail' to delete link. $output .= html_writer::tag('a', $strdelete, array('href' => $CFG->wwwroot . '/mod/oublog/deletepost.php?blog=' . $post->oublogid . '&post=' . $post->id . '&delete=1', 'class' => 'oublog_deleteandemail_' . $post->id)); self::render_oublog_print_delete_dialog($cm->id, $post->id); } else { $output .= html_writer::tag('a', $strdelete, array('href' => $CFG->wwwroot . '/mod/oublog/deletepost.php?blog=' . $post->oublogid . '&post=' . $post->id . '&delete=1')); } } } // Show portfolio export link. if (!empty($CFG->enableportfolios) && (has_capability('mod/oublog:exportpost', $modcontext) || $post->userid == $USER->id && has_capability('mod/oublog:exportownpost', $modcontext))) { if (!$forexport && !$email) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('oublog_portfolio_caller', array('postid' => $post->id), 'mod_oublog'); if (empty($files)) { $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); } else { $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); } $output .= $button->to_html(PORTFOLIO_ADD_TEXT_LINK) . ' '; } } // Show OU Alerts reporting link. if (isloggedin() && oublog_oualerts_enabled() && oublog_get_reportingemail($oublog) && !($post->userid == $USER->id) && !$post->deletedby) { $itemnurl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id)); $reportlink = oualerts_generate_alert_form_url('oublog', $modcontext->id, 'post', $post->id, $itemnurl, $itemnurl, '', false, true); if ($reportlink != '' && !$forexport && !$email) { $output .= html_writer::tag('a', get_string('postalert', 'oublog'), array('href' => $reportlink)); } } // Show comments. if ($post->allowcomments) { // If this is the current user's post, show pending comments too. $showpendingcomments = $post->userid == $USER->id && !empty($post->pendingcomments); if ((isset($post->comments) || $showpendingcomments) && $commentcount) { // Show number of comments. if (isset($post->comments)) { $linktext = get_string(count($post->comments) == 1 ? 'onecomment' : 'ncomments', 'oublog', count($post->comments)); } // Show number of pending comments. if (isset($post->pendingcomments)) { // Use different string if we already have normal comments too. if (isset($post->comments)) { $linktext .= get_string($post->pendingcomments == 1 ? 'onependingafter' : 'npendingafter', 'oublog', $post->pendingcomments); } else { $linktext = get_string($post->pendingcomments == 1 ? 'onepending' : 'npending', 'oublog', $post->pendingcomments); } } if (!$forexport) { // Display link. $output .= html_writer::tag('a', $linktext, array('href' => $CFG->wwwroot . '/mod/oublog/viewpost.php?post=' . $post->id . '#oublogcomments')); } else { $output .= $linktext; } // Display information about most recent comment. if (isset($post->comments)) { $last = array_pop($post->comments); array_push($post->comments, $last); $a = new stdClass(); if ($last->userid) { $a->fullname = fullname($last); } else { $a->fullname = s($last->authorname); } $a->timeposted = oublog_date($last->timeposted, true); $output .= ' ' . get_string('lastcomment', 'oublog', $a); } } else { if (oublog_can_comment($cm, $oublog, $post)) { if (!$forexport && !$email) { $output .= html_writer::tag('a', $strcomment, array('href' => $CFG->wwwroot . '/mod/oublog/editcomment.php?blog=' . $post->oublogid . '&post=' . $post->id)); } } } } } $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('div'); return $output; }
if ($canaudit) { $canaudit = 1; } else { $canaudit = 0; } if (empty($oubloguser->id)) { $oubloguser->id = 0; } $tagid = null; if (!is_null($tag)) { // Make tag work with portfolio param cleaning by looking up id. if ($tagrec = $DB->get_record('oublog_tags', array('tag' => $tag), 'id')) { $tagid = $tagrec->id; } } $button = new portfolio_add_button(); $button->set_callback_options('oublog_all_portfolio_caller', array('postid' => $post->id, 'oublogid' => $oublog->id, 'offset' => $offset, 'currentgroup' => $currentgroup, 'currentindividual' => $currentindividual, 'oubloguserid' => $oubloguser->id, 'canaudit' => $canaudit, 'tag' => $tagid, 'cmid' => $cm->id), 'mod_oublog'); echo $button->to_html(PORTFOLIO_ADD_TEXT_LINK) . get_string('exportpostscomments', 'oublog'); } echo '</div>'; } // Print information allowing the user to log in if necessary, or letting // them know if there are no posts in the blog. if (isguestuser() && $USER->id == $user) { print '<p class="oublog_loginnote">' . get_string('guestblog', 'oublog', 'bloglogin.php?returnurl=' . urlencode($returnurl)) . '</p>'; } else { if (!isloggedin() || isguestuser()) { print '<p class="oublog_loginnote">' . get_string('maybehiddenposts', 'oublog', (object) array('link' => 'bloglogin.php?returnurl=' . urlencode($returnurl), 'name' => oublog_get_displayname($oublog))) . '</p>'; } else { if (!$posts) { print '<p class="oublog_noposts">' . get_string('noposts', 'oublog', oublog_get_displayname($oublog)) . '</p>';
$canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext); if (!$canreply and $forum->type !== 'news') { if (isguestuser() or !isloggedin()) { $canreply = true; } if (!is_enrolled($modcontext) and !is_viewing($modcontext)) { // allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link // normal users with temporary guest access see this link too, they are asked to enrol instead $canreply = enrol_selfenrol_available($course->id); } } /// Print the controls across the top echo '<div class="discussioncontrols clearfix">'; if (!empty($CFG->enableportfolios) && has_capability('mod/forum:exportdiscussion', $modcontext)) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('forum_portfolio_caller', array('discussionid' => $discussion->id), '/mod/forum/locallib.php'); $button = $button->to_html(PORTFOLIO_ADD_FULL_FORM, get_string('exportdiscussion', 'mod_forum')); $buttonextraclass = ''; if (empty($button)) { // no portfolio plugin available. $button = ' '; $buttonextraclass = ' noavailable'; } echo html_writer::tag('div', $button, array('class' => 'discussioncontrol exporttoportfolio' . $buttonextraclass)); } else { echo html_writer::tag('div', ' ', array('class' => 'discussioncontrol nullcontrol')); } // groups selector not needed here echo '<div class="discussioncontrol displaymode">'; forum_print_mode_form($discussion->id, $displaymode);
/** * Renders the 'export entire wiki' link. * @param object $subwiki Subwiki data object * @param bool $anyfiles True if any page of subwiki contains files * @return string HTML content of list item with link, or nothing if none */ public function render_export_all_li($subwiki, $anyfiles) { global $CFG; if (!$CFG->enableportfolios) { return ''; } require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('ouwiki_all_portfolio_caller', array('subwikiid' => $subwiki->id), '/mod/ouwiki/portfoliolib.php'); if ($anyfiles) { $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); } else { $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); } return html_writer::tag('li', $button->to_html(PORTFOLIO_ADD_TEXT_LINK)); }
function view() { global $OUTPUT, $CFG, $USER, $PAGE; $edit = optional_param('edit', 0, PARAM_BOOL); $saved = optional_param('saved', 0, PARAM_BOOL); $context = get_context_instance(CONTEXT_MODULE, $this->cm->id); require_capability('mod/assignment:view', $context); $submission = $this->get_submission($USER->id, false); //Guest can not submit nor edit an assignment (bug: 4604) if (!is_enrolled($this->context, $USER, 'mod/assignment:submit')) { $editable = false; } else { $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked); } $editmode = ($editable and $edit); if ($editmode) { // prepare form and process submitted data $editoroptions = array('noclean' => false, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $this->course->maxbytes); $data = new stdClass(); $data->id = $this->cm->id; $data->edit = 1; if ($submission) { $data->sid = $submission->id; $data->text = $submission->data1; $data->textformat = $submission->data2; } else { $data->sid = NULL; $data->text = ''; $data->textformat = NULL; } $data = file_prepare_standard_editor($data, 'text', $editoroptions, $this->context, 'mod_assignment', $this->filearea, $data->sid); $mform = new mod_assignment_online_edit_form(null, array($data, $editoroptions)); if ($mform->is_cancelled()) { redirect($PAGE->url); } if ($data = $mform->get_data()) { $submission = $this->get_submission($USER->id, true); //create the submission if needed & its id $data = file_postupdate_standard_editor($data, 'text', $editoroptions, $this->context, 'mod_assignment', $this->filearea, $submission->id); $submission = $this->update_submission($data); //TODO fix log actions - needs db upgrade add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id); $this->email_teachers($submission); //redirect to get updated submission date and word count redirect(new moodle_url($PAGE->url, array('saved' => 1))); } } add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id); /// print header, etc. and display form if needed if ($editmode) { $this->view_header(get_string('editmysubmission', 'assignment')); } else { $this->view_header(); } $this->view_intro(); $this->view_dates(); if ($saved) { echo $OUTPUT->notification(get_string('submissionsaved', 'assignment'), 'notifysuccess'); } if (is_enrolled($this->context, $USER)) { if ($editmode) { echo $OUTPUT->box_start('generalbox', 'onlineenter'); $mform->display(); } else { echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter', 'online'); if ($submission && has_capability('mod/assignment:exportownsubmission', $this->context)) { $text = file_rewrite_pluginfile_urls($submission->data1, 'pluginfile.php', $this->context->id, 'mod_assignment', $this->filearea, $submission->id); echo format_text($text, $submission->data2, array('overflowdiv' => true)); if ($CFG->enableportfolios) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php'); $fs = get_file_storage(); if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', $this->filearea, $submission->id, "timemodified", false)) { $button->set_formats(PORTFOLIO_FORMAT_RICHHTML); } else { $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); } $button->render(); } } else { if ($this->isopen()) { //fix for #4206 echo '<div style="text-align:center">' . get_string('emptysubmission', 'assignment') . '</div>'; } } } echo $OUTPUT->box_end(); if (!$editmode && $editable) { if (!empty($submission)) { $submitbutton = "editmysubmission"; } else { $submitbutton = "addsubmission"; } echo "<div style='text-align:center'>"; echo $OUTPUT->single_button(new moodle_url('view.php', array('id' => $this->cm->id, 'edit' => '1')), get_string($submitbutton, 'assignment')); echo "</div>"; } } $this->view_feedback(); $this->view_footer(); }
} if (!is_enrolled($modcontext) and !is_viewing($modcontext)) { // allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link // normal users with temporary guest access see this link too, they are asked to enrol instead $canreply = enrol_selfenrol_available($course->id); } } // Output the links to neighbour discussions. $neighbours = twf_get_discussion_neighbours($cm, $discussion); $neighbourlinks = $renderer->neighbouring_discussion_navigation($neighbours['prev'], $neighbours['next']); echo $neighbourlinks; /// Print the controls across the top echo '<div class="discussioncontrols clearfix">'; if (!empty($CFG->enableportfolios) && has_capability('mod/twf:exportdiscussion', $modcontext)) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('twf_portfolio_caller', array('discussionid' => $discussion->id), 'mod_twf'); $button = $button->to_html(PORTFOLIO_ADD_FULL_FORM, get_string('exportdiscussion', 'mod_twf')); $buttonextraclass = ''; if (empty($button)) { // no portfolio plugin available. $button = ' '; $buttonextraclass = ' noavailable'; } echo html_writer::tag('div', $button, array('class' => 'discussioncontrol exporttoportfolio' . $buttonextraclass)); } else { echo html_writer::tag('div', ' ', array('class' => 'discussioncontrol nullcontrol')); } // groups selector not needed here echo '<div class="discussioncontrol displaymode">'; twf_print_mode_form($discussion->id, $displaymode);
function referentiel_menu_certificat($context, $certificat_id, $referentiel_instance_id, $verrou, $userid = 0, $select_acc = 0, $rang = 0, $dossier_ferme) { global $CFG; global $OUTPUT; global $USER; $s = ""; $s .= '<tr valign="top">'; $s .= '<td align="center" colspan="6">' . "\n"; $s .= ' <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&select_acc=' . $select_acc . '&certificat_id=' . $certificat_id . '&userid=' . $userid . '&mode=listcertifsingle&sesskey=' . sesskey() . '#certificat_' . $certificat_id . '"><img src="' . $OUTPUT->pix_url('search', 'referentiel') . '" alt="' . get_string('plus', 'referentiel') . '" title="' . get_string('plus', 'referentiel') . '" /></a>' . "\n"; if (!$dossier_ferme) { $s .= ' <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&select_acc=' . $select_acc . '&certificat_id=' . $certificat_id . '&userid=' . $userid . '&mode=updatecertif&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('/t/edit') . '" alt="' . get_string('edit') . '" title="' . get_string('edit') . '" /></a>' . "\n"; } if (has_capability('mod/referentiel:comment', $context) && !$dossier_ferme) { // or referentiel_certificat_isowner($certificat_id)) { $s .= ' <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&select_acc=' . $select_acc . '&certificat_id=' . $certificat_id . '&userid=' . $userid . '&mode=commentcertif&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('feedback', 'referentiel') . '" alt="' . get_string('comment', 'referentiel') . '" title="' . get_string('comment', 'referentiel') . '" /></a>' . "\n"; } if (has_capability('mod/referentiel:managecertif', $context)) { $s .= ' <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&select_acc=' . $select_acc . '&certificat_id=' . $certificat_id . '&userid=' . $userid . '&mode=deletecertif&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('/t/delete') . '" alt="' . get_string('certificat_initialiser', 'referentiel') . '" title="' . get_string('certificat_initialiser', 'referentiel') . '" /></a>' . "\n"; if (!$dossier_ferme) { if ($verrou) { $s .= ' <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&select_acc=' . $select_acc . '&certificat_id=' . $certificat_id . '&userid=' . $userid . '&mode=deverrouiller&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('/t/go') . '" alt="' . get_string('deverrouiller', 'referentiel') . '" title="' . get_string('deverrouiller', 'referentiel') . '" /></a>' . "\n"; } else { $s .= ' <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&select_acc=' . $select_acc . '&certificat_id=' . $certificat_id . '&userid=' . $userid . '&mode=verrouiller&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('/t/stop') . '" alt="' . get_string('verrouiller', 'referentiel') . '" title="' . get_string('verrouiller', 'referentiel') . '" /></a>' . "\n"; } $s .= ' <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&select_acc=' . $select_acc . '&certificat_id=' . $certificat_id . '&userid=' . $userid . '&mode=clorecertificat&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('cadenas_f', 'referentiel') . '" alt="' . get_string('c_clore', 'referentiel') . '" title="' . get_string('c_clore', 'referentiel') . '" /></a>' . "\n"; } else { $s .= ' <a href="' . $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance_id . '&select_acc=' . $select_acc . '&certificat_id=' . $certificat_id . '&userid=' . $userid . '&mode=ouvrircertificat&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('cadenas_o', 'referentiel') . '" alt="' . get_string('c_ouvrir', 'referentiel') . '" title="' . get_string('c_ouvrir', 'referentiel') . '" /></a>' . "\n"; } if (referentiel_site_can_print_referentiel($referentiel_instance_id)) { $s .= ' <a href="' . $CFG->wwwroot . '/mod/referentiel/print_certificat.php?d=' . $referentiel_instance_id . '&select_acc=' . $select_acc . '&certificat_id=' . $certificat_id . '&userid=' . $userid . '&mode=printcertif&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('printer', 'referentiel') . '" alt="' . get_string('print', 'referentiel') . '" title="' . get_string('print', 'referentiel') . '" /></a>' . "\n"; } } // Portofolio if (!empty($CFG->enableportfolios)) { require_once $CFG->libdir . '/portfoliolib.php'; // Mahara export stuff $button = new portfolio_add_button(); // Version anterieure à Moodle 2.4 // $button->set_callback_options('referentiel_portfolio_caller', // array('instanceid' => $referentiel_instance_id, 'certificatid' => $certificat_id, 'report' => 0, 'export_format' => ''), '/mod/referentiel/portfolio/mahara/locallib_portfolio.php'); // Version Moodle 2.4 $button->set_callback_options('referentiel_portfolio_caller', array('instanceid' => $referentiel_instance_id, 'certificatid' => $certificat_id, 'report' => 0, 'export_format' => ''), 'mod_referentiel'); $button->set_formats(array(PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_LEAP2A)); $s .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); // Mahara ATranscript stuff // Ne pas activer pour le moment (juin 2012) car le developpement n'est pas achevé if (MAHARA_ARTEFACT_ATRANSCRIPT) { $button = new portfolio_add_button(); // Version antérieure à Moodle 2.4 // $button->set_callback_options('atranscript_portfolio_caller', // array('instanceid' => $referentiel_instance_id, 'userid' => $USER->id, 'certificatid' => $certificat_id, 'export_format' => PORTFOLIO_FORMAT_LEAP2A), '/mod/referentiel/portfolio/mahara/atranscript_artefact/locallib_portfolio.php'); // Version Moodle 2.4 $button->set_callback_options('atranscript_portfolio_caller', array('instanceid' => $referentiel_instance_id, 'userid' => $USER->id, 'certificatid' => $certificat_id, 'export_format' => PORTFOLIO_FORMAT_LEAP2A), 'mod_referentiel'); $button->set_formats(array(PORTFOLIO_FORMAT_LEAP2A)); $s .= $button->to_html(PORTFOLIO_ADD_ICON_LINK, get_string('atranscript', 'referentiel')); // $s.=$button->to_html(PORTFOLIO_ADD_TEXT_LINK); } } $s .= '</td></tr>' . "\n"; if ($rang % 2 == 0) { $s .= '<td class="couleur_paire" heigth="4" colspan="6"></td>' . "\n"; } else { $s .= '<td class="couleur_impaire" heigth="4" colspan="6"></td>' . "\n"; } return $s; }
/** * Preprocessing the file list to add the portfolio links if required. * * @param array $dir * @param string $filearea * @param string $component * @return void */ public function preprocess($dir, $filearea, $component) { global $CFG; foreach ($dir['subdirs'] as $subdir) { $this->preprocess($subdir, $filearea, $component); } foreach ($dir['files'] as $file) { $file->portfoliobutton = ''; if (!empty($CFG->enableportfolios)) { $button = new portfolio_add_button(); if (has_capability('mod/sepl:exportownsubmission', $this->context)) { $portfolioparams = array('cmid' => $this->cm->id, 'fileid' => $file->get_id()); $button->set_callback_options('sepl_portfolio_caller', $portfolioparams, 'mod_sepl'); $button->set_format_by_file($file); $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK); } } $path = '/' . $this->context->id . '/' . $component . '/' . $filearea . '/' . $file->get_itemid() . $file->get_filepath() . $file->get_filename(); $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", $path, true); $filename = $file->get_filename(); $file->fileurl = html_writer::link($url, $filename); } }
/** * takes a list of records, the current data, a search string, * and mode to display prints the translated template * * @global object * @global object * @param string $template * @param array $records * @param object $data * @param string $search * @param int $page * @param bool $return * @return mixed */ function data_print_template($template, $records, $data, $search='', $page=0, $return=false) { global $CFG, $DB, $OUTPUT; $cm = get_coursemodule_from_instance('data', $data->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id); static $fields = NULL; static $isteacher; static $dataid = NULL; if (empty($dataid)) { $dataid = $data->id; } else if ($dataid != $data->id) { $fields = NULL; } if (empty($fields)) { $fieldrecords = $DB->get_records('data_fields', array('dataid'=>$data->id)); foreach ($fieldrecords as $fieldrecord) { $fields[]= data_get_field($fieldrecord, $data); } $isteacher = has_capability('mod/data:managetemplates', $context); } if (empty($records)) { return; } foreach ($records as $record) { // Might be just one for the single template // Replacing tags $patterns = array(); $replacement = array(); // Then we generate strings to replace for normal tags foreach ($fields as $field) { $patterns[]='[['.$field->field->name.']]'; $replacement[] = highlight($search, $field->display_browse_field($record->id, $template)); } // Replacing special tags (##Edit##, ##Delete##, ##More##) $patterns[]='##edit##'; $patterns[]='##delete##'; if (has_capability('mod/data:manageentries', $context) or data_isowner($record->id)) { $replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/edit.php?d=' .$data->id.'&rid='.$record->id.'&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="'.get_string('edit').'" title="'.get_string('edit').'" /></a>'; $replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d=' .$data->id.'&delete='.$record->id.'&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="'.get_string('delete').'" title="'.get_string('delete').'" /></a>'; } else { $replacement[] = ''; $replacement[] = ''; } $moreurl = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&rid=' . $record->id; if ($search) { $moreurl .= '&filter=1'; } $patterns[]='##more##'; $replacement[] = '<a href="' . $moreurl . '"><img src="' . $OUTPUT->pix_url('i/search') . '" class="iconsmall" alt="' . get_string('more', 'data') . '" title="' . get_string('more', 'data') . '" /></a>'; $patterns[]='##moreurl##'; $replacement[] = $moreurl; $patterns[]='##user##'; $replacement[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$record->userid. '&course='.$data->course.'">'.fullname($record).'</a>'; $patterns[]='##export##'; if (!empty($CFG->enableportfolios) && ($template == 'singletemplate' || $template == 'listtemplate') && ((has_capability('mod/data:exportentry', $context) || (data_isowner($record->id) && has_capability('mod/data:exportownentry', $context))))) { require_once($CFG->libdir . '/portfoliolib.php'); $button = new portfolio_add_button(); $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'recordid' => $record->id), '/mod/data/locallib.php'); list($formats, $files) = data_portfolio_caller::formats($fields, $record); $button->set_formats($formats); $replacement[] = $button->to_html(PORTFOLIO_ADD_ICON_LINK); } else { $replacement[] = ''; } $patterns[] = '##timeadded##'; $replacement[] = userdate($record->timecreated); $patterns[] = '##timemodified##'; $replacement [] = userdate($record->timemodified); $patterns[]='##approve##'; if (has_capability('mod/data:approve', $context) && ($data->approval) && (!$record->approved)){ $replacement[] = '<span class="approve"><a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&approve='.$record->id.'&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('i/approve') . '" class="icon" alt="'.get_string('approve').'" /></a></span>'; } else { $replacement[] = ''; } $patterns[]='##comments##'; if (($template == 'listtemplate') && ($data->comments)) { if (!empty($CFG->usecomments)) { require_once($CFG->dirroot . '/comment/lib.php'); list($context, $course, $cm) = get_context_info_array($context->id); $cmt = new stdClass(); $cmt->context = $context; $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'database_entry'; $cmt->itemid = $record->id; $cmt->showcount = true; $cmt->component = 'mod_data'; $comment = new comment($cmt); $replacement[] = $comment->output(true); } } else { $replacement[] = ''; } // actual replacement of the tags $newtext = str_ireplace($patterns, $replacement, $data->{$template}); // no more html formatting and filtering - see MDL-6635 if ($return) { return $newtext; } else { echo $newtext; // hack alert - return is always false in singletemplate anyway ;-) /********************************** * Printing Ratings Form * *********************************/ if ($template == 'singletemplate') { //prints ratings options data_print_ratings($data, $record); } /********************************** * Printing Comments Form * *********************************/ if (($template == 'singletemplate') && ($data->comments)) { if (!empty($CFG->usecomments)) { require_once($CFG->dirroot . '/comment/lib.php'); list($context, $course, $cm) = get_context_info_array($context->id); $cmt = new stdClass(); $cmt->context = $context; $cmt->course = $course; $cmt->cm = $cm; $cmt->area = 'database_entry'; $cmt->itemid = $record->id; $cmt->showcount = true; $cmt->component = 'mod_data'; $comment = new comment($cmt); $comment->output(false); } } } } }
echo $data->listtemplatefooter; echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl); } } } $search = trim($search); if (empty($records)) { $records = array(); } if ($mode == '' && !empty($CFG->enableportfolios) && !empty($records)) { require_once($CFG->libdir . '/portfoliolib.php'); $button = new portfolio_add_button(); $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id), 'mod_data'); if (data_portfolio_caller::has_files($data)) { $button->set_formats(array(PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_LEAP2A)); // no plain html for us } echo $button->to_html(PORTFOLIO_ADD_FULL_FORM); } //Advanced search form doesn't make sense for single (redirects list view) if (($maxcount || $mode == 'asearch') && $mode != 'single') { data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode); } } echo $OUTPUT->footer();
/** * Produces a list of links to the files uploaded by a user * * @param $userid int optional id of the user. If 0 then $USER->id is used. * @param $return boolean optional defaults to false. If true the list is returned rather than printed * @return string optional */ function print_user_files($userid=0, $return=false) { global $CFG, $USER, $OUTPUT; if (!$userid) { if (!isloggedin()) { return ''; } $userid = $USER->id; } $output = ''; $fs = get_file_storage(); $found = false; $submission = $this->get_submission($userid); if (($submission) && $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) { require_once($CFG->libdir.'/portfoliolib.php'); require_once($CFG->dirroot . '/mod/assignment/locallib.php'); $button = new portfolio_add_button(); foreach ($files as $file) { $filename = $file->get_filename(); $found = true; $mimetype = $file->get_mimetype(); $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename); $output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'.s($filename).'</a>'; if ($this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) { $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= plagiarism_get_links(array('userid'=>$userid, 'file'=>$file, 'cmid'=>$this->cm->id, 'course'=>$this->course, 'assignment'=>$this->assignment)); $output .= '<br />'; } if (count($files) > 1 && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) { $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/locallib.php'); $output .= '<br />' . $button->to_html(); } } $output = '<div class="files">'.$output.'</div>'; if ($return) { return $output; } echo $output; }
public function preprocess($dir, $filearea) { global $CFG; foreach ($dir['subdirs'] as $subdir) { $this->preprocess($subdir, $filearea); } foreach ($dir['files'] as $file) { $file->portfoliobutton = ''; if (!empty($CFG->enableportfolios)) { $button = new portfolio_add_button(); if (has_capability('mod/assignment:exportownsubmission', $this->context)) { $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php'); $button->set_format_by_file($file); $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK); } } $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$this->context->id.'/mod_assignment/'.$filearea.'/'.$file->get_itemid(). $file->get_filepath().$file->get_filename(), true); $filename = $file->get_filename(); $file->fileurl = html_writer::link($url, $filename); } }
$canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext); if (!$canreply and $forum->type !== 'news') { if (isguestuser() or !isloggedin()) { $canreply = true; } if (!is_enrolled($modcontext) and !is_viewing($modcontext)) { // allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link // normal users with temporary guest access see this link too, they are asked to enrol instead $canreply = enrol_selfenrol_available($course->id); } } /// Print the controls across the top echo '<div class="discussioncontrols clearfix">'; if (!empty($CFG->enableportfolios) && has_capability('mod/forum:exportdiscussion', $modcontext)) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('forum_portfolio_caller', array('discussionid' => $discussion->id), 'mod_forum'); $button = $button->to_html(PORTFOLIO_ADD_FULL_FORM, get_string('exportdiscussion', 'mod_forum')); $buttonextraclass = ''; if (empty($button)) { // no portfolio plugin available. $button = ' '; $buttonextraclass = ' noavailable'; } echo html_writer::tag('div', $button, array('class' => 'discussioncontrol exporttoportfolio' . $buttonextraclass)); } else { echo html_writer::tag('div', ' ', array('class' => 'discussioncontrol nullcontrol')); } // groups selector not needed here echo '<div class="discussioncontrol displaymode">'; forum_print_mode_form($discussion->id, $displaymode);
echo $OUTPUT->box_start('glossarydisplay generalbox'); ?> <form action="exportfile.php" method="post"> <table border="0" cellpadding="6" cellspacing="6" width="100%"> <tr><td align="center"> <input type="submit" value="<?php p($strexportfile); ?> " /> </td></tr></table> <div> <input type="hidden" name="id" value="<?php p($id); ?> " /> <input type="hidden" name="cat" value="<?php p($cat); ?> " /> </div> </form> <?php // don't need cap check here, we share with the general export. if ($DB->count_records('glossary_entries', array('glossaryid' => $glossary->id))) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); $button->set_callback_options('glossary_csv_portfolio_caller', array('id' => $cm->id), '/mod/glossary/lib.php'); $button->render(); } echo $OUTPUT->box_end(); echo $OUTPUT->footer();
/** * Returns attachments as formated text/html optionally with separate images * * @global object * @global object * @global object * @param object $post * @param object $cm * @param string $type html/text/separateimages * @return mixed string or array of (html text withouth images and image HTML) */ function forum_print_attachments($post, $cm, $type) { global $CFG, $DB, $USER, $OUTPUT; if (empty($post->attachment)) { return $type !== 'separateimages' ? '' : array('', ''); } if (!in_array($type, array('separateimages', 'html', 'text'))) { return $type !== 'separateimages' ? '' : array('', ''); } if (!$context = context_module::instance($cm->id)) { return $type !== 'separateimages' ? '' : array('', ''); } $strattachment = get_string('attachment', 'forum'); $fs = get_file_storage(); $imagereturn = ''; $output = ''; $canexport = !empty($CFG->enableportfolios) && (has_capability('mod/forum:exportpost', $context) || ($post->userid == $USER->id && has_capability('mod/forum:exportownpost', $context))); if ($canexport) { require_once($CFG->libdir.'/portfoliolib.php'); } $files = $fs->get_area_files($context->id, 'mod_forum', 'attachment', $post->id, "timemodified", false); if ($files) { if ($canexport) { $button = new portfolio_add_button(); } foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')); $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/mod_forum/attachment/'.$post->id.'/'.$filename); if ($type == 'html') { $output .= "<a href=\"$path\">$iconimage</a> "; $output .= "<a href=\"$path\">".s($filename)."</a>"; if ($canexport) { $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), 'mod_forum'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= "<br />"; } else if ($type == 'text') { $output .= "$strattachment ".s($filename).":\n$path\n"; } else { //'returnimages' if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // Image attachments don't get printed as links $imagereturn .= "<br /><img src=\"$path\" alt=\"\" />"; if ($canexport) { $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), 'mod_forum'); $button->set_format_by_file($file); $imagereturn .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } } else { $output .= "<a href=\"$path\">$iconimage</a> "; $output .= format_text("<a href=\"$path\">".s($filename)."</a>", FORMAT_HTML, array('context'=>$context)); if ($canexport) { $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), 'mod_forum'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= '<br />'; } } if (!empty($CFG->enableplagiarism)) { require_once($CFG->libdir.'/plagiarismlib.php'); $output .= plagiarism_get_links(array('userid' => $post->userid, 'file' => $file, 'cmid' => $cm->id, 'course' => $post->course, 'forum' => $post->forum)); $output .= '<br />'; } } } if ($type !== 'separateimages') { return $output; } else { return array($output, $imagereturn); } }
function referentiel_get_manage_archives($contextid, $titre, $appli, $userid_filtre = 0, $instanceid = 0, $ok_portfolio = false, $report = false, $export_format = '') { // retourne la liste des liens vers des fichiers stockes dans le filearea // propose la suppression global $CFG; global $OUTPUT; // Archives older than REFERENTIEL_ARCHIVE_OBSOLETE days will be deleted. $delai_destruction = REFERENTIEL_ARCHIVE_OBSOLETE * 24 * 3600; $date_obsolete = time() - $delai_destruction; $msg = get_string('archive_deleted', 'referentiel', date("Y-m-d H:i:s.", $date_obsolete)); $s = ''; $total_size = 0; $nfile = 0; // fileareas autorisees $filearea = 'archive'; $strauthor = get_string('auteur', 'referentiel'); $strfilename = get_string('filename', 'referentiel'); $strfilesize = get_string('filesize', 'referentiel'); $strtimecreated = get_string('timecreated', 'referentiel'); $strtimemodified = get_string('timemodified', 'referentiel'); $strmimetype = get_string('mimetype', 'referentiel'); $strmenu = get_string('delete'); $strportfolio = get_string('publishporttfolio', 'referentiel'); $strurl = get_string('url'); // publication via potfolio if ($ok_portfolio) { require_once $CFG->libdir . '/portfoliolib.php'; } $fs = get_file_storage(); if ($files = $fs->get_area_files($contextid, 'mod_referentiel', $filearea, 0, "timemodified", false)) { $table = new html_table(); if ($ok_portfolio) { $table->head = array($strauthor, $strfilename, $strfilesize, $strtimecreated, $strtimemodified, $strmimetype, $strmenu, $strportfolio); $table->align = array("right", "center", "left", "left", "left", "center", "center", "center"); } else { $table->head = array($strauthor, $strfilename, $strfilesize, $strtimecreated, $strtimemodified, $strmimetype, $strmenu); $table->align = array("right", "center", "left", "left", "left", "center", "center"); } $ok = false; //drapeau d'affichage foreach ($files as $file) { // print_object($file); $filesize = $file->get_filesize(); $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $filepath = $file->get_filepath(); $iconimage = '<img src="' . $OUTPUT->pix_url(file_mimetype_icon($mimetype)) . '" class="icon" alt="' . $mimetype . '" />'; $userid = 0; $author = ''; $parts = explode('/', $filepath); if (is_array($parts)) { $refrefid = $parts[1]; if (isset($parts[2])) { $userid = trim($parts[2]); // echo "<br />USER:$userid\n"; $author = '#' . $userid . ' ' . referentiel_get_user_info($userid); } } $fullpath = '/' . $contextid . '/mod_referentiel/' . $filearea . '/' . '0' . $filepath . $filename; // echo "<br />FULPATH :: $fullpath \n"; $timecreated = userdate($file->get_timecreated(), "%Y/%m/%d-%H:%M", 99, false); $timemodified = userdate($file->get_timemodified(), "%Y/%m/%d-%H:%M", 99, false); $link = new moodle_url($CFG->wwwroot . '/pluginfile.php' . $fullpath); $url = ' <a href="' . $link . '" target="_blank">' . $iconimage . $filename . '</a><br />' . "\n"; $delete_link = '<input type="checkbox" name="deletefile[]" value="' . $fullpath . '" />' . "\n"; if ($userid && ($userid_filtre == 0 || $userid == $userid_filtre)) { // afficher ce fichier $ok = true; $output_button = ''; // Publish button if ($ok_portfolio) { $params = array('instanceid' => $instanceid, 'attachment' => $file->get_id(), 'report' => $report, 'export_format' => $export_format); // DEBUG /* echo "<br />DEBUG :: lib_archive.php :: 585 :: PARAM PORTFOLIO<br />\n"; print_object($params); echo "<br />\n"; // exit; */ $button = new portfolio_add_button(); // Version anterieure à Moodle 2.4 // $button->set_callback_options('referentiel_portfolio_caller', // $params, '/mod/referentiel/portfolio/mahara/locallib_portfolio.php'); // Version Moodle 2.4 $button->set_callback_options('referentiel_portfolio_caller', $params, 'mod_referentiel'); $button->set_format_by_file($file); // $button->set_formats(array(PORTFOLIO_FORMAT_FILE)); // $output_button = "<a href=\"$path\">$iconimage</a> "; $output_button .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); $table->data[] = array($author, $url, display_size($filesize), $timecreated, $timemodified, $mimetype, $delete_link, $output_button); } else { $table->data[] = array($author, $url, display_size($filesize), $timecreated, $timemodified, $mimetype, $delete_link); } $total_size += $filesize; $nfile++; } } if ($ok) { if ($ok_portfolio) { $table->data[] = array('', get_string('nbfile', 'referentiel', $nfile), get_string('totalsize', 'referentiel', display_size($total_size)), '', '', '', ''); } else { $table->data[] = array('', get_string('nbfile', 'referentiel', $nfile), get_string('totalsize', 'referentiel', display_size($total_size)), '', ''); } echo $OUTPUT->box_start('generalbox boxaligncenter'); echo '<div align="center">' . "\n"; echo '<h3>' . $titre . '</h3>' . "\n"; // message d'information echo '<p><i>' . $msg . '</i></p>' . "\n"; echo '<form method="post" action="' . $appli . '">' . "\n"; echo "\n" . '<input type="hidden" name="sesskey" value="' . sesskey() . '" />' . "\n"; echo '<div align="center">' . "\n"; echo '<input type="button" name="select_all_archive" id="select_tous_enseignants" value="' . get_string('select_all', 'referentiel') . '" onClick="return checkall()" />' . "\n"; // echo ' <input type="button" name="select_not_any_archive" id="select_aucun_enseignant" value="'.get_string('select_not_any', 'referentiel').'" onClick="return uncheckall()" />'."\n"; // echo '<input type="reset" value="'.get_string('corriger', 'referentiel').'" />'."\n"; echo ' <input type="reset" value="' . get_string('select_not_any', 'referentiel') . '" />' . "\n"; echo ' '; echo '<input type="submit" name="save" value="' . get_string('deletefile', 'referentiel') . '" />' . "\n"; echo '<input type="submit" name="cancel" value="' . get_string('quit', 'referentiel') . '" />' . "\n"; echo '</div>' . "\n"; echo html_writer::table($table); echo '<div align="center">' . "\n"; echo '<input type="button" name="select_all_archive" id="select_tous_enseignants" value="' . get_string('select_all', 'referentiel') . '" onClick="return checkall()" />' . "\n"; // echo ' <input type="button" name="select_not_any_archive" id="select_aucun_enseignant" value="'.get_string('select_not_any', 'referentiel').'" onClick="return uncheckall()" />'."\n"; // echo '<input type="reset" value="'.get_string('corriger', 'referentiel').'" />'."\n"; echo ' <input type="reset" value="' . get_string('select_not_any', 'referentiel') . '" />' . "\n"; echo ' '; echo '<input type="submit" name="save" value="' . get_string('deletefile', 'referentiel') . '" />' . "\n"; echo '<input type="submit" name="cancel" value="' . get_string('quit', 'referentiel') . '" />' . "\n"; echo '</div>' . "\n"; echo '</form>' . "\n"; echo '</div>' . "\n"; echo $OUTPUT->box_end(); } } }