Location: PHPKode > projects > OpenCabling > opencabling/create_connection.php
<?php

	$conn_type=$_REQUEST['conn_type'];
        $start_id=$_REQUEST['start_id'];
        $start_item=$_REQUEST['start_item'];
        $end_id=$_REQUEST['end_id'];
        $end_item=$_REQUEST['end_item'];
	$name=$_REQUEST['conn_name'];
	$description=$_REQUEST['conn_description'];

        include "opendb.php";

// Test if all elements are present

if ($conn_type=='Choose' || $start_id=='' || $start_item=='' || $end_id=='' || $end_item=='') {
  echo "<html><body><h1>Error!</h1><p>Unable to create the requested connection: one of the mandatary info is missing.</p><p><a href=\"javascript: history.go(-1)\">Back</a></p></body></html>";
  die();
}

// Test if another connection came from the same starting object, same position

$sql="select * from connections where ( start_obj='".$start_id."' and start_item='".$start_item."' ) or (end_obj='".$start_id."' and end_item='".$start_item."' )";
$query=mysql_query($sql,$mysql_conn);
if (mysql_num_rows($query)>0) {
  echo "<html><body><h1>Error!</h1><p>Unable to create the requested connection: there is already a connection from the starting object, item choosen.</p><p><a href=\"javascript: history.go(-1)\">Back</a></p></body></html>";
  die();
}

// Test if another connection came from the same ending object, same position

$sql="select * from connections where ( start_obj='".$end_id."' and start_item='".$end_item."' ) or (end_obj='".$end_id."' and end_item='".$end_item."' )";
$query=mysql_query($sql,$mysql_conn);
if (mysql_num_rows($query)>0) {
  echo "<html><body><h1>Error!</h1><p>Unable to create the requested connection: there is already a connection from the ending object, item choosen.</p><p><a href=\"javascript: history.go(-1)\">Back</a></p></body></html>";
  die();
}


$sql="insert into connections(connection_type,name,start_obj,start_item,end_obj,end_item,description) values('$conn_type','$name','$start_id','$start_item','$end_id','$end_item','$description')";
$query=mysql_query($sql,$mysql_conn);

echo "<script lang=javascript>location.href = 'show_detail.php?object=".$start_id."';</script>";

?>
Return current item: OpenCabling