From 62e2d5ce895ebada5e683f684d3156411deeef58 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Thu, 22 Nov 2007 01:03:12 +0100 Subject: [PATCH] [svn r13742] Minor - improved code to avoid warnings (and possibly stabilise it) --- main/forum/forumfunction.inc.php | 24 ++- main/forum/index.php | 309 ++++++++++++++++--------------- 2 files changed, 171 insertions(+), 162 deletions(-) diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index ff3a0f6af4..e4118a4090 100644 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -1185,15 +1185,22 @@ function get_forums($id='') // finding the last post information (last_post_id, last_poster_id, last_post_date, last_poster_name, last_poster_lastname, last_poster_firstname) if ($id=='') { - foreach ($forum_list as $key=>$value) + if(is_array($forum_list)) { - $last_post_info_of_forum=get_last_post_information($key,is_allowed_to_edit()); - $forum_list[$key]['last_post_id']=$last_post_info_of_forum['last_post_id']; - $forum_list[$key]['last_poster_id']=$last_post_info_of_forum['last_poster_id']; - $forum_list[$key]['last_post_date']=$last_post_info_of_forum['last_post_date']; - $forum_list[$key]['last_poster_name']=$last_post_info_of_forum['last_poster_name']; - $forum_list[$key]['last_poster_lastname']=$last_post_info_of_forum['last_poster_lastname']; - $forum_list[$key]['last_poster_firstname']=$last_post_info_of_forum['last_poster_firstname']; + foreach ($forum_list as $key=>$value) + { + $last_post_info_of_forum=get_last_post_information($key,is_allowed_to_edit()); + $forum_list[$key]['last_post_id']=$last_post_info_of_forum['last_post_id']; + $forum_list[$key]['last_poster_id']=$last_post_info_of_forum['last_poster_id']; + $forum_list[$key]['last_post_date']=$last_post_info_of_forum['last_post_date']; + $forum_list[$key]['last_poster_name']=$last_post_info_of_forum['last_poster_name']; + $forum_list[$key]['last_poster_lastname']=$last_post_info_of_forum['last_poster_lastname']; + $forum_list[$key]['last_poster_firstname']=$last_post_info_of_forum['last_poster_firstname']; + } + } + else + { + $forum_list = array(); } } else @@ -1304,7 +1311,6 @@ function get_threads($forum_id) ON post.poster_id= last_poster_users.user_id WHERE thread.forum_id='".mysql_real_escape_string($forum_id)."' ORDER BY thread.thread_sticky DESC, thread.thread_date DESC"; - if (is_allowed_to_edit()) { // important note: it might seem a little bit awkward that we have 'thread.locked as locked' in the sql statement diff --git a/main/forum/index.php b/main/forum/index.php index f62aded01d..21c85733e6 100644 --- a/main/forum/index.php +++ b/main/forum/index.php @@ -187,202 +187,205 @@ if (api_is_allowed_to_edit()) Display Forum Categories and the Forums in it ------------------------------------------------------------------------------------------------------ */ -echo "\n"; +echo '
'."\n"; // Step 3: we display the forum_categories first -foreach ($forum_categories_list as $forum_category_key => $forum_category) +if(is_array($forum_categories_list)) { - echo "\t\n\t\t\n"; - if (api_is_allowed_to_edit()) - { - echo "\t\t\n\t\t\n"; - } - echo "\t\n"; - - // step 4: the interim headers (for the forum) - echo "\t\n"; - echo "\t\t\n"; - echo "\t\t\n"; - echo "\t\t\n"; - echo "\t\t\n"; - if (api_is_allowed_to_edit()) - { - echo "\t\t\n"; - } - echo "\t\n"; - - // the forums in this category - $forums_in_category=get_forums_in_category($forum_category['cat_id']); - - // step 5: we display all the forums in this category. - $forum_count=0; - foreach ($forum_list as $key=>$forum) - { - // Here we clean the whatnew_post_info array a little bit because to display the icon we - // test if $whatsnew_post_info[$forum['forum_id']] is empty or not. - if(is_array($whatsnew_post_info[$forum['forum_id']])) + if (api_is_allowed_to_edit()) { - foreach ($whatsnew_post_info[$forum['forum_id']] as $key_thread_id => $new_post_array) - { - if (empty($whatsnew_post_info[$forum['forum_id']][$key_thread_id])) - { - unset($whatsnew_post_info[$forum['forum_id']][$key_thread_id]); - unset($_SESSION['whatsnew_post_info'][$forum['forum_id']][$key_thread_id]); - } - } + echo "\t\t\n"; } - // note: this can be speeded up if we transform the $forum_list to an array that uses the forum_category as the key. - if (prepare4display($forum['forum_category'])==prepare4display($forum_category['cat_id'])) + echo "\t\n"; + + // step 4: the interim headers (for the forum) + echo "\t\n"; + echo "\t\t\n"; + echo "\t\t\n"; + echo "\t\t\n"; + echo "\t\t\n"; + if (api_is_allowed_to_edit()) { - // the forum has to be showed if - // 1.v it is a not a group forum (teacher and student) - // 2.v it is a group forum and it is public (teacher and student) - // 3. it is a group forum and it is private (always for teachers only if the user is member of the forum - // if the forum is private and it is a group forum and the user is not a member of the group forum then it cannot be displayed - //if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user))) - //{ - $show_forum=false; - - // SHOULD WE SHOW THIS PARTICULAR FORUM - // you are teacher => show forum - - if (api_is_allowed_to_edit()) + echo "\t\t\n"; + } + echo "\t\n"; + + // the forums in this category + $forums_in_category=get_forums_in_category($forum_category['cat_id']); + + // step 5: we display all the forums in this category. + $forum_count=0; + foreach ($forum_list as $key=>$forum) + { + // Here we clean the whatnew_post_info array a little bit because to display the icon we + // test if $whatsnew_post_info[$forum['forum_id']] is empty or not. + if(is_array($whatsnew_post_info[$forum['forum_id']])) { - //echo 'teacher'; - $show_forum=true; + foreach ($whatsnew_post_info[$forum['forum_id']] as $key_thread_id => $new_post_array) + { + if (empty($whatsnew_post_info[$forum['forum_id']][$key_thread_id])) + { + unset($whatsnew_post_info[$forum['forum_id']][$key_thread_id]); + unset($_SESSION['whatsnew_post_info'][$forum['forum_id']][$key_thread_id]); + } + } } - // you are not a teacher - else + // note: this can be speeded up if we transform the $forum_list to an array that uses the forum_category as the key. + if (prepare4display($forum['forum_category'])==prepare4display($forum_category['cat_id'])) { - //echo 'student'; - // it is not a group forum => show forum (invisible forums are already left out see get_forums function) - if ($forum['forum_of_group']=='0') + // the forum has to be showed if + // 1.v it is a not a group forum (teacher and student) + // 2.v it is a group forum and it is public (teacher and student) + // 3. it is a group forum and it is private (always for teachers only if the user is member of the forum + // if the forum is private and it is a group forum and the user is not a member of the group forum then it cannot be displayed + //if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user))) + //{ + $show_forum=false; + + // SHOULD WE SHOW THIS PARTICULAR FORUM + // you are teacher => show forum + + if (api_is_allowed_to_edit()) { - //echo '-gewoon forum'; + //echo 'teacher'; $show_forum=true; } - // it is a group forum + // you are not a teacher else { - //echo '-groepsforum'; - // it is a group forum but it is public => show - if ($forum['forum_group_public_private']=='public') + //echo 'student'; + // it is not a group forum => show forum (invisible forums are already left out see get_forums function) + if ($forum['forum_of_group']=='0') { + //echo '-gewoon forum'; $show_forum=true; - //echo '-publiek'; } - // it is a group forum and it is private + // it is a group forum else { - //echo '-prive'; - // it is a group forum and it is private but the user is member of the group - if (in_array($forum['forum_of_group'],$groups_of_user)) + //echo '-groepsforum'; + // it is a group forum but it is public => show + if ($forum['forum_group_public_private']=='public') { - //echo '-is lid'; $show_forum=true; + //echo '-publiek'; } + // it is a group forum and it is private else { - //echo '-is GEEN lid'; - $show_forum=false; + //echo '-prive'; + // it is a group forum and it is private but the user is member of the group + if (in_array($forum['forum_of_group'],$groups_of_user)) + { + //echo '-is lid'; + $show_forum=true; + } + else + { + //echo '-is GEEN lid'; + $show_forum=false; + } } + } - } - } - //echo '
'; - - if ($show_forum) - { - $form_count++; - echo "\t\n"; - echo "\t\t\n"; + echo "\t\t\n"; + if ($forum['forum_of_group']<>'0') { - echo icon('../img/forumgroupnew.gif'); + $group_title=substr($all_groups[$forum['forum_of_group']]['name'],0,30); + $forum_title_group_addition=' ('.$group_title.')'; } else { - echo icon('../img/forumgroup.gif'); + $forum_title_group_addition=''; } - } - else - { - if (is_array($whatsnew_post_info[$forum['forum_id']]) and !empty($whatsnew_post_info[$forum['forum_id']])) + + echo "\t\t\n"; + //$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated + // the number of topics and posts + echo "\t\t\n"; + echo "\t\t\n"; + // the last post in the forum + if ($forum['last_poster_name']<>'') { - echo icon('../img/forum.gif'); + $name=$forum['last_poster_name']; + $poster_id=0; } else { - echo icon('../img/forum.gif'); + $name=$forum['last_poster_firstname'].' '.$forum['last_poster_lastname']; + $poster_id=$forum['last_poster_id']; + } + echo "\t\t\n"; - if ($forum['forum_of_group']<>'0') - { - $group_title=substr($all_groups[$forum['forum_of_group']]['name'],0,30); - $forum_title_group_addition=' ('.$group_title.')'; - } - else - { - $forum_title_group_addition=''; - } - - echo "\t\t\n"; - //$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated - // the number of topics and posts - echo "\t\t\n"; - echo "\t\t\n"; - // the last post in the forum - if ($forum['last_poster_name']<>'') - { - $name=$forum['last_poster_name']; - $poster_id=0; - } - else - { - $name=$forum['last_poster_firstname'].' '.$forum['last_poster_lastname']; - $poster_id=$forum['last_poster_id']; - } - echo "\t\t\n"; - - - if (api_is_allowed_to_edit()) - { - echo "\t\t\n"; + + + if (api_is_allowed_to_edit()) + { + echo "\t\t\n"; + } + echo "\t"; } - echo "\t"; } } - } - if (count($forum_list)==0) - { - echo "\t\n"; + if (count($forum_list)==0) + { + echo "\t".(api_is_allowed_to_edit()?'':'')."\n"; + } } } echo "
"; - echo ''.prepare4display($forum_category['cat_title']).'
'; - if ($forum_category['cat_comment']<>'' AND trim($forum_category['cat_comment'])<>' ') + foreach ($forum_categories_list as $forum_category_key => $forum_category) { - echo ''.prepare4display($forum_category['cat_comment']).''; - } - echo "
"; - echo "".icon('../img/edit.gif',get_lang('Edit')).""; - echo "".icon('../img/delete.gif',get_lang('Delete')).""; - display_visible_invisible_icon('forumcategory', prepare4display($forum_category['cat_id']), prepare4display($forum_category['visibility'])); - display_lock_unlock_icon('forumcategory',prepare4display($forum_category['cat_id']), prepare4display($forum_category['locked'])); - display_up_down_icon('forumcategory',prepare4display($forum_category['cat_id']), $forum_categories_list); + echo "\t
"; + echo ''.prepare4display($forum_category['cat_title']).'
'; + if ($forum_category['cat_comment']<>'' AND trim($forum_category['cat_comment'])<>' ') + { + echo ''.prepare4display($forum_category['cat_comment']).''; + } echo "
".get_lang('Forum')."".get_lang('Topics')."".get_lang('Posts')."".get_lang('LastPosts')."".get_lang('Actions')."
"; + echo "".icon('../img/edit.gif',get_lang('Edit')).""; + echo "".icon('../img/delete.gif',get_lang('Delete')).""; + display_visible_invisible_icon('forumcategory', prepare4display($forum_category['cat_id']), prepare4display($forum_category['visibility'])); + display_lock_unlock_icon('forumcategory',prepare4display($forum_category['cat_id']), prepare4display($forum_category['locked'])); + display_up_down_icon('forumcategory',prepare4display($forum_category['cat_id']), $forum_categories_list); + echo "
".get_lang('Forum')."".get_lang('Topics')."".get_lang('Posts')."".get_lang('LastPosts')."".get_lang('Actions')."
"; - if ($forum['forum_of_group']!=='0') + //echo '
'; + + if ($show_forum) { - if (is_array($whatsnew_post_info[$forum['forum_id']]) and !empty($whatsnew_post_info[$forum['forum_id']])) + $form_count++; + echo "\t
"; + if ($forum['forum_of_group']!=='0') + { + if (is_array($whatsnew_post_info[$forum['forum_id']]) and !empty($whatsnew_post_info[$forum['forum_id']])) + { + echo icon('../img/forumgroupnew.gif'); + } + else + { + echo icon('../img/forumgroup.gif'); + } + } + else + { + if (is_array($whatsnew_post_info[$forum['forum_id']]) and !empty($whatsnew_post_info[$forum['forum_id']])) + { + echo icon('../img/forum.gif'); + } + else + { + echo icon('../img/forum.gif'); + } + + } + echo "".prepare4display($forum['forum_title']).''.$forum_title_group_addition.'
'.prepare4display($forum['forum_comment'])."
".$forum['number_of_threads']."".$forum['number_of_posts'].""; + if (!empty($forum['last_post_id'])) + { + echo $forum['last_post_date']."
".get_lang('By').' '.display_user_link($poster_id, $name); } - - } - echo "
".prepare4display($forum['forum_title']).''.$forum_title_group_addition.'
'.prepare4display($forum['forum_comment'])."
".$forum['number_of_threads']."".$forum['number_of_posts'].""; - if (!empty($forum['last_post_id'])) - { - echo $forum['last_post_date']."
".get_lang('By').' '.display_user_link($poster_id, $name); - } - echo "
"; - echo "".icon('../img/edit.gif',get_lang('Edit')).""; - echo "".icon('../img/delete.gif',get_lang('Delete')).""; - display_visible_invisible_icon('forum',$forum['forum_id'], $forum['visibility']); - display_lock_unlock_icon('forum',$forum['forum_id'], $forum['locked']); - display_up_down_icon('forum',$forum['forum_id'], $forums_in_category); echo ""; + echo "".icon('../img/edit.gif',get_lang('Edit')).""; + echo "".icon('../img/delete.gif',get_lang('Delete')).""; + display_visible_invisible_icon('forum',$forum['forum_id'], $forum['visibility']); + display_lock_unlock_icon('forum',$forum['forum_id'], $forum['locked']); + display_up_down_icon('forum',$forum['forum_id'], $forums_in_category); + echo "
".get_lang('NoForumInThisCategory')."
".get_lang('NoForumInThisCategory')."
\n";