MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/www/imenso.co/matrix/admin/assignment.php
<?php include 'admin_header.php';
error_reporting(0);
/*error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);*/

// include('../PHPExcel/Classes/PHPExcel/IOFactory.php');

require '../vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
// echo dirname( dirname(__FILE__) ).'/zip_files/*.zip';
// die();

if(isset($_POST['save']))
{
    // $doc_nos = ['408416', '408506'];
    $doc_nos =  $_POST['doc_no'];
    foreach($doc_nos as $doc_no)
    {
        
        $file = "../../data/data/a/$doc_no.zip";
        // $file = "../zip_files/$doc_no.zip";
        $path = "../docs/$doc_no";
        $zip = new ZipArchive;
        $res = $zip->open($file);
        if ($res === TRUE) 
        {
            if(count(glob("$path/*"))<=0)
            {
                $zip->extractTo($path);
                $zip->close();
            }
            

            $sql = "INSERT INTO assignments ( assignment_no,no_of_record,assignment_date,assignment_status_id,user_id,submit_date,created_at,updated_at) 
            VALUES 
            ( '".$doc_no."', '0', '".date("Y-m-d")."', '1', '".$_POST['operator_id']."', NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)";
    
            if ($conn->query($sql) === TRUE) 
            {
                $assignment_id = $conn->insert_id;
                
                $FileName = "../docs/$doc_no/$doc_no.xls" ;
                if(file_exists($FileName))
                {
                    $inputFileName = $FileName;
                }
                else{

                    $inputFileName = "../docs/$doc_no/$doc_no.xlsx";
                }

                /* Simple Library */
               /* $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
                $excel2 = PHPExcel_IOFactory::createReader($inputFileType);
                $excel2 = $objPHPExcel = $excel2->load($inputFileName);
                $sheet = $objPHPExcel->getSheet(0);
                $highestRow = $sheet->getHighestRow();
               
                for ($row = 2; $row <= $highestRow; $row++) 
                {
                    $sql1 = "INSERT INTO assignment_details ( assignment_id,doc_id) 
                    VALUES 
                    ( '".$assignment_id."','".$sheet->getCell('A'.$row)->getValue()."' )";
                    $conn->query($sql1) ;   
                }*/

                /* Laravel Library */
                
                // $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
                // $spreadsheet = $reader->load($inputFileName);
                $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);

                $d=$spreadsheet->getSheet(0)->toArray();
                $highestRow = $spreadsheet->getActiveSheet()->getHighestRow();
                $sheetData = $spreadsheet->getActiveSheet()->toArray();

                for ($row = 2; $row <= $highestRow; $row++) 
                {
                    $sql1 = "INSERT INTO assignment_details ( assignment_id,doc_id) 
                    VALUES 
                    ( '".$assignment_id."','".$spreadsheet->getActiveSheet()->getCell('A'.$row)->getValue()."' )";
                    $conn->query($sql1) ;   
                }



                $conn->query("UPDATE assignments SET no_of_record='".($highestRow - 1)."' WHERE id=".$assignment_id."") ;
            } 
            else 
            {
                echo "Error: " . $sql . "<br>" . $conn->error;
            }
            
          
        } 
        else 
        {
            //echo "Doh! I couldn't open $file";
        }
    }
}


?>
<div class="container" style="background: #fff;position:relative; margin-top:42px ">
    <div class="assignment-dashboard">
        <form action="" method="POST" >
            <div class="row">
                <div class="col-sm-8 border-right">
                     <h5 class="mt-3 mb-3">NEW FOLDERS <span class="font-weight-light small text-info total_count">[0]</span><div class="pull-right"><strong class="badge badge-secondary checked_count">0</strong></div></h5>
                    <input type="text" name="search" class="mb-3 assignment_new"  placeholder="Search: [Folder Index]" id="search" style=" width: -webkit-fill-available; text-align: center;">
                    <div class="table-responsive" id="new_assignment_table">
                        <table class="table table-striped table-sm table-bordered" >
                            <thead>
                                <tr>
                                    <th>Action</th>
                                    <th>Folder Index
                                        <!-- <a href="javascript:;" class="column_sort_new" id="assignment_no" data-order="desc">Folder Index</a>  -->
                                    </th>
                                    <th>Data Count
                                        <!-- <a href="javascript:;" class="column_sort_new" id="no_of_record" data-order="desc"> Data Count</a> -->
                                    </th>
                                    <th>Upload Date
                                        <!-- <a href="javascript:;" class="column_sort_new" id="assignment_date" data-order="desc">Upload Date</a> -->
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $total = 0 ;
                                date_default_timezone_set('Asia/Kolkata');
                                $fileList = array_reverse(glob('../../data/data/a/*.zip'));
                                // $fileList = array_reverse(glob(dirname( dirname(__FILE__) ).'/zip_files/*.zip')) ;

                                $files = array();
                                foreach($fileList as $filename){
                                $file = basename($filename) ;
                                $file = basename($file, ".zip");
                                $files[] = $file ;
                                $result = $conn->query("SELECT * FROM assignments WHERE assignment_no = $file");
                                $row = mysqli_fetch_row($result);
                                if(!$row)
                                {
                                    $za = new ZipArchive();
                                    $za->open($filename);
                                    $count = $za->numFiles - 1 ;
                                    $total =  $total + $count ;

                                    if($count>0){
                                ?>
                                <tr>
                                    <td><input type="checkbox" class="chk_doc_no" name="doc_no[]" value="<?php echo $file ; ?>" file_count="<?php echo $count ; ?>"  /></td>
                                    <td><?php echo $file ?></td>
                                    
                                    <td>
                                        <?php echo $count ; ?>
                                    </td>
                                    <td><?php echo date("m/d/Y", filemtime($filename)); ?> </td>
                                </tr>
                                <?php
                            }
                                }
                                }
                                
                                // echo $sql = "SELECT * FROM assignments WHERE assignment_no NOT IN (".implode(',', $files).")";
                                // $result = $conn->query($sql);
                                // while($row = $result->fetch_assoc()) {
                                //     echo "id: " . $row["id"]. " - assignment_no: " . $row["assignment_no"]. " " . $row["no_of_record"]. "<br>";
                                // }
                                
                                ?> 
                            </tbody>
                            <!--<tfoot>-->
                            <!--    <tr>-->
                            <!--        <th>Action</th>-->
                            <!--        <th>Folder Index</th>-->
                            <!--        <th>Data Count</th>-->
                            <!--        <th>Upload Date</th>-->
                            <!--    </tr>-->
                            <!--</tfoot>-->
                        </table>
                    </div>
                </div>
                <div class="col-sm-4">
                    <h5 class="mt-3 mb-3">ASSIGN TO:</h5>
                    <?php
                    $sql = "SELECT users.* , sum(assignments.no_of_record) as no_of_pending FROM users inner join role_user on role_user.user_id = users.id left join assignments on assignments.user_id = users.id and assignments.assignment_status_id = 1  WHERE role_user.role_id IN ('2','3') group by users.id";
                    $result = $conn->query($sql);
                    while($row = $result->fetch_assoc()) {
                        ?> 
                        <div class="card mb-3">
                            <div class="card-body">
                                <div class="card-text pull-left">
                                    <img src="../images/user.png" class="rounded-circle border mr-3" alt="Cinque Terre" width="36"> 
                                    <strong><?php echo $row["name"]; ?></strong> 
                                    <span class="badge badge-info "><?php echo  $row["no_of_pending"]; ?></span>
                                </div>
                                <div class="card-link pull-right" style="margin-top: 6px;">
                                    <input type="radio" class=""   name="operator_id" value="<?php echo $row["id"] ; ?>"  >
                              </div>
                            </div>
                        </div>
                        <?php
                    }
                    ?>
                    <div class="text-right">
                        <input class="btn btn-primary" type="submit" name="save" value="Assign" />
                    </div>
                    
                </div>
            </div>
        </form>
    </div>
</div>

<?php
// // assuming file.zip is in the same directory as the executing script.
// $file = '359939.zip';

// // get the absolute path to $file
// echo $path = pathinfo(realpath($file), PATHINFO_DIRNAME).'/360893';

// $zip = new ZipArchive;
// $res = $zip->open($file);
// if ($res === TRUE) {
//   // extract it to the path we determined above
//   $zip->extractTo($path);
//   $zip->close();
//   echo "WOOT! $file extracted to $path";
// } else {
//   echo "Doh! I couldn't open $file";
// }
?>
<script>
    $(document).ready(function(){
        
        $(".total_count").html("[<?php echo $total ?>]");
        
        $(".chk_doc_no").change(function() {
            var total = 0 ;
            $("input[name='doc_no[]']:checked").each(function () {
                total = total + parseInt($(this).attr("file_count"));
            });
            $(".checked_count").html(total); 
        });
        
    });
</script>
<?php 

$conn->close();


//include 'admin_footer.php';
?>