<?php

include 'loader.php';

$json = array();

switch ($func->get('type')){
    case 'users':
        if($func->post('name') && $func->post('phone')){
            $first = substr($func->post('phone'),0,1);
            if($first=='+'){
                $phone = $func->post('phone');
            }elseif($first == '5'){
                $phone = '+90'.$func->post('phone');
            }elseif($first == '9'){
                $phone = '+'.$func->post('phone');
            }elseif($first == '0'){
                $phone = '+9'.$func->post('phone');
            }else{
                $phone = $func->post('phone');
            }

            foreach ($func->post() as $key=>$item) {
                if($key=='phone'){
                    $item = $phone;
                }
                $query[] = $key."='".$db->escape($item)."'";
            }
//echo '<pre>';print_r($query);echo '</pre>'; die();
            $db->query("INSERT INTO ".DBPREFIX."forms SET " . implode(',', $query));

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

            $json['success'] = $status;
            $json['status'] = $status;
        }
        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);