<?php 
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# main menu mobile site
#
# !! 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('../includes/template.inc.php');
require_once('../includes/miscfunctions.inc.php');

$DB->getResults($checkIfNewUser,$DB->escape($_SESSION['user_id'])); 
$isnew = ($DB->nbResults() == 0)  ?   true    :   false;
$DB->freeResults();

$i=0;
$prevTabId='';
$html = '';
$tabs = array();
$selectedTab = '';
$max_tab = 0;
if (isset($_GET['tab']) && !empty($_GET['tab'])) {
	$selectedTab = $_GET['tab'];
}
$DB->getResults($portalConfiguration_getUserWidgets,$DB->escape($_SESSION['user_id']));
if ($DB->nbResults()>0) {
    while ($row = $DB->fetch(0)) {
        if ($max_tab == 4) { break; }
        $tabId = $row['profile_id'];
        $item_id = $row['item_id'];
        $widgetUniq = $row['uniq'];
        $checked = empty($row['check_uniq'])?'':' checked="checked"';
        $available = $row['available'];
        $title = $row['widget_name'];
        $nbArticles = (isset($row['nb_articles']))  ?  $row['nb_articles']  :  12;
        $format = $row['format'];
        if ($tabId!=$prevTabId) {
            $html.='<br /><span class="tab_title"><a name="'.$tabId.'">'.$row['tab_name'].'</a></span><br />';
            $max_tab++;
        }
        $prevTabId = $tabId;
        if (!empty($available) || $format == 'R' || $format == 'I') {
            $title = parser($row['variables'],'ptitl=');
            if (empty($title)) {
                $title = $row['widget_name'];
            }
            $html.='<input type="checkbox" name="check[]" '.$checked.' value="uniq='.$widgetUniq.'&profile_id='.$tabId.'&item_id='.$item_id.'" />  '.$title.'<br />'; 
            if ($format == 'R') {
                $html.= '<span class="configuration_nbart">'.lg("nb_art").'</span>
                         <input type="text" name="nbart_'.$widgetUniq.'" value="'.$nbArticles.'" size="2" maxlength="2"/><br />';
            }
        }
    }
    $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">';

if (!$isnew) {
    $htmlTabs = buildTabs($selectedTab,$tabs);
    echo $htmlTabs;
}

echo '<div id="configuration_form">
        <form method="post" action="scr_portal_configuration.php?tab='.$selectedTab.'">
            <div class="configuration_title">'.lg("select_wid").'</div>
            <div class="configuration_subtitle">'.lg("selectwidgets").'</div>';
            echo '<br /><strong>'.lg("information").': </strong>'.lg("maxtabs").'<br />';
            echo $html;
echo '      <div class="submit_btn">
            <input type="submit" value="'.lg('btn_valid').'" />&nbsp;&nbsp;';
if (!$isnew) echo '<a href="portal.php?tab='.$selectedTab.'"><input type="button" value="'.lg('cancel').'" name="cancel" /></a>';
echo'       </div>
        </form>
    </div>
    </div>';
echo '</div>';
    
echo generate_footer("pages");