<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* 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.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
if (!defined('ADMIN_FILE') && !defined('ADMIN_MAX')) {
	die ("Access Denied");
}
if ($acces == 1) {
if($admintest && $adminsecu)  {

	OpenHeader(_BLOCKMGR);
		$bid = $db->XMFnum($bid);
		$row = $db->sql_fetchrow($db->sql_query("select * from ".TABLE_BLOCKS." where bid='$bid'"));
        $groups = $row['groups'];
		$bkey = stripslashes($row['bkey']);
		$title = stripslashes($row['title']);
		$content = stripslashes($row['content']);
		$url = stripslashes($row['url']);
		$bposition = stripslashes($row['bposition']);
		$weight = $db->XMFnum($row['weight']);
		$active = $db->XMFbin($row['active']);
		$refresh = $db->XMFnum($row['refresh']);
		$blanguage = stripslashes($row['blanguage']);
		$blockfile = stripslashes($row['blockfile']);
		$view = $db->XMFnum($row['view']);
		$expire = $db->XMFnum($row['expire']);
		$action = $db->XMFnum($row['action']);
		$subscription = $db->XMFbin($row['subscription']);
		if ($url != "") {
			$type = _RSSCONTENT;
		} elseif ($blockfile != "") {
			$type = _BLOCKFILE;
		}
		Max_OpenTable();
		echo "<center><font class=\"option\"><b>"._BLOCK.": $title $type</b></font></center><br /><br />"
		."<form action=\"".$admin_file.".php\" method=\"post\">"
		."<table border=\"0\" width=\"100%\">"
		."<tr><td>"._TITLE.":</td><td><input type=\"text\" name=\"title\" size=\"30\" maxlength=\"60\" value=\"$title\"></td></tr>";
		if ($blockfile != "") {
			echo "<tr><td>"._FILENAME.":</td><td>"
			."<select name=\"blockfile\">";
			$blocksdir = dir("blocks");
			while($func=$blocksdir->read()) {
				if(substr($func, 0, 6) == "block-") {
					$blockslist .= "$func ";
				}
			}
			closedir($blocksdir->handle);
			$blockslist = explode(" ", $blockslist);
			sort($blockslist);
			for ($i=0; $i < sizeof($blockslist); $i++) {
				if($blockslist[$i]!="") {
					$bl = ereg_replace("block-","",$blockslist[$i]);
					$bl = ereg_replace(".php","",$bl);
					$bl = ereg_replace("_"," ",$bl);
					echo "<option value=\"$blockslist[$i]\" ";
					if ($blockfile == $blockslist[$i]) { echo "selected"; }
					echo ">$bl</option>\n";
				}
			}
			echo "</select>&nbsp;&nbsp;<font class=\"tiny\">"._FILEINCLUDE."</font></td></tr>";
		} else {
			if ($url != "") {
				echo "<tr><td>"._RSSFILE.":</td><td><input type=\"text\" name=\"url\" size=\"30\" maxlength=\"200\" value=\"$url\">&nbsp;&nbsp;<font class=\"tiny\">"._ONLYHEADLINES."</font></td></tr>";
			} else {
				echo "<tr><td>"._CONTENT.":</td><td><textarea name=\"content\" cols=\"70\" rows=\"15\">$content</textarea></td></tr>";
			}
		}
		$oldposition = $bposition;
		echo "<input type=\"hidden\" name=\"bposition\" value=\"$oldposition\">";
		echo "<input type=\"hidden\" name=\"page\" value=\"$page\">";
		echo "<input type=\"hidden\" name=\"wb_name\" value=\"$wb_name\">";
		if ($multilingual == 1) {
			echo "<tr><td>"._LANGUAGE.":</td><td>"
			."<select name=\"blanguage\">";
			$handle=opendir('language');
			while ($file = readdir($handle)) {
				if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
					$langFound = $matches[1];
					$languageslist .= "$langFound ";
				}
			}
			closedir($handle);
			$languageslist = explode(" ", $languageslist);
			sort($languageslist);
			for ($i=0; $i < sizeof($languageslist); $i++) {
				if($languageslist[$i]!="") {
					echo "<option value=\"$languageslist[$i]\" ";
					if($languageslist[$i]==$blanguage) echo "selected";
					echo ">".ucfirst($languageslist[$i])."</option>\n";
				}
			}
			if ($blanguage != "") {
				$sel3 = "";
			} else {
				$sel3 = "selected";
			}
			echo "<option value=\"\" $sel3>"._ALL."</option></select></td></tr>";
		} else {
			echo "<input type=\"hidden\" name=\"blanguage\" value=\"\">";
		}
		if ($active == 1) {
			$sel1 = "checked";
			$sel2 = "";
		} elseif ($active == 0) {
			$sel1 = "";
			$sel2 = "checked";
		}
		if ($expire != 0) {
			$oldexpire = $expire;
			$expire = $db->XMFnum(($expire - time()) / 3600);
			$exp_day = $expire / 24;
			$expire = "<input type=\"hidden\" name=\"expire\" value=\"$oldexpire\"><b>$expire "._HOURS." (".substr($exp_day,0,5)." "._DAYS.")</b> <input type='text' name='moretime' size='4'> "._MOREDAYS."";
		} else {
			$expire = "<input type=\"text\" name=\"expire\" value=\"0\" size=\"4\" maxlength=\"3\"> "._DAYS."";
		}
		if ($action == "d") {
			$selact1 = "selected";
			$selact2 = "";
		} elseif ($action == "r") {
			$selact1 = "";
			$selact2 = "selected";
		}
		echo "<tr><td>"._ACTIVATE2."</td><td><input type=\"radio\" name=\"active\" value=\"1\" $sel1>"._YES." &nbsp;&nbsp;"
		."<input type=\"radio\" name=\"active\" value=\"0\" $sel2>"._NO."</td></tr>"
		."<tr><td>"._EXPIRATION.":</td><td>$expire</td></tr>"
		."<tr><td>"._AFTEREXPIRATION.":</td><td><select name=\"action\">"
		."<option name=\"action\" value=\"d\" $selact1>"._DEACTIVATE."</option>"
		."<option name=\"action\" value=\"r\" $selact2>"._DELETE."</option></select></td></tr>";
		if ($url != "") {
			if ($refresh == 1800) {
				$sel1 = "selected";
				$sel2 = "";
				$sel3 = "";
				$sel4 = "";
				$sel5 = "";
			} elseif ($refresh == 3600) {
				$sel1 = "";
				$sel2 = "selected";
				$sel3 = "";
				$sel4 = "";
				$sel5 = "";
			} elseif ($refresh == 18000) {
				$sel1 = "";
				$sel2 = "";
				$sel3 = "selected";
				$sel4 = "";
				$sel5 = "";
			} elseif ($refresh == 36000) {
				$sel1 = "";
				$sel2 = "";
				$sel3 = "";
				$sel4 = "selected";
				$sel5 = "";
			} elseif ($refresh == 86400) {
				$sel1 = "";
				$sel2 = "";
				$sel3 = "";
				$sel4 = "";
				$sel5 = "selected";
			}
			echo "<tr><td>"._REFRESHTIME.":</td><td><select name=\"refresh\"><option name=\"refresh\" value=\"1800\" $sel1>1/2 "._HOUR."</option>"
			."<option name=\"refresh\" value=\"3600\" $sel2>1 "._HOUR."</option>"
			."<option name=\"refresh\" value=\"18000\" $sel3>5 "._HOURS."</option>"
			."<option name=\"refresh\" value=\"36000\" $sel4>10 "._HOURS."</option>"
			."<option name=\"refresh\" value=\"86400\" $sel5>24 "._HOURS."</option></select>&nbsp;<font class=\"tiny\">"._ONLYHEADLINES."</font>";
		}
		$sel1 = $sel2 = $sel3 = $sel4 = $sel5 = "";
       if ($view == 0) {
	   $sel1 = "selected";
       } elseif ($view == 1) {
 	   $sel2 = "selected";
       } elseif ($view == 2) {
	   $sel3 = "selected";
       } elseif ($view == 3) {
	   $sel4 = "selected";
       } elseif ($view > 3) {
        $sel5 = "selected";
       }

		if ($subscription == 1) {
			$sub_c1 = "";
			$sub_c2 = "checked";
		} else {
			$sub_c1 = "checked";
			$sub_c2 = "";
		}
		echo "</td></tr><tr><td>"._VIEWPRIV."</td><td><select name=\"view\">"
		."<option value=\"0\" $sel1>"._MVALL."</option>"
		."<option value=\"1\" $sel2>"._MVUSERS."</option>"
		."<option value=\"2\" $sel3>"._MVADMIN."</option>"
		."<option value=\"3\" $sel4>"._MVANON."</option>"
		."<option value=\"4\" $sel5>"._MVGROUPS."</option>"
        ."</select></td></tr><tr><td nowrap>"
        ."<b>"._WHATGROUPS."</b></td><td><font class='tiny'>"._WHATGRDESC."</font><br /><select name='groups[]' multiple size='5'>";
        $ingroups = explode("-",$groups);
        $groupsResult = $db->sql_query("select gid, gname from ".TABLE_NSNGR_GROUPS."");
	while($raw = $db->sql_fetchrow($groupsResult)) {
	$gid = $db->XMFnum($raw['gid']);
	$gname = stripslashes($raw['gname']);
        if(in_array($gid,$ingroups)) { $sel = " selected"; } else { $sel = ""; }
        echo "<OPTION VALUE='$gid'$sel>$gname</option>";
    }
    echo "</select></td></tr><tr><td nowrap>"
        .""._SUBVISIBLE."</td><td><input type=\"radio\" name=\"subscription\" value=\"0\" $sub_c1> "._YES."&nbsp;&nbsp;<input type=\"radio\" name=\"subscription\" value=\"1\" $sub_c2> "._NO.""
		."</td></tr></table><br /><br />"
		."<input type=\"hidden\" name=\"wb_name\" value=\"$wb_name\">"
		."<input type=\"hidden\" name=\"bid\" value=\"$bid\">"
		."<input type=\"hidden\" name=\"bkey\" value=\"$bkey\">"
		."<input type=\"hidden\" name=\"weight\" value=\"$weight\">"
		."<input type=\"hidden\" name=\"op\" value=\"BlocksManager_BlocksEditSave\">"
		."<input type=\"submit\" value=\""._SAVEBLOCK."\"></form>";
		Max_CloseTable();
CloseFooter();

}
}else {
	echo "Access Denied";
}