function rel_dofreePDF($text_to_pdf)
{
    global $JLMS_CONFIG;
    chdir(JPATH_SITE);
    if (file_exists(JPATH_SITE . DS . 'components' . DS . 'com_joomla_lms' . DS . 'includes' . DS . 'pdf' . DS . 'lms.pdf.php')) {
        include JPATH_SITE . DS . 'components' . DS . 'com_joomla_lms' . DS . 'includes' . DS . 'pdf' . DS . 'lms.pdf.php';
    } else {
        die('Unable to print PDF');
    }
    $text_to_pdf_header = rel_pdfCleaner($text_to_pdf->header);
    $text_to_pdf_table = rel_pdfCleaner2($text_to_pdf->table);
    $pdf = new JLMSPDF('P', 'mm', 'A4', true, 'UTF-8', false);
    //A4 Portrait
    $pdf->SetMargins(10, 10, 10, true);
    $pdf->SetDrawColor(0, 0, 0);
    $header = "<br /><br /><table width=\"100%\">\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td width=\"50%\" align=\"right\">" . $JLMS_CONFIG->get('sitename') . "</td>\n\t\t\t\t\t\t\t<td width=\"50%\" align=\"right\">{pagination}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>";
    $footer = "\n\t\t<hr />\n\t\t<table>\n\t\t    <tr>\n\t\t        <td align=\"left\">" . $JLMS_CONFIG->get('live_site') . "</td>\n\t";
    if ($JLMS_CONFIG->get('is_trial')) {
        $footer .= "<td align=\"center\">Powered by JoomlaLMS (www.joomlalms.com)</td>";
    }
    $footer .= "\n\t\t        <td align=\"right\">" . date('j F, Y, H:i', time() + $JLMS_CONFIG->get('offset') * 60 * 60) . "</td>\n\t\t    </tr>\t\t  \n\t\t</table>\n\t";
    $pdf->setHeaderFont(array('freesans', '', 6));
    $pdf->setHeaderHTML($header);
    $pdf->setFooterMargin(5);
    $pdf->setFooterFont(array('freesans', '', 6));
    $pdf->setFooterHTML($footer);
    $pdf->addPage();
    $pdf->setFont('freesans');
    //choose font
    $pdf->SetFontSize(8);
    $top = 20;
    $dYl = $top;
    //	$options['cols'] = array( 'Questions' => $col_quest_text_options);
    $pdf->setY($dYl);
    $pdf->writeHTML(nl2br($text_to_pdf_header));
    ob_clean();
    ob_start();
    echo '<table cellspacing="0" cellpadding="1" border="1">';
    if (isset($text_to_pdf_table[0])) {
        $keys = array_keys($text_to_pdf_table[0]);
        echo '<tr>';
        foreach ($keys as $key) {
            $key = preg_replace('/\\s\\s+/', ' ', $key);
            echo '<td width="' . $text_to_pdf->colsWidths[$key] . '%">' . $key . '</td>';
        }
        echo '</tr>';
    }
    for ($i = 0; $i < count($text_to_pdf_table); $i++) {
        $values = array_values($text_to_pdf_table[$i]);
        echo '<tr>';
        foreach ($values as $value) {
            echo '<td>' . nl2br($value) . '</td>';
        }
        echo '</tr>';
    }
    echo '</table><br />';
    $html = ob_get_contents();
    ob_end_flush();
    ob_clean();
    $pdf->setFont('freesans');
    //choose font
    $pdf->SetFontSize(8);
    $pdf->writeHTML($html, true, false, false, false, '');
    // 15.12.2007 fix for showing PDF in IE. (DEN)
    /* 
     *  JoomlaLMS uses sessions, but session_start operation sent header 'pragma:no-cache' and 'cache-control:...' - here we will redefine them.
     */
    /*
    if (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $_SERVER['HTTP_USER_AGENT'])) {
    	header('Pragma: anytextexeptno-cache', true);
    	//header('Pragma: cache=1', true);
    	header('Cache-Control: cache=on', true);
    }
    */
    //footer
    $pdf->Output('QuizResults.pdf', 'I');
}
Ejemplo n.º 2
0
    function JLMS_salesReportPDF($rows)
    {
        global $JLMS_CONFIG;
        include JPATH_SITE . DS . 'components' . DS . 'com_joomla_lms' . DS . 'includes' . DS . 'pdf' . DS . 'lms.pdf.php';
        $pdf = new JLMSPDF('P', 'mm', 'A4', true, 'UTF-8', false);
        //A4 Portrait
        $pdf->SetXY(0, 0);
        $pdf->SetMargins(10, 20, 10, true);
        $pdf->setFont('freesans');
        //choose font
        $pdf->setFontSize(8);
        //choose font
        $pdf->SetDrawColor(0, 0, 0);
        $header = "<br /><div align=\"center\">" . $JLMS_CONFIG->get('sitename') . ' - ' . strtolower(_JLMS_PAYS_SALES_REPORT) . "</div>";
        $footer = "\n\t\t\t<hr />\n\t\t\t<table width=\"100%\">\n\t\t\t    <tr>\n\t\t\t        <td align=\"left\">" . $JLMS_CONFIG->get('live_site') . "</td>\n\t\t";
        if ($JLMS_CONFIG->get('is_trial')) {
            $footer .= "<td align=\"center\">Powered by JoomlaLMS (www.joomlalms.com)</td>";
        }
        $footer .= "\n\t\t\t        <td align=\"right\">" . date('j F, Y, H:i', time() + $JLMS_CONFIG->get('offset') * 60 * 60) . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $pdf->getAliasNumPage() . ' / ' . $pdf->getAliasNbPages() . "</td>\n\t\t\t    </tr>\t\t  \n\t\t\t</table>\n\t\t";
        $pdf->setHeaderFont(array('freesans', '', 6));
        $pdf->setHeaderHTML($header);
        $pdf->setFooterMargin(5);
        $pdf->setFooterFont(array('freesans', '', 6));
        $pdf->setFooterHTML($footer);
        $pdf->AddPage();
        ob_clean();
        ob_start();
        ?>
		
		
			<table width="100%">		
				<tr>
					<th width="5%" align="center"><strong>#</strong></th>									
					<th width="80%"><strong><?php 
        echo _JLMS_PAYS_SUBS_NAME;
        ?>
</strong></th>
					<th width="15%"><strong><?php 
        echo _JLMS_PAYS_NUMB_OF_ORDERS;
        ?>
</strong></th>						
				</tr>	
				<tr><td colspan="3"><hr /></td></tr>	
			<?php 
        $k = 0;
        for ($i = 0, $n = count($rows); $i < $n; $i++) {
            $row = $rows[$i];
            ?>
				<tr>
					<td width="5%" align="center"><?php 
            echo $i + 1;
            ?>
</td>									
					<td width="80%" align="left">
						<?php 
            echo $row->name;
            ?>
					</td>	
					<td width="15%" align="center">
						<?php 
            echo $row->count;
            ?>
					</td>									
				</tr>
				<?php 
        }
        ?>
			
			</table>					
		<?php 
        $content = ob_get_contents();
        ob_end_clean();
        $pdf->writeHTML($content);
        $pdf->Output('sales_report', 'I');
        die;
    }
    function gbUserPDF($id, $option, &$rows, &$lists)
    {
        global $Itemid, $JLMS_CONFIG, $JLMS_DB;
        $juser = JLMSFactory::getUser();
        $JLMS_ACL =& JLMSFactory::getACL();
        chdir(JPATH_SITE);
        if (file_exists(JPATH_SITE . DS . 'components' . DS . 'com_joomla_lms' . DS . 'includes' . DS . 'pdf' . DS . 'lms.pdf.php')) {
            include JPATH_SITE . DS . 'components' . DS . 'com_joomla_lms' . DS . 'includes' . DS . 'pdf' . DS . 'lms.pdf.php';
        } else {
            die('Unable to print PDF');
        }
        $pdf = new JLMSPDF('P', 'mm', 'A4', true, 'UTF-8', false);
        //A4 Portrait
        $pdf->SetMargins(10, 10, 10, true);
        $pdf->SetDrawColor(0, 0, 0);
        $header = "<br /><div align=\"center\">" . $JLMS_CONFIG->get('course_name') . "</div>";
        $footer = "\n\t\t\t<hr />\n\t\t\t<table>\n\t\t\t    <tr>\n\t\t\t        <td align=\"left\">" . $JLMS_CONFIG->get('sitename') . ' - ' . $JLMS_CONFIG->get('live_site') . "</td>\n\t\t";
        if ($JLMS_CONFIG->get('is_trial')) {
            $footer .= "<td align=\"center\">Powered by JoomlaLMS (www.joomlalms.com)</td>";
        }
        $footer .= "\n\t\t\t        <td align=\"right\">" . date('j F, Y, H:i', time() + $JLMS_CONFIG->get('offset') * 60 * 60) . "</td>\n\t\t\t    </tr>\t\t  \n\t\t\t</table>\n\t\t";
        $pdf->setHeaderFont(array('freesans', '', 6));
        $pdf->setHeaderHTML($header);
        $pdf->setFooterMargin(5);
        $pdf->setFooterFont(array('freesans', '', 6));
        $pdf->setFooterHTML($footer);
        $pdf->addPage();
        $pdf->setFont('freesans');
        //choose font
        $pdf->SetFontSize(8);
        ob_clean();
        ob_start();
        ?>
		<table width="100%">
			<tr>
				<td align="right">				
				<font size="10"><?php 
        if ($rows[0]->user_certificate) {
            echo $JLMS_ACL->CheckPermissions('gradebook', 'manage') ? _JLMS_COURSE_COMPLETED_ADMIN : ($juser->get('id') == $rows[0]->user_id ? _JLMS_COURSE_COMPLETED_USER : _JLMS_COURSE_COMPLETED_ADMIN);
            echo str_repeat('&nbsp;', 15);
        }
        ?>
</font>				
				</td>
			</tr>
		</table>
		<br />
		<?php 
        $params_cs = array();
        if ($JLMS_ACL->CheckPermissions('gradebook', 'manage') && !empty($lists['enrollment_answers'])) {
            ?>
			
			<table width="100%">
			<tr>			
				<td width="50%" valign="top">
					<div><strong><font size="10"><?php 
            echo _JLMS_GB_USER_INFORMATION;
            ?>
</font></strong></div>
					<table width="100%" cellpadding="0" cellspacing="0" border="0" >				
					<tr>
						<td width="20%" align="left"><strong><?php 
            echo _JLMS_UI_USERNAME;
            ?>
</strong></td>
						<td align="left"><?php 
            echo $rows[0]->username;
            ?>
</td>
					</tr>
					<tr>
						<td align="left"><strong><?php 
            echo _JLMS_UI_NAME;
            ?>
</strong></td>
						<td align="left"><?php 
            echo $rows[0]->name;
            ?>
</td>
					</tr>
					<tr>
						<td align="left"><strong><?php 
            echo _JLMS_UI_EMAIL;
            ?>
</strong></td>
						<td align="left"><?php 
            echo $rows[0]->email;
            ?>
</td>
					</tr>
					<tr>
						<td align="left"><strong><?php 
            echo _JLMS_UI_GROUP;
            ?>
</strong></td>
						<td align="left"><?php 
            echo $rows[0]->ug_name ? $rows[0]->ug_name : '&nbsp;';
            ?>
</td>
					</tr>
					</table>					
				</td>							
				<td width="50%" valign="top">					
					<div><strong><font size="10"><?php 
            echo _JLMS_GB_REG_INFORMATION;
            ?>
</font></strong></div>
					<table width="100%" cellpadding="0" cellspacing="0" border="0">						<?php 
            foreach ($lists['enrollment_answers'] as $ea) {
                echo '<tr><td width: "30%"><strong>' . $ea->course_question . '</strong></td><td>' . ($ea->user_answer ? $ea->user_answer : '&nbsp;') . '</td></tr>';
            }
            ?>
					</table>
				</td>
			</tr>
			</table>
			<?php 
        } else {
            ?>
			<table width="100%" cellpadding="0" cellspacing = "0">
				<tr><td width="20%" align="left"><strong><?php 
            echo _JLMS_UI_USERNAME;
            ?>
</strong></td><td align="left"><?php 
            echo $rows[0]->username;
            ?>
</td></tr>
				<tr><td align="left"><strong><?php 
            echo _JLMS_UI_NAME;
            ?>
</strong></td><td align="left"><?php 
            echo $rows[0]->name;
            ?>
</td></tr>
				<tr><td align="left"><strong><?php 
            echo _JLMS_UI_EMAIL;
            ?>
</strong></td><td align="left"><?php 
            echo $rows[0]->email;
            ?>
</td></tr>
				<tr><td align="left"><strong><?php 
            echo _JLMS_UI_GROUP;
            ?>
</strong></td><td align="left"><?php 
            echo $rows[0]->ug_name ? $rows[0]->ug_name : '&nbsp;';
            ?>
</td></tr>
			</table>
			<?php 
        }
        $html = ob_get_contents();
        ob_end_flush();
        ob_clean();
        $pdf->writeHTML($html, true, false, false, false, '');
        $pdf->setY($pdf->GetY() + 20);
        /**
         * Certificates MOD - 04.10.2007 (DEN)
         * We will show the list of all achieved certificates in the User Gradebook
         */
        $query = "SELECT count(*) FROM #__lms_certificates WHERE course_id = '" . $id . "' AND published = 1 AND crtf_type = 1 AND parent_id = 0";
        $JLMS_DB->SetQuery($query);
        $is_course_certificate = $JLMS_DB->loadResult();
        if (!empty($lists['user_quiz_certificates']) || isset($rows[0]->user_certificate) && $rows[0]->user_certificate && $is_course_certificate) {
            $pdf->setFontSize(10);
            $pdf->setFont('freesansb');
            //choose font
            $pdf->Cell(0, 10, _JLMS_GB_CERTIFICATES, '', 1, 'L');
            $pdf->setFont('freesans');
            //choose font
            $pdf->setFontSize(8);
            ob_clean();
            ob_start();
            $old_format = $JLMS_CONFIG->get('date_format', 'Y-m-d');
            $new_format = $JLMS_CONFIG->get('gradebook_certificate_date', '');
            if ($new_format) {
                $JLMS_CONFIG->set('date_format', $new_format);
            }
            echo '<table width="100%" cellpadding="0" cellspacing="0" border="1">';
            foreach ($lists['user_quiz_certificates'] as $crtf_row) {
                ?>
				
				<tr>					
					<td width="50%" align="left">&nbsp;<strong><?php 
                echo $crtf_row->quiz_name;
                ?>
</strong></td>
					<td align="center"><?php 
                echo JLMS_dateToDisplay($crtf_row->crtf_date);
                ?>
</td>
				</tr>
				<?php 
            }
            if (isset($rows[0]->user_certificate) && $rows[0]->user_certificate && $is_course_certificate) {
                $cert_user_id = 0;
                if (isset($lists['user_id']) && $lists['user_id']) {
                    global $my;
                    if ($my->id == $lists['user_id']) {
                    } else {
                        $cert_user_id = $lists['user_id'];
                    }
                }
                ?>
				
				<tr>
					<td width="50%" align="left">&nbsp;<strong><?php 
                echo _JLMS_GB_COURSE_CERTIFICATE;
                ?>
</strong></td>
					<td align="center"><?php 
                echo JLMS_dateToDisplay($rows[0]->user_certificate_date);
                ?>
</td>
				</tr>
				<?php 
            }
            $JLMS_CONFIG->set('date_format', $old_format);
            echo '</table>';
            $html = ob_get_contents();
            ob_end_flush();
            ob_clean();
            $pdf->writeHTML($html, true, false, false, false, '');
        }
        /* END of Certificates MOD */
        if (count($lists['sc_rows'])) {
            $is_shown = 0;
            foreach ($lists['sc_rows'] as $sc_row) {
                if ($sc_row->show_in_gradebook) {
                    $is_shown++;
                    if ($is_shown == 1) {
                        $pdf->setFontSize(10);
                        $pdf->setFont('freesansb');
                        //choose font
                        $pdf->cell(0, 10, _JLMS_GB_SCORM_RESULTS, '', 1, 'L');
                        $pdf->setFont('freesans');
                        //choose font
                        $pdf->setFontSize(8);
                        ob_clean();
                        ob_start();
                        echo '<table width="100%" cellpadding="0" cellspacing="0" border="1">';
                    }
                    $j = 0;
                    while ($j < count($rows[0]->scorm_info)) {
                        if ($rows[0]->scorm_info[$j]->gbi_id == $sc_row->item_id) {
                            if ($rows[0]->scorm_info[$j]->user_status == -1) {
                                ?>
								<tr>
									<td width="50%" align="left">&nbsp;<strong><?php 
                                echo $sc_row->lpath_name;
                                ?>
</strong></td>
									<td width="20%" align="center"> - </td>
									<td width="30%" align="center"> </td>
								</tr>
								<?php 
                            } else {
                                $status = $rows[0]->scorm_info[$j]->user_status ? _JLMS_GB_SCORM_COMPLETED : _JLMS_GB_SCORM_INCOMPLETED;
                                ?>
								
								<tr>
									<td width="50%" align="left">&nbsp;<strong><?php 
                                echo $sc_row->lpath_name;
                                ?>
</strong></td>
									<td width="20%" align="center"><strong><?php 
                                echo $status;
                                ?>
</strong></td>	
									<td width="30%" align="center"><b><?php 
                                echo $rows[0]->scorm_info[$j]->user_grade . "</b> (" . $rows[0]->scorm_info[$j]->user_pts . _JLMS_GB_POINTS . ")";
                                ?>
</td>
								</tr>
								<?php 
                            }
                        }
                        $j++;
                    }
                }
            }
            if ($is_shown) {
                echo '</table>';
                $html = ob_get_contents();
                ob_end_flush();
                ob_clean();
                $pdf->writeHTML($html, true, false, false, false, '');
            }
        }
        if (count($lists['quiz_rows'])) {
            $pdf->setFontSize(10);
            $pdf->setFont('freesansb');
            //choose font
            $pdf->cell(0, 10, _JLMS_GB_QUIZ_RESULTS, '', 1, 'L');
            $pdf->setFont('freesans');
            //choose font
            $pdf->setFontSize(8);
            ob_clean();
            ob_start();
            /*Integration Plugin Percentiles*/
            echo '<table width="100%" cellpadding="0" cellspacing="0" border="1">';
            foreach ($lists['quiz_rows'] as $quiz_row) {
                $j = 0;
                while ($j < count($rows[0]->quiz_info)) {
                    if ($rows[0]->quiz_info[$j]->gbi_id == $quiz_row->c_id) {
                        if ($rows[0]->quiz_info[$j]->user_status == -1) {
                            ?>
							<tr>
								<td width="50%" align="left">&nbsp;<strong><?php 
                            echo $quiz_row->c_title;
                            ?>
</strong></td>
								<td width="20%" align="center"> - </td>
								<td width="30%" align="center"> </td>
							</tr>
							<?php 
                        } else {
                            $status = $rows[0]->quiz_info[$j]->user_status ? _JLMS_GB_SCORM_COMPLETED : _JLMS_RESULT_FAIL;
                            ?>
							
							<tr>
								<td width="50%" align="left">&nbsp;<strong><?php 
                            echo $quiz_row->c_title;
                            ?>
</strong></td>
								<td width="20%" align="center"><strong><?php 
                            echo $status;
                            ?>
</strong></td>
								<td width="30%" align="center">					
								<?php 
                            if ($rows[0]->quiz_info[$j]->user_grade != '-') {
                                echo "<b>" . $rows[0]->quiz_info[$j]->user_grade . "</b> (" . $rows[0]->quiz_info[$j]->user_pts_full . ")";
                            } else {
                                echo $rows[0]->quiz_info[$j]->user_pts_full;
                            }
                            if (isset($rows[0]->quiz_info[$j]->user_percentile)) {
                                echo ' - ' . $rows[0]->quiz_info[$j]->user_percentile;
                            }
                            ?>
								</td>
							</tr>
						<?php 
                        }
                    }
                    $j++;
                }
            }
            echo '</table>';
            $html = ob_get_contents();
            ob_end_flush();
            ob_clean();
            $pdf->writeHTML($html, true, false, false, false, '');
        }
        if (count($lists['gb_rows'])) {
            $pdf->setFontSize(10);
            $pdf->setFont('freesansb');
            //choose font
            $pdf->cell(0, 10, _JLMS_GB_GBI_RESULTS, '', 1, 'L');
            $pdf->setFont('freesans');
            //choose font
            $pdf->setFontSize(8);
            ob_clean();
            ob_start();
            echo '<table width="100%" cellpadding="0" cellspacing="0" border="1">';
            foreach ($lists['gb_rows'] as $gb_row) {
                $j = 0;
                while ($j < count($rows[0]->grade_info)) {
                    if ($rows[0]->grade_info[$j]->gbi_id == $gb_row->id) {
                        ?>
						<tr>
							<td width="50%" align="left">&nbsp;<strong><?php 
                        echo $gb_row->gbi_name;
                        ?>
</strong></td>
							<td width="50%" align="center">
								<?php 
                        echo $rows[0]->grade_info[$j]->user_grade != '-' ? $rows[0]->grade_info[$j]->user_grade : '';
                        ?>
						
							</td>
						</tr>
						<?php 
                    }
                    $j++;
                }
            }
            echo '</table>';
            $html = ob_get_contents();
            ob_end_flush();
            ob_clean();
            $pdf->writeHTML($html, true, false, false, false, '');
        }
        $pdf->Output('gradebook_' . $rows[0]->username . '_course' . $id . '.pdf', 'I');
        die;
    }