[21] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | group_list.php | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
| 6 | // | branch : BSF (Best So Far) | |
---|
| 7 | // +-----------------------------------------------------------------------+ |
---|
| 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2004-02-11 23:20:38 +0000 (Wed, 11 Feb 2004) $ |
---|
| 10 | // | last modifier : $Author: z0rglub $ |
---|
| 11 | // | revision : $Revision: 362 $ |
---|
| 12 | // +-----------------------------------------------------------------------+ |
---|
| 13 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 14 | // | it under the terms of the GNU General Public License as published by | |
---|
| 15 | // | the Free Software Foundation | |
---|
| 16 | // | | |
---|
| 17 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 20 | // | General Public License for more details. | |
---|
| 21 | // | | |
---|
| 22 | // | You should have received a copy of the GNU General Public License | |
---|
| 23 | // | along with this program; if not, write to the Free Software | |
---|
| 24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 25 | // | USA. | |
---|
| 26 | // +-----------------------------------------------------------------------+ |
---|
[226] | 27 | include_once( './admin/include/isadmin.inc.php' ); |
---|
[21] | 28 | //----------------------------------------------------- template initialization |
---|
[225] | 29 | $sub = $vtp->Open( './template/'.$user['template'].'/admin/group_list.vtp' ); |
---|
[21] | 30 | $tpl = array( 'group_add','add','listuser_permission','delete', |
---|
| 31 | 'group_confirm','yes','no','group_list_title' ); |
---|
| 32 | templatize_array( $tpl, 'lang', $sub ); |
---|
[29] | 33 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
[21] | 34 | //-------------------------------------------------------------- delete a group |
---|
| 35 | $error = array(); |
---|
| 36 | if ( isset ( $_GET['delete'] ) and is_numeric( $_GET['delete'] ) ) |
---|
| 37 | { |
---|
| 38 | $query = 'SELECT name'; |
---|
| 39 | $query.= ' FROM '.PREFIX_TABLE.'groups'; |
---|
| 40 | $query.= ' WHERE id = '.$_GET['delete']; |
---|
| 41 | $query.= ';'; |
---|
| 42 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
| 43 | // confirm group deletion ? |
---|
[345] | 44 | if ( !isset( $_GET['confirm'] ) or $_GET['confirm'] != 1 ) |
---|
[21] | 45 | { |
---|
| 46 | $vtp->addSession( $sub, 'deletion' ); |
---|
| 47 | $vtp->setVar( $sub, 'deletion.name', $row['name'] ); |
---|
[143] | 48 | $yes_url = './admin.php?page=group_list&delete='.$_GET['delete']; |
---|
[21] | 49 | $yes_url.= '&confirm=1'; |
---|
| 50 | $vtp->setVar( $sub, 'deletion.yes_url', add_session_id( $yes_url ) ); |
---|
[143] | 51 | $no_url = './admin.php?page=group_list'; |
---|
[21] | 52 | $vtp->setVar( $sub, 'deletion.no_url', add_session_id( $no_url ) ); |
---|
| 53 | $vtp->closeSession( $sub, 'deletion' ); |
---|
| 54 | } |
---|
| 55 | // group deletion confirmed |
---|
| 56 | else |
---|
| 57 | { |
---|
| 58 | $vtp->addSession( $sub, 'confirmation' ); |
---|
| 59 | $query = 'SELECT COUNT(*) AS nb_result'; |
---|
| 60 | $query.= ' FROM '.PREFIX_TABLE.'groups'; |
---|
| 61 | $query.= ' WHERE id = '.$_GET['delete']; |
---|
| 62 | $query.= ';'; |
---|
| 63 | $row2 = mysql_fetch_array( mysql_query( $query ) ); |
---|
| 64 | if ( $row2['nb_result'] > 0 ) |
---|
| 65 | { |
---|
| 66 | delete_group( $_GET['delete'] ); |
---|
| 67 | $vtp->setVar( $sub, 'confirmation.class', 'info' ); |
---|
| 68 | $info = '"'.$row['name'].'" '.$lang['listuser_info_deletion']; |
---|
| 69 | $vtp->setVar( $sub, 'confirmation.info', $info ); |
---|
| 70 | } |
---|
| 71 | else |
---|
| 72 | { |
---|
| 73 | $vtp->setVar( $sub, 'confirmation.class', 'erreur' ); |
---|
| 74 | $vtp->setVar( $sub, 'confirmation.info', $lang['group_err_unknown'] ); |
---|
| 75 | } |
---|
| 76 | $vtp->closeSession( $sub, 'confirmation' ); |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | //----------------------------------------------------------------- add a group |
---|
| 80 | if ( isset( $_POST['submit'] ) ) |
---|
| 81 | { |
---|
| 82 | if ( preg_match( "/'/", $_POST['name'] ) |
---|
| 83 | or preg_match( '/"/', $_POST['name'] ) ) |
---|
| 84 | { |
---|
| 85 | array_push( $error, $lang['group_add_error1'] ); |
---|
| 86 | } |
---|
| 87 | if ( count( $error ) == 0 ) |
---|
| 88 | { |
---|
| 89 | // is the group not already existing ? |
---|
| 90 | $query = 'SELECT id'; |
---|
| 91 | $query.= ' FROM '.PREFIX_TABLE.'groups'; |
---|
| 92 | $query.= " WHERE name = '".$_POST['name']."'"; |
---|
| 93 | $query.= ';'; |
---|
| 94 | $result = mysql_query( $query ); |
---|
| 95 | if ( mysql_num_rows( $result ) > 0 ) |
---|
| 96 | { |
---|
| 97 | array_push( $error, $lang['group_add_error2'] ); |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | if ( count( $error ) == 0 ) |
---|
| 101 | { |
---|
| 102 | // creating the group |
---|
| 103 | $query = ' INSERT INTO '.PREFIX_TABLE.'groups'; |
---|
| 104 | $query.= " (name) VALUES ('".$_POST['name']."')"; |
---|
| 105 | $query.= ';'; |
---|
| 106 | mysql_query( $query ); |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | //-------------------------------------------------------------- errors display |
---|
| 110 | if ( sizeof( $error ) != 0 ) |
---|
| 111 | { |
---|
| 112 | $vtp->addSession( $sub, 'errors' ); |
---|
| 113 | for ( $i = 0; $i < sizeof( $error ); $i++ ) |
---|
| 114 | { |
---|
| 115 | $vtp->addSession( $sub, 'li' ); |
---|
| 116 | $vtp->setVar( $sub, 'li.li', $error[$i] ); |
---|
| 117 | $vtp->closeSession( $sub, 'li' ); |
---|
| 118 | } |
---|
| 119 | $vtp->closeSession( $sub, 'errors' ); |
---|
| 120 | } |
---|
| 121 | //----------------------------------------------------------------- groups list |
---|
| 122 | $vtp->addSession( $sub, 'groups' ); |
---|
| 123 | |
---|
| 124 | $query = 'SELECT id,name'; |
---|
| 125 | $query.= ' FROM '.PREFIX_TABLE.'groups'; |
---|
| 126 | $query.= ' ORDER BY id ASC'; |
---|
| 127 | $query.= ';'; |
---|
| 128 | $result = mysql_query( $query ); |
---|
| 129 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 130 | { |
---|
| 131 | $vtp->addSession( $sub, 'group' ); |
---|
| 132 | $vtp->setVar( $sub, 'group.name', $row['name'] ); |
---|
| 133 | $url = './admin.php?page=group_perm&group_id='.$row['id']; |
---|
| 134 | $vtp->setVar( $sub, 'group.permission_url', add_session_id( $url ) ); |
---|
[143] | 135 | $url = './admin.php?page=group_list&delete='.$row['id']; |
---|
[21] | 136 | $vtp->setVar( $sub, 'group.deletion_url', add_session_id( $url ) ); |
---|
| 137 | $vtp->closeSession( $sub, 'group' ); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | $vtp->closeSession( $sub, 'groups' ); |
---|
| 141 | //------------------------------------------------------- create new group form |
---|
| 142 | $action = './admin.php?'.$_SERVER['QUERY_STRING']; |
---|
| 143 | $vtp->setVar( $sub, 'form_action', $action ); |
---|
| 144 | //----------------------------------------------------------- sending html code |
---|
| 145 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
[362] | 146 | ?> |
---|