<?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;
}
if ($task == 'allmedia') {
  $part_link = $mosConfig_live_site.'/index.php?option=com_medialibrary&task=allmedia&catid='.$catid .'Itemid='. $Itemid;
}

global $other_uid;

  $user=Jfactory::getUser();


// $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');
?>
<?php positions_ml($params->get('singleuser01'));?>
<?php positions_ml($params->get('singlecategory01')); ?>
<div id="medialibrary">

    <div class="componentheading<?php echo $params->get( 'pageclass_sfx' ); ?>">
      <?php echo $currentcat->header; ?>
    </div>
<?php positions_ml($params->get('singleuser02'));?>
<?php positions_ml($params->get('singlecategory02'));?>

<noscript>
    Javascript is required to use MediaLibrary 
    <a href="https://ordasoft.com/media-library-joomla-extension">
        Media Library - Media Center Software for create digital media library
    </a>,
    <a href="https://ordasoft.com/media-library-joomla-extension">
        MediaLibrary Software allow you create website with audio, video, game and other product for rent and sell files
    </a>
</noscript>

<div class="ml-row media-tools-container">


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

        <?php
        if(strpos($currentcat->header,_MEDIALIBRARY_LABEL_SEARCH) && count($rows) == 0  ){
        ?>
          <div class="search-block">
                  <?php echo _MEDIALIBRARY_NOTHING_FOUND ; ?>
          </div>
        <?php
          return;
        }

        if($params->get('show_search')){
        ?>
          <div class="search-block ml-collumn-lg-12 ml-collumn-md-12 ml-collumn-sm-12 ml-collumn-xs-12">
                <?php

                    if($params->get('search_fieldshow')){
                        echo HTML_medialibrary::displaySimpleSearch();
                    }

                    if($params->get('advsearch_show')){

                        $href=sefRelToAbs(
                          "index.php?option=com_medialibrary&task=show_search&catid=0&Itemid=".$Itemid);
                        echo '<div style="font-size: 16px;line-height: 0.9em;" class="search-button"><a href="'.$href.'">'._MEDIALIBRARY_LABEL_SEARCH.'</a></div>';
                    }
                    $link = sefRelToAbs('index.php?option=com_medialibrary&task=show_search&catid='.
                    $catid. '&Itemid='. $Itemid);
                ?>
       </div>
        <?php
        }
        ?>

<?php
    $total = count($rows);
    if($total > 0) {

      $view_type =$params->get('view_type');
      if(isset($_REQUEST['viewtype'])) {
         $view_type_selected=mosGetParam($_REQUEST, 'viewtype');
         $session =JFactory::getSession();
         $session->set('view_type_selected', $view_type_selected);
      }
      else {
         $session =JFactory::getSession();
         $view_type_selected=$session->get('view_type_selected');
      }

      $is_show_view_type = false;
      //add view type selecting
       if($view_type==2){
         $redirect_url = $_SERVER["REQUEST_URI"];
         $pos = strpos($redirect_url,"viewtype");
         if( $pos !== FALSE ){
          if( strpos($_SERVER["REQUEST_URI"],'=') !== false){
           $redirect_url1 = str_replace("viewtype=1","viewtype=0",$redirect_url);
           $redirect_url2 = str_replace("viewtype=0","viewtype=1",$redirect_url);
          }else if( strpos($_SERVER["REQUEST_URI"],',') !== false)
          {
           $redirect_url1 = str_replace("/viewtype,1","/viewtype,0",$redirect_url);
           $redirect_url2 = str_replace("/viewtype,0","/viewtype,1",$redirect_url);
          }else
          {
           $redirect_url1 = str_replace("/viewtype:1","/viewtype:0",$redirect_url);
           $redirect_url2 = str_replace("/viewtype:0","/viewtype:1",$redirect_url);
          }
         } else {
          if(strpos($_SERVER["REQUEST_URI"],'=') !== false){
           $redirect_url1 = $_SERVER["REQUEST_URI"].'&viewtype=0';
           $redirect_url2 = $_SERVER["REQUEST_URI"].'&viewtype=1';
          }else if( strpos($_SERVER["REQUEST_URI"],',') !== false)
          {
           $redirect_url1 = $_SERVER["REQUEST_URI"].'/viewtype,0';
           $redirect_url2 = $_SERVER["REQUEST_URI"].'/viewtype,1';
          }else
          {
           $redirect_url1 = $_SERVER["REQUEST_URI"].'/viewtype:0';
           $redirect_url2 = $_SERVER["REQUEST_URI"].'/viewtype:1';
          }
         }
         $is_show_view_type = true;
       }

       $sort_arr['order_field'] = $params->get('sort_arr_order_field');
       $sort_arr['order_direction'] = $params->get('sort_arr_order_direction');

                 ?>
<?php positions_ml($params->get('singleuser03'));?>
<?php positions_ml($params->get('singlecategory04')); ?>
                    <div id="ShowOrderBy"  class="order_by ml-collumn-lg-12 ml-collumn-md-12 ml-collumn-sm-12 ml-collumn-xs-12" >

                        <form method="POST" action="<?php
                          echo $_SERVER["REQUEST_URI"];?>" name="orderForm">

                        <input type="hidden" id="order_direction" name="order_direction" value="<?php
                          echo $sort_arr['order_direction']; ?>" >
                        <a title="Click to sort by this column."
                          onclick="ml_allreordering();return false;" href="#">
                          <img alt="" src="<?php
                            echo $mosConfig_live_site; ?>/components/com_medialibrary/images/sort_<?php
                           if(isset($sort_arr['order_direction']))
                              echo $sort_arr['order_direction'];
                            else
                              echo "asc"; ?>.png"></a>
                          <?php echo _MEDIALIBRARY_LABEL_ORDER_BY;?> <select size="1" class="inputbox"
                           onchange="javascript:document.orderForm.order_direction.value='asc';
                            document.orderForm.submit();" id="order_field" name="order_field">
                          <option  value="date" <?php if($sort_arr['order_field'] == "release_date")
                            echo 'selected="selected"'; ?> >  <?php echo _MEDIALIBRARY_RELEASE_DATA;
                            ?> </option>
                          <option value="price" <?php if($sort_arr['order_field'] == "price")
                            echo 'selected="selected"'; ?> > <?php
                            echo _MEDIALIBRARY_LABEL_PRICE; ?></option>
                          <option value="title" <?php if($sort_arr['order_field'] == "title")
                            echo 'selected="selected"'; ?> > <?php
                            echo _MEDIALIBRARY_LABEL_TITLE; ?></option>
                          <?php if($params->get('media_type') == 'book' ) { ?>
                            <option value="people_name" <?php
                              if($sort_arr['order_field'] == "people_name")
                                echo 'selected="selected"'; ?> > <?php
                                echo _MEDIALIBRARY_SHOW_SEARCH_FOR_AVTORS; ?></option>
                          <?php } ?>
                          <?php if($params->get('media_type') == 'music' ) { ?>
                            <option value="people_name" <?php
                              if($sort_arr['order_field'] == "people_name")
                                echo 'selected="selected"'; ?> > <?php
                                echo _MEDIALIBRARY_SHOW_SEARCH_FOR_ARTIST; ?></option>
                          <?php } ?>
                          <?php if($params->get('media_type') == 'game' ||
                                   $params->get('media_type') == 'video' ) { ?>
                            <option value="people_name" <?php
                              if($sort_arr['order_field'] == "people_name")
                                echo 'selected="selected"'; ?> > <?php
                                echo _MEDIALIBRARY_SHOW_SEARCH_FOR_STUDIO; ?></option>
                          <?php } ?>
                          </select>
                        </form>

                        </div>

</div>

<?php positions_ml($params->get('singleuser04'));?>
<?php positions_ml($params->get('singlecategory05')); ?>
<?php
                   if($view_type==0||($view_type==2 && ($view_type_selected==0 ||
                      !isset($view_type_selected)))){
?>



                 <div id="gallery">
                     <?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>
                             </div>
                         </div>
                     <?php }?>
                 </div>
             <?php }?>

  

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

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

            <?php
            }
            ?>

    
    <?php
     } //if($total > 0) {
    if ( $is_exist_sub_categories ){
    ?>


<?php positions_ml($params->get('singlecategory07')); ?>
        <div class="componentheading<?php echo $params->get( 'pageclass_sfx' ); ?>">
             <?php echo _MEDIALIBRARY_LABEL_FETCHED_SUBCATEGORIES . " : " 
              . $params->get( 'category_name' ); ?>
        </div>
<?php positions_ml($params->get('singlecategory08')); ?>
    <?php
      HTML_medialibrary::listCategories($params, $categories, $catid, $tabclass , $currentcat);
    }
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>


