function display($tpl = null)
 {
     global $mainframe;
     //check permission
     jomtube::checkPermission("acl_addvideo");
     $c = jomtube_configs::get_instance();
     $this->assignRef('c', $c);
     parent::display($tpl);
 }
 function display($tpl = null)
 {
     global $mainframe;
     $c = jomtube_configs::get_instance();
     //check user login
     $user =& JFactory::getUser();
     jomtube::checkPermission("acl_uploadvideo");
     //$this->setModel('video');
     $model = $this->getModel('video');
     $categories = $model->getParentOption();
     $parentOptions[] = JHTML::_('select.option', '', '-Select Parent-');
     foreach ($categories as $category) {
         $category_name = str_repeat(' ', 4 * substr_count($category->family_id, "/")) . "+" . $category->category_name;
         $parentOptions[] = JHTML::_('select.option', $category->id, $category_name);
     }
     $parentSelect = JHTML::_('select.genericlist', $parentOptions, 'category_id', 'class="inputbox" size="1" ', 'value', 'text', '');
     $this->assignRef('c', $c);
     $this->assignRef('parentSelect', $parentSelect);
     parent::display($tpl);
 }
        //echo $newLink3;
        $patterns[0] = '/\\/modules\\//';
        $patterns[1] = '/mod_jomtube_tabs\\//';
        $replacements[0] = '';
        $replacements[1] = '';
        $parsedLink3 = preg_replace($patterns, $replacements, $newLink3);
        ?>
					<div id="video-from-jt-tabs-module">
						<?php 
        echo _VIDEOINFO_AUTHOR;
        ?>
:<span class="video-username-jt-tabs-module"> <a href="<?php 
        echo JURI::BASE() . $newLink3;
        ?>
"><?php 
        echo jomtube::showShortAuthor($item->username);
        ?>
</a></span>
					</div>
					<?php 
    }
    ?>
					<!--## VIDEO HITS COUNTER ##-->
					<?php 
    if ($show_numberviews) {
        ?>
					<div id="video-view-count-jt-tabs-module">
						<?php 
        echo _VIDEOINFO_NUMBER_VIEWS;
        ?>
: <?php 
function aio()
{
    $act = JRequest::getVar('act', '');
    $database =& JFactory::getDBO();
    switch ($act) {
        case 'category':
            $catid = JRequest::getVar('catid', 0);
            $where = ' WHERE v.category_id = ' . $catid;
            break;
        case 'member':
            $user_id = JRequest::getVar('userid', 0);
            $where = ' WHERE v.user_id = ' . $user_id;
            break;
        case 'newest':
            $catid = JRequest::getVar('catid', 0);
            $where = ' ';
            break;
        case 'featured':
            $catid = JRequest::getVar('catid', 0);
            $where = ' WHERE v.featured = 1';
            break;
        default:
            echo "other";
            break;
    }
    //switch
    $select = 'SELECT v.*, c.directory, u.username, c.category_name, u.id as userid ' . ' FROM #__jomtube_videos AS v ' . ' LEFT JOIN #__users AS u ON v.user_id = u.id' . ' JOIN #__jomtube_categories AS c ON c.id = v.category_id';
    $query = $select . $where . ' AND v.published = 1 ORDER BY v.date_added DESC LIMIT 20';
    $count_query = 'SELECT COUNT(*) FROM #__jomtube_videos AS v' . $where;
    $database->setQuery($query);
    $videos = $database->loadObjectList();
    $database->setQuery($count_query);
    $count = $database->loadResult();
    ?>
    <?php 
    foreach ($videos as $video) {
        ?>
						<div class="video-entry">
							<div class="v90WideEntry">
								<div class="v90WrapperOuter">
									<div class="v90WrapperInner">
									<?php 
        if ($video->video_type == 'local' || $video->video_type == '') {
            ?>
					   				<a href="index.php?option=com_jomtube&view=video&id=<?php 
            echo $video->id;
            ?>
" id="video-url-e8FGIveLwyw">
						        	<img alt="<?php 
            echo $video->video_title;
            ?>
" qlicon="e8FGIveLwyw" class="vimg90" src="<?php 
            echo substr(JURI::base(), 0, strlen(JURI::base()) - 24) . $video->directory;
            ?>
/_thumbs/<?php 
            echo $video->video_thumb;
            ?>
" border="0" />
							 		</a>
						 			<?php 
        } else {
            ?>
						   			<a href="index.php?option=com_jomtube&view=video&id=<?php 
            echo $video->id;
            ?>
" id="video-url-e8FGIveLwyw">
						        	<img alt="<?php 
            echo $video->video_title;
            ?>
" qlicon="e8FGIveLwyw" class="vimg90" src="<?php 
            echo $video->video_thumb;
            ?>
" border="0" />
							 		</a>
						 			<?php 
        }
        ?>
										<div class="video-time"><span><?php 
        echo $video->duration;
        ?>
</span>
										</div>
								</div>
							</div>
						</div>
						<div class="video-main-content">
							<div class="video-mini-title"><a href="index.php?option=com_jomtube&view=video&id=<?php 
        echo $video->id;
        ?>
" title="<?php 
        echo $video->video_title;
        ?>
"><?php 
        echo stripslashes($video->video_title);
        ?>
</a>
							</div>
							<div class="video-view-count"><?php 
        echo $video->hits;
        ?>
 <?php 
        echo strtolower(_VIDEOINFO_NUMBER_VIEWS);
        ?>
							</div>
							<div class="video-username"><?php 
        echo _VIDEOINFO_AUTHOR;
        ?>
: <a href="index.php?option=com_jomtube&view=videos&type=member&user_id=<?php 
        echo $video->user_id;
        ?>
"><?php 
        echo jomtube::showShortAuthor($video->username);
        ?>
</a>
	  						</div>
						</div>
					</div>
					<div class="watch-discoverbox-divider"/>
					</div>
					<?php 
    }
    ?>
				  					<?php 
    if ($count > 20) {
        ?>
				  					<center><a href="index.php?option=com_jomtube&view=videos&category_id=<?php 
        echo $catid;
        ?>
">See all <?php 
        echo $count;
        ?>
 videos</a></center>
				  					<?php 
    }
    ?>

<?php 
}
//Require helperfile
require_once JPATH_COMPONENT_SITE . DS . 'helpers' . DS . 'helpers.php';
require_once JPATH_COMPONENT_SITE . DS . 'helpers' . DS . 'toolsHelpers.php';
require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jomtube' . DS . 'helpers' . DS . 'JTubePluginHelper.php';
$document =& JFactory::getDocument();
//$document->addScript("components/com_jomtube/assets/js/mootools-release-1.11.js");
$document->addScript("components/com_jomtube/assets/js/jomtube.js");
$document->addScript("http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js");
//Include JomTube Style
$c = jomtube_configs::get_instance();
$document->addStyleSheet("components/com_jomtube/assets/styles/{$c->jtube_skin}/css/template.css");
//upload progress
//$document->addScript("components/com_jomtube/assets/js/swfobject.js");
require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jomtube' . DS . 'assets' . DS . 'lib' . DS . 'FlashUploader' . DS . 'SolmetraUploader.php';
//check permission
jomtube::checkPermission("acl_component");
// include language file
$lang_file = JPATH_COMPONENT . DS . 'languages' . DS . $c->jtube_language . '.php';
$lang_default_file = JPATH_COMPONENT . DS . 'languages' . DS . 'english.php';
if (file_exists($lang_file)) {
    require_once $lang_file;
} else {
    require_once $lang_default_file;
}
// Create the controller
$classname = 'jomtubeController' . $controller;
$controller = new $classname();
// Perform the Request task
$controller->execute(JRequest::getVar('task'));
// Redirect if set by the controller
$controller->redirect();
function aio()
{
    $act = JRequest::getVar('act', '');
    $numVideos = JRequest::getVar('numVideos', 0);
    $thumbnail_size = JRequest::getVar('thumbnail_size', '');
    $columns_per_row = JRequest::getVar('columns_per_row', '');
    $margin_left_aio = JRequest::getVar('marginleftvid', 0);
    //video description parameters
    $show_videotitle = JRequest::getVar('show_videotitle', 0);
    $show_dateadded = JRequest::getVar('show_dateadded', 0);
    $show_author = JRequest::getVar('show_author', 0);
    $show_numberviews = JRequest::getVar('show_numberviews', 0);
    $show_ratingstar = JRequest::getVar('show_ratingstar', 0);
    $show_videoduration = JRequest::getVar('show_videoduration', 0);
    $database =& JFactory::getDBO();
    $order = '';
    $where = ' WHERE v.published = 1 ';
    switch ($act) {
        case 'lastest':
            $order = 'v.date_added DESC';
            break;
        case 'viewed':
            $order = 'v.hits DESC';
            break;
        case 'rated':
            $order = 'v.votetotal DESC';
            break;
        case 'featured':
            $where .= ' AND v.featured = 1';
            $order = 'v.date_added DESC';
            break;
        default:
            var_dump($act);
            break;
    }
    //switch
    $select = 'SELECT v.*, c.directory, u.username, c.category_name, u.id as userid ' . ' FROM #__jomtube_videos AS v ' . ' LEFT JOIN #__users AS u ON v.user_id = u.id' . ' JOIN #__jomtube_categories AS c ON c.id = v.category_id';
    $query = $select . $where . ' ORDER BY ' . $order . ' LIMIT ' . $numVideos;
    $count_query = 'SELECT COUNT(*) FROM #__jomtube_videos AS v' . $where;
    $database->setQuery($query);
    $items = $database->loadObjectList();
    $Itemid = JomtubeTabsHelper::generateJomTubeItemid();
    $count = count($items);
    for ($i = 0; $i < $count; $i++) {
        $query = 'SELECT AVG(rating) FROM #__jomtube_rating WHERE v_id = ' . $items[$i]->id;
        $database->setQuery($query);
        $items[$i]->ratingAvg = $database->loadResult();
    }
    ?>



  <div id="video_grid-jt-tabs-module" class="grid-view-jt-tabs-module">

	<div id="browse-video-data-jt-tabs-module">

	<?php 
    $itemcount = 0;
    if ($items) {
        foreach ($items as $item) {
            $itemcount++;
            ?>

<!--## AMOUNT OF COLUMNS FIGURED OUT BY WIDTH PERCENT ##-->

		<div class="video-cell-jt-tabs-module" style="width:<?php 
            echo $columns_per_row;
            ?>
%">

			<div class="video-entry-jt-tabs-module" style="<?php 
            if ($thumbnail_size == 'small') {
                echo "width:92px;";
            } elseif ($thumbnail_size == 'medium') {
                echo "width:290px;";
            } elseif ($thumbnail_size == 'large') {
                echo "width:154px;";
            }
            ?>
">

				<div class="v120WideEntry-jt-tabs-module">

					<div class="<?php 
            if ($thumbnail_size == 'small') {
                echo "v90WrapperOuter-jt-tabs-module";
            } elseif ($thumbnail_size == 'medium') {
                echo "v120WrapperOuter-jt-tabs-module";
            } elseif ($thumbnail_size == 'large') {
                echo "v150WrapperOuter-jt-tabs-module";
            }
            ?>
" style="position: relative;">

						<div class="<?php 
            if ($thumbnail_size == 'small') {
                echo "v90WrapperInner-jt-tabs-module";
            } elseif ($thumbnail_size == 'medium') {
                echo "v120WrapperInner-jt-tabs-module";
            } elseif ($thumbnail_size == 'large') {
                echo "v150WrapperInner-jt-tabs-module";
            }
            ?>
" style="position: static;">

						   <?php 
            if ($item->video_type == 'local' || $item->video_type == '') {
                ?>
						   <?php 
                $newLink = JRoute::_("index.php?option=com_jomtube&view=video&id=" . $item->id . "&Itemid=" . $Itemid);
                $newLink10 = JRoute::_("index.php?option=com_jomtube&view=video&id={$item->id}");
                $patterns[0] = '/\\/modules\\//';
                $patterns[1] = '/mod_jomtube_tabs\\//';
                $replacements[0] = '';
                $replacements[1] = '';
                $parsedLink = preg_replace($patterns, $replacements, $newLink10);
                ?>
								
  					   			<a href="/<?php 
                echo $parsedLink;
                ?>
">

							        <img class="<?php 
                if ($thumbnail_size == 'small') {
                    echo "vimg90-jt-tabs-module";
                } elseif ($thumbnail_size == 'medium') {
                    echo "vimg120-jt-tabs-module";
                } elseif ($thumbnail_size == 'large') {
                    echo "vimg150-jt-tabs-module";
                }
                ?>
" src="<?php 
                echo JomtubeTabsHelper::showSrcLocalThumbnailAjax($item->directory . "/_thumbs/" . $item->video_thumb);
                ?>
" border="0" />

								 </a>

							<?php 
            } else {
                ?>
						    <?php 
                $newLink = JRoute::_("index.php?option=com_jomtube&view=video&id=" . $item->id . "&Itemid=" . $Itemid);
                $newLink10 = JRoute::_("index.php?option=com_jomtube&view=video&id={$item->id}");
                $patterns[0] = '/\\/modules\\//';
                $patterns[1] = '/mod_jomtube_tabs\\//';
                $replacements[0] = '';
                $replacements[1] = '';
                $parsedLink = preg_replace($patterns, $replacements, $newLink10);
                ?>
							   <a href="/<?php 
                echo $parsedLink;
                ?>
">

							        <img class="<?php 
                if ($thumbnail_size == 'small') {
                    echo "vimg90-jt-tabs-module";
                } elseif ($thumbnail_size == 'medium') {
                    echo "vimg120-jt-tabs-module";
                } elseif ($thumbnail_size == 'large') {
                    echo "vimg150-jt-tabs-module";
                }
                ?>
" src="<?php 
                echo $item->video_thumb;
                ?>
" border="0" />

								 </a>

							 <?php 
            }
            ?>

							<!--## VIDEO TIME##-->

							<?php 
            if ($show_videoduration) {
                ?>

							     <?php 
                if (trim($item->duration) != "") {
                    ?>

								<div class="video-time-videolist-jt-tabs-module" style="<?php 
                    if ($thumbnail_size == 'small') {
                        echo "margin-top:-61px;";
                    } elseif ($thumbnail_size == 'medium') {
                        echo "margin-top:-81px;";
                    } elseif ($thumbnail_size == 'large') {
                        echo "margin-top:-101px;";
                    }
                    ?>
">

								<span><?php 
                    echo $item->duration;
                    ?>
</span>

								</div>

								<?php 
                }
                ?>

							<?php 
            }
            ?>

						</div>

					</div>


					<!-- ## Video metadata -->
					<div id="video-metadata">
					
					<!--## VIDEO TITLE ##-->

					<?php 
            if ($show_videotitle) {
                ?>

					<div id="video-title-jt-tabs-module">
				    <?php 
                $newLink2 = JRoute::_("index.php?option=com_jomtube&view=video&id=" . $item->id . "&Itemid=" . $Itemid);
                $newLink10 = JRoute::_("index.php?option=com_jomtube&view=video&id={$item->id}");
                $patterns[0] = '/\\/modules\\//';
                $patterns[1] = '/mod_jomtube_tabs\\//';
                $replacements[0] = '';
                $replacements[1] = '';
                $parsedLink2 = preg_replace($patterns, $replacements, $newLink10);
                ?>
						<a href="/<?php 
                echo $parsedLink2;
                ?>
" title="<?php 
                echo $item->video_title;
                ?>
">

					        <?php 
                echo stripslashes($item->video_title);
                ?>

						</a>

					</div>

					<?php 
            }
            ?>

					<!--## VIDEO DATE ADDED ##-->

					<?php 
            if ($show_dateadded) {
                ?>

					<div id="video-added-jt-tabs-module">

						<?php 
                echo _VIDEOINFO_DATE_ADDED;
                ?>
: <?php 
                echo $item->date_added;
                ?>

					</div>

					<?php 
            }
            ?>

					<!--## AUTHOR OF VIDEO ##-->

					<?php 
            if ($show_author) {
                ?>

					<div id="video-from-jt-tabs-module">
				    <?php 
                //this is currently broken?? need to look at filter by user later
                //$newLink3 = JRoute::_('index.php?option=com_jomtube&view=videos&type=member&user_id=' . $item->user_id."&Itemid=".$Itemid);
                $newLink3 = JRoute::_("index.php?option=com_community&view=profile&userid=" . $item->user_id);
                //echo $newLink3;
                $patterns[0] = '/\\/modules\\//';
                $patterns[1] = '/mod_jomtube_tabs\\//';
                $replacements[0] = '';
                $replacements[1] = '';
                $parsedLink3 = preg_replace($patterns, $replacements, $newLink3);
                //echo $parsedLink3;
                //$parsedLink3 = '/community/profile?userid='. $item->user_id;
                //$parsedLink3 = preg_replace($patterns, $replacements, $newLink10);
                ?>
						<?php 
                echo _VIDEOINFO_AUTHOR;
                ?>
:<span class="video-username-jt-tabs-module"> <a href="<?php 
                echo DS . $parsedLink3;
                ?>
"><?php 
                echo jomtube::showShortAuthor($item->username);
                ?>
</a></span>

					</div>

					<?php 
            }
            ?>

					<!--## VIDEO HITS COUNTER ##-->

					<?php 
            if ($show_numberviews) {
                ?>

					<div id="video-view-count-jt-tabs-module">

						<?php 
                echo _VIDEOINFO_NUMBER_VIEWS;
                ?>
: <?php 
                echo $item->hits;
                ?>

					</div>

					<?php 
            }
            ?>

					<!--## STARS RATING ##-->

					<?php 
            if ($show_ratingstar) {
                ?>

					<div class="video-thumb-duration-rating-jt-tabs-module">

						 <div style="float:left">

	  						<?php 
                $root = substr(JURI::root(true), 0, strlen(JURI::root(true)) - 24);
                $emptyStar = $root . "components/com_jomtube/assets/images/emptyStar12x12.gif";
                $halfStar = $root . "components/com_jomtube/assets/images/halfStar12x12.gif";
                $fullStar = $root . "components/com_jomtube/assets/images/fullStar12x12.gif";
                if ($item->ratingAvg > 0) {
                    for ($i_rating = 1; $i_rating <= 5; $i_rating++) {
                        $star = floor($item->ratingAvg) >= $i_rating ? $fullStar : (round($item->ratingAvg) == $i_rating ? $halfStar : $emptyStar);
                        echo "<img src=\"" . $star . "\" height=\"12\" width=\"12\" " . "alt=\"Rated " . round($item->ratingAvg, 1) . " of 5\" " . "title=\"Rated " . round($item->ratingAvg, 1) . " of 5\" />";
                    }
                } else {
                    for ($i_rating = 1; $i_rating <= 5; $i_rating++) {
                        echo "<img src=\"" . $emptyStar . "\" height=\"12\" width=\"12\" " . "alt=\"Rated 0 of 5\" " . "title=\"Rated 0 of 5\" />";
                    }
                }
                ?>

	  			   	  	</div>

					</div>

					<?php 
            }
            ?>
					
					</div>
					<!-- ## Video Metadata ## -->
					
				</div>

			</div>

		</div>

	<?php 
        }
    }
    if ($itemcount == 0) {
        echo "<p>We don't have any videos in this section yet. ";
    }
    ?>

	</div>

</div>



<?php 
}