<?php

include("../includes/site_config.php");

include('../session_handler.inc');

include('../error.php');

include('../imagesizer.php');

include('../message.php');

include('paginate.php');

include('../includes/functions.php');

include('../lib/lib.Functions.php');

include("../includes/tab_functions.js");
$mode=$_GET['mode'];



unset($_SESSION['chkPrivate']);

include_once __INCLUDE_CLASS_PATH."/class.ItemManager.php";
$option_manager = new OptionManager();
$imagecount=$option_manager->GetValue('image_count');
$CONST_MAIL=$option_manager->GetValue('mail');
# retrieve the template

include_once __INCLUDE_CLASS_PATH."/class.Picture.php";

$picture = new Picture();

include_once __INCLUDE_CLASS_PATH."/class.DB.php";

$db = new DB();

$Sess_UserId = $_SESSION['Sess_UserId'];

$Sess_UserName = $_SESSION['Sess_UserName'];

if(isset($_REQUEST['appPicture'])){
$upd=mysql_query("UPDATE adverts set adv_imageappr='1' where adv_userid='".form_get('appPicture')."'");
}

if(isset($_REQUEST['delPic'])){
$upd=mysql_query("UPDATE adverts set adv_imageappr='2' where adv_userid='".form_get('delPic')."'");
}


# select advert data


$adv_count =$db->get_var("SELECT count(*) FROM adverts WHERE adv_userid=$Sess_UserId");

$count_app=$db->get_var("select count(*) from adverts where adv_picture!='templates/default/images/genericm.gif' AND adv_picture!='templates/default/images/genericf.gif' AND adv_imageappr='0'");



# if nothing is returned then show error otherwise get data



if ($adv_count < 1) {



    $error_message=PRGPICADMIN_ERROR1;



    error_page($error_message,GENERAL_USER_ERROR);



}


if ($mode=='amend') {

    if ($Sess_UserName == '$Sess_UserName') {



        restrict_demo();



    }


    //$radDefault=formGet('radDefault');

//$radDefault=$_REQUEST['radDefault'];



    //$chkRemove=formGet('chkRemove');

$chkRemove=form_get('chkRemove');

//    $chkPrivate=formGet('chkPrivate');

$chkPrivate=form_get('chkPrivate');
$appPic=form_get('appPic');

    $picture->ClearPrivate($Sess_UserId);
if ($appPic) {
    //if (count($chkPrivate)) {

       // foreach ( $chkPrivate as $key=>$value) {



            $picture->InitById($appPic);



            $picture->SetApprove();

$quePic=mysql_fetch_object(mysql_query("SELECT * from pictures LEFT JOIN members on(pic_userid=mem_userid) where pic_id='$appPic'"));
      			send_mail ("$quePic->mem_email", "$CONST_MAIL", "$CONST_COMPANY ".PIC_APR, MAIL_APPROVEDPIC,$type,"ON");

       // }



    }

    if ($radDefault) {



        $picture->InitById($radDefault);



        $result = $picture->SetDefault($Sess_UserId);



        if ($result === null) error_page(join("<br>",$picture->error),GENERAL_USER_ERROR);



    }

 if ($chkRemove) {
   // if (count($chkRemove)) {



        //foreach ( $chkRemove as $key=>$value) {

$quePic=mysql_fetch_object(mysql_query("SELECT * from pictures LEFT JOIN members on(pic_userid=mem_userid) where pic_id='$chkRemove'"));

      			

           $picture->InitById($chkRemove);



           $picture->DeletePic($Sess_UserId);
send_mail ("$quePic->mem_email", "$CONST_MAIL", "$CONST_COMPANY ".PIC_UNAPR, MAIL_UNAPPROVEDPIC,$type,"ON");
        //}



    }



    $rownum=0;






}



$aPictures = $picture->GetListByPictureApprove();



//print_r($aPictures);



$result = count($aPictures);



//echo "<br>Result".$result;



$area = 'member';


################

# Add Image Area!

################

# retrieve the template



# select advert data
$result = mysql_query("SELECT * FROM adverts WHERE adv_userid=$Sess_UserId",$link);
$TOTAL = mysql_num_rows($result);
# if nothing is returned then show error otherwise get data
if ($TOTAL < 1) {
    $error_message=PRGPICADMIN_ERROR1;
    error_page($error_message,GENERAL_USER_ERROR);
}

$query="SELECT COUNT(pic_id) FROM pictures LEFT JOIN members ON(pic_userid=mem_userid) where approved='0' AND mem_confirm!=0";
$retpicapp=mysql_query($query,$link) or die(mysql_error());
$totalpicapp=mysql_result($retpicapp,0,0);



?>



<?php include("include/header.php"); ?>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0

  window.open(theURL,winName,features);
  return false;
}
//-->
</script>
<?php include('approve_menu.php'); ?>

<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Approve Photos</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">
<? 
if ($totalpicapp < 1 && $count_app < 1) {?>

    <tr align="center"> 


 


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





          </tr>




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

<!--<script type="text/javascript" src="<?=$CONST_LINK_ROOT?>/lightbox/js/prototype.js"></script>
<script type="text/javascript" src="<?=$CONST_LINK_ROOT?>/lightbox/js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="<?=$CONST_LINK_ROOT?>/lightbox/js/lightbox.js"></script>
<link rel="stylesheet" href="<?=$CONST_LINK_ROOT?>/lightbox/css/lightbox.css" type="text/css" media="screen" />-->

          <?php



$indx=0;

$i=0;

foreach ($aPictures as $sql_array) {



    $indx++;



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



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



    $pic_info = $sql_array->getInfo('small');
	$pic_Full = $sql_array->getInfo('small');

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

    print(" 




           <!-- <td align='left'><input type=radio name=radDefault $pic_default value=\"$sql_array->pic_id\"></td>



            <td align='left'>$indx</td>
-->


       <!--     <td><input type='file' name='fupload' size='20' disabled class='inputf'><input type='hidden' name='pic_exists[]' value=$sql_array->pic_id></td>



<td><input type='file' name='fupload[]' size='20' disabled class='inputf'></td>-->



            <td align='center'>
			<a href='$CONST_LINK_ROOT/includes$pic_Full->Path' rel='lightbox' title='$sql_array->caption'><img border='0' src='$CONST_LINK_ROOT/includes$pic_info->Path' height='100' width='100s'></a>
			
			
			
			<br>
			<br><a href='$CONST_LINK_ROOT/admin/approve_pictures.php?chkRemove=$sql_array->pic_id&mode=amend&type=p'");?> onclick="javascript:return confirm('Are you sure want to delete')">Delete</a>|
		<? print("
<a href=\"$CONST_LINK_ROOT/admin/approve_pictures.php?appPic=$sql_array->pic_id&type=ap&mode=amend\">Approve</a>
			<input type='hidden' name='pic_exists[]' value=$sql_array->pic_id></td>

			

		



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



           



      ");


$i++;
}


?>

          <tr> 

           <?php /*?> <td  class="tdfoot"><?php



 if ($indx<$CONST_IMAGE_COUNT) print("<input type='button' name='Cancel' value='Add picture' class='button' onClick=\"window.location = 'addpicture.php?PHPSESSID=".session_id()."'\">");



?>&nbsp;</td><?php */?>


		<input type="hidden" name="type" value="p" >


           <!-- <td colspan="2" align='center'  class="tdfoot"><input type="submit" name="Submit" value="<?php echo BUTTON_UPDATE ?>" class="button"></td>-->
 </tr> 
 
 <?php /*?><tr>
 
<? 



$que=mysql_query("select adv_picture,adv_userid from adverts where adv_picture!='templates/default/images/genericm.gif' AND adv_picture!='templates/default/images/genericf.gif' AND adv_imageappr='0'");

$pic=0;
while($app_pic=mysql_fetch_object($que)){
if(($pic%5)==0)
	{
	print "<tr>";
}

?> 
 
            <td  width="100%" align='left' colspan="6">
			<a href='<?=$CONST_LINK_ROOT."/".$app_pic->adv_picture?>' rel='lightbox'><img border='0' src='<?=$CONST_LINK_ROOT."/".$app_pic->adv_picture?>' height='100' width='100s'></a>
			<br>
			<br><a href="<?=$_SERVER['PHP_SELF']?>?delPic=<?=$app_pic->adv_userid?>&mode=amend&type=p" onclick="javascript:return confirm('Are you sure want to delete')">Delete</a>|
	
<a href="<?=$_SERVER['PHP_SELF']?>?appPicture=<?=$app_pic->adv_userid?>&type=ap&mode=amend">Approve</a>
			
			
			</td>

			<?  $pic++; }?>
			</tr><?php */?>
 
 
 </table> </form>


</td>
  </tr>
</table>
</div><div class="admin-page-bottom"></div></div>

<br /><br />
<!--Approved Images Area Starts here-->
<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;<?=APPROVED_PICS?></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 	*
								FROM pictures
								left join members
								ON(pic_userid=mem_userid)
								WHERE approved = '1' AND
								mem_confirm!='0'
								
								ORDER BY pic_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='left'><input type=radio name=radDefault $pic_default value=\"$sql_app->pic_id\"></td>



            <td align='left'>$indx</td>
-->


       <!--     <td><input type='file' name='fupload' size='20' disabled class='inputf'><input type='hidden' name='pic_exists[]' value=$sql_app->pic_id></td>



<td><input type='file' name='fupload[]' size='20' disabled class='inputf'></td>-->



            <td align='center'>
			<a href='$CONST_LINK_ROOT/includes/members/".$sql_app->pic_id.".jpg' rel='lightbox' title='$sql_app->caption'><img border='0' src='$CONST_LINK_ROOT/includes/members/".$sql_app->pic_id."_small.jpg' height='100' width='100s'></a>
			
			
			
			<br>
			<br>");?> <? if($DEMO==false){?><a href='<?=$CONST_LINK_ROOT?>/admin/approve_pictures.php?chkRemove=<?=$sql_app->pic_id?>&mode=amend&type=p'  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++;
}


?>

          <tr> 

           <?php /*?> <td  class="tdfoot"><?php



 if ($indx<$CONST_IMAGE_COUNT) print("<input type='button' name='Cancel' value='Add picture' class='button' onClick=\"window.location = 'addpicture.php?PHPSESSID=".session_id()."'\">");



?>&nbsp;</td><?php */?>


		<input type="hidden" name="type" value="p" >


           <!-- <td colspan="2" align='center'  class="tdfoot"><input type="submit" name="Submit" value="<?php echo BUTTON_UPDATE ?>" class="button"></td>-->
 </tr> 
 
 <?php /*?><tr>
 
<? 
$que=mysql_query("select adv_picture,adv_userid from adverts where adv_picture!='templates/default/images/genericm.gif' AND adv_picture!='templates/default/images/genericf.gif' AND adv_imageappr='0'");

$pic=0;
while($app_pic=mysql_fetch_object($que)){
if(($pic%5)==0)
	{
	print "<tr>";
}

?> 
 
            <td  width="100%" align='left' colspan="6">
			<a href='<?=$CONST_LINK_ROOT."/".$app_pic->adv_picture?>' rel='lightbox'><img border='0' src='<?=$CONST_LINK_ROOT."/".$app_pic->adv_picture?>' height='100' width='100s'></a>
			<br>
			<br><a href="<?=$_SERVER['PHP_SELF']?>?delPic=<?=$app_pic->adv_userid?>&mode=amend&type=p" onclick="javascript:return confirm('Are you sure want to delete')">Delete</a>|
	
<a href="<?=$_SERVER['PHP_SELF']?>?appPicture=<?=$app_pic->adv_userid?>&type=ap&mode=amend">Approve</a>
			
			
			</td>

			<?  $pic++; }?>
			</tr><?php */?>
 

 </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"); ?>

