<?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
 *
 */

if (!defined('DS'))
    define('DS', DIRECTORY_SEPARATOR);
//require_once ($mosConfig_absolute_path . "/libraries/joomla/plugin/helper.php");
jimport( 'joomla.plugin.helper' );
jimport('joomla.html.toolbar');
require_once ($mosConfig_absolute_path . "/components/com_medialibrary/medialibrary.php");
//require_once ($mosConfig_absolute_path . "/administrator/components/com_medialibrary/menubar_ext.php");
jimport('joomla.html.toolbar');
$mosConfig_live_site = JURI::root(true); //for 1.6
$GLOBALS['$mosConfig_live_site'] = $mosConfig_live_site;
$GLOBALS['$mosConfig_absolute_path'] = $mosConfig_absolute_path; //for 1.6
// for J 1.6
$mainframe = JFactory::getApplication();
$GLOBALS['mainframe'] = $mainframe;
$templateDir = JPATH_THEMES . DS . JFactory::getApplication()->getTemplate() . DS;
$GLOBALS['templateDir'] = $templateDir;
$doc = JFactory::getDocument();
$GLOBALS['doc'] = $doc;

$doc->addScript(JURI::root(true) . '/components/com_medialibrary/includes/jQuerMedia.js');
$doc->addScript(JURI::base(true) .'/components/com_medialibrary/includes/jQuerMedia-ui.js');
$doc->addStyleSheet(JURI::root(true) . '/components/com_medialibrary/includes/jQuerMedia-ui.css');

$doc->addStyleSheet($mosConfig_live_site . '/components/com_medialibrary/includes/font-awesome.css');
$doc->addStyleSheet($mosConfig_live_site . '/components/com_medialibrary/includes/medialibrary.css');

// --
/* $pageNav = new JPagination( $total, $limitstart, $limit );
  $g_item_count = 0; */
class HTML_medialibrary {



    static function showLendRequest(&$medias, &$currentcat, &$params, &$tabclass, &$catid, 
                    &$sub_categories, $is_exist_sub_categories, $category) {
        HTML_medialibrary::displayMedias($medias, $currentcat, $params, $tabclass, $catid, 
                $sub_categories, $is_exist_sub_categories, $category);
    }



    static function displayMedias($rows, $currentcat, &$params, $tabclass, $catid, $categories, 
            $is_exist_sub_categories, $pageNav, $cat_name = "", $layout = 'list', $category='', $task='') {
              
        global $limit, $total, $limitstart, $paginations, $mainframe, 
            $medialibrary_configuration, $database;
        global $doc, $hide_js, $Itemid, $mosConfig_live_site, $mosConfig_absolute_path, $option, $doc;
        $title_tabs = $currentcat->header;
        if($title_tabs == "my medias"){

            showTabs();
        }


        //print_r($rows);exit;
        //if (!empty($rows))
        $layout_menu = "resultsearch";
// alonecategory
// print_r($layout_menu);exit;
      if ($params->get($layout_menu, '') != '') {

            $layout = $params->get($layout_menu, '');
      } 
      /*elseif ($_REQUEST['task'] == 'search' && $_REQUEST['view'] == 'alonecategory') {
                if ($params->get($_REQUEST['view'], '') != '') {
                $layout = $params->get($_REQUEST['view'], '');
        } else {
                $layout = $medialibrary_configuration['view_type_single'];
        }
        } */
      elseif ($params->get($layout_menu, '') == '') {
              $query = "SELECT params FROM #__menu WHERE path LIKE 'single%category'";
                $database->setQuery($query);

                $paramsLayuot = $database->loadResult();
                $object_params = json_decode($paramsLayuot);
                if ($object_params && !empty($object_params->alonecategory)) {
                    $layout = $object_params->alonecategory;
                } elseif (!empty($medialibrary_configuration['view_type_single'])) {
                    $layout = $medialibrary_configuration['view_type_single'];
                }
        } else {
            $layout;
        }
        if ($layout == '' ){
            $layout = $params->get('alonecategory');
        }

      
        //echo __FILE__.":  ".__LINE__,"<br />";
        //echo "qwerty11<pre>";
        //var_dump($task); echo "<br />";
        // print_r($layout);
       // echo "qwerty11111111</pre>";exit;
       //var_dump($task); exit;
        if ($task == 'search') $type = 'resultsearch';
        elseif ($task == 'allmedia') $type = $task;
        else $type = 'alonecategory';

        // print_r(getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout));exit;


        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);

        $doc->addScript($mosConfig_live_site . '/components/com_medialibrary/includes/functions.js');
        if ($task == "search"){
          ?>
          <!-- <a class="kc_own" href="<?php echo sefRelToAbs(
              "index.php?option=com_medialibrary&task=show_search_media&Itemid=" . $Itemid); ?>"  >
              <i class="fa fa-user"></i>
          </a> -->
          <!--img src='<?php //echo JURI::base(true) 
          ?>/components/com_medialibrary/images/dm_accept_32.png' align='middle'  border='0' 
          alt='Go back' /-->
          <br />
          <?php
        }
    }

    static function displayMediasVideo($rows, $currentcat, &$params, $tabclass, $catid, $categories, 
        $is_exist_sub_categories, &$pageNav = null, $type = "", $layout = 'allvideo', $category) {
        global $limit, $total, $limitstart, $task, $paginations, $mainframe, $medialibrary_configuration;
        global $doc, $hide_js, $Itemid, $mosConfig_live_site, $mosConfig_absolute_path, $option, $doc;
        //require($mosConfig_absolute_path."/components/com_medialibrary/views/allvideo/tmpl/"
        //.$layout.".php");
        //$type = 'allvideo';
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
        $doc->addScript($mosConfig_live_site . '/components/com_medialibrary/includes/functions.js');
    }

    static function displayMediasMusic($rows, $currentcat, &$params, $tabclass, $catid, $categories, 
            $is_exist_sub_categories, &$pageNav = null, $type = "allmusic", $layout = 'list', $category) {
        global $limit, $total, $limitstart, $task, $paginations, $mainframe, $medialibrary_configuration;
        global $doc, $hide_js, $Itemid, $mosConfig_live_site, $mosConfig_absolute_path, $option, $doc;
        //require($mosConfig_absolute_path."/components/com_medialibrary/views/allmusic/tmpl/"
        // .$layout.".php");
        //$type = 'allmusic';
        
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
        $doc->addScript($mosConfig_live_site . '/components/com_medialibrary/includes/functions.js');
    }

    static function displayMediasGame($rows, $currentcat, &$params, $tabclass, $catid, $categories, 
            $is_exist_sub_categories, &$pageNav = null, $cat_name = "", $layout = 'list', $category) {
        global $limit, $total, $limitstart, $task, $paginations, $mainframe, $medialibrary_configuration;
        global $doc, $hide_js, $Itemid, $mosConfig_live_site, $mosConfig_absolute_path, $option, $doc;
        //require($mosConfig_absolute_path."/components/com_medialibrary/views/allgame/tmpl/"
        // .$layout.".php");
        $type = 'allgame';
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
        $doc->addScript($mosConfig_live_site . '/components/com_medialibrary/includes/functions.js');
    }

    static function displayMediasBook($rows, $currentcat, &$params, $tabclass, $catid, $categories, 
            $is_exist_sub_categories, &$pageNav = null, $cat_name = "", $layout = '', $category) {
        global $limit, $total, $limitstart, $task, $paginations, $mainframe, $medialibrary_configuration;
        global $doc, $hide_js, $Itemid, $mosConfig_live_site, $mosConfig_absolute_path, $option, $doc;
        // require($mosConfig_absolute_path."/components/com_medialibrary/views/allbook/tmpl/"
        // .$layout.".php");
        $type = 'allbook';
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
        $doc->addScript($mosConfig_live_site . '/components/com_medialibrary/includes/functions.js');
    }

    static function displayMediasPrint($rows, $currentcat, &$params, $tabclass, $catid, $categories, 
            $is_exist_sub_categories, &$pageNav = null) {
        global $hide_js, $Itemid, $mosConfig_live_site, $mosConfig_absolute_path, $doc;
        global $limit, $total, $limitstart, $task, $paginations, $mainframe, $medialibrary_configuration;
        $session = JFactory::getSession();
        $arr = $session->get("array", "default");
        ?>
        <div class="componentheading<?php echo $params->get('pageclass_sfx'); ?>">
            <table class="basictable">
                <tr>
                    <td>
        <?php 
        if (/* !$params->get('wrongitemid') */
                1) {
            echo $currentcat->header;
        } else {
            $parametrs = $mainframe->getParams();
            echo $parametrs->_registry['_default']['data']->page_title;
        }
        ?>
                    </td>
                    <td align="right">
                    <?php
                    if (version_compare(JVERSION, "1.6.0", "lt")) {
                        ?>
                            <a href="#" onclick="window.print();return false;">
                                <img src="<?php 
                                    echo $mosConfig_live_site; ?>/images/M_images/printButton.png" 
                                    alt="Print"  />
                            </a>
                            <?php
                        } else if (version_compare(JVERSION, "1.6.0", "ge")) {
                            ?>
                            <a href="#" onclick="window.print();return false;">
                                <img src="<?php 
                                    echo $mosConfig_live_site; ?>/media/system/images/printButton.png"
                                    alt="Print"  /></a>
                        <?php
                    } else {
                        echo "Sanity test. Error version check!";
                        exit;
                    } 
                    ?>
                    </td>
                </tr>
            </table>
        </div>


        <div id="list">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="basictable">
                <tr>
                    <td height="20" 
                        class="sectiontableheader<?php echo $params->get('pageclass_sfx'); ?>">
                    <?php echo _MEDIALIBRARY_LABEL_COVER; ?>
                    </td>
                    <td height="20" 
                        class="sectiontableheader<?php echo $params->get('pageclass_sfx'); ?>">
                        <?php echo _MEDIALIBRARY_LABEL_TITLE; ?>
                    </td>
                    <td height="20" 
                        class="sectiontableheader<?php echo $params->get('pageclass_sfx'); ?>">
                    <?php echo _MEDIALIBRARY_LABEL_MEDIA_TYPE; ?>
                    </td>
                    <?php
                    if ($catid != 0) {
                        ?>
                        <td height="20" 
                            class="sectiontableheader<?php echo $params->get('pageclass_sfx'); ?>">
                    <?php echo _MEDIALIBRARY_CATEGORIES_NAME; ?>
                        </td>
                    <?php
                }
                ?>
        <?php
        if ($params->get('show_rating')) {
            ?>
                        <td height="20" 
                            class="sectiontableheader<?php echo $params->get('pageclass_sfx'); ?>">
                            <?php echo _MEDIALIBRARY_LABEL_RATING; ?>
                        </td>
                            <?php
                        }
                        if ($params->get('hits')) {
                            ?>
                        <td width="30" height="20" 
                            class="sectiontableheader<?php echo $params->get('pageclass_sfx'); ?>" 
                            align="right">
                            <?php echo _MEDIALIBRARY_LABEL_HITS; ?>
                        </td>
                            <?php
                        }
                        if ($params->get('show_lendstatus')) {
                            ?>
                        <td height="20" 
                            class="sectiontableheader<?php echo $params->get('pageclass_sfx'); ?>">
                            <?php echo _MEDIALIBRARY_LABEL_LEND_CB; ?>
                        </td>
                            <?php
                        }
                        ?>
                </tr>
        <?php
        $available = false;
        $k = 0;
        foreach ($rows as $row) {
            $link = 'index.php?option=com_medialibrary&amp;task=view&amp;id=' . $row->id 
            . '&amp;catid=' . $catid . '&amp;Itemid=' . $Itemid; //
            ?>
                    <tr class="<?php echo $tabclass[$k]; ?>" >
                        <td style="padding-left:5px; padding-top:5px; padding-right:10px;">
                            <?php
                            $book = $row;
                            //for local images
                            $imageURL = $book->imageURL;
                            if ($imageURL != '' && substr($imageURL, 0, 4) != "http") {
                                $imageURL = $mosConfig_live_site . '/' . $book->imageURL;
                                ;
                            }
                            if ($imageURL != '') {
                                echo '<img height="'.$medialibrary_configuration['foto']['high']
                                    .'" width="'.$medialibrary_configuration['foto']['width'].'" src="';
                                echo $imageURL;
                                echo '" alt="cover" border="0" height="50" />&nbsp;';
                            } else {
                                echo '<img height="'.$medialibrary_configuration['foto']['high'].'"
                                  width="'.$medialibrary_configuration['foto']['width'].'"  src="' . $mosConfig_live_site 
                                    . '/components/com_medialibrary/images/';
                                echo _MEDIALIBRARY_NO_PICTURE;
                                echo '" alt="no-img_eng.png" border="0" />&nbsp;';
                            }
                            ?>
                        </td>
                        <td  width="45%">
                            <a href="<?php echo sefRelToAbs($link); ?>" class="category<?php 
                                echo $params->get('pageclass_sfx'); ?>">
                        <?php echo $row->title; ?>
                            </a>
                            <!--<?php
            if ($params->get('item_description')) {
                            ?>
                                    <br />
                            <?php echo $row->description; ?>
                            <?php
                        }
                        ?>-->
                        </td>
                        <td  width="10%">
                        <?php echo $row->media_type; ?>
                        </td>
                            <?php
                            if ($catid != 0) {
                                ?>
                            <td  width="10%">
                                <?php echo $row->category; ?>
                            </td>
                                <?php
                            }
                            ?>
                            <?php
                            if ($params->get('show_rating')) {
                                //if($row->rating == 0 && $row->rating2 != 0)  
                                    //$row->rating = $row->rating2;
                                ?>
                            <td align="right">
                                <img src="<?php echo JURI::root(); 
                                ?>/components/com_medialibrary/images/rating-<?php 
                                    echo $row->rating; ?>.gif" 
                                alt="<?php echo ($row->rating) / 2; ?>" 
                                align="left" border="0" />&nbsp;&nbsp;
                            </td>
                        <?php
                    }
                    if ($params->get('hits')) {
                        ?>
                            <td align="left">
                <?php echo $row->hits; ?>
                            </td>
                <?php
            }
            if ($params->get('show_lendstatus') && $params->get('show_lendrequest')) {
                $data1 = JFactory::getDBO();
                $query = "SELECT  b.lend_from , b.lend_until  FROM #__medialibrary_lend  AS b 
                        LEFT JOIN #__medialibrary AS c ON b.fk_mediaid = c.id 
                        WHERE  c.id=" . $row->id . " AND c.published='1' 
                            AND c.approved='1' AND b.lend_return IS NULL";
                $data1->setQuery($query);
                $lends1 = $data1->loadObjectList();
                ?>
                            <td align="center">
                <?php
                if (count($lends1) == 0) {
                    echo "<img src='" . $mosConfig_live_site 
                        ."/components/com_medialibrary/images/available.png' alt='Available' "
                        ."name='image' border='0' align='middle' />";
                } else {
                    echo _MEDIALIBRARY_LABEL_LEND_FROM_UNTIL . "<br />";
                    for ($a = 0; $a < count($lends1); $a++) {
                        $from_until = substr($lends1[$a]->lend_from, 0, 10) . "&nbsp;/&nbsp;" 
                            . substr($lends1[$a]->lend_until, 0, 10) . "\n";
                        print_r($from_until);
                    }
                }
                ?>
                                <br>
                            </td>
                <?php }
            ?>
                    </tr>
            <?php
            $k = 1 - $k;
        }
        ?>
                <tr><td colspan="6" align="center">&nbsp;</td></tr>
            </table>
        </div>
                            <?php
                           exit;
                        }
    
  static function displayPeoplesPrint($all_authors, &$pageNav = null, &$params, $layout, $list_str, 
        $typeshow_filter, $currentcat, $category, $catid) {
    global $hide_js, $mainframe, $Itemid, $medialibrary_configuration, $mosConfig_live_site, 
        $mosConfig_absolute_path, $my, $doc, $option;
    JPluginHelper::importPlugin('content');
    $dispatcher = JDispatcher::getInstance();
    echo '<!DOCTYPE html> <html> <head>';
    echo '<link rel="stylesheet" href="'.$mosConfig_live_site 
        . '/templates/protostar/css/template.css" type="text/css" />';
    echo '<link rel="stylesheet" href="'.$mosConfig_live_site 
        . '/components/com_medialibrary/includes/medialibrary.css" type="text/css" />';
    echo '</head><body>';
            ?>
        <!--<div class="componentheading<?php echo $params->get('pageclass_sfx'); ?>">-->
            <table class="basictable">
                <tr>
                    <td>
        <?php
        if (!$params->get('wrongitemid')) {
            echo $currentcat->header;
        } else {
            $parametrs = $mainframe->getParams();
            echo $parametrs->_registry['_default']['data']->page_title;
        }
        ?>
                    </td>
                    <td align="right"><?php
        if (version_compare(JVERSION, "1.6.0", "lt")) {
            ?>
                <a href="#" onclick="window.print();return false;">
                    <img src="<?php 
                        echo $mosConfig_live_site; ?>/images/M_images/printButton.png" 
                        alt="Print"  />
                </a>
                <?php
            } else if (version_compare(JVERSION, "1.6.0", "ge")) {
                ?>
                <a href="#" onclick="window.print();return false;">
                    <img src="<?php 
                    echo $mosConfig_live_site; ?>/media/system/images/printButton.png" 
                    alt="Print"  />
                </a>
                <?php
            } else {
                echo "Sanity test. Error version check!";
                exit;
            }
            ?>
                    </td>
                </tr>
            </table>
        

        
        <?php

        global $mosConfig_absolute_path;
        
        $layout = 'photolayout';
        if ($layout == '') $layout = "default";
        $type = 'allpeople';
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
        ?>

        <table width="100%" cellpadding="4" cellspacing="0" border="0" align="center" 
            class="contentpane<?php echo $params->get('pageclass_sfx'); ?>" class="basictable">

            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
        </table>
        <?php
        exit();      
  }
static function displayPeoplePrint($authors, &$params, $rows, $author_description, $books_titles, 
        $currentcat, $catid) { 
    global $hide_js, $mainframe, $Itemid, $medialibrary_configuration, $mosConfig_live_site, 
        $mosConfig_absolute_path, $my, $doc, $option;
    JPluginHelper::importPlugin('content');
    $dispatcher = JDispatcher::getInstance();
    echo '<!DOCTYPE html> <html> <head>';
    echo '<link rel="stylesheet" href="'.$mosConfig_live_site 
        . '/templates/protostar/css/template.css" type="text/css" />';
    echo '<link rel="stylesheet" href="'.$mosConfig_live_site 
        . '/components/com_medialibrary/includes/medialibrary.css" type="text/css" />';
    echo '</head><body>';
            ?>
        <!--<div class="componentheading<?php echo $params->get('pageclass_sfx'); ?>">-->
            <table class="basictable">
                <tr>
                    <td>
        <?php
        if (!$params->get('wrongitemid')) {
            echo $currentcat->header;
        } else {
            $parametrs = $mainframe->getParams();
            echo $parametrs->_registry['_default']['data']->page_title;
        }
        ?>
                    </td>
                    <td align="right"><?php
        if (version_compare(JVERSION, "1.6.0", "lt")) {
            ?>
            <a href="#" onclick="window.print();return false;"><img src="<?php 
                echo $mosConfig_live_site; ?>/images/M_images/printButton.png" alt="Print"  /></a>
                <?php
            } else if (version_compare(JVERSION, "1.6.0", "ge")) {
                ?>
                <a href="#" onclick="window.print();return false;"><img src="<?php 
                echo $mosConfig_live_site; ?>/media/system/images/printButton.png" alt="Print"  /></a>
                <?php
            } else {
                echo "Sanity test. Error version check!";
                exit;
            }
            ?>
                    </td>
                </tr>
            </table>
        

        
        <?php

        global $mosConfig_absolute_path;
        $layout = "default";
        $type = 'view_people';
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
            
         ?>

        <table width="100%" cellpadding="4" cellspacing="0" border="0" align="center" 
            class="contentpane<?php echo $params->get('pageclass_sfx'); ?>" class="basictable">

            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
        </table>
        <?php
        exit();      
  }

  static function displayPeople(&$authors, $params, $rows, $author_description,$books_titles, 
            $currentcat) {
        global $mosConfig_absolute_path;
        $layout = "default";
        $type = 'view_people';
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
    }
  static function displayPeoples($all_authors, $pageNav, $params, $layout, $list_str, $typeshow_filter, 
      $currentcat, $category) {
        global $mosConfig_absolute_path;
        if ($layout == '') $layout = "default";
        $type = 'allpeople';
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
    }


    
    static function displaySimpleSearch($align = 'right') {
        global $doc, $Itemid, $mosConfig_live_site, $task;
        ?>
        <form id="adminForm" name="simlesearchform" action="<?php 
            echo sefRelToAbs("index.php?option=com_medialibrary&task=search&Itemid=" 
                . $Itemid); ?>"  method="get">
            <div style="text-align: <?php echo $align; ?>">
                <input type="text" name="searchtext" value="" />
                <!--input type="submit" value="<?php echo _MEDIALIBRARY_SHOW_SEARCH; ?>"-->
                <a class="ck_search" href="javascript:document.simlesearchform.submit();" >
                    <i class="fa fa-search"></i>
                    <!--img src="<?php //echo $mosConfig_live_site; 
                    ?>/components/com_medialibrary/images/search.gif" alt="Search" title="Search" /-->
                </a>
                <input type="hidden" name="option" value="com_medialibrary">
                <input type="hidden" name="task" value="search">
                <?php
                
                if ($task == ''){
                    $task = protectInjectionWithoutQuote('view', '');
                }
                if ($task == 'allbook'){?>
                  <input type="hidden" name="book" value="on">
                <?php 
                } else if ($task == 'allgame'){?>
                  <input type="hidden" name="game" value="on">
                <?php 
                } else if ($task == 'allvideo'){?>
                  <input type="hidden" name="video" value="on">
                <?php 
                } else if ($task == 'allmusic'){?>
                  <input type="hidden" name="music" value="on">
                <?php 
                }?>
                <input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>">
        <input type="hidden" name="view" value="<?php
                            if (!isset($_REQUEST['view'])){
                                echo $task;
                            } else {
                                echo $_REQUEST['view'];
                            }

                             ?>">
                <input type="hidden" name="searchtype" value="simplesearch">
            </div>
        </form>
        <?php
    }

    //----------------------------------------------------------
   static function displayMediaBook(&$media, &$media_type_class, &$params,$option='true',
        $currentcat='true',$cat='true', $layout = 'default', $id, $catid,$videos, $audios, $tracks) {
        
        global $hide_js, $medialibrary_configuration, $mosConfig_live_site, $Itemid, $doc, 
            $mosConfig_absolute_path;
        //require($mosConfig_absolute_path
        //."/components/com_medialibrary/views/displaybook/tmpl/".$layout.".php");
        $type = 'displaybook';
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
    }

    //----------------------------------------------------------
    static function displayMediaVideo(&$media, &$media_type_class, &$params,$option='true',
            $currentcat='true', $cat='true', $layout = 'default',$id,$catid,$videos, $audios, $tracks) {
        global $hide_js, $medialibrary_configuration, $mosConfig_live_site, $Itemid, $doc, 
            $mosConfig_absolute_path;
        //require($mosConfig_absolute_path
            //."/components/com_medialibrary/views/displayvideo/tmpl/".$layout.".php");
        $type = 'displayvideo';
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
    }

    //----------------------------------------------------------
    static function displayMediaMusic(&$media, &$media_type_class, &$params,$option='true',
        $currentcat='true', $cat='true', $layout = 'default', $id, $catid,$videos, $audios, $tracks) {
        global $hide_js, $medialibrary_configuration, $mosConfig_live_site, $Itemid, $doc, 
            $mosConfig_absolute_path;
        //require($mosConfig_absolute_path
            //."/components/com_medialibrary/views/displaymusic/tmpl/".$layout.".php");
        $type = 'displaymusic';
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
    }

    //----------------------------------------------------------
    static function displayMediaGame(&$media, &$media_type_class, &$params,$option='true',
        $currentcat='true', $cat='true', $layout = 'default', $id, $catid,$videos, $audios, $tracks) {
        global $hide_js, $medialibrary_configuration, $mosConfig_live_site, $Itemid, $doc, 
            $mosConfig_absolute_path;
        //require($mosConfig_absolute_path
            //."/components/com_medialibrary/views/displaygame/tmpl/".$layout.".php");
        $type = 'displaygame';
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
    }

    /**
     * Displays the media
     * Lend Status
     */
    static function displayMedia(&$media, &$media_type_class, &$tabclass, &$params, &$currentcat, $cat, 
            $id, $catid, $videos, $audios, $tracks, $layout) {
        if ($media->published == 0){
         echo "<script> alert('This media is unpublished. Publish first to view');
                window.history.go(-1); </script>\n";
        exit();
        }

        global $hide_js, $mainframe, $Itemid, $medialibrary_configuration, $mosConfig_live_site, 
            $mosConfig_absolute_path, $my, $option, $doc;
        $doc->addScript($mosConfig_live_site . '/components/com_medialibrary/includes/functions.js');
        // for 1.6
        ?>

        <?php
        switch ($media->media_type) {
            case 'book':
                HTML_medialibrary::displayMediaBook($media, $media_type_class, $params,$option,
                    $currentcat, $cat, $layout, $id, $catid, $videos, $audios, $tracks);
                break;
            case 'video':
                HTML_medialibrary::displayMediaVideo($media, $media_type_class, $params,$option,
                    $currentcat, $cat, $layout, $id, $catid, $videos, $audios, $tracks);
                break;
            case 'music':
                HTML_medialibrary::displayMediaMusic($media, $media_type_class, $params,$option,
                    $currentcat, $cat, $layout, $id, $catid, $videos, $audios, $tracks);
                break;
            case 'game':
                HTML_medialibrary::displayMediaGame($media, $media_type_class, $params,$option,
                    $currentcat, $cat, $layout, $id, $catid, $videos, $audios, $tracks);
                break;
        }
        ?>

            <?php
        }

        /**
         * Display links to categories
         */
        static function showCategories(&$params, &$categories, &$catid, &$tabclass, &$currentcat, 
                $layout = 'default') {
            global $doc; // for 1.6
            global $hide_js, $Itemid, $acl, $mosConfig_live_site, $my, $mainframe, 
                $mosConfig_absolute_path, $option;
            $doc->addStyleSheet($mosConfig_live_site 
                . '/components/com_medialibrary/includes/medialibrary.css');
            //require($mosConfig_absolute_path
            //."/components/com_medialibrary/views/allcategories/tmpl/".$layout.".php");
            $type = 'allcategories';

            require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
            ?>

            <?php
        }




                static function listCategories($params, $cat_all, $catid, $tabclass, $currentcat) {
                    global $Itemid, $mosConfig_live_site, $doc;
                    ?>
        <?php positions_ml($params->get('allcategories04')); ?>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="basictable">
            <tr>
                <td class="cat_name" colspan="2" height="40" width="80%" class="sectiontableheader<?php 
                    echo $params->get('pageclass_sfx'); ?>">
                    <?php echo _MEDIALIBRARY_LABEL_MEDIALIBRARY_CATEGORY; ?>
                </td>
                <td height="20" width="10%" class="sectiontableheader<?php 
                    echo $params->get('pageclass_sfx');?>">
                <?php echo _MEDIALIBRARY_LABEL_MEDIA; ?>
                </td>

            </tr>
            <tr>
                <td colspan="4">
        <?php positions_ml($params->get('allcategories05')); ?>
        <?php
        HTML_medialibrary::showInsertSubCategory($catid, $cat_all, $params, $tabclass, $Itemid, 0);
        ?>
                </td>
            </tr>
            <tr>
                <td colspan="3">&nbsp;
                </td>
            </tr>
        </table>
        <?php positions_ml($params->get('allcategories06')); ?>
        <?php
    }

    /*
     * function for show subcategory
     */

    static function showInsertSubCategory($id, $cat_all, $params, $tabclass, $Itemid, $deep) {
        global $g_item_count, $medialibrary_configuration, $mosConfig_live_site, $doc;
        $deep++;
        for ($i = 0; $i < count($cat_all); $i++) {
            if (($id == $cat_all[$i]->parent_id) && ($cat_all[$i]->display == 1)) {
                $g_item_count++;
                // $link = "index.php?option=com_medialibrary&task=alonecategory&catid="
                // .$cat_all[$i]->id."&Itemid=".$Itemid;
                $link = "index.php?option=com_medialibrary&task=alonecategory&catid=" . $cat_all[$i]->id;
                ?>
                <table width="100%" border="0" cellspacing="0" cellpadding="0" class="basictable">
                    <tr class="<?php echo $tabclass[($g_item_count % 2)]; ?>">
                        <td width="1%" nowrap="nowrap">
                <?php
                if ($deep != 1) {
                    echo str_repeat("&nbsp;", $deep * 4) . '&nbsp;|_';
                }
                ?>
                        </td>
                        <td class="images_container" width="9%">
                <?php if (($params->get('show_cat_pic')) && ($cat_all[$i]->image != "")) { ?>
                                <img src="<?php echo $mosConfig_live_site; 
                            ?>/images/stories/<?php echo $cat_all[$i]->image; ?>" 
                                    alt="picture for subcategory" height="48" width="48" />&nbsp;
                    <?php
                } else {
                    ?>
                                <a <?php echo "href=" . sefRelToAbs($link); ?> 
                                    class="category<?php echo $params->get('pageclass_sfx'); ?>" 
                                    style="text-decoration: none">
                                        <img src="<?php echo $mosConfig_live_site;?>/components/com_medialibrary/images/folder.png" 
                                            alt="picture for subcategory" height="48" 
                                            width="48" />
                                </a>&nbsp;
                    <?php }
                ?>
                        </td>
                        <td width="71%">
                            <a href="<?php echo JRoute::_($link, false); ?>" class="category<?php 
                                echo $params->get('pageclass_sfx'); ?>">
                <?php echo $cat_all[$i]->title; ?>
                            </a>
                        </td>
                        <td  align="left" width="10%">
                <?php if ($cat_all[$i]->medias == '')
                    echo "0";
                else
                    echo $cat_all[$i]->medias;
                ?>
                        </td>
                    </tr>
                </table>
                <?php
                if ($medialibrary_configuration['subcategory']['show']) {
                    HTML_medialibrary::showInsertSubCategory($cat_all[$i]->id, $cat_all, $params, 
                        $tabclass, $Itemid, $deep);
                }
            } //end if ($id == $cat_all[$i]->parent_id)
            //        $z = 1 - $z;
        } //end for(...)
    }

//end function showInsertSubCategory($id, $cat_all)

    static function showSearchMedias($params, $currentcat, $clist, $option, $layout = 'default') {
        global $doc, $hide_js, $Itemid, $mainframe, $mosConfig_live_site, $Itemid, 
            $medialibrary_configuration;

        if( checkJavaScriptIncluded("jQuerMedia.js") === false )   {
          $doc->addScript(JURI::root(true) . '/components/com_medialibrary/includes/jQuerMedia.js');
          
        
          $doc->addScript(JURI::base(true) .'/components/com_medialibrary/includes/jQuerMedia-ui.js');
        }                 
        // for J 1.6
        $script_content = '';
        $script_content.= " function trim(string){  return string.replace(/(^\s+)|(\s+$)/g, '');  } \n";
        $script_content.= " function searchsubmit() \n";
        $script_content.= " { \n";
        $script_content.= "   var form = document.com_booklibsearchForm; \n";
        $script_content.= "   var flag = true; \n";
        $script_content.= "//        var t_lprice = trim(document.getElementById('lprice').value); \n";
        $script_content.= "//        var t_uprice = trim(document.getElementById('uprice').value); \n";
        $script_content.= "//        var t_ldate = trim(document.getElementById('ldate').value); \n";
        $script_content.= "//        var t_udate = trim(document.getElementById('udate').value); \n";
        $script_content.= "//        if(!((t_lprice!='' && t_uprice!='') || (t_uprice == t_lprice))) \n";
        $script_content.= "//        { \n";
        $script_content.= "//          alert('If you want search by price - interval must be set') \n";
        $script_content.= "//          flag=false; \n";
        $script_content.= "//        } \n";
        $script_content.= "//        if(!((t_ldate!='' && t_udate!='') || (t_ldate == t_udate))) \n";
        $script_content.= "//        { \n";
        $script_content.= "//     alert('If you want search by release date - interval must be set') \n";
        $script_content.= "//          flag=false; \n";
        $script_content.= "//        } \n";
        $script_content.= "        if(flag) \n";
        $script_content.= "          form.submit(); \n";
        $script_content.= "      } \n";
        $doc->addScriptDeclaration($script_content);
        // --
        
        $type = 'show_search_media';
        require getLayoutPath::getLayoutPathCom('com_medialibrary', $type, $layout);
    }

    static function showLendRequestThanks($params, $currentcat) {
        global $hide_js, $Itemid, $doc, $mosConfig_live_site, $option;
        //$doc->addStyleSheet($mosConfig_live_site
        //.'/administrator/components/com_medialibrary/includes/medialibrary.css');
        $id = $GLOBALS['id_media'];
        ?>
        <div class="componentheading<?php echo $params->get('pageclass_sfx'); ?>">
        <?php echo $currentcat->header; ?>
        </div>
        <div id="noborders" class="ml-component__lend-request-message">

                    <?php
                    if ($currentcat->img != null) {
                        ?>

                            <img src="<?php echo $currentcat->img; ?>" alt="?" />
                          <?php
                      }
                      ?>

                      <p>
                      <?php echo $currentcat->descrip; ?>
                      </p>

                      <div class="ml-component__button-container">
                      <?php if (version_compare(JVERSION, '2.6', 'lt')) { 
                        $link = 'index.php/component/medialibrary/'.$Itemid.'/?task=view&id='.$id;
                        ?>
                      <a class="btn btn-default" href="<?php echo $link;?>" onClick="window.history.go(-2);"><?php 
                        echo _MEDIALIBRARY_LABEL_OK;?></a>
                      <?php 
                      } else { ?>
                      <a class="btn btn-default" href="#" onClick="window.history.go(-2);"><?php echo _MEDIALIBRARY_LABEL_OK;?></a>
                      <?php } ?>
                      </div>


        </div>
            <?php
        }
    
    static function showAddMediaThanks($params, $currentcat) {
        global $hide_js, $Itemid, $doc, $mosConfig_live_site, $option;
        //   $doc->addStyleSheet($mosConfig_live_site
        //.'/administrator/components/com_medialibrary/includes/medialibrary.css');
            ?>
        <div class="componentheading<?php echo $params->get('pageclass_sfx'); ?>">
        <?php echo $currentcat->header; ?>
        </div>
        <table class="basictable">
            <tr>
        <?php
        if ($currentcat->img != null) {
            ?>
                    <td>

                        <img src="<?php echo $currentcat->img; ?>" alt="?" />
                    </td>
            <?php
        }
        ?>
                <td width="100%" class="basictable">
        <?php echo $currentcat->descrip; ?>
                </td>

            </tr>
        </table>
        <form  action="<?php echo JRoute::_("index.php?option=com_medialibrary&Itemid=" 
            . $Itemid, false); ?>" method="post" name="userForm" class="add_media_message">
            <table border="0" cellpadding="4" cellspacing="0" width="100%" class="basictable">
                <tr>
                    <td colspan="2" align="right">&nbsp;
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="submit" name="submit" 
                            value="<?php echo _MEDIALIBRARY_LABEL_OK;?>" class="button" />
                    </td>
                </tr>
            </table>
        </form>
        <?php
    }


      static function showTabs(&$params, &$userid, &$username, &$comprofiler, &$option) {

              //  $option = 'com_medialibrary';
        ?>
                <div class='my_media_tabs' id="medialibrary">
        <?php
               
        if ($params->get('show_cb')) {

            if ($params->get('show_cb_registrationlevel') && (!empty($username))) {?>

                    <span class='media_button'>
                        <a href="<?php echo JRoute::_('index.php?option=' . $option 
                            . '&task=ownermedias&tab=getmymediasTab&name=' . $username . '&user=' 
                            . $userid . '&is_show_data=1' 
                            . '#tabs-4'); ?>"><?php echo _MEDIALIBRARY_LABEL_CBMEDIAS; ?></a>
                    </span>&nbsp;&nbsp;
                                    <?php
                                    //  }
                }
            }
            if ($params->get('show_edit')) {
                if ($params->get('show_edit_registrationlevel') && (!empty($username))) {
                                    ?>
                    <span class='media_button'>
                        <a href="<?php echo JRoute::_('index.php?option=' . $option . '&task=mymedias' 
                            .$comprofiler.'#tabs-4'); ?>"><?php echo _MEDIALIBRARY_LABEL_CBEDIT; ?></a>
                    </span>
                    <?php
                }
            }
            if ($params->get('show_lend')) {
                if ($params->get('show_lend_registrationlevel')) {
                    ?>
                    <span class='media_button'>
                        <a href="<?php echo JRoute::_('index.php?option=' . $option 
                            . '&task=lend_requests' . $comprofiler 
                            . '#tabs-4'); ?>"><?php echo _MEDIALIBRARY_LABEL_CBLEND; ?></a>
                    </span>&nbsp;&nbsp;
                    <?php
                }
            }
            if ($params->get('show_history')) {
                if ($params->get('show_history_registrationlevel')) {
                    ?>
                    <span class='media_button'>
                        <a href="<?php echo JRoute::_('index.php?option=' . $option 
                            . '&task=lend_history&name=' . $username . '&user=' . $userid 
                            .$comprofiler.'#tabs-4');?>"><?php echo _MEDIALIBRARY_LABEL_CBHISTORY;?></a>
                    </span>
                        <?php
                    }
            }
                ?>
        </div>
          <?php                    
  }    


    static function create_search_tr($search_fields) {
        global $doc, $mosConfig_live_site;
        $searchtype = array('game' => _MEDIALIBRARY_LABEL_MEDIA_TYPE_GAME, 
                            'music' => _MEDIALIBRARY_LABEL_MEDIA_TYPE_MUSIC, 
                            'video' => _MEDIALIBRARY_LABEL_MEDIA_TYPE_VIDEO, 
                            'book' => _MEDIALIBRARY_LABEL_MEDIA_TYPE_BOOK);
        ?>
        <div class="basictable">
            <div id='search_boxs' class="ml-row">

                <?php foreach ($search_fields as $search_key => $search_field): ?>
                    <div class="ck_box ml-collumn-xs-6 ml-collumn-sm-3 ml-collumn-md-3 ml-collumn-lg-3">
                            <label for="<?php echo $search_key; ?>"> <?php echo $searchtype[$search_key] ?>:</label>
                            <input type="checkbox" name="<?php echo $search_key; ?>" 
                                id="<?php echo $search_key; ?>" checked="checked" 
                                onClick="if(this.checked) {ml_checkboxs_on('checkboks<?php 
                                    echo $search_key; ?>');} else {ml_checkboxs_off('checkboks<?php 
                                    echo $search_key; ?>');}"/>
                        <ul id='checkboks<?php echo $search_key; ?>'>
                            <?php foreach ($search_field as $search_title => $search_colon): ?>
                                <li class='li'>
                                <?php
                                if (is_numeric($search_title)) {
                                    $field_end = $search_colon;
                                } else {
                                    $field_end = $search_title;
                                } //echo $field_end;
                                echo '<label for="'.$search_key, '-', $field_end.'">'.  $search_colon . '</label>';
                                ?>
                                    <input  type="checkbox" 
                                            name="<?php echo $search_key, '-', $field_end; ?>" 
                                            id="<?php echo $search_key, '-', $field_end; ?>" 
                                            checked="checked" 
                                            onClick="if(this.checked) document.getElementById('<?php 
                                                echo $search_key; ?>').checked = 'true'"/>
                                </li>
                                <?php endforeach; ?>
                        </ul>
                    </div>
                <?php endforeach; ?>

            </div>
        </div>
                <?php
            }




     static function showLendMedias($option, $medias, $rows, $userlist, $type) {
        global $my, $mosConfig_live_site, $mainframe, $doc, $Itemid, $database, 
            $medialibrary_configuration;
            $doc->addScript($mosConfig_live_site . '/components/com_medialibrary/includes/functions.js');
            ?>

        <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
        <form action="index.php" method="get" name="mediaEditForm" >

            <table cellpadding="4" cellspacing="0" class="basictable" width="100%">
                <tr>
                    <td width="100%" class="medialibrary_caption"></td>
                </tr>
                <tr>
                    <td align="left">&nbsp;
                        <td align="center" nowrap="nowrap">
                            <?php echo $userlist; ?>
                        </td>
                    </td>
                </tr>
            </table>
                <?php
                if ($type == "lend" || $type == "edit_lend") {
                    ?>
                <table cellpadding="4" cellspacing="0" class="basictable" width="100%">
                    <tr>
                        <td align="center" nowrap="nowrap">
                    <?php echo _MEDIALIBRARY_LABEL_LEND_TO . ":"; ?>
                        </td>
                        <td align="center" nowrap="nowrap">
                    <?php echo _MEDIALIBRARY_LABEL_LEND_USER . ":"; ?>
                        </td>
                        <td>
                            <input type="text" name="user_name" class="inputbox" 
                                value="<?php echo $my->name; ?>" />
                        </td>
                        <td width="100%">
                        </td>
                    </tr>
                    <tr>
                        <td align="left">&nbsp;
                        </td>
                        <td align="left">&nbsp;
                        </td>
                        <td align="center" nowrap="nowrap">
                    <?php echo _MEDIALIBRARY_LABEL_LEND_EMAIL . ":"; ?>
                        </td>
                        <td>
                            <input type="text" name="user_email" class="inputbox" 
                                    value="<?php echo $my->email; ?>" />
                        </td>
                        <td width="30%">&nbsp;
                        </td>
                    </tr>
                   <script>
                      Date.prototype.toLocaleFormat = function(format) {
                      var f = {Y : this.getYear() + 1900,m : this.getMonth() + 1,d : this.getDate(),
                            H : this.getHours(),M : this.getMinutes(),S : this.getSeconds()}
                            for(k in f)
                            format = format.replace('%' + k, f[k] < 10 ? "0" + f[k] : f[k]);
                            return format;
                      };
                      window.onload = function(){
                      var today = new Date();
                          var date = today.toLocaleFormat("<?php 
                                echo $medialibrary_configuration['date_format'];?>");
                          document.getElementById('lend_from').value = date;
                          document.getElementById('lend_until').value = date;
                    };
                  </script>
                    <tr>
                      <td align="left" nowrap="nowrap">
                        <?php echo _MEDIALIBRARY_LABEL_LEND_FROM . ":"; ?>
                      </td>
                      <td align="left" nowrap="nowrap">
                              <?php echo JHtml::_('calendar', date("Y-m-d"), 'lend_from', 'lend_from', 
                                $medialibrary_configuration['date_format']); ?>
                      </td>
                      <td align="left" nowrap="nowrap">
                        <?php echo _MEDIALIBRARY_LABEL_LEND_UNTIL . ':'; ?>
                      </td>
                      <td align="left" nowrap="nowrap">
                            <?php echo JHtml::_('calendar', date("Y-m-d"), 'lend_until', 'lend_until', 
                                $medialibrary_configuration['date_format']); ?>
                      </td>
                        <td colspan="3">&nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td align="left">&nbsp;
                        </td>
                    </tr>
                </table>

                    <?php } else {
                    ?>
                &nbsp;
                    <?php }
                ?>

            <table cellpadding="4" cellspacing="0" border="0" width="100%"
                   class="adminlist bl_admin_lent-bottom_table my_table">
                <tr>
      <th width="20" align="center">
      <?php if ($type != 'lend') { ?> <?php
            if (version_compare(JVERSION, "2.5.0", "ge")) { ?>
            <input type="checkbox" name="toggle" value="" onClick="Joomla.checkAll( this);" />
                                                        <?php
            } ?>
                 <?php if (version_compare(JVERSION, "2.6.0", "lt")) { ?>
                 <input type="checkbox" name="toggle" value="" onClick="checkAll(<?php 
                    echo count($rows) ?>);" />
                    <?php
            } ?>
        <?php
        } ?> </th>
        <th align = "center" width="30">#</th>
        <th align = "center" class="title" width="5%" nowrap="nowrap">
        <?php echo _MEDIALIBRARY_LABEL_MEDIA_TYPE_ID; ?></th>
        <th align = "center" class="title" width="7%" nowrap="nowrap">
        <?php echo _MEDIALIBRARY_LABEL_MEDIA_TYPE; ?></th>
        <th align = "center" class="title" width="25%" nowrap="nowrap">
        <?php echo _MEDIALIBRARY_LABEL_TITLE; ?></th>
        <th align = "center" class="title" width="15%" nowrap="nowrap">
        <?php echo _MEDIALIBRARY_LABEL_LEND_FROM; ?></th>
        <th align = "center" class="title" width="15%" nowrap="nowrap">
        <?php echo _MEDIALIBRARY_LABEL_LEND_UNTIL; ?></th>
        <th align = "center" class="title" width="15%" nowrap="nowrap">
        <?php echo _MEDIALIBRARY_TOOLBAR_ADMIN_RETURN; ?></th>
        <th align = "center" class="title" width="15%" nowrap="nowrap">
        <?php echo _MEDIALIBRARY_LABEL_LEND_TO; ?></th>
                </tr>
                <tr>
                <?php
        if ($type == "lend") {
?>
      <td align="center">  <input class="inputbox"  type="checkbox"
        name="checkMedia" id="checkMedia" size="0" maxlength="0" value="on"/></td>
                 <?php
        } else if ($type == "edit_lend") { ?>
                  <td align="center">
                    <input type="hidden"  name="checkMedia" id="checkMedia" value="on" />
                  </td>
                 <?php
        }
        $assoc_title = '';
        for ($t = 0, $z = count($rows);$t < $z;$t++) {
            if ($rows[$t]->id != $medias->mainid) $assoc_title.= " " . $rows[$t]->title;
        }
        print_r("
                  <td align=\"center\">" . $medias->id . "</td>
                  <td align=\"center\">" . $medias->mediaid . "</td>
                  <td align=\"center\">" . $medias->media_type . "</td>
                  <td align=\"center\">" . $medias->title . " ( " . $assoc_title . " ) " . "</td>
                  <td align=\"center\">" . " " . "</td>
                  <td align=\"center\">" . " " . "</td>
                  <td align=\"center\">" . " " . "</td>
                  <td align=\"center\">" . " " . "</td>
                  </tr>");

        print_r("<tr>
                  <td align=\"center\">-</td>
                  <td align=\"center\">-</td>
                  <td align=\"center\">-------</td>
                  <td align=\"center\">" . "-----------" . "</td>
                  <td align=\"center\">" . "-----------------" . "</td>
                  <td align=\"center\">" . " -------------" . "</td>
                  <td align=\"center\">" . " ---------" . "</td>
                  <td align=\"center\">" . " ---------------------" . "</td>
                  <td align=\"center\">" . "------------------" . "</td>
                  </tr>");

        for ($j = 0, $n = count($rows);$j < $n;$j++) {
            $row = $rows[$j];
?>
                    <input class="inputbox" type="hidden"  name="mediaid" id="mediaid" size="0"
                           maxlength="0" value="<?php echo $row->mediaid; ?>" />
                    <input class="inputbox"  type="hidden"  name="id" id="id" size="0"
                           maxlength="0" value="<?php echo $row->id; ?>" />
          <input class="inputbox" type="hidden" name="title" id="title" size="0" maxlength="0"
              value="<?php echo $row->title; ?>" />
                    <?php
            $data = JFactory::getDBO();
            $query = "SELECT * FROM #__medialibrary_lend WHERE fk_mediaid =" . $row->id 
                . " ORDER BY lend_return ";
            $data->setQuery($query);
            $alllend = $data->loadObjectList();
            $num = 1;
            for ($i = 0, $n2 = count($alllend);$i < $n2;$i++) {
                if (!isset($alllend[$i]->lend_return) && $type != "lend") {
?>
       <td align="center"><input type="checkbox" id="cb<?php echo $i; ?>"
       name="mid[]" value="<?php echo $alllend[$i]->id; ?>" 
       onClick="Joomla.isChecked(this.checked);" /></td>
                                <?php
                } else {
?>
                                <td align="center"></td>
                                <?php
                }
                print_r("
                <td align=\"center\">" . $num . "</td>
                <td align=\"center\">" . $row->mediaid . "</td>
                <td align=\"center\">" . $row->media_type . "</td>
                <td align=\"center\">" . $row->title . "</td>
                <td align=\"center\">" . $alllend[$i]->lend_from . "</td>
                <td align=\"center\">" . $alllend[$i]->lend_until . "</td>
                <td align=\"center\">" . $alllend[$i]->lend_return . "</td>
                <td align=\"center\">" . $alllend[$i]->user_name . ":  " 
                    . $alllend[$i]->user_email . "</td> </tr>");
                $num++;
            }
?>
        <?php
        } ?>
            </table>

            <input type="hidden" name="option" value="<?php echo $option; ?>" />
            <input type="hidden" id="adminFormTaskInput" name="task" value="" />
            <input type="hidden" name="save" value="1" />
            <input type="hidden" name="boxchecked" value="1" />
        <?php
         if ($option != "com_medialibrary") {
            ?>
                <input type="hidden" name="tab" value="getmymediasTab" />
                <input type="hidden" name="is_show_data" value="1" />
            <?php
        }
        ?>
            <input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />
        <?php if ($type == "lend") { ?>
                <input type="button" name="lend_save" value="<?php 
                    echo _MEDIALIBRARY_LABEL_BUTTON_RENT; ?>" onclick="ml_buttonClickLend(this)"/>
            <?php }
        ?>
        <?php if ($type == "lend_return") { ?>
                <input type="button" name="lendout_save" value="<?php 
                    echo _MEDIALIBRARY_LABEL_BUTTON_RETURN_MEDIA_FROM_RENT; ?>" 
                    onclick="ml_buttonClickLend(this)"/>
            <?php }
        ?>
        </form>
        <?php
    }

    
} //end class
