root/trunk/actions/communities/createTopic.action.php

Revision 1, 2.4 KB (checked in by anonymous, 7 years ago)

initial import

Line 
1<?php
2/****************************************************** Open .node ***
3 * Description:   
4 * Status:        Stable.
5 * Author:        Alexandre Dath <alexandre@dotnode.com>
6 * $Id$
7 *
8 * Copyright (C) 2005 Alexandre Dath <alexandre@dotnode.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 ******************** http://opensource.ikse.net/projects/dotnode ***/
24
25if(is_numeric($token[3]) )
26{
27    $is_membre = $db->getOne('SELECT count(id) as nb FROM user_comm WHERE id=? AND status=? AND id_comm=?', array($_SESSION['my_id'], 'ok', $token[3]));
28    if($is_membre != 1)
29    {
30        header('Location: /error/not_in_community');
31                exit();
32    }
33
34    $date = time();
35    $title = stripslashes($_POST['title']);
36    $message = stripslashes($_POST['message']);
37
38    if(strlen(trim($_POST['title'])) < 1 || strlen(trim($_POST['message'])) < 1)
39    {
40        header('Location: /error/incorrect_topic');
41        exit();
42    }
43
44
45    $topic_values = array(
46                'id' => $_SESSION['my_id'],
47                'id_comm' => $token[3],
48                'author'  => $_SESSION['my_fname'],
49                'title'   => $title,
50                'nb_posts'=> 1,
51                'date' => $date,
52                'last_post_date' => $date);
53        $db->autoExecute('community_topic', $topic_values, DB_AUTOQUERY_INSERT);
54
55    $id_topic = $db->getOne('SELECT LAST_INSERT_ID()');
56
57    $post_values = array(
58        'id'      => $_SESSION['my_id'],
59        'id_topic'=> $id_topic,
60        'id_comm' => $token[3],
61        'author'  => $_SESSION['my_fname'],
62        'title'   => $title,
63        'message' => $message,
64        'date'    => $date);
65    $db->autoExecute('community_post', $post_values, DB_AUTOQUERY_INSERT);
66
67    $db->query('UPDATE community SET last_post_date=? WHERE id_comm=?', array($date, $token[3]));
68
69}
70
71header('Location: /communities/view/'.$token[3]);
72?>
Note: See TracBrowser for help on using the browser.