JezK
Edit File: add_notification.php
<?php // start session @session_start(); // set time for session timeout $currentTime = time() + 25200; $expired = 3600; // if session not set go to login page if(!isset($_SESSION['user'])){ header("location:index.php"); } // if current time is more than session timeout back to login page if($currentTime > $_SESSION['timeout']){ session_destroy(); header("location:index.php"); } // destroy previous session timeout and create new one unset($_SESSION['timeout']); $_SESSION['timeout'] = $currentTime + $expired; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="css/font-awesome.min.css"> <link rel="stylesheet" href="css/bootstrap.css"> <link rel="stylesheet" href="css/custom.css"> <title>Pharisee</title> <link rel="icon" href="images/icons/favicon.png" type="image/icon type"> </head> <body> <div id="container"> <?php include('public/menubar.php'); include_once('includes/connect_database.php'); include_once('public/functions.php'); if(!empty($_POST)) { $notifypic=''; if(isset($_FILES["notificationImg"]["name"])) { $t = $_FILES["notificationImg"]["tmp_name"]; $n = $_FILES["notificationImg"]["name"]; $p=strtotime(date('d-m-Y H:i:s')); $k=substr(str_shuffle($p),0,5); $tfname=$k.$n; if(move_uploaded_file($t, "upload/notifyimg/".$tfname)) { $notifypic=$tfname; } } $date=date('Y-m-d H:i:s'); $title="Admin Message"; $notifyMessage=strip_tags($_POST['info']); $sql_query="INSERT INTO notification set title=?,message=?,notify_image=?,create_date=?,user_type=2"; $stmt = $connect->stmt_init(); if($stmt->prepare($sql_query)) { // Bind your variables to replace the ?s $stmt->bind_param('ssss',$title,$notifyMessage,$notifypic,$date); // Execute query $stmt->execute(); // store result $save_result = $stmt->store_result(); $type=9; $notifyMesg="Admin Message"; $mess=$notifyMessage; $attachementPic=$notifypic; $lastInsertId = $stmt -> insert_id; // include("./public/androidNotify.php"); $stmt->close(); } echo '<script>location.replace("notify.php")</script>'; } if(empty($keyword)){ $sql_query = "SELECT id,message,user_type,order_id,user_id,read_status,create_date FROM notification where delete_status=0 and user_type=2 ORDER BY id DESC "; //~ }else{ //~ $sql_query = "SELECT Category_ID, Category_name, Category_image ,main_company //~ FROM tbl_category //~ WHERE Category_name LIKE ? //~ ORDER BY Category_ID DESC LIMIT ?, ?"; //~ } $stmt_paging = $connect->stmt_init(); if($stmt_paging ->prepare($sql_query)) { // Bind your variables to replace the ?s //~ if(empty($keyword)){ //~ $stmt_paging ->bind_param('ss', $from, $offset); //~ }else{ //~ $stmt_paging ->bind_param('sss', $bind_keyword, $from, $offset); //~ } // Execute query $stmt_paging ->execute(); // store result $stmt_paging ->store_result(); $stmt_paging->bind_result($data['id'], $data['message'], $data['user_type'], $data['order_id'], $data['user_id'], $data['read_status'], $data['create_date'] ); // for paging purpose //$total_records_paging = $total_records; } } ?> <div id="content" class="container col-md-12"> <div class="col-md-12"> <h1>Add Notification</h1> <hr> </div> <br/> <div class="col-md-8"> <form method="POST" enctype= multipart/form-data> <label>Message</label> <textarea class="form-control" name="info" id="messageinfo"></textarea> <span id="msgEr" class="errormsg"></span><br/> <label>Browse</label> <input type="file" name="notificationImg" id="notificationImg" onchange="return ValidateFileUpload()"></textarea><span id="imgErr" class="errormsg"></span><br/> <input type="submit" class="btn btn-success" name="sub" value="Submit" onclick="return validate();"> </form> </div> </div > </div> </body> <script type="text/javascript"> function validate() { let messageinfo=document.getElementById('messageinfo').value; let notificationImg=document.getElementById('notificationImg').value; document.getElementById('msgEr').innerHTML=''; document.getElementById('imgErr').innerHTML=''; if(messageinfo=='') { document.getElementById('msgEr').innerHTML='Enter message'; document.getElementById('messageinfo').focus(); return false; } else if(notificationImg=='') { document.getElementById('imgErr').innerHTML='Upload image'; document.getElementById('notificationImg').focus(); return false; } } function ValidateFileUpload() { var fuData = document.getElementById('notificationImg'); var FileUploadPath = fuData.value; //To check if user upload any file if (FileUploadPath == '') { alert("Please upload an image"); } else { var Extension = FileUploadPath.substring( FileUploadPath.lastIndexOf('.') + 1).toLowerCase(); //The file uploaded is an image if (Extension == "gif" || Extension == "png" || Extension == "jpeg" || Extension == "jpg") { // To Display if (fuData.files && fuData.files[0]) { var reader = new FileReader(); // reader.onload = function(e) { // } // reader.readAsDataURL(fuData.files[0]); } } //The file upload is NOT an image else { alert("Photo only allows file types of GIF, PNG, JPG, JPEG. "); document.getElementById('notificationImg').value=''; } } } </script> </html>