All pastes #516918 Raw Edit

Untitled

public text v1 · immutable
#516918 ·published 2007-05-28 22:04 UTC
rendered paste body
	/**
	 * Update userinformation
	 *
	 * @params array $args
	 * @params array $fields
	 */
	function update ($id, $args, $fields, $table = 'users') {
		$update = '';
		$c = count($fields) - 1;
		$x = 0;
		foreach($fields as $key):
			if(isset($args[$key])):
				$update .= "$key = '{$args[$key]}'";
				
				if($x != $c)
					$update .= ', ';
				++$x;
			endif;
		endforeach;
	
		if($table == 'users'):
			if(isset($args['admin']) && $args['admin'] == 1)
				if(!$this->isAdmin($id))
					$this->makeAdmin($id);
			
			if(isset($args['admin']) && $args['admin'] == 0)
				if($this->isAdmin($id))
					$this->revokeAdmin($id);
		endif;

		$this->db->query("update $table set $update where id = $id");
	}