<?
include("../includes/site_config.php");
//include($CONST_INCLUDE_ROOT.'/session_handler.inc');include('../session_handler.inc');
//include($CONST_INCLUDE_ROOT.'/error.php');include('../error.php');
include_once __INCLUDE_CLASS_PATH."/class.Gallery.php";
include_once __INCLUDE_CLASS_PATH."/class.GalleryItem.php";
//include($CONST_INCLUDE_ROOT.'/message.php');
include('../message.php');
include('../includes/functions.php');
include("../includes/tab_functions.js");
include('paginate.php');
include('../lib/lib.Functions.php');

$option_manager = new OptionManager();
$CONST_MAIL = $option_manager->GetValue('mail'); 

$area = 'member';
//$user_id = formGet('user_id');
$user_id = form_get('user_id');
	if(isset($_REQUEST['chkRemove'])){
	$chkRemove=form_get('chkRemove');
	$query=mysql_query("DELETE FROM galleryitem WHERE MD5(GalleryItem_ID)='$chkRemove'");
 	}


$gallery = new Gallery();
$gallery_item = new GalleryItem();

//if (FormGet('DONE')){
  if ($_REQUEST['DONE']){
    //$items = formGet('item');
	$items = $_REQUEST['item'];
    foreach ($items as $id => $status){
	$quePic=mysql_fetch_object(mysql_query("SELECT 	*
								FROM galleryitem
								left join gallery
								ON(galleryitem.Gallery_ID=gallery.Gallery_ID)
								LEFT JOIN members
								ON(mem_id=mem_userid) where GalleryItem_ID='$id'"));
	If($status=='Rejected'){
		send_mail ("$quePic->mem_email", "$CONST_MAIL", "$CONST_COMPANY ".GAL_REJ, MAIL_UNAPPROVEDGAL,$type,"ON");
	}
	If($status=='Approved'){
		send_mail ("$quePic->mem_email", "$CONST_MAIL", "$CONST_COMPANY ".GAL_APP, MAIL_APPROVEDGAL,$type,"ON");
	}
        $gallery_item->Init($id);
        $gallery_item->Approve($status);
    } ?>

    

<!--<script language="javascript">
window.location='index.php?PHPSESSID=".session_id()';
   
   </script>-->

<?php //header("Location: $CONST_ADMIN_LINK_ROOT/$SCRIPT_NAME?PHPSESSID=".session_id());
    //exit;
}

 $user_id = $gallery->GetMemberForApprove();

/*if (!$user_id) {
        $error_message="<p><a href='$CONST_LINK_ROOT/admin/index.php'>Continue</a></p>";
        display_page($error_message,PRGAUTHGALLERY_TEXT1);
}*/
$aGallery = $gallery->GetPendingGallery($user_id);
$size= count($aGallery);
?>
<?php include("include/header.php"); ?>
<link rel="stylesheet" href="../lightbox2/lightbox.css" type="text/css" media="screen" />
<script type="text/javascript" src="../lightbox2/lightbox.js"></script>

<?php include('approve_menu.php'); ?>

<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Approve Galleries</div></div>
<div class="clear"></div>
<div class="admin-page">
<form enctype='multipart/form-data' method='post' action='<?=$_SERVER['PHP_SELF']?><?php print("?PHPSESSID=".session_id()); ?>'>

<table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">
  <!-- <tr>
    <td align="right">
		<?php // require_once("../user_status.inc.php");?>
    </td>
  </tr> -->
  <? if($size < 1){?>

<tr > 


            <td>&nbsp;</td>


 <td  align="left"> <font color="#CC0000" size="+2">Nothing To Approve!</font></td>



 <td align="center"></td>

          </tr>

<? }?>
    <tr>
    <td align=left   class='normal'>&nbsp;</td>
  </tr>

<?
foreach ($aGallery as $gallery_row){
?>
  <tr>
    <td>
    	<?= $gallery_row->Name?>
	  <table width="100%" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">
		 <tr>
			<?
			$i=0;
            $aItems = $gallery->GetPendingItemList($gallery_row->Gallery_ID);
			foreach ($aItems as $item_row){
			
				$item = new GalleryItem();
			    $item->Init($item_row);
			if ($item->Type == 'Image') {
			    $src = $item->File->getInfo('small');
			    $src_full = $item->File->getInfo();
		        //$link = "<a href=\"javascript:MDM_openWindow('$CONST_LINK_ROOT/prgdisplaypic.php?thePic=/includes$src_full->Path','Photograph','width=1,height=1');\"><img border='0' src='$CONST_LINK_ROOT/includes$src_full->Path' width='100' height='100'></a>&nbsp;&nbsp;&nbsp;&nbsp;";
				$link = "<a href='$CONST_LINK_ROOT/includes$src_full->Path' rel='lightbox'><img border='0' src='$CONST_LINK_ROOT/includes$src->Path' width='100' height='100'></a>&nbsp;&nbsp;&nbsp;&nbsp;";
				
			} elseif ($item->Type == 'Video') {
		        $src = $item->File->getInfo();
		        $link = "<a href=\"$CONST_LINK_ROOT/includes$src->Path\"><img border='0' src='$CONST_IMAGE_ROOT/$CONST_IMAGE_LANG/video.gif' width='60' height='45'></a>";
			}
			?>
			    <td>
			    	<table width="100%" border="0" cellspacing="0" cellpadding="0">
			    	<tr><td>
			    	<? if ($src) {?>
			        	<?=$link?><br />
						<div align="center"><?=$item_row->Description?></div>
			    	<? }?><br />
			    	</td></tr>
			    	<tr><td>
			    	<select name="item[<?=$item->GalleryItem_ID?>]">
					<? foreach ($item->StatusList as $key => $value){?>
					<? if ($key!= 'Pending'){?><option value="<?=$key?>"> <?=$value?></option><?}?>
					<? }?>
					</select>
					</td></tr>
					</table>
			    </td>
			   <?php /*?> <? if (++$i%$gallery->ImagePerLine == 0){?></tr><tr><? }?><?php */?>
			    <? if (++$i%5 == 0){?></tr><tr><? }?>
	      <? }?>
			</tr>
		</table>
    </td>
  </tr>

  <tr>
    <td>
    	<input type="submit" name="DONE" value="<?=GENERAL_SAVE?>">
    </td>
  </tr><? }?>
</table>
</form>
</div><div class="admin-page-bottom"></div></div>


<!--Approved Images Area Starts here-->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->
<!---->

<br /><br />

<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;<?=APPROVED_GALS?></div></div>
<div class="clear"></div>
<div class="admin-page">
<table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">
  <tr>

    <td> <form enctype='multipart/form-data' method='post' action='<?=$_SERVER['PHP_SELF']?><?php print("?PHPSESSID=".session_id()); ?>&mode=amend' name="FrmPicture"><table width="100%"  border="0" cellpadding="5" cellspacing="5" align="center">

     
<!--<link rel="stylesheet" href="../lightbox2/lightbox.css" type="text/css" media="screen" />
<script type="text/javascript" src="../lightbox2/lightbox.js"></script>-->



          <?php
		  
		

 $query="
	        					SELECT 	*, galleryitem.Description as descri
								FROM galleryitem
								left join gallery
								ON(galleryitem.Gallery_ID=gallery.Gallery_ID)
								LEFT JOIN members
								ON(mem_id=mem_userid)
								WHERE Approved = 'Approved' AND
								mem_confirm!='0'
								
								ORDER BY GalleryItem_ID DESC
        ";


//$apPictures = $picture->GetApprovedList();
$record_per_page='20';

$pager = new PS_Pagination($link,$query,$record_per_page,5);
$rs = $pager->paginate();

$indx=0;

$j=0;
while($sql_app=mysql_fetch_object($rs)){
//foreach ($rs as $sql_app) {



    $indx++;



    $pic_private = ($sql_app->pic_private=='Y') ? "checked" : "";



    $pic_default = ($sql_app->pic_default=='Y') ? "checked" : "";



    //$pic_info = $sql_app->getInfo();

//print $sql_app->pic_id;
	if(($j%5)==0)
	{
	print "<tr><td colspan='0'>&nbsp;</td></tr>
	<tr>";
}

    print(" 

            <td align='center'>
			<a href='$CONST_LINK_ROOT/includes/members/gallery/".$sql_app->GalleryItem_ID.".jpg' rel='lightbox' title=".$sql_app->Description."><img border='0' src='$CONST_LINK_ROOT/includes/members/gallery/".$sql_app->GalleryItem_ID."_small.jpg' height='100' width='100s'></a>
			
			
			
			<br>
			
			<br>");?> 
			<?=$sql_app->descri?><br>
			<? if($DEMO==false){?><a href="<?=$CONST_LINK_ROOT?>/admin/approve_media.php?chkRemove=<?=md5($sql_app->GalleryItem_ID)?>&mode=amend" onclick="javascript:return confirm('Are you sure want to delete')">Delete</a><? }?>
		<? print("
			<input type='hidden' name='pic_exists[]' value=$sql_app->pic_id></td>

			

		



            <td align='center'></td>



           



      ");


$j++;
}


?>

 

 </table> </form>
    </td>
  </tr>
  <tr><td align="right"><? echo $pager->renderNext(); ?></td></tr>
</table>
</div><div class="admin-page-bottom"></div></div>


<?php include("include/footer.php"); ?>
