<?php
include_once("../include/main.inc.php");
check_session('MyCpanel', 'index.php');
?>
<?php
################ Paging Starts From Here ##################
@extract($_REQUEST);
$start = (intval($start) < 0 or $start == "") ? 0 : $start;
$pagesize = intval($pagesize) == 0 ? $pagesize = 20 : $pagesize;


if ($slno != '') {
    $sql = db_query("select * from manage_services_tbl where slno='$slno'");
    $result = mysqli_fetch_array($sql);
    $record_name = $result['question'];
}


$heading = $record_name;
$record_type = "Services";
$script_name = "manage-servicedata.php";
$redirect_script_name = "manage-servicedata.php";
$table_name = "serviceData_tbl";

####################################################

$media_logo = getMediaLogo();

//websitewithse section code
if ($slno != '' && $frmData == '1') {

    if ($id == "add_record") {


    $sqlCheck=mysqli_query($dbconn, "SELECT * FROM $table_name WHERE sid = '$slno'");

    if (mysqli_num_rows($sqlCheck) > 0) 
    {
        updateTable($table_name, "  sname='$sname' where sid='$slno'");
        header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
        exit;

    } else {

        $maxRes = mysqli_fetch_array(mysqli_query($dbconn, "select max(sorder) from `$table_name` where sid='$slno'"));
        $sorder = $maxRes[0] + 1;
        $sql = db_query("insert into $table_name set sname='$sname',sorder='$sorder',frmData='$frmData', sid='$slno'");

        header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
        exit;

    }


    }

  
      

    // if ($id == "update_record") {
    //     updateTable($table_name, "  sname='$sname' where id='$recordID'");
    //     // $_SESSION['session_message']=$record_type.' has been updated successfully';
    //     header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
    //     exit;
    // }


}

//keywords Ranking section code

if ($slno != '' && $frmData == '2') {


    if ($id == "add_record") {

       
        $sqlCheck=mysqli_query($dbconn, "SELECT * FROM $table_name WHERE sid = '$slno'");

        $keywords =  htmlentitiesDecode($keywords);
    
        if (mysqli_num_rows($sqlCheck) > 0) 
        {
            
            updateTable($table_name, "  keywords='$keywords' where sid='$slno'");
            // $_SESSION['session_message']=$record_type.' has been updated successfully';
            header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
            exit;
    
        } else {
    
           
            $maxRes = mysqli_fetch_array(mysqli_query($dbconn, "select max(sorder) from `$table_name` where sid='$slno'"));
            $sorder = $maxRes[0] + 1;

            $sql = db_query("insert into $table_name set keywords='$keywords', sorder='$sorder',frmData='$frmData',sid='$slno'");
            header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
            exit;
    
        }
    
    
        }

}

//Off Page SEO for Link-building section

if ($slno != '' && $frmData == '3') {
    if ($id == "update_record") {
       

    $sqlCheck=mysqli_query($dbconn, "SELECT * FROM $table_name WHERE sid = '$slno'");

    if (mysqli_num_rows($sqlCheck) > 0) 
    {
        updateTable($table_name, "  da='$da',das='$das',ra='$ra',ras='$ras',bl='$bl',bls='$bls' where sid='$slno'");
        // $_SESSION['session_message']=$record_type.' has been updated successfully';
        header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
        exit;
    }
    else{
  
        $maxRes = mysqli_fetch_array(mysqli_query($dbconn, "select max(sorder) from `$table_name` where sid='$slno'"));
        $sorder = $maxRes[0] + 1;

        $sql = db_query("insert into $table_name set da='$da',das='$das',ra='$ra',ras='$ras',bl='$bl',bls='$bls',sorder='$sorder',frmData='$frmData',sid='$slno'");
        header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
        exit;
    
    }
}
}


//National TV & Media Websites

if ($slno != '' && $frmData == '4') {

    if ($id == "add_record") {

        if ($_POST['media'] != '') {
            $mediaArr = $_POST['media'];
            $mediaVal = implode(',', $mediaArr);
        }
        //Award Photo 1
        if ($_FILES['image']['name'] != " ") {

            $file_extension = strtolower(getExtension($_FILES['image']['name']));
            $img_name = 'awardphoto' . uniqid();
            $img = upload_file($img_name, "image", "uploaded-files/media-image");

            $width = "285";
            $height = "156";
            $source_folder = SITE_DIR_PATH . "/uploaded-files/media-image/";
            $destination_folder = SITE_DIR_PATH . "/uploaded-files/media-image/thumbs/";
            saveResizedPhoto($img, $width, $height, $source_folder, $destination_folder);
        }

        //Award Photo 2
        if ($_FILES['image1']['name'] != " ") {
            $file_extension = strtolower(getExtension($_FILES['image1']['name']));

            $img_name1 = 'awardphoto1' . uniqid();
            $img1 = upload_file($img_name1, "image1", "uploaded-files/media-image");


            $width = "285";
            $height = "156";
            $source_folder = SITE_DIR_PATH . "/uploaded-files/media-image/";
            $destination_folder = SITE_DIR_PATH . "/uploaded-files/media-image/thumbs/";
            saveResizedPhoto($img1, $width, $height, $source_folder, $destination_folder);
        }

        // echo "insert into `$table_name` set name='$name',caption='$caption',logo_image='$img'";
        // exit;

        $maxRes = mysqli_fetch_array(mysqli_query($dbconn, "select max(sorder) from `$table_name` where sid='$slno'"));
        $sorder = $maxRes[0] + 1;

        $sql = db_query("insert into $table_name set image='$img',image1='$img1',media='$mediaVal',sorder='$sorder',frmData='$frmData',sid='$slno'");
        header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
        exit;
    }

    if ($id == "update_record") {
        // print_r($_FILES);
        // exit;

        if ($_POST['media'] != '') {
            $mediaArr = $_POST['media'];
            $mediaVal = implode(',', $mediaArr);
        }

        if ($_FILES['image']['name'] != "") {

            $file_extension = strtolower(getExtension($_FILES['image']['name']));
            if ($file_extension != "jpg" && $file_extension != "gif" && $file_extension != "jpeg" && $file_extension != "png" && $file_extension != "webp") {
                $_SESSION['session_message'] = '<div class="btn btn-warning"> Please upload image (.jpg,.gif,.png,.webp Format Only) </div>';
                header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id . "&id=edit_record" . "&recordID" . $recordID);
                exit;
            }
            if ($_FILES['image']['name'] != "") {
                $categoryRes = getResult($table_name, " where id='$recordID'", "image");

                $filename = $categoryRes['image'];
                if ($filename != "") {
                    $file = site_url . "/uploaded-files/media-image/" . $filename;
                    if (file_exists($file)) {
                        unlink($file);
                    }

                    $img_name = 'awardphoto' . uniqid();

                    $img = upload_file($img_name, "image", "uploaded-files/media-image");

                    $width = "285";
                    $height = "156";
                    $source_folder = SITE_DIR_PATH . "/uploaded-files/media-image/";
                    $destination_folder = SITE_DIR_PATH . "/uploaded-files/media-image/thumbs/";
                    saveResizedPhoto($img, $width, $height, $source_folder, $destination_folder);

                    updateTable($table_name, " image='$img' where id='$recordID'");
                }
            }
        }

        if ($_FILES['image1']['name'] != "") {

            $categoryRes = getResult($table_name, " where id='$recordID'", "image1");

            $filename = $categoryRes['image1'];
            if ($filename != "") {
                $file = site_url . "/uploaded-files/media-image/" . $filename;
                if (file_exists($file)) {
                    unlink($file);
                }

                $img_name = 'awardphoto1' . uniqid();

                $img = upload_file($img_name, "image1", "uploaded-files/media-image");

                $width = "285";
                $height = "156";
                $source_folder = SITE_DIR_PATH . "/uploaded-files/media-image/";
                $destination_folder = SITE_DIR_PATH . "/uploaded-files/media-image/thumbs/";
                saveResizedPhoto($img, $width, $height, $source_folder, $destination_folder);

                updateTable($table_name, " image1='$img' where id='$recordID'");
            }
        }



        updateTable($table_name, " media='$mediaVal' where id='$recordID'");
        // $_SESSION['session_message']=$record_type.' has been updated successfully';
        header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
        exit;
    }
}


if ($action == "Update") {
    $input = $_POST;
    $part = array_splice($input, 0, 2);

    while (list($key, $val) = each($input)) {
        if (substr($key, 0, 6) == "order_") {
            $key1 = substr($key, 6, strlen($key) - 6);

            $qry1 = db_query("update $table_name set sorder='$val' where id='$key1'");
        }
    }
    // $_SESSION['session_message']='<div class="btn btn-success">' . $record_type . ' has been updated successfully  </div>';

    header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
    exit;
}


if (isset($_POST['active'])) {
    if (!empty($_POST['arr_id'])) {
        $catid = $_POST['arr_id'];
        foreach ($catid as $id) {
            mysqli_query($dbconn, "UPDATE $table_name SET status = 'Y' WHERE id = '$id'");
        }
        // $_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' has been updated successfully</div>';
    } else {
        $_SESSION['session_message'] = '<div class="btn btn-danger">No Category selected</div>';
    }
    header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
    exit;
}

if (isset($_POST['inactive'])) {
    if (!empty($_POST['arr_id'])) {
        $catid = $_POST['arr_id'];
        foreach ($catid as $id) {
            // echo "UPDATE $table_name SET status = 'N'  WHERE slno = '$id'";
            // exit;
            mysqli_query($dbconn, "UPDATE $table_name SET status = 'N'  WHERE id = '$id'");
        }
        // $_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' has been updated successfully</div>';
    } else {
        $_SESSION['session_message'] = '<div class="btn btn-danger">No Category selected</div>';
    }
    header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
    exit;
}


if (isset($_POST['delete'])) {
    if (!empty($_POST['arr_id'])) {
        $catid = $_POST['arr_id'];
        foreach ($catid as $id) {
            mysqli_query($dbconn, "DELETE FROM $table_name WHERE id='$id'");
        }
        $_SESSION['session_message'] = '<div class="btn btn-success">' . $record_type . ' has been deleted successfully</div>';
    } else {
        $_SESSION['session_message'] = '<div class="btn btn-danger">No Category selected</div>';
    }
    header("Location: " . SITE_ADMIN_URL . "/" . $script_name . "?slno=" . $slno . "&frmData=" . $frmData . "&category_id=" . $category_id);
    exit;
}

admin_header("");
//echo  "select * from $table_name where category_id='$category_id'";

$qry = db_query("select * from $table_name where sid='$slno'");

?>
<?php
$res = getResult($table_name, " where id='$recordID' order by id asc");
$ress = getResult($table_name, " where sid='$slno'");

$mediaRes = $res['media'];
$dataM = explode(',', $mediaRes);
// print_r($dataM);
// exit;

?>
<!-- Website with SEO start -->
<?php if ($slno != '' && $frmData == '1') { ?>
<div class="content-wrapper">


    <div class="page-header">
        <h3 class="page-title">
            <?= $heading; ?> | <?= get_cat_name_company($category_id) ?>
        </h3>


        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="nav-item d-none d-lg-flex">
                    <a class="nav-link"
                        href="<?= SITE_ADMIN_URL; ?>/manage-services.php?category_id=<?= $category_id; ?>">
                        <span class="btn btn-primary">Go Back</span>
                    </a>
                </li>
            </ol>
        </nav>

    </div>

    <!-- <div class="page-header">

       
    </div> -->
    <div class="row">
        <div class="col-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    <form class="forms-sample" method="POST" action="">
                        <?php if ($category_id != null) { ?>
                        <div class="form-group" style="display:none;">
                            <label>Category</label>
                            <input class="typeahead" type="text" name="" value="<?= get_category_name($category_id) ?>"
                                placeholder="Category Name">
                        </div>
                        <?php } ?>


                        <!-- <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label>Content Line 1 <small class="text-danger">(Must be seperate by 'comma')</small></label>
                                    <input class="form-control form-control-sm" type="text" name="data[]"
                                        placeholder="Content Line 1" required>
                                </div>
                            </div>

                            <div class="col-md-3">
                                <div class="form-group">
                                    <button type="button" class="btn btn-info mr-2" name="add more" id="add">Add
                                        More</button>
                                </div>
                            </div>


                   
                        </div> -->


                        <div class="form-group">
                            <label for="exampleTextarea1">Add/Update Services *</label>
                            <textarea class="form-control editor" name="sname" rows="10"
                                required><?= $ress['sname']?></textarea>
                        </div>





                        <button type="submit" class="btn btn-primary mr-2" name="submit">Submit</button>
                        <input type="hidden" name="id" value="add_record">

                        <button class="btn btn-light"
                            onclick="javascript: window.location.href = '<?= SITE_ADMIN_URL; ?>/<?= $redirect_script_name; ?>?parentID=<?= $parentID; ?>&catID=<?= $catID; ?>'">Cancel</button>

                    </form>
                </div>
            </div>
        </div>
    </div>

</div>
</div>



</div>
</div>


<!-- Keyword Ranking on Google.com start -->

<?php  } else if ($slno != '' && $frmData == '2') { ?>
<div class="content-wrapper">

    <div class="page-header">
        <h3 class="page-title">
            <?= $heading; ?> | <?= get_cat_name_company($category_id) ?>
        </h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">

                <li class="nav-item d-none d-lg-flex">
                    <a class="nav-link"
                        href="<?= SITE_ADMIN_URL; ?>/manage-services.php?category_id=<?= $category_id; ?>">
                        <span class="btn btn-primary">Go Back</span>
                    </a>
                </li>

                <!-- <li class="breadcrumb-item"><a href="<? admin_url ?>welcome.php">Admin</a></li> -->
                <!-- <li class="breadcrumb-item active" aria-current="page"><?= $heading; ?></li> -->
            </ol>
        </nav>
    </div>


    <div class="row">
        <div class="col-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    <form class="forms-sample" method="POST" action="">
                        <?php if ($category_id != null) { ?>
                        <div class="form-group" style="display:none;">
                            <label>Category</label>
                            <input class="typeahead" type="text" name="" value="<?= get_category_name($category_id) ?>"
                                placeholder="Category Name">
                        </div>
                        <?php } ?>


                        <div class="form-group">
                            <label for="exampleTextarea1">Add/Update Keywords *</label>
                            <textarea class="form-control editor" name="keywords" rows="10"
                                required><?= $ress['keywords']?></textarea>
                        </div>


                        <button type="submit" class="btn btn-primary mr-2" name="submit">Submit</button>
                        <input type="hidden" name="id" value="add_record">

                        <button class="btn btn-light"
                            onclick="javascript: window.location.href = '<?= SITE_ADMIN_URL; ?>/<?= $redirect_script_name; ?>?parentID=<?= $parentID; ?>&catID=<?= $catID; ?>'">Cancel</button>

                    </form>
                </div>
            </div>
        </div>
    </div>

</div>
</div>
</div>
</div>
<!-- Off Page SEO for Link-building -->
<?php } else if ($slno != '' && $frmData == '3') { ?>

<div class="content-wrapper">

    <div class="page-header">
        <h3 class="page-title">
            <?= $heading; ?> | <?= get_cat_name_company($category_id) ?>
        </h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">

                <li class="nav-item d-none d-lg-flex">
                    <a class="nav-link"
                        href="<?= SITE_ADMIN_URL; ?>/manage-services.php?category_id=<?= $category_id; ?>">
                        <span class="btn btn-primary">Go Back</span>
                    </a>
                </li>

                <!-- <li class="breadcrumb-item"><a href="<? admin_url ?>welcome.php">Admin</a></li> -->
                <!-- <li class="breadcrumb-item active" aria-current="page"><?= $heading; ?></li> -->
            </ol>
        </nav>
    </div>


    <div class="row">
        <div class="col-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    <form class="forms-sample" method="POST" action="">
                        <!-- <div class="form-group">
                      <label>Keywords</label>
                        <input class="typeahead" type="text"  name="keywords" value="<?= $res['keywords'] ?>" placeholder="Keywords" required>
                 	</div> -->
                        <div class="row">
                            <div class="col-md-8">
                                <div class="form-group">
                                    <label>Domain Authority*</label>
                                    <input class="form-control form-control-sm" type="text" name="da"
                                        placeholder="Domain Authority" value="<?= $ress['da'] ?>">
                                </div>
                            </div>

                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Status*</label>
                                    <!-- <input class="form-control form-control-sm" type="text" name="das" placeholder=""
                                        value="<?= $ress['das'] ?>"> -->

                                    <select class="form-control form-control-sm" name="das" required>
                                        <option value="Average" <?=$ress['das'] == 'Average' ? 'selected' : '';?>>
                                            Average</option>
                                        <option value="Good" <?=$ress['das'] == 'Good' ? 'selected' : '';?>>Good
                                        </option>
                                        <option value="Excellent" <?=$ress['das'] == 'Excellent' ? 'selected' : '';?>>
                                            Excellent</option>

                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-8">
                                <div class="form-group">
                                    <label>Referring Domains*</label>
                                    <input class="form-control form-control-sm" type="text" name="ra"
                                        placeholder="Referring Domains" value="<?= $ress['ra'] ?>">
                                </div>
                            </div>

                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Status*</label>
                                    <!-- <input class="form-control form-control-sm" type="text" name="ras" placeholder=""
                                        value="<?= $ress['ras'] ?>"> -->

                                    <select class="form-control form-control-sm" name="ras" required>
                                        <option value="Average" <?=$ress['ras'] == 'Average' ? 'selected' : '';?>>
                                            Average</option>
                                        <option value="Good" <?=$ress['ras'] == 'Good' ? 'selected' : '';?>>Good
                                        </option>
                                        <option value="Excellent" <?=$ress['ras'] == 'Excellent' ? 'selected' : '';?>>
                                            Excellent</option>

                                    </select>
                                </div>
                            </div>


                        </div>

                        <div class="row">
                            <div class="col-md-8">
                                <div class="form-group">
                                    <label>Backlinks*</label>
                                    <input class="form-control form-control-sm" type="text" name="bl"
                                        placeholder="Backlinks" value="<?= $ress['bl'] ?>">
                                </div>
                            </div>

                            <!-- <input class="form-control form-control-sm" type="text" name="bls" placeholder=""
                            value="<?= $ress['bls'] ?>"> -->

                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Status*</label>

                                    <select class="form-control form-control-sm" name="bls" required>
                                        <option value="Average" <?=$ress['bls'] == 'Average' ? 'selected' : '';?>>
                                            Average</option>
                                        <option value="Good" <?=$ress['bls'] == 'Good' ? 'selected' : '';?>>Good
                                        </option>
                                        <option value="Excellent" <?=$ress['bls'] == 'Excellent' ? 'selected' : '';?>>
                                            Excellent</option>

                                    </select>

                                </div>
                            </div>

                        </div>


                        <button type="submit" class="btn btn-primary mr-2" name="add_record">Update</button>
                        <input type="hidden" name="recordID" value="<?= $res['id']; ?>">
                        <input type="hidden" name="id" value="update_record">

                        <button class="btn btn-light"
                            onclick="javascript: window.location.href = '<?= SITE_ADMIN_URL; ?>/<?= $redirect_script_name; ?>?parentID=<?= $parentID; ?>&catID=<?= $catID; ?>'">Cancel</button>

                    </form>
                </div>
            </div>
        </div>
    </div>

</div>
</div>

</div>
</div>

<!--  National TV & Media Websites -->

<?php } else if ($slno != '' && $frmData == '4') { ?>

<div class="content-wrapper">

    <div class="page-header">
        <h3 class="page-title">
            <?= $heading; ?>
        </h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">

                <li class="nav-item d-none d-lg-flex">
                    <a class="nav-link"
                        href="<?= SITE_ADMIN_URL; ?>/manage-services.php?category_id=<?= $category_id; ?>">
                        <span class="btn btn-primary">Go Back</span>
                    </a>
                </li>

                <!-- <li class="breadcrumb-item"><a href="<? admin_url ?>welcome.php">Admin</a></li> -->
                <!-- <li class="breadcrumb-item active" aria-current="page"><?= $heading; ?></li> -->
            </ol>
        </nav>
    </div>
    <div class="card">
        <div class="card-body">
            <div class="row">
                <div class="col-12">
                    <form method="Post" action="">
                        <div class="table-responsive">
                            <table id="order-listing" class="table table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>
                                            <div class="form-check mt-0">
                                                <label class="form-check-label">
                                                    <input type="checkbox" class="form-check-input" name="check_all"
                                                        id="check_all" value="1" onclick="checkall(this.form)">
                                                    <i class="input-helper"></i>
                                                </label>
                                            </div>
                                        </th>


                                        <th>Award Photo 1</th>
                                        <th>Award Photo 2</th>
                                        <th>Order
                                        <th>Status</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    $sl = $start + 1;
                                    while ($arr = mysqli_fetch_array($qry)) { ?>
                                    <tr>
                                        <td><input type="checkbox" name="arr_id[]" value="<?= $arr['id'] ?>"></td>


                                        <td>
                                            <p class="dongle-dcs"> <?php
                                                                        if ($arr['image'] != "") {
                                                                            $file1 = SITE_DIR_PATH . "/uploaded-files/media-image/" . $arr['image'];
                                                                            $dimens = GetImageSize($file1);
                                                                            if ($dimens[0] > 130) {
                                                                                $dimens[0] = $dimens[0] + 30;
                                                                                $dimens[1] = $dimens[1] + 80;
                                                                            } else {
                                                                                $dimens[0] = 200;
                                                                                $dimens[1] = 200;
                                                                            }
                                                                        ?>
                                              

                                                <a href="javascript:void(0);"
                                                    onClick="openwin('<?= SITE_ADMIN_URL; ?>/popup_new.php?img=media-image/<?= $arr['image']; ?>', '<?= $dimens[0]; ?>', '<?= $dimens[1]; ?>')"
                                                    class="pay-status-dcs">

                                                    <span class="adminThumb">
                                                        <!-- <img src="<? //= SITE_ADMIN_URL; ?>/popup_new.php?img=category/images/<? //= $arr['catImage']; ?>', '<? //= $dimens[0]; ?>', '<? //= $dimens[1]; ?>'"> -->
                                                        <img
                                                            src="<?=site_url?>/uploaded-files/media-image/<?= $arr['image']; ?>">
                                                    </span>

                                                </a>
                                                <?php } ?>
                                        </td>



                                        <td>
                                            <p class="dongle-dcs"> <?php
                                                                        if ($arr['image1'] != "") {
                                                                            $file1 = SITE_DIR_PATH . "/uploaded-files/media-image/" . $arr['image1'];
                                                                            $dimens = GetImageSize($file1);
                                                                            if ($dimens[0] > 130) {
                                                                                $dimens[0] = $dimens[0] + 30;
                                                                                $dimens[1] = $dimens[1] + 80;
                                                                            } else {
                                                                                $dimens[0] = 200;
                                                                                $dimens[1] = 200;
                                                                            }
                                                                        ?>
                                                <a href="javascript:void(0);"
                                                    onClick="openwin('<?= SITE_ADMIN_URL; ?>/popup_new.php?img=media-image/<?= $arr['image1']; ?>', '<?= $dimens[0]; ?>', '<?= $dimens[1]; ?>')"
                                                    class="pay-status-dcs">

                                                    <span class="adminThumb">
                                                        <!-- <img src="<? //= SITE_ADMIN_URL; ?>/popup_new.php?img=category/images/<? //= $arr['catImage']; ?>', '<? //= $dimens[0]; ?>', '<? //= $dimens[1]; ?>'"> -->
                                                        <img
                                                            src="<?=site_url?>/uploaded-files/media-image/<?= $arr['image1']; ?>">
                                                    </span>

                                                </a>
                                                <?php } ?>
                                        </td>
                                        <td>
                                            <p class="rec-date-dcs">
                                                <input name="order_<?= $arr['id']; ?>" class="form-control order"
                                                    type="text" size="2" value="<?= $arr['sorder']; ?>">
                                            </p>
                                        </td>
                                        <td>
                                            <p class="status-dcs"><?php if ($arr['status'] == 'Y') { ?><label
                                                    class="badge badge-success badge-pill">Active</label><?php } else if ($arr['status'] == 'N') { ?>
                                                <label class="badge badge-danger badge-pill">In-Active</label>
                                                <?php } ?>
                                            </p>
                                        </td>
                                        <td>
                                            <p class="download-dcs">
                                                <a
                                                    href="<?= $script_name; ?>?slno=<?= $slno ?>&id=edit_record&recordID=<?= $arr['id'] ?>&frmData=<?= $frmData; ?>&category_id=<?= $category_id; ?>">
                                                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
                                                        viewBox="0 0 24 24" fill="none" stroke="currentColor"
                                                        stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
                                                        class="feather feather-edit-3">
                                                        <path d="M12 20h9"></path>
                                                        <path
                                                            d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z">
                                                        </path>
                                                    </svg></a>
                                            </p>
                                        </td>
                                    </tr>
                                    <?php $sl++;
                                    } ?>

                                </tbody>
                            </table>

                            <div class="btn-grp">
                                <button type="submit" name="active" onclick="return select_chk()"
                                    class="btn btn-success btn-icon-text btn-sm">
                                    <i class="fas fa-toggle-on mr-1"></i>Activate
                                </button>
                                <button type="submit" name="inactive" onclick="return select_chk()"
                                    class="btn btn-warning btn-icon-text btn-sm">
                                    <i class="far fa-times-circle mr-1"></i>Deactivate
                                </button>
                                <!-- <button type="submit" name="delete" onclick="return select_chk()" class="btn btn-danger btn-icon-text btn-sm">
							<i class="fas fa-trash-alt mr-1"></i>Delete
                        </button> -->
                                <button type="submit" name="action" value="Update"
                                    class="btn btn-default btn-icon-text btn-sm">
                                    <i class="far fa-check-square mr-1"></i>Update Order
                                </button>



                                <button type="submit" name="delete" onclick="return select_chk()"
                                    class="btn btn-danger btn-icon-text btn-sm">
                                    <i class="fas fa-trash-alt mr-1"></i>Delete
                                </button>

                    </form>
                </div>
            </div>
        </div>
    </div>
    <br>
    <br>
    <div class="page-header">


        <?php if ($recordID != null) { ?>
        <h3 class="page-title">Update Data</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="<? admin_url ?>welcome.php">Admin</a></li>
                <li class="breadcrumb-item active" aria-current="page">Update Data</li>
            </ol>
        </nav>
    </div>
    <div class="row">
        <div class="col-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    <form class="forms-sample" method="POST" action="" enctype="multipart/form-data">
                        <!-- <div class="form-group">
                      <label>Keywords</label>
                        <input class="typeahead" type="text"  name="keywords" value="<?= $res['keywords'] ?>" placeholder="Keywords" required>
                 	</div> -->
                        <?php
                        if ($res['id'] == "") { ?>
                        <div class="form-group">
                            <label for="exampleTextarea1">Award Photo 1</label>
                            <input type="file" class="dropify" name="image">
                        </div>
                        <?php } else { ?>
                        <div class="form-group row">
                            <div class="col">
                                <label>Award Photo 1</label>
                                <input type="file" class="dropify" name="image">
                            </div>
                            <div class="col">
                                <img src="<?= site_url . "/uploaded-files/media-image/" . $res['image'] ?>" alt="image"
                                    style="width: 60%;">
                            </div>
                        </div>
                        <?php   } ?>

                        <?php
                        if ($res['id'] == "") { ?>
                        <div class="form-group">
                            <label for="exampleTextarea1">Award Photo 2</label>
                            <input type="file" class="dropify" name="image1">
                        </div>
                        <?php } else { ?>
                        <div class="form-group row">
                            <div class="col">
                                <label>Award Photo 1</label>
                                <input type="file" class="dropify" name="image1">
                            </div>
                            <div class="col">
                                <img src="<?= site_url . "/uploaded-files/media-image/" . $res['image1'] ?>" alt="image"
                                    style="width: 60%;">
                            </div>
                        </div>
                        <?php   } ?>

                        <div class="row">




                            <?php foreach ($media_logo as $key => $val) {



                                $checked =  in_array($val['id'], $dataM) ? 'checked' : '';

                            ?>


                            <div class="col-md-3">
                                <div class="form-check">
                                    <label class="form-check-label">
                                        <?= $val['name']; ?> <input type="checkbox"
                                            class="form-check-input <?= $key; ?>" name="media[]"
                                            value="<?= $val['id']; ?>" <?= $checked; ?>>
                                        <i class="input-helper"></i></label>
                                </div>

                            </div>
                            <?php  } ?>
                        </div>
                        <br>
                        <br>


                        <button type="submit" class="btn btn-primary mr-2" name="add_record">Update</button>
                        <input type="hidden" name="recordID" value="<?= $res['id']; ?>">
                        <input type="hidden" name="id" value="update_record">

                        <button class="btn btn-light"
                            onclick="javascript: window.location.href = '<?= SITE_ADMIN_URL; ?>/<?= $redirect_script_name; ?>?parentID=<?= $parentID; ?>&catID=<?= $catID; ?>'">Cancel</button>

                    </form>
                </div>
            </div>
        </div>
    </div>

</div>
</div>


<?php } else { ?>

<h3 class="page-title">Add National TV & Media Websites</h3>
<nav aria-label="breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="<? admin_url ?>welcome.php">Admin</a></li>
        <li class="breadcrumb-item active" aria-current="page">Add Details</li>
    </ol>
</nav>
</div>
<div class="row">
    <div class="col-12 grid-margin stretch-card">
        <div class="card">
            <div class="card-body">
                <form class="forms-sample" method="POST" action="" enctype="multipart/form-data">
                    <?php if ($category_id != null) { ?>
                    <div class="form-group" style="display:none;">
                        <label>Category</label>
                        <input class="typeahead" type="text" name="" value="<?= get_category_name($category_id) ?>"
                            placeholder="Category Name">
                    </div>
                    <?php } ?>




                    <?php
                        if ($res['id'] == "") { ?>
                    <div class="form-group">
                        <label for="exampleTextarea1">Award Photo 1</label>
                        <input type="file" class="dropify" name="image" required>
                    </div>
                    <?php } else { ?>
                    <div class="form-group row">
                        <div class="col">
                            <label>Award Photo 1</label>
                            <input type="file" class="dropify" name="image">
                        </div>
                        <div class="col">
                            <img src="<?= site_url . "/uploaded-files/media-image/" . $res['image'] ?>" alt="image"
                                style="width: 60%;">
                        </div>
                    </div>
                    <?php   } ?>

                    <?php
                        if ($res['id'] == "") { ?>
                    <div class="form-group">
                        <label for="exampleTextarea1">Award Photo 2</label>
                        <input type="file" class="dropify" name="image1" required>
                    </div>
                    <?php } else { ?>
                    <div class="form-group row">
                        <div class="col">
                            <label>Award Photo 2</label>
                            <input type="file" class="dropify" name="image1">
                        </div>
                        <div class="col">
                            <img src="<?= site_url . "/uploaded-files/media-image/" . $res['image1'] ?>" alt="image"
                                style="width: 60%;">
                        </div>
                    </div>
                    <?php   } ?>

                    <div class="row">




                        <?php foreach ($media_logo as $key => $val) { ?>


                        <div class="col-md-3">
                            <div class="form-check">
                                <label class="form-check-label">
                                    <?= $val['name']; ?> <input type="checkbox" class="form-check-input" name="media[]"
                                        value="<?= $val['id']; ?>">
                                    <i class="input-helper"></i></label>
                            </div>

                        </div>
                        <?php  } ?>





                    </div>
                    <br>
                    <br>

                    <button type="submit" class="btn btn-primary mr-2" name="submit">Submit</button>
                    <input type="hidden" name="id" value="add_record">

                    <button class="btn btn-light"
                        onclick="javascript: window.location.href = '<?= SITE_ADMIN_URL; ?>/<?= $redirect_script_name; ?>?parentID=<?= $parentID; ?>&catID=<?= $catID; ?>'">Cancel</button>

                </form>
            </div>
        </div>
    </div>
</div>

</div>
</div>
</div>

<?php }
        } ?>

<script language="javascript">
checked = false;

function checkall(frm1) {
    var aa = frm1;
    if (checked == false) {
        checked = true
    } else {
        checked = false
    }
    for (var i = 0; i < aa.elements.length; i++) {
        aa.elements[i].checked = checked;
    }
}

function select_chk() {
    var chks = document.getElementsByName('arr_id[]');
    var hasChecked = false;
    for (var i = 0; i < chks.length; i++) {
        if (chks[i].checked) {
            hasChecked = true;
            break;
        }
    }
    if (hasChecked == false) {
        alert("Please Select At Least One.");
        return false;
    }
}
</script>

<?php
admin_footer();
?>
<!-- webiste with seo -->
<script>
var sll = 2;
$('#add').click(function() {
    // alert(sll);

    $('#dynamicField').append('<div class="row" id="dataLoad' + sll +
        '"><div class="col-md-9"><div class="form-group"><input class="form-control form-control-sm" type="text" name="data[]" placeholder="Content Line ' +
        sll +
        '" required></div></div><div class="col-md-3"><div class="form-group"><button type="button" name="remove" id="' +
        sll + '" class="btn btn-danger btn_remove">X</button></div></div></div>'
    );
    sll++;
});

$(document).on('click', '.btn_remove', function() {
    var button_id = $(this).attr("id");
    $('#dataLoad' + button_id + '').remove();
});
</script>

<!-- Keyword Ranking on Google.com-->
<script>
var sllk = 2;
$('#addK').click(function() {
    // alert(sll);

    $('#dynamicFieldK').append('<div class="row" id="dataLoadK' + sllk +
        '"><div class="col-md-8"><div class="form-group"><input class="form-control form-control-sm" type="text" name="keywords[]" placeholder="Keywords ' +
        sllk +
        '" required></div></div><div class="col-md-2"><div class="form-group"><input class="form-control form-control-sm" type="number" name="ranking[]" placeholder="Ranking" required></div></div><button type="button" name="remove" id="' +
        sllk + '" class="btn btn-danger btn_remove">X</button></div>');
    sllk++;
});

$(document).on('click', '.btn_remove', function() {
    var button_id = $(this).attr("id");
    $('#dataLoadK' + button_id + '').remove();
});
</script>

<script>
$(document).ready(function() {
    $('.edtRcd').click(function() {
        $('input[name=serviceID]').val($(this).data('id'));
        $('.modal-title').text($(this).data('name'));


        $('#frmSubmit').click(function(e) {

            e.preventDefault();


            $.ajax({

                url: '<?= SITE_ADMIN_URL; ?>/ajax-data.php',

                type: 'POST',

                data: $('#forms-sample').serialize(),

                dataType: 'json',

                success: function(response) {

                }

            })

        })


    });

    // $(document).on('click', '.edit_save', function() {

    //     var sname = $("input[name=sname]").val();
    //     $.ajax({
    //         url: '<?= SITE_ADMIN_URL; ?>/updatAjaxdata.php',
    //         type: 'POST',
    //         data: {
    //             sname: sname
    //         },
    //         dataType: 'json',
    //         success: function(response) {


    //         }

    //     })



    // });


});
</script>

<?php
exit;
?>