Пример #1
0
 function generatePdfReport($pdfData, $mode, $params, $fileName)
 {
     $countries = CJFunctions::get_country_names();
     $responses = array();
     $include_email_in_reports = $params->get('include_email_in_reports', 0);
     foreach ($pdfData->responses as $response) {
         $responses[$response->id] = new stdClass();
         $responses[$response->id]->created_by = $response->created_by;
         $responses[$response->id]->created = $response->created;
         $responses[$response->id]->username = $response->username;
         $responses[$response->id]->name = $response->name;
         if ($include_email_in_reports == 1) {
             $responses[$response->id]->email = $response->email;
         }
         $responses[$response->id]->questions = array();
         foreach ($pdfData->questions as $question) {
             $responses[$response->id]->questions[$question->id] = new stdClass();
             $responses[$response->id]->questions[$question->id]->answer = '';
             $responses[$response->id]->questions[$question->id]->question_type = $question->question_type;
         }
     }
     if (!empty($pdfData->entries)) {
         foreach ($pdfData->entries as $entry) {
             if (isset($responses[$entry->response_id]) && isset($responses[$entry->response_id]->questions[$entry->question_id])) {
                 if (!empty($entry->answer)) {
                     if (empty($responses[$entry->response_id]->questions[$entry->question_id]->answer)) {
                         $responses[$entry->response_id]->questions[$entry->question_id]->answer = $entry->answer;
                     } else {
                         $responses[$entry->response_id]->questions[$entry->question_id]->answer .= '<br/>' . $entry->answer;
                     }
                     if (!empty($entry->answer_image) && JFile::exists(S_IMAGES_UPLOAD_DIR . '/' . $entry->answer_image)) {
                         //$image = JHtml::image(JURI::root(true).'/media/communitysurveys/images/'.$entry->answer_image, $entry->answer);
                         $image = '<img src="' . JURI::root(true) . '/media/communitysurveys/images/' . $entry->answer_image . '">';
                         $responses[$entry->response_id]->questions[$entry->question_id]->answer .= '<br/>' . $image;
                     }
                 }
                 if (!empty($entry->answer2)) {
                     if (empty($responses[$entry->response_id]->questions[$entry->question_id]->answer)) {
                         $responses[$entry->response_id]->questions[$entry->question_id]->answer = $entry->answer2;
                     } else {
                         $responses[$entry->response_id]->questions[$entry->question_id]->answer .= '<br/>' . $entry->answer2;
                     }
                 }
                 if (!empty($entry->free_text)) {
                     // do special types formatting //
                     if ($responses[$entry->response_id]->questions[$entry->question_id]->question_type == S_SPECIAL_NAME) {
                         $names = explode('|', $entry->free_text);
                         if (!empty($names)) {
                             $entry->free_text = $names[0] . '. ' . $names[1] . ' ' . $names[2];
                         } else {
                             $entry->free_text = '';
                         }
                     } else {
                         if ($responses[$entry->response_id]->questions[$entry->question_id]->question_type == S_SPECIAL_ADDRESS) {
                             $parts = explode('|||', $entry->free_text);
                             if (count($parts) == 7) {
                                 $entry->free_text = '<address><strong>' . CJFunctions::escape($parts[0]) . '</strong><br>';
                                 $entry->free_text .= CJFunctions::escape($parts[1]) . '<br>';
                                 if (!empty($parts[2])) {
                                     $entry->free_text .= CJFunctions::escape($parts[2]) . '<br>';
                                 }
                                 $entry->free_text .= CJFunctions::escape($parts[3]) . ', ' . CJFunctions::escape($parts[4]) . ', ' . CJFunctions::escape($parts[6]) . '<br>';
                                 $entry->free_text .= !empty($countries[$parts[5]]) ? $countries[$parts[5]]->country_name : CJFunctions::escape($parts[5]);
                             } else {
                                 $entry->free_text = '';
                             }
                         }
                     }
                     // do special types formatting //
                     if (empty($responses[$entry->response_id]->questions[$entry->question_id]->answer)) {
                         $responses[$entry->response_id]->questions[$entry->question_id]->answer = $entry->free_text;
                     } else {
                         $responses[$entry->response_id]->questions[$entry->question_id]->answer .= '<br/>' . $entry->free_text;
                     }
                 }
             }
         }
     }
     $response_rows = array();
     foreach ($responses as $id => $response) {
         $string = '<table class="table table-striped" width="100%">';
         $string = $string . '<tr><th width="30%"><strong>Response ID:</strong></th><td width="70%">' . $id . '</td></tr>';
         $string = $string . '<tr><th><strong>Response Date:</strong></th><td>' . $response->created . '</td></tr>';
         $string = $string . '<tr><th><strong>User ID:</strong></th><td>' . $response->created_by . '</td></tr>';
         $string = $string . '<tr><th><strong>Username:</strong></th><td>' . $response->username . '</td></tr>';
         $string = $string . '<tr><th><strong>User Display Name:</strong></th><td>' . $response->name . '</td></tr>';
         if ($include_email_in_reports == 1) {
             $string = $string . '<tr><td><strong>Email:</strong></td><td>' . $response->email . '</td></tr>';
         }
         foreach ($pdfData->questions as $question) {
             $string = $string . '<tr><td colspan="2">&nbsp;<hr></td></tr>';
             $string = $string . '<tr><th colspan="2"><h3>' . $question->title . '</h3></th></tr>';
             if (!empty($question->description)) {
                 $string = $string . '<tr><td colspan="2">' . $question->description . '</td></tr>';
             }
             $string = $string . '<tr><td colspan="2">&nbsp;</td></tr>';
             $string = $string . '<tr><td colspan="2">' . $response->questions[$question->id]->answer . '</td></tr>';
         }
         $string = $string . '</table>';
         array_push($response_rows, $string);
     }
     // create new PDF document
     require_once JPATH_COMPONENT_SITE . '/helpers/tcpdf.php';
     $pdf = new MYPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set default header data
     $pdf->SetHeaderData('logo.png', PDF_HEADER_LOGO_WIDTH, $pdfData->title, '');
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('corejoomla.com');
     $pdf->SetTitle('Survey Report');
     $pdf->SetSubject('Survey Responses Report');
     $pdf->SetKeywords('survey, report');
     // set header and footer fonts
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     //set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     //set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     //set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // ---------------------------------------------------------
     // set font
     $pdf->SetFont('freesans');
     foreach ($response_rows as $i => $response) {
         $pdf->AddPage();
         $pdf->writeHTML($response, true, false, true, false, '');
         $pdf->lastPage();
     }
     $pdf->Output($fileName, $mode);
 }
Пример #2
0
    public function get_address_question($item, $class)
    {
        $free_text = '';
        $country_options = array();
        $classname = $item->mandatory ? ' required' : '';
        $html = '<div id="qn-' . $item->id . '" class="question-item well well-transperant' . (isset($item->hidden) ? ' hideme ' : ' ') . $class . ' ' . $item->params->get('question_class', '') . ' clearfix"' . (isset($item->hidden) ? ' style="display: none;"' : '') . (isset($item->rule_answered) ? ' showitems="' . implode(',', $item->rule_answered) . '"' : '') . '>';
        $html .= '<div class="question-title qtype-' . $item->question_type . ' ' . $item->params->get('title_class', '') . '">' . CJFunctions::escape($item->title) . '</div>';
        $html .= '<div class="question-description ' . $item->params->get('description_class', '') . '">' . CJFunctions::process_html($item->description, $this->_bbcode, $this->_content) . '</div>';
        if (!empty($item->responses)) {
            foreach ($item->responses as $response) {
                if (!empty($response->free_text)) {
                    $free_text = CJFunctions::escape($response->free_text);
                    break;
                }
            }
        }
        $address_parts = explode('|||', $free_text);
        if (count($address_parts) != 7) {
            $address_parts = array('', '', '', '', '', '', '');
        }
        if (null == $this->_countries) {
            $this->_countries = CJFunctions::get_country_names();
        }
        foreach ($this->_countries as $country) {
            $country_options[] = '<option value="' . $country->country_code . '"' . ($address_parts[5] == $country->country_code ? ' selected="selected"' : '') . '>' . CJFunctions::escape($country->country_name) . '</option>';
        }
        $html .= '
		<div class="container-fluid address-wrapper error no-space-left">
			<div class="row-fluid">
				<input type="text" name="address-name-' . $item->id . '" class="span12' . $classname . '" value="' . $address_parts[0] . '" 
					placeholder="' . JText::_('LBL_ADDRESS_FULL_NAME') . '">
			</div>
			<div class="row-fluid">
				<input type="text" name="address-line1-' . $item->id . '" class="span12' . $classname . '" value="' . $address_parts[1] . '" 
					placeholder="' . JText::_('LBL_ADDRESS_ADDRESS_LINE1') . '">
			</div>
			<div class="row-fluid">
				<input type="text" name="address-line2-' . $item->id . '" class="span7" value="' . $address_parts[2] . '" 
					placeholder="' . JText::_('LBL_ADDRESS_ADDRESS_LINE2') . '">
				<input type="text" name="address-city-' . $item->id . '" class="span5' . $classname . ' pull-right" value="' . $address_parts[3] . '" 
					placeholder="' . JText::_('LBL_ADDRESS_ADDRESS_CITY') . '">
			</div>
			<div class="row-fluid">
				<input type="text" name="address-state-' . $item->id . '" class="span4' . $classname . '" value="' . $address_parts[4] . '" 
					placeholder="' . JText::_('LBL_ADDRESS_ADDRESS_STATE') . '">
				<select name="address-country-' . $item->id . '" size="1" class="span5' . $classname . '">
					<option>' . JText::_('LBL_SELECT_OPTION') . '</option>
					' . implode('', $country_options) . '
				</select>
				<input type="text" name="address-zip-' . $item->id . '" class="span3' . $classname . ' pull-right" value="' . $address_parts[6] . '" 
					placeholder="' . JText::_('LBL_ADDRESS_ADDRESS_ZIP') . '">
			</div>
		</div>';
        $html .= '</div>';
        return $html;
    }