<?php
session_start();
function check_session($sess_name, $REDIRECT_URL)
{
  if (!strlen($_SESSION[$sess_name])) {
    header("Location:$REDIRECT_URL");
    exit;
  }
}

function admin_header($sitetitle = "")
{ $Alertmessage = "";
?>
  <!DOCTYPE html>
  <html lang="en">

  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>
      <?= ucfirst($_SESSION['companyName']); ?> -
      <?= $sitetitle ?>
    </title>
    <!-- plugins:css -->
    <link rel="icon" href="<?= theme_url ?>images/favicon.png">
    <link rel="stylesheet" href="<?= admin_url; ?>vendors/iconfonts/font-awesome/css/all.min.css">
    <link rel="stylesheet" href="<?= admin_url; ?>vendors/css/vendor.bundle.base.css">
    <link rel="stylesheet" href="<?= admin_url; ?>vendors/css/vendor.bundle.addons.css">
 
  
    <!-- inject:css -->
    <link rel="stylesheet" href="css/style.css">
    <!-- endinject -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script type="text/javascript">var admin_link = "<?= SITE_ADMIN_URL ?>";</script>
  </head>

  <body>
    <div class="container-scroller">
      <!-- partial:partials/_navbar.html -->
      <nav class="navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row default-layout-navbar">
        <div class="text-center navbar-brand-wrapper d-flex align-items-center justify-content-center">
          <a class="navbar-brand brand-logo" href="<?= admin_url ?>welcome.php"><img src="<?= theme_url ?>images/logo.png" alt="<?= COMPANY ?>" title="<?= COMPANY ?>"></a>
          <a class="navbar-brand brand-logo-mini" href="<?= admin_url ?>welcome.php"><img src="<?= site_url; ?>/designer/images/logo-mini.png" alt="<?= COMPANY ?>" title="<?= COMPANY ?>"></a>
        </div>
        <div class="navbar-menu-wrapper d-flex align-items-stretch">
          <button class="navbar-toggler navbar-toggler align-self-center" type="button" data-toggle="minimize">
            <span class="fas fa-bars"></span>
          </button>
          <ul class="navbar-nav">
            <li class="nav-item nav-search d-none d-md-flex">
              <div class="nav-link">
                <a href="<?= site_url ?>" class="href" target="_blank">Visit Site</a>
              </div>
            </li>
          </ul>
          <ul class="navbar-nav navbar-nav-right">
            <li class="nav-item nav-profile dropdown">
              <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" id="profileDropdown">
                <span>Hi - <?= strtoupper($_SESSION['MyAdminUserName']); ?></span>
                <!-- <img src="images/faces/webpulseW.webp" alt="profile" /> -->
              </a>
              <div class="dropdown-menu dropdown-menu-right navbar-dropdown" aria-labelledby="profileDropdown">
                <a class="dropdown-item" href="<?= SITE_ADMIN_URL; ?>/general-setting.php">
                  <i class="fas fa-cog text-primary"></i>
                  Settings
                </a>
                <div class="dropdown-divider"></div>
                <a class="dropdown-item" href="<?= SITE_ADMIN_URL; ?>/index.php?id1=Logout">
                  <i class="fas fa-power-off text-primary"></i>
                  Logout
                </a>
              </div>
            </li>
          </ul>
          <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="offcanvas">
            <span class="fas fa-bars"></span>
          </button>
        </div>
      </nav>
      <!-- partial -->
      <div class="container-fluid page-body-wrapper">
        <!-- partial:partials/_settings-panel.html -->
        <div class="theme-setting-wrapper">
          <div id="settings-trigger"><i class="fas fa-fill-drip"></i></div>
          <div id="theme-settings" class="settings-panel">
            <i class="settings-close fa fa-times"></i>
            <p class="settings-heading">SIDEBAR SKINS</p>
            <div class="sidebar-bg-options selected" id="sidebar-light-theme">
              <div class="img-ss rounded-circle bg-light border mr-3"></div>Light
            </div>
            <div class="sidebar-bg-options" id="sidebar-dark-theme">
              <div class="img-ss rounded-circle bg-dark border mr-3"></div>Dark
            </div>
            <p class="settings-heading mt-2">HEADER SKINS</p>
            <div class="color-tiles mx-0 px-4">
              <div class="tiles primary"></div>
              <div class="tiles success"></div>
              <div class="tiles warning"></div>
              <div class="tiles danger"></div>
              <div class="tiles info"></div>
              <div class="tiles dark"></div>
              <div class="tiles default"></div>
            </div>
          </div>
        </div>
        <!-- partial -->
        <!-- partial:partials/_sidebar.html -->
        <nav class="sidebar sidebar-offcanvas" id="sidebar">
          <ul class="nav" id="v-pills-tab" role="tablist" aria-orientation="vertical">
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>welcome.php">
                <i class="fa fa-home menu-icon"></i>
                <span class="menu-title">Dashboard</span>
              </a>
            </li>
         
            <?php
                    $uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$lastUriSegment = array_pop($uriSegments);

                    $disble_link_user = [
                              'manage_locations.php',
                              'manage_location_content.php',
                              'addeditlocation.php',
                              'manage_scontent_new.php',
                              'manage_scontent.php',
                              'manage_scontent.php',
                              'manage_subdomainmetatag.php',
                              'manage_categories.php',
                              'addeditcategory.php',
                              'page-content.php'
                    ];
 if(($_SESSION['MyAdminUserType'] == "user") && (in_array($lastUriSegment,$disble_link_user)))
                    {
                  echo "<script>alert('You are not allowed view this page')
                  window.location.href = '/wps-admin/welcome.php';
                  </script>";
                  exit;
                            
                    } ?>
            <?php if ($_SESSION['MyAdminUserType'] == 'admin') { ?>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage-category.php">
                <i class="fa fa-list-alt menu-icon"></i>
                <span class="menu-title">Manage Category</span>
                <i class="menu-arrow"></i>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage_products.php">
                <i class="fa fa-list-alt menu-icon"></i>
                <span class="menu-title">Manage Product</span>
                <i class="menu-arrow"></i>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage-enquiry.php">
                <i class="fa fa-list-alt menu-icon"></i>
                <span class="menu-title">Manage Enquiry</span>
                <i class="menu-arrow"></i>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage-newsletter.php">
                <i class="fa fa-list-alt menu-icon"></i>
                <span class="menu-title">Manage Newsletter</span>
                <i class="menu-arrow"></i>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage-blog.php">
                <i class="fa fa-envelope menu-icon"></i>
                <span class="menu-title">Manage Blogs</span>
               
              </a>
            </li>
 
            <!-- <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage-testimonial-video.php">
                <i class="fa fa-list-alt menu-icon"></i>
                <span class="menu-title">Client Testimonial Videos</span>
              </a>
            </li> -->

            <li class="nav-item">
            <a class="nav-link" href="<?= admin_url ?>manage-banners.php">
              <i class="fa fa-film menu-icon"></i>
              <span class="menu-title">Manage Banners</span>
            </a>
          </li>
          <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage_gallery.php">
                <i class="fa fa-film menu-icon"></i>
                <span class="menu-title">Manage Gallery</span>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage_videos.php">
                <i class="fa fa-film menu-icon"></i>
                <span class="menu-title">Manage Videos</span>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage-clients.php">
                <i class="fa fa-trophy menu-icon"></i>
                <span class="menu-title">Trusted by (Client Logos)</span>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage-faqs.php">
                <i class="fa fa-question-circle menu-icon"></i>
                <span class="menu-title">Manage FAQ</span>
              </a>
            </li>

           
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage-staticpage.php">
                <i class="fab fa-trello menu-icon"></i>
                <span class="menu-title">Manage Static Pages</span>
                <i class="menu-arrow"></i>
              </a>

            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage-location.php">
                <i class="fas fa-map-marker-alt menu-icon"></i>
                <span class="menu-title">Manage Location</span>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage_success_stories.php">
                <i class="fas fas fa-user-alt menu-icon"></i>
                <span class="menu-title">Manage Testimonials</span>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage_location_content.php?category_id=0">
                <i class="fab fa-trello menu-icon"></i>
                <span class="menu-title">Manage Home Subdomain</span>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage_allpagesmeta.php">
                <i class="fab fa-trello menu-icon"></i>
                <span class="menu-title">Manage All Page Meta Tags</span>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage_staticpage_meta.php">
                <i class="fab fa-trello menu-icon"></i>
                <span class="menu-title">Add New Static Page</span>
              </a>
            </li>
          <?php }else{  ?>
           
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage_products.php">
                <i class="fa fa-list-alt menu-icon"></i>
                <span class="menu-title">Manage Product</span>
                <i class="menu-arrow"></i>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage-enquiry.php">
                <i class="fa fa-list-alt menu-icon"></i>
                <span class="menu-title">Manage Enquiry</span>
                <i class="menu-arrow"></i>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage-blog.php">
                <i class="fa fa-envelope menu-icon"></i>
                <span class="menu-title">Manage Blogs</span>
               
              </a>
            </li>
 
          
            <li class="nav-item">
            <a class="nav-link" href="<?= admin_url ?>manage-banners.php">
              <i class="fa fa-film menu-icon"></i>
              <span class="menu-title">Manage Banners</span>
            </a>
          </li>

            <li class="nav-item">
              <a class="nav-link" href="<?= admin_url ?>manage-clients.php">
                <i class="fa fa-trophy menu-icon"></i>
                <span class="menu-title">Trusted by (Client Logos)</span>
              </a>
            </li>
           
            <?php } ?>
          <li class="nav-item">
            <a class="nav-link" href="<?= admin_url; ?>/index.php?id1=Logout">
              <i class="fa fa-power-off menu-icon"></i>
              <span class="menu-title">Logout</span>
            </a>
          </li>
          </ul>
        </nav>
        <!-- partial -->
        <div class="main-panel">
          <div class="clearfix"></div>
        <?php
      }

      function admin_footer()
      { //footer for control panel...
        ?>
          <!-- partial:partials/_footer.html -->
          <footer class="footer">
            <div class="d-sm-flex justify-content-center justify-content-sm-between">
              <span class="text-muted text-center text-sm-left d-block d-sm-inline-block">Copyright ©
                <?= date('Y'); ?>.
                <?= COMPANY ?> All rights reserved.
              </span>
              <span class="float-none float-sm-right d-block mt-1 mt-sm-0 text-center">Webpulse Solution & made with <i class="far fa-heart text-danger"></i></span>
            </div>
          </footer>
          <!-- partial -->
        </div>
        <!-- main-panel ends -->
      </div>
      <!-- page-body-wrapper ends -->
    </div>
    <!-- container-scroller -->

    <!-- plugins:js -->
    <script src="<?= admin_url; ?>vendors/js/vendor.bundle.base.js"></script>
    <script src="<?= admin_url; ?>vendors/js/vendor.bundle.addons.js"></script>
    <!-- endinject -->
    <!-- Plugin js for this page-->
    <!-- End plugin js for this page-->
    <!-- inject:js -->
    <script src="<?= admin_url; ?>js/off-canvas.js"></script>
    <script src="<?= admin_url; ?>js/hoverable-collapse.js"></script>
    <script src="<?= admin_url; ?>js/misc.js"></script>
    <script src="<?= admin_url; ?>js/settings.js"></script>
    <!-- endinject -->
    <script>
    
      // Replace all textareas with class name "editor"
      var editors = CKEDITOR.replaceAll('editor', {
        extraAllowedContent: 'div',
        height: 460,
        removeButtons: 'PasteFromWord',
    
      });
  

      // Loop through all editors and customize as needed
      for (var i = 0; i < editors.length; i++) {
        var editor = editors[i];
        editor.on('instanceReady', function() {
          // Output self-closing tags the HTML4 way, like <br>.
          this.dataProcessor.writer.selfClosingEnd = '>';

          // Use line breaks for block elements, tables, and lists.
          var dtd = CKEDITOR.dtd;
          for (var e in CKEDITOR.tools.extend({}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent)) {
            this.dataProcessor.writer.setRules(e, {
              indent: true,
              breakBeforeOpen: true,
              breakAfterOpen: true,
              breakBeforeClose: true,
              breakAfterClose: true
            });
          }
          // Start in source mode.
          this.setMode('source');
        });
      }


    
    </script>
     
    
    <!-- Custom js for this page-->
    <script src="<?= admin_url; ?>js/dashboard.js"></script>
    <script src="<?= admin_url; ?>js/admin.js"></script>
    <!-- End custom js for this page-->
    <script src="<?= admin_url; ?>js/data-table.js"></script>
    <script src="<?= admin_url ?>js/dropify.js"></script>
    <!-- <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.12.0/dist/sweetalert2.all.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.12.0/dist/sweetalert2.min.css" rel="stylesheet"> -->

  <!-- endinject -->
  <script src="https://cdn.ckeditor.com/4.22.1/standard/ckeditor.js"></script>

<script>
// CKEDITOR.replace('editor', {
//     format_tags: 'h1;h2;h3;h4;h5;h6',
//     allowedContent: true
//     // Additional configuration if needed
// });


var textareas = document.querySelectorAll('.editor');
        
        // Loop through each textarea with class editor and initialize CKEditor
        textareas.forEach(function(textarea) {
            CKEDITOR.replace(textarea, {
              format_tags: 'h1;h2;h3;h4;h5;h6',
                allowedContent: true
            });
        });
</script>



<!-- 
                     <script>
                  Swal.fire({
  position: "center",
  icon: "info",
  title: "Your work has been saved",
  showConfirmButton: false,
  timer: 2000
});

                    </script> -->

  
  <style>
    .cke_notifications_area{
      display:none!important
    }
    </style>
                

                <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script>
 function initializeSortable() {
    $("#sortable").sortable({
        placeholder: "ui-sortable-placeholder"
    }).disableSelection();
}

$(document).ready(function() {
    initializeSortable();
});

    function saveOrder() {
      let product_id = $("#sortable").data("product-id");
        let order = [];
        $("#sortable li").each(function() {
            order.push($(this).data("filename"));
        });

        // Send the new order to the server using AJAX
        $.post("update_image_order.php", {
        order: order.join(","),
        product_id: product_id
    }, function(response) {
        alert(response); // Handle server response
    });
    }
</script>      
   
  </body>
  </html>
  
<?php
      }

      function pop_header($title)
      {
?>
  <!DOCTYPE html>
  <html xmlns="http://www.w3.org/1999/xhtml">

  <head>
    <title>
      <?= $title; ?>
    </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link href="<?= SITE_ADMIN_URL; ?>/admin.css" rel="stylesheet" type="text/css" />
    <script language="javascript" src="admin_js.js"></script>
  </head>

  <body>
    <p bgcolor="#f1f1f1" align="center"><br><a href="javascript:void(0);" OnClick="javascript:window.close();">Close
        Window</a>&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" OnClick="javascript:window.print();">Print Details</a>
    </p>
  <?php
      }

      function pop_footer()
      {
  ?>
    <br /><br />
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="center" bgcolor="#f1f1f1"><strong>Copyright
            <?= date('Y'); ?> &copy;
            <?= $_SESSION['companyName']; ?>
          </strong></td>
      </tr>
    </table>
    <p bgcolor="#f1f1f1" align="center"><br><a href="javascript:void(0);" OnClick="javascript:window.close();">Close
        Window</a>&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" OnClick="javascript:window.print();">Print Details</a>
    </p>
  </body>

  </html>
<?php
      }

      function admin_change_pass()
      {
        $res = getResult("admin_details", " where user_id='" . $_SESSION['MyAdminUserID'] . "' and user_type='" . $_SESSION['MyAdminUserType'] . "'");
?>
  <script type="text/javascript">
    function validate_form() {
      var frm = document.chgPwd;
      if (frm.username.value == 0) {
        alert("Please enter username");
        frm.username.focus();
        return false;
      }
      if (frm.old_password.value == 0) {
        alert("Please enter your current password");
        frm.old_password.focus();
        return false;
      }
      if (frm.password.value == 0) {
        alert("Please enter your new password");
        frm.password.focus();
        return false;
      }
      if (frm.repassword.value == 0) {
        alert("Please confirm your new password");
        frm.repassword.focus();
        return false;
      }
      if (frm.password.value != frm.repassword.value) {
        alert("Password and Confirm Password mismatched");
        frm.repassword.focus();
        return false;
      }
    }
  </script>

  <form action="" method="post" name="chgPwd" id="chgPwd" onsubmit="return validate_form();">

    <div class="form-group">
      <?php
        if ($_SESSION['session_message'] != '') {
          echo '<font color="#C05813"></font><br>';
        }
      ?>
    </div>
    <div class="form-group">
      <label>Username:<span>*</span></label>
      <input type="text" name="username" value="<?= $res['user_id']; ?>" class="form-control">
    </div>
    <div class="form-group">
      <label>Current Password:<span>*</span></label>
      <input type="password" name="old_password" class="form-control" placeholder="Enter Current Password">
    </div>
    <div class="form-group">
      <label>New Password:<span>*</span></label>
      <input type="password" name="password" placeholder="Enter New Password" class="form-control">
    </div>
    <div class="form-group">
      <label>Confirm Password:<span>*</span></label>
      <input type="password" name="repassword" placeholder="Enter Confirm Password" class="form-control">
    </div>
    <div class="form-group">
      <input type="button" name="imageField" Value="Submit" class="btn btn-success" />
      <input type="hidden" name="action" value="Update">
    </div>
  </form>
<?php
      }

      function welcome()
      {
        $q = getResult("admin_details", " where user_id='" . $_SESSION['MyAdminUserID'] . "' and user_type='" . $_SESSION['MyAdminUserType'] . "'");
?>
  <div align="left">
    <font color="red"><strong>Last Login At ::</strong></font>
    <?= showdatetime($q['last_login']); ?>
  </div>
  <hr size="2" width="100%" color="#92B2D6">
  <br /><br /><br />
  <table width="80%" align="center" cellpadding="5" cellspacing="0" border="0">
    <tr>
      <td align="center">
        <marquee behavior="alternate">
          <font color="navy" size="3">
            <?= WEBSITE_NAME; ?><br /><br />Administrator Work Area
          </font>
        </marquee>
      </td>
    </tr>
  </table>
<?php
      }

      function addEditLinks($id)
      {
        $num = getCount("static_pages", " where pageID='$id'");
        if ($num > 0) {
          $res = getResult("static_pages", " where pageID='$id'");
          echo '<script type="text/javascript">document.getElementById("pgtitle _Container").innerHTML="' . $res['pageTitle'] . '";</script>';
          $var1 = '
		<form method="post" action="" name="faqfrm" enctype="multipart/form-data">
  <div class="form-group">
        <label> Keyword 1 </label>
        <input type="text" name="keyword1" id="mtitle" rows=10 cols=100  class="form-control" value="' .$res['keyword1'].'">
        </div>
        <div class="form-group">
        <label> Keyword 2 </label>
        <input type="text" name="keyword2" id="mtitle" rows=10 cols=100  class="form-control" value="' .$res['keyword2'].'">
        </div>
   <div class="form-group">
        <label> Meta Title (<font color="red">*</font>) mandatory fields</label>
        <input type="text" name="mtitle" id="mtitle" rows=10 cols=100  class="form-control" value="'.$res['page_metatitle'] .'">
        </div>

           <div class="form-group">
        <label> Meta Desc (<font color="red">*</font>) mandatory fields</label>

        <textarea name="mdesc" rows=7 cols=50  class="form-control">'.$res['page_metadesc'] .'</textarea>
        </div>

        <div class="form-group">
        <label> Meta Keyword (<font color="red">*</font>) mandatory fields</label>
       <input type="text" name="mkeyword" id="mtitle" rows=10 cols=100  class="form-control" value="'.$res['page_keyword'] .'">
        </div>
        <div class="form-group">
        <label>Short Content (<font color="red">*</font>) mandatory fields</label>
        <textarea name="pageDesc" rows=10 cols=100  class="form-control">'.$res['pageDesc'] .'</textarea>
        </div>

         <div class="form-group">
        <label>Full Content (<font color="red">*</font>) mandatory fields</label>
        <textarea name="pageDesc1"  rows=10 cols=100  class="form-control editor">'.$res['pageDesc1'] .'</textarea>
        </div>
          <div class="form-group">
        <label>Full Content 2 </label>
        <textarea name="pageDesc2"  rows=10 cols=100  class="form-control editor">'. $res['pageDesc2'] .'</textarea>
        </div>
        <div class="form-group row">
        <div class="col">
        <label> Page Banner (<font color="red">*</font>) </label>
        <div id="bloodhound">
        <input type="file" name="banner" class="dropify">';
          if ($res['pageBanner'] != Null) {
            $banner = site_url . "/uploaded-files/page-banners/" . $res['pageBanner'];
            if (file_exists($banner)) {
              $dimens = GetImageSize($banner);
              if ($dimens[0] > 130) {
                $dimens[0] = $dimens[0] + 50;
                $dimens[1] = $dimens[1] + 80;
              } else {
                $dimens[0] = 200;
                $dimens[1] = 200;
              }
              $var1 .= "&nbsp;<a href=\"javascript:void(0);\" onClick=\"openwin('" . SITE_ADMIN_URL . "/popup_new.php?img=page-banners/" . $res['pageBanner'] . "', '$dimens[0]', '$dimens[1]')\" class=\"linkgray fontbold\"><b>View Image</b></a>&nbsp; <strong><a href=" . SITE_ADMIN_URL . "/page-content.php?cid=" . $id . "&id=remove_image&field=pageBanner\">Remove</a></strong>";
            }
          }
          $var1 .= '</div></div>
         <div class="col">
        <label>Page Image <font color="red">*</font></label>
        <div id="bloodhound">
        <input type="file" name="image" class="dropify">';
          if ($res['pageImage'] != null) {
            $banner = site_url . "/uploaded-files/page-images/" . $res['pageImage'];
            if (file_exists($banner)) {
              $dimens = GetImageSize($banner);
              if ($dimens[0] > 130) {
                $dimens[0] = $dimens[0] + 50;
                $dimens[1] = $dimens[1] + 80;
              } else {
                $dimens[0] = 200;
                $dimens[1] = 200;
              }
              $var1 .= "<a href=\"javascript:void(0);\" onClick=\"openwin('" . admin_url . "/popup_new.php?img=page-images/" . $res['pageImage'] . "','$dimens[0]', '$dimens[1]')\" class=\"linkgray fontbold\"><b>View Image</b></a>&nbsp; <strong><a href=" . SITE_ADMIN_URL . "/page-content.php?cid=" . $id . "&id=remove_image&field=pageImage\">Remove</a></strong>";
            }
          }

          $var1 .= '</div></div>
                </div>
            <div class="form-group">
            <input type="hidden" name="st_id" value="' . $id . '">
            <input type="submit" name="add_ct" value="Save" class="btn btn-success">
            </div></form>';
        } else {
          echo '<script type="text/javascript">document.getElementById("pgtitle _Container").innerHTML="????";</script>';
          $var1 = '<br><br><center>No Record Found</center>';
        }

        return $var1;
      }

      function validate_session()
      {
        $mem = explode("~", $_SESSION['SessionId']);
        $res = getResult("admin_details", " where adminId='$mem[0]'");
        $un1 = substr(md5($res['username']), 0, 10);
        $pn1 = substr(md5($res['pwd']), 0, 10);
        if ($un1 == $mem[1] && $pn1 == $mem[2]) {
          return "V";
        } else {
          return "I";
        }
      }

      function adminName()
      {
        $mem = explode("~", $_SESSION['SessionId']);
        $res = getResult("admin_details", " where user_id='" . $_SESSION['MyAdminUserID'] . "' and user_type='" . $_SESSION['MyAdminUserType'] . "'");
        if ($res['name'] != "") {
          echo $res['name'] . ",";
        } else {
          echo "Admin,";
        }
      }

      function required()
      {
        $mem = explode("~", $_SESSION['SessionId']);
        $res = getResult("admin_details", " where user_id='" . $_SESSION['MyAdminUserID'] . "' and user_type='" . $_SESSION['MyAdminUserType'] . "'");
        if (($res['name'] == "" || $res['email'] == "" || $res['website'] == "") && $_SESSION['SessionId'] != "") {
          return "<br /><center><font style='color:#ee0000;'>Some Required Fields are empty.Please enter this fields by <a href='<?=SITE_ADMIN_URL;?>/myaccount.php'>clicking here</a></font></center>";
        } else {
          return 0;
        }
      }

      function showdatetime($date)
      {
        $split_time = explode(" ", $date);
        $cdate = explode("-", $split_time[0]);
        $month = $cdate[1];
        $day = $cdate[2];
        $year = $cdate[0];

        $ctime = explode(":", $split_time[1]);
        $hours = $ctime[0];
        $minutes = $ctime[1];
        $seconds = $ctime[2];
        return date('d F, Y G:i:s', mktime($hours, $minutes, $seconds, $month, $day, $year));
      }

      function date_format_only($date)
      {
        $cdate = explode("-", $date);
        $month = $cdate[1];
        $day = $cdate[2];
        $year = $cdate[0];
        return date('d/m/Y', mktime(0, 0, 0, $month, $day, $year));
      }

      function showdate($date)
      {
        $cdate = explode("-", $date);
        $month = $cdate[1];
        $day = $cdate[2];
        $year = $cdate[0];

        if ($date != "" && $date != "0000-00-00") {
          return date('d-m-Y', mktime('', '', '', $month, $day, $year));
        } else {
          return "";
        }
      }


      function generate_unique_code($code)
      {
        $prefix = $code; // Optional prefix for the generated code
        $code = $prefix . uniqid(); // Concatenate the prefix with a unique identifier

        return $code;
      }

      function rss_write()
      {
        $pgnm = site_url . "/rss/news_feed.rss";
        $fp = fopen("$pgnm", "w");

        $newsCnt = getCount("news_tbl", " where status='Y'");
        if ($newsCnt > 0) {
          $rss_content = '<?xml version="1.0" encoding="iso-8859-1" ?> ' . "\n" . '<rss version="2.0">' . "\n" . '<channel>' . "\n" . '<title>Red Apple</title>' . "\n" . '' . "\n";
          $newsQry = db_query("select * from news_tbl where status='Y'");
          while ($newsRes = mysqli_fetch_array($newsQry)) {
            $newsRes = ms_htmlentities_decode($newsRes);
            $rss_content .= '<item>' . "\n";
            $look = array('\'', '"', '&', '<', '>');
            $replace = array('&quot;', '&quot;', '&amp;', '&lt;', '&gt;');
            $newsHeading = str_replace($look, $replace, $newsRes['newsHeading']);
            $newsDescription = str_replace($look, $replace, $newsRes['newsDescription']);
            $rss_content .= '<title>' . $newsHeading . '</title>' . "\n";

            $rss_content .= '<description>' . "\n\t\t" . $newsDescription . "\n" . '</description>' . "\n";
            $rss_content .= '</item>' . "\n";
          }
          $rss_content .= '</channel>' . "\n";
          $rss_content .= '</rss>' . "\n";
        }
        fwrite($fp, $rss_content);
        fclose($fp);
      }

      function get_team_group_name($id)
      {
        $sql = mysqli_query($GLOBALS['dbconn'], "SELECT * FROM team_group_tbl where id= $id");
        $team_group = mysqli_fetch_array($sql);
        if (is_array($team_group)) {
          return $team_group['group_name'];
        } else {
          return "";
        }
      }

      function get_cat_name($id)
      {
        $sql = mysqli_query($GLOBALS['dbconn'], "SELECT * FROM category_tbl where catID= $id");
        $team_group = mysqli_fetch_array($sql);
        if (is_array($team_group)) {
          return $team_group['catName'];
        } else {
          return "";
        }
      }

      function get_cat_name_company($id)
      {
        $sql = mysqli_query($GLOBALS['dbconn'], "SELECT * FROM casestudy_tbl where catID= $id");
        $team_group = mysqli_fetch_array($sql);
        if (is_array($team_group)) {
          return $team_group['catName'];
        } else {
          return "";
        }
      }

      function get_brand_name($id)
      {
        $sql = mysqli_query($GLOBALS['dbconn'], "SELECT * FROM brand_tbl where slno= $id");
        $team_group = mysqli_fetch_array($sql);
        if (is_array($team_group)) {
          return $team_group['brandName'];
        } else {
          return "";
        }
      }

      function get_brand_logo($id)
      {
        $sql = mysqli_query($GLOBALS['dbconn'], "SELECT * FROM brand_tbl where slno= $id");
        $team_group = mysqli_fetch_array($sql);
        if (is_array($team_group)) {
          echo $team_group['brandImage'];
          die();
        } else {
          return "";
        }
      }

      function get_location_name($id)
      {
        $sql = mysqli_query($GLOBALS['dbconn'], "SELECT * FROM location_tbl where locationID= $id");
        $team_group = mysqli_fetch_array($sql);
        if (is_array($team_group)) {
          return $team_group['locationName'];
        } else {
          return "";
        }
      }

      function get_category_count()
      {
        return mysqli_num_rows(mysqli_query($GLOBALS['dbconn'], "SELECT * FROM category_tbl"));
      }

      function get_enquiry_count()
      {
        return mysqli_num_rows(mysqli_query($GLOBALS['dbconn'], "SELECT * FROM tbl_enquiry"));
      }

      function get_blog_count()
      {
        return mysqli_num_rows(mysqli_query($GLOBALS['dbconn'], "SELECT * FROM blog_tbl where status ='Y'"));
      }

      function get_coupan_count()
      {
        return mysqli_num_rows(mysqli_query($GLOBALS['dbconn'], "SELECT * FROM coupan_codes_tbl where status ='1'"));
      }

      function get_order_count()
      {
        return mysqli_num_rows(mysqli_query($GLOBALS['dbconn'], "SELECT * FROM orders_tbl"));
      }


      function get_location_count()
      {
        return mysqli_num_rows(mysqli_query($GLOBALS['dbconn'], "SELECT * FROM location_tbl"));
      }

      unset($_SESSION['message']);
?>