<?php
/*
 *    Copyright (c) 2010 VidiScript
 *
 *    This file is part of VidiScript.
 *
 *    VidiScript is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    VidiScript is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with VidiScript.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    File Name: groupsavailable.inc
 *    Description: Functions  for determining  which groups are available to the currently logged in member
 *    $Date: 2010-02-21 23:16:57 +0000 (Sun, 21 Feb 2010) $
 *    $Revision: 12 $
 */
function groupOptions($currentGroupid) {
	global $db,$sitepath,$loggedIn,$templateimagepath ;
	$db->query("SELECT id FROM member WHERE username = '".quote_smart($_SESSION['username'])."'") ;
	$res = $db->fetch() ;
	$memberid = $res['id'] ;
	$joinquery = "SELECT * FROM `group` LEFT JOIN `group_member` ON (`group`.`group_id`=`group_member`.`group_id_g`) WHERE ((`group_member`.`member_id`=".$memberid.") AND (`group_member`.`approved`=1)) OR (`group`.`owner_id`=".$memberid.") GROUP BY `group`.`group_id`" ;
	$db->query($joinquery) ;
	$res = $db->fetchAll() ;
	if ($currentGroupid == 0) {
		$groups = "<option value=\"0\" SELECTED>(No Group)</option>" ;
	}
	else {
		$groups = "<option value=\"0\">(No Group)</option>" ;
	}
	if ($db->numRows() > 0) {
		foreach ($res as $key=>$value) {
			if (($value['group_id'] == $currentGroupid) && ($currentGroupid != 0)) {
				$selectedString = ' SELECTED' ;
			}
			else {
				$selectedString = '' ;
			}
			$groups .= '<option value="'.$value['group_id'].'"'.$selectedString.'>'.$value['name'].'</option>' ;
		}
	}
	$groups .= "group".$currentGroupid ;
	return $groups ;
}

?>
