Location: PHPKode > projects > eBlog > admin/sections.php
<?php

/**************************************************************************
 *                                                                        *
 *                                                                        *
 *         Solution: eBlog                                                *
 *          Release: 1.7                                                  *
 *             File: admin/sections.php                                   *
 *               By: Emuci inc.                                           *
 *          Website: http://www.emuci.com                                 *
 *        Copyright: (C) 2010 Emcui inc.                                  *
 *                                                                        *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *                                                                        *
 *   This script is NOT freeware and is subjected to Emuci terms of use   *
 *   located in the docs folder.                                          *
 *                                                                        *
 *                                                                        *
 *************************************************************************/


include 'global.php';

$action = $_GET['action'];
$id     = $_GET['id'];
$section = $_GET['section'];

if(empty($action))
{
	$action = "form";
}

if($section != "")
{
echo "<meta http-equiv=\"refresh\" content=\"0;url=sections.php#$section\">";
}	

if($_SESSION['permission'] == 1){

	// 1: show main form
	if($action == "form"){
	
		// construct page map
		$thisPageNav = "&nbsp;<img src=\"../images/icons/prev_$blog_dir.gif\">&nbsp;<a href=\"sections.php\"><font face=\"tahoma\" style=\"font-size: 10pt;\">$lang_admin_link_3</font></a>";
	
	
		// construct quick links menu
		$quicklinks = "<table width=\"100%\" border=\"0\" cellspacing=\"5\" cellpadding=\"1\">

					 <tr><td valign =\"top\" width=\"22\"><img src=\"../images/icons/icon_bullet.gif\"></td>
					 <td><a href=\"#add\"><font style=\"font-size: 0.7em;\" face=\"Tahoma\">$lang_admin_addSection</font></a></td>
					 </tr>
					 					 
					 <tr><td valign =\"top\" width=\"22\"><img src=\"../images/icons/icon_bullet.gif\"></td>
					 <td><a href=\"#list\"><font style=\"font-size: 0.7em;\" face=\"Tahoma\">$lang_admin_sectionsCat1</font></a></td>
					 </tr>
					 					 
					 <tr><td valign =\"top\" width=\"22\"><img src=\"../images/icons/icon_bullet.gif\"></td>
					 <td><a href=\"sections.php?action=pages#addPages\"><font style=\"font-size: 0.7em;\" face=\"Tahoma\">$lang_admin_sectionsCat3</font></a></td>
					 </tr>
					 					 
					 <tr><td valign =\"top\" width=\"22\"><img src=\"../images/icons/icon_bullet.gif\"></td>
					 <td><a href=\"sections.php?action=pages\"><font style=\"font-size: 0.7em;\" face=\"Tahoma\">$lang_admin_sectionsCat4</font></a></td>
					 </tr>
					 					 
					 
					 <tr><td valign =\"top\" width=\"22\"><img src=\"../images/icons/icon_bullet.gif\"></td>
					 <td><a href=\"topics.php?action=add\"   title=\"$lang_admin_addTopic\" rel=\"gb_page_center[640, 500]\"><font style=\"font-size: 0.7em;\" face=\"Tahoma\">$lang_admin_addTopic</font></a></td>
					 </tr>
					 					 
					 
					 <tr><td valign =\"top\" width=\"22\"><img src=\"../images/icons/icon_bullet.gif\"></td>
					 <td><a href=\"topics.php\"><font style=\"font-size: 0.7em;\" face=\"Tahoma\">$lang_admin_showTopic</font></a></td>
					 </tr>	
					 					 					 				 					 					 
					 
					 
					 </table>";
					 
		$conn = mysql_connect($dbhost, $dbuser, $dbpass);
		mysql_select_db($dbname);
		$query  = "SELECT id, title FROM eblog_sections ORDER BY id ASC";
		$result = mysql_query($query);
		$allOptions = "";
		$allRows = "";
		$counter = 0;
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			$counter++;
			
			$devider = $counter%2;
			
			if($devider==0)
			$bgColor="#f2f2f2";
			else
			$bgColor="#dadada";
			
			$id	= $row['id'];
			$title	= $row['title'];
		
			$allOptions = $allOptions . "<option value=\"$id\">$title</option>";
			
			$allRows = $allRows . "<tr bgcolor=\"$bgColor\"><td width=\"40\" align=\"center\"><font face=\"tahoma\" size=\"2\">$id</font></td><td><a href=\"sections.php?action=edit&id=$id\"   title=\"$lang_admin_editSection\" rel=\"gb_page_center[640, 280]\"><font face=\"tahoma\" size=\"2\">$title</font></a></td><td width=\"60\"><a href=\"sections.php?action=edit&id=$id\"   title=\"$lang_admin_editSection\" rel=\"gb_page_center[640, 340]\"><img src=\"../images/icons/icon_fix.gif\" border=\"0\" title=\"$lang_admin_edit\"></a>&nbsp;<a href=\"topics.php?action=ShowAll&id=$id\"><img border=\"0\" src=\"../images/icons/icon_list.gif\" title=\"$lang_admin_ShowAllTopics\"></a>&nbsp;<a href=\"#\" onClick=\"rusure($id); return false;\"><img src=\"../images/icons/icon_remove.gif\" border=\"0\" title=\"$lang_admin_delete\"></a></td></tr>";	
		}
		
		if ($counter < 1)
		{
		$allRows = $allRows . "<tr bgColor=\"f2f2f2\"><td colspan=\"3\"><font face=\"tahoma\" size=\"2\">$lang_admin_noSections</font></td></tr>";
		}
		
		mysql_close($conn);	
		
		// construct the form
		$sections_form = "
						<script language=\"javascript\">
					  function checkForm(form){
					  
					  if(form.name.value == \"\"){
					  alert( \"$lang_erorr_code116\" );
					  form.name.focus();
					  return false;
					  }
					  
					  if(form.disc.value == \"\"){
					  alert( \"$lang_erorr_code117\" );
					  form.disc.focus();
					  return false;
					  }
					  
					  return true;
					  }
					  
						function rusure(ID2Delete){
							question = confirm(\"$lang_admin_confirmDeleteSection\")
							if (question !=\"0\"){
								top.location = \"sections.php?action=remove&id=\" + ID2Delete;
							}
						}			  
						
						</script>
						<div>
						<form method=\"post\" action=\"sections.php?action=add\" onsubmit=\"return checkForm(this);\">
						<table bordercolor=\"#727272\" style=\"border-collapse: collapse\" width=\"100%\" cellSpacing=\"0\" cellPadding=\"5\"  border=\"1\">
						
						
						<tr bgcolor=\"9b196c\" background=\"../images/icons/disc_bar.gif\">
						<td colspan = \"2\" background=\"../images/icons/disc_bar.gif\">
						<font color=\"#ffffff\" size=\"2\" face=\"Tahoma\">
						<a name=\"add\">$lang_admin_addSection<a>
						</font>
						</td>
						</tr>
						
						<tr bgcolor=\"f2f2f2\">
						<td width=\"200\">
						<font size=\"2\" face=\"tahoma\">
							$lang_admin_sectionName:
						</font>
						</td>
						<td>
						<input type=\"text\" name=\"name\" style=\"font-family: Tahoma; font-size: 12px; color: #000000; width:100%;  border: 1px solid #000000;\">
						</td>				
						</tr>
						
						
						<tr bgcolor=\"dadada\">
						<td width=\"200\">
						<font size=\"2\" face=\"tahoma\">
							$lang_admin_sectionDisc:
						</font>
						</td>
						<td>
						<textarea name=\"disc\" rows=\"5\" MAXLENGTH=\"10000\" style=\"font-family: Tahoma; font-size: 12px; color: #000000; width:100%;  border: 1px solid #000000; resize: none;\"></textarea>
						</td>				
						</tr>	
		
						
						
						<tr bgcolor=\"f2f2f2\">
						<td width=\"200\">
						<font size=\"2\" face=\"tahoma\">
							$lang_admin_sectionParent:
						</font>
						</td>
						<td>
						<select name=\"parent\" style=\"width:100%;  height:21\">
						<option value=\"0\" selected>$lang_admin_none</option>
						$allOptions
						</select>
						</td>				
						</tr>	
						
						
						<tr bgcolor=\"dadada\">
						<td width=\"200\">
						<font size=\"2\" face=\"tahoma\">
							$lang_admin_sectionAllowComment:
						</font>
						</td>
						<td>
						<input type=\"radio\" name=\"g1\" value=\"1\" checked><font size=\"2\" face=\"tahoma\">$lang_admin_yes</font>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<input type=\"radio\" name=\"g1\" value=\"0\"><font size=\"2\" face=\"tahoma\">$lang_admin_no</font>
						</td>				
						</tr>	
						
						
						
						<tr bgcolor=\"f2f2f2\">
						<td width=\"200\">
						<font size=\"2\" face=\"tahoma\">
							$lang_admin_sectionAllowSec:
						</font>
						</td>
						<td>
						<input type=\"radio\" name=\"g2\" value=\"1\" checked><font size=\"2\" face=\"tahoma\">$lang_admin_yes</font>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<input type=\"radio\" name=\"g2\" value=\"0\"><font size=\"2\" face=\"tahoma\">$lang_admin_no</font>
						</td>				
						</tr>																				
						
						
									
						</table>
						<center><table><tr><td heigh=\"30\"><input type=\"submit\" value=\"$lang_admin_add\"></td></tr></table></center>
						</form>
						</div>
						<br>
						
												<div align=\"center\">
													<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\">
														<tr>
															<td height=\"20\"><table><tr>
																<td>
																<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">
																	<tr>
																		<td width=\"16\"><img src=\"../images/icons/icon_bullet.gif\"></td>
																		<td><a name=\"list\"><font color=\"#912F69\" face=\"tahoma\" style=\"font-size: 10pt;\">
															$lang_admin_eBlogSections</font></a></td>
																	</tr>
																</table>
																</td>
																</tr><tr>
																	<td height=\"6\">
																	<img border=\"0\" src=\"../images/subheader_bg.gif\"></td>
																</tr></table></td>
														</tr>
													</table>
												</div>					
						
						<div>
						<table bordercolor=\"#727272\" style=\"border-collapse: collapse\" width=\"100%\" cellSpacing=\"0\" cellPadding=\"3\"  border=\"1\">
						
						
						
						<tr background=\"../images/icons/disc_bar.gif\">
		<td width=\"40\" align=\"center\" background=\"../images/icons/disc_bar.gif\"><font style=\"font-size: 0.8em;\" face=\"Tahoma\" color=\"#ffffff\">$lang_admin_id</font></td>
		<td align=\"center\" background=\"../images/icons/disc_bar.gif\"><font style=\"font-size: 0.8em;\" face=\"Tahoma\" color=\"#ffffff\">$lang_admin_name</font></td>
		<td width=\"60\" align=\"center\" background=\"../images/icons/disc_bar.gif\"><font style=\"font-size: 0.8em;\" face=\"Tahoma\" color=\"#ffffff\">$lang_admin_actions</font></td>
		</tr>
						
						</tr>
						$allRows
						</table>
						</div>
		
		";
		
	
		$static_value = array ($blog_dir, $blog_windows_encoding, $lang_admin_adminPanel, $JAVA_ALERTS, $blog_slogan, $lang_admin_showHomePage, $lang_admin_link_1, $lang_admin_link_2, $lang_admin_link_3, $lang_admin_link_4, $lang_admin_link_5, $lang_admin_link_6, $lang_admin_link_7, $lang_admin_sync, $lang_admin_search,
		
		$lang_admin_quickLinks,$quicklinks,$lang_admin_readDocumentation,
		$lang_admin_notifications, $notifications, $lang_admin_resolve,
		$lang_admin_kc, $kc, $lang_admin_ReadTheAgreement,
		
		
		$lang_admin_footer1,$lang_admin_footer1_1,$lang_admin_footer1_2,$lang_admin_footer1_3,
		$lang_admin_footer2,$lang_admin_footer2_1,$lang_admin_footer2_2,$lang_admin_footer2_3,$lang_admin_footer2_4,
		$lang_admin_footer3,$lang_admin_footer3_1,$lang_admin_footer3_2,
		$lang_admin_footerRights,
		 
		$lang_admin_home, $thisPageNav,
		
		$lang_admin_eBlogAddSections, $sections_form	
		
		);
		$static_name = array ("{blog_dir}","{blog_windows_encoding}", "{title_name}", "{JAVA_ALERTS}", "{blog_slogan}", "{lang_admin_showHomePage}", "{lang_admin_link_1}", "{lang_admin_link_2}", "{lang_admin_link_3}", "{lang_admin_link_4}", "{lang_admin_link_5}", "{lang_admin_link_6}", "{lang_admin_link_7}", "{lang_admin_sync}", "{lang_admin_search}",
		
		"{lang_admin_quickLinks}","{quicklinks}","{lang_admin_readDocumentation}",
		"{lang_admin_notifications}", "{notifications}", "{lang_admin_resolve}",
		"{lang_admin_kc}", "{kc}", "{lang_admin_ReadTheAgreement}",
		
		
		"{lang_admin_footer1}","{lang_admin_footer1_1}","{lang_admin_footer1_2}","{lang_admin_footer1_3}",
		"{lang_admin_footer2}","{lang_admin_footer2_1}","{lang_admin_footer2_2}","{lang_admin_footer2_3}","{lang_admin_footer2_4}",
		"{lang_admin_footer3}","{lang_admin_footer3_1}","{lang_admin_footer3_2}",
		"{blog_rights}",
		 
		"{lang_admin_home}", "{thisPageNav}",
	
		"{lang_admin_eBlogAddSections}", "{sections_form}"			
		
		);	
		
		$header = $new_template->load_template ("../templates/$defaultTemplate/admin/header.html");
		$home = $new_template->load_template ("../templates/$defaultTemplate/admin/sections.html");
		$footer = $new_template->load_template ("../templates/$defaultTemplate/admin/footer.html");		
		$template = $new_template->replace_static($static_name, $static_value, $header.$home.$footer);	
		echo $template;	
	
	}
	
	
	
	// 2: Add new section
	else if($action == "add"){
			$name = $_POST['name'];
			$disc = $_POST['disc'];
			$parent = $_POST['parent'];
			$allowed = $_POST['g1'];
			$doSync = $_POST['g2'];
			
			
			if($parent == "0")
			$parent = "";
			
			$conn = mysql_connect($dbhost, $dbuser, $dbpass);
			mysql_select_db($dbname);
			$newID = 0;
			$query  = "SELECT id FROM eblog_sections ORDER BY id ASC";
			$result = mysql_query($query);
			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{
				$newID = $row['id'];
			}
			$newID++;
		    mysql_query("INSERT INTO eblog_sections  VALUES ('$newID', '$name', '$disc', '$allowed' ,'$parent')");
		    
		    mysql_query("INSERT INTO eblog_sec2sync  VALUES ('$newID', '$doSync')");
		    		    
			mysql_close($conn);
			
			
			
			echo "<meta http-equiv=\"refresh\" content=\"0;url=sections.php#list\">";		
	}
	
	
	// 3: Edit a given section
	else if($action == "edit"){
	
			$conn = mysql_connect($dbhost, $dbuser, $dbpass);
			mysql_select_db($dbname);		
			$parentsArray = array();
			
			$query  = "SELECT id, parent FROM eblog_sections ORDER BY id ASC";
			$result = mysql_query($query);
			$allOptions = "";
			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{				
				$rowID = $row['id'];
				$parentsArray[$rowID]=$row['parent'];
			}
			
						
			
			$query  = "SELECT id, title, disc, parent, allow_comments FROM eblog_sections ORDER BY id ASC";
			$result = mysql_query($query);
			$allOptions = "";
			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{				
				$rowID     = $row['id'];
				$rowName   = $row['title'];
				$rowParent = $row['parent'];
				$myParent =  $parentsArray[$id];
				$myChild =  $parentsArray[$rowID];
				
				
				if($rowID == $id)
				{
				$name	= $row['title'];
				$disc	= $row['disc'];
				$parent	= $row['parent'];
				$allow	= $row['allow_comments'];
					if($allow == 1)
					$radio_1 = "checked";
					else
					$radio_2 = "checked";
				}
				


				if($id != $myChild){
					if($rowID != $id){
						if($rowID == $myParent)
						$allOptions = $allOptions . "<option value=\"$rowID\" selected>$rowName</option>";
						else
						$allOptions = $allOptions . "<option value=\"$rowID\">$rowName</option>";	
					}
				}
				
			}
			
				
			$result = mysql_query("SELECT status FROM eblog_sec2sync WHERE secID = '$id'");	
			$row = mysql_fetch_row($result);
			$syncStatus = $row[0];	
			if($syncStatus == 1)
			$radio_3 = "checked";
			else
			$radio_4 = "checked";								
			
			mysql_close($conn);

		
			echo "<html dir=\"$blog_dir\">
			<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$blog_windows_encoding\">
			<script language=\"javascript\">
			  function checkForm(form){
			  
			  if(form.name.value == \"\"){
			  alert( \"$lang_erorr_code116\" );
			  form.name.focus();
			  return false;
			  }
			  
			  if(form.disc.value == \"\"){
			  alert( \"$lang_erorr_code117\" );
			  form.disc.focus();
			  return false;
			  }
			  
			  return true;
			  }
			  
				function rusure(ID2Delete){
					question = confirm(\"$lang_admin_confirmDeleteSection\")
					if (question !=\"0\"){
						top.location = \"sections.php?action=remove&id=\" + ID2Delete;
					}
				}			  
				
				</script>
				<br>
				<div>
				<form method=\"post\" action=\"sections.php?action=update&id=$id\" onsubmit=\"return checkForm(this);\">
				<table bordercolor=\"#727272\" style=\"border-collapse: collapse\" width=\"100%\" cellSpacing=\"0\" cellPadding=\"5\"  border=\"1\">
				

				
				<tr bgcolor=\"f2f2f2\">
				<td width=\"250\">
				<font size=\"2\" face=\"tahoma\">
					$lang_admin_sectionName:
				</font>
				</td>
				<td>
				<input type=\"text\" name=\"name\" style=\"width:100%; font-family: Tahoma; font-size: 12px; color: #000000; border: 1px solid #000000;\" value=\"$name\">
				</td>				
				</tr>
				
				
				<tr bgcolor=\"dadada\">
				<td width=\"250\">
				<font size=\"2\" face=\"tahoma\">
					$lang_admin_sectionDisc:
				</font>
				</td>
				<td>
				<textarea name=\"disc\" rows=\"5\" MAXLENGTH=\"10000\" style=\"font-family: Tahoma; font-size: 12px; color: #000000; width:100%; border: 1px solid #000000; resize: none;\">$disc</textarea>
				</td>				
				</tr>	

				
				
				<tr bgcolor=\"f2f2f2\">
				<td width=\"250\">
				<font size=\"2\" face=\"tahoma\">
					$lang_admin_sectionParent:
				</font>
				</td>
				<td>
				<select name=\"parent\" style=\"width:100%;  height:21\">
				<option value=\"0\" selected>$lang_admin_none</option>
				$allOptions
				<select>
				</td>				
				</tr>	
				
				
				<tr bgcolor=\"dadada\">
				<td width=\"250\">
				<font size=\"2\" face=\"tahoma\">
					$lang_admin_sectionAllowComment:
				</font>
				</td>
				<td>
				<input type=\"radio\" name=\"g1\" value=\"1\" $radio_1><font size=\"2\" face=\"tahoma\">$lang_admin_yes</font>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input type=\"radio\" name=\"g1\" value=\"0\" $radio_2><font size=\"2\" face=\"tahoma\">$lang_admin_no</font>
				</td>				
				</tr>		
				
				
				<tr bgcolor=\"f2f2f2\">
				<td width=\"200\">
				<font size=\"2\" face=\"tahoma\">
					$lang_admin_sectionAllowSec:
				</font>
				</td>
				<td>
				<input type=\"radio\" name=\"g2\" value=\"1\" $radio_3><font size=\"2\" face=\"tahoma\">$lang_admin_yes</font>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<input type=\"radio\" name=\"g2\" value=\"0\" $radio_4><font size=\"2\" face=\"tahoma\">$lang_admin_no</font>
				</td>				
				</tr>																	
				
				
							
				</table>
				<br>
				<center><input type=\"submit\" value=\"$lang_admin_update\"></center>
				</form>
				</div>
				</html>
				";	
	}

	
	
	// 4: Update given section
	else if($action == "update"){
			$name = $_POST['name'];
			$disc = $_POST['disc'];
			$parent = $_POST['parent'];
			$allowed = $_POST['g1'];
			$doSync = $_POST['g2'];
			

			
			if($parent == "0")
			$parent = "";
			
			$conn = mysql_connect($dbhost, $dbuser, $dbpass);
			mysql_select_db($dbname);

			$sql="UPDATE eblog_sections SET title='$name' WHERE id = '$id'";
			$result=mysql_query($sql);
			
			$sql="UPDATE eblog_sections SET disc='$disc' WHERE id = '$id'";
			$result=mysql_query($sql);
			
			$sql="UPDATE eblog_sections SET allow_comments='$allowed' WHERE id = '$id'";
			$result=mysql_query($sql);
			
			$sql="UPDATE eblog_sections SET parent='$parent' WHERE id = '$id'";
			$result=mysql_query($sql);	
			
			
			$sql="UPDATE eblog_sec2sync SET status='$doSync' WHERE secID = '$id'";
			$result=mysql_query($sql);												
		
			mysql_close($conn);
			echo "<meta http-equiv=\"refresh\" content=\"0;url=sections.php?action=refresh\">";		
	}
	
	
	// 5: Remove given section
	else if($action == "remove"){
	
			$conn = mysql_connect($dbhost, $dbuser, $dbpass);
			mysql_select_db($dbname);
			
			
			mysql_query("DELETE FROM eblog_sections WHERE id=$id");
			
			mysql_query("DELETE FROM eblog_sec2sync WHERE secID=$id");
			
			
			$sql="UPDATE eblog_sections SET parent='' WHERE parent = '$id'";
			$result=mysql_query($sql);
			

			$query  = "SELECT id, sec FROM eblog_topics";
			$result = mysql_query($query);
			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{				
				$rowSEC = $row['sec'];
				$rowID = $row['id'];
				if($rowSEC == $id){
				mysql_query("DELETE FROM eblog_topics WHERE id=$rowID");
						

						$query2  = "SELECT id, topicID FROM eblog_comments";
						$result2 = mysql_query($query2);
						while($row2 = mysql_fetch_array($result2, MYSQL_ASSOC))
						{				
							$topicID = $row2['topicID'];
							$xID = $row2['id'];
							if($topicID == $rowID){
								mysql_query("DELETE FROM eblog_comments WHERE id=$xID");
							}	
						}	
			
			
				}	
			}

			mysql_close($conn);
			
			
			
			echo "<meta http-equiv=\"refresh\" content=\"0;url=sections.php#list\">";		
	}	
	


	// 6: Add new page
	else if($action == "addPage"){
			$name = $_POST['name'];
			$url = $_POST['url'];
			$content = $_POST['content'];
			$status = $_POST['g2'];
			$type = $_POST['g1'];
			$window = $_POST['g3'];
			$visible = $_POST['g4'];

			
			$conn = mysql_connect($dbhost, $dbuser, $dbpass);
			mysql_select_db($dbname);
			$newID = 0;
			
			$query  = "SELECT id FROM eblog_pages ORDER BY id ASC";
			$result = mysql_query($query);
			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{
				$newID = $row['id'];
			}
			$newID++;
			
		    mysql_query("INSERT INTO eblog_pages  VALUES ('$newID', '$name', '$content', '$url' ,'$status', '$type', '$window', '$visible')");
		    
			mysql_close($conn);
			
			
			echo "<meta http-equiv=\"refresh\" content=\"0;url=sections.php?action=pages\">";		
	}
	
	
	// 7: edit given page
	else if($action == "editPage"){
	
			$conn = mysql_connect($dbhost, $dbuser, $dbpass);
			mysql_select_db($dbname);
			
			$query  = "SELECT * FROM eblog_pages ORDER BY id ASC";
			$result = mysql_query($query);
			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{
				$rowID = $row['id'];
				if($rowID == $id)
				{
					$rowTitle = $row['title'];
					$rowStatus = $row['status'];
					$rowContent = $row['content'];
					$rowURL = $row['url'];
					$rowType = $row['type'];
					$rowWindow = $row['window'];
					$rowVisible = $row['visible'];
				}
			}
			mysql_close($conn);
			
			if($rowType == 1){
			$disable2 = "disabled";
			$checked_1_1 = "checked";
			}
			if($rowType == 2){
			$disable1 = "disabled";	
			$checked_1_2 = "checked";
			}	
			
			if($rowStatus == 0)	
			$checked_2_2 = "checked";
			if($rowStatus == 1)	
			$checked_2_1 = "checked";
			
			if($rowWindow == 1)	
			$checked_3_1 = "checked";
			if($rowWindow == 2)	
			$checked_3_2 = "checked";
			
			if($rowVisible == 0)	
			$checked_4_2 = "checked";
			if($rowVisible == 1)	
			$checked_4_1 = "checked";									
						
			echo "
			<html dir=\"$blog_dir\">
			
			  <script language=\"javascript\">
			  function checkForm(form){
			  
			  if(form.name.value == \"\"){
			  alert( \"$lang_erorr_code139\" );
			  form.name.focus();
			  return false;
			  }
			  
			  
			  return true;
			  }		  
				
			function rusure(ID2Delete){
			question = confirm(\"$lang_admin_confirmDeletePage\")
			if (question !=\"0\"){
				top.location = \"sections.php?action=deletePage&id=\" + ID2Delete;
			}
			}
							
			function EnableContent(){
			FullForm.content.disabled=true;
			FullForm.url.disabled=false;											
			}
			
			function EnableURL(){
			FullForm.content.disabled=false;
			FullForm.url.disabled=true;											
			}	
			
				
			  </script>
			
			<div><br>
			<form method=\"post\" action=\"sections.php?action=SavePage&id=$id\" name=\"FullForm\" onsubmit=\"return checkForm(this);\">
			<table bordercolor=\"#727272\" style=\"border-collapse: collapse\" width=\"100%\" cellSpacing=\"0\" cellPadding=\"5\"  border=\"1\">
			
			
			<tr bgcolor=\"f2f2f2\">
			<td width=\"150\">
			<font size=\"2\" face=\"tahoma\">
				$lang_admin_pageName:
			</font>
			</td>
			<td>
			<input type=\"text\" name=\"name\" size=\"57\" style=\"font-family: Tahoma; font-size: 12px; color: #000000; border: 1px solid #000000;\" value=\"$rowTitle\">
			</td>				
			</tr>
			
			
			
			
		<tr bgcolor=\"dadada\">
		<td width=\"150\">
		<font size=\"2\" face=\"tahoma\">
			$lang_admin_pageType:
		</font>
		</td>
		<td>


		<table width=\"100%\" border=\"0\">
		<tr><td width=\"50%\"><input type=\"radio\" name=\"g1\" value=\"1\" onClick=\"EnableURL()\" $checked_1_1><font size=\"2\" face=\"tahoma\">$lang_admin_htmlPage</font></td>
		<td width=\"50%\"><input type=\"radio\" name=\"g1\" onClick=\"EnableContent()\" value=\"2\" $checked_1_2><font size=\"2\" face=\"tahoma\">$lang_admin_webLink</font></td></tr>
		</table>
		
						
		</td>				
		</tr>
		
	
		
		
		
		<tr bgcolor=\"f2f2f2\">
		<td width=\"150\">
		<font size=\"2\" face=\"tahoma\">
			$lang_admin_pageStatus:
		</font>
		</td>
		<td>
		
				
				
		<table width=\"100%\" border=\"0\">
		<tr><td width=\"50%\"><input type=\"radio\" name=\"g2\" value=\"1\" $checked_2_1><font size=\"2\" face=\"tahoma\">$lang_admin_active</font></td>
		<td width=\"50%\"><input type=\"radio\" name=\"g2\" value=\"0\" $checked_2_2><font size=\"2\" face=\"tahoma\">$lang_admin_inactive</font></td></tr>
		</table>				
				
		</td>				
		</tr>	
		
		
		<tr bgcolor=\"dadada\">
		<td width=\"150\">
		<font size=\"2\" face=\"tahoma\">
			$lang_admin_pageWindow:
		</font>
		</td>
		<td>
		
		

		<table width=\"100%\" border=\"0\">
		<tr><td width=\"50%\"><input type=\"radio\" name=\"g3\" value=\"1\" $checked_3_1><font size=\"2\" face=\"tahoma\">$lang_admin_sameWindow</font></td>
		<td width=\"50%\"><input type=\"radio\" name=\"g3\" value=\"2\"  $checked_3_2><font size=\"2\" face=\"tahoma\">$lang_admin_newWindow</font></td></tr>
		</table>
		
		</td>				
		</tr>	
		
		
		
		
		<tr bgcolor=\"f2f2f2\">
		<td width=\"150\">
		<font size=\"2\" face=\"tahoma\">
			$lang_admin_addToMainMenu:
		</font>
		</td>
		<td>
		
		<table width=\"100%\" border=\"0\">
		<tr><td width=\"50%\"><input type=\"radio\" name=\"g4\" value=\"1\" $checked_4_1><font size=\"2\" face=\"tahoma\">$lang_admin_yes</font></td>
		<td width=\"50%\"><input type=\"radio\" name=\"g4\" value=\"0\" $checked_4_2><font size=\"2\" face=\"tahoma\">$lang_admin_no</font></td></tr>
		</table>
		
		
				
		</td>				
		</tr>				
			
				
			
			
			<tr bgcolor=\"dadada\">
			<td width=\"150\">
			<font size=\"2\" face=\"tahoma\">
				$lang_admin_pageContent:
			</font>
			</td>
			<td>
			<textarea name=\"content\" cols=\"55\" rows=\"5\" style=\"font-family: Tahoma; font-size: 12px; color: #000000; border: 1px solid #000000; resize: none;\" $disable1>$rowContent</textarea>
			</td>				
			</tr>
			
			
			
			<tr bgcolor=\"f2f2f2\">
			<td width=\"150\">
			<font size=\"2\" face=\"tahoma\">
				$lang_admin_pageURL:
			</font>
			</td>
			<td>
			<input type=\"text\" name=\"url\" size=\"57\" style=\"font-family: Tahoma; font-size: 12px; color: #000000; border: 1px solid #000000;\" value=\"$rowURL\" $disable2>
			</td>				
			</tr>								
					
	
			</table>
			<br>
			<center><input type=\"submit\" value=\"$lang_admin_update\"></center>
			</form>
			</div>
			</html>
	";	
	}
	
	
	// 8: Delete given page
	else if($action == "deletePage"){
		$conn = mysql_connect($dbhost, $dbuser, $dbpass);
		mysql_select_db($dbname);
		mysql_query("DELETE FROM eblog_pages WHERE id=$id");
		mysql_close($conn);
		echo "<meta http-equiv=\"refresh\" content=\"0;url=sections.php?action=pages\">";	
	}		
	
	
	// 9: Save given page
	else if($action == "SavePage"){
		$name = $_POST['name'];
		$url = $_POST['url'];
		$content = $_POST['content'];
		$status = $_POST['g2'];
		$type = $_POST['g1'];
		$window = $_POST['g3'];
		$visible = $_POST['g4'];

		
		$conn = mysql_connect($dbhost, $dbuser, $dbpass);
		mysql_select_db($dbname);
		
		$sql="UPDATE eblog_pages SET title='$name' WHERE id = '$id'";
		$result=mysql_query($sql);
		
		if(!empty($url)){
		$sql="UPDATE eblog_pages SET url='$url' WHERE id = '$id'";
		$result=mysql_query($sql);
		}
		
		if(!empty($content)){
		$sql="UPDATE eblog_pages SET content='$content' WHERE id = '$id'";
		$result=mysql_query($sql);
		}
		
		$sql="UPDATE eblog_pages SET status='$status' WHERE id = '$id'";
		$result=mysql_query($sql);
		
		$sql="UPDATE eblog_pages SET type='$type' WHERE id = '$id'";
		$result=mysql_query($sql);
		
		$sql="UPDATE eblog_pages SET window='$window' WHERE id = '$id'";
		$result=mysql_query($sql);
		
		$sql="UPDATE eblog_pages SET visible='$visible' WHERE id = '$id'";
		$result=mysql_query($sql);							
											
		mysql_close($conn);
		
		echo "
		<script type=\"text/javascript\">
		 top.parent.location = \"sections.php?action=pages\";
		</script>
		";	
	}	
	
	
	// 10: List of pages
	else if($action == "pages")
	{
		// construct page map
		$thisPageNav = "&nbsp;<img src=\"../images/icons/prev_$blog_dir.gif\">&nbsp;<a href=\"sections.php\"><font face=\"tahoma\" style=\"font-size: 10pt;\">$lang_admin_link_3</font></a>&nbsp;<img src=\"../images/icons/prev_$blog_dir.gif\">&nbsp;<a href=\"sections.php?action=pages\"><font face=\"tahoma\" style=\"font-size: 10pt;\">$lang_admin_managingPages</font></a>";
		
		
		// construct quick links menu (go to each section in the form)
		$quicklinks = "<table width=\"100%\" border=\"0\" cellspacing=\"5\" cellpadding=\"1\">
		
							 <tr><td valign =\"top\" width=\"22\"><img src=\"../images/icons/icon_bullet.gif\"></td>
							 <td><a href=\"sections.php#add\"><font style=\"font-size: 0.7em;\" face=\"Tahoma\">$lang_admin_addSection</font></a></td>
							 </tr>
							 
							 
							 <tr><td valign =\"top\" width=\"22\"><img src=\"../images/icons/icon_bullet.gif\"></td>
							 <td><a href=\"sections.php#list\"><font style=\"font-size: 0.7em;\" face=\"Tahoma\">$lang_admin_sectionsCat1</font></a></td>
							 </tr>
							 
							 
							 <tr><td valign =\"top\" width=\"22\"><img src=\"../images/icons/icon_bullet.gif\"></td>
							 <td><a href=\"#addPages\"><font style=\"font-size: 0.7em;\" face=\"Tahoma\">$lang_admin_sectionsCat3</font></a></td>
							 </tr>
							 
							 
							 <tr><td valign =\"top\" width=\"22\"><img src=\"../images/icons/icon_bullet.gif\"></td>
							 <td><a href=\"#top\"><font style=\"font-size: 0.7em;\" face=\"Tahoma\">$lang_admin_sectionsCat4</font></a></td>
							 </tr>
							 							 
							 
							 <tr><td valign =\"top\" width=\"22\"><img src=\"../images/icons/icon_bullet.gif\"></td>
							 <td><a href=\"topics.php?action=add\"   title=\"$lang_admin_addTopic\" rel=\"gb_page_center[640, 500]\"><font style=\"font-size: 0.7em;\" face=\"Tahoma\">$lang_admin_addTopic</font></a></td>
							 </tr>
							 							 
							 
							 <tr><td valign =\"top\" width=\"22\"><img src=\"../images/icons/icon_bullet.gif\"></td>
							 <td><a href=\"topics.php\"><font style=\"font-size: 0.7em;\" face=\"Tahoma\">$lang_admin_showTopic</font></a></td>
							 </tr>	
							 					 					 				 					 					 
							 							 
							 </table>";
							 
							 
		$list_name = $lang_admin_managingPages;
		
		// collect pages
		$conn = mysql_connect($dbhost, $dbuser, $dbpass);
		mysql_select_db($dbname);
		
		$counter = 0;
		$query  = "SELECT * FROM eblog_pages ORDER BY id ASC";
		$result = mysql_query($query);
		$allPages = "<table bordercolor=\"#727272\" style=\"border-collapse: collapse\" width=\"100%\" cellSpacing=\"0\" cellPadding=\"4\"  border=\"1\">
		
		<tr background=\"../images/icons/disc_bar.gif\">
		<td width=\"40\" align=\"center\" background=\"../images/icons/disc_bar.gif\"><font style=\"font-size: 0.8em;\" face=\"Tahoma\" color=\"#ffffff\">$lang_admin_id</font></td>
		<td align=\"center\"background=\"../images/icons/disc_bar.gif\" ><font style=\"font-size: 0.8em;\" face=\"Tahoma\" color=\"#ffffff\">$lang_admin_name</font></td>
		<td width=\"120\" align=\"center\" background=\"../images/icons/disc_bar.gif\"><font style=\"font-size: 0.8em;\" face=\"Tahoma\" color=\"#ffffff\">$lang_admin_status</font></td>
		<td width=\"60\" align=\"center\" background=\"../images/icons/disc_bar.gif\"><font style=\"font-size: 0.8em;\" face=\"Tahoma\" color=\"#ffffff\">$lang_admin_actions</font></td>
		</tr>";
		
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			$rowID = $row['id'];
			$rowTitle = $row['title'];
			$rowStatus = $row['status'];
			
			$reminder = $counter%2;
			
			if($reminder == 0)
			$bgColor="#dadada";
			else
			$bgColor = "#f2f2f2";
			
			
			if($rowStatus == 0)
			$toStatus = $lang_admin_inactive;
			if($rowStatus == 1)
			$toStatus = $lang_admin_active;	
			
			$allPages = $allPages . "<tr bgcolor=\"$bgColor\"><td align=\"center\"><font face=\"tahoma\" size=\"2\">$rowID</font></td><td><font face=\"tahoma\" size=\"2\">$rowTitle</font></td><td align=\"center\"><font face=\"tahoma\" size=\"2\">$toStatus</font></td><td align=\"center\">
			<a href=\"sections.php?action=editPage&id=$rowID\" title=\"$lang_admin_editPage\" rel=\"gb_page_center[640, 500]\"><img src=\"../images/icons/icon_fix.gif\" border=\"0\" title=\"$lang_admin_edit\"></a>
			<a href=\"#\" onClick=\"rusure($rowID); return false;\"><img src=\"../images/icons/icon_remove.gif\" border=\"0\" title=\"$lang_admin_delete\"></a>
			</td></tr>";
			$counter++;
		}
		$allPages = $allPages . "</table>";
		
		
		if($counter < 1)
		{
			$list_content = $list_content . "<font face=\"tahoma\" size=\"2\">$lang_admin_noPages</font><br><br>";
			$allPages = "";
		}	
					
		$list_content = $list_content . $allPages . "
			<br>
			<br>
			  <script language=\"javascript\">
			  function checkForm(form){
			  
			  if(form.name.value == \"\"){
			  alert( \"$lang_erorr_code139\" );
			  form.name.focus();
			  return false;
			  }
			  
			  
			  return true;
			  }		  
				
			function rusure(ID2Delete){
			question = confirm(\"$lang_admin_confirmDeletePage\")
			if (question !=\"0\"){
				top.location = \"sections.php?action=deletePage&id=\" + ID2Delete;
			}
			}
							
			function EnableContent(){
			FullForm.content.disabled=true;
			FullForm.url.disabled=false;											
			}
			
			function EnableURL(){
			FullForm.content.disabled=false;
			FullForm.url.disabled=true;											
			}	
			
				
			  </script>
			  
				<div>
				<form method=\"post\" action=\"sections.php?action=addPage\" name=\"FullForm\" onsubmit=\"return checkForm(this);\">
				<table bordercolor=\"#727272\" style=\"border-collapse: collapse\" width=\"100%\" cellSpacing=\"0\" cellPadding=\"5\"  border=\"1\">
				
				<tr bgcolor=\"9b196c\" background=\"../images/icons/disc_bar.gif\">
				<td colspan = \"2\" background=\"../images/icons/disc_bar.gif\">
				<font color=\"#ffffff\" size=\"2\" face=\"Tahoma\">
				<a name=\"addPages\">$lang_admin_addPage</a>
				</font>
				</td>
				</tr>
				
				<tr bgcolor=\"f2f2f2\">
				<td width=\"150\">
				<font size=\"2\" face=\"tahoma\">
					$lang_admin_pageName:
				</font>
				</td>
				<td>
				<input type=\"text\" name=\"name\" size=\"67\" style=\"font-family: Tahoma; font-size: 12px; color: #000000; border: 1px solid #000000;\">
				</td>				
				</tr>
				
				
				
				
				<tr bgcolor=\"dadada\">
				<td width=\"150\">
				<font size=\"2\" face=\"tahoma\">
					$lang_admin_pageType:
				</font>
				</td>
				<td>
		
		
				<table width=\"100%\" border=\"0\">
				<tr><td width=\"50%\"><input type=\"radio\" name=\"g1\" value=\"1\" onClick=\"EnableURL()\" checked><font size=\"2\" face=\"tahoma\">$lang_admin_htmlPage</font></td>
				<td width=\"50%\"><input type=\"radio\" name=\"g1\" onClick=\"EnableContent()\" value=\"2\"><font size=\"2\" face=\"tahoma\">$lang_admin_webLink</font></td></tr>
				</table>
				
								
				</td>				
				</tr>
				
			
				
				
				
				<tr bgcolor=\"f2f2f2\">
				<td width=\"150\">
				<font size=\"2\" face=\"tahoma\">
					$lang_admin_pageStatus:
				</font>
				</td>
				<td>
				
						
						
				<table width=\"100%\" border=\"0\">
				<tr><td width=\"50%\"><input type=\"radio\" name=\"g2\" value=\"1\" checked><font size=\"2\" face=\"tahoma\">$lang_admin_active</font></td>
				<td width=\"50%\"><input type=\"radio\" name=\"g2\" value=\"0\"><font size=\"2\" face=\"tahoma\">$lang_admin_inactive</font></td></tr>
				</table>				
						
				</td>				
				</tr>	
				
				
				<tr bgcolor=\"dadada\">
				<td width=\"150\">
				<font size=\"2\" face=\"tahoma\">
					$lang_admin_pageWindow:
				</font>
				</td>
				<td>
				
				
		
				<table width=\"100%\" border=\"0\">
				<tr><td width=\"50%\"><input type=\"radio\" name=\"g3\" value=\"1\"><font size=\"2\" face=\"tahoma\">$lang_admin_sameWindow</font></td>
				<td width=\"50%\"><input type=\"radio\" name=\"g3\" value=\"2\" checked><font size=\"2\" face=\"tahoma\">$lang_admin_newWindow</font></td></tr>
				</table>
				
				</td>				
				</tr>	
				
				
				
				
				<tr bgcolor=\"f2f2f2\">
				<td width=\"150\">
				<font size=\"2\" face=\"tahoma\">
					$lang_admin_addToMainMenu:
				</font>
				</td>
				<td>
				
				<table width=\"100%\" border=\"0\">
				<tr><td width=\"50%\"><input type=\"radio\" name=\"g4\" value=\"1\" checked><font size=\"2\" face=\"tahoma\">$lang_admin_yes</font></td>
				<td width=\"50%\"><input type=\"radio\" name=\"g4\" value=\"0\"><font size=\"2\" face=\"tahoma\">$lang_admin_no</font></td></tr>
				</table>
				
				
						
				</td>				
				</tr>					
				
				
					
				
				
				<tr bgcolor=\"dadada\">
				<td width=\"150\">
				<font size=\"2\" face=\"tahoma\">
					$lang_admin_pageContent:
				</font>
				</td>
				<td>
				<textarea name=\"content\" cols=\"65\" rows=\"5\" style=\"font-family: Tahoma; font-size: 12px; color: #000000; border: 1px solid #000000; resize: none;\"></textarea>
				</td>				
				</tr>
				
				
				
				<tr bgcolor=\"f2f2f2\">
				<td width=\"150\">
				<font size=\"2\" face=\"tahoma\">
					$lang_admin_pageURL:
				</font>
				</td>
				<td>
				<input type=\"text\" name=\"url\" size=\"67\" style=\"font-family: Tahoma; font-size: 12px; color: #000000; border: 1px solid #000000;\" disabled>
				</td>				
				</tr>								
						
		
				</table>
				<br>
				<center><input type=\"submit\" value=\"$lang_admin_add\"></center>
				</form>
				</div>
		";
			
		mysql_close($conn);
	
		$static_value = array ($blog_dir, $blog_windows_encoding, $lang_admin_adminPanel, $JAVA_ALERTS, $blog_slogan, $lang_admin_showHomePage, $lang_admin_link_1, $lang_admin_link_2, $lang_admin_link_3, $lang_admin_link_4, $lang_admin_link_5, $lang_admin_link_6, $lang_admin_link_7, $lang_admin_sync, $lang_admin_search,
		
		$lang_admin_quickLinks,$quicklinks,$lang_admin_readDocumentation,
		$lang_admin_notifications, $notifications, $lang_admin_resolve,
		$lang_admin_kc, $kc, $lang_admin_ReadTheAgreement,
		
		
		$lang_admin_footer1,$lang_admin_footer1_1,$lang_admin_footer1_2,$lang_admin_footer1_3,
		$lang_admin_footer2,$lang_admin_footer2_1,$lang_admin_footer2_2,$lang_admin_footer2_3,$lang_admin_footer2_4,
		$lang_admin_footer3,$lang_admin_footer3_1,$lang_admin_footer3_2,
		$lang_admin_footerRights,
		 
		$lang_admin_home, $thisPageNav,
		
		$list_name, $list_content	
		
		);
		$static_name = array ("{blog_dir}","{blog_windows_encoding}", "{title_name}", "{JAVA_ALERTS}", "{blog_slogan}", "{lang_admin_showHomePage}", "{lang_admin_link_1}", "{lang_admin_link_2}", "{lang_admin_link_3}", "{lang_admin_link_4}", "{lang_admin_link_5}", "{lang_admin_link_6}", "{lang_admin_link_7}", "{lang_admin_sync}", "{lang_admin_search}",
		
		"{lang_admin_quickLinks}","{quicklinks}","{lang_admin_readDocumentation}",
		"{lang_admin_notifications}", "{notifications}", "{lang_admin_resolve}",
		"{lang_admin_kc}", "{kc}", "{lang_admin_ReadTheAgreement}",
		
		
		"{lang_admin_footer1}","{lang_admin_footer1_1}","{lang_admin_footer1_2}","{lang_admin_footer1_3}",
		"{lang_admin_footer2}","{lang_admin_footer2_1}","{lang_admin_footer2_2}","{lang_admin_footer2_3}","{lang_admin_footer2_4}",
		"{lang_admin_footer3}","{lang_admin_footer3_1}","{lang_admin_footer3_2}",
		"{blog_rights}",
		 
		"{lang_admin_home}", "{thisPageNav}",
	
		"{list_name}", "{list_content}"			
		
		);	
		
		$header = $new_template->load_template ("../templates/$defaultTemplate/admin/header.html");
		$home = $new_template->load_template ("../templates/$defaultTemplate/admin/list.html");
		$footer = $new_template->load_template ("../templates/$defaultTemplate/admin/footer.html");		
		$template = $new_template->replace_static($static_name, $static_value, $header.$home.$footer);	
		echo $template;		
	}						
	
	
	// 11: Force window to refresh
	else if($action == "refresh"){
		echo " 
		<script type=\"text/javascript\">
		top.parent.location = \"sections.php?section=list\";
		</script>
		";	
	}	
	
	
	// 12: else, show error message
	else
	{
		echo "<meta http-equiv=\"refresh\" content=\"0;url=index.php\">";
	}
	
	
 }
   else{   
    echo "<meta http-equiv=\"refresh\" content=\"0;url=index.php\">";
 }
			
?>
Return current item: eBlog