<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	// Manage Boards and Categories
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_messageboard.gif" width="26" height="18"> '.$MsgText[2][4];
	$BrowserTitle = $MsgText[2][4];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[2][4];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[204] == 'y') {
	
			$PageContents = '<br><a href="#new">'.$MsgText[2][12].'</a><br><br><br><b>'.$MsgText[2][13].'</b>';
			
			
			
			$query = "select * from `".$Settings['DBPrefix']."mb-Settings`";
			$result = mysql_query($query) or die (mysql_error());
			while ($row = mysql_fetch_array($result)) {
				$mbSettings[$row['Name']] = $row['Value'];
			}
			
			
			$OverridesArray = explode('%%',$mbSettings['ColorOverrides']);
			
		
			if ($OverridesArray[1] != '') { 
			$Colors['MBBorder'] = $OverridesArray[1];			// main border
			}
			if ($OverridesArray[2] != '') {
			$Colors['MBBG'] = $OverridesArray[2];				// main background
			}
			if ($OverridesArray[3] != '') {
			$Colors['MBAlternateBG'] = $OverridesArray[3];				// alternate background color
			}
			if ($OverridesArray[4] != '') {
			$Colors['MBSpacerLine'] = $OverridesArray[4];		// spacer line between categories and messages in a thread
			}
			if ($OverridesArray[5] != '') {
			$Colors['MBHeadingText'] = $OverridesArray[5];		// top headings text
			}
			if ($OverridesArray[6] != '') {
			$Colors['MBHeadingBG'] = $OverridesArray[6];			// top headings background
			}
			if ($OverridesArray[7] != '') {
			$Colors['MBText'] = $OverridesArray[7];				// main text
			}
			if ($OverridesArray[8] != '') {
			$Colors['MBQCBorder'] = $OverridesArray[8];			// quote/code sections border
			}
			if ($OverridesArray[9] != '') {
			$Colors['MBQCBG'] = $OverridesArray[9];			// quote/code sections background
			}
			if ($OverridesArray[10] != '') {
			$Colors['MBQCText'] = $OverridesArray[10];				// quote/code sections text
			}
			
			
			
			$query = "select Level,Description from `".$Settings['DBPrefix']."core-Permissions` where Level<=".$UserLevel;
	   		$result = mysql_query($query) or die (mysql_error());
			while ($row = mysql_fetch_array($result)) {
				$LevelDescriptions[$row['Level']] = $row['Description'];
			}
		
			$PermissionsDropdown = '<option value="0" selected> 0 - '.$MsgText[0][162].'</option>';
			for ($i = 1; $i <= $UserLevel; $i++) {
				if ($LevelDescriptions[$i] != '') {
					$PermissionsDropdown .= '<option value="'.$i.'"> '.$i.' - '.$LevelDescriptions[$i].'</option>';
				}
				else {
					$PermissionsDropdown .= '<option value="'.$i.'"> '.$i.'</option>';
				}
			}
			
			
			
		$query = "select * from `".$Settings['DBPrefix']."mb-Categories` where MinLevel <= ".$UserLevel." order by CategoryOrder asc, Title asc";
		$result = mysql_query($query) or die (mysql_error());
		while ($row = mysql_fetch_array($result)) {
			$CategoryIDs[] = $row['RecordNumber'];
			$CategoryTitle[$row['RecordNumber']] = $row['Title'];
			$CategoryDescription[$row['RecordNumber']] = $row['Description'];
			
			$CatMinLevels[$row['RecordNumber']] = $row['MinLevel'];
			
			$CatsCount++;			
		}
		
		
		$query = "select * from `".$Settings['DBPrefix']."mb-Boards` where MinLevel <= ".$UserLevel." order by BoardOrder asc, Title asc";
		$result = mysql_query($query) or die (mysql_error());
		while ($row = mysql_fetch_array($result)) {
			$BoardID[$row['Category']][] = $row['RecordNumber'];
			$BoardTitle[$row['Category']][] = $row['Title'];
			$BoardDescription[$row['Category']][] = $row['Description'];
			
			$MinLevels[$row['Category']][] = $row['MinLevel'];
	
			
		}
		
		
		$BoardsList .= '<table width="100%" border="0" cellspacing="1" cellpadding="0"><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>

				<td bgcolor="'.$Colors['BG'].'" width="55%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['Text'].'"><b>'.$MsgText[2][14].'</b><br><font size="'.($FontSize-1).'">'.$MsgText[2][15].'</font></td></tr></table></td>

				<td bgcolor="'.$Colors['BG'].'" width="15%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['Text'].'">'.$MsgText[2][16].'</td></tr></table></td>

				<td bgcolor="'.$Colors['BG'].'" width="15%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['Text'].'">'.$MsgText[2][17].'</td></tr></table></td>

				<td bgcolor="'.$Colors['BG'].'" width="15%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['Text'].'">'.$MsgText[0][155].' / '.$MsgText[0][156].'</td></tr></table></td>

				</tr></table></td></tr></table>
				
				<table width="100%" border="0" cellspacing="1" cellpadding="0">';
		
				
		
		for ($i = 0; $i < count($CategoryIDs); $i++) {
			//if (count($BoardTitle[$CategoryIDs[$i]]) > 0) {
			
			if (count($CategoryIDs) > 1) {
				if ($i == 0) {
				// first one
					$OrderLinks = '<a href="'.$MainURL.'/admin/messageboard_catorder/'.$CategoryIDs[$i].'/down"><img src="'.$TemplateImagesURL.'/admin/arrow_down_lt.gif" border="0" alt="'.$MsgText[2][18].'"></a>';
				}
				else if ($i == (count($CategoryIDs)-1)) {
				// last one
					$OrderLinks = '<a href="'.$MainURL.'/admin/messageboard_catorder/'.$CategoryIDs[$i].'/up"><img src="'.$TemplateImagesURL.'/admin/arrow_up_lt.gif" border="0" alt="'.$MsgText[2][19].'"></a>';
				}
				else {
				// middle ones
					$OrderLinks = '<a href="'.$MainURL.'/admin/messageboard_catorder/'.$CategoryIDs[$i].'/up"><img src="'.$TemplateImagesURL.'/admin/arrow_up_lt.gif" border="0" alt="'.$MsgText[2][19].'"></a><a href="'.$MainURL.'/admin/messageboard_catorder/'.$CategoryIDs[$i].'/down"><img src="'.$TemplateImagesURL.'/admin/arrow_down_lt.gif" border="0" alt="'.$MsgText[2][18].'"></a>';
				}
			}
			else {
				$OrderLinks = '-';
			}
			
				
				$BoardsList .= '<tr><td><table width="100%" border="0" cellspacing="0" cellpadding="1"><tr><td bgcolor="'.$Colors['MBBorder'].'"><table width="100%" border="0" cellspacing="1" cellpadding="0"><tr><td bgcolor="'.$Colors['BG'].'"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>

				<td bgcolor="'.$Colors['MBHeadingBG'].'" width="55%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBHeadingText'].'"><b>'.$CategoryTitle[$CategoryIDs[$i]].'</b><br><font size="'.($FontSize-1).'">'.$CategoryDescription[$CategoryIDs[$i]].'</font></td></tr></table></td>

				<td bgcolor="'.$Colors['MBHeadingBG'].'" width="15%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBHeadingText'].'">'.$CatMinLevels[$CategoryIDs[$i]].'</td></tr></table></td>

				<td bgcolor="'.$Colors['MBHeadingBG'].'" width="15%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBHeadingText'].'">'.$OrderLinks.'</td></tr></table></td>

				<td bgcolor="'.$Colors['MBHeadingBG'].'" width="15%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.($FontSize-1).'" color="'.$Colors['MBHeadingText'].'"><a href="'.$MainURL.'/admin/messageboard_catedit/'.$CategoryIDs[$i].'"><font color="'.$Colors['MBHeadingText'].'">'.$MsgText[0][155].'</font></a> / <a href="'.$MainURL.'/admin/messageboard_catdelete/'.$CategoryIDs[$i].'"><font color="'.$Colors['MBHeadingText'].'">'.$MsgText[0][156].'</font></a></td></tr></table></td>

				</tr>

				<tr><td colspan="4" height="2" bgcolor="'.$Colors['MBBorder'].'"><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="2" alt=""></td></tr>';


				$BGColor = $Colors['MBBG'];		

			
				for ($j = 0; $j < count($BoardTitle[$CategoryIDs[$i]]); $j++) {
				
					if (count($BoardTitle[$CategoryIDs[$i]]) > 1) {
					
						if ($j == 0) {
						// first one
							$OrderLinks = '<a href="'.$MainURL.'/admin/messageboard_boardorder/'.$BoardID[$CategoryIDs[$i]][$j].'/down"><img src="'.$TemplateImagesURL.'/admin/arrow_down.gif" border="0" alt="'.$MsgText[2][18].'"></a>';
						}
						else if ($j == (count($BoardTitle[$CategoryIDs[$i]])-1)) {
						// last one
							$OrderLinks = '<a href="'.$MainURL.'/admin/messageboard_boardorder/'.$BoardID[$CategoryIDs[$i]][$j].'/up"><img src="'.$TemplateImagesURL.'/admin/arrow_up.gif" border="0" alt="'.$MsgText[2][19].'"></a>';
						}
						else {
						// middle ones
							$OrderLinks = '<a href="'.$MainURL.'/admin/messageboard_boardorder/'.$BoardID[$CategoryIDs[$i]][$j].'/up"><img src="'.$TemplateImagesURL.'/admin/arrow_up.gif" border="0" alt="'.$MsgText[2][19].'"></a><a href="'.$MainURL.'/admin/messageboard_boardorder/'.$BoardID[$CategoryIDs[$i]][$j].'/down"><img src="'.$TemplateImagesURL.'/admin/arrow_down.gif" border="0" alt="'.$MsgText[2][18].'"></a>';
						}
					}
					else {
						$OrderLinks = '-';
					}				
	
	
					$BoardsList .= '<tr>
					
					<td height="100%" width="55%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td valign="middle" bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'"><b>'.$BoardTitle[$CategoryIDs[$i]][$j].'</b><br><font size="'.($FontSize-1).'">'.$BoardDescription[$CategoryIDs[$i]][$j].'</font></font></td></tr></table></td>

					<td height="100%" width="15%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle" bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'">'.$MinLevels[$CategoryIDs[$i]][$j].'</font></td></tr></table></td>

					<td height="100%" width="15%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle" bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'">'.$OrderLinks.'</font></td></tr></table></td>

					<td height="100%" width="15%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle" bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.($FontSize-1).'" color="'.$Colors['MBText'].'"><a href="'.$MainURL.'/admin/messageboard_boardedit/'.$BoardID[$CategoryIDs[$i]][$j].'"><font color="'.$Colors['MBText'].'">'.$MsgText[0][155].'</font></a> / <a href="'.$MainURL.'/admin/messageboard_boarddelete/'.$BoardID[$CategoryIDs[$i]][$j].'"><font color="'.$Colors['MBText'].'">'.$MsgText[0][156].'</font></a></font></td></tr></table></td>

					</tr>';
					
					
					if ($BGColor == $Colors['MBBG']) {
						$BGColor = $Colors['MBAlternateBG'];
					}
					else {
						$BGColor = $Colors['MBBG'];
					}
					
			
				}
				
				$BoardsList .= '</table></td></tr></table></td></tr></table></td></tr>';
				
				
				if ($i < (count($CategoryIDs)-1)) {
					$BoardsList .= '<tr><td height="1" align="center"><table width="98%" border="0" cellpadding="0" cellspacing="0"><tr><td height="1" bgcolor="'.$Colors['MBSpacerLine'].'"><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""></td></tr></table></td></tr>';
				}
			
			//}
		}
	
	
		$BoardsList .= '</table><br>';
	
			
			$query2 = "select * from `".$Settings['DBPrefix']."mb-Categories` order by CategoryOrder asc, Title asc";
			$result2 = mysql_query($query2) or die (mysql_error());
			while ($row2 = mysql_fetch_array($result2)) {
				$CategoriesDropdown .= '<option value="'.$row2['RecordNumber'].'"> '.$row2['Title'].'</option>';
			}
				

			
			if ($CatsCount > 0) {
				$NewBoardPrint = '<form action="'.$MainURL.'/admin/messageboard_newboard" method="post">
<b>'.$MsgText[2][20].':</b><br><input type="text" name="Title" size="50"><br><br><b>'.$MsgText[2][21].':</b><br><input type="text" name="Description" size="70"><br><br><b>'.$MsgText[2][22].':</b><br><select name="Category">'.$CategoriesDropdown.'</select><br><br><b>'.$MsgText[2][23].':</b><br><input type="text" name="BoardOrder" size="5"><br><font size="1">'.$MsgText[2][138].'<br></font><br><b>'.$MsgText[2][24].':</b><br><select name="MinLevel">'.$PermissionsDropdown.'</select><br><br><br><input type="submit" value="'.$MsgText[2][25].'"></form>';
			}
			else {
				$NewBoardPrint = '<font color="#ff0000">'.$MsgText[2][26].'<br></font>';
			}
			

			$PageContents = '<br><a href="#new">'.$MsgText[2][12].'</a><br><br><br><b>'.$MsgText[2][13].':</b><br><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""><br>'.$BoardsList.'<br><br><br><a name="new"></a><b>'.$MsgText[2][27].'</b><br>'.$NewBoardPrint.'<br><br><b>'.$MsgText[2][28].'</b><br><form action="'.$MainURL.'/admin/messageboard_newcategory" method="post">
<b>'.$MsgText[2][20].':</b><br><input type="text" name="Title" size="50"><br><br><b>'.$MsgText[2][21].':</b><br><input type="text" name="Description" size="70"><br><br><b>'.$MsgText[2][23].':</b><br><input type="text" name="CategoryOrder" size="5"><br><font size="1">'.$MsgText[2][138].'<br></font><br><b>'.$MsgText[2][24].':</b><br><select name="MinLevel">'.$PermissionsDropdown.'</select><br><br><br><input type="submit" value="'.$MsgText[2][29].'"></form>';
			
	
	
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}
	

	// ========================================================================================




?>
