<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Reels</title>
		<link rel="stylesheet" href="/rythm/mystyle.css">

    <link rel="stylesheet" href="styles.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
</head>
<body>

<style>
.modal_hidden {
    max-width: 900px;
    margin-left: 600px;
    padding: 30px;
}
.videosize
{
	background-color:lightgray;
	height:650px;
	width:350px;
}

.zoomiconns:hover
{
	 transform: scale(1.1); 
}



</style>
<?php

session_start();

require("connect.php");	

$username = $_SESSION['username'];
 $rolemaster_id = $_SESSION['rolemaster_id'];
$getall = $con->query("SELECT * FROM `posters` WHERE status = '1' order by id desc");
$inc = 0;
while($data = $getall->fetch(PDO::FETCH_ASSOC))
{
	$inc++;
	
	 $now = time();
        $datediff = $now - strtotime($data['created_on']);
        $numofdays = round($datediff / (60 * 60 * 24));

        if ($numofdays == 0) {
            $postdate = 'Today';
        } else {
            $postdate = $numofdays . 'd';
        }
	$post_id=$data['poster_id'];
	//$usernameid=$data['username_id'];
    $postType = $data['post_type'];
    $postImg = $data['postimg'];
    $postVideo = $data['postvideos'];
	if($postType=="video")
	{
		
		$getlikescount=$con->query("SELECT *,sum(likestatus) as  countoflike FROM `posters` WHERE poster_id='$post_id' and status=1");
		$data2 = $getlikescount->fetch(PDO::FETCH_ASSOC);
		
		$getmgscount=$con->query("SELECT *,COUNT(commands) as msgcount FROM `posters_commads` WHERE posterid='$post_id'");
		$data3 = $getmgscount->fetch(PDO::FETCH_ASSOC);
?>
 <input type="hidden" id="postimgvideoid<?php echo $inc;?>" name="postimgvideoid<?php echo $inc;?>" value="<?php echo $data2['id'];?>">
 
  <input type="hidden" id="posterspath<?php echo $inc;?>" name="posterspath<?php echo $inc;?>" value="<?php echo $data2['postimg'];?>">

    <div id="reelsModal" class="modal_hidden">
        <div class="modal-content">
            
            <div class="video-wrapper" style="display:flex;justify-conent:space-between;gap:20px;">
                 
            <video controls class="videosize">
                <source src="<?php echo $postVideo; ?>" type="video/mp4">
                
            </video>
                <div class="video-actions" style="margin-top:237px;">
				   <div class="icon" onclick="toggleLike(<?php echo $inc;?>)">
							<?php
							 if($data2['ownlikessts']==0 && $data2['username_id']==$rolemaster_id)
							 {
							?>
								<img  id="likeIcon_<?php echo $inc; ?>" src="/rythm/assets/likeheart.png" alt="Heart Icon" class="zoomiconns" style="height:25px;width:25px;">
							<?php
							 }
							 else if($data2['ownlikessts']==1 && $data2['username_id']==$rolemaster_id)
							 {
							?>
								<img  id="likeIcon_<?php echo $inc; ?>" src="/rythm/assets/likeredhreat.png" alt="Heart Icon" class="zoomiconns" style="height:25px;width:25px;">

							<?php
							 }
							 else
							 {
							 ?>
							 <img  id="likeIcon_<?php echo $inc; ?>" src="/rythm/assets/likeheart.png" alt="Heart Icon" class="zoomiconns" style="height:25px;width:25px;">
                            <?php
							 }
							 ?>
							</div>
					<br>
					 <label style="font-weight:600;" id="likelbelidd_<?php echo $inc;?>"><?php echo $data2['countoflike'].'likes';?></label><br><br>
					
					<div class="icon" onclick="messagepopup(<?php echo $data2['id'];?>, <?php echo $inc; ?>)">
					<img src="/rythm/assets/speech-bubble.png" alt="Message Icon" style="height:28px;width:28px;" class="zoomiconns">
					</div>
					<br><span style="font-size:18px;margin-left:9px;"><?php echo $data3['msgcount'];?></span><br><br>
					
					
					
<!-----------------------------------------messagePopupContentstart------------------------------------->
	
	
	<div id="popup-container_<?php echo $inc; ?>" class="popup-container" style="display:none;">
	
	        <img src="/rythm/assets/whitcloseicon.png" class="close-button" onclick="messageclosePopup(<?php echo $inc; ?>)">

    <div class="popup-card">
	
	
	       <div style="display:flex;justify-content:space-between;">
		   
		   
	         <div class="messagepopup-img<?php echo $inc; ?>" >
				
				</div>
	    
       		    
				
			<div class="messageofrightsidecontent">
	
                <div style="margin-left:370px;">
							<div class="user-profile" style="margin-left:0px;">
							<img src="/rythm/assets/rsz_logo2.png" alt="User Profile" class="profile-pic">
							<span class="username"><span style="font-weight:600;"><?php echo $data['username'];?></span> . <?php echo $postdate?></span>
							</div>
						<label class="locationname" style="margin-left:60px;"><?php echo $data['location'];?></label><br>
						<label class="mesgmoredott" onclick="showPopup2(<?php echo $inc; ?>)" >. . .</label>
				</div>
                    <hr style="width:72vh;margin-left:50vh;color:lightgray;">
					
					
					<div class="messageddcontent" style="margin-top:-10px;">
								<div class="user-profile1" style="margin-left:49vh;">
								<img src="/rythm/assets/rsz_logo2.png" alt="User Profile" class="profile-pic1">
								
								 <div style="max-width:380px;">
								<label class="username"><font style="font-weight:600;"><?php echo $data['username'];?></font><span style="font-weight:normal;color:blue;">&nbsp;&nbsp;<?php echo $data['posters_caption'];?>  </span></label>
                                 </div>							
								</div><br><br>
							      <label style="color:gray;margin-left:53vh;"><?php echo $postdate;?></label>
								  <br><br>
								  
								  <?php
								  $posteriddddd=$data['id'];
								  
								  $commanderdetails=$con->query("SELECT * FROM `posters_commads` WHERE posterid='$posteriddddd' order by id desc");
								  $popdyid=0;
								  while ($commanddata = $commanderdetails->fetch(PDO::FETCH_ASSOC)) {
									  $popdyid++;
									  
									    $now = time();
										$cmddatediff = $now - strtotime($commanddata['created_on']);
										$cmdnumofdays = round($cmddatediff / (60 * 60 * 24));

										if ($cmdnumofdays == 0) {
											$cmdpostdate = 'Today';
										} else {
											$cmdpostdate = $cmdnumofdays . 'd';
										}
									  
									  $useridddd=$commanddata['commander_id'];//userid
									  $allcommands=$commanddata['commands'];//all commandss
									  
									  $getuserdetails=$con->query("SELECT * FROM `posters` where username_id='$useridddd' and status=1");
									  
									  
									  $alldetails = $getuserdetails->fetch(PDO::FETCH_ASSOC);
									  
									  
									 // echo $alldetails['username'].'sdfghjkkjhgfd';

								  ?>
								  
								  <div style="margin-left:52vh;">
									<div class="user">
								<img src="/rythm/assets/penguin.png" class="profile-pic">
								 <span class="followername"><?php echo $alldetails['username']; ?>&nbsp;&nbsp;<span style="font-weight:400;"><?php echo ucfirst($allcommands); ?></span></span>
								 
								   </div>
								   <div style="display:flex;justify-content:space-flex-start;">
								   <label style="color:gray;margin-left:48px;max-width:380px;"><?php echo $cmdpostdate; ?></label>
								    <?php
								      $cmderid=$alldetails['id'];//cmder id
								  
								  
								   
								   $takecuntlikes=$con->query("SELECT *,sum(likests_cmd) as likcntt FROM `posters_commads` WHERE posterid='$posteriddddd' and id='$commanddata[id]' and likests_cmd!=0 ");
								 
								   $takedata = $takecuntlikes->fetch(PDO::FETCH_ASSOC);
								   
								   ?>
								   <label style="color:gray;margin-left:48px;" id="msgcmdlikelbelidd_<?php echo $popdyid.''.$inc;?>"><?php echo $takedata['likcntt'].'likes';?></label>
								 
								   <div class="icon" onclick="messagereplyfunc(<?php echo $inc;?>,<?php echo $popdyid;?>,<?php echo $data['username_id'];?>,<?php echo $posteriddddd;?>)">
								   <label style="color:gray;margin-left:48px;">Reply</label>
						            </div>
								   </div>
								   
								 <?php
								 if($takedata['likeorno']==0)
								 {
								 ?>
								   <div class="icon" onclick="messtoggleicon(<?php echo $inc;?>,<?php echo $popdyid;?>,<?php echo $commanddata['id'];?>)">
								   
								    <img  id="messgelikeIcon_<?php echo $inc.''.$popdyid;?>" src="/rythm/assets/likeheart.png" alt="Heart Icon" class="zoomiconns" style="height:17px;width:17px;display:flex;margin:-25px 430px;">
	                               </div>
								   
								   <br><br><br>
									
									
								 </div>
								  <?php 
								  }
								  else if($takedata['likeorno']==1)
								  {
									   ?>
									  <div class="icon" onclick="messtoggleicon(<?php echo $inc;?>,<?php echo $popdyid;?>,<?php echo $commanddata['id'];?>)">
								   
								    <img  id="messgelikeIcon_<?php echo $inc.''.$popdyid;?>" src="/rythm/assets/likeredhreat.png" alt="Heart Icon" class="zoomiconns" style="height:17px;width:17px;display:flex;margin:-25px 430px;">
	                               </div>
								   
								   <br><br><br>
									</div>
									
								 <?php
								  }
									  
								 ?>
								 
								 <?php 
								  
	                          
							  }
	

								 ?>
							   </div>
							   
					         <hr style="width:70vh;margin-left:52vh;color:lightgray;">
							 
					<div class="comment-section" onkeyup="typeacommandsecond(<?php echo $inc;?>);" style="width:68vh;margin-left:366px;">
					<textarea type="text" name="bio_<?php echo $inc;?>" class="form-control emoji_act" id="bio_<?php echo $inc;?>" placeholder="Add a Command" onkeyup="count_char(this, 140);"></textarea>
                    <span id="bio_val"></span>
                        <br>
						
                   <label id="postatag<?php echo $inc;?>" style="color:blue;display:none;float:right;" onclick="commandinsert(<?php echo $inc;?>, <?php echo $data['id'];?>,  <?php echo $rolemaster_id;?>);">Post</label>
				
				</div>
				
				
				
					 </div>
					
				</div>	
				



				
        
    </div>
</div>
							
<!------------------------------------------messagePopupContentEnd-------------------------------------->
					
					<div class="icon" onclick="sharePost(<?php echo $inc;?>)">
					<img id="sendicond" src="/rythm/assets/send.png" alt="send Icon" style="height:28px;width:28px;" class="zoomiconns"><br><br><br>
					</div>
					
					
					
					
<!-------------------------------------Share the posts startportion----------------------------------->							


<div id="popup-sharePostcontainer_<?php echo $inc; ?>" class="popup-container" style="display:none;">
	
	      

    <div class="popup-card" style="width:40%;height:70%;">
	
	 <img src="/rythm/assets/blkcolorcross.png" class="close-button" onclick="shareclosePopup(<?php echo $inc; ?>)"  style="height:20px;width:20px;"> 
	
	<h2 style="text-align:center;">Share</h2>
	<hr>
	
	<label style="font-size:20px;font-weight:600;font-style:italic;">To:&nbsp;<input type="text" id="tosendposts<?php echo $inc; ?>" name="tosendposts<?php echo $inc; ?>" class="tosendimpuuuut" placeholder="Search..."/></label>
	<hr>
	
	<br>
	<?php
	$shareedyid=0;
	$sql2 = $con->query("SELECT * FROM `user_master`");

      while ($sharedata = $sql2->fetch(PDO::FETCH_ASSOC)) {
		  $shareedyid++;
	
	?>
	
	<div class="folowersnameee" style="">
	
	
				<div style="display:flex;justify-content:space-between;">
				
				          <div class="user">
								<img src="/rythm/assets/lion.png"  class="profile-pic">
								 <span class="followername"><?php echo ucfirst($sharedata['user_name']); ?>&nbsp;&nbsp;<span style="font-weight:400;"></span>
						   </div>
				
				
					<img id="clickableImage_<?php echo $inc.''.$shareedyid; ?>" src="/rythm/assets/circle.png" onclick="changeImage(<?php echo $shareedyid; ?>, '<?php echo ucfirst($sharedata['user_name']); ?>',<?php echo $sharedata['id']; ?>,<?php echo $inc; ?>)" style="height:30px;width:30px;">           
				</div>
				
				

				
				<style>
				 .folowersnameee {
        overflow-y: auto; /* Add vertical scroll bar */
        max-height: 200px; /* Set maximum height to enable scrolling */
        /* You can adjust the max-height value according to your needs */
    }
									 
									.share-btn {
										background-color: pink;
										color: white;
										border: none;
										padding: 10px 20px;
										text-align: center;
										text-decoration: none;
										display: inline-block;
										font-size: 16px;
										cursor: pointer;
										border-radius: 5px;
										width:100%;
										
									}
									.tosendimpuuuut
									{
										box-shadow: none;
										  outline: none;
										  border: none;
										  padding: 10px; 
									}
							</style>
	      
	</div>
	<?php
	  }
	  ?>
	<br>
	<hr>
	<div id="writesenttopsmess<?php echo $inc; ?>" style="display:none;">
	<input type="text" id="writemgsforpost<?php echo $inc; ?>" name="writemgsforpost<?php echo $inc; ?>" placeholder="write a message..." class="tosendimpuuuut">
	
	</div>
	<br>
	
	<input type="hidden" id="sendterids<?php echo $inc; ?>" name="sendterids<?php echo $inc; ?>" value="">
	
	<button type="button" class="share-btn" id="sharebtnnn_<?php echo $inc; ?>" onclick="sendsumbit(<?php echo $data['id']; ?>,<?php echo $inc; ?>)">Send</button>
	 </div>
</div>

				




							
<!-------------------------------------Share the posts endportion----------------------------------->							
							
							
					
					
					
					
					<br>
					
					 <?php
$saveddata = $con->query("SELECT * FROM `poster_download` WHERE poster_id='$posteriddddd' and downloader_id='$rolemaster_id' and donwload_sts!=0 order by id desc");

if ($saveddata) {
    $getsave_data = $saveddata->fetch(PDO::FETCH_ASSOC);

    if ($getsave_data) {
        // Poster is saved
        if ($getsave_data['donwload_sts'] == 1) {
            echo '<div class="icon" onclick="savedpost(' . $inc . ');">';
            echo '<img id="savebtnicon_' . $inc . '" src="/rythm/assets/savedpost.png" alt="Save Icon" style="height:25px;width:25px;" class="zoomiconns">';
            echo '<div class="save-label">Remove</div>';
            echo '</div>';
        } else {
            // Poster is not saved
            echo '<div class="icon" onclick="savedpost(' . $inc . ');">';
            echo '<img id="savebtnicon_' . $inc . '" src="/rythm/assets/bookmark.png" alt="Save Icon" style="height:25px;width:25px;" class="zoomiconns">';
            echo '<div class="save-label">Save</div>';
            echo '</div>';
        }
    } else {
        // No save data found, poster is not saved
        echo '<div class="icon" onclick="savedpost(' . $inc . ');">';
        echo '<img id="savebtnicon_' . $inc . '" src="/rythm/assets/bookmark.png" alt="Save Icon" style="height:25px;width:25px;" class="zoomiconns">';
        echo '<div class="save-label">Save</div>';
        echo '</div>';
    }
} else {
    // Query failed
    echo 'Query failed: ' . $con->error;
}

?>
					
					<br><br>
					
					
					<label onclick="showPopup()" style="font-weight:600;font-size:20px;">. . .</label>
					
					
					
					
					<br><br><br>
					
					<?php
					$usernameidd=$data['username_id'];
					$getuserprofile=$con->query("SELECT * FROM `user_master` WHERE role_master_id='$usernameidd'");
					$showprofilee = $getuserprofile->fetch(PDO::FETCH_ASSOC);
					
					?>
					<div class="user-profile2">
					<img src="<?php echo $showprofilee['profile_img'];?>" alt="User Profile" class="profile-pic2" style="height:45px;width:45px;border-radius:17px;">
					</div>
                    
                </div>
            </div>
            
            
            <!-- Add more video wrappers as needed -->
        </div>
    </div>
	
	<div class="threedotpopup" id="threedotpopup">

    <div class="threedotpopup-content"><br><br>

       <label style="color:red;font-weight:600;">Report</label>
	   <hr><br>
	   <label id="flloworunfoolow_<?php echo $inc;?>" style="color:red;font-weight:600;" onclick="openfollofunct(<?php echo $inc;?>,);">Unfollow</label>
	   <hr><br>
	   <label>Add to Favorites</label>
	   <hr><br>
	   <label onclick="gotopost();">Go To Post</label>
	   <hr><br>
	   <label>share to ...</label>
	   <hr><br>
	   <label>copy link</label>
	   <hr><br>
	   <label>Embed</label>
	   <hr><br>
	   <label>About This Account</label>
	   <hr><br>
	   <label onclick="closePopup()">Cancel</label>
    </div>
</div>
<?php 
} 
}// This is the correct position for the closing curly brace
?>

    <script src="script.js"></script>
   <div class="footerlabeel" style="margin-left:450px;display:flex;justify-content:space-between;gap:20px;">
            <label class="lableoffooter" style="font-size:18px;">©&nbspAll&nbsprights&nbspreserved&nbsp@2024</label><br>
             <label class="lableoffooter" style="font-size:18px;">
Developed&nbspand&nbspMaintained&nbspby&nbspBluebase&nbspSoftware&nbspServices&nbspPrivate&nbspLimited
</label>
            
            </div>
			<br><br>
</body>
</html>
<script>
    let isLiked = false;

    function toggleLike(dyyid) {
		debugger;
        isLiked = !isLiked;
        var likeIcon = document.getElementById('likeIcon_' + dyyid);
        var postimgvideoid = document.getElementById('postimgvideoid'+dyyid).value; 

        if (isLiked) {
            likeIcon.src = "/rythm/assets/likeredhreat.png";
            likeIcon.style.filter = "brightness(1.2)";
            updateLikeStatus(postimgvideoid, 1,dyyid); // 1 indicates liked
        } else {
            likeIcon.src = "/rythm/assets/likeheart.png";
            likeIcon.style.filter = "brightness(1)";
            updateLikeStatus(postimgvideoid, 0,dyyid); // 0 indicates unliked
        }
    }

    function updateLikeStatus(postId, likeStatus,dyyid) {
	//	debugger;
        $.ajax({
            type: 'POST',
            url: 'updatelikests.php', 
            data: {
                post_id: postId,
                like_status: likeStatus
            },
            success: function (dta) {
				
				console.warn(dta) ;
				
                   document.getElementById('likelbelidd_'+dyyid).innerText = dta;	
               //window.location.href='/rythm/homee.php';				   
                
            },
            error: function (error) {
                
               // console.error(error);
            }
        });
    }
</script>



<script>
// Add this JavaScript for handling the popup
function messagepopup(id, dyn) {

	debugger;
    // Show the popup container
    document.getElementById('popup-container_'+dyn).style.display = 'block';

$.ajax({
    type: 'POST',
    url: 'messagecontent.php',
    data: {
        post_id: id
    },
    dataType: 'json', // Specify JSON dataType

    success: function (response) {
        var messagePopupContent = document.querySelector('.messagepopup-img'+dyn);

        if (!messagePopupContent) {
            console.error('Error: .messagepopup-img element not found.');
            return;
        }

        messagePopupContent.innerHTML = '';

        if (response.postType === 'image') {
            var imgElement = document.createElement('img');
            imgElement.src = response.content;
            imgElement.style.width = '340px';
            imgElement.style.height = '100.3%';
            imgElement.style.position = 'absolute'; // or 'absolute'
            imgElement.style.top = '-1px';
            imgElement.style.left = '0px';
			
            messagePopupContent.appendChild(imgElement);
			
        } else if (response.postType === 'video') {
            console.log('Video URL:', response.content);

            var videoElement = document.createElement('video');
            videoElement.width = '380';
            videoElement.height = '120%';  // Set the same height percentage as the image
            videoElement.controls = true;

            var sourceElement = document.createElement('source');
            sourceElement.src = response.content;
            sourceElement.type = 'video/mp4';

            videoElement.appendChild(sourceElement);

            // Apply the same styles as the image element
            videoElement.style.width = '340px';
            videoElement.style.height = '100.3%';
            videoElement.style.position = 'absolute'; // or 'absolute'
            videoElement.style.top = '-1px';
            videoElement.style.left = '0px';
			videoElement.style.background='black';

            // Check if the video tag is appended to the parent element
            if (messagePopupContent.appendChild(videoElement)) {
                console.log('Video tag appended successfully.');
            } else {
                console.error('Error appending video tag to .messagepopup-img.');
            }
        } else {
            console.error('Invalid post type:', response.postType);
        }
    },
    error: function (error) {
        console.error(error);
    }
});


	
	
    centerPopup(dyn);
}

function messageclosePopup(dyn) {
    // Close the popup container
    document.getElementById('popup-container_'+dyn).style.display = 'none';
}

function centerPopup(dyn) {
    // Center the popup on the screen
    var popupContainer = document.getElementById('popup-container_'+dyn);
    var screenWidth = window.innerWidth;
    var screenHeight = window.innerHeight;

    var popupWidth = popupContainer.offsetWidth;
    var popupHeight = popupContainer.offsetHeight;

    var leftPosition = (screenWidth - popupWidth) / 2;
    var topPosition = (screenHeight - popupHeight) / 2;

    popupContainer.style.left = leftPosition + 'px';
    popupContainer.style.top = topPosition + 'px';
}

// Call centerPopup() on window resize to recenter the popup
window.addEventListener('resize', centerPopup);
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  <script src="https://rawgit.com/mervick/emojionearea/master/dist/emojionearea.js"></script>
  <script>
   $(document).ready(function() {
      $(".emoji_act").emojioneArea({
        emojiPlaceholder: ":smile_cat:",
        searchPlaceholder: "Search",
        buttonTitle: "Use your TAB key to insert emoji faster",
        searchPosition: "bottom",
        pickerPosition: "bottom"
      });
    });
	</script>
	
	<script>
    function showPopup2(dyiddddd) {
	//	debugger;
		var messag=document.getElementById('popup-container_'+dyiddddd);
		messag.style.display='none';
        var popup = document.getElementById('threedotpopup');
        popup.style.display = 'flex';
    }

    function closePopup2() {
        var popup = document.getElementById('threedotpopup');
        popup.style.display = 'none';
    }
	 
</script>


<script>
function messagereplyfunc(dynmicid,popdynmicid,commderid,posterid)
{
	//debugger;
	$.ajax({
            type: 'POST',
            url: 'getcommdername.php', 
            data: {
                post_id: posterid,
                //like_status: commderid,
				commder_id:commderid
            },
            success: function (response) {
				
				console.warn(response) ;
                  //document.getElementById('msgcmdlikelbelidd_'+cmdlikeid + '' +dynmid).innerText = response;	
               //window.location.href='/rythm/homee.php';				   
                
            },
            error: function (error) {
                
               // console.error(error);
            }
        });
}
</script>
<script>
  let isLiked2 = false;
  
function messtoggleicon(dynmid, cmdlikeid,cmdersid)
{
	//debugger;
	isLiked2 = !isLiked2;
        var likeIcon = document.getElementById('messgelikeIcon_' + dynmid + '' +cmdlikeid);
        var postimgvideoid = document.getElementById('postimgvideoid'+dynmid).value; 

        if (isLiked2) {
            likeIcon.src = "/rythm/assets/likeredhreat.png";
            likeIcon.style.filter = "brightness(1.2)";
            updateLikeStatusforcmds(postimgvideoid, 1,cmdersid,cmdlikeid,dynmid); // 1 indicates liked
        } else {
            likeIcon.src = "/rythm/assets/likeheart.png";
            likeIcon.style.filter = "brightness(1)";
            updateLikeStatusforcmds(postimgvideoid, 0,cmdersid,cmdlikeid,dynmid); // 1 indicates liked
        }
	
	
}

 function updateLikeStatusforcmds(postId,likeStatus,cmderrid,cmdlikeid,dynmid) {
		//debugger;
        $.ajax({
            type: 'POST',
            url: 'updatelikestsforcmnders.php', 
            data: {
                post_id: postId,
                like_status: likeStatus,
				commder_id:cmderrid
            },
            success: function (response) {
				
				console.warn(response) ;
				
                  document.getElementById('msgcmdlikelbelidd_'+cmdlikeid + '' +dynmid).innerText = response;	
                  
               //window.location.href='/rythm/homee.php';				   
                
            },
            error: function (error) {
                
               // console.error(error);
            }
        });
    }
	
function typeacommandsecond(dyid)
{
	$("#postatag"+dyid).slideDown();
}

function typeacommand(dyid)
{
	//debugger;
	$("#postatag_"+dyid).show();
}


function commandinsert(dyid, posterid, commanderid) {
	debugger;
    var textareaval = $('#bio_' + dyid).val();
    var alldataval = posterid + "**" + commanderid + "**" + textareaval;

    $.ajax({
        type: "POST",
        url: "/rythm/commandsinsert.php",
        data: { alldata: alldataval },
        success: function(data) {
			
			if(data==1)
			{
				window.location.href="/rythm/homee.php";
				
				
			}
			
        }
    });
}
</script>
<script>

function sharePost(dyn)
{
	 document.getElementById('popup-sharePostcontainer_'+dyn).style.display = 'block';
}
function shareclosePopup(dyn)
{
	document.getElementById('popup-sharePostcontainer_'+dyn).style.display = 'none';
}
</script>

<script>
function sendsumbit(posterid, dynamicid) {
    //debugger;
    var writesenttopsmess = $('#writemgsforpost' + dynamicid).val();
    var sendterids = document.getElementById('sendterids' + dynamicid).value;

   // console.log('posterid:', posterid);
    //console.log('dynamicid:', dynamicid);
    //console.log('writesenttopsmess:', writesenttopsmess);
    //console.log('sendterids:', sendterids);

    $.ajax({
        type: 'POST',
        url: '/rythm/messagesendandpost.php',
        data: {
            post_id: posterid,
            tosenderid: sendterids,
            messagecontent: writesenttopsmess
        },
        success: function (response) {
			if(response==1)
			{
				alert('send!');
				window.location.href='/rythm/homee.php';
			}
			else
			{
				alert('not send!');
				window.location.href='/rythm/homee.php';
			}
		
            console.warn(response);
            // Handle success
        },
        error: function (error) {
            // Handle error
            console.error(error);
        }
    });
}


</script>
<script>
var selectedSharers = []; // Initialize an array to store selected sharers

var selectssharesidd=[];

function changeImage(sharedynn, sharername, id, dyn) {
    //debugger;
    var clickableImage = document.getElementById('clickableImage_' + dyn + '' +sharedynn);
    var shareBtn = document.getElementById('sharebtnnn_' + dyn);
    var tosendposts = document.getElementById('tosendposts' + dyn);
	var writesenttopsmess=document.getElementById('writesenttopsmess'+dyn);
	
	var sendterids=document.getElementById('sendterids'+dyn);

    // Check the current source of the image
    if (clickableImage.src.includes('circle.png')) {
        // Change to the tickmark image
        clickableImage.src = '/rythm/assets/check.png';
        clickableImage.style.height = '30px';
        clickableImage.style.width = '30px';
     
      
        selectedSharers.push(sharername);//namepush
		selectssharesidd.push(id);//idpush
    } else {
        // Change back to the circle image
        clickableImage.src = '/rythm/assets/circle.png';
        
        // Remove the sharername from the selectedSharers array
        var index = selectedSharers.indexOf(sharername);
        if (index !== -1) {
            selectedSharers.splice(index, 1);
			
        }
		var index = selectssharesidd.indexOf(id);
        if (index !== -1) {
            selectssharesidd.splice(index, 1);
			
        }
		
		 
    }

    // Update the input box value with all selected sharers
    tosendposts.value = selectedSharers.join(', ');
	
	sendterids.value = selectssharesidd.join(', ');
	
    tosendposts.style.fontSize = '20px'; // Use camelCase for fontSize
    tosendposts.style.color = 'deeppink';

    // Update the button background color based on selectedSharers length
    shareBtn.style.background = selectedSharers.length > 0 ? 'deeppink' : 'pink';
	
	writesenttopsmess.style.display = selectedSharers.length > 0 ? 'block' : 'none';
	
	
	
}


</script>
<script>
  let saveornot = false;

function savedpost(dynmicccccc) {
	debugger;
    var likeIcon = document.getElementById('savebtnicon_' + dynmicccccc);
    var postimgvideoid = document.getElementById('postimgvideoid' + dynmicccccc).value;
    var posterspath = document.getElementById('posterspath' + dynmicccccc).value;

    // Determine the save status based on the current image displayed
    var saveStatus = (likeIcon.src.includes('savedpost.png')) ? 0 : 1;

    // Update the UI and the save status based on the current save status
    if (saveStatus === 1) {
        likeIcon.src = "/rythm/assets/savedpost.png";
        likeIcon.style.filter = "brightness(1.2)";
    } else {
        likeIcon.src = "/rythm/assets/bookmark.png";
        likeIcon.style.filter = "brightness(1)";
    }

    // Call the function to update the server-side save status
    updateposterssave(postimgvideoid, saveStatus, dynmicccccc, posterspath);
}

function updateposterssave(postId, savests, dynmicccccc, posterspath) {
	debugger;
    $.ajax({
        type: 'POST',
        url: 'updateposters_saved.php',
        data: {
            post_id: postId,
            save_status: savests,
            posters_path: posterspath
        },
        success: function (getdtaa) {
            if (getdtaa == 1) {
                alert('Post saved!..');
            } else {
                alert('Post not saved!..');
            }
            // Redirect to homee.php regardless of success or failure
            window.location.href = 'homee.php';
        },
        error: function (error) {
            console.error(error);
        }
    });
}

</script>