<?php

include('../../includes/checkSession.php');

include('../../includes/con2pma3.php');

include('../../includes/topmenunewest.php');


/*phpinfo();
die;*/
/*include('../includes/header_in.php');*/

/*include('../includes/topmenuin.php');*/

/*error_reporting(0);*/

$company_id = $_SESSION['id'];

$companyID = $company_id;
/*ini_set("upload_max_filesize", "50M");
ini_set("post_max_size", "51M");

ini_set("max_execution_time", "200");
ini_set("max_input_time", "200");
*/

?>



<html><head>

    <meta charset="utf-8">

    <title>pmAnywhere - Suggestions</title>

    <script src="../includes/js/jquery.min.js" type="text/javascript"></script>

<link href="03-00Scope-Styles0.css" rel="stylesheet" type="text/css" />

    <script scr='../includes/js/jquery-1.10.2.min.js' type="text/javascript"></script>

    <script>



        $(function () {

            $('#uploadForm').on("submit", function(){

                // get import type



                var importType = document.getElementById('WBStype').value;

                // 1 pm, 2 csv , 4 xer

                if(importType == 1 || importType == 2 ){

                    document.getElementById('uploadForm').action = '03-04Scope-01WBS01DB.php?import=true';

                    return true;

                }else if( importType == 4 ){

                    var max =  54525952; // 32MB
                //    var max =  33550000; // 32MB
                    var inputFile = document.getElementById('fileToUpload');
                    if (inputFile.files && inputFile.files[0].size > max) {
                       // alert("File sizes larger than 30MB cannot be uploaded. Please contact pmAnywhere for more information."); // Do your thing to handle the error.
                        alert("File sizes larger than 50MB cannot be uploaded. Please contact pmAnywhere for more information."); // Do your thing to handle the error.
                        inputFile.value = null; // Clear the field.
                        return false;
                    }else{
                        document.getElementById('uploadForm').action = 'uploadXER.php';

                        if(confirm('Levels greater than 5 will not be imported. Click OK to import.')){

                            return true;

                            // sumbit form

                        }else{

                            // nothing

                            document.getElementById('uploadForm').action = '';

                            return false;

                        }
                    }

                }



            });

        });

        function ImportWBS(str)

        {





            if (str=="" || str=="3" || str=="-1")



            {



                document.getElementById("import").innerHTML="";



                $('#choose').hide();





                return;



            }



            if (window.XMLHttpRequest)



            {// code for IE7+, Firefox, Chrome, Opera, Safari







                xmlhttp=new XMLHttpRequest();



            }



            else



            {// code for IE6, IE5



                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");



            }



            xmlhttp.onreadystatechange=function()



            {



                if (xmlhttp.readyState==4 && xmlhttp.status==200)



                {



                    document.getElementById("import").style.display='';



                    $('#choose').show();

                    document.getElementById("import").innerHTML=xmlhttp.responseText;







                }



            }

            if (str=="1")



            {

                xmlhttp.open("GET","importPMWBSfield.php",true);

            }

            else if (str=="4")



            {

                xmlhttp.open("GET","importXERfield.php",true);

            }

            else

                xmlhttp.open("GET","importWBSfield.php",true);

            xmlhttp.send();







        }







    </script>

</head>



<body style="backgrond-color:#E8E8E8">



<script>



function saveWork(WID, fileName, msg) {

if(confirm('Note: These suggestions will be added to your active lists and might cause duplication if you have something similar already active or archived. Click OK to proceed.')){

    url = "saveXER.php";

    $.ajax({

        url: url,

        type: 'POST',

        data: {WID:WID,fileName:fileName},

        success: function (data) {

            if (data == 0) {

                if( msg == 1)

                alert('File Imported Successfully.');

                else if( msg == 2 )

                    alert('File Imported Successfully. Imports are done up to 5 levels only.');

                window.location.href = "03-04Scope-01WBS01.php?msg=File Imported";

            }



            else {

                alert('Something went wrong.');

            }

        },

        error: function (e) {



        }

    });

}

}





</script>





<?php// if( @$_REQUEST['msg'] == 1 ){?>

    <script>

      //  alert("File Imported Successfully.");

    </script>

<?php  //} else if(@$_REQUEST['msg'] == 2) {?>

    <script>

       // alert("File Imported Successfully. Imports are done up to 5 levels only.");

    </script>

<?php  /*} else*/ if(@$_REQUEST['msg'] == 3) {?>

    <script>

        alert("Error Uploading File.");

    </script>

<?php }elseif(@$_REQUEST['msg'] == 4) {?>

    <script>

        alert("Form is not posted.");

    </script>

<?php }
    ?>



<div><br></div>







  <!--<input id="import" name="import" value="1" type="hidden" />-->

  <fieldset>

  <legend align="center">

  <button class="button1" >&nbsp;IMPORT FROM A FILE&nbsp;</button></legend>

  

 <?php



if(isset( $_REQUEST['WID'])) {

    $WID = $_REQUEST['WID'];

}

$resultWBSname = mysql_query("SELECT WBSList_code,WBSList_title FROM wbslist where WBSList_id='$WID'");

$rowWBSname = mysql_fetch_array($resultWBSname, MYSQL_ASSOC);

?>

<?php



if(!isset( $_REQUEST['companyID'])) {?>

<form id="uploadForm" align="center" action="" method="post"  enctype="multipart/form-data">



    <table name="importsuggestions" align="center" class="table4" width="80%" border="0" cellpadding="0">

        <tr>

          <td align="left" >

                <select name="WBStype" class="ablks1" id="WBStype"  onchange="ImportWBS(this.value)" required style="width:100% !important">

                    <option value="">Select</option>

                    <option value="1">Import from PManywhere</option>

                    <option value="2">Import from my CSV file</option>

                    <option value="4">Import from my XER file</option>

                </select>

            </td>
        </tr>
	<tr>
     <td style="width:100% !important" align="left" id="import"></td>
    </tr>






    <input type="hidden" name="WID" id="WID" value="<?php echo $WID; ?>">

    <input type="hidden" name="companyID" id="companyID" value="<?php echo $companyID; ?>">

   <!-- <input type="file" required name="fileToUpload" accept=".xer" id="fileToUpload"><br><br>-->


    <tr>

        <td style="width:100% !important">

        <input type="submit" value="Upload" name="submit" style="width:100% !important">

        </td>

    </tr>

    </table>

</form><br>

</fieldset>

<br>



<?php } else { $companyID = $_REQUEST['companyID']; }?>



<form style="<?php if(!isset($_REQUEST['msg'])) echo 'display:none;'; ?>" align="center" id="form1" method="post" <?php if($companyID == 261) { ?>action="03-04Scope-01WBS01-IV01DB.php?WID=239&companyID=261&WIDO=<?php if(isset($_REQUEST['WIDO'])) echo $_REQUEST['WIDO']; ?>" <?php } else { ?> action="saveXER.php" <?php } ?> >

   

  

<table name="importsuggestions" align="center" class="table4" width="80%" border="0" cellpadding="0">

    <tr>

      <td colspan="5" align="left" valign="top"><strong>GWBS Code:<?php echo $rowWBSname['WBSList_code']; ?></strong></td>

      <td align="right" valign="top"><!--<a href="03-04Scope-01WBS01-IV01.php?WID=239&companyID=261&WIDO=<?php /*if(isset($_REQUEST['WIDO'])) echo $_REQUEST['WIDO']; else

          echo $WID;*/?> "></a>--></td>

    </tr>

    <tr>

      <td colspan="6" align="left" valign="top"><strong>GWBS Name: <?php echo $rowWBSname['WBSList_title']; ?></strong></td>

      </tr>

    <tr>

      <td colspan="6" align="left" valign="top">&nbsp;</td>

      </tr>









    <tr>

      <td width="10%" align="left" valign="top"><strong>CODE</strong></td>

      <td width="20%" align="left" valign="top"><strong>MWBS</strong></td>

      <td width="10%" align="left" valign="top"><strong>CODE</strong></td>

      <td width="30%" align="left" valign="top"><strong>WBS ELEMENTS</strong></td>

      <td width="10%" align="left" valign="top"><strong>CODES</strong></td>

      <td width="30%" align="left" valign="top"><strong>ACTIVITIES (ITEMS/ SUBITEMS)</strong></td>

      </tr>

    <?php



    $result1 = mysql_query("SELECT * FROM globalwbs where gwbslist_id ='$WID' && companyID = '-1' && parent=0 

                                  ORDER BY WBSIDA ASC,WBSIDA ASC,WBSIDB ASC,WBSIDC ASC,WBSIDD ASC,WBSIDE ASC");

    //echo"load";

    while($row1 = mysql_fetch_array($result1 , MYSQL_ASSOC))

    {



    $WBSIDA1 = $row1["WBSIDA"];

    $WBSIDB1 = $row1["WBSIDB"];

    $WBSIDC1 = $row1["WBSIDC"];

    $WBSIDD1 = $row1["WBSIDD"];

    $WBSIDE1 = $row1["WBSIDE"];

    $WBSID1 = $row1["WBSID"];







    ?>







<!------------------------Level 1 WBS------------>

    <tr>

      <td align="left" valign="top"><?php echo $WBSIDA1.".".$WBSIDB1.".".$WBSIDC1.".".$WBSIDD1.".".$WBSIDE1; ?></td>

      <td align="left" valign="top">&nbsp<?php echo $row1['description']; ?></td>

      <td align="left" valign="top">&nbsp;</td>

      <td align="left" valign="top">&nbsp;</td>

      <td align="left" valign="top">&nbsp;</td>

      <td align="left" valign="top">&nbsp;</td>

    </tr>

        <!----------------Level 1 Items/Sub-Items----------->

        <?php

        $result11 = mysql_query("SELECT * FROM globalitems where WBSID ='$WBSID1' && companyID = '$companyID'  ORDER BY itemID");

        //echo"load";

        while($row11 = mysql_fetch_array($result11 , MYSQL_ASSOC)) {



            $itemID1 = $row11["itemID"];

            ?>

            <tr>



                <td align="left" valign="top">&nbsp;</td>

                <td align="left" valign="top">&nbsp;</td>

                <td align="left" valign="top">&nbsp;</td>

                <td align="left" valign="top">&nbsp;</td>

                <td align="left"

                    valign="top"><?php echo $WBSIDA1 . "." . $WBSIDB1 . "." . $WBSIDC1 . "." . $WBSIDD1 . "." . $WBSIDE1 . ".".$itemID1; ?></td>

                <td align="left" valign="top">&nbsp<?php echo $row11['description']; ?></td>

            </tr>



            <?php

        }

        // ------------------------------ Level 2 WBS-----------------

    $result2 = mysql_query("SELECT * FROM globalwbs where gwbslist_id ='$WID' && companyID = '-1' && parent='$WBSID1' ORDER BY WBSIDA ASC,WBSIDA ASC,WBSIDB ASC,WBSIDC ASC,WBSIDD ASC,WBSIDE ASC");

    //echo"load";

    while($row2 = mysql_fetch_array($result2 , MYSQL_ASSOC)) {



        $WBSIDA2 = $row2["WBSIDA"];

        $WBSIDB2 = $row2["WBSIDB"];

        $WBSIDC2 = $row2["WBSIDC"];

        $WBSIDD2 = $row2["WBSIDD"];

        $WBSIDE2 = $row2["WBSIDE"];

        $WBSID2 = $row2["WBSID"];

?>

    <tr>



    <td align="left" valign="top">&nbsp;</td>

    <td align="left" valign="top">&nbsp;</td>

        <td align="left" valign="top"><?php echo $WBSIDA2.".".$WBSIDB2.".".$WBSIDC2.".".$WBSIDD2.".".$WBSIDE2; ?></td>

        <td align="left" valign="top">&nbsp<?php echo $row2['description']; ?></td>

    <td align="left" valign="top">&nbsp;</td>

    <td align="left" valign="top">&nbsp;</td>

    </tr>



        <!----------------Level 2 Items/Sub-Items----------->

        <?php

        $result22 = mysql_query("SELECT * FROM globalitems where WBSID ='$WBSID2' && companyID = '$companyID'  ORDER BY itemID");

        //echo"load";

        while($row22 = mysql_fetch_array($result22 , MYSQL_ASSOC)) {



            $itemID2 = $row22["itemID"];

            ?>

            <tr>



                <td align="left" valign="top">&nbsp;</td>

                <td align="left" valign="top">&nbsp;</td>

                <td align="left" valign="top">&nbsp;</td>

                <td align="left" valign="top">&nbsp;</td>

                <td align="left"

                    valign="top"><?php echo $WBSIDA2 . "." . $WBSIDB2 . "." . $WBSIDC2 . "." . $WBSIDD2 . "." . $WBSIDE2 . ".".$itemID2; ?></td>

                <td align="left" valign="top">&nbsp<?php echo $row22['description']; ?></td>

            </tr>



            <?php

        }?>









        <!---------------------------- Level 3 WBS ------>

        <?php



        $result3 = mysql_query("SELECT * FROM globalwbs where gwbslist_id ='$WID' && companyID = '-1' && parent='$WBSID2' ORDER BY WBSIDA ASC,WBSIDA ASC,WBSIDB ASC,WBSIDC ASC,WBSIDD ASC,WBSIDE ASC");

        //echo"load";

        while($row3 = mysql_fetch_array($result3 , MYSQL_ASSOC)) {



            $WBSIDA3 = $row3["WBSIDA"];

            $WBSIDB3 = $row3["WBSIDB"];

            $WBSIDC3 = $row3["WBSIDC"];

            $WBSIDD3 = $row3["WBSIDD"];

            $WBSIDE3 = $row3["WBSIDE"];

            $WBSID3 = $row3["WBSID"];

            ?>

            <tr>



                <td align="left" valign="top">&nbsp;</td>

                <td align="left" valign="top">&nbsp;</td>

                <td align="left" valign="top" style="padding-left: 13px"><?php echo $WBSIDA3.".".$WBSIDB3.".".$WBSIDC3.".".$WBSIDD3.".".$WBSIDE3; ?></td>

                <td align="left" valign="top" style="padding-left: 13px">&nbsp;<?php echo $row3['description']; ?></td>

                <td align="left" valign="top">&nbsp;</td>

                <td align="left" valign="top">&nbsp;</td>

            </tr>



            <!----------------Level 3 Items/Sub-Items----------->

            <?php

            $result33 = mysql_query("SELECT * FROM globalitems where WBSID ='$WBSID3' && companyID = '$companyID'  ORDER BY itemID");

            //echo"load";

            while($row33 = mysql_fetch_array($result33 , MYSQL_ASSOC)) {



                $itemID3 = $row33["itemID"];

                ?>

                <tr>



                    <td align="left" valign="top">&nbsp;</td>

                    <td align="left" valign="top">&nbsp;</td>

                    <td align="left" valign="top">&nbsp;</td>

                    <td align="left" valign="top">&nbsp;</td>

                    <td align="left"

                        valign="top"><?php echo $WBSIDA3 . "." . $WBSIDB3 . "." . $WBSIDC3 . "." . $WBSIDD3 . "." . $WBSIDE3 . ".".$itemID3; ?></td>

                    <td align="left" valign="top">&nbsp<?php echo $row33['description']; ?></td>

                </tr>



                <?php

            }?>















            <!---------------------------- Level 4 WBS ------>

            <?php



            $result4 = mysql_query("SELECT * FROM globalwbs where gwbslist_id ='$WID' && companyID = '-1' && parent='$WBSID3' ORDER BY WBSIDA ASC,WBSIDA ASC,WBSIDB ASC,WBSIDC ASC,WBSIDD ASC,WBSIDE ASC");

            //echo"load";

            while($row4 = mysql_fetch_array($result4 , MYSQL_ASSOC)) {



                $WBSIDA4 = $row4["WBSIDA"];

                $WBSIDB4 = $row4["WBSIDB"];

                $WBSIDC4 = $row4["WBSIDC"];

                $WBSIDD4 = $row4["WBSIDD"];

                $WBSIDE4 = $row4["WBSIDE"];

                $WBSID4 = $row4["WBSID"];

                ?>

                <tr>



                    <td align="left" valign="top">&nbsp;</td>

                    <td align="left" valign="top">&nbsp;</td>

                    <td align="left" valign="top" style="padding-left: 23px"><?php echo $WBSIDA4.".".$WBSIDB4.".".$WBSIDC4.".".$WBSIDD4.".".$WBSIDE4; ?></td>

                    <td align="left" valign="top" style="padding-left: 23px">&nbsp;<?php echo $row4['description']; ?></td>

                    <td align="left" valign="top">&nbsp;</td>

                    <td align="left" valign="top">&nbsp;</td>

                </tr>



                <!----------------Level 4 Items/Sub-Items----------->

                <?php

                $result44 = mysql_query("SELECT * FROM globalitems where WBSID ='$WBSID4' && companyID = '$companyID'  ORDER BY itemID");

                //echo"load";

                while($row44 = mysql_fetch_array($result44 , MYSQL_ASSOC)) {



                    $itemID4 = $row44["itemID"];

                    ?>

                    <tr>



                        <td align="left" valign="top">&nbsp;</td>

                        <td align="left" valign="top">&nbsp;</td>

                        <td align="left" valign="top">&nbsp;</td>

                        <td align="left" valign="top">&nbsp;</td>

                        <td align="left"

                            valign="top"><?php echo $WBSIDA4 . "." . $WBSIDB4 . "." . $WBSIDC4 . "." . $WBSIDD4 . "." . $WBSIDE4 . ".".$itemID4; ?></td>

                        <td align="left" valign="top">&nbsp<?php echo $row44['description']; ?></td>

                    </tr>



                    <?php

                }?>









                <!-----********************--->





                <!---------------------------- Level 5 WBS ------>

                <?php



                $result5 = mysql_query("SELECT * FROM globalwbs where gwbslist_id ='$WID' && companyID = '-1' && parent='$WBSID4' ORDER BY WBSIDA ASC,WBSIDA ASC,WBSIDB ASC,WBSIDC ASC,WBSIDD ASC,WBSIDE ASC");

                //echo"load";

                while($row5 = mysql_fetch_array($result5 , MYSQL_ASSOC)) {



                    $WBSIDA5 = $row5["WBSIDA"];

                    $WBSIDB5 = $row5["WBSIDB"];

                    $WBSIDC5 = $row5["WBSIDC"];

                    $WBSIDD5 = $row5["WBSIDD"];

                    $WBSIDE5 = $row5["WBSIDE"];

                    $WBSID5 = $row5["WBSID"];

                    ?>

                    <tr>



                        <td align="left" valign="top">&nbsp;</td>

                        <td align="left" valign="top">&nbsp;</td>

                        <td align="left" valign="top" style="padding-left: 33px"><?php echo $WBSIDA5.".".$WBSIDB5.".".$WBSIDC5.".".$WBSIDD5.".".$WBSIDE5; ?></td>

                        <td align="left" valign="top" style="padding-left: 33px">&nbsp;<?php echo $row5['description']; ?></td>

                        <td align="left" valign="top">&nbsp;</td>

                        <td align="left" valign="top">&nbsp;</td>

                    </tr>



                    <!----------------Level 5 Items/Sub-Items----------->

                    <?php

                    $result55 = mysql_query("SELECT * FROM globalitems where WBSID ='$WBSID5' && companyID = '$companyID'  ORDER BY itemID");

                    //echo"load";

                    while($row55 = mysql_fetch_array($result55 , MYSQL_ASSOC)) {



                        $itemID5 = $row55["itemID"];

                        ?>

                        <tr>



                            <td align="left" valign="top">&nbsp;</td>

                            <td align="left" valign="top">&nbsp;</td>

                            <td align="left" valign="top">&nbsp;</td>

                            <td align="left" valign="top">&nbsp;</td>

                            <td align="left"

                                valign="top"><?php echo $WBSIDA5 . "." . $WBSIDB5 . "." . $WBSIDC5 . "." . $WBSIDD5 . "." . $WBSIDE5 . ".".$itemID5; ?></td>

                            <td align="left" valign="top">&nbsp<?php echo $row55['description']; ?></td>

                        </tr>



                        <?php

                    }?>





                <?php  }



                ?>

                <!-- Level 5 End -->









                <!-----********************--->















            <?php  }



            ?>

            <!-- Level 4 End -->













        <?php  }



        ?>

        <!-- Level 3 End -->



  <?php  }



        ?>



    <tr>



        <td align="left" valign="top">&nbsp;</td>

        <td align="left" valign="top">&nbsp;</td>

        <td align="left" valign="top">&nbsp;</td>

        <td align="left" valign="top">&nbsp;</td>

        <td align="left" valign="top">&nbsp;</td>

        <td align="left" valign="top">&nbsp;</td>

    </tr>







		<tr>

          <td align="left" valign="top"></td>

          <td align="left" valign="top"></td>

          <td align="left" valign="top"></td>

          <td align="left" valign="top">&nbsp;</td>

          <td align="left" valign="top">&nbsp;</td>

          <td align="left" valign="top"></td>

        </tr>





<?php } ?>



    <tr>

      <td align="left" valign="top">&nbsp;</td>

      <td align="right" valign="top">&nbsp;</td>

      <td align="right" valign="top">&nbsp;</td>

      <td align="right" valign="top">&nbsp;</td>

      <td align="right" valign="top">&nbsp;</td>

      <td align="right" valign="top">

          <button type="button" onClick="window.location='03-04Scope-01WBS01.php';" style="vertical-align: bottom" class="button11" title="Cancel">&#xab;</button>

        &nbsp;

        <a href="javascript:void(0)">

            <?php if(isset($_REQUEST['WIDO'])){ ?>

          <button type="submit" onClick="return confirm('Note: These suggestions will be added to your active lists and will not be added if you have something similar already active or archived. Click OK to proceed.');" style="vertical-align: bottom" id="btnImport" class="button11" title="Import">&#xbb;</button>

        <?php } else { ?>

            <button type="button"  style="vertical-align: bottom" id="btnImport" <?php if(isset($_REQUEST['msg'])) { if($_REQUEST['msg'] !=3 ) { $fileName = @$_REQUEST['fileName']; $msg= $_REQUEST['msg']; ?> onclick="saveWork(<?php echo $WID.',\''.$fileName.'\','.$msg; ?>)" <?php } } ?> class="button11" title="Import">&#xbb;</button>

            <?php } ?>

        </a>

        </td>

    </tr>

    </table>

<br>

<table width="80%" border="0" align="center" cellpadding="0" class="table4" name="importsuggestions">

  <tr>

    <td align="right" valign="top">(The imported entries from the file will be added to your existing entries and pmAnywhere is not responsible for any omissions/ errors/ damages/ mistakes or subsequent implications.) </td>

    </tr>

</table>

    

</form>



	<br>

</body>

</html>



