PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/php/contractevents.php

https://github.com/admister/itdb
PHP | 63 lines | 52 code | 6 blank | 5 comment | 5 complexity | 489ae36b8d8defcd33b4b221923c3127 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. if (file_exists('init.php'))
  3. require_once("init.php");
  4. else
  5. require_once("../init.php");
  6. //print_r($_POST);
  7. //form submit
  8. if (isset($_POST['eventid'])) {
  9. $eventid=$_POST['eventid'];
  10. foreach($_POST as $k => $v) { $$k = $v;}
  11. if ($eventid=="new") {
  12. $sql="INSERT into contractevents ".
  13. " (contractid,siblingid , startdate , enddate, description) ".
  14. " VALUES ('$contractid','$ev_siblingid','".ymd2sec($ev_startdate)."','".ymd2sec($ev_enddate)."','$ev_description') ";
  15. db_exec($dbh,$sql,0,0,$lastid);
  16. //echo "Added $lastid, $ev_startdate";
  17. }
  18. elseif(is_numeric($eventid)) {
  19. $sql="UPDATE contractevents ".
  20. " SET siblingid='$ev_siblingid', startdate='".ymd2sec($ev_startdate)."',enddate='".ymd2sec($ev_enddate)."',description='$ev_description' ".
  21. " WHERE id='$eventid'";
  22. db_exec($dbh,$sql,0,0,$lastid);
  23. //echo "UPDATED $eventid";
  24. }
  25. }//isset id
  26. elseif (isset($_POST['deleventid'])) {
  27. $sql="DELETE FROM contractevents WHERE id='{$_POST['deleventid']}'";
  28. db_exec($dbh,$sql);
  29. //echo "DELETED ".$_POST['deleventid'];
  30. }
  31. ?>
  32. <!-- print contract events table -->
  33. <table width='100%' class='tbl2 brdr sortable' id='eventslisttbl'>
  34. <thead>
  35. <tr><th style='width:40px;'><?php te("Edit");?></th><th>ID</th><th><?php te("Related");?></th>
  36. <th><?php te("Start");?></th><th><?php te("End");?></th><th><?php te("Description");?></th></tr>
  37. </thead>
  38. <tbody>
  39. <?php
  40. if (!isset($id)) $id=$contractid;
  41. $sql="SELECT * from contractevents WHERE contractid='$id' order by startdate,id DESC";
  42. $sth=db_execute($dbh,$sql);
  43. while ($ir=$sth->fetch(PDO::FETCH_ASSOC)) {
  44. $rowid=$ir['id'];
  45. echo "\n<tr>";
  46. echo "<td><img src='images/delete.png' onClick=\"javascript:$('#ev_deldialog').data('rowid',$rowid).dialog({ position: {my:'left',at:'right',of:event,offset:'20 60'} }).dialog('open')\">";
  47. echo "<img src='images/edit.png' onClick=\"javascript:$('#ev_dialog').data('rowid',$rowid).dialog({ position: {my:'left',at:'right',of:event,offset:'20 60'} }).dialog('open')\"></td> ";
  48. echo
  49. "<td id='eventid_$rowid'>".$ir['id']."</td>".
  50. "<td id='ev_siblingid_$rowid'>".$ir['siblingid']."</td>".
  51. "<td id='ev_startdate_$rowid'>".date($dateparam,$ir['startdate'])."</td>".
  52. "<td id='ev_enddate_$rowid'>".date($dateparam,$ir['enddate'])."</td>".
  53. "<td id='ev_description_$rowid'>".$ir['description']."</td></tr>\n";
  54. }
  55. ?>
  56. </tbody>
  57. </table>