source: gm_system/forum/forum_submit_add.php@ 651

Last change on this file since 651 was 651, checked in by aleg, 15 years ago

Změněná cesta k GM a Char logům pro realmy 4 a 7.

File size: 5.9 KB
Line 
1<?php
2/*
3 $Id: forum_submit.php 1704 2008-01-01 06:09:52Z andrewsimpson $
4
5 (c) 2002 - 2009 Andrew Simpson <andrew.simpson at paradise.net.nz>
6
7 WebCollab
8 ---------------------------------------
9
10 This program is free software; you can redistribute it and/or modify it under the
11 terms of the GNU General Public License as published by the Free Software Foundation;
12 either version 2 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 PARTICULAR PURPOSE. See the GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License along with this
19 program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
20 Cambridge, MA 02139, USA.
21
22 Function:
23 ---------
24
25 Forum add submission
26
27*/
28
29//security check
30if(! defined('UID' ) ) {
31 die('Direct file access not permitted' );
32}
33
34//includes
35require_once(BASE.'includes/usergroup_security.php' );
36include_once(BASE.'includes/admin_config.php');
37
38//secure variables
39$mail_list = array();
40
41if((GUEST) && (GUEST_LOCKED != 'N' ) ){
42 warning($lang['access_denied'], 'Guests are not permitted to post in forums' );
43}
44
45//if user aborts, let the script carry onto the end
46ignore_user_abort(TRUE);
47
48//if all values are filled in correctly we can submit the forum-item
49if(empty($_POST['text'] ) ) {
50 warning($lang['forum_submit'], $lang['no_message'] );
51}
52$input_array = array('parentid', 'taskid', 'usergroupid');
53foreach($input_array as $var ) {
54 if(! @safe_integer($_POST[$var]) ){
55 error('Forum submit', "Variable $var is not set" );
56 }
57 ${$var} = $_POST[$var];
58}
59
60$text = safe_data_long($_POST['text'] );
61
62if(isset($_POST['mail_owner'] ) && ($_POST['mail_owner'] === 'on' ) ) {
63 $mail_owner = true;
64}
65else {
66 $mail_owner = '';
67}
68
69if(isset($_POST['mail_group'] ) && ($_POST['mail_group'] === 'on' ) ) {
70 $mail_group = true;
71}
72else {
73 $mail_group = '';
74}
75
76//do data consistency check on parentid
77if($parentid != 0 ) {
78 if(db_result(db_query('SELECT COUNT(*) FROM '.PRE.'forum WHERE id='.$parentid ), 0, 0 ) == 0 ){
79 error('Forum submit', 'Data consistency error - child post has no parent' );
80 }
81}
82
83//check usergroup security
84$taskid = usergroup_check($taskid );
85
86//okay now check if we need to post in the public or the private forums of the task
87switch($usergroupid ) {
88 case 0:
89 //public post
90 db_begin();
91 db_query ('INSERT INTO '.PRE.'forum(parent, taskid, posted, edited, text, userid, usergroupid, sequence)
92 VALUES ('.$parentid.', '.$taskid.', now(), now(), \''.$text.'\', '.UID.', 0, 0)' );
93 break;
94
95 default:
96 //private post
97 //check if the user does belong to that group
98 if((! ADMIN ) && ( ! isset($GID[($usergroupid)] ) ) ) {
99 error('Forum submit', 'You do not have enough rights to post in that forum' );
100 }
101
102 db_begin();
103 db_query ('INSERT INTO '.PRE.'forum(parent, taskid, posted, edited, text, userid, usergroupid, sequence)
104 VALUES ('.$parentid.', '.$taskid.', now(), now(), \''.$text.'\', '.UID.', '.$usergroupid.', 0)' );
105 break;
106
107}
108//set time of last forum post to this task
109db_query('UPDATE '.PRE.'tasks SET lastforumpost=now() WHERE id='.$taskid );
110db_commit();
111
112//get task data
113$q = db_query('SELECT '.PRE.'tasks.name AS name,
114 '.PRE.'tasks.usergroupid AS usergroupid,
115 '.PRE.'users.email AS email
116 FROM '.PRE.'tasks
117 LEFT JOIN '.PRE.'users ON ('.PRE.'tasks.owner='.PRE.'users.id)
118 WHERE '.PRE.'tasks.id='.$taskid );
119$task_row = db_fetch_array($q, 0 );
120
121//set owner's email
122if($task_row['email'] && $mail_owner ) {
123 $mail_list[] = $task_row['email'];
124}
125
126//if usergroup set, add the user list
127if($task_row['usergroupid'] && $mail_group ){
128 $q = db_query('SELECT '.PRE.'users.email
129 FROM '.PRE.'users
130 LEFT JOIN '.PRE.'usergroups_users ON ('.PRE.'usergroups_users.userid='.PRE.'users.id)
131 WHERE '.PRE.'usergroups_users.usergroupid='.$task_row['usergroupid'].
132 ' AND '.PRE.'users.deleted=\'f\'' );
133
134 for( $i=0 ; $row = @db_fetch_num($q, $i ) ; ++$i ) {
135 $mail_list[] = $row[0];
136 }
137}
138
139//do we need to email?
140if(sizeof($mail_list) > 0 ){
141 include_once(BASE.'includes/email.php' );
142 include_once(BASE.'includes/time.php' );
143 include_once(BASE.'lang/lang_email.php' );
144
145 $message_unclean = validate($_POST['text'] );
146
147 //get rid of magic_quotes - it is not required here
148 if(get_magic_quotes_gpc() ){
149 $message_unclean = stripslashes($message_unclean );
150 }
151 //get & add the mailing list
152 if(sizeof($EMAIL_MAILINGLIST ) > 0 ){
153 $mail_list = array_merge((array)$mail_list, (array)$EMAIL_MAILINGLIST );
154 }
155
156 switch($parentid ) {
157 case 0:
158 //this is a new post
159 email($mail_list, sprintf($title_forum_post, $task_row['name']), sprintf($email_forum_post, UID_NAME, $message_unclean, 'index.php?taskid='.$taskid ) );
160 break;
161
162 default:
163 //this is a reply to an earlier post
164 $q = db_query('SELECT '.PRE.'forum.text AS text,
165 '.PRE.'users.fullname AS username
166 FROM '.PRE.'forum
167 LEFT JOIN '.PRE.'users ON ('.PRE.'forum.userid='.PRE.'users.id)
168 WHERE '.PRE.'forum.id='.$parentid );
169
170 $row = db_fetch_array($q, 0 );
171
172 if($row['username'] == NULL ){
173 $row['username'] = "----";
174 }
175
176 email($mail_list, sprintf($title_forum_post, $task_row['name']), sprintf($email_forum_reply, UID_NAME, $row['username'], $row['text'], $message_unclean, 'index.php?taskid='.$taskid ) );
177 break;
178 }
179}
180
181//go back to where this request came from
182header('Location: '.BASE_URL.'tasks.php?x='.X.'&action=show&taskid='.$taskid );
183
184?>
Note: See TracBrowser for help on using the repository browser.