1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | |||
4 | /** |
||
5 | * These files are a complete rework of the forum. The database structure is |
||
6 | * based on phpBB but all the code is rewritten. A lot of new functionalities |
||
7 | * are added: |
||
8 | * - forum categories and forums can be sorted up or down, locked or made invisible |
||
9 | * - consistent and integrated forum administration |
||
10 | * - forum options: are students allowed to edit their post? |
||
11 | * moderation of posts (approval) |
||
12 | * reply only forums (students cannot create new threads) |
||
13 | * multiple forums per group |
||
14 | * - sticky messages |
||
15 | * - new view option: nested view |
||
16 | * - quoting a message. |
||
17 | * |
||
18 | * @Author Patrick Cool <[email protected]>, Ghent University |
||
19 | * @Copyright Ghent University |
||
20 | * @Copyright Patrick Cool |
||
21 | * |
||
22 | * @package chamilo.forum |
||
23 | */ |
||
24 | require_once __DIR__.'/../inc/global.inc.php'; |
||
25 | |||
26 | // The section (tabs). |
||
27 | $this_section = SECTION_COURSES; |
||
28 | |||
29 | // Notification for unauthorized people. |
||
30 | api_protect_course_script(true); |
||
31 | |||
32 | $cidreq = api_get_cidreq(); |
||
33 | $_user = api_get_user_info(); |
||
34 | |||
35 | $nameTools = get_lang('ToolForum'); |
||
36 | |||
37 | require_once 'forumfunction.inc.php'; |
||
38 | |||
39 | // Are we in a lp ? |
||
40 | $origin = api_get_origin(); |
||
41 | /* MAIN DISPLAY SECTION */ |
||
42 | $current_forum = get_forum_information($_GET['forum']); |
||
0 ignored issues
–
show
|
|||
43 | $current_forum_category = get_forumcategory_information($current_forum['forum_category']); |
||
44 | |||
45 | $logInfo = [ |
||
46 | 'tool' => TOOL_FORUM, |
||
47 | 'tool_id' => (int) $_GET['forum'], |
||
48 | 'tool_id_detail' => 0, |
||
49 | 'action' => 'add-thread', |
||
50 | 'action_details' => '', |
||
51 | ]; |
||
52 | Event::registerLog($logInfo); |
||
53 | |||
54 | if (api_is_in_gradebook()) { |
||
55 | $interbreadcrumb[] = [ |
||
56 | 'url' => Category::getUrl(), |
||
57 | 'name' => get_lang('ToolGradebook'), |
||
58 | ]; |
||
59 | } |
||
60 | |||
61 | /* Is the user allowed here? */ |
||
62 | |||
63 | // The user is not allowed here if: |
||
64 | |||
65 | // 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager |
||
66 | if (!api_is_allowed_to_edit(false, true) && |
||
67 | (($current_forum_category && $current_forum_category['visibility'] == 0) || $current_forum['visibility'] == 0) |
||
68 | ) { |
||
69 | api_not_allowed(); |
||
70 | } |
||
71 | |||
72 | // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager |
||
73 | if (!api_is_allowed_to_edit(false, true) && |
||
74 | (($current_forum_category['visibility'] && $current_forum_category['locked'] != 0) || $current_forum['locked'] != 0) |
||
75 | ) { |
||
76 | api_not_allowed(); |
||
77 | } |
||
78 | |||
79 | // 3. new threads are not allowed and the user is not a course manager |
||
80 | if (!api_is_allowed_to_edit(false, true) && |
||
81 | $current_forum['allow_new_threads'] != 1 |
||
82 | ) { |
||
83 | api_not_allowed(); |
||
84 | } |
||
85 | // 4. anonymous posts are not allowed and the user is not logged in |
||
86 | if (!$_user['user_id'] && $current_forum['allow_anonymous'] != 1) { |
||
87 | api_not_allowed(); |
||
88 | } |
||
89 | |||
90 | // 5. Check user access |
||
91 | if ($current_forum['forum_of_group'] != 0) { |
||
92 | $show_forum = GroupManager::user_has_access( |
||
93 | api_get_user_id(), |
||
94 | $current_forum['forum_of_group'], |
||
95 | GroupManager::GROUP_TOOL_FORUM |
||
96 | ); |
||
97 | if (!$show_forum) { |
||
98 | api_not_allowed(); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | // 6. Invited users can't create new threads |
||
103 | if (api_is_invitee()) { |
||
104 | api_not_allowed(true); |
||
105 | } |
||
106 | |||
107 | $groupId = api_get_group_id(); |
||
108 | if (!empty($groupId)) { |
||
109 | $groupProperties = GroupManager::get_group_properties($groupId); |
||
110 | $interbreadcrumb[] = [ |
||
111 | 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.$cidreq, |
||
112 | 'name' => get_lang('Groups'), |
||
113 | ]; |
||
114 | $interbreadcrumb[] = [ |
||
115 | 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.$cidreq, |
||
116 | 'name' => get_lang('GroupSpace').' '.$groupProperties['name'], |
||
117 | ]; |
||
118 | $interbreadcrumb[] = [ |
||
119 | 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.intval($_GET['forum']), |
||
120 | 'name' => $current_forum['forum_title'], |
||
121 | ]; |
||
122 | $interbreadcrumb[] = [ |
||
123 | 'url' => api_get_path(WEB_CODE_PATH).'forum/newthread.php?'.$cidreq.'&forum='.intval($_GET['forum']), |
||
124 | 'name' => get_lang('NewTopic'), |
||
125 | ]; |
||
126 | } else { |
||
127 | $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'forum/index.php?'.$cidreq, 'name' => $nameTools]; |
||
128 | $interbreadcrumb[] = [ |
||
129 | 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforumcategory.php?'.$cidreq.'&forumcategory='.$current_forum_category['cat_id'], |
||
130 | 'name' => $current_forum_category['cat_title'], |
||
131 | ]; |
||
132 | $interbreadcrumb[] = [ |
||
133 | 'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.$cidreq.'&forum='.intval($_GET['forum']), |
||
134 | 'name' => $current_forum['forum_title'], |
||
135 | ]; |
||
136 | $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('NewTopic')]; |
||
137 | } |
||
138 | |||
139 | $htmlHeadXtra[] = " |
||
140 | <script> |
||
141 | $(function() { |
||
142 | $('#reply-add-attachment').on('click', function(e) { |
||
143 | e.preventDefault(); |
||
144 | |||
145 | var newInputFile = $('<input>', { |
||
146 | type: 'file', |
||
147 | name: 'user_upload[]' |
||
148 | }); |
||
149 | $('[name=\"user_upload[]\"]').parent().append(newInputFile); |
||
150 | }); |
||
151 | }); |
||
152 | </script> |
||
153 | "; |
||
154 | |||
155 | $form = show_add_post_form( |
||
156 | $current_forum, |
||
157 | 'newthread', |
||
158 | isset($_SESSION['formelements']) ? $_SESSION['formelements'] : null |
||
159 | ); |
||
160 | |||
161 | if ($origin == 'learnpath') { |
||
162 | Display::display_reduced_header(); |
||
163 | } else { |
||
164 | Display::display_header(); |
||
165 | } |
||
166 | handle_forum_and_forumcategories(); |
||
167 | |||
168 | // Action links |
||
169 | echo '<div class="actions">'; |
||
170 | echo '<span style="float:right;">'.search_link().'</span>'; |
||
171 | echo '<a href="viewforum.php?forum='.intval($_GET['forum']).'&'.$cidreq.'">'. |
||
172 | Display::return_icon('back.png', get_lang('BackToForum'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
173 | echo '</div>'; |
||
174 | |||
175 | // Set forum attachment data into $_SESSION |
||
176 | getAttachedFiles($current_forum['forum_id'], 0, 0); |
||
177 | |||
178 | if ($form) { |
||
179 | $form->display(); |
||
180 | } |
||
181 | |||
182 | if ($origin == 'learnpath') { |
||
183 | Display::display_reduced_footer(); |
||
184 | } else { |
||
185 | Display::display_footer(); |
||
186 | } |
||
187 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.