HRDIODB
[ class tree: HRDIODB ] [ index: HRDIODB ] [ all elements ]

Source for file editmodes.php

Documentation is available at editmodes.php

  1. <?php
  2. /**
  3.  * Edit UARS Day modes.
  4.  * This file displays the UARS Day modes editing interface.
  5.  * @package HRDIODB
  6.  */
  7.  
  8. /**
  9.  * This file is part of HRDIODB.
  10.  *
  11.  * HRDIODB is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2 of the License, or
  14.  * (at your option) any later version.
  15.  *
  16.  * HRDIODB is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with HRDIODB; if not, write to the Free Software
  23.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24.  */
  25.  
  26. /** Configuration file */
  27. require_once("conf.php");
  28. /** Debugging functions */
  29. require_once("debugging.php");
  30. /** PHP session class */
  31. require_once("session_class.php");
  32. /** UARS day class */
  33. require_once("uars_day_class.php");
  34. /** HRDI database class */
  35. require_once("hrdi_db_class.php");
  36. /** Day modes class */
  37. require_once("mode_class.php");
  38. /** User class */
  39. require_once("user_class.php");
  40. /** Common class */
  41. require_once("common_class.php");
  42.  
  43. // Create class instances
  44. $session new session();
  45. $hdb new hrdi_db ($dsn);
  46. $user new user($hdb$session);
  47.  
  48. // Make sure we're authenticated
  49. if (!$user->authenticated()) {
  50.   $session->set_var("page"$_SERVER['REQUEST_URI']);
  51.   // Redirect to login page
  52.     common::redirect("login.php");
  53. }
  54.  
  55. // Page title
  56. $page_title "Editing Day Modes";
  57.  
  58. // Include the header
  59. require_once("header.php");
  60.  
  61. // Make sure we're an admin user
  62. if (!$user->is_admin()) {
  63.   error("You need to be an admin to edit mode data");
  64.   require_once("footer.php");
  65.   exit(1);
  66. }
  67.  
  68. // Get the UARS day from GET or POST data
  69. $uars_day = isset($_POST['UARS_Day']$_POST['UARS_Day'@$_GET['uars_day'];
  70.  
  71. // Verify the UARS day
  72. if (!is_numeric($uars_day|| ($uars_day 1)) {
  73.   error("UARS day is not valid");
  74.   require_once("footer.php");
  75.   exit(0);
  76. }
  77.  
  78. // Figure out the action, if any
  79. $action = isset($_POST['action']$_POST['action'@$_GET['action'];
  80.  
  81. if ($action &&
  82.     ($action != "add"&&
  83.     ($action != "edit"&&
  84.     ($action != "delete")) {
  85.   error("Invalid action");
  86.   require_once("footer.php");
  87.   exit(0);
  88. }
  89.  
  90. // Figure out the mode id, if any
  91. $id = isset($_POST['id']$_POST['id'@$_GET['id'];
  92.  
  93. if ($id && (!is_numeric($id|| ($id 0))) {
  94.   error("Mode ID is not valid");
  95.   require_once("footer.php");
  96.   exit(0);
  97. }
  98.  
  99. // Check to see if we're performing an action
  100. if (isset($_POST['add'])) {
  101.   // Unset things we don't want
  102.     unset($_POST['add']);
  103.   unset($_POST['action']);
  104.   unset($_POST['id']);
  105.  
  106.   // Add a new mode
  107.     $mode new mode($hdb);
  108.   if ($mode->add($_POST)) {
  109.     $action FALSE;
  110.   }
  111. else if (isset($_POST['update'])) {
  112.   // Unset things we don't want
  113.     unset($_POST['update']);
  114.   unset($_POST['action']);
  115.   unset($_POST['id']);
  116.  
  117.   // Update an existing mode
  118.     $mode new mode($hdb$_POST['ID']);
  119.   if ($mode->update($_POST)) {
  120.     $action FALSE;
  121.   }
  122. else if (isset($_POST['delete_yes'])) {
  123.   // Unset things we don't want
  124.     unset($_POST['delete_yes']);
  125.   unset($_POST['action']);
  126.   unset($_POST['id']);
  127.  
  128.   // Delete an existing mode
  129.     $mode new mode($hdb$_POST['ID']);
  130.   if ($mode->delete($_POST)) {
  131.     $action FALSE;
  132.   }
  133. else if (isset($_POST['delete_no'])) {
  134.   $action FALSE;
  135. }
  136.  
  137. // Create a UARS day class instance
  138. $day new uars_day ($hdb$uars_day);
  139.  
  140. // Display the mode table
  141. ?>
  142. <center>
  143. <table class="hrdi">
  144.   <tr>
  145.     <td class="label" colspan="7">Modes for UARS Day <?php print $day->day ?></td>
  146.     <td class="label_nb" align="right"><a href="day.php?uars_day=<?php print $day->day?>">View Day</a></td>
  147.   </tr>
  148.   <tr class="label">
  149.     <td>Pid</td>
  150.     <td>Az1</td>
  151.     <td>Az2</td>
  152.     <td>Az3</td>
  153.     <td>Az4</td>
  154.     <td>Description</td>
  155.     <td>Planned</td>
  156.     <td>Action</td>
  157.   </tr>
  158.   <?php foreach ($day->modes as $m?>
  159.     <tr class="data">
  160.       <td><?php print $m['Process_ID']?></td>
  161.       <td><?php print $m['Azimuth1']?></td>
  162.       <td><?php print $m['Azimuth2']?></td>
  163.       <td><?php print $m['Azimuth3']?></td>
  164.       <td><?php print $m['Azimuth4']?></td>
  165.       <td><?php print $m['Description']?></td>
  166.       <td><?php print ($m['Planned'"Yes" "No")?></td>
  167.       <td>
  168.         <a href="<?php print "{$_SERVER['PHP_SELF']}?uars_day={$day->day}&action=edit&id={$m['ID']}"?>"><img src="images/edit.png" border="0" alt="Edit" title="Edit Mode" align="center"></a>
  169.         &nbsp;
  170.         <a href="<?php print "{$_SERVER['PHP_SELF']}?uars_day={$day->day}&action=delete&id={$m['ID']}"?>"><img src="images/delete.png" border="0" alt="Delete" title="Delete Mode" align="center"></a>
  171.       </td>
  172.     </tr>
  173.   <?php ?>
  174. </table>
  175. <br/>
  176. <a href="<?php print "{$_SERVER['PHP_SELF']}?uars_day={$day->day}&action=add"?>"><img src="images/add.png" border="0" alt="Add" title="Add mode" align="middle" align="center"> Add a mode</a>
  177. <br/><br/>
  178.  
  179. <?php 
  180. // Create a mode object for a new or an existing mode
  181. if ($action == 'add'
  182.   $mode new mode($hdb);
  183. else if (($action == 'edit'|| ($action == 'delete')) {
  184.   $mode new mode($hdb$id);
  185. }
  186.  
  187. // If we're performing an action, we need to show the action table
  188. if (($action == 'add'|| ($action == 'edit'|| ($action == 'delete')) {
  189.   ?>
  190.   <form method="post" action="<?php print "{$_SERVER['PHP_SELF']}?uars_day={$day->day}"?>">
  191.   <input type="hidden" name="UARS_Day" value="<?php print $uars_day?>">
  192.   <input type="hidden" name="action" value="<?php print $action?>">
  193.   <input type="hidden" name="id" value="<?php print $id?>">
  194.   <?php
  195. }
  196.  
  197. // Add and edit actions can use the same table
  198. if (($action == 'add'|| ($action == 'edit')) {
  199. ?>
  200. <table class="hrdi">
  201.   <tr class="label">
  202.     <td>Pid / Description</td>
  203.     <td>Az1</td>
  204.     <td>Az2</td>
  205.     <td>Az3</td>
  206.     <td>Az4</td>
  207.     <td>Planned</td>
  208.   </tr>
  209.   <tr class="data">
  210.     <td>
  211.       <select name="Process_ID">
  212.       <?php
  213.         foreach ($mode->pids as $pid{
  214.           $pids[$pid['Pid']] "{$pid['Pid']} - {$pid['Description']}";
  215.         }
  216.   
  217.         common::print_select_options ($pidscommon::get_value('Process_ID'$_POST$mode->data));
  218.       ?>
  219.       </select>
  220.     </td>
  221.     <td><input type="text" size="4" maxlength="4" name="Azimuth1"
  222.                value="<?php print common::get_value('Azimuth1'$_POST$mode->data)?>"></td>
  223.     <td><input type="text" size="4" maxlength="4" name="Azimuth2"
  224.                value="<?php print common::get_value('Azimuth2'$_POST$mode->data)?>"></td>
  225.     <td><input type="text" size="4" maxlength="4" name="Azimuth3"
  226.                value="<?php print common::get_value('Azimuth3'$_POST$mode->data)?>"></td>
  227.     <td><input type="text" size="4" maxlength="4" name="Azimuth4"
  228.                value="<?php print common::get_value('Azimuth4'$_POST$mode->data)?>"></td>
  229.     <td>
  230.       <input id="Planned_yes" type="radio" name="Planned" value="1"
  231.       <?php 
  232.         if (!isset($mode->data['Planned']|| common::get_value('Planned'$_POST$mode->data)) {
  233.           print "checked";
  234.         }
  235.       ?>
  236.       > <label for="Planned_yes">Yes</label>
  237.       <input id="Planned_no" type="radio" name="Planned" value="0"
  238.       <?php
  239.         if (isset($mode->data['Planned']&& !common::get_value('Planned'$_POST$mode->data)) {
  240.           print "checked";
  241.         }
  242.       ?>
  243.       > <label for="Planned_no">No</label>
  244.     </td>
  245.   </tr>
  246.   <tr>
  247.     <td class="label" colspan="6" align="right">
  248.       <?php if ($action == 'add'?>
  249.         <input type="submit" name="add" value="Add Mode">
  250.       <?php else ?>
  251.         <input type="hidden" name="ID" value="<?php print $mode->data['ID']?>">
  252.         <input type="submit" name="update" value="Update Mode">
  253.       <?php ?>
  254.     </td>
  255.   </tr>
  256. </table>
  257. <?php
  258. // Delete action requires a different table
  259. else if ($action == 'delete'{
  260. ?>
  261. <input type="hidden" name="ID" value="<?php print $mode->data['ID']?>">
  262. <table class="hrdi">
  263.   <tr class="label">
  264.     <td>Pid / Description</td>
  265.     <td>Az1</td>
  266.     <td>Az2</td>
  267.     <td>Az3</td>
  268.     <td>Az4</td>
  269.     <td>Planned</td>
  270.   </tr>
  271.   <tr class="data">
  272.     <td><?php print $mode->data['Process_ID']?> - <?php print $mode->data['Description']?></td>
  273.     <td><?php print $mode->data['Azimuth1']?></td>
  274.     <td><?php print $mode->data['Azimuth2']?></td>
  275.     <td><?php print $mode->data['Azimuth3']?></td>
  276.     <td><?php print $mode->data['Azimuth4']?></td>
  277.     <td><?php print ($mode->data['Planned'"Yes" "No")?></td>
  278.   </tr>
  279.   <tr>
  280.     <td class="label" colspan="6" align="center">
  281.       Are you sure you want to delete this mode?
  282.       &nbsp;&nbsp;&nbsp;
  283.       <input type="submit" name="delete_yes" value="Yes">
  284.       <input type="submit" name="delete_no" value="No">
  285.     </td>
  286.   </tr>
  287. </table>
  288. <?php }
  289.  
  290. // Let's end what we started
  291. if (($action == 'add'|| ($action == 'edit'|| ($action == 'delete')) {
  292.   print "</form>";
  293. }
  294.  
  295. print "</center>";
  296.  
  297. // Include the page footer
  298. require_once("footer.php");
  299. ?>

Documentation generated on Tue, 23 Jan 2007 22:57:47 -0500 by phpDocumentor 1.3.0RC6