Example #1
0
 function search_pdf($VAR, $construct, $type)
 {
     # include fpdf class:
     include_once PATH_CORE . 'fpdf.inc.php';
     # set the field list for this method:
     $arr = $construct->method["{$type}"];
     # loop through the field list to create the sql queries
     $field_list = '';
     $heading_list = '';
     $width_list = '';
     $i = 0;
     while (list($key, $value) = each($arr)) {
         if ($i == 0) {
             $field_var = $construct->table . '_' . $value;
             $field_list .= $value;
             $heading_list .= strtoupper($value);
             // <- translate
             $width_list .= $construct->field[$value]['pdf_width'];
         } else {
             $field_var = $construct->table . '_' . $value;
             $field_list .= "," . $value;
             $heading_list .= "," . strtoupper($value);
             // <- translate
             $width_list .= "," . $construct->field[$value]['pdf_width'];
         }
         $i++;
     }
     # start the new PDF class...
     $pdf = new PDF_MC_Table();
     $pdf->Open();
     $pdf->AddPage();
     # Determine the number of columns and width for each one...
     $SetWidths = explode(",", $width_list);
     $pdf->SetWidths($SetWidths);
     # Define the table heading
     $TableHeading = explode(",", $heading_list);
     # Define the Properties for the table heading cells:
     # set the font:
     $pdf->HeadFontFamily = "Arial";
     $pdf->HeadFontStyle = "BI";
     $pdf->HeadFontSize = 8;
     # set the font color:
     $pdf->HeadTextColor1 = 255;
     $pdf->HeadTextColor2 = 255;
     $pdf->HeadTextColor3 = 255;
     # set the bg color:
     $pdf->HeadFillColor1 = 90;
     $pdf->HeadFillColor2 = 90;
     $pdf->HeadFillColor3 = 90;
     # set the hieght
     $pdf->HeadHeight = 6;
     # Print the Heading:
     $pdf->HeadRow($TableHeading);
     # Define the row settings for the rest of the cells...
     # define the font settings
     $pdf->SetFontFamily = "Arial";
     $pdf->SetFontStyle = "";
     $pdf->SetFontSize = "7";
     # set the hieght
     $pdf->RowHeight = 4;
     /************** BEGIN STANDARD EXPORT SEARCH CODE *********************/
     # set the field list for this method:
     $arr = $construct->method["{$type}"];
     # loop through the field list to create the sql queries
     $arr = $construct->method[$type];
     $field_list = '';
     $i = 0;
     while (list($key, $value) = each($arr)) {
         if ($i == 0) {
             $field_var = $construct->table . '_' . $value;
             $field_list .= AGILE_DB_PREFIX . $construct->table . '.' . $value;
             // determine if this record is linked to another table/field
             if ($construct->field[$value]["asso_table"] != "") {
                 $this->linked[] = array('field' => $value, 'link_table' => $construct->field[$value]["asso_table"], 'link_field' => $construct->field[$value]["asso_field"]);
             }
         } else {
             $field_var = $construct->table . '_' . $value;
             $field_list .= "," . AGILE_DB_PREFIX . $construct->table . "." . $value;
             // determine if this record is linked to another table/field
             if ($construct->field[$value]["asso_table"] != "") {
                 $this->linked[] = array('field' => $value, 'link_table' => $construct->field[$value]["asso_table"], 'link_field' => $construct->field[$value]["asso_field"]);
             }
         }
         $i++;
     }
     # get the search details:
     if (isset($VAR['search_id'])) {
         include_once PATH_CORE . 'search.inc.php';
         $search = new CORE_search();
         $search->get($VAR['search_id']);
     } else {
         echo '<BR> The search terms submitted were invalid!';
     }
     # get the sort order details:
     if (isset($VAR['order_by']) && $VAR['order_by'] != "") {
         $order_by = ' ORDER BY ' . AGILE_DB_PREFIX . $construct->table . '.' . $VAR['order_by'];
         $smarty_order = $VAR['order_by'];
     } else {
         $order_by = ' ORDER BY ' . AGILE_DB_PREFIX . $construct->table . '.' . $construct->order_by;
         $smarty_order = $search->order_by;
     }
     # format saved search string
     $sql = explode(" WHERE ", $search->sql);
     # generate the full query
     $q = preg_replace("/%%fieldList%%/i", $field_list, $search->sql);
     $q = preg_replace("/%%tableList%%/i", AGILE_DB_PREFIX . $construct->table, $q);
     $q = preg_replace("/%%whereList%%/i", "", $q);
     $q .= " " . AGILE_DB_PREFIX . $construct->table . ".site_id = '" . DEFAULT_SITE . "'";
     $q .= $order_by;
     $db =& DB();
     $result = $db->Execute($q);
     # error reporting
     if ($result === false) {
         global $C_debug;
         $C_debug->error('core:export.inc.php', 'search_xml', $db->ErrorMsg() . '<br><br>' . $q);
         echo "An SQL error has occured!";
         return;
     }
     # put the results into an array
     $i = 0;
     $class_name = TRUE;
     $results = '';
     while (!$result->EOF) {
         $results[$i] = $result->fields;
         $result->MoveNext();
         $i++;
     }
     # get any linked fields
     if ($i > 0) {
         $this->result = $results;
         $db_join = new CORE_database();
         $this->result = $db_join->join_fields($results, $this->linked);
     } else {
         $this->result = $results;
     }
     /************** END STANDARD EXPORT SEARCH CODE *********************/
     # LOOP THROUGH THE RESULTS & DISPLAY AS PDF
     $results = $result->RecordCount();
     $BackAlt = TRUE;
     while (!$result->EOF) {
         # get the data for each cell:
         reset($arr);
         $CurrRow = '';
         $i = 0;
         while (list($key, $value) = each($arr)) {
             if ($i == 0) {
                 $CurrRow .= $result->fields["{$key}"];
             } else {
                 $CurrRow .= "::" . $result->fields["{$key}"];
             }
             $i++;
         }
         $ThisRow = explode("::", $CurrRow);
         # set the colors & fonts
         if ($BackAlt) {
             # alternating row 1:
             $pdf->SetTextColorVar1 = "50";
             $pdf->SetTextColorVar2 = "50";
             $pdf->SetTextColorVar3 = "50";
             $pdf->SetFillColorVar1 = 255;
             $pdf->SetFillColorVar2 = 255;
             $pdf->SetFillColorVar3 = 255;
             $BackAlt = FALSE;
         } else {
             # alternating row 2:
             $pdf->SetTextColorVar1 = "0";
             $pdf->SetTextColorVar2 = "0";
             $pdf->SetTextColorVar3 = "0";
             $pdf->SetFillColorVar1 = 240;
             $pdf->SetFillColorVar2 = 240;
             $pdf->SetFillColorVar3 = 240;
             $BackAlt = TRUE;
         }
         # check for needed page break
         $nb = 0;
         for ($ii = 0; $ii < count($dataarr); $ii++) {
             $nb = max($nb, $pdf->NbLines($pdf->widths[$ii], $dataarr[$ii]));
         }
         $h = 5 * $nb;
         # Issue a page break first if needed
         if ($pdf->CheckPageBreak($h)) {
             # print the Table Heading again
             $pdf->HeadRow($TableHeading);
         }
         $pdf->Row($ThisRow);
         # Next record
         $result->MoveNext();
     }
     # Dispay the output
     $pdf->Output();
     exit;
 }