<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

include 'loader.php';

$json = array();
$json['status'] = false;

switch ($func->get('type')){
    case 'users':
        if($func->post('name') && $func->post('telephone') && $func->post('password') && $func->post('email')){
            $check = $db->query("SELECT * FROM ".DBPREFIX."customer WHERE email ='".$func->post('email')."'");
            if($check->num_rows){
                $json['error'] = 'Kayıtlı kullanıcı!';
                $json['status'] = false;
            }else{
                $first = substr($func->post('telephone'),0,1);
                if($first=='+'){
                    $phone = $func->post('telephone');
                }elseif($first == '5'){
                    $phone = '+90'.$func->post('telephone');
                }elseif($first == '9'){
                    $phone = '+'.$func->post('telephone');
                }elseif($first == '0'){
                    $phone = '+9'.$func->post('telephone');
                }else{
                    $phone = $func->post('telephone');
                }

                $db->query("INSERT INTO ".DBPREFIX."customer SET status=1, name='".$func->post('name')."', phone='".$phone."', email ='".$func->post('email')."', password='".md5($func->post('password'))."'");
                $status = $db->getLastId()?$db->getLastId():0;

                $json['success'] = $status;
                $json['status'] = $status;
            }

            $login = $customer->login($func->post('email'),$func->post('password'));

        }
        break;
    case 'coupon_clear':
        $session->uset('coupon');
        $session->uset('coupon_type');
        $session->uset('coupon_group');
        $json['success'] = 'Kupon kodunuz iptal edildi.';
        break;

}

echo json_encode($json); die();