<?php
include("../../packages/require.php");
include("controller/controller_document.php");
$curpage = "po";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title><?=$title['po'];?></title>
    <?php include($global['root']."packages/head.php");?>
</head>
<body class="<?=$global['body-css'];?>">
    <div class="wrapper">

        <?php include($global['root']."section/header.php");?>

        <?php include($global['root']."section/sidebar.php");?>

        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
              <h1>
                Module Purchase Order
                <small>Track all your po here</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="<?=$path['dashboard'];?>"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Purchase Order</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- Default box -->
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">
                        Activity Purchase Order (<?=correctDisplay($data[0]['po_id']);?>)
                        <?php if($data[0]['po_status'] == 'open'){ ?>
                        <span class="label label-info">Open</span>
                        <?php } else if($data[0]['po_status'] == 'progress'){ ?>
                        <span class="label label-warning">In Progress</span>
                        <?php } else if($data[0]['po_status'] == 'prepared'){ ?>
                        <span class="label label-primary">Prepared</span>
                        <?php } else if($data[0]['po_status'] == 'complete'){ ?>
                        <span class="label label-success">Completed</span>
                        <?php } else { ?>
                        <span class="label label-danger">Canceled</span>
                        <?php } ?>
                    </h3>
                </div>
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li>
                            <a href="<?=$path['po-detail'].$O_po.'/';?>">Preview Purchase Order</a>
                        </li>
                        <?php if($acsp_edit == 1){ ?>
                        <?php if($data[0]['po_status'] == 'open'){ ?>
                        <li>
                            <a href="<?=$path['po-edit'].$O_po.'/';?>">Edit Purchase Order</a>
                        </li>
                        <?php } ?>
                        <?php } ?>
                        <?php if($acsp_viewact == 1){ ?>
                        <li>
                            <a href="<?=$path['po-activity'].$O_po.'/';?>">Activity</a>
                        </li>
                        <?php } ?>
                        <?php if($acsp_document == 1){ ?>
                        <?php if($data[0]['po_status'] != 'open' && $data[0]['po_status'] != 'prepared' && $data[0]['po_status'] != 'cancel'){ ?>
                        <li class="active">
                            <a href="<?=$path['po-document'].$O_po.'/';?>">Document</a>
                        </li>
                        <?php } ?>
                        <?php } ?>
                    </ul>
                </div>
                <div class="box-body">
                    <div class="head-btn text-right">
                        <a href="#modalUpload" data-toggle="modal"  data-target="#modalUpload" class="btn btn-success full-xs xs-down10">
                            <i class="fa fa-plus"></i> Upload New Document
                        </a>
                        <input type="hidden" id="input-pageurl" value="<?=$path['po-document'];?>">
                        <input type="hidden" id="input-poid" value="<?=$O_po;?>">
                    </div>
                    <div class="order-item">
                        <div class="table-responsive table-click">
                            <table class="table table-bordered table-middle">
                                <thead>
                                    <tr>
                                        <th class="text-center">No</th>
                                        <th class="text-center">File Name</th>
                                        <th class="text-center">Format</th>
                                        <th class="text-center">File</th>
                                        <th class="text-center">Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if(is_array($documents)){ ?>
                                    <?php 
                                    $num=1;
                                    foreach($documents as $docs){ 
                                    $ext=pathinfo($global['absolute-url'].$docs['document_file'], PATHINFO_EXTENSION);
                                    ?>
                                    <tr>
                                        <td class='text-center'><?=$num;?></td>
                                        <td class='text-center'><?=correctDisplay($docs['document_title']);?></td>
                                        <td class='text-center' style="text-transform: uppercase;"><?=$ext;?></td>
                                        <td class='text-center'>
                                            <div class="btn-group">
                                                <a href="<?=$global['absolute-url'].$docs['document_file'];?>" target="_blank" download="<?=correctDisplay($docs['document_title']);?>" class="btn bg-purple btn-xs"><i class="fa fa-download"></i> Download</a>
                                                <?php if($ext == "pdf" || $ext == "doc" || $ext == "docx"){ ?>
                                                <a href="<?=$global['absolute-url'].$docs['document_file'];?>" title="<?=correctDisplay($docs['document_title']);?>" class="btn bg-orange btn-xs fancyboxdoc">
                                                <?php } else { ?>
                                                <a href="<?=$global['absolute-url'].$docs['document_file'];?>" title="<?=correctDisplay($docs['document_title']);?>" class="btn bg-orange btn-xs fancybox">
                                                <?php } ?>
                                                    <i class="fa fa-search"></i> Preview
                                                </a>
                                            </div>
                                        </td>
                                        <td class='text-center'>
                                            <div class="btn-group">
                                                <a href="javascript:void(0);" onclick="confirmRemove('<?=$docs['document_id'];?>', '<?=correctDisplay($docs['document_title']);?>');" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> Delete</a>
                                            </div>
                                        </td>
                                    </tr> 
                                    <?php $num++;} ?>
                                    <?php } else { ?>
                                    <tr>
                                        <td colspan="5" class="text-center">Please upload document file.</td>
                                    </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="box-footer clearfix">
                    <div class="row">
                        <div class="col-sm-4 col-xs-6">
                            <div class="text-left">
                                <a href="<?=$path['po-detail'].$O_po.'/';?>" class="btn btn-default">
                                    <i class="fa fa-arrow-left"></i> Back
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->

<?php include($global['root']."section/footer.php");?>

</div>
<!-- ./wrapper -->

<!-- ./wrapper -->
<div id="modalUpload" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog madd-dialog" role="document">
        <div class="modal-content madd-content">
            <div class="modal-header madd-header">
                Upload New Document
            </div>
             <form id="form-create" action="<?=$path['po-document'].'?action=upload';?>" enctype="multipart/form-data" method="post" onsubmit="return validateFormDocument();">
                <div class="modal-body madd-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label for="input-filename">File Name *</label>
                                <input type="text" class="form-control" id="input-filename" name="filenames" value="" placeholder="file name">
                                <div id="error-filename" class="error-text"></div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label for="input-file">Upload File *</label>
                                <input type="file" class="form-control" id="input-file" value="" name="document" placeholder="Upload File">
                                <div id="error-file" class="error-text"></div>
                                <p class="help-block">File format has to be pdf, doc, docx, jpg, jpeg, png, gif and less than 10Mb.</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer madd-footer">
                    <div class="row">
                        <div class="col-sm-6 col-xs-6">
                            <div class="text-left">
                                <a href="#" data-dismiss="modal" class="btn btn-default">
                                    <i class="fa fa-arrow-left"></i> Cancel
                                </a>
                            </div>
                        </div>
                        <div class="col-sm-6 col-xs-6">
                            <div class="text-right">
                                <input type="hidden" name="po_id" value="<?=$O_po;?>">
                                <button id="btn-upload" class="btn btn-success" type="submit">
                                    <i class="fa fa-save"></i> Upload Document
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<?php include($global['root']."packages/footer.php");?>
<script type="text/javascript">
    $(document).ready(function() {
        <?php if(is_array($vmessage)){ ?>
        <?php $c=0; foreach($vmessage as $vm){ if($c > 0){ $time =  5000 + ($c*1000); } else { $time = 5000; } ?>
            var alertText = "<?=$vm;?>";
            <?php if($valert[$c] != "success"){ ?>
            errorAlertTimer(alertText,<?=$time;?>);// error alert
            <?php } else { ?>
            successAlertTimer(alertText,<?=$time;?>);// success alert
            <?php } ?>
        <?php $c++;} ?>
        <?php } ?>
    });
    $(function () {
      $('[data-toggle="tooltip"]').tooltip()
    });

</script>
<script src="<?=$global['absolute-url'];?>module/po/js/document.js?<?=mt_rand(10,1000);?>"></script>
</body>
</html>