echo '<table width="100%">'; echo '<tr><td><h3>' . $_GET['num_poems'] . ' uusinta runoa</h3></td>'; echo '<td>'; echo '<a href="rss.php?special=newest"><img src="graphics/rss.gif" class="rss">'; echo '</a></td></tr></table>'; // Get 50 newest poems $cPoem = new CPoem($db, $_SESSION); $cUsers = new CUsers($db, $_SESSION); $poems = $cPoem->getNewestPoems($_GET['num_poems']); echo '<table>'; echo '<tr>'; echo '<td><b>Runoilija</b></td>'; echo '<td><b>Runon nimi</b></td>'; echo '<td><b>Lisätty</b></td>'; echo '</tr>'; $poems_per_page = $cPoem->getPoemsPerPage(); foreach ($poems as $poem) { echo '<tr>'; echo '<td>'; echo '<a href="poet.php?id=' . $poem['user_id'] . '">'; echo $cUsers->getUsername($poem['user_id']); echo '</a>'; echo '</td>'; echo '<td><a href="poet.php?id=' . $poem['user_id']; // Count how many poems this writer has written // since this poem. This is necessary so we can // create link to correct poem even if that poem // is on another page than the first one. $q = 'SELECT COUNT(*) FROM rs_poem WHERE added > "' . $poem['added'] . '" AND user_id=' . $poem['user_id']; try { $ret = $db->query($q);
function show_poems($id) { global $db; require_once 'CPoem.php'; $cPoem = new CPoem($db, $_SESSION); // Poems are splitted in multiple pages if there is too // many poems. If we do not have page number in URL, then // we want to show first page. if (isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } // Get poems. Note! This does NOT return all the poems // at the time. This automatically split results if there // is too many poems in one page. if ($_SESSION['id'] == $id) { $poems = $cPoem->getPoems($id, $page, true); } else { $poems = $cPoem->getPoems($id, $page, false); } $poemsPerPage = $cPoem->getPoemsPerPage(); $last = $poemsPerPage * $page; // Count number of poems. if ($_SESSION['id'] == $id) { $numPoems = $cPoem->numPoems($id, true); } else { $numPoems = $cPoem->numPoems($id, false); } // Was there any poems in database? if (!is_null($poems)) { foreach ($poems as $cur) { // Create unique named DIV so we can create // a href what will jump directly here. echo '<div id="poem_' . $cur['id'] . '">'; $cur['added'] = date('d.m.Y H:i', strtotime($cur['added'])); $cur['poem'] = nl2br($cur['poem']); // If poem title is empty string, then // show "Nimetön runo" as a title. $title = stripslashes($cur['title']); if ($title == '') { $title = '<i>(Nimetön runo)</i>'; } if ($cur['visible'] == '0') { echo '<p class="poem_header_hidden">'; } else { echo '<p class="poem_header">'; } echo $title; echo '</p>'; if ($cur['visible'] == '0') { echo '<p class="poem_hidden">'; } else { echo '<p class="poem">'; } $cur['poem'] = str_replace('<br />', '<br>', $cur['poem']); echo stripslashes($cur['poem']); echo '<p class="poem_added">'; echo $cur['added']; echo '</p>'; // Get comments for this poem. $comments = $cPoem->getComments($cur['id']); $num = count($comments); // If we are browsing our own poems, then we should // add also links where we can remove and // modify those poems. if (isset($_SESSION['id']) && $_SESSION['id'] == $id) { echo '<p class="poem_actions">'; echo '<a href="edit_poem.php?id=' . $cur['id'] . '">Muokkaa</a>'; echo ' / '; echo '<a href="remove_poem.php?id=' . $cur['id'] . '">Poista</a> / '; echo '<a href="hide_poem.php?id=' . $cur['id'] . '&page=' . $_GET['page'] . '">'; if ($cur['visible'] == '1') { echo 'Piilota</a> / '; } else { echo 'Näytä</a> / '; } echo '<a href="#" id="comment' . $cur['id'] . '" class="showComments" onClick="return false;">' . 'Näytä kommentit (' . $num . ')</a>'; echo '</p>'; } else { echo '<p class="poem_actions">'; if (isset($_SESSION['username'])) { echo '<a href="add_comment.php?id=' . $cur['id'] . '&page=' . $page . '">Jätä kommentti</a> / '; } echo '<a href="#" id="comment' . $cur['id'] . '" class="showComments" onClick="return false;">' . 'Näytä kommentit (' . $num . ')</a>'; echo '</p>'; } // Generate unique ID so we can toggle comments // to visible and hidden by this unique ID. echo '<div class="poem_comment" id="poem_comment' . $cur['id'] . '">'; for ($i = 0; $i < $num; $i++) { echo '<p>'; echo $comments[$i]['comment']; echo '<br>'; echo 'Kommentoija: <a href="poet.php?id=' . $comments[$i]['commenter_id'] . '">' . $comments[$i]['username'] . '</a><br>'; echo $comments[$i]['date_added']; } echo '</div>'; echo '</div>'; } echo '<hr>'; echo '<div class="change_page">'; // Count number of poem pages. $numPages = ceil($numPoems / $poemsPerPage); echo 'Sivu ' . $page . ' / ' . $numPages . '<br>'; // Get the correct URL where user should be forwareded // if he/she press "Seuraava" or "Edellinen" link. if (isset($_SESSION['id']) && $_SESSION['id'] == $id) { $url = 'ownpage.php'; } else { $url = 'poet.php'; } // Is "Seuraava sivu" shown? $prevShown = false; // Show link to previous poem page? if ($page > 1) { $prevPage = $page - 1; // Link to prev poem page echo '<a href="' . $url . '?page=' . $prevPage . '&id=' . $id . '">' . 'Edellinen sivu</a>'; $prevShown = true; } // Show link to next poem page? if ($numPoems > $last) { if ($prevShown) { echo ' / '; } $nextPage = $page + 1; // Link to next poem page echo '<a href="' . $url . '?page=' . $nextPage . '&id=' . $id . '">' . 'Seuraava sivu</a>'; } } else { echo '<p class="poem">'; echo 'Yhtään runoa ei löytynyt.'; echo '</p>'; } echo '<br><br>'; echo '</div>'; }