Cleaned up code indentation
This commit is contained in:
parent
7177e5f096
commit
bcd321b9d0
194
accred_list.php
194
accred_list.php
@ -52,88 +52,88 @@ $mysqli = new mysqli($cfg['host'], $cfg['user'],$cfg['pass'], $cfg['name']);
|
|||||||
if ($mysqli->connect_errno) {
|
if ($mysqli->connect_errno) {
|
||||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||||
}
|
}
|
||||||
if ($result = $mysqli->query($query)) {
|
if ($result = $mysqli->query($query)) {
|
||||||
$line = 1;
|
$line = 1;
|
||||||
// First merge keys of all serialized values so we are sure to have all columns
|
// 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()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
$ser = $row['formdata'];
|
$ser = $row['formdata'];
|
||||||
$seru = unserialize($ser);
|
$seru = unserialize($ser);
|
||||||
$or = array_merge($row,$seru);
|
$or = array_merge($row,$seru);
|
||||||
if($line==1) {
|
if($line==1) {
|
||||||
$master_array = $or;
|
$master_array = $or;
|
||||||
}
|
}
|
||||||
$master_array = merge_two_arrays($master_array,$or);
|
$master_array = merge_two_arrays($master_array,$or);
|
||||||
$line++;
|
$line++;
|
||||||
}
|
}
|
||||||
// Now remove unwanted columns
|
// Now remove unwanted columns
|
||||||
foreach($master_array as $key => $val ) {
|
foreach($master_array as $key => $val ) {
|
||||||
if(!($key=='UID' || $key=='modifieduid' || $key=='btnsubmit' || $key=='btnfinalise' || $key=='btnprocess' || $key=='formdata' || $key=='name_form')) {
|
if(!($key=='UID' || $key=='modifieduid' || $key=='btnsubmit' || $key=='btnfinalise' || $key=='btnprocess' || $key=='formdata' || $key=='name_form')) {
|
||||||
$header[$key] = $key;
|
$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 */
|
/* fetch associative array */
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
$ser = $row['formdata'];
|
$ser = $row['formdata'];
|
||||||
$seru = unserialize($ser);
|
$seru = unserialize($ser);
|
||||||
$or = array_merge($row,$seru);
|
$or = array_merge($row,$seru);
|
||||||
// Build full row
|
// Build full row
|
||||||
unset($fr);
|
unset($fr);
|
||||||
foreach($header as $key => $val) {
|
foreach($header as $key => $val) {
|
||||||
if($key=='status') {
|
if($key=='status') {
|
||||||
$disp = 'Indéfini';
|
$disp = 'Indéfini';
|
||||||
switch($or[$key]) {
|
switch($or[$key]) {
|
||||||
case 0:
|
case 0:
|
||||||
$disp = 'Finalisé';
|
$disp = 'Finalisé';
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
$disp = 'Ouvert';
|
$disp = 'Ouvert';
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
$disp = 'Traité';
|
$disp = 'Traité';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$fr[$key] = $disp;
|
$fr[$key] = $disp;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$fr[$key] = $or[$key];
|
$fr[$key] = $or[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($line==1) {
|
if($line==1) {
|
||||||
$keys = array_keys ( $header );
|
$keys = array_keys ( $header );
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->fromArray(
|
->fromArray(
|
||||||
$keys, // The data to set
|
$keys, // The data to set
|
||||||
NULL, // Array values with this value will not be set
|
NULL, // Array values with this value will not be set
|
||||||
'A1' // Top left coordinate of the worksheet range where
|
'A1' // Top left coordinate of the worksheet range where
|
||||||
// we want to set these values (default is A1)
|
// we want to set these values (default is A1)
|
||||||
);
|
);
|
||||||
$line++;
|
$line++;
|
||||||
|
|
||||||
}
|
}
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->fromArray(
|
->fromArray(
|
||||||
$fr, // The data to set
|
$fr, // The data to set
|
||||||
NULL, // Array values with this value will not be set
|
NULL, // Array values with this value will not be set
|
||||||
'A'.$line // Top left coordinate of the worksheet range where
|
'A'.$line // Top left coordinate of the worksheet range where
|
||||||
// we want to set these values (default is A1)
|
// we want to set these values (default is A1)
|
||||||
);
|
);
|
||||||
$line++;
|
$line++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$spreadsheet->getActiveSheet()->getStyle('1')->getFont()->setBold(true);
|
$spreadsheet->getActiveSheet()->getStyle('1')->getFont()->setBold(true);
|
||||||
$spreadsheet->getActiveSheet()->setTitle('Toutes demandes');
|
$spreadsheet->getActiveSheet()->setTitle('Toutes demandes');
|
||||||
foreach (range('A','Z') as $col) {
|
foreach (range('A','Z') as $col) {
|
||||||
$spreadsheet->getActiveSheet()->getColumnDimension($col)->setAutoSize(true);
|
$spreadsheet->getActiveSheet()->getColumnDimension($col)->setAutoSize(true);
|
||||||
}
|
}
|
||||||
foreach (range('A','E') as $col) {
|
foreach (range('A','E') as $col) {
|
||||||
$spreadsheet->getActiveSheet()->getColumnDimension('A'.$col)->setAutoSize(true);
|
$spreadsheet->getActiveSheet()->getColumnDimension('A'.$col)->setAutoSize(true);
|
||||||
}
|
}
|
||||||
// Add totals
|
// 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
|
// 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)) {
|
if ($result = $mysqli->query($query)) {
|
||||||
|
|
||||||
$line = 1;
|
$line = 1;
|
||||||
/* fetch associative array */
|
/* fetch associative array */
|
||||||
while ($row = $result->fetch_assoc()) {
|
while ($row = $result->fetch_assoc()) {
|
||||||
$ser = $row['formdata'];
|
$ser = $row['formdata'];
|
||||||
@ -186,50 +186,50 @@ $line = 1;
|
|||||||
|
|
||||||
}
|
}
|
||||||
if($prevName!=$fr['name']) {
|
if($prevName!=$fr['name']) {
|
||||||
$keys = array_keys ( $header );
|
$keys = array_keys ( $header );
|
||||||
// Create new worksheet
|
// Create new worksheet
|
||||||
if($prevSheet) {
|
if($prevSheet) {
|
||||||
// Add totals
|
// Add totals
|
||||||
// //
|
// //
|
||||||
$highestRow = $prevSheet->getHighestRow();
|
$highestRow = $prevSheet->getHighestRow();
|
||||||
$coord = 'N' . ($highestRow+2);
|
$coord = 'N' . ($highestRow+2);
|
||||||
$prevSheet->setCellValue($coord, 'TOTAL');
|
$prevSheet->setCellValue($coord, 'TOTAL');
|
||||||
foreach(range('O','Z') as $col) {
|
foreach(range('O','Z') as $col) {
|
||||||
$prevSheet->setCellValue($col.($highestRow+2), '=SUM('.$col.'2:'.$col.($highestRow).')');
|
$prevSheet->setCellValue($col.($highestRow+2), '=SUM('.$col.'2:'.$col.($highestRow).')');
|
||||||
}
|
}
|
||||||
// Do AA
|
// Do AA
|
||||||
$prevSheet->setCellValue('AA'.($highestRow+2), '=SUM(AA2:AA'.($highestRow).')');
|
$prevSheet->setCellValue('AA'.($highestRow+2), '=SUM(AA2:AA'.($highestRow).')');
|
||||||
// Format the total
|
// Format the total
|
||||||
$prevSheet->getStyle($coord.':AA'.($highestRow+2))->getFill()
|
$prevSheet->getStyle($coord.':AA'.($highestRow+2))->getFill()
|
||||||
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
|
||||||
->getStartColor()->setARGB('BBBBBBBB');
|
->getStartColor()->setARGB('BBBBBBBB');
|
||||||
|
|
||||||
}
|
}
|
||||||
$prevSheet = $spreadsheet->getActiveSheet();
|
$prevSheet = $spreadsheet->getActiveSheet();
|
||||||
$myWorkSheet = $spreadsheet->createSheet();
|
$myWorkSheet = $spreadsheet->createSheet();
|
||||||
$myWorkSheet->setTitle($fr['name']);
|
$myWorkSheet->setTitle($fr['name']);
|
||||||
$myWorkSheet
|
$myWorkSheet
|
||||||
->fromArray(
|
->fromArray(
|
||||||
$keys, // The data to set
|
$keys, // The data to set
|
||||||
NULL, // Array values with this value will not be set
|
NULL, // Array values with this value will not be set
|
||||||
'A1' // Top left coordinate of the worksheet range where
|
'A1' // Top left coordinate of the worksheet range where
|
||||||
// we want to set these values (default is A1)
|
// we want to set these values (default is A1)
|
||||||
);
|
);
|
||||||
$myWorkSheet->getStyle('1')->getFont()->setBold(true);
|
$myWorkSheet->getStyle('1')->getFont()->setBold(true);
|
||||||
$line=2;
|
$line=2;
|
||||||
$prevName = $fr['name'];
|
$prevName = $fr['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$myWorkSheet
|
$myWorkSheet
|
||||||
->fromArray(
|
->fromArray(
|
||||||
$fr, // The data to set
|
$fr, // The data to set
|
||||||
NULL, // Array values with this value will not be set
|
NULL, // Array values with this value will not be set
|
||||||
'A'.$line // Top left coordinate of the worksheet range where
|
'A'.$line // Top left coordinate of the worksheet range where
|
||||||
// we want to set these values (default is A1)
|
// we want to set these values (default is A1)
|
||||||
);
|
);
|
||||||
|
|
||||||
$line++;
|
$line++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (range('A','Z') as $col) {
|
foreach (range('A','Z') as $col) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user