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

$object=$_REQUEST['object'];
$cascade=$_REQUEST['cascade'];

include "opendb.php";

// Search the parent object

$sql="select * from objects where id_object='".$object."'";
$query=mysql_query($sql,$mysql_conn);
$result=mysql_fetch_assoc($query);
$parent_object=$result['parent_obj'];

if ($cascade=='on') {

  $toanalize=array();
  $todelete=array();

  array_push($toanalize,$object);
 
  while (($item=array_pop($toanalize))>0) {
    array_push($todelete,$item);
    $sql="select id_object from objects where parent_obj='".$item."'";
    $query=mysql_query($sql,$mysql_conn);
    while ($result=mysql_fetch_assoc($query)) {
      array_push($toanalize,$result['id_object']);
    }
  }
}
else {
  $sql="select * from objects where parent_obj='".$object."'";
  $query=mysql_query($sql,$mysql_conn);
  if (mysql_num_rows($query)>0) {
    echo "<html><body><h1>Error!</h1><p>Unable to delete the selected object. It contains other objects. Please delete them before or check the cascade box</p><p><a href=\"javascript: history.go(-1)\">Back</a></p></body></html>";
    die();
  }

  $sql="select * from connections where start_obj='".$object."' or end_obj='".$object."'";
  $query=mysql_query($sql,$mysql_conn);
  if (mysql_num_rows($query)>0) {
    echo "<html><body><h1>Error!</h1><p>Unable to delete the selected object. It has connections to other objects. Please delete them before or check the cascade box</p><p><a href=\"javascript: history.go(-1)\">Back</a></p></body></html>";
    die();
  }

  $todelete[0]=$object;

}

while (($item=array_pop($todelete))>0) {
  $sql="delete from objects where id_object='".$item."'";
  $query=mysql_query($sql,$mysql_conn);
  $sql="delete from connections where start_obj='".$item."'";
  $query=mysql_query($sql,$mysql_conn);
  $sql="delete from connections where end_obj='".$item."'";
  $query=mysql_query($sql,$mysql_conn);
  $sql="delete from vlannames where obj_id='".$item."'";
  $query=mysql_query($sql,$mysql_conn);
  $sql="delete from vlanports where obj_id='".$item."'";
  $query=mysql_query($sql,$mysql_conn);
}

echo "<script lang=javascript>opener.top.frames[\"left\"].collapse(".$parent_object.")</script>";
echo "<script lang=javascript>opener.top.frames[\"left\"].expand(".$parent_object.")</script>";
echo "<script lang=javascript>opener.top.frames[\"left\"].select(".$parent_object.")</script>";
echo "<script lang=javascript>window.close();</script>";

?>
Return current item: OpenCabling