<?php
include("core/init.php");
include("session.php");

if(Input::particularInputExists("post","bannerId") && Input::particularInputExists("post","position"))
{

    Db::getInstance()->update("banners",array("position"=>Input::getInput("position")),array("id"=>Input::getInput("bannerId")));

}



if(Input::particularInputExists("post","registrationId") )
{

    $emailer=Db::getInstance()->get_row("select emailer from registrations WHERE id='".Input::getInput("registrationId")."'");

    echo $emailer["emailer"];

}



if(Input::particularInputExists("post","scheduleId"))
{
    $scheduleId=Input::getInput("scheduleId");
    $result=Db::getInstance()->get_row("select status from schedule where id='$scheduleId'");

    if($result[0]==0)
    {
        Db::getInstance()->update("schedule",array("status"=>1),array("id"=>$scheduleId));

        echo 'fa fa-check fa-lg text-success';

    }
    if($result[0]==1)
    {

        Db::getInstance()->update("schedule",array("status"=>0),array("id"=>$scheduleId));

        echo 'fa fa-remove fa-lg text-danger';

    }




}

if(Input::particularInputExists("post","updatePositionId") && Input::particularInputExists("post","position"))
{
    $scheduleId=(int)Input::getInput("updatePositionId");
    $position=(int)Input::getInput("position");
    Db::getInstance()->update("schedule",array("position"=>$position),array("id"=>$scheduleId));

}




/**************** Load Linked Locations **********************/

if(Input::particularInputExists("post","linkedScheduleId"))
{


    $linkedScheduleId=Input::getInput("linkedScheduleId");

    $results=Db::getInstance()->get_results("select schedule_province.id,province.province from schedule_province
JOIN province ON (province.id=schedule_province.province_id)
WHERE schedule_province.schedule_id='".$linkedScheduleId."' ORDER BY province.province");
    foreach($results as $result)
    {
        echo '<tr><td><input type="checkbox" name="linkedLocations" value="'.$result["id"].'"> '.$result["province"].' </td></tr>';
    }
   // echo '';



}
/*************************************************************************/


if (Input::particularInputExists("post", "deleteLocationIds")) {
    $deleteLocationIds = explode(",", Input::getInput("deleteLocationIds"));
    foreach ($deleteLocationIds as $deleteLocationId) {
        Db::getInstance()->delete("schedule_province", array("id" => $deleteLocationId));
    }
    Session::flash("message", '<div class="alert-success" style="padding: 5px;">Schedule Deleted From Locations.</div><Br>');
}

