Commit f7d48966 authored by Leif Andersson's avatar Leif Andersson
Browse files

A

parent 2d49438f
......@@ -30,8 +30,8 @@ if (! $this->CheckPermission('Use ReglerAddress')) {
* wrapped in the DisplayAdminPanel() method in the module body.
*/
$groups = Group::getGroup();
//echo '<pre>'; print_r($groups); echo '</pre>';
$groups = Group::getGroupList();
//echo '<pre>'; print_r($groups); echo '</pre>'; exit;
//file_put_contents("/tmp/defaultadmin.txt",print_r($params,TRUE));
$addrDB = AddressDB::getDB();
......@@ -72,7 +72,10 @@ $smarty->assign('newButton',$place);
$name = 'Grupp';
$groupNames = array(' ' => 'None') + $groups;
$groupNames = array(' ' => 'None');
foreach ($groups as $group) {
$groupNames[$group->Gruppnamn] = $group->ID;
}
$selected = array();
if (isset($params[$name])) $selected[] = $params[$name];
$place = $this->CreateInputSelectList($id, $name, $groupNames,
......
<?php
if (!isset($gCms)) exit;
//echo '<pre>'; print_r($params); echo '</pre>';
if (! $this->CheckPermission('Use ReglerAddress')) {
return $this->DisplayErrorPage($id, $params, $returnid,
'ReglerAddress access denied.');
}
require_once 'lib/class.Group.php';
?>
......@@ -2,11 +2,11 @@
class Group {
private static $maildir = '/tmp/maildir';
private static $maildir = '/home/leif/slask/maildir';
private static $queryList = <<<EOS
select ID, Gruppnamn from Grupper order by Gruppnamn
select ID, Gruppnamn, GruppInfo from Grupper order by Gruppnamn
EOS;
private static $queryMembership = <<<EOS
......@@ -27,19 +27,44 @@ EOS;
Adresser.ID = AdressID and GruppID = ?
EOS;
private static $groupFields = array('ID', 'Gruppnamn', 'GruppInfo');
private static $instance;
private $list;
private static $list = array();
private function __construct($param = NULL) {
foreach (self::$groupFields as $field) {$this->$field = '';}
if (is_null($param)) return;
if (is_array($param)) {
foreach (self::$groupFields as $field) {
$this->$field = $param[$field];
}
}
}
private function __construct() {
global $gCms;
if (!isset($gCms)) exit;
$ADB = AddressDB::getDB();
$result = $ADB->Execute(self::$queryList,array());
public static function getGroupList() {
if (count(self::$list) > 0) return $list;
global $gCms; if (!isset($gCms)) exit;
$c = __CLASS__;
$db = AddressDB::getDB();
$result = $db->Execute(self::$queryList,array());
if ($result === false) { die("Database error!<br>" . $db->ErrorMsg());}
while ($row = $result->FetchRow()) {
$this->list[$row['Gruppnamn']] = $row['ID'];
self::$list[] = new $c($row);
}
return self::$list;
}
/* global $gCms; */
/* if (!isset($gCms)) exit; */
/* $ADB = AddressDB::getDB(); */
/* $result = $ADB->Execute(self::$queryList,array()); */
/* while ($row = $result->FetchRow()) { */
/* $this->list[$row['Gruppnamn']] = $row['ID']; */
/* } */
/* } */
public static function getMembers($GruppID) {
global $gCms; if (!isset($gCms)) exit;
......@@ -55,7 +80,12 @@ EOS;
public static function getNonMembers($GruppID) {
$members = self::getMembers($GruppID);
$nonmembers = array_diff_assoc(self::getGroup(),$members);
$allgroups = array();
self::getGroupList();
foreach (self::$list as $group) {
$allgroups[$group->Gruppnamn] = $group->ID;
}
$nonmembers = array_diff_assoc($allgroups,$members);
return $nonmembers;
}
......@@ -77,24 +107,24 @@ EOS;
if ($result === false) {die("Database error!<br>" . $db->ErrorMsg()); }
}
public static function getGroup() {
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance->list;
}
/* public static function getGroup() { */
/* if (!isset(self::$instance)) { */
/* $c = __CLASS__; */
/* self::$instance = new $c; */
/* } */
/* return self::$instance->list; */
/* } */
public static function setMailLists() {
global $gCms; if (!isset($gCms)) exit;
$db = AddressDB::getDB();
$groups = self::getGroup();
$groups = self::getGroupList();
if(!is_dir(self::$maildir)) mkdir(self::$maildir,'0755',true);
foreach ($groups as $name => $ID) {
$pos = strrpos($name, '.dis');
foreach ($groups as $group) {
$pos = strrpos($group->Gruppnamn, '.dis');
if ($pos === false) continue;
$epost = array();
$values = array($ID);
$values = array($group->ID);
$result = $db->Execute(self::$queryMail,$values);
if ($result === false) { die("Database error!<br>" . $db->ErrorMsg()); }
while ($row = $result->FetchRow()) {
......@@ -103,7 +133,7 @@ EOS;
}
if (count($epost) > 0) {
// echo '<pre>'; print_r($epost); echo '</pre>';
$filename = self::$maildir . '/' . $name;
$filename = self::$maildir . '/' . $group->Gruppnamn;
$file = fopen($filename,'w');
if ($file === false) die('Cannot write '.$filename);
foreach ($epost as $line) fwrite($file,$line.PHP_EOL);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment