*/
extract(FormVariables::GetVariables(array('action', 'id', 'data')));
if (isset($data)) {
    $data['date_stamp'] = TTDate::parseDateTime($data['date_stamp']);
}
$rf = new RequestFactory();
$action = Misc::findSubmitButton();
$action = strtolower($action);
switch ($action) {
    case 'submit':
        //Debug::setVerbosity(11);
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        $rf->StartTransaction();
        $rf->setId($data['id']);
        $rf->setUserDate($data['user_id'], $data['date_stamp']);
        $rf->setType($data['type_id']);
        $rf->setStatus(30);
        if ($rf->isNew()) {
            Debug::Text('Object is NEW!', __FILE__, __LINE__, __METHOD__, 10);
            $rf->setMessage($data['message']);
        } else {
            Debug::Text('Object is NOT new!', __FILE__, __LINE__, __METHOD__, 10);
        }
        if ($rf->isValid()) {
            $request_id = $rf->Save();
            $rf->CommitTransaction();
            //$rf->FailTransaction();
            //Redirect::Page( URLBuilder::getURL( array('refresh' => FALSE ), '../CloseWindow.php') );
            Redirect::Page(URLBuilder::getURL(array('refresh' => TRUE), '../CloseWindow.php'));
        }
        $rf->FailTransaction();
 function createRequest($type, $user_id, $date_stamp)
 {
     $date_stamp = strtotime($date_stamp);
     //Make sure date_stamp is always an integer.
     $rf = new RequestFactory();
     $rf->setUserDate($user_id, $date_stamp);
     switch ($type) {
         case 10:
             $rf->setType(30);
             //Vacation Request
             $rf->setStatus(30);
             $rf->setMessage('I would like to request 1 week vacation starting this friday.');
             $rf->setCreatedBy($user_id);
             break;
         case 20:
             $rf->setType(40);
             //Schedule Request
             $rf->setStatus(30);
             $rf->setMessage('I would like to leave at 1pm this friday.');
             $rf->setCreatedBy($user_id);
             break;
         case 30:
             $rf->setType(10);
             //Schedule Request
             $rf->setStatus(30);
             $rf->setMessage('Sorry, I forgot to punch out today. I left at 5:00PM');
             $rf->setCreatedBy($user_id);
             break;
     }
     if ($rf->isValid()) {
         $insert_id = $rf->Save();
         Debug::Text('Request ID: ' . $insert_id, __FILE__, __LINE__, __METHOD__, 10);
         return $insert_id;
     }
     Debug::Text('Failed Creating Request!', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }