From bcd321b9d01d60b01d62335336cb5c013af58734 Mon Sep 17 00:00:00 2001 From: lars Date: Thu, 2 May 2019 14:55:16 +0200 Subject: [PATCH] Cleaned up code indentation --- accred_list.php | 196 ++++++++++++++++++++++++------------------------ 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/accred_list.php b/accred_list.php index 8d87f160..91aaab6e 100644 --- a/accred_list.php +++ b/accred_list.php @@ -52,88 +52,88 @@ $mysqli = new mysqli($cfg['host'], $cfg['user'],$cfg['pass'], $cfg['name']); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } - if ($result = $mysqli->query($query)) { - $line = 1; - // First merge keys of all serialized values so we are sure to have all columns +if ($result = $mysqli->query($query)) { + $line = 1; + // First merge keys of all serialized values and build an array containing all columns + // (even if they are empty on first line... -> no key) while ($row = $result->fetch_assoc()) { $ser = $row['formdata']; $seru = unserialize($ser); - $or = array_merge($row,$seru); - if($line==1) { - $master_array = $or; - } - $master_array = merge_two_arrays($master_array,$or); - $line++; + $or = array_merge($row,$seru); + if($line==1) { + $master_array = $or; + } + $master_array = merge_two_arrays($master_array,$or); + $line++; } // Now remove unwanted columns foreach($master_array as $key => $val ) { if(!($key=='UID' || $key=='modifieduid' || $key=='btnsubmit' || $key=='btnfinalise' || $key=='btnprocess' || $key=='formdata' || $key=='name_form')) { $header[$key] = $key; - } - } + } + } } - if ($result = $mysqli->query($query)) { -$line = 1; +// Now we have a array with all the keys/columns we want to export to Excel +if ($result = $mysqli->query($query)) { + $line = 1; /* fetch associative array */ while ($row = $result->fetch_assoc()) { $ser = $row['formdata']; $seru = unserialize($ser); $or = array_merge($row,$seru); - // Build full row - unset($fr); - foreach($header as $key => $val) { - if($key=='status') { - $disp = 'Indéfini'; - switch($or[$key]) { - case 0: - $disp = 'Finalisé'; - break; - case 1: - $disp = 'Ouvert'; - break; - case 3: - $disp = 'Traité'; - break; - } - $fr[$key] = $disp; - } - else { + // Build full row + unset($fr); + foreach($header as $key => $val) { + if($key=='status') { + $disp = 'Indéfini'; + switch($or[$key]) { + case 0: + $disp = 'Finalisé'; + break; + case 1: + $disp = 'Ouvert'; + break; + case 3: + $disp = 'Traité'; + break; + } + $fr[$key] = $disp; + } + else { $fr[$key] = $or[$key]; - } + } } - if($line==1) { - $keys = array_keys ( $header ); - $spreadsheet->getActiveSheet() - ->fromArray( - $keys, // The data to set - NULL, // Array values with this value will not be set - 'A1' // Top left coordinate of the worksheet range where + if($line==1) { + $keys = array_keys ( $header ); + $spreadsheet->getActiveSheet() + ->fromArray( + $keys, // The data to set + NULL, // Array values with this value will not be set + 'A1' // Top left coordinate of the worksheet range where // we want to set these values (default is A1) - ); - $line++; + ); + $line++; - } -$spreadsheet->getActiveSheet() - ->fromArray( - $fr, // The data to set - NULL, // Array values with this value will not be set - 'A'.$line // Top left coordinate of the worksheet range where - // we want to set these values (default is A1) - ); + } + $spreadsheet->getActiveSheet() + ->fromArray( + $fr, // The data to set + NULL, // Array values with this value will not be set + 'A'.$line // Top left coordinate of the worksheet range where + // we want to set these values (default is A1) + ); $line++; - } - - - + } } + $spreadsheet->getActiveSheet()->getStyle('1')->getFont()->setBold(true); $spreadsheet->getActiveSheet()->setTitle('Toutes demandes'); foreach (range('A','Z') as $col) { - $spreadsheet->getActiveSheet()->getColumnDimension($col)->setAutoSize(true); + $spreadsheet->getActiveSheet()->getColumnDimension($col)->setAutoSize(true); } foreach (range('A','E') as $col) { - $spreadsheet->getActiveSheet()->getColumnDimension('A'.$col)->setAutoSize(true); + $spreadsheet->getActiveSheet()->getColumnDimension('A'.$col)->setAutoSize(true); } // Add totals // @@ -153,10 +153,10 @@ $spreadsheet->getActiveSheet()->getStyle($coord.':AA'.($highestRow+2))->getFill( // ------ // Go again this time sorted by name so we can create a worksheet per requestor - $query = "SELECT * from submissions ORDER BY name"; +$query = "SELECT * from submissions ORDER BY name"; if ($result = $mysqli->query($query)) { -$line = 1; + $line = 1; /* fetch associative array */ while ($row = $result->fetch_assoc()) { $ser = $row['formdata']; @@ -186,50 +186,50 @@ $line = 1; } if($prevName!=$fr['name']) { - $keys = array_keys ( $header ); - // Create new worksheet - if($prevSheet) { - // Add totals - // // - $highestRow = $prevSheet->getHighestRow(); - $coord = 'N' . ($highestRow+2); - $prevSheet->setCellValue($coord, 'TOTAL'); - foreach(range('O','Z') as $col) { - $prevSheet->setCellValue($col.($highestRow+2), '=SUM('.$col.'2:'.$col.($highestRow).')'); - } - // Do AA - $prevSheet->setCellValue('AA'.($highestRow+2), '=SUM(AA2:AA'.($highestRow).')'); - // Format the total - $prevSheet->getStyle($coord.':AA'.($highestRow+2))->getFill() - ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID) - ->getStartColor()->setARGB('BBBBBBBB'); - - } - $prevSheet = $spreadsheet->getActiveSheet(); - $myWorkSheet = $spreadsheet->createSheet(); - $myWorkSheet->setTitle($fr['name']); - $myWorkSheet - ->fromArray( - $keys, // The data to set - NULL, // Array values with this value will not be set - 'A1' // Top left coordinate of the worksheet range where - // we want to set these values (default is A1) - ); - $myWorkSheet->getStyle('1')->getFont()->setBold(true); - $line=2; - $prevName = $fr['name']; + $keys = array_keys ( $header ); + // Create new worksheet + if($prevSheet) { + // Add totals + // // + $highestRow = $prevSheet->getHighestRow(); + $coord = 'N' . ($highestRow+2); + $prevSheet->setCellValue($coord, 'TOTAL'); + foreach(range('O','Z') as $col) { + $prevSheet->setCellValue($col.($highestRow+2), '=SUM('.$col.'2:'.$col.($highestRow).')'); + } + // Do AA + $prevSheet->setCellValue('AA'.($highestRow+2), '=SUM(AA2:AA'.($highestRow).')'); + // Format the total + $prevSheet->getStyle($coord.':AA'.($highestRow+2))->getFill() + ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID) + ->getStartColor()->setARGB('BBBBBBBB'); + + } + $prevSheet = $spreadsheet->getActiveSheet(); + $myWorkSheet = $spreadsheet->createSheet(); + $myWorkSheet->setTitle($fr['name']); + $myWorkSheet + ->fromArray( + $keys, // The data to set + NULL, // Array values with this value will not be set + 'A1' // Top left coordinate of the worksheet range where + // we want to set these values (default is A1) + ); + $myWorkSheet->getStyle('1')->getFont()->setBold(true); + $line=2; + $prevName = $fr['name']; } - $myWorkSheet - ->fromArray( - $fr, // The data to set - NULL, // Array values with this value will not be set - 'A'.$line // Top left coordinate of the worksheet range where - // we want to set these values (default is A1) - ); + $myWorkSheet + ->fromArray( + $fr, // The data to set + NULL, // Array values with this value will not be set + 'A'.$line // Top left coordinate of the worksheet range where + // we want to set these values (default is A1) + ); $line++; - } + } } foreach (range('A','Z') as $col) {