/**
     * 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, 'Welcome');
        $splashImageFileNameList = array();
        $splashImageFileNameList[] = '1.jpg';
        $splashImageFileNameList[] = '2.jpg';
        $splashImageFileNameList[] = '3.jpg';
        $splashImageFileNameList[] = '4.jpg';
        $splashImageNumber = rand(0, count($splashImageFileNameList) - 1);
        $splashImageName = $splashImageFileNameList[$splashImageNumber];
        $splashImageUrl = UrlFormatter::formatImageUrl("splash/{$splashImageName}");
        $startActionUrl = UrlFormatter::formatRoutingItemUrl('views/StartJourneyView');
        ?>
	<img style="padding-left: 10px; float: right; max-width: 50%; max-height: 700px;" src="<?php 
        echo $splashImageUrl;
        ?>
"/>
	<p>
	     The primary question examined by this project is, how does a contiguous experience of viewing artwork have an affect on one's perception of art in subsequent viewings. Experimenting with this idea, this application works interactively with the user to construct a unique contiguous art experience, and then asks the user to reflect on their experiences. A contiguous art experience is classified as a journey through art, comprised of viewings of a psuedo-randomly generated sequence of art pieces. The user begins their journey by being presented with a choice of random art pieces with distinct attributes. At each step along the journey, the user is presented with a full-scale viewing of the current art piece, along with a choice of three options to choose from, two comprised of random pieces which share attributes with the current piece being viewed, and a third completely random piece. As the user makes each choice, the user is advanced to a viewing of the chosen piece along with 3 new options. Throughout the journey this application tracks the most commonly chosen attribute by the user. After 6 pieces have been viewed, the user is shown their journey's history, their most commonly chosen attribute with matching art suggestions, and a prompt to give feedback about their journey, namely what emotions were elicited by the experience and what impressions they were left with. Finally, the user is able to give their journey a name, so that others can re-trace the steps of that particular journey if they so choose. This allows each user to construct a unique contiguous art experience, with some entropic computational guidance from the webapp itself, culminating with the an introspection by the user on how their experience has changed their own perceptions of art. 
	</p>
        <br/><br/>
        <a class="button" href="<?php 
        echo $startActionUrl;
        ?>
">Start Journey</a>
	<?php 
        parent::displayFooter();
    }
    private function displayImageDetailLink(ImageData $imageData)
    {
        $imageDetailsUrl = UrlFormatter::formatRoutingItemUrl('views/ImageDetailsView', array(ImageDetailsView::GET_PARAM_IMAGE_ID => $imageData->getId()));
        $thumbnailUrl = UrlFormatter::formatImageUrl($imageData->getThumbnailUri());
        ?>
	<a target="_blank" href="<?php 
        echo $imageDetailsUrl;
        ?>
"><img src="<?php 
        echo $thumbnailUrl;
        ?>
"/></a>
	<?php 
    }
    public function processRequest(User $user = NULL)
    {
        parent::displayHeader($user, 'Image Search Results');
        // compose and execute query
        $dbConnection = DbConnectionUtil::getDbConnection();
        $queryString = 'SELECT imd.id FROM image_data imd ';
        $attribute = RequestParser::parseRequestParam($_REQUEST, ImageSearchResultsView::POST_PARAM_ATTRIBUTE, RequestParser::PARAM_FILTER_TYPE_ALPHA_NUMERIC_WS_ONLY);
        if ($attribute != NULL) {
            $queryString .= "INNER JOIN image_attribute ima ON imd.id = ima.image_data_id AND ima.attribute LIKE '%{$attribute}%' ";
        }
        $queryString .= ' WHERE 1=1 ';
        $title = RequestParser::parseRequestParam($_REQUEST, ImageSearchResultsView::POST_PARAM_TITLE, RequestParser::PARAM_FILTER_TYPE_ALPHA_NUMERIC_WS_ONLY);
        if ($title != NULL) {
            $queryString .= "AND imd.title LIKE '%{$title}%' ";
        }
        $year = RequestParser::parseRequestParam($_REQUEST, ImageSearchResultsView::POST_PARAM_YEAR, RequestParser::PARAM_FILTER_TYPE_INT);
        if ($year != NULL) {
            $queryString .= "AND imd.year LIKE '%{$year}%' ";
        }
        $author = RequestParser::parseRequestParam($_REQUEST, ImageSearchResultsView::POST_PARAM_AUTHOR, RequestParser::PARAM_FILTER_TYPE_ALPHA_WS_ONLY);
        if ($author != NULL) {
            $queryString .= "AND imd.author LIKE '%{$author}%' ";
        }
        //print( "<br/>queryString: $queryString<br/><br/>" );
        $preparedStatement = $dbConnection->prepare($queryString);
        $preparedStatement->execute();
        $idList = array();
        while ($resultRow = $preparedStatement->fetch(PDO::FETCH_ASSOC)) {
            $idList[] = $resultRow['id'];
        }
        $preparedStatement = NULL;
        if (count($idList) > 0) {
            $imageDataResultList = ImageData::loadImageDataListByIdSet($dbConnection, $idList);
        } else {
            $imageDataResultList = array();
        }
        ?>
	<h1>Search Results</h1>
	<br/>
	<div class="imageDetailsView">
	<?php 
        foreach ($imageDataResultList as $imageData) {
            $viewImageDetailsUrl = UrlFormatter::formatRoutingItemUrl('views/ImageDetailsView', array(ImageDetailsView::GET_PARAM_IMAGE_ID => $imageData->getId()));
            ?>
		 <div class="searchResultItem">
		 <?php 
            $thumbnailUri = $imageData->getThumbnailUri();
            if (!empty($thumbnailUri)) {
                ?>
		       <div>
		       	<a href="<?php 
                echo $viewImageDetailsUrl;
                ?>
"><img  id="thumbnail_field" src="<?php 
                echo UrlFormatter::formatImageUrl($imageData->getThumbnailUri());
                ?>
"/></a>
			 <br/>
			 <a href="<?php 
                echo $viewImageDetailsUrl;
                ?>
">Details</a>
		       
		       </div>
		       <?php 
                $title = $imageData->getTitle();
                if ($title != null) {
                    ?>
		       		<label for="title_field">Title</label>
		      		 <span  id="title_field" class="imageDetailsField"><?php 
                    echo $title;
                    ?>
</span>
		      		 <br/>
		      		 <?php 
                }
                ?>
		       <?php 
                $author = $imageData->getAuthor();
                if ($author != null) {
                    ?>
		       		<label for="author_field">Author</label>
		      		 <span  id="author_field" class="imageDetailsField"><?php 
                    echo $author;
                    ?>
</span>
		      		 <br/>
		      		 <?php 
                }
                ?>
			<br/>
		       	
		       <?php 
            }
            ?>
		 </div>
		 <div style="clear:both"></div>
		 <?php 
        }
        ?>
	</div>
	<?php 
        parent::displayFooter();
    }
    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 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();
    }
    public function processRequest(User $user = NULL)
    {
        parent::displayHeader($user, 'Start Journey');
        // TODO query for existing journeys
        // query for distinct image attributes
        $dbConnection = DbConnectionUtil::getDbConnection();
        $distinctAttributeList = ImageAttribute::loadExistingValues($dbConnection);
        // randomly select attributes, foreach attribute, retrieve the id of a unique image, store in sourceImageList
        shuffle($distinctAttributeList);
        $sourceImageIdList = array();
        for ($i = 0; $i < self::NUM_START_SELECTION_COUNT && count($distinctAttributeList) > 0; $i++) {
            $attribute = array_shift($distinctAttributeList);
            $imageIdList = ImageAttribute::loadImageIdListByAttribute($dbConnection, $attribute);
            shuffle($imageIdList);
            while (count($imageIdList) > 0) {
                $imageId = array_shift($imageIdList);
                if (!in_array($imageId, $sourceImageIdList)) {
                    $sourceImageIdList[] = $imageId;
                    break;
                }
            }
        }
        // if the full number of starting images could not be found with distinct attributes, then randomly select more to fill in the gap
        if (count($sourceImageIdList) < self::NUM_START_SELECTION_COUNT) {
            $allImageIdList = ImageData::loadAllImageIdList($dbConnection);
            shuffle($allImageIdList);
            while (count($sourceImageIdList) < self::NUM_START_SELECTION_COUNT && count($allImageIdList) > 0) {
                $imageId = array_shift($allImageIdList);
                if (!in_array($imageId, $sourceImageIdList)) {
                    $sourceImageIdList[] = $imageId;
                }
            }
        }
        // load the randomly selected images
        $sourceImageDataList = ImageData::loadImageDataListByIdSet($dbConnection, $sourceImageIdList);
        shuffle($sourceImageDataList);
        // reset the journey's session data
        if (isset($_SESSION['JOURNEY_IMAGE_LIST'])) {
            unset($_SESSION['JOURNEY_IMAGE_LIST']);
        }
        $_SESSION['JOURNEY_IMAGE_LIST'] = array();
        if (isset($_SESSION['JOURNEY_ATTRIBUTE_MAP'])) {
            unset($_SESSION['JOURNEY_ATTRIBUTE_MAP']);
        }
        $_SESSION['JOURNEY_ATTRIBUTE_MAP'] = array();
        ?>
	<p class="imageGridHeader">Choose Your Journey's Starting Image</p>
	<div class="centerWrapper">
	<div class="imageGrid">	     
             <?php 
        foreach ($sourceImageDataList as $imageData) {
            $imageJourneyUrl = UrlFormatter::formatRoutingItemUrl('views/JourneyStepView', array(JourneyStepView::GET_PARAM_NEXT_IMAGE_ID => $imageData->getId()));
            $imageThumbUrl = UrlFormatter::formatImageUrl($imageData->getThumbnailUri());
            ?>
		 <a href="<?php 
            echo $imageJourneyUrl;
            ?>
"> <img src="<?php 
            echo $imageThumbUrl;
            ?>
"></a>
		 <?php 
        }
        ?>
	</div>
	</div>
	<?php 
        // TODO display a list of existing journeys
        parent::displayFooter();
    }
    /**
     * Displays the footer section of the site.
     * @return void
     */
    protected function displayFooter()
    {
        $footerLogoUrl = UrlFormatter::formatImageUrl('ui/footer_ua_logo.png');
        ?>
	</div>
    <div style="clear:both"></div>
	<div class="footerSection">
		<img src="<?php 
        echo $footerLogoUrl;
        ?>
"/>
	</div>
    </body>
    </html>
	<?php 
    }
    public function processRequest(User $user = NULL)
    {
        $journeyId = RequestParser::parseRequestParam($_GET, self::GET_PARAM_JOURNEY_ID, RequestParser::PARAM_FILTER_TYPE_INT);
        $baseUrl = Settings::getSetting('APPLICATION_URL');
        if (!$journeyId) {
            header("Location: {$baseUrl}");
            exit;
        }
        // load the journey data
        $dbConnection = DbConnectionUtil::getDbConnection();
        $journeyData = Journey::loadJourneyById($dbConnection, $journeyId);
        if (!$journeyData) {
            header("Location: {$baseUrl}");
            exit;
        }
        // load the images from the journey
        $imageDataList = ImageData::loadImageDataListByIdSet($dbConnection, $journeyData->getImageIdList());
        parent::displayHeader($user, 'Journey Details');
        ?>
	<div class="imageDetailsView">
	     <label for="journey_name_field">Journey Name</label>
	     <br/>
             <span id="journey_name_field" class="imageDetailsViewField"><?php 
        echo $journeyData->getTitle();
        ?>
</span>
	     <br/>
	     <label for="journey_creation_date_field">Journey Date</label>
             <br/>
             <span id="journey_creation_date_field" class="imageDetailsViewField"><?php 
        echo $journeyData->getCreationDate();
        ?>
</span>
	     <br/>
             <label for="journey_comments_field">Journey Comments</label>
             <br/>
             <p id="journey_comments_field" class="imageDetailsViewField"><?php 
        echo $journeyData->getComments();
        ?>
</p>
	</div>
        <div class="imageGrid">
        <?php 
        foreach ($imageDataList as $imageData) {
            $imageDetailsUrl = UrlFormatter::formatRoutingItemUrl('views/ImageDetailsView', array(ImageDetailsView::GET_PARAM_IMAGE_ID => $imageData->getId()));
            $thumbnailUrl = UrlFormatter::formatImageUrl($imageData->getThumbnailUri());
            ?>
	       <a target="_blank" href="<?php 
            echo $imageDetailsUrl;
            ?>
"><img src="<?php 
            echo $thumbnailUrl;
            ?>
"/></a>
	       <?php 
        }
        ?>
        </div>
	
	<?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();
    }