<?php 
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# Display groups notebook
#
# !! 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('../../../../db_layer/'.__DBTYPE.'/enterprise.php');
require_once('../includes/date.inc.php');

$id = (isset($_GET['id']))      ?       $_GET['id']       :       0;
$page = isset($_GET['page'])        ?       $_GET['page']       :       0;
$ismyprofil = false;
$myarticles = array();
$previousStr = '';
$nextStr = '';
$today = getToday();
$yesterday = getYesterday();

$options = defineHeader();

echo page_begining();

echo '<div id="header">';
    echo generate_header($options,$message);
echo '</div>';

echo '<div id="wrapper">';
echo '<div id="page">';		

echo $htmlTabs;

//group control: check if the user user has access to the group notebook.
include_once('../../../../notebook/groupsecurity.inc.php');
if ($userIsMemberOfGroup == 0) {
    echo generate_warning('alert',lg("NotCorrectGroup"),'','');
    echo "</div>";
    echo "</div>";
	echo generate_footer("group");
	exit();
}

$DB->getResults($notebook_getGroupbookProperties,$DB->escape($_SESSION['user_id']),$DB->escape($id));
$nbRes = $DB->nbResults();
if ($nbRes == 0) {
	echo generate_warning('info',''.lg("NotCorrectGroup").'','','');
    echo "</div>";
    echo "</div>";
	echo generate_footer("group");
	exit();
}
$row = $DB->fetch(0);
$description = $row['description'];
if (strlen($description)>75) {
    $description = formatString($description,75).'...';
}
echo '
      <div class="users">
        <div class="title">
            <img src="../../../'.displayPicture($row['picture']).'" class="avatar" width="50" height="50" style="float: left;margin-right: 5px;">
            <span>'.$row['name'].'</span>
        </div>';
            if ($description != '') echo '<div class="subtitle">'.$description.'</div>';  
echo '	<div class="links">
                <a href="group_members.php?id='.$id.'" class="greylink">'.lg("network").'</a> |';
    echo '      <a href="groupbook_addarticle.php?id='.$id.'" class="greylink">'.lg("add_article").'</a>';
echo '
        </div>
      </div>';
$DB->freeResults();

$DB->getResults($mobNotebookArticles_getArticlesListId, $DB->escape($_SESSION['user_id']));
while($row = $DB->fetch(0)) {
     array_push($myarticles,$row['article_id']);
}
$DB->freeResults();	

//load articles
$DB->getResults($index_getGroupbookArticles,
                                            $DB->escape($id),
                                            $groupbookAccessLevel,
                                            $DB->escape($_SESSION['user_id']),
                                            $DB->escape($page));
$max = $DB->nbResults();
if ($max==0)        echo generate_warning('info',''.lg("empty_notebook").'','','');
$cpt = 0;
while( ($row = $DB->fetch(0)) && $cpt<10) {
    $title = $row['title'];
    $hisid = $row['owner_id'];
    $user_name = $row['long_name'];
    $date = substr($row['pubdate'],0,10);
    $date = formatDate($date,$today,$yesterday);
    $artid = $row['id'];
    $commentsnb = $row['commentsnb'];
    $x = 0;
    while ($x<count($myarticles) && $myarticles[$x]!=$artid) {
        $x++;
    }
    $igotit = ($x<count($myarticles))     ?       true    :   false;
        
	echo '
		<div class="item" style="border-bottom: 1px solid #CFCFCF;">
			<span class="title" ><a href="groupbook_article.php?gid='.$id.'&artid='.$artid.'&page=0&wid='.$hisid.'">'.$title.'</a></span>
			<div class="subtitle_small">'.$date.', '.lg("by");   
    if ($hisid == $_SESSION['user_id'])
    echo '      <span style="color:#CFCFCF;">'.$user_name.'</span></div>';
	else
    echo '      <a style="color:#CFCFCF;font-size:11px;" href="network_profil.php?id='.$hisid.'">'.$user_name.'</a></div>';
    
    echo '      <div class="subtitle_small">';
	
    if(!$ismyprofil 
       AND $hisid != $_SESSION['user_id'] 
       AND !$igotit) {
			echo'<a class="greylink" href="scr_addnotebook.php?id='.$id.'&artid='.$artid.'">'.lg("add_notebook").'</a> |';
	}
    
	echo' <a class="greylink" href="groupbook_article.php?gid='.$id.'&artid='.$artid.'&page=0&wid='.$hisid.'#commentaire">'.$commentsnb.' '.lg("comment").'</a>
			</div>
		</div>';
    $cpt++;
}

if ($page!=0) {
	$previousStr = '<a href="groupbook.php?page='.($page-10).'">'.lg("page_back").'</a>';
}
if ($max == 11) {
	$nextStr = '<a href="groupbook.php?page='.($page+10).'">'.lg("page_next").'</a>';
}

echo '<center><div>'.$previousStr.' &nbsp;&nbsp; '.$nextStr.'</div></center>'; 

echo "</div>";
echo "</div>";

echo generate_footer("group");
?>