<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
?>
<?php include APPLICATION_PATH .  '/application/modules/Stories/views/scripts/dismiss_message.tpl';?>
<script type="text/javascript">
  function multiDelete()
  {
    return confirm("<?php echo $this->translate("Are you sure you want to delete the selected stories?") ?>");
  }
function selectAll()
{
  var i;
  var multidelete_form = document.getElementById('multidelete_form');
  var inputs = multidelete_form.elements;
  for (i = 1; i < inputs.length - 1; i++) {
    inputs[i].checked = inputs[0].checked;
  }
}
  function killProcess(story_id) {
    (scriptJquery.ajax({
      'format': 'json',
      'url' : '<?php echo $this->url(array('module' => 'stories', 'controller' => 'admin-manage', 'action' => 'kill'), 'default', true) ?>',
      'data' : {
      'format' : 'json',
      'story_id' : story_id
    }
                      ,
                      'onRequest' : function(){
     scriptJquery('input[type=radio]').attr('disabled', true);
  }
  ,
    success : function(responseJSON)
  {
    window.location.reload();
  }
  }
  ));
  }
</script>
<h3>
  <?php echo $this->translate("Manage Stories") ?>
</h3>
<?php $stories_admin = Zend_Registry::isRegistered('stories_admin') ? Zend_Registry::get('stories_admin') : null; ?>
<p>
  <?php echo $this->translate('This page lists all of the stories your users have uploaded on your website. You can use this page to monitor these stories and delete offensive material if necessary. Entering criteria into the filter fields will help you find specific story. Leaving the filter fields blank will show all the stories on your social network.') ?>
</p>
<div class='admin_search'>
  <?php echo $this->formFilter->render($this) ?>
</div>
<?php if(is_countable($this->paginator) &&  engine_count($this->paginator)): ?>
<div class="mb-3">
  <?php echo $this->translate(array('%s story found.', '%s stories found.', $this->paginator->getTotalItemCount()), $this->locale()->toNumber($this->paginator->getTotalItemCount())) ?>
</div>
<form id='multidelete_form' method="post" action="<?php echo $this->url();?>" onSubmit="return multiDelete()">
  <div class="admin_table_form" style="overflow:auto;">
    <table class='admin_table'>
      <thead>
        <tr>
          <th class='admin_table_short'>
            <input onclick='selectAll();' type='checkbox' class='checkbox' />
          </th>
          <th class='admin_table_short'><?php echo $this->translate("ID"); ?>
          </th>
          <th>
            <?php echo $this->translate("Title") ?>
          </th>
          <th>
            <?php echo $this->translate("Type") ?>
          </th>
          <th>
            <?php echo $this->translate("Owner") ?>
          </th>
          <th>
            <?php echo $this->translate("Options") ?>
          </th>
        </tr>
      </thead>
      <tbody>
				<?php if($stories_admin) { ?>
					<?php foreach ($this->paginator as $item): ?>
						<tr>
							<td>
								<input type='checkbox' class='checkbox' name='delete_<?php echo $item->story_id;?>' value='<?php echo $item->story_id ?>' />
							</td>
							<td>
								<?php echo $item->getIdentity() ?>
							</td>
							<td>
								<?php echo !empty($item->title) ? $item->title : '---'; ?>
							</td>
							<td>
								<?php if(empty($item->type)) { ?>
								<?php echo $item->file_id ? "Photo" : "Text"; ?>
								<?php } else { ?>
								<?php echo "Video"; ?>
								<?php } ?>
							</td>
							<td>
								<?php echo $this->htmlLink($item->getHref(), $item->getOwner()); ?>
							</td>
							<td>
								<?php $file = Engine_Api::_()->getItemTable('storage_file')->getFile($item->file_id, ''); ?>
								<?php if(isset($file)) { ?>
								<?php $path = $file->map(); ?>
								<a href="<?php echo $path; ?>" target="_blank">
									<?php echo "View"; ?>
								</a> | 
								<?php }else{
										// for live streaming.
										if (Engine_Api::_()->getDbtable('modules', 'core')->isModuleEnabled('elivestreaming')) {
											$staticUserImage = 'application/modules/User/externals/images/nophoto_user_thumb_profile.png';
											$user = Engine_Api::_()->getItem('user', $item->owner_id);
											$elivehost = Engine_Api::_()->getDbtable('elivehosts', 'elivestreaming')->getHostId(array('story_id' => $item->story_id));
											$userImage = $user->getPhotoUrl() ? $user->getPhotoUrl() : $staticUserImage;
											if($elivehost->elivehost_id){ ?>
												<a href="<?php echo $userImage; ?>" target="_blank"><?php echo "View"; ?></a> |<?php 
											}else{ ?>
												<a href="<?php echo $userImage; ?>" target="_blank"><?php echo "View"; ?></a> | <?php 
											}
										}
									} ?>
								<?php echo $this->htmlLink(array('route' => 'default', 'module' => 'stories', 'controller' => 'admin-manage', 'action' => 'delete', 'id' => $item->story_id),$this->translate("Delete"),array('class' => 'smoothbox')) ?>
							</td>
						</tr>
					<?php endforeach; ?>
				<?php } ?>
      </tbody>
    </table>
  </div>
  <div class='buttons'>
    <button type='submit'>
      <?php echo $this->translate("Delete Selected") ?>
    </button>
  </div>
</form>
<div>
  <?php echo $this->paginationControl($this->paginator); ?>
</div>
<?php else: ?>
<div class="tip">
  <span>
    <?php echo $this->translate("There are no stories uploaded by your members yet.") ?>
  </span>
</div>
<?php endif; ?>
