<?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'];
$wid = isset($_GET['wid'])?$_GET['wid']:0;
$message = (isset($_GET['message']))        ?       $_GET['message']        :   '';

if (isset($_GET["id"])) {
	$id = $_GET["id"];
}
else {
	$DB->getResults($detail_getArticleOwner,$artid);
	$row = $DB->fetch(0);
	$id = $row["owner_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();

if (empty($isfriend) && $id!==$_SESSION['user_id'])     $userAL = 3;
if (isset($isfriend))                                   $userAL = '2,3';
if ($id == $_SESSION['user_id'])                        $userAL = '1,2,3';

$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_article.php?id=".$id."&artid=".$artid."&wid=".$wid."");

echo '<div align="right">
        <a href="notebook_articles.php?id='.$id.'">'.lg('backToContrib').'</a>
      </div>';      
      
$DB->getResults($mobNotebookArticle_getArticle,$DB->escape($artid),$userAL,$id);
$max = $DB->nbResults();
if ($max == 0) {
	echo generate_warning('alert',lg("res_restriction"),'notebook_articles.php?id='.$id,lg('back'));
    echo "</div>";
    echo "</div>";
	echo generate_footer("network");
	exit();
}
$row = $DB->fetch(0);
$title = $row['title'];
$status = $row['status'];
$keywords = $row['keywords'];
$description = $row['description'];
$date = getDBDate($row['article_pubdate']);
$type = $row['type'];
$writer_name = $row["long_name"];
$disp_kw = ($keywords == ''?'':'<b>'.lg("tags").':</b>'.$keywords);
$dateStr = formatDate($date,getToday(),getYesterday());

echo '
	<h2>'.$title.'</h2>
	<div class="item">
		<div class="description">'.$description.'<br /></div>
		<div class="subtitle">'.$disp_kw.'</div>';
if ($id == $_SESSION['user_id'])
echo '		<div class="subtitle">'.$dateStr.', '.lg("by").' <span>'.$writer_name.'</span></div>';
else       
echo '		<div class="subtitle">'.$dateStr.', '.lg("by").' <a href="network_profil.php?id='.$wid.'">'.$writer_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();
		
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">';
        if ($row['user_id'] != $_SESSION['user_id'])
        echo '		'.$dateCommentStr.', '.lg("by").' <a style="color:grey;font-size:11px;" href="network_profil.php?id='.$row['user_id'].'">'.$row['long_name'].'</a>';
        else       
        echo '		'.$dateCommentStr.', '.lg("by").' <span>'.$row['long_name'].'</span>';        
        echo '  </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="id" value="<?php echo $id;?>" />
    <input type="hidden" name="title" value="<?php echo $title;?>" />
    <input type="hidden" name="access" value="<?php echo $status;?>" />
    <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("network");
?>