<?php

$folder_name = "";
//get current url address
if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
{
    $protocol = 'https://';
}
else
{
    $protocol = 'http://';
}
$basedir = $protocol . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/'));
$jsondata = file_get_contents("./api/zyx.json");
$data = json_decode($jsondata, true);
$json = $data['app_conf'];
$jsondata = file_get_contents("./api/zyx.json");
$data = json_decode($jsondata, true);
$json = $data['app_conf'];
if (isset($_POST['submit_1c']))
{
    $jsonData = file_get_contents("./api/zyx.json");
    $arrayData = json_decode($jsonData, true);
    $replacementData = array( 'app_conf' => array(
            "report_issue_from_email"=>$_POST["report_issue_from_email"], 
            "report_issue_to_email"=>$_POST["report_issue_to_email"], 
"report_issue"=>$_POST["report_issue"], 
"reporting_api"=>$_POST["reporting_api"], 
"mqtt_server"=>$_POST["mqtt_server"], 
"mqtt_endpoint"=>$_POST["mqtt_endpoint"]
        ));
    $newArrayData = array_replace_recursive($arrayData, $replacementData);
    $newJsonData = json_encode($newArrayData, JSON_PRETTY_PRINT);
    file_put_contents("./api/zyx.json", $newJsonData);
    header("Location: reporting.php?");
}

if (isset($_POST['submit_2c'])){
    $json2 = $data['app_conf'];
    $jsonData2 = file_get_contents("./api/zyx.json");
    $arrayData2 = json_decode($jsonData2, true);
    $replacementData2 = array(
        'app_conf' => array(
           "channel_reporting"		            => $_POST["channel_reporting"],
	"channel_reporting_to_email"		        => $_POST["channel_reporting_to_email"],
	"movie_show_reqest"		        => $_POST["movie_show_reqest"],
	"movie_show_reqest_to_email"		        => $_POST["movie_show_reqest_to_email"],
	"channel_report_email_subject"		            => $_POST["channel_report_email_subject"],
		"movie_shows_reqest_email_subject"		        => $_POST["movie_shows_reqest_email_subject"]
        )
    );
    $newArrayData2 = array_replace_recursive($arrayData2, $replacementData2);
    $newJsonData2 = json_encode($newArrayData2, JSON_PRETTY_PRINT);
    file_put_contents("./api/zyx.json", $newJsonData2);
    header("Location: reporting.php?");
}
if (isset($_POST['submit_3c']))
{
    $jsonData3 = file_get_contents("./api/zyx.json");
    $arrayData3 = json_decode($jsonData3, true);
    $replacementData3 = array(
        'app_conf' => array(
            "chat_url" => $_POST["chat_url"],
            "smtp_server"		            => $_POST["smtp_server"],
	"smtp_port"		        => $_POST["smtp_port"],
	"smtp_username"		            => $_POST["smtp_username"],
	"smtp_password"		        => $_POST["smtp_password"],
	"smtp_from_email"		            => $_POST["smtp_from_email"],
        )
    );
    $newArrayData3 = array_replace_recursive($arrayData3, $replacementData3);
    $newJsonData3 = json_encode($newArrayData3, JSON_PRETTY_PRINT);
    file_put_contents("./api/zyx.json", $newJsonData3);
    header("Location: reporting.php?");
}
$jsondata = file_get_contents('./api/zyx.json');
$data = json_decode($jsondata, true);
$json = $data['app_conf'];
include ('includes/header.php');
?>
<!-- Begin Page Content -->
        <div class="container-fluid">
          <!-- Page Heading -->
          <h1 class="h3 mb-1 text-gray-8 00"> Purple Settings   Three Submenus</h1>         
          <!-- Content Row -->
          <div class="row">
            	<!-- First Column -->
            <div class="col-lg-4">
            <div class="wrapper">
              <!-- Custom codes -->
                <div class="card border-left-primary alert-primary shadow h-100 card shadow mb-4">
                <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-user-shield"></i> Issue Reporting </h6>
                </div>
                <div class="card-body">
                    <form method="post">   						 	
	   <div class="form-group ">
       <label class="control-label " for="report_issue_from_email"><strong>report_issue_from_email</strong></label>
               <div class="input-group">
                        <input class="form-control" name="report_issue_from_email"  id="report_issue_from_email"  placeholder=""value="<? echo $json['report_issue_from_email']?>"  type="text" /></div></div>
    <div class="form-group ">
       <label class="control-label " for="report_issue_to_email"><strong>report_issue_to_email</strong></label>
               <div class="input-group">
                        <input class="form-control" name="report_issue_to_email"  id="report_issue_to_email"  placeholder=""value="<? echo $json['report_issue_to_email']?>"  type="text" /></div></div>
    <div class="form-group ">
       <label class="control-label " for="report_issue"><strong>report_issue</strong></label>
               <div class="input-group">
                        <input class="form-control" name="report_issue"  id="report_issue"  placeholder=""value="<? echo $json['report_issue']?>"  type="text" /></div></div>
    <div class="form-group ">
       <label class="control-label " for="reporting_api"><strong>reporting_api</strong></label>
               <div class="input-group">
                        <input class="form-control" name="reporting_api"  id="reporting_api"  placeholder=""value="<? echo $json['reporting_api']?>"  type="text" /></div></div>
    <div class="form-group ">
       <label class="control-label " for="mqtt_server"><strong>mqtt_server</strong></label>
               <div class="input-group">
                        <input class="form-control" name="mqtt_server"  id="mqtt_server"  placeholder=""value="<? echo $json['mqtt_server']?>"  type="text" /></div></div>
    <div class="form-group ">
       <label class="control-label " for="mqtt_endpoint"><strong>mqtt_endpoint</strong></label>
               <div class="input-group">
                        <input class="form-control" name="mqtt_endpoint"  id="mqtt_endpoint"  placeholder=""value="<? echo $json['mqtt_endpoint']?>"  type="text" /></div></div>
                        <div class="form-group">
                        <button class="btn btn-primary btn-icon-split" name="submit_1c" type="submit">
                        <span class="icon text-white-50"><i class="fas fa-check"></i></span><span class="text">Submit</span>
                           </button>
                             </div>
                               </form>
                                
		                          </div></div>
		                          </div></div>
		        <!-- 2nd Column -->
            <div class="col-lg-4">
             <div class="wrapper">
              <!-- Custom codes -->
                <div class="card border-left-primary alert-primary shadow h-100 card shadow mb-4">
                <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-user-shield"></i> Channel Reporting  </h6>
                </div>
                <div class="card-body">
                <form method="post">	
 <div class="form-group ">
                        <label class="control-label requiredField" for="channel_reporting_to_email">
                        <strong> Channel Reorting To Email</strong>
                        </label>
                        <div class="input-group">
                        <input class="form-control" id="channel_reporting_to_email" name="channel_reporting_to_email" placeholder="To Email" value="<?=$json['channel_reporting_to_email']?>"type="text"/>
                        </div>
                        </div>
                        <div class="form-group ">
                        <label class="control-label requiredField" for="channel_report_email_subject">
                        <strong> Channel Reporting Subject</strong>
                        </label>
                        <div class="input-group">
                        <input class="form-control" id="channel_report_email_subject" name="channel_report_email_subject" placeholder="Subject" value="<?=$json['channel_report_email_subject']?>"type="text"/>
                        </div>
                        </div>
						<div class="form-group ">
                        <label class="control-label requiredField" for="movie_show_reqest_to_email">
                        <strong> Movie Request Email</strong>
                        </label>
                        <div class="input-group">
                        <input class="form-control" id="movie_show_reqest_to_email" name="movie_show_reqest_to_email" placeholder="To Email" value="<?=$json['movie_show_reqest_to_email']?>"type="text"/>
                        </div>
                        </div>
                        <div class="form-group ">
                        <label class="control-label requiredField" for="movie_shows_reqest_email_subject">
                        <strong> Movie Request Subject</strong>
                        </label>
                        <div class="input-group">
                        <input class="form-control" id="movie_shows_reqest_email_subject" name="movie_shows_reqest_email_subject" placeholder="Subject" value="<?=$json['movie_shows_reqest_email_subject']?>"type="text"/>
                        </div>
                        </div>
                        <div class="form-group ">
                        <label class="control-label requiredField" for="channel_reporting">
                        <strong> Allow Channel Reporting</strong> </label>
                        	<p>
							<label>True</label>
							<input type="radio" name="channel_reporting" value="true"  
							<?php  if($json['channel_reporting'] == 'true' ){ echo 'checked="checked"'; } ?> />
							<label>False</label>
							<input type="radio" name="channel_reporting" value="false" 
							<?php  if($json['channel_reporting'] == 'false' ){ echo 'checked="checked"'; } ?> />
							</p>
                        <div class="form-group ">
                        <label class="control-label requiredField" for="movie_show_reqest">
                        <strong> Allow Movie Requests</strong> 
                        	<p		
							<label>True
							<input type="radio" name="movie_show_reqest" value="true"  
							<?php  if($json['movie_show_reqest'] == 'true' ){ echo 'checked="checked"'; } ?> />
							</label>
							<label>False
							<input type="radio" name="movie_show_reqest" value="false" 
							<?php  if($json['movie_show_reqest'] == 'false' ){ echo 'checked="checked"'; } ?> />
							</label>

                        <div class="form-group">
                        <button class="btn btn-primary btn-icon-split" name="submit_2c" type="submit">
                        <span class="icon text-white-50"><i class="fas fa-check"></i></span><span class="text">Submit</span>
                          </button>
                            </div>
                              </div>
                                </form>
                                  </body>
                                    </div>
                               </form>
                               </div>
                               </div>
                               </div>
                               </div>
                        <!-- Third Column -->
            <div class="col-lg-4">
<div class="wrapper">
              <!-- Custom codes -->
                <div class="card border-left-primary alert-primary shadow h-100 card shadow mb-4">
                <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-user-shield"></i> SMPT Settings </h6>
                </div>
                <div class="card-body">
                    <form method="post">
                           <div class="form-group ">
                        <label class="control-label " for="chat_url">
                        <strong> In App Chat Url</strong> 
                        </label>
                        <div class="input-group">
                        <input class="form-control" name="chat_url"  id="chat_url"  placeholder="http://link to Chat"value="<?=$json['chat_url']?>"  type="text" />
                        </div>
                        </div>
                        <div class="form-group">
                        <label class="control-label requiredField" for="smtp_server">
                        <strong> SMTP Server</strong>
                        </label>
                        <div class="input-group">
                        <input class="form-control" id="smtp_server" name="smtp_server"  placeholder="SMTP Server"value="<?=$json['smtp_server']?>" type="text"/>
                        </div>
                        </div>
                        <div class="form-group ">
                        <label class="control-label " for="smtp_port">
                        <strong> SMTP Port</strong> 
                        </label>
                        <div class="input-group">
                        <input class="form-control" name="smtp_port"  id="smtp_port" placeholder="SMTP Port" value="<?=$json['smtp_port']?>"  type="text" />
                        </div>
                        </div>
                        <div class="form-group ">
                        <label class="control-label requiredField" for="smtp_username">
                        <strong> SMTP Username</strong>
                        </label>
                        <div class="input-group">
                        <input class="form-control" id="smtp_username" name="smtp_username" placeholder="SMTP Username" value="<?=$json['smtp_username']?>"type="text"/>
                        </div>
                        </div>
                        <div class="form-group ">
                        <label class="control-label requiredField" for="smtp_password">
                        <strong> SMTP Password</strong>
                        </label>
                        <div class="input-group">
                        <input class="form-control" id="smtp_password" name="smtp_password" placeholder="SMTP Password" value="<?=$json['smtp_password']?>"type="text"/>
                        </div>
                        </div>
                        <div class="form-group ">
                        <label class="control-label requiredField" for="smtp_from_email">
                        <strong> SMTP From Email</strong>
                        </label>
                        <div class="input-group">
                        <input class="form-control" id="smtp_from_email" name="smtp_from_email" placeholder="From Email" value="<?=$json['smtp_from_email']?>"type="text"/>
                        </div>
                        </div>

                        <div class="form-group">
                        <button class="btn btn-primary btn-icon-split" name="submit_3c" type="submit">
                        <span class="icon text-white-50"><i class="fas fa-check"></i></span><span class="text">Submit</span>
                        </button>
                          </div>      
                           </form>
                             </body>
                               </div></div>
                               </div></div>
                                 
 <script> 
$(document).ready(function () {
    $("#flash-msg").delay(3000).fadeOut("slow");
});
  </script>
<?php include ('includes/footer.php'); ?>
</html>
