1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * group.php * |
---|
4 | * ------------------- * |
---|
5 | * application : PhpWebGallery 1.3 * |
---|
6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
7 | * * |
---|
8 | ***************************************************************************/ |
---|
9 | |
---|
10 | /*************************************************************************** |
---|
11 | * * |
---|
12 | * This program is free software; you can redistribute it and/or modify * |
---|
13 | * it under the terms of the GNU General Public License as published by * |
---|
14 | * the Free Software Foundation; * |
---|
15 | * * |
---|
16 | ***************************************************************************/ |
---|
17 | include_once( './include/isadmin.inc.php' ); |
---|
18 | //----------------------------------------------------- template initialization |
---|
19 | $sub = $vtp->Open( '../template/'.$user['template'].'/admin/group_list.vtp' ); |
---|
20 | $tpl = array( 'group_add','add','listuser_permission','delete', |
---|
21 | 'group_confirm','yes','no','group_list_title' ); |
---|
22 | templatize_array( $tpl, 'lang', $sub ); |
---|
23 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
24 | //-------------------------------------------------------------- delete a group |
---|
25 | $error = array(); |
---|
26 | if ( isset ( $_GET['delete'] ) and is_numeric( $_GET['delete'] ) ) |
---|
27 | { |
---|
28 | $query = 'SELECT name'; |
---|
29 | $query.= ' FROM '.PREFIX_TABLE.'groups'; |
---|
30 | $query.= ' WHERE id = '.$_GET['delete']; |
---|
31 | $query.= ';'; |
---|
32 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
33 | // confirm group deletion ? |
---|
34 | if ( $_GET['confirm'] != 1 ) |
---|
35 | { |
---|
36 | $vtp->addSession( $sub, 'deletion' ); |
---|
37 | $vtp->setVar( $sub, 'deletion.name', $row['name'] ); |
---|
38 | $yes_url = './admin.php?page=group&delete='.$_GET['delete']; |
---|
39 | $yes_url.= '&confirm=1'; |
---|
40 | $vtp->setVar( $sub, 'deletion.yes_url', add_session_id( $yes_url ) ); |
---|
41 | $no_url = './admin.php?page=group'; |
---|
42 | $vtp->setVar( $sub, 'deletion.no_url', add_session_id( $no_url ) ); |
---|
43 | $vtp->closeSession( $sub, 'deletion' ); |
---|
44 | } |
---|
45 | // group deletion confirmed |
---|
46 | else |
---|
47 | { |
---|
48 | $vtp->addSession( $sub, 'confirmation' ); |
---|
49 | $query = 'SELECT COUNT(*) AS nb_result'; |
---|
50 | $query.= ' FROM '.PREFIX_TABLE.'groups'; |
---|
51 | $query.= ' WHERE id = '.$_GET['delete']; |
---|
52 | $query.= ';'; |
---|
53 | $row2 = mysql_fetch_array( mysql_query( $query ) ); |
---|
54 | if ( $row2['nb_result'] > 0 ) |
---|
55 | { |
---|
56 | delete_group( $_GET['delete'] ); |
---|
57 | $vtp->setVar( $sub, 'confirmation.class', 'info' ); |
---|
58 | $info = '"'.$row['name'].'" '.$lang['listuser_info_deletion']; |
---|
59 | $vtp->setVar( $sub, 'confirmation.info', $info ); |
---|
60 | } |
---|
61 | else |
---|
62 | { |
---|
63 | $vtp->setVar( $sub, 'confirmation.class', 'erreur' ); |
---|
64 | $vtp->setVar( $sub, 'confirmation.info', $lang['group_err_unknown'] ); |
---|
65 | } |
---|
66 | $vtp->closeSession( $sub, 'confirmation' ); |
---|
67 | } |
---|
68 | } |
---|
69 | //----------------------------------------------------------------- add a group |
---|
70 | if ( isset( $_POST['submit'] ) ) |
---|
71 | { |
---|
72 | if ( preg_match( "/'/", $_POST['name'] ) |
---|
73 | or preg_match( '/"/', $_POST['name'] ) ) |
---|
74 | { |
---|
75 | array_push( $error, $lang['group_add_error1'] ); |
---|
76 | } |
---|
77 | if ( count( $error ) == 0 ) |
---|
78 | { |
---|
79 | // is the group not already existing ? |
---|
80 | $query = 'SELECT id'; |
---|
81 | $query.= ' FROM '.PREFIX_TABLE.'groups'; |
---|
82 | $query.= " WHERE name = '".$_POST['name']."'"; |
---|
83 | $query.= ';'; |
---|
84 | $result = mysql_query( $query ); |
---|
85 | if ( mysql_num_rows( $result ) > 0 ) |
---|
86 | { |
---|
87 | array_push( $error, $lang['group_add_error2'] ); |
---|
88 | } |
---|
89 | } |
---|
90 | if ( count( $error ) == 0 ) |
---|
91 | { |
---|
92 | // creating the group |
---|
93 | $query = ' INSERT INTO '.PREFIX_TABLE.'groups'; |
---|
94 | $query.= " (name) VALUES ('".$_POST['name']."')"; |
---|
95 | $query.= ';'; |
---|
96 | mysql_query( $query ); |
---|
97 | } |
---|
98 | } |
---|
99 | //-------------------------------------------------------------- errors display |
---|
100 | if ( sizeof( $error ) != 0 ) |
---|
101 | { |
---|
102 | $vtp->addSession( $sub, 'errors' ); |
---|
103 | for ( $i = 0; $i < sizeof( $error ); $i++ ) |
---|
104 | { |
---|
105 | $vtp->addSession( $sub, 'li' ); |
---|
106 | $vtp->setVar( $sub, 'li.li', $error[$i] ); |
---|
107 | $vtp->closeSession( $sub, 'li' ); |
---|
108 | } |
---|
109 | $vtp->closeSession( $sub, 'errors' ); |
---|
110 | } |
---|
111 | //----------------------------------------------------------------- groups list |
---|
112 | $vtp->addSession( $sub, 'groups' ); |
---|
113 | |
---|
114 | $query = 'SELECT id,name'; |
---|
115 | $query.= ' FROM '.PREFIX_TABLE.'groups'; |
---|
116 | $query.= ' ORDER BY id ASC'; |
---|
117 | $query.= ';'; |
---|
118 | $result = mysql_query( $query ); |
---|
119 | while ( $row = mysql_fetch_array( $result ) ) |
---|
120 | { |
---|
121 | $vtp->addSession( $sub, 'group' ); |
---|
122 | $vtp->setVar( $sub, 'group.name', $row['name'] ); |
---|
123 | $url = './admin.php?page=group_perm&group_id='.$row['id']; |
---|
124 | $vtp->setVar( $sub, 'group.permission_url', add_session_id( $url ) ); |
---|
125 | $url = './admin.php?page=group&delete='.$row['id']; |
---|
126 | $vtp->setVar( $sub, 'group.deletion_url', add_session_id( $url ) ); |
---|
127 | $vtp->closeSession( $sub, 'group' ); |
---|
128 | } |
---|
129 | |
---|
130 | $vtp->closeSession( $sub, 'groups' ); |
---|
131 | //------------------------------------------------------- create new group form |
---|
132 | $action = './admin.php?'.$_SERVER['QUERY_STRING']; |
---|
133 | $vtp->setVar( $sub, 'form_action', $action ); |
---|
134 | //----------------------------------------------------------- sending html code |
---|
135 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
136 | ?> |
---|