Location: PHPKode > projects > Katyshop > katyshop_ro_0.3.2.1/web/admin/formparser/category.php
<?php

/**
 * Product: Katyshop
 * @version 0.3.2.1
 * @author Catalin Hulea - hide@address.com
 * @copyright Copyright (C) 2007 Catalin Hulea
 * @license GNU General Public License version 3
 * 			You can find a copy of GNU GPL v3 at this path: /docs/LICENSE
 * @link https://sourceforge.net/projects/katyshop
 *
 * 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 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

require_once(dirname(dirname(dirname(__FILE__))) . "/init.php");
require_once(WEB_DIR . "/includes/req_admin.php");

$db = Application::getDb();
if(@$_GET["action"] == "save")
{
	$c = new Category();
	$c->copyFromArray($_POST);
	if($c->validate())
	{
		if($c->id > 0)
		{
			$old = $db->tbCategory->getRecordById($c->id);
			$c->picture = $old->picture;
		}
		$db->tbCategory->save($c);
		Application::addMessage("Categoria a fost salvata");

		$up = new UploadFile("picture", WEB_DIR . "/img/categories", DATA_DIR . "/temp");
		if(!$up->isEmpty())
		{
			$up->setTmpPrefix("tmpcat" . $c->id);
			$up->setPrefix("cat" . $c->id);
			$up->validateInput();
			$up->validateImage();
			$up->upload(false);
			$up->resize_limitwh(220, 100);
			if($up->commit($c->picture))
			{
				$c->picture = $up->newFilename;
				$db->tbCategory->save($c);
				Application::addMessage("Imaginea a fost schimbata");
			}
			else
			{
				Application::appendErrors($up->errors);
			}
		}

		if(Application::hasErrors())
		{
			SessionHandler::set("editCategory", $c);
			Tools::redirect("../category.php?action=edit&id_parent=" . intval($c->id_parent));
		}
		else
		{
			Tools::redirect("../category.php?id_category={$c->id}");
		}
	}
	else
	{
		SessionHandler::set("editCategory", $c);
		Tools::redirect("../category.php?action=edit&id_parent=" . intval($c->id_parent));
	}
}
elseif (@$_GET["action"] == "delete")
{
	$c = $db->tbCategory->getRecordById(@$_POST["id_category"]);
	if($c->id == 0)
	{
		Application::addError("Nu a putut fi gasita categoria care trebuie stearsa");
		Tools::redirect("../category.php");
	}
	else
	{
		$db->tbCategory->deleteObj($c);
		Application::addMessage("Categoria a fost stearsa");
		Tools::redirect("../category.php?id_category={$c->id_parent}#subcategs");
	}
}
elseif (@$_GET["action"] == "change_parent")
{
	$id_category = intval(@$_POST["id_category"]);
	$id_destination = intval(@$_POST["id_destination"]);
	$c = $db->tbCategory->getRecordById($id_category);
	if($c->id == 0)
	{
		Application::addError("Nu a putut fi gasita categoria care trebuie mutata");
	}
	else
	{
		$c->id_parent = $id_destination;
		$c->pos = $db->tbCategory->getMaxPos($id_destination) + 1;
		if($c->validate())
		{
			$db->tbCategory->save($c);
			Application::addMessage("Categoria a fost mutata");
		}
	}

	if(Application::hasErrors())
		Tools::redirect("../category.php?action=change_parent&id_category=$id_category&id_destination=$id_destination");
	else
		Tools::redirect("../category.php?id_category=$id_category");
}
elseif (@$_GET["action"] == "change_position")
{
	$c = $db->tbCategory->getRecordById(@$_POST["id_category"]);
	if($c->id == 0)
	{
		Application::addError("Nu a putut fi gasita categoria pentru a-i schimba pozitia");
	}
	else
	{
		if(@$_POST["direction"] == "up")
			$c->pos--;
		elseif (@$_POST["direction"] == "down")
			$c->pos++;
		else
			Application::addError("Trebuie sa specificati directia in care trebuie schimbata pozitia");

		$maxPos = $db->tbCategory->getMaxPos($c->id_parent);
		if($c->pos < 1)
			$c->pos = 1;
		elseif ($c->pos > $maxPos)
			$c->pos = $maxPos;

		if($c->validate())
		{
			$db->tbCategory->save($c);
			Application::addMessage("Pozitia categoriei a fost schimbata");
		}
	}
	Tools::redirect("../category.php?id_category=" . intval($c->id_parent) . "#subcategs");

}
elseif (@$_GET["action"] == "change_active_state")
{
	$c = $db->tbCategory->getRecordById(@$_POST["id_category"]);
	if($c->id == 0)
	{
		Application::addError("Nu a putut fi gasita categoria care trebuie activata / dezactivata");
	}
	else
	{
		$c->active = (@$_POST["active"] == "1") ? 1 : 0;
		if($c->validate())
		{
			$db->tbCategory->save($c);
			if($c->active == 1)
				Application::addMessage("Categoria a fost activata");
			else
				Application::addMessage("Categoria a fost dezactivata");
		}
	}
	Tools::redirect("../category.php?id_category=" . intval($c->id_parent) . "#subcategs");
}




?>
Return current item: Katyshop