File: 0.00.0a/base/screen.inc.php (View as HTML)

  1: <?php // screen.inc.php -- web page screen library
  2: 
  3: $menu=array();
  4: $menu[0]="<a href=http://www.purplepixie.org/freenats/>FreeNATS Homepage</a>";
  5: $menu[1]="<a href=monitor.php>Monitor</a> | <a href=main.php>Main</a> | <a href=pref.php>Settings</a> | <a href=logout.php>Logout</a>";
  6: $menu[2]=$menu[1]." | <a href=admin.php>Administrator</a>";
  7: 
  8: function Screen_Header($title,$menuindex=0,$alertpane=0)
  9: {
 10: global $menu,$NATS,$NATS_Session;
 11: if ($menuindex==1) $alertpane=1; // bodge
 12: if ($NATS_Session->userlevel>9) $menuindex=2; // further bodge!
 13: echo "<html><head><title>FreeNATS: ".$title."</title>\n";
 14: echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/main.css\">\n";
 15: echo "</head>\n";
 16: echo "<body>";
 17: 
 18: echo "<table width=100% class=\"maintitle\">\n";
 19: echo "<tr><td align=left valign=center>\n";
 20: echo "<b class=\"maintitle\">FreeNATS: ".$title."</b></td>\n";
 21: echo "<td class=\"titlelink\" align=right valign=center>\n";
 22: echo $menu[$menuindex];
 23: echo "</td></tr></table>\n";
 24: 
 25: if ($alertpane==1)
 26: 	{
 27: 	$alerts=$NATS->GetAlerts();
 28: 	if (is_array($alerts))
 29: 		{
 30: 		echo "<div class=\"alertpane\" id=\"fn_alertpane\">";
 31: 		echo "<b><u>NATS Alerts</u></b><br><br>";
 32: 		foreach($alerts as $alert)
 33: 			{
 34: 			echo "&nbsp;<a href=node.php?nodeid=".$alert['nodeid'].">";
 35: 			echo "<b class=\"al".$alert['alertlevel']."\">".$alert['nodeid']."</b></a><br>";
 36: 			}
 37: 		echo "<br>";
 38: 		echo "</div>";
 39: 		}
 40: 	}
 41: 
 42: }
 43: 
 44: function Screen_Footer()
 45: {
 46: global $NATS;
 47: echo "<br><br>\n";
 48: //$NATS->Cfg->DumpToScreen();
 49: echo "<table class=\"nfooter\" width=100%>";
 50: echo "<tr><td align=left><a href=http://www.purplepixie.org/freenats/>FreeNATS</a> from ";
 51: echo "<a href=http://www.purplepixie.org/>PurplePixie Systems</a>";
 52: echo "</td><td align=right>";
 53: echo "Version: ".$NATS->Version;
 54: if ($NATS->Release!="") echo "/".$NATS->Release;
 55: echo "</td></tr>";
 56: echo "</div>";
 57: echo "\n</body></html>\n";
 58: }
 59: 
 60: function UL_Error($task="")
 61: {
 62: Screen_Header("Insufficient Access");
 63: echo "<br>Sorry but your user has insufficient access to perform task (".$task.").<br><br>";
 64: echo "<a href=main.php>Please click here to continue.</a><br><br>";
 65: Screen_Footer();
 66: exit();
 67: }
 68: 
 69: function nicedt($ts)
 70: {
 71: if ($ts<=0) return "never";
 72: return date("H:i:s d/m/Y",$ts);
 73: }
 74: 
 75: function enicedt($ts)
 76: {
 77: echo nicedt($ts);
 78: }
 79: 
 80: function nicediff($diff)
 81: {
 82: $hr=0;
 83: $mn=0;
 84: $se=0;
 85: if ($diff>59)
 86: 	{
 87: 	$mn=round($diff/60,0);
 88: 	$se=$diff%60;
 89: 	if ($mn>59)
 90: 		{
 91: 		$hr=round($mn/60,0);
 92: 		$mn=$mn%60;
 93: 		}
 94: 	}
 95: else $se=$diff;
 96: $s="";
 97: if ($hr<10) $s="0";
 98: $s.=$hr.":";
 99: if ($mn<10) $s.="0";
100: $s.=$mn.":";
101: if ($se<10) $s.="0";
102: $s.=$se;
103: return $s;
104: }
105: 
106: function dtago($ts)
107: {
108: if ($ts<=0) return "never";
109: $now=time();
110: $diff=$now-$ts;
111: $s=nicediff($diff);
112: $s.=" ago";
113: return $s;
114: }
115: 
116: function edtago($ts)
117: {
118: echo dtago($ts);
119: }
120: 
121: $allowed="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@_-.,";
122: 
123: function nices($s)
124: {
125: global $allowed;
126: $o="";
127: for ($a=0; $a<strlen($s); $a++)
128: 	{
129: 	$c=$s[$a];
130: 	if (strpos($allowed,$c)==false)
131: 		{
132: 		// skip it
133: 		}
134: 	else $o.=$c;
135: 	}
136: return $o;
137: }
138: 
139: function ShowIcons()
140: {
141: global $fnIcons,$fnIcon_DefNode,$fnIcon_DefGroup;
142: $c=0;
143: echo "<table border=1>";
144: for ($a=0; $a<count($fnIcons); $a++)
145: 	{
146: 	echo "<td valign=top align=left><img src=icons/".$fnIcons[$a]."><br>".$fnIcons[$a]."<br>";
147: 	if ($a==$fnIcon_DefNode) echo "<i>Node Default</i> ";
148: 	if ($a==$fnIcon_DefGroup) echo "<i>Group Default</i>";
149: 	echo "</td>";
150: 	}
151: echo "</tr></table>";
152: }
153: 
154: 
155: // Icons!
156: $fnIcons=array();
157: $fnIcons[0]="default_node.gif";
158: $fnIcons[1]="default_group.gif";
159: $fnIcons[2]="globe.gif";
160: $fnIcons[3]="monitor.gif";
161: $fnIcons[4]="personfile.gif";
162: $fnIcons[5]="special.gif";
163: 
164: $fnIcon_DefNode=0;
165: $fnIcon_DefGroup=1;
166: 
167: function NodeIcon($nodeid)
168: {
169: global $NATS,$fnIcons,$fnIcon_DefNode;
170: $q="SELECT nodeicon FROM fnnode WHERE nodeid=\"".ss($nodeid)."\"";
171: $r=$NATS->DB->Query($q);
172: if ($row=$NATS->DB->Fetch_Array($r)) 
173: 	{
174: 	if ($row['nodeicon']!="") return $row['nodeicon'];
175: 	}
176: return $fnIcons[$fnIcon_DefNode];
177: }
178: 
179: function GroupIcon($groupid)
180: {
181: global $NATS,$fnIcons,$fnIcon_DefGroup;
182: $q="SELECT groupicon FROM fngroup WHERE groupid=\"".ss($groupid)."\"";
183: $r=$NATS->DB->Query($q);
184: if ($row=$NATS->DB->Fetch_Array($r)) 
185: 	{
186: 	if ($row['groupicon']!="") return $row['groupicon'];
187: 	}
188: return $fnIcons[$fnIcon_DefGroup];
189: }
190: 
191: function np_tiny($nodeid,$text=true)
192: {
193: global $NATS;
194: $al=$NATS->NodeAlertLevel($nodeid);
195: echo "<table class=\"nptiny-al".$al."\">";
196: echo "<tr><td valign=center align=center>";
197: echo "<a href=node.php?nodeid=".$nodeid.">";
198: echo "<img src=\"icons/".NodeIcon($nodeid)."\" border=0>";
199: echo "</a>";
200: if ($text)
201: 	{
202: 	echo "<br><b class=\"al".$al."\">".$nodeid."</b>";
203: 	}
204: echo "</td></tr></table>";
205: }
206: 
207: function ng_tiny($groupid,$groupname="",$text=true)
208: {
209: global $NATS;
210: // to do - get groupname if not sent but F--- it for now
211: $al=$NATS->GroupAlertLevel($groupid);
212: echo "<table class=\"nptiny-al".$al."\">";
213: echo "<tr><td valign=center align=center>";
214: echo "<a href=group.php?groupid=".$groupid.">";
215: echo "<img src=\"icons/".GroupIcon($groupid)."\" border=0>";
216: echo "</a>";
217: if ($text)
218: 	{
219: 	echo "<br><b class=\"al".$al."\">".$groupname."</b>";
220: 	}
221: echo "</td></tr></table>";
222: }
223: 
224: function ng_big($groupid,$groupname="",$groupdesc="",$groupicon="")
225: {
226: global $NATS;
227: if ($groupicon=="") $groupicon=GroupIcon($groupid);
228: $al=$NATS->GroupAlertLevel($groupid);
229: echo "<table class=\"npbig-al".$al."\">";
230: echo "<tr><td align=left valign=top>";
231: echo "<table class=\"nicetable\" width=300>";
232: echo "<tr><td align=right>Group Name :";
233: echo "</td><td align=left><a href=group.php?groupid=".$groupid.">".$groupname."</a></td></tr>";
234: echo "<tr><td align=right>Description :";
235: echo "</td><td align=left>".$groupdesc."</td></tr>";
236: echo "<tr><td align=right>Status :</td><td align=left>";
237: echo "<b class=\"al".$al."\">".oText($al)."</b></td></tr>";
238: echo "</table></td>";
239: //echo "<td align=left valign=top align=right width=60>";
240: //echo "<img src=icons/".GroupIcon($groupid).">";
241: //echo "</td>";
242: echo "</tr>";
243: echo "</table>";
244: }
245: 
246: ?>