Can anybody help..please..I am really tired!!!

Can anybody help..please..I am really tired!!!

by Mohammed Shamshad -
Number of replies: 14
Hi there,

Can anybody help me how to hide the All courses button in the homepage of users.I tried to hide it by enabling the hide all courses option in modules/courses.But it affects only for the admin user for the rest of the others it is still visible.I also tried to enable my moodle and it is not functioning properly.Somehow i want tongueout to hide the all courses button in the homepage as i want only the students to see the courses only to which they have enrolled.The moodle version is given below.
Moodle 1.9 + (Build: 20080402)

Regards
Mohammed Shamshadtongueouttongueout
Average of ratings: -
In reply to Mohammed Shamshad

Re: Can anybody help..please..I am really tired!!!

by Mauno Korpelainen -
I haven't tested if it still works but http://moodle.org/mod/forum/discuss.php?d=61336
Average of ratings: Useful (1)
In reply to Mauno Korpelainen

Re: Can anybody help..please..I am really tired!!!

by John White -
Mohammed & Mauno,

I too looked at that thread to see if there was a neat answer to Mohammed's question, and I thought: that's anything but neat!

So I think I have found an alternative answer, but it raises a different question which I will place in the General Developers Forum instead of just tacking it on here!

So, my suggested answer (which I have only tested in 1.9.1)...

Firstly look in your Moodle HTML directory (moodle19, or public_html perhaps) and open config.php in an editor (Ultraedit, perhaps?)

In config.php, after $CFG->prefix = 'mdl_';, add the following:

$CFG->block_course_list_hideallcourseslink = true;
$CFG->course_lib_hideallcourseslink = true;
$CFG->course_lib_hidesearchbox = true;

Save the file.

Now go into the 'course' directory and open course/lib.php

Find...

print_course_search("", false, "short");

...and wrap it round with an if statement exactly like this...

if (!($CFG->course_lib_hidesearchbox)) {
print_course_search("", false, "short");
}

Now find...

print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get");

and wrap it with an if so that it looks like this...

if (!($CFG->course_lib_hideallcourseslink)) {
print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get");
}

Save the file.

Now go to the directory 'blocks/course_list' and open the file blocks/course_list/block_course_list.php

If this file, find the 3 instances of...

|| empty($CFG->block_course_list_hideallcourseslink)

...and change them each to...

&& !($CFG->block_course_list_hideallcourseslink)

Be very careful with this last one because I have not shown the final bracket ) on each line, and you must keep the same number of brackets as you stated with!

Save this file.

Job done.

You can now turn the Search box or the All Courses links on and off by changing between true and false settings in the config file.


Note that the administrator would have to use Site Administration->Courses to see all courses, if these are not set to appear on the front page anyway.

One last thing, keep a record of these changes (e.g. print this), because future upgrades will set these changes back!

Regards,

John

PS Mauno, will have already guessed my question!
Link to question in Developers forum

Average of ratings: Useful (1)
In reply to John White

Re: Can anybody help..please..I am really tired!!!

by Mohammed Shamshad -
HI Jhon,

I have done everything as you have mentioned.But now i could see an error message surprise Parse error: syntax error, unexpected $end C:\Inetpub\vhosts\someone.com\httpdocs\course\lib.php on line 2963

Could you help me out please

Thanks,
Mohammed Shamshad
In reply to Mohammed Shamshad

Re: Can anybody help..please..I am really tired!!!

by John White -
Hi Mohammed,

The most likely thing is that you have an error in the course/lib.php file.

Could you open the file, find the place where we made the changes, and copy and paste about 15 lines from that section into a post,
starting at: if (count_records("course") > (count($courses) + 1) )
and going down to: } else {

Alternatively, you could click on my name link and email me the whole file, but zip it up first please
(my Outlook does funny things when receiving php attachments).

I hope I can sort it!

Regards,

John
Average of ratings: Useful (1)
In reply to John White

Re: Can anybody help..please..I am really tired!!!

by Mohammed Shamshad -
Hi Jhon,

Please find the lines below where i did the changes.

if (count_records("course") > (count($courses) + 1) ) { // Some courses not being displayed
echo "<table width=\"100%\"><tr><td align=\"center\">";
if (!($CFG->course_lib_hidesearchbox)) {
print_course_search("", false, "short");
}
echo "</td><td align=\"center\">";
if (!($CFG->course_lib_hideallcourseslink)) {
print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get");
}
echo "</td></tr></table>\n";
} else {
if (count_records("course_categories") > 1) {
print_simple_box_start("center", "100%", "#FFFFFF", 5, "categorybox");
print_whole_category_list();
print_simple_box_end();
} else {


I am emailing the same file too to you.

Thanks,
Mohammed Shamshad
In reply to John White

Re: Can anybody help..please..I am really tired!!!

by Mohammed Shamshad -
Hi John,

Thank you very much for the help.I appreciate it.It really works.I could fix the error in the php.The error caused just because of a blank line at the end of the code.Now the users can see only the courses to which they have enrolled.
I also thank Mauno for the concern and he had shown me some other way to do the same but unfortunately it doesn't work on moodle version 1.9.
big grin
Thanks again,
Mohammed Shamshad
In reply to Mohammed Shamshad

Re: Can anybody help..please..I am really tired!!!

by John White -
Mohammed,

I'm glad you've sorted it.
Be very careful to check that it works in all circumstances, and that it doesn't then cause some other problem for users (all sorts of users)!
...Who creates courses in your site, does this still work for whoever needs it?

I think the real problem that you hit is to do with using a low quality editor to look at php files.
I mentioned UltraEdit because it has never failed me; but I am very suspicious of certain editors
as I think some put spurious hidden characters into the code!
I think there was a 'brace' { missing in your code sample, but its good you've now got it sorted.

Regards,

John
Average of ratings: Useful (1)
In reply to John White

Re: Can anybody help..please..I am really tired!!!

by Mohammed Shamshad -
Hi John,

You are absolutely right.In the first attempt i used some other php editor.Then in the second attempt i tried the Ultra edit and i could easily find out the error.Now i would like to get one more thing in to your attention

Is it possible to list the courses in in multiple pages instead of showing all the courses in one,single page? Now the admin user can see the entire course list, just in one page it makes my home page uncomfortably lengthy.

Regards,
Mohammed shamshadsmile
In reply to Mohammed Shamshad

Re: Can anybody help..please..I am really tired!!!

by John White -
Mohammed,

It happens that Reiner Simon has asked that same question at...
http://moodle.org/mod/forum/discuss.php?d=98525
In fact the question has been raised across several versions of Moodle.

Its rather odd that Front Page->Front Page Settings->'Courseperpage' doesn't work the way you might expect it to.
I'm still trying to understand that myself, so I think it would be best to watch that thread to see if the answer arrives!

Regards,

John
Average of ratings: Useful (1)
In reply to John White

Re: Can anybody help..please..I am really tired!!!

by CommLab India -

Hi John,

I was also facing the same problem and I tried you suggestions and it worked.

Then we came with a new requirement that Administrator should have the authority to enable or disable the button.

I did some more modification to your code and its working perfectly. Now the Admin can enable or disable the button using Administration > Modules > Blocks  > Courses.

In moodle/course/lib.php

Step 1:
Find
 print_course_search("", false, "short");
and replace it with
 if(!($CFG->block_course_list_hideallcourseslink)) {
       print_course_search("", false, "short");
 }

Find 
 print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get");
and replace it with
 if(!($CFG->block_course_list_hideallcourseslink)) {
              print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get");
   }

Step 2:

In blocks/course_list/block_course_list.php

find three instances of...

|| empty($CFG->block_course_list_hideallcourseslink)

and replace all the three instances with

&& !($CFG->block_course_list_hideallcourseslink)


Regards,

CL

In reply to John White

Re: Hide All courses in users course list

by onur canalp -
Hi John,
Firstly I want to say thanks for you but I have some problems..
I do all things, so I can Hide All Courses button but...
But if people writes on adress line "/course/index.php" re listing all courses..
I want to dont show unselected courses in users course list..
How can I fix this bug?
help me please..
In reply to onur canalp

Re: Hide All courses in users course list

by John White -
Onur,

This is not really a bug.

The view the user gets from "/course/index.php" should contain all the courses he (she) has Student access to,
plus (I believe) all the courses that have 'Guest' access for anyone.

Try removing 'Guest' access from one of the courses a student does not have the Student role in,
and then see if that course drops off his list.

You change Guest access in the course' Settings.

Regards,

John
In reply to John White

Re: Hide All courses in users course list

by Gary Hutson -
Hi,

first a big thanks to John and all for the help above which I used to also turn off the Search Courses and All Courses links.

However it is still possible for my students to get to all the courses if they know the link /course/index.php which seems by default to display all the categories, and courses and search courses box.

I have the course "Availability" settings as:
"This course is available to students"
AND
"Do not allow guests in"

but the students can see all the courses, categories and the search courses box on the course/index.php page


Am I missing another core setting, or is there a change necessary to course/index.php to stop the course listings / search box showing here?

Gary

In reply to Gary Hutson

Re: Hide All courses in users course list

by Rudy Preston -
Hi

I took a different approach with this:

First set the front page setting checkbox to "show classes in hidden categories" and hide your categories (if you already have classes in the categories, you will then need to go unhide the classes individually).

Then I needed to get rid of the search box and "view all class" buttons. So I and wrapped them in a css class, then styled it to not display. I can then change it back later, or any admin can change it if they use chameleon.

Here is the patch I used to finish this fix, which works great for us, hope it can for you too!

*****Hide Search for a Course Box (Student View)**************

summary:
In order to keep students from seeing classes they
were not enrolled in, we had to hide a table containing
a search input and a "view all courses" button.

description:
I have added an "id" tag (course_search_table) to the
library file that generates this particular table.
I then styled the "id" in the CSS.

Total Files Changed: 02

----
| 01 | MOODLE INSTALL ROOT/course/lib.php
----

CODE SNIP (LINES 2135 - 2151):

BEFORE
**************************************************************

if (count_records("course") > (count($courses) + 1) ) { // Some courses not being displayed
echo "<table width=\"100%\"><tr><td align=\"center\">";
print_course_search("", false, "short");
echo "</td><td align=\"center\">";
print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get");
echo "</td></tr></table>\n";
}

*************************************************************


AFTER
*************************************************************
COPY BETWEEN THE `%@%COPY%@%` BUT NOT THE `%@%COPY%@%` *
*************************************************************

`%@%COPY%@%`


/*
PATCH 01 == See the README_BEFORE_UPGRADE.txt file
*/
if (count_records("course") > (count($courses) + 1) ) { // Some courses not being displayed
echo "<table id=\"course_search_table\" width=\"100%\"><tr><td align=\"center\">";
print_course_search("", false, "short");
echo "</td><td align=\"center\">";
print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get");
echo "</td></tr></table>\n";
}
/*
END PATCH 01 == See the README_BEFORE_UPGRADE.txt file
*/


`%@%COPY%@%`

**************************************************************


----
| 02 | MOODLE INSTALL ROOT/theme/chameleon/user_styles.css
----

CODE SNIP (LINES 601-603):

>This was written via the Chameleon template SHIFT+CLICK feature
>Modify your themes -- this would need to be added to it's CSS
>file called user_styles.css
**************************************************************


#course_search_table {
display: none;
}


**************************************************************
END PATCH 01 *
**************

smile
Rudy