<?php

include("../public/impOpreation.php");
$do = $_GET['do'];
$today = date("Y-m-d H:i:s");
$date = date("Y-m-d");
$userid = $_SESSION['userid'];

if (empty($do)) {  
    
    
    $showData = R::load('onlinestoremainsetting',1);
    $smarty->assign('showData', $showData);
    $stores = R::getAll('select storeId,storeName from store where conditions=0');
    $smarty->assign('stores', $stores);
  
    $smarty->display("header.html");
    $smarty->display("onlinestoremainsettingview/edit.html");
    $smarty->display("footer.html");
} elseif ($do == "update") {
    include("../library/newUplode/uploadfunctions.php");

    try {
      $logo = uploadupdate('logo', 'logourl', False, 0, 0, 'onlinestoremainsetting');
      $logo_dark = uploadupdate('logodark', 'logodarkurl', False, 0, 0, 'onlinestoremainsetting');
      $updateData = R::load('onlinestoremainsetting',1);
      $updateData->logo = $logo;
      $updateData->logo_dark = $logo_dark;
      $updateData->send_type = $_POST['send_type'];
      $updateData->shippingfree_numberitems = $_POST['shippingfree_numberitems'];
      $updateData->numberitems = $_POST['numberitems'];
      $updateData->shippingfree_totleitems = $_POST['shippingfree_totleitems'];
      $updateData->totleitems = $_POST['totleitems'];
      $updateData->fixedshipping_value = $_POST['fixedshipping_value'];
      $updateData->shipping_value = $_POST['shipping_value'];
      $updateData->address_ar = $_POST['address_ar'];
      $updateData->address_en = $_POST['address_en'];
      $updateData->mobile = $_POST['mobile'];
      $updateData->another_mobile = $_POST['another_mobile'];
      $updateData->email = $_POST['email'];
      $updateData->another_email = $_POST['another_email'];
      $updateData->facebook = $_POST['facebook'];
      $updateData->twitter = $_POST['twitter'];
      $updateData->instagram = $_POST['instagram'];
      $updateData->telegram = $_POST['telegram'];
      $updateData->account_sid = $_POST['account_sid'];
      $updateData->auth_token = $_POST['auth_token'];
      $updateData->twilio_number = $_POST['twilio_number'];
      $updateData->mail_host = $_POST['mail_host'];
      $updateData->mail_port = $_POST['mail_port'];
      $updateData->mail_username = $_POST['mail_username'];
      $updateData->mail_password = $_POST['mail_password'];
      $updateData->mail_encryption = $_POST['mail_encryption'];
      $updateData->mail_fromaddress = $_POST['mail_fromaddress'];
      $updateData->store_id = $_POST['store_id'];
      $updateData->close_site_status = $_POST['close_site_status'];
      $updateData->close_site_ar = $_POST['close_site_ar'];
      $updateData->close_site_en = $_POST['close_site_en'];
      $updateData->site_name_ar = $_POST['site_name_ar'];
      $updateData->site_name_en = $_POST['site_name_en'];
      $updateData->header_text_ar = $_POST['header_text_ar'];
      $updateData->header_text_en = $_POST['header_text_en'];
      $updateData->footer_text_ar = $_POST['footer_text_ar'];
      $updateData->footer_text_en = $_POST['footer_text_en'];
      $updateData->working_hours_ar = $_POST['working_hours_ar'];
      $updateData->working_hours_en = $_POST['working_hours_en'];
      $updateData->app_android  = $_POST['app_android'];
      $updateData->app_ios  = $_POST['app_ios'];
      $updateData->points  = $_POST['points'];
      $updateData->point_value  = $_POST['point_value'];
      $updateData->hotline  = $_POST['hotline'];
      $updateData->iframe_map  = $_POST['iframe_map'];
      R::store($updateData);
        if (isset($_POST['curlpost']) && $_POST['curlpost'] == 1) {
            $data = array('status' => 1, 'message' => 'تمت العمليه بنجاح', 'message_en' => 'Success');
            echo json_encode($data);
        } else {
            header("location:onlinestoremainsetting.php");
        }
    } catch (Exception $e) {
        if (isset($_POST['curlpost']) && $_POST['curlpost'] == 1) {
            $data = array('status' => 2, 'message' => 'حدث خطأ', 'message_en' => 'Error');
            echo json_encode($data);
        } else {
            echo "حدث خطأ: " . $e->getMessage();
        }
    }
}
    
   
    

?>