phpDocumentor koliportal
[ class tree: koliportal ] [ index: koliportal ] [ all elements ]

Source for file forum_topiclist.php

Documentation is available at forum_topiclist.php

  1. <?php
  2. /** A fórum témáit megjelenító kódok
  3. * @package koliportal
  4. * @author Karakó Miklós <palacsint_X_freemail.hu>
  5. * @copyright Copyright &copy; 2005, Karakó Miklós
  6. */
  7. if (isset($_POST["newtopic"]) && isset($_POST["title"]))
  8. {
  9. $errc = 0;
  10. $title = trim($_POST["title"]);
  11. if (false === check_login())
  12. {
  13. forum_msg("Csak bejelentkezett felhasználó hozhat létre új témát!", FORUM_ERR);
  14. $errc++;
  15. }
  16.  
  17. if ((0 === $errc) && (strlen($title) < 4))
  18. {
  19. forum_msg("Rövid a megadott témanév!", FORUM_ERR);
  20. $errc++;
  21. }
  22. if (0 === $errc)
  23. {
  24. $sql_q = "SELECT tid FROM topics WHERE title LIKE '$title'";
  25. $sql_res = mysql_query($sql_q, $database);
  26. if ((false === $sql_res))
  27. {
  28. forum_msg("Az új téma létrehozása nem sikerült!", FORUM_ERR);
  29. mylog(sprintf("forum - newtopic: %s", mysql_error()));
  30. $errc++;
  31. }
  32. }
  33.  
  34. if (0 === $errc)
  35. {
  36. $arr = mysql_fetch_assoc($sql_res);
  37. if ((false !== $arr) && (is_numeric($arr["tid"])))
  38. {
  39. forum_msg(sprintf('Már létezik <i><a href="%s?page=%s&amp;tid=%d">%s</a></i> címmel egy téma.',
  40. $_SERVER["PHP_SELF"], $page, $arr["tid"], stripslashes($title)), FORUM_MSG);
  41. $errc++;
  42. }
  43. unset($arr); // később nehogy galibát okozzon
  44. }
  45. if (0 === $errc)
  46. {
  47. $uid = $_SESSION["sid"];
  48. if (!is_numeric($uid))
  49. {
  50. forum_msg("Belső hiba!", FORUM_ERR);
  51. // FIXME: ezt vhogy általánossá kellene tenni
  52. }
  53. $title = addslashes($title);
  54. $sql_i = "INSERT INTO topics (title, cuid, ct)
  55. VALUES ('$title', '$uid', CURRENT_TIMESTAMP)";
  56. $sql_res = mysql_query($sql_i, $database);
  57.  
  58. if ((false === $sql_res))
  59. {
  60. forum_msg("Az új téma létrehozása nem sikerült!", FORUM_ERR);
  61. mylog(sprintf("forum - newtopic: %s", mysql_error()));
  62. $errc++;
  63. }
  64. }
  65. if ((0 === $errc) && (1 !== mysql_affected_rows($database)))
  66. {
  67. forum_msg("Az új téma létrehozása nem sikerült!", FORUM_ERR);
  68. mysqlog(sprintf("forum - newtopic2: %s", mysql_error()));
  69. $errc++;
  70. }
  71. if (0 === $errc)
  72. {
  73. forum_msg("Az új téma sikeresen létrehozva.", FORUM_MSG);
  74. }
  75. }
  76.  
  77. ?>
  78.  
  79. <p><a href="<?= SERVER_ROOT ?>forum-rss.php">rss feed</a>
  80.  
  81. </p>
  82. <form action="<?= $_SERVER["PHP_SELF"] ?>?page=<?= $page ?>" id="nt_form" method="post">
  83.  
  84. <table id="topics">
  85. <tr>
  86. <th>téma</th>
  87. <th>hozzászólások</th>
  88. <th>utolsó hozzászóló</th>
  89. <th>utolsó hozzászólás</th>
  90. <th>létrehozva</th>
  91. <th>létrehozta</th>
  92. </tr>
  93.  
  94.  
  95. <?php
  96. // FIXME:
  97. //
  98. /*
  99. SELECT DISTINCT t1.title, t1.tid,
  100. CASE WHEN p1.dt is NULL THEN t1.ct ELSE p1.dt END AS lastmsg,
  101. CASE WHEN p1.postid is NULL THEN t1.cuid ELSE p1.uid END AS lastuid
  102. FROM topics AS t1
  103. LEFT OUTER JOIN posts AS p1
  104. ON (p1.tid = t1.tid)
  105. ORDER BY lastmsg DESC;
  106. */
  107.  
  108. /*
  109. LEFT JOIN-al hozzácsapjuk minden topichoz az utolsó hozzászólását
  110. az ord_lastmsg segít sorrendezni az eredménytáblát, értéke:
  111. - ha van hozzászólás az adott topichoz, akkor az utolsó hozzászólás ideje
  112. - ha nincs hozzászólás, akkor a topic létrehozásának ideje (CASE)
  113. */
  114. $sql_q = "
  115. SELECT DISTINCT t1.title, t1.tid, p1.dt AS lastmsg, p1.uid AS lastuid,
  116. t1.ct AS ct, t1.cuid AS cuid,
  117. (SELECT count(*) FROM posts AS p4temp WHERE p4temp.tid = t1.tid) AS msgcount,
  118. CASE WHEN p1.dt is NULL THEN t1.ct ELSE p1.dt END AS ord_lastmsg
  119.  
  120. FROM topics AS t1
  121. LEFT OUTER JOIN posts AS p1
  122. ON (p1.tid = t1.tid
  123. AND p1.postid = (SELECT max(p3temp.postid) FROM posts AS p3temp WHERE p3temp.tid = t1.tid)
  124. )
  125. ORDER BY ord_lastmsg DESC
  126. ";
  127.  
  128. //$sql_q = "SELECT * FROM topics ORDER BY lastmsg DESC LIMIT 20";
  129. $t_res = mysql_query($sql_q, $database)
  130. or myerr(ERROR_DB, $sql_q); // FIXME: hibakezelés
  131. while ($t_arr = mysql_fetch_assoc($t_res))
  132. {
  133. $last_st_name = get_student_name($t_arr["lastuid"]);
  134. if ('nem' == $last_st_name) $last_st_name = '';
  135. ?>
  136. <tr>
  137. <td><a href="<?= $_SERVER["PHP_SELF"] ?>?page=<?= $page ?>&amp;tid=<?= $t_arr["tid"] ?>"><?= $t_arr["title"] ?></a></td>
  138. <td><?= $t_arr["msgcount"] ?></td>
  139. <td><?= $last_st_name ?></td>
  140. <td><?= $t_arr["lastmsg"] ?></td>
  141. <td><?= $t_arr["ct"] ?></td>
  142. <td><?= get_student_name($t_arr["cuid"]) ?></td>
  143. </tr>
  144.  
  145. <?php
  146. }
  147. if (true === check_login())
  148. {
  149. ?>
  150.  
  151.  
  152. <tr>
  153. <th colspan="3">Új téma: <input type="text" name="title" value="" /></th>
  154. <th><input type="submit" value="Létrehoz" /></th>
  155. <th colspan="2">
  156. <input type="hidden" name="newtopic" value="newtopic" />
  157. </th>
  158. </tr>
  159.  
  160.  
  161. <?php
  162. }
  163. ?>
  164. </table>
  165.  
  166. </form>

Documentation generated on Wed, 18 May 2005 19:24:21 +0200 by phpDocumentor 1.3.0RC3