root/trunk/actions/friends/join.action.php

Revision 1, 4.3 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($_POST['add'] || $_POST['resend'])
26{
27    $invitations[0]['fname'] = $_POST['fname'];
28    $invitations[0]['lname'] = $_POST['lname'];
29    $invitations[0]['email'] = $_POST['email'];
30    $invitations[0]['lang'] = $_POST['lang'];
31    $invitations[0]['type'] = 'man';
32}
33elseif($_POST['import'])
34{
35    $CSV = fopen($_FILES['csv']['tmp_name'], 'r');
36    $first_carac = fread($CSV, 1);
37    fclose($CSV);
38    if($_FILES['csv']['type'] == 'text/comma-separated-values' || $first_carac == '"')
39    {
40        $lines = file($_FILES['csv']['tmp_name']);
41        $idx=0;
42        foreach($lines as $line)
43        {
44            $line = trim($line);
45            if(preg_match("/^\"(.*)\",\"(.*)\",\"(.*@.*\..*)\"$/", $line, $matches))
46            {
47                $invitations[$idx]['fname'] = $matches[1];
48                $invitations[$idx]['lname'] = $matches[2];
49                $invitations[$idx]['email'] = $matches[3];
50                $invitations[$idx]['type'] = 'csv';
51                $invitations[$idx]['lang'] = $lang;
52
53            }
54            $idx++;
55        }
56    }
57}
58
59foreach($invitations as $invitation)
60{
61    if($invitation['fname']!='' && $invitation['lname']!='' && valid_email($invitation['email']) && valid_lang($invitation['lang']) )
62    {
63        $user_w_this_email = $db->getCol('SELECT id FROM user_contact WHERE email=? OR email2=? OR email3=? OR email4=?', 0, array($invitation['email'], $invitation['email'],$invitation['email'],$invitation['email']) );
64        if(count($user_w_this_email) == 0)
65        {
66            $invit = $db->getRow('SELECT id, status, response FROM invitation_email WHERE email=?', array($invitation['email']) );
67            if(!is_array($invit) || $_POST['id'] && strlen($_POST['id'])==32)
68            {
69                $values = array (
70                        'id_invit' => $_SESSION['my_id'],
71                        'fname' => $invitation['fname'],
72                        'lname' => $invitation['lname'],
73                        'email' => $invitation['email'],
74                        'lname' => $invitation['lname'],
75                        'lang'  => $invitation['lang'],
76                        'type' => $invitation['type'],
77                        'ip'  => $_SERVER['REMOTE_ADDR'],
78                        'date_begin' => time());
79
80                if($_POST['id'] && strlen($_POST['id'])==32 )
81                {
82                    $values['response']=NULL;
83                    $values['failure_notice']=NULL;
84                    $values['status']='todo';
85                    $db->autoExecute('invitation_email', $values, DB_AUTOQUERY_UPDATE, "id='".$_POST['id']."'");
86                }
87                else
88                {
89                    $values['id']= md5($invitation['fname'].$invitation['lname'].$invitation['email']);
90                    $db->autoExecute('invitation_email', $values);
91                }
92
93            }
94            else
95            {
96                $error++;
97                $error_msg[] = _('You or another .node member have invited this person:').' '.$invitation['fname'].' '.$invitation['lname'].' ('.$invitation['email'].')';
98            }
99
100        }
101        elseif(count($user_w_this_email) == 1)
102        {
103            $error++;
104                        $error_msg[] = _('Already member').': <a href="/friends/'.$user_w_this_email[0].'/invitation/already_member">'.$invitation['fname'].' '.$invitation['lname'].' ('.$invitation['email'].')</a>';
105        }
106        else
107        {
108            $error++;
109            $error_msg[] = $invitation['email'].': '._('More than 1 person on .node have this email');
110        }
111    }
112    else
113    {
114        $error++;
115        $error_msg[] = $invitation['fname'].' '.$invitation['lname'].' ('.$invitation['email'].'): '._('You must enter a first name, last name, and valid email');
116    }
117}
118
119if($error > 0)
120{
121    $_SESSION['error']['title'] = $error.' '._('errors');
122    $_SESSION['error']['msg'] = '<ul>';
123    foreach($error_msg as $msg)
124        $_SESSION['error']['msg'] .= '<li>'.$msg.'</li>';
125    $_SESSION['error']['msg'] .= '</ul>';
126   
127}
128
129header('Location: /friends/join');
130
131?>
Note: See TracBrowser for help on using the browser.