HTML; // HTML template end $html_end = << HTML; // Initialize the HTML files fwrite($def_no_grp_html, $html_start); fwrite($def_grp1_html, $html_start); fwrite($def_grp2_html, $html_start); fwrite($def_grp3_html, $html_start); fwrite($def_grp4_html, $html_start); fwrite($def_multiple_cases_html, $html_start); fwrite($def_akas_html, $html_start); $sql = "SELECT * FROM cases"; $st = $dbh->prepare($sql); if ( $st->execute() ) { while ( $case = $st->fetch(PDO::FETCH_ASSOC) ) { $has_multiple_cases = false; $has_akas = false; $defendant_csv = array( $case['court_case_no'], $case['name'], $case['date_birth'], ); $defendant_html = << HTML; $sql_charge = "SELECT * FROM charges WHERE case_id = '{$case['id']}'"; $st_charge = $dbh->prepare($sql_charge); $st_charge->execute(); $charges = $st_charge->fetchAll(PDO::FETCH_ASSOC); // The default group is no group (i.e. 0) $disposition_group = 0; foreach ( $charges as $charge ) { // Figure out into which, if any, disposition group // this charge puts the case foreach ( $disposition_groups as $group_and_disposition ) { list($group,$disposition) = explode(',', $group_and_disposition); if ( $charge['disposition'] == $disposition ) { // Only move a case into a higher group, never backward if ( $disposition_group == '0' || $group < $disposition_group ) { $disposition_group = $group; } } } // Don't process this case if there is an empty disposition if ( ! trim($charge['disposition']) ) { continue(2); } // If the disposition is a "fatal" one then go to next case if ( in_array( $charge['disposition'], $fatal_dispositions) ) { continue(2); } // If the charge is excludable and the disposition is not a safe one then go to the next case if ( in_array($charge['charge'], $excludable_charges) && ! in_array($charge['disposition'], $safe_dispositions) ) { continue(2); } } // Does this person have multiple cases, based on the same name and date of birth? $sql_def = "SELECT count(*) from cases WHERE name = '{$case['name']}' AND date_birth = '{$case['date_birth']}' AND id != '{$case['id']}'"; $st_def = $dbh->prepare($sql_def); $st_def->execute(); $case_count = $st_def->fetchColumn(); if ( $case_count != '0' ) { $has_multiple_cases = true; } // Does this person has any AKAs? $sql_akas = "SELECT count(*) FROM akas WHERE case_id = '{$case['id']}'"; $st_akas = $dbh->prepare($sql_akas); $st_akas->execute(); if ( $st_akas->fetchColumn() != '0' ) { $has_akas = true; } if ( $has_multiple_cases && ! $has_akas ) { fputcsv($def_multiple_cases_csv, $defendant_csv); fwrite($def_multiple_cases_html, $defendant_html); } if ( $has_akas && ! $has_multiple_cases ) { fputcsv($def_akas_csv, $defendant_csv); fwrite($def_akas_html, $defendant_html); } if ( $has_multiple_cases && $has_akas ) { fputcsv($def_akas_multiple_cases_csv, $defendant_csv); fwrite($def_akas_multiple_cases_html, $defendant_html); } // The highest quality list if ( ! $has_multiple_cases && ! $has_akas ) { switch ( $disposition_group ) { case '1': fputcsv($def_grp1_csv, $defendant_csv); fwrite($def_grp1_html, $defendant_html); break; case '2': fputcsv($def_grp2_csv, $defendant_csv); fwrite($def_grp2_html, $defendant_html); case '3': fputcsv($def_grp3_csv, $defendant_csv); fwrite($def_grp3_html, $defendant_html); break; case '4': fputcsv($def_grp4_csv, $defendant_csv); fwrite($def_grp4_html, $defendant_html); break; default: fputcsv($def_no_grp_csv, $defendant_csv); fwrite($def_no_grp_html, $defendant_html); } } } } // Finalize HTML files fwrite($def_no_grp_html, $html_stop); fwrite($def_grp1_html, $html_stop); fwrite($def_grp2_html, $html_stop); fwrite($def_grp3_html, $html_stop); fwrite($def_grp4_html, $html_stop); fwrite($def_multiple_cases_html, $html_stop); fwrite($def_akas_html, $html_stop); fwrite($def_akas_multiple_cases_html, $html_stop); fclose($def_no_group_csv); fclose($def_grp1_csv); fclose($def_grp2_csv); fclose($def_grp3_csv); fclose($def_grp4_csv); fclose($def_multiple_cases_csv); fclose($def_akas_csv); fclose($def_akas_multiple_cases_csv); fclose($def_no_group_html); fclose($def_grp1_html); fclose($def_grp2_html); fclose($def_grp3_html); fclose($def_grp4_html); fclose($def_multiple_cases_html); fclose($def_akas_html); fclose($def_akas_multiple_cases_html); ?>
{$case['court_case_no']} {$case['name']} {$case['date_birth']} [charges]