File: 0.04.00a/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 FreeNATS.  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: 		$nodename=strtolower($_REQUEST['nodeid']);
 83: 		$nodename=str_replace(" ","_",$nodename);
 84: 		if (strlen($nodename)>0)
 85: 			{
 86: 			$q="INSERT INTO fnnode(nodeid,weight) VALUES(\"".ss($nodename)."\",".$hw.")";
 87: 			$NATS->DB->Query($q);
 88: 			if ($NATS->DB->Affected_Rows()>0)
 89: 				{
 90: 				header("Location: node.edit.php?nodeid=".$nodename);
 91: 				exit();
 92: 				}
 93: 			}
 94: 		$msg="Failed to Create Node";
 95: 		break;
 96: 		
 97: 	case "move":
 98: 	// get my weight
 99: 	$q="SELECT weight FROM fnnode WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\"";
100: 	$r=$NATS->DB->Query($q);
101: 	$row=$NATS->DB->Fetch_Array($r);
102: 	$myweight=$row['weight'];
103: 	$NATS->DB->Free($r);
104: 	
105: 	// get next/prev one
106: 	$q="SELECT nodeid,weight FROM fnnode WHERE ";
107: 	if ($_REQUEST['dir']=="up") $q.="weight<".$myweight." ORDER BY weight DESC LIMIT 0,1";
108: 	else $q.="weight>".$myweight." ORDER BY weight ASC LIMIT 0,1";
109: 	$r=$NATS->DB->Query($q);
110: 	if ($row=$NATS->DB->Fetch_Array($r))
111: 		{
112: 		// swap 'em
113: 		$uq="UPDATE fnnode SET weight=".$myweight." WHERE nodeid=\"".$row['nodeid']."\"";
114: 		$NATS->DB->Query($uq);
115: 		$uq="UPDATE fnnode SET weight=".$row['weight']." WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\"";
116: 		$NATS->DB->Query($uq);
117: 		$msg="Updated Node Display Order";
118: 		}
119: 	else $msg="No Higher/Lower Node";
120: 	break;
121: 		
122: 	case "move_before":
123: 	// get nodeid of what to move before the and movebefore weight
124: 	$q="UPDATE fnnode SET weight=weight+1 WHERE weight>=".ss($_REQUEST['move_before']);
125: 	$msg=$q;
126: 	$NATS->DB->Query($q);
127: 	$q="UPDATE fnnode SET weight=".ss($_REQUEST['move_before'])." WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\"";
128: 	$NATS->DB->Query($q);
129: 	//$msg="Moved Node";
130: 	break;
131: 		
132: 	case "reorderweight":
133: 	$q="SELECT nodeid,weight FROM fnnode ORDER BY weight ASC";
134: 	$r=$NATS->DB->Query($q);
135: 	$p=1;
136: 	while ($row=$NATS->DB->Fetch_Array($r))
137: 		{
138: 		$uq="UPDATE fnnode SET weight=".$p." WHERE nodeid=\"".$row['nodeid']."\"";
139: 		$NATS->DB->Query($uq);
140: 		$p++;
141: 		}
142: 	$msg="Reorder Completed";
143: 	break;
144: 	
145: 	default: $msg="Unknown Node Action";
146: 	}
147: header("Location: main.php?message=".urlencode($msg));
148: exit();
149: 
150: ?>
151: