/**
 * Returns the url of the first image contained in the course summary file area
 * @param  int $id the course id
 * @return string     the url to the image
 */
function block_my_course_progress_get_course_image_url($id)
{
    global $CFG;
    require_once $CFG->libdir . "/filelib.php";
    $course = get_course($id);
    if ($course instanceof stdClass) {
        require_once $CFG->libdir . '/coursecatlib.php';
        $course = new course_in_list($course);
    }
    foreach ($course->get_course_overviewfiles() as $file) {
        $isimage = $file->is_valid_image();
        if ($isimage) {
            return file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
        }
    }
    return false;
}
 protected function coursecat_coursebox_content(coursecat_helper $chelper, $course)
 {
     global $CFG;
     if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
         return '';
     }
     if ($course instanceof stdClass) {
         require_once $CFG->libdir . '/coursecatlib.php';
         $course = new course_in_list($course);
     }
     $content = '';
     // Display course overview files.
     $contentimages = $contentfiles = '';
     foreach ($course->get_course_overviewfiles() as $file) {
         $isimage = $file->is_valid_image();
         $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
         if ($isimage) {
             $contentimages .= html_writer::start_tag('div', array('class' => 'imagebox'));
             $images = html_writer::empty_tag('img', array('src' => $url, 'alt' => 'Course Image ' . $course->fullname, 'class' => 'courseimage'));
             $contentimages .= html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $images);
             $contentimages .= html_writer::end_tag('div');
         } else {
             $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
             $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
             $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon'));
         }
     }
     $content .= $contentimages . $contentfiles;
     // Display course summary.
     if ($course->has_summary()) {
         $content .= $chelper->get_course_formatted_summary($course);
     }
     // Display course contacts. See course_in_list::get_course_contacts().
     if ($course->has_course_contacts()) {
         $content .= html_writer::start_tag('ul', array('class' => 'teachers'));
         foreach ($course->get_course_contacts() as $userid => $coursecontact) {
             $name = $coursecontact['rolename'] . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $userid, 'course' => SITEID)), $coursecontact['username']);
             $content .= html_writer::tag('li', $name);
         }
         $content .= html_writer::end_tag('ul');
         // ...Teachers!.
     }
     return $content;
 }
 protected function mycourses($CFG, $sidebar)
 {
     $mycourses = enrol_get_users_courses($_SESSION['USER']->id);
     $courselist = array();
     foreach ($mycourses as $key => $val) {
         $courselist[] = $val->id;
     }
     $content = '';
     for ($x = 1; $x <= sizeof($courselist); $x++) {
         $course = get_course($courselist[$x - 1]);
         $title = $course->fullname;
         if ($course instanceof stdClass) {
             require_once $CFG->libdir . '/coursecatlib.php';
             $course = new course_in_list($course);
         }
         $url = $CFG->wwwroot . "/theme/keats/pix/coursenoimage.jpg";
         foreach ($course->get_course_overviewfiles() as $file) {
             $isimage = $file->is_valid_image();
             $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
             if (!$isimage) {
                 $url = $CFG->wwwroot . "/theme/keats/pix/coursenoimage.jpg";
             }
         }
         $content .= '<div class="view view-second view-mycourse ' . ($x % 3 == 0 ? 'view-nomargin' : '') . '">
                         <img src="' . $url . '" />
                         <div class="mask">
                             <h2>' . $title . '</h2>
                             <a href="' . $CFG->wwwroot . '/course/view.php?id=' . $courselist[$x - 1] . '" class="info">Enter</a>
                         </div>
                     </div>';
     }
     return $content;
 }
 /**
  * Internal function - creates htmls structure suitable for YUI tree.
  */
 protected function htmllize_tree($tree, $dir)
 {
     global $CFG;
     $yuiconfig = array();
     $yuiconfig['type'] = 'html';
     if (empty($dir['subdirs']) and empty($dir['files'])) {
         return '';
     }
     $result = '<ul>';
     foreach ($dir['subdirs'] as $subdir) {
         $image = $this->output->pix_icon("f/folder", $subdir['dirname'], 'moodle', array('class' => 'icon'));
         $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'><div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' . $this->htmllize_tree($tree, $subdir) . '</li>';
     }
     foreach ($dir['files'] as $file) {
         $url = file_encode_url("{$CFG->wwwroot}/blocks/csv_enrol/getfile.php", '/' . $tree->context->id . '/user/csvenrol' . $file->get_filepath() . $file->get_filename(), true);
         $filename = $file->get_filename();
         $icon = mimeinfo("icon", $filename);
         if (strlen($filename) > 10) {
             $pi = pathinfo($filename);
             $txt = $pi['filename'];
             $ext = $pi['extension'];
             $filename = substr($filename, 0, 14) . '...' . $ext;
         }
         $image = $this->output->pix_icon("f/{$icon}", $filename, 'moodle', array('class' => 'icon'));
         $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'><div>' . html_writer::link($url, $image . '&nbsp;' . $filename) . '</div></li>';
     }
     $result .= '</ul>';
     return $result;
 }
Example #5
0
/**
 * Internal function - creates htmls structure suitable for YUI tree.
 */
function imscp_htmllize_item($item, $imscp, $cm)
{
    global $CFG;
    if ($item['href']) {
        if (preg_match('|^https?://|', $item['href'])) {
            $url = $item['href'];
        } else {
            $context = context_module::instance($cm->id);
            $urlbase = "{$CFG->wwwroot}/pluginfile.php";
            $path = '/' . $context->id . '/mod_imscp/content/' . $imscp->revision . '/' . $item['href'];
            $url = file_encode_url($urlbase, $path, false);
        }
        $result = "<li><a href=\"{$url}\">" . $item['title'] . '</a>';
    } else {
        $result = '<li>' . $item['title'];
    }
    if ($item['subitems']) {
        $result .= '<ul>';
        foreach ($item['subitems'] as $subitem) {
            $result .= imscp_htmllize_item($subitem, $imscp, $cm);
        }
        $result .= '</ul>';
    }
    $result .= '</li>';
    return $result;
}
 public function get_content()
 {
     global $CFG;
     if ($this->content !== null) {
         return $this->content;
     }
     if (empty($this->instance)) {
         $this->content = '';
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     $this->content->text = '';
     // The user/index.php expect course context, so get one if page has module context.
     $currentcontext = $this->page->context->get_course_context(false);
     if (empty($currentcontext)) {
         return $this->content;
     }
     if ($this->page->course->id == SITEID) {
         $courses = self::get_featured_courses();
         require_once $CFG->libdir . '/coursecatlib.php';
         $chelper = new coursecat_helper();
         foreach ($courses as $course) {
             $course = new course_in_list($course);
             $this->content->text .= '<div class="container-fluid coursebox">';
             $content = '';
             $coursename = $chelper->get_course_formatted_name($course);
             $coursenamelink = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $coursename, array('class' => $course->visible ? '' : 'dimmed'));
             $content .= html_writer::tag('div', $coursenamelink, array('class' => 'coursename'));
             if ($course->has_summary()) {
                 $content .= html_writer::start_tag('div', array('class' => 'summary'));
                 $content .= $chelper->get_course_formatted_summary($course, array('overflowdiv' => true, 'noclean' => true, 'para' => false));
                 $content .= html_writer::end_tag('div');
             }
             // Display course overview files.
             $contentimages = $contentfiles = '';
             foreach ($course->get_course_overviewfiles() as $file) {
                 $isimage = $file->is_valid_image();
                 $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
                 if ($isimage) {
                     $contentimages .= html_writer::tag('div', html_writer::empty_tag('img', array('src' => $url, 'style' => 'max-height: 150px')), array('class' => 'courseimage'));
                 } else {
                     $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
                     $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
                     $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon'));
                 }
             }
             $content .= $contentimages . $contentfiles;
             $this->content->text .= $content . '</div>';
         }
     }
     return $this->content;
 }
Example #7
0
/**
 * Returns file link
 * @param object $file
 * @param object $folder
 * @param object $context
 * @return string html link
 */
function folder_get_file_link($file, $folder, $context)
{
    global $CFG;
    $strfile = get_string('file');
    $strdownload = get_string('download');
    $icon = mimeinfo_from_type("icon", $file->get_mimetype());
    $urlbase = "{$CFG->wwwroot}/pluginfile.php";
    $path = '/' . $context->id . '/folder_content/' . $folder->revision . $file->get_filepath() . $file->get_filename();
    $viewurl = file_encode_url($urlbase, $path, false);
    $downloadurl = file_encode_url($urlbase, $path, true);
    $downloadurl = "&nbsp;<a href=\"{$downloadurl}\" title=\"" . get_string('downloadfile') . "\"><img src=\"{$CFG->pixpath}/t/down.gif\" class=\"iconsmall\" alt=\"{$strdownload}\" /></a>";
    return "<a href=\"{$viewurl}\" title=\"\"><img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" />&nbsp;" . s($file->get_filename()) . '</a>' . $downloadurl;
}
 /**
  * Returns file download url
  * @param bool $forcedownload
  * @param bool $htts force https
  * @return string url
  */
 public function get_url($forcedownload = false, $https = false)
 {
     global $CFG;
     if (!$this->is_readable()) {
         return null;
     }
     if ($this->lf->is_directory()) {
         return null;
     }
     $filepath = $this->lf->get_filepath();
     $filename = $this->lf->get_filename();
     $courseid = $this->context->instanceid;
     $path = '/' . $courseid . $filepath . $filename;
     return file_encode_url($this->urlbase, $path, $forcedownload, $https);
 }
Example #9
0
 function print_student_answer($userid, $return = false)
 {
     global $CFG, $USER, $OUTPUT;
     $fs = get_file_storage();
     $browser = get_file_browser();
     $output = '';
     if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) {
         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 class="icon" src="' . $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)) . '" alt="' . $mimetype . '" />' . s($filename) . '</a><br />';
         }
     }
     $output = '<div class="files">' . $output . '</div>';
     return $output;
 }
/**
 * Internal function - creates htmls structure suitable for YUI tree.
 */
function imscp_htmllize_item($item, $imscp, $cm)
{
    global $CFG;
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    $urlbase = "{$CFG->wwwroot}/pluginfile.php";
    $path = '/' . $context->id . '/mod_imscp/content/' . $imscp->revision . '/' . $item['href'];
    $url = file_encode_url($urlbase, $path, false);
    $result = "<li><a href=\"{$url}\">" . $item['title'] . '</a>';
    if ($item['subitems']) {
        $result .= '<ul>';
        foreach ($item['subitems'] as $subitem) {
            $result .= imscp_htmllize_item($subitem, $imscp, $cm);
        }
        $result .= '</ul>';
    }
    $result .= '</li>';
    return $result;
}
Example #11
0
 /**
  * Internal function - creates htmls structure suitable for YUI tree.
  */
 protected function htmllize_tree($tree, $dir)
 {
     global $CFG;
     if (empty($dir['subdirs']) and empty($dir['files'])) {
         return '';
     }
     $result = '<ul>';
     foreach ($dir['subdirs'] as $subdir) {
         $result .= '<li>' . s($subdir['dirname']) . ' ' . $this->htmllize_tree($tree, $subdir) . '</li>';
     }
     foreach ($dir['files'] as $file) {
         $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $tree->context->id . '/mod_ubikc/content/' . $tree->ubikc->kcrevision . $file->get_filepath() . $file->get_filename(), true);
         $filename = $file->get_filename();
         $result .= '<li><span>' . html_writer::link($url, $filename) . '</span></li>';
     }
     $result .= '</ul>';
     return $result;
 }
 function print_student_answer($userid, $return = false)
 {
     global $CFG, $USER, $OUTPUT;
     $fs = get_file_storage();
     $browser = get_file_browser();
     $output = '';
     if ($submission = $this->get_submission($userid)) {
         if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) {
             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 . '" >' . $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')) . s($filename) . '</a><br />';
                 $output .= plagiarism_get_links(array('userid' => $userid, 'file' => $file, 'cmid' => $this->cm->id, 'course' => $this->course, 'assignment' => $this->assignment));
                 $output .= '<br/>';
             }
         }
     }
     $output = '<div class="files">' . $output . '</div>';
     return $output;
 }
Example #13
0
 /**
  * Internal function - creates htmls structure suitable for YUI tree.
  * @param user_files_tree $tree
  * @param array $dir
  * @return string HTML
  */
 protected function htmllize_tree($tree, $dir)
 {
     global $CFG;
     $yuiconfig = array();
     $yuiconfig['type'] = 'html';
     if (empty($dir['subdirs']) and empty($dir['files'])) {
         return '';
     }
     $result = '<ul>';
     foreach ($dir['subdirs'] as $subdir) {
         $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class' => 'icon'));
         $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'><div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' . $this->htmllize_tree($tree, $subdir) . '</li>';
     }
     foreach ($dir['files'] as $file) {
         $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $tree->context->id . '/user/private' . $file->get_filepath() . $file->get_filename(), true);
         $filename = $file->get_filename();
         $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class' => 'icon'));
         $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'><div>' . $image . ' ' . html_writer::link($url, $filename) . '</div></li>';
     }
     $result .= '</ul>';
     return $result;
 }
Example #14
0
/**
 * Export folder resource contents
 *
 * @return array of file content
 */
function folder_export_contents($cm, $baseurl)
{
    global $CFG, $DB;
    $contents = array();
    $context = context_module::instance($cm->id);
    $folder = $DB->get_record('folder', array('id' => $cm->instance), '*', MUST_EXIST);
    $fs = get_file_storage();
    $files = $fs->get_area_files($context->id, 'mod_folder', 'content', 0, 'sortorder DESC, id ASC', false);
    foreach ($files as $fileinfo) {
        $file = array();
        $file['type'] = 'file';
        $file['filename'] = $fileinfo->get_filename();
        $file['filepath'] = $fileinfo->get_filepath();
        $file['filesize'] = $fileinfo->get_filesize();
        $file['fileurl'] = file_encode_url("{$CFG->wwwroot}/" . $baseurl, '/' . $context->id . '/mod_folder/content/' . $folder->revision . $fileinfo->get_filepath() . $fileinfo->get_filename(), true);
        $file['timecreated'] = $fileinfo->get_timecreated();
        $file['timemodified'] = $fileinfo->get_timemodified();
        $file['sortorder'] = $fileinfo->get_sortorder();
        $file['userid'] = $fileinfo->get_userid();
        $file['author'] = $fileinfo->get_author();
        $file['license'] = $fileinfo->get_license();
        $contents[] = $file;
    }
    return $contents;
}
 public function top_promoted_courses()
 {
     global $CFG, $OUTPUT, $DB, $PAGE;
     $featuredcontent = '';
     /* Get Featured courses id from DB */
     $featuredids = theme_pioneer_get_setting('toppromotedcourses');
     $rcourseids = !empty($featuredids) ? explode(",", $featuredids, 10) : array();
     if (empty($rcourseids)) {
         return false;
     }
     $hcourseids = theme_pioneer_hidden_courses_ids();
     if (!empty($hcourseids)) {
         foreach ($rcourseids as $key => $val) {
             if (in_array($val, $hcourseids)) {
                 unset($rcourseids[$key]);
             }
         }
     }
     foreach ($rcourseids as $key => $val) {
         $ccourse = $DB->get_record('course', array('id' => $val));
         if (empty($ccourse)) {
             unset($rcourseids[$key]);
             continue;
         }
     }
     if (empty($rcourseids)) {
         return false;
     }
     $fcourseids = array_chunk($rcourseids, 10);
     $totalfcourse = count($fcourseids);
     $promotedtitle = theme_pioneer_get_setting('toppromotedtitle', 'format_text');
     $promotedtitle = theme_pioneer_lang($promotedtitle);
     $closelisting = theme_pioneer_get_setting('topclosefeatured', 'format_text');
     $topshowfeatured = theme_pioneer_get_setting('topshowfeatured', 'format_text');
     $featuredheader = '<div class="custom-courses-list" id="topPromoted-Courses">
                           <div class="container-fluid">
                          <div class="promoted_courses" data-crow="' . $totalfcourse . '">';
     $featuredfooter = ' </div>
                         </div>
                         </div>';
     if (!empty($fcourseids)) {
         echo '<div id="featured-listing" class="collapse out">';
         echo '<div data-toggle="collapse" data-target="#featured-listing" class="btn-link"style="text-align:center;">' . $closelisting . '</div>';
         foreach ($fcourseids as $courseids) {
             $rowcontent = '<div><div class="row-fluid topcarousel">';
             foreach ($courseids as $courseid) {
                 $course = get_course($courseid);
                 $no = get_config('theme_pioneer', 'toppatternselect');
                 $nimgp = empty($no) || $no == "default" ? 'no-image' : 'cs0' . $no . '/no-image';
                 $noimgurl = $OUTPUT->pix_url($nimgp, 'theme');
                 $courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
                 if ($course instanceof stdClass) {
                     require_once $CFG->libdir . '/coursecatlib.php';
                     $course = new course_in_list($course);
                 }
                 $imgurl = '';
                 $summary = theme_pioneer_strip_html_tags($course->summary);
                 $summary = theme_pioneer_course_trim_char($summary, 125);
                 $trimtitle = theme_pioneer_course_trim_char($course->fullname, 90);
                 $context = context_course::instance($course->id);
                 $nostudents = count_role_users(5, $context);
                 foreach ($course->get_course_overviewfiles() as $file) {
                     $isimage = $file->is_valid_image();
                     $imgurl = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
                     if (!$isimage) {
                         $imgurl = $noimgurl;
                     }
                 }
                 if (empty($imgurl)) {
                     $imgurl = $PAGE->theme->setting_file_url('headerbackgroundimage', 'headerbackgroundimage', true);
                     if (!$imgurl) {
                         $imgurl = $noimgurl;
                     }
                 }
                 $listitems = '
                 <div class="row-fluid">
                 <div class="span3">
                 <img src="' . $imgurl . '" width="100%" height="75px" alt="' . $course->fullname . '">
                 </div>
                 <div class="span5">
                 <h5><a href="' . $courseurl . '" >' . $trimtitle . '</a></h5>
                 </div>
                 <div class="span4">
                 <p>' . $summary . '</p>
                 </div>
                 </div>';
                 $coursehtml = '
                     <div style="background-image: url(' . $imgurl . ');background-repeat: no-repeat;background-size:cover; background-position:center;" class="promowrap">
                         <div class="fp-coursebox">
                             <div class="fp-courseinfo">
                                 <p style="font-size:24px;font-weight:bold;"><a href="' . $courseurl . '" id="button" data-toggle="tooltip" data-placement="bottom"title="' . $summary . '" >' . $trimtitle . '</a></p>
                             <div class="titlebar"> <h5>' . $promotedtitle . '</h5> </div>
                             <div data-toggle="collapse" data-target="#featured-listing" class="btn-link">' . $topshowfeatured . '</div>
                             </div>
                         </div>
                     </div>';
                 $rowcontent .= $coursehtml;
                 echo $listitems;
             }
             $rowcontent .= '</div></div> ';
             $featuredcontent .= $rowcontent;
         }
         echo "</div>";
     }
     $featuredcourses = $featuredheader . $featuredcontent . $featuredfooter;
     return $featuredcourses;
 }
Example #16
0
 /**
  * Gets the file data
  *
  * @param stored_file $file
  * @param int $entryid Attachment entry id
  */
 public function __construct($file, $entryid)
 {
     global $CFG;
     $this->file = $file;
     $this->filename = $file->get_filename();
     $this->url = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . SYSCONTEXTID . '/blog/attachment/' . $entryid . '/' . $this->filename);
 }
Example #17
0
 function display_browse_field($recordid, $template)
 {
     global $CFG, $DB;
     if (!($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid)))) {
         return false;
     }
     if (empty($content->content)) {
         return '';
     }
     $alt = $content->content1;
     $title = $alt;
     if ($template == 'listtemplate') {
         $src = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $this->context->id . '/mod_data/content/' . $content->id . '/' . 'thumb_' . $content->content);
         // no need to add width/height, because the thumb is resized properly
         $str = '<a href="view.php?d=' . $this->field->dataid . '&amp;rid=' . $recordid . '"><img src="' . $src . '" alt="' . s($alt) . '" title="' . s($title) . '" class="list_picture"/></a>';
     } else {
         $src = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $this->context->id . '/mod_data/content/' . $content->id . '/' . $content->content);
         $width = $this->field->param1 ? ' width="' . s($this->field->param1) . '" ' : ' ';
         $height = $this->field->param2 ? ' height="' . s($this->field->param2) . '" ' : ' ';
         $str = '<a href="' . $src . '"><img ' . $width . $height . ' src="' . $src . '" alt="' . s($alt) . '" title="' . s($title) . '" class="list_picture"/></a>';
     }
     return $str;
 }
Example #18
0
 /**
  * Get the URL of a file that belongs to a response variable of this
  * question_attempt.
  * @param stored_file $file the file to link to.
  * @return string the URL of that file.
  */
 public function get_response_file_url(stored_file $file)
 {
     return file_encode_url(new moodle_url('/pluginfile.php'), '/' . implode('/', array($file->get_contextid(), $file->get_component(), $file->get_filearea(), $this->usageid, $this->slot, $file->get_itemid())) . $file->get_filepath() . $file->get_filename(), true);
 }
 /**
  * Returns submissions for the requested seplment ids
  *
  * @param int[] $seplmentids
  * @param string $status only return submissions with this status
  * @param int $since only return submissions with timemodified >= since
  * @param int $before only return submissions with timemodified <= before
  * @return array of submissions for each requested seplment
  * @since Moodle 2.5
  */
 public static function get_submissions($seplmentids, $status = '', $since = 0, $before = 0)
 {
     global $DB, $CFG;
     require_once "{$CFG->dirroot}/mod/sepl/locallib.php";
     $params = self::validate_parameters(self::get_submissions_parameters(), array('seplmentids' => $seplmentids, 'status' => $status, 'since' => $since, 'before' => $before));
     $warnings = array();
     $seplments = array();
     // Check the user is allowed to get the submissions for the seplments requested.
     $placeholders = array();
     list($inorequalsql, $placeholders) = $DB->get_in_or_equal($params['seplmentids'], SQL_PARAMS_NAMED);
     $sql = "SELECT cm.id, cm.instance FROM {course_modules} cm JOIN {modules} md ON md.id = cm.module " . "WHERE md.name = :modname AND cm.instance " . $inorequalsql;
     $placeholders['modname'] = 'sepl';
     $cms = $DB->get_records_sql($sql, $placeholders);
     $sepls = array();
     foreach ($cms as $cm) {
         try {
             $context = context_module::instance($cm->id);
             self::validate_context($context);
             require_capability('mod/sepl:grade', $context);
             $sepl = new sepl($context, null, null);
             $sepls[] = $sepl;
         } catch (Exception $e) {
             $warnings[] = array('item' => 'seplment', 'itemid' => $cm->instance, 'warningcode' => '1', 'message' => 'No access rights in module context');
         }
     }
     foreach ($sepls as $sepl) {
         $submissions = array();
         $submissionplugins = $sepl->get_submission_plugins();
         $placeholders = array('seplid1' => $sepl->get_instance()->id, 'seplid2' => $sepl->get_instance()->id);
         $submissionmaxattempt = 'SELECT mxs.userid, MAX(mxs.attemptnumber) AS maxattempt
                                  FROM {sepl_submission} mxs
                                  WHERE mxs.seplment = :seplid1 GROUP BY mxs.userid';
         $sql = "SELECT mas.id, mas.seplment,mas.userid," . "mas.timecreated,mas.timemodified,mas.status,mas.groupid,mas.attemptnumber " . "FROM {sepl_submission} mas " . "JOIN ( " . $submissionmaxattempt . " ) smx ON mas.userid = smx.userid " . "WHERE mas.seplment = :seplid2 AND mas.attemptnumber = smx.maxattempt";
         if (!empty($params['status'])) {
             $placeholders['status'] = $params['status'];
             $sql = $sql . " AND mas.status = :status";
         }
         if (!empty($params['before'])) {
             $placeholders['since'] = $params['since'];
             $placeholders['before'] = $params['before'];
             $sql = $sql . " AND mas.timemodified BETWEEN :since AND :before";
         } else {
             $placeholders['since'] = $params['since'];
             $sql = $sql . " AND mas.timemodified >= :since";
         }
         $submissionrecords = $DB->get_records_sql($sql, $placeholders);
         if (!empty($submissionrecords)) {
             $fs = get_file_storage();
             foreach ($submissionrecords as $submissionrecord) {
                 $submission = array('id' => $submissionrecord->id, 'userid' => $submissionrecord->userid, 'timecreated' => $submissionrecord->timecreated, 'timemodified' => $submissionrecord->timemodified, 'status' => $submissionrecord->status, 'attemptnumber' => $submissionrecord->attemptnumber, 'groupid' => $submissionrecord->groupid);
                 foreach ($submissionplugins as $submissionplugin) {
                     $plugin = array('name' => $submissionplugin->get_name(), 'type' => $submissionplugin->get_type());
                     // Subtype is 'seplsubmission', type is currently 'file' or 'onlinetext'.
                     $component = $submissionplugin->get_subtype() . '_' . $submissionplugin->get_type();
                     $fileareas = $submissionplugin->get_file_areas();
                     foreach ($fileareas as $filearea => $name) {
                         $fileareainfo = array('area' => $filearea);
                         $files = $fs->get_area_files($sepl->get_context()->id, $component, $filearea, $submissionrecord->id, "timemodified", false);
                         foreach ($files as $file) {
                             $filepath = $file->get_filepath() . $file->get_filename();
                             $fileurl = file_encode_url($CFG->wwwroot . '/webservice/pluginfile.php', '/' . $sepl->get_context()->id . '/' . $component . '/' . $filearea . '/' . $submissionrecord->id . $filepath);
                             $fileinfo = array('filepath' => $filepath, 'fileurl' => $fileurl);
                             $fileareainfo['files'][] = $fileinfo;
                         }
                         $plugin['fileareas'][] = $fileareainfo;
                     }
                     $editorfields = $submissionplugin->get_editor_fields();
                     foreach ($editorfields as $name => $description) {
                         $editorfieldinfo = array('name' => $name, 'description' => $description, 'text' => $submissionplugin->get_editor_text($name, $submissionrecord->id), 'format' => $submissionplugin->get_editor_format($name, $submissionrecord->id));
                         $plugin['editorfields'][] = $editorfieldinfo;
                     }
                     $submission['plugins'][] = $plugin;
                 }
                 $submissions[] = $submission;
             }
         } else {
             $warnings[] = array('item' => 'module', 'itemid' => $sepl->get_instance()->id, 'warningcode' => '3', 'message' => 'No submissions found');
         }
         $seplments[] = array('seplmentid' => $sepl->get_instance()->id, 'submissions' => $submissions);
     }
     $result = array('seplments' => $seplments, 'warnings' => $warnings);
     return $result;
 }
Example #20
0
 /**
  * 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;
 }
Example #21
0
 /**
  * if return=html, then return a html string.
  * if return=text, then return a text-only string.
  * otherwise, print HTML for non-images, and return image HTML
  *
  * @param bool $return Whether to return or print the generated code
  * @return void
  */
 public function print_attachments($return = false)
 {
     global $CFG, $OUTPUT;
     require_once $CFG->libdir . '/filelib.php';
     $fs = get_file_storage();
     $syscontext = get_context_instance(CONTEXT_SYSTEM);
     $files = $fs->get_area_files($syscontext->id, 'blog', 'attachment', $this->id);
     $imagereturn = "";
     $output = "";
     $strattachment = get_string("attachment", "forum");
     foreach ($files as $file) {
         if ($file->is_directory()) {
             continue;
         }
         $filename = $file->get_filename();
         $ffurl = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . SYSCONTEXTID . '/blog/attachment/' . $this->id . '/' . $filename);
         $mimetype = $file->get_mimetype();
         $icon = mimeinfo_from_type("icon", $mimetype);
         $type = mimeinfo_from_type("type", $mimetype);
         $image = $OUTPUT->pix_icon("f/{$icon}", $filename, 'moodle', array('class' => 'icon'));
         if ($return == "html") {
             $output .= html_writer::link($ffurl, $image);
             $output .= html_writer::link($ffurl, $filename);
         } else {
             if ($return == "text") {
                 $output .= "{$strattachment} {$filename}:\n{$ffurl}\n";
             } else {
                 if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
                     // Image attachments don't get printed as links
                     $imagereturn .= "<br />" . $OUTPUT->pix_icon($ffurl, $filename);
                 } else {
                     $imagereturn .= html_writer::link($ffurl, $image);
                     $imagereturn .= format_text(html_writer::link($ffurl, $filename), FORMAT_HTML, array('context' => $syscontext));
                 }
             }
         }
     }
     if ($return) {
         return $output;
     }
     return $imagereturn;
 }
Example #22
0
    /**
     * 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;
    }
Example #23
0
/**
 * Produces a list of links to the issued certificates.  Used for report.
 *
 * @param stdClass $certificate
 * @param int $userid
 * @param stdClass $context
 * @return boolean, true if success printing
 */
function certificate_print_user_files($certificate, $userid, $context)
{
    global $CFG, $DB, $OUTPUT;
    $output = '';
    $certrecord = certificate_get_latest_issue($certificate->id, $userid);
    $fs = get_file_storage();
    $browser = get_file_browser();
    $component = 'mod_certificate';
    $filearea = 'issue';
    $files = $fs->get_area_files($context, $component, $filearea, $certrecord->id);
    foreach ($files as $file) {
        $filename = $file->get_filename();
        $mimetype = $file->get_mimetype();
        $link = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $context . '/mod_certificate/issue/' . $certrecord->id . '/' . $filename);
        $output = '<img src="' . $OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype())) . '" height="16" width="16" alt="' . $file->get_mimetype() . '" />&nbsp;' . '<a href="' . $link . '" >' . s($filename) . '</a>';
    }
    $output .= '<br />';
    $output = '<div class="files">' . $output . '</div>';
    return $output;
}
Example #24
0
 public function test_encodepath()
 {
     global $CFG;
     $fb = new file_browser();
     $CFG->slasharguments = true;
     $this->assertEqual('http://test.url.com/path/to/page.php', file_encode_url('http://test.url.com', '/path/to/page.php'));
     $this->assertEqual('http://test.url.com/path/to/page.php?forcedownload=1', file_encode_url('http://test.url.com', '/path/to/page.php', true));
     $this->assertEqual('https://test.url.com/path/to/page.php?forcedownload=1', file_encode_url('http://test.url.com', '/path/to/page.php', true, true));
     // TODO add error checking for malformed path (does method support get variables?)
     $this->assertEqual('http://test.url.com/path/to/page.php?var1=value1&var2=value2', file_encode_url('http://test.url.com', '/path/to/page.php?var1=value1&var2=value2'));
     $this->assertEqual('http://test.url.com/path/to/page.php?var1=value1&var2=value2&forcedownload=1', file_encode_url('http://test.url.com', '/path/to/page.php?var1=value1&var2=value2', true));
     $CFG->slasharguments = false;
     $this->assertEqual('http://test.url.com?file=%2Fpath%2Fto%2Fpage.php', file_encode_url('http://test.url.com', '/path/to/page.php'));
     $this->assertEqual('http://test.url.com?file=%2Fpath%2Fto%2Fpage.php&amp;forcedownload=1', file_encode_url('http://test.url.com', '/path/to/page.php', true));
     $this->assertEqual('https://test.url.com?file=%2Fpath%2Fto%2Fpage.php&amp;forcedownload=1', file_encode_url('http://test.url.com', '/path/to/page.php', true, true));
 }
Example #25
0
/**
 * Display fullname and shortname of course
 * @author André Rodrigues <Math>
 * @date 2015/12/19
 */
$actual_link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
if (strpos($actual_link, $CFG->wwwroot . '/course') !== false) {
    // if ($PAGE->course->category != 0) {
    if (isset($_GET['id'])) {
        $courseid = $_GET['id'];
        $c = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
        $course = new course_in_list($c);
        $url = '';
        foreach ($course->get_course_overviewfiles() as $file) {
            $isimage = $file->is_valid_image();
            $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
        }
        echo '<div>';
        echo '<img src="' . $url . '" />';
        echo '</div>';
        echo '<div>';
        echo '<p>' . $PAGE->course->fullname . '</p>';
        echo '<p>' . $PAGE->course->shortname . '</p>';
        echo '</div>';
    }
}
?>
           <script>
            $(function() {
              $('.seal').css('margin-left', '100px');
              $('.seal').css('float', 'left');
Example #26
0
 /**
  * Returns HTML to display course content (summary, course contacts and optionally category name)
  *
  * This method is called from coursecat_coursebox() and may be re-used in AJAX
  *
  * @param coursecat_helper $chelper various display options
  * @param stdClass|course_in_list $course
  * @return string
  */
 protected function coursecat_coursebox_content(coursecat_helper $chelper, $course)
 {
     global $CFG;
     if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
         return '';
     }
     if ($course instanceof stdClass) {
         require_once $CFG->libdir . '/coursecatlib.php';
         $course = new course_in_list($course);
     }
     $content = '';
     // display course summary
     if ($course->has_summary()) {
         $content .= html_writer::start_tag('div', array('class' => 'summary'));
         $content .= $chelper->get_course_formatted_summary($course, array('overflowdiv' => true, 'noclean' => true, 'para' => false));
         $content .= html_writer::end_tag('div');
         // .summary
     }
     // display course overview files
     $contentimages = $contentfiles = '';
     foreach ($course->get_course_overviewfiles() as $file) {
         $isimage = $file->is_valid_image();
         $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
         if ($isimage) {
             $contentimages .= html_writer::tag('div', html_writer::empty_tag('img', array('src' => $url)), array('class' => 'courseimage'));
         } else {
             $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
             $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
             $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon'));
         }
     }
     $content .= $contentimages . $contentfiles;
     // display course contacts. See course_in_list::get_course_contacts()
     if ($course->has_course_contacts()) {
         $content .= html_writer::start_tag('ul', array('class' => 'teachers'));
         foreach ($course->get_course_contacts() as $userid => $coursecontact) {
             $name = $coursecontact['rolename'] . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $userid, 'course' => SITEID)), $coursecontact['username']);
             $content .= html_writer::tag('li', $name);
         }
         $content .= html_writer::end_tag('ul');
         // .teachers
     }
     // display course category if necessary (for example in search results)
     if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) {
         require_once $CFG->libdir . '/coursecatlib.php';
         if ($cat = coursecat::get($course->category, IGNORE_MISSING)) {
             $content .= html_writer::start_tag('div', array('class' => 'coursecat'));
             $content .= get_string('category') . ': ' . html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)), $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
             $content .= html_writer::end_tag('div');
             // .coursecat
         }
     }
     return $content;
 }
Example #27
0
/**
 * 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);
    }
}
Example #28
0
 /**
  * Renders a list of files attached to the submission
  *
  * If format==html, then format a html string. If format==text, then format a text-only string.
  * Otherwise, returns html for non-images and html to display the image inline.
  *
  * @param int $submissionid submission identifier
  * @param string format the format of the returned string - html|text
  * @return string formatted text to be echoed
  */
 protected function helper_submission_attachments($submissionid, $format = 'html')
 {
     global $CFG;
     require_once $CFG->libdir . '/filelib.php';
     $fs = get_file_storage();
     $ctx = $this->page->context;
     $files = $fs->get_area_files($ctx->id, 'mod_workshop', 'submission_attachment', $submissionid);
     $outputimgs = '';
     // images to be displayed inline
     $outputfiles = '';
     // list of attachment files
     foreach ($files as $file) {
         if ($file->is_directory()) {
             continue;
         }
         $filepath = $file->get_filepath();
         $filename = $file->get_filename();
         $fileurl = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $ctx->id . '/mod_workshop/submission_attachment/' . $submissionid . $filepath . $filename, true);
         $type = $file->get_mimetype();
         $type = mimeinfo_from_type('type', $type);
         $image = html_writer::empty_tag('img', array('src' => $this->output->pix_url(file_mimetype_icon($type)), 'alt' => $type, 'class' => 'icon'));
         $linkhtml = html_writer::link($fileurl, $image) . substr($filepath, 1) . html_writer::link($fileurl, $filename);
         $linktxt = "{$filename} [{$fileurl}]";
         if ($format == 'html') {
             if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
                 $preview = html_writer::empty_tag('img', array('src' => $fileurl, 'alt' => '', 'class' => 'preview'));
                 $preview = html_writer::tag('a', $preview, array('href' => $fileurl));
                 $outputimgs .= $this->output->container($preview);
             } else {
                 $outputfiles .= html_writer::tag('li', $linkhtml, array('class' => $type));
             }
         } else {
             if ($format == 'text') {
                 $outputfiles .= $linktxt . PHP_EOL;
             }
         }
     }
     if ($format == 'html') {
         if ($outputimgs) {
             $outputimgs = $this->output->container($outputimgs, 'images');
         }
         if ($outputfiles) {
             $outputfiles = html_writer::tag('ul', $outputfiles, array('class' => 'files'));
         }
         return $this->output->container($outputimgs . $outputfiles, 'attachments');
     } else {
         return $outputfiles;
     }
 }
Example #29
0
/**
 * Prints a table with the files attached to a wiki page
 * @param object $context
 * @param string $filearea
 * @param int $fileitemid
 * @param array deleteuploads
 */
function wiki_print_upload_table($context, $filearea, $fileitemid, $deleteuploads = array())
{
    global $CFG, $OUTPUT;
    $htmltable = new html_table();
    $htmltable->head = array(get_string('deleteupload', 'wiki'), get_string('uploadname', 'wiki'), get_string('uploadactions', 'wiki'));
    $fs = get_file_storage();
    $files = $fs->get_area_files($context->id, 'mod_wiki', $filearea, $fileitemid);
    //TODO: this is weird (skodak)
    foreach ($files as $file) {
        if (!$file->is_directory()) {
            $checkbox = '<input type="checkbox" name="deleteupload[]", value="' . $file->get_pathnamehash() . '"';
            if (in_array($file->get_pathnamehash(), $deleteuploads)) {
                $checkbox .= ' checked="checked"';
            }
            $checkbox .= " />";
            $htmltable->data[] = array($checkbox, '<a href="' . file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $context->id . '/wiki_upload/' . $fileitemid . '/' . $file->get_filename()) . '">' . $file->get_filename() . '</a>', "");
        }
    }
    print '<h3 class="upload-table-title">' . get_string('uploadfiletitle', 'wiki') . "</h3>";
    print html_writer::table($htmltable);
}
Example #30
0
/**
 * Given a course_module object, this function returns any
 * "extra" information that may be needed when printing
 * this activity in a course listing.
 *
 * See {@link get_array_of_activities()} in course/lib.php
 *
 * @param object $coursemodule
 * @return object info
 */
function resource_get_coursemodule_info($coursemodule) {
    global $CFG, $DB;
    require_once("$CFG->libdir/filelib.php");
    require_once("$CFG->dirroot/mod/resource/locallib.php");
    require_once($CFG->libdir.'/completionlib.php');

    $context = get_context_instance(CONTEXT_MODULE, $coursemodule->id);

    if (!$resource = $DB->get_record('resource', array('id'=>$coursemodule->instance), 'id, name, display, displayoptions, tobemigrated, revision')) {
        return NULL;
    }

    $info = new stdClass();
    $info->name = $resource->name;

    if ($resource->tobemigrated) {
        $info->icon ='i/cross_red_big';
        return $info;
    }
    $fs = get_file_storage();
    $files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false); // TODO: this is not very efficient!!
    if (count($files) >= 1) {
        $mainfile = array_pop($files);
        $info->icon = file_extension_icon($mainfile->get_filename());
        $resource->mainfile = $mainfile->get_filename();
    }

    $display = resource_get_final_display_type($resource);

    if ($display == RESOURCELIB_DISPLAY_POPUP) {
        $fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&amp;redirect=1";
        $options = empty($resource->displayoptions) ? array() : unserialize($resource->displayoptions);
        $width  = empty($options['popupwidth'])  ? 620 : $options['popupwidth'];
        $height = empty($options['popupheight']) ? 450 : $options['popupheight'];
        $wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
        $info->extra = "onclick=\"window.open('$fullurl', '', '$wh'); return false;\"";

    } else if ($display == RESOURCELIB_DISPLAY_NEW) {
        $fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&amp;redirect=1";
        $info->extra = "onclick=\"window.open('$fullurl'); return false;\"";

    } else if ($display == RESOURCELIB_DISPLAY_OPEN) {
        $fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&amp;redirect=1";
        $info->extra = "onclick=\"window.location.href ='$fullurl';return false;\"";

    } else if ($display == RESOURCELIB_DISPLAY_DOWNLOAD) {
        if (empty($mainfile)) {
            return NULL;
        }
        // do not open any window because it would be left there after download
        $path = '/'.$context->id.'/mod_resource/content/'.$resource->revision.$mainfile->get_filepath().$mainfile->get_filename();
        $fullurl = addslashes_js(file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, true));

        // When completion information is enabled for download files, make
        // the JavaScript version go to the view page with redirect set,
        // instead of directly to the file, otherwise we can't make it tick
        // the box for them
        if (!$course = $DB->get_record('course', array('id'=>$coursemodule->course), 'id, enablecompletion')) {
            return NULL;
        }
        $completion = new completion_info($course);
        if ($completion->is_enabled($coursemodule) == COMPLETION_TRACKING_AUTOMATIC) {
            $fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&amp;redirect=1";
        }
        $info->extra = "onclick=\"window.open('$fullurl'); return false;\"";
    }

    return $info;
}