<?php
/**
*
* @Artiphp 6
* @paquetage video
* @version index.inc.php, 2018/12/28 arteam
* @copyright (c) 2001-2019 Ronald Gu&eacute;rin - webmaster@artiloo.com - http://www.artiloo.com
* @license consulter artpublic/license/index.html GNU Public License
*
*/

// Protection - Page
define('IN_ARTI', true);

// Chargement configuration
require('../artpublic/config.inc.php'); // ATTENTION : chemin relatif depuis racine Artiphp

// Debug de la page
//error_reporting(E_ALL ^ E_NOTICE);

// Connexion au noyau
// ------------------
include(ARTI_SYS_INT_FCT_PATH . 'identification.inc.php'); // zone membre

// Langue
// ------
if (empty($_SESSION['SESSION_IDSKIN'])) {
    include(ARTI_SYS_INT_FCT_PATH . 'donnees_skin.inc.php');
}
$SESSION_LANGSKIN = $_SESSION['SESSION_LANGSKIN'];
include(ARTI_SYS_INT_PATH . "langues/$SESSION_LANGSKIN/index.inc.php");

include('config_mod.inc.php'); //config specifique au module
include(ARTI_SYS_INT_FCT_PATH . 'verif_acl.inc.php'); // ACL general

include_once(ARTI_SYS_INT_FCT_PATH . 'fonctions_date.inc.php');



// -------------------------
// CODE SPECIFIQUE AU MODULE
// -------------------------

// traitement des valeurs passant par l'url
$idcat = $_GET['idcat'];
$page = $_GET['page'];
if (!($limit)) {
    $limit = $_GET['limit'];
}
$pagination = '';
$debutpag = '';
$finpag = '';
$PHP_SELF = htmlspecialchars($_SERVER['PHP_SELF']);

if ($_GET['val']) {
    $val = $_GET['val'];
    list($idcat, $suite) = explode('_', $val);
    $suite = htmlentities(urlencode($suite));
}

if ($_GET['val2']) {
    $val2 = $_GET['val2'];
    list($idcat, $page, $limit, $suite) = explode('_', $val2);
    $suite = htmlentities(urlencode($suite));
}

if ($_GET['val3']) {
    $val3 = $_GET['val3'];
    list($page, $limit) = explode('_', $val3);
    $suite = htmlentities(urlencode($suite));
}

$idcat = intval($idcat);
$page = intval($page);
$limit = intval($limit);
$suite = htmlspecialchars($suite);

// pagination : le limit d&eacute;finit le nombre d'enregistrements par page
if (!($limit)) {
    $limit = 12;
}
if (!($page)) {
    $page = 0;
}

if ($idcat) {
    $ajoutcat = " AND id_cat='$idcat'";
    $ajoutval = '?val2=' . $idcat . '_';
    $ajoutval2 = '?val=' . $idcat;
    $ajoutsuite = '_' . $suite;
    $ajoutrewrite = 'cat_' . $idcat . '_';
    $ajoutrewrite2 = '_' . $urlfriendlycat;
    $ajouttable = '';
} else {
    $ajouttable = '';
    $ajoutcat = "";
    $ajoutval = '?val3=';
    $ajoutsuite = '';
    $ajoutrewrite = 'allcat_';
    $ajoutrewrite2 = '';
}

// comptage des enregistrements
$requete2 = "SELECT id_video FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "`" . $ajouttable . " WHERE affichagePage2='1' " . $ajoutcat . "";
$results = mysql_query($requete2, $link);
$rows = mysql_num_rows($results);

// A REVOIR
if ($rows == 0) {
    $listedossiers = "<strong><span style=\"color:#FF0000\">$LG_NORESULT</span></strong>\n";
}

$pages = intval($rows / $limit);
if ($rows % $limit) {
    $pages++;
}
$current = ($page / $limit) + 1;
if (($pages < 1) || ($pages == 0)) {
    $total = 1;
} else {
    $total = $pages;
}
$first = $page + 1;
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
    $last = $page + $limit;
} else {
    $last = $rows;
}

mysql_free_result($results);
// -------------------------

// DEFINITION DE LA CATEGORIE

if ($idcat) {
    // la cat&eacute;gorie
    $requete2 = "SELECT id_categorie, nomCategorie, descCat, url_friendly FROM " . ARTI_PREFIX_TB . "categories WHERE id_categorie='$idcat' AND nom_cmodule='" . $mod_encours_sys . "'";
    $result2 = mysql_query($requete2, $link);
    $defcat = mysql_fetch_object($result2);

    $defcat->nomCategorie = stripslashes($defcat->nomCategorie);
    $urlfriendlycat = stripslashes($defcat->url_friendly);

    // -----------------------------------------
    $entete2 = '<h1>' . $defcat->nomCategorie . '</h1>';
    // si la categorie est une sous-categorie

        $nomcat = stripslashes($defcat->nomCategorie);
        $cat = $defcat->id_categorie;

    // EN-TETE DE PAGE
    $entete = "<a href=\"" . ARTI_WEB_PATH . "index.php\">$LG_ACCUEIL</a><a href=\"index.php\">$lg_mod_titre</a>\n";

} else {

    $entete = "<a href=\"" . ARTI_WEB_PATH . "index.php\">$LG_ACCUEIL</a><a href=\"index.php\">$lg_mod_titre</a>\n";
    $entete2 = "<h1>Toutes les vid&eacute;os</h1>\n\n";

    // metatags
    include('langues/' . $SESSION_LANGSKIN .'/metatags.inc.php');
    $metatitle = $LG_METADOS . ' ';
    $metaDescription = $LG_METADESDOS . ' - ' . $metaplus;
}

if ($idcat) {
    $ajouttable = '';
    $ajoutnomcat = '';
} else {
    $ajouttable = ', ' . ARTI_PREFIX_TB . 'categories';
    $ajoutcat = " AND id_categorie=id_cat";
    $ajoutnomcat = ', nomCategorie, id_categorie, url_friendly';
}

// AFFICHAGE DES VIDEOS
// ----------------------

$page = intval($page);
$limit = intval($limit);

if ($idcat) {
	$requete = "SELECT id_video, nom_video, url_video, date_video, id_cat, videorewriting FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "` WHERE affichagePage2='1' AND id_cat='$idcat' ORDER BY date_video desc LIMIT $page, $limit";
} else {
	$requete = "SELECT id_video, nom_video, url_video, date_video, id_cat, videorewriting FROM `" . ARTI_PREFIX_TB . $mod_encours_dir . "` WHERE affichagePage2='1' ORDER BY date_video desc LIMIT $page, $limit";
}



$result = mysql_query($requete, $link);
$ix = 0;

$listedossiers = '';

while ($dossier = mysql_fetch_object($result)) {

    // decodage du texte
    $dossier->nom_video = stripslashes($dossier->nom_video);
    $dossier->url_video = stripslashes($dossier->url_video);
    $dossier->id_cat = intval($dossier->id_cat);
    $dossier->date_video = stripslashes($dossier->date_video);

    if (! $idcat) {
    
    	if ($dossier->id_cat=='0') {
    		$liscategorie = "\n"; 
    	} else {
    		$requetecat = "SELECT id_categorie, nomCategorie, url_friendly FROM " . ARTI_PREFIX_TB . "categories WHERE id_categorie='$dossier->id_cat' AND nom_cmodule='" . $mod_encours_sys . "'";
    		$resultcat = mysql_query($requetecat, $link);
    		$donneecat = mysql_fetch_object($resultcat);
    	
    	    $dossier->nomCategorie = stripslashes($donneecat->nomCategorie);

        	// url friendly pour cat
        	$urlfriendlycat = stripslashes($donneecat->url_friendly);
        	if (ARTI_URL_TYPE == 1) {
        	    $valurl2 = 'cat.php?val=' . $donneecat->id_categorie . '_' . $urlfriendlycat;
        	} else {
        	    $valurl2 = 'categorie_' . $donneecat->id_categorie . '_' . $urlfriendlycat . '.html';
       	 	}
        	// --------------
        	
        	$liscategorie = "<span class=\"video_cat\"><a href=\"$valurl2\">" . $dossier->nomCategorie . "</a></span>\n";
        }
       
        
    } else {
    
        $liscategorie = '';
        
    }
    
    
        	$urlfriendly10 = stripslashes($dossier->videorewriting);
    		if (ARTI_URL_TYPE == 1) {
        		$valurl10 = 'video.php?val=' . $dossier->id_video . '_' . $urlfriendly10;
    		} else {
        		$valurl10 = 'video_' . $dossier->id_video . '_' . $urlfriendly10 . '.html';
    		}
    		
    		// recherche image webp
    		$filename = '../video/images/' . $dossier->url_video . '.webp';

			if (file_exists($filename)) {
    			$imgvideoaff=$filename;
			} else {
    			$imgvideoaff="https://i.ytimg.com/vi/" . $dossier->url_video . "/hqdefault.jpg";
			}	


    $listedossiers .= "<div class=\"ytthumb\"><a href=\"" . $valurl10 . "\">\n";
    $listedossiers .= "<div class=\"video_img\"><img src=\"" . $imgvideoaff . "\" alt=\"\"></div>\n";
    $listedossiers .= "<div class=\"video_legend\">" . $dossier->nom_video . "</div>\n";
    $listedossiers .= "</a>\n";
    $listedossiers .= $liscategorie . "\n";

    $listedossiers .= "</div>\n";

}











mysql_free_result($result);

// -----------------------------------------------------------------------
// Deuxieme partie du code de pagination
// (à modifier si vous avez d'autres donn&eacute;es à faire circuler dans l'URL)
// -----------------------------------------------------------------------

if ($idcat) {
    $ajoutrewrite2 = '_' . $urlfriendlycat;
} else {
    $ajoutrewrite2 = '';
}

if ($page != 0) {
    $pagination = '';
    $back_page = $page - $limit;

    if (ARTI_URL_TYPE == 1) {
        if ($back_page == '0') {
            $pagination .= "<a href=\"$PHP_SELF" . $ajoutval2 . $ajoutsuite . "\">&#171; $LG_PGPRECED</a> | \n";
        } else {
            $pagination .= "<a href=\"$PHP_SELF" . $ajoutval . $back_page . "_" . $limit . $ajoutsuite . "\">&#171; $LG_PGPRECED</a> | \n";
        }
    } else {
        if ($back_page == '0') {
            $pagination .= "<a href=\"categorie_" . $idcat . $ajoutrewrite2 . ".html\">&#171; $LG_PGPRECED</a> | \n";
        } else {
            $pagination .= "<a href=\"" . $ajoutrewrite . $back_page . "_" . $limit . $ajoutrewrite2 . ".html\">&#171; $LG_PGPRECED</a> | \n";
        }
    }
}

for ($i = 1; $i <= $pages; $i++) {
    $ppage = $limit * ($i - 1);
    if ($ppage == $page) {
        if ($total == 1) {
            $pagination .= '';
        } else {
            $pagination .= "<strong>" . $LG_PAGE . " $i/$pages</strong> | \n";
            $ajmeta = "- " . $LG_PAGE . " $i/$pages";
        }
    }
}

if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
    $next_page = $page + $limit;

    if (ARTI_URL_TYPE == 1) {
        $pagination .= "<a href=\"$PHP_SELF" . $ajoutval . $next_page . "_" . $limit . $ajoutsuite . "\">$LG_PGSUITE &#187;</a>\n";
    } else {
        $pagination .= "<a href=\"" . $ajoutrewrite . $next_page . "_" . $limit . $ajoutrewrite2 . ".html\">$LG_PGSUITE &#187;</a>\n";
    }
}

if (! $pagination) {
    $finpag .= '';
} else {
    $debutpag .= "<div class=\"entete2\">";
    $finpag .= "</div>";
}
// -------------------------------------------------------------------------


// metatags --------------------------------
$nCat = htmlspecialchars($nomcat);
$nCat2 = htmlspecialchars($nomsscat);
$metatitle .= $nCat . ' ' . $nCat2 . ' ' . $ajmeta . ' - ' . ARTI_SITE_NAME;
$nCatDes = strip_tags($defcat->descCat);
$nCatDes = htmlspecialchars($nCatDes);
$metaDescription .= $nCatDes . ' - ' . $nCat . ' ' . $nCat2;

mysql_free_result($result);

// presentation
// ------------
$milieu = "<div id=\"mod_".$mod_encours_dir."\" class=\"mod_content\">\n\n";
$milieu .= $entete2;
//$milieu .= $debutpag . ' ' . $pagination . ' ' . $finpag;
$milieu .= $listedossiers;

$milieu .= $debutpag . ' ' . $pagination . ' ' . $finpag;


$milieu .= '</div>';


// Template
// --------
$SESSION_SKIN = $_SESSION['SESSION_SKIN'];
include(ARTI_SYS_INT_PATH . "templates/temp$SESSION_SKIN/temp.html");
echo $arti;

mysql_close($link);
?>




