root / editClub.php @ 6ebba44e3bf110d4ce262c25b020719c2f060e94

1
<?php
2
3
/*
4
5
  Copyright (C) 2010, All Rights Reserved.
6
7
  This file is part of RPInventory.
8
9
  RPInventory is free software: you can redistribute it and/or modify
10
  it under the terms of the GNU General Public License as published by
11
  the Free Software Foundation, either version 3 of the License, or
12
  (at your option) any later version.
13
14
  RPInventory is distributed in the hope that it will be useful,
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
  GNU General Public License for more details.
18
19
  You should have received a copy of the GNU General Public License
20
  along with RPInventory.  If not, see <http://www.gnu.org/licenses/>.
21
22
*/
23
24
require_once("lib/auth.lib.php");  //Session
25
require_once('lib/clubs.lib.php');
26
require_once('lib/users.lib.php');
27
require_once('class/database.class.php');
28
29
function array_obj_diff ($array1, $array2) {
30
    $usernames = array();
31
    $usernames_remove = array();
32
    $result = array();
33
34
    // All usernames
35
    foreach ($array1 as &$obj)
36
    {
37
        array_push($usernames, $obj->username);
38
    }
39
40
    // All usernames to remove
41
    foreach ($array2 as &$obj)
42
    {
43
        if (in_array($obj->username, $usernames))
44
        {
45
            array_push($usernames_remove, $obj->username);
46
        }
47
    }
48
49
    for ($i=0; $i<count($usernames); $i++)
50
    {
51
        if (in_array($usernames[$i], $usernames_remove))
52
        {
53
            array_shift($array1);
54
        }
55
        else
56
        {
57
            array_push($result, array_shift($array1));
58
        }
59
    }
60
   
61
    return $result;
62
}
63
64
// Connect
65
$db = new database();
66
67
//Authenticate
68
$auth = GetAuthority();        
69
if ($auth < 3)
70
{
71
        die( 'Permission Denied' );
72
}
73
74
// SMARTY Setup
75
require_once('lib/smarty_inv.class.php');
76
$smarty = new Smarty_Inv();
77
78
$id = (int)$_GET['id'];
79
if ($id == 0)
80
{
81
    die("Invalid ID Given");
82
}
83
84
//club
85
$club = getClub($id, $db);
86
87
if ($club == false)
88
{
89
    die("Could not get information");
90
}
91
92
$users = getAllUsers($db);
93
$club_users = getClubUsers($id, $db);
94
95
$display_users = array_obj_diff($users, $club_users);
96
97
//Assign vars
98
$smarty->assign('title', "Edit Club");
99
$smarty->assign('authority', $auth);
100
$smarty->assign('page_tpl', 'editClub');
101
$smarty->assign('club_id', $id);
102
$smarty->assign('club', $club);
103
$smarty->assign('users', $club_users);
104
$smarty->assign('newUsers', $display_users);
105
106
$smarty->display('index.tpl');
107
108
$db->close();
109
110
?>
111