コード例 #1
0
    function JQ_GetQuestData_nojs($q_data, $jq_language, $stu_quiz_id = 0)
    {
        global $JLMS_DB, $my, $option, $JLMS_CONFIG;
        $ret_str = '';
        $cur_template = 'joomlaquiz_lms_template';
        if ($cur_template) {
            require_once dirname(__FILE__) . '/templates/' . $cur_template . '/jq_template.php';
            $ret_add = '';
            $test_text = $q_data->c_question;
            require_once dirname(__FILE__) . '/../lms_certificates.php';
            $a = new stdClass();
            $a->quiz_id = $q_data->c_quiz_id;
            $a->stu_quiz_id = $stu_quiz_id;
            $test_text = JLMS_Certificates::ReplaceQuizAnswers($test_text, $a, $my->id, $q_data->course_id);
            $test_text = JLMS_Certificates::ReplaceEventOptions($test_text, $a, $my->id, $q_data->course_id);
            $test_text = str_replace('#date#', date('m-d-Y', time() - date('Z')), $test_text);
            $q_data->c_question = $test_text;
            if ($q_data->c_type == 7) {
                //temporary for 'hotspot' support
                $ret_add = '<div style="text-align:center;">' . $q_data->c_question . '</div>';
            } else {
                $q_description = JLMS_ShowText_WithFeatures($q_data->c_question, true);
                $ret_add = '<div style="text-align:center;">' . $q_description . '</div>';
            }
            //		$ret_str = "\t" . '<quest_data>'.$ret_add.'</quest_data>' . "\n";
            $ret_str = "\t" . $ret_add . "\n";
            $ret_str .= "\t" . '<input type="hidden" name="quest_type" value="' . $q_data->c_type . '"/>' . "\n";
            $ret_str .= "\t" . '<input type="hidden" name="quest_id" value="' . $q_data->c_id . '"/>' . "\n";
            $ret_str .= "\t" . '<input type="hidden" name="quest_score" value="' . $q_data->c_point . '"/>' . "\n";
            $qtype = $q_data->c_type;
            $qu_id = $q_data->c_id;
            if ($q_data->c_pool) {
                $qu_id = $q_data->c_pool;
            }
            $quest_params = new JLMSParameters($q_data->params);
            switch ($qtype) {
                case 1:
                case 12:
                    if ($quest_params->get('mandatory') == 1 && $quest_params->get('survey_question') == 1) {
                        $is_mandatory = 1;
                    } else {
                        $is_mandatory = 0;
                    }
                    $sql_var = '';
                    $sql_table = '';
                    $sql_where = '';
                    if ($qtype == 12) {
                        $sql_var .= ', b.imgs_name';
                        $sql_table = ', #__lms_quiz_images as b';
                        $sql_where .= ' AND a.c_choice = b.imgs_id';
                    }
                    $query = "SELECT a.c_id as value, a.c_choice as text, '0' as c_right, '0' as c_review" . $sql_var . " FROM #__lms_quiz_t_choice as a" . $sql_table . " WHERE a.c_question_id = '" . $qu_id . "'" . $sql_where . " ORDER BY a.ordering";
                    $JLMS_DB->SetQuery($query);
                    $choice_data = $JLMS_DB->LoadObjectList();
                    $qhtml = JoomlaQuiz_template_class::JQ_createMChoice($choice_data, $qtype);
                    //				$ret_str .= "\t" . '<quest_data_user><div>'.$qhtml.'<input type="hidden" name="ismandatory" value="'.$is_mandatory.'" /></div></quest_data_user>' . "\n";
                    $ret_str .= "\t" . '<div>' . $qhtml . '<input type="hidden" name="ismandatory" value="' . $is_mandatory . '" /></div>' . "\n";
                    break;
                case 3:
                    $query = "SELECT c_id as value, c_choice as text, '0' as c_right, '0' as c_review FROM #__lms_quiz_t_choice WHERE c_question_id = '" . $qu_id . "' ORDER BY ordering";
                    $JLMS_DB->SetQuery($query);
                    $choice_data = $JLMS_DB->LoadObjectList();
                    $i = 0;
                    while ($i < count($choice_data)) {
                        if ($choice_data[$i]->text == 'true' || $choice_data[$i]->text == 'True') {
                            $choice_data[$i]->text = $jq_language['quiz_simple_true'];
                        } elseif ($choice_data[$i]->text == 'false' || $choice_data[$i]->text == 'False') {
                            $choice_data[$i]->text = $jq_language['quiz_simple_false'];
                        }
                        $i++;
                    }
                    $qhtml = JoomlaQuiz_template_class::JQ_createMChoice($choice_data, $qtype);
                    $ret_str .= "\t" . '<div style="text-align:center;">' . $qhtml . '</div>' . "\n";
                    break;
                case 2:
                case 13:
                    $sql_var = '';
                    $sql_table = '';
                    $sql_where = '';
                    if ($qtype == 13) {
                        $sql_var .= ', b.imgs_name';
                        $sql_table = ', #__lms_quiz_images as b';
                        $sql_where .= ' AND a.c_choice = b.imgs_id';
                    }
                    $query = "SELECT a.c_id as value, a.c_choice as text, '0' as c_right, '0' as c_review" . $sql_var . " FROM #__lms_quiz_t_choice as a" . $sql_table . " WHERE a.c_question_id = '" . $qu_id . "'" . $sql_where . " ORDER BY a.ordering";
                    $JLMS_DB->SetQuery($query);
                    $choice_data = $JLMS_DB->LoadObjectList();
                    $qhtml = JoomlaQuiz_template_class::JQ_createMResponse($choice_data, $qtype, 1);
                    $ret_str .= "\t" . '<div>' . $qhtml . '</div>' . "\n";
                    break;
                case 4:
                    $query = "SELECT *, c_right_text as c_val FROM #__lms_quiz_t_matching WHERE c_question_id = '" . $qu_id . "'" . "\n ORDER BY ordering";
                    $JLMS_DB->SetQuery($query);
                    $match_data = $JLMS_DB->LoadObjectList();
                    $shuffle_match = $match_data;
                    shuffle($shuffle_match);
                    for ($di = 0, $dn = count($shuffle_match); $di < $dn; $di++) {
                        $shuffle_match[$di]->c_val = md5($shuffle_match[$di]->c_val);
                    }
                    //				$ret_str .= "\t" . '<div>'
                    //				. '<div id="cont" class="d_cont"><div id="col_1" style="float:left; width:49%;">';
                    //				for ($i=0, $n = count( $match_data ); $i < $n; $i++ ) {
                    //					$ret_str .= '<div id=\'cdiv_'.($i+1).'\' class=\'jq_drop\'>'
                    //					. $match_data[$i]->c_left_text . '</div>';
                    //				}
                    //				$ret_str .= '</div><div id="col_2" style="float:left; width:49%;">';
                    //				for ($i=0, $n = count( $shuffle_match ); $i < $n; $i++ ) {
                    //					$ret_str .= '<div id=\'ddiv_'.($i+1).'\' class=\'jq_drag\'>' //onmousedown=\'startDrag()\' onmouseup=\'stopDrag()\'
                    //					. $shuffle_match[$i]->c_right_text . '</div>';
                    //				}
                    //				$ret_str .= '</div><div style="clear:both;"><!-- --></div></div>';
                    //				$ret_str .= '</div>' . "\n";
                    $shuffle_match1 = array();
                    $shuffle_match1[0]->c_right_text = _JLMS_QUIZ_SHOW_SELECT_YOUR_ANSWER;
                    $shuffle_match1[0]->c_val = '{0}';
                    $shuffle_match1 = array_merge($shuffle_match1, $shuffle_match);
                    $qdata = array();
                    for ($i = 0, $n = count($match_data); $i < $n; $i++) {
                        $qdata[$i]->c_left_text = '<div class=\'jq_drop\'>' . $match_data[$i]->c_left_text . '</div>';
                        $qdata[$i]->c_right_text = mosHTML::selectList($shuffle_match1, 'quest_match[' . $i . ']', 'class="inputbox" size="1" ', 'c_val', 'c_right_text', null);
                    }
                    $qhtml = JoomlaQuiz_template_class::JQ_createMDropDown($qdata);
                    $ret_str .= "\t" . '<div>' . $qhtml . '</div>' . "\n";
                    break;
                case 5:
                    $query = "SELECT *, c_right_text as c_val FROM #__lms_quiz_t_matching WHERE c_question_id = '" . $qu_id . "'" . "\n ORDER BY ordering";
                    $JLMS_DB->SetQuery($query);
                    $match_data = $JLMS_DB->LoadObjectList();
                    $shuffle_match = $match_data;
                    shuffle($shuffle_match);
                    for ($di = 0, $dn = count($shuffle_match); $di < $dn; $di++) {
                        $shuffle_match[$di]->c_val = md5($shuffle_match[$di]->c_val);
                    }
                    $shuffle_match1 = array();
                    $shuffle_match1[0]->c_right_text = _JLMS_QUIZ_SHOW_SELECT_YOUR_ANSWER;
                    $shuffle_match1[0]->c_val = '{0}';
                    $shuffle_match1 = array_merge($shuffle_match1, $shuffle_match);
                    $qdata = array();
                    for ($i = 0, $n = count($match_data); $i < $n; $i++) {
                        $qdata[$i]->c_left_text = $match_data[$i]->c_left_text;
                        $qdata[$i]->c_right_text = mosHTML::selectList($shuffle_match1, 'quest_match[' . $i . ']', 'class="inputbox" size="1" ', 'c_val', 'c_right_text', null);
                    }
                    $qhtml = JoomlaQuiz_template_class::JQ_createMDropDown($qdata);
                    $ret_str .= "\t" . '<div>' . $qhtml . '</div>' . "\n";
                    break;
                case 6:
                    //$quest_params = new JLMSParameters($q_data->params);
                    if ($quest_params->get('mandatory') == 1 && $quest_params->get('survey_question') == 1) {
                        $is_mandatory = 1;
                    } else {
                        $is_mandatory = 0;
                    }
                    $def_cb = '';
                    $def_cb = '';
                    if ($quest_params->get('survey_question')) {
                        $query = "SELECT c_default FROM #__lms_quiz_t_blank WHERE c_question_id = '" . $qu_id . "'";
                        $JLMS_DB->SetQuery($query);
                        $blank_data = $JLMS_DB->LoadObjectList();
                        if (isset($blank_data[0]->c_default) && $blank_data[0]->c_default) {
                            $def_cb = $blank_data[0]->c_default;
                        }
                    }
                    if ($def_cb) {
                        $def_cb = str_replace('{', '', $def_cb);
                        $def_cb = str_replace('}', '', $def_cb);
                        require _JOOMLMS_FRONT_HOME . '/includes/classes/lms.cb_join.php';
                        $def_cb2 = JLMSCBJoin::getASSOC($def_cb);
                        if ($def_cb2) {
                            $def_cb = $def_cb2;
                        }
                        $def_cb = str_replace('#date#', date('m-d-Y', time() - date('Z')), $def_cb);
                    }
                    $qhtml = JoomlaQuiz_template_class::JQ_createBlank('', $def_cb);
                    $ret_str .= '<div style="text-align:center;">' . $qhtml . '</div>' . "\n" . "\t" . '<input type="hidden" name="ismandatory" value="' . $is_mandatory . '" />' . "\n";
                    break;
                case 7:
                    global $JLMS_CONFIG;
                    $is_hotspot_manual_correct = $JLMS_CONFIG->get('quiz_hs_offset_manual_correction');
                    $hs_div_offset_class = $JLMS_CONFIG->get('quiz_hs_offset_div_class');
                    $hs_manual_offset = $JLMS_CONFIG->get('quiz_hs_ofset_manual_value');
                    $src = 'images/joomlaquiz/images/' . $q_data->c_image . '';
                    $qhtml = '<input type="image" name="hotspot" value="hs" src="' . $src . '"/>';
                    $ret_str .= "\t" . '<div style="text-align:center;">' . $qhtml . '</div>' . "\n";
                    break;
                case 8:
                    if ($quest_params->get('mandatory') == 1) {
                        $is_mandatory = 1;
                    } else {
                        $is_mandatory = 0;
                    }
                    $qhtml = JoomlaQuiz_template_class::JQ_createSurvey();
                    // 'Survey' - question type
                    $ret_str .= '<div style="text-align:center;">' . $qhtml . "</div>\n" . "\t" . '<input type="hidden" name="ismandatory" value="' . $is_mandatory . '" />' . "\n";
                    break;
                case 9:
                    if ($quest_params->get('mandatory') == 1) {
                        $is_mandatory = 1;
                    } else {
                        $is_mandatory = 0;
                    }
                    $query = "SELECT * FROM #__lms_quiz_t_scale WHERE c_question_id = '" . $qu_id . "'" . "\n ORDER BY ordering";
                    $JLMS_DB->SetQuery($query);
                    $scale_data = $JLMS_DB->LoadObjectList();
                    $qhtml = JoomlaQuiz_template_class::JQ_createScale($scale_data, 0);
                    $ret_str .= "\t" . '<div>' . $qhtml . '<input type="hidden" name="ismandatory" value="' . $is_mandatory . '" /></div>' . "\n";
                    break;
                case 10:
                    $ret_str .= "\n" . "\t" . '' . "\n";
                    break;
                case 11:
                    $query = "SELECT a.*, a.c_right_text as c_val, b.imgs_name as left_name, c.imgs_name as right_name FROM #__lms_quiz_t_matching as a, #__lms_quiz_images as b, #__lms_quiz_images as c WHERE c_question_id = '" . $qu_id . "' AND a.c_left_text = b.imgs_id AND a.c_right_text = c.imgs_id" . "\n ORDER BY a.ordering";
                    $JLMS_DB->SetQuery($query);
                    $match_data = $JLMS_DB->LoadObjectList();
                    $shuffle_match = $match_data;
                    shuffle($shuffle_match);
                    for ($di = 0, $dn = count($shuffle_match); $di < $dn; $di++) {
                        $shuffle_match[$di]->c_val = md5($shuffle_match[$di]->c_val);
                    }
                    $shuffle_match1 = array();
                    $shuffle_match1[0]->right_name = _JLMS_QUIZ_SHOW_SELECT_YOUR_ANSWER;
                    $shuffle_match1[0]->c_val = '{0}';
                    $shuffle_match1 = array_merge($shuffle_match1, $shuffle_match);
                    $qdata = array();
                    for ($i = 0, $n = count($match_data); $i < $n; $i++) {
                        $link = 'index.php?tmpl=component&option=' . $option . '&task=quizzes&page=imgs_v&file_id=' . $match_data[$i]->c_left_text . '&imgs_name=' . $match_data[$i]->left_name;
                        $qdata[$i]->c_left_text = '<div class=\'jq_drop\' style=\'width: ' . $JLMS_CONFIG->get('quiz_match_max_width', 250) . 'px; height: ' . $JLMS_CONFIG->get('quiz_match_max_height', 30) . 'px;\'>
					<img src="' . ampReplace($JLMS_CONFIG->get('live_site') . '/index.php?tmpl=component&option=' . $option . '&task=quizzes&page=imgs_v&id=' . $q_data->course_id . '&file_id=' . $match_data[$i]->c_left_text . '&imgs_name=' . $match_data[$i]->left_name . '&pic_width=' . $JLMS_CONFIG->get('quiz_match_max_width', 250) . '&pic_height=' . $JLMS_CONFIG->get('quiz_match_max_height', 250) . '&bg_color=dddddd" border="0" alt="' . $match_data[$i]->left_name) . '" title="' . $match_data[$i]->left_name . '"/>
					</div>';
                        $qdata[$i]->c_right_text = mosHTML::selectList($shuffle_match1, 'quest_match[' . $i . ']', 'class="inputbox" size="1" ', 'c_val', 'right_name', null);
                    }
                    $qhtml = JoomlaQuiz_template_class::JQ_createMDropDown($qdata);
                    $ret_str .= "\t" . '<div>' . $qhtml . '</div>' . "\n";
                    break;
            }
        }
        return $ret_str;
    }
コード例 #2
0
 function JLMS_outputCertificate($id, $course_id, $txt_mes_obj = null, $user_obj = null)
 {
     global $JLMS_DB, $JLMS_CONFIG, $my;
     if (is_null($user_obj)) {
         $user_obj = new stdClass();
         $user_obj->id = $my->id;
         $user_obj->username = $my->username;
         $user_obj->email = $my->email;
         $user_obj->name = $my->name;
     }
     $JLMS_ACL =& JLMSFactory::getACL();
     $is_preview = false;
     $is_exist = false;
     $quiz_id = 0;
     $quiz_name = '';
     $course_name = '';
     if (isset($txt_mes_obj->is_preview)) {
         $is_preview = $txt_mes_obj->is_preview;
     }
     if (isset($txt_mes_obj->quiz_id)) {
         $quiz_id = $txt_mes_obj->quiz_id;
     }
     if (isset($txt_mes_obj->quiz_name)) {
         $quiz_name = $txt_mes_obj->quiz_name;
     }
     if (isset($txt_mes_obj->course_name)) {
         $course_name = $txt_mes_obj->course_name;
     }
     $do_s = true;
     $crtf_role = 0;
     if ($is_preview) {
         $crtf_role = intval(mosGetParam($_REQUEST, 'crtf_role', 0));
     } else {
         $crtf_role = intval($JLMS_ACL->GetRole(1));
     }
     if ($crtf_role) {
         $query = "SELECT a.*, b.course_name FROM #__lms_certificates as a, #__lms_courses as b WHERE a.course_id = '" . $course_id . "' AND a.course_id = b.id AND a.parent_id = {$id} AND a.crtf_type = {$crtf_role}";
         $JLMS_DB->SetQuery($query);
         $crts = $JLMS_DB->loadObjectList();
         if (count($crts) == 1) {
             if ($crts[0]->file_id) {
                 $do_s = false;
             } else {
                 $query = "SELECT file_id FROM #__lms_certificates as a WHERE a.id = '" . $id . "' AND a.course_id = '" . $course_id . "' AND a.parent_id = 0";
                 $JLMS_DB->SetQuery($query);
                 $crts[0]->file_id = $JLMS_DB->LoadResult();
                 if ($crts[0]->file_id) {
                     $do_s = false;
                 }
             }
         }
     }
     if ($do_s) {
         $query = "SELECT a.*, b.course_name FROM #__lms_certificates as a, #__lms_courses as b WHERE a.id = '" . $id . "' AND a.course_id = '" . $course_id . "' AND a.course_id = b.id AND a.parent_id = 0";
         $JLMS_DB->SetQuery($query);
         $crts = $JLMS_DB->loadObjectList();
     }
     if (count($crts) == 1) {
         $is_duplicate = false;
         $print_duplicate_watermark = $JLMS_CONFIG->get('crtf_duplicate_wm', true);
         $crt = $crts[0];
         $JLMS_DB->SetQuery("SELECT file_srv_name FROM #__lms_files WHERE id = '" . $crt->file_id . "'");
         $cert_name = $JLMS_DB->LoadResult();
         if ($cert_name) {
             $ucode = md5(uniqid(rand(), true));
             $ex_crtf_id = 0;
             $is_saved_on_server = false;
             $ucode = substr($ucode, 0, 10);
             if (!$is_preview) {
                 $query = "SELECT * FROM #__lms_certificate_prints WHERE user_id = {$user_obj->id} AND role_id = {$crtf_role} AND course_id = {$course_id} AND crtf_id = {$id} AND quiz_id = {$quiz_id}";
                 $JLMS_DB->SetQuery($query);
                 $cr_pr = $JLMS_DB->LoadObject();
                 if (is_object($cr_pr) && isset($cr_pr->id)) {
                     $is_exist = $cr_pr->id;
                     $ex_crtf_id = $cr_pr->id;
                     $ucode = $cr_pr->uniq_id;
                     $txt_mes_obj->name = $cr_pr->name;
                     $txt_mes_obj->username = $cr_pr->username;
                     //$txt_mes_obj->course_name = $cr_pr->course_name;
                     if (isset($txt_mes_obj->force_update_print_date) && $txt_mes_obj->force_update_print_date && isset($txt_mes_obj->crtf_date) && $txt_mes_obj->crtf_date) {
                         $query = "UPDATE #__lms_certificate_prints SET crtf_date = '" . $txt_mes_obj->crtf_date . "' WHERE id = " . $cr_pr->id . " AND user_id = {$user_obj->id} AND role_id = {$crtf_role} AND course_id = {$course_id} AND crtf_id = {$id} AND quiz_id = {$quiz_id}";
                         $JLMS_DB->SetQuery($query);
                         $JLMS_DB->query();
                     } else {
                         $txt_mes_obj->crtf_date = strtotime($cr_pr->crtf_date);
                     }
                     $is_duplicate = true;
                     if ($JLMS_CONFIG->get('save_certificates', 1)) {
                         $im_crtf_path = $JLMS_CONFIG->get('jlms_crtf_folder', '');
                         $file_on_srv = $im_crtf_path . '/' . md5($ex_crtf_id . '_' . $ucode) . '.png';
                         if (file_exists($file_on_srv)) {
                             $is_saved_on_server = true;
                         }
                     }
                 }
             }
             if ($is_saved_on_server) {
                 $loadFile = $file_on_srv;
             } else {
                 $loadFile = _JOOMLMS_DOC_FOLDER . $cert_name;
             }
             $im_fullsize = getimagesize($loadFile);
             if (isset($im_fullsize[2])) {
                 if ($im_fullsize[2] == 1) {
                     $im = imagecreatefromgif($loadFile);
                 } elseif ($im_fullsize[2] == 2) {
                     $im = imagecreatefromjpeg($loadFile);
                 } elseif ($im_fullsize[2] == 3) {
                     $im = imagecreatefrompng($loadFile);
                     if (function_exists('imagesavealpha')) {
                         imagesavealpha($im, true);
                     }
                 } else {
                     die;
                 }
             } else {
                 die('Bad image format.');
             }
             if (!$is_saved_on_server) {
                 require_once dirname(__FILE__) . '/libchart/barcode.php';
                 $b_params = array();
                 if ($JLMS_CONFIG->get('crtf_show_sn', 1)) {
                     $b_params[] = 'text';
                 }
                 if ($JLMS_CONFIG->get('crtf_show_barcode', 1)) {
                     $b_params[] = 'bar';
                 }
             }
             $origWidth = $im_fullsize[0];
             $origHeight = $im_fullsize[1];
             if ($is_duplicate && $print_duplicate_watermark) {
                 require_once _JOOMLMS_FRONT_HOME . DS . "includes" . DS . "libchart" . DS . "libchart.php";
                 JLMS_cleanLibChartCache();
                 $watermark = _JOOMLMS_FRONT_HOME . DS . "lms_images" . DS . "duplicate.png";
                 $wmTarget = $JLMS_CONFIG->getCfg('absolute_path') . "/" . ($JLMS_CONFIG->get('temp_folder', '') ? $JLMS_CONFIG->get('temp_folder', '') . "/" : '') . time() . '_' . md5(uniqid(rand(), true)) . ".png";
                 $waterMarkInfo = getimagesize($watermark);
                 $waterMarkWidth = $waterMarkInfo[0];
                 $waterMarkHeight = $waterMarkInfo[1];
                 $placementX = 0;
                 $placementY = 0;
                 $waterMarkDestWidth = $waterMarkWidth;
                 $waterMarkDestHeight = $waterMarkHeight;
                 $waterMarkDestWidth = round($origWidth / $waterMarkDestWidth * $waterMarkDestWidth);
                 $waterMarkDestHeight = round($origHeight / $waterMarkDestHeight * $waterMarkDestHeight);
                 // both of the watermark dimensions need to be 5% more than the original image...
                 // adjust width first.
                 #if($waterMarkWidth > $origWidth*0.95 && $waterMarkHeight > $origHeight*0.95) {
                 // both are already larger than the original by at least 5%...
                 // we need to make the watermark *smaller* for this one.
                 /*
                 					// where is the largest difference?
                 					$wdiff=$waterMarkDestWidth - $origWidth;
                 					$hdiff=$waterMarkDestHeight - $origHeight;
                 					if($wdiff > $hdiff) {
                 						// the width has the largest difference - get percentage
                 						$sizer=($wdiff/$waterMarkDestWidth)+0.05;
                 					} else {
                 						$sizer=($hdiff/$waterMarkDestHeight)+0.05;
                 					}
                 					$waterMarkDestWidth-=$waterMarkDestWidth * $sizer;
                 					$waterMarkDestHeight-=$waterMarkDestHeight * $sizer;*/
                 #$waterMarkDestWidth = round(($origWidth / $waterMarkDestWidth) * $waterMarkDestWidth);
                 #$waterMarkDestHeight = round(($origHeight / $waterMarkDestHeight) * $waterMarkDestHeight);
                 #} else {
                 // the watermark will need to be enlarged for this one
                 // where is the largest difference?
                 /*$wdiff=$origWidth - $waterMarkDestWidth;
                 		$hdiff=$origHeight - $waterMarkDestHeight;
                 		if($wdiff > $hdiff) {
                 			// the width has the largest difference - get percentage
                 			$sizer=($wdiff/$waterMarkDestWidth)+0.05;
                 		} else {
                 			$sizer=($hdiff/$waterMarkDestHeight)+0.05;
                 		}
                 		$waterMarkDestWidth+=$waterMarkDestWidth * $sizer;
                 		$waterMarkDestHeight+=$waterMarkDestHeight * $sizer;*/
                 #$waterMarkDestWidth = round(($origWidth / $waterMarkDestWidth) * $waterMarkDestWidth);
                 #$waterMarkDestHeight = round(($origHeight / $waterMarkDestHeight) * $waterMarkDestHeight);
                 #}
                 JLMS_Certificates::resize_png_image($watermark, $waterMarkDestWidth, $waterMarkDestHeight, $wmTarget, false);
                 // get the size info for this watermark.
                 $wmInfo = getimagesize($wmTarget);
                 $waterMarkDestWidth = $wmInfo[0];
                 $waterMarkDestHeight = $wmInfo[1];
                 $differenceX = $origWidth - $waterMarkDestWidth;
                 $differenceY = $origHeight - $waterMarkDestHeight;
                 $placementX = round($differenceX / 2);
                 $placementY = round($differenceY / 2);
             }
             if (!$is_saved_on_server) {
                 if (!empty($b_params)) {
                     $barcode = new JLMS_barcode($ucode, $b_params);
                     $barcode->generate($im, $origWidth, $origHeight);
                 }
                 $white = imagecolorallocate($im, 255, 255, 255);
                 $grey = imagecolorallocate($im, 128, 128, 128);
                 $black = imagecolorallocate($im, 0, 0, 0);
                 $text_messages = array();
                 $crtf_msg = new stdClass();
                 $crtf_msg->text_size = $crt->text_size;
                 $crtf_msg->text_x = $crt->text_x;
                 $crtf_msg->text_y = $crt->text_y;
                 $crtf_msg->crtf_font = isset($crt->crtf_font) && $crt->crtf_font ? $crt->crtf_font : 'arial.ttf';
                 $crtf_msg->crtf_text = $crt->crtf_text;
                 $crtf_msg->course_name = $crt->course_name;
                 $crtf_msg->crtf_shadow = $crt->crtf_shadow;
                 $crtf_msg->crtf_align = $crt->crtf_align;
                 $text_messages[] = $crtf_msg;
                 $query = "SELECT * FROM #__lms_certificates WHERE course_id = {$course_id} AND parent_id = {$crt->id} AND crtf_type = '-2' ORDER BY crtf_align";
                 $JLMS_DB->SetQuery($query);
                 $add_cert_msgs = $JLMS_DB->LoadObjectList();
                 foreach ($add_cert_msgs as $acms) {
                     $crtf_msg = new stdClass();
                     $crtf_msg->text_size = $acms->text_size;
                     $crtf_msg->text_x = $acms->text_x;
                     $crtf_msg->text_y = $acms->text_y;
                     $crtf_msg->crtf_font = isset($acms->crtf_font) && $acms->crtf_font ? $acms->crtf_font : 'arial.ttf';
                     $crtf_msg->crtf_text = $acms->crtf_text;
                     $crtf_msg->course_name = $crt->course_name;
                     $crtf_msg->crtf_shadow = $acms->crtf_shadow;
                     $crtf_msg->crtf_align = 0;
                     $text_messages[] = $crtf_msg;
                 }
                 foreach ($text_messages as $crt7) {
                     $font_size = $crt7->text_size;
                     $font_x = $crt7->text_x;
                     $font_y = $crt7->text_y;
                     $font_filename = $crt7->crtf_font;
                     $inform = array();
                     $font_text = $crt7->crtf_text;
                     $username = isset($txt_mes_obj->username) ? $txt_mes_obj->username : '';
                     $name = isset($txt_mes_obj->name) ? $txt_mes_obj->name : '';
                     $course_name = isset($txt_mes_obj->course_name) ? $txt_mes_obj->course_name : $crt7->course_name;
                     //$spec_answer = isset($txt_mes_obj->crtf_spec_answer)?$txt_mes_obj->crtf_spec_answer:'';
                     $crtf_date = isset($txt_mes_obj->crtf_date) ? $txt_mes_obj->crtf_date : time();
                     $font_text = str_replace('#username#', $username, $font_text);
                     $font_text = str_replace('#name#', $name, $font_text);
                     $font_text = str_replace('#course#', $course_name, $font_text);
                     $font_text = JLMS_Certificates::ReplaceCourseRegAnswers($font_text, $txt_mes_obj, $user_obj->id, $course_id);
                     //$font_text = str_replace('#reg_answer#', $spec_answer, $font_text);
                     $font_text = JLMS_Certificates::ReplaceQuizAnswers($font_text, $txt_mes_obj, $user_obj->id, $course_id);
                     $font_text = JLMS_Certificates::ReplaceEventOptions($font_text, $txt_mes_obj, $user_obj->id, $course_id);
                     $font_text = JLMS_Certificates::ReplaceCBProfileOptions($font_text, $txt_mes_obj, $user_obj->id, $course_id);
                     //$font_text = JLMS_Certificates::ReplaceUPN($font_text, $txt_mes_obj, $user_obj->id, $course_id);
                     // replace #date#
                     $str_format = 'Y-m-d';
                     $str_format_pre = '';
                     $first_pos = strpos($font_text, '#date');
                     if ($first_pos !== false) {
                         $first_str = substr($font_text, $first_pos + 5, strlen($font_text) - $first_pos - 5);
                         $sec_pos = strpos($first_str, '#');
                         $str_format = substr($first_str, 0, $sec_pos);
                         $str_format_pre = $str_format;
                         echo $str_format;
                         if ($str_format) {
                             if (substr($str_format, 0, 1) == '(') {
                                 $str_format = substr($str_format, 1);
                             }
                             if (substr($str_format, -1) == ')') {
                                 $str_format = substr($str_format, 0, -1);
                             }
                         }
                         echo $str_format;
                     }
                     if (!$str_format) {
                         $str_format = 'Y-m-d';
                     }
                     $font_text = str_replace('#date' . $str_format_pre . '#', date($str_format, $crtf_date), $font_text);
                     // end of #date#
                     $font = JPATH_SITE . "/media/arial.ttf";
                     if (file_exists(JPATH_SITE . "/media/" . $font_filename)) {
                         $font = JPATH_SITE . "/media/" . $font_filename;
                     }
                     $text_array = explode("\n", $font_text);
                     #print_r($text_array);die;
                     $count_lines = count($text_array);
                     $text_lines_xlefts = array();
                     $text_lines_xrights = array();
                     $text_lines_heights = array();
                     for ($i = 0; $i < $count_lines; $i++) {
                         $font_box = imagettfbbox($font_size, 0, $font, $text_array[$i]);
                         $text_lines_xlefts[$i] = $font_box[0];
                         $text_lines_xrights[$i] = $font_box[2];
                         $text_lines_heights[$i] = $font_box[1] - $font_box[7];
                         if ($text_lines_heights[$i] < $font_size) {
                             $text_lines_heights[$i] = $font_size;
                         }
                     }
                     $min_x = 0;
                     $max_x = 0;
                     $max_w = 0;
                     for ($i = 0; $i < $count_lines; $i++) {
                         if ($min_x > $text_lines_xlefts[$i]) {
                             $min_x = $text_lines_xlefts[$i];
                         }
                         if ($max_x < $text_lines_xrights[$i]) {
                             $max_x = $text_lines_xrights[$i];
                         }
                         if ($max_w < $text_lines_xrights[$i] - $text_lines_xlefts[$i]) {
                             $max_w = $text_lines_xrights[$i] - $text_lines_xlefts[$i];
                         }
                     }
                     #$crt->crtf_text
                     #$alignment = 'left';
                     $allow_shadow = $crt7->crtf_shadow == 1;
                     #$alignment = 'left';
                     switch (intval($crt7->crtf_align)) {
                         case 1:
                             for ($i = 0; $i < $count_lines; $i++) {
                                 $cur_w = $text_lines_xrights[$i] - $text_lines_xlefts[$i];
                                 $ad = intval(($max_w - $cur_w) / 2) - intval($max_w / 2);
                                 if ($allow_shadow) {
                                     imagettftext($im, $font_size, 0, $font_x + $ad + 2, $font_y + 2, $grey, $font, $text_array[$i]);
                                 }
                                 imagettftext($im, $font_size, 0, $font_x + $ad, $font_y, $black, $font, $text_array[$i]);
                                 $font_y = $font_y + $text_lines_heights[$i] + 3;
                             }
                             break;
                         case 2:
                             for ($i = 0; $i < $count_lines; $i++) {
                                 $cur_w = $text_lines_xrights[$i] - $text_lines_xlefts[$i];
                                 $ad = intval($max_w - $cur_w) - intval($max_w);
                                 if ($allow_shadow) {
                                     imagettftext($im, $font_size, 0, $font_x + $ad + 2, $font_y + 2, $grey, $font, $text_array[$i]);
                                 }
                                 imagettftext($im, $font_size, 0, $font_x + $ad, $font_y, $black, $font, $text_array[$i]);
                                 $font_y = $font_y + $text_lines_heights[$i] + 3;
                             }
                             break;
                         default:
                             for ($i = 0; $i < $count_lines; $i++) {
                                 $cur_w = $text_lines_xrights[$i] - $text_lines_xlefts[$i];
                                 $ad = 0;
                                 //intval(($max_w - $cur_w)/2);
                                 if ($allow_shadow) {
                                     imagettftext($im, $font_size, 0, $font_x + $ad + 2, $font_y + 2, $grey, $font, $text_array[$i]);
                                 }
                                 imagettftext($im, $font_size, 0, $font_x + $ad, $font_y, $black, $font, $text_array[$i]);
                                 $font_y = $font_y + $text_lines_heights[$i] + 3;
                             }
                             break;
                     }
                 }
                 #$font_box = imagettfbbox($font_size, 0, $font, $font_text);
                 #imagettftext($im, $font_size, 0, $font_x, $font_y, $grey, $font, $font_text, 'R');
                 #imagettftext($im, $font_size, 0, $font_x, $font_y, $black, $font, $font_text, 'R');
                 #@ob_end_clean();
             }
             if (!$is_preview) {
                 if (!$is_exist) {
                     $query = "INSERT INTO #__lms_certificate_prints (uniq_id, user_id, role_id, crtf_date, crtf_id, crtf_text, last_printed, name, username, course_id, course_name, quiz_id, quiz_name ) VALUES" . "\n (" . $JLMS_DB->Quote($ucode) . ", {$user_obj->id}, {$crtf_role}," . $JLMS_DB->Quote(date('Y-m-d H:i:s', $crtf_date)) . ", {$id}, " . $JLMS_DB->Quote($crt->crtf_text) . "," . "\n " . $JLMS_DB->Quote(date('Y-m-d H:i:s')) . ", " . $JLMS_DB->Quote($user_obj->name) . ", " . $JLMS_DB->Quote($user_obj->username) . "," . "\n {$course_id}, " . $JLMS_DB->Quote($course_name) . ", {$quiz_id}, " . $JLMS_DB->Quote($quiz_name) . ")";
                     $JLMS_DB->SetQuery($query);
                     $JLMS_DB->query();
                     $ex_crtf_id = $JLMS_DB->insertid();
                 } else {
                     $query = "UPDATE #__lms_certificate_prints SET last_printed = " . $JLMS_DB->Quote(date('Y-m-d H:i:s')) . "," . "\n crtf_text = " . $JLMS_DB->Quote($crt->crtf_text) . ", course_name = " . $JLMS_DB->Quote($course_name) . "," . "\n quiz_name = " . $JLMS_DB->Quote($quiz_name) . "\n WHERE id = {$is_exist}";
                     $JLMS_DB->SetQuery($query);
                     $JLMS_DB->query();
                     $ex_crtf_id = $is_exist;
                 }
             }
             if (preg_match('/Opera(\\/| )([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'])) {
                 $UserBrowser = "Opera";
             } elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'])) {
                 $UserBrowser = "IE";
             } else {
                 $UserBrowser = '';
             }
             $file_name = 'Certificate.png';
             header('Content-Type: image/png');
             header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
             if ($UserBrowser == 'IE') {
                 header('Content-Disposition: inline; filename="' . $file_name . '";');
                 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                 header('Pragma: public');
             } else {
                 header('Content-Disposition: inline; filename="' . $file_name . '";');
                 header('Pragma: no-cache');
             }
             @ob_end_clean();
             if (!$is_saved_on_server && !$is_preview) {
                 if ($JLMS_CONFIG->get('save_certificates', 1)) {
                     $im_crtf_path = $JLMS_CONFIG->get('jlms_crtf_folder', '');
                     if ($im_crtf_path && is_writable($im_crtf_path)) {
                         imagepng($im, $im_crtf_path . '/' . md5($ex_crtf_id . '_' . $ucode) . '.png');
                     }
                 }
             }
             if ($is_duplicate && $print_duplicate_watermark) {
                 imagealphablending($im, TRUE);
                 $finalWaterMarkImage = imagecreatefrompng($wmTarget);
                 $finalWaterMarkWidth = imagesx($finalWaterMarkImage);
                 $finalWaterMarkHeight = imagesy($finalWaterMarkImage);
                 imagecopy($im, $finalWaterMarkImage, $placementX, $placementY, 0, 0, $finalWaterMarkWidth, $finalWaterMarkHeight);
                 imagealphablending($im, FALSE);
                 imagesavealpha($im, TRUE);
             }
             imagepng($im);
             imagedestroy($im);
             exit;
         } elseif ($is_preview) {
             @ob_end_clean();
             echo 'Certificate preview is not available. Please make sure an image for the certificate is uploaded.';
             exit;
         }
     }
 }
コード例 #3
0
ファイル: emails.php プロジェクト: parkmi/dolschool14
function getCertificateFile($params)
{
    global $my, $JLMS_DB, $JLMS_CONFIG, $Itemid;
    $course_id = $params['course_id'];
    //$usertype = JLMS_GetUserType($my->id, $course_id);
    $JLMS_ACL =& JLMSFactory::getACL();
    $user_id_request = $params['user_id'];
    $user_id = $my->id;
    if ($user_id_request && $user_id_request != $user_id) {
        if ($JLMS_ACL->isCourseTeacher()) {
            $user_id = $user_id_request;
        } elseif ($JLMS_ACL->isStaff() && isset($JLMS_ACL->_staff_learners) && is_array($JLMS_ACL->_staff_learners) && in_array($user_id_request, $JLMS_ACL->_staff_learners)) {
            $user_id = $user_id_request;
        }
    }
    $query = "SELECT id, crt_date FROM #__lms_certificate_users WHERE course_id = '" . $course_id . "' AND user_id = '" . $user_id . "' AND crt_option = 1";
    $JLMS_DB->SetQuery($query);
    $row = $JLMS_DB->LoadObject();
    $tm_obj = new stdClass();
    if ($row->crt_date == '0000-00-00 00:00:00' || !$row->crt_date) {
        $row->crt_date = date('Y-m-d H:i:s');
        $query = "UPDATE #__lms_certificate_users SET crt_date = '" . date('Y-m-d H:i:s') . "' WHERE id = " . $row->id . " AND course_id = '" . $course_id . "' AND user_id = '" . $user_id . "' AND crt_option = 1";
        $JLMS_DB->SetQuery($query);
        $JLMS_DB->query();
        $tm_obj->force_update_print_date = true;
        //to fix bug with 'null' date of print.
    }
    $query = "SELECT id FROM #__lms_certificates WHERE course_id = '" . $course_id . "' AND crtf_type = 1 AND published = 1";
    $JLMS_DB->SetQuery($query);
    $crtf_id = $JLMS_DB->LoadResult();
    require_once _JOOMLMS_FRONT_HOME . "/includes/lms_certificates.php";
    $query = "SELECT * FROM #__users WHERE id = '" . $user_id . "'";
    $JLMS_DB->SetQuery($query);
    $u_data = $JLMS_DB->LoadObjectList();
    $tm_obj->username = isset($u_data[0]->username) ? $u_data[0]->username : '';
    $tm_obj->name = isset($u_data[0]->name) ? $u_data[0]->name : '';
    $tm_obj->crtf_date = strtotime($row->crt_date);
    //time();
    $tm_obj->crtf_spec_answer = '';
    $tm_obj->is_preview = false;
    $user = new stdClass();
    $user->id = isset($u_data[0]->id) ? $u_data[0]->id : 0;
    $user->username = isset($u_data[0]->username) ? $u_data[0]->username : '';
    $user->name = isset($u_data[0]->name) ? $u_data[0]->name : '';
    $user->email = isset($u_data[0]->email) ? $u_data[0]->email : '';
    $id = $crtf_id;
    $course_id = $course_id;
    $txt_mes_obj = isset($tm_obj) ? $tm_obj : null;
    $user_obj = isset($user) ? $user : null;
    if (is_null($user_obj)) {
        $user_obj = new stdClass();
        $user_obj->id = $my->id;
        $user_obj->username = $my->username;
        $user_obj->email = $my->email;
        $user_obj->name = $my->name;
    }
    //	$JLMS_ACL = & JLMSFactory::getACL();
    $is_preview = false;
    $is_exist = false;
    $quiz_id = 0;
    $quiz_name = '';
    $course_name = '';
    if (isset($txt_mes_obj->is_preview)) {
        $is_preview = $txt_mes_obj->is_preview;
    }
    if (isset($txt_mes_obj->quiz_id)) {
        $quiz_id = $txt_mes_obj->quiz_id;
    }
    if (isset($txt_mes_obj->quiz_name)) {
        $quiz_name = $txt_mes_obj->quiz_name;
    }
    if (isset($txt_mes_obj->course_name)) {
        $course_name = $txt_mes_obj->course_name;
    }
    $do_s = true;
    $crtf_role = 0;
    if ($is_preview) {
        $crtf_role = intval(mosGetParam($_REQUEST, 'crtf_role', 0));
    } else {
        $crtf_role = intval($JLMS_ACL->GetRole(1));
    }
    if ($crtf_role) {
        $query = "SELECT a.*, b.course_name FROM #__lms_certificates as a, #__lms_courses as b WHERE a.course_id = '" . $course_id . "' AND a.course_id = b.id AND a.parent_id = {$id} AND a.crtf_type = {$crtf_role}";
        $JLMS_DB->SetQuery($query);
        $crts = $JLMS_DB->loadObjectList();
        if (count($crts) == 1) {
            if ($crts[0]->file_id) {
                $do_s = false;
            } else {
                $query = "SELECT file_id FROM #__lms_certificates as a WHERE a.id = '" . $id . "' AND a.course_id = '" . $course_id . "' AND a.parent_id = 0";
                $JLMS_DB->SetQuery($query);
                $crts[0]->file_id = $JLMS_DB->LoadResult();
                if ($crts[0]->file_id) {
                    $do_s = false;
                }
            }
        }
    }
    if ($do_s) {
        $query = "SELECT a.*, b.course_name FROM #__lms_certificates as a, #__lms_courses as b WHERE a.id = '" . $id . "' AND a.course_id = '" . $course_id . "' AND a.course_id = b.id AND a.parent_id = 0";
        $JLMS_DB->SetQuery($query);
        $crts = $JLMS_DB->loadObjectList();
    }
    if (count($crts) == 1) {
        $is_duplicate = false;
        $print_duplicate_watermark = $JLMS_CONFIG->get('crtf_duplicate_wm', true);
        $crt = $crts[0];
        $JLMS_DB->SetQuery("SELECT file_srv_name FROM #__lms_files WHERE id = '" . $crt->file_id . "'");
        $cert_name = $JLMS_DB->LoadResult();
        if ($cert_name) {
            $ucode = md5(uniqid(rand(), true));
            $ex_crtf_id = 0;
            $is_saved_on_server = false;
            $ucode = substr($ucode, 0, 10);
            if (!$is_preview) {
                $query = "SELECT * FROM #__lms_certificate_prints WHERE user_id = {$user_obj->id} AND role_id = {$crtf_role} AND course_id = {$course_id} AND crtf_id = {$id} AND quiz_id = {$quiz_id}";
                $JLMS_DB->SetQuery($query);
                $cr_pr = $JLMS_DB->LoadObject();
                if (is_object($cr_pr) && isset($cr_pr->id)) {
                    $is_exist = $cr_pr->id;
                    $ex_crtf_id = $cr_pr->id;
                    $ucode = $cr_pr->uniq_id;
                    $txt_mes_obj->name = $cr_pr->name;
                    $txt_mes_obj->username = $cr_pr->username;
                    //$txt_mes_obj->course_name = $cr_pr->course_name;
                    if (isset($txt_mes_obj->force_update_print_date) && $txt_mes_obj->force_update_print_date && isset($txt_mes_obj->crtf_date) && $txt_mes_obj->crtf_date) {
                        $query = "UPDATE #__lms_certificate_prints SET crtf_date = '" . $txt_mes_obj->crtf_date . "' WHERE id = " . $cr_pr->id . " AND user_id = {$user_obj->id} AND role_id = {$crtf_role} AND course_id = {$course_id} AND crtf_id = {$id} AND quiz_id = {$quiz_id}";
                        $JLMS_DB->SetQuery($query);
                        $JLMS_DB->query();
                    } else {
                        $txt_mes_obj->crtf_date = strtotime($cr_pr->crtf_date);
                    }
                    $is_duplicate = true;
                    if ($JLMS_CONFIG->get('save_certificates', 1)) {
                        $im_crtf_path = $JLMS_CONFIG->get('jlms_crtf_folder', '');
                        $file_on_srv = $im_crtf_path . '/' . md5($ex_crtf_id . '_' . $ucode) . '.png';
                        if (file_exists($file_on_srv)) {
                            $is_saved_on_server = true;
                        }
                    }
                }
            }
            if ($is_saved_on_server) {
                $loadFile = $file_on_srv;
            } else {
                $loadFile = _JOOMLMS_DOC_FOLDER . $cert_name;
            }
            $im_fullsize = getimagesize($loadFile);
            if (isset($im_fullsize[2])) {
                if ($im_fullsize[2] == 1) {
                    $im = imagecreatefromgif($loadFile);
                } elseif ($im_fullsize[2] == 2) {
                    $im = imagecreatefromjpeg($loadFile);
                } elseif ($im_fullsize[2] == 3) {
                    $im = imagecreatefrompng($loadFile);
                    if (function_exists('imagesavealpha')) {
                        imagesavealpha($im, true);
                    }
                } else {
                    die;
                }
            } else {
                die('Bad image format.');
            }
            if (!$is_saved_on_server) {
                require_once _JOOMLMS_FRONT_HOME . DS . 'includes' . DS . 'libchart' . DS . 'barcode.php';
                $b_params = array();
                if ($JLMS_CONFIG->get('crtf_show_sn', 1)) {
                    $b_params[] = 'text';
                }
                if ($JLMS_CONFIG->get('crtf_show_barcode', 1)) {
                    $b_params[] = 'bar';
                }
            }
            $origWidth = $im_fullsize[0];
            $origHeight = $im_fullsize[1];
            if ($is_duplicate && $print_duplicate_watermark) {
                require_once _JOOMLMS_FRONT_HOME . DS . "includes" . DS . "libchart" . DS . "libchart.php";
                JLMS_cleanLibChartCache();
                $watermark = _JOOMLMS_FRONT_HOME . DS . "lms_images" . DS . "duplicate.png";
                $wmTarget = $JLMS_CONFIG->getCfg('absolute_path') . "/" . ($JLMS_CONFIG->get('temp_folder', '') ? $JLMS_CONFIG->get('temp_folder', '') . "/" : '') . time() . '_' . md5(uniqid(rand(), true)) . ".png";
                $waterMarkInfo = getimagesize($watermark);
                $waterMarkWidth = $waterMarkInfo[0];
                $waterMarkHeight = $waterMarkInfo[1];
                $placementX = 0;
                $placementY = 0;
                $waterMarkDestWidth = $waterMarkWidth;
                $waterMarkDestHeight = $waterMarkHeight;
                $waterMarkDestWidth = round($origWidth / $waterMarkDestWidth * $waterMarkDestWidth);
                $waterMarkDestHeight = round($origHeight / $waterMarkDestHeight * $waterMarkDestHeight);
                JLMS_Certificates::resize_png_image($watermark, $waterMarkDestWidth, $waterMarkDestHeight, $wmTarget, false);
                // get the size info for this watermark.
                $wmInfo = getimagesize($wmTarget);
                $waterMarkDestWidth = $wmInfo[0];
                $waterMarkDestHeight = $wmInfo[1];
                $differenceX = $origWidth - $waterMarkDestWidth;
                $differenceY = $origHeight - $waterMarkDestHeight;
                $placementX = round($differenceX / 2);
                $placementY = round($differenceY / 2);
            }
            if (!$is_saved_on_server) {
                if (!empty($b_params)) {
                    $barcode = new JLMS_barcode($ucode, $b_params);
                    $barcode->generate($im, $origWidth, $origHeight);
                }
                $white = imagecolorallocate($im, 255, 255, 255);
                $grey = imagecolorallocate($im, 128, 128, 128);
                $black = imagecolorallocate($im, 0, 0, 0);
                $text_messages = array();
                $crtf_msg = new stdClass();
                $crtf_msg->text_size = $crt->text_size;
                $crtf_msg->text_x = $crt->text_x;
                $crtf_msg->text_y = $crt->text_y;
                $crtf_msg->crtf_font = isset($crt->crtf_font) && $crt->crtf_font ? $crt->crtf_font : 'arial.ttf';
                $crtf_msg->crtf_text = $crt->crtf_text;
                $crtf_msg->course_name = $crt->course_name;
                $crtf_msg->crtf_shadow = $crt->crtf_shadow;
                $crtf_msg->crtf_align = $crt->crtf_align;
                $text_messages[] = $crtf_msg;
                $query = "SELECT * FROM #__lms_certificates WHERE course_id = {$course_id} AND parent_id = {$crt->id} AND crtf_type = '-2' ORDER BY crtf_align";
                $JLMS_DB->SetQuery($query);
                $add_cert_msgs = $JLMS_DB->LoadObjectList();
                foreach ($add_cert_msgs as $acms) {
                    $crtf_msg = new stdClass();
                    $crtf_msg->text_size = $acms->text_size;
                    $crtf_msg->text_x = $acms->text_x;
                    $crtf_msg->text_y = $acms->text_y;
                    $crtf_msg->crtf_font = isset($acms->crtf_font) && $acms->crtf_font ? $acms->crtf_font : 'arial.ttf';
                    $crtf_msg->crtf_text = $acms->crtf_text;
                    $crtf_msg->course_name = $crt->course_name;
                    $crtf_msg->crtf_shadow = $acms->crtf_shadow;
                    $crtf_msg->crtf_align = 0;
                    $text_messages[] = $crtf_msg;
                }
                foreach ($text_messages as $crt7) {
                    $font_size = $crt7->text_size;
                    $font_x = $crt7->text_x;
                    $font_y = $crt7->text_y;
                    $font_filename = $crt7->crtf_font;
                    $inform = array();
                    $font_text = $crt7->crtf_text;
                    $username = isset($txt_mes_obj->username) ? $txt_mes_obj->username : '';
                    $name = isset($txt_mes_obj->name) ? $txt_mes_obj->name : '';
                    $course_name = isset($txt_mes_obj->course_name) ? $txt_mes_obj->course_name : $crt7->course_name;
                    //$spec_answer = isset($txt_mes_obj->crtf_spec_answer)?$txt_mes_obj->crtf_spec_answer:'';
                    $crtf_date = isset($txt_mes_obj->crtf_date) ? $txt_mes_obj->crtf_date : time();
                    $font_text = str_replace('#username#', $username, $font_text);
                    $font_text = str_replace('#name#', $name, $font_text);
                    $font_text = str_replace('#course#', $course_name, $font_text);
                    $font_text = JLMS_Certificates::ReplaceCourseRegAnswers($font_text, $txt_mes_obj, $user_obj->id, $course_id);
                    //$font_text = str_replace('#reg_answer#', $spec_answer, $font_text);
                    $font_text = JLMS_Certificates::ReplaceQuizAnswers($font_text, $txt_mes_obj, $user_obj->id, $course_id);
                    $font_text = JLMS_Certificates::ReplaceEventOptions($font_text, $txt_mes_obj, $user_obj->id, $course_id);
                    $font_text = JLMS_Certificates::ReplaceCBProfileOptions($font_text, $txt_mes_obj, $user_obj->id, $course_id);
                    //$font_text = JLMS_Certificates::ReplaceUPN($font_text, $txt_mes_obj, $user_obj->id, $course_id);
                    // replace #date#
                    $str_format = 'Y-m-d';
                    $str_format_pre = '';
                    $first_pos = strpos($font_text, '#date');
                    if ($first_pos !== false) {
                        $first_str = substr($font_text, $first_pos + 5, strlen($font_text) - $first_pos - 5);
                        $sec_pos = strpos($first_str, '#');
                        $str_format = substr($first_str, 0, $sec_pos);
                        $str_format_pre = $str_format;
                        echo $str_format;
                        if ($str_format) {
                            if (substr($str_format, 0, 1) == '(') {
                                $str_format = substr($str_format, 1);
                            }
                            if (substr($str_format, -1) == ')') {
                                $str_format = substr($str_format, 0, -1);
                            }
                        }
                        echo $str_format;
                    }
                    if (!$str_format) {
                        $str_format = 'Y-m-d';
                    }
                    $font_text = str_replace('#date' . $str_format_pre . '#', date($str_format, $crtf_date), $font_text);
                    // end of #date#
                    $font = JPATH_SITE . "/media/arial.ttf";
                    if (file_exists(JPATH_SITE . "/media/" . $font_filename)) {
                        $font = JPATH_SITE . "/media/" . $font_filename;
                    }
                    $text_array = explode("\n", $font_text);
                    #print_r($text_array);die;
                    $count_lines = count($text_array);
                    $text_lines_xlefts = array();
                    $text_lines_xrights = array();
                    $text_lines_heights = array();
                    for ($i = 0; $i < $count_lines; $i++) {
                        $font_box = imagettfbbox($font_size, 0, $font, $text_array[$i]);
                        $text_lines_xlefts[$i] = $font_box[0];
                        $text_lines_xrights[$i] = $font_box[2];
                        $text_lines_heights[$i] = $font_box[1] - $font_box[7];
                        if ($text_lines_heights[$i] < $font_size) {
                            $text_lines_heights[$i] = $font_size;
                        }
                    }
                    $min_x = 0;
                    $max_x = 0;
                    $max_w = 0;
                    for ($i = 0; $i < $count_lines; $i++) {
                        if ($min_x > $text_lines_xlefts[$i]) {
                            $min_x = $text_lines_xlefts[$i];
                        }
                        if ($max_x < $text_lines_xrights[$i]) {
                            $max_x = $text_lines_xrights[$i];
                        }
                        if ($max_w < $text_lines_xrights[$i] - $text_lines_xlefts[$i]) {
                            $max_w = $text_lines_xrights[$i] - $text_lines_xlefts[$i];
                        }
                    }
                    #$crt->crtf_text
                    #$alignment = 'left';
                    $allow_shadow = $crt7->crtf_shadow == 1;
                    #$alignment = 'left';
                    switch (intval($crt7->crtf_align)) {
                        case 1:
                            for ($i = 0; $i < $count_lines; $i++) {
                                $cur_w = $text_lines_xrights[$i] - $text_lines_xlefts[$i];
                                $ad = intval(($max_w - $cur_w) / 2) - intval($max_w / 2);
                                if ($allow_shadow) {
                                    imagettftext($im, $font_size, 0, $font_x + $ad + 2, $font_y + 2, $grey, $font, $text_array[$i]);
                                }
                                imagettftext($im, $font_size, 0, $font_x + $ad, $font_y, $black, $font, $text_array[$i]);
                                $font_y = $font_y + $text_lines_heights[$i] + 3;
                            }
                            break;
                        case 2:
                            for ($i = 0; $i < $count_lines; $i++) {
                                $cur_w = $text_lines_xrights[$i] - $text_lines_xlefts[$i];
                                $ad = intval($max_w - $cur_w) - intval($max_w);
                                if ($allow_shadow) {
                                    imagettftext($im, $font_size, 0, $font_x + $ad + 2, $font_y + 2, $grey, $font, $text_array[$i]);
                                }
                                imagettftext($im, $font_size, 0, $font_x + $ad, $font_y, $black, $font, $text_array[$i]);
                                $font_y = $font_y + $text_lines_heights[$i] + 3;
                            }
                            break;
                        default:
                            for ($i = 0; $i < $count_lines; $i++) {
                                $cur_w = $text_lines_xrights[$i] - $text_lines_xlefts[$i];
                                $ad = 0;
                                //intval(($max_w - $cur_w)/2);
                                if ($allow_shadow) {
                                    imagettftext($im, $font_size, 0, $font_x + $ad + 2, $font_y + 2, $grey, $font, $text_array[$i]);
                                }
                                imagettftext($im, $font_size, 0, $font_x + $ad, $font_y, $black, $font, $text_array[$i]);
                                $font_y = $font_y + $text_lines_heights[$i] + 3;
                            }
                            break;
                    }
                }
                #$font_box = imagettfbbox($font_size, 0, $font, $font_text);
                #imagettftext($im, $font_size, 0, $font_x, $font_y, $grey, $font, $font_text, 'R');
                #imagettftext($im, $font_size, 0, $font_x, $font_y, $black, $font, $font_text, 'R');
                #@ob_end_clean();
            }
            if (!$is_preview) {
                if (!$is_exist) {
                    $query = "INSERT INTO #__lms_certificate_prints (uniq_id, user_id, role_id, crtf_date, crtf_id, crtf_text, last_printed, name, username, course_id, course_name, quiz_id, quiz_name ) VALUES" . "\n (" . $JLMS_DB->Quote($ucode) . ", {$user_obj->id}, {$crtf_role}," . $JLMS_DB->Quote(date('Y-m-d H:i:s', $crtf_date)) . ", {$id}, " . $JLMS_DB->Quote($crt->crtf_text) . "," . "\n " . $JLMS_DB->Quote(date('Y-m-d H:i:s')) . ", " . $JLMS_DB->Quote($user_obj->name) . ", " . $JLMS_DB->Quote($user_obj->username) . "," . "\n {$course_id}, " . $JLMS_DB->Quote($course_name) . ", {$quiz_id}, " . $JLMS_DB->Quote($quiz_name) . ")";
                    $JLMS_DB->SetQuery($query);
                    $JLMS_DB->query();
                    $ex_crtf_id = $JLMS_DB->insertid();
                } else {
                    $query = "UPDATE #__lms_certificate_prints SET last_printed = " . $JLMS_DB->Quote(date('Y-m-d H:i:s')) . "," . "\n crtf_text = " . $JLMS_DB->Quote($crt->crtf_text) . ", course_name = " . $JLMS_DB->Quote($course_name) . "," . "\n quiz_name = " . $JLMS_DB->Quote($quiz_name) . "\n WHERE id = {$is_exist}";
                    $JLMS_DB->SetQuery($query);
                    $JLMS_DB->query();
                    $ex_crtf_id = $is_exist;
                }
            }
            $file_server_name = '';
            if ($is_saved_on_server) {
                $file_server_name = $im_crtf_path . '/' . md5($ex_crtf_id . '_' . $ucode) . '.png';
            } else {
                header('Content-Type: image/png');
                if (!$is_saved_on_server && !$is_preview) {
                    if ($JLMS_CONFIG->get('save_certificates', 1)) {
                        $im_crtf_path = $JLMS_CONFIG->get('jlms_crtf_folder', '');
                        if ($im_crtf_path && is_writable($im_crtf_path)) {
                            $file_server_name = $im_crtf_path . '/' . md5($ex_crtf_id . '_' . $ucode) . '.png';
                            imagepng($im, $file_server_name);
                        }
                    }
                }
                imagedestroy($im);
            }
            return $file_server_name;
        }
    }
    return '';
}