File: 0.02.28a/server/web/node.action.php (View as HTML)

  1: <?php
  2: /* -------------------------------------------------------------
  3: This file is part of FreeNATS
  4: 
  5: FreeNATS is (C) Copyright 2008 PurplePixie Systems
  6: 
  7: FreeNATS is free software: you can redistribute it and/or modify
  8: it under the terms of the GNU General Public License as published by
  9: the Free Software Foundation, either version 3 of the License, or
 10: (at your option) any later version.
 11: 
 12: FreeNATS is distributed in the hope that it will be useful,
 13: but WITHOUT ANY WARRANTY; without even the implied warranty of
 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15: GNU General Public License for more details.
 16: 
 17: You should have received a copy of the GNU General Public License
 18: along with Foobar.  If not, see www.gnu.org/licenses
 19: 
 20: For more information see www.purplepixie.org/freenats
 21: -------------------------------------------------------------- */
 22: 
 23: ob_start();
 24: require("include.php");
 25: $NATS->Start();
 26: if (!$NATS_Session->Check($NATS->DB))
 27: 	{
 28: 	header("Location: ./?login_msg=Invalid+Or+Expired+Session");
 29: 	exit();
 30: 	}
 31: if ($NATS_Session->userlevel<5) UL_Error("Action Node");
 32: $msg="";
 33: 
 34: switch($_REQUEST['action'])
 35: 	{
 36: 	case "delete":
 37: 		if (!isset($_REQUEST['confirm']))
 38: 			{
 39: 			$go="confirm.php?action=Delete+Node+".$_REQUEST['nodeid']."+and+all+associated+data&back=";
 40: 			$go.=urlencode("node.action.php?action=delete&nodeid=".$_REQUEST['nodeid']."&confirm=1");
 41: 			header("Location: ".$go);
 42: 			exit();
 43: 			}
 44: 		// delete it and shit!
 45: 		
 46: 		// node + localtests + lt results
 47: 		
 48: 		$dnc=0;
 49: 		$dnt=0;
 50: 		$dnd=0;
 51: 		$q="SELECT localtestid FROM fnlocaltest WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\"";
 52: 		$r=$NATS->DB->Query($q);
 53: 		while ($row=$NATS->DB->Fetch_Array($r))
 54: 			{
 55: 			$dq="DELETE FROM fnrecord WHERE testid=\"L".$row['localtestid']."\"";
 56: 			$NATS->DB->Query($dq);
 57: 			$dnd+=$NATS->DB->Affected_Rows();
 58: 			$dq="DELETE FROM fnlocaltest WHERE localtestid=".$row['localtestid'];
 59: 			$NATS->DB->Query($dq);
 60: 			$dnt+=$NATS->DB->Affected_Rows();
 61: 			}
 62: 		$NATS->DB->Free($r);
 63: 		$dq="DELETE FROM fnnode WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\"";
 64: 		$NATS->DB->Query($dq);
 65: 		$dnc+=$NATS->DB->Affected_Rows();	
 66: 		
 67: 		// group links
 68: 		$q="DELETE FROM fngrouplink WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\"";
 69: 		$NATS->DB->Query($q);
 70: 		
 71: 		$msg="Node ".$_REQUEST['nodeid']." deleted (".$dnc." node, ".$dnt." tests, ".$dnd." records)";
 72: 		break;
 73: 		
 74: 	case "create":
 75: 		// get highest weight
 76: 		$hw=0;
 77: 		$hq="SELECT weight FROM fnnode ORDER BY weight DESC LIMIT 0,1";
 78: 		$hr=$NATS->DB->Query($hq);
 79: 		if ($hrow=$NATS->DB->Fetch_Array($hr)) $hw=($hrow['weight'])+10;
 80: 		else $hw=10;
 81: 		$NATS->DB->Free($hr);
 82: 		$q="INSERT INTO fnnode(nodeid,weight) VALUES(\"".ss(strtolower($_REQUEST['nodeid']))."\",".$hw.")";
 83: 		$NATS->DB->Query($q);
 84: 		if ($NATS->DB->Affected_Rows()>0)
 85: 			{
 86: 			header("Location: node.edit.php?nodeid=".strtolower($_REQUEST['nodeid']));
 87: 			exit();
 88: 			}
 89: 		$msg="Failed to Create Node";
 90: 		break;
 91: 		
 92: 	case "move":
 93: 	// get my weight
 94: 	$q="SELECT weight FROM fnnode WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\"";
 95: 	$r=$NATS->DB->Query($q);
 96: 	$row=$NATS->DB->Fetch_Array($r);
 97: 	$myweight=$row['weight'];
 98: 	$NATS->DB->Free($r);
 99: 	
100: 	// get next/prev one
101: 	$q="SELECT nodeid,weight FROM fnnode WHERE ";
102: 	if ($_REQUEST['dir']=="up") $q.="weight<".$myweight." ORDER BY weight DESC LIMIT 0,1";
103: 	else $q.="weight>".$myweight." ORDER BY weight ASC LIMIT 0,1";
104: 	$r=$NATS->DB->Query($q);
105: 	if ($row=$NATS->DB->Fetch_Array($r))
106: 		{
107: 		// swap 'em
108: 		$uq="UPDATE fnnode SET weight=".$myweight." WHERE nodeid=\"".$row['nodeid']."\"";
109: 		$NATS->DB->Query($uq);
110: 		$uq="UPDATE fnnode SET weight=".$row['weight']." WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\"";
111: 		$NATS->DB->Query($uq);
112: 		$msg="Updated Node Display Order";
113: 		}
114: 	else $msg="No Higher/Lower Node";
115: 	break;
116: 		
117: 
118: 		
119: 	default: $msg="Unknown Node Action";
120: 	}
121: header("Location: main.php?message=".urlencode($msg));
122: exit();
123: 
124: ?>
125: