<?php
/*
 * This file is part of the Easy-CMS project.
 * Easy-CMS 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.
 * 
 * Easy-CMS 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 Easy-CMS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/**
 * @package Core
 */

/**
 */
include_once('classes/core/CoreObject.class.php');
include_once('classes/core/users/User.class.php');

/**
 * Generates HTML forms for content administration.
 *
 * @access  public
 * @author	Cedric Francoys <cedric.francoys@easy-cms.org>
 * @version	FormsManager.class, Sun Nov 14 16:43:59 CET 2004
 * @package	Core
 */
class FormsManager extends CoreObject 
{
	/**
	 * Constructor
	 */
    function FormsManager() 
	{
    } 
	
	function getVarFromArray($varName, &$array)
	{
		if(empty($array)){	
			$this->debug("FormsManager.getVarFromArray($varName), warning : missing array.", 3);
			return -1;
		}
		
		if(!isset($array[$varName])){
			$this->debug("FormsManager.getVarFromArray($varName), warning : missing variable.", 3);
			return -1;
		}
		return $array[$varName];
	}
	
	function &getPostedVar($varName, $defaultValue = null){
		if(($value = $this->getVarFromArray($varName, $_POST)) < 0){
			if(($value = $this->getVarFromArray($varName, $_GET)) < 0){
				$this->debug("FormsManager.getPostedVar($varName), warning : missing variable (default value is '$defaultValue').", 3);
				return $defaultValue;
			}
		}
		$this->debug("FormsManager.getPostedVar($varName), status : success (value is '$value').", 10);
		return $value;
	}

    function &getModifForm($content, $display) {
		$form = "";
        $form .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
        $form .= "  <tr>\n";
        $form .= "    <td>$content</td>\n";
        $form .= "  </tr>\n";
        $form .= "  <tr>\n";
        $form .= "    <td>\n";
        $form .= "      <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
        $form .= "        <tr>\n";
        $form .= "          <td width=\"500\" align=\"right\">\n";
        $form .= "            <input name=\"display\" type=\"hidden\" value=\"$display\">\n";		
        $form .= "            <input class=\"button\" type=\"button\" value=\"OK\" onclick=\"javascript:saveContent();document.forms[0].submit();\">&#160;&#160;<input class=\"button\" type=\"button\" value=\"Cancel\" onclick=\"javascript:window.close();\">\n";		
        $form .= "          </td>\n";
        $form .= "          <td>\n";
        $form .= "          </td>\n";
        $form .= "        </tr>\n";				
        $form .= "      </table>\n";
        $form .= "    </td>\n";		
        $form .= "  </tr>\n";		
        $form .= "</table>\n";
		return $form;
    } 
        
    function &getDeleteForm($content, $display) {
		$form = "";
		$form .= "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
        $form .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
        $form .= "  <tr>\n";
        $form .= "    <td>Are you sure you want to delete this element ?</td>\n";
        $form .= "  </tr>\n";				
        $form .= "  <tr>\n";
        $form .= "    <td height=\"25\"><span /></td>\n";
        $form .= "  </tr>\n";				
        $form .= "  <tr>\n";
        $form .= "    <td>$content</td>\n";
        $form .= "  </tr>\n";				
        $form .= "  <tr>\n";
        $form .= "    <input name=\"display\" type=\"hidden\" value=\"$display\">\n";		
        $form .= "    <td align=\"right\"><input class=\"button\" type=\"submit\" value=\"OK\">&#160;&#160;<input class=\"button\" type=\"button\" value=\"Cancel\" onclick=\"javascript:window.close();\"></td>\n";
        $form .= "  </tr>\n";		
        $form .= "</table>\n";
        $form .= "</form>\n";
		return $form;
    } 

	/**
	 * Gets Login Form
	 *
	 * @return string
	 */
	function getLogonForm()
	{
		$form = "";
		$form .= "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
        $form .= "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n";
        $form .= "  <tr>\n";
        $form .= "    <td>Enter your login and password :</td>\n";
        $form .= "  </tr>\n";
        $form .= "  <tr>\n";
        $form .= "    <td height=\"10\"></td>\n";
        $form .= "  </tr>\n";		
        $form .= "  <tr>\n";
        $form .= "    <td width=\"100%\">\n";
        $form .= "      <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
        $form .= "        <tr>\n";
        $form .= "          <td>login :</td>\n";
        $form .= "          <td><input name=\"login\" size=\"20\" maxlength=\"20\" /></td>\n";
        $form .= "        </tr>\n";
        $form .= "        <tr>\n";
        $form .= "          <td colspan=\"2\" height=\"2\"></td>\n";
        $form .= "        </tr>\n";		
        $form .= "        <tr>\n";
        $form .= "          <td>password :</td>\n";
        $form .= "          <td><input type=\"password\" name=\"c_password\" size=\"20\" maxlength=\"20\" onchange=\"document.getElementById('password').value=hex_md5(this.value);\"/></td>\n";						
        $form .= "        </tr>\n";
        $form .= "      </table>\n";
        $form .= "    </td>\n";
        $form .= "  </tr>\n";
        $form .= "  <tr>\n";
        $form .= "    <td height=\"20\"></td>\n";
        $form .= "  </tr>\n";
        $form .= "  <tr>\n";
        $form .= "    <td width=\"100%\" align=\"right\"><input class=\"button\" type=\"submit\" value=\"OK\">&#160;&#160;<input class=\"button\" type=\"button\" value=\"Cancel\" onclick=\"javascript:window.close();\"></td>\n";
        $form .= "  </tr>\n";		
        $form .= "</table>\n";
        $form .= "<input type=\"hidden\" name=\"mode\" value=\"".LOGON."\">\n";		
        $form .= "<input type=\"hidden\" id=\"password\" name=\"password\" value=\"\">\n";		        
        $form .= "</form>\n";
		
		return $form;	
	}	
} 

?>
