public function processRequest(User $user = NULL)
    {
        // attempt to parse and load the next image id
        $nextImageId = RequestParser::parseRequestParam($_REQUEST, self::GET_PARAM_NEXT_IMAGE_ID, RequestParser::PARAM_FILTER_TYPE_INT);
        // if no image was specified, redirect to the start journey view
        $startJourneyUrl = UrlFormatter::formatRoutingItemUrl('views/StartJourneyView');
        if (!$nextImageId) {
            header("Location: {$startJourneyUrl}");
            exit;
        }
        $dbConnection = DbConnectionUtil::getDbConnection();
        $nextImageData = ImageData::loadImageDataById($dbConnection, $nextImageId);
        if (!$nextImageData) {
            header("Location: {$startJourneyUrl}");
            exit;
        }
        parent::displayHeader($user, 'Journey');
        // attempt to parse the chosen attribute, if specified add to its tally
        if (isset($_GET[self::GET_PARAM_CHOSEN_ATTRIBUTE])) {
            $chosenAttribute = $_GET[self::GET_PARAM_CHOSEN_ATTRIBUTE];
            // verify the specified chosen attribute is actually an attribute of the chosen image
            if ($nextImageData->hasAttribute($chosenAttribute)) {
                if (!isset($_SESSION['JOURNEY_ATTRIBUTE_MAP'][$chosenAttribute])) {
                    $_SESSION['JOURNEY_ATTRIBUTE_MAP'][$chosenAttribute] = 1;
                } else {
                    $_SESSION['JOURNEY_ATTRIBUTE_MAP'][$chosenAttribute]++;
                }
            }
        }
        // store the current image id, in the journey session array, check for membership incase of a page re-load
        if (!in_array($nextImageId, $_SESSION['JOURNEY_IMAGE_LIST'])) {
            $_SESSION['JOURNEY_IMAGE_LIST'][] = $nextImageId;
        }
        $commonAttributeImageDataTupleList = NULL;
        $commonAttributeImageIdList = NULL;
        $randomImageDataList = NULL;
        // find NUM_SIMILAR_CHOICES common images if possible
        $commonAttributeImageIdTupleList = ImageAttribute::loadCommonAttributeImageIdTupleList($dbConnection, $nextImageId, $_SESSION['JOURNEY_IMAGE_LIST']);
        //print( "<br/>common id list: " ); print_r( $commonAttributeImageIdTupleList ); print("<br/>" );
        shuffle($commonAttributeImageIdTupleList);
        $commonAttributeImageIdList = array();
        $commonAttributeImageDataTupleList = array();
        while (count($commonAttributeImageDataTupleList) < self::NUM_SIMILAR_CHOICES && count($commonAttributeImageIdTupleList) > 0) {
            $currentEntry = array();
            $commonAttributeImageIdTuple = array_shift($commonAttributeImageIdTupleList);
            if (!in_array($commonAttributeImageIdTuple['imageId'], $commonAttributeImageDataTupleList) && !in_array($commonAttributeImageIdTuple['imageId'], $_SESSION['JOURNEY_IMAGE_LIST'])) {
                $imageData = ImageData::loadImageDataById($dbConnection, $commonAttributeImageIdTuple['imageId']);
                //print( "<br/>Image Data: " ); print_r( $imageData ); print( '<br/>' );
                $commonAttributeImageIdList[] = $commonAttributeImageIdTuple['imageId'];
                $currentEntry['imageData'] = $imageData;
                $currentEntry['attribute'] = $commonAttributeImageIdTuple['attribute'];
                $commonAttributeImageDataTupleList[] = $currentEntry;
            }
        }
        //print( "<br/>common map: " ); print_r( $commonAttributeImageDataTupleList ); print("<br/>" );
        // add a random image to the choices list, and fill in the gaps if NUM_SIMILAR_CHOICES could not be found, if possible
        /*
          print( "<br/>commonAttributeImageDataTupleList: " ); print_r( $commonAttributeImageDataTupleList ); print( "<br/>" );
          print( "allImageIdList: " ); print_r( $allImageIdList ); print( "<br/>" );
          print( "att_map: " ); print_r( $_SESSION['JOURNEY_IMAGE_LIST'] ); print( "<br/>" );
        */
        $allImageIdList = ImageData::loadAllImageIdList($dbConnection);
        shuffle($allImageIdList);
        $randomImageIdList = array();
        while (count($randomImageIdList) + count($commonAttributeImageIdList) < self::NUM_SIMILAR_CHOICES + 1 && count($allImageIdList) > 0) {
            $imageId = array_shift($allImageIdList);
            if ($imageId != $nextImageId && !in_array($imageId, $randomImageIdList) && !in_array($imageId, $commonAttributeImageIdList) && !in_array($imageId, $_SESSION['JOURNEY_IMAGE_LIST'])) {
                $randomImageIdList[] = $imageId;
            }
        }
        if (!empty($randomImageIdList)) {
            $randomImageDataList = ImageData::loadImageDataListByIdSet($dbConnection, $randomImageIdList);
        } else {
            $randomImageDataList = array();
        }
        // If the journey session array size has reached the number of journey steps, then set the is last
        // step flag to true, otherwise it should be false
        $IS_LAST_STEP = FALSE;
        if (count($_SESSION['JOURNEY_IMAGE_LIST']) == self::NUM_JOURNEY_STEPS) {
            $IS_LAST_STEP = TRUE;
        }
        // display the current image
        ?>
	<div class="currentJourneyImageSection">
	     <img src="<?php 
        echo UrlFormatter::formatImageUrl($nextImageData->getContentUri());
        ?>
"/>
	</div>
	<?php 
        // if this is not the last step, display further choices
        if (!$IS_LAST_STEP) {
            ?>
	    <p class="imageGridHeader">Choose Your Journey's Next Step</p>
	    <div class="centerWrapper">
	    <div class="imageGrid">
	    <?php 
            // list common choices
            foreach ($commonAttributeImageDataTupleList as $commonAttributeImageDataTuple) {
                $commonImageId = $commonAttributeImageDataTuple['imageData']->getId();
                $commonImageThumbUrl = UrlFormatter::formatImageUrl($commonAttributeImageDataTuple['imageData']->getThumbnailUri());
                $commonAttribute = $commonAttributeImageDataTuple['attribute'];
                $choiceUrl = UrlFormatter::formatRoutingItemUrl('views/JourneyStepView', array(self::GET_PARAM_NEXT_IMAGE_ID => $commonImageId, self::GET_PARAM_CHOSEN_ATTRIBUTE => $commonAttribute));
                ?>
		<a href="<?php 
                echo $choiceUrl;
                ?>
"><img src="<?php 
                echo $commonImageThumbUrl;
                ?>
"/></a>
		<?php 
            }
            // list random choices
            foreach ($randomImageDataList as $randomImageData) {
                $randomImageId = $randomImageData->getId();
                $thumbnailUrl = UrlFormatter::formatImageUrl($randomImageData->getThumbnailUri());
                $choiceUrl = UrlFormatter::formatRoutingItemUrl('views/JourneyStepView', array(self::GET_PARAM_NEXT_IMAGE_ID => $randomImageId));
                ?>
		<a href="<?php 
                echo $choiceUrl;
                ?>
"><img src="<?php 
                echo $thumbnailUrl;
                ?>
"/></a>
		<?php 
            }
            ?>
	    </div>
	    </div>
	    <?php 
        } else {
            $finishJourneyUrl = UrlFormatter::formatRoutingItemUrl('views/FinishJourneyView');
            ?>
	    <div class="finishJourneyButtonSection">
		 <a class="button" href="<?php 
            echo $finishJourneyUrl;
            ?>
">Finish Journey</a>
	    </div>
	    <?php 
        }
        parent::displayFooter();
    }
 /**
  * This abstract function performs the processing of the user request.
  * @param User $user The requesting user. If the user is not null, then by convention
  * actions will assume the user is authenticated, otherwise not.
  * @throws Exception If an error was encountered while processing this request, an exception
  * will be thrown.
  * @return void
  */
 public function processRequest(User $user = NULL)
 {
     // if image id was specified, parse it, attempt to load an image data object using the id
     $imageId = RequestParser::parseRequestParam($_REQUEST, EditImageAction::GET_PARAM_IMAGE_ID, RequestParser::PARAM_FILTER_TYPE_INT);
     $imageData = NULL;
     if ($imageId != NULL) {
         $imageData = ImageData::loadImageDataById(DbConnectionUtil::getDbConnection(), $imageId);
     }
     // otherwise create a new image data object
     if ($imageData == NULL) {
         $imageData = new ImageData();
         $imageData->setSubmitterUserId($user->getId());
     }
     // set the fields in the image data object
     $author = NULL;
     if (isset($_POST['author'])) {
         $author = $_POST['author'];
     }
     if ($author != NULL) {
         $imageData->setAuthor($author);
     }
     $title = NULL;
     if (isset($_POST['title'])) {
         $title = $_POST['title'];
     }
     if ($title != NULL) {
         $imageData->setTitle($title);
     }
     $year = NULL;
     if (isset($_POST['year'])) {
         $year = $_POST['year'];
     }
     if ($year != NULL) {
         $imageData->setYear($year);
     }
     // update attributes list
     $attributeString = $_POST[EditImageAction::POST_PARAM_ATTRIBUTE_LIST];
     if (!empty($attributeString)) {
         $attributeStringList = explode(",", $attributeString);
     } else {
         $attributeStringList = array();
     }
     // add new attributes
     foreach ($attributeStringList as $attString) {
         if ($attString != "") {
             if (!$imageData->hasAttribute($attString)) {
                 $imageData->addAttributeByString($attString);
             }
         }
     }
     $dbConnection = DbConnectionUtil::getDbConnection();
     // remove deleted ones
     $attributeList = $imageData->getAttributeList();
     foreach ($attributeList as $attribute) {
         if (!in_array($attribute->getAttribute(), $attributeStringList)) {
             $imageData->removeAttributeBystring($attribute->getAttribute());
             $attribute->delete($dbConnection);
         }
     }
     // save the image data object
     $imageData->save($dbConnection);
     // if image data was uploaded, process the image uploads and save again
     if (!empty($_FILES[EditImageAction::POST_PARAM_THUMBNAIL]['name'])) {
         $thumbnailUri = $this->processImageUpload('image_data_thumbs', $imageData->getId(), EditImageAction::POST_PARAM_THUMBNAIL);
         $imageData->setThumbnailUri($thumbnailUri);
         $imageData->save($dbConnection);
     }
     if (!empty($_FILES[EditImageAction::POST_PARAM_FILE]['name'])) {
         $fileUri = $this->processImageUpload('image_data', $imageData->getId(), EditImageAction::POST_PARAM_FILE);
         $imageData->setContentUri($fileUri);
         $imageData->save($dbConnection);
     }
     // redirect the user to the image viewing page
     $getParamMap = array(ImageDetailsView::GET_PARAM_IMAGE_ID => $imageData->getId());
     $imageDetailsViewUrl = UrlFormatter::formatRoutingItemUrl('views/ImageDetailsView', $getParamMap);
     header("Location: {$imageDetailsViewUrl}");
 }
    /**
     * This function performs the processing of the user request.
     * @param User $user The requesting user. If the user is not null, then by convention
     * actions will assume the user is authenticated, otherwise not.
     * @throws Exception If an error was encountered while processing this request, an exception
     * will be thrown.
     * @return void
     */
    public function processRequest(User $user = NULL)
    {
        // if an image id was specified, assuming editting an existing image, otherwise assume it's a new image
        $imageId = NULL;
        if (isset($_GET[EditImageView::GET_PARAM_IMAGE_ID])) {
            $imageId = $_GET[EditImageView::GET_PARAM_IMAGE_ID];
        }
        $pageHeader = $imageId == NULL ? 'Add New Image' : 'Edit Image';
        parent::displayHeader($user, $pageHeader);
        $editImageActionUrl = NULL;
        $getParamMap = NULL;
        $imageData = NULL;
        if ($imageId != NULL) {
            $getParamMap = array();
            $getParamMap[EditImageAction::GET_PARAM_IMAGE_ID] = $imageId;
            $imageData = ImageData::loadImageDataById(DbConnectionUtil::getDbConnection(), $imageId);
        }
        $author = '';
        $title = '';
        $year = '';
        $attributeList = NULL;
        $attributeListString = "";
        $thumbnailUri = NULL;
        $contentUri = NULL;
        if ($imageData != NULL) {
            $contentUri = $imageData->getContentUri();
            $thumbnailUri = $imageData->getThumbnailUri();
            $title = $imageData->getTitle();
            $year = $imageData->getYear();
            $author = $imageData->getAuthor();
            $attributeList = $imageData->getAttributeList();
            foreach ($attributeList as $attribute) {
                $attributeListString .= "," . $attribute->getAttribute();
            }
        }
        $editImageActionUrl = UrlFormatter::formatRoutingItemUrl('actions/EditImageAction', $getParamMap);
        $submitLabel = $imageId == NULL ? 'Create' : 'Save';
        ?>
	<script type="text/javascript" >
	
	function replaceThumbnail( ) {
		$("#thumbnail_div").html( "<input type=\"file\" id=\"thumbnail_field\" name=\"<?php 
        echo EditImageAction::POST_PARAM_THUMBNAIL;
        ?>
\">" ); 
	}

	function replaceFile( ) {
		$("#file_div").html( "<input type=\"file\" id=\"file_field\" name=\"<?php 
        echo EditImageAction::POST_PARAM_FILE;
        ?>
\">" ); 
	}

	function cancel( ) {
	    var previousPageUrl = "<?php 
        echo $_SERVER['HTTP_REFERER'];
        ?>
";
	    window.location.href = previousPageUrl;
	}

	function removeAttributeAtIndex( index ) {
	    var rowList = $("#attribute_list_table tr");
	    
	    for( i = 0; i < rowList.length; i++ ) {
		if ( i == index ) {
		    var removedAttString = $( rowList[i] ).children( ).first( ).text( );
		    var attList = $( "#attribute_list").val( ).split( "," );
		    attList.splice( attList.indexOf( removedAttString ), 1 );
		    $( "#attribute_list").val( attList.join( ) );
		    $( rowList[i] ).remove( );		    
		}
	    }
	}

	function addAttribute( ) {
	    var attributeValue = prompt( "Specify New Attribute" );
	    var attList = $( "#attribute_list").val( ).split( "," );
	    if ( attributeValue != null && attributeValue != "" && attList.indexOf( attributeValue ) == -1 ) {
		var newIndex = $( "#attribute_list_table tr" ).length;
		$( "#attribute_list_table" ).append( "<tr><td>" + attributeValue + "</td><td><a onclick=\"removeAttributeAtIndex( " + newIndex + " );\">Remove</a></td></tr>" );
		
		attList.push( attributeValue );
		$( "#attribute_list").val( attList.join( ) );
	    }
	}
	
	function validate( ) {
	    var result = true;
	    $("#errorSection").html("" );
	    <?php 
        if ($imageData == NULL) {
            ?>
		var thumbnailVal = $("#thumbnail_field").val( );
		if ( thumbnailVal == null || thumbnailVal == "" ) {
		    $("#errorSection").append( "<span class=\"errorMessage\">Thumbnail Required</span><br/>" );
		    $("#errorSection").css( "display", "inline-block");
		    $("#thumbnail_field_label").css( "color", " #EE3124" );
		    result = false;
		}
		var fileVal = $("#file_field").val( );
		if ( fileVal == null || fileVal == "" ) {
		    $("#errorSection").append( "<span class=\"errorMessage\">File Required</span><br/>" );
		    $("#errorSection").css( "display", "inline-block");
		$("#file_field_label").css( "color", " #EE3124" );
		result = false;
		}
		<?php 
        }
        ?>
	    var authorVal = $("#author_field").val( );
	    if ( authorVal == null || authorVal == "" ) {
		$("#errorSection").append( "<span class=\"errorMessage\">Author Required</span><br/>" );
		$("#errorSection").css( "display", "inline-block");
		$("#author_field_label").css( "color", " #EE3124" );
		result = false;
	    }
	    var titleVal = $("#title_field").val( );
	    if ( titleVal == null || titleVal == "" ) {
		$("#errorSection").append( "<span class=\"errorMessage\">Title Required</span><br/>" );
		$("#errorSection").css( "display", "inline-block");
		$("#title_field_label").css( "color", " #EE3124" );
		result = false;
	    }
	    var yearVal = $("#year_field").val( );
	    if ( yearVal == null || yearVal == "" ) {
		$("#errorSection").append( "<span class=\"errorMessage\">Year Required</span><br/>" );
		$("#errorSection").css( "display", "inline-block");
		$("#year_field_label").css( "color", " #EE3124" );
		result = false;
	    }
	    return result;
	}

	
	</script>
	<form class="imageForm" method="POST" action="<?php 
        echo $editImageActionUrl;
        ?>
" enctype="multipart/form-data" onsubmit="return validate( )">
	      <div class="errorSection" id="errorSection"></div>
	      <br/>

	      <label id="author_field_label" for="author_field">Author</label>
	     <br/>
	     <input id="author_field" type="text" name="<?php 
        echo EditImageAction::POST_PARAM_AUTHOR;
        ?>
" value="<?php 
        echo $author;
        ?>
"/>
		  <?php 
        parent::formatImageDataAutoComplete(DbConnectionUtil::getDbConnection(), 'author', 'author_field');
        ?>
	     <br/>
	     <label id="title_field_label" for="title_field">Title</label>
	     <br/>
             <input id="title_field" type="text" name="<?php 
        echo EditImageAction::POST_PARAM_TITLE;
        ?>
" value="<?php 
        echo $title;
        ?>
"/>
             <br/>
             <label id="year_field_label" for="year_field">Year</label>
             <br/>
	     <input id="year_field" name="<?php 
        echo EditImageAction::POST_PARAM_YEAR;
        ?>
" value="<?php 
        echo $year;
        ?>
"/>
             <br/><br/>

	     <input id="attribute_list" type="hidden" name="<?php 
        echo EditImageAction::POST_PARAM_ATTRIBUTE_LIST;
        ?>
" value="<?php 
        echo $attributeListString;
        ?>
"/>
             <label for="attribute_table">Attributes</label>
	     <table class="attribute_table" id="attribute_list_table">
	     <?php 
        if ($attributeList != NULL) {
            for ($i = 0; $i < count($attributeList); $i++) {
                ?>
						      <tr>
						      <td><?php 
                echo $attributeList[$i]->getAttribute();
                ?>
</td>
						      <td><a onclick="removeAttributeAtIndex(<?php 
                echo $i;
                ?>
);">Remove</a>
						      </tr>
						      <?php 
            }
        }
        ?>
             </table>
             <br/>
	     <a class="button" onclick="addAttribute( );">Add Attribute</a>
	     <br/><br/>

	     <label id="thumbnail_field_label" for="thumbnail_field">Thumbnail</label>
	      <br/>
	      <div id="thumbnail_div">
	      <?php 
        if ($thumbnailUri == NULL) {
            ?>
	         <input type="file" id="thumbnail_field" name="<?php 
            echo EditImageAction::POST_PARAM_THUMBNAIL;
            ?>
"/>
	      <?php 
        } else {
            ?>
		  <img src="<?php 
            echo UrlFormatter::formatImageUrl($thumbnailUri);
            ?>
"/>
		  <br/>
		  <input type="button" onclick="replaceThumbnail( )" value="Replace"/>
	      <?php 
        }
        ?>
	      </div>

             <label id="file_field_label" for="file_field">File</label>
             <br/>
	      <div id="file_div">
	      <?php 
        if ($contentUri == NULL) {
            ?>
			<input type="file" id="file_field" name="<?php 
            echo EditImageAction::POST_PARAM_FILE;
            ?>
"/>
		    <?php 
        } else {
            ?>
			<img style="max-width: 100%" src="<?php 
            echo UrlFormatter::formatImageUrl($contentUri);
            ?>
"/>
			<br/>
		        <input type="button" onclick="replaceFile( )" value="Replace"/>
			<br/>
		    <?php 
        }
        ?>
	      </div>	      
	     
	     <input class="button" type="submit" value="<?php 
        echo $submitLabel;
        ?>
"/>
	     <input class="button" type="button" onclick="cancel( )" value="Cancel"/>
	</form>
	<?php 
        parent::displayFooter();
    }
    /**
     * This function performs the processing of the user request.
     * @param User $user The requesting user. If the user is not null, then by convention
     * actions will assume the user is authenticated, otherwise not.
     * @throws Exception If an error was encountered while processing this request, an exception
     * will be thrown.
     * @return void
     */
    public function processRequest(User $user = NULL)
    {
        parent::displayHeader($user, 'Image Details');
        if (isset($_REQUEST[ImageDetailsView::GET_PARAM_RETURN_URL])) {
            ?>
	    <a href="<?php 
            echo $_REQUEST[ImageDetailsView::GET_PARAM_RETURN_URL];
            ?>
">Return</a>
	    <br/>
	    <?php 
        }
        if (isset($_REQUEST[ImageDetailsView::GET_PARAM_IMAGE_ID])) {
            $imageId = $_REQUEST[ImageDetailsView::GET_PARAM_IMAGE_ID];
            $imageData = ImageData::loadImageDataById(DbConnectionUtil::getDbConnection(), $imageId);
            if ($imageData == NULL) {
                print "Failed to load image data ";
            } else {
                $editImageUrl = UrlFormatter::formatRoutingItemUrl('views/EditImageView', array(EditImageView::GET_PARAM_IMAGE_ID => $imageData->getId()));
                $thumbnailUri = $imageData->getThumbnailUri();
                $contentUri = $imageData->getContentUri();
                ?>
		<div class="imageDetailsView">
		<label for="title_field">Title</label>
                <br/>
	        <span id="title_field" class="imageDetailsViewField"><?php 
                echo $imageData->getTitle();
                ?>
</span>
	        <br/>
                <label for="author_field">Author</label>
                <br/>
                <span id="author_field" class="imageDetailsViewField"><?php 
                echo $imageData->getAuthor();
                ?>
</span>
                <br/>                
                <label for="year_field">Year</label>
                <br/>
                <span id="year_field" class="imageDetailsViewField"><?php 
                echo $imageData->getYear();
                ?>
</span>
		<br/>
                <label for="attributes_field">Attributes</label>
                <br/>
                <table class="attribute_table" id="attributes_field">
                <?php 
                foreach ($imageData->getAttributeList() as $attribute) {
                    ?>
                   <tr><td><?php 
                    echo $attribute->getAttribute();
                    ?>
</td></tr>
                <?php 
                }
                ?>
                </table>
	        <br/>
		<br/>
		<label for="content_uri_field">Image</label>
		<br/>
                <span id="content_uri_field" class="imageDetailsViewField">
                <image style="max-width: 100%" id="content_uri_field" src="<?php 
                echo UrlFormatter::formatImageUrl($contentUri);
                ?>
"/>
                </span>
    	        <br/><br/>
		<label for="thumbnail_field">Thumbnail</label>
                <br/>
		<img id="thumbnail_field" src="<?php 
                echo UrlFormatter::formatImageUrl($thumbnailUri);
                ?>
"/>
		<br/><br/>
		<?php 
                if ($user != NULL) {
                    ?>
		      <a class="button" href="<?php 
                    echo $editImageUrl;
                    ?>
">Edit</a>
		   <?php 
                }
                ?>
	        </div>
	        <?php 
            }
        } else {
            print "No image specified";
        }
        parent::displayFooter();
    }