<?php

#############################################################################
#                              Site@School
# Site@School is a website management system designed for schools.
#
# About Site@School:
# Comissioned by: City District 'de Baarsjes', Amsterdam, Netherlands
# Original idea, coding (version 1.0) and design : Mark de Haan (mark@starwave.nl)
# Ideas, improvements, expansions (version 1.1 - 2.4): Fred Stuurman 
# Current coder & maintainer: Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# sas_link.php: last changed 04/10/2006  , version: 2.4.10
#            by Fred Stuurman  (fc.stuurman@hccnet.nl)
#$Id: sas_link.php,v 1.2 2006/10/15 19:08:55 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
# Copyright (C) 2002 - 2006 Municipality of Amsterdam, City District
#  'de Baarsjes', Amsterdam, the Netherlands.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
##############################################################################
define('IN_SAS', true);

include ("../../../../../configuration/database.inc.php"); // connecting to database
mysql_connect("$db_server", "$db_username", "$db_password");
mysql_select_db("$db_name");

include ("../../../../../core/session.php"); // create a session

if ($_SESSION['site'] == "protected")
{
	$table_sections = $dbprefix . "prot_sections";
	$table_pages = $dbprefix . "prot_pages";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
 * 
 * Licensed under the terms of the GNU Lesser General Public License:
 * 		http://www.opensource.org/licenses/lgpl-license.php
 * 
 * For further information visit:
 * 		http://www.fckeditor.net/
 * 
 * "Support Open Source software. What about a donation today?"
 * 
 * File Name: fck_sas_link.php
 * 	SiteSchool insert link Plugin.
 * 
 * this file is part of Site@School CMS http://siteatschool.sourceforge.net
 *
 * File Authors:
 * 		Fred Stuurman (fc.stuurman@hccnet.nl)
 * 		last changed 23/06/2006
 */
-->
<?php


$query = "SELECT config_value FROM $table_configuration where config_key='url'"; // getting the site url
$result = mysql_query($query);
$site_url = mysql_result($result, 0);
unset ($query);
unset ($result);
$query = "SELECT config_value FROM $table_configuration where config_key='language'"; // getting the language
$result = mysql_query($query);
$language = mysql_result($result, 0);
include ("../../../../../languages/$language/$language.php"); // including language file
unset ($query);
unset ($result);
?>

<html>
	<head>
		<title><?php echo $sas_lang['internal_link'] ?></title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta content="noindex, nofollow" name="robots">
		<script language="javascript">

var oEditor = window.parent.InnerDialogLoaded() ;
var FCKLang = oEditor.FCKLang ;
var FCKPlaceholders = oEditor.FCKPlaceholders ;

window.onload = function ()
{
	// First of all, translate the dialog box texts
	oEditor.FCKLanguageManager.TranslatePage( document ) ;
	
}

var eSelected = oEditor.FCKSelection.GetSelectedElement() ;


function Ok(url, linkname)
{
	 oEditor.FCK.InsertHtml( url + linkname + '</a>' ) ; 
	  window.close();
	return true ;
}

</script>
	</head>
	<body>
<?php


if (IsSet ($_GET[section]))
{
	$section = $_GET[section];
}
if (IsSet ($_GET[category]))
{
	$category = $_GET[category];
}

$query = "SELECT id, name, frontpage FROM $table_sections WHERE parent = '' ORDER BY sort";
$result = mysql_query($query);

while ($section_list = mysql_fetch_array($result))
{
	$i = 1;
	print "<a href=\"sas_link.php?section=$section_list[0]\" style =\"color: #0000FF\">$section_list[1]</a>";

	$query1 = "SELECT id, category FROM $table_pages WHERE section = '$section' GROUP BY category"; // getting catlist
	$result2 = mysql_query($query1);

	while ($cat_list = mysql_fetch_array($result2)) //loop through categories
	{

		$category1 = htmlspecialchars(rawurlencode($cat_list[1]));

		if (!empty ($cat_list[1]) and ($section_list[0] == $section)) //only display when categrory has no blanks
		{
			if ($i == 1)
			{
				print "<ul>";
			} //only print the first time
			$i++;
			print "<li><a href=sas_link.php?option=pagemanager&category=$category1&section=$section>$cat_list[1]</li>";
		}

		if (($cat_list[1] == $category) and ($section_list[0] == $section))
		{
			$query1 = "SELECT id, name, module, category FROM $table_pages WHERE category = '$category' and section = '$section' ORDER BY sort";
			$result1 = mysql_query($query1);
			print "<ul>";
			while ($page_list = mysql_fetch_array($result1))
			{

				$page_name = addslashes($page_list[1]);
				if ($page_list[3] != "")
				{
					$category = htmlspecialchars(rawurlencode($page_list[3]));
					print "<li><a href=# onclick=\"javascript:Ok('<a href=" . $site_url . "index.php?section=" . $section_list[0] . "&category=" . $category . "&page=" . $page_list[0] . ">','" . $page_name . "');\">$page_list[1]</a></li>";
				}
				else
				{
					print "<li><a href=# onclick=\"javascript:Ok('<a href=" . $site_url . "index.php?section=" . $section_list[0] . "&page=" . $page_list[0] . ">','" . $page_name . "');\">$page_list[1]</a></li>";
				}
			}

			print "</ul>";
		}
	}
	if ($i > 1)
	{
		print "</ul>";
	}
	if ($i == 1)
	{
		print "<br>";
	}
}
?>
	</body>
</html>
