<?php 
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# Display widget 
#
# !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
# ***************************************
$not_access=1;
$granted="I";

require_once('includes_mobile.php');
require_once('../../../../db_layer/'.__DBTYPE.'/portal.php');
require_once('../includes/template.inc.php');
require_once('../includes/date.inc.php');
require_once('../../../feed.inc.php');
require_once('../../../xml.inc.php');
require_once ('../../../http.inc.php');

$selectedTab = '';
$tabs = array();
$htmlTabs = '';

if (!isset($_GET['mod_id'])  || (isset($_GET['mod_id'])  &&  $_GET['mod_id'] == 0)) exit();
if (isset($_GET['pfid']) && $_GET['pfid']!=0) $pfid = $_GET['pfid'];
if (!isset($_GET['tab'])) exit();
$mod_id = $_GET['mod_id'];
$prof_id = $_GET['tab'];
$unread = '';
if (isset($_GET['tab']) && !empty($_GET['tab'])) {
	$selectedTab = $_GET['tab'];
}

$DB->getResults($portal_getwidget_properties,$DB->escape($_SESSION['user_id']),$DB->escape($prof_id),$DB->escape($mod_id));
if ($DB->nbResults()!=0) {
    if ($mod_id == "86") {
        while ($row = $DB->fetch(0)) {
            $variables = $row['variables'];
            if (preg_match("/pfid=".$pfid."&/i", $variables)) {
                $format = $row['format'];
                $url = $row['url'];
                $uniq = $row['uniq'];
                $title = $row['widget_name'];
                $nb_articles = $row['nb_articles'];
                break;
            }
        }
    }
    else {
        $row = $DB->fetch(0);
        $variables = $row['variables'];
        $format = $row['format'];
        $url = $row['url'];
        $uniq = $row['uniq'];
        $title = $row['widget_name'];
        $nb_articles = $row['nb_articles'];
    }
    $DB->freeResults();
    
    if ($format == "R") {
        $htmlTabs = buildTabs($selectedTab,$tabs);
        $options = defineHeader();
        echo page_begining();
        echo '<div id="header">';
        echo generate_header($options);
        echo '</div>';
        echo '<div id="wrapper">';
        echo '<div id="page">';		
        echo $htmlTabs;	
    
        $title = formatString(parser($variables,'ptitl='),15);
        //$pfid = parser($variables,'pfid=');
        $limit = $nb_articles;
        $unread = 0;
        $DB->getResults($mobRssWidgetUnreadArticles,$DB->escape($_SESSION['user_id']),$DB->escape($pfid),$DB->escape($limit));
        while ($row = $DB->fetch(0)) {
            if ($row['status'] != 1 && $row['status'] != 2) {
                $unread++;
            }
        }
        $row = $DB->fetch(0);
        $unread = "(".($unread).")";
        $DB->freeResults();
    }
    else {
        echo page_begining_simple();
    }

    if ($format == "R") {
        echo   '<h2 class="specificfont2">'.$title.$unread.'</h2>';
    }
    else {
        echo   '<h2 class="specificfont1">'.$title.$unread.'</h2>';
    }
    echo '      <div class="previous_top" align="right">
                <a href="portal.php?tab='.$selectedTab.'">'.lg('backportal').'</a>
            </div>';

    if ($format == 'R') {
        include('../widgets/widget_86.inc.php');
    }
    else if ($format == 'M') {
        include('../widgets/widget_'.$mod_id.'.inc.php');
    }
    else if ($format == 'I' && substr($url, 0, 2)== "..") {
        //url points to portaneo script
        echo '
            <iframe src="../../../'.$url.'?'.$variables.'&tab='.$selectedTab.'" width="100%" height="100%" scrolling="yes" frameborder="0" name="widget_'.$mod_id.'"></iframe>
            <a style="margin-left:5px;" href="../../../'.$url.'?'.$variables.'" target="_blank">'.lg('openInANewPage').'</a>';
    }
    else{
        //url points out of portaneo
        echo '
            <iframe src="'.$url.'?'.$variables.'&tab='.$selectedTab.'" width="100%" height="100%" scrolling="yes" frameborder="0" name="widget_'.$mod_id.'"></iframe>
            <a style="margin-left:5px;" href="'.$url.'?'.$variables.'" target="_blank">'.lg('openInANewPage').'</a>';
    }
    if ($format == "R") {
        echo   '<div class="previous_bottom" align="right">
                    <a href="portal.php?tab='.$selectedTab.'">'.lg('backportal').'</a>
                </div>';
    }
}
else {
    echo generate_warning('alert',''.lg('widgetNotFound').'','','');
    echo '<center><a href="portal.php">'.lg('backportal').'</a></center>';
}

if ($format == "R") {
    echo '</div>';
    echo '</div>';
    echo generate_footer("pages");
}
else {
    echo "</body></html>";
}
?>