This commit is contained in:
Sebijk 2022-02-15 16:42:44 +01:00
parent baf9650676
commit b8dccb13c7
6 changed files with 1265 additions and 1215 deletions

View file

@ -20,524 +20,540 @@
*/
define('ADMIN_MODE', true);
include('../serverlib/init.inc.php');
if(defined('TOOLBOX_SERVER')) $toolbox_serverurl = TOOLBOX_SERVER;
include '../serverlib/init.inc.php';
if (defined('TOOLBOX_SERVER')) {
$toolbox_serverurl = TOOLBOX_SERVER;
}
// tables
$customTextsHTML = array(
$customTextsHTML = [
// 'imprint' => true
);
$permsTable = array(
'overview' => $lang_admin['overview'],
'users' => $lang_admin['users'],
'groups' => $lang_admin['groups'],
'workgroups' => $lang_admin['workgroups'],
'activity' => $lang_admin['activity'],
'abuse' => $lang_admin['abuseprotect'],
'newsletter' => $lang_admin['newsletter'],
'payments' => $lang_admin['payments'],
'optimize' => $lang_admin['optimize'],
'maintenance' => $lang_admin['maintenance'],
'stats' => $lang_admin['stats'],
'logs' => $lang_admin['logs']
);
$fieldTypeTable = array(
FIELD_CHECKBOX => $lang_admin['checkbox'],
FIELD_DROPDOWN => $lang_admin['dropdown'],
FIELD_RADIO => $lang_admin['radio'],
FIELD_TEXT => $lang_admin['text'],
FIELD_DATE => $lang_admin['date']
);
$pluginTypeTable = array(
BMPLUGIN_DEFAULT => $lang_admin['module'],
BMPLUGIN_FILTER => $lang_admin['filter'],
BMPLUGIN_WIDGET => $lang_admin['widget']
);
$statusTable = array(
'yes' => $lang_admin['locked'],
'no' => $lang_admin['active'],
'locked' => $lang_admin['notactivated'],
'delete' => $lang_admin['deleted'],
'registered' => $lang_admin['registered']
);
$statusImgTable = array(
'yes' => 'locked',
'no' => 'active',
'locked' => 'notactivated',
'delete' => 'deleted',
'registered' => 'nologin'
);
$aliasTypeTable = array(
ALIAS_RECIPIENT => $lang_admin['receive'],
ALIAS_SENDER => $lang_admin['send'],
ALIAS_SENDER|ALIAS_RECIPIENT => $lang_admin['send'] . ', ' . $lang_admin['receive'],
ALIAS_SENDER|ALIAS_PENDING => $lang_admin['notconfirmed']
);
$ruleActionTable = array(
RECVRULE_ACTION_ISRECIPIENT => $lang_admin['isrecipient'],
RECVRULE_ACTION_SETRECIPIENT => $lang_admin['setrecipient'],
RECVRULE_ACTION_ADDRECIPIENT => $lang_admin['addrecipient'],
RECVRULE_ACTION_DELETE => $lang_admin['delete'],
RECVRULE_ACTION_BOUNCE => $lang_admin['bounce'],
RECVRULE_ACTION_MARKSPAM => $lang_admin['markspam'],
RECVRULE_ACTION_MARKINFECTED => $lang_admin['markinfected'],
RECVRULE_ACTION_SETINFECTION => $lang_admin['setinfection'],
RECVRULE_ACTION_MARKREAD => $lang_admin['markread']
);
$ruleTypeTable = array(
RECVRULE_TYPE_INACTIVE => $lang_admin['inactive'],
RECVRULE_TYPE_RECEIVERULE => $lang_admin['receiverule'],
RECVRULE_TYPE_CUSTOMRULE => $lang_admin['custom']
);
$faqRequirementTable = array(
'responder' => $lang_admin['autoresponder'],
'forward' => $lang_admin['forward'],
'mail2sms' => $lang_admin['mail2sms'],
'pop3' => $lang_admin['pop3'],
'imap' => $lang_admin['imap'],
'webdav' => $lang_admin['webdav'],
'wap' => $lang_admin['mobileaccess'],
'checker' => $lang_admin['mailchecker'],
'webdisk' => $lang_admin['webdisk'],
'share' => $lang_admin['wdshare'],
'syncml' => $lang_admin['syncml'],
'organizerdav' => $lang_admin['organizerdav'],
'ftsearch' => $lang_admin['ftsearch']
);
$lockedTypeTable = array(
'start' => $lang_admin['startswith'],
'mitte' => $lang_admin['contains'],
'ende' => $lang_admin['endswith'],
'gleich' => $lang_admin['isequal']
);
$backupTables = array(
'prefs' => array('prefs', 'ads', 'codes', 'extensions', 'faq', 'gruppen',
'locked', 'mods', 'profilfelder', 'recvrules', 'smsgateways',
'smstypen', 'staaten', 'texts', 'workgroups', 'workgroups_member',
'groupoptions'),
'stats' => array('stats'),
'users' => array('users', 'aliase', 'autoresponder', 'filter', 'filter_actions', 'filter_conditions',
'folder_conditions', 'folders', 'pop3', 'signaturen', 'smsend', 'userprefs'),
'organizer' => array('adressen', 'adressen_gruppen', 'adressen_gruppen_member', 'dates', 'dates_attendees',
'dates_groups', 'notes', 'tasks'),
'mails' => array('mails', 'certmails'),
'webdisk' => array('diskfiles', 'diskfolders', 'diskprops')
);
];
$permsTable = [
'overview' => $lang_admin['overview'],
'users' => $lang_admin['users'],
'groups' => $lang_admin['groups'],
'workgroups' => $lang_admin['workgroups'],
'activity' => $lang_admin['activity'],
'abuse' => $lang_admin['abuseprotect'],
'newsletter' => $lang_admin['newsletter'],
'payments' => $lang_admin['payments'],
'optimize' => $lang_admin['optimize'],
'maintenance' => $lang_admin['maintenance'],
'stats' => $lang_admin['stats'],
'logs' => $lang_admin['logs'],
];
$fieldTypeTable = [
FIELD_CHECKBOX => $lang_admin['checkbox'],
FIELD_DROPDOWN => $lang_admin['dropdown'],
FIELD_RADIO => $lang_admin['radio'],
FIELD_TEXT => $lang_admin['text'],
FIELD_DATE => $lang_admin['date'],
];
$pluginTypeTable = [
BMPLUGIN_DEFAULT => $lang_admin['module'],
BMPLUGIN_FILTER => $lang_admin['filter'],
BMPLUGIN_WIDGET => $lang_admin['widget'],
];
$statusTable = [
'yes' => $lang_admin['locked'],
'no' => $lang_admin['active'],
'locked' => $lang_admin['notactivated'],
'delete' => $lang_admin['deleted'],
'registered' => $lang_admin['registered'],
];
$statusImgTable = [
'yes' => 'locked',
'no' => 'active',
'locked' => 'notactivated',
'delete' => 'deleted',
'registered' => 'nologin',
];
$aliasTypeTable = [
ALIAS_RECIPIENT => $lang_admin['receive'],
ALIAS_SENDER => $lang_admin['send'],
ALIAS_SENDER | ALIAS_RECIPIENT => $lang_admin['send'].', '.$lang_admin['receive'],
ALIAS_SENDER | ALIAS_PENDING => $lang_admin['notconfirmed'],
];
$ruleActionTable = [
RECVRULE_ACTION_ISRECIPIENT => $lang_admin['isrecipient'],
RECVRULE_ACTION_SETRECIPIENT => $lang_admin['setrecipient'],
RECVRULE_ACTION_ADDRECIPIENT => $lang_admin['addrecipient'],
RECVRULE_ACTION_DELETE => $lang_admin['delete'],
RECVRULE_ACTION_BOUNCE => $lang_admin['bounce'],
RECVRULE_ACTION_MARKSPAM => $lang_admin['markspam'],
RECVRULE_ACTION_MARKINFECTED => $lang_admin['markinfected'],
RECVRULE_ACTION_SETINFECTION => $lang_admin['setinfection'],
RECVRULE_ACTION_MARKREAD => $lang_admin['markread'],
];
$ruleTypeTable = [
RECVRULE_TYPE_INACTIVE => $lang_admin['inactive'],
RECVRULE_TYPE_RECEIVERULE => $lang_admin['receiverule'],
RECVRULE_TYPE_CUSTOMRULE => $lang_admin['custom'],
];
$faqRequirementTable = [
'responder' => $lang_admin['autoresponder'],
'forward' => $lang_admin['forward'],
'mail2sms' => $lang_admin['mail2sms'],
'pop3' => $lang_admin['pop3'],
'imap' => $lang_admin['imap'],
'webdav' => $lang_admin['webdav'],
'wap' => $lang_admin['mobileaccess'],
'checker' => $lang_admin['mailchecker'],
'webdisk' => $lang_admin['webdisk'],
'share' => $lang_admin['wdshare'],
'syncml' => $lang_admin['syncml'],
'organizerdav' => $lang_admin['organizerdav'],
'ftsearch' => $lang_admin['ftsearch'],
];
$lockedTypeTable = [
'start' => $lang_admin['startswith'],
'mitte' => $lang_admin['contains'],
'ende' => $lang_admin['endswith'],
'gleich' => $lang_admin['isequal'],
];
$backupTables = [
'prefs' => ['prefs', 'ads', 'codes', 'extensions', 'faq', 'gruppen',
'locked', 'mods', 'profilfelder', 'recvrules', 'smsgateways',
'smstypen', 'staaten', 'texts', 'workgroups', 'workgroups_member',
'groupoptions', ],
'stats' => ['stats'],
'users' => ['users', 'aliase', 'autoresponder', 'filter', 'filter_actions', 'filter_conditions',
'folder_conditions', 'folders', 'pop3', 'signaturen', 'smsend', 'userprefs', ],
'organizer' => ['adressen', 'adressen_gruppen', 'adressen_gruppen_member', 'dates', 'dates_attendees',
'dates_groups', 'notes', 'tasks', ],
'mails' => ['mails', 'certmails'],
'webdisk' => ['diskfiles', 'diskfolders', 'diskprops'],
];
// files and folders that should have write permissions
$writeableFiles = array(
'admin/templates/cache/',
'languages/',
'logs/',
'plugins/',
'plugins/templates/',
'plugins/templates/images/',
'plugins/js/',
'plugins/css/',
'temp/',
'temp/session/',
'temp/cache/',
'templates/' . $bm_prefs['template'] . '/cache/'
);
$writeableFiles = [
'admin/templates/cache/',
'languages/',
'logs/',
'plugins/',
'plugins/templates/',
'plugins/templates/images/',
'plugins/js/',
'plugins/css/',
'temp/',
'temp/session/',
'temp/cache/',
'templates/'.$bm_prefs['template'].'/cache/',
];
// htaccess files that should exist
$htaccessFiles = array(
B1GMAIL_DATA_DIR . '.htaccess',
B1GMAIL_REL . 'logs/.htaccess',
B1GMAIL_REL . 'temp/.htaccess'
);
$htaccessFiles = [
B1GMAIL_DATA_DIR.'.htaccess',
B1GMAIL_REL.'logs/.htaccess',
B1GMAIL_REL.'temp/.htaccess',
];
/**
* check if admin is allowed to do sth.
*
* @param string $priv Privilege name
*
* @return bool
*/
function AdminAllowed($priv)
{
global $adminRow;
global $adminRow;
return($adminRow['type']==0 || isset($adminRow['privileges'][$priv]));
return $adminRow['type'] == 0 || isset($adminRow['privileges'][$priv]);
}
/**
* require privilege
* require privilege.
*
* @param string $priv
*/
function AdminRequirePrivilege($priv)
{
if(!AdminAllowed($priv))
{
DisplayError(0x02, 'Unauthorized', 'You are not authrized to view or change this dataset or page. Possible reasons are too few permissions or an expired session.',
sprintf("Requested privileges:\n%s",
$priv),
__FILE__,
__LINE__);
exit();
}
if (!AdminAllowed($priv)) {
DisplayError(0x02, 'Unauthorized', 'You are not authrized to view or change this dataset or page. Possible reasons are too few permissions or an expired session.',
sprintf("Requested privileges:\n%s",
$priv),
__FILE__,
__LINE__);
exit();
}
}
/**
* get stat data
* get stat data.
*
* @param mixed $types Stat type(s)
* @param int $time Stat time
* @param int $time Stat time
*
* @return array
*/
function GetStatData($types, $time)
{
global $db;
global $db;
// load class, if needed
if(!class_exists('BMCalendar'))
include(B1GMAIL_DIR . 'serverlib/calendar.class.php');
// load class, if needed
if (!class_exists('BMCalendar')) {
include B1GMAIL_DIR.'serverlib/calendar.class.php';
}
// types?
if(!is_array($types))
$types = array($types);
$typeList = '\'' . implode('\',\'', $types) . '\'';
// types?
if (!is_array($types)) {
$types = [$types];
}
$typeList = '\''.implode('\',\'', $types).'\'';
// pepare result array
$result = $falseArray = $nullArray = array();
foreach($types as $type)
$nullArray[$type] = 0;
foreach($types as $type)
$falseArray[$type] = false;
for($i=1; $i<=BMCalendar::GetDaysInMonth(date('m', $time), date('Y', $time)); $i++)
$result[(int)$i] = (mktime(0, 0, 0, date('m', $time), $i, date('Y', $time)) > time()) ? $falseArray : $nullArray;
// pepare result array
$result = $falseArray = $nullArray = [];
foreach ($types as $type) {
$nullArray[$type] = 0;
}
foreach ($types as $type) {
$falseArray[$type] = false;
}
for ($i = 1; $i <= BMCalendar::GetDaysInMonth(date('m', $time), date('Y', $time)); ++$i) {
$result[(int) $i] = (mktime(0, 0, 0, date('m', $time), $i, date('Y', $time)) > time()) ? $falseArray : $nullArray;
}
// fetch stats from DB
$res = $db->Query('SELECT typ,d,SUM(anzahl) AS anzahlSum FROM {pre}stats WHERE typ IN ('.$typeList.') AND m=? AND y=? GROUP BY d ORDER BY d ASC',
date('m', $time),
date('Y', $time));
while($row = $res->FetchArray(MYSQLI_ASSOC))
{
$result[(int)$row['d']][$row['typ']] = in_array($row['typ'], array('wd_down', 'wd_up'))
? round($row['anzahlSum']/1024, 2)
: $row['anzahlSum'];
}
$res->Free();
// fetch stats from DB
$res = $db->Query('SELECT typ,d,SUM(anzahl) AS anzahlSum FROM {pre}stats WHERE typ IN ('.$typeList.') AND m=? AND y=? GROUP BY d ORDER BY d ASC',
date('m', $time),
date('Y', $time));
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$result[(int) $row['d']][$row['typ']] = in_array($row['typ'], ['wd_down', 'wd_up'])
? round($row['anzahlSum'] / 1024, 2)
: $row['anzahlSum'];
}
$res->Free();
return($result);
return $result;
}
/**
* get categorized space usage
* get categorized space usage.
*
* @return array
*/
function GetCategorizedSpaceUsage()
{
global $backupTables, $db, $mysql;
global $backupTables, $db, $mysql;
// get table sizes
$tableSizes = array();
$res = $db->Query('SHOW TABLE STATUS');
while($row = $res->FetchArray(MYSQLI_ASSOC))
{
if(substr($row['Name'], 0, strlen($mysql['prefix'])) == $mysql['prefix'])
{
if($row['Engine'] == 'InnoDB')
$val = $row['Data_length'];
else
$val = $row['Data_length'] - $row['Data_free'];
$tableSizes[substr($row['Name'], strlen($mysql['prefix']))] = $val;
}
}
$res->Free();
// get table sizes
$tableSizes = [];
$res = $db->Query('SHOW TABLE STATUS');
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
if (substr($row['Name'], 0, strlen($mysql['prefix'])) == $mysql['prefix']) {
if ($row['Engine'] == 'InnoDB') {
$val = $row['Data_length'];
} else {
$val = $row['Data_length'] - $row['Data_free'];
}
$tableSizes[substr($row['Name'], strlen($mysql['prefix']))] = $val;
}
}
$res->Free();
// estimate sizes
$sizes = array();
foreach($backupTables as $key=>$tables)
foreach($tables as $table)
if(isset($sizes[$key]))
$sizes[$key] += $tableSizes[$table];
else
$sizes[$key] = $tableSizes[$table];
// estimate sizes
$sizes = [];
foreach ($backupTables as $key => $tables) {
foreach ($tables as $table) {
if (isset($sizes[$key])) {
$sizes[$key] += $tableSizes[$table];
} else {
$sizes[$key] = $tableSizes[$table];
}
}
}
// data size for mails + webdisk
$res = $db->Query('SELECT SUM(size) FROM {pre}mails');
list($emailSize) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
$res = $db->Query('SELECT SUM(size) FROM {pre}diskfiles');
list($diskSize) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
$sizes['mails'] += $emailSize;
$sizes['webdisk'] += $diskSize;
// data size for mails + webdisk
$res = $db->Query('SELECT SUM(size) FROM {pre}mails');
list($emailSize) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
$res = $db->Query('SELECT SUM(size) FROM {pre}diskfiles');
list($diskSize) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
$sizes['mails'] += $emailSize;
$sizes['webdisk'] += $diskSize;
// return
return($sizes);
// return
return $sizes;
}
/**
* get categorizes space usage
* get categorizes space usage.
*
* @return array
*/
function GetGroupSpaceUsage()
{
global $db, $mysql;
global $db, $mysql;
$sizes = array();
$sizes = [];
// get groups
$res = $db->Query('SELECT id,titel FROM {pre}gruppen ORDER BY titel ASC');
while($row = $res->FetchArray(MYSQLI_ASSOC))
{
// get sizes
$res2 = $db->Query('SELECT SUM(mailspace_used),SUM(diskspace_used),COUNT(*) FROM {pre}users WHERE gruppe=?',
$row['id']);
list($mailSpace, $diskSpace, $userCount) = $res2->FetchArray(MYSQLI_NUM);
$res2->Free();
$sizes[$row['id']] = array(
'title' => $row['titel'],
'users' => $userCount,
'size' => $mailSpace+$diskSpace
);
}
$res->Free();
// get groups
$res = $db->Query('SELECT id,titel FROM {pre}gruppen ORDER BY titel ASC');
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
// get sizes
$res2 = $db->Query('SELECT SUM(mailspace_used),SUM(diskspace_used),COUNT(*) FROM {pre}users WHERE gruppe=?',
$row['id']);
list($mailSpace, $diskSpace, $userCount) = $res2->FetchArray(MYSQLI_NUM);
$res2->Free();
$sizes[$row['id']] = [
'title' => $row['titel'],
'users' => $userCount,
'size' => $mailSpace + $diskSpace,
];
}
$res->Free();
// return
return($sizes);
// return
return $sizes;
}
/**
* load toolbox config descriptors
* load toolbox config descriptors.
*
* @return array
*/
function LoadTbxConfigDescriptors()
{
global $lang_admin, $lang_user, $lang_client, $bm_prefs;
global $lang_admin, $lang_user, $lang_client, $bm_prefs;
$tbxConfig = array();
include(B1GMAIL_DIR . 'serverlib/toolbox.config.php');
$tbxConfig = [];
include B1GMAIL_DIR.'serverlib/toolbox.config.php';
function cmpTbxConfig($a, $b)
{
if($a == $b) return 0;
function cmpTbxConfig($a, $b)
{
if ($a == $b) {
return 0;
}
list($aMajor, $aMinor) = explode('.', $a);
list($bMajor, $bMinor) = explode('.', $b);
list($aMajor, $aMinor) = explode('.', $a);
list($bMajor, $bMinor) = explode('.', $b);
return(($aMajor*1000+$aMinor) - ($bMajor*1000+$bMinor));
}
return ($aMajor * 1000 + $aMinor) - ($bMajor * 1000 + $bMinor);
}
uksort($tbxConfig, 'cmpTbxConfig');
uksort($tbxConfig, 'cmpTbxConfig');
return($tbxConfig);
return $tbxConfig;
}
/**
* delete an user and associated data
* delete an user and associated data.
*
* @param int $userID
*/
function DeleteUser($userID, $qAddAND = '')
{
global $db;
global $db;
if($userID <= 0)
return(false);
if ($userID <= 0) {
return false;
}
// get mail address
$res = $db->Query('SELECT email FROM {pre}users WHERE id=?' . $qAddAND,
$userID);
if($res->RowCount() == 0)
return(false);
list($userMail) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
// get mail address
$res = $db->Query('SELECT email FROM {pre}users WHERE id=?'.$qAddAND,
$userID);
if ($res->RowCount() == 0) {
return false;
}
list($userMail) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
// module handler
ModuleFunction('OnDeleteUser', array($userID));
// module handler
ModuleFunction('OnDeleteUser', [$userID]);
// delete blobs
$blobStorageIDs = array();
$res = $db->Query('SELECT DISTINCT(`blobstorage`) FROM {pre}mails WHERE userid=?',
$userID);
while($row = $res->FetchArray(MYSQLI_ASSOC))
$blobStorageIDs[] = $row['blobstorage'];
$res->Free();
$res = $db->Query('SELECT DISTINCT(`blobstorage`) FROM {pre}diskfiles WHERE `user`=?',
$userID);
while($row = $res->FetchArray(MYSQLI_ASSOC))
$blobStorageIDs[] = $row['blobstorage'];
$res->Free();
foreach(array_unique($blobStorageIDs) as $blobStorageID)
BMBlobStorage::createProvider($blobStorageID, $userID)->deleteUser();
// delete blobs
$blobStorageIDs = [];
$res = $db->Query('SELECT DISTINCT(`blobstorage`) FROM {pre}mails WHERE userid=?',
$userID);
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$blobStorageIDs[] = $row['blobstorage'];
}
$res->Free();
$res = $db->Query('SELECT DISTINCT(`blobstorage`) FROM {pre}diskfiles WHERE `user`=?',
$userID);
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$blobStorageIDs[] = $row['blobstorage'];
}
$res->Free();
foreach (array_unique($blobStorageIDs) as $blobStorageID) {
BMBlobStorage::createProvider($blobStorageID, $userID)->deleteUser();
}
// delivery status entries
$db->Query('DELETE FROM {pre}maildeliverystatus WHERE userid=?',
$userID);
// delivery status entries
$db->Query('DELETE FROM {pre}maildeliverystatus WHERE userid=?',
$userID);
// abuse points
$db->Query('DELETE FROM {pre}abuse_points WHERE userid=?',
$userID);
// abuse points
$db->Query('DELETE FROM {pre}abuse_points WHERE userid=?',
$userID);
// delete group<->member associations + groups
$groupIDs = array();
$res = $db->Query('SELECT id FROM {pre}adressen_gruppen WHERE user=?',
$userID);
while($row = $res->FetchArray(MYSQLI_ASSOC))
$groupIDs[] = $row['id'];
$res->Free();
if(count($groupIDs) > 0)
{
$db->Query('DELETE FROM {pre}adressen_gruppen_member WHERE gruppe IN(' . implode(',', $groupIDs) . ')');
$db->Query('DELETE FROM {pre}adressen_gruppen WHERE user=?',
$userID);
}
// delete group<->member associations + groups
$groupIDs = [];
$res = $db->Query('SELECT id FROM {pre}adressen_gruppen WHERE user=?',
$userID);
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$groupIDs[] = $row['id'];
}
$res->Free();
if (count($groupIDs) > 0) {
$db->Query('DELETE FROM {pre}adressen_gruppen_member WHERE gruppe IN('.implode(',', $groupIDs).')');
$db->Query('DELETE FROM {pre}adressen_gruppen WHERE user=?',
$userID);
}
// delete addresses
$db->Query('DELETE FROM {pre}adressen WHERE user=?',
$userID);
// delete addresses
$db->Query('DELETE FROM {pre}adressen WHERE user=?',
$userID);
// delete aliases
$db->Query('DELETE FROM {pre}aliase WHERE user=?',
$userID);
// delete aliases
$db->Query('DELETE FROM {pre}aliase WHERE user=?',
$userID);
// delete autoresponder
$db->Query('DELETE FROM {pre}autoresponder WHERE userid=?',
$userID);
// delete autoresponder
$db->Query('DELETE FROM {pre}autoresponder WHERE userid=?',
$userID);
// delete calendar dates
$dateIDs = array();
$res = $db->Query('SELECT id FROM {pre}dates WHERE user=?',
$userID);
while($row = $res->FetchArray(MYSQLI_ASSOC))
$dateIDs[] = $row['id'];
$res->Free();
if(count($dateIDs) > 0)
{
$db->Query('DELETE FROM {pre}dates_attendees WHERE date IN(' . implode(',', $dateIDs) . ')');
$db->Query('DELETE FROM {pre}dates WHERE user=?',
$userID);
}
// delete calendar dates
$dateIDs = [];
$res = $db->Query('SELECT id FROM {pre}dates WHERE user=?',
$userID);
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$dateIDs[] = $row['id'];
}
$res->Free();
if (count($dateIDs) > 0) {
$db->Query('DELETE FROM {pre}dates_attendees WHERE date IN('.implode(',', $dateIDs).')');
$db->Query('DELETE FROM {pre}dates WHERE user=?',
$userID);
}
// delete calendar groups
$db->Query('DELETE FROM {pre}dates_groups WHERE user=?',
$userID);
// delete calendar groups
$db->Query('DELETE FROM {pre}dates_groups WHERE user=?',
$userID);
// delete disk props
$db->Query('DELETE FROM {pre}diskprops WHERE user=?',
$userID);
// delete disk props
$db->Query('DELETE FROM {pre}diskprops WHERE user=?',
$userID);
// delete disk locks
$db->Query('DELETE FROM {pre}disklocks WHERE user=?',
$userID);
// delete disk locks
$db->Query('DELETE FROM {pre}disklocks WHERE user=?',
$userID);
// delete disk folders
$db->Query('DELETE FROM {pre}diskfolders WHERE user=?',
$userID);
// delete disk folders
$db->Query('DELETE FROM {pre}diskfolders WHERE user=?',
$userID);
// delete disk files
$db->Query('DELETE FROM {pre}diskfiles WHERE user=?',
$userID);
// delete disk files
$db->Query('DELETE FROM {pre}diskfiles WHERE user=?',
$userID);
// delete cert mails
$db->Query('DELETE FROM {pre}certmails WHERE user=?',
$userID);
// delete cert mails
$db->Query('DELETE FROM {pre}certmails WHERE user=?',
$userID);
// delete filters
$filterIDs = array();
$res = $db->Query('SELECT id FROM {pre}filter WHERE userid=?',
$userID);
while($row = $res->FetchArray(MYSQLI_ASSOC))
$filterIDs[] = $row['id'];
$res->Free();
if(count($filterIDs) > 0)
{
$db->Query('DELETE FROM {pre}filter_actions WHERE filter IN(' . implode(',', $filterIDs) . ')');
$db->Query('DELETE FROM {pre}filter_conditions WHERE filter IN(' . implode(',', $filterIDs) . ')');
$db->Query('DELETE FROM {pre}filter WHERE userid=?',
$userID);
}
// delete filters
$filterIDs = [];
$res = $db->Query('SELECT id FROM {pre}filter WHERE userid=?',
$userID);
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$filterIDs[] = $row['id'];
}
$res->Free();
if (count($filterIDs) > 0) {
$db->Query('DELETE FROM {pre}filter_actions WHERE filter IN('.implode(',', $filterIDs).')');
$db->Query('DELETE FROM {pre}filter_conditions WHERE filter IN('.implode(',', $filterIDs).')');
$db->Query('DELETE FROM {pre}filter WHERE userid=?',
$userID);
}
// delete folder conditions + folders
$folderIDs = array();
$res = $db->Query('SELECT id FROM {pre}folders WHERE userid=?',
$userID);
while($row = $res->FetchArray(MYSQLI_ASSOC))
$folderIDs[] = $row['id'];
$res->Free();
if(count($folderIDs) > 0)
{
$db->Query('DELETE FROM {pre}folder_conditions WHERE folder IN(' . implode(',', $folderIDs) . ')');
$db->Query('DELETE FROM {pre}folders WHERE userid=?',
$userID);
}
// delete folder conditions + folders
$folderIDs = [];
$res = $db->Query('SELECT id FROM {pre}folders WHERE userid=?',
$userID);
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$folderIDs[] = $row['id'];
}
$res->Free();
if (count($folderIDs) > 0) {
$db->Query('DELETE FROM {pre}folder_conditions WHERE folder IN('.implode(',', $folderIDs).')');
$db->Query('DELETE FROM {pre}folders WHERE userid=?',
$userID);
}
// delete mails
$db->Query('DELETE FROM {pre}mailnotes WHERE `mailid` IN (SELECT `id` FROM {pre}mails WHERE `userid`=?)',
$userID);
$db->Query('DELETE FROM {pre}mails WHERE userid=?',
$userID);
$db->Query('DELETE FROM {pre}attachments WHERE userid=?',
$userID);
// delete mails
$db->Query('DELETE FROM {pre}mailnotes WHERE `mailid` IN (SELECT `id` FROM {pre}mails WHERE `userid`=?)',
$userID);
$db->Query('DELETE FROM {pre}mails WHERE userid=?',
$userID);
$db->Query('DELETE FROM {pre}attachments WHERE userid=?',
$userID);
// delete notes
$db->Query('DELETE FROM {pre}notes WHERE user=?',
$userID);
// delete notes
$db->Query('DELETE FROM {pre}notes WHERE user=?',
$userID);
// uid index + ext. pop3s
$pop3IDs = array();
$res = $db->Query('SELECT id FROM {pre}pop3 WHERE user=?',
$userID);
while($row = $res->FetchArray(MYSQLI_ASSOC))
$pop3IDs[] = $row['id'];
$res->Free();
if(count($pop3IDs) > 0)
{
$db->Query('DELETE FROM {pre}uidindex WHERE pop3 IN(' . implode(',', $pop3IDs) . ')');
$db->Query('DELETE FROM {pre}pop3 WHERE user=?',
$userID);
}
// uid index + ext. pop3s
$pop3IDs = [];
$res = $db->Query('SELECT id FROM {pre}pop3 WHERE user=?',
$userID);
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$pop3IDs[] = $row['id'];
}
$res->Free();
if (count($pop3IDs) > 0) {
$db->Query('DELETE FROM {pre}uidindex WHERE pop3 IN('.implode(',', $pop3IDs).')');
$db->Query('DELETE FROM {pre}pop3 WHERE user=?',
$userID);
}
// sigs
$db->Query('DELETE FROM {pre}signaturen WHERE user=?',
$userID);
// sigs
$db->Query('DELETE FROM {pre}signaturen WHERE user=?',
$userID);
// sent sms
$db->Query('DELETE FROM {pre}smsend WHERE user=?',
$userID);
// sent sms
$db->Query('DELETE FROM {pre}smsend WHERE user=?',
$userID);
// spam index
$db->Query('DELETE FROM {pre}spamindex WHERE userid=?',
$userID);
// spam index
$db->Query('DELETE FROM {pre}spamindex WHERE userid=?',
$userID);
// tasks
$db->Query('DELETE FROM {pre}tasks WHERE user=?',
$userID);
// tasks
$db->Query('DELETE FROM {pre}tasks WHERE user=?',
$userID);
// workgroup memberships
$db->Query('DELETE FROM {pre}workgroups_member WHERE user=?',
$userID);
// workgroup memberships
$db->Query('DELETE FROM {pre}workgroups_member WHERE user=?',
$userID);
// certificates
$db->Query('DELETE FROM {pre}certificates WHERE userid=?',
$userID);
// certificates
$db->Query('DELETE FROM {pre}certificates WHERE userid=?',
$userID);
// user prefs
$db->Query('DELETE FROM {pre}userprefs WHERE userid=?',
$userID);
// user prefs
$db->Query('DELETE FROM {pre}userprefs WHERE userid=?',
$userID);
// search index
$indexFileName = DataFilename($userID, 'idx', true);
if(file_exists($indexFileName))
@unlink($indexFileName);
// search index
$indexFileName = DataFilename($userID, 'idx', true);
if (file_exists($indexFileName)) {
@unlink($indexFileName);
}
// finally, the user record itself
$db->Query('DELETE FROM {pre}users WHERE id=?',
$userID);
// finally, the user record itself
$db->Query('DELETE FROM {pre}users WHERE id=?',
$userID);
// log
PutLog(sprintf('User <%s> (%d) deleted',
$userMail,
$userID),
PRIO_NOTE,
__FILE__,
__LINE__);
// log
PutLog(sprintf('User <%s> (%d) deleted',
$userMail,
$userID),
PRIO_NOTE,
__FILE__,
__LINE__);
return(true);
return true;
}

View file

@ -39,7 +39,7 @@ class CSVReader
* @param resource $fp File pointer to CSV file
* @return CSVReader
*/
function __construct($fp, $encoding = 'UTF-8')
public function __construct($fp, $encoding = 'UTF-8')
{
$this->_encoding = $encoding;
$this->_fp = $fp;
@ -51,7 +51,7 @@ class CSVReader
*
* @return array
*/
function FetchRow()
public function FetchRow()
{
return(isset($this->_data[++$this->_rp]) ? $this->_generate_assoc_row($this->_rp) : false);
}
@ -61,7 +61,7 @@ class CSVReader
*
* @return array
*/
function Fields()
public function Fields()
{
return($this->_data[0]);
}
@ -71,7 +71,7 @@ class CSVReader
*
* @return int
*/
function NumFields()
public function NumFields()
{
return(count($this->_data[0]));
}
@ -82,7 +82,7 @@ class CSVReader
* @param int $index Row index
* @return array
*/
function _generate_assoc_row($index)
private function _generate_assoc_row($index)
{
$result = array();
$row = $this->_data[$index];
@ -103,7 +103,7 @@ class CSVReader
* @param resource $fp File pointer
* @return array
*/
function _parse_file($fp)
private function _parse_file($fp)
{
$rows = array(array(''));
$inString = false;

View file

@ -19,319 +19,315 @@
*
*/
if(!defined('B1GMAIL_INIT'))
die('Directly calling this file is not supported');
if (!defined('B1GMAIL_INIT')) {
die('Directly calling this file is not supported');
}
/**
* db controller class
* db controller class.
*/
class DB
{
var $_handle; // mysql handle
var $_qcount; // query count
var $_last_handle; // last mysql handle
var $_current_charset; // current charset
public $_handle; // mysql handle
private $_qcount; // query count
private $_last_handle; // last mysql handle
private $_current_charset; // current charset
/**
* constructor
*
* @param resource $handle MySQL connection
*/
function __construct($handle)
{
$this->_handle = $handle;
$this->_qcount = 0;
$this->_current_charset = false;
}
/**
* constructor.
*
* @param resource $handle MySQL connection
*/
public function __construct($handle)
{
$this->_handle = $handle;
$this->_qcount = 0;
$this->_current_charset = false;
}
/**
* set connection charset
*
* @param string $charset
*/
function SetCharset($charset)
{
$this->_current_charset = $charset;
mysqli_set_charset($this->_handle, $charset);
}
/**
* set connection charset.
*
* @param string $charset
*/
public function SetCharset($charset)
{
$this->_current_charset = $charset;
mysqli_set_charset($this->_handle, $charset);
}
/**
* get server version
*
* @return string
*/
function GetServerVersion()
{
return(mysqli_get_server_info($this->_handle));
}
/**
* get server version.
*
* @return string
*/
public function GetServerVersion()
{
return mysqli_get_server_info($this->_handle);
}
/**
* escape a string for use in SQL query
*
* @param string $str String
* @return string
*/
function Escape($str)
{
return(mysqli_real_escape_string($this->_handle, $str));
}
/**
* escape a string for use in SQL query.
*
* @param string $str String
*
* @return string
*/
public function Escape($str)
{
return mysqli_real_escape_string($this->_handle, $str);
}
/**
* execute safe query
*
* @param string $query
* @return DB_Result
*/
function Query($query)
{
global $bm_modules, $mysql;
/**
* execute safe query.
*
* @param string $query
*
* @return DB_Result
*/
public function Query($query)
{
global $bm_modules, $mysql;
// replace {pre} with prefix
$query = str_replace('{pre}', $mysql['prefix'], $query);
// replace {pre} with prefix
$query = str_replace('{pre}', $mysql['prefix'], $query);
// insert escaped values, if any
if(func_num_args() > 1)
{
$args = func_get_args();
$pos = 0;
for($i=1; $i<func_num_args(); $i++)
{
$pos = strpos($query, '?', $pos);
if($pos === false)
{
$szUsername = $args[$i];
break;
}
else
{
if(is_string($args[$i]) && (strcmp($args[$i], '#NULL#') == 0))
{
$intxt = 'NULL';
}
else if(is_array($args[$i]))
{
$intxt = '';
foreach($args[$i] as $val)
$intxt .= ',\'' . $this->Escape($val) . '\'';
$intxt = '(' . substr($intxt, 1) . ')';
if($intxt == '()')
$intxt = '(0)';
}
else
{
$intxt = '\'' . $this->Escape($args[$i]) . '\'';
}
// insert escaped values, if any
if (func_num_args() > 1) {
$args = func_get_args();
$pos = 0;
for ($i = 1; $i < func_num_args(); ++$i) {
$pos = strpos($query, '?', $pos);
if ($pos === false) {
$szUsername = $args[$i];
break;
} else {
if (is_string($args[$i]) && (strcmp($args[$i], '#NULL#') == 0)) {
$intxt = 'NULL';
} elseif (is_array($args[$i])) {
$intxt = '';
foreach ($args[$i] as $val) {
$intxt .= ',\''.$this->Escape($val).'\'';
}
$intxt = '('.substr($intxt, 1).')';
if ($intxt == '()') {
$intxt = '(0)';
}
} else {
$intxt = '\''.$this->Escape($args[$i]).'\'';
}
$query = substr_replace($query, $intxt, $pos, 1);
$pos += strlen($intxt);
}
}
}
$query = substr_replace($query, $intxt, $pos, 1);
$pos += strlen($intxt);
}
}
}
// has a module a better handle?
$handle = $this->_handle;
if(is_array($bm_modules))
foreach($bm_modules as $mKey=>$module)
if($bm_modules[$mKey]->Features('MySQLHandle'))
$handle = $bm_modules[$mKey]->MySQLHandle($query, $handle, $szUsername);
// has a module a better handle?
$handle = $this->_handle;
if (is_array($bm_modules)) {
foreach ($bm_modules as $mKey => $module) {
if ($bm_modules[$mKey]->Features('MySQLHandle')) {
$handle = $bm_modules[$mKey]->MySQLHandle($query, $handle, $szUsername);
}
}
}
$ok = ($result = mysqli_query($handle, $query));
$ok = ($result = mysqli_query($handle, $query));
// try one re-connect on timeout (might happen in pipe keep-alive mode)
if(!$ok && mysqli_errno($handle) == 2006)
{
$handle = @mysqli_connect($mysql['host'], $mysql['user'], $mysql['pass']);
if($handle)
{
if(@mysqli_select_db($handle, $mysql['db']))
{
@mysqli_query($handle, 'SET SESSION sql_mode=\'\'');
$this->_handle = $handle;
if($this->_current_charset)
$this->SetCharset($this->_current_charset);
$ok = ($result = mysqli_query($handle, $query));
}
}
}
// try one re-connect on timeout (might happen in pipe keep-alive mode)
if (!$ok && mysqli_errno($handle) == 2006) {
$handle = @mysqli_connect($mysql['host'], $mysql['user'], $mysql['pass']);
if ($handle) {
if (@mysqli_select_db($handle, $mysql['db'])) {
@mysqli_query($handle, 'SET SESSION sql_mode=\'\'');
$this->_handle = $handle;
if ($this->_current_charset) {
$this->SetCharset($this->_current_charset);
}
$ok = ($result = mysqli_query($handle, $query));
}
}
}
// increment query count
$this->_qcount++;
// increment query count
++$this->_qcount;
// set last handle
$this->_last_handle = $handle;
// set last handle
$this->_last_handle = $handle;
// return new MySQL_Result object if query was successful
if($ok)
{
return(isset($result) ? new DB_Result($handle, $result, $query) : false);
}
else
{
if(strpos(strtolower($query), 'insert into ' . strtolower($mysql['prefix']) . 'logs') !== false)
{
// log table corrupt -> error page! (would end up in endless loop otherwise)
DisplayError(0x05, 'Log table error', 'Failed to write log entry to ' . $mysql['prefix'] . 'logs-table. Please check and repair the table.',
sprintf("Process:\n%s\n\nError number:\n%d\n\nError description:\n%s",
'Query',
mysqli_errno($handle),
mysqli_error($handle)),
__FILE__,
__LINE__);
die();
}
else if(DEBUG)
{
// debug mode -> error page!
DisplayError(0x09, 'MySQL error', 'Failed to execute MySQL query.',
sprintf("Process:\n%s\n\nQuery:\n%s\n\nError number:\n%d\n\nError description:\n%s",
'Query',
$query,
mysqli_errno($handle),
mysqli_error($handle)),
__FILE__,
__LINE__);
}
PutLog("MySQL-Error at '" . $_SERVER['SCRIPT_NAME'] . "': '" . mysqli_error($handle) . "', tried to execute '" . $query . "'", PRIO_ERROR, __FILE__, __LINE__);
if(DEBUG)
die();
return(false);
}
}
// return new MySQL_Result object if query was successful
if ($ok) {
return isset($result) ? new DB_Result($handle, $result, $query) : false;
} else {
if (strpos(strtolower($query), 'insert into '.strtolower($mysql['prefix']).'logs') !== false) {
// log table corrupt -> error page! (would end up in endless loop otherwise)
DisplayError(0x05, 'Log table error', 'Failed to write log entry to '.$mysql['prefix'].'logs-table. Please check and repair the table.',
sprintf("Process:\n%s\n\nError number:\n%d\n\nError description:\n%s",
'Query',
mysqli_errno($handle),
mysqli_error($handle)),
__FILE__,
__LINE__);
die();
} elseif (DEBUG) {
// debug mode -> error page!
DisplayError(0x09, 'MySQL error', 'Failed to execute MySQL query.',
sprintf("Process:\n%s\n\nQuery:\n%s\n\nError number:\n%d\n\nError description:\n%s",
'Query',
$query,
mysqli_errno($handle),
mysqli_error($handle)),
__FILE__,
__LINE__);
}
PutLog("MySQL-Error at '".$_SERVER['SCRIPT_NAME']."': '".mysqli_error($handle)."', tried to execute '".$query."'", PRIO_ERROR, __FILE__, __LINE__);
if (DEBUG) {
die();
}
/**
* get insert id
*
* @return int
*/
function InsertId()
{
return(mysqli_insert_id($this->_last_handle));
}
return false;
}
}
/**
* get number of affected rows
*
* @return int
*/
function AffectedRows()
{
return(mysqli_affected_rows($this->_last_handle));
}
/**
* get insert id.
*
* @return int
*/
public function InsertId()
{
return mysqli_insert_id($this->_last_handle);
}
/**
* get number of affected rows.
*
* @return int
*/
public function AffectedRows()
{
return mysqli_affected_rows($this->_last_handle);
}
}
/**
* db result class
* db result class.
*/
class DB_Result
{
var $_handle; // mysql handle
var $_result; // mysql result
var $_query;
public $_handle; // mysql handle
private $_result; // mysql result
private $_query;
/**
* constructor
*
* @param resource $handle
* @param resource $result
* @return DB_Result
*/
function __construct($handle, $result, $query = '')
{
$this->_handle = $handle;
$this->_result = $result;
$this->_query = $query;
}
/**
* constructor.
*
* @param resource $handle
* @param resource $result
*
* @return DB_Result
*/
public function __construct($handle, $result, $query = '')
{
$this->_handle = $handle;
$this->_result = $result;
$this->_query = $query;
}
/**
* fetch a row as array
*
* @return array
*/
function FetchArray($resultType = MYSQLI_BOTH)
{
return(mysqli_fetch_array($this->_result, $resultType));
}
/**
* fetch a row as array.
*
* @return array
*/
public function FetchArray($resultType = MYSQLI_BOTH)
{
return mysqli_fetch_array($this->_result, $resultType);
}
/**
* fetch a row as object
*
* @return object
*/
function FetchObject()
{
return(mysqli_fetch_object($this->_result));
}
/**
* fetch a row as object.
*
* @return object
*/
public function FetchObject()
{
return mysqli_fetch_object($this->_result);
}
/**
* get count of rows in result set
*
* @return int
*/
function RowCount()
{
return(mysqli_num_rows($this->_result));
}
/**
* get count of rows in result set.
*
* @return int
*/
public function RowCount()
{
return mysqli_num_rows($this->_result);
}
/**
* get field count
*
* @return int
*/
function FieldCount()
{
return(mysqli_num_fields($this->_result));
}
/**
* get field count.
*
* @return int
*/
public function FieldCount()
{
return mysqli_num_fields($this->_result);
}
/**
* get field name
*
* @param int $index Index
* @return string
*/
function FieldName($index)
{
$field = mysqli_fetch_field_direct($this->_result, $index);
return($field->name);
}
/**
* get field name.
*
* @param int $index Index
*
* @return string
*/
public function FieldName($index)
{
$field = mysqli_fetch_field_direct($this->_result, $index);
/**
* free result
*
*/
function Free()
{
@mysqli_free_result($this->_result);
}
return $field->name;
}
/**
* export result set as CSV
*
* @param string $lineBreakChar Line break character
* @param string $quoteChar Quoting character
* @param string $sepChar Seperator character
*/
function ExportCSV($lineBreakChar = "\n", $quoteChar = '"', $sepChar = ';')
{
// get fields
$fields = array();
for($i=0; $i<$this->FieldCount(); $i++)
$fields[] = $this->FieldName($i);
/**
* free result.
*/
public function Free()
{
@mysqli_free_result($this->_result);
}
// print field list
$fieldList = '';
foreach($fields as $field)
$fieldList .= $sepChar . $quoteChar . addslashes($field) . $quoteChar;
$fieldList = substr($fieldList, 1) . $lineBreakChar;
echo $fieldList;
/**
* export result set as CSV.
*
* @param string $lineBreakChar Line break character
* @param string $quoteChar Quoting character
* @param string $sepChar Seperator character
*/
public function ExportCSV($lineBreakChar = "\n", $quoteChar = '"', $sepChar = ';')
{
// get fields
$fields = [];
for ($i = 0; $i < $this->FieldCount(); ++$i) {
$fields[] = $this->FieldName($i);
}
// print data
while($row = $this->FetchArray(MYSQLI_ASSOC))
{
$columnList = '';
foreach($fields as $field)
$columnList .= $sepChar . $quoteChar . addslashes($row[$field]) . $quoteChar;
$columnList = substr($columnList, 1) . $lineBreakChar;
echo $columnList;
}
}
// print field list
$fieldList = '';
foreach ($fields as $field) {
$fieldList .= $sepChar.$quoteChar.addslashes($field).$quoteChar;
}
$fieldList = substr($fieldList, 1).$lineBreakChar;
echo $fieldList;
// print data
while ($row = $this->FetchArray(MYSQLI_ASSOC)) {
$columnList = '';
foreach ($fields as $field) {
$columnList .= $sepChar.$quoteChar.addslashes($row[$field]).$quoteChar;
}
$columnList = substr($columnList, 1).$lineBreakChar;
echo $columnList;
}
}
}

View file

@ -35,7 +35,7 @@ class BMNotes
* @param int $userID User ID
* @return BMNotes
*/
function __construct($userID)
public function __construct($userID)
{
$this->_userID = $userID;
}
@ -48,7 +48,7 @@ class BMNotes
* @param int $limit Entry limit
* @return array
*/
function GetNoteList($sortColumn = 'date', $sortOrder = 'ASC', $limit = -1)
public function GetNoteList($sortColumn = 'date', $sortOrder = 'ASC', $limit = -1)
{
global $db;
@ -71,7 +71,7 @@ class BMNotes
* @param int $id Note ID
* @return array
*/
function GetNote($id)
public function GetNote($id)
{
global $db;
@ -92,7 +92,7 @@ class BMNotes
* @param int $id Note ID
* @return bool
*/
function Delete($id)
public function Delete($id)
{
global $db;
@ -109,7 +109,7 @@ class BMNotes
* @param string $text Text
* @return int
*/
function Add($priority, $text)
public function Add($priority, $text)
{
global $db;
@ -129,7 +129,7 @@ class BMNotes
* @param string $text New test
* @return bool
*/
function Change($id, $priority, $text)
public function Change($id, $priority, $text)
{
global $db;

View file

@ -19,376 +19,397 @@
*
*/
if(!defined('B1GMAIL_INIT'))
die('Directly calling this file is not supported');
if (!defined('B1GMAIL_INIT')) {
die('Directly calling this file is not supported');
}
/**
/*
* constants
*/
define('TASKS_NOTBEGUN', 16);
define('TASKS_PROCESSING', 32);
define('TASKS_DONE', 64);
define('TASKS_POSTPONED', 128);
define('TASKS_NOTBEGUN', 16);
define('TASKS_PROCESSING', 32);
define('TASKS_DONE', 64);
define('TASKS_POSTPONED', 128);
/**
* todo interface class
* todo interface class.
*/
class BMTodo
{
var $_userID;
var $_prioTrans = array(
'low' => -1,
'normal' => 0,
'high' => 1,
-1 => 'low',
0 => 'normal',
1 => 'high'
);
private $_userID;
private $_prioTrans = [
'low' => -1,
'normal' => 0,
'high' => 1,
-1 => 'low',
0 => 'normal',
1 => 'high',
];
/**
* constructor
*
* @param int $userID User ID
* @return BMTodo
*/
function __construct($userID)
{
$this->_userID = $userID;
}
/**
* constructor.
*
* @param int $userID User ID
*
* @return BMTodo
*/
public function __construct($userID)
{
$this->_userID = $userID;
}
/**
* get list of tasks
*
* @param string $sortColumn Sort column
* @param string $sortOrder Sort order
* @param int $limit Entry limit
* @param int $taskListID Task list ID
* @return array
*/
function GetTodoList($sortColumn = 'faellig,beginn', $sortOrder = 'ASC', $limit = -1, $taskListID = 0, $undoneOnly = false)
{
global $db;
/**
* get list of tasks.
*
* @param string $sortColumn Sort column
* @param string $sortOrder Sort order
* @param int $limit Entry limit
* @param int $taskListID Task list ID
*
* @return array
*/
public function GetTodoList($sortColumn = 'faellig,beginn', $sortOrder = 'ASC', $limit = -1, $taskListID = 0, $undoneOnly = false)
{
global $db;
$queryAdd = '';
if($undoneOnly)
$queryAdd .= ' AND akt_status!=' . TASKS_DONE;
$queryAdd = '';
if ($undoneOnly) {
$queryAdd .= ' AND akt_status!='.TASKS_DONE;
}
$result = array();
$res = $db->Query('SELECT id,beginn,faellig,akt_status,titel,priority,erledigt,comments,dav_uri,dav_uid FROM {pre}tasks WHERE user=? AND tasklistid=?' . $queryAdd . ' ORDER BY ' . $sortColumn . ' ' . $sortOrder
. ($limit != -1 ? ' LIMIT ' . $limit : ''),
$this->_userID,
$taskListID);
while($row = $res->FetchArray())
{
$result[$row['id']] = array(
'id' => $row['id'],
'beginn' => $row['beginn'],
'faellig' => $row['faellig'],
'akt_status' => $row['akt_status'],
'titel' => $row['titel'],
'priority' => $this->_prioTrans[$row['priority']],
'erledigt' => $row['erledigt'],
'comments' => $row['comments'],
'dav_uri' => $row['dav_uri'],
'dav_uid' => $row['dav_uid']
);
}
$result = [];
$res = $db->Query('SELECT id,beginn,faellig,akt_status,titel,priority,erledigt,comments,dav_uri,dav_uid FROM {pre}tasks WHERE user=? AND tasklistid=?'.$queryAdd.' ORDER BY '.$sortColumn.' '.$sortOrder
.($limit != -1 ? ' LIMIT '.$limit : ''),
$this->_userID,
$taskListID);
while ($row = $res->FetchArray()) {
$result[$row['id']] = [
'id' => $row['id'],
'beginn' => $row['beginn'],
'faellig' => $row['faellig'],
'akt_status' => $row['akt_status'],
'titel' => $row['titel'],
'priority' => $this->_prioTrans[$row['priority']],
'erledigt' => $row['erledigt'],
'comments' => $row['comments'],
'dav_uri' => $row['dav_uri'],
'dav_uid' => $row['dav_uid'],
];
}
return($result);
}
return $result;
}
/**
* get undone task count
*
* @return int
*/
function GetUndoneTaskCount()
{
global $db;
/**
* get undone task count.
*
* @return int
*/
public function GetUndoneTaskCount()
{
global $db;
$res = $db->Query('SELECT COUNT(*) FROM {pre}tasks WHERE user=? AND akt_status!=?',
$this->_userID,
TASKS_DONE);
list($taskCount) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
$res = $db->Query('SELECT COUNT(*) FROM {pre}tasks WHERE user=? AND akt_status!=?',
$this->_userID,
TASKS_DONE);
list($taskCount) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
return($taskCount);
}
return $taskCount;
}
/**
* add a task
*
* @param int $beginn Begin
* @param int $faellig Due
* @param int $akt_status Status
* @param string $titel Titel
* @param int $priority Priority
* @param int $erledigt Done
* @param string $comments Comments
* @return int
*/
function Add($beginn, $faellig, $akt_status, $titel, $priority, $erledigt, $comments, $taskListID = 0, $davURI = '', $davUID = '')
{
global $db;
/**
* add a task.
*
* @param int $beginn Begin
* @param int $faellig Due
* @param int $akt_status Status
* @param string $titel Titel
* @param int $priority Priority
* @param int $erledigt Done
* @param string $comments Comments
*
* @return int
*/
public function Add($beginn, $faellig, $akt_status, $titel, $priority, $erledigt, $comments, $taskListID = 0, $davURI = '', $davUID = '')
{
global $db;
// translate $priority, if neccessary
if(is_numeric($priority))
$priority = $this->_prioTrans[$priority];
// translate $priority, if neccessary
if (is_numeric($priority)) {
$priority = $this->_prioTrans[$priority];
}
$db->Query('INSERT INTO {pre}tasks(user,beginn,faellig,akt_status,titel,priority,erledigt,comments,tasklistid,dav_uri,dav_uid) VALUES(?,?,?,?,?,?,?,?,?,?,?)',
$this->_userID,
(int)$beginn,
(int)$faellig,
(int)$akt_status,
$titel,
$priority,
(int)$erledigt,
$comments,
(int)$taskListID,
$davURI,
$davUID);
$id = $db->InsertID();
$db->Query('INSERT INTO {pre}tasks(user,beginn,faellig,akt_status,titel,priority,erledigt,comments,tasklistid,dav_uri,dav_uid) VALUES(?,?,?,?,?,?,?,?,?,?,?)',
$this->_userID,
(int) $beginn,
(int) $faellig,
(int) $akt_status,
$titel,
$priority,
(int) $erledigt,
$comments,
(int) $taskListID,
$davURI,
$davUID);
$id = $db->InsertID();
ChangelogAdded(BMCL_TYPE_TODO, $id, time());
ChangelogAdded(BMCL_TYPE_TODO, $id, time());
return($id);
}
return $id;
}
/**
* change a task
*
* @param int $id Task ID
* @param int $beginn Begin
* @param int $faellig Due
* @param int $akt_status Status
* @param string $titel Titel
* @param int $priority Priority
* @param int $erledigt Done
* @param string $comments Comments
* @return bool
*/
function Change($id, $beginn, $faellig, $akt_status, $titel, $priority, $erledigt, $comments, $taskListID = 0)
{
global $db;
/**
* change a task.
*
* @param int $id Task ID
* @param int $beginn Begin
* @param int $faellig Due
* @param int $akt_status Status
* @param string $titel Titel
* @param int $priority Priority
* @param int $erledigt Done
* @param string $comments Comments
*
* @return bool
*/
public function Change($id, $beginn, $faellig, $akt_status, $titel, $priority, $erledigt, $comments, $taskListID = 0)
{
global $db;
// translate $priority, if neccessary
if(is_numeric($priority))
$priority = $this->_prioTrans[$priority];
// translate $priority, if neccessary
if (is_numeric($priority)) {
$priority = $this->_prioTrans[$priority];
}
$db->Query('UPDATE {pre}tasks SET beginn=?,faellig=?,akt_status=?,titel=?,priority=?,erledigt=?,comments=?,tasklistid=? WHERE id=? AND user=?',
(int)$beginn,
(int)$faellig,
(int)$akt_status,
$titel,
$priority,
(int)$erledigt,
$comments,
(int)$taskListID,
(int)$id,
$this->_userID);
$db->Query('UPDATE {pre}tasks SET beginn=?,faellig=?,akt_status=?,titel=?,priority=?,erledigt=?,comments=?,tasklistid=? WHERE id=? AND user=?',
(int) $beginn,
(int) $faellig,
(int) $akt_status,
$titel,
$priority,
(int) $erledigt,
$comments,
(int) $taskListID,
(int) $id,
$this->_userID);
if($db->AffectedRows() == 1)
{
ChangelogUpdated(BMCL_TYPE_TODO, $id, time());
return(true);
}
return(false);
}
if ($db->AffectedRows() == 1) {
ChangelogUpdated(BMCL_TYPE_TODO, $id, time());
/**
* update task status
*
* @param int $id Task ID
* @param int $status New status
* @return bool
*/
function SetStatus($id, $status)
{
global $db;
return true;
}
$db->Query('UPDATE {pre}tasks SET akt_status=? WHERE id=? AND user=?',
(int)$status,
(int)$id,
$this->_userID);
if($db->AffectedRows() == 1)
{
ChangelogUpdated(BMCL_TYPE_TODO, $id, time());
return(true);
}
return(false);
}
return false;
}
/**
* delete a task
*
* @param int $id Task ID
* @return bool
*/
function Delete($id)
{
global $db;
/**
* update task status.
*
* @param int $id Task ID
* @param int $status New status
*
* @return bool
*/
public function SetStatus($id, $status)
{
global $db;
$db->Query('DELETE FROM {pre}tasks WHERE id=? AND user=?',
(int)$id,
$this->_userID);
if($db->AffectedRows() == 1)
{
ChangelogDeleted(BMCL_TYPE_TODO, $id, time());
return(true);
}
return(false);
}
$db->Query('UPDATE {pre}tasks SET akt_status=? WHERE id=? AND user=?',
(int) $status,
(int) $id,
$this->_userID);
if ($db->AffectedRows() == 1) {
ChangelogUpdated(BMCL_TYPE_TODO, $id, time());
/**
* get task info
*
* @param int $id Task ID
* @return array
*/
function GetTask($id)
{
global $db;
return true;
}
$res = $db->Query('SELECT id,beginn,faellig,akt_status,titel,priority,erledigt,comments,tasklistid,dav_uri,dav_uid FROM {pre}tasks WHERE id=? AND user=?',
(int)$id,
$this->_userID);
if($res->RowCount() == 0)
return(false);
$row = $res->FetchArray();
$res->Free();
return false;
}
return(array(
'id' => $row['id'],
'beginn' => $row['beginn'],
'faellig' => $row['faellig'],
'akt_status' => $row['akt_status'],
'titel' => $row['titel'],
'priority' => $this->_prioTrans[$row['priority']],
'erledigt' => $row['erledigt'],
'comments' => $row['comments'],
'tasklistid' => $row['tasklistid'],
'dav_uri' => $row['dav_uri'],
'dav_uid' => $row['dav_uid']
));
}
/**
* delete a task.
*
* @param int $id Task ID
*
* @return bool
*/
public function Delete($id)
{
global $db;
/**
* get task lists
*
* @return array
*/
function GetTaskLists()
{
global $db, $lang_user;
$db->Query('DELETE FROM {pre}tasks WHERE id=? AND user=?',
(int) $id,
$this->_userID);
if ($db->AffectedRows() == 1) {
ChangelogDeleted(BMCL_TYPE_TODO, $id, time());
$result = array();
$result[0] = array('tasklistid' => 0, 'title' => $lang_user['tasks']);
$res = $db->Query('SELECT `tasklistid`,`title`,`dav_uri` FROM {pre}tasklists WHERE `userid`=? ORDER BY `tasklistid` ASC',
$this->_userID);
while($row = $res->FetchArray(MYSQLI_ASSOC))
{
$result[$row['tasklistid']] = $row;
}
$res->Free();
return true;
}
return($result);
}
return false;
}
/**
* add a task list
*
* @param string $title Title
* @return int ID of new list
*/
function AddTaskList($title, $davURI = '')
{
global $db;
/**
* get task info.
*
* @param int $id Task ID
*
* @return array
*/
public function GetTask($id)
{
global $db;
$db->Query('INSERT INTO {pre}tasklists(`userid`,`title`,`dav_uri`) VALUES(?,?,?)',
$this->_userID,
$title,
$davURI);
return($db->InsertId());
}
$res = $db->Query('SELECT id,beginn,faellig,akt_status,titel,priority,erledigt,comments,tasklistid,dav_uri,dav_uid FROM {pre}tasks WHERE id=? AND user=?',
(int) $id,
$this->_userID);
if ($res->RowCount() == 0) {
return false;
}
$row = $res->FetchArray();
$res->Free();
/**
* change a task list
*
* @param string $title New title
* @return bool
*/
function ChangeTaskList($taskListID, $title)
{
global $db;
return [
'id' => $row['id'],
'beginn' => $row['beginn'],
'faellig' => $row['faellig'],
'akt_status' => $row['akt_status'],
'titel' => $row['titel'],
'priority' => $this->_prioTrans[$row['priority']],
'erledigt' => $row['erledigt'],
'comments' => $row['comments'],
'tasklistid' => $row['tasklistid'],
'dav_uri' => $row['dav_uri'],
'dav_uid' => $row['dav_uid'],
];
}
$db->Query('UPDATE {pre}tasklists SET `title`=? WHERE `userid`=? AND `tasklistid`=?',
$title,
$this->_userID,
$taskListID);
return($db->AffectedRows() == 1);
}
/**
* get task lists.
*
* @return array
*/
public function GetTaskLists()
{
global $db, $lang_user;
/**
* delete a task list
*
* @param int $taskListID ID of task list to delete
* @param bool $deleteTasks Delete tasks in list? ('false' moves them to default list)
* @return bool Success
*/
function DeleteTaskList($taskListID, $deleteTasks = true)
{
global $db;
$result = [];
$result[0] = ['tasklistid' => 0, 'title' => $lang_user['tasks']];
$res = $db->Query('SELECT `tasklistid`,`title`,`dav_uri` FROM {pre}tasklists WHERE `userid`=? ORDER BY `tasklistid` ASC',
$this->_userID);
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$result[$row['tasklistid']] = $row;
}
$res->Free();
if($taskListID < 0)
return(false);
return $result;
}
if($deleteTasks)
{
$db->Query('DELETE FROM {pre}tasks WHERE `user`=? AND `tasklistid`=?',
$this->_userID,
$taskListID);
}
else
{
$db->Query('UPDATE {pre}tasks SET `tasklistid`=0 WHERE `user`=? AND `tasklistid`=?',
$this->_userID,
$taskListID);
}
/**
* add a task list.
*
* @param string $title Title
*
* @return int ID of new list
*/
public function AddTaskList($title, $davURI = '')
{
global $db;
$db->Query('DELETE FROM {pre}tasklists WHERE `tasklistid`=? AND `userid`=?',
$taskListID,
$this->_userID);
return($db->AffectedRows() > 0);
}
$db->Query('INSERT INTO {pre}tasklists(`userid`,`title`,`dav_uri`) VALUES(?,?,?)',
$this->_userID,
$title,
$davURI);
/**
* move task(s) to different task list
*
* @param array/int $tasks Task ID(s)
* @param int $taskListID Destination task list ID
* @return bool Success
*/
function MoveTasks($tasks, $taskListID)
{
global $db;
return $db->InsertId();
}
if(!is_array($tasks))
$tasks = array($tasks);
if(count($tasks) == 0)
return(false);
/**
* change a task list.
*
* @param string $title New title
*
* @return bool
*/
public function ChangeTaskList($taskListID, $title)
{
global $db;
$db->Query('UPDATE {pre}tasks SET `tasklistid`=? WHERE `id` IN ? AND `user`=?',
$taskListID,
$tasks,
$this->_userID);
$db->Query('UPDATE {pre}tasklists SET `title`=? WHERE `userid`=? AND `tasklistid`=?',
$title,
$this->_userID,
$taskListID);
if($db->AffectedRows() > 0)
{
foreach($tasks as $taskID)
ChangelogUpdated(BMCL_TYPE_TODO, $taskID, time());
return(true);
}
return $db->AffectedRows() == 1;
}
return(false);
}
/**
* delete a task list.
*
* @param int $taskListID ID of task list to delete
* @param bool $deleteTasks Delete tasks in list? ('false' moves them to default list)
*
* @return bool Success
*/
public function DeleteTaskList($taskListID, $deleteTasks = true)
{
global $db;
if ($taskListID < 0) {
return false;
}
if ($deleteTasks) {
$db->Query('DELETE FROM {pre}tasks WHERE `user`=? AND `tasklistid`=?',
$this->_userID,
$taskListID);
} else {
$db->Query('UPDATE {pre}tasks SET `tasklistid`=0 WHERE `user`=? AND `tasklistid`=?',
$this->_userID,
$taskListID);
}
$db->Query('DELETE FROM {pre}tasklists WHERE `tasklistid`=? AND `userid`=?',
$taskListID,
$this->_userID);
return $db->AffectedRows() > 0;
}
/**
* move task(s) to different task list.
*
* @param array/int $tasks Task ID(s)
* @param int $taskListID Destination task list ID
*
* @return bool Success
*/
public function MoveTasks($tasks, $taskListID)
{
global $db;
if (!is_array($tasks)) {
$tasks = [$tasks];
}
if (count($tasks) == 0) {
return false;
}
$db->Query('UPDATE {pre}tasks SET `tasklistid`=? WHERE `id` IN ? AND `user`=?',
$taskListID,
$tasks,
$this->_userID);
if ($db->AffectedRows() > 0) {
foreach ($tasks as $taskID) {
ChangelogUpdated(BMCL_TYPE_TODO, $taskID, time());
}
return true;
}
return false;
}
}

View file

@ -19,242 +19,259 @@
*
*/
if(!defined('B1GMAIL_INIT'))
die('Directly calling this file is not supported');
if (!defined('B1GMAIL_INIT')) {
die('Directly calling this file is not supported');
}
define('WORKGROUP_TYPE_MAILFOLDER', 1);
define('WORKGROUP_TYPE_MAILFOLDER', 1);
/**
* workgroup class
* workgroup class.
*/
class BMWorkgroup
{
var $_id;
var $_row;
public $_id;
public $_row;
/**
* constructor
*
* @param int $id
* @return BMWorkgroup
*/
function __construct($id)
{
$this->_id = $id;
$this->_row = $this->Fetch();
}
/**
* constructor.
*
* @param int $id
*
* @return BMWorkgroup
*/
public function __construct($id)
{
$this->_id = $id;
$this->_row = $this->Fetch();
}
/**
* fetch a group row (assoc)
*
* @param int $id
* @return $array
*/
function Fetch($id = -1)
{
global $db;
/**
* fetch a group row (assoc).
*
* @param int $id
*
* @return $array
*/
public function Fetch($id = -1)
{
global $db;
if($id == -1)
{
$id = $this->_id;
if(is_array($this->_row))
return($this->_row);
}
if ($id == -1) {
$id = $this->_id;
if (is_array($this->_row)) {
return $this->_row;
}
}
$res = $db->Query('SELECT * FROM {pre}workgroups WHERE id=?',
$id);
if($res->RowCount() == 0)
return(false);
$row = $res->FetchArray(MYSQLI_ASSOC);
$res->Free();
$res = $db->Query('SELECT * FROM {pre}workgroups WHERE id=?',
$id);
if ($res->RowCount() == 0) {
return false;
}
$row = $res->FetchArray(MYSQLI_ASSOC);
$res->Free();
return($row);
}
return $row;
}
/**
* retrieve a simple id/title workgroup list for user
*
* @param int $userID
* @param bool $withMembers Include members?
* @param bool $excludeDeleted Exclude deleted members?
* @return array
*/
static function GetSimpleWorkgroupList($userID, $withMembers = false, $excludeDeleted = true)
{
global $db;
/**
* retrieve a simple id/title workgroup list for user.
*
* @param int $userID
* @param bool $withMembers Include members?
* @param bool $excludeDeleted Exclude deleted members?
*
* @return array
*/
public static function GetSimpleWorkgroupList($userID, $withMembers = false, $excludeDeleted = true)
{
global $db;
$groups = array();
$res = $db->Query('SELECT {pre}workgroups.id AS id,{pre}workgroups.title AS title,{pre}workgroups.email AS email,{pre}workgroups.webdisk AS webdisk FROM {pre}workgroups,{pre}workgroups_member WHERE {pre}workgroups.id={pre}workgroups_member.workgroup AND {pre}workgroups_member.user=? ORDER BY title ASC',
(int)$userID);
while($row = $res->FetchArray(MYSQLI_ASSOC))
{
if($withMembers)
{
$members = array();
$res2 = $db->Query('SELECT {pre}users.vorname AS vorname,{pre}users.nachname AS nachname,{pre}users.email AS email,{pre}users.id AS id FROM {pre}users,{pre}workgroups_member WHERE {pre}users.id={pre}workgroups_member.user AND {pre}workgroups_member.workgroup=? ' . ($excludeDeleted ? 'AND {pre}users.gesperrt!=\'delete\' ' : '') . 'ORDER BY nachname ASC',
$row['id']);
while($memberRow = $res2->FetchArray(MYSQLI_ASSOC))
$members[$memberRow['id']] = $memberRow;
$res2->Free();
$groups = [];
$res = $db->Query('SELECT {pre}workgroups.id AS id,{pre}workgroups.title AS title,{pre}workgroups.email AS email,{pre}workgroups.webdisk AS webdisk FROM {pre}workgroups,{pre}workgroups_member WHERE {pre}workgroups.id={pre}workgroups_member.workgroup AND {pre}workgroups_member.user=? ORDER BY title ASC',
(int) $userID);
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
if ($withMembers) {
$members = [];
$res2 = $db->Query('SELECT {pre}users.vorname AS vorname,{pre}users.nachname AS nachname,{pre}users.email AS email,{pre}users.id AS id FROM {pre}users,{pre}workgroups_member WHERE {pre}users.id={pre}workgroups_member.user AND {pre}workgroups_member.workgroup=? '.($excludeDeleted ? 'AND {pre}users.gesperrt!=\'delete\' ' : '').'ORDER BY nachname ASC',
$row['id']);
while ($memberRow = $res2->FetchArray(MYSQLI_ASSOC)) {
$members[$memberRow['id']] = $memberRow;
}
$res2->Free();
$row['members'] = $members;
$row['memberCount'] = count($members);
}
$row['members'] = $members;
$row['memberCount'] = count($members);
}
$groups[$row['id']] = $row;
}
$res->Free();
$groups[$row['id']] = $row;
}
$res->Free();
return($groups);
}
return $groups;
}
/**
* get workgroup id by mail address
*
* @param string $email Mail address
* @return int
*/
function GetIDbyMail($email)
{
global $db;
/**
* get workgroup id by mail address.
*
* @param string $email Mail address
*
* @return int
*/
public function GetIDbyMail($email)
{
global $db;
list(, $domainPart) = explode('@', $email);
$res = $db->Query('SELECT id FROM {pre}workgroups WHERE email=? OR email=? LIMIT 1',
$email,
'*@' . $domainPart);
if($res->RowCount() > 0)
{
list($id) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
return($id);
}
list(, $domainPart) = explode('@', $email);
$res = $db->Query('SELECT id FROM {pre}workgroups WHERE email=? OR email=? LIMIT 1',
$email,
'*@'.$domainPart);
if ($res->RowCount() > 0) {
list($id) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
return(0);
}
return $id;
}
/**
* get group members (id, email)
*
* @param int $id Workgroup ID
* @param bool $excludeDeleted Exclude deleted users?
* @return array
*/
function GetMembers($id = -1, $excludeDeleted = true)
{
global $db;
return 0;
}
if($id == -1)
$id = $this->_id;
/**
* get group members (id, email).
*
* @param int $id Workgroup ID
* @param bool $excludeDeleted Exclude deleted users?
*
* @return array
*/
public function GetMembers($id = -1, $excludeDeleted = true)
{
global $db;
$members = array();
$res = $db->Query('SELECT {pre}users.id AS id, {pre}users.email AS email FROM {pre}users,{pre}workgroups_member WHERE {pre}users.id={pre}workgroups_member.user AND {pre}workgroups_member.workgroup=?'
. ($excludeDeleted ? ' AND {pre}users.gesperrt!=\'delete\'' : ''),
$id);
while($row = $res->FetchArray(MYSQLI_ASSOC))
$members[$row['id']] = $row;
$res->Free();
if ($id == -1) {
$id = $this->_id;
}
return($members);
}
$members = [];
$res = $db->Query('SELECT {pre}users.id AS id, {pre}users.email AS email FROM {pre}users,{pre}workgroups_member WHERE {pre}users.id={pre}workgroups_member.user AND {pre}workgroups_member.workgroup=?'
.($excludeDeleted ? ' AND {pre}users.gesperrt!=\'delete\'' : ''),
$id);
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$members[$row['id']] = $row;
}
$res->Free();
/**
* check if user is in a workgroup
*
* @param int $userID
* @param int $groupID
* @return bool
*/
function UserInGroup($userID, $groupID)
{
global $db, $__inGroupCache;
return $members;
}
// init cache
if(!isset($__inGroupCache) || !is_array($__inGroupCache))
$__inGroupCache = array();
/**
* check if user is in a workgroup.
*
* @param int $userID
* @param int $groupID
*
* @return bool
*/
public function UserInGroup($userID, $groupID)
{
global $db, $__inGroupCache;
// cached?
if(isset($__inGroupCache[$userID.'_'.$groupID]))
return($__inGroupCache[$userID.'_'.$groupID]);
// init cache
if (!isset($__inGroupCache) || !is_array($__inGroupCache)) {
$__inGroupCache = [];
}
// get from db
$res = $db->Query('SELECT COUNT(*) FROM {pre}workgroups_member WHERE workgroup=? AND user=?',
(int)$groupID,
(int)$userID);
list($rowCount) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
// cached?
if (isset($__inGroupCache[$userID.'_'.$groupID])) {
return $__inGroupCache[$userID.'_'.$groupID];
}
// cache, return
$__inGroupCache[$userID.'_'.$groupID] = $rowCount == 1;
return($__inGroupCache[$userID.'_'.$groupID]);
}
// get from db
$res = $db->Query('SELECT COUNT(*) FROM {pre}workgroups_member WHERE workgroup=? AND user=?',
(int) $groupID,
(int) $userID);
list($rowCount) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
/**
* get title by id
*
* @param int $id
* @return string
*/
function GetTitle($id)
{
global $db;
// cache, return
$__inGroupCache[$userID.'_'.$groupID] = $rowCount == 1;
$res = $db->Query('SELECT title FROM {pre}workgroups WHERE id=?',
$id);
list($title) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
return $__inGroupCache[$userID.'_'.$groupID];
}
return($title);
}
/**
* get title by id.
*
* @param int $id
*
* @return string
*/
public function GetTitle($id)
{
global $db;
/**
* check if access to a certain shared element is allowed
*
* @param int $userID User ID
* @param int $shareType Share type (see constants at top of file)
* @param bool $writeAccess Also check for write access?
* @return bool
*/
static function AccessAllowed($userID, $shareType, $shareID, $writeAccess)
{
global $db, $wgAccessCache;
$res = $db->Query('SELECT title FROM {pre}workgroups WHERE id=?',
$id);
list($title) = $res->FetchArray(MYSQLI_NUM);
$res->Free();
if(!EXTENDED_WORKGROUPS)
return(false);
return $title;
}
if(!isset($wgAccessCache) || !is_array($wgAccessCache))
$wgAccessCache = array();
/**
* check if access to a certain shared element is allowed.
*
* @param int $userID User ID
* @param int $shareType Share type (see constants at top of file)
* @param bool $writeAccess Also check for write access?
*
* @return bool
*/
public static function AccessAllowed($userID, $shareType, $shareID, $writeAccess)
{
global $db, $wgAccessCache;
if($shareID <= 0)
return(false);
if (!EXTENDED_WORKGROUPS) {
return false;
}
// this function gets called quite frequently, so we want to cache all shared objects
// this user may access to avoid unnecessary db queries
if(!isset($wgAccessCache[$userID]))
{
$wgAccessCache[$userID] = array();
if (!isset($wgAccessCache) || !is_array($wgAccessCache)) {
$wgAccessCache = [];
}
$res = $db->Query('SELECT sharetype,shareid,writeaccess FROM {pre}workgroups_shares '
. 'INNER JOIN {pre}workgroups_member ON {pre}workgroups_shares.workgroupid={pre}workgroups_member.workgroup '
. 'WHERE {pre}workgroups_member.user=?',
$userID);
while($row = $res->FetchArray(MYSQLI_ASSOC))
{
if(!isset($wgAccessCache[$userID][$row['sharetype']]))
$wgAccessCache[$userID][$row['sharetype']] = array();
$wgAccessCache[$userID][$row['sharetype']][$row['shareid']] = ($row['writeaccess']==1?'rw':'ro');
}
$res->Free();
}
if ($shareID <= 0) {
return false;
}
$result = false;
// this function gets called quite frequently, so we want to cache all shared objects
// this user may access to avoid unnecessary db queries
if (!isset($wgAccessCache[$userID])) {
$wgAccessCache[$userID] = [];
if(!isset($wgAccessCache[$userID][$shareType][$shareID]))
$result = false;
else if($writeAccess)
$result = ($wgAccessCache[$userID][$shareType][$shareID] == 'rw');
else
$result = true;
$res = $db->Query('SELECT sharetype,shareid,writeaccess FROM {pre}workgroups_shares '
.'INNER JOIN {pre}workgroups_member ON {pre}workgroups_shares.workgroupid={pre}workgroups_member.workgroup '
.'WHERE {pre}workgroups_member.user=?',
$userID);
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
if (!isset($wgAccessCache[$userID][$row['sharetype']])) {
$wgAccessCache[$userID][$row['sharetype']] = [];
}
$wgAccessCache[$userID][$row['sharetype']][$row['shareid']] = ($row['writeaccess'] == 1 ? 'rw' : 'ro');
}
$res->Free();
}
return($result);
}
$result = false;
if (!isset($wgAccessCache[$userID][$shareType][$shareID])) {
$result = false;
} elseif ($writeAccess) {
$result = ($wgAccessCache[$userID][$shareType][$shareID] == 'rw');
} else {
$result = true;
}
return $result;
}
}