The big task of Period 2 was to make a CMS system. To challenge myself I went for the impossible:
I attempted to make a forum. This really was a big task. I didn’t make it in the end and there was no real ‘content management’ yet. But I did learn a lot in the progress.
There was a friend that wanted a forum for his web-game. So he asked me if I could make it for his webgame. Which made it more fun. He uses ajax in his webgame and he wanted me to use it. I haven’t even heard of ajax and I already started in PHP, but in the end the ajax part was very small for me as my partner gave the ajax-code he made which I could use. I applied that to build the forum.
This forum was also an attempt on object oriented programming.
I learned:
- PDO
- Object Oriented Programming
- What is Ajax and why use Ajax
- PHP Sessions
- Analysing
- Action Plan
- Functional Design
- Technical Design
Here are a few parts of the code to get an idea how I did things at that time.
private function countPosts($bid){ global $db; $query = $db->prepare("SELECT topics.id FROM topics WHERE id_board = '$bid' LIMIT 1"); $query->execute(); $row = $query->fetchAll(); if ($row){ $id = $row[0][0]; $query = $db->prepare("SELECT COUNT(*) FROM topics_posts WHERE id_topic = '$id'"); $query->execute(); return $query->fetchColumn(); } else { return '0'; } }
public function makeBoards($cid){ global $db; $query = $db->prepare("SELECT * FROM boards WHERE id_cat=$cid ORDER BY order_boards ASC"); $query->execute() or die ("error".$db->errorCode()); $return = ""; $color = "0e5980"; foreach ($query->fetchAll() as $row){ $color=="#03406e"?$color="#0e5980":$color="#03406e"; $return = $return."<tr> <td bgcolor=\"$color\" onMouseOver=\"this.bgColor='#4a8bac'\" onMouseOut=\"this.bgColor='$color'\" height=\"50px\"><table id=\"forumInf\" border=\"0px\" OnClick=\"ajaxFunction('ajaxforummain','?goto=topics&bid=".$row['id']."&bname=".$row['name']."')\"> <tr> <td width=\"32px\"><b id='profileMenu'>[img]</b></td> <td width=\"200px\" class=\"left\"><b id='profileMenu'>".$row['name']."</b></td> <td width=\"248px\"><b id='profileMenu'>".$row['description']."</b></td> <td width=\"70px\" class=\"left\"><b id='profileMenu'>".$this->countTopics($row['id'])." Topics</b></td> <td width=\"70px\" class=\"left\"><b id='profileMenu'>".$this->countPosts($row['id'])." Posts</b></td> <td width=\"250px\" ><b id='profileMenu'>Last topic stuff</b></td> </tr> </table></td> </tr>"; } return "<table id=\"forums\" border=\"0px\">".$return."</table>"; }
public function printPages($tname,$tid){ global $db; global $p_posts; global $p_show; global $prefix; global $userTable; isset($_GET['tpage'])?$_GET['tpage']>5?$start=$_GET['tpage']-5:$start=$_GET['tpage']:$start=1; $end = $start+$p_show; $query = $db->prepare("SELECT COUNT(*) FROM ".$prefix."topics_posts"); $query->execute() or die("SELECT COUNT(*) FROM topics_posts"); $aantal = $query->fetchColumn(); $amount = ceil($aantal / $p_posts); // 1st 3 pages $j = "Pages: | "; for ($i=1;$i<=3 && $i <=$amount;$i++){ $j = $j . "<span class=\"page\" onClick=\"ajaxFunction('ajaxforummain','?goto=posts&tname={$tname}&tid={$tid}&page=$i')\">$i | </span>"; } if ($amount <= 5 && $amount > 3){ for ($i=4;$i<=$amount;$i++){ $j = $j . "<span class=\"page\" onClick=\"ajaxFunction('ajaxforummain','?goto=posts&tname={$tname}&tid={$tid}&page=$i')\">$i | </span>"; } } else if ($amount > 5){ $gotoFor = true; $bAmount = 6; $eAmount = $amount; if ($amount == 6){ $j = $j . "<span class=\"page\" onClick=\"ajaxFunction('ajaxforummain','?goto=posts&tname={$tname}&tid={$tid}&page=$i')\">$i | </span>"; $gotoFor = false; } else if ($amount > 10){ $bAmount = ceil($amount / 2 - 3); $eAmount = ceil($amount / 2 + 3); $bAmount < 4?:$gotoFor = false; } for ($i = $bAmount;$i<=$eAmount && $gotoFor;$i++){ $j = $j . "<span class=\"page\" onClick=\"ajaxFunction('ajaxforummain','?goto=posts&tname={$tname}&tid={$tid}&page=$i')\">$i | </span>"; } } echo "<br />".$j; }