Changeset 9372 for extensions/community/admin.php
- Timestamp:
- Feb 25, 2011, 12:22:52 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/community/admin.php
r3673 r9372 3 3 // | Piwigo - a PHP based picture gallery | 4 4 // +-----------------------------------------------------------------------+ 5 // | Copyright(C) 2009 Pierrick LE GALL http://piwigo.org | 5 // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | 6 // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | 7 // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | 6 8 // +-----------------------------------------------------------------------+ 7 9 // | This program is free software; you can redistribute it and/or modify | … … 26 28 27 29 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 30 include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); 31 28 32 load_language('plugin.lang', COMMUNITY_PATH); 29 33 30 $conf['community_permission_levels'] = array(1,2); 31 $admin_base_url = get_root_url().'admin.php?page=plugin§ion=community%2Fadmin.php'; 34 define('COMMUNITY_BASE_URL', get_root_url().'admin.php?page=plugin-community'); 32 35 33 36 // +-----------------------------------------------------------------------+ 34 37 // | Check Access and exit when user status is not ok | 35 38 // +-----------------------------------------------------------------------+ 39 36 40 check_status(ACCESS_ADMINISTRATOR); 37 41 38 42 // +-----------------------------------------------------------------------+ 39 // | functions|43 // | Tabs | 40 44 // +-----------------------------------------------------------------------+ 41 45 42 function get_permission_level_label($level) 46 $tabs = array( 47 array( 48 'code' => 'permissions', 49 'label' => l10n('Upload Permissions'), 50 ), 51 array( 52 'code' => 'pendings', 53 'label' => l10n('Pending Photos'), 54 ), 55 ); 56 57 $tab_codes = array_map( 58 create_function('$a', 'return $a["code"];'), 59 $tabs 60 ); 61 62 if (isset($_GET['tab']) and in_array($_GET['tab'], $tab_codes)) 43 63 { 44 return '('.$level.') '.l10n( sprintf('Community level %d', $level) ); 64 $page['tab'] = $_GET['tab']; 65 } 66 else 67 { 68 $page['tab'] = $tabs[0]['code']; 45 69 } 46 70 47 // +-----------------------------------------------------------------------+ 48 // | add permissions | 49 // +-----------------------------------------------------------------------+ 50 51 if (isset($_POST['submit_add']) and !is_adviser()) 71 $tabsheet = new tabsheet(); 72 foreach ($tabs as $tab) 52 73 { 53 if (!is_numeric($_POST['user_options'])) 54 { 55 array_push($page['errors'], 'invalid user'); 56 } 57 if (!is_numeric($_POST['permission_level_options'])) 58 { 59 array_push($page['errors'], 'invalid permission level'); 60 } 61 62 if (count($page['errors']) == 0) 63 { 64 $query = ' 65 SELECT 66 '.$conf['user_fields']['username'].' AS username 67 FROM '.USERS_TABLE.' 68 WHERE '.$conf['user_fields']['id'].' = '.$_POST['user_options'].' 69 ;'; 70 list($username) = mysql_fetch_row(pwg_query($query)); 71 // remove any existing permission for this user 72 $query = ' 73 DELETE 74 FROM '.COMMUNITY_TABLE.' 75 WHERE user_id = '.$_POST['user_options'].' 76 ;'; 77 pwg_query($query); 78 79 // creating the permission 80 $query = ' 81 INSERT INTO '.COMMUNITY_TABLE.' 82 (user_id, permission_level) 83 VALUES 84 ('.$_POST['user_options'].', '.$_POST['permission_level_options'].') 85 ;'; 86 pwg_query($query); 87 88 array_push( 89 $page['infos'], 90 sprintf( 91 l10n('community permissions "%s" added/updated for "%s"'), 92 get_permission_level_label($_POST['permission_level_options']), 93 $username 94 ) 95 ); 96 } 97 74 $tabsheet->add( 75 $tab['code'], 76 $tab['label'], 77 COMMUNITY_BASE_URL.'-'.$tab['code'] 78 ); 98 79 } 99 100 // +-----------------------------------------------------------------------+ 101 // | remove permissions | 102 // +-----------------------------------------------------------------------+ 103 104 if (isset($_GET['delete']) and !is_adviser()) 105 { 106 if (is_numeric($_GET['delete'])) 107 { 108 $query = ' 109 SELECT 110 community.user_id, 111 community.permission_level, 112 u.'.$conf['user_fields']['username'].' AS username 113 FROM '.COMMUNITY_TABLE.' AS community 114 INNER JOIN '.USERS_TABLE.' AS u 115 ON u.'.$conf['user_fields']['id'].' = community.user_id 116 WHERE community.user_id = '.$_GET['delete'].' 117 ;'; 118 $result = pwg_query($query); 119 if (mysql_num_rows($result) == 0) 120 { 121 array_push($page['errors'], 'this user has no community permission yet'); 122 } 123 124 if (count($page['errors']) == 0) 125 { 126 list($user_id, $permission_level, $username) = mysql_fetch_row($result); 127 128 $query = ' 129 DELETE 130 FROM '.COMMUNITY_TABLE.' 131 WHERE user_id = '.$user_id.' 132 ;'; 133 pwg_query($query); 134 135 array_push( 136 $page['infos'], 137 sprintf( 138 l10n('community permissions "%s" removed for "%s"'), 139 get_permission_level_label($permission_level), 140 $username 141 ) 142 ); 143 } 144 } 145 } 80 $tabsheet->select($page['tab']); 81 $tabsheet->assign(); 146 82 147 83 // +-----------------------------------------------------------------------+ … … 151 87 $template->set_filenames( 152 88 array( 153 'p lugin_admin_content' => dirname(__FILE__).'/admin.tpl'89 'photos_add' => 'photos_add_'.$page['tab'].'.tpl' 154 90 ) 155 91 ); 156 92 157 $template->assign(158 array(159 'F_ADD_ACTION'=> $admin_base_url,160 )161 );162 163 164 // user options165 $query = '166 SELECT167 u.'.$conf['user_fields']['id'].' AS id,168 u.'.$conf['user_fields']['username'].' AS username169 FROM '.USERS_TABLE.' AS u170 INNER JOIN '.USER_INFOS_TABLE.' AS ui171 ON u.'.$conf['user_fields']['id'].' = ui.user_id172 WHERE ui.status = "normal"173 ORDER BY username174 ;';175 $user_options = array();176 $result = pwg_query($query);177 while ($row = mysql_fetch_assoc($result))178 {179 $user_options[ $row['id'] ] = $row['username'];180 }181 $template->assign(182 array(183 'user_options'=> $user_options,184 )185 );186 187 188 // permission level options189 $permission_level_options = array();190 foreach ($conf['community_permission_levels'] as $level)191 {192 $permission_level_options[$level] = get_permission_level_label($level);193 }194 $template->assign(195 array(196 'permission_level_options'=> $permission_level_options,197 )198 );199 200 // user with community permissions201 $query = '202 SELECT203 community.user_id,204 community.permission_level,205 u.'.$conf['user_fields']['username'].' AS username206 FROM '.COMMUNITY_TABLE.' AS community207 INNER JOIN '.USERS_TABLE.' AS u208 ON u.'.$conf['user_fields']['id'].' = community.user_id209 ORDER BY username210 ;';211 $result = pwg_query($query);212 213 while ($row = mysql_fetch_assoc($result))214 {215 $template->append(216 'users',217 array(218 'NAME' => $row['username'],219 'PERMISSION_LEVEL' => get_permission_level_label($row['permission_level']),220 'U_DELETE' => $admin_base_url.'&delete='.$row['user_id']221 )222 );223 }224 225 93 // +-----------------------------------------------------------------------+ 226 // | sending html code|94 // | Load the tab | 227 95 // +-----------------------------------------------------------------------+ 228 96 229 $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');97 include(COMMUNITY_PATH.'admin_'.$page['tab'].'.php'); 230 98 ?>
Note: See TracChangeset
for help on using the changeset viewer.