Enable guests to post in home page forum?

Enable guests to post in home page forum?

by George Kao -
Number of replies: 14

Hi all,

On our Moodle home page  PresidioWorldCollege.org/moodle I have created a forum called "Guestbook". 

I would like to have visitors be able to go into that forum and post.  How do I do that?

Thank you,

George

Average of ratings: -
In reply to George Kao

Re: Enable guests to post in home page forum?

by Timothy Takemoto -

Dear George Kao

I would like to add a help forum to the homepage of my moodle site too.

But, one of the most common problems that students have is that they cannot log in. And many of them may be too shy to post their problems with their names -- it is a shame culture and all -- so I also would like to be able to allow guests to post to the help forum on the front page of my site. This is quite essential actually. Darn, it is a shame I missed this till now.

There is a demand for anonymous posting here, which is a little different from guests posting.
http://moodle.org/mod/forum/discuss.php?d=5444

I see that at the top of post.php there is

    if (isguest()) {
        error(get_string("noguestpost", "forum"), $_SERVER["HTTP_REFERER"]);
    }

I am going to try removing it! and then we shall see what happens.

Tim

In reply to Timothy Takemoto

Re: Enable guests to post in home page forum?

by N Hansen -
Tim-Perhaps the solution to the shame issue is for someone to work on a forms module, so that there is an easy way for people to email you privately about their problems.

Here in Egypt we have the opposite cultural problem-nobody is afraid to ask questions, but people are ashamed to say they don't know the answer, so they will give you an answer of some kind even if they have to make it up. Doesn't make it easy sometimes when you are asking for directions in the street...
In reply to N Hansen

Re: Enable guests to post in home page forum?

by Timothy Takemoto -

A private module would be a possibility but then I would not be able to ask students to look at previous help questions, which was the reason for having a help forum, rather than doing it by email. If I am going to use forms, I think that I will use email.

I commented out the above lines in mod/forum/post.php but at the moment I have the 1.4 beta guests-can't-login problem, now corrected in 1.4 beta. So I would need to upload that and my server is not all that fast so it takes as while perhaps I can just upload one of the authentication files.

I also realised that even if the above hack works, and guests are allowed to post, then the "post a new discussion" link will not be displayed until they logiin as a guest.

It is now possible apparently to force site visitors to be logged in as a guest as soon as they arrive at the site. But then students who just want to access courses would be unable to do so. And would first have to logout before accessing their course. This is not so difficult but each stage is going to loose a certain percentage of the 670 that I am soon going to have to support.

I might have to hack the forum more so that the post a new discussion link is displayed even if one is not logged in? It would be nice if then it would ask me to log in. And then I could log in as a guest.

Or I could just put my invision board to good use.

Tim

In reply to Timothy Takemoto

Re: Enable guests to post in home page forum?

by Ger Tielemans -

You could put a button to send you email on the frontpage, and then "rework" the question with your answer in the public read-forum on the frontpage.

(Or even better: The Questions modul from Jon with the FAQ-engine could be installed?)

In reply to Ger Tielemans

Re: Enable guests to post in home page forum?

by W Page -
Hi Ger!

Where is "Questions modul from Jon with the FAQ-engine"??

WP1
In reply to Ger Tielemans

Re: Enable guests to post in home page forum?

by Timothy Takemoto -
Thanks for your suggestions Ger,

But I am afraid I don't like the idea of having to rework a lot of emails. I don't see the Question Module on the downloads site. I think that I would like to stick to fairly standard modles. And that may rule out the "Question Module")

Tim
In reply to Ger Tielemans

Guestbook

by Timothy Takemoto -

I have updated to 1.4 stable and guests can now log in.

And, I realise that my "help forum" is basically, a guestbook, bascially I need a guestbook.

So...returning to the orginal problem. What do I need to do to enable forum posing for guests?

1) Make the above change to post.php to enable guests to post by commenting out?

//  Timothy Takemoto is going to see if it is possible to allow guests to post to forums.
//    if (isguest()) {
//        error(get_string("noguestpost", "forum"), $_SERVER["HTTP_REFERER"]);
//    }

2) But what do I need to do to make the "post a new discussion" appear for guests as well?

I see that in mod/forum/lib.php there is the following.

function forum_user_can_post_discussion($forum, $currentgroup=false) {
// $forum is an object
    global $USER;

    if ($forum->type == "eachuser") {
        return (! forum_user_has_posted_discussion($forum->id, $USER->id));
    } else if ($forum->type == "teacher") {
        return isteacher($forum->course);
    } else if ($currentgroup) {
        return (isteacheredit($forum->course) or (ismember($currentgroup) and $forum->open == 2));
    } else if (isteacher($forum->course)) {
        return true;
    } else {
        return ($forum->open == 2);
    }
}

I could not work out why the first "eachuser" type forum returned FALSE if the user has already posted but at last realised that there is a type of forum which allows one post from each user!

How about if instead there were an extra type of forum where everyone can post -- basically a guestbook.

    if ($forum->type == "guestbook") {
    return true; 
    }
else if ($forum->type == "eachuser") {
        return (! forum_user_has_posted_discussion($forum->id, $USER->id));
    }

Then at some time in the future, I can try and add that option to the GUI but for the time being, I can add "guestbook" directly into the forum row in the database, perhaps.

Okay, assuming that I have created this new forum type then, in post.php it would be safer to have

//  Timothy Takemoto is going to see if it is possible to allow guests to post to "guestbook" type forums. 

 if (!($forum->type == "guestbook") && (isguest()) ){
       error(get_string("noguestpost", "forum"), $_SERVER["HTTP_REFERER"]);  }

I will try that. 

No... I can't  add "guestbook" to the database so easily because the type is specified using a drop down menu in PHP MYSQL . I see that there is this in the db folder. I guess I could add an extra entry.

    execute_sql("ALTER TABLE `forum` CHANGE `type` `type` ENUM( 'single', 'news', 'social', 'general',
                             'eachuser', 'teacher', 'guestbook' ) DEFAULT 'general' NOT NULL ");

But I think that I will use "social" forum. I don't  even know what a social forum is, there are none others in my database, so for the time being a social forum will become a guestbook.

to lib.php

    if ($forum->type == "social") {
    return true; 
    }
else if ($forum->type == "eachuser") {
        return (! forum_user_has_posted_discussion($forum->id, $USER->id));
    }

to post.php

 if (($forum->type != "social") && (isguest()) ){
       error(get_string("noguestpost", "forum"), $_SERVER["HTTP_REFERER"]);  }

The first change works (I can now see the "post discussion" link as guest), but the change to post.php is not working. If I just edit out the if isguest() line then I get another error message. But it would seem that post.php is not passed forum$ since the above does not work.  It seems that post.php is called in post.html. But I can't find what variables post.php is passed.  I assume that it is passed at least $post.

I tried adding a

      $forum = get_record("forum", "id", $post->forum);

before the if statement but it did not change things.

But if I hardcode the id of the forum

      $forum = get_record("forum", "id", 23);

Then the above does work, but I get an error message saying "incorrect forum number"

Tim

In reply to Timothy Takemoto

Re: Guestbook

by W Page -
Hi Timothy,

Why not just request a "GuestBook" as a feature?

WP1

In reply to W Page

Re: Guestbook

by Timothy Takemoto -

Dear WP1,

Well...Moodle is open source. If I can't do this, then I will. But then again since my php is so poor perhaps I should not bother to try. Or at least in public.

Perhaps i am hoping someone will take pity. Things are progressing though. Please see below.

Progress.

It seems that post.php is passed variables from a form via "data_submitted()" so it is not untill the first of the lines below, that post.php fill the $post varible.

    if ($post = data_submitted()) {  // $post gets its contents at this point.
        if (!empty($post->course)) {
            if ($course = get_record('course', 'id', $post->course)) {
                if (!empty($course->lang)) {
                    $CFG->courselang = $course->lang;
                }
            }
        }

It is only after the $post=data_submitted() that $post is filled, so it is only after tha point that we can get the forum id from $post->forum, and then get the forum type from $forum->type.

If I wait till $post is filled, and then fill $forum, then I can at last test to see if this is a social type forum. The below succeeds in performing that tests, but both $post and $forum will be filled with stuff that they should not be filled with if this is a guest trying to post to a non social forum. I wonder if there is a flush($post); flush($forum) command?

//  Timothy Takemoto is going to see if it is possible to allow guests to post to "social" type forums.

//     optional_variable($f);             // Forum ID  I tried this but $f is not available.
      if ($post->forum) {

       if (! $forum = get_record("forum", "id",  $post->forum)) {
            error("Forum ID was incorrect or no longer exists");
       }
     } else {
         error("There does not seem to be a variable  $post->forum");
      }  
     if (isguest() && ($forum->type != "social")){
               error(get_string("noguestpost", "forum"), $_SERVER["HTTP_REFERER"]);  }

// End of my addition. I have also commented out the line two lines that correspond to the last two lines in this "addition" further up.  

Now the error message that is displayed is "(Main default course of your site id=1) does not allow guests to enter"  I do not see where I can change this using the GUI. I do not have "force login" on. But I can change this in the Database by changing guest to 1.

And yes, presto, it seems that guests can now post.
http://ds21.cc.yamaguchi-u.ac.jp/~eigo/moodle/mod/forum/post.php?forum=23

Of course, other guests will be able to edit each others' posts. I think that I should change it so that guests users are not allowed to edit or delete. To do that it seems fair that one must login.

And the whole world will be able to comment spam my guest book.

But other than that...

What are the dangers of the fact that I have not flushed $post and $forum above (when a guest tries to send a post to a non-social forum)?

Are there any other horrors of the above script?

I have just noticed one. The GUESTUSER does not have a mail address. What happens when the cron fires and Moodle attempts to send mail to GUESTUSER? I will find out soon.

Tim
Takemoto
Ps, why is the "m" removed from my name in mails from the forums? Will the question mark be removed from this sentence?

In reply to Timothy Takemoto

Re: Guestbook

by Timothy Takemoto -
I spoke too soon. It seems that I can post too all the forums on my site as a guest using the above addition, even though most of the forums are general forums and there are no other "social forums". Strange.
In reply to Timothy Takemoto

Re: Guestbook

by Timothy Takemoto -

The above is dross. The reason why a guest user can now seem to post to all forums is because I put the the check to see whether the user is a guest or not after

if ($post = data_submitted()) {  // $post gets its contents at this point.

which is of course, the point when the user makes the post! Durr.

The problem is that before the data_(is)_submitted I do not seem to be able to access the required information ($forum->type) within post.php.

There are various ways that this could be achieved. View.php seems to be using a variable $f which contains the forum id. I am not sure where this value is coming from but view.php is getting it in that way. Or it might be possibe to use the session variables but...I guess sessions can time out? It does not seem to be done that way.
 

I tried using optional_variable($f) but $f is 0
I tried using require_variable($f) but this crashed.

Hmm...



In reply to Timothy Takemoto

Re: Guestbook

by Timothy Takemoto -

Moodle variables are often passed using "require_variable" and "optional_variable"

I also tried adding both
optional_variable($f)
and
require_variable($f)
to the file that calls post.php i.e. post.html
<?php require_variable($f); ?>
<?php optional_variable($f); ?>
together with both
optional_variable($f)
require_variable($f)
in post.php but optional variably results in a $f value or zero and require_variable($f) results in an error that says a that a parameter is missing.

In reply to Timothy Takemoto

Re: Guestbook

by Timothy Takemoto -

Well I completely gave up on trying to pass variables.

Here is how I seem to have added a guestbook.

1) comment out the lines
//     if (isguest()) {
//         echo "f is $f";
//         error(get_string("noguestpost", "forum"), $_SERVER["HTTP_REFERER"]);
//     }

from the top of mod/forum/post.php

2) Add the lines
    global $USER;
    if ($forum->type == "social") {
    return true;
    } else if ($forum->type == "eachuser") {
// and edit out the next line from around 2308 of mod/forum/lib.php
//    if ($forum->type == "eachuser") {

The above is not working as it should. It was designed to limit guests users to "social forums" but it seems that guests are able to post to either of three types of forum.

Since all the courses at my site are not open to guests, guests will only be able to post to the forums on the front page. And the only forum on the front page is the guest book.

So the above seems to work. If anyone would be kind enough to improve this, tell me why it works, or why it is going to do really bad things to my installation I will be very grateful. But a guestbook was a must.
Timothy