<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__)
    .' is not allowed.' );



/**
 *
 * @package  MediaLibrary
 * @copyright 2021 Andrey Kvasnevskiy-OrdaSoft(akbet@mail.ru); Rob de Cleen(rob@decleen.com);
 * Homepage: https://ordasoft.com
 * @version: 4.6 Free
 * @license GNU General Public license version 2 or later; see LICENSE.txt
 *
 */

$part_link = '';
if ($task == 'search' || $task == 'simplesearch'){
    foreach ($_GET as $key => $value) {
        $part_link .= "&".$key."=".$value;
    }
    $part_link = substr($part_link, 1);
}
if ($task == 'alonecategory'){
    $part_link = $mosConfig_live_site.'/index.php?option=com_medialibrary&task=alonecategory&catid='.$catid
          .'Itemid='. $Itemid;
}
if ($task == 'ownermedias'){
    $other_uid = protectInjectionWithoutQuote('other_uid', '');
    $part_link .= 'task=ownermedias&other_uid='.$other_uid;
}

global $other_uid;

        $user=Jfactory::getUser();
        if(isset($_REQUEST['userId'])){
            if($option != 'com_medialibrary' and $_REQUEST['userId'] == $user->id)
              showTabs();
        }
        else
        {
           // if($option != 'com_medialibrary')
            showTabs();
        }

        // $category->catid = $_REQUEST['catid'];
        if($cat_name!=""){
            $category_url_part = "task=".$cat_name;
        } else{
            $category_url_part = "task=alonecategory&amp;catid=".$catid;
        }

        $session = JFactory::getSession();
        $arr = $session->get("array","default");
        $sort_arr['order_field'] = $params->get('sort_arr_order_field');
        $sort_arr['order_direction'] = $params->get('sort_arr_order_direction');
?>

<noscript>
    Javascript is required to use MediaLibrary 
    <a href="https://ordasoft.com/media-library-joomla-extension">
        Media Library Software for create modern library .
    </a>,
    <a href="https://ordasoft.com/media-library-joomla-extension">
        MediaLibrary create website for rent, sell media files
    </a>
</noscript>


<div  class="ml_search_result_page ml_search_result_list" id="medialibrary" >
<?php positions_ml($params->get('singleuser01'));?>
<?php positions_ml($params->get('singlecategory01')); ?>
<?php positions_ml($params->get('search_mod1')); ?>
    <div class="componentheading<?php echo $params->get( 'pageclass_sfx' ); ?>">
      <?php echo $currentcat->header; ?>
    </div>

<?php 
if($pageNav->total > 0){
  $song_for = trim(protectInjectionWithoutQuote('searchtext')) ;
  $slash = '';
  if(!empty($song_for))$slash = '/';
  positions_ml($params->get('singleuser02'));
  positions_ml($params->get('singlecategory02'));
  positions_ml($params->get('search_mod2'));

  echo "<div class="search_result_title"><h2 class='search_expression'>" .$song_for . "</h2><span>$slash</span><h5>"._MEDIALIBRARY_FOUND." <strong>". $pageNav->total ."</strong> ".
    _MEDIALIBRARY_HEADER_NUMBER."</h5></div>" ;
}
?>

<?php positions_ml($params->get('singleuser03')); ?>
<?php positions_ml($params->get('singlecategory03')); ?>
<?php positions_ml($params->get('search_mod3')); ?>



         <?php
             //}else{
               ?>

                 <div id="gallery" class="galery">
                     <?php $total = count($rows);
                     foreach ($rows as $row) {
                         $link = /*sefRelToAbs(*/'index.php?option=' . $option
                          . '&amp;task=view&amp;tab=getmymediasTab&amp;is_show_data=1&amp;id='
                          . $row->id . '&amp;catid=' . $catid . '&amp;Itemid=' . $Itemid/*)*/;
                         $imageURL = $row->imageURL;
                         ?>
                         <div class="galery__item">
                            <div>
                             <a href="<?php echo sefRelToAbs($link); ?>" >
                             <?php

                             if ($imageURL != '') {
                                    if($imageURL != '' && substr($imageURL,0,4) != "http"){
                                        $imageURL = $mosConfig_live_site . '/'. $imageURL;;
                                    }
                                    echo '<img style="height:'.$medialibrary_configuration['foto'][
                                      'high'].'px; width:'.$medialibrary_configuration['foto']['width']
                                      .'px;" src="' .$imageURL . '" border="0">';
                             } else {
                                    echo '<img  style="height:'.$medialibrary_configuration['foto'][
                                      'high'].'px; width:'.$medialibrary_configuration['foto']['width']
                                      .'px;" src="' . './components/com_medialibrary/images/'
                                      ._MEDIALIBRARY_NO_PICTURE
                                      .'" alt="no-img_eng_big.gif" border="0"  />';
                             }
                             ?>
                             </a>
                            </div>
                             <div class="textmedia">
                             <div class="titlemedia">
                                <a href="<?php echo sefRelToAbs($link); ?>" >
                                  <?php if(strlen($row->title)>10) echo substr($row->title,0,10),'...';
                                  else {
                                      echo $row->title;
                                  }?>
                                </a>
                             </div>

                             <?php
                             if (isset($row->price) && isset($row->priceunit)) {
                             ?>
                             <div class="price"><?php     if ($medialibrary_configuration['price_unit_show'] == '1'){
                                    echo  formatMoney($row->price, true, $medialibrary_configuration[
                                    'price_format']) . ' ' .  $row->priceunit;
                                }
                                else {
                                    echo  $row->priceunit . ' ' . formatMoney($row->price, true,
                                    $medialibrary_configuration['price_format']);
                                } 
                             ?></div> <?php
                              }?>
                             </div>

                         </div>
                     <?php }?>
                 </div>
<?php 
<?php positions_ml($params->get('singleuser03'));?>
<?php positions_ml($params->get('singlecategory04')); ?>


      if ($pageNav !=null && $pageNav->total > $pageNav->limit ) { 
?>

              <div id="ml-paginator-custom" class="pagination-custom">
                  <?php echo $pageNav->getPagesLinks( ); ?>
              </div>

<?php
      }
?>  
<?php positions_ml($params->get('singleuser04'));?>
<?php positions_ml($params->get('singlecategory05')); ?>

    <?php
      positions_ml($params->get('singlecategory10'));
    if ($params->get( 'ownerslist_show')){
        HTML_medialibrary::showOwnersButton();
    }
    positions_ml($params->get('singlecategory11'));
    ?>
        <?php if ($params->get('back_button')!= ''): ?>
            <div style="text-align: center;" class="back_button">
                <?php mosHTML::BackButton ( $params, $hide_js ); ?>
            </div>
        <?php endif ?>

</div>


<style type="text/css">
.galery__item{
/*    width: <?php echo $medialibrary_configuration['foto']['width']+10;?>px;
    height: <?php echo $medialibrary_configuration['foto']['high']+65;?>px;*/
    float:left;
    padding:10px;
    position:relative;
    border:1px solid white;
    margin:5px;
    text-align: center;
}
/* .okno:hover{
    border:1px solid black;
} */
.galery__item img{

    width:<?php echo $medialibrary_configuration['foto']['width'];?>px;
    height: <?php echo $medialibrary_configuration['foto']['high'];?>px;
}
.galery__item .textmedia{
/*    width:<?php echo $medialibrary_configuration['foto']['width'];?>px;
    position:absolute;
    bottom:5px;*/
    max-width: 100%;
}
.galery__item .titlemedia{
    max-height: 50px;
    margin: 10px 0 0;
}

</style>

