<?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(__FILE__)) . "/init.php");
$user = Application::getUser();
$db = Application::getDb();
if(!$user->isUserLoggedIn())
Tools::redirect("../login.php");
if($user->isAdminLoggedIn())
{
Application::addError("Conturile de tip Admin nu pot avea adrese");
Tools::redirect("../profile.php");
}
if(@$_GET["action"] == "save")
{
$user = Application::getUser();
$a = new Address();
$a->copyFromArray($_POST);
$a->id_user = $user->id;
if($a->validate())
{
$db->tbAddress->save($a);
Application::addMessage("Adresa a fost salvata");
Tools::redirect("../address.php");
}
else
{
SessionHandler::set("editAddress", $a);
Tools::redirect("../address.php?detail=true");
}
}
elseif(@$_GET["action"] == "toggle_checkbox")
{
$a = $db->tbAddress->getRecordById(@$_POST["id"]);
$a->id_user = $user->id;
$field = @$_POST["field"];
if(!in_array($field, array("delivery", "invoiceing", "primary_addr")))
{
Application::addError("Serverul nostru nu a putut intelege cererea trimisa de browserul dumneavoastra");
}
else
{
$a->$field = ($a->$field == 0) ? 1 : 0;
if($a->validate())
{
$db->tbAddress->save($a);
Application::addMessage("Adresa a fost salvata");
}
}
Tools::redirect("../address.php");
}
elseif (@$_GET["action"] == "delete")
{
$a = $db->tbAddress->getRecordById(@$_POST["id"]);
if($a->id == 0)
{
Application::addError("Nu a putut fi gasita adresa care trebuie stearsa");
}
elseif ($a->id_user != $user->id)
{
Application::addError("Adresa aceea nu va apartine");
}
else
{
$db->tbAddress->deleteObj($a);
Application::addMessage("Adresa a fost stearsa");
}
Tools::redirect("../address.php");
}
?>