Location: PHPKode > scripts > phpFlickrSynch > phpflickrsynch/backoffice/index.php
<?php
	require_once('../phpFlickrSynch.php');
	require_once('../_classes/class_FlickrToPortfolio.php');
	include '_include/header.php';


?>
<h1>
	<span>phpFlickrSynch</span>
	<a href="./index.php" class="selected">Manage photo albums</a> 
    <a href="./groups.php">Manage photo groups</a>
</h1>
<?php
	$MAPPING = new FlickrToPortfolio();
	$DBPORTFOLIO = new TableFlickrPortfolio();
	$DBGROUP = new TableFlickrGroup();
	$groups = array();
	foreach ($DBGROUP->getAllGroups() as $key => $val) {
		$groups[$val['id']] = $val['name'];
	}
	
	$ACTION = isset($_REQUEST['action']) ? $_REQUEST['action'] : NULL;	
	$FLICKRID = isset($_REQUEST['flickrid']) ? $_REQUEST['flickrid'] : NULL;
	$FILTER = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : 'ALL';
	$groupId = isset($_REQUEST['groupId']) ? (integer)$_REQUEST['groupId'] : -1;

	switch ($ACTION) {
		case 'UNREGISTER':
			if (isset($FLICKRID) && strlen($FLICKRID) > 0) {
				$response = $MAPPING->unregisterAlbum($FLICKRID);
				echo '<div class="infoMsg"><div class="inner">' . $response->toString() . '</div></div>';
			}
			break;
		default:
			break;
	}

	$all_flickr_albums = $MAPPING->getAllFlickrAlbums();
	function cmp($a, $b) { return strcmp($a["title"], $b["title"]);}
	usort($all_flickr_albums, 'cmp');
	
	$registered_albums = $DBPORTFOLIO->getRegisteredAlbums();
	
	$res = array();
	
	$flagShowAll = strcmp($FILTER, 'ALL') == 0;
	$flagShowGroup = strcmp($FILTER, 'GROUP') == 0;
	$flagShowUnregistered = strcmp($FILTER, 'UNREGISTERED') == 0;
	
	foreach ($all_flickr_albums as $key => $val) {
		$flickrid = $val['id'];
		$already_registered = isset($registered_albums[$flickrid]);
		$porId = 0;
		$grpId = 0;
		$groupName = NULL;
		
		if ($already_registered) {
			$porId = $registered_albums[$flickrid]['porId'];
			$grpId = $registered_albums[$flickrid]['grpId'];
			$groupName = isset($groups[$grpId]) ? $groups[$grpId] : '';			
		}
		
		if ($flagShowAll || ($flagShowUnregistered && !$already_registered) || ($flagShowGroup && $grpId == $groupId && $already_registered)) {
			$res[] = array(
				'flickrid' => $val['id'],
				'title' => $val['title'],
				'registered' => $already_registered,
				'porId' => $porId,
				'grpId' => $grpId,
				'groupName' => $groupName
			);
		}
	}
?>

<p class="introduction">Below here is the list of all your photo albums on Flickr. You can choose to register / unregister photo albums within phpFlickSynch, organize the registered photo albums inside groups.</p>

<div>
	<div class="left">
    	<button type="button" id="resynchall"><span>Resynch selected albums</span></button>
	</div>
    <div class="right">
		<?php if (!$flagShowAll) { ?><a href="index.php?filter=ALL">Show all photo albums</a><?php } else { ?><strong>Show all photo albums</strong><?php } ?> - 
    	<?php if (!$flagShowUnregistered) { ?><a href="index.php?filter=UNREGISTERED">Only show non-registered</a><?php } else { ?><strong>Only show non-registered</strong><?php } ?> -
        <?php if (!$flagShowGroup) { ?>Show from group:<?php } else { ?><strong>Show from group:</strong><?php } ?>
        <form method="get">
        <input type="hidden" name="filter" value="GROUP"/>
        <select id="groupIdSelect" name="groupId" style="font-size: 12px;">
        	<option value="0"<?php if ($groupId == 0) echo ' selected="true"';?>>None</option>
<?php foreach ($groups as $id => $name) { ?>
        	<option value="<?php echo $id;?>"<?php if ($groupId == $id) echo ' selected="true"';?>><?php echo $name;?></option>
<?php } ?>            
        </select>
        <button type="submit">GO</button>
        </form>
	</div>
    <div class="clear"></div>
</div>

<form method="post" action="#">
<table>
<thead>
<tr>
	<th>&nbsp;</th>
    <th>Photo album title</th>
    <th>Status</th>
    <th>Group</th>
    <th>Actions</th>
</tr>
</thead>
<?php	
	foreach ($res as $key => $val) {
		$flickrid = $val['flickrid'];
		$already_registered = $val['registered'];		
		$porId = $val['porId'];
		$grpId = $val['grpId'];
		$groupName = $val['groupName'];
		$title = $val['title'];
?>
<tr id="photoalbum-<?php echo $flickrid?>" class="photoalbumrow">
<?php
		if ($already_registered) {
?>	
	<td><input type="checkbox" class="albumcheckbox" name="album-<?php echo $flickrid?>" value="<?php echo $flickrid?>"/></td>
	<td class="registered"><?php echo $title;?></td>
	<td class="registered"><span class="green">Registered</span> - ID=<span id="porid-<?php echo $flickrid?>"><?php echo $porId?></span></td>
    <td><span id="groupname-<?php echo $flickrid?>"><?php echo $groupName;?></span></td>
    <td>
		<a href="?action=UNREGISTER&amp;flickrid=<?php echo $flickrid?>"><img title="Unregister" src="_images/link_break.png" width="16" height="16"/></a>
		<img title="Resynch" alt="Resynch" src="_images/arrow_refresh.png" width="16" height="16" id="resynch-<?php echo $flickrid?>" class="icon"/>      
		<a href="./photodata.php?porid=<?php echo $porId?>"><img title="Show photo data" src="_images/page_white_database.png" width="16" height="16"/></a>
    </td>
<?php
		} else {
?>	
	<td>&nbsp;</td>
    <td><?php echo $title;?></td>
    <td><span class="orange">Not registered</span></td>
    <td>&nbsp;</td>
    <td><span id="register-<?php echo $flickrid?>" class="link">Register</span></td>
<?php
		}
?>
</tr>
<?php		
	}
?>
</table>
</form>

<div id="ajaxWindow" style="display:none">
	<div id="ajaxWindowContent"></div>
	<button id="ajaxWindowClose" class="action" style="display:none">DONE</button>
</div>

<script type="text/javascript">
<!--
var PA = new PhotoAlbums();
PA.init();
-->
</script>

<?php
	include '_include/footer.php';	
?>
Return current item: phpFlickrSynch