<?php

if(!defined('ABSPATH')){
  die("Not Allowed");
}

global $wpdb, $charset_collate;
$charset_collate = $wpdb->get_charset_collate();

function create_msorgTemplate(){

    global $wpdb, $charset_collate,$status,$message,$level,$done_code;
  
  
    $msorg_table = $wpdb->prefix.'vtupress_msorgTemplate';
  
  
    $sql= "CREATE TABLE IF NOT EXISTS $msorg_table (
    id int NOT NULL AUTO_INCREMENT,
    color_from text,
    color_to text,
    enable_ref_message text,
    ref_message text,
    enable_ref_link_copy_button text,
    enable_ctt_message text,
    ctt_message text,
    enable_ctt_button text,
    ctt_button_link text,
    enable_scroll_message text,
    scroll_message text,
    enable_faq_button text,
    faq_link text,
    enable_download_button text,
    download_link text,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (id) )$charset_collate;";
    dbDelta($sql);
  
    //now add a default values to the table columns as seen above for the $msorg_table
    $add = [];
    foreach ($add as  $value) {
      maybe_add_column($msorg_table,$value,"ALTER TABLE $msorg_table ADD $value text");
    }
    
    $add_gateway = [
        "id"=> "1",
        "color_from" => "#F83AC3",
        "color_to" => "#121068",
        "enable_ref_message" => "no",
        "ref_message" => "To enjoy our referral program, refer friends and family to our website and ensure they upgrade their accounts. EARN immediately the person upgrade his/her account to RESELLER/TOP USERS . THIS IS PARTNERSHIP PROFIT",
        "enable_ref_link_copy_button" => "no",
        "enable_ctt_message" => "no",
        "ctt_message" => "Own a retailer website and retail all our services; Such as DATA AND AIRTIME",
        "enable_ctt_button" => "yes",
        "ctt_button_link" => "#",
        "enable_scroll_message" => "yes",
        "scroll_message" => "Welcome",
        "enable_faq_button" => "no",
        "faq_link" => "#",
        "enable_download_button" => "no",
        "download_link" => "#"
    ];
  
  
        
        $id = $add_gateway["id"];
        $result =  $wpdb->get_results("SELECT * FROM $msorg_table WHERE id = '$id' ");
  
        if(empty($result)){
            $turn = $wpdb->insert( $msorg_table,$add_gateway);
        }
         
  
  
  }


  function msorgDbs(){
    create_msorgTemplate();
  }