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

$artid = $_GET['artid'];
$id = $_GET['gid'];
$owner = $_GET['wid'];
$message = (isset($_GET['message']))        ?       $_GET['message']        :   '';
$ismyprofil = false;

$DB->getResults($mobNotebookArticle_getUserInfo,$DB->escape($_SESSION['user_id']),$DB->escape($owner));
$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);
echo '</div>';

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

echo '<div align="right">
        <a href="groupbook.php?id='.$id.'">'.lg('backToContrib').'</a>
      </div>';      
      
//get Articles access level
if ($_SESSION['user_id'] == $owner) {
	$notebookAccessLevel=1;
}
else {
	$DB->getResults($xmlnotebookprofile_isInNetwork,$DB->escape($owner),$DB->escape($_SESSION['user_id']));
	if ($DB->nbResults()==0) {
		$notebookAccessLevel=3;
	}
	else {
		$notebookAccessLevel=2;
	}
	$DB->freeResults();
}

//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($detail_getGroupArticleInfo,$DB->escape($artid),$DB->escape($id));
$max = $DB->nbResults();
if ($max == 0) {
	echo generate_warning('alert',lg("res_restriction"),'groupbook.php?id='.$id,lg('back'));
    echo "</div>";
    echo "</div>";
	echo generate_footer("group");
	exit();
}
$row = $DB->fetch(0);
$articleStatus = $row['status'];
$articleType = $row['type'];
$title = $row["title"];
$description = $row["description"];
$long_name = $row["long_name"];
$picture = $row["picture"];
$linked_id = $row["linked_id"];
$owner_id = $row["owner_id"];
$pubdate = $row["pubdate"];
$keywords = $row["keywords"];
$dateStr = formatDate(substr($pubdate,0,10),getToday(),getYesterday());
$DB->freeResults();

if ($articleStatus < $notebookAccessLevel) {
	if( $articleStatus == 2 ) {
		$DB->getResults($detail_checkUserInGroup,$DB->escape($_SESSION['user_id']),$DB->escape($artid));
		if ($DB->nbResults()==0) {
			exit('error 1'); 
		}
	} else {
		exit('error 2'); 
	}
}

echo '
	<h2>'.$title.'</h2>
	<div class="item">
		<div class="description">'.$description.'<br /></div>
		<div class="subtitle">'.$disp_kw.'</div>';
if ($owner_id == $_SESSION['user_id'])
echo '		<div class="subtitle">'.$dateStr.', '.lg("by").' <span style="color:grey;font-size:11px;">'.$long_name.'</span></div>';
else       
echo '		<div class="subtitle">'.$dateStr.', '.lg("by").' <a style="color:grey;font-size:11px;" href="network_profil.php?id='.$owner_id.'">'.$long_name.'</a></div>';     
echo '	</div>';

$DB->getResults($detail_getTrackbacks,$DB->escape($artid));
if ($DB->nbResults()!=0) {
		echo'<h2>'.lg("theyTakeThisArticle").'</h2>';
		while ($row = $DB->fetch(0)) {
			echo' <a href="notebook_articles.php?id='.$row["user_id"].'" name="track"><center><big>'.$row["long_name"].'</big></center></a><br>';
		}
}
$DB->freeResults();

//groups trackback		
$DB->getResults($detail_getTrackbacksGroup,$DB->escape($artid));
if ($DB->nbResults()!=0) {
		echo'<h2>'.lg("theyTakeThisArticle").'</h2>';
		while ($row = $DB->fetch(0)) {
			echo' <a href="groupbook.php?id='.$row["group_id"].'" name="track"><center><big>'.$row["name"].'</big></center></a><br>';
		}
}
$DB->freeResults();
        
echo'<a name="commentaire"></a><h2>'.lg("comments").'</h2>';

$DB->getResults($detail_getComments_mobile,$DB->escape($artid));
if ($DB->nbResults()>0) {
	$today = getToday();
	$yesterday = getYesterday();
	while ($row = $DB->fetch(0)) {
		$dateCommentStr = formatDate(getDBDate($row['pubdate']),$today,$yesterday);
		echo '<div class="item" style="clear: both;height: 60px;">
				<img src="../../../'.displayPicture($row['picture']).'" class="avatar" width="50" height="50" style="float: left;margin-right: 5px;">
				<div class="description">'.$row['message'].'</div>
				<div class="subtitle">
					'.$dateCommentStr.', '.lg("by").' <a style="color:grey;font-size:11px;" href="network_profil.php?id='.$row['user_id'].'">'.$row['long_name'].'</a>
				</div>
			</div>';
	}
}
else {
	echo "<span style='margin-left:5px;'>".lg("any_comment_yet").'</span><br />';
}       
?>

<h2><?php echo lg("add_comments");?></h2>
<form method="post" action="scr_notebook_commentadd.php">
    <?php echo lg("ur_mess");?><br /> <textarea rows="4" name="message" style="width: 95%"></textarea><br />
    <input type="hidden" name="artid" value="<?php echo $artid;?>" />
    <input type="hidden" name="title" value="<?php echo $title;?>" />
    <input type="hidden" name="access" value="<?php echo $status;?>" />
    <input type="hidden" name="group" value="<?php echo $id;?>" />
    <input type="hidden" name="wid" value="<?php echo $wid;?>"/><br />
    <input type="submit" value="<?php echo lg("envoyer");?>">
</form>
<br />

<?php	
echo "</div>";
echo "</div>";

echo generate_footer("group");
?>