<?php 
include('view/new_header_file.php');
include_once("classes/database.class.php");
include_once("classes/oanda.php");
include_once('classes/phpToPDF.php');
?>

<link rel="stylesheet" type="text/css" href="node_modules/css-toggle-switch/dist/toggle-switch.css">




  <style type="text/css">

    .tabs-left, .tabs-right {

      border-bottom: none;

      padding-top: 2px;

  }

  .tabs-left {

    border-right: 1px solid #ddd;

  }

  .tabs-right {

    border-left: 1px solid #ddd;

  }

  .tabs-left>li, .tabs-right>li {

    float: none;

    margin-bottom: 2px;

  }

  .tabs-left>li {

    margin-right: -1px;

  }

  .tabs-right>li {

    margin-left: -1px;

  }

  .tabs-left>li.active>a,

  .tabs-left>li.active>a:hover,

  .tabs-left>li.active>a:focus {

    border-bottom-color: #ddd;

    border-right-color: transparent;

  }



  .tabs-right>li.active>a,

  .tabs-right>li.active>a:hover,

  .tabs-right>li.active>a:focus {

    border-bottom: 1px solid #ddd;

    border-left-color: transparent;

  }

  .tabs-left>li>a {

    border-radius: 4px 0 0 4px;

    margin-right: 0;

    display:block;

  }

  .tabs-right>li>a {

    border-radius: 0 4px 4px 0;

    margin-right: 0;

  }

  .vertical-text {

    margin-top:50px;

    border: none;

    position: relative;

  }

  .vertical-text>li {

    height: 20px;

    width: 120px !!important;

    margin-bottom: 100px;

  }

  .vertical-text>li>a {

    border-bottom: 1px solid #ddd;

    border-right-color: transparent;

    text-align: center;

    border-radius: 4px 4px 0px 0px;

  }

  .vertical-text>li.active>a,

  .vertical-text>li.active>a:hover,

  .vertical-text>li.active>a:focus {

    border-bottom-color: transparent;

    border-right-color: #ddd;

    border-left-color: #ddd;

  }

  .vertical-text.tabs-left {

    left: -50px;

  }

  .vertical-text.tabs-right {

    right: -50px;

  }

  .vertical-text.tabs-right>li {

    -webkit-transform: rotate(90deg);

    -moz-transform: rotate(90deg);

    -ms-transform: rotate(90deg);

    -o-transform: rotate(90deg);

    transform: rotate(90deg);

  }

  .vertical-text.tabs-left>li {

    -webkit-transform: rotate(-90deg);

    -moz-transform: rotate(-90deg);

    -ms-transform: rotate(-90deg);

    -o-transform: rotate(-90deg);

    transform: rotate(-90deg);

  }

  .tabs-left > li 

  {

    padding-top: 5px !important;

    padding-bottom: 5px !important;

  }

  .panel-heading

  {

    background-color: #F7614E !important;

    text-align: center;

    padding: 7px !important;

    font-size: 18px !important;

    font-weight: 500;

  }

  .panel-body

  {

    background-color: #0E162D !important;

    text-align: center;

    padding-top: 40px;

    padding-bottom: 40px;

    font-size: 48px !important;

  }

  .swal-modal

  {

    background-color: #202943;

  }

  .swal-title

  {

    color: #F7614E;

  }

  .swal-text

  {

    color: #fff;

  }

  .swal-icon--success:before, .swal-icon--success:after

  {

    background-color: #202943;  

  }

  .swal-icon--success__hide-corners {



    background-color: #202943;  

  }

  .lightTabs

  {

    background: #fff !important;

  }

  .lightTabs > li > a

  {

    color: #F7614E !important; 

  }

  #home

  {

    color: white;

    background: #1F2638 !important;

  }

  #rightTab, #rightTab > .crypt-tab-content

  {

    background-color: #1F2638;

  }

  .lightRightTab, .lightRightTab > div, .lightRightTab > div > #home, .lightRightTab >  .crypt-tab-content 

  {

    background-color: #fff !important;

  }

  .light-panel-body

  {

    background: #eee !important;

    color: #1F2638 !important;

  }

  .lightTableVersion, .lightTableVersion > thead, .lightTableVersion > thead > tr, .lightTableVersion > thead > tr > th, .lightTableVersion > tbody, .lightTableVersion > tbody > tr, .lightTableVersion > tbody > tr > td

  {

    background-color: #fff;

    color: #1F2638 !important;

    border: 1px solid #1F2638 !important;

  }

  .lightRightTab > div > #profile > form > div > label, .lightRightTab > div > #messages > form > div > div > label, .lightRightTab > div > #targets > form > div > div > label, .lightRightTab > div > #userSettings > #acc_type_row > form > div > label, .lightRightTab > div > #userSettings > #logRules > form > div > label

  {

    color: #1F2638 !important;

  }

  .lightRightTab > div > #profile > form > div > input, .lightRightTab > div > #profile > form > div > select, .lightRightTab > div > #messages > form > div > div > input, .lightRightTab > div > #targets > form > div > div > input, .lightRightTab > div > #userSettings > #acc_type_row > form > div > input, .lightRightTab > div > #userSettings > #logRules > form > div > input, .lightRightTab > div > #userSettings > #logRules > form > div > select

  {

    color: #1F2638 !important;

    background-color: #eee !important;  

  }

  .round {

  position: relative;

}



.round label {

  background-color: #fff;

  border: 1px solid #ccc;

  border-radius: 50%;

  cursor: pointer;

  height: 28px;

  left: 0;

  position: absolute;

  top: 0;

  width: 28px;

}



.round label:after {

  border: 2px solid #fff;

  border-top: none;

  border-right: none;

  content: "";

  height: 6px;

  left: 7px;

  opacity: 0;

  position: absolute;

  top: 8px;

  transform: rotate(-45deg);

  width: 12px;

}



.round input[type="checkbox"] {

  visibility: hidden;

}



.round input[type="checkbox"]:checked + label {

  background-color: #66bb6a;

  border-color: #66bb6a;

}



.round input[type="checkbox"]:checked + label:after {

  opacity: 1;

}




  </style>

  <?php 

    if(isset($_COOKIE['id']) && isset($_COOKIE['uid'])){

    $userId = filter_input(INPUT_COOKIE, 'id');

    $userUId = filter_input(INPUT_COOKIE, 'uid');


    $db = new database();

    $stmt = $db->db->prepare("SELECT * FROM users WHERE id = :id and uid = :uid");

    $stmt->execute(array(':id' => $userId, ':uid' => $userUId));

    $userDetails = $stmt->fetch(PDO::FETCH_OBJ);

    $fullN = $userDetails->name;

    $splitname = explode(" ", $fullN);

    $loggedIn = true;

        $firstname = $splitname[0];

    $lastname = $splitname[1];

    $accType = $userDetails->acctype;

    $starting_money = $userDetails->starting_money;



  }

  ?>


      <div class="container">
         <div class="row sm-gutters">


                    <div class="col-xs-3 col-sm-3 col-lg-3">

                         
                          <?php 

                          include_once('menu.php');

                          ?>

                      </div>

                      <div class="col-xs-9 col-sm-9 col-lg-9" id="rightTab">


                          <div class="tab-content crypt-tab-content" style="width: 100%;">







                              <div class="tab-pane active" id="userSettings" style="color: white;padding-top: 20px !important;padding-bottom: 20px !important;">





                              <?php 



                                $getRules = $db->db->prepare("SELECT *, COUNT(id) AS total FROM algovalues WHERE userid = '$userId'");



                                $getRules->execute();



                                $rulesValues = $getRules->fetch(PDO::FETCH_OBJ);



                                $rulesCheck = 0;



                                $maxMarginVal = "";

                                $maxMarginPerAccount = "";

                                $algoType = "";

                                $MaxDrawDown = "";

                                $MaxHoldtime = "";

                                $MinHoldTime = "";

                                



                                if ($rulesValues->total >= 1) {

                                  # code...

                                  $rulesCheck = 1;

                                  $maxMarginVal = $rulesValues->maxMargin;

                                  $maxMarginPerAccount = $rulesValues->maxMarginPerAccount;

                                  $algoType = $rulesValues->algoType;

                                  $MaxDrawDown = $rulesValues->maxDrawdown;

                                  $MaxHoldtime = $rulesValues->maxHoldTime;

                                  $MinHoldTime = $rulesValues->minHoldTime;

                                  $man_auto = $rulesValues->man_auto;



                                  if ($man_auto == '0') {

                                    # code...

                                    $rulesCheck = 1;

                                    

                                  }else{

                                    $rulesCheck = 0;

                                  }

                                }





                                if (isset($_POST['Algosubmit'])) {

                                  # code...

                                  $m_m = $_POST['maxMargin'];

                                  $m_m_p_a = $_POST['maxMarginPerAccount'];

                                  $algo = $_POST['algotype'];

                                  $m_d = $_POST['MaxDrawDown'];

                                  $min_h = $_POST['MinHoldTime'];

                                  $max_h = $_POST['MaxHoldtime'];





                                  



                                  if ($rulesCheck == 1) {

                                    # code...

                                    $updateRules = "UPDATE algovalues SET maxMargin = '$m_m', maxMarginPerAccount = '$m_m_p_a', algoType = '$algo', maxDrawDown = '$m_d', maxHoldTime = '$max_h', minHoldTime = '$min_h' WHERE userid = '$userId'"; 

                                  }else{



                                    $updateRules = "INSERT INTO algovalues(userid, maxMargin, maxMarginPerAccount, algoType, maxDrawDown, maxHoldTime, minHoldTime) VALUES ('$userId' ,'$m_m', '$m_m_p_a', '$algo', '$m_d', '$max_h', '$min_h')";





                                  }



                                  $stmtAlgo = $db->db->prepare($updateRules);



                                  if ($stmtAlgo->execute()) {

                                    # code...

                                    ?>



                                    <script type="text/javascript">

                                      location.href = location.href;

                                    </script>

                                    <?php 

                                  }



                                  



                                }

                              ?>



                              <div class="row">



                                <div class="col-md-6">

                                  <fieldset>

                              <label>Account Type</label>

                              <div class="switch-toggle switch-candy">





                                <input id="real" name="accType" type="radio" value="real" onchange="accType(value)" <?php if ($accType == 0) {

                                  # code...

                                  echo "checked";

                                } ?>>

                                <label for="real" onclick="" style="padding-top: 7px;padding-bottom: 7px;">Real</label>



                                <input id="demo" name="accType" type="radio" value="demo" onchange="accType(value)" <?php if ($accType == 1) {

                                  # code...

                                  echo "checked";

                                } ?>>

                                <label for="demo" onclick="" style="padding-top: 7px;padding-bottom: 7px;">Demo</label>

                                <a></a>

                              </div>

                            </fieldset>

                                </div>

                                

                              </div>







                              <div id="acc_type_row" <?php if ($accType == 0) {

                                # code...

                                ?>

                                style="display: none;"

                                <?php 

                              }else{



                                ?>

                                style="margin-top: 30px;"

                                <?php 

                              } ?>>



                                <form method="post" action="" class="row">



                                    <div class="col-md-12">

                              <label style="color: #fff;"> Starting Money </label>

                              <input type="number" id="startingMoney" class="form form-control newformcontrol" name="startingMoney" value="<?=$starting_money; ?>" placeholder="Starting Money" required />

                            </div>



                            <div class="col-md-5">

                              <button name="AccTypeSubmit" id="startmoneybtn" onclick="updateStartingMoneyFunc()" type="button" class="btn btn-md btn-success" style="border-radius: 0px !important;margin-top: 10px !important;background-color: #F7614E !important;border: none !important;width: 100% !important;color: #fff;">

                            Update Starting Money</button>

                            </div>



                          </form>



                                

                              </div>









                                

                                <div class="row" style="margin-top: 30px;">



                                  <div class="col-md-6">

                                    <fieldset>

                              <label>Algorithm Rules</label>

                              <div class="switch-toggle switch-candy">





                                <input id="week" name="view" type="radio" value="auto" onchange="algorules(value)" <?php if ($rulesCheck == 0) {

                                  # code...

                                  echo "checked";

                                } ?>>

                                <label style="padding-top: 7px;padding-bottom: 7px;" for="week" onclick="">Auto</label>



                                <input id="month" name="view" type="radio" value="manual" onchange="algorules(value)" <?php if ($rulesCheck == 1) {

                                  # code...

                                  echo "checked";

                                } ?>>

                                <label style="padding-top: 7px;padding-bottom: 7px;" for="month" onclick="">Manual</label>



                                <a></a>

                              </div>

                            </fieldset>

                                  </div>

                                  

                                </div>













                                <div id="logRules" <?php if ($rulesCheck == 0) {

                                  # code...

                                  ?>

                                  style="display: none";

                                  <?php 

                                } ?>>



                                    <form method="post" action="" class="row">



                                    <div class="col-md-12">

                              <label style="color: #fff"> Max Margin </label>

                              <input type="text" class="form form-control newformcontrol" name="maxMargin" value="<?=$maxMarginVal; ?>" placeholder="Max Margin" required />

                            </div>



                            <div class="col-md-12">

                              <label style="color: #fff"> Max Margin Per Account</label>

                              <input type="text" class="form form-control newformcontrol" name="maxMarginPerAccount" value="<?=$maxMarginPerAccount; ?>" placeholder="Max Margin Per Account" required />

                            </div>



                            <div class="col-md-12">

                              <label style="color: #fff"> Algo Type </label>

                              <select name="algotype" class="form-control newformcontrol">

                                <?php 



                                if ($algoType != "") {

                                  # code...

                                  ?>

                                  <option value="<?=$algoType; ?>"><?=$algoType; ?></option>

                                  <?php 

                                }



                                ?>



                                <?php 



                                if ($algoType == "") {

                                  # code...

                                  ?>

                                  <option value="Agressive">Agressive</option>

                                  <option value="Safe">Safe</option>

                                  <option value="Normal">Normal</option>

                                  

                                  <?php 

                                }



                                if ($algoType == "Agressive") {

                                  # code...

                                  ?>

                                  <option value="Normal">Normal</option>

                                  <option value="Safe">Safe</option>

                                  

                                  <?php 

                                }



                                if ($algoType == "Normal") {

                                  # code...

                                  ?>

                                  <option value="Agressive">Agressive</option>

                                  <option value="Safe">Safe</option>

                                  <?php 

                                }



                                if ($algoType == "Safe") {

                                  # code...

                                  ?>

                                  <option value="Agressive">Agressive</option>

                                  <option value="Normal">Normal</option>

                                  

                                  <?php 

                                }





                                ?>



                                

                              </select>

                            </div>



                            <div class="col-md-12">

                              <label style="color: #fff"> Max DrawDown </label>

                              <input type="text" class="form form-control newformcontrol" name="MaxDrawDown" value="<?=$MaxDrawDown; ?>" placeholder="Max Draw Down" required />

                            </div>



                            <div class="col-md-12">

                              <label style="color: #fff"> Max Hold Time </label>

                              <input type="text" class="form form-control newformcontrol" name="MaxHoldtime" value="<?= $MaxHoldtime; ?>" placeholder="Max Hold Time" required />

                            </div>



                            <div class="col-md-12">

                              <label style="color: #fff"> Min Hold Time </label>

                              <input type="text" class="form form-control newformcontrol" name="MinHoldTime" value="<?=$MinHoldTime; ?>" placeholder="Min Hold Time" required />

                            </div>

                                  

                            <div class="col-md-5">

                              <input name="Algosubmit" type="submit" class="btn btn-md btn-success" style="border-radius: 0px !important;margin-top: 10px !important;background-color: #F7614E !important;border: none !important;width: 100% !important;color: #fff;" value="Update Algorithm Values">

                            </div>

                                  </form>       

                                </div>







                              </div>



























                              </div>

                            </div>

          



        </div>
    </div>


<?php
include('view/new_footer_file.php');
?>


	  <script type="text/javascript">
	  	var getCar = '<?=$userDetails->pcarrier; ?>';
	  	$("#pcar").val(getCar).change();
	</script>
  <script type="text/javascript">
      
      $(function() {

            var firstcharsale = '<?=$firstSaleChar; ?>';
            var firstcharbuy = '<?=$firstBuyChar; ?>';
            var firstcharclose = '<?=$firstCloseChar ?>';

            $("#saleskey1").val(firstcharsale).change();
            $("#buykey1").val(firstcharbuy).change();
            $("#closekey1").val(firstcharclose).change();

      });

  </script>


  <script type="text/javascript">
    function updateStartingMoneyFunc()
    {
      var sm = $("#startingMoney").val();
      
      var uid = '<?=$userId; ?>';    
      
      $("#startmoneybtn").html('Please wait');

        $.post('controller/updateinfo.controller.php', {action:'smupdate', sm:sm, uid:uid})
              .done(function(data){

                var result = JSON.parse(data);
                var resu = result.result;
                if (resu == 'success') {

            swal("You have successfully updated starting money", {
            icon: "success",
            dangerMode:true,
            });

            $("#startmoneybtn").html('Update Starting Money');


            }

          });  

    }
  </script>





<script type="text/javascript">

    function algorules(values)

    {





      var uid = "<?=$userId; ?>";



      if (values == 'manual') {



        $("#logRules").show();



        $.ajax({

                  type: 'POST',

                  url: '<?=$url;?>/controller/algo.controller.php', 

                  data: {action:'algo', uid:uid, vl:values},

                  success: function(res){



                    var result = JSON.parse(res);

                    var resu = result.res;

                    



                  }

              });







      }else{

        



        $("#logRules").hide();



        $.ajax({

                  type: 'POST',

                  url: '<?=$url;?>/controller/algo.controller.php', 

                  data: {action:'algo', uid:uid, vl:values},

                  success: function(res){



                    var result = JSON.parse(res);

                    var resu = result.res;

                    



                  }

              });









      }

    }

  </script>




  <script type="text/javascript">

    function accType(values)

    {

      var acccounttype = '';

      if (values == 'real') {



        acccounttype = '0';



        $("#acc_type_row").hide();



      }else{

        acccounttype = '1';



        $("#acc_type_row").show();

      }







      var uid = "<?=$userId; ?>";





      $.ajax({

          type: 'POST',

          url: '<?=$url;?>/controller/algo.controller.php', 

          data: {action:'actionAccountType', uid:uid, type:acccounttype},

          success: function(res){



          }

      });





    }

  </script>