<?php
ini_set('display_errors', 1);

require_once '../../../resources/base_path_include.php';

require_once $base_path_to_learning_resources  . "includes/connect.php"; // use require for mandatory files

require_once $base_path_to_learning_resources . 'lib/function.php';
require_once $base_path_to_learning_resources . 'lib/validate_api_signature.php';

//valdation file
require_once $base_path_to_learning_resources.'lib/validate_function.php';

require_once $base_path_to_learning . '/user_management/check_username_availability.php';

require_once $base_path_to_learning.'user_management/authenticate.php';

require_once $base_path_to_learning.'academic_session/functions/registration_functions.php';

require_once $base_path_to_learning.'modules/student_registration/functions/functions.php';

$postdata = json_decode(file_get_contents("php://input"), true);

checkIfNoPhpContentsReceive();
validateApiSignature($postdata['api_signature']);


$jwttoken = $postdata['jwt_token'];

$jwt_validate = authenticate_jwt($jwttoken);
//then workspace_id is iin decodede data of jwt use from there
$userid = $jwt_validate->data->id;

$institution_id = $jwt_validate->data->institution_id;
//echo $institution_id;die();
$username = $jwt_validate->data->username;
$role = $jwt_validate->data->role;

$branch_id = $jwt_validate->data->branch_id;



if($postdata['function_type'] == "add_template_color_schema") {
    
    
  $margin_top = (isset($postdata['margin_top']) and !empty($postdata['margin_top'])) ? ucwords(trim($postdata['margin_top'])) : null;
  $margin_bottom = (isset($postdata['margin_bottom']) and !empty($postdata['margin_bottom'])) ? ucwords(trim($postdata['margin_bottom'])) : null;
  $margin_right = (isset($postdata['margin_right']) and !empty($postdata['margin_right'])) ? ucwords(trim($postdata['margin_right'])) : null;
  $margin_left = (isset($postdata['margin_left']) and !empty($postdata['margin_left'])) ? ucwords(trim($postdata['margin_left'])) : null;
  $border_settings = (isset($postdata['border_settings']) and !empty($postdata['border_settings'])) ? ucwords(trim($postdata['border_settings'])) : null;
  $padding_top = (isset($postdata['padding_top']) and !empty($postdata['padding_top'])) ? ucwords(trim($postdata['padding_top'])) : null;
  $padding_bottom = (isset($postdata['padding_bottom']) and !empty($postdata['padding_bottom'])) ? ucwords(trim($postdata['padding_bottom'])) : null;
  $padding_right = (isset($postdata['padding_right']) and !empty($postdata['padding_right'])) ? ucwords(trim($postdata['padding_right'])) : null;
  $padding_left = (isset($postdata['padding_left']) and !empty($postdata['padding_left'])) ? ucwords(trim($postdata['padding_left'])) : null;
  $header_structure = (isset($postdata['header_structure']) and !empty($postdata['header_structure'])) ? ucwords(trim($postdata['header_structure'])) : null;
  $footer_structure = (isset($postdata['footer_structure']) and !empty($postdata['footer_structure'])) ? ucwords(trim($postdata['footer_structure'])) : null;
  $header_background = (isset($postdata['header_background']) and !empty($postdata['header_background'])) ? ucwords(trim($postdata['header_background'])) : null;
  $institution_name_font = (isset($postdata['institution_name_font']) and !empty($postdata['institution_name_font'])) ? ucwords(trim($postdata['institution_name_font'])) : null;
  $institution_name_fontsize = (isset($postdata['institution_name_fontsize']) and !empty($postdata['institution_name_fontsize'])) ? ucwords(trim($postdata['institution_name_fontsize'])) : null;
  $institution_subtitle_font = (isset($postdata['institution_subtitle_font']) and !empty($postdata['institution_subtitle_font'])) ? ucwords(trim($postdata['institution_subtitle_font'])) : null;
  $institution_subtitle_fontsize = (isset($postdata['institution_subtitle_fontsize']) and !empty($postdata['institution_subtitle_fontsize'])) ? ucwords(trim($postdata['institution_subtitle_fontsize'])) : null;
  $institution_subtitle_color = (isset($postdata['institution_subtitle_color']) and !empty($postdata['institution_subtitle_color'])) ? ucwords(trim($postdata['institution_subtitle_color'])) : null;
  $instiution_address_font = (isset($postdata['instiution_address_font']) and !empty($postdata['instiution_address_font'])) ? ucwords(trim($postdata['instiution_address_font'])) : null;
  $instiution_address_fontsize = (isset($postdata['instiution_address_fontsize']) and !empty($postdata['instiution_address_fontsize'])) ? ucwords(trim($postdata['instiution_address_fontsize'])) : null;
  $instiution_address_color = (isset($postdata['instiution_address_color']) and !empty($postdata['instiution_address_color'])) ? ucwords(trim($postdata['instiution_address_color'])) : null;
  $institution_affiliation_font = (isset($postdata['institution_affiliation_font']) and !empty($postdata['institution_affiliation_font'])) ? ucwords(trim($postdata['institution_affiliation_font'])) : null;
  $institution_affiliation_fontsize = (isset($postdata['institution_affiliation_fontsize']) and !empty($postdata['institution_affiliation_fontsize'])) ? ucwords(trim($postdata['institution_affiliation_fontsize'])) : null;
  $institution_affiliation_color = (isset($postdata['institution_affiliation_color']) and !empty($postdata['institution_affiliation_color'])) ? ucwords(trim($postdata['institution_affiliation_color'])) : null;
  $page_title_font = (isset($postdata['page_title_font']) and !empty($postdata['page_title_font'])) ? ucwords(trim($postdata['page_title_font'])) : null;
  $page_title_fontsize = (isset($postdata['page_title_fontsize']) and !empty($postdata['page_title_fontsize'])) ? ucwords(trim($postdata['page_title_fontsize'])) : null;
  $page_title_color = (isset($postdata['page_title_color']) and !empty($postdata['page_title_color'])) ? ucwords(trim($postdata['page_title_color'])) : null;
  $body_background = (isset($postdata['body_background']) and !empty($postdata['body_background'])) ? ucwords(trim($postdata['body_background'])) : null;
  $body_fontsize = (isset($postdata['body_fontsize']) and !empty($postdata['body_fontsize'])) ? ucwords(trim($postdata['body_fontsize'])) : null;
  $body_font = (isset($postdata['body_font']) and !empty($postdata['body_font'])) ? ucwords(trim($postdata['body_font'])) : null;
  $footer_background = (isset($postdata['footer_background']) and !empty($postdata['footer_background'])) ? ucwords(trim($postdata['footer_background'])) : null;
  $footer_fontsize = (isset($postdata['footer_fontsize']) and !empty($postdata['footer_fontsize'])) ? ucwords(trim($postdata['footer_fontsize'])) : null;
  $footertextcolor = (isset($postdata['footertextcolor']) and !empty($postdata['footertextcolor'])) ? ucwords(trim($postdata['footertextcolor'])) : null;
  $footer_font = (isset($postdata['footer_font']) and !empty($postdata['footer_font'])) ? ucwords(trim($postdata['footer_font'])) : null;
  $specific_to = (isset($postdata['specific_to']) and !empty($postdata['specific_to'])) ? ucwords(trim($postdata['specific_to'])) : null;

     
     
  $sql = "INSERT INTO template_color_schema(institution_id,margin_top,margin_bottom,margin_right,margin_left,border_settings,padding_top,padding_bottom,padding_right,padding_left,header_structure,footer_structure,header_background,institution_name_font
  ,institution_name_fontsize,instiution_address_font,instiution_address_fontsize,instiution_address_color,institution_subtitle_font,institution_subtitle_fontsize,institution_subtitle_color,
  	institution_affiliation_font,institution_affiliation_fontsize,institution_affiliation_color,page_title_font,page_title_fontsize,page_title_color,body_background,body_fontsize
  	,body_font,footer_background,footer_fontsize,footertextcolor,footer_font,specific_to)
                             VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
 $stmt =  $conn_rjllearning->prepare($sql); 
 $stmt->execute(array($institution_id,$margin_top,$margin_bottom,$margin_right,$margin_left,$border_settings,$padding_top,$padding_bottom,$padding_right,$padding_left,$header_structure,$footer_structure,$header_background,$institution_name_font
  ,$institution_name_fontsize,$instiution_address_font,$instiution_address_fontsize,$instiution_address_color,$institution_subtitle_font,$institution_subtitle_fontsize,$institution_subtitle_color,$institution_affiliation_font,$institution_affiliation_fontsize,$institution_affiliation_color,$page_title_font,$page_title_fontsize,$page_title_color,$body_background,$body_fontsize,$body_font,$footer_background,$footer_fontsize,$footertextcolor,$footer_font,$specific_to));
  	
 $id = $conn_rjllearning->lastInsertId();
 
    
    
}