Location: PHPKode > projects > RepMan > repman/inc/cl.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>Clients management</title>
  <link rel="stylesheet" href="sc/style.css" type="text/css">
</head>
<body>
<br>
  <div id="menu">
    <?
      require ('inc/menu.php');

      ConnectIt();
    ?>
  </div>
<?
  	
  if(isset($_GET["new"]) && isLoggedIn()):
?>
  <h1>Add new client</h1>
  <form action="clients.php" method="post" accept="text/html" class="frm">
  <input type="hidden" name="insert" value="1">
  
  <div class="item">
    <label for="host">Hostname</label><br>
    <input type="text" name="host" maxlength="15">
  </div>  
  <input type="submit" value="add" class="item">
  
  </form>
<?
  elseif(isset($_GET["edit"]) && isset($_GET["cn"]) && isLoggedIn()):
    if ($cldata = Query("SELECT * FROM client WHERE id=".mysql_escape_string($_GET["cn"]).";")) {
      $cllist = $cldata[0];
?>
  <h1>Edit client</h1>
  <form action="clients.php" method="post" accept="text/html" class="frm">
  <input type="hidden" name="update" value="1">
  <input type="hidden" name="clindex" value="<? echo $_GET["cn"]; ?>">
  
  <div class="item">
    <label for="host">Hostname</label><br>
    <input type="text" name="host" maxlength="15" value="<? echo $cllist[1]; ?>">
  </div>  
  <input type="submit" value="add" class="item">
  
  </form>
<?
    } else {
      echo "<div class=\"info\"><p align=\"center\">I've problem with selecting client!!!!</p></div>\n";
    }
  else:
    if ((isset($_POST["insert"]) || isset($_POST["update"]))  && isLoggedIn()){
    	loginput($_POST["host"]);
    	$host = strtoupper(mysql_escape_string($_POST["host"]));
    	$h_ko = 0;
    	echo "<div class=\"info\"><p align=\"center\">";
      if ($host) { 
        $cdata = Query("SELECT name FROM client;");
        foreach ($cdata as $clist) {
          if ($host == $clist[0]) {
            $h_ko = 1;
            logdebug("!!!!! $host == $clist[0] !!!!!<br>");          
          } else {
            logdebug("$host != $clist[0]<br>");
          }
        }
        if ($h_ko) {
          echo "Host $host already exists.</div></p>\n";
          logdebug("Host $host already exists.");
        } else {
          logdebug("Host $host OK.<br>"); 
          if (isset($_POST["insert"])) {
            if (Query("INSERT INTO client(name) values('$host');")) {
              echo "Host $host successfully added into DB.<br>\n";
              if ($id=Query("SELECT id FROM client WHERE name='$host';")) {
                echo "$host's ID = ".$id[0][0].".</div></p>\n";
              } else {
                echo "Could not find $host's ID!!!</div></p>\n";
              }
            } else {
              echo "Some problem with adding host $host to database.</div></p>\n";
            }
          } else {
            if (Query("UPDATE client SET name='$host' WHERE id=".$_POST["clindex"].";")) {
              echo "Host $host was successfully updated.<br>\n";
              if ($id=Query("SELECT id FROM client WHERE name='$host';")) {
                echo "$host's ID = ".$id[0][0].".</div></p>\n";
              } else {
                echo "Could not find $host's ID!!!</div></p>\n";
              }
            } else {
              echo "Some problem with updating host $host in database.</div></p>\n";
            }
          }       
        }
     	  logdebug("Success, client add name == ".$_POST["host"]);
     	} else {
     	  echo "Hostname is empty!</p></div>";
        logdebug("Hostname is empty!"); 
      }
    }      
?>
  <h1>Clients management</h1>
  <?
    if ($clientd = Query("SELECT * FROM client;")) {
  ?>
  <ul class="no_dec">
  <li>&nbsp;&nbsp;&nbsp;<u>ID</u>&nbsp;&nbsp;&nbsp;<u>name</u></li>
  <?
      foreach ($clientd as $client) {
        echo "<li>".sayifadmin("<a href=\"?edit=1&cn=".$client[0]."\" title=\"Edit\">~</a>",1)."&nbsp;&nbsp;$client[0]".str_repeat("&nbsp;",5-strlen($client[0]))."$client[1]".str_repeat("&nbsp;",30-strlen($client[1]))."</li>";
      }
      echo sayifadmin("<li>&nbsp;&nbsp;&nbsp;<a href=\"?new=1\" title=\"Add new\">+</a></li>",0)."\n</ul>";
    } else {
      if (isLoggedIn()) {
        echo "<div class=\"info\"><p><u>No client defined</u><br>\nFor begin of using RepMan, you should to <a href=\"?new=1\" title=\"Add new client\">add client</a>.</p></div>\n";
      } else {
        echo "<div class=\"info\"><p><u>No client defined</u><br>\nFor begin of using RepMan, you should to add client.<br>\nIf you want to do this, you must <a href=\"?admin=1\" title=\"Log in as administrator\">log in as Repman's administrator</a></p></div>\n";        
      }  
    }
  ?>
</body>
</html>
<?
  endif;
?>
Return current item: RepMan