<?php
/*
* Copyright © 2010-2012 MLECMS. All Rights Reserved.
* @Multi-Language Enterprise Content Management System
* This Is Not a Freeware, Use Is Subject To License Terms.
*/
require_once(dirname(__FILE__).'/header.php');
if(is_numeric($_GET['del'])){ 
	$db->execute("DELETE FROM `{$DB['prefix']}shipping` WHERE `id` = '{$_GET['del']}'"); msgbox('','CURRENT');
} elseif (is_numeric($_GET['enable'])) { 
	$db->execute("UPDATE `{$DB['prefix']}shipping` SET `enable` = '1' WHERE `id` = '{$_GET['enable']}'"); msgbox('','CURRENT');
} elseif (is_numeric($_GET['disable'])){ 
	$db->execute("UPDATE `{$DB['prefix']}shipping` SET `enable` = '0' WHERE `id` = '{$_GET['disable']}'"); msgbox('','CURRENT');
}
if(!is_numeric($_GET['id'])){ 
	$language['page']['title']['update'] = $language['page']['title']['update'][0];
	$language['page']['submit'] = $language['page']['other'][0];
	$mle['sp']['topay'] = 0;
	$mle['sp']['enable'] = 1;
} else { 
	$language['page']['title']['update'] = $language['page']['title']['update'][1];
	$language['page']['submit'] = $language['page']['other'][1];
	$mle['sp'] = $db->query("SELECT * FROM `{$DB['prefix']}shipping` WHERE `lang` = '".LANG."' && `id` = '{$_GET['id']}' LIMIT 1",1);
	isset($mle['sp']['id']) or die('Parameter Error.');
}
if(!empty($_POST['title'])){
	$freight = numeric($_POST['freight']);
	$topay = numeric($_POST['topay']);
	$insure = numeric($_POST['insure']);
	$enable = numeric($_POST['enable']);
	if(is_numeric($_GET['id'])){ 
		$sql = "UPDATE `{$DB['prefix']}shipping` SET `title` = '{$_POST['title']}',`freight` = '{$freight}',`topay` = '{$topay}',`insure` = '{$insure}',`description` = '{$_POST['description']}',`enable` = '{$enable}' WHERE `id` = '{$_GET['id']}'";
		$t = 3; 
	} else { 
		$sql = "INSERT INTO `{$DB['prefix']}shipping` (`lang`,`title`,`freight`,`topay`,`insure`,`description`,`enable`) VALUES ('".LANG."','{$_POST['title']}','{$freight}','{$topay}','{$insure}','{$_POST['description']}','{$enable}')";
		$t = 2; 
	}
	if($db->execute($sql)){
		admin::logs($t,$language['page']['title']['update'].'，'.$language['common']['successful']); 
		msgbox($language['common']['successful'],'CURRENT'); 	
	} else {
		admin::logs($t,$language['page']['title']['update'].','.$language['common']['failed']); 
		msgbox($language['common']['failed'],'CURRENTS');			
	}	
}
require_once(ADMIN_PATH.'/footer.php');