<?php
/*
UserCake Version: 2.0.2
http://usercake.com
*/

require_once("models/config.php");
// Setting session for redirection
$_SESSION['redirect_url'] = "http://homepage.rs" . $_SERVER['REQUEST_URI'];
if (!securePage($_SERVER['PHP_SELF'])){die();}
require_once("models/header.php");
include("main-nav.php");

//Ako nisi ulogovan - begaj odavde :)
if(!isUserLoggedIn()) :
	header("Location: index.php");
	die(); 
endif;
  
    if(isset($_GET['img'])) :
        $image = getSingleImage($_GET['img']);
        //print_r($loggedInUser);
?>

<div class="popup_bg"></div>
<div class="popup_inner">
    <div class="popup_close">X</div>
    <div class="popup_content"></div>
</div>

<section>
    <h2>Glasaj za moju sliku</h2>
    <div class="row_holder_single">
	    <div class="row_image_single">
      	<img src="http://homepage.rs/cchellenic/ccphotos/<?php echo $image['filename']; ?>.jpg" alt="<?php echo $image['display_name']; ?>" />
      </div>
      <div class="row_name_single">
	        <?php echo $image['display_name']; ?>
          <div class="row_votes_single">
            <!--<a class="vote" href="#">Glasaj</a>-->
            <?php if($image['broj']){ echo $image['broj'];} else{echo "0";} ?>
          </div>
	    </div>
      
    </div>
   <!-- <div class="invite_friends">
    		<p>Pozovite svoje prijatelje da glasaju za Vašu fotografiju</p>
        <div class="emails">
            <input type="text" class="email_1" placeholder="Email 1" tabindex="1">        
            <input type="text" class="email_2" placeholder="Email 2" tabindex="3">        
            <input type="text" class="email_3" placeholder="Email 3" tabindex="5">        
            <input type="text" class="email_4" placeholder="Email 4" tabindex="7">        
            <input type="text" class="email_5" placeholder="Email 5" tabindex="9">
        </div>
        <div class="friends">
            <input type="text" class="name_1" placeholder="Prijatelj 1" tabindex="2">
            <input type="text" class="name_2" placeholder="Prijatelj 2" tabindex="4">
            <input type="text" class="name_3" placeholder="Prijatelj 3" tabindex="6">
            <input type="text" class="name_4" placeholder="Prijatelj 4" tabindex="8">
            <input type="text" class="name_5" placeholder="Prijatelj 5" tabindex="10">
        </div>
        <a class="send_invites" href="#">Pošalji pozivnice</a>
    </div>
--> 
</section>
<!--[if IE]>
<script type="text/javascript" language="javascript"> 
  /* <![CDATA[ */
  $(function() {
    var input = document.createElement("input");
      if(('placeholder' in input)==false) { 
      $('[placeholder]').focus(function() {
        var i = $(this);
        if(i.val() == i.attr('placeholder')) {
          i.val('').removeClass('placeholder');
          if(i.hasClass('password')) {
            i.removeClass('password');
            this.type='password';
          }         
        }
      }).blur(function() {
        var i = $(this);    
        if(i.val() == '' || i.val() == i.attr('placeholder')) {
          if(this.type=='password') {
            i.addClass('password');
            this.type='text';
          }
          i.addClass('placeholder').val(i.attr('placeholder'));
        }
      }).blur().parents('form').submit(function() {
        $(this).find('[placeholder]').each(function() {
          var i = $(this);
          if(i.val() == i.attr('placeholder'))
            i.val('');
        })
      });
    }
  });
  /* ]]> */
</script>
<![endif]-->
<script type="text/javascript" language="javascript">
    $('.vote').click(function(){
        $.ajax({
            type : 'POST',
            url : 'https://homepage.rs/cchellenic/ajax_vote.php',
            data : {
                user_ip : '<?php echo $_SERVER['REMOTE_ADDR']; ?>',
                id_user : '<?php echo $loggedInUser->user_id; ?>',
                id_image : '<?php echo $_GET['img']; ?>'
            },
            success : function(returned){
               $('.popup_bg').show();
               $('.popup_inner').show();
               $('.popup_inner').show();
               $('.popup_content').html(returned);
               window.setTimeout("close_popup_reload()",2000);
            }
        });
    });
    
    // invite friends
    $('.send_invites').click(function(){
        $.ajax({
            type : 'POST',
            url : 'ajax_invite_friends.php',
            //cache: false,
            data : {
                additional_data :{
                    from_name : '<?php echo $loggedInUser->displayname; ?>',
                    from : '<?php echo $loggedInUser->email; ?>',
                    url : '<?php echo $_SESSION['redirect_url']; ?>'
                },
                emails :{
                    email_1 : $('.email_1').val(),
                    email_2 : $('.email_2').val(),
                    email_3 : $('.email_3').val(),
                    email_4 : $('.email_4').val(),
                    email_5 : $('.email_5').val()
                },
                names :{
                    name_1 : $('.name_1').val(),
                    name_2 : $('.name_2').val(),
                    name_3 : $('.name_3').val(),
                    name_4 : $('.name_4').val(),
                    name_5 : $('.name_5').val()    
                }
            },
            success : function(returned){
                       $('.popup_bg').show();
                       $('.popup_inner').show();
                       $('.popup_inner').show();
                       $('.popup_content').html(returned);
                       close_popup();
                //window.location.reload();
            }
        });
    });
    
</script>

<?php else : ?>
    <h3>Niste izabrali sliku.</h3>
<?php endif; 
$_SESSION['redirect_url'] = NULL;
?>



<script type="text/javascript" language="javascript">
    function close_popup(){
    // close popup
    $('.popup_close').click(function(){
        $('.popup_bg').hide();
        $('.popup_inner').hide();
    });
    $('.popup_bg').click(function(){
        $(this).hide();
        $('.popup_inner').hide();
    });
}
function close_popup_reload(){
    // close popup
        $('.popup_bg').hide();
        $('.popup_inner').hide();
        location.reload(true);
}
</script>
<?php require_once("models/footer.php"); ?>

