<head>
<title><?php 
wp_title('|', true, 'right');
?>
</title>
<?php 
wp_head();
?>
</head>
<body <?php 
body_class('single-certificate');
?>
>
<?php 
$ID = ThemexCore::getRewriteRule('certificate');
$certificate = ThemexCourse::getCertificate(themex_decode($ID), themex_decode($ID, true));
if (isset($certificate['user'])) {
    ?>
	<div class="certificate-wrap">
		<?php 
    if (!empty($certificate['background'])) {
        ?>
		<div class="substrate">
			<img src="<?php 
        echo $certificate['background'];
        ?>
" class="fullwidth" alt="" />
		</div>
		<?php 
    }
    ?>
 /**
  * Saves lesson attachment
  *
  * @access public
  * @return void
  */
 public static function saveAttachment()
 {
     $file = ThemexCore::getRewriteRule('file');
     if (!empty($file)) {
         $index = themex_decode($file);
         $lesson = themex_decode($file, true);
         self::refresh($lesson);
         if (!empty(self::$data['course'])) {
             ThemexCourse::refresh(self::$data['course']);
             if (isset(self::$data['attachments'][$index]) && (ThemexCourse::isSubscriber() && ThemexCourse::isMember() || ThemexCourse::isAuthor() || self::$data['status'] == 'free')) {
                 $attachment = self::$data['attachments'][$index];
                 if (isset($attachment['status']) && $attachment['status'] == 'link') {
                     wp_redirect($attachment['url']);
                 } else {
                     $name = basename($attachment['url']);
                     header('Content-Type: application/octet-stream');
                     header('Content-Transfer-Encoding: Binary');
                     header('Content-disposition: attachment; filename="' . $name . '"');
                     readfile($attachment['url']);
                 }
             } else {
                 wp_redirect(get_permalink(self::$data['course']));
             }
             exit;
         }
         wp_redirect(SITE_URL);
         exit;
     }
 }