<?php 
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# Display  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');

$previousStr = '';
$nextStr = '';
$message = (isset($_GET['message']))        ?       $_GET['message']        :   '';
$page = isset($_GET['page'])        ?       $_GET['page']       :       0;
$id = $_GET['id'];
if ($id == $_SESSION['user_id']) {
	$ismyprofil = true;
}
else {
	$ismyprofil = false;
	$myarticles = array();
	$DB->getResults($mobNotebookArticles_getArticlesListId, $DB->escape($_SESSION['user_id']));
	while($row = $DB->fetch(0)) {
		 array_push($myarticles,$row['article_id']);
	}
	$DB->freeResults();	
}

$DB->getResults($mobNotebookArticle_getUserInfo,$DB->escape($_SESSION['user_id']),$DB->escape($id));
$row = $DB->fetch(0);
$pic_user=$row['picture'];
$name_user=$row['long_name'];
$stat_user=$row['stat'];
$isfriend=$row['friend_id'];
$DB->freeResults();

$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 generate_statusform("notebook_articles.php?id=".$id."&page=".$page."");

echo '<div class="users" style="clear:both;">
        <div class="title">
            <img src="../../../'.displayPicture($row['picture']).'" class="avatar" width="50" height="50" style="float: left;margin-right: 5px;">
            <span>'.$row['long_name'].' '.$row['firstname'].'</span>
        </div>';
            if ($row['stat']!='') echo '<div class="subtitle">'.$row['stat'].'</div>';  
echo '	<div class="links">
                <a href="network_profil.php?id='.$id.'&act=prof" class="greylink">'.lg("display_info").'</a> |';
if ($id == $_SESSION['user_id'])    
    echo '      <a href="notebook_addarticle.php" class="greylink">'.lg("add_article").'</a>';
else 
    echo '      <a href="network_profil.php?id='.$id.'&act=note" class="greylink">'.lg("personalNotes").'</a>';
echo '  </div>
      </div>';

//define the pattern to use in request $view_blog
//$userAL = 1,2,3 means users owns the blog
//$userAL = 1,2 means users belong to the network of blog owner
//$userAL = 3 means users isn't connected to the blog owner
if (empty($isfriend) && $id!==$_SESSION['user_id'])     $userAL = 3; 
if (isset($isfriend))                                   $userAL = '2,3';
if ($id == $_SESSION['user_id'])                        $userAL='1,2,3';

$DB->getResults($mobNotebookArticles_countArticles,$DB->escape($id));
$limit = 0;
while($row = $DB->fetch(0)) {
	$status = $row['status'];
	$user_id = $row['user_id'];
	if ($status==3)                                      $limit++;
	if ($status==2 && isset($isfriend))                  $limit++;
	if ($status==2 && $user_id == $_SESSION['user_id'])  $limit++;
	if ($status==1 && $user_id == $_SESSION['user_id'])  $limit++;
}
$DB->freeResults();

$DB->getResults($mobNotebookArticles_getArticles,$DB->escape($id),$userAL,$page);
$max = $DB->nbResults();
if ($max==0)        echo generate_warning('info',''.lg("empty_notebook").'','','');

$i = 0;
$today = getToday();
$yesterday = getYesterday();
while($row = $DB->fetch(0)) {
	$i++;
	$title = $row['title'];
	$artid = $row['id'];
	$description = $row['description'];
	$date = getDBDate($row['pubdate']);
	$user_name = $row['long_name'];
	$hisid = $row['owner_id'];
	$type = $row['type'];
	$commentsnb = $row['commentsnb'];
	$status = $row['status'];
	$user_id = $row['user_id'];
	$takeon = $row['take_on'];
	$trackbacknb = $row['trackbacknb'];
	if (!$ismyprofil) {
		$x=0;
		while ($x<count($myarticles) && $myarticles[$x]!=$artid) {
			$x++;
		}
		$igotit = ($x<count($myarticles))     ?       true    :   false;
	}

	$dateStr = formatDate($date,$today,$yesterday);

	echo '
		<div class="item" style="border-bottom: 1px solid #CFCFCF;">
			<span class="title" ><a href="notebook_article.php?id='.$id.'&artid='.$artid.'&page=0&wid='.$hisid.'">'.$title.'</a></span>
			<div class="subtitle_small">'.$dateStr.', '.lg("by");   
    if ($hisid == $_SESSION['user_id'])
    echo '      <span style="color:#CFCFCF;">'.$user_name.'</span></div>';
	else
    echo '      <a style="font-size:10px;color:#CFCFCF;" 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="notebook_article.php?id='.$id.'&artid='.$artid.'&page=0&wid='.$hisid.'">'.$commentsnb.' '.lg("comment").'</a>
			</div>
		</div>';
}

if ($page!=0) {
	$previousStr = '<a href="notebook_articles.php?id='.$id.'&page='.($page-10).'">'.lg("page_back").'</a>';
}

if ($page+10<$limit) {
	$nextStr = '<a href="notebook_articles.php?id='.$id.'&page='.($page+10).'">'.lg("page_next").'</a>';
}

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

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

$footer_focus = "network";
if ($id == $_SESSION['user_id']) $footer_focus = "notebook";

echo generate_footer($footer_focus);
?>