PDA

View Full Version : groups


giants10
04-22-2008, 12:36 AM
when a user wants to create a group or something on a website, how would you write the code to process the request and give them the same features that other groups have?

Inigoesdr
04-22-2008, 04:29 AM
This question is pretty ambiguous; it depends on what you mean. You should do some research, and maybe look at the source code for other projects that have something similar to what you're after.

giants10
04-23-2008, 03:07 AM
how would you store group information on a database? also how do you create a general group layout and have a moderator in charge of the entire group?

mjlorbet
04-23-2008, 03:11 AM
create a table that contains the id of the group, the group's name, and the moderator of the group

create another table that contains the id of the group, and any other information you need

this is so you can join the two tables on the id if you need to locate the name and moderator of the group per dataset without having to store the same information repedatively in the same table

giants10
04-23-2008, 03:33 AM
i get that, that makes sense. lets just say i want to create a group and it had a forum in it. how would i store the information from a forum. also when your dealing with a chatroom, do you need a database for that?

mjlorbet
04-23-2008, 03:47 AM
it's quick and simple that way

Table 1 (Forums):
ForumID
ForumName
ParentForumID
ModeratorName

Table 2 (Threads):
ForumID
ThreadID
ThreadTitle
ThreadMakerID

Table 3 (Users):
UserID
UserName
UserPassword
Avatar
PostCount
ThankCount
Reputation

Table 4 (Posts):
ThreadID
PosterID
PostBody (make sure to protect against injection in this one)


Select ThreadTitle, UserName From Forums
INNER JOIN Threads ON
Forums.ForumId = Threads.ForumId
INNER JOIN Users ON
Threads.ThreadMakerID = Users.UserID
WHERE Forums.ForumName = "C#"

would return the title of each thread and the creator of the thread inside the C# forum

mjlorbet
04-23-2008, 04:06 AM
since this topic is cross-posted and i've given a template for the database tables in the other post, i'd say something like


INSERT INTO Forums SET (ThreadMakerID, ThreadTitle, ForumID) VALUES (yourvalue, threadtitle, ForumID)


i forget the actual factual syntax (possibly), but that'd be about the extent of it, assuming that the id of the thread of itself is set as an auto-incrementing primary key, and that you've stored the ThreadMakerID (id of the current user) in a session state variable or something along those lines

giants10
04-23-2008, 04:26 AM
i get it so pretty much the group information in the database will be based by the id number. one thing though, how do you set the privileges for a moderator in code?
also, the group layout like the forum and the chatroom how would you set each group to have a design like that?

mjlorbet
04-23-2008, 04:44 AM
<? if($_GroupModId == $_UserId){ ?>
<input id="modbtn" type="button" value="Only mods can see this button" />
<?}?>


where you've stored the id of the moderator from the forums table in $_GroupModId (this would be necessary for the lookup of the name of the forum, which they would be vieing presently) and the id of the current user as $_UserId (a session scoped variable). basically you're not setting permissions like on the file system where you can set read-only and such, you're just giving extra elements for that user to work with that can do things that would not be available to normal users.

so, for example, in the above code, you could have the button populate a hidden field and post a form so that a particular thread would be removed from a forum, or a post from a thread, and such like that. if you're worried about normal users hacking this, you can validate the poster's id against the user registered as the moderator for the group in question before executing the action specified.

<form id="modact" action="modperms.php" method="post">
<input type="hidden" value="" id="modaction" />
<input type="hidden" value="<?=$_UserId?>" id="postinguser" />
</form>
<script type="text/javascript">
function dokillthread(){
document.getElementById("modaction").value = "kill|thread|<?= $_ThisThreadId ?>";
document.getElementById("modact").submit();
}
document.getElementById("modbtn").onclick = dokillthread;
</script>

would bind to that button and submit a command to kill the thread with the id specified by $_ThisThreadId

on the php side you'd use explode (i think) on the post parameter modaction against the vertical bar |, check on the first parameter, if it's kill then go through the checks for things you can kill on the second parameter, if it's thread, look at for the third parameter for the id of the thread to kill, then use DELETE * FROM Threads WHERE ThreadID = $_TheThirdParameter on the database to remove the entry for the thread, you also may want to remove the posts that accompany the thread

DELETE * FROM Posts WHERE ThreadID = $_TheThirdParameter

giants10
04-23-2008, 04:56 AM
your the man. so pretty much you would set the pages to match the modID with the userID and set the privileges based on the number alone.

another question sorry to bother you.

lets just say any user can create their own group. they would automatically become a moderator. now every group would have like a forum. what kind of a script would you need to create a forum just based on the group name. where would you store all the posts and group information, in a separate folder?:

kbluhm
04-23-2008, 05:05 AM
Folder? That is MySQL man. A database server. No folders involved. Now, a separate table? Yes.

mjlorbet
04-23-2008, 05:06 AM
Create the forum
INSERT INTO Forums SET ModeratorID=$_UserID, ForumName=$_SpecifiedName

Create the thread
INSERT INTO Threads SET ThreadName=$_SpecifiedName, OriginalPosterId=$_UserId, GroupId=$_GroupId

Store a post
INSERT INTO Posts SET ThreadName=$_ThisThreadId, PosterId=$_UserId, PostBody=$_ThisPost

Inigoesdr
04-23-2008, 05:32 AM
giants10, do not crosspost again. If you do, you will be banned since you already have multiple infractions and it would put you over the limit.

giants10
04-23-2008, 06:44 AM
i kno im a very bad man.. i like to live life dangerously