<?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; }

$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">Add Photos</div></td>
        </tr>
        <tr>
          <td>Can't find an album to edit.</td>
        </tr>
      </table></td>
  </tr>
</table>
<?php
	die;
}

?>
<div id="top_panel" class="grey_row_back">
  <?php include ("panel_top.php"); ?>
</div>
<script type="text/javascript" src="js/json2.js"></script> 
<script type="text/javascript" src="js/jquery.form.js"></script> 
<script type="text/javascript">
jQuery(document).ready(function(){
   	jQuery('#add_photos').ajaxForm({
   	type: "post",
   	url: "gallery_submit.php",
   	data: { Submit: 'add_photos'},
    beforeSubmit: validate,
   	success: function(result){
		jQuery('#loading').hide();	
	 	jQuery('#right_loading_c').hide();
 		jQuery("#msg_content_error").fadeIn('slow');
		result = JSON.parse(result);
		
		if(result.status == '1') { 
			location.href='#ceditgallery?tab=media&'+result.url;
			jQuery.get('editgallery.php?tab=media&'+result.url, function(data) {
 				jQuery("#main_content").fadeIn('slow');
 				jQuery('#main_content').html(data);
			});
		} else {
 			jQuery('#msg_content_error').html('Ops! Error, please try again!');
		
				if (result.error){
				if (jQuery.isArray(result.error)==true){
				jQuery.each(result.error, function(key, value) { 
 					jQuery('#msg_content_error').append('<br>'+value);
				});
				} else {
 					jQuery('#msg_content_error').append('<br>'+result.error);
				}
				}
				if (result.success){
 				jQuery("#msg_content_done").fadeIn('slow');
 				jQuery('#msg_content_done').html('Here is the successful uploaded files!');
				if (jQuery.isArray(result.success)==true){
				jQuery.each(result.success, function(key, value) { 
 					jQuery('#msg_content_done').append('<br>'+value);
				});
				} else {
 					jQuery('#msg_content_done').append('<br>'+result.success);
				}
				}
		}
	}
 });
});
 function validate(formData, jqForm, options) { 
     var file = jQuery('input[type=file]').fieldValue(); 
    var agree = jQuery('input[name=agree]').fieldValue(); 
 
     /* Checking empty input file */
   if (!(file[0] || file[1] || file[2] || file[3] || file[4])) { 
        alert('No file to upload!'); 
        return false; 
    } 
    /* Checking file type */
    var re_text = /\.jpeg|\.jpg|\.gif|\.png|\.JPG|\.GIF|\.PNG/i; 

    for (var i = 0; i < 5; i++) {
	var filename = file[i];
	if (filename!=''){
		if (filename.search(re_text) == -1)
    	{
        	alert(filename + " is not a valid file. Please select a file with JPEG / GIF / PNG  format!"); 
        	return false;
    	}
	}
	}
    /* Checking agree check */
	if ( !agree[0] )
    {
      alert("Please certify the right before uploading!");
      return false;
    }
	 jQuery('#loading').show();
	 jQuery('#right_loading_c').show();
}

   </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 colspan="2"><div class="grey_12 pink_row_back solid_line_separator padding_5">Add Photos -
              <?=$galleryname->Name?>
          </div></td>
        </tr>
        <tr>
          <td valign="top" class="right_side_menu_panel"><div style="width:80px; text-align:right;">
              <ul id="left-small-menu">
                <li><a href="#ceditgallery?tab=media&gid=<?=$gid?>" rel="subpage_link" onclick="javascript: callpage(this.href);">Edit&nbsp;Photos</a></li>
                <li><a href="#caddgphoto?tab=media&gid=<?=$gid?>" rel="subpage_link" class="current" onclick="javascript: callpage(this.href);">Add&nbsp;More</a></li>
                <li><a href="#ceditinfo?tab=media&gid=<?=$gid?>" rel="subpage_link" onclick="javascript: callpage(this.href);">Edit&nbsp;Info</a></li>
				<li><a href="#ceditdelete?tab=media&gid=<?=$gid?>" rel="subpage_link" onclick="javascript: callpage(this.href);">Delete</a></li>
              </ul>
			  </div>
            </td>
          <td valign="top" width="100%"><div id="msg_content_error" style="display:none;"></div><div id="msg_content_done" style="display:none;"></div><div id="sub_content">
            <form method="post" enctype="multipart/form-data" name="add_photos" id="add_photos" style="padding:0; margin:0; border:0;">
              <input name="userid" type="hidden" value="<?=$WUserID?>" />
              <input name="gid" type="hidden" value="<?=$gid?>" />
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td>
                       <table width="100%" border="0" cellspacing="0" cellpadding="10" class="white_back_t_xb">
                        <tr>
                          <td valign="top" align="left" width="100%">
                              <table width="463" border="0" align="center" cellpadding="5" cellspacing="0" class="white_back_t_xb">
                                <tr>
                                  <td width="185" valign="top">Photos:<br />
                                    <span class="red_10">Allowed&nbsp;file&nbsp;format <br />
                                    (JPG,&nbsp;GIF&nbsp;or&nbsp;PNG&nbsp;)<br />
                                    <br />
                                    The file size limit 5 MB.<br />
                                    If your upload does not 
                                    work, <br />
                                    try   uploading a smaller picture.</span></td>
                                  <td width="258" valign="top"><input name="file1" id="file1" type="file" size="30" />
                                    <input name="file2" id="file2"  type="file" size="30" />
                                    <input name="file3" id="file3" type="file" size="30" />
                                    <input name="file4" id="file4" type="file" size="30" />
                                    <input name="file5" id="file5" type="file" size="30" /></td>
                                </tr>
                            </table>                            </td>
                         </tr>
                        <tr>
                          <td valign="top" align="center"><label><input id="agree" name="agree" value="1" type="checkbox" />
I certify and accept responsibility of all the file that I have submitted in <a href="http://www.wowdoyou.com/terms.html">Terms of Use</a>. </label></td>
                        </tr>
                        <tr>
                          <td valign="top" align="left">&nbsp;</td>
                        </tr>
                      </table>
                    <div class="left solid_line"><img src="images/spacer.gif" width="1" height="1" /></div>                   </td>
                </tr>
                <tr>
                  <td align="center"><input name="save" type="submit" class="button" id="save" value="Upload"/>
                    
                    <input name="cancel" type="button" class="button" id="cancel" value="Cancel" onclick="javascript: callpage('#cgallery?tab=media&gid=<?=$gid?>');"/></td>
                </tr>
                <tr>
                  <td align="center">&nbsp;</td>
                </tr>
              </table>
            </form></div></td>
        </tr>
      </table></td>
  </tr>
</table>
