Commit 5304073d authored by Leif Andersson's avatar Leif Andersson
Browse files

Added handling of mailing list when groups change.

parent 89b27838
......@@ -30,11 +30,13 @@ $smarty->assign('headline',$headline);
if (isset($params['setMember'])) {
$GroupID = $params['nonmembers'];
Group::setMember($ID,$GroupID);
Group::setMailLists();
}
if (isset($params['unsetMember'])) {
$GroupID = $params['members'];
Group::UnsetMember($ID,$GroupID);
Group::setMailLists();
}
$members = Group::getMembers($ID);
......
......@@ -2,6 +2,9 @@
class Group {
private static $maildir = '/tmp/maildir';
private static $queryList = <<<EOS
select ID, Gruppnamn from Grupper order by Gruppnamn
EOS;
......@@ -19,6 +22,11 @@ EOS;
delete from GruppAdress where AdressID = ? and GruppID = ?
EOS;
private static $queryMail = <<<EOS
select Epost from Adresser, GruppAdress where
Adresser.ID = AdressID and GruppID = ?
EOS;
private static $instance;
private $list;
......@@ -77,6 +85,32 @@ EOS;
return self::$instance->list;
}
public static function setMailLists() {
global $gCms; if (!isset($gCms)) exit;
$db = AddressDB::getDB();
$groups = self::getGroup();
if(!is_dir(self::$maildir)) mkdir(self::$maildir,'0755',true);
foreach ($groups as $name => $ID) {
$pos = strrpos($name, '.dis');
if ($pos === false) continue;
$epost = array();
$values = array($ID);
$result = $db->Execute(self::$queryMail,$values);
if ($result === false) { die("Database error!<br>" . $db->ErrorMsg()); }
while ($row = $result->FetchRow()) {
if (!$row['Epost']) continue;
$epost[] = $row['Epost'];
}
if (count($epost) > 0) {
// echo '<pre>'; print_r($epost); echo '</pre>';
$filename = self::$maildir . '/' . $name;
$file = fopen($filename,'w');
if ($file === false) die('Cannot write '.$filename);
foreach ($epost as $line) fwrite($file,$line.PHP_EOL);
fclose($file);
}
}
// exit;
}
}
?>
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