Location: PHPKode > projects > Katyshop > katyshop_ro_0.3.2.1/web/admin/formparser/manufacturer.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")
{
	$m = new Manufacturer();
	$m->copyFromArray($_POST);
	if($m->validate())
	{
		if($m->id > 0)
		{
			$old = $db->tbManufacturer->getManufacturerById($m->id);
			$m->picture = $old->picture;
		}
		$db->tbManufacturer->save($m);
		Application::addMessage("Producatorul a fost schimbat");

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

		if(Application::hasErrors())
		{
			SessionHandler::set("editManufacturer", $m);
			Tools::redirect("../manufacturer.php?action=detail");
		}
		else
		{
			Tools::redirect("../manufacturer.php?action=detail&id={$m->id}");
		}
	}
	else
	{
		SessionHandler::set("editManufacturer", $m);
		Tools::redirect("../manufacturer.php?action=detail");
	}
}
elseif (@$_GET["action"] == "delete")
{
	$m = $db->tbManufacturer->getManufacturerById(@$_POST["id"]);
	if($m->id == 0)
	{
		Application::addError("Nu a putut fi gasit producatorul care trebuie sters");
		Tools::redirect("../manufacturer.php");
	}
	else
	{
		$db->tbManufacturer->deleteObj($m);
		Application::addMessage("Producatorul a fost sters");
		Tools::redirect("../manufacturer.php");
	}
}

?>
Return current item: Katyshop