Skip to content

Commit

Permalink
add comments to pdf generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas CARPi committed Mar 24, 2014
1 parent 47ee8ca commit 2ed9bb7
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,36 @@ function make_pdf($id, $type, $out = 'browser')
}
$req->closeCursor();

// SQL to get comments
// check if there is something to display first
// get all comments, and infos on the commenter associated with this experiment
$sql = "SELECT * FROM experiments_comments
LEFT JOIN users ON (experiments_comments.userid = users.userid)
WHERE exp_id = :id
ORDER BY experiments_comments.datetime DESC";
$req = $pdo->prepare($sql);
$req->execute(array(
'id' => $id
));
if ($req->rowCount() > 0) {
$comments_block .= "<section>";
if ($req->rowCount() === 1) {
$comments_block .= "<h3>Comment :</h3>";
} else {
$comments_block .= "<h3>Comments :</h3>";
}
// there is comments to display
while ($comments = $req->fetch()) {
if (empty($comments['firstname'])) {
$comments['firstname'] = '[deleted]';
}
$comments_block .= "<p>On ".$comments['datetime']." ".$comments['firstname']." ".$comments['lastname']." wrote :<br />";
$comments_block .= "<p>".$comments['comment']."</p>";

}
$comments_block .= "</section>";
}

// build content of page
$content = "<h1>".$title."</h1><br />
Date : ".$date."<br />
Expand Down Expand Up @@ -636,13 +666,12 @@ function make_pdf($id, $type, $out = 'browser')
$content .= "</ul></section>";
}

// Comments
// SQL to get comments
$sql = "SELECT * FROM comments";

// Add comments
$content .= $comments_block;
// ELABID and URL
$content .= "<br /><p>elabid : ".$elabid."</p>";
$content .= "<p>URL : <a href='".$full_url."'>".$full_url."</a></p>";

} else { // ITEM
if ($out === 'browser') {
$url = str_replace('make_pdf.php', 'database.php', $url);
Expand All @@ -654,6 +683,7 @@ function make_pdf($id, $type, $out = 'browser')
}



// Generate pdf with mpdf
require_once 'lib/mpdf/mpdf.php';
$mpdf = new mPDF();
Expand Down

0 comments on commit 2ed9bb7

Please sign in to comment.