PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/admin_attendance_codes.php

http://swifttide.googlecode.com/
PHP | 159 lines | 125 code | 17 blank | 17 comment | 11 complexity | 379a48f9ddfa8c38783d32f040124bbc MD5 | raw file
  1. <?php
  2. //*
  3. // admin_attendance_codes.php
  4. // Admin Section
  5. // Display and Manage Attendance Codes Table
  6. //*
  7. //Check if admin is logged in
  8. session_start();
  9. if(!session_is_registered('UserId') || $_SESSION['UserType'] != "A")
  10. {
  11. header ("Location: index.php?action=notauth");
  12. exit;
  13. }
  14. //Include global functions
  15. include_once "common.php";
  16. //Initiate database functions
  17. include_once "ez_sql.php";
  18. //Include paging class
  19. include_once "ez_results.php";
  20. // config
  21. include_once "configuration.php";
  22. $msgFormErr="";
  23. //Check what we have to do
  24. $action=get_param("action");
  25. if (!strlen($action))
  26. $action="none";
  27. //Add or Remove Attendance Codes according to admin choice
  28. switch ($action){
  29. case "remove":
  30. $attendance_codes_id=get_param("id");
  31. if($norem=$db->get_results("SELECT attendance_history_code FROM attendance_history WHERE attendance_history_code='".$attendance_codes_id."'")){
  32. $msgFormErr=_ADMIN_ATTENDANCE_CODES_FORM_ERROR;
  33. }else{
  34. $sSQL="DELETE FROM attendance_codes WHERE attendance_codes_id='".$attendance_codes_id."'";
  35. $db->query($sSQL);
  36. };
  37. break;
  38. case "add":
  39. $attendance_codes_desc=get_param("attendancename");
  40. //Check for duplicates
  41. $tot=$db->get_var("SELECT count(*) FROM attendance_codes WHERE attendance_codes_desc='$attendance_codes_desc'");
  42. if($tot>0){
  43. $msgFormErr=_ADMIN_ATTENDANCE_CODES_DUP;
  44. }else{
  45. $sSQL="INSERT INTO attendance_codes (attendance_codes_desc) VALUES (".tosql($attendance_codes_desc, "Text").")";
  46. $db->query($sSQL);
  47. };
  48. break;
  49. case "edit":
  50. $attendance_codes_id=get_param("id");
  51. $sSQL="SELECT attendance_codes_desc FROM attendance_codes WHERE attendance_codes_id='".$attendance_codes_id."'";
  52. $attendance_codes_desc = $db->get_var($sSQL);
  53. break;
  54. case "update":
  55. $attendance_codes_id=get_param("id");
  56. $attendance_codes_desc=get_param("attendancename");
  57. $sSQL="UPDATE attendance_codes SET attendance_codes_desc='$attendance_codes_desc' WHERE attendance_codes_id='".$attendance_codes_id."'";
  58. $db->query($sSQL);
  59. break;
  60. };
  61. //Set paging appearence
  62. $ezr->results_open = "<table width=65% cellpadding=2 cellspacing=0 border=1>";
  63. $ezr->results_close = "</table>";
  64. $ezr->results_row = "<tr><td class=paging width=70%>COL2</td><td class=paging width=15% align=center><a href=admin_attendance_codes.php?action=edit&id=COL1 class=aform>&nbsp;" . _ADMIN_ATTENDANCE_CODES_EDIT . "</a></td><td class=paging width=15% align=center><a name=href_remove href=# onclick=cnfremove(COL1); class=aform>&nbsp;" . _ADMIN_ATTENDANCE_CODES_REMOVE . "</a></td></tr>";
  65. $ezr->query_mysql("SELECT attendance_codes_id, attendance_codes_desc FROM attendance_codes ORDER BY attendance_codes_desc");
  66. ?>
  67. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  68. <html xmlns="http://www.w3.org/1999/xhtml">
  69. <head>
  70. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  71. <title><?echo _BROWSER_TITLE?></title>
  72. <style type="text/css" media="all">@import "student-admin.css";</style>
  73. <SCRIPT language="JavaScript">
  74. /* Javascript function to submit form and check if field is empty */
  75. function submitform(fldName)
  76. {
  77. var f = document.forms[0];
  78. var t = f.elements[fldName];
  79. if (t.value!="")
  80. f.submit();
  81. else
  82. alert("<?php echo _ENTER_VALUE?>");
  83. }
  84. /* Javascript function to ask confirmation before removing record */
  85. function cnfremove(id) {
  86. var answer;
  87. answer = window.confirm("<?php echo _ADMIN_ATTENDANCE_CODES_SURE?>");
  88. if (answer == 1) {
  89. var url;
  90. url = "admin_attendance_codes.php?action=remove&id=" + id;
  91. window.location = url; // other browsers
  92. href_remove.href = url; // explorer
  93. }
  94. return false;
  95. }
  96. </SCRIPT>
  97. <link rel="icon" href="favicon.ico" type="image/x-icon"><link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
  98. <script type="text/javascript" language="JavaScript" src="sms.js"></script>
  99. </head>
  100. <body><img src="images/<?php echo _LOGO?>" border="0">
  101. <div id="Header">
  102. <table width="100%">
  103. <tr>
  104. <td width="50%" align="left"><font size="2">&nbsp;&nbsp;<?php echo date(_DATE_FORMAT); ?></font></td>
  105. <td width="50%"><?php echo _ADMIN_ATTENDANCE_CODES_UPPER?></td>
  106. </tr>
  107. </table>
  108. </div>
  109. <div id="Content">
  110. <h1><?php echo _ADMIN_ATTENDANCE_CODES_TITLE?></h1>
  111. <br>
  112. <?php
  113. if ($action!="edit"){
  114. //Dislay results with paging options
  115. $ezr->display();
  116. ?>
  117. <br>
  118. <form name="addattendance" method="post" action="admin_attendance_codes.php">
  119. <p class="pform"><?php echo _ADMIN_ATTENDANCE_CODES_ADD_NEW?><br>
  120. <input type="text" onChange="capitalizeMe(this)" name="attendancename" size="20">&nbsp;<A class="aform" href="javascript: submitform('attendancename')"><?php echo _ADMIN_ATTENDANCE_CODES_ADD?></a>
  121. <input type="hidden" name="action" value="add">
  122. </p>
  123. </form>
  124. <?php
  125. }else{
  126. ?>
  127. <br>
  128. <form name="editattendance" method="post" action="admin_attendance_codes.php">
  129. <p class="pform"><?php echo _ADMIN_ATTENDANCE_CODES_UPDATE_ATT?><br>
  130. <input type="text" onChange="capitalizeMe(this)" name="attendancename" size="20" value="<?php echo $attendance_codes_desc; ?>">&nbsp;<A class="aform" href="javascript: submitform('attendancename')"><?php echo _ADMIN_ATTENDANCE_CODES_UPDATE?></a>
  131. <input type="hidden" name="action" value="update">
  132. <input type="hidden" name="id" value="<?php echo $attendance_codes_id; ?>">
  133. </p>
  134. </form>
  135. <?php
  136. };
  137. ?>
  138. <h3><?php echo $msgFormErr; ?></h3>
  139. </div>
  140. <?php include "admin_maint_tables_menu.inc.php"; ?>
  141. </body>
  142. </html>