public function view_image()
 {
     global $DB;
     if ($this->imagetime) {
         $context = context_course::instance($this->courseid);
         $fs = get_file_storage();
         if ($image = $fs->get_file($context->id, 'assignsubmission_pdf', 'previewimage', 0, '/', 'preview.png')) {
             $imginfo = $image->get_imageinfo();
             echo "<div style='width: {$imginfo['width']}px; height: {$imginfo['height']}px; border: solid 1px black;'>";
             echo '<div style="position: relative;">';
             $imageurl = new moodle_url('/mod/assign/submission/pdf/previewimage.php', array('context' => $context->id, 'time' => $this->imagetime));
             echo '<img src="' . $imageurl . '" alt="Preview Template" style="position:absolute;top:0px;left:0px;"
                 onclick="clicked_on_image(event);" />';
             if ($this->templateid > 0) {
                 $templateitems = $DB->get_records('assignsubmission_pdf_tmplit', array('templateid' => $this->templateid));
                 if ($templateitems) {
                     foreach ($templateitems as $ti) {
                         $tiwidth = '';
                         if ($ti->type == 'text') {
                             $tiwidth = ' width: ' . $ti->width . 'px; ';
                         }
                         $cssid = '';
                         $border = '';
                         if ($this->itemid == $ti->id) {
                             $border = 'border: dashed 1px red;';
                             $cssid = ' id = "current_template_item" ';
                         }
                         echo "<div style=\"position: absolute;{$border}font-family:helvetica, arial, sans;\n                             font-size: 12px; top:{$ti->ypos}px;left:{$ti->xpos}px;{$tiwidth}\" {$cssid} >";
                         if ($ti->type == 'text' || $ti->type == 'shorttext') {
                             echo s($ti->setting);
                         } else {
                             if ($ti->type == 'date') {
                                 echo date($ti->setting);
                             }
                         }
                         echo '</div>';
                     }
                 }
                 if ($this->itemid == -1) {
                     echo '<div style="position:absolute;border:dashed 1px red;
                           font-family:helvetica, arial, sans;font-size: 12px;
                           top: 0px; left: 0px;" id = "current_template_item">';
                     echo get_string('enterformtext', 'assignsubmission_pdf');
                     echo '</div>';
                 }
             }
             echo '</div>';
             echo '&nbsp;';
             echo '</div>';
         }
     }
     $mform = new edit_templates_form();
     $mform->addhidden($this->url->params());
     $mform->display();
 }
 function view_image()
 {
     global $CFG, $DB;
     if ($this->imagetime) {
         $context = get_context_instance(CONTEXT_COURSE, $this->courseid);
         $fs = get_file_storage();
         if ($image = $fs->get_file($context->id, 'mod_assignment', 'previewimage', 0, '/', 'preview.png')) {
             $imginfo = $image->get_imageinfo();
             //                list($width, $height, $type, $attr) = getimagesize($fullpath);
             echo "<div style='width: {$imginfo['width']}px; height: {$imginfo['height']}px; border: solid 1px black;'>";
             echo '<div style="position: relative;">';
             $imageurl = new moodle_url('/mod/assignment/type/uploadpdf/previewimage.php', array('context' => $context->id, 'time' => $this->imagetime));
             echo '<img src="' . $imageurl . '" alt="Preview Template" style="position: absolute; top: 0px; left: 0px;" onclick="clicked_on_image(event);" />';
             if ($this->templateid > 0) {
                 $templateitems = $DB->get_records('assignment_uploadpdf_tmplitm', array('template' => $this->templateid));
                 if ($templateitems) {
                     foreach ($templateitems as $ti) {
                         $tiwidth = '';
                         if ($ti->type == 'text') {
                             $tiwidth = ' width: ' . $ti->width . 'px; ';
                         }
                         $cssid = '';
                         $border = '';
                         if ($this->itemid == $ti->id) {
                             $border = ' border: dashed 1px red; ';
                             $cssid = ' id = "current_template_item" ';
                         }
                         echo '<div style="position: absolute;' . $border . ' font-family: helvetica, arial, sans; font-size: 12px; ';
                         echo 'top: ' . $ti->ypos . 'px; left: ' . $ti->xpos . 'px; ' . $tiwidth;
                         echo '"' . $cssid . '>';
                         if ($ti->type == 'text' || $ti->type == 'shorttext') {
                             echo s($ti->setting);
                         } elseif ($ti->type == 'date') {
                             echo date($ti->setting);
                         }
                         echo '</div>';
                     }
                 }
                 if ($this->itemid == -1) {
                     echo '<div style="position: absolute; border: dashed 1px red; font-family: helvetica, arial, sans; font-size: 12px; ';
                     echo 'top: 0px; left: 0px;" id = "current_template_item">';
                     echo get_string('enterformtext', 'assignment_uploadpdf');
                     echo '</div>';
                 }
             }
             echo '</div>';
             echo '&nbsp;';
             echo '</div>';
             //    return;
         }
     }
     $mform = new edit_templates_form();
     $mform->addhidden($this->url->params());
     $mform->display();
 }