<?php
/**
 * Project:   astat - simple site engine
 * File:        /modules/text/addcategory.apnl.php
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @link http://www.astat.org SVN: $URL$
 * @copyright 2009 becast.at
 * @author Bernhard Jaud <bernhard at becast dot at>
 * @package astat core
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @version $Id: ca7c3b985bdb214ce7622dc7397419774c03bace $
*/

If (!defined("IN_BCWE_ADMIN")) {
    die("Dieses Script kann nicht ausserhalb des Frameworks laufen!");
} 
$session->page_begin("add Category", True);

class addcategory_text_panel extends admin_module{
 	
	function output(){
		global $config, $db,$panel, $root, $core, $session;
		$fail=FALSE;
		if(isset($_POST['send'])&& $_POST['send']==1){
			if(isset($_POST['categoryname'])&& $_POST['categoryname']!=""){
				$userfile_name = $_FILES['picture']['name'];
				$userfile_tmp = $_FILES['picture']['tmp_name'];
				$userfile_size = $_FILES['picture']['size'];
				$userfile_type = $_FILES['picture']['type']; 
				$filedir = $root.'/catimages/';
				$size = 120;
				if (isset($_FILES['picture']['name']) && $_FILES['picture']['name']!=""){
					$prod_img = $filedir.$userfile_name;
					$ret=$core->upload_file($prod_img, $userfile_tmp, $size, $size, TRUE, TRUE);
					if($ret!==TRUE){
						$panel->admin_message("Fehler", "Das Bild konnte nicht hochgeladen wrden <br /> Der Fehler war: ". $ret,TRUE,"addcategory_text");
					}
				}
					$categoryname=$db->escape($_POST['categoryname']);
					$active=$db->escape($_POST['active']);
					$db->query("INSERT INTO `" . $config["prefix"]. "article_categories` (`categoryname`,`picture`,`active`) VALUES ('".$categoryname."','".$userfile_name."','".$active."')") or die ($db->error());
					$panel->admin_message("Danke", "Die Kategorie wurde erfolgreich eingetragen!.",TRUE,"addcategory_text");
			}else{
				$fail="<span style=\"text-align: center; color: red;\">Der Kategoriename muss angegeben werden!</span>";
			}
		}elseif(!isset($_POST['send']) || $fail){
			$panel->title="Kategorie hinzuf&uuml;gen";
			$panel->form(array("action"=>$config["path"]."/admin/index.php?panel=addcategory_text"),FALSE,"enctype=\"multipart/form-data\"");
			if($fail){
				$panel->content.=$fail;
			}
			$panel->content.="<h3>Kategoriename:</h3>";
			$panel->field(array("name"=>"categoryname","typ"=>"text","value"=>$_POST["categoryname"]));
			$panel->content.="<h3>Kategoriebild:</h3>";
			$panel->field(array("name"=>"picture","typ"=>"file","value"=>$_POST["picture"]));
			$panel->content.="<br />";		
			$panel->content.="<h3>Aktiv:</h3>";
			$panel->select(array("Nein"=>"false","Ja"=>"true"),$_POST["active"],"active");			
			$panel->content.="<br />";							
			$panel->field(array("name"=>"send","typ"=>"hidden","value"=>"1"));
			$panel->content.="<br />";
			$panel->submit();
			$panel->formClose();
		}
	}
}
?>