<?php
include("includes/site_info.php");
include('session_handler.inc');

$WUserID = $_SESSION['Sess_UserId'];
$WUsername = $_SESSION['Sess_UserName'];
if ($_REQUEST['gid']) { $gid = $_REQUEST['gid']; }
else { $gid = 0; }
if ($_REQUEST['pid']) { $pid = $_REQUEST['pid']; }
else { $pid = 0; }

$galleryname_query=mysql_query("SELECT Name, cover FROM gallery WHERE mem_id = '$WUserID' and Gallery_ID = '$gid'") or die(mysql_error());
$galleryname_TOTAL = mysql_num_rows($galleryname_query);
if ($galleryname_TOTAL >0) {
	$galleryname=mysql_fetch_object($galleryname_query) or die(mysql_error());
} else {
?>

<div id="top_panel" class="grey_row_back">
  <?php include ("panel_top.php"); ?>
</div>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="white_back_t_xb">
        <tr>
          <td><div class="grey_12 pink_row_back solid_line_separator padding_5">Edit Photo </div></td>
        </tr>
            <tr class="lightgrey_10">
              <td align="center"><a title="Add Album" href="#caddalbum?tab=media" onclick="javascript: callpage(this.href);" rel="subpage_link">Add Album</a> | <a href="#cgalleries?tab=media" onclick="javascript: callpage(this.href);">Back to Galleries</a></td>
            </tr>
        <tr>
          <td align="center"><div class="padding_10">Can't find a photo or album to edit.</div></td>
        </tr>
      </table></td>
  </tr>
</table>
<?php
	die;
}

$galleryitem_query=mysql_query("SELECT * FROM galleryitem WHERE GalleryItem_ID = '$pid' and Gallery_ID = '$gid' limit 1") or die(mysql_error());
$galleryitem_TOTAL = mysql_num_rows($galleryitem_query);
?>
<div id="top_panel" class="grey_row_back">
  <?php include ("panel_top.php"); ?>
</div>
<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#edit_photo").submit(function(){
	 	jQuery('#loading').show();
	 	jQuery('#right_loading_c').show();

	var str = 'Submit=edit_photo&' + jQuery(this).serialize();

   		jQuery.ajax({
   		type: "POST",
   		url: "gallery_submit.php",
   		data: str,
   		success: function(result){
		jQuery('#loading').hide();	
	 	jQuery('#right_loading_c').hide();
		if(result.indexOf("delete") != 1) { 
		var jump = 'galleryphoto.php?tab=media&';
		var hash = '#cgphoto?tab=media&';
		} else {
		var jump = 'gallery.php?tab=media&';
		var hash = '#cgallery?tab=media&';
		}
		location.href=hash+result;
		jQuery.get(jump+result, function(data) {
 		jQuery("#main_content").fadeIn('slow');
 		jQuery('#main_content').html(data);
		});
		}

 });
return false;
    });
});
   </script>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="white_back_t_xb">
        <tr>
          <td><div class="grey_12 pink_row_back solid_line_separator padding_5">Edit Photo from <?=$galleryname->Name?>
            </div></td>
        </tr>
        <?php if ($galleryitem_TOTAL > 0){ ?>
        <tr>
          <td valign="top" width="100%"><div id="sub_content">
            <form id="edit_photo" name="edit_photo" method="post" style="padding:0; margin:0; border:0;">
              <input name="userid" type="hidden" value="<?=$WUserID?>" />
              <input name="gid" type="hidden" value="<?=$gid?>" />
              <input name="pid" type="hidden" value="<?=$pid?>" />
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td><?php 
	while ($gallery = mysql_fetch_object($galleryitem_query) ) {
?>
                       <table width="100%" border="0" cellspacing="0" cellpadding="10">
                        <tr>
                          <td valign="top" align="left" width="100%">
                              <table width="100%" border="0" cellspacing="0" cellpadding="5" class="white_back_t_xb">
                                <tr>
                                  <td valign="top">Album&nbsp;Cover: </td>
                                  <td width="100%" valign="top"><input name="cover" type="radio" value="<?=$gallery->GalleryItem_ID?>" <?php if($gallery->GalleryItem_ID==$galleryname->cover){ echo "checked";}?>/></td>
                                </tr>
                                <tr>
                                  <td valign="top">Move to: </td>
                                  <td valign="top"><select name="move" id="move">
                                      <option value="">- Choose -</option>
                                      <?php
												$glrq=mysql_query("select Gallery_ID, Name FROM gallery where mem_id = '$WUserID' and Gallery_ID != '$gid' order by Name ASC");
												while($glr= mysql_fetch_array($glrq))
												{
												?>
                                      <option value="<?php echo $glr["Gallery_ID"];?>"><?php echo $glr["Name"];?></option>
                                      <?php
												}
												?>
                                    </select>                                  </td>
                                </tr>
                                <tr>
                                  <td valign="top">Description:</td>
                                  <td valign="top"><textarea name="description" id="description" cols="40" rows="4" class="grey_12_xb"><?=$gallery->Description?></textarea></td>
                                </tr>
                                <tr>
                                  <td valign="top">Delete&nbsp;this&nbsp;photo:</td>
                                  <td valign="top"><input type="checkbox" name="delete" id=="delete" value="1" /></td>
                                </tr>
                                <tr>
                                  <td valign="top">&nbsp;</td>
                                  <td valign="top">&nbsp;</td>
                                </tr>
                              </table>                            </td>
                          <td valign="top" align="center"><div style="width:180px;"><img src="<?=$SITE_MAIN_WWW_ROOT?>/members/<?=$WUsername?>/gallery/<?=md5($gallery->GalleryItem_ID)?>_medium.<?=$gallery->ext?>" class="img_b_p3" border="0"></div></td>
                        </tr>
                      </table>
                    <div class="left solid_line"><img src="images/spacer.gif" width="1" height="1" /></div>
                    <?php } ?>                  </td>
                </tr>
                <tr>
                  <td align="center"><input name="save" type="submit" class="button" id="save" value="Save Changes"/>
                    <input name="cancel" type="button" class="button" id="cancel" value="Cancel" onclick="javascript: callpage('#cgphoto?tab=media&gid=<?=$gid?>&pid=<?=$pid?>');"/></td>
                </tr>
                <tr>
                  <td align="center">&nbsp;</td>
                </tr>
              </table>
            </form></div></td>
        </tr>
        <?php } ?>
      </table></td>
  </tr>
</table>
