2000-10-20 04:45:54 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare - administration *
|
|
|
|
* http://www.phpgroupware.org *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program 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 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2000-10-20 06:43:13 +02:00
|
|
|
function account_read($method,$start,$sort,$order)
|
2000-10-20 04:45:54 +02:00
|
|
|
{
|
2000-10-20 07:14:53 +02:00
|
|
|
global $phpgw;
|
|
|
|
|
|
|
|
if (! $start) {
|
|
|
|
$start = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($order) {
|
|
|
|
$ordermethod = "order by $order $sort";
|
|
|
|
} else {
|
2000-11-17 22:16:49 +01:00
|
|
|
$ordermethod = "order by account_lid,account_lastname,account_firstname asc";
|
2000-10-20 07:14:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! $sort) {
|
|
|
|
$sort = "desc";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($query) {
|
|
|
|
$querymethod = " where account_firstname like '%$query%' OR account_lastname like "
|
|
|
|
. "'%$query%' OR account_lid like '%$query%' ";
|
|
|
|
}
|
2000-10-20 04:45:54 +02:00
|
|
|
|
2000-10-20 07:14:53 +02:00
|
|
|
$phpgw->db->query("select account_id,account_firstname,account_lastname,account_lid "
|
|
|
|
. "from accounts $querymethod $ordermethod limit "
|
|
|
|
. $phpgw->nextmatchs->sql_limit($start));
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
while ($phpgw->db->next_record()) {
|
|
|
|
$account_info[$i]["account_id"] = $phpgw->db->f("account_id");
|
|
|
|
$account_info[$i]["account_lid"] = $phpgw->db->f("account_lid");
|
|
|
|
$account_info[$i]["account_lastname"] = $phpgw->db->f("account_lastname");
|
|
|
|
$account_info[$i]["account_firstname"] = $phpgw->db->f("account_firstname");
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $account_info;
|
2000-10-20 04:45:54 +02:00
|
|
|
}
|
|
|
|
|
2000-10-23 08:34:25 +02:00
|
|
|
function account_view($loginid)
|
|
|
|
{
|
|
|
|
global $phpgw_info, $phpgw;
|
|
|
|
|
|
|
|
$phpgw->db->query("select account_id,account_firstname,account_lastname from accounts where "
|
|
|
|
. "account_lid='$loginid'");
|
|
|
|
$phpgw->db->next_record();
|
|
|
|
|
|
|
|
$account_info["account_id"] = $phpgw->db->f("account_id");
|
|
|
|
$account_info["account_lid"] = $loginid;
|
|
|
|
$account_info["account_lastname"] = $phpgw->db->f("account_lastname");
|
|
|
|
$account_info["account_firstname"] = $phpgw->db->f("account_firstname");
|
|
|
|
|
|
|
|
return $account_info;
|
|
|
|
}
|
|
|
|
|
2000-10-20 04:45:54 +02:00
|
|
|
function account_add($account_info)
|
|
|
|
{
|
2000-10-20 05:30:28 +02:00
|
|
|
global $phpgw, $phpgw_info;
|
2000-10-20 04:45:54 +02:00
|
|
|
|
2000-10-20 05:30:28 +02:00
|
|
|
$phpgw->db->lock(array("accounts","preferences"));
|
|
|
|
|
|
|
|
while ($permission = each($account_info["permissions"])) {
|
|
|
|
if ($phpgw_info["apps"][$permission[0]]["enabled"]) {
|
|
|
|
$phpgw->accounts->add_app($permission[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "insert into accounts (account_lid,account_pwd,account_firstname,account_lastname,"
|
|
|
|
. "account_permissions,account_groups,account_status,account_lastpwd_change) values ('"
|
|
|
|
. $account_info["loginid"] . "','" . md5($account_info["passwd"]) . "','"
|
|
|
|
. addslashes($account_info["firstname"]) . "','". addslashes($account_info["lastname"])
|
|
|
|
. "','" . $phpgw->accounts->add_app("",True) . "','" . $account_info["groups"] . "','A',0)";
|
|
|
|
|
|
|
|
$phpgw->db->query($sql);
|
2000-11-03 21:07:57 +01:00
|
|
|
|
|
|
|
$phpgw->db->query("select account_id from accounts where account_lid='"
|
|
|
|
. $account_info["loginid"] . "'");
|
|
|
|
$phpgw->db->next_record();
|
|
|
|
add_default_preferences($phpgw->db->f("account_id"));
|
|
|
|
|
2000-10-20 05:30:28 +02:00
|
|
|
$phpgw->db->unlock();
|
|
|
|
|
|
|
|
$sep = $phpgw->common->filesystem_separator();
|
|
|
|
|
|
|
|
$basedir = $phpgw_info["server"]["files_dir"] . $sep . "users" . $sep;
|
2000-11-23 23:00:11 +01:00
|
|
|
//echo "TEST: " . $basedir . $account_info["loginid"];
|
2000-10-27 01:17:06 +02:00
|
|
|
if (! @mkdir($basedir . $account_info["loginid"], 0707)) {
|
2000-10-20 05:30:28 +02:00
|
|
|
$cd = 36;
|
|
|
|
} else {
|
|
|
|
$cd = 28;
|
|
|
|
}
|
|
|
|
return $cd;
|
2000-10-20 04:45:54 +02:00
|
|
|
}
|
|
|
|
|
2000-10-20 06:43:13 +02:00
|
|
|
function account_edit($account_info)
|
2000-10-20 04:45:54 +02:00
|
|
|
{
|
2000-10-20 06:43:13 +02:00
|
|
|
global $phpgw_info, $phpgw;
|
2000-10-20 04:45:54 +02:00
|
|
|
|
2000-11-26 10:32:34 +01:00
|
|
|
$phpgw->db->lock(array("accounts","preferences","phpgw_sessions"));
|
2000-10-20 06:43:13 +02:00
|
|
|
|
2000-11-23 23:00:11 +01:00
|
|
|
// $lid = $account_info["loginid"];
|
2000-10-24 04:35:36 +02:00
|
|
|
|
2000-11-23 23:00:11 +01:00
|
|
|
if ($account_info["old_loginid"] != $account_info["loginid"]) {
|
|
|
|
$phpgw->db->query("update accounts set account_lid='" . $account_info["loginid"]
|
|
|
|
. "' where account_lid='" . $account_info["old_loginid"] . "'");
|
2000-10-20 06:43:13 +02:00
|
|
|
|
2000-11-23 23:00:11 +01:00
|
|
|
// $account_info["loginid"] = $account_info["n_loginid"];
|
2000-10-20 06:43:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($account_info["passwd"]) {
|
|
|
|
$phpgw->db->query("update accounts set account_pwd='" . md5($account_info["passwd"]) . "', "
|
|
|
|
. "account_lastpwd_change='" . time() . "' where account_lid='"
|
|
|
|
. $account_info["loginid"] . "'");
|
2000-11-26 10:34:39 +01:00
|
|
|
$phpgw->db->query("update phpgw_sessions set session_pwd='" . addslashes($account_info["passwd"])
|
2000-10-24 04:35:36 +02:00
|
|
|
. "' where session_lid='" . $lid . "'");
|
2000-10-20 06:43:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
while ($permission = each($account_info["permissions"])) {
|
2000-10-26 03:16:10 +02:00
|
|
|
if ($phpgw_info["apps"][$permission[0]]["enabled"]) {
|
|
|
|
$phpgw->accounts->add_app($permission[0]);
|
|
|
|
}
|
2000-10-20 06:43:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! $account_info["account_status"]) {
|
|
|
|
$account_info["account_status"] = "L";
|
|
|
|
}
|
|
|
|
$cd = 27;
|
|
|
|
|
2000-11-23 23:00:11 +01:00
|
|
|
if ($account_info["old_loginid"] != $account_info["loginid"]) {
|
2000-10-26 03:16:10 +02:00
|
|
|
$sep = $phpgw->common->filesystem_separator();
|
2000-10-20 06:43:13 +02:00
|
|
|
|
2000-10-26 03:16:10 +02:00
|
|
|
$basedir = $phpgw_info["server"]["files_dir"] . $sep . "users" . $sep;
|
2000-10-20 06:43:13 +02:00
|
|
|
|
2000-11-23 23:00:11 +01:00
|
|
|
if (! @rename($basedir . $account_info["old_loginid"], $basedir . $account_info["loginid"])) {
|
2000-10-26 03:16:10 +02:00
|
|
|
$cd = 35;
|
2000-10-20 06:43:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$phpgw->db->query("update accounts set account_firstname='"
|
|
|
|
. addslashes($account_info["firstname"]) . "', account_lastname='"
|
|
|
|
. addslashes($account_info["lastname"]) . "', account_permissions='"
|
|
|
|
. $phpgw->accounts->add_app("",True) . "', account_status='"
|
|
|
|
. $account_info["account_status"] . "', account_groups='"
|
|
|
|
. $account_info["groups"] . "' where account_lid='" . $account_info["loginid"]
|
|
|
|
. "'");
|
|
|
|
|
|
|
|
$phpgw->db->unlock();
|
|
|
|
|
|
|
|
return $cd;
|
2000-10-20 04:45:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function account_delete($account_id)
|
|
|
|
{
|
|
|
|
global $phpgw;
|
|
|
|
|
|
|
|
$phpgw->db->query("select account_lid from accounts where account_id=$account_id");
|
|
|
|
$phpgw->db->next_record();
|
|
|
|
$lid = $phpgw->db->f(0);
|
|
|
|
|
2000-11-21 03:32:22 +01:00
|
|
|
$table_locks = array('preferences','todo','addressbook','accounts');
|
2000-10-20 04:45:54 +02:00
|
|
|
|
2000-11-21 03:32:22 +01:00
|
|
|
$phpgw->calendar->delete($lid);
|
2000-10-20 04:45:54 +02:00
|
|
|
|
2000-11-21 03:32:22 +01:00
|
|
|
$phpgw->db->lock($table_locks);
|
2000-10-20 04:45:54 +02:00
|
|
|
|
2000-11-17 04:28:36 +01:00
|
|
|
$phpgw->db->query("delete from todo where todo_owner='".$account_id."'");
|
|
|
|
$phpgw->db->query("delete from addressbook where ab_owner='".$account_id."'");
|
|
|
|
$phpgw->db->query("delete from accounts where account_id='".$account_id."'");
|
2000-12-16 17:51:03 +01:00
|
|
|
$phpgw->db->query("delete from preferences where preference_owner='".$account_id."'");
|
2000-10-20 04:45:54 +02:00
|
|
|
|
|
|
|
$phpgw->db->unlock();
|
|
|
|
|
|
|
|
$sep = $phpgw->common->filesystem_separator();
|
|
|
|
|
|
|
|
$basedir = $phpgw_info["server"]["files_dir"] . $sep . "users" . $sep;
|
|
|
|
|
|
|
|
if (! @rmdir($basedir . $lid)) {
|
|
|
|
$cd = 34;
|
|
|
|
} else {
|
|
|
|
$cd = 29;
|
|
|
|
}
|
|
|
|
return $cd;
|
|
|
|
}
|
2000-10-20 05:30:28 +02:00
|
|
|
|
|
|
|
function account_exsists($loginid)
|
|
|
|
{
|
|
|
|
global $phpgw;
|
|
|
|
|
|
|
|
$phpgw->db->query("select count(*) from accounts where account_lid='$loginid'");
|
|
|
|
$phpgw->db->next_record();
|
|
|
|
if ($phpgw->db->f(0) != 0) {
|
|
|
|
return True;
|
|
|
|
} else {
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-20 07:14:53 +02:00
|
|
|
function account_total()
|
|
|
|
{
|
|
|
|
global $phpgw, $query;
|
|
|
|
|
|
|
|
if ($query) {
|
|
|
|
$querymethod = " where account_firstname like '%$query%' OR account_lastname like "
|
|
|
|
. "'%$query%' OR account_lid like '%$query%' ";
|
|
|
|
}
|
|
|
|
|
|
|
|
$phpgw->db->query("select count(*) from accounts $querymethod");
|
|
|
|
$phpgw->db->next_record();
|
|
|
|
|
|
|
|
return $phpgw->db->f(0);
|
|
|
|
}
|
2000-10-20 07:59:25 +02:00
|
|
|
|
|
|
|
// This is need for LDAP, so this is a dummy function.
|
|
|
|
function account_close()
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|