<?php

include '../root/config.php';
if (!isset($_POST['action'])) {
    echo '';
    exit;
}
if ($_POST['action'] == 'login') {
    $loginUname = addslashes($_POST['loginUname']);
    $loginPassword = md5($_POST['loginPassword']);
    $qry = "SELECT * FROM " . DB_PREFIX . "admin WHERE 	username='" . $loginUname . "'";
    $row = $ai_db->aiGetQuery($qry);
    if (count($row)) {
        foreach ($row as $user) {
            if ($loginPassword == $user['password']) {
                if ($user['is_active'] == '1') {
                    $_SESSION['aid'] = $user['id'];
                    $_SESSION['email'] = $user['email'];
                    $_SESSION['username'] = $user['username'];
                    $data = "success";
                } else {
                    $data = "not active";
                }
            }
        }
    } else {
        $data = "not found";
    }
    echo $data;
}
if ($_POST['action'] == 'check-password') {
    $OldPassword = md5($_POST['old_pass']);
    $qry = "SELECT * FROM " . DB_PREFIX . "admin WHERE password='" . $OldPassword . "' AND id=" . $_SESSION['aid'];
    $result = $ai_db->aiGetQueryObj($qry);
    if (empty($result)) {
        echo 'fail';
    } else {
        echo 'success';
    }
}

if($_POST['action'] == 'getstate')
{

    $id = $_POST['id'];
	$qrys = "SELECT * FROM ".DB_PREFIX."state WHERE country_id='".$id."'";
	$rows = $ai_db->aiGetQueryObj($qrys);
	?>
	<option value="">Select State</option>
	<?php
	foreach($rows as $mcrow){
	?>
	
	<option value="<?php echo $mcrow->id; ?>"><?php echo $mcrow->state; ?></option> 
	<?php }
	
}

if($_POST['action'] == 'GetOrderItem')
{

    $id = $_POST['id'];
	$qrys = "SELECT * FROM view_order_item WHERE order_id='".$id."'";
	$rows = $ai_db->aiGetQueryObj($qrys);
	?>
<?php $r_data ='<tr>
<th>Product Name</th>
<th>Price</th>
<th>Qty</th>
<th>Package Plan</th>
<th>Printed Sets</th>
<th>Foundation</tH>
<th>Reverse Plan</th>
<th>Drawings</th>
</tr>';

	foreach($rows as $mcrow){
$r_data .='<tr>
<td>'.$mcrow->product_name.'</td>
<td>'.$mcrow->price.'</td>
<td>'.$mcrow->qtys.'</td>
<td>'.$mcrow->package_plan_name.'('.CURRENCY.$mcrow->package_plan_price.')</td>
<td>'.$mcrow->printed_sets_name.'('.CURRENCY.$mcrow->printed_sets_price.')</td>
<td>'.$mcrow->foundation_name.'('.CURRENCY.$mcrow->foundation_price.')</td>
<td>'.$mcrow->reverse_plan_name.'('.CURRENCY.$mcrow->reverse_plan_price.')</td>
<td>'.$mcrow->drawings_name.'('.CURRENCY.$mcrow->drawings_price.')</td>
</tr>';
	
	}
echo $r_data;	
}


if($_POST['action'] == 'GetOrderShipping')
{
$id = $_POST['id'];
$Result = $ai_db->aiGetQueryObj("SELECT * FROM ".DB_PREFIX."order_shipping_detail WHERE order_id='".$id."'");
$data = '
<tr>
<th colspan="4" style="text-align: center;">Shipping Information</th>
</tr>
<tr>
<th>First Name :</th>
<td>'.$Result[0]->shp_first_name.'</td>
<th>Last Name :</th>
<td>'.$Result[0]->shp_last_name.'</td>
</tr>
<tr>
<th>Company :</th>
<td>'.$Result[0]->shp_company.'</td>
<th>Address :</th>
<td>'.$Result[0]->shp_address_1.' '.$Result[0]->shp_address_2.'</td>
</tr>
<tr>
<th>Country :</th>
<td>'.$Result[0]->shp_country.'</td>
<th>State :</th>
<td>'.$Result[0]->shp_state.'</td>
</tr>

<tr>
<th>City :</th>
<td>'.$Result[0]->shp_city.'</td>
<th>Zipcode :</th>
<td>'.$Result[0]->shp_zipcode.'</td>
</tr>

<tr>
<th>Phone :</th>
<td colspan="3">'.$Result[0]->shp_phone.'</td>	
</tr>
<tr>
<th colspan="4" style="text-align: center;">Billing Information</th>
</tr>
<tr>
<th>First Name :</th>
<td>'.$Result[0]->bl_first_name.'</td>
<th>Last Name :</th>
<td>'.$Result[0]->bl_last_name.'</td>
</tr>
<tr>
<th>Company :</th>
<td>'.$Result[0]->bl_company.'</td>
<th>Address :</th>
<td>'.$Result[0]->bl_address_1.' '.$Result[0]->bl_address_2.'</td>
</tr>
<tr>
<th>Country :</th>
<td>'.$Result[0]->bl_country.'</td>
<th>State :</th>
<td>'.$Result[0]->bl_state.'</td>
</tr>

<tr>
<th>City :</th>
<td>'.$Result[0]->bl_city.'</td>
<th>Zipcode :</th>
<td>'.$Result[0]->bl_zipcode.'</td>
</tr>

<tr>
<th>Phone :</th>
<td colspan="3">'.$Result[0]->bl_phone.'</td>	
</tr>';

echo $data;
}