Jump to content

Recommended Posts

How do i update proposals with date and time when someone approves/complete/rejects the proposal? Screen123 is my database's image. Do i have to add a new column in it for date and time separately? 

Down below screen12 is my dashboard image, in here i would like to add and show the time and date of the proposal after it gets approved/rejects/completed?

1. This code here shows the approval index.

<body>
   <?php
session_start();
//Checking User Logged or Not
if(empty($_SESSION['user'])){
 header('location:index.php');
}
?>
<?php
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
$conn = mysqli_connect("localhost","root", "","registration");

    $res = $conn->query("SELECT id
                              , details      
                              , location
                              , date
                              , time
                              , reporteddept
                              , reportedname
                              , status                              
                          FROM proposals WHERE YEAR(date) = YEAR(CURDATE())
                          ORDER BY id    
                        ");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-language" content="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
    <h2 style="text-align:center; font-size:20px; inline-block; width: 180px; position: relative; left:40%; top:5px; font-weight: bold; background-color:#00FFFF; padding:6px;">DASHBOARD</h2>
<div class="w3-content w3-padding">
<style>
table {
  font-family: arial, sans-serif;
  border-collapse: separate;
  width: 100%;
  table-layout: fixed;
   background-color: #EBFFE3;
   overflow: auto; 
   flex:1;
   text-overflow: ellipsis;}
td, th {
  border: 1px solid #90D199;
  text-align: left;
  padding: 8px;
  text-overflow: ellipsis;  
  overflow: hidden;
  white-space: nowrap;}
tr:nth-child(even) {
  background-color: #dddddd;
  text-overflow: ellipsis;}
</style>  
<table>
  <h3>
    <tr style="background-color:#E4EBC5; color:orangered;">
    <th>Nearmiss No.</th>
    <th>Details</th>  
    <th>Location</th>
    <th>Date</th>
    <th>Time</th>    
    <th>Status</th>   
  </tr>
    </h3>
    <?php
        if ($row = $res->fetch_assoc()) {
            do {
                switch ($row['status']){}
                echo "<tr>
                         <td><a href='plantapproval.php?id={$row['id']}' class='w3-button w3-tiny w3-khaki'>{$row['id']}{$row['reportedname']}{$row['reporteddept']}</a></td>
                         <td>{$row['details']}</td>             
                         <td>{$row['location']}</td>
                         <td>{$row['date']}</td>
                         <td>{$row['time']}</td>
                         <td>{$row['status']}</td>                                           
                      </tr>
                     ";
            } while ($row = $res->fetch_assoc());
        }
        else {
            echo "<tr><td>No records</td></tr>" ;
        }
    ?>    
    </table>
</div>
</body>
</html>
 </body>  

2. This code here is the approval.php and i want to add the date and time when the approval button gets clicked?

<?php
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
$conn = mysqli_connect("localhost","root", "","registration");

//
//   PROCESS POSTED DATA
//
        if ($_SERVER['REQUEST_METHOD']=='POST') {
            $stmt = $conn->prepare("UPDATE proposals
                                    SET status = ?                                        
                                    WHERE id = ?
                                    ");
            $stmt->bind_param('si', $_POST['status'],$_POST['id']);
            $stmt->execute();
            
            header("Location: plantdashboard.php");
            exit;
        }
if (!isset($_GET['id']) || trim($_GET['id'])=='') {
    header("Location: ");
    exit;
}
$res = $conn->prepare("SELECT id
                            , details
                            , location
                            , date
                            , time
                            , checkbox
                            , injured
                            , agegender
                            , contact
                            , empid
                            , dept
                            , organization
                            , summary
                            , image
                            , outcome
                            , cause
                            , action
                            , reportedname
                            , position
                            , organisation
                            , reportedcontact
                            , reporteddept
                            , status
                            
                            , department
                       FROM proposals
                       WHERE id = ?
                       ");
$res->bind_param('i', $_GET['id']);
$res->execute();
$res->bind_result($id, $details, $location,  $date, $time, $checkbox,$injured,$agegender,$contact,$empid,$dept,$organization,$summary,$image,$outcome,$cause,$action,$reportedname,$position,$organisation,$reportedcontact,$reporteddept,$status,$department);
$res->fetch();
$res->close();
//
//  status-dependent processing
//
$buttons = "<div class='data'>
            <button name='status' class='w3-button w3-khaki' value='$status'>Update</button> 
            </div>";
switch ($status)  {
    case 'pending':
        $cls1 = 'class="w3-dark-gray data"';
        $buttons = "<div class='data'>
                    <button name='status' style='background-color:deepskyblue; border-radius:10px; cursor:pointer; font-size:20px;' class='w3-button w3-green' value='approved'>Approve</button> 
                    <button name='status' style='background-color:deepskyblue; border-radius:10px; cursor:pointer; font-size:20px;' class='w3-button w3-red' value='rejected'>Reject</button>         
                    </div>
                    ";
        break;
    case 'approved':
        $cls1 = 'class="w3-pale-green data"';
        break;
    case 'rejected':
        $cls1 = 'class="w3-pale-red data"';    
}
$buttons1 = "<div class='data'>
            <button name='status' class='w3-button w3-khaki' value='$status'>Update</button> 
            </div>";
switch ($status)  {
    case 'approved':
        $cls1 = 'class="w3-green data"';
        $buttons = "<div class='data'>
            <button name='status' style='background-color:deepskyblue; border-radius:10px; cursor:pointer; font-size:20px;' value='completed' disabled>Complete</button> 
            </div>";
        break;
    case 'completed':
        $cls1 = 'class="w3-pale-green data"';
        $buttons = "<div class='data'>
            <button name='status' style='background-color:deepskyblue; border-radius:10px; cursor:pointer; font-size:20px;'  value='$status' disabled>Update</button> 
            </div>";
    case 'rejected':
        $cls1 = 'class="w3-pale-green data"';
        $buttons = "<div class='data'>
            <button name='status' style='background-color:deepskyblue; border-radius:10px; cursor:pointer; font-size:20px;'  value='$status' disabled>Update</button> 
            </div>";        
}
?>

<html lang = "en">
  <head>
    <title>Proposals</title>
    <meta charset = "UTF-8" />
  </head>
  <body><button onclick="myFunction()">Print</button>

<script>
function myFunction() {
  window.print();
}
</script>
    <h1>Proposal Form No : <?php echo $id ?></h1>
    <form method='POST' id='formId'>
    
    <input type='hidden' name='id' value='<?=$id?>'>
    
        <fieldset>
        <legend>NearMiss Proposal</legend>
        
          <p>
          <b style="font-size:17px; color:black; position: absolute; top:130px;">Details of incident :</b>
          <textarea style="position:relative;"  disabled id = "myTextArea"
                  rows = "5"
                  cols = "110"><?php echo $details ?></textarea></p><br>
        <fieldset style="height:55px; width:848px; border:1px solid #888;">
          <p>
          <b style="font-size:17px; color:black; position: relative; bottom:-5px;">Location :</b>
          <textarea style="position:absolute; left:115px;" disabled id = "myTextArea"
                 rows="2" cols="56"><?php echo $location ?></textarea>
        </p>
        <br>
          <p>
          <b style="font-size:17px; color:black; position:relative; left:545px; bottom:80px;" >Date :</b><textarea style="position:relative; left:555px; bottom:70px;" disabled id = "myTextArea"
                 rows="2" cols="10"><?php echo $date ?></textarea>
         
        </p>
          <p>
          <b style="font-size:17px; color:black; position:relative; left:708px; bottom:135px;" >Time :</b><textarea style="position:relative; left:715px; bottom:125px;" disabled id = "myTextArea"
                 rows="2" cols="10"><?php echo $time ?></textarea>        
        </p>
            </fieldset>
          <p><b>Classification(Tick the appropriate one, Leave blank if you find it difficulty) :</b><br>
          <label style="font-size:16px;color:black;">Selected Classification :</label>
          <textarea style="position:relative; bottom:-3px;" disabled id = "myTextArea"
                 rows="1" cols="47"><?php echo $checkbox ?></textarea>
        </p>
         <p>
          <b style="font-size:17px;color:black;">Details of Injured(IP)(if any) :NA</b><br>
                        <b>Name:</b>
                        
                            <textarea style="position:relative; bottom:-5px;" disabled name="name" cols="25" rows="1" class="form-control"> <?php echo $injured ?></textarea>
        </p>
        <p style="position:relative; left:280px; bottom:35px;">
           <b style="position:relative; bottom:4px;">Age/Gender :</b>
                        
                            <textarea disabled name="agegender" cols="3" rows="1"><?php echo $agegender ?></textarea>
          </p>
        <p style="position:relative; left:435px; bottom:75px;">
           <b style="position:relative; bottom:4px;">Contact :</b>
                        
                            <textarea disabled name="agegender" cols="9" rows="1"><?php echo $contact ?></textarea>
          </p>
        <p style="position:relative; left:600px; bottom:115px;">
           <b style="position:relative; bottom:4px;">Organization :</b>
                        
                            <textarea disabled name="agegender" cols="9" rows="1"><?php echo $organization ?></textarea>
          </p>
        <p style="position:relative; left:0px; bottom:125px;">
           <b style="position:relative; bottom:4px;">Department :</b>
                        
                            <textarea disabled name="agegender" cols="9" rows="1"><?php echo $dept ?></textarea>
          </p>
          <p style="position:relative; left:226px; bottom:165px;">
           <b style="position:relative; bottom:4px;">Employee ID :</b>
                        
                            <textarea disabled name="agegender" cols="9" rows="1"><?php echo $empid ?></textarea>
          </p><br>
        <p>
          <b style="color:black; position: relative; bottom:204px;">Summary of Incident(Attach Photographs, if any, as Annexure1) :</b>
          <textarea style="position:absolute; left:25px; top:525px;" disabled id = "myTextArea"
                 rows="8" cols="110"><?php echo $summary ?></textarea>
        </p>
        <div class="form-group">
                        <label style="position:absolute; left:82%; top:505px;">Uploaded Images Here :</label><b style="position:relative; left:88%; bottom:198px;"><?php echo "<a href='uploads/" . $image . "'><img src='uploads/" . $image . "'height='105' width='120'></a>" ?>  </b>
                        </div>
       
        <p>
          <b style="color:black; position: relative; bottom:186px;">Potential outcome(Incase of Near Miss Case or Potential incident only) :</b>
          <textarea style="position:absolute; left:27px; top:700px;" disabled id = "myTextArea"
                 rows="8" cols="110"><?php echo $outcome ?></textarea>     
          </p>
        <p>
          <b style="color:black; position: relative; bottom:146px;">Likely cause(s) :</b>
          <textarea style="position:relative; right:112px; top:-10px;" disabled id = "myTextArea"
                 rows="8" cols="110"><?php echo $cause ?></textarea>         
          </p><br>
        <p>
          <b style="position: absolute; top:1032px;">Immediate action(s) taken :</b>
          <textarea style=" float:left; position:relative; bottom:14px;" disabled id = "myTextArea"
                    rows="8" cols="110"><?php echo $action ?></textarea></p>
       <br><br><br><br><br><br><br>
          <p style="float:left;">
          <b style="font-size:17px;color:black;">Incident reported by :</b><br><br>
                        <b>Name:</b>
                        
                            <input type="text" disabled value="<?php echo $reportedname ?>">
              <b>Position:</b>              
              <input type="text" disabled value="<?php echo $position ?>">
              <b>Organisation:</b>              
              <input type="text" disabled value="<?php echo $organisation ?>"><br><br>
              <b>Reporter contact no:</b>              
              <input type="text" disabled value="<?php echo $reportedcontact ?>">
              <b>Reporter department:</b>              
              <input type="text" disabled name="name" value= "<?php echo $reporteddept ?>">
        </p>
      <fieldset style="position:relative; top:30px; width:848px; ">        
      <p>
          <b style="font-size:18px; color:darkblue;">Status of the Proposal : <div<?=$cls1?>><?=$status?></div></b>
            
        </p>
        <!--<p>
        <b style="font-size:18px;">Select Department :</b>    
        <input type='hidden' name='department'>
                <tr>
    <td><select name='department'>
    <option value='' selected>------SELECT DEPARTMENT------</option>
    <option value='Civil'>Civil</option>
    <option value='O&M'>O&M</option>
    <option value='C&M'>C&M</option>
    <option value='MMD'>MMD</option>
    <option value='Logistics'>Logistics</option>
    <option value='HR&ADMIN'>HR&ADMIN</option>
    <option value='Fire & Safety'>Fire & Safety</option>
    <option value='IT & MIS'>IT & MIS</option>
    <option value='F&M'>F&M</option>
    <option value='EMD'>EMD</option>
    <option value='C&I'>C&I</option>
    <option value='Store'>Store</option>
    <option value='EHS'>EHS</option>
    <option value='Tech Cell'>Tech Cell</option>
    <option value='Operation'>Operation</option>
        
  </select></td>
    </tr>
      </p>-->       
 
        
        <div>
            <b style="font-size:18px;">Selected Departments : <input type="text" disabled value="<?php echo $department ?>"></b>
            
        </div>
       </fieldset> 
       
        
     <br><br><br>
      </fieldset><br>
       <div style="display: flex; justify-content: center;">
        <?=$buttons?> 
    </div>
    </form> </body></html>
<br>
<label style="background-color:deepskyblue; border-radius: 5px; font-size:32px;">Uploaded Files after Completion</label>
  <fieldset style="background-color:aliceblue;">
<br>
    <!--<div>
        <form action="upload.php" method="post" enctype="multipart/form-data">
        <input type="hidden" name="id" value="<?php echo $row->id?>"> 
            
            <div>
                 <label><b>Upload Image Here :</b></label><br><br>
                        <div>                            
                            <input type="file" name="name" enctype="multipart/form-data" id="incident_reference" onchange="document.getElementById('inc_ref').src = window.URL.createObjectURL(this.files[0]); document.getElementById('inc_ref').className +='_active'; document.getElementById('inc_ref_span').className += '_hidden'">
                        </div><iframe id="inc_ref" width="220px" height="130px"></iframe><br><br>
                <b>Details :</b><br>
    <div>
                <textarea rows="6" cols="110" style="border-radius:12px;" name="details" placeholder="Details"></textarea>
    
        </div>
        </div>
            <input type="submit" name="submit" style="background-color:deepskyblue; cursor:pointer; border-radius: 8px; font-size:19px;" value="Submit"></form>
        
    </div>-->
     <?php
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
$conn = mysqli_connect("localhost","root", "","registration");

$res = $conn->prepare("SELECT id
                            ,image, details
                            FROM upload
                       WHERE id = ?
                       ");
$res->bind_param('i', $_GET['id']);
$res->execute();
$res->bind_result($id,$image,$details);
           while ($res->fetch()) { 
    echo '<b style="font-size:18px;">Click Image to View</b><br><br>';       
    echo"<a href='completedupload/" . $image . "'><img src='completedupload/" . $image . "'height='105' width='120'></a><br><br>";  
    echo '<b style="font-size:18px;">Details :'.$details.'</b><br>';
  }          
?>
    </fieldset><br>
<fieldset style="background-color:aliceblue;">
<label style="background-color:deepskyblue; border-radius: 5px; font-size:22px;">Comment Section</label><br><br>
    <div>
        <form action="plantcomment.php" method="post">
        <input type="hidden" name="id" value="<?php echo $id ?>"> 
            
            <div>
                <b>Name :</b>
                <input type="text" name="cname" style="border-radius:5px;"><br><br>
                <b>Leave a Comment :</b>
    <div>
                <textarea rows="6" cols="110" style="border-radius:12px;" name="comment" placeholder="comment"></textarea>
    
        </div>
        </div>
            <input type="submit" name="postcomment" style="background-color:deepskyblue; cursor:pointer; border-radius: 8px; font-size:19px;" value="comment"></form>
        
</div>
 <?php
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
$conn = mysqli_connect("localhost","root", "","registration");

if (!isset($_GET['id']) || trim($_GET['id'])=='') {
    header("Location: plantapproval.php ");
    exit;
}

$res = $conn->prepare("SELECT id
                            ,cname, comment,date
                            FROM comments
                       WHERE id = ?
                       ");
$res->bind_param('i', $_GET['id']);
$res->execute();
$res->bind_result($id,$cname,$comment,$date);
           while ($res->fetch()) { 
           
    echo'<b style="color:darkmagenta">'.$cname.'  :  </b>';  
    echo ''.$comment.'<br>';
    echo'<b style="color:gray">'.$date.'</b><br><br>';
             
  }

          
?>
</fieldset>

Kindly help me i am stuck. Thanks alot.

Link to comment
https://forums.phpfreaks.com/topic/311352-php-update/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.