<?php

require_once '../../../../init.php';

// Required files
require_once MAX_PATH . '/lib/OA/Admin/Option.php';
require_once MAX_PATH . '/lib/OA/Admin/Settings.php';
require_once MAX_PATH . '/lib/OA/Creative/File.php';
require_once MAX_PATH . '/lib/max/Plugin/Translation.php';
require_once MAX_PATH . '/www/admin/config.php';
require_once MAX_PATH . '/lib/OA/Dal.php';
require_once MAX_PATH . '/lib/OA/Creative/File.php';
require_once MAX_PATH . '/www/admin/config.php';
require_once MAX_PATH . '/lib/max/other/common.php';
require_once MAX_PATH . '/lib/max/other/html.php';
require_once MAX_PATH . '/lib/OA/Admin/UI/component/Form.php';
require_once MAX_PATH . '/lib/OA/Maintenance/Priority.php';
require_once LIB_PATH . '/Plugin/Component.php';

if($GLOBALS['_MAX']['CONF']['database']['type']=='mysql')
{
require_once MAX_PATH . '/lib/OA/Dal/Delivery/mysql.php';
}
else if($GLOBALS['_MAX']['CONF']['database']['type']=='pgsql')
{
require_once MAX_PATH . '/lib/OA/Dal/Delivery/pgsql.php';
}
else if($GLOBALS['_MAX']['CONF']['database']['type']=='mysqli')
{
require_once MAX_PATH . '/lib/OA/Dal/Delivery/mysqli.php';
}

session_start();
// Security check
OA_Permission::enforceAccount(OA_ACCOUNT_ADMIN);
$table_prefix = $GLOBALS['_MAX']['CONF']['table']['prefix'];
$id=$_GET['aid'];
if (isset($_POST['submitok']) && $_POST['submitok'] == 'true') 
{
	$translation = new OX_Translation();
	
	if(empty($_REQUEST['mobile_os'])){

			$translated_message = $translation->translate ("<b style='color:red'>Invalid data</b>");
			
			OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
	}

	if($_REQUEST['id'])
	{	
	
	           OA_Dal_Delivery_query("UPDATE {$table_prefix}mobile SET `mobile_os`='".$_REQUEST['mobile_os']."',`mobile_brand`='".$_REQUEST['mobile_brand']."',`mobile_model`='".$_REQUEST['mobile_model']."' WHERE mobile_id='".$_POST['id']."'");	
				$translated_message = $translation->translate("Mobile Has Been Updated.");
				OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
				OX_Admin_Redirect::redirect("plugins/mobileAdsDelivery/Mobile-os.php");
				exit();
	}
	else	
{
				OA_Dal_Delivery_query("INSERT INTO {$table_prefix}mobile (`mobile_os`,`mobile_brand`,`mobile_model`) VALUES ('".$_REQUEST['mobile_os']."','".$_REQUEST['mobile_brand']."','".$_REQUEST['mobile_model']."')");
				$translated_message = $translation->translate("Mobile-os Has Been Added.");
				OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
				OX_Admin_Redirect::redirect("plugins/mobileAdsDelivery/Mobile-os.php");
				exit();
	}

}

$tempQuery= OA_Dal_Delivery_query("Select * FROM {$table_prefix}mobile where mobile_id='".$id."'");
$row=OA_Dal_Delivery_fetchAssoc($tempQuery);
//print_r("Select * FROM {$table_prefix}mobile where mobile_id='".$id."'");
$aErrormessage = array();
$oOptions = new OA_Admin_Option('Mobiledata'); 
?>

<style>
table .cellenabled
{
	padding-bottom:15px;
	
}

</style>
<?php

if($_REQUEST['action']=='edit')
{

	
$oHeaderModel = new OA_Admin_UI_Model_PageHeaderModel("Edit Mobiledata");
phpAds_PageHeader('Mobile-os', $oHeaderModel);

$aSettings = array(
		   array (
				'text'    => 'Edit Mobile Settings',
				'items'   => array (
							 array ('type'=> 'text','text' => 'Mobile OS','required'=>'required','name' => 'mobile_os','value'=> $row['mobile_os']),
							 array ('type'=> 'text','text' => 'Mobile Brand','name' => 'mobile_brand','value'=> $row['mobile_brand']),
							 array ('type'=> 'text','text' => 'Mobile Model','name' => 'mobile_model','value'=> $row['mobile_model']),
							 array ('type'  => 'break'),
							 array ('type'    => 'hiddenfield','text'    => 'id','name'    => 'id','value'   => $id,'req'     => true),
							
							 ),
				   
				)
		);
}
else
{
	$oHeaderModel = new OA_Admin_UI_Model_PageHeaderModel("New Mobiledata");
phpAds_PageHeader('Mobile-os', $oHeaderModel);
$aSettings = array(
		   array (
				'text'    => 'Add Mobile Settings',
				'items'   => array (
							 array ('type' => 'text', 'text'  => 'Mobile OS','required'=>'required','name'  => 'mobile_os','value' => $row['mobile_os']),
							 array ('type' => 'text', 'text'  => 'Mobile Brand','name'  => 'mobile_brand','value' => $row['mobile_brand']),
							array ('type' => 'text', 'text'  => 'Mobile Model','name'  => 'mobile_model','value' => $row['mobile_model']),
							
					  ),
					 	 
					
			 )
			 

		);
}

$oOptions->show($aSettings, null);


phpAds_PageFooter();

?>
