reSIProcate/repro  9694
savenewresource.php
Go to the documentation of this file.
00001 <?php
00002 require('reprofunctions.php');
00003 dbgSquirt("============= Save New Resource ===============");
00004 dbgSquirt(dbgShowFile($_POST));
00005 
00006 $result = checkCookies($forceLogin,$error,FALSE);
00007 if (!($result) || $forceLogin) {
00008   // we got an error back that occurred while checkCookies was being run, 
00009   // or authentication failed.  Either way, bounce them back to the login screen
00010   header("Location: http://" . $_SERVER['HTTP_HOST'] . 
00011          dirname($_SERVER['PHP_SELF']) . 
00012          "/index.php?error=$error");
00013   exit;
00014  }
00015 $username = $_COOKIE['user'];
00016 
00017 $bounceURL = "Location: http://" . $_SERVER['HTTP_HOST'] . 
00018   dirname($_SERVER['PHP_SELF']) . 
00019   "/addresource.php?aor=" . $_POST['aor'] . 
00020   "&forwardType=" . $_POST['forwardType'] . 
00021   "&forward=" . $_POST['forward'] . 
00022   "&voicemail=" . $_POST['voicemail'] . 
00023   "&error=";
00024 
00025 // make sure post variables have arrived
00026 // note -- can't check for forward because if it was diabled on the previous
00027 // screen by clicking No, it will not be sent as a POST variable
00028 if (!isset($_POST['aor']) || !isset($_POST['forwardType']) || 
00029     !isset($_POST['voicemail'])) {
00030   header($bounceURL . "The information to create a new resource was not provided.  Please enter the information and click Save.  If this error reoccurs, contact an administrator.");
00031   exit;
00032  }
00033 
00034 // check if the user pressed cancel ... if so, back to user home
00035 if ("Cancel" == $_POST['submit']) {
00036   header("Location: http://" . $_SERVER['HTTP_HOST'] . 
00037          dirname($_SERVER['PHP_SELF']) . "/userhome.php");
00038   exit;
00039  }
00040 
00041 // check that resource name is non-blank
00042 if (empty($_POST['aor'])) {
00043   header($bounceURL . "The address must be filled in.");
00044   exit;
00045  }
00046 $aor = $_POST['aor'];
00047 
00048 // check that if forwarding is Yes, then a forward address must be provided
00049 // in this case we need to check forwardType against "Yes" rather than "Y since
00050 // the value comes from the previous form rather than that database (which only
00051 // stores 1 char)
00052 if (($_POST['forwardType'] == "Yes") && empty($_POST['forward'])) {
00053   header($bounceURL . "If forwarding is turned on, a forwarding address must be provided.");
00054   exit;
00055  }
00056 $forwardType = $_POST['forwardType'];
00057 $forward = $_POST['forward'];
00058 $voicemail = $_POST['voicemail'];
00059 
00060 // TODO: add code to validate that the forwarding address and voicemail
00061 // address are valid SIP URI's
00062 
00063 // save the resource to the database
00064 if (createResource($username,$aor,$forwardType,$forward,$voicemail)) {
00065   // new resource added successfully
00066   $title = "New Resource Added";
00067   $heading = "New Resource Added";
00068   $msg = "Successfully added the new resource <em>$aor.</em>";
00069  } else {
00070   $title = "Error While Adding Resource";
00071   $heading = "Error While Adding Resource";
00072   $msg = "An error occurred while attempting to add this resource.  Please contact an administrator.";
00073  }
00074 ?>
00075 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
00076 
00077 <!--
00078 System:  Repro
00079 File:    savenewresource.php
00080 Purpose: Validate the user provided information about a new resource and then
00081          add that resource to their profile
00082 Author:  S. Chanin
00083 -->
00084 <html>
00085 <head>
00086 <link rel="stylesheet" type="text/css" href="repro_style.css" />
00087   <title><?php echo $title; ?></title>
00088 </head>
00089 
00090 <body>
00091 <h1 class="title">Repro</h1>
00092 <h1><?php echo $heading; ?></h1>
00093 <hr />
00094 <p><?php echo $msg; ?></p>
00095 <br /><hr />
00096 <a href="userhome.php">Return to User Home</a><br />
00097 <a href="logout.php">Logout</a><br />
00098 
00099 </body>
00100 </html>