function buildInvitation()
{
    //Build the invitation section.
    global $debug, $message, $success;
    $output = '<ul class="break">
		<li class="sectionTitle">Invite a new user</li>
	</ul>
';
    //A user will only ever have a site role of None, Read, or Site Admin, which equate to Blocked, Allowed, and Site Admin.
    //See if the user is linked to any folder accounts.
    $foldersQuery = "SELECT\n\tfolders.folderName AS 'folderName',\n\tfolders.folderId AS 'folderId'\nFROM\n\tfolders\nLEFT JOIN\n\tuserFolderSettings ON userFolderSettings.folderId = folders.folderId AND\n\t(userFolderSettings.folderRoleId >= '2')\nWHERE\n\tuserFolderSettings.userId = '" . $_SESSION['userId'] . "'\nORDER BY\n\tfolders.folderName";
    if ($foldersResult = mysql_query($foldersQuery)) {
        if (mysql_affected_rows() == 0) {
            $output .= '<span class="red">You must be a Folder Manager or Owner to send invitations.</span>';
            $debug->add("The users isn't linked to any folders.");
        } else {
            $folders = '<select id="invitationFolder">
<option value="">Select a folder:</option>';
            while ($row = mysql_fetch_assoc($foldersResult)) {
                $folders .= '<option value="' . $row['folderId'] . '">' . $row['folderName'] . '</option>
';
            }
            $folders .= '</select><span class="red" id="responseInvitationFolder" style="padding:0px 0px 0px 10px"></span>
';
            $output .= 'Invite someone to share your lists with. Once they create an account you\'ll see their name in the "Folders" section. The user\'s account will be linked to your folder and you can set their list roles. You can always remove the user later.
		<div style="padding:10px 0px 0px 0px">
			<div class="break">
				<div class="invitationLeft">Folder:&nbsp;</div>
				<div class="invitationRight">' . $folders . '</div>
			</div>
			<div class="break">
				<div class="invitationLeft">Folder Role:&nbsp;</div>
				<div class="invitationRight"><select id="invitationFolderRole">
						<option value="0">None</option>
						<option value="1" selected="selected">Read</option>
						<option value="3">Account Admin</option>
					</select> <img alt="" class="question top" height="16" qid="24" onClick="" src="' . LINKIMAGES . '/question.png" width="16"></div>
			</div>
			<div class="hide" id="invitationListHolder">
				<div class="break">
					<div class="invitationLeft">ADR List:&nbsp;</div>
					<div class="invitationRight" id="returnInvitationLists"></div>
				</div>
				<div class="break">
					<div class="invitationLeft">ADR List Role:&nbsp;</div>
					<div class="invitationRight">' . buildRoles('invitationListRole', 1) . faqLink(24) . '</div>
				</div>
			</div>
			<div class="break">
				<div class="invitationLeft">Recipient\'s Email:&nbsp;</div>
				<div class="invitationRight"><input autocapitalize="off" autocorrect="off" id="invitationToAddress" type="email" size="25"> <span class="red" id="invitationToAddressResponse"></span></div>
			</div>
			<div class="break">
				<div class="invitationLeft">Message:&nbsp;</div>
				<div class="invitationRight italic">' . $_SESSION['firstName'] . ' ' . $_SESSION['lastName'] . ' has shared an ADR list with you. To accept this invitation click the link below:<br>
<textarea id="invitationMessage" style="width:500px">(optional personal message here)</textarea></div>
			</div>
			<div class="break">
				<div class="invitationLeft">&nbsp;</div>
				<div class="left" id="sendInvitationButton" onClick=""><img alt="" class="link middle" height="24" src="' . LINKIMAGES . '/send.png" width="24"><span class="linkPadding middle">Send</span> <span class="middle red" id="invitationResponse" style="padding:0px 10px 0px 0px"></span></div>
				<div class="left" id="viewInvitationsTrigger" onClick=""><div id="viewInvitationsShow"><img alt="" class="link middle" height="24" src="' . LINKIMAGES . '/mailDown.png" width="24"><span class="linkPadding middle">Show Invitations</span></div><div class="hide" id="viewInvitationsHide" onClick=""><img alt="" class="link middle" height="24" src="' . LINKIMAGES . '/mailUp.png" width="24"><span class="linkPadding middle">Hide Invitations</span></div> <span class="middle red" id="viewInvitationsResponse"></span></div>
			</div>
		</div>
		<div id="viewInvitationsHolder" style="display:none"></div>';
        }
    } else {
        error(__LINE__);
        pdoError(__LINE__, $foldersQuery, '$foldersQuery');
    }
    return $output;
}
Beispiel #2
0
function reconcileLists($userId)
{
    /*
    Automatically lock lists beyond the account credit balance, starting with the list with the oldest modified date.
    
    Returns true if lists were locked.
    */
    global $debug, $message, $Dbc;
    try {
        $locked = false;
        $userBillingInfo = Adrlist_Billing::getUserPlan($_SESSION['userId']);
        $_SESSION['credits'] = $_SESSION['siteRoleId'] == 5 ? 9999 : $userBillingInfo['credits'];
        $activeLists = getActiveLists($_SESSION['userId']);
        $_SESSION['activeLists'] = count($activeLists);
        $creditBalance = $_SESSION['credits'] - $_SESSION['activeLists'];
        if ($creditBalance < 0) {
            $Dbc->beginTransaction();
            //Get a list of the user's currently unlocked lists.
            $unlockedListsStmt = $Dbc->prepare("SELECT\n\tlists.listId AS 'listId',\n\tlists.listName AS 'listName',\n\tlists.modified AS 'modified'\nFROM\n\tlists\nJOIN\n\tuserListSettings ON userListSettings.listId = lists.listId AND\n\tuserListSettings.userId = ? AND\n\tuserListSettings.listRoleId = 4\nWHERE\n\tlists.locked = 0\nORDER BY\n\tmodified ASC");
            $unlockedListsParams = array($_SESSION['userId']);
            $unlockedListsStmt->execute($unlockedListsParams);
            $preUnlockedLists = array();
            $listsToLock = abs($creditBalance);
            $lockListId = '';
            $x = 1;
            while ($row = $unlockedListsStmt->fetch(PDO::FETCH_ASSOC)) {
                $preUnlockedLists[] = $row;
                $lockListId .= empty($lockListId) ? $row['listId'] : ', ' . $row['listId'];
                if ($x = $listsToLock) {
                    //Only lock as many lists as we need to.
                    break;
                }
            }
            $debug->add('$listsToLock: ' . $listsToLock);
            $lockStmt = $Dbc->query("UPDATE\n\tlists\nSET\n\tlocked = 1\nWHERE\n\tlistId IN (" . $lockListId . ")");
            pdoError(__LINE__, $lockStmt, '');
            $lockStmt->execute();
            //Re-run the unlocked list query to check for differences.
            $unlockedListsStmt->execute($unlockedListsParams);
            $postUnlockedLists = array();
            while ($row = $unlockedListsStmt->fetch(PDO::FETCH_ASSOC)) {
                $postUnlockedLists[] = $row;
            }
            $debug->printArray($postUnlockedLists, '$postUnlockedLists');
            $difference = arrayRecursiveDiff($preUnlockedLists, $postUnlockedLists);
            $debug->printArray($difference, '$difference');
            $message .= 'As you have more active lists than credits, the following lists were locked ' . faqLink(29) . ':<br>';
            foreach ($difference as $key => $value) {
                $message .= $value['listName'] . '<br>';
            }
            $Dbc->commit();
            $locked = true;
            //$Dbc->rollback();
        }
    } catch (Adrlist_CustomException $e) {
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
    return $locked;
}
function buildMyInformation()
{
    //User information, where the user can change name, email address, password, etc.
    global $debug, $message, $success, $Dbc, $returnThis;
    $output = '';
    try {
        if (empty($_SESSION['userId'])) {
            throw new Adrlist_CustomException('$_SESSION[\'userId\'] is empty.', '');
        }
        $output .= '<div class="myAccountTitle textCenter">My Information</div>
<div class="textCenter">Change your name, email address, and password here. Leave the new password empty if you do not want to change it.</div>
';
        $stmt = $Dbc->prepare("SELECT\n\tusers.userId AS userId,\n\tusers.firstName as 'firstName',\n\tusers.lastName as 'lastName',\n\tusers.primaryEmail AS 'primaryEmail',\n\tusers.secondaryEmail AS 'secondaryEmail'\nFROM\n\tusers\nWHERE\nusers.userId = ?");
        $stmt->execute(array($_SESSION['userId']));
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        $folders = array();
        $output .= '
<div class="center textCenter">
	<div class="ui-field-contain">
		<label for="myInformationFirstName" unused="ui-hidden-accessible">First Name</label>
		<input autocapitalize="on" autocorrect="off" data-wrapper-class="true" id="myInformationFirstName" goswitch="saveMyInformation" name="myInformationFirstName" placeholder="" value="' . $row['firstName'] . '" type="text">
	</div>
	<div class="ui-field-contain">
		<label for="myInformationLastName" unused="ui-hidden-accessible">Last Name</label>
		<input autocapitalize="on" autocorrect="off" data-wrapper-class="true" id="myInformationLastName" goswitch="saveMyInformation" name="myInformationLastName" placeholder="" value="' . $row['lastName'] . '" type="text">
	</div>
	<div class="ui-field-contain">
		<label for="primaryEmail" unused="ui-hidden-accessible"><span class="red">*</span> Primary Email Address</label>
		<input autocapitalize="off" autocorrect="off" data-wrapper-class="true" id="primaryEmail" goswitch="saveMyInformation" name="primaryEmail" placeholder="" value="' . $row['primaryEmail'] . '" type="email">
	</div>
	<div class="ui-field-contain">
		<label for="primaryEmailRetype" unused="ui-hidden-accessible"><span class="red">*</span> Re-type Primary Email Address</label>
		<input autocapitalize="off" autocorrect="off" data-wrapper-class="true" id="primaryEmailRetype" goswitch="saveMyInformation" name="primaryEmailRetype" placeholder="" value="' . $row['primaryEmail'] . '" type="email">
	</div>
	<div class="ui-field-contain">
		<label for="secondaryEmail" unused="ui-hidden-accessible">' . faqLink(37) . 'Secondary Email Address</label>
		<input autocapitalize="off" autocorrect="off" data-wrapper-class="true" id="secondaryEmail" goswitch="saveMyInformation" name="secondaryEmail" placeholder="" value="' . $row['secondaryEmail'] . '" type="email">
	</div>
	<div class="ui-field-contain">
		<label for="secondaryEmailRetype" unused="ui-hidden-accessible">Re-type Secondary Email Address</label>
		<input autocapitalize="off" autocorrect="off" data-wrapper-class="true" id="secondaryEmailRetype" goswitch="saveMyInformation" name="secondaryEmailRetype" placeholder="" value="' . $row['secondaryEmail'] . '" type="email">
	</div>
	<div class="ui-field-contain">
		<label for="currentPassword" unused="ui-hidden-accessible"><span class="red">*</span> Current Password</label>
		<input autocapitalize="off" autocorrect="off" id="currentPassword" goswitch="saveMyInformation" name="currentPassword" placeholder="" value="" type="password">
	</div>
	<div class="ui-field-contain">
		<label for="newPassword" unused="ui-hidden-accessible">New Password</label>
		<input autocapitalize="off" autocorrect="off" id="newPassword" goswitch="saveMyInformation" name="newPassword" placeholder="" value="" type="password">
	</div>
	<span class="textSmall">case-sensitive, at least 6 characters, ! and @ allowed</span>
	<div class="ui-field-contain">
		<label for="newPasswordRetype" unused="ui-hidden-accessible">Re-type New Password</label>
		<input autocapitalize="off" autocorrect="off" id="newPasswordRetype" goswitch="saveMyInformation" name="newPasswordRetype" placeholder="" value="" type="password">
	</div>
	<a href="' . LINKFORGOTPASSWORD . '">forgot password ?</a>
	<div>
		<button class="ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-icon-left ui-icon-heart" id="saveMyInformation">Save</button>
	</div>
</div>';
    } catch (Adrlist_CustomException $e) {
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
    return $output;
}
function initializeList()
{
    global $debug, $message, $Dbc;
    try {
        //Get the basic info of the list and the user's relationship to it.
        $initializeListStmt = $Dbc->prepare("SELECT\n\tuserSiteSettings.listId AS 'listId',\n\tlists.listName AS 'listName',\n\tlists.frId AS 'frId',\n\tlists.locked AS 'locked',\n\tlists.cId AS 'cId',\n\tlists.created AS 'created',\n\tlists.mId AS 'mId',\n\tlists.modified AS 'modified',\n\tlists.dId AS 'dId',\n\tlists.deleted AS 'deleted',\n\tfolders.folderName AS 'folderName',\n\tframerates.framerate AS 'framerate',\n\tframerates.fps AS 'fps',\n\tuserFolderSettings.folderRoleId AS 'folderRoleId',\n\tuserListSettings.listRoleId AS 'listRoleId',\n\tuserListSettings.listOffset AS 'offset',\n\tuserListSettings.limitCount AS 'limit',\n\tuserListSettings.orderBy AS 'orderBy',\n\tuserListSettings.orderDirection AS 'orderDirection',\n\tuserListSettings.viewReels AS 'viewReels',\n\tuserListSettings.viewCharacters AS 'viewCharacters',\n\tuserListSettings.showCompletedLines AS 'showCompletedLines',\n\tuserListSettings.showDeletedLines AS 'showDeletedLines',\n\tuserListSettings.showCharacterColors AS 'showCharacterColors'\nFROM\n\tlists\nJOIN\n\tuserSiteSettings ON userSiteSettings.listId = lists.listId AND\n\tuserSiteSettings.userId = ?\nJOIN\n\tuserListSettings ON userListSettings.listId = userSiteSettings.listId AND\n\tuserListSettings.listRoleId <> '0' AND\n\tuserListSettings.userId = userSiteSettings.userId\nJOIN\n\tframerates on framerates.frId = lists.frId\nLEFT JOIN\n\tfolders ON folders.folderId = lists.folderId\nLEFT JOIN\n\tuserFolderSettings ON userFolderSettings.folderId = folders.folderId AND\n\tuserFolderSettings.folderRoleId <> '0' AND\n\tuserFolderSettings.userId = userSiteSettings.userId");
        $initializeListStmt->execute(array($_SESSION['userId']));
        $initializeListRow = $initializeListStmt->fetch(PDO::FETCH_ASSOC);
        if (empty($initializeListRow)) {
            $message .= "Your role doesn't allow you to access that list.";
            header('Location:' . LINKADRLISTS . '?message=' . $message);
        } elseif ($initializeListRow['locked']) {
            $message .= "That list is locked. It must be unlocked before it can be viewed or edited. " . faqLink(45);
            header('Location:' . LINKADRLISTS . '?message=' . $message);
        } else {
            foreach ($initializeListRow as $key => $value) {
                $_SESSION[$key] = $value;
            }
        }
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
}
function listPropertiesStep1()
{
    global $debug, $message, $success, $Dbc, $returnThis;
    $output = '';
    try {
        if (empty($_POST['listId'])) {
            throw new Adrlist_CustomException('', '$_POST[\'listId\'] is empty.');
        }
        $_POST['listId'] = intval($_POST['listId']);
        //Get the listname, frId, and folderId.
        $listInfo = getListInfo($_SESSION['userId'], $_POST['listId']);
        if ($listInfo === false || $listInfo['listRoleId'] < 3) {
            throw new Adrlist_CustomException('Your role does not allow you to change the properties of this list.', '');
        }
        //Get the folders for which the user is an owner (4). This allows the user to move the list into a folder.
        $userFoldersStmt = $Dbc->prepare("SELECT\n\tfolders.folderId AS 'folderId',\n\tfolders.folderName AS 'folderName',\n\tuserFolderSettings.folderRoleId AS 'folderRoleId'\nFROM\n\tuserFolderSettings\nJOIN\n\tfolders ON folders.folderId = userFolderSettings.folderId\nWHERE\n\tuserFolderSettings.userId = ? AND\n\tuserFolderSettings.folderRoleId = ?");
        $params = array($_SESSION['userId'], 4);
        $userFoldersStmt->execute($params);
        $selectFolder = '';
        while ($row = $userFoldersStmt->fetch(PDO::FETCH_ASSOC)) {
            if (!empty($listInfo['folderId']) && $row['folderId'] == $listInfo['folderId']) {
                $selectFolder .= '	<option value="' . $row['folderId'] . '" selected="selected">' . $row['folderName'] . '</option>
';
            } else {
                $selectFolder .= '	<option value="' . $row['folderId'] . '">' . $row['folderName'] . '</option>
';
            }
        }
        //Build the framerate list.
        $frameratesArray = getFramerates();
        $frameRateOutput = '<div class="ui-field-contain">
	<label for="listPropertyFramerate">Framerate</label>
		<select id="listPropertyFramerate" goswitch="listPropertiesStep2">';
        foreach ($frameratesArray as $frId => $framerate) {
            $frameRateOutput .= '<option value="' . $frId . '"';
            $frameRateOutput .= $frId == $listInfo['frId'] ? ' selected="selected"' : '';
            $frameRateOutput .= '>' . $framerate . '</option>';
        }
        $frameRateOutput .= '</select>
	</div>';
        //Build the output.
        $output .= '<div class="myAccountTitle">
	List Properties
</div>
<div class="ui-field-contain">
	<label for="listPropertyName">List Name</label>
	<input autocapitalize="on" autocorrect="off" data-wrapper-class="true" id="listPropertyName" goswitch="listPropertiesStep2" name="listPropertyName" placeholder="" value="' . $listInfo['listName'] . '" type="text">
</div>';
        if (!empty($selectFolder)) {
            $output .= '<div class="ui-field-contain">
	<label for="newFolderId">in folder</label>
	<select id="newFolderId" goswitch="listPropertiesStep2">
		<option value="0">(no folder)</option>
' . $selectFolder . '</select>
</div>
<div class="red">
	Note: By changing the folder of this list, all users with a role for this list will automatically be given a role for the selected folder.' . faqLink(24) . '
</div>
';
        }
        $output .= $frameRateOutput . '
<button class="ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-icon-left ui-icon-heart" id="listPropertiesStep2" listId="' . $_POST['listId'] . '">Save</button>' . cancelButton();
        $returnThis['listPropertiesStep1'] = $output;
        $success = MODE == 'listPropertiesStep1' ? true : $success;
    } catch (Adrlist_CustomException $e) {
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
    if (MODE == 'listPropertiesStep1') {
        returnData();
    }
}
function buildUMLists()
{
    //Build the user management lists section.
    global $debug, $message, $success, $Dbc;
    $message = '';
    try {
        //Get the framerate values.
        $frameratesArray = getFramerates();
        //Get the user's lists and folders with lists.
        //Lists not in folders.
        $buildListsQueryStart = "SELECT\n\tlists.listId AS 'listId',\n\tlists.listName AS 'listName',\n\tlists.frId AS 'frId',\n\tlists.created AS 'listCreated',\n\tlists.modified AS 'listModified'\nFROM\n\tlists";
        //Folders.
        $buildFoldersQueryStart = "SELECT\n\tfolders.folderId AS 'folderId',\n\tfolders.folderName AS 'folderName',\n\tfolders.created AS 'folderCreated',\n\tfolders.modified AS 'folderModified',\n\tDATE_FORMAT(expires, '%M %D, %Y') AS 'expires'\nFROM\n\tfolders";
        if (empty($_POST['searchVal']) && empty($_POST['letters'])) {
            //Search for specific user(s).
            $success = true;
            //Will reset to show no users.
        } else {
            if (empty($_POST['searchVal']) && !empty($_POST['letters'])) {
                $search = false;
                $_POST['letters'] = trim($_POST['letters']);
                $buildListsQuery = $buildListsQueryStart . "\nWHERE\n\tfolderId IS NULL AND\n\tlistName RLIKE ?\nORDER BY\n\tlistName";
                $buildFoldersQuery = $buildFoldersQueryStart . "\nWHERE\n\tfolderName RLIKE ?\nORDER BY\n\tfolderName";
                $listStmt = $Dbc->prepare($buildListsQuery);
                $listParams = array('^[' . $_POST['letters'] . ']');
                $folderStmt = $Dbc->prepare($buildFoldersQuery);
                $folderParams = array('^[' . $_POST['letters'] . ']');
            } elseif (!empty($_POST['searchVal'])) {
                //Search for specific user(s).
                $search = true;
                $searchVal = '%' . trim($_POST['searchVal']) . '%';
                $debug->add('$searchval: ' . $searchVal);
                $buildListsQuery = $buildListsQueryStart . "\nWHERE\n\tfolderId IS NULL AND\n\tlistName LIKE ?\nORDER BY\n\tlistName";
                $buildFoldersQuery = $buildFoldersQueryStart . "\nWHERE\n\tfolderName LIKE ?\nORDER BY\n\tfolderName";
                $listStmt = $Dbc->prepare($buildListsQuery);
                $listParams = array($searchVal);
                $folderStmt = $Dbc->prepare($buildFoldersQuery);
                $folderParams = array($searchVal);
            }
            $listStmt->execute($listParams);
            $folderStmt->execute($folderParams);
            $output = '<div class="sectionTitle textCenter">Lists</div>
<div>
	<span class="textLeft" id="addFolderStep1" onClick=""><img alt="" class="linkPadding middle" src="' . LINKIMAGES . '/addFolder.png" style="height:15px;width:15px;"><span class="link middle">Add Folder</span></span>' . faqLink(30) . '
	<span class="textLeft" id="addListStep1" onClick=""><img alt="" class="linkPadding middle" src="' . LINKIMAGES . '/add.png" style="height:15px;width:15px;"><span class="link middle">Add List</span></span>
</div>
<div class="textLeft">
';
            $output .= '
	<div class="rowTitle" style="min-width:100px;width:30%">
		<div class="row textLeft" style="width:40px;padding:0 0 0 5px;">
			Type
		</div>
		Name
	</div>
	<div class="rowTitle" style="min-width:3em;width:8%">Framerate</div>
	<div class="rowTitle" style="min-width:5em;width:8%">Role' . faqLink(24) . '</div>
	<div class="rowTitle" style="min-width:5em;width:15%">Created</div>
	<div class="rowTitle" style="min-width:5em;width:15%">Modified</div>
	<div class="rowTitle" style="min-width:5em;width:24%"><div class="textRight">Actions' . faqLink(35) . '</div></div>
	<div class="hr2"></div>
';
            $class = 'rowWhite';
            $foundLists = false;
            $foundFolders = false;
            $lists = array();
            while ($row = $listStmt->fetch(PDO::FETCH_ASSOC)) {
                $foundLists = true;
                if (!array_key_exists($row['listId'], $lists)) {
                    $lists[$row['listId']] = array('listName' => $row['listName'], 'frId' => $row['frId'], 'created' => $row['listCreated'], 'modified' => $row['listModified']);
                }
            }
            $folders = array();
            if (empty($searchVal)) {
                while ($foldersRow = $folderStmt->fetch(PDO::FETCH_ASSOC)) {
                    $foundFolders = true;
                    //Get the lists inside the folders.
                    $listsInFoldersStmt = $Dbc->prepare("SELECT\n\tlists.listId AS 'listId',\n\tlists.listName AS 'listName',\n\tlists.frId AS 'frId',\n\tlists.created AS 'listCreated',\n\tlists.modified AS 'listModified'\nFROM\n\tlists\nJOIN\n\tfolders ON folders.folderId = lists.folderId AND\n\tfolders.folderId = ?");
                    $listsInFoldersParams = array($foldersRow['folderId']);
                    $listsInFoldersStmt->execute($listsInFoldersParams);
                    if (!array_key_exists($foldersRow['folderId'], $folders)) {
                        $folders[$foldersRow['folderId']] = array('folderName' => $foldersRow['folderName'], 'created' => $foldersRow['folderCreated'], 'modified' => $foldersRow['folderModified']);
                    }
                    while ($listsInFoldersRow = $listsInFoldersStmt->fetch(PDO::FETCH_ASSOC)) {
                        $foundListsInFolders = true;
                        $folders[$foldersRow['folderId']]['lists'][$listsInFoldersRow['listId']] = array('listName' => $listsInFoldersRow['listName'], 'frId' => $listsInFoldersRow['frId'], 'created' => $listsInFoldersRow['listCreated'], 'modified' => $listsInFoldersRow['listModified']);
                    }
                }
            } else {
                //When searching, if the term is not found in a folder name, then the folder and it's lists will not be included. This prevents lists matching the search term from appearing. We must therefore create an entirely separate query to search for terms in lists inside of folders.
                $listsInFoldersSearchStmt = $Dbc->prepare("SELECT\n\tlists.listId AS 'listId',\n\tlists.listName AS 'listName',\n\tlists.frId AS 'frId',\n\tlists.created AS 'listCreated',\n\tlists.modified AS 'listModified',\n\tfolders.folderId AS 'folderId',\n\tfolders.folderName AS 'folderName',\n\tfolders.created AS 'folderCreated',\n\tfolders.modified AS 'folderModified'\nFROM\n\tlists\nJOIN\n\tfolders ON folders.folderId = lists.folderId AND\n\tlists.listName LIKE ?");
                $debug->add('searching lists in folders.');
                $listsInFoldersSearchParams = array($searchVal);
                $listsInFoldersSearchStmt->execute($listsInFoldersSearchParams);
                while ($listsInFoldersSearchRow = $listsInFoldersSearchStmt->fetch(PDO::FETCH_ASSOC)) {
                    $foundFolders = true;
                    if (!array_key_exists($listsInFoldersSearchRow['folderId'], $folders)) {
                        $folders[$listsInFoldersSearchRow['folderId']] = array('folderName' => $listsInFoldersSearchRow['folderName'], 'folderRoleId' => $listsInFoldersSearchRow['folderRoleId'], 'created' => $listsInFoldersSearchRow['folderCreated'], 'modified' => $listsInFoldersSearchRow['folderModified']);
                    }
                    $folders[$listsInFoldersSearchRow['folderId']]['lists'][$listsInFoldersSearchRow['listId']] = array('listName' => $listsInFoldersSearchRow['listName'], 'listRoleId' => $listsInFoldersSearchRow['listRoleId'], 'frId' => $listsInFoldersSearchRow['frId'], 'created' => $listsInFoldersSearchRow['listCreated'], 'modified' => $listsInFoldersSearchRow['listModified']);
                }
            }
            //$debug->printArray($lists,'$lists');
            $debug->printArray($folders, '$folders');
            /*An nest of arrays:
            			Array $folders:
            array (
              2 => 
              array (
            	'folderName' => 'Junk Food',
            	'folderRoleId' => '3',
            	'modified' => '2012-02-25 11:26:45',
            	'lists' => 
            	array (
            	  9 => 
            	  array (
            		'listName' => '\'63 Comet',
            		'listRoleId' => '3',
            		'modified' => '2012-02-17 13:51:17',
            	  ),
            	  12 => 
            	  array (
            		'listName' => 'The Awesome List2',
            		'listRoleId' => '2',
            		'modified' => '2012-02-25 07:49:32',
            	  ),
            	),
              ),
              14 => 
              array (
            	'folderName' => 'My Super Awesome Folder',
            	'folderRoleId' => '1',
            	'modified' => NULL,
            	'lists' => 
            	array (
            	  '' => 
            	  array (
            		'listName' => NULL,
            		'listRoleId' => NULL,
            		'modified' => NULL,
            	  ),
            	),
              ),
              1 => 
              array (
            	'folderName' => 'Scizors',
            	'folderRoleId' => '1',
            	'modified' => NULL,
            	'lists' => 
            	array (
            	  1 => 
            	  array (
            		'listName' => 'River of Sorrow',
            		'listRoleId' => '2',
            		'modified' => '2011-04-22 07:33:44',
            	  ),
            	  6 => 
            	  array (
            		'listName' => 'Hit List',
            		'listRoleId' => '2',
            		'modified' => '2011-10-04 06:20:19',
            	  ),
            	  4 => 
            	  array (
            		'listName' => 'I AM',
            		'listRoleId' => '2',
            		'modified' => '2010-06-18 23:51:11',
            	  ),
            	  2 => 
            	  array (
            		'listName' => 'Norman',
            		'listRoleId' => '2',
            		'modified' => '2009-08-03 23:12:36',
            	  ),
            	  8 => 
            	  array (
            		'listName' => 'Thunderballs S1E1',
            		'listRoleId' => '2',
            		'modified' => '2011-06-28 20:44:14',
            	  ),
            	  5 => 
            	  array (
            		'listName' => 'Locked Down',
            		'listRoleId' => '2',
            		'modified' => '2012-01-25 09:48:27',
            	  ),
            	  3 => 
            	  array (
            		'listName' => 'Wrong Turn At Tahoe',
            		'listRoleId' => '2',
            		'modified' => '2009-07-27 05:31:23',
            	  ),
            	),
              ),
            )
            		*/
            //Build the lists not in folders.
            foreach ($lists as $listId => $listValues) {
                if ($class == 'rowWhite') {
                    $class = 'rowAlt';
                } else {
                    $class = 'rowWhite';
                }
                $output .= '	<div class="overflowauto relative ' . $class . '">
		<div class="row textLeft" style="min-width:100px;width:30%">
			<div class="row textLeft" style="width:40px;padding:0 0 0 5px;">
				<img alt="" src="' . LINKIMAGES . '/list.png" style="height:15px;width:15px">
			</div>
			<span id="listName' . $listId . '">' . $listValues['listName'] . '</span>
		</div>
		<div class="row" style="min-width:3em;width:8%">' . $frameratesArray[$listValues['frId']] . '</div>
		<div class="row textSmall" style="min-width:5em;width:15%">
			';
                if (empty($listValues['created'])) {
                    $output .= 'n/a';
                } else {
                    $output .= Adrlist_Time::utcToLocal($listValues['created']);
                }
                $output .= '		</div>
		<div class="row textSmall" style="min-width:5em;width:15%">
			';
                if (empty($listValues['modified'])) {
                    $output .= 'n/a';
                } else {
                    $output .= Adrlist_Time::utcToLocal($listValues['modified']);
                }
                $output .= '		</div>
			<div class="bold hand row" id="rowActionsButtonList' . $listId . '" uniqueId="List' . $listId . '" style="min-width:5em;width:24%" onClick="">
				<div class="textRight">
					List Actions <img alt="" class="middle" src="' . LINKIMAGES . '/greenArrowRight.png" style="height:12px;width:12px">
				</div>
			</div>
';
                //The rowActions for lists not in folders.
                $output .= '<div class="hide right" id="rowActionsHolderList' . $listId . '" listId="' . $listId . '" style="background-color:inherit">
			<ul class="textLeft" style="list-style:none;margin:5px 0px">
				<li class="actions" id="editList' . $listId . '" listId="' . $listId . '" onClick="">
					<img alt="" class="middle" src="' . LINKIMAGES . '/edit.png" style="height:20px;width:20px;"><span class="linkPadding">Edit</span>
				</li>
				<li class="actions" id="listPropertiesStep1' . $listId . '" listId="' . $listId . '" onClick="">
					<img alt="" class="middle" src="' . LINKIMAGES . '/tools.png" style="height:20px;width:20px;"><span class="linkPadding">Properties</span>
				</li>
				<li class="actions" id="buildListUsers' . $listId . '" listId="' . $listId . '" onClick="">
					<img alt="" class="middle" src="' . LINKIMAGES . '/charSearch.png" style="height:20px;width:20px;"><span class="linkPadding">Manage Users</span>
				</li>
				<li class="actions" id="transferList' . $listId . '" listId="' . $listId . '" onClick="">
					<img alt="" class="middle" src="' . LINKIMAGES . '/transfer.png" style="height:20px;width:20px;"><span class="linkPadding">Transfer</span>
				</li>
				<li class="actions" id="lockListStep1' . $listId . '" listId="' . $listId . '" onClick="">
					<img alt="" class="middle" src="' . LINKIMAGES . '/lock.png"  style="height:20px;width:20px;"><span class="linkPadding">Lock</span>
				</li>
				<li class="actions" id="deleteListStep1' . $listId . '" listId="' . $listId . '" onClick="">
					<img alt="" class="middle" src="' . LINKIMAGES . '/trash.png"  style="height:20px;width:20px;"><span class="linkPadding">Delete</span>
				</li>
			</ul>
		</div>
	</div>
';
                //End rowActions.
            }
            //End lists not in folders.
            //Build folders.
            foreach ($folders as $folderId => $folderValues) {
                $output .= '	<div class="folderRow" id="rowActionsFolder' . $folderId . '">
		<div class="hand row textLeft" id="toggleFolderLists' . $folderId . '" folderid="' . $folderId . '" onClick="" style="min-width:100px;width:30%">
			<div class="row textLeft" style="width:40px;padding:0 0 0 5px;">
				<img alt="" src="' . LINKIMAGES . '/folder.png" style="height:20px;width:20px"><span><img id="folderListsImg' . $folderId . '" thing="Lists" src="' . LINKIMAGES . '/bulletArrow';
                $output .= $search ? 'Down' : 'Right';
                $output .= '.png" style="height:20px;width:20px;"></span>
			</div>
			<span id="folderName' . $folderId . '">' . $folderValues['folderName'] . '</span>
		</div>
		<div class="row" style="min-width:3em;width:8%"></div>
		<div class="row textSmall" style="min-width:5em;width:15%">
			';
                if (empty($folderValues['created'])) {
                    $output .= 'n/a';
                } else {
                    $output .= Adrlist_Time::utcToLocal($folderValues['created']);
                }
                $output .= '		</div>
		<div class="row textSmall" style="min-width:5em;width:15%">
			';
                if (empty($folderValues['modified'])) {
                    $output .= 'n/a';
                } else {
                    $output .= Adrlist_Time::utcToLocal($folderValues['modified']);
                }
                $output .= '		</div>
			<div class="bold hand row" id="rowActionsButtonFolder' . $folderId . '" onClick="" uniqueId="Folder' . $folderId . '" style="min-width:5em;width:24%">
				<div class="textRight">
					Folder Actions <img alt="" class="middle" id="folderActionsImg' . $folderId . '" src="' . LINKIMAGES . '/greenArrowRight.png" style="height:12px;width:12px"">
				</div>
			</div>
';
                //The folder rowActions.
                $output .= '			<div class="hide right" id="rowActionsHolderFolder' . $folderId . '" style="background-color:inherit">
				<ul class="textLeft" style="list-style:none;margin:5px 0px">
					<li class="actions" id="renameFolderStep1' . $folderId . '" folderid="' . $folderId . '" folderName="' . $folderValues['folderName'] . '" onClick="">
						<img alt="" class="middle" src="' . LINKIMAGES . '/pencil.png" style="height:1.6em;width:1.6em"><span class="linkPadding">Rename</span>
					</li>
					<li class="actions" id="buildFolderUsers' . $folderId . '" folderid="' . $folderId . '" onClick="">
						<img alt="" class="middle" src="' . LINKIMAGES . '/charSearch.png" style="height:1.6em;width:1.6em"><span class="linkPadding">Manage Users</span>
					</li>
					<li class="actions" id="deleteFolder' . $folderId . '" folderid="' . $folderId . '" folderName="' . $folderValues['folderName'] . '" onClick="">
						<img alt="" class="middle" src="' . LINKIMAGES . '/trash.png" style="height:1.6em;width:1.6em"><span class="linkPadding">Delete</span>
					</li>
				</ul>
			</div>
		<div';
                $output .= $search ? '' : ' class="hide"';
                $output .= ' id="folderListsHolder' . $folderId . '">
';
                //The lists in the folder.
                $listCount = 0;
                if (empty($folderValues['lists'])) {
                    $output .= '<div class="break textCenter">There are no lists in this folder.</div>';
                }
                if (array_key_exists('lists', $folderValues)) {
                    foreach ($folderValues['lists'] as $listId => $listValues) {
                        if ($class == 'rowWhite') {
                            $class = 'rowAlt';
                        } else {
                            $class = 'rowWhite';
                        }
                        $output .= '			<div class=" ' . $class . '" id="rowActionsList' . $listId . '">
				<div class="row textLeft" style="min-height:21px;min-width:170px;width:30%">
					<div class="row textLeft" style="width:40px;padding:0 0 0 5px;">
						<img alt="" src="' . LINKIMAGES . '/list.png" style="height:15px;left:5px;width:15px">
					</div>
					<span id="listName' . $listId . '">' . $listValues['listName'] . '</span>
				</div>
				<div class="row" style="min-width:3em;width:8%">' . $frameratesArray[$listValues['frId']] . '</div>
				<div class="row textSmall" style="min-width:5em;width:15%">
			';
                        if (empty($listValues['created'])) {
                            $output .= 'n/a';
                        } else {
                            $output .= Adrlist_Time::utcToLocal($listValues['created']);
                        }
                        $output .= '				</div>
				<div class="row textSmall" style="min-width:5em;width:15%">
			';
                        if (empty($listValues['modified'])) {
                            $output .= 'n/a';
                        } else {
                            $output .= Adrlist_Time::utcToLocal($listValues['modified']);
                        }
                        $output .= '				</div>
				<div class="bold hand row" id="rowActionsButtonList' . $listId . '" uniqueId="List' . $listId . '" style="min-width:5em;width:24%">
					<div class="textRight">
						List Actions <img alt="" class="middle" src="' . LINKIMAGES . '/greenArrowRight.png" style="height:12px;width:12px">
					</div>
				</div>
';
                        //The rowActions for lists in folders.
                        $output .= '<div class="hide right" id="rowActionsHolderList' . $listId . '" style="background-color:inherit">
			<ul class="textLeft" style="list-style:none;margin:5px 0px">
				<li class="actions" id="editList' . $listId . '" listId="' . $listId . '" onClick="">
					<img alt="" class="middle" src="' . LINKIMAGES . '/edit.png" style="height:1.6em;width:1.6em;"><span class="linkPadding">Edit</span>
				</li>
				<li class="actions" id="listPropertiesStep1' . $listId . '" listId="' . $listId . '" onClick="">
					<img alt="" class="middle" src="' . LINKIMAGES . '/tools.png" style="height:20px;width:20px;"><span class="linkPadding">Properties</span>
				</li>
				<li class="actions" id="buildListUsers' . $listId . '" listId="' . $listId . '" onClick="">
					<img alt="" class="middle" src="' . LINKIMAGES . '/charSearch.png" style="height:1.6em;width:1.6em;"><span class="linkPadding">Manage Users</span>
				</li>
				<li class="actions" id="transferListStep1' . $listId . '" listId="' . $listId . '" onClick="">
					<img alt="" class="middle" src="' . LINKIMAGES . '/transfer.png" style="height:1.6em;width:1.6em;"><span class="linkPadding">Transfer</span>
				</li>
				<li class="actions" id="lockListStep1' . $listId . '" onClick="">
					<img alt="" class="middle" src="' . LINKIMAGES . '/lock.png"  style="height:1.6em;width:1.6em;"><span class="linkPadding">Lock</span>
				</li>
				<li class="actions" id="deleteListStep1' . $listId . '" listId="' . $listId . '" onClick="">
					<img alt="" class="middle" src="' . LINKIMAGES . '/trash.png"  style="height:1.6em;width:1.6em;"><span class="linkPadding">Delete</span>
				</li>
			</ul>
		</div>
	</div>
';
                        //End lists in folders.
                    }
                }
                $output .= '		</div>
	</div>
';
                //End folders.
            }
            if (!$foundLists && !$foundFolders) {
                if ($search) {
                    $output .= '<div class="red textCenter" style="padding:5px 0px 10px 0px;">There are no matches for "' . $_POST['searchVal'] . '".</div>';
                } else {
                    $output .= '<div class="textCenter" style="padding:5px 0px 10px 0px;">You are not associated with any folders or lists.</div>';
                }
                pdoError(__LINE__, $listStmt, $listParams, true);
                pdoError(__LINE__, $folderStmt, $folderParams, true);
                if (isset($listsInFoldersStmt)) {
                    pdoError(__LINE__, $listsInFoldersStmt, $listsInFoldersParams, true);
                }
                if (!empty($listsInFoldersSearchStmt)) {
                    pdoError(__LINE__, $listsInFoldersSearchStmt, $listsInFoldersSearchParams, true);
                }
            }
            $output .= '</div>
';
            $success = true;
            $returnThis['buildUMLists'] = $output;
        }
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
    if (MODE == 'buildUMLists') {
        returnData();
    } else {
        return $output;
    }
}