Location: PHPKode > projects > ConPortal > conportal/inc/groups/db.php
<?php
/*
 *  ConPortal - Pomona College ITS scheduling appplication
 *  Copyright (C) 2005-2006  Pomona College
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of version 2 of the GNU General Public License
 *  as published by the Free Software Foundation.
 *
 *  This program 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/*
 * Functions in this file:
 *    createGroup
 *    getAllGroups
 *    getGroupDetails
 *    getGroupsForPosition
 *    getPrimaryGroups
 *    getSecurityGroups
 *    isPrimaryGroup
 *    removeGroup
 */

function createGroup ($name, $desc, $primary_group)
{
    safeQuery("insert into groups set name = '%s', description = '%s', " .
		"primary_group = '%s'",
		mysql_real_escape_string(strtolower($name)),
		mysql_real_escape_string($desc),
		mysql_real_escape_string($primary_group));
    return mysql_insert_id();
}

function getAllGroups ()
{
    $result = safeQuery("select pid from groups");
    $a = array();
    while ($row = mysql_fetch_assoc($result))
        $a[] = $row['pid'];
    return $a;
}

function getGroupDetails ($pid)
{
    $result = safeQuery("select * from groups where pid = " . intval($pid));
    return mysql_fetch_assoc($result);
}

function getGroupsForPosition ($positionPid)
{
    $result = safeQuery("select `group` from position_group where position = %d", $positionPid);
    $a = array();
    while ($row = mysql_fetch_assoc($result))
        $a[] = $row['group'];
    return $a;
}

function getPrimaryGroups ()
{
    $result = safeQuery("select pid from groups where primary_group = TRUE");
    $a = array();
    while ($row = mysql_fetch_assoc($result))
        $a[] = $row['pid'];
    return $a;
}

function getSecurityGroups ()
{
    $result = safeQuery("select pid from groups where primary_group = FALSE");
    $a = array();
    while ($row = mysql_fetch_assoc($result))
        $a[] = $row['pid'];
    return $a;
}

function isPrimaryGroup ($pid)
{
    $info = getGroupDetails($pid);
    return ($info and $info['primary_group']);
}

// Delete all references to the group
// (so, look at the user_group, groups, and group_perm tables)
function removeGroup ($pid)
{
    safeQuery("delete from user_group where `group` = %d", $pid);
    safeQuery("delete from group_perm where `group` = %d", $pid);
    safeQuery("delete from groups where pid = %d", $pid);
}

?>
Return current item: ConPortal