PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/admin_add_edit_teacher_2.php

http://swifttide.googlecode.com/
PHP | 186 lines | 142 code | 16 blank | 28 comment | 20 complexity | 3d8e44c8fe61be306179f718d01b86a5 MD5 | raw file
  1. <?php
  2. //*
  3. // admin_add_edit_teacher_2.php
  4. // Admin Section
  5. // Process update/add teacher
  6. //*
  7. //Version 1.01, April 10,2005. Fixed:inability to add teachers.
  8. //Version 1.02, April 20, 2005. Added "Access to Health" field to assign
  9. //health personnel.
  10. //V1.03 11-26-05, check for dupe username. don't add if dupe.
  11. //v1.52 12-30-05 display username/password, allow updating
  12. //v1.52 12-31-05 when updating a teacher to add web access, update web users (add the
  13. //record if it doesn't already exist.
  14. // 04-18-07 inserted missing line ("get_param") so teacher gets inserted correctly
  15. //Check if admin is logged in
  16. session_start();
  17. if(!session_is_registered('UserId') || $_SESSION['UserType'] != "A")
  18. {
  19. header ("Location: index.php?action=notauth");
  20. exit;
  21. }
  22. //Include global functions
  23. include_once "common.php";
  24. //Initiate database functions
  25. include_once "ez_sql.php";
  26. // config
  27. include_once "configuration.php";
  28. //Gather info from form
  29. $tfname=get_param("tfname");
  30. $tlname=get_param("tlname");
  31. $tmi=get_param("tmi");
  32. $school=get_param("school");
  33. $title=get_param("title");
  34. $email=get_param("email");
  35. $username=get_param("username");
  36. $password=get_param("password");
  37. $flname=$tfname." ".$tlname;
  38. $health=get_param("health");
  39. $stype=get_param("stype");
  40. $webid=get_param("webid");
  41. $action=get_param("action");
  42. if($health=='N')
  43. $stype="N";
  44. elseif($health=='A')
  45. $stype="A";
  46. else $stype="T";
  47. //Validate mandatory fields
  48. $msgFormErr="";
  49. if(!strlen($tfname))
  50. $msgFormErr .= _ADMIN_ADD_EDIT_TEACHER_2_ENTER_FIRST . "<br>";
  51. if(!strlen($tlname))
  52. $msgFormErr .= _ADMIN_ADD_EDIT_TEACHER_2_ENTER_LAST . "<br>";
  53. if(!strlen($username))
  54. $msgFormErr .= _ADMIN_ADD_EDIT_TEACHER_2_ENTER_USER . "<br>";
  55. if(!strlen($password))
  56. $msgFormErr .= _ADMIN_ADD_EDIT_TEACHER_2_ENTER_PASS . "<br>";
  57. if(!strlen($email)){
  58. $msgFormErr .= _ADMIN_ADD_EDIT_TEACHER_2_ENTER_EMAIL . "<br>";
  59. }else{
  60. $oEmail = new email;
  61. if (!$oEmail->valida($email)){
  62. $msgFormErr .= _ADMIN_ADD_EDIT_TEACHER_2_EMAIL_VALID . "<br>";
  63. };
  64. };
  65. //Check to make sure duplicate usernames are not being assigned
  66. //check for duplicate username.
  67. $tot=$db->get_var("SELECT COUNT(*) FROM web_users WHERE
  68. web_users_username='$username' AND web_users_id<>'$webid'");
  69. if($tot>0){
  70. $msgFormErr .= _ADMIN_ADD_EDIT_TEACHER_2_DUP;
  71. };
  72. //If a new user, check to make sure we're not adding dupe username.
  73. //If a new user, webid will be empty
  74. if($webid==""){
  75. $tot=$db->get_var("SELECT COUNT(*) FROM web_users WHERE
  76. web_users_username='$username'");
  77. if($tot>0){
  78. $msgFormErr .= _ADMIN_ADD_EDIT_TEACHER_2_DUP;
  79. };
  80. };
  81. //No errors on validation, insert/update record
  82. if ($msgFormErr==""){
  83. if ($action=="new"){
  84. $msg_header=_ADMIN_ADD_EDIT_TEACHER_2_ADDED;
  85. $sSQL="INSERT INTO teachers (teachers_fname, teachers_lname, teachers_mi, teachers_school, teachers_email, teachers_title, teachers_active) VALUES (".tosql($tfname, "Text").", ".tosql($tlname, "Text").", ".tosql($tmi, "text").", $school, ".tosql($email, "Text").", $title, 'Y')";
  86. $db->query($sSQL);
  87. $teacherid=mysql_insert_id();
  88. $sSQL="INSERT INTO web_users (web_users_username,
  89. web_users_password, web_users_type, web_users_relid, web_users_flname, active)
  90. VALUES ('$username', '$password', '$stype', $teacherid, '$flname', 1)";
  91. $db->query($sSQL);
  92. $msg_header=_ADMIN_ADD_EDIT_TEACHER_2_ADDED;
  93. }else{
  94. $teacherid=get_param("teacherid");
  95. $msg_header=_ADMIN_ADD_EDIT_TEACHER_2_UPDATED;
  96. $sSQL="UPDATE teachers SET teachers_fname=".tosql($tfname, "Text").", teachers_lname=".tosql($tlname, "Text").", teachers_mi=".tosql($tmi, "Text").", teachers_school='".$school."', teachers_title='".$title."', teachers_email=".tosql($email, "text")." WHERE teachers_id='".$teacherid."'";
  97. $db->query($sSQL);
  98. $webid=get_param("webid");
  99. if($webid<>""){
  100. //must update existing record.
  101. $sSQL="UPDATE web_users SET
  102. web_users_username=".tosql($username, "Text").",
  103. web_users_password=".tosql($password, "Text").",
  104. web_users_flname=".tosql($flname, "Text").",
  105. web_users_type=".tosql($stype, "Text")." WHERE web_users_id='".$webid."'";
  106. }else{
  107. //insert a new record.
  108. $sSQL="INSERT INTO web_users (web_users_username, web_users_password,
  109. web_users_type, web_users_relid, web_users_flname, active) VALUES ('$username',
  110. '$password', '$stype', $teacherid, '$flname', 1)";
  111. }
  112. $db->query($sSQL);
  113. $msg_header=_ADMIN_ADD_EDIT_TEACHER_2_UPDATED;
  114. };
  115. }else{
  116. if ($action=="new"){
  117. $msg_header=_ADMIN_ADD_EDIT_TEACHER_2_ADDING;
  118. }else{
  119. $msg_header=_ADMIN_ADD_EDIT_TEACHER_2_UPDATING;
  120. };
  121. };
  122. //Set appropriate menu
  123. $rback=get_param("rback");
  124. if(strlen($rback)){
  125. $menustudent=1;
  126. };
  127. ?>
  128. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  129. <html xmlns="http://www.w3.org/1999/xhtml">
  130. <head>
  131. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  132. <title><?php echo _BROWSER_TITLE?></title>
  133. <style type="text/css" media="all">@import "student-admin.css";</style>
  134. <link rel="icon" href="favicon.ico" type="image/x-icon"><link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
  135. <script type="text/javascript" language="JavaScript" src="sms.js"></script>
  136. </head>
  137. <body><img src="images/<?php echo _LOGO?>" border="0">
  138. <div id="Header">
  139. <table width="100%">
  140. <tr>
  141. <td width="50%" align="left"><font size="2">&nbsp;&nbsp;<?php echo date(_DATE_FORMAT); ?></font></td>
  142. <td width="50%"><?php echo _ADMIN_ADD_EDIT_TEACHER_2_UPPER?></td>
  143. </tr>
  144. </table>
  145. </div>
  146. <div id="Content">
  147. <?php
  148. //Found errors validating fields
  149. if ($msgFormErr!=""){
  150. ?>
  151. <h1><?php echo _ADMIN_ADD_EDIT_TEACHER_2_TITLE?> <?php echo $msg_header; ?> <?php echo _ADMIN_ADD_EDIT_TEACHER_2_TEACHER?></h1>
  152. <br>
  153. <h2><?php echo _ADMIN_ADD_EDIT_TEACHER_2_ERROR_BACK?></h2>
  154. <br>
  155. <h3><?php echo $msgFormErr; ?></h3>
  156. <?php
  157. }else{
  158. ?>
  159. <h1><?php echo _ADMIN_ADD_EDIT_TEACHER_2_SUCCESSFULLY?> <?php echo $msg_header; ?> <?php echo _ADMIN_ADD_EDIT_TEACHER_2_TEACHER?></h1>
  160. <br>
  161. <h2><?php echo $tfname." ".$tlname; ?></h2>
  162. <br>
  163. <a href="admin_add_edit_teacher_1.php?action=new" class="aform"><?php echo _ADMIN_ADD_EDIT_TEACHER_2_ADD_TEACHER?></a>
  164. <?php
  165. };
  166. ?>
  167. </div>
  168. <?php include "admin_menu.inc.php"; ?>
  169. </body>
  170. </html>