diff --git a/action.changeGroups.php b/action.changeGroups.php index 5c4251bf7598468549cb7791e42c229c0b568d9d..4641b8d1c67fc5a6ce1fa4973f55557fc55eb0d1 100644 --- a/action.changeGroups.php +++ b/action.changeGroups.php @@ -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); diff --git a/lib/class.Group.php b/lib/class.Group.php index 23d39d3c5059f93c3db843282bc843df59bd3385..439fde1667e040b7b32b03ef8502c0de36fb4cb7 100644 --- a/lib/class.Group.php +++ b/lib/class.Group.php @@ -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; + } } ?>