<?php
$tt_page_info = array(
  'Page_Info' =>   array(
    'Title' =>$mypoll_title,
    'Description' =>'' ,
    'Keyword' => '',
  ),
  'Social_og' => array(
    'Image' => $mypoll_image,
    'Type' => 'website',
    'URL' => $mypoll_pagelink,
  ),
);

require_once('./header.php'); // Include Footer
?>
<section class="py-4">
  <div class="container">
    <div class="col-12 my-3">
      <?php echo getBlockTitle('', 'অনলাইন জরিপ',$site_domain.'opinion-poll/'); ?>
    </div>
    <?php
    if ($my_poll_status == true) {
      ?>
      <div class="row g-4 mb-4">
        <div class="col-lg-8">
          <?php
          // Total votes
          $my_poll_total_votes = $my_poll['PollOptionOneView'] + $my_poll['PollOptionTwoView'] + $my_poll['PollOptionThreeView'];
          // Avoid division by zero
          if ($my_poll_total_votes > 0) {
              $my_poll_p1 = floor(($my_poll['PollOptionOneView'] / $my_poll_total_votes) * 100);
              $my_poll_p2 = floor(($my_poll['PollOptionTwoView'] / $my_poll_total_votes) * 100);
              $my_poll_p3 = floor(($my_poll['PollOptionThreeView'] / $my_poll_total_votes) * 100);
          } else {
              $my_poll_p1 = $my_poll_p2 = $my_poll_p3 = 0;
          }

          $my_poll_link = pollLink($my_poll['PollID']);
          $my_poll_title = htmlentities($my_poll['PollTitle'], ENT_QUOTES, 'utf-8');
          ?>
          <div class="border rounded-2 bg-white p-3 mt-2 mahamudfutureit_poll">
            <div>
              <div class="row">
                <div class="col-10">
                  <span class="mahamudfutureit_poll_date"><?php echo dateTimeShow($my_poll['PollDate']) ?></span>
                </div>
                <div class="col-2 text-end">
                  <span class="mahamudfutureit_poll_download" id="poll_download_<?php echo $my_poll['PollID'] ?>" data-poll-date="<?php echo dateTimeShow($my_poll['PollDate']) ?>"
                                                          data-poll-image="<?php echo  getPollImage($my_poll['PollID']); ?>"
                                                          data-poll-title="<?php echo htmlentities($my_poll['PollTitle'], ENT_QUOTES, 'utf-8'); ?>"
                                                          data-poll-option1="<?php echo htmlentities($my_poll['PollOptionOne'], ENT_QUOTES, 'utf-8'); ?>"
                                                          data-poll-option2="<?php echo htmlentities($my_poll['PollOptionTwo'], ENT_QUOTES, 'utf-8'); ?>"
                                                          data-poll-option3="<?php echo htmlentities($my_poll['PollOptionThree'], ENT_QUOTES, 'utf-8'); ?>"
                                                          data-poll-option1-vote="<?php echo bnNumber($my_poll_p1) ?> %"
                                                          data-poll-option2-vote="<?php echo bnNumber($my_poll_p2) ?> %"
                                                          data-poll-option3-vote="<?php echo bnNumber($my_poll_p3) ?> %"
                                                          data-poll-option1-vote-per="<?php echo $my_poll_p1 ?>%"
                                                          data-poll-option2-vote-per="<?php echo $my_poll_p2 ?>%"
                                                          data-poll-option3-vote-per="<?php echo $my_poll_p3 ?>%"
                                                          data-poll-download="ডাউনলোডঃ <?php echo dateTimeShow(date('Y-m-d H:i:s')); ?>"
                                                          data-poll-total-votes="মোট ভোটদাতাঃ <?php echo bnNumber($my_poll_total_votes) ?> জন"><i class="bi bi-download"></i></span>
                </div>
              </div>
            </div>
            <div class="mahamudfutureit_poll_image mt-2">
              <img class="rounded-2 w-100"  src="<?php echo $advancenews['Poll_DF_Img'] ?>" data-src="<?php echo  getPollImage($my_poll['PollID']); ?>" alt="<?php echo htmlentities($my_poll['PollTitle'], ENT_QUOTES, 'utf-8'); ?>">
            </div>
            <div class="mahamudfutureit_poll_title mt-2">
              <h2 class="news-title-2"><?php echo htmlentities($my_poll['PollTitle'], ENT_QUOTES, 'utf-8'); ?></h2>
            </div>
            <div class="mahamudfutureit_poll_options">
              <div class="mahamudfutureit_poll_options_item rounded-2 collect_vote collect_vote_<?php echo $my_poll['PollID'] ?>" data-poll-id="<?php echo $my_poll['PollID'] ?>" data-poll-option="1">
                <div class="mahamudfutureit_poll_item_info fw-bold">
                  <i class="bi bi-circle tt_poll_selector_<?php echo $my_poll['PollID'] ?>" id="ttpoll_icon_<?php echo $my_poll['PollID'] ?>_1"></i>&nbsp;&nbsp;<?php echo htmlentities($my_poll['PollOptionOne'], ENT_QUOTES, 'utf-8'); ?> <span id="ttpoll_perc_<?php echo $my_poll['PollID'] ?>_1" style="display:none" class="float-end fw-bold">৯৭%</span>
                </div>
                <div class="mahamudfutureit_poll_item_bar" id="ttpoll_opt_<?php echo $my_poll['PollID'] ?>_1" style="width: 0%; display:none"></div>
              </div>
              <div class="mahamudfutureit_poll_options_item rounded-2 collect_vote collect_vote_<?php echo $my_poll['PollID'] ?>" data-poll-id="<?php echo $my_poll['PollID'] ?>" data-poll-option="2">
                <div class="mahamudfutureit_poll_item_info fw-bold">
                  <i class="bi-circle tt_poll_selector_<?php echo $my_poll['PollID'] ?>" id="ttpoll_icon_<?php echo $my_poll['PollID'] ?>_2"></i>&nbsp;&nbsp;<?php echo htmlentities($my_poll['PollOptionTwo'], ENT_QUOTES, 'utf-8'); ?> <span id="ttpoll_perc_<?php echo $my_poll['PollID'] ?>_2" style="display:none" class="float-end fw-bold">৯৭%</span>
                </div>
                <div class="mahamudfutureit_poll_item_bar" id="ttpoll_opt_<?php echo $my_poll['PollID'] ?>_2" style="width: 0%; display:none"></div>
              </div>
              <div class="mahamudfutureit_poll_options_item rounded-2 collect_vote collect_vote_<?php echo $my_poll['PollID'] ?>" data-poll-id="<?php echo $my_poll['PollID'] ?>" data-poll-option="3">
                <div class="mahamudfutureit_poll_item_info fw-bold">
                  <i class="bi bi-circle tt_poll_selector_<?php echo $my_poll['PollID'] ?>" id="ttpoll_icon_<?php echo $my_poll['PollID'] ?>_3"></i>&nbsp;&nbsp;<?php echo htmlentities($my_poll['PollOptionThree'], ENT_QUOTES, 'utf-8'); ?> <span id="ttpoll_perc_<?php echo $my_poll['PollID'] ?>_3" style="display:none" class="float-end fw-bold">৯৭%</span>
                </div>
                <div class="mahamudfutureit_poll_item_bar" id="ttpoll_opt_<?php echo $my_poll['PollID'] ?>_3" style="width: 0%; display:none"></div>
              </div>
            </div>
            <div class="mahamudfutureit_poll_total_voter text-center my-3 fw-bold">
              মোট ভোটদাতাঃ <span id="ttpoll_total_<?php echo $my_poll['PollID'] ?>"><?php echo bnNumber($my_poll['PollOptionOneView']+$my_poll['PollOptionTwoView']+$my_poll['PollOptionThreeView']) ?></span> জন
            </div>
            <div class="text-center mb-2">
              <div class="mahamudfutureit_social_menu  bordered round color ">
                <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $my_poll_link; ?>" target="_blank" class="facebook">
                    <i class="fa-brands fa-facebook-f"></i>
                </a>
                <a href="https://api.whatsapp.com/send?text=<?php echo $my_poll_title . ' ' . $my_poll_link; ?>" target="_blank" class="whatsapp">
                    <i class="fa-brands fa-whatsapp"></i>
                </a>
                <a href="https://www.messenger.com/t/?link=<?php echo $my_poll_link; ?>" target="_blank" class="messenger">
                    <i class="bi bi-messenger"></i>
                </a>
                <a href="https://twitter.com/intent/tweet?url=<?php echo $my_poll_link; ?>&text=<?php echo $my_poll_title; ?>" target="_blank" class="twitter">
                    <i class="fa-brands fa-x-twitter"></i>
                </a>
                <a href="https://www.linkedin.com/shareArticle?mini=true&url=<?php echo $my_poll_link; ?>&title=<?php echo $my_poll_title; ?>" target="_blank" class="linkedin">
                    <i class="fa-brands fa-linkedin-in"></i>
                </a>
              </div>
            </div>
          </div>
        </div>
        <?php
        $poll_ads_1 = showAds($advancenews['SinglePollAds1'], 'off');
        if ($poll_ads_1 != '') {
          ?>
          <div class="col-lg-4">
            <?php echo $poll_ads_1 ?>
          </div>
          <?php
        }
        ?>
      </div>
      <?php
    }
    ?>
    <div class="row g-4" id="news-container">
      <?php
      $all_poll = getPoll(6, 0);
      foreach ($all_poll as $the_poll) {
        // Total votes
        $total_votes = $the_poll['PollOptionOneView'] + $the_poll['PollOptionTwoView'] + $the_poll['PollOptionThreeView'];
        // Avoid division by zero
        if ($total_votes > 0) {
            $p1 = floor(($the_poll['PollOptionOneView'] / $total_votes) * 100);
            $p2 = floor(($the_poll['PollOptionTwoView'] / $total_votes) * 100);
            $p3 = floor(($the_poll['PollOptionThreeView'] / $total_votes) * 100);
        } else {
            $p1 = $p2 = $p3 = 0;
        }

        $poll_link = pollLink($the_poll['PollID']);
        $poll_title = htmlentities($the_poll['PollTitle'], ENT_QUOTES, 'utf-8');
        ?>
        <div class="col-lg-4 col-12">
          <div class="border rounded-2 bg-white p-3 mahamudfutureit_poll">
            <div>
              <div class="row">
                <div class="col-10">
                  <span class="mahamudfutureit_poll_date"><?php echo dateTimeShow($the_poll['PollDate']) ?></span>
                </div>
                <div class="col-2 text-end">
                  <span class="mahamudfutureit_poll_download" id="poll_download_<?php echo $the_poll['PollID'] ?>" data-poll-date="<?php echo dateTimeShow($the_poll['PollDate']) ?>"
                                                          data-poll-image="<?php echo  getPollImage($the_poll['PollID']); ?>"
                                                          data-poll-title="<?php echo htmlentities($the_poll['PollTitle'], ENT_QUOTES, 'utf-8'); ?>"
                                                          data-poll-option1="<?php echo htmlentities($the_poll['PollOptionOne'], ENT_QUOTES, 'utf-8'); ?>"
                                                          data-poll-option2="<?php echo htmlentities($the_poll['PollOptionTwo'], ENT_QUOTES, 'utf-8'); ?>"
                                                          data-poll-option3="<?php echo htmlentities($the_poll['PollOptionThree'], ENT_QUOTES, 'utf-8'); ?>"
                                                          data-poll-option1-vote="<?php echo bnNumber($p1) ?> %"
                                                          data-poll-option2-vote="<?php echo bnNumber($p2) ?> %"
                                                          data-poll-option3-vote="<?php echo bnNumber($p3) ?> %"
                                                          data-poll-option1-vote-per="<?php echo $p1 ?>%"
                                                          data-poll-option2-vote-per="<?php echo $p2 ?>%"
                                                          data-poll-option3-vote-per="<?php echo $p3 ?>%"
                                                          data-poll-download="ডাউনলোডঃ <?php echo dateTimeShow(date('Y-m-d H:i:s')); ?>"
                                                          data-poll-total-votes="মোট ভোটদাতাঃ <?php echo bnNumber($total_votes) ?> জন"><i class="bi bi-download"></i></span>
                </div>
              </div>
            </div>
            <div class="mahamudfutureit_poll_image mt-2">
              <img class="rounded-2 w-100"  src="<?php echo $advancenews['Poll_DF_Img'] ?>" data-src="<?php echo  getPollImage($the_poll['PollID']); ?>" alt="<?php echo htmlentities($the_poll['PollTitle'], ENT_QUOTES, 'utf-8'); ?>">
            </div>
            <div class="mahamudfutureit_poll_title mt-2">
              <h2 class="news-title-2"><?php echo htmlentities($the_poll['PollTitle'], ENT_QUOTES, 'utf-8'); ?></h2>
            </div>
            <div class="mahamudfutureit_poll_options">
              <div class="mahamudfutureit_poll_options_item rounded-2 collect_vote collect_vote_<?php echo $the_poll['PollID'] ?>" data-poll-id="<?php echo $the_poll['PollID'] ?>" data-poll-option="1">
                <div class="mahamudfutureit_poll_item_info fw-bold">
                  <i class="bi bi-circle tt_poll_selector_<?php echo $the_poll['PollID'] ?>" id="ttpoll_icon_<?php echo $the_poll['PollID'] ?>_1"></i>&nbsp;&nbsp;<?php echo htmlentities($the_poll['PollOptionOne'], ENT_QUOTES, 'utf-8'); ?> <span id="ttpoll_perc_<?php echo $the_poll['PollID'] ?>_1" style="display:none" class="float-end fw-bold">৯৭%</span>
                </div>
                <div class="mahamudfutureit_poll_item_bar" id="ttpoll_opt_<?php echo $the_poll['PollID'] ?>_1" style="width: 0%; display:none"></div>
              </div>
              <div class="mahamudfutureit_poll_options_item rounded-2 collect_vote collect_vote_<?php echo $the_poll['PollID'] ?>" data-poll-id="<?php echo $the_poll['PollID'] ?>" data-poll-option="2">
                <div class="mahamudfutureit_poll_item_info fw-bold">
                  <i class="bi-circle tt_poll_selector_<?php echo $the_poll['PollID'] ?>" id="ttpoll_icon_<?php echo $the_poll['PollID'] ?>_2"></i>&nbsp;&nbsp;<?php echo htmlentities($the_poll['PollOptionTwo'], ENT_QUOTES, 'utf-8'); ?> <span id="ttpoll_perc_<?php echo $the_poll['PollID'] ?>_2" style="display:none" class="float-end fw-bold">৯৭%</span>
                </div>
                <div class="mahamudfutureit_poll_item_bar" id="ttpoll_opt_<?php echo $the_poll['PollID'] ?>_2" style="width: 0%; display:none"></div>
              </div>
              <div class="mahamudfutureit_poll_options_item rounded-2 collect_vote collect_vote_<?php echo $the_poll['PollID'] ?>" data-poll-id="<?php echo $the_poll['PollID'] ?>" data-poll-option="3">
                <div class="mahamudfutureit_poll_item_info fw-bold">
                  <i class="bi bi-circle tt_poll_selector_<?php echo $the_poll['PollID'] ?>" id="ttpoll_icon_<?php echo $the_poll['PollID'] ?>_3"></i>&nbsp;&nbsp;<?php echo htmlentities($the_poll['PollOptionThree'], ENT_QUOTES, 'utf-8'); ?> <span id="ttpoll_perc_<?php echo $the_poll['PollID'] ?>_3" style="display:none" class="float-end fw-bold">৯৭%</span>
                </div>
                <div class="mahamudfutureit_poll_item_bar" id="ttpoll_opt_<?php echo $the_poll['PollID'] ?>_3" style="width: 0%; display:none"></div>
              </div>
            </div>
            <div class="mahamudfutureit_poll_total_voter text-center my-3 fw-bold">
              মোট ভোটদাতাঃ <span id="ttpoll_total_<?php echo $the_poll['PollID'] ?>"><?php echo bnNumber($the_poll['PollOptionOneView']+$the_poll['PollOptionTwoView']+$the_poll['PollOptionThreeView']) ?></span> জন
            </div>
            <div class="text-center mb-2">
              <div class="mahamudfutureit_social_menu  bordered round color ">
                <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $poll_link; ?>" target="_blank" class="facebook">
                    <i class="fa-brands fa-facebook-f"></i>
                </a>
                <a href="https://api.whatsapp.com/send?text=<?php echo $poll_title . ' ' . $poll_link; ?>" target="_blank" class="whatsapp">
                    <i class="fa-brands fa-whatsapp"></i>
                </a>
                <a href="https://www.messenger.com/t/?link=<?php echo $poll_link; ?>" target="_blank" class="messenger">
                    <i class="bi bi-messenger"></i>
                </a>
                <a href="https://twitter.com/intent/tweet?url=<?php echo $poll_link; ?>&text=<?php echo $poll_title; ?>" target="_blank" class="twitter">
                    <i class="fa-brands fa-x-twitter"></i>
                </a>
                <a href="https://www.linkedin.com/shareArticle?mini=true&url=<?php echo $poll_link; ?>&title=<?php echo $poll_title; ?>" target="_blank" class="linkedin">
                    <i class="fa-brands fa-linkedin-in"></i>
                </a>
              </div>
            </div>
          </div>
        </div>
        <?php
      }
      ?>
    </div>
    <div class="row mb-2">
         <div id="loader" class="col-md-12 text-center py-3" style="display: none;"><img src="<?php echo $site_domain ?>assets/image/loading-post.gif" style=" height:40px;"></div>
         <div class="col-12 text-center py-3">
             <button class="btn btn-more-details tt-white tt-text" id="load-more-button"> আরো পড়ুন  </button>
         </div>
    </div>
  </div>
</section>
<div class="dPoll bg-white p-2" id="downloadPoll" style="display: none;">
  <div class="p-3 rounded-2 border">
    <div class="row align-items-center">
      <div class="col-7">
        <h4 class="mb-1">অনলাইন জরিপ</h4>
        <h5 class="fw-normal m-0 poll-date"></h5>
      </div>
      <div class="col-5">
        <img class="w-100 " src="<?php echo $advancenews['Website_Logo'] ?>" alt="Poll Image">
      </div>
    </div>
    <div class="py-2 mt-2">
      <img class="w-100 rounded-2 poll-image" src="" alt="Poll Image">
    </div>
    <div class="mt-2">
      <h5 class="poll-title"></h5>
    </div>
    <div class="mahamudfutureit_poll_options">
      <div class="mahamudfutureit_poll_options_item rounded-2">
        <div class="mahamudfutureit_poll_item_info fw-bold">
          <span class="poll-option1-text"></span>
          <span class="float-end fw-bold poll-option1-vote"></span>
        </div>
        <div class="mahamudfutureit_poll_item_bar poll-option1-bar"></div>
      </div>
      <div class="mahamudfutureit_poll_options_item rounded-2">
        <div class="mahamudfutureit_poll_item_info fw-bold">
          <span class="poll-option2-text"></span>
          <span class="float-end fw-bold poll-option2-vote"></span>
        </div>
        <div class="mahamudfutureit_poll_item_bar poll-option2-bar"></div>
      </div>
      <div class="mahamudfutureit_poll_options_item rounded-2">
        <div class="mahamudfutureit_poll_item_info fw-bold">
          <span class="poll-option3-text"></span>
          <span class="float-end fw-bold poll-option3-vote"></span>
        </div>
        <div class="mahamudfutureit_poll_item_bar poll-option3-bar"></div>
      </div>
    </div>
    <div class="text-center mt-3">
      <h4 class="poll-total-votes"></h4>
      <h6 class="poll-download-date"></h6>
    </div>
  </div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
    document.addEventListener('click', function(e) {
        const target = e.target.closest('.collect_vote');
        if (target) {
            const pollId = target.getAttribute('data-poll-id');
            const pollOption = target.getAttribute('data-poll-option');

            fetch('<?php echo $site_domain ?>ajax_master/collect-vote/', {
                method: 'POST',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                body: `poll_id=${encodeURIComponent(pollId)}&poll_option=${encodeURIComponent(pollOption)}`
            })
            .then(res => res.text())
            .then(data => {
                const resultDiv = document.getElementById('XtcC23ts23a');
                if (resultDiv) {
                    resultDiv.innerHTML = data;
                    resultDiv.querySelectorAll("script").forEach(script => {
                        const newScript = document.createElement("script");
                        if (script.src) {
                            newScript.src = script.src;
                            newScript.async = false;
                            document.head.appendChild(newScript);
                        } else {
                            newScript.textContent = script.textContent;
                            document.body.appendChild(newScript);
                        }
                    });
                }
            });
        }
    });
});
</script>
<div id="XtcC23ts23a"></div>
<script>
let page=2;
var data_type="ttpl";
data_id="";
let isLoading=!1;

function loadMoreNews() {
    if (isLoading) {
        return;
    }

    isLoading = true;
    $('#loader').show();

    $.ajax({
        url: '<?php echo $site_domain ?>ajax_master/load-post/',
        type: 'POST',
        data: {
            page: page ,
            data_id : data_id,
            data_type :data_type,

            },
        success: function(data) {
            const newsContainer = $('#news-container');
            newsContainer.append(data);

            page++;
            isLoading = false;
            $('#loader').hide();
            lazyLoadImages();
        },
        error: function(error) {
            isLoading = false;
            $('#loader').hide();
        }
    });
}
$('#load-more-button').click(function() {
    loadMoreNews();
});
</script>
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
<?php
require_once('./footer.php'); // Include Footer
?>
