<?php
include('../../includes/checkSession.php');
include('../../includes/con2pma3.php');
include('../includes/header_in.php');
?>

<?php $DID = isset($_GET['did']) ? $_GET['did'] : 0; ?>
<?php
$cid = $_SESSION['id'];


$result = mysql_query("SELECT dwg.*,p.projectName,p.projectCode,d.discipline_name, d.discipline_code FROM 
                 scope_dwg dwg
                 LEFT OUTER JOIN projects p ON (dwg.dwgProject =p.projectSerial )
                 LEFT OUTER JOIN discipline d ON (d.discipline_id = dwg.discipline_id)
                 where  dwg.dwgID='$DID' AND dwg.dwgStatus='1' ");
$row = mysql_fetch_array($result, MYSQL_ASSOC);
?>
<style>
    .editfield{display:none}
    .pheadin-txt .panel-numbering,.pheadin-txt .htitle {font-size:14px; font-weight:bold}
    .whead{    padding: 4px 0 8px 0;}
    .panel-edit a{margin-right:7px}
    .panel-edit span{margin-left:7px}
    .panel-edit{text-align:right}
    .panel-detail{padding:0 !important}
    .action{text-align:right}
    select{height:27px !important}
    .submitbtn{
        background: transparent;
        border: 0 !important;
        color: #3a70ab;
    }
    .heading{

        padding: 10px 15px;
        color: #FFF !important;
        background: #3a70ab !important;
        background: -moz-linear-gradient(top, #5ba5cb 0%, #3a70ab 100%) !important;
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#5ba5cb), color-stop(100%, #3a70ab)) !important;
        background: -webkit-linear-gradient(top, #5ba5cb 0%, #3a70ab 100%) !important;
        background: -o-linear-gradient(top, #5ba5cb 0%, #3a70ab 100%) !important;
        background: -ms-linear-gradient(top, #5ba5cb 0%, #3a70ab 100%) !important;
        background: linear-gradient(to bottom, #5ba5cb 0%, #3a70ab 100%) !important;
    }
    .es{display:none}
</style>
<section class="content">
    <div class="container">
        <div class="row">
            <div class="main-content">
                <h5>
                    <?php if (isset($_REQUEST["msg"])) { ?>
                        <?php echo $_REQUEST["msg"]; ?>
                    <?php } ?>
                </h5>
                <div class="widget">
                    <div class="whead"> <h6> <i class="fa fa-play-circle"></i>DRAWING DETAIL</h6>   </div>

                    <form enctype="multipart/form-data" style="overflow:hidden">

                        <div class="formRow fRow">
                            <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Project Name:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
                                <?php echo $row["projectName"]; ?>
                            </div>

                            <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Design Completion:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
                                <?php echo $row['dwgcomplePercent']; ?>
                            </div>
                            <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Type:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
                                <?php echo $row['dwgType']; ?>
                            </div>

                        </div>

                        <div class="formRow fRow">
                            <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>No of Dwgs:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
                                <?php echo $row["no_of_dwgs"]; ?>
                            </div>

                            <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Range from:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
                                <?php echo $row["range_from"]; ?>
                            </div>
                            <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Range to:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
                                <?php echo $row["range_to"]; ?>
                            </div>

                        </div>
                        <div class="formRow fRow">
                            <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Dwg Type:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
                                <?php echo $row["dwg_type"]; ?>
                            </div>

                            <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Dwg Suffix:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
                                <?php echo $row["dwg_suffix"]; ?>
                            </div>
                            <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Discipline:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
                                <?php echo $row["discipline_name"]; ?>
                            </div>

                        </div>
                        <div class="formRow fRow">
                            <div class="col-sm-1-8 docdetail-label" style="padding-right:0px;">

                                <label>Notes:</label></div>

                            <div class="col-sm-2-2 docdetail-field" style="padding-left:0px;">
                                <?php echo $row["dwgNotes"]; ?>
                            </div>




                        </div>
                    </form>

                </div>

                <div class="clear"></div>

                <div class="widget">
                    <div class="whead"> <h6> <i class="fa fa-play-circle"></i>Drawing control list for Project</h6>   </div>
                    <div class="formRow fRow" style="padding:0 !important">

                        <div class="col-md-12" style="padding-left:0 !important;padding-right:0 !important;">
                            <div class="col-md-1 heading" style="width:4% !important">#</div>
                            <div class="col-md-1 heading" style="width:10% !important">Project Code</div> 
                            <div class="col-md-1 heading">Discipline</div>
                            <div class="col-md-2 heading">DWG No/ Sheet No/ Rev No</div>
                            <div class="col-md-4 heading">DWG Title</div>
                            <div class="col-md-2 heading">Attachment</div>
                            <div class="col-md-1 actions heading" style="width:11% !important">Actions</div>
                        </div>

                    </div>
                    <?php
                    ?>
                    <?php
                    $reserved_sheets = array();
                    $reserved_rev = array();
                    $query = "SELECT * FROM scope_dwg_revisions WHERE dwg_id =$DID";
                    $result = mysql_query($query);
                    while ($rr = mysql_fetch_array($result)) {
                        array_push($reserved_sheets, $rr['sheet_no']);

                        array_push($reserved_rev, $rr['rev_no']);
                    }

                    for ($i = $row['range_from']; $i <= $row['range_to']; $i++) {
                        ?>
                        <?php
                        $query = "SELECT * FROM scope_dwg_revisions WHERE dwg_id =$DID AND range_no=$i";
                        $result = mysql_query($query);
                        $rew = mysql_fetch_object($result);

                        if ($rew) {
                            ?>
                            <div class="formRow fRow" style="padding-left:0 !important;padding-right:0 !important;">
                                <form enctype="multipart/form-data" style="overflow:hidden" method="post" action="../../DB/03-scope/DWG2DB.php" 
                                      onsubmit="return validatefield('dwg_title<?php echo $i ?>', 'dwgrevision<?php echo $i ?>', 'dwgsheet<?php echo $i ?>')">
                                    <input type="hidden" name="dwg_id"  value="<?php echo $DID ?>">
                                    <input type="hidden" name="recordID"  value="<?php echo $rew->id ?>">
                                    <input type="hidden" name="range_no" id="range_no<?php echo $i ?>" value="<?php echo $i ?>">
                                    <input type="hidden" name="task"  value="update">
                                    <div class="col-md-12" style="padding-left:0 !important;padding-right:0 !important;">
                                        <div class="col-md-1" style="width:4% !important"><?php echo $i; ?></div>
                                        
                                        <div class="rs read_section<?php echo $i ?>">
                                        <div class="col-md-1" style="width:10% !important">
                                            
                                                <?php echo $row['projectCode'] ?> 
                                        </div>
                                        <div class="col-md-1">
                                            
                                                <?php echo $row['discipline_code']; ?> 
                                        </div>
                                        <div class="col-md-2">
                                            
                                                <?php echo $row['dwg_suffix'] . $i . " - " . str_pad($rew->sheet_no, 3, '0', STR_PAD_LEFT) . "-" . str_pad($rew->rev_no, 3, '0', STR_PAD_LEFT); ?> 
                                        </div>

                                        </div>
                                        <!--column read end-->
                                            <div class="es edit_section<?php echo $i ?>">
                                                <div class="col-md-1" style="width:10% !important">
                                            
														<?php echo $row['projectCode'] ?> 
                                                </div>
                                                <div class="col-md-1">
                                                    
                                                        <?php echo $row['discipline_code']; ?> 
                                                </div>
                                        <div class="col-md-2">
                                         <?php echo $row['dwg_suffix'] . $i . " - "; ?>
                                                <select name="dwgsheet"  id="dwgsheet<?php echo $i ?>">
                                                    <option value="">--</option>
                                                    <?php for ($k = 1; $k <= 30; $k++) { ?>
                                                        <?php if (false === array_search($k, $reserved_sheets) || $rew->sheet_no == $k) { ?>

                                                            <option value="<?php echo str_pad($k, 3, '0', STR_PAD_LEFT) ?>" <?php
                                                            if ($rew->sheet_no == str_pad($k, 3, '0', STR_PAD_LEFT)) {
                                                                echo "selected";
                                                            }
                                                            ?>><?php echo str_pad($k, 3, '0', STR_PAD_LEFT) ?></option>
                                                                <?php }
                                                            }
                                                            ?>


                                                </select>-<select name="dwgrevision"  id="dwgrevision<?php echo $i ?>">
                                                    <option value="">--</option>
                                                    <?php for ($j = 1; $j <= 10; $j++) { ?>

                                                        <?php if (false === array_search($j, $reserved_rev) || $rew->rev_no == $j) { ?>
                                                            <option value="<?php echo str_pad($j, 3, '0', STR_PAD_LEFT) ?>" <?php
                                                            if ($rew->rev_no == str_pad($j, 3, '0', STR_PAD_LEFT)) {
                                                                echo "selected";
                                                            }
                                                            ?>><?php echo str_pad($j, 3, '0', STR_PAD_LEFT) ?></option>
                                                                <?php }
                                                            }
                                                            ?>
                                                </select>
                                                </div>
                                            </div>
                                        
                                        <div class="col-md-4"> 
                                            <span class="rs read_section<?php echo $i ?>"><?php echo $rew->dwg_title ?> </span>
                                            <span class="es edit_section<?php echo $i ?>">
                                                <input type="text" class=" form-control" name="dwg_title" id="dwg_title<?php echo $i ?>" value="<?php echo $rew->dwg_title ?>">
                                            </span>
                                        </div>
                                        <div class="col-md-2">
                                            <input type="hidden" name="old_filename"  value="<?php echo $rew->attachment ?>">
        <?php if ($rew->attachment != "") { ?>
                                                <a href="../../uploads/<?php echo $rew->attachment ?>" target="_blank" ><?php echo $rew->attachment ?></a> <?php } ?>
                <!--<input type='file' name='attachment' >-->
                                        </div>
                                        <div class="col-md-1 actions" style="width:11% !important">
                                            <a href="javascript:void(0)" class="rs read_section<?php echo $i ?>" onclick="ShowEditSection(<?php echo $i ?>)">Edit&nbsp;|</a>
                                            <a class="es edit_section<?php echo $i ?>" href="javascript:void(0)" data-toggle="modal" data-target="#myModal<?php echo $i ?>">Upload&nbsp;|</a>
                                            <a href="javascript:void(0)" class="es edit_section<?php echo $i ?>" onclick="showreadsection(<?php echo $i ?>)">&nbsp;Cancel</a> 
                                             <a class="rs read_section<?php echo $i ?> submitbtn"  href="../../DB/03-scope/DWG2DB.php?dwgID=<?php echo $DID ?>&del=<?php echo $rew->id ?>">&nbsp;Delete</a></div>
                                    </div>

                                    <div class="modal fade" id="myModal<?php echo $i ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                        <div class="modal-dialog" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                    <h4 class="modal-title" id="myModalLabel">Upload Attachment</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <input type='file' name='attachment' >
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                    <button type="submit" class="btn btn-primary">Upload & Save</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>


                            <?php
                        } else {
                            ?>
                            <div class="formRow fRow" style="padding-left:0 !important;padding-right:0 !important;">
                                <form enctype="multipart/form-data" style="overflow:hidden" method="post" action="../../DB/03-scope/DWG2DB.php" onsubmit="return validatefield('dwg_title<?php echo $i ?>', 'dwgrevision<?php echo $i ?>', 'dwgsheet<?php echo $i ?>')">
                                    <input type="hidden" name="dwg_id"  value="<?php echo $DID ?>">
                                    <input type="hidden" name="task"  value="add">
                                    <input type="hidden" name="range_no" id="range_no<?php echo $i ?>" value="<?php echo $i ?>">
                                    <div class="col-md-12" style="padding-left:0 !important;padding-right:0 !important;">
                                        <div class="col-md-1" style="width:4%"><?php echo $i; ?></div>
                                        <div class="col-md-1" style="width:10% !important">
                                            
                                                <?php echo $row['projectCode'] ?> 
                                        </div>
                                        <div class="col-md-1">
                                            
                                                <?php echo $row['discipline_code']; ?> 
                                        </div>
                                        <div class="col-md-2">
                                        <?php echo $row['dwg_suffix'] . $i . " - "; ?>
                                            <select name="dwgsheet"  id="dwgsheet<?php echo $i ?>">
                                                <?php for ($k = 1; $k <= 30; $k++) { ?>
                                                    <?php if (false === array_search($k, $reserved_sheets)) { ?>
                                                        <option value="<?php echo str_pad($k, 3, '0', STR_PAD_LEFT) ?>"><?php echo str_pad($k, 3, '0', STR_PAD_LEFT) ?></option>
                                                        <?php
                                                    }
                                                }
                                                ?>
                                            </select>-<select name="dwgrevision"  id="dwgrevision<?php echo $i ?>">
                                                <?php for ($j = 1; $j <= 10; $j++) { ?>
                                                    <?php if (false === array_search($j, $reserved_rev)) { ?>
                                                        <option value="<?php echo str_pad($j, 3, '0', STR_PAD_LEFT) ?>"><?php echo str_pad($j, 3, '0', STR_PAD_LEFT) ?></option>
                                                        <?php
                                                    }
                                                }
                                                ?>
                                            </select>

                                        </div>
                                        <div class="col-md-4"> <input type="text" class="form-control" value="" name="dwg_title" id="dwg_title<?php echo $i ?>"></div>
                                        <div class="col-md-2">
                                            <!--<input type='file' name='attachment' >-->
                                        </div>
                                        <div class="col-md-1 actions" style="width:11%">
                                            <a class="" href="javascript:void(0)" data-toggle="modal" data-target="#myModal<?php echo $i ?>">Upload</a></div>
                                    </div>
                                    <div class="modal fade" id="myModal<?php echo $i ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                        <div class="modal-dialog" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                    <h4 class="modal-title" id="myModalLabel">Upload Attachment</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <input type='file' name='attachment' >
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                    <button type="submit" class="btn btn-primary">Upload & Save</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <?php
                        }
                    }
                    ?>

                </div>


            </div>
        </div>
    </div>
</section>

<script>

    function submitForm(id) {
        $("#revform" + id).submit()

    }
    function nothing() {

    }
    function ShowEditSection(id) {
        $(".read_section" + id).hide();
        $(".edit_section" + id).show();
    }
    function showreadsection(id) {
        $(".edit_section" + id).hide();
        $(".read_section" + id).show();

    }
</script>

</body>
</html>
