public function get_csswww()
 {
     global $CFG;
     if (!$this->theme_essential_lte_ie9()) {
         if (right_to_left()) {
             $moodlecss = 'essential-rtl.css';
         } else {
             $moodlecss = 'essential.css';
         }
         $syscontext = context_system::instance();
         $itemid = theme_get_revision();
         $url = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$syscontext->id}/theme_essential/style/{$itemid}/{$moodlecss}");
         $url = preg_replace('|^https?://|i', '//', $url->out(false));
         return '<link rel="stylesheet" href="' . $url . '">';
     } else {
         if (right_to_left()) {
             $moodlecssone = 'essential-rtl_ie9-blessed1.css';
             $moodlecsstwo = 'essential-rtl_ie9.css';
         } else {
             $moodlecssone = 'essential_ie9-blessed1.css';
             $moodlecsstwo = 'essential_ie9.css';
         }
         $syscontext = context_system::instance();
         $itemid = theme_get_revision();
         $urlone = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$syscontext->id}/theme_essential/style/{$itemid}/{$moodlecssone}");
         $urlone = preg_replace('|^https?://|i', '//', $urlone->out(false));
         $urltwo = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$syscontext->id}/theme_essential/style/{$itemid}/{$moodlecsstwo}");
         $urltwo = preg_replace('|^https?://|i', '//', $urltwo->out(false));
         return '<link rel="stylesheet" href="' . $urlone . '"><link rel="stylesheet" href="' . $urltwo . '">';
     }
 }
 /**
  * Do the necessary processing on content that came from the user, for example
  * the question text or general feedback. The result of calling this method is
  * then passed to Moodle's {@link format_text()} function.
  * @param string $text the content to process.
  * @param qtype_stack_renderer $renderer (options) the STACK renderer, if you have one.
  * @return string the content ready to pass to format_text.
  */
 public function process_display_castext($text, $replacedollars, qtype_stack_renderer $renderer = null)
 {
     if ($replacedollars) {
         $text = $this->replace_dollars($text);
     }
     $text = str_replace('!ploturl!', moodle_url::make_file_url('/question/type/stack/plot.php', '/'), $text);
     $text = stack_fact_sheets::display($text, $renderer);
     return $text;
 }
Example #3
0
/**
 * This function returns the URL for the RSS XML file.
 *
 * @param int    $contextid      the course id
 * @param int    $userid         the current user id
 * @param string $componentname  the name of the current component. For example "forum"
 * @param string $additionalargs For modules, module instance id
 * @return string the url of the RSS feed
 */
function rss_get_url($contextid, $userid, $componentname, $additionalargs)
{
    global $CFG;
    if (empty($userid)) {
        $userid = guest_user()->id;
    }
    $usertoken = rss_get_token($userid);
    $url = '/rss/file.php';
    return moodle_url::make_file_url($url, '/' . $contextid . '/' . $usertoken . '/' . $componentname . '/' . $additionalargs . '/rss.xml');
}
 /**
  * Returns URL to the stored file via pluginfile.php.
  *
  * Note the theme must also implement pluginfile.php handler,
  * theme revision is used instead of the itemid.
  *
  * @param string $setting
  * @param string $filearea
  * @return string protocol relative URL or null if not present
  */
 public function setting_file_url($setting, $filearea)
 {
     global $CFG;
     if (empty($this->settings->{$setting})) {
         return null;
     }
     $component = 'theme_' . $this->name;
     $itemid = theme_get_revision();
     $filepath = $this->settings->{$setting};
     $syscontext = context_system::instance();
     $url = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$syscontext->id}/{$component}/{$filearea}/{$itemid}" . $filepath);
     // Now this is tricky because the we can not hardcode http or https here, lets use the relative link.
     // Note: unfortunately moodle_url does not support //urls yet.
     $url = preg_replace('|^https?://|i', '//', $url->out(false));
     return $url;
 }
Example #5
0
    static public function get_csswww() {
        global $CFG;

        if (!self::lte_ie9()) {
            if (\right_to_left()) {
                $moodlecss = 'essential-rtl.css';
            } else {
                $moodlecss = 'essential.css';
            }

            $syscontext = \context_system::instance();
            $itemid = \theme_get_revision();
            $url = \moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php",
                            "/$syscontext->id/theme_essential/style/$itemid/$moodlecss");
            $url = preg_replace('|^https?://|i', '//', $url->out(false));
            return '<link rel="stylesheet" href="' . $url . '">';
        } else {
            if (\right_to_left()) {
                $moodlecssone = 'essential-rtl_ie9-blessed1.css';
                $moodlecsstwo = 'essential-rtl_ie9.css';
            } else {
                $moodlecssone = 'essential_ie9-blessed1.css';
                $moodlecsstwo = 'essential_ie9.css';
            }

            $syscontext = \context_system::instance();
            $itemid = \theme_get_revision();
            $urlone = \moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php",
                            "/$syscontext->id/theme_essential/style/$itemid/$moodlecssone");
            $urlone = preg_replace('|^https?://|i', '//', $urlone->out(false));
            $urltwo = \moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php",
                            "/$syscontext->id/theme_essential/style/$itemid/$moodlecsstwo");
            $urltwo = preg_replace('|^https?://|i', '//', $urltwo->out(false));
            return '<link rel="stylesheet" href="'.$urlone . '"><link rel="stylesheet" href="'.$urltwo.'">';
        }
    }
Example #6
0
/**
 * Gets the instance custom icon if exists.
 * Filearea: activityicon
 * Itemid: 0
 *
 * @param int cm id
 * @return moodle_url
 */
function dataform_get_custom_icon_url($cmid)
{
    $fs = get_file_storage();
    $context = context_module::instance($cmid);
    if ($files = $fs->get_area_files($context->id, 'mod_dataform', 'activityicon', 0, 'sortorder', false)) {
        $file = reset($files);
        $filename = $file->get_filename();
        $path = "/{$context->id}/mod_dataform/activityicon/0";
        return moodle_url::make_file_url('/pluginfile.php', "{$path}/{$filename}");
    }
    return null;
}
Example #7
0
    $file = reset($files);
    unset($files);
}
$resource->mainfile = $file->get_filename();
$displaytype = resource_get_final_display_type($resource);
if ($displaytype == RESOURCELIB_DISPLAY_OPEN || $displaytype == RESOURCELIB_DISPLAY_DOWNLOAD) {
    // For 'open' and 'download' links, we always redirect to the content - except
    // if the user just chose 'save and display' from the form then that would be
    // confusing
    if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], 'modedit.php') === false) {
        $redirect = true;
    }
}
if ($redirect) {
    // coming from course page or url index page
    // this redirect trick solves caching problems when tracking views ;-)
    $path = '/' . $context->id . '/mod_resource/content/' . $resource->revision . $file->get_filepath() . $file->get_filename();
    $fullurl = moodle_url::make_file_url('/pluginfile.php', $path, $displaytype == RESOURCELIB_DISPLAY_DOWNLOAD);
    redirect($fullurl);
}
switch ($displaytype) {
    case RESOURCELIB_DISPLAY_EMBED:
        resource_display_embed($resource, $cm, $course, $file);
        break;
    case RESOURCELIB_DISPLAY_FRAME:
        resource_display_frame($resource, $cm, $course, $file);
        break;
    default:
        resource_print_workaround($resource, $cm, $course, $file);
        break;
}
 /**
  *
  */
 protected function get_action_icon_download($preset, $area)
 {
     global $OUTPUT;
     static $icon;
     if (!$icon) {
         $icon = new pix_icon('t/download', $this->get_strings()->download);
     }
     $url = moodle_url::make_file_url("/pluginfile.php", "/{$preset->contextid}/mod_dataform/{$area}/{$preset->itemid}/{$preset->name}");
     return $OUTPUT->action_icon($url, $icon);
 }
Example #9
0
 /**
  *
  */
 protected function display_file($file, $path, $altname, $params = null)
 {
     $field = $this->_field;
     if ($file->is_valid_image()) {
         $filename = $file->get_filename();
         $imgattr = array('style' => array());
         if (!empty($params['tn'])) {
             // Decline if the file is not really a thumbnail.
             if (strpos($filename, 'thumb_') === false) {
                 return '';
             }
         } else {
             // Decline if the file is a thumbnail.
             if (strpos($filename, 'thumb_') !== false) {
                 return '';
             }
             // The picture's display dimension may be set in the field.
             if ($field->appearance->dispw) {
                 $imgattr['style'][] = 'width:' . s($field->appearance->dispw) . s($field->appearance->dispu);
             }
             if ($field->appearance->disph) {
                 $imgattr['style'][] = 'height:' . s($field->appearance->disph) . s($field->appearance->dispu);
             }
         }
         // Calculate src: either moodle url or base64.
         if (!empty($params['download'])) {
             return $this->display_link($file, $path, $altname, $params);
         } else {
             if (!empty($params['base64'])) {
                 $src = 'data:' . $file->get_mimetype() . ';base64,' . base64_encode($file->get_content());
             } else {
                 $pluginfileurl = new moodle_url('/pluginfile.php');
                 $src = moodle_url::make_file_url($pluginfileurl, "{$path}/{$filename}");
                 // For url request return it here.
                 if (!empty($params['url'])) {
                     return $src;
                 }
             }
         }
         $imgattr['src'] = $src;
         $imgattr['style'] = implode(';', $imgattr['style']);
         $str = html_writer::empty_tag('img', $imgattr);
         if (!empty($params['linked'])) {
             return html_writer::link($src, $str);
         } else {
             return $str;
         }
     } else {
         return '';
     }
 }
Example #10
0
 /**
  *
  */
 protected function display_link($file, $path, $altname, $params = null)
 {
     global $OUTPUT;
     $filename = $file->get_filename();
     $displayname = $altname ? $altname : $filename;
     $fileicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype())), 'alt' => $file->get_mimetype(), 'height' => 16, 'width' => 16));
     if (!empty($params['download'])) {
         list(, $context, , , $contentid) = explode('/', $path);
         $url = new moodle_url("/mod/dataform/field/file/download.php", array('cid' => $contentid, 'context' => $context, 'file' => $filename));
     } else {
         $url = moodle_url::make_file_url('/pluginfile.php', "{$path}/{$filename}");
     }
     return html_writer::link($url, "{$fileicon}&nbsp;{$displayname}");
 }
 /**
  * Returns the html for entries displays. Assumes that {@link mod_dataform_entry_manager::set_content()}
  * has been called for this view and its entries property is set in accordance with the display mode
  * of the view submission settings.
  *
  * @return string HTML fragment
  */
 public function get_entries_display(array $options = null)
 {
     $html = '';
     $entryman = $this->entry_manager;
     $editing = $this->user_is_editing();
     if ($editing) {
         if ($this->in_edit_display_mode(self::EDIT_SEPARATE)) {
             // Extract the edited and non-edited entries from the set.
             $editentries = explode(',', $this->editentries);
             $edited = array();
             $nonedited = array();
             foreach ($entryman->entries as $entryid => $entry) {
                 if (in_array($entryid, $editentries)) {
                     $edited[$entryid] = $entry;
                 } else {
                     $nonedited[$entryid] = $entry;
                 }
             }
             // Get the form html for the edited entries.
             if ($elements = $this->get_entries_definition($edited)) {
                 if ($this->editentries) {
                     $entriesform = $this->get_entries_form(array('elements' => $elements));
                     $html .= $entriesform->render();
                 } else {
                     // Turns out that all requested edits are not allowed.
                     $html .= implode('', $elements);
                 }
             }
             // Add the rest.
             $elements = $this->get_entries_definition($nonedited, false);
             $html .= implode('', $elements);
         } else {
             // Get the form html for all entries.
             if ($elements = $this->get_entries_definition($entryman->entries)) {
                 if ($this->editentries) {
                     $entriesform = $this->get_entries_form(array('elements' => $elements));
                     $html .= $entriesform->render();
                 } else {
                     // Turns out that all requested edits are not allowed.
                     $html .= implode('', $elements);
                 }
             }
         }
         return $html;
     }
     // Not editing so fetch the entries and display html.
     $elements = $this->get_entries_definition($entryman->entries, false);
     $html .= implode('', $elements);
     // RM ??? Replace pluginfile urls if needed (e.g. in export).
     $pluginfileurl = isset($options['pluginfileurl']) ? $options['pluginfileurl'] : null;
     if ($pluginfileurl) {
         $pluginfilepath = \moodle_url::make_file_url("/pluginfile.php", "/{$this->df->context->id}/mod_dataform/content");
         $pattern = str_replace('/', '\\/', $pluginfilepath);
         $pattern = "/{$pattern}\\/\\d+\\//";
         $html = preg_replace($pattern, $pluginfileurl, $html);
     }
     return $html;
 }
function tur_get_course_intro_image($contextid)
{
    $fs = get_file_storage();
    $files = $fs->get_area_files($contextid, 'mod_resource', 'content', 0);
    if ($file = end($files)) {
        $filename = $file->get_filename();
        if ($filename != '.') {
            return moodle_url::make_file_url('/pluginfile.php', "/{$contextid}/mod_resource/content/0/{$filename}");
        }
    }
}
Example #13
0
 /**
  * Print single user participation for display
  *
  * @param object $cm current course module object
  * @param object $course current course object
  * @param object $oublog current oublog object
  * @param int $userid user id of user to view participation for
  * @param int $groupid optional group id, no group = 0
  * @param string $download download type (csv only, default '')
  * @param int $page flexible_table pagination page
  * @param array $participation mixed array of user participation values
  * @param object $context current context
  * @param bool $viewfullnames flag for global users fullnames capability
  * @param string groupname group name for display, default ''
  */
 public function render_user_participation_list($cm, $course, $oublog, $participation, $groupid, $download, $page, $context, $viewfullnames, $groupname, $start, $end)
 {
     global $DB, $CFG;
     $user = $participation->user;
     $fullname = fullname($user, $viewfullnames);
     // Setup the table.
     require_once $CFG->dirroot . '/mod/oublog/participation_table.php';
     $filename = "{$course->shortname}-" . format_string($oublog->name, true);
     if ($groupname !== '') {
         $filename .= '-' . format_string($groupname, true);
     }
     $filename .= '-' . format_string($fullname, true);
     $table = new oublog_user_participation_table($cm->id, $course, $oublog, $user->id, $fullname, $groupname, $groupid, $start, $end);
     $table->setup($download);
     $table->is_downloading($download, $filename, get_string('participation', 'oublog'));
     // Print standard output.
     $output = '';
     $modcontext = context_module::instance($cm->id);
     if (!$table->is_downloading()) {
         $output .= html_writer::tag('h2', get_string('postsby', 'oublog', $fullname));
         if (!$participation->posts) {
             $output .= html_writer::tag('p', get_string('nouserposts', 'oublog'));
         } else {
             $counter = 0;
             foreach ($participation->posts as $post) {
                 $row = $counter % 2 ? 'oublog-odd' : 'oublog-even';
                 $counter++;
                 $output .= html_writer::start_tag('div', array('class' => 'oublog-post ' . $row));
                 $output .= html_writer::start_tag('div', array('class' => 'oublog-post-top'));
                 // Post attachments.
                 $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'));
                     foreach ($files as $file) {
                         $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'));
                         $fileurlbase = $CFG->wwwroot . '/pluginfile.php';
                         $filepath = '/' . $modcontext->id . '/mod_oublog/attachment/' . $post->id . '/' . $filename;
                         $path = moodle_url::make_file_url($fileurlbase, $filepath);
                         $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');
                 }
                 // Post title and date.
                 if (isset($post->title) && !empty($post->title)) {
                     $viewposturl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id));
                     $viewpost = html_writer::link($viewposturl, s($post->title));
                     $output .= html_writer::tag('h3', $viewpost, array('class' => 'oublog-post-title'));
                     $output .= html_writer::start_tag('div', array('class' => 'oublog-post-date'));
                     $output .= oublog_date($post->timeposted);
                     $output .= html_writer::end_tag('div');
                 } else {
                     $viewposturl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id));
                     $viewpost = html_writer::link($viewposturl, oublog_date($post->timeposted));
                     $output .= html_writer::tag('h3', $viewpost, array('class' => 'oublog-post-title'));
                 }
                 $output .= html_writer::end_tag('div');
                 // Post content.
                 $output .= html_writer::start_tag('div', array('class' => 'oublog-post-content'));
                 $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_oublog', 'message', $post->id);
                 $output .= format_text($post->message, FORMAT_HTML);
                 $output .= html_writer::end_tag('div');
                 // End display box.
                 $output .= html_writer::end_tag('div');
             }
         }
         $output .= html_writer::tag('h2', get_string('commentsby', 'oublog', $fullname));
         if (!$participation->comments) {
             $output .= html_writer::tag('p', get_string('nousercomments', 'oublog'));
         } else {
             $output .= html_writer::start_tag('div', array('id' => 'oublogcomments', 'class' => 'oublog-post-comments oublogpartcomments'));
             foreach ($participation->comments as $comment) {
                 $output .= html_writer::start_tag('div', array('class' => 'oublog-comment'));
                 $author = new StdClass();
                 $author->id = $comment->authorid;
                 $userfields = get_all_user_name_fields();
                 foreach ($userfields as $field) {
                     $author->{$field} = $comment->{$field};
                 }
                 $authorurl = new moodle_url('/user/view.php', array('id' => $author->id));
                 $authorlink = html_writer::link($authorurl, fullname($author, $viewfullnames));
                 if (isset($comment->posttitle) && !empty($comment->posttitle)) {
                     $viewposturl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $comment->postid));
                     $viewpostlink = html_writer::link($viewposturl, s($comment->posttitle));
                     $strparams = array('title' => $viewpostlink, 'author' => $authorlink);
                     $output .= html_writer::tag('h3', get_string('commentonby', 'oublog', $strparams));
                 } else {
                     $viewposturl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $comment->postid));
                     $viewpostlink = html_writer::link($viewposturl, oublog_date($comment->postdate));
                     $strparams = array('title' => $viewpostlink, 'author' => $authorlink);
                     $output .= html_writer::tag('h3', get_string('commentonby', 'oublog', $strparams));
                 }
                 // Comment title.
                 if (isset($comment->title) && !empty($comment->title)) {
                     $output .= html_writer::tag('h3', s($comment->title), array('class' => 'oublog-comment-title'));
                 }
                 // Comment content and date.
                 $output .= html_writer::start_tag('div', array('class' => 'oublog-comment-date'));
                 $output .= oublog_date($comment->timeposted);
                 $output .= html_writer::end_tag('div');
                 $output .= html_writer::start_tag('div', array('class' => 'oublog-comment-content'));
                 $comment->message = file_rewrite_pluginfile_urls($comment->message, 'pluginfile.php', $modcontext->id, 'mod_oublog', 'messagecomment', $comment->id);
                 $output .= format_text($comment->message, FORMAT_HTML);
                 $output .= html_writer::end_tag('div');
                 // End display box.
                 $output .= html_writer::end_tag('div');
             }
             $output .= html_writer::end_tag('div');
         }
         // Only printing the download buttons.
         echo $table->download_buttons();
         // Print the actual output.
         echo $output;
         // Grade.
         if (isset($participation->gradeobj)) {
             $this->render_user_grade($course, $cm, $oublog, $participation, $groupid);
         }
     } else {
         // Posts.
         if ($participation->posts) {
             $table->add_data($table->posts);
             $table->add_data($table->postsheader);
             foreach ($participation->posts as $post) {
                 $row = array();
                 $row[] = userdate($post->timeposted, get_string('strftimedate'));
                 $row[] = userdate($post->timeposted, get_string('strftimetime'));
                 $row[] = isset($post->title) && !empty($post->title) ? $post->title : '';
                 $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_oublog', 'message', $post->id);
                 $row[] = format_text($post->message, FORMAT_HTML);
                 $fs = get_file_storage();
                 if ($files = $fs->get_area_files($modcontext->id, 'mod_oublog', 'attachment', $post->id, 'timemodified', false)) {
                     $attachmentstring = '';
                     foreach ($files as $file) {
                         $filename = $file->get_filename();
                         $attachmentstring .= ' ' . $filename . ', ';
                     }
                     $attachmentstring = substr($attachmentstring, 0, -2);
                     $row[] = $attachmentstring;
                 } else {
                     $row[] = '';
                 }
                 $table->add_data($row);
             }
         }
         // Comments.
         if ($participation->comments) {
             $table->add_data($table->comments);
             $table->add_data($table->commentsheader);
             foreach ($participation->comments as $comment) {
                 $author = new StdClass();
                 $author->id = $comment->authorid;
                 $userfields = get_all_user_name_fields();
                 foreach ($userfields as $field) {
                     $author->{$field} = $comment->{$field};
                 }
                 $authorfullname = fullname($author, $viewfullnames);
                 $row = array();
                 $row[] = userdate($comment->timeposted, get_string('strftimedate'));
                 $row[] = userdate($comment->timeposted, get_string('strftimetime'));
                 $row[] = isset($comment->title) ? $comment->title : '';
                 $comment->message = file_rewrite_pluginfile_urls($comment->message, 'pluginfile.php', $modcontext->id, 'mod_oublog', 'messagecomment', $comment->id);
                 $row[] = format_text($comment->message, FORMAT_HTML);
                 $row[] = $authorfullname;
                 $row[] = userdate($comment->postdate, get_string('strftimedate'));
                 $row[] = userdate($comment->postdate, get_string('strftimetime'));
                 $row[] = isset($comment->posttitle) ? $comment->posttitle : '';
                 $table->add_data($row);
             }
         }
         if (!$participation->posts && !$participation->comments) {
             $table->add_data(array(''));
         }
         $table->finish_output();
     }
 }
                // Loop through columns and create tag for each one
                // Only print the capabilities if they're associated with one of our roles
                if (in_array($cap->roleid, $role_ids)) {
                    $xml->begin_tag('ROLE_CAPABILITY');
                    foreach ($cap_array as $field => $value) {
                        $xml->full_tag(strtoupper($field), $value);
                    }
                    $xml->end_tag('ROLE_CAPABILITY');
                }
            }
        }
        $xml->end_tag('ROLE_CAPABILITIES');
        $xml->end_tag('ROLE');
    }
}
$xml->end_tag('ROLES');
$xml->end_tag('MOODLE_ROLES_MIGRATION');
$xml->stop();
// Create the XML file from the XML object stored in memory
if ($fs->create_file_from_string($fileinfo, $xml_output->get_allcontents())) {
    if ($file = $fs->get_file($fileinfo['contextid'], $fileinfo['component'], $fileinfo['filearea'], $fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename'])) {
        $path = "/" . $fileinfo['contextid'] . "/" . $fileinfo['component'] . "/" . $fileinfo['filearea'] . "/" . $fileinfo['itemid'] . $fileinfo['filepath'] . $fileinfo['filename'];
        $url = moodle_url::make_file_url($CFG->wwwroot . "/pluginfile.php", $path);
        redirect($url);
    } else {
        send_file_not_found();
    }
} else {
    send_file_not_found();
}
die;
Example #15
0
 /**
  * Sets the dataform page js.
  *
  * @return void
  */
 protected function set_page_js()
 {
     global $PAGE;
     $jsurls = array();
     // Js includes from the js template.
     if ($this->jsincludes) {
         foreach (explode("\n", $this->jsincludes) as $jsinclude) {
             $jsinclude = trim($jsinclude);
             if ($jsinclude) {
                 $jsurls[] = new moodle_url($jsinclude);
             }
         }
     }
     // Uploaded js files.
     $fs = get_file_storage();
     if ($files = $fs->get_area_files($this->context->id, 'mod_dataform', 'js', 0, 'sortorder', false)) {
         $path = "/{$this->context->id}/mod_dataform/js/0";
         foreach ($files as $file) {
             $filename = $file->get_filename();
             $jsurls[] = moodle_url::make_file_url('/pluginfile.php', "{$path}/{$filename}");
         }
     }
     // Js code from the js template.
     if ($this->js) {
         $jsurls[] = new moodle_url('/mod/dataform/js.php', array('d' => $this->id));
     }
     foreach ($jsurls as $jsurl) {
         $PAGE->requires->js($jsurl);
     }
 }
Example #16
0
    public function mail($message, $reply = false, $offset = 0) {
        global $CFG, $USER;

        $totalusers = 0;
        $output = '';

        if (!$reply) {
            $output .= html_writer::empty_tag('input', array(
                    'type' => 'hidden',
                    'name' => 'm',
                    'value' => $message->id(),
            ));

            $output .= html_writer::empty_tag('input', array(
                    'type' => 'hidden',
                    'name' => 'offset',
                    'value' => $offset,
            ));
        }

        $output .= $this->output->container_start('mail_header');
        $output .= $this->output->container_start('left');
        $output .= $this->output->user_picture($message->sender());
        $output .= $this->output->container_end();
        $output .= $this->output->container_start('mail_info');
        $output .= html_writer::link(new moodle_url('/user/view.php',
                                            array(
                                                'id' => $message->sender()->id,
                                                'course' => $message->course()->id
                                            )),
                                    fullname($message->sender()),
                                    array('class' => 'user_from'));
        $output .= $this->date($message, true);
        if (!$reply) {
            $output .= $this->output->container_start('mail_recipients');
            foreach (array('to', 'cc', 'bcc') as $role) {
                $recipients = $message->recipients($role);
                if (!empty($recipients)) {
                    if ($role == 'bcc' and $message->sender()->id !== $USER->id) {
                        continue;
                    }
                    $output .= html_writer::start_tag('div');
                    $output .= html_writer::tag('span', get_string($role, 'local_mail'), array('class' => 'mail_role'));
                    $numusers = count($recipients);
                    $totalusers += $numusers;
                    $cont = 1;
                    foreach ($recipients as $user) {
                        $output .= html_writer::link(new moodle_url('/user/view.php',
                                            array(
                                                'id' => $user->id,
                                                'course' => $message->course()->id
                                            )),
                                            fullname($user));
                        if ($cont < $numusers) {
                            $output .= ', ';
                        }
                        $cont += 1;
                    }
                    $output .= ' ';
                    $output .= html_writer::end_tag('div');
                }
            }
            $output .= $this->output->container_end();
        } else {
            $output .= html_writer::tag('div', '', array('class' => 'mail_recipients'));
        }
        $output .= $this->output->container_end();
        $output .= $this->output->container_end();

        $output .= $this->output->container_start('mail_body');
        $output .= $this->output->container_start('mail_content');
        $output .= local_mail_format_content($message);
        $attachments = local_mail_attachments($message);
        if ($attachments) {
            $output .= $this->output->container_start('mail_attachments');
            if (count($attachments) > 1) {
                $text = get_string('attachnumber', 'local_mail', count($attachments));
                $output .= html_writer::tag('span', $text, array('class' => 'mail_attachment_text'));
                $downloadurl = new moodle_url($this->page->url, array('downloadall' => '1'));
                $iconimage = $this->output->pix_icon('a/download_all', get_string('downloadall', 'local_mail'), 'moodle', array('class' => 'icon'));
                $output .= html_writer::start_div('mail_attachment_downloadall');
                $output .= html_writer::link($downloadurl, $iconimage);
                $output .= html_writer::link($downloadurl, get_string('downloadall', 'local_mail'), array('class' => 'mail_downloadall_text'));
                $output .= html_writer::end_div();
            }
            foreach ($attachments as $attach) {
                $filename = $attach->get_filename();
                $filepath = $attach->get_filepath();
                $mimetype = $attach->get_mimetype();
                $iconimage = $this->output->pix_icon(file_file_icon($attach), get_mimetype_description($attach), 'moodle', array('class' => 'icon'));
                $path = '/'.$attach->get_contextid().'/local_mail/message/'.$attach->get_itemid().$filepath.$filename;
                $fullurl = moodle_url::make_file_url('/pluginfile.php', $path, true);
                $output .= html_writer::start_tag('div', array('class' => 'mail_attachment'));
                $output .= html_writer::link($fullurl, $iconimage);
                $output .= html_writer::link($fullurl, s($filename));
                $output .= html_writer::tag('span', display_size($attach->get_filesize()), array('class' => 'mail_attachment_size'));
                $output .= html_writer::end_tag('div');
            }
            $output .= $this->output->container_end();
        }
        $output .= $this->output->container_end();
        $output .= $this->newlabelform();
        if (!$reply) {
            if ($message->sender()->id !== $USER->id) {
                $output .= $this->toolbar('reply', $message->course()->id, array('replyall' => ($totalusers > 1)));
            } else {
                $output .= $this->toolbar('forward', $message->course()->id);
            }
        }
        $output .= $this->output->container_end();
        return $output;
    }
/**
 * Create url for question export
 *
 * @param int $contextid, current context
 * @param int $categoryid, categoryid
 * @param string $format
 * @param string $withcategories
 * @param string $ithcontexts
 * @param moodle_url export file url
 */
function question_make_export_url($contextid, $categoryid, $format, $withcategories, $withcontexts, $filename)
{
    global $CFG;
    $urlbase = "{$CFG->httpswwwroot}/pluginfile.php";
    return moodle_url::make_file_url($urlbase, "/{$contextid}/question/export/{$categoryid}/{$format}/{$withcategories}" . "/{$withcontexts}/{$filename}", true);
}
Example #18
0
/**
 * Crea un archivo PDF a partir de un quiz, agregando una hoja de respuestas de opción múltiple
 * 
 * @param unknown $cm
 * @param string $debug
 * @param string $context
 * @param string $course
 * @param string $logofilepath
 * @param boolean $answersheetsonly
 * @return void|NULL
 */
function emarking_create_quiz_pdf($cm, $debug = false, $context = null, $course = null, $answersheetsonly = false, $pbar = false)
{
    global $DB, $CFG, $OUTPUT;
    // Inclusión de librerías
    require_once $CFG->dirroot . '/mod/assign/feedback/editpdf/fpdi/fpdi2tcpdf_bridge.php';
    require_once $CFG->dirroot . '/mod/assign/feedback/editpdf/fpdi/fpdi.php';
    require_once $CFG->libdir . '/pdflib.php';
    require_once $CFG->dirroot . '/mod/quiz/locallib.php';
    require_once $CFG->dirroot . '/mod/emarking/print/locallib.php';
    $filedir = $CFG->dataroot . "/temp/emarking/{$context->id}";
    emarking_initialize_directory($filedir, true);
    $fileimg = $CFG->dataroot . "/temp/emarking/{$context->id}/qr";
    emarking_initialize_directory($fileimg, true);
    $userimgdir = $CFG->dataroot . "/temp/emarking/{$context->id}/u";
    emarking_initialize_directory($userimgdir, true);
    $logofile = emarking_get_logo_file();
    $logofilepath = $logofile ? emarking_get_path_from_hash($filedir, $logofile->get_pathnamehash()) : null;
    $fullhtml = array();
    $numanswers = array();
    $attemptids = array();
    $images = array();
    $imageshtml = array();
    $users = emarking_get_enroled_students($course->id);
    if ($pbar) {
        echo $OUTPUT->heading(get_string('loadingquestions', 'mod_emarking'), 3);
        $progressbar = new progress_bar();
        $progressbar->create();
        $progressbar->update(0, count($users), get_string('processing', 'mod_emarking'));
    }
    $current = 0;
    foreach ($users as $user) {
        $current++;
        if ($pbar) {
            $progressbar->update($current, count($users), "{$user->firstname}, {$user->lastname}");
        }
        // Get the quiz object
        $quizobj = quiz::create($cm->instance, $user->id);
        // Create the new attempt and initialize the question sessions
        $attemptnumber = 1;
        $lastattempt = null;
        $timenow = time();
        // Update time now, in case the server is running really slowly.
        $attempts = quiz_get_user_attempts($quizobj->get_quizid(), $user->id, 'all');
        $numattempts = count($attempts);
        foreach ($attempts as $attempt) {
            $attemptobj = quiz_attempt::create($attempt->id);
            $slots = $attemptobj->get_slots();
            foreach ($slots as $slot) {
                $qattempt = $attemptobj->get_question_attempt($slot);
                $question = $qattempt->get_question();
                if ($question->get_type_name() === 'multianswer') {
                    $q = $question->subquestions[1];
                    $numanswers[$user->id][] = count($q->answers);
                } else {
                    if ($question->get_type_name() === 'multichoice') {
                        $numanswers[$user->id][] = count($question->answers);
                    }
                }
                $attemptids[$user->id] = $attempt->id;
                $qhtml = $attemptobj->render_question($slot, false);
                $qhtml = emarking_clean_question_html($qhtml);
                $currentimages = emarking_extract_images_url($qhtml);
                $idx = 0;
                foreach ($currentimages[1] as $imageurl) {
                    if (!array_search($imageurl, $images)) {
                        $images[] = $imageurl;
                        $imageshtml[] = $currentimages[0][$idx];
                    }
                    $idx++;
                }
                $fullhtml[$user->id][] = $qhtml;
            }
            // One attempt per user
            break;
        }
    }
    $save_to = $CFG->tempdir . '/emarking/printquiz/' . $cm->id . '/';
    emarking_initialize_directory($save_to, true);
    // Bajar las imágenes del HTML a dibujar
    $search = array();
    $replace = array();
    $replaceweb = array();
    $imagesize = array();
    $idx = 0;
    if ($pbar) {
        $progressbar->update_full(100, get_string('finished', 'mod_emarking'));
        echo $OUTPUT->heading(get_string('downloadingimages', 'mod_emarking'), 3);
        $progressbar = new progress_bar();
        $progressbar->create();
        $progressbar->update(0, count($images), get_string('processing', 'mod_emarking'));
    }
    foreach ($images as $image) {
        if ($pbar) {
            $imagefilename = explode("/", $image);
            $progressbar->update($idx + 1, count($images), $imagefilename[count($imagefilename) - 1]);
        }
        // Si solamente incluiremos hojas de respuesta terminamos el ciclo
        if ($answersheetsonly) {
            break;
        }
        if (!(list($filename, $imageinfo) = emarking_get_file_from_url($image, $save_to))) {
            echo "Problem downloading file {$image} <hr>";
        } else {
            // Buscamos el src de la imagen
            $search[] = 'src="' . $image . '"';
            $replacehtml = ' src="' . $filename . '"';
            $replacehtmlxweb = ' src="' . $image . '"';
            // Si el html de la misma contiene ancho o alto, se deja tal cual
            $imghtml = $imageshtml[$idx];
            if (substr_count($imghtml, "width") + substr_count($imghtml, "height") == 0) {
                $width = $imageinfo[0];
                $height = $imageinfo[1];
                $ratio = floatval(10) / floatval($height);
                $height = 10;
                $width = (int) ($ratio * floatval($width));
                $sizehtml = 'width="' . $width . '" height="' . $height . '"';
                $replacehtml = $sizehtml . ' ' . $replacehtml;
                $replacehtmlxweb = $sizehtml . ' ' . $replacehtmlxweb;
            }
            $replace[] = $replacehtml;
            $replaceweb[] = $replacehtmlxweb;
            $imagesize[] = $imageinfo;
        }
        $idx++;
    }
    if ($debug) {
        foreach ($fullhtml as $uid => $questions) {
            $index = 0;
            foreach ($questions as $question) {
                echo str_replace($search, $replaceweb, $fullhtml[$uid][$index]);
                $index++;
            }
        }
        return;
    }
    // Now we create the pdf file with the modified html
    $doc = new FPDI();
    $doc->setPrintHeader(false);
    $doc->setPrintFooter(false);
    $doc->SetFont('times', '', 12);
    // set margins
    $doc->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $doc->SetHeaderMargin(250);
    $doc->SetFooterMargin(PDF_MARGIN_FOOTER);
    if ($pbar) {
        $progressbar->update_full(100, get_string('finished', 'mod_emarking'));
        echo $OUTPUT->heading(get_string('creatingpdffile', 'mod_emarking'), 3);
        $progressbar = new progress_bar();
        $progressbar->create();
    }
    $current = 0;
    foreach ($fullhtml as $uid => $questions) {
        $current++;
        $stinfo = $DB->get_record('user', array('id' => $uid));
        $stinfo->name = $stinfo->firstname . ' ' . $stinfo->lastname;
        $stinfo->picture = emarking_get_student_picture($stinfo, $userimgdir);
        $stinfo->idnumber = $uid . '-' . $attemptids[$uid];
        if ($pbar) {
            $progressbar->update($current, count($fullhtml), $stinfo->name);
        }
        $groups = groups_get_user_groups($course->id, $uid);
        if ($groups && isset($groups[0][0]) && ($group = $DB->get_record('groups', array('id' => $groups[0][0])))) {
            $stinfo->group = $group->name;
        } else {
            $stinfo->group = '';
        }
        emarking_add_answer_sheet($doc, $filedir, $stinfo, $logofilepath, null, $fileimg, $course, $quizobj->get_quiz_name(), $numanswers[$uid], $attemptids[$uid]);
        // Una vez agregada la página de respuestas, si es todo lo que hay que hacer saltar al siguiente
        if ($answersheetsonly) {
            continue;
        }
        $doc->AddPage();
        emarking_draw_header($doc, $stinfo, $quizobj->get_quiz_name(), 2, $fileimg, $logofilepath, $course, null, false, 0);
        $doc->SetFont('times', '', 12);
        $doc->SetAutoPageBreak(true);
        $doc->SetXY(PDF_MARGIN_LEFT, 40);
        $index = 0;
        foreach ($questions as $question) {
            $prevy = $doc->getY();
            $fullhtml[$uid][$index] = str_replace($search, $replace, $fullhtml[$uid][$index]);
            $doc->writeHTML($fullhtml[$uid][$index]);
            $y = $doc->getY();
            $fmargin = $doc->getFooterMargin();
            $height = $doc->getPageHeight();
            $spaceleft = $height - $fmargin - $y;
            $questionsize = $y - $prevy;
            if ($spaceleft < 70) {
                $doc->AddPage();
            }
            $index++;
        }
    }
    if ($pbar) {
        $progressbar->update_full(100, get_string('finished', 'mod_emarking'));
    }
    $qid = $quizobj->get_quizid();
    $pdfquizfilename = 'quiz-' . $qid . '-' . random_string() . '.pdf';
    $fs = get_file_storage();
    $filerecord = array('component' => 'mod_emarking', 'filearea' => 'pdfquiz', 'contextid' => $context->id, 'itemid' => $quizobj->get_quizid(), 'filepath' => '/', 'filename' => $pdfquizfilename);
    $doc->Output($filedir . '/' . $pdfquizfilename, 'F');
    $file = $fs->create_file_from_pathname($filerecord, $filedir . '/' . $pdfquizfilename);
    $downloadurl = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$context->id}/mod_emarking/pdfquiz/{$qid}/{$pdfquizfilename}", null, true);
    return $downloadurl;
}