Index: trunk/CHANGELOG
===================================================================
--- trunk/CHANGELOG	(revision 783)
+++ trunk/CHANGELOG	(revision 784)
@@ -11,6 +11,8 @@
 ! = Update/Change
 
 ------------------------------------- 2.7.0 -------------------------------------
+01-Apr-2008 Christian Sommer
+!	added updated edit CSS functions to the Form module
 31-Mar-2008 Christian Sommer
 #	fixed bug in output filter (mailto links with HTML entities in optional part)
 29-Mar-2008 Christian Sommer
Index: trunk/wb/modules/form/edit_css.php
===================================================================
--- trunk/wb/modules/form/edit_css.php	(revision 783)
+++ trunk/wb/modules/form/edit_css.php	(revision 784)
@@ -27,21 +27,42 @@
 require('../../config.php');
 require(WB_PATH.'/modules/admin.php');
 
+/**
+	DEFINE LANGUAGE DEPENDING OUTPUTS FOR THE EDIT CSS PART
+*/
+$lang_dir = WB_PATH .'/modules/' .$_POST['mod_dir'] .'/languages/';
+if(file_exists($lang_dir .LANGUAGE .'.php')) {
+	// try to include custom language file if exists
+	require_once($lang_dir .LANGUAGE .'.php');
+} elseif(file_exists($lang_dir .'EN.php')) {
+	// try to include default module language file
+	require_once($lang_dir .'EN.php');
+}
+
+// set defaults if output varibles are not set in the languages files
+if(!isset($CAP_EDIT_CSS)) $CAP_EDIT_CSS	= 'Edit CSS';
+if(!isset($HEADING_CSS_FILE))	$HEADING_CSS_FILE = 'Actual module file: ';
+if(!isset($TXT_EDIT_CSS_FILE)) $TXT_EDIT_CSS_FILE = 'Edit the CSS definitions in the textarea below.';
+
 // include functions to edit the optional module CSS files (frontend.css, backend.css)
 require_once('css.functions.php');
 
+// check if the module directory is valid
+$mod_dir = check_module_dir($_POST['mod_dir']);
+if($mod_dir == '') die(header('Location: index.php'));
+
 // check if action is: save or edit
-if(isset($_GET['action']) && $_GET['action'] == 'save' && 
-		isset($_POST['edit_file']) && mod_file_exists($_POST['edit_file'])) {
+if($_POST['action'] == 'save' && mod_file_exists($mod_dir, $_POST['edit_file'])) {
 	/** 
-	SAVE THE UPDATED CONTENTS TO THE CSS FILE
+		SAVE THE UPDATED CONTENTS TO THE CSS FILE
 	*/
+
 	$css_content = '';
 	if(isset($_POST['css_codepress']) && strlen($_POST['css_codepress']) > 0) {
-		// if Javascript is enabled, take contents from hidden field: css_codepress
+		// Javascript is enabled so take contents from hidden field: css_codepress
 		$css_content = stripslashes($_POST['css_codepress']);
 	} elseif(isset($_POST['css_data']) && strlen($_POST['css_data']) > 0) {
-		// if Javascript is disabled, take contens from textarea: css_data
+		// Javascript disabled, take contens from textarea: css_data
 		$css_content = stripslashes($_POST['css_data']);
 	}
 
@@ -62,14 +83,20 @@
 		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
 	}
 
+
 } else {
 	/** 
-	MODIFY CONTENTS OF THE CSS FILE VIA TEXT AREA 
+		MODIFY CONTENTS OF THE CSS FILE VIA TEXT AREA 
 	*/
-	
+	// include the backend.css file if exists
+	if(file_exists(WB_PATH .'/modules/' .$mod_dir .'/backend.css')) {
+		echo '<style type="text/css">';
+		include(WB_PATH .'/modules/' .$mod_dir .'/backend.css');
+		echo "\n</style>\n";
+	}
+
 	// check which module file to edit (frontend.css, backend.css or '')
-	$css_file = '';
-	if(isset($_GET['edit_file'])) $css_file = edit_mod_file($_GET['edit_file']);
+	$css_file = (in_array($_POST['edit_file'], array('frontend.css', 'backend.css'))) ? $_POST['edit_file'] : '';
 
 	// display output
 	if($css_file == '') {
@@ -79,10 +106,10 @@
 		$output  = "<a href=\"#\" onclick=\"javascript: window.location = '";
 		$output .= ADMIN_URL ."/pages/modify.php?page_id=" .$page_id ."'\">back</a>";
 		echo $output;
+	
 	} else {
 		// store content of the module file in variable
 		$css_content = @file_get_contents(dirname(__FILE__) .'/' .$css_file);
-	  	// output content of module file to textareas
 
 		// make sure that codepress stuff is only used if the framework is available
 		$CODEPRESS['CLASS'] = '';
@@ -91,20 +118,23 @@
 			$CODEPRESS['CLASS'] = 'class="codepress css" ';
 			$CODEPRESS['JS'] = 'onclick="javascript: css_codepress.value = area_codepress.getCode();"';
 		}
-			
+
+		// write out heading
+		echo '<h2>' .$HEADING_CSS_FILE .'"' .$css_file .'"</h2>';
+		// include button to switch between frontend.css and backend.css (only shown if both files exists)
+		toggle_css_file($mod_dir, $css_file); 
+	  echo '<p>' .$TXT_EDIT_CSS_FILE .'</p>';
+
+		// output content of module file to textareas
 	?>
-		<form name="edit_module_file" action="<?php echo htmlspecialchars(strip_tags($_SERVER['PHP_SELF'])) .'?action=save';?>" method="post" style="margin: 0;">
-	  		<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
-	  		<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
+		<form name="edit_module_file" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" style="margin: 0;">
 			<input type="hidden" name="css_codepress" value="" />
+	  	<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
+	  	<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
+	  	<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>">
 			<input type="hidden" name="edit_file" value="<?php echo $css_file; ?>" />
-	
-			<h2><?php echo $HEADING_CSS_FILE .'"' .$css_file; ?>"</h2>
-			<?php 
-				// include the toggle button to switch between frontend.css and backend.css (if both files exists)
-				toggle_css_file($css_file); 
-			?>
-	  		<p><?php echo $TXT_EDIT_CSS_FILE; ?></p> 
+	  	<input type="hidden" name="action" value="save">
+
 			<textarea id="area_codepress" name="css_data" <?php echo $CODEPRESS['CLASS'];?>cols="115" rows="25" wrap="VIRTUAL" 
 				style="margin:2px;"><?php echo $css_content; ?></textarea>
 
Index: trunk/wb/modules/form/css.functions.php
===================================================================
--- trunk/wb/modules/form/css.functions.php	(revision 783)
+++ trunk/wb/modules/form/css.functions.php	(revision 784)
@@ -23,85 +23,85 @@
 
 */
 
-// DEFINE LANGUAGE DEPENDING OUTPUTS FOR THE EDIT CSS PART
-$lang_dir = WB_PATH .'/modules/' .basename(dirname(__FILE__)) .'/languages/';
-if(file_exists($lang_dir .LANGUAGE .'.php')) {
-	// try to include custom language file if exists
-	require_once($lang_dir .LANGUAGE .'.php');
-} elseif(file_exists($lang_dir .'EN.php')) {
-	// try to include default module language file
-	require_once($lang_dir .'EN.php');
+// prevent this file from being accessed directly
+if(!defined('WB_PATH')) die(header('Location: index.php'));  
+
+// this function checks the validity of the specified module directory
+if(!function_exists('check_module_dir')) {
+	function check_module_dir($mod_dir) {
+		// check if module directory is formal correct (only characters: "a-z,0-9,_,-")
+		if(!preg_match('/^[a-z0-9_-]+$/iD', $mod_dir)) return '';
+		// check if the module folder contains the required info.php file
+		return (file_exists(WB_PATH .'/modules/' .$mod_dir .'/info.php')) ? $mod_dir : '';
+	}
 }
 
-// set defaults if output varibles are not set in the languages files
-if(!isset($CAP_EDIT_CSS)) $CAP_EDIT_CSS	= 'Edit CSS';
-if(!isset($CAP_TOGGLE_CSS)) $CAP_TOGGLE_CSS	= 'Switch to ';
-if(!isset($HEADING_CSS_FILE))	$HEADING_CSS_FILE = 'Actual module file: ';
-if(!isset($TXT_EDIT_CSS_FILE)) $TXT_EDIT_CSS_FILE = 'Edit the CSS definitions in the textarea below.';
-
 // this function checks if the specified optional module file exists
 if (!function_exists('mod_file_exists')) {
-	function mod_file_exists($mod_file='frontend.css') {
-		// extract the module directory
-		$mod_dir = basename(dirname(__FILE__)) .'/' .$mod_file;
-		return file_exists(WB_PATH .'/modules/' .$mod_dir);
+	function mod_file_exists($mod_dir, $mod_file='frontend.css') {
+  	// check if the module file exists
+		return file_exists(WB_PATH .'/modules/' .$mod_dir .'/' .$mod_file);
 	}
 }
 
-// this function displays a "Edit CSS" button in modify.php 
-// if the optional module files (module.css, module.js) if exists
+// this function displays the "Edit CSS" button in modify.php 
 if (!function_exists('css_edit')) {
-	function css_edit() {
+	function css_edit($mod_dir) {
 		global $page_id, $section_id, $CAP_EDIT_CSS;
-		// extract the module directory
-		$mod_dir = basename(dirname(__FILE__));
-		$frontend_css = mod_file_exists('frontend.css');
-		$backend_css = mod_file_exists('backend.css');
+		// check if specified module directory is valid
+		if(check_module_dir($mod_dir) == '') return;
+		
+		// check if frontend.css or backend.css exist
+		$frontend_css = mod_file_exists($mod_dir, 'frontend.css');
+		$backend_css = mod_file_exists($mod_dir, 'backend.css');
+		
+		// output the edit CSS submtin button if required
 		if($frontend_css || $backend_css) {
-			// display link to edit the optional CSS module files
-			$file = $frontend_css ? 'frontend.css' : 'backend.css';
-			$output  = '<div class="mod_' .$mod_dir .'_edit_css"><a href="' .WB_URL .'/modules/' .$mod_dir .'/edit_css.php';
-			$output .= '?page_id=' .$page_id .'&section_id=' .$section_id .'&edit_file=' .$file .'">';
-			$output .= $CAP_EDIT_CSS .'</a></div>';
-			echo $output;
-		}
-	}
+			// default text used for the edit CSS routines if not defined in the modules language file
+			if(!isset($CAP_EDIT_CSS)) $CAP_EDIT_CSS	= 'Edit CSS';
+			if(!isset($HEADING_CSS_FILE)) $HEADING_CSS_FILE	= 'Actual module file: ';
+			if(!isset($TXT_EDIT_CSS_FILE)) $TXT_EDIT_CSS_FILE = 'Edit the CSS definitions in the textarea below.';
+			?>
+			<form name="edit_module_file" action="<?php echo WB_URL .'/modules/' .$mod_dir .
+				'/edit_css.php';?>" method="post" style="margin: 0; align:right;">
+				<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
+				<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
+				<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>">
+				<input type="hidden" name="edit_file" value="<?php echo ($frontend_css) ?'frontend.css' : 'backend.css';?>">
+				<input type="hidden" name="action" value="edit">
+				<input type="submit" value="<?php echo $CAP_EDIT_CSS;?>" class="mod_<?php echo $mod_dir;?>_edit_css">
+			</form>
+			<?php
+    }
+  }
 }
 
-// this function returns a secure module file from $_GET['edit_file']
-if (!function_exists('edit_mod_file')) {
-	function edit_mod_file() {
-		$allowed_files = array('frontend.css', 'backend.css');
-		if(isset($_GET['edit_file']) && in_array($_GET['edit_file'], $allowed_files)) {
-			return $_GET['edit_file'];
-		} elseif(mod_file_exists('frontend.css')) {
-			return 'frontend.css';
-		} elseif(mod_file_exists('backend_css')) {
-			return 'backend.css';
-		} else {
-			return '';
-		}
-	}
-}	
-
-// this function displays a button to toggle between the optional module CSS files
-// function is invoked from edit_css.php file
+// this function displays a button to toggle between CSS files (invoked from edit_css.php)
 if (!function_exists('toggle_css_file')) {
-	function toggle_css_file($base_css_file = 'frontend.css') {
-		$allowed_mod_files = array('frontend.css', 'backend.css');
-		if(!in_array($base_css_file, $allowed_mod_files)) return;
+	function toggle_css_file($mod_dir, $base_css_file = 'frontend.css') {
 		global $page_id, $section_id, $CAP_TOGGLE_CSS;
-		// extract the module directory
-		$mod_dir = basename(dirname(__FILE__));
+		// check if specified module directory is valid
+		if(check_module_dir($mod_dir) == '') return;
+
+		// do sanity check of specified css file
+		if(!in_array($base_css_file, array('frontend.css', 'backend.css'))) return;
+		
+		// display button to toggle between the two CSS files: frontend.css, backend.css
 		$toggle_file = ($base_css_file == 'frontend.css') ? 'backend.css' : 'frontend.css';
-		if(mod_file_exists($toggle_file)) {
-			// display button to toggle between the two CSS files: frontend.css, backend.css
-			$output  = '<div class="mod_' .$mod_dir .'_edit_css"><a href="' .WB_URL .'/modules/' .$mod_dir .'/edit_css.php';
-			$output .= '?page_id=' .$page_id .'&section_id=' .$section_id .'&edit_file=' .$toggle_file .'">';
-			$output .= $CAP_TOGGLE_CSS .$toggle_file .'</a></div>';
-			echo $output;
+		if(mod_file_exists($mod_dir, $toggle_file)) {
+			?>
+			<form name="toggle_module_file" action="<?php echo WB_URL .'/modules/' .$mod_dir .
+				'/edit_css.php';?>" method="post" style="margin: 0; align:right;">
+				<input type="hidden" name="page_id" value="<?php echo $page_id; ?>">
+				<input type="hidden" name="section_id" value="<?php echo $section_id; ?>">
+				<input type="hidden" name="mod_dir" value="<?php echo $mod_dir; ?>">
+				<input type="hidden" name="edit_file" value="<?php echo $toggle_file; ?>">
+				<input type="hidden" name="action" value="edit">
+				<input type="submit" value="<?php echo ucwords($toggle_file);?>" class="mod_<?php echo $mod_dir;?>_edit_css">
+			</form>
+			<?php
 		}
-	}
+  }
 }
 
 ?>
\ No newline at end of file
Index: trunk/wb/modules/form/modify_settings.php
===================================================================
--- trunk/wb/modules/form/modify_settings.php	(revision 783)
+++ trunk/wb/modules/form/modify_settings.php	(revision 784)
@@ -63,9 +63,10 @@
 ?>
 <h2><?php echo $MOD_FORM['SETTINGS']; ?></h2>
 <?php
-	// include the button to edit the optionla module CSS files
+	// include the button to edit the optional module CSS files
 	// Note: CSS styles for the button are defined in backend.css (div class="mod_moduledirectory_edit_css")
-	css_edit();
+	// Place this call outside of any <form></form> construct!!!
+	css_edit('form');
 ?>
 
 <form name="edit" action="<?php echo WB_URL; ?>/modules/form/save_settings.php" method="post" style="margin: 0;">
Index: trunk/wb/modules/form/languages/NL.php
===================================================================
--- trunk/wb/modules/form/languages/NL.php	(revision 783)
+++ trunk/wb/modules/form/languages/NL.php	(revision 784)
@@ -31,7 +31,6 @@
 
 // Variables for the module CSS edit outputs
 $CAP_EDIT_CSS = 'Wijzig CSS';
-$CAP_TOGGLE_CSS = 'Wijzig ';
 $HEADING_CSS_FILE = 'Actuele module bestand: ';
 $TXT_EDIT_CSS_FILE = 'Wijzig de CSS definities in het textveld hieronder.';
 
Index: trunk/wb/modules/form/languages/EN.php
===================================================================
--- trunk/wb/modules/form/languages/EN.php	(revision 783)
+++ trunk/wb/modules/form/languages/EN.php	(revision 784)
@@ -31,7 +31,6 @@
 
 // Variables for the module CSS edit outputs
 $CAP_EDIT_CSS = 'Edit CSS';
-$CAP_TOGGLE_CSS = 'Edit ';
 $HEADING_CSS_FILE = 'Actual module file: ';
 $TXT_EDIT_CSS_FILE = 'Edit the CSS definitions in the textarea below.';
 
Index: trunk/wb/modules/form/languages/RU.php
===================================================================
--- trunk/wb/modules/form/languages/RU.php	(revision 783)
+++ trunk/wb/modules/form/languages/RU.php	(revision 784)
@@ -31,7 +31,6 @@
 
 // Variables for the module CSS edit outputs
 $CAP_EDIT_CSS = '&#1056;&#1077;&#1076;&#1072;&#1082;&#1090;&#1080;&#1088;&#1086;&#1074;&#1072;&#1090;&#1100; CSS';
-$CAP_TOGGLE_CSS = '&#1056;&#1077;&#1076;&#1072;&#1082;&#1090;&#1080;&#1088;&#1086;&#1074;&#1072;&#1090;&#1100; ';
 $HEADING_CSS_FILE = '&#1048;&#1084;&#1103; &#1092;&#1072;&#1081;&#1083;&#1072;: ';
 $TXT_EDIT_CSS_FILE = '&#1048;&#1079;&#1084;&#1077;&#1085;&#1080;&#1090;&#1077; CSS &#1092;&#1072;&#1081;&#1083;, &#1077;&#1089;&#1083;&#1080; &#1085;&#1077;&#1086;&#1073;&#1093;&#1086;&#1076;&#1080;&#1084;&#1086;:';
 
Index: trunk/wb/modules/form/languages/DE.php
===================================================================
--- trunk/wb/modules/form/languages/DE.php	(revision 783)
+++ trunk/wb/modules/form/languages/DE.php	(revision 784)
@@ -31,7 +31,6 @@
 
 // Variablen fuer Textausgabe der frontend.css/backend.css Bearbeitung
 $CAP_EDIT_CSS = 'Bearbeite CSS';
-$CAP_TOGGLE_CSS = 'Wechsle zu ';
 $HEADING_CSS_FILE = 'Aktuelle Moduldatei: ';
 $TXT_EDIT_CSS_FILE = 'Bearbeite die CSS Definitionen im nachfolgenden Textfeld.';
 
Index: trunk/wb/modules/form/backend.css
===================================================================
--- trunk/wb/modules/form/backend.css	(revision 783)
+++ trunk/wb/modules/form/backend.css	(revision 784)
@@ -5,16 +5,18 @@
 	border-top: 1px dashed #fff;
 }
 
-div.mod_form_edit_css {
-  width: 100%;
+/* 
+  The definitions below provide the style for the edit CSS button 
+  Required CSS class name: input.mod_moduledirectory_edit_css
+*/
+input.mod_form_edit_css {
+  color: #000;
+  background-color: #F0F0F0;
+  border: 1px solid gray;
+  padding: 2px;
+  margin: 0;
+  margin-left: 625px;
   margin-top: -20px;
-  margin-bottom: 15px;
-  text-align: right;
-}
-
-div.mod_form_edit_css a {
-  width: 100px;
-  padding: 5px;
-  border: 1px solid;
-  background-color: #F0F0F0;
+  margin-bottom: 5px;
+  width: 110px;
 }
\ No newline at end of file
