File: 1.01.2a/server/web/node.action.php (View as Code)

1: 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: $NATS->DeleteTest("L".$row['localtestid']); 56: /* 57: $dq="DELETE FROM fnrecord WHERE testid=\"L".$row['localtestid']."\""; 58: $NATS->DB->Query($dq); 59: $dnd+=$NATS->DB->Affected_Rows(); 60: $dq="DELETE FROM fnlocaltest WHERE localtestid=".$row['localtestid']; 61: $NATS->DB->Query($dq); 62: $dnt+=$NATS->DB->Affected_Rows(); 63: */ 64: } 65: $NATS->DB->Free($r); 66: $q="SELECT nstestid FROM fnnstest WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 67: $r=$NATS->DB->Query($q); 68: while ($row=$NATS->DB->Fetch_Array($r)) 69: { 70: $NATS->DeleteTest("N".$row['nstestid']); 71: } 72: $NATS->DB->Free($r); 73: $dq="DELETE FROM fnnode WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 74: $NATS->DB->Query($dq); 75: $dnc+=$NATS->DB->Affected_Rows(); 76: 77: // group links 78: $q="DELETE FROM fngrouplink WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 79: $NATS->DB->Query($q); 80: 81: $msg="Node ".$_REQUEST['nodeid']." deleted (".$dnc." node)"; 82: break; 83: 84: case "create": 85: // get highest weight 86: $hw=0; 87: $hq="SELECT weight FROM fnnode ORDER BY weight DESC LIMIT 0,1"; 88: $hr=$NATS->DB->Query($hq); 89: if ($hrow=$NATS->DB->Fetch_Array($hr)) $hw=($hrow['weight'])+10; 90: else $hw=10; 91: $NATS->DB->Free($hr); 92: $nodename=strtolower($_REQUEST['nodeid']); 93: $nodename=str_replace(" ","_",$nodename); 94: if (strlen($nodename)>0) 95: { 96: $q="INSERT INTO fnnode(nodeid,weight) VALUES(\"".ss($nodename)."\",".$hw.")"; 97: $NATS->DB->Query($q); 98: if ($NATS->DB->Affected_Rows()>0) 99: { 100: header("Location: node.edit.php?nodeid=".$nodename."&showoptions=1"); 101: exit(); 102: } 103: } 104: $msg="Failed to Create Node"; 105: break; 106: 107: case "move": 108: // get my weight 109: $q="SELECT weight FROM fnnode WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 110: $r=$NATS->DB->Query($q); 111: $row=$NATS->DB->Fetch_Array($r); 112: $myweight=$row['weight']; 113: $NATS->DB->Free($r); 114: 115: // get next/prev one 116: $q="SELECT nodeid,weight FROM fnnode WHERE "; 117: if ($_REQUEST['dir']=="up") $q.="weight<".$myweight." ORDER BY weight DESC LIMIT 0,1"; 118: else $q.="weight>".$myweight." ORDER BY weight ASC LIMIT 0,1"; 119: $r=$NATS->DB->Query($q); 120: if ($row=$NATS->DB->Fetch_Array($r)) 121: { 122: // swap 'em 123: $uq="UPDATE fnnode SET weight=".$myweight." WHERE nodeid=\"".$row['nodeid']."\""; 124: $NATS->DB->Query($uq); 125: $uq="UPDATE fnnode SET weight=".$row['weight']." WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 126: $NATS->DB->Query($uq); 127: $msg="Updated Node Display Order"; 128: } 129: else $msg="No Higher/Lower Node"; 130: break; 131: 132: case "move_before": 133: // get nodeid of what to move before the and movebefore weight 134: $q="UPDATE fnnode SET weight=weight+1 WHERE weight>=".ss($_REQUEST['move_before']); 135: $msg=$q; 136: $NATS->DB->Query($q); 137: $q="UPDATE fnnode SET weight=".ss($_REQUEST['move_before'])." WHERE nodeid=\"".ss($_REQUEST['nodeid'])."\""; 138: $NATS->DB->Query($q); 139: //$msg="Moved Node"; 140: break; 141: 142: case "reorderweight": 143: $q="SELECT nodeid,weight FROM fnnode ORDER BY weight ASC"; 144: $r=$NATS->DB->Query($q); 145: $p=1; 146: while ($row=$NATS->DB->Fetch_Array($r)) 147: { 148: $uq="UPDATE fnnode SET weight=".$p." WHERE nodeid=\"".$row['nodeid']."\""; 149: $NATS->DB->Query($uq); 150: $p++; 151: } 152: $msg="Reorder Completed"; 153: break; 154: 155: default: $msg="Unknown Node Action"; 156: } 157: header("Location: main.php?mode=nodes&message=".urlencode($msg)); 158: exit(); 159: 160: ?> 161: