<?php
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# Display portal
#
# !! 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 = '';
$inc=0;
$widgets = array();
$iconsPath = "../images/icons/";

if (isset($_GET['tab']) && !empty($_GET['tab'])) {
	$selectedTab = $_GET['tab'];
}

$htmlTabs = buildTabs($selectedTab,$tabs);

$inc = 0;
$DB->getResults($mobPortal_getWidgets,$DB->escape($_SESSION['user_id']),$DB->escape($selectedTab));
if ($DB->nbResults()==0) {
	header('location:portal_configuration.php');
	exit();
}
while ($row = $DB->fetch(0)) {
	$widgets[$inc] = array(
			"id" => $row['item_id'],
			"variables" => $row['variables'],
			"format" => $row['format'],
			"name" => $row['widget_name'],
			"picture" => $row['picture'],
			"nb_articles" => $row['nb_articles']
	);
	$inc++;
}
$DB->freeResults();

$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;

if (count($tabs)!=0) {
   //echo '<div class="suboptions"><a href="portal_addmodule.php?tab='.$selectedTab.'">'.lg("addWidget").'</a></div>';
}

if (count($tabs)==0) {
	echo generate_warning('info',''.lg('noPortalExisting',__LOCALFOLDER).'','','');
}
else {
	foreach ($widgets AS $widget) {
        $title = $widget['name'];
        $unread = '';
        $pfid = 0;
        if ($widget['format'] == "R") {
            $title = formatString(parser($widget['variables'],'ptitl='),11);
            $pfid = parser($widget['variables'],'pfid=');
            $limit = $widget['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++;
                }
            }
            $unread = "<font color='orange'>(".$unread.")</font>";
            $DB->freeResults();
        }
        $icon = $iconsPath.$widget["picture"];
        echo  '<div id="portal_widget">
                    <a href="display_widget.php?mod_id='.$widget['id'].'&tab='.$selectedTab.'&pfid='.$pfid.'">
                        <div class="portal_widget_img">
                            <img src="'.$icon.'" width="48" height="48"><br />
                            <span class="portal_widget_span">'.ucfirst($title).$unread.'</span>
                        </div>
                    </a>
               </div>';
	}
    echo '<center><div id="configure_link"><div><span><a href="portal_configuration.php?tab='.$selectedTab.'">'.lg("pageConfiguration").'</a></span></div></div></center';
}

echo '</div>';
echo '</div>';

echo generate_footer("pages");
?>