public static function getDefault($adminEmail)
    {
        $email = new WpProQuiz_Model_Email();
        if ($adminEmail) {
            $email->setSubject(__('Wp-Pro-Quiz: One user completed a quiz', 'wp-pro-quiz'));
            $email->setMessage(__('Wp-Pro-Quiz

The user "$username" has completed "$quizname" the quiz.

Points: $points
Result: $result

', 'wp-pro-quiz'));
        } else {
            $email->setSubject(__('Wp-Pro-Quiz: One user completed a quiz', 'wp-pro-quiz'));
            $email->setMessage(__('Wp-Pro-Quiz

You have completed the quiz "$quizname".

Points: $points
Result: $result

', 'wp-pro-quiz'));
        }
        return $email;
    }
    private function upgradeDbV23()
    {
        $this->_wpdb->query('
			ALTER TABLE  ' . $this->_wpdb->prefix . 'wp_pro_quiz_master  
				ADD  `admin_email` TEXT NOT NULL ,
				ADD  `user_email` TEXT NOT NULL ;
		');
        $mapper = new WpProQuiz_Model_GlobalSettingsMapper();
        $adminEmail = $mapper->getEmailSettings();
        $userEmail = $mapper->getUserEmailSettings();
        $adminEmailNew = new WpProQuiz_Model_Email();
        $adminEmailNew->setTo($adminEmail['to']);
        $adminEmailNew->setFrom($adminEmail['from']);
        $adminEmailNew->setSubject($adminEmail['subject']);
        $adminEmailNew->setHtml($adminEmail['html']);
        $adminEmailNew->setMessage($adminEmail['message']);
        $userEmailNew = new WpProQuiz_Model_Email();
        $userEmailNew->setFrom($userEmail['from']);
        $userEmailNew->setToUser(true);
        $userEmailNew->setSubject($userEmail['subject']);
        $userEmailNew->setHtml($userEmail['html']);
        $userEmailNew->setMessage($userEmail['message']);
        $this->_wpdb->update($this->_wpdb->prefix . 'wp_pro_quiz_master', array('admin_email' => @serialize($adminEmailNew)), array('email_notification' => 1), array('%s'), array('%d'));
        $this->_wpdb->update($this->_wpdb->prefix . 'wp_pro_quiz_master', array('admin_email' => @serialize($adminEmailNew)), array('email_notification' => 2), array('%s'), array('%d'));
        $this->_wpdb->update($this->_wpdb->prefix . 'wp_pro_quiz_master', array('user_email' => @serialize($userEmailNew)), array('user_email_notification' => 1), array('%s'), array('%d'));
        return 24;
    }
 private function createQuizModel($xml)
 {
     $model = new WpProQuiz_Model_Quiz();
     $model->setName(trim($xml->title));
     $model->setText(trim($xml->text));
     $model->setTitleHidden($xml->title->attributes()->titleHidden == 'true');
     $model->setQuestionRandom($xml->questionRandom == 'true');
     $model->setAnswerRandom($xml->answerRandom == 'true');
     $model->setTimeLimit($xml->timeLimit);
     $model->setResultText($xml->resultText);
     $model->setResultGradeEnabled($xml->resultText);
     $model->setCategoryName(trim($xml->category));
     if (isset($xml->resultText)) {
         $attr = $xml->resultText->attributes();
         if ($attr !== null) {
             $model->setResultGradeEnabled($attr->gradeEnabled == 'true');
             if ($model->isResultGradeEnabled()) {
                 $resultArray = array('text' => array(), 'prozent' => array());
                 foreach ($xml->resultText->text as $result) {
                     $resultArray['text'][] = trim((string) $result);
                     $resultArray['prozent'][] = $result->attributes() === null ? 0 : (int) $result->attributes()->prozent;
                 }
                 $model->setResultText($resultArray);
             } else {
                 $model->setResultText(trim((string) $xml->resultText));
             }
         }
     }
     $model->setShowPoints($xml->showPoints == 'true');
     $model->setBtnRestartQuizHidden($xml->btnRestartQuizHidden == 'true');
     $model->setBtnViewQuestionHidden($xml->btnViewQuestionHidden == 'true');
     $model->setNumberedAnswer($xml->numberedAnswer == 'true');
     $model->setHideAnswerMessageBox($xml->hideAnswerMessageBox == 'true');
     $model->setDisabledAnswerMark($xml->disabledAnswerMark == 'true');
     if (isset($xml->statistic)) {
         $attr = $xml->statistic->attributes();
         if ($attr !== null) {
             $model->setStatisticsOn($attr->activated == 'true');
             $model->setStatisticsIpLock($attr->ipLock);
         }
     }
     if (isset($xml->quizRunOnce)) {
         $model->setQuizRunOnce($xml->quizRunOnce == 'true');
         $attr = $xml->quizRunOnce->attributes();
         if ($attr !== null) {
             $model->setQuizRunOnceCookie($attr->cookie == 'true');
             $model->setQuizRunOnceType($attr->type);
             $model->setQuizRunOnceTime($attr->time);
         }
     }
     if (isset($xml->showMaxQuestion)) {
         $model->setShowMaxQuestion($xml->showMaxQuestion == 'true');
         $attr = $xml->showMaxQuestion->attributes();
         if ($attr !== null) {
             $model->setShowMaxQuestionValue($attr->showMaxQuestionValue);
             $model->setShowMaxQuestionPercent($attr->showMaxQuestionPercent == 'true');
         }
     }
     $model->setEndOnFirstIncorrect($xml->endOnFirstIncorrect == 'true');
     if (isset($xml->toplist)) {
         $model->setToplistActivated($xml->toplist->attributes()->activated == 'true');
         $model->setToplistDataAddPermissions($xml->toplist->toplistDataAddPermissions);
         $model->setToplistDataSort($xml->toplist->toplistDataSort);
         $model->setToplistDataAddMultiple($xml->toplist->toplistDataAddMultiple == 'true');
         $model->setToplistDataAddBlock($xml->toplist->toplistDataAddBlock);
         $model->setToplistDataShowLimit($xml->toplist->toplistDataShowLimit);
         $model->setToplistDataShowIn($xml->toplist->toplistDataShowIn);
         $model->setToplistDataCaptcha($xml->toplist->toplistDataCaptcha == 'true');
         $model->setToplistDataAddAutomatic($xml->toplist->toplistDataAddAutomatic == 'true');
     }
     $model->setShowAverageResult($xml->showAverageResult == 'true');
     $model->setPrerequisite($xml->prerequisite == 'true');
     $model->setQuizModus($xml->quizModus);
     $model->setShowReviewQuestion($xml->showReviewQuestion == 'true');
     $model->setQuizSummaryHide($xml->quizSummaryHide == 'true');
     $model->setSkipQuestionDisabled($xml->skipQuestionDisabled == 'true');
     $model->setEmailNotification($xml->emailNotification);
     $model->setUserEmailNotification($xml->userEmailNotification == 'true');
     $model->setShowCategoryScore($xml->showCategoryScore == 'true');
     $model->setHideResultCorrectQuestion($xml->hideResultCorrectQuestion == 'true');
     $model->setHideResultQuizTime($xml->hideResultQuizTime == 'true');
     $model->setHideResultPoints($xml->hideResultPoints == 'true');
     $model->setAutostart($xml->autostart == 'true');
     $model->setForcingQuestionSolve($xml->forcingQuestionSolve == 'true');
     $model->setHideQuestionPositionOverview($xml->hideQuestionPositionOverview == 'true');
     $model->setHideQuestionNumbering($xml->hideQuestionNumbering == 'true');
     //0.27
     $model->setStartOnlyRegisteredUser($xml->startOnlyRegisteredUser == 'true');
     $model->setSortCategories($xml->sortCategories == 'true');
     $model->setShowCategory($xml->showCategory == 'true');
     if (isset($xml->quizModus)) {
         $attr = $xml->quizModus->attributes();
         if ($attr !== null) {
             $model->setQuestionsPerPage($attr->questionsPerPage);
         }
     }
     if (isset($xml->forms)) {
         $attr = $xml->forms->attributes();
         $model->setFormActivated($attr->activated == 'true');
         $model->setFormShowPosition($attr->position);
     }
     //0.29
     if (isset($xml->adminEmail)) {
         $adminEmail = new WpProQuiz_Model_Email();
         $adminEmail->setTo($xml->adminEmail->to);
         $adminEmail->setFrom($xml->adminEmail->form);
         $adminEmail->setSubject($xml->adminEmail->subject);
         $adminEmail->setHtml($xml->adminEmail->html == 'true');
         $adminEmail->setMessage($xml->adminEmail->message);
         $model->setAdminEmail($adminEmail);
     }
     if (isset($xml->userEmail)) {
         $userEmail = new WpProQuiz_Model_Email();
         $userEmail->setTo($xml->userEmail->to);
         $userEmail->setToUser($xml->userEmail->toUser == 'true');
         $userEmail->setToForm($xml->userEmail->toForm == 'true');
         $userEmail->setFrom($xml->userEmail->form);
         $userEmail->setSubject($xml->userEmail->subject);
         $userEmail->setHtml($xml->userEmail->html == 'true');
         $userEmail->setMessage($xml->userEmail->message);
         $model->setUserEmail($userEmail);
     }
     //Check
     if ($model->getName() == '') {
         return null;
     }
     if ($model->getText() == '') {
         return null;
     }
     return $model;
 }
    private function userEmailOption()
    {
        /** @var WpProQuiz_Model_Email * */
        $email = $this->quiz->getUserEmail();
        $email = $email === null ? WpProQuiz_Model_Email::getDefault(false) : $email;
        $to = $email->getTo();
        ?>
        <div class="postbox" id="userEmailSettings">
            <h3 class="hndle"><?php 
        _e('User e-mail settings', 'wp-pro-quiz');
        ?>
</h3>

            <div class="inside">
                <table class="form-table">
                    <tbody>
                    <tr>
                        <th scope="row">
                            <?php 
        _e('User e-mail notification', 'wp-pro-quiz');
        ?>
                        </th>
                        <td>
                            <fieldset>
                                <legend class="screen-reader-text">
                                    <span><?php 
        _e('User e-mail notification', 'wp-pro-quiz');
        ?>
</span>
                                </legend>
                                <label>
                                    <input type="checkbox" name="userEmailNotification"
                                           value="1" <?php 
        $this->checked($this->quiz->isUserEmailNotification());
        ?>
>
                                    <?php 
        _e('Activate', 'wp-pro-quiz');
        ?>
                                </label>

                                <p class="description">
                                    <?php 
        _e('If you enable this option, an email is sent with his quiz result to the user.', 'wp-pro-quiz');
        ?>
                                </p>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">
                            <?php 
        _e('To:', 'wp-pro-quiz');
        ?>
                        </th>
                        <td>
                            <label>
                                <input type="checkbox" name="userEmail[toUser]"
                                       value="1" <?php 
        $this->checked($email->isToUser());
        ?>
>
                                <?php 
        _e('User Email-Address (only registered users)', 'wp-pro-quiz');
        ?>
                            </label><br>
                            <label>
                                <input type="checkbox" name="userEmail[toForm]"
                                       value="1" <?php 
        $this->checked($email->isToForm());
        ?>
>
                                <?php 
        _e('Custom fields', 'wp-pro-quiz');
        ?>
 :
                                <select name="userEmail[to]" class="emailFormVariables"
                                        data-default="<?php 
        echo empty($to) && $to != 0 ? -1 : $email->getTo();
        ?>
"></select>
                                <?php 
        _e('(Type Email)', 'wp-pro-quiz');
        ?>
                            </label>

                        </td>
                    </tr>
                    <tr>
                        <th scope="row">
                            <?php 
        _e('From:', 'wp-pro-quiz');
        ?>
                        </th>
                        <td>
                            <label>
                                <input type="text" name="userEmail[from]" value="<?php 
        echo $email->getFrom();
        ?>
"
                                       class="regular-text">
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">
                            <?php 
        _e('Subject:', 'wp-pro-quiz');
        ?>
                        </th>
                        <td>
                            <label>
                                <input type="text" name="userEmail[subject]" value="<?php 
        echo $email->getSubject();
        ?>
"
                                       class="regular-text">
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">
                            <?php 
        _e('HTML', 'wp-pro-quiz');
        ?>
                        </th>
                        <td>
                            <label>
                                <input type="checkbox" name="userEmail[html]"
                                       value="1" <?php 
        $this->checked($email->isHtml());
        ?>
> <?php 
        _e('Activate', 'wp-pro-quiz');
        ?>
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">
                            <?php 
        _e('Message body:', 'wp-pro-quiz');
        ?>
                        </th>
                        <td>
                            <?php 
        wp_editor($email->getMessage(), 'userEmailEditor', array('textarea_rows' => 20, 'textarea_name' => 'userEmail[message]'));
        ?>

                            <div style="padding-top: 10px;">
                                <table style="width: 100%;">
                                    <thead>
                                    <tr>
                                        <th style="padding: 0;">
                                            <?php 
        _e('Allowed variables', 'wp-pro-quiz');
        ?>
                                        </th>
                                        <th style="padding: 0;">
                                            <?php 
        _e('Custom fields - Variables', 'wp-pro-quiz');
        ?>
                                        </th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr>
                                        <td style="vertical-align: top;">
                                            <ul>
                                                <li><span>$userId</span> - <?php 
        _e('User-ID', 'wp-pro-quiz');
        ?>
</li>
                                                <li><span>$username</span> - <?php 
        _e('Username', 'wp-pro-quiz');
        ?>
                                                </li>
                                                <li><span>$quizname</span> - <?php 
        _e('Quiz-Name', 'wp-pro-quiz');
        ?>
                                                </li>
                                                <li><span>$result</span> - <?php 
        _e('Result in precent', 'wp-pro-quiz');
        ?>
</li>
                                                <li><span>$points</span> - <?php 
        _e('Reached points', 'wp-pro-quiz');
        ?>
                                                </li>
                                                <li><span>$ip</span> - <?php 
        _e('IP-address of the user', 'wp-pro-quiz');
        ?>
</li>
                                                <li><span>$categories</span> - <?php 
        _e('Category-Overview', 'wp-pro-quiz');
        ?>
</li>
                                            </ul>
                                        </td>
                                        <td style="vertical-align: top;">
                                            <ul class="formVariables"></ul>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>

                            </div>

                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <?php 
    }