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

Revision 1, 4.7 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
25$community_values = array();
26
27if(strtoupper($_POST['code']).'.jpeg' == $_SESSION['pix_code'])
28{
29    foreach(array_keys($table_fields['communities']) as $key)
30    {
31        if(array_key_exists($key, $_POST) )
32        {
33            $value='';
34            if( is_array($_POST[$key]) )
35                $value = implode(",", $_POST[$key]);
36            elseif( $_POST[$key] == "(null)" || $_POST[$key] == "" || $_POST[$key] == "http://")
37                $value = NULL;
38            else
39                $value = $_POST[$key];
40
41            if(($key == 'name' ||
42                $key == 'categorie' ||
43                $key == 'moderated' ||
44                $key == 'description' ) &&
45               is_null($value))
46            {
47                $_SESSION['error']['title'] = _('Impossible to create your community');
48                $_SESSION['error']['msg'] = _('You must enter a valid name, category and description to create your community');
49                $_SESSION['error']['post'] = array_map('stripslashes', $_POST);
50                header('Location: /communities/create');
51                exit();
52            }
53
54            if(is_null($value))
55                $community_values[$key] = NULL;
56            else
57                $community_values[$key] = stripslashes($value);
58
59        }
60    }
61
62    $community_values['id'] = $_SESSION['my_id'];
63    $community_values['date'] = time();
64
65    $result =& $db->autoExecute('community', $community_values, DB_AUTOQUERY_INSERT);
66    if (DB::isError($result))
67    {
68        $id_comm = $db->getOne('SELECT id_comm FROM community WHERE name LIKE ?', array($community_values['name']));
69                if($id_comm)
70                {
71                        $_SESSION['error']['title'] = _('Community already exist');
72                        $_SESSION['error']['msg'] = _('A community with the same same already exist.');
73                }
74                else
75                {
76                        $_SESSION['error']['title'] = _('Unknow error');
77                        $_SESSION['error']['msg'] = _('An unknow error arose. <a href="/ReportBogus?url=%2Fcommunities%2Fcreate">Report the problem.</a>');
78        error_log($_SERVER['HTTP_HOST'].' | '.__FILE__.' '.$result->getMessage());
79                }
80
81    }
82    elseif($db->affectedRows())
83    {
84        $db->query('UPDATE community_cat SET nb_communities=nb_communities+1 WHERE id_cat=?', $_POST['id_cat']);
85
86        $id_comm = $db->getOne('SELECT LAST_INSERT_ID()');
87        $query_val = array($_SESSION['my_id'], $id_comm);
88        $db->query('INSERT INTO user_comm SET id=?, id_comm=?', $query_val);
89
90        $my_comm_id = $db->getCol('SELECT id_comm FROM user_comm WHERE id=?', 0, $_SESSION['my_id']);
91
92        $query_val = array(
93            'communities_id' => implode(',', $my_comm_id),
94            'nb_communities' => count($my_comm_id) );
95        $result =& $db->autoExecute('cache_user', $query_val, DB_AUTOQUERY_UPDATE, "id='".$_SESSION['my_id']."'");
96        if (DB::isError($result)) {
97            error_log($_SERVER['HTTP_HOST'].' | '.__FILE__.' '.$result->getMessage());
98        }
99
100
101        $_SESSION['my_communities_id'] = $my_comm_id;
102
103    // Generating keyword data for search
104   
105        $array_description = explode(' ', $community_values['description']);
106                $array_name = explode(' ', $community_values['name']);
107
108                $array = array_merge($array_description, $array_name);
109
110        foreach($array as $elemt)
111        {
112            $elemt = ereg_replace("(.*)s$", "\\1", $elemt);
113            if(strlen($elemt)>2)
114            {
115                $sndx = get_mysql_soundex($elemt);
116                $db->query('INSERT INTO community_keyword SET key_sndx=?, id_comm=?, id_cat=?', array($sndx, $id_comm, $_POST['id_cat']));
117            }
118        }
119
120
121        upload_image($_FILES, 'logo', $_SESSION['my_id'], $id_comm, BASEPATH, '/comm_logos', true'/comm_logos/thumb');
122    }
123
124    header('Location: /communities/view/'.$id_comm);
125}
126else
127{
128    $_SESSION['error']['title'] = _('Verification code failed');
129    $_SESSION['error']['msg'] = _('The sent code don\'t match the image');
130    $_SESSION['error']['post'] = array_map('stripslashes', $_POST);
131    header('Location: /communities/create');
132}
133?>
Note: See TracBrowser for help on using the browser.