Location: PHPKode > projects > WebMachinek > WMinst-0.62/delete.php
<?php
require("$public/.sys/.conf.php");
require("$public/.sys/.start.php");

$slash = strstr($dir, "/");
if ($slash != "") {
 $length = strlen($dir);
 $position = strpos($dir, "/");
 $category = substr($dir, 0, $position );
 $parent_file = substr($dir, $position + 1);
 $subcat = "yes";
} else {
 $category = $dir;
 $subcat = "no";
}

$conn = pg_connect("dbname=$dbase user=$dbuser port=5432");

if ($subcat == "no" AND $child == "t") {
 echo "<form><h1>Error: This Page contains a sub-level</h1>";
 echo "<h2>You can't delete such a Page:";
 echo '<input type="button" onclick="history.back();" value="OK"></h2></form>';
 exit;
}


elseif ($subcat == "no" AND $file == "index") {
 $query1 = pg_exec($conn,"SELECT count(file) FROM page
         WHERE dir LIKE '$dir';");
 $numbofiles = pg_fetch_array($query1, 0);
 if ($numbofiles[0] != 1) {
  echo "<form><h1>Error: This Page contains a sub-level</h1>";
  echo "<h2>You can't delete a Page with the sub-level:";
  echo ' <input type="button" onclick="history.back();" value="OK"></h2></form>';
  exit;
 } else {
  $query = pg_exec($conn,"SELECT count(dir) FROM category;");
  $numbocat = pg_fetch_array($query, 0);
  if ($numbocat[0] == 1) {
   echo "<form><h1>Error: This is the very last page in the system</h1>";
   echo "<h2>You can't remove the system this way:";
   echo ' <input type="button" onclick="history.back();" value="OK"></h2></form>';
   exit;
  } else {
   $query1 = pg_exec($conn,"SELECT pos FROM category
         WHERE dir LIKE '$dir';");
   $delpos = pg_fetch_array($query1, 0);
   pg_exec($conn,"DELETE FROM category
         WHERE dir LIKE '$dir';");
   pg_exec($conn,"DELETE FROM page
         WHERE dir LIKE '$dir';");
   pg_exec($conn,"DELETE FROM page_descr
         WHERE dir LIKE '$dir';");
   pg_exec($conn,"DELETE FROM page_layout
         WHERE dir LIKE '$dir';");
   pg_exec($conn,"UPDATE category SET pos = pos - 1
         WHERE pos > $delpos[0] AND dir NOT LIKE '%/%';");
   exec ("rm -r $public/$dir");
   exec ("rm -r $admin/$dir");
   exec ("rm -r $admin/.repos/$dir");
   $delcat = true;
  }
 }
}


elseif ($subcat == "yes") {
 $query1 = pg_exec($conn,"SELECT count(file) FROM page
         WHERE dir LIKE '$dir';");
 $numbofiles = pg_fetch_array($query1, 0);
 if ($numbofiles[0] == 1) {
  pg_exec($conn,"DELETE FROM category
         WHERE dir LIKE '$dir';");
  pg_exec($conn,"DELETE FROM page
         WHERE dir LIKE '$dir';");
  pg_exec($conn,"DELETE FROM page_descr
         WHERE dir LIKE '$dir';");
  pg_exec($conn,"DELETE FROM page_layout
         WHERE dir LIKE '$dir';");
  pg_exec($conn,"UPDATE page SET child = 'f'
         WHERE file LIKE '$parent_file' AND dir LIKE '$category';");
  exec ("rm $public/$dir/$file*");
  exec ("rm $admin/$dir/$file*");
  exec ("rm -r $admin/.repos/$dir");
  startpage("$parent_file", "$category", "f", "t", "$admin/$dir/index.php");
  startpage("$parent_file", "$category", "f", "f", "$public/$dir/index.php");
 } else {
  $query1 = pg_exec($conn,"SELECT page_pos FROM page
         WHERE dir LIKE '$dir' AND file LIKE '$file';");
  $delpos = pg_fetch_array($query1, 0);
  pg_exec($conn,"DELETE FROM page
         WHERE dir LIKE '$dir' AND file LIKE '$file';");
  pg_exec($conn,"DELETE FROM page_descr
         WHERE dir LIKE '$dir' AND file LIKE '$file';");
  pg_exec($conn,"DELETE FROM page_layout
         WHERE dir LIKE '$dir' AND file LIKE '$file';");
  pg_exec($conn,"UPDATE page SET page_pos = page_pos - 1
         WHERE page_pos > $delpos[0] AND dir LIKE '$dir' AND file LIKE '$file';");
  exec ("rm $public/$dir/$file*");
  exec ("rm $admin/$dir/$file*");
  exec ("rm $admin/.repos/$dir/$file.xml");
 }
}


else {
 $query1 = pg_exec($conn,"SELECT page_pos FROM page
         WHERE dir LIKE '$dir' AND file LIKE '$file';");
 $delpos = pg_fetch_array($query1, 0);
 pg_exec($conn,"DELETE FROM page
         WHERE dir LIKE '$dir' AND file LIKE '$file';");
 pg_exec($conn,"DELETE FROM page_descr
         WHERE dir LIKE '$dir' AND file LIKE '$file';");
 pg_exec($conn,"DELETE FROM page_layout
         WHERE dir LIKE '$dir' AND file LIKE '$file';");
 pg_exec($conn,"UPDATE page SET page_pos = page_pos - 1
         WHERE page_pos > $delpos[0] AND dir LIKE '$dir';");
 exec ("rm -r $public/$dir/$file");
 exec ("rm -r $admin/$dir/$file");
 exec ("rm $admin/.repos/$dir/$file.xml");
}


if ($delcat) {
 $query1 = pg_exec($conn,"SELECT dir FROM category
         WHERE pos = '1' AND dir NOT LIKE '%/%';");
 $gocat = pg_fetch_array($query1, 0);
 $link = "$urladmin/$gocat[0]/index.php";
 echo('<script LANGUAGE="JavaScript1.1" type="text/javascript">');
 echo("document.location=\"$link\"");
 echo("</script>");
} else {
 $link = "$urladmin/$dir/index.php";
 echo('<script LANGUAGE="JavaScript1.1" type="text/javascript">');
 echo("document.location=\"$link\"");
 echo("</script>");
}
php?>

Return current item: WebMachinek