<td>' . iconv('UTF-8', 'WINDOWS-1251', $row['field19']) . '</td> </tr> </table> <table border="0" class="startusq11"> <tr> <td>' . $datess[0] . '</td> <td>' . $datess[1] . '</td> <td>' . $datess[2] . '</td> <td>' . $datess[3] . '</td> <td>' . $datess[4] . '</td> <td>' . $datess[5] . '</td> <td>' . $datess[6] . '</td> <td>' . $datess[7] . '</td> </tr> </table> '; $stylesheet = file_get_contents('pdf2.css'); $mpdf->charset_in = 'cp1251'; $mpdf->WriteHTML($stylesheet, 1); $mpdf->SetXY(0, 22); $mpdf->WriteHTML($html); $mpdf->AddPage(); $tplIdx = $mpdf->ImportPage(2); $mpdf->UseTemplate($tplIdx); $mpdf->SetXY(0, 22); $mpdf->WriteHTML($html2); $mpdf->WriteHTML($stylesheet, 1); $mpdf->Output('newpdf.pdf', 'I'); exit;
function exportOrders($sql) { $db = JFactory::getDBO(); $export = JRequest::getVar("export", ""); $db->setQuery($sql); $db->query(); $result = $db->loadAssocList(); if ($export == "csv") { $users = $this->getUsers(); $courses = $this->getAllCourses(); $data = ""; $header = array("Date", "Price", "Username", "Student", "Status", "Course(s)", "Payment Method"); $data .= implode(",", $header); $data .= "\n"; if (isset($result) && count($result) > 0) { foreach ($result as $key => $value) { $data .= $value["order_date"] . ","; if ($value["amount_paid"] == "-1") { $data .= $value["amount"] . ","; } else { $data .= $value["amount_paid"] . ","; } $data .= $users[$value["userid"]]["username"] . ","; $data .= $users[$value["userid"]]["name"] . ","; $data .= $value["status"] . ","; if (isset($value["courses"]) && trim($value["courses"]) != "") { $list = explode("|", $value["courses"]); if (isset($list) && count($list) > 0) { $list_courses_name = array(); foreach ($list as $nr => $element) { $temp = explode("-", $element); if (isset($temp["0"]) && trim($temp["0"]) != "") { $list_courses_name[] = $courses[$temp["0"]]["name"]; } } $data .= implode("; ", $list_courses_name) . ","; } else { $data .= ","; } } else { $data .= ","; } $data .= $value["processor"] . "\n"; } } $csv_filename = "orders.csv"; $size_in_bytes = strlen($data); header("Content-Type: application/x-msdownload"); header("Content-Disposition: attachment; filename=" . $csv_filename); header("Pragma: no-cache"); header("Expires: 0"); echo utf8_decode($data); exit; } elseif ($export == "pdf") { $users = $this->getUsers(); $courses = $this->getAllCourses(); $file_content = "<style>\r\n\t\t\t\t\t\t\t\ttd{\r\n\t\t\t\t\t\t\t\t\tborder:1px solid #000000;\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\ttable{\r\n\t\t\t\t\t\t\t\t\tborder-collapse: collapse\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t </style>"; require JPATH_SITE . DS . "components" . DS . "com_guru" . DS . "helpers" . DS . "MPDF" . DS . "mpdf.php"; $pdf = new mPDF('utf-8', 'A4-L'); $file_content .= '<table>'; $file_content .= ' <tr>'; $file_content .= ' <td>Date</td>'; $file_content .= ' <td>Price</td>'; $file_content .= ' <td>Username</td>'; $file_content .= ' <td>Student</td>'; $file_content .= ' <td>Status</td>'; $file_content .= ' <td>Course(s)</td>'; $file_content .= ' <td>Payment Method</td>'; $file_content .= ' </tr>'; if (isset($result) && count($result) > 0) { foreach ($result as $key => $value) { $file_content .= '<tr>'; $file_content .= '<td>' . $value["order_date"] . '</td>'; if ($value["amount_paid"] == "-1") { $file_content .= '<td>' . $value["amount"] . '</td>'; } else { $file_content .= '<td>' . $value["amount_paid"] . '</td>'; } $file_content .= '<td>' . $users[$value["userid"]]["username"] . '</td>'; $file_content .= '<td>' . $users[$value["userid"]]["name"] . '</td>'; $file_content .= '<td>' . $value["status"] . '</td>'; if (isset($value["courses"]) && trim($value["courses"]) != "") { $list = explode("|", $value["courses"]); if (isset($list) && count($list) > 0) { $list_courses_name = array(); foreach ($list as $nr => $element) { $temp = explode("-", $element); if (isset($temp["0"]) && trim($temp["0"]) != "") { $list_courses_name[] = $courses[$temp["0"]]["name"]; } } $file_content .= '<td>' . implode("</br>", $list_courses_name) . '</td>'; } else { $file_content .= '<td></td>'; } } else { $file_content .= '<td></td>'; } $file_content .= '<td>' . $value["processor"] . '</td>'; $file_content .= '</tr>'; } } $file_content .= '</table>'; //set up a page $pdf->AddPage('L'); $pdf->SetXY(100, 50); $pdf->SetDisplayMode('fullpage'); $pdf->WriteHTML($file_content); $pdf->Output('orders.pdf', 'D'); exit; } }
if ($row) { if ($schema_type == $SCHEMA_TYPE_SRC) { //pixel→mm変換 $vertical_mm = round(($form['y'] - $page_top) / $convertUnit * $mm_per_inch); $horizontal_mm = round($form['x'] / $convertUnit * $mm_per_inch); if ($form['type'] == 'checkbox') { if ($row['value'] == 'on') { $mpdf->Image(\Sop\Resource::getImageFilePath('checkbox_on.png'), $horizontal_mm - 2, $vertical_mm - 2.4, 3, 3, 'png'); } else { $mpdf->Image(\Sop\Resource::getImageFilePath('checkbox_off.png'), $horizontal_mm - 2, $vertical_mm - 2.4, 3, 3, 'png'); } } else { $width_mm = round($form['width'] / $convertUnit * $mm_per_inch); $height_mm = \Sop\Constant::PDF_MULTICELL_RIGHT; //一行の高さ $mpdf->SetXY($horizontal_mm, $vertical_mm); $mpdf->MultiCell($width_mm, $height_mm, $row['value'], 0); } } } } if ($schema_type == $SCHEMA_TYPE_SRC) { $mark_position_x = 1150; //pixel→mm変換 $horizontal_mm = round($mark_position_x / $convertUnit * $mm_per_inch); foreach ($fileHwrList as $row) { $mark_position_y = $row['mark_position_y']; if ($page_top <= $mark_position_y && $mark_position_y < $page_bottom) { //pixel→mm変換 $vertical_mm = round(($mark_position_y - $page_top) / $convertUnit * $mm_per_inch); $width_mm = round(250 / $convertUnit * $mm_per_inch);
function savepdfcertificate() { $datac = JRequest::get('post', JREQUEST_ALLOWRAW); include JPATH_SITE . DS . 'components' . DS . 'com_guru' . DS . 'models' . DS . 'gurutask.php'; $background_color = ""; $op = JRequest::getVar("op", ""); if ($op == 9) { $db = JFactory::getDBO(); $user = JFactory::getUser(); $config = JFactory::getConfig(); $imagename = "SELECT * FROM #__guru_certificates WHERE id=1"; $db->setQuery($imagename); $db->query(); $imagename = $db->loadAssocList(); if ($imagename[0]["design_background"] != "") { $image_theme = explode("/", $imagename[0]["design_background"]); if (trim($image_theme[4]) == 'thumbs') { $image_theme = $image_theme[5]; } else { $image_theme = $image_theme[4]; } } else { $background_color = "background-color:" . "#" . $imagename[0]["design_background_color"]; } $site_url = JURI::root(); $coursename = JRequest::getVar('cn', '', 'get'); $authorname = JRequest::getVar('an', '', 'get'); $certificateid = JRequest::getVar('id', '', 'get'); $completiondate = JRequest::getVar('cd', '', 'get'); $course_id = JRequest::getVar('ci', '', 'get'); $sitename = $config->get('sitename'); $user_id = $user->id; $scores_avg_quizzes = @guruModelguruTask::getAvgScoresQ($user_id, $course_id); $avg_quizzes_cert = "SELECT avg_certc FROM #__guru_program WHERE id=" . intval($course_id); $db->setQuery($avg_quizzes_cert); $db->query(); $avg_quizzes_cert = $db->loadResult(); $sql = "SELECT id_final_exam FROM #__guru_program WHERE id=" . intval($course_id); $db->setQuery($sql); $result = $db->loadResult(); $sql = "SELECT hasquiz from #__guru_program WHERE id=" . intval($course_id); $db->setQuery($sql); $resulthasq = $db->loadResult(); $sql = "SELECT max_score FROM #__guru_quiz WHERE id=" . intval($result); $db->setQuery($sql); $result_maxs = $db->loadResult(); // final quiz -------------------------------------------------- $sql = "SELECT id, score_quiz FROM #__guru_quiz_question_taken_v3 WHERE user_id=" . intval($user_id) . " and quiz_id=" . intval($result) . " and pid=" . intval($course_id) . " ORDER BY id DESC LIMIT 0,1"; $db->setQuery($sql); $result_q = $db->loadObject(); $first = explode("|", @$result_q->score_quiz); @($res = intval($first[0] / $first[1] * 100)); if ($resulthasq == 0 && $scores_avg_quizzes == "") { $avg_certc = "N/A"; } elseif ($resulthasq != 0 && $scores_avg_quizzes == "") { $avg_certc = "N/A"; } elseif ($resulthasq != 0 && isset($scores_avg_quizzes)) { if ($scores_avg_quizzes >= intval($avg_quizzes_cert)) { $avg_certc = $scores_avg_quizzes . '%'; } else { $avg_certc = $scores_avg_quizzes . '%'; } } // final quiz -------------------------------------------------- // regular ---------------------------------------------- $s = 0; $sql = "select mr.`media_id` from #__guru_mediarel mr, #__guru_days d where mr.`type`='dtask' and mr.`type_id`=d.`id` and d.`pid`=" . intval($course_id); $db->setQuery($sql); $db->query(); $lessons = $db->loadColumn(); if (!isset($lessons) || count($lessons) == 0) { $lessons = array("0"); } $sql = "select mr.`media_id` from #__guru_mediarel mr where mr.`layout`='12' and mr.`type`='scr_m' and mr.`type_id` in (" . implode(", ", $lessons) . ")"; $db->setQuery($sql); $db->query(); $all_quizzes = $db->loadColumn(); if (isset($all_quizzes) && count($all_quizzes) > 0) { foreach ($all_quizzes as $key_quiz => $quiz_id) { $sql = "SELECT score_quiz FROM #__guru_quiz_question_taken_v3 WHERE user_id=" . intval($user_id) . " and quiz_id=" . intval($quiz_id) . " and pid=" . intval($course_id) . " ORDER BY id DESC LIMIT 0,1"; $db->setQuery($sql); $db->query(); $result_q = $db->loadColumn(); $res = @$result_q["0"]; $s += $res; } $avg_certc1 = "N/A"; if ($s > 0) { $avg_certc1 = $s / count($all_quizzes) . "%"; } } // regular ---------------------------------------------- /*$sql = "SELECT id, score_quiz, time_quiz_taken_per_user FROM #__guru_quiz_taken_v3 WHERE user_id=".intval($user_id)." and quiz_id=".intval($result)." and pid=".intval($course_id )." ORDER BY id DESC LIMIT 0,1"; $db->setQuery($sql); $result_q = $db->loadObject(); $first= explode("|", @$result_q->score_quiz); @$res = intval(($first[0]/$first[1])*100); if($resulthasq == 0 && $scores_avg_quizzes == ""){ $avg_certc1 = "N/A"; } elseif($resulthasq != 0 && $scores_avg_quizzes == ""){ $avg_certc1 = "N/A"; } elseif($resulthasq != 0 && isset($scores_avg_quizzes)){ if($scores_avg_quizzes >= intval($avg_quizzes_cert)){ $avg_certc1 = $scores_avg_quizzes.'%'; } else{ $avg_certc1 = $scores_avg_quizzes.'%'; } }*/ /*if($result !=0 && $res !="" ){ if( $res >= $result_maxs){ $avg_certc = $res.'%'; } elseif($res < $result_maxs){ $avg_certc = $res.'%'; } } elseif(($result !=0 && $result !="")){ $avg_certc = "N/A"; } elseif($result ==0 || $result ==""){ $avg_certc = "N/A"; }*/ $firstnamelastname = "SELECT firstname, lastname FROM #__guru_customer WHERE id=" . intval($user_id); $db->setQuery($firstnamelastname); $db->query(); $firstnamelastname = $db->loadAssocList(); $coursemsg = "SELECT certificate_course_msg FROM #__guru_program WHERE id=" . intval($course_id); $db->setQuery($coursemsg); $db->query(); $coursemsg = $db->loadResult(); $certificate_url = JUri::base() . "index.php?option=com_guru&view=guruOrders&task=printcertificate&opt=" . $certificateid . "&cn=" . $coursename . "&an=" . $authorname . "&cd=" . $completiondate . "&id=" . $certificateid; $certificate_url = str_replace(" ", "%20", $certificate_url); $imagename[0]["templates1"] = str_replace("[SITENAME]", $sitename, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[STUDENT_FIRST_NAME]", $firstnamelastname[0]["firstname"], $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[STUDENT_LAST_NAME]", $firstnamelastname[0]["lastname"], $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[SITEURL]", $site_url, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[CERTIFICATE_ID]", $certificateid, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COMPLETION_DATE]", $completiondate, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COURSE_NAME]", $coursename, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[AUTHOR_NAME]", $authorname, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[CERT_URL]", $certificate_url, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COURSE_MSG]", $coursemsg, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COURSE_AVG_SCORE]", $avg_certc1, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COURSE_FINAL_SCORE]", $avg_certc, $imagename[0]["templates1"]); while (ob_get_level()) { ob_end_clean(); } header("Content-Encoding: None", true); if (strlen($imagename[0]["design_text_color"]) == 3) { $r = hexdec(substr($imagename[0]["design_text_color"], 0, 1) . substr($imagename[0]["design_text_color"], 0, 1)); $g = hexdec(substr($imagename[0]["design_text_color"], 1, 1) . substr($imagename[0]["design_text_color"], 1, 1)); $b = hexdec(substr($imagename[0]["design_text_color"], 2, 1) . substr($imagename[0]["design_text_color"], 2, 1)); } else { $r = hexdec(substr($imagename[0]["design_text_color"], 0, 2)); $g = hexdec(substr($imagename[0]["design_text_color"], 2, 2)); $b = hexdec(substr($imagename[0]["design_text_color"], 4, 2)); } $background_color = explode(":", $background_color); @($background_color[1] = str_replace("#", "", $background_color[1])); if (strlen($background_color[1]) == 3) { $rg = hexdec(substr($background_color[1], 0, 1) . substr($background_color[1], 0, 1)); $gg = hexdec(substr($background_color[1], 1, 1) . substr($background_color, 1, 1)); $bg = hexdec(substr($background_color[1], 2, 1) . substr($background_color[1], 2, 1)); } else { $rg = hexdec(substr($background_color[1], 0, 2)); $gg = hexdec(substr($background_color[1], 2, 2)); $bg = hexdec(substr($background_color[1], 4, 2)); } if ($imagename[0]["library_pdf"] == 0) { require_once JPATH_SITE . DS . "components" . DS . "com_guru" . DS . "helpers" . DS . "fpdf.php"; $pdf = new PDF('L', 'mm', 'A5'); $pdf->SetFont($imagename[0]["font_certificate"], '', 12); $pdf->SetTextColor($r, $g, $b); //set up a page $pdf->AddPage(); if ($image_theme != "") { $pdf->Image(JUri::base() . "images/stories/guru/certificates/" . $image_theme, -4, -1, 210, 150); //$pdf->Cell(0,75,JText::_("GURU_CERTIFICATE_OF_COMPLETION"),0,1,'C'); } else { $pdf->SetFillColor($rg, $gg, $bg); //$pdf->Cell(0,115,JText::_("GURU_CERTIFICATE_OF_COMPLETION"),0,1,'C',true); } $pdf->Ln(20); $pdf->SetXY(100, 50); $pdf->WriteHTML(iconv('UTF-8', 'ISO-8859-1', $imagename[0]["templates1"]), true); $pdf->Output('certificate' . $certificateid . '.pdf', 'D'); } else { require JPATH_SITE . DS . "components" . DS . "com_guru" . DS . "helpers" . DS . "MPDF" . DS . "mpdf.php"; $pdf = new mPDF('utf-8', 'A4-L'); $pdf = new mPDF('utf-8', 'A4-L', 0, strtolower($imagename[0]["font_certificate"])); $imagename[0]["templates1"] = '<style> body { font-family:"' . strtolower($imagename[0]["font_certificate"]) . '" ; color: rgb(' . $r . ', ' . $g . ', ' . $b . '); }</style>' . $imagename[0]["templates1"]; //set up a page $pdf->AddPage('L'); if ($image_theme != "") { $pdf->Image(JPATH_BASE . "/images/stories/guru/certificates/" . $image_theme, 0, 0, 298, 210, 'jpg', '', true, false); //$pdf->Cell(0,75,JText::_("GURU_CERTIFICATE_OF_COMPLETION"),0,1,'C'); } else { $pdf->SetFillColor($rg, $gg, $bg); //$pdf->Cell(0,115,JText::_("GURU_CERTIFICATE_OF_COMPLETION"),0,1,'C',true); } //$pdf->Ln(20); $pdf->SetXY(100, 50); $pdf->SetDisplayMode('fullpage'); $pdf->WriteHTML($imagename[0]["templates1"]); $pdf->Output('certificate' . $certificateid . '.pdf', 'D'); exit; } } else { $db = JFactory::getDBO(); $user = JFactory::getUser(); $config = JFactory::getConfig(); $imagename = "SELECT * FROM #__guru_certificates WHERE id=1"; $db->setQuery($imagename); $db->query(); $imagename = $db->loadAssocList(); if ($imagename[0]["design_background"] != "") { $image_theme = explode("/", $imagename[0]["design_background"]); if (trim($image_theme[4]) == 'thumbs') { $image_theme = $image_theme[5]; } else { $image_theme = $image_theme[4]; } } else { $background_color = "background-color:" . "#" . $imagename[0]["design_background_color"]; } $site_url = JURI::root(); $coursename = $datac['cn']; $authorname = $datac['an']; $certificateid = $datac['id']; $completiondate = $datac['cd']; $course_id = $datac['ci']; $sitename = $config->get('config.sitename'); $user_id = $user->id; $scores_avg_quizzes = guruModelguruTask::getAvgScoresQ($user_id, $course_id); $avg_quizzes_cert = "SELECT avg_certc FROM #__guru_program WHERE id=" . intval($course_id); $db->setQuery($avg_quizzes_cert); $db->query(); $avg_quizzes_cert = $db->loadResult(); $sql = "SELECT id_final_exam FROM #__guru_program WHERE id=" . intval($course_id); $db->setQuery($sql); $result = $db->loadResult(); $sql = "SELECT hasquiz from #__guru_program WHERE id=" . intval($course_id); $db->setQuery($sql); $resulthasq = $db->loadResult(); $sql = "SELECT max_score FROM #__guru_quiz WHERE id=" . intval($result); $db->setQuery($sql); $result_maxs = $db->loadResult(); $sql = "SELECT id, score_quiz, time_quiz_taken_per_user FROM #__guru_quiz_taken_v3 WHERE user_id=" . intval($user_id) . " and quiz_id=" . intval($result) . " and pid=" . intval($course_id) . " ORDER BY id DESC LIMIT 0,1"; $db->setQuery($sql); $result_q = $db->loadObject(); $first = explode("|", @$result_q->score_quiz); @($res = intval($first[0] / $first[1] * 100)); if ($resulthasq == 0 && $scores_avg_quizzes == "") { $avg_certc1 = "N/A"; } elseif ($resulthasq != 0 && $scores_avg_quizzes == "") { $avg_certc1 = "N/A"; } elseif ($resulthasq != 0 && isset($scores_avg_quizzes)) { if ($scores_avg_quizzes >= intval($avg_quizzes_cert)) { $avg_certc1 = $scores_avg_quizzes . '%'; } else { $avg_certc1 = $scores_avg_quizzes . '%'; } } if ($result != 0 && $res != "") { if ($res >= $result_maxs) { $avg_certc = $res . '%'; } elseif ($res < $result_maxs) { $avg_certc = $res . '%'; } } elseif ($result != 0 && $result != "") { $avg_certc = "N/A"; } elseif ($result == 0 || $result == "") { $avg_certc = "N/A"; } $firstnamelastname = "SELECT firstname, lastname FROM #__guru_customer WHERE id=" . intval($user_id); $db->setQuery($firstnamelastname); $db->query(); $firstnamelastname = $db->loadAssocList(); $coursemsg = "SELECT certificate_course_msg FROM #__guru_program WHERE id=" . intval($course_id); $db->setQuery($coursemsg); $db->query(); $coursemsg = $db->loadResult(); $certificate_url = JUri::base() . "index.php?option=com_guru&view=guruOrders&task=printcertificate&opt=" . $certificateid . "&cn=" . $coursename . "&an=" . $authorname . "&cd=" . $completiondate . "&id=" . $certificateid; $certificate_url = str_replace(" ", "%20", $certificate_url); $imagename[0]["templates1"] = str_replace("[SITENAME]", $sitename, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[STUDENT_FIRST_NAME]", $firstnamelastname[0]["firstname"], $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[STUDENT_LAST_NAME]", $firstnamelastname[0]["lastname"], $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[SITEURL]", $site_url, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[CERTIFICATE_ID]", $certificateid, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COMPLETION_DATE]", $completiondate, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COURSE_NAME]", $coursename, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[AUTHOR_NAME]", $authorname, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[CERT_URL]", $certificate_url, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COURSE_MSG]", $coursemsg, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COURSE_AVG_SCORE]", $avg_certc1, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COURSE_FINAL_SCORE]", $avg_certc, $imagename[0]["templates1"]); while (ob_get_level()) { ob_end_clean(); } header("Content-Encoding: None", true); if (strlen($imagename[0]["design_text_color"]) == 3) { $r = hexdec(substr($imagename[0]["design_text_color"], 0, 1) . substr($imagename[0]["design_text_color"], 0, 1)); $g = hexdec(substr($imagename[0]["design_text_color"], 1, 1) . substr($imagename[0]["design_text_color"], 1, 1)); $b = hexdec(substr($imagename[0]["design_text_color"], 2, 1) . substr($imagename[0]["design_text_color"], 2, 1)); } else { $r = hexdec(substr($imagename[0]["design_text_color"], 0, 2)); $g = hexdec(substr($imagename[0]["design_text_color"], 2, 2)); $b = hexdec(substr($imagename[0]["design_text_color"], 4, 2)); } $background_color = explode(":", $background_color); $background_color[1] = str_replace("#", "", $background_color[1]); if (strlen($background_color[1]) == 3) { $rg = hexdec(substr($background_color[1], 0, 1) . substr($background_color[1], 0, 1)); $gg = hexdec(substr($background_color[1], 1, 1) . substr($background_color, 1, 1)); $bg = hexdec(substr($background_color[1], 2, 1) . substr($background_color[1], 2, 1)); } else { $rg = hexdec(substr($background_color[1], 0, 2)); $gg = hexdec(substr($background_color[1], 2, 2)); $bg = hexdec(substr($background_color[1], 4, 2)); } if ($imagename[0]["library_pdf"] == 0) { require JPATH_SITE . DS . "components" . DS . "com_guru" . DS . "helpers" . DS . "fpdf.php"; $pdf = new PDF('L', 'mm', 'A5'); $pdf->SetFont($imagename[0]["font_certificate"], '', 12); $pdf->SetTextColor($r, $g, $b); //set up a page $pdf->AddPage(); if ($image_theme != "") { $pdf->Image(JUri::base() . "images/stories/guru/certificates/" . $image_theme, -4, -1, 210, 150); //$pdf->Cell(0,75,JText::_("GURU_CERTIFICATE_OF_COMPLETION"),0,1,'C'); } else { $pdf->SetFillColor($rg, $gg, $bg); //$pdf->Cell(0,115,JText::_("GURU_CERTIFICATE_OF_COMPLETION"),0,1,'C',true); } $pdf->Ln(20); $pdf->SetXY(100, 50); $pdf->WriteHTML(iconv('UTF-8', 'ISO-8859-1', $imagename[0]["templates1"]), true); $pdf->Output('certificate' . $certificateid . '.pdf', 'D'); } else { require JPATH_SITE . DS . "components" . DS . "com_guru" . DS . "helpers" . DS . "MPDF" . DS . "mpdf.php"; $pdf = new mPDF('utf-8', 'A4-L'); $imagename[0]["templates1"] = '<style> body { font-family:"' . strtolower($imagename[0]["font_certificate"]) . '" ; color: rgb(' . $r . ', ' . $g . ', ' . $b . '); }</style>' . $imagename[0]["templates1"]; //set up a page $pdf->AddPage('L'); if ($image_theme != "") { $pdf->Image(JPATH_BASE . "/images/stories/guru/certificates/" . $image_theme, 0, 0, 298, 210, 'jpg', '', true, false); //$pdf->Cell(0,75,JText::_("GURU_CERTIFICATE_OF_COMPLETION"),0,1,'C'); } else { $pdf->SetFillColor($rg, $gg, $bg); //$pdf->Cell(0,115,JText::_("GURU_CERTIFICATE_OF_COMPLETION"),0,1,'C',true); } //$pdf->Ln(20); $pdf->SetXY(100, 50); $pdf->SetDisplayMode('fullpage'); $pdf->WriteHTML($imagename[0]["templates1"]); $pdf->Output('certificate' . $certificateid . '.pdf', 'D'); exit; } } }
function savecertificatepdf() { $datac = JRequest::get('post', JREQUEST_ALLOWRAW); $db = JFactory::getDBO(); $config = JFactory::getConfig(); $user = JFactory::getUser(); $user_id = $user->id; $sql = "SELECT `name` from #__guru_program WHERE `id` =" . $datac['ci']; $db->setQuery($sql); $db->query(); $result = $db->loadResult(); $imagename = "SELECT * FROM #__guru_certificates WHERE id=1"; $db->setQuery($imagename); $db->query(); $imagename = $db->loadAssocList(); $authorname = "SELECT name from #__users where id IN (SELECT author_id FROM #__guru_mycertificates WHERE user_id = " . intval($user_id) . " AND course_id =" . $datac['ci'] . " )"; $db->setQuery($authorname); $db->query(); $authorname = $db->loadResult(); $date_completed = "SELECT datecertificate FROM #__guru_mycertificates WHERE user_id=" . intval($user_id) . " AND course_id=" . intval($datac['ci']); $db->setQuery($date_completed); $db->query(); $date_completed = $db->loadResult(); $format = "SELECT datetype FROM #__guru_config WHERE id=1"; $db->setQuery($format); $db->query(); $format = $db->loadResult(); $date_completed = date($format, strtotime($date_completed)); $completiondate = $date_completed; $sitename = $config->get('sitename'); $coursename = $result; $site_url = JURI::root(); $certificateid = $datac['id']; $coursemsg = "SELECT certificate_course_msg FROM #__guru_program WHERE id=" . intval($datac['ci']); $db->setQuery($coursemsg); $db->query(); $coursemsg = $db->loadResult(); $scores_avg_quizzes = guruModelguruTask::getAvgScoresQ($user_id, $course_id); $avg_quizzes_cert = "SELECT avg_certc FROM #__guru_program WHERE id=" . intval($datac['ci']); $db->setQuery($avg_quizzes_cert); $db->query(); $avg_quizzes_cert = $db->loadResult(); $sql = "SELECT id_final_exam FROM #__guru_program WHERE id=" . intval($datac['ci']); $db->setQuery($sql); $result = $db->loadResult(); $sql = "SELECT hasquiz from #__guru_program WHERE id=" . intval($datac['ci']); $db->setQuery($sql); $resulthasq = $db->loadResult(); $sql = "SELECT max_score FROM #__guru_quiz WHERE id=" . intval($result); $db->setQuery($sql); $result_maxs = $db->loadResult(); $sql = "SELECT id, score_quiz, time_quiz_taken_per_user FROM #__guru_quiz_taken WHERE user_id=" . intval($user_id) . " and quiz_id=" . intval($result) . " and pid=" . intval($datac['ci']) . " ORDER BY id DESC LIMIT 0,1"; $db->setQuery($sql); $result_q = $db->loadObject(); $first = explode("|", @$result_q->score_quiz); @($res = intval($first[0] / $first[1] * 100)); if ($resulthasq == 0 && $scores_avg_quizzes == "") { $avg_certc1 = "N/A"; } elseif ($resulthasq != 0 && $scores_avg_quizzes == "") { $avg_certc1 = "N/A"; } elseif ($resulthasq != 0 && isset($scores_avg_quizzes)) { if ($scores_avg_quizzes >= intval($avg_quizzes_cert)) { $avg_certc1 = $scores_avg_quizzes . '%'; } else { $avg_certc1 = $scores_avg_quizzes . '%'; } } if ($result != 0 && $res != "") { if ($res >= $result_maxs) { $avg_certc = $res . '%'; } elseif ($res < $result_maxs) { $avg_certc = $res . '%'; } } elseif ($result != 0 && $result != "") { $avg_certc = "N/A"; } elseif ($result == 0 || $result == "") { $avg_certc = "N/A"; } $firstnamelastname = "SELECT firstname, lastname FROM #__guru_customer WHERE id=" . intval($user_id); $db->setQuery($firstnamelastname); $db->query(); $firstnamelastname = $db->loadAssocList(); $certificate_url = JUri::base() . "index.php?option=com_guru&view=guruOrders&task=printcertificate&opt=" . $certificateid . "&cn=" . $coursename . "&an=" . $authorname . "&cd=" . $completiondate . "&id=" . $certificateid . "&ci=" . $datac['ci']; $certificate_url = str_replace(" ", "%20", $certificate_url); $imagename[0]["templates1"] = str_replace("[SITENAME]", $sitename, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[STUDENT_FIRST_NAME]", $firstnamelastname[0]["firstname"], $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[STUDENT_LAST_NAME]", $firstnamelastname[0]["lastname"], $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[SITEURL]", $site_url, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[CERTIFICATE_ID]", $certificateid, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COMPLETION_DATE]", $completiondate, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COURSE_NAME]", $coursename, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[AUTHOR_NAME]", $authorname, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[CERT_URL]", $certificate_url, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COURSE_MSG]", $coursemsg, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COURSE_AVG_SCORE]", $avg_certc1, $imagename[0]["templates1"]); $imagename[0]["templates1"] = str_replace("[COURSE_FINAL_SCORE]", $avg_certc, $imagename[0]["templates1"]); $datac["content"] = $imagename[0]["templates1"]; while (ob_get_level()) { ob_end_clean(); } header("Content-Encoding: None", true); if (strlen($datac["color"]) == 3) { $r = hexdec(substr($datac["color"], 0, 1) . substr($datac["color"], 0, 1)); $g = hexdec(substr($datac["color"], 1, 1) . substr($datac["color"], 1, 1)); $b = hexdec(substr($datac["color"], 2, 1) . substr($datac["color"], 2, 1)); } else { $r = hexdec(substr($datac["color"], 0, 2)); $g = hexdec(substr($datac["color"], 2, 2)); $b = hexdec(substr($datac["color"], 4, 2)); } $datac["bgcolor"] = explode(":", $datac["bgcolor"]); $datac["bgcolor"][1] = str_replace("#", "", $datac["bgcolor"][1]); if (strlen($datac["bgcolor"][1]) == 3) { $rg = hexdec(substr($datac["bgcolor"][1], 0, 1) . substr($datac["bgcolor"][1], 0, 1)); $gg = hexdec(substr($datac["bgcolor"][1], 1, 1) . substr($datac["bgcolor"][1], 1, 1)); $bg = hexdec(substr($datac["bgcolor"][1], 2, 1) . substr($datac["bgcolor"][1], 2, 1)); } else { $rg = hexdec(substr($datac["bgcolor"][1], 0, 2)); $gg = hexdec(substr($datac["bgcolor"][1], 2, 2)); $bg = hexdec(substr($datac["bgcolor"][1], 4, 2)); } if ($imagename[0]["library_pdf"] == 0) { require JPATH_SITE . DS . "components" . DS . "com_guru" . DS . "helpers" . DS . "fpdf.php"; $pdf = new PDF('L', 'mm', 'A5'); $pdf->SetFont($datac["font"], '', 12); $pdf->SetTextColor($r, $g, $b); //set up a page $pdf->AddPage(); if ($datac["image"] != "") { $pdf->Image(JUri::base() . "images/stories/guru/certificates/" . $datac["image"], -4, -1, 210, 150); //$pdf->Cell(0,75,JText::_("GURU_CERTIFICATE_OF_COMPLETION"),0,1,'C'); } else { $pdf->SetFillColor($rg, $gg, $bg); //$pdf->Cell(0,115,JText::_("GURU_CERTIFICATE_OF_COMPLETION"),0,1,'C',true); } $pdf->Ln(20); $pdf->SetXY(100, 50); $pdf->WriteHTML(iconv('UTF-8', 'ISO-8859-1', $imagename[0]["templates1"]), true); $pdf->Output('certificate' . $certificateid . '.pdf', 'D'); } else { require JPATH_SITE . DS . "components" . DS . "com_guru" . DS . "helpers" . DS . "MPDF" . DS . "mpdf.php"; $pdf = new mPDF('utf-8', 'A4-L'); $imagename[0]["templates1"] = '<style> body { font-family:"' . strtolower($datac["font"]) . '" ; color: rgb(' . $r . ', ' . $g . ', ' . $b . '); }</style>' . $imagename[0]["templates1"]; //set up a page $pdf->AddPage('L'); if ($datac["image"] != "") { $pdf->Image(JPATH_BASE . "/images/stories/guru/certificates/" . $datac["image"], 0, 0, 298, 210, 'jpg', '', true, false); //$pdf->Cell(0,75,JText::_("GURU_CERTIFICATE_OF_COMPLETION"),0,1,'C'); } else { $pdf->SetFillColor($rg, $gg, $bg); //$pdf->Cell(0,115,JText::_("GURU_CERTIFICATE_OF_COMPLETION"),0,1,'C',true); } //$pdf->Ln(20); $pdf->SetXY(100, 50); $pdf->SetDisplayMode('fullpage'); $pdf->WriteHTML($imagename[0]["templates1"]); $pdf->Output('certificate' . $certificateid . '.pdf', 'D'); exit; } }