blob: 205326eb77ca680d2cfa58a4c959a0f55bc0ec6d [file] [log] [blame]
<?php
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* \file
*/
////////////////////////////////////////////////////////////////////////////////
///
/// \fn addITECSUser($loginid)
///
/// \param $loginid - email address of user
///
/// \return new id from user table or NULL if there was a problem
///
/// \brief looks up a user's info in the accounts database and adds the user to
/// our database
///
////////////////////////////////////////////////////////////////////////////////
function addITECSUser($loginid) {
global $mysql_link_vcl, $ENABLE_ITECSAUTH;
if(! $ENABLE_ITECSAUTH)
return NULL;
$query = "SELECT id AS uid, "
. "first, "
. "middle, "
. "last, "
. "email, "
. "created, "
. "active, "
. "lockedout "
. "FROM user "
. "WHERE email = '$loginid'";
$qh = doQuery($query, 101, "accounts");
if($row = mysql_fetch_assoc($qh)) {
// FIXME test replacing ''s
// FIXME do we care if the account is active?
$first = ereg_replace("'", "\'", $row['first']);
$middle = ereg_replace("'", "\'", $row['middle']);
$last = ereg_replace("'", "\'", $row['last']);
$loweruser = strtolower($row['email']);
$query = "INSERT INTO user ("
. "uid, "
. "unityid, "
. "affiliationid, "
. "firstname, "
. "middlename, "
. "lastname, "
. "email, "
. "emailnotices, "
. "lastupdated) "
. "VALUES ("
. "{$row['uid']}, "
. "'$loweruser', "
. "2, "
. "'$first', "
. "'$middle', "
. "'$last', "
. "'{$row['email']}', "
. "0, "
. "NOW())";
// FIXME might want this logged
doQuery($query, 101, 'vcl', 1);
}
if(mysql_affected_rows($mysql_link_vcl)) {
$qh = doQuery("SELECT LAST_INSERT_ID() FROM user", 101);
if(! $row = mysql_fetch_row($qh)) {
abort(101);
}
return $row[0];
}
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn validateITECSUser($loginid)
///
/// \param $loginid - email address for user
///
/// \return 1 if account exists and is active or not yet activated, 0 otherwise
///
/// \brief looks up $loginid in accounts db
///
////////////////////////////////////////////////////////////////////////////////
function validateITECSUser($loginid) {
global $ENABLE_ITECSAUTH;
if(! $ENABLE_ITECSAUTH)
return 0;
$query = "SELECT email "
. "FROM user "
. "WHERE email = '$loginid' AND "
. "(active = 1 OR "
. "activated = 0)";
$qh = doQuery($query, 101, "accounts");
if(mysql_num_rows($qh))
return 1;
return 0;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn updateITECSUser($userid)
///
/// \param $userid - email address for user
///
/// \return NULL if fail to update data or an array with these elements:\n
/// \b id - user's numeric from user table\n
/// \b uid - user's numeric unity id\n
/// \b unityid - unity ID for the user\n
/// \b affiliation - user's affiliation\n
/// \b affiliationid - user's affiliation id\n
/// \b curriculum - curriculum user is in\n
/// \b firstname - user's first name\n
/// \b preferredname - user's preferred name\n
/// \b middlename - user's middle name\n
/// \b lastname - user's last name\n
/// \b email - user's preferred email address\n
/// \b IMtype - user's preferred IM protocol\n
/// \b IMid - user's IM id\n
/// \b adminlevel - user's admin level (= 'none' if no admin access)\n
/// \b adminlevelid - id of adminlevel\n
/// \b width - rdp file width\n
/// \b height - rdp file height\n
/// \b bpp - rdp file bpp\n
/// \b audiomode - rdp file audio mode\n
/// \b mapdrives - rdp file drive mapping\n
/// \b mapprinters - rdp file printer mapping\n
/// \b mapserial - rdp file serial port mapping\n
/// \b showallgroups - show all user groups or not\n
/// \b lastupdated - datetime the information was last updated
///
/// \brief updates user's info in the user table; adds user if not already in
/// table
///
////////////////////////////////////////////////////////////////////////////////
function updateITECSUser($userid) {
global $ENABLE_ITECSAUTH;
if(! $ENABLE_ITECSAUTH)
return NULL;
$query = "SELECT id AS uid, "
. "first, "
. "middle, "
. "last, "
. "email, "
. "created "
. "FROM user "
. "WHERE email = '$userid'";
$qh = doQuery($query, 101, "accounts");
if(! ($userData = mysql_fetch_assoc($qh)))
return NULL;
$now = unixToDatetime(time());
// select desired data from db
$query = "SELECT c.name AS curriculum, "
. "i.name AS IMtype, "
. "u.IMid AS IMid, "
. "u.affiliationid, "
. "af.name AS affiliation, "
. "a.name AS adminlevel, "
. "a.id AS adminlevelid, "
. "u.preferredname AS preferredname, "
. "u.uid AS uid, "
. "u.id AS id, "
. "u.width AS width, "
. "u.height AS height, "
. "u.bpp AS bpp, "
. "u.audiomode AS audiomode, "
. "u.mapdrives AS mapdrives, "
. "u.mapprinters AS mapprinters, "
. "u.mapserial AS mapserial, "
. "u.showallgroups "
. "FROM user u, "
. "curriculum c, "
. "IMtype i, "
. "affiliation af, "
. "adminlevel a "
. "WHERE u.curriculumid = c.id AND "
. "u.IMtypeid = i.id AND "
. "u.adminlevelid = a.id AND "
. "u.affiliationid = af.id AND "
. "u.uid = " . $userData["uid"];
$qh = doQuery($query, 255);
// if get a row
// update db
// update results from select
if($user = mysql_fetch_assoc($qh)) {
$user["unityid"] = $userid;
$user["firstname"] = $userData['first'];
$user["middlename"] = $userData['middle'];
$user["lastname"] = $userData["last"];
$user["email"] = $userData["email"];
$user["lastupdated"] = $now;
$query = "UPDATE user "
. "SET unityid = '$userid', "
. "firstname = '{$userData['first']}', "
. "middlename = '{$userData['middle']}', "
. "lastname = '{$userData['last']}', "
. "email = '{$userData['email']}', "
. "lastupdated = '$now' "
. "WHERE uid = " . $userData["uid"];
doQuery($query, 256, 'vcl', 1);
}
else {
// call addITECSUser
$id = addITECSUser($userid);
$query = "SELECT u.unityid AS unityid, "
. "u.affiliationid, "
. "af.name AS affiliation, "
. "c.name AS curriculum, "
. "u.firstname AS firstname, "
. "u.middlename AS middlename, "
. "u.lastname AS lastname, "
. "u.preferredname AS preferredname, "
. "u.email AS email, "
. "i.name AS IMtype, "
. "u.IMid AS IMid, "
. "u.uid AS uid, "
. "u.id AS id, "
. "a.name AS adminlevel, "
. "a.id AS adminlevelid, "
. "u.width AS width, "
. "u.height AS height, "
. "u.bpp AS bpp, "
. "u.audiomode AS audiomode, "
. "u.mapdrives AS mapdrives, "
. "u.mapprinters AS mapprinters, "
. "u.mapserial AS mapserial, "
. "u.showallgroups, "
. "u.lastupdated AS lastupdated "
. "FROM user u, "
. "curriculum c, "
. "IMtype i, "
. "affiliation af, "
. "adminlevel a "
. "WHERE u.curriculumid = c.id AND "
. "u.IMtypeid = i.id AND "
. "u.adminlevelid = a.id AND "
. "u.affiliationid = af.id AND "
. "u.id = $id";
$qh = doQuery($query, 101);
$user = mysql_fetch_assoc($qh);
# add account to demo group
$demoid = getUserGroupID('demo', getAffiliationID('ITECS'));
updateGroups(array($demoid), $user['id']);
}
$user["groups"] = getUsersGroups($user["id"], 1);
checkExpiredDemoUser($user['id'], $user['groups']);
$user["privileges"] = getOverallUserPrivs($user["id"]);
$tmparr = explode('@', $user['unityid']);
$user['login'] = $tmparr[0];
return $user;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn testITECSAffiliation(&$login, &$affilid)
///
/// \param $login - (pass by ref) a login id with affiliation
/// \param $affilid - (pass by ref) gets overwritten
///
/// \return - 1 if successfully found affiliation id, 0 if failed
///
/// \brief changes $login to be without affiliation and sticks the associated
/// affiliation id for ITECS in $affilid
///
////////////////////////////////////////////////////////////////////////////////
function testITECSAffiliation(&$login, &$affilid) {
if(preg_match('/^([^@]*@[^@]*\.[^@]*)@ITECS$/', $login, $matches) ||
preg_match('/^([^@]*@[^@]*\.[^@]*)$/', $login, $matches)) {
$login = $matches[1];
$affilid = getAffiliationID('ITECS');
return 1;
}
return 0;
}
array_push($findAffilFuncs, "testITECSAffiliation");
?>