Project

General

Profile

« Previous | Next » 

Revision 318

Added by stefan about 18 years ago

Added methods get_user_details, get_page_details, get_page_permission to class admin.

View differences:

class.admin.php
183 183
			}
184 184
		}
185 185
	}
186
		
187
	function get_user_details($user_id) {
188
		global $database;
189
		$query_user = "SELECT username,display_name FROM ".TABLE_PREFIX."users WHERE user_id = '$user_id'";
190
		$get_user = $database->query($query_user);
191
		if($get_user->numRows() != 0) {
192
			$user = $get_user->fetchRow();
193
		} else {
194
			$user['display_name'] = 'Unknown';
195
			$user['username'] = 'unknown';
196
		}
197
		return $user;
198
	}	
199
	
200
	function get_page_details($page_id) {
201
		$query = "SELECT page_id,page_title,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
202
		$results = $database->query($query);
203
		if($database->is_error()) {
204
			$this->print_header();
205
			$this->print_error($database->get_error());
206
		}
207
		if($results->numRows() == 0) {
208
			$this->print_header();
209
			$this->print_error($MESSAGE['PAGES']['NOT_FOUND']);
210
		}
211
		$results_array = $results->fetchRow();
212
		return $results_array;
213
	}	
214
	
215
	/** Function get_page_permission takes either a numerical page_id,
216
	 * upon which it looks up the permissions in the database,
217
	 * or an array with keys admin_groups and admin_users  
218
	 */
219
	function get_page_permission($page,$action='admin') {
220
		if ($action!='viewing') $action='admin';
221
		$action_groups=$action.'_groups';
222
		$action_users=$action.'_users';
223
		if (is_array($page)) {
224
				$groups=$page[$action_groups];
225
				$users=$page[$action_users];
226
		} else {				
227
			global $database;
228
			$results = $database->query("SELECT $action_groups,$action_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
229
			$result = $results->fetchRow();
230
			$groups = explode(',', str_replace('_', '', $result[$action_groups]));
231
			$users = explode(',', str_replace('_', '', $result[$action_users]));
232
		}
233
		if(!is_numeric(array_search($this->get_group_id(), $groups)) AND !is_numeric(array_search($this->get_user_id(), $users))) {
234
			return false;
235
		}
236
		return true;
237
	}
238
		
186 239

  
187 240
	// Returns a system permission for a menu link
188 241
	function get_link_permission($title) {

Also available in: Unified diff