<?php

/*
 *	  CLASS:  UserList
 *    
*/
class UserList {
	private $all = array();
	
	
	function __construct($bHideSelect = False) {
		$this->init($bHideSelect);
	}
	
	private function init($bHideSelect = False) {
		try {
			// get the list of active users
			$sql = "SELECT uid, name FROM {users} u
							WHERE status = 1 ORDER BY name";	
			$results = db_query($sql);

			if ( !$bHideSelect ) {
				$this->all[0] = '- Select -';  // add default option
			}

			foreach($results as $u) {
				// this is needed for a mixed select list
				// add the 'U' suffix to the id
				// if the outside processes need it, its available
				// if the outside processes do not need it, its easily ignored when cast to an int
				
				$this->all[$u->uid . 'U'] = $u->name;
			}
		}
		catch (Exception $e) {
			watchdog('sabreQMS', 'UserList::init() ' . $e->getMessage(), array(), WATCHDOG_ERROR);
		} 	
	}
	
	public function get($assigned_user_list = array()) {
		
		// if an $assigned_user_list is passed as a parm, 
		// remove those users from the user list returned
		// returns all items in $this->all not in the $assigned_user_list
		
		return array_diff($this->all, $assigned_user_list);
	}

	public function getName($id) {
		if ( $id && isset($this->all[$id]) ) {
			return $this->all[$id];
		}
		return '';
	}
	
	
} // end - class UserList
