<!DOCTYPE html>
<html>
<head>
  <title>ESRU Calibro</title>
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <link type="text/css" rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"/>
  <link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro"/>
  <link type="text/css" rel="stylesheet" href="../CSS/style.css"/>
  <script src="../JS/js_functions.js"></script>
  <?php
    $project_name = "";
	if(!empty($_GET["project_name"]))$project_name = $_GET["project_name"];
    if(isset($_POST["goback"]))header("location: projects.html?name={$project_name}&llns=none");
    require "UserAdmin/super_secret_stuff.php";
    $con = mysqli_connect($website,$mysqli_username,$pw,$dbase);
    $user_id = get_userid($con);

	$get_doit = "";
	if(!empty($_GET["doit"]))$get_doit = $_GET["doit"];
    if($get_doit == "yes"){
      $res = mysqli_query($con,"SELECT calproj_id,name FROM Calibro_projects WHERE shared_between LIKE '%,{$user_id},%'");
      while($row = mysqli_fetch_array($res)){
        $index = $row[0];
        mysqli_query($con,"UPDATE Calibro_projects SET name='{$_POST[$index]}' WHERE calproj_id = {$index}");
      }
      mysqli_close($con);
      header("location: projects.php");
    } // endif doit = yes
  ?>
</head>
<body>
  <div id="header_div_left" class="normal_text1">
	Edit model name(s)
  </div>
<div id="header_div_right"></div>
  <div id="body_div_left" class='normal_text2'>
    <form action="edit_model.php?doit=yes" method="post">
	<table>
      <?php
        $res = mysqli_query($con,"SELECT calproj_id,name FROM Calibro_projects WHERE shared_between LIKE '%,{$user_id},%'");
        while($row = mysqli_fetch_array($res)){
          echo ("<tr><td>");
          echo ("<input type='text' name='{$row[0]}' value='{$row[1]}'
          pattern='[a-zA-Z0-9.-\s]*'  maxlength='80' size='40' title='Only alphanumerics and . allowed' >");
          echo ("</td>");
          
          echo ("<td>");
		  echo "<a href='delete_model.php?id={$row[0]}' title='Delete model' style='float:right;'><i class='fa fa-minus'></i></a>";
          echo ("</td></tr>");
        }
        mysqli_close($con);
      ?>
      <tr><td>
        <button type='submit' title="Cancel" style='float:right;'><i class='fa fa-times'></i></button>
        <button type='submit' title="OK"     style='float:right;'><i class='fa fa-check'></i></button>
      </tr></td>
	</table>
    </form>
  </div>
</body>
</html>
