Forums: Forum template - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Forum template

#1 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 15495
  • Joined: 03-February 03

Posted 24 March 2010 - 01:43 AM

A few people asked how you can build a forum with PHPRunner. To illustrate this we have built very basic forum template that you can use, study, modify etc.

Forum template for PHPRunner 5.x/6.x download link.

For PHPRunner 7.x or better download it from our marketplace.


Unzip it to <Directory where PHPRunner installed>\templates\business. Then create a new project choosing Forum template from list of templates on the left.

This template is for PHPRunner at the moment. You also need to have CKEditor plugin installed in order to use this template.

A few words on how this forum works. Guest users are able to browse topics. To post a new topic or answer existing one you need to register. No threads or posts can be deleted. Users can edit their own posts though. Admin area and other potentially useful stuff were omitted for the sake of brevity.

Now the tricky part. When new topic is created we need to add a record to both Threads and Posts tables. Another trick is to make search function to search across both threads and posts.

1. Database
We have three tables here.
Users - serves as a login table
Threads - stores general thread info
Posts - stores actual posts

Threads and Posts are related as Master-Details.

Posted Image

2. SQL Query

Add a new dummy field to the SQL Query of Threads table. We are going to need this field on thread add page.

SELECT
title,
description,
startedby,
ID,
'' AS post
FROM threads


3. Pages and fields

Uncheck pages and fields we don't need.

4. Security screen

Turn on login page. Users table, username/password fields. Under User Login Settings enable options that make sense for this app.

Under Advanced Security settings enable Guest login and choose 'Users can see other users data; can edit their own data only' mode for posts table (users can edit their own posts). Use ID from Users table and userid from posts table to create a link.

5. Choose theme

Pick one of themes with search box on the top. We decided that Madrid will work the best for this application.

6. Visual Editor

We'll need to modify list pages of Threads and Posts tables to make it visually appealing.

- Threads list page
Remove unnecessary buttons, rename labels (records->threads), add new grid column named 'Stats' and drag number of child records (posts) there.

Now we need to make Title link to posts page. Set 'View as' format to 'Custom' and enter the following code there:

$value = "<a href='posts_list.php?mastertable=threads&masterkey1=".$data["ID"]."' style='font-size: 120%'>".$value."</a>";


You might ask where this fancy URL came from. Before I started making changes in Visual Editor I built this app and went to Threads list page. A typical link to details page looks like posts_list.php?mastertable=threads&masterkey1=1. I replaced 1 with $data["ID"] and made it look more prominent (style='font-size: 120%').

A few final touches. Increase row height a bit to make the list of topics more readable. Drag 'Description' field to 'Topic' column and change font color to grey. Remove grid columns you no linger need.

Rename 'Add new' button to 'Start new topic'. To make this button appear on the left switch to HTML mode and find style descriptions in the beginning of the file.
Make #recordcontrols_block look as follows:

#recordcontrols_block{$id} {padding:13px 10px 9px 10px;text-align:left}



Posted Image

- Posts list page

Rearrange fields in similar fashion and remove unnecessary grid columns.

Now we need to pull 'title' and 'description' fields from corresponding Threads record. Put mouse cursor into grid header row, switch to HTML mode and insert two placeholders there separated by space:

{$topic} {$description}


When you switch back to visual mode you can see those placeholders appear as yellow rectangles.

Rename 'Inline add' button to 'Add Reply' and move it to the left modify #recordcontrols_block description in HTML mode the same way we did it on Threads list page.

Posted Image

- Threads add page

Double-click on 'Message' field and set 'Edit as' format to 'Textarea'. Choose CKEditor from the list of Rich Text Editors.

7. Events.

Now the fun part.

- AfterSuccessfulLogin event

We need to save ID from users table in session variable and redirect user to Threads list page.

$_SESSION["ID"]=$data["ID"];
header("Location: threads_list.php");
exit();


- Posts table: BeforeDisplay event

Remember those 'title' and 'description' placeholders we added on posts list page. Now it's the time to populate them using $_REQUEST["masterkey1"] as a pointer to record in master table (Threads).

$rs = CustomQuery("select * from threads where id=".$_REQUEST["masterkey1"]);
$data = db_fetch_array($rs);
$xt->assign("topic", $data["title"]);
$str = "<span style='font-weight: normal'>".$data["description"]."</span>";
$xt->assign("description", $str);


Values in grid header row will appear bold on the page so we change font weight to normal for description field.

- Posts table: Before record added event

We want to timestamp each reply automatically and populate 'userid' field with ID value from Users table (saved in AfterSuccessfulLogin event).

$values["created"] = now();
$values["userid"] = $_SESSION["ID"];

return true;


- Threads table: BeforeRecordAdded event

The value of dummy field 'post' needs to be saved in session variable as we need to add it to Posts table. Since 'post' is a dummy (non-existent) field we need to remove it from the list of fields to be inserted using unset($values["post"]).

$values["startedby"]=$_SESSION["ID"];

$_SESSION["post"] = $values["post"];
unset($values["post"]);

return true;


- Threads table: AfterRecordAdded event

Now we can add a record to Posts table linking it to the Thread we just created.

global $dal;
$posts = $dal->Table("posts");
$posts->threadid = $keys["ID"];         // thread ID  
$posts->message = $_SESSION["post"];    // message we saved in session variable  
$posts->created = now();                // timestamp 
$posts->userid = $_SESSION["ID"];       // ID from users table
$posts->Add();



If we want to redirect user to another page after new topic was created - we need to do so in this event as well. Right now user stays on the same 'Start New Topic' page.


- Threads page: BeforeSQLQuery event

And the last step - we need to tweak search function a bit so it can search threads title and description fields as well as posts.

IF statement makes sure this code executed only when we run search. We run search on JOIN query and then return a list of thread IDs that match our criteria.

if (@$_REQUEST["a"]=="integrated" && @$_REQUEST["ctlSearchFor"])
{

$strWhereClause = " id in (SELECT distinct threadid FROM threads inner join `posts` on
threads.id=posts.threadid
WHERE message like ('%".$_REQUEST["ctlSearchFor"]."%') or title like ('%".$_REQUEST["ctlSearchFor"]."%')
or description like ('%".$_REQUEST["ctlSearchFor"]."%'))";

}


This is it. You can build it now and run it in the browser.

Posted Image

As a next step you can add an admin area, give admin permissions to rename/delete topics, add mass email capabilities, add CAPTCHA etc. It also makes sense to allow users edit their own data i.e. change email address.

You are welcome to post questions and suggestions for the next version. If someone wants to take this template to the next level - we'll be glad to provide all required assistance including posting updated versions of template here.
Best regards,
Sergey Kornilov
0

#2 User is offline   titanic 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 34
  • Joined: 10-December 09

Posted 25 March 2010 - 07:13 AM

excellent... this tutorial will reduce the questions in future..
0

#3 User is offline   mike_ceb 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 48
  • Joined: 27-January 10

Posted 25 March 2010 - 01:46 PM

Excellent :)
Thanks,-Mike
PHPRunner 6.1
0

#4 User is offline   Kabukiblood 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 11-February 10

Posted 25 March 2010 - 03:54 PM

Hello,

So I installed this template, verified all information was correct, built it, but when I click New Topic I get the following error.


php error happened

Technical information
Error type 2
Error description include(plugins/ckeditor/ckeditor.php) [function.include]: failed to open stream: No such file or directory
URL localhost/forum/threads_add.php?
Error file C:\wamp\www\Forum\threads_add.php
Error line 844
SQL query

Any help would be greatly appreciated.
0

#5 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 15495
  • Joined: 03-February 03

Posted 25 March 2010 - 05:26 PM

Kabukiblood,

make sure CKEditor plugin is installed. Check 'Rich Text Editor plugins' topic in PHPRunner manual for more info.
Best regards,
Sergey Kornilov
0

#6 User is offline   Kabukiblood 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 11-February 10

Posted 25 March 2010 - 06:01 PM

View Postadmin, on 25 March 2010 - 10:26 AM, said:

Kabukiblood,

make sure CKEditor plugin is installed. Check 'Rich Text Editor plugins' topic in PHPRunner manual for more info.


Thank you I am checking that now
0

#7 User is offline   Mark Wilson 

  • Member
  • PipPip
  • Group: Members
  • Posts: 20
  • Joined: 14-June 09

Posted 03 May 2010 - 05:00 PM

Any news on when we will see this for ASPrunner 6.2 for access?
0

#8 User is offline   Steve Billett 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 13-October 08

Post icon  Posted 30 September 2010 - 03:31 PM

Hi

You were asked in May 2010 when the ASPrunner Version would be ready, Any News??

I am am sure a man like you could knock it up in five minutes and make us all :rolleyes: happy :rolleyes:
0

#9 User is offline   Boguslaw 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 04-March 11

Posted 27 April 2011 - 07:09 PM

Welcome.
I tried several times to run the forum template PHPRunner 5.3 and each time it ended in failure. Please help where is the problem. I copied the unzipped files to a specified directory and does not appear in the window of the templates.
Thank you for your help.

Boguslaw
0

#10 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 15495
  • Joined: 03-February 03

Posted 28 April 2011 - 01:08 PM

Boguslaw,

you need to contact support directly sending a screenshot that shows where you have installed this template on your system.
Best regards,
Sergey Kornilov
0

#11 User is offline   mitzi 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 55
  • Joined: 02-December 12

Posted 21 December 2012 - 06:24 PM

admin said:

We'll have ASP version shortly along with step-by-step video tutorial. You also need to have CKEditor plugin installed in order to use this template.


Do you have it available already for the ASPrunner,please?
0

#12 User is offline   Tandy Services 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 43
  • Joined: 03-January 16

Posted 06 April 2016 - 07:35 AM

I have bought the New Forum Template 2 months ago.. When will the new Template be released?

Thank You.
0

#13 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 15495
  • Joined: 03-February 03

Posted 19 April 2016 - 02:27 PM

@Tandy Services,

Forum template was released, please logon to your Marketplace account and download it.
Best regards,
Sergey Kornilov
0

#14 User is offline   Tandy Services 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 43
  • Joined: 03-January 16

Posted 19 April 2016 - 08:51 PM

Thank you Sergey..
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic