2015-04-27 57 views
-3

我正在爲教師創建一個組件,教師可以爲所有已完成課程的學生生成pdf。 檢查所有學生和pdf應該生成並保存在磁盤上。之後提供下載鏈接以下載所生成的所有pdf的zip文件。這是我想要實現的。我正在使用fpdf生成pdf。 有什麼建議嗎?如何點擊按鈕生成多個pdf文件

以下是貼在表格和學生ID-

<form 
     action="<?php echo JRoute::_('index.php?option=com_mentor&view=download_certificate&cid=' . $cid . '&Itemid=529') ?>" 
     name="download_certificate" method="post" id="download_certificate"> 
     <table class="adminlist" border="1" cellpadding="0" cellspacing="0" 
       style="table-layout: fixed" id="content"> 
      <thead> 
      <tr> 
       <th class="nowrap" style="width: 35px"> 
        <input type="checkbox" name="selectall" id="selectall"> 
       </th> 
       <th class="nowrap" align="center"> 
        <?php echo JText::_('COM_MENTOR_USER_NAME'); ?> 
       </th> 
       <th class="nowrap" style="width: 140px"> 
        <?php echo JText::_('COM_MENTOR_COURSE_STATUS'); ?> 
       </th> 
       <th class="nowrap" style="width: 140px"> 
        <?php echo JText::_('COM_MENTOR_ENROLLMENT_DATE'); ?> 
       </th> 
       <th class="nowrap" style="width: 140px"> 
        <?php echo JText::_('COM_MENTOR_ACTIVITY'); ?> 
       </th> 
       <th class="nowrap" style="width: 50px"> 
        <?php echo JText::_('COM_MENTOR_SCORE'); ?> 
       </th> 
       <th class="nowrap" style="width: 50px"> 
        <?php echo JText::_('COM_MENTOR_RESULT'); ?> 
       </th> 
      </tr> 
      </thead> 
      <tbody> 
      <?php 
      //echo '<pre>';print_r($this->mentor_details); die; 
      foreach ($this->mentor_details as $students) { 
       $cid = $this->mentor_details['cid']; 
       $i = 1; 
       foreach ($students['students'] as $student) { 
        $userid = $student['id']; 
//    echo '<pre>'; 
//    print_r($student); 
//    die; 
        ?> 
        <tr class="status" id="<?php echo $userid ?>"> 
         <td align="center"> 
          <input type="checkbox" id="<?php echo $userid ?>" name="check[]" class="checkbox1" 
            value="<?php echo $userid ?>"> 
         </td> 
         <td> 
          <a href="<?php echo JRoute::_('index.php?option=com_mentor&view=grader&cid=' . $cid . '&uid=' 
           . $userid . $itemid) ?>"> 
           <?php echo $student['username']; ?> 
          </a> 
         </td> 
         <!--     <td> 
         <?php// echo $student['email']; ?> 
        </td> --> 
         <td align="center"> 
          <?php 
          $incomplete = $completed = $not_started = 0; 
          for ($k = 0; $k < count($student['elements']); $k++) { 
           foreach ($student['elements'] as $elements) { 
            if ($elements['userid'] == $userid) { 
//         echo '<pre>';print_r($elements); die; 
             if ($elements['element']['cmi.core.lesson_status'] == 'incomplete') { 
              $incomplete++; 
             } else { 
              $completed++; 
             } 
            } 
           } 
          } 
          if ($incomplete == 0 && $completed == 0) { 
           echo 'Not yet started'; 
          } else { 
           if ($completed == count($student['elements'])) { 
            echo 'Completed'; 
           } else { 
            echo 'Incomplete'; 
           } 
          } 
          ?> 
         </td> 
         <td align="center"> 
          <?php 
          if (!empty($student['timestart'])) { 
           $date = date('d-m-Y H:i', $student['timestart']); 
           echo $date; 
          } else { 
           echo "Not yet started"; 
          } ?> 
         </td> 
         <td align="center"> 
          <?php 
          if (!empty($student['activity']['lasttime']) && (!empty($student['activity']['starttime']))) { 
           $start_date = date('d-m-Y H:i', $student['activity']['starttime']); 
           $last_date = date('d-m-Y H:i', $student['activity']['lasttime']); 
           echo $start_date . '<br/>' . $last_date; 
          } else { 
           echo "-"; 
          } ?> 
         </td> 
         <td align="center"> 
          <?php 
          $grades = $student['grades']; 
          $total_grade = array(); 
          $j = 0; 
          //for ($j = 0; $j < count($grades); $j++) { 
          // $total_grade[$j] = $grades[$j]['finalgrade']; 
          //} 
          //print_r($total_grade);die; 
          if (!empty($grades)) { 
           //echo number_format(array_sum($total_grade), 2); 
           $total_grade[$j] = $grades[$j]['finalgrade']; 
           echo number_format($total_grade[$j], 2); 
          } else { 
           echo '-'; 
          } 
          //echo '<pre>'; 
          //print_r($student['grades']); 
          //die; 
          ?> 
         </td> 
         <td align="center"> 
          <?php 
          //echo '<pre>';print_r($student);die; 
          if (!empty($student['scores'])) { 
           if (isset($grades[$j]['feedbacktext'])) { 
            echo $grades[$j]['feedbacktext']; 
           } else { 
            echo '-'; 
           } 
          } else { 
           echo '-'; 
          } 
          ?> 
         </td> 
        </tr> 
        <?php $i++; 
       } 
      } ?> 
      </tbody> 
     </table> 
    </form> 
<script> 
function checked_value() { 
     var checkedValue = []; 
     var $len = $(".checkbox1:checked").length; 

     if ($len == 0) { 
      alert('Please select user'); 
     } 
//  else if ($len > 1) { 
//   alert('Please select a single user only.'); 
//  } 
     else { 
      $(".checkbox1").each(function() { 
       var $this = $(this); 
       if ($this.is(":checked")) { 
        checkedValue.push($this.attr("id")); 
       } 
      }); 

      $("#download_certificate").submit(); 
    </script> 

在點擊圖片標籤,形式與學生ID提交,我讓學生數據,他的名字,成績,當然,

<img src="/components/com_mentor/images/certificate_blue.png" class="certificate-ico right" 
      title="Download Certificate" onclick="checked_value();"/> 

此處理後,頁面會被重定向到pdf.php頁

require_once('/wamp/opt/bitnami/apache2/htdocs/lms/lib/fpdf/fpdf.php'); 
$pdf = new FPDF(); $pdf->SetFont('times', '', 12); 
$pdf->SetTextColor(50, 60, 100); $pdf->AddPage('L'); 
$pdf->SetDisplayMode(real, 'default'); $pdf->SetXY(10, 60); 
$pdf->SetFontSize(12); 
$pdf->Write(5, 'Dear Ms.XYX'); 
$filename = "test.pdf"; 
$dir = "/assets/"; 
$pdf->Output($dir . $filename, 'F'); 
+2

請發佈相關的代碼部分。你到目前爲止嘗試了什麼? –

+0

現在我單擊按鈕只有pdf 1生成並保存。但我想說10個學生。下面是我用來生成pdf的代碼: 'require_once('/ wamp/opt/bitnami/apache2/htdocs/lms/lib/fpdf/fpdf.php'); $ pdf = new FPDF(); $ pdf-> SetFont('times','',12); $ pdf-> SetTextColor(50,60,100); $ pdf-> AddPage('L'); $ pdf-> SetDisplayMode(real,'default'); $ pdf-> SetXY(10,60); $ pdf-> SetFontSize(12); $ pdf->寫(5,'Dear Ms.XYX'); $ filename =「test.pdf」; $ dir =「/ assets /」; $ pdf->輸出($ dir。$ filename,'F');' –

+0

上面的代碼不會超出PDF生成的基本模板。你有沒有編寫任何代碼來爲那位老師提供特定學生的信息?如果不是,我會建議先從那裏開始。 –

回答

0

謝謝你們爲你的幫助..解決了我的問題。 環通過PDF功能的第n號。的用戶。