<?php
   include('session.php');
   include('header1.php');

?>

<?php 


// start role specific 

$user_role = $_SESSION['role'];
$companyID = $_SESSION['companyselect'];

switch ($user_role) {

  case 1: // Admin Role

  break;


  default:

}

$updated = 0;

if(isset($_GET['updated'])) {

    $updated = $_GET['updated'];

  }

$sqlcompanyfile = "
        SELECT *
        FROM companyfile
        WHERE companyid = $companyID
        ";

$resultcompanyfile = mysqli_query($db,$sqlcompanyfile);

$countcompanyfile = mysqli_num_rows($resultcompanyfile);


?>


        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
          <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
            <h1 class="h2">Company Settings</h1>
            <div class="btn-toolbar mb-2 mb-md-0">
              <div class="btn-group mr-2">
              </div>
            </div>
          </div>

<?php 

if ($updated != 0) {

echo "<div class=\"alert alert-primary\" role=\"alert\">
  Company File Updated!
</div>";


}


if ($user_role == 1) {

if ($countcompanyfile != 0) {
  
  while ($rowcompanyfile = mysqli_fetch_array($resultcompanyfile)) { 

          echo "<form id=\"settingsform\" name=\"form\" method = \"POST\" action = \"inputcompanyfile.php\">
          <table class=\"table\">
              ";

      echo "<tbody>";
      echo "<tr>";
      echo "<input type=\"hidden\" name = \"existboolean\" value = \"existing\">";
      echo "<input type=\"hidden\" name = \"currentcompanyid\" value = \"" . $companyID . "\">";
      echo "<td>Company Name</td>";
      echo "<td><input type=\"text\" name = \"companyName\" value = \"" . $rowcompanyfile['companyName'] . "\"></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Company BRN</td>";
      echo "<td><input type=\"text\" name = \"companyBRN\" value = \"" . $rowcompanyfile['companyBRN'] . "\"></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Company ERN</td>";
      echo "<td><input type=\"text\" name = \"companyERN\" value = \"" . $rowcompanyfile['companyERN'] . "\"></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Company Address</td>";
      echo "<td><textarea name = \"companyAddress\" >" . $rowcompanyfile['companyAddress'] . "</textarea></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Accountant Name</td>";
      echo "<td><textarea name = \"accountantName\">" . $rowcompanyfile['accountantName'] . "</textarea></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Accountant Phone Number</td>";
      echo "<td><textarea name = \"accountantPNumber\">" . $rowcompanyfile['accountantPNumber'] . "</textarea></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Accountant Mobile Number</td>";
      echo "<td><textarea name = \"accountantMNumber\">" . $rowcompanyfile['accountantMNumber'] . "</textarea></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Accountant Email Address</td>";
      echo "<td><textarea name = \"accountantEmail\">" . $rowcompanyfile['accountantEmail'] . "</textarea></td>";
      echo "</tr>";
      

      echo "</tr>";

      echo "<tr><td><input type = \"submit\"></td></tr>";
        echo "
        </tbody></table></form>
              ";
  }

} else {
        echo "<table class=\"table\">
              <form id=\"settingsform\" name=\"form\" method = \"POST\" action = \"inputcompanyfile.php\">";

      echo "<tr>";
      echo "<input type=\"hidden\" name = \"existboolean\" value = \"new\">";
      echo "<td>Company Name</td>";
      echo "<td><input type=\"text\" name = \"companyName\"></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Company BRN</td>";
      echo "<td><input type=\"text\" name = \"companyBRN\"></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Company ERN</td>";
      echo "<td><input type=\"text\" name = \"companyERN\"></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Company Address</td>";
      echo "<td><textarea name = \"companyAddress\"></textarea></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Accountant Name</td>";
      echo "<td><textarea name = \"accountantName\"></textarea></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Accountant Phone Number</td>";
      echo "<td><textarea name = \"accountantPNumber\"></textarea></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Accountant Mobile Number</td>";
      echo "<td><textarea name = \"accountantMNumber\"></textarea></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Accountant Email Address</td>";
      echo "<td><textarea name = \"accountantEmail\"></textarea></td>";
      echo "</tr>";

      echo "<tr>";
      echo "<td>Company Logo</td>";

      echo "</tr>";

      echo "<tr><td><input type = \"submit\"></td></tr>";

        echo "</form>
              </table>";


}

echo "<br>";

echo "<h3>Company PRGF Values - <a href = \"addCompanyValue.php?companyID=$companyID\">Add Value</a></h3>";

$dqlGetCompanyValues = "
        SELECT *
        FROM valuesbycompany
        WHERE companyid = $companyID
        ORDER BY valueenddate DESC
        ";

$resultValuesByCompany = mysqli_query($db,$dqlGetCompanyValues);

$countValuesByCompany = mysqli_num_rows($resultValuesByCompany);

if ($countValuesByCompany != 0) {
  
  echo "<table class=\"table\">";
  echo "<thead><th>Value Name</th><th>Value</th><th>Effective Start Date</th><th>Effective End Date</th><th>Delete</th></thead>";
  echo "<tbody>";

  while ($rowValuesByCompany = mysqli_fetch_array($resultValuesByCompany)) { 

    echo "<tr>";
      echo "<td>";
        echo $rowValuesByCompany['valuename'];
      echo "</td>";
      echo "<td>";
        echo $rowValuesByCompany['value'];
      echo "</td>";
      echo "<td>";
        echo $rowValuesByCompany['valuestartdate'];
      echo "</td>";
      echo "<td>";
        echo $rowValuesByCompany['valueenddate'];
      echo "</td>";
      echo "<td>";
        echo "<a href=\"deleteValueCompany.php?valueid=" . $rowValuesByCompany['valueid'] . "\" onclick=\"javascript: return confirm('Please confirm deletion of value');\">Delete</a>";
      echo "</td>";

    echo "</tr>";

  }

  echo "</tbody>";
  echo "</table>";

    } else {
    echo "<p>No Values by Company saved yet.</p>";
  }



} else {
  echo "You have no permission to edit company settings. Please contact Administrator";
}
     ?>


        </main>
      </div>
    </div>

<?php
   include('footer1.php');
?>



