/**
     * Outputs frontpage HTML
     *
     * @param string $option  the joomla component name
     * @param array  $rows  array of video data
     * @param array  $rowsfeatured  array of featured video data
     * @param object $pageNav  page navigation object
     * @param int    $total  the total video count
     * @return       Nothing
     */
	function recountVideosInCategory($catid=null) {
		$db = & JFactory::getDBO();
		$c = hwd_vs_Config::get_instance();

        if (isset($catid)) {
			$rows[0]->id = $catid;
        } else {
        	// get all categories
			$query = 'SELECT id'
					. ' FROM #__hwdvidscategories'
					;
			$db->SetQuery($query);
			$rows = $db->loadObjectList();
		}

		for ($i=0, $n=count($rows); $i < $n; $i++) {
			$row = $rows[$i];

			if ($c->countcvids == 1) {
				$cids = hwd_vs_tools::getChildCategories($row->id);
				$where = ' WHERE category_id IN ('.$cids.')';
			} else {
				$where = ' WHERE category_id = '.$row->id;
			}

			// count videos in category
			$query = 'SELECT count(*)'
					. ' FROM #__hwdvidsvideos'
					. $where
					. ' AND published = 1'
					. ' AND approved = "yes"'
					;
			$db->SetQuery($query);
			$total = $db->loadResult();

			// update category
			$db->SetQuery("UPDATE #__hwdvidscategories SET num_vids = $total WHERE id = $row->id");
			$db->Query();
			if ( !$db->query() ) {
				echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
				exit();
			}
		}

		return true;
    }
Ejemplo n.º 2
0
    /**
     * Query SQL for requested category data
     *
     * @return       Nothing
     */
    function viewcategory()
    {
        global $mainframe, $limitstart, $hwdvs_joinv, $hwdvs_selectv, $smartyvs;
		$c = hwd_vs_Config::get_instance();
		$db = & JFactory::getDBO();
		$my = & JFactory::getUser();
		$acl= & JFactory::getACL();
		$usersConfig = &JComponentHelper::getParams( 'com_users' );
		$app = & JFactory::getApplication();

        // number of videos to display
        $limit     = intval($c->vpp);

        // get POST array values
        $cat_id = JRequest::getInt( 'cat_id', 0 );

        // get category name
        $query_cat = 'SELECT *'
                   . ' FROM #__hwdvidscategories'
                   . ' WHERE id = '.$cat_id
                   ;
        $db->SetQuery( $query_cat );
        $cat = $db->loadObject();

		if (count($cat) == 0)
		{
			hwd_vs_tools::infomessage(1, 0,  _HWDVIDS_TITLE_NOACCESS, _HWDVIDS_TCDNE, "exclamation.png", 0);
			return;
		}

		$order = JRequest::getCmd( 'order' );
		$app->setUserState( 'hwdvsCategoryVideoOrder', $order );
		$filter_order = $app->getUserStateFromRequest( 'hwdvsCategoryVideoOrder', 'order' );

		if (!empty($filter_order)) {
			$cco = $filter_order;
		} else if ($cat->order_by !== "0") {
        	$cco = $cat->order_by;
        } else {
        	$cco = $c->cvordering;
        }

        // filter for sql data
        $where = ' WHERE video.published = 1';
        $where .= ' AND video.approved = "yes"';
        if ($c->countcvids == 1) {
	        $cids = hwd_vs_tools::getChildCategories($cat->id);
			$where .= ' AND video.category_id IN ('.$cids.')';
		} else {
        	$where .= ' AND video.category_id = '.$cat_id;
		}

		if ( $cco == "orderASC" ) {
			$order = ' ORDER BY video.ordering ASC';
		} else if ( $cco == "orderDESC" ) {
			$order = ' ORDER BY video.ordering DESC';
		} else if ( $cco == "dateASC" ) {
			$order = ' ORDER BY video.date_uploaded ASC';
		} else if ( $cco == "dateDESC" ) {
			$order = ' ORDER BY video.date_uploaded DESC';
		} else if ( $cco == "nameASC" ) {
			$order = ' ORDER BY video.title ASC';
		} else if ( $cco == "nameDESC" ) {
			$order = ' ORDER BY video.title DESC';
		} else if ( $cco == "hitsASC" ) {
			$order = ' ORDER BY video.number_of_views ASC';
		} else if ( $cco == "hitsDESC" ) {
			$order = ' ORDER BY video.number_of_views DESC';
		} else if ( $cco == "voteASC" ) {
			$order = ' ORDER BY video.updated_rating ASC';
		} else if ( $cco == "voteDESC" ) {
			$order = ' ORDER BY video.updated_rating DESC';
		} else if ( $cco == "random" ) {
			$order = ' ORDER BY rand()';
		} else {
			$order = ' ORDER BY video.date_uploaded DESC';
		}

        // count filtered videos
        $db->SetQuery( 'SELECT count(*)'
                     . ' FROM #__hwdvidsvideos AS video'
                     . $where
                     );
        $total = $db->loadResult();
        echo $db->getErrorMsg();

		jimport('joomla.html.pagination');
		$pageNav = new JPagination( $total, $limitstart, $limit );

        // get filtered video data
        $query = 'SELECT'.$hwdvs_selectv
                . ' FROM #__hwdvidsvideos AS video'
				. $hwdvs_joinv
                . $where
                . $order
                ;
        $db->SetQuery($query, $pageNav->limitstart, $pageNav->limit);
        $rows = $db->loadObjectList();

		if ($c->bviic == 1)
		{
			if (!hwd_vs_access::allowAccess( $cat->access_v, $cat->access_v_r, hwd_vs_access::userGID( $my->id ))) {
				if ( ($my->id < 1) && (!$usersConfig->get( 'allowUserRegistration' ) == '0' && hwd_vs_access::allowAccess( $c->gtree_upld, 'RECURSE', $acl->get_group_id('Registered','ARO') ) ) ) {
					$smartyvs->assign("showconnectionbox", 1);
					hwd_vs_tools::infomessage(2, 0, _HWDVIDS_TITLE_NOACCESS, _HWDVIDS_ALERT_REGISTERFORCAT, "exclamation.png", 0);
					return;
				} else {
					$smartyvs->assign("showconnectionbox", 1);
					hwd_vs_tools::infomessage(2, 0, _HWDVIDS_TITLE_NOACCESS, _HWDVIDS_ALERT_CAT_NOT_AUTHORIZED, "exclamation.png", 0);
					return;
				}
			}
		}

		// get subcategories
		$order = JRequest::getCmd( 'hwdcorder' );
		$app->setUserState( 'hwdvsCategoryOrder', $order );
		$filter_order = $app->getUserStateFromRequest( 'hwdvsCategoryOrder', 'cateorder' );

		if (!empty($filter_order)) {
			$c->cordering = $filter_order;
		}

		if ( $c->cordering == "orderASC" ) {
			$order = ' ORDER BY ordering ASC, category_name';
		} else if ( $c->cordering == "orderDESC" ) {
			$order = ' ORDER BY ordering DESC, category_name';
		} else if ( $c->cordering == "nameASC" ) {
			$order = ' ORDER BY category_name ASC';
		} else if ( $c->cordering == "nameDESC" ) {
			$order = ' ORDER BY category_name DESC';
		} else if ( $c->cordering == "novidsASC" ) {
			$order = ' ORDER BY num_vids ASC';
		} else if ( $c->cordering == "novidsDESC" ) {
			$order = ' ORDER BY num_vids DESC';
		} else if ( $c->cordering == "nosubsASC" ) {
			$order = ' ORDER BY num_subcats ASC';
		} else if ( $c->cordering == "nosubsDESC" ) {
			$order = ' ORDER BY num_subcats DESC';
		} else {
			$order = ' ORDER BY ordering, category_name';
		}

		$wherecat = ' WHERE published = 1 AND parent = '.$cat_id;
		if ($c->cat_he == 1) {
			$wherecat.= ' AND num_vids > 0';
		}

		$query = 'SELECT *'
				. ' FROM #__hwdvidscategories'
				. $wherecat
				. $order
				;
		$db->setQuery( $query );
		$subcats = $db->loadObjectList();

        // sent out
        hwd_vs_html::viewCategory($rows, $pageNav, $total, $cat_id, $cat, $subcats);
    }