mpdf = $mpdf = new \Mpdf\Mpdf([ 'margin_top' => 5, // Set your desired top margin in millimeters 'margin_bottom' => 1, 'margin_left' => 1, 'margin_right' => 1, ]); $this->mpdf->Addpage($page_orientations); $stylesheet = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/WebApp/Styles/pdf.css'); $this->mpdf->WriteHTML($stylesheet, \Mpdf\HTMLParserMode::HEADER_CSS); $this->htmlContent = ''; } function CustomDesign() { return $this->mpdf; } function add_page($page_orientations = "P") { $this->mpdf->Addpage($page_orientations); } function pageHeading($text) { $this->htmlContent = $this->htmlContent . "
" . str_replace('_', ' ', strtoupper($text)) . " REPORT"; } function report_on_table($table_name, $columns_not_to_show = [], $columns_to_count = [], $columns_not_to_link = []) { $db = new DBMain(); $counts_row = []; $table_data = ''; $results = $db->query("SELECT COLUMN_NAME,CHARACTER_MAXIMUM_LENGTH,IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '$table_name' and table_schema = '{$_SESSION['db_name']}'"); while ($row = $results->fetch_assoc()) { if ($row['COLUMN_NAME'] != 'record_id') { if (strlen(array_search($row['COLUMN_NAME'], $columns_not_to_show)) > 0) { } else { $columns[] = $row['COLUMN_NAME']; } } } $table_headers = ""; foreach ($columns as $col) { $table_headers = $table_headers . "" . str_replace($table_name, '', str_replace('id', '', str_replace("_", " ", $col))) . ""; } $table_headers = $table_headers . ""; $table_data_res = $db->exec_query($table_name, ['*'], '', '', '', '', '1', "ORDER BY record_id DESC"); while ($data = $table_data_res->fetch_assoc()) { $table_data = $table_data . ""; foreach ($columns as $col) { if (strpos($col, "_id") > 0) { if (strlen(array_search($col, $columns_not_to_link)) > 0) { } else { $link_table_name = substr($col, 0, strpos($col, "_id")); $res = $db->exec_query($link_table_name, ['*'], '', '', '', '', "record_id = {$data[$col]}"); $a = $res->fetch_assoc(); if (strpos(str_replace('_', ' ', $col), 'users') > 0) { $d = $a['username']; } else { $d = $a[$link_table_name . '_name']; } } } else { $d = $data[$col]; } $table_data = $table_data . "" . $d . ""; if (strlen(array_search($col, $columns_to_count)) > 0) { $counts_row[$col] = $counts_row[$col] + $data[$col]; } else { $counts_row[$col] = ''; } } $table_data = $table_data . ""; } $totals_row = ''; foreach ($counts_row as $totals) { $totals_row = $totals_row . "" . $totals . ''; } $totals_row = $totals_row . ''; $this->htmlContent = $this->htmlContent . "
" . str_replace('_', ' ', strtoupper($table_name)) . " REPORT $table_headers $table_data $totals_row
"; } function inject_html($html) { $this->htmlContent = $this->htmlContent . " " . $html; } function __destruct() { $this->mpdf->WriteHTML($this->htmlContent); $this->mpdf->Output("/WebApp/Reports/Daaa.pdf","I"); } }