1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
|
<?php
/**
* FusionForge Mailing Lists Facility
*
* Copyright 2003 Guillaume Smet
* http://fusionforge.org/
*
* @version $Id$
*
* This file is part of FusionForge.
*
* FusionForge 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.
*
* FusionForge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Portions Copyright 2010 (c) Mélanie Le Bail
*/
/*
This work is based on Tim Perdue's work on the forum stuff
*/
require_once 'MailmanListDao.class.php';
require_once 'ProjectManager.class.php';
require_once 'UserManager.class.php';
require_once 'common/dao/CodendiDataAccess.class.php';
require_once 'common/system_event/SystemEventManager.class.php';
require_once 'common/system_event/SystemEvent.class.php';
class MailmanList extends Error {
/**
* DAO
*
* @var MailingListDao $mailingDAO.
*/
var $_mailingDAO;
/**
* Associative array of data from db.
*
* @var array $dataArray.
*/
var $dataArray;
/**
* The Group object.
*
* @var object $Group.
*/
var $Group;
/**
* The mailing list id
*
* @var int $groupMailmanListId
*/
var $groupMailmanListId;
/**
* Constructor.
*
* @param object The Group object to which this mailing list is associated.
* @param int The group_list_id.
* @param array The associative array of data.
* @return boolean success.
*/
function MailmanList($group_id, $groupListId = false, $dataArray = false) {
$pm = ProjectManager::instance();
$Group = $pm->getProject($group_id);
$this->_mailingDAO = new MailmanListDao(CodendiDataAccess::instance());
$this->Error();
if (!$Group || !is_object($Group)) {
exit_no_group();
}
if ($Group->isError()) {
$this->setError('MailmanList: '.$Group->getErrorMessage());
return false;
}
$this->Group =& $Group;
if ($groupListId) {
$this->groupMailmanListId = $groupListId;
if (!$dataArray || !is_array($dataArray)) {
if (!$this->fetchData($groupListId)) {
return false;
}
} else {
$this->dataArray =& $dataArray;
if ($this->dataArray['group_id'] != $this->Group->getID()) {
$this->setError(_('group_id in db result does not match Group Object'));
$this->dataArray = null;
return false;
}
}
if (!$this->isPublic()) {
if (!isLogged()) {
$this->dataArray = null;
return false;
}
}
}
return true;
}
/**
* create - use this function to create a new entry in the database.
*
* @param string The name of the mailing list
* @param string The description of the mailing list
* @param int Pass (1) if it should be public (0) for private.
*
* @return boolean success.
**/
function create($listName, $description, $isPublic = '1',$creator_id=false) {
$current_user=UserManager::instance()->getCurrentUser();
//
// During the group creation, the current user_id will not match the admin's id
//
if (!$creator_id) {
$creator_id=$current_user->getID();
if(!$current_user->isMember($this->Group->getID(),'A')) {
exit_permission_denied();
return false;
}
}
if(!$listName || strlen($listName) < 4) {
$this->setError(_('Must Provide List Name That Is 4 or More Characters Long'));
return false;
}
$realListName = strtolower($this->Group->getUnixName().'-'.$listName);
if(!validate_email($realListName.'@'.forge_get_config('lists_host'))) {
$this->setError(_('Invalid List Name') . _(': ') .
$realListName.'@'.forge_get_config('lists_host'));
return false;
}
$result=&$this->_mailingDAO->searchByName($realListName);
if ($result->valid()) {
$this->setError(_('List Already Exists'));
return false;
}
$listPassword = substr(md5($GLOBALS['session_hash'] . time() . rand(0,40000)), 0, 16);
$result = $this->_mailingDAO->insertNewList($this->Group->getID(), $realListName,$isPublic,$listPassword,$creator_id,'1',$description);
if (!$result) {
$this->setError(_('Error Creating mailing list')._(': ').db_error());
return false;
}
$this->groupMailmanListId = $result;
// Raise an event
require_once 'mailman/include/events/SystemEvent_MAILMAN_LIST_CREATE.class.php';
$systemevent = SystemEventManager::instance();
$systemevent->createEvent('MAILMAN_LIST_CREATE', $this->groupMailmanListId,SystemEvent::PRIORITY_MEDIUM);
$this->fetchData($this->groupMailmanListId);
$user=UserManager::instance()->getUserByID($creator_id);
$userEmail = $user->getEmail();
if(empty($userEmail) || !validate_email($userEmail)) {
$this->setInvalidEmailError();
return false;
} else {
sendCreationMail($userEmail,$this);
}
return true;
}
/**
* activationRequested - LEt us know if an event is present to create this list
*
* @return boolean
*/
function activationRequested()
{
$systemevent = SystemEventManager::instance();
$result1 = $systemevent->fetchEvents(0,10,false,SystemEvent::STATUS_NEW,'MAILMAN_LIST_CREATE',$this->getID());
$result2 = $systemevent->fetchEvents(0,10,false,SystemEvent::STATUS_RUNNING,'MAILMAN_LIST_CREATE',$this->getID());
if(count($result1)+count($result2)<1) {
return false;
}
else {
return true;
}
}
/**
* recreate - let the admin recrate a list which had a problem during creation
*
* @return bool
*/
function recreate()
{
$systemevent = SystemEventManager::instance();
$systemevent->createEvent('MAILMAN_LIST_CREATE', $this->getID(),SystemEvent::PRIORITY_MEDIUM);
}
/**
* fetchData - re-fetch the data for this mailing list from the database.
*
* @param int The list_id.
* @return boolean success.
*/
function fetchData($groupListId) {
$res =& $this->_mailingDAO->searchListFromGroup($groupListId, $this->Group->getID());
if (!$res) {
$this->setError(_('Error Getting mailing list'));
return false;
}
$this->dataArray =& $res->getRow();
return true;
}
/**
* update - use this function to update an entry in the database.
*
* @param string The description of the mailing list
* @param int Pass (1) if it should be public (0) for private
* @return boolean success.
*/
function update($description, $isPublic ='1',$status='1') {
$current_user=UserManager::instance()->getCurrentUser();
if(!$current_user->isMember($this->Group->getID(),'A')) {
exit_permission_denied();
return false;
}
$res = $this->_mailingDAO->updateList($this->groupMailmanListId, $this->Group->getID(),$description , $isPublic,$status);
if (!$res) {
$this->setError(_('Update failed')._(': ').db_error());
return false;
}
return true;
}
/**
* getGroup - get the Group object this mailing list is associated with.
*
* @return object The Group object.
*/
function &getGroup() {
return $this->Group;
}
/**
* getID - The id of this mailing list
*
* @return int The group_list_id #.
*/
function getID() {
return $this->dataArray['group_list_id'];
}
/**
* isPublic - Is this mailing list open to the general public.
*
* @return boolean is_public.
*/
function isPublic() {
return $this->dataArray['is_public'];
}
/**
* getName - get the name of this mailing list
*
* @return string The name of this mailing list
*/
function getName() {
return $this->dataArray['list_name'];
}
/**
* getDescription - get the description of this mailing list
*
* @return string The description.
*/
function getDescription() {
return $this->dataArray['description'];
}
/**
* getPassword - get the password to administrate the mailing list
*
* @return string The password
*/
function getPassword() {
return $this->dataArray['password'];
}
/**
* getListAdminID - get the user id who is the admin of this mailing list
*
* @return id The admin user
*/
function getListAdminID() {
return $this->dataArray['list_admin'];
}
/**
* getStatus - get the status of this mailing list
*
* @return int The status
*/
function getStatus() {
return $this->dataArray['status'];
}
/**
* getArchivesUrl - get the url to see the archives of the list
*
* @return string url of the archives
*/
function getArchivesUrl() {
if ($this->isPublic()) {
$iframe_url = '/pipermail/'.$this->getName().'/';
} else {
$iframe_url = '/mailman/private/'.$this->getName().'/';
}
htmlIframe($iframe_url, array('class' => 'iframe_service'));
}
/**
* getExternalInfoUrl - get the url to subscribe/unsubscribe
*
* @return string url of the info page
*/
function getExternalInfoUrl() {
return util_make_url('/mailman/listinfo/'.$this->getName());
}
/**
* getOptionsUrl - get the url to manage options for user
*
* @return string url of the info page
*/
function getOptionsUrl() {
$current_user=UserManager::instance()->getCurrentUser();
$user=$current_user->getEmail();
$iframe_url = '/mailman/options/'.$this->getName().'/'.$user;
htmlIframe($iframe_url, array('class' => 'iframe_service'));
}
/**
* subscribeUrl - add the user to the mailinglist
*
* @return string url of the info page
*/
function subscribe() {
$current_user=UserManager::instance()->getCurrentUser();
if(isLogged() && $current_user->isMember($this->Group->getID()) && !$this->isMonitoring())
{
$user=$current_user->getEmail();
$passwd= $current_user->getUserPw();
$name= $current_user->getRealName();
$res = $this->_mailingDAO->newSubscriber($user,$name,$passwd,$this->getName());
if (!$res) {
$this->setError(_('Update failed')._(': ').db_error());
return false;
}
htmlRedirect('/plugins/mailman/index.php?group_id='.$this->Group->getId());
}
}
/**
* unsubscribeUrl - delete the user from the mailing list
*
* @return string url of the info page
*/
function unsubscribe() {
$current_user=UserManager::instance()->getCurrentUser();
$user=$current_user->getEmail();
$res = $this->_mailingDAO->deleteSubscriber($user,$this->getName());
if (!$res) {
$this->setError(_('Update failed')._(': ').db_error());
return false;
}
htmlRedirect('/plugins/mailman/index.php?group_id='.$this->Group->getId());
}
/**
* isMonitoring - See if the current user is in the list of people monitoring the forum.
*
* @return boolean is_monitoring.
*/
function isMonitoring() {
if (!isLogged()) {
return false;
}
$current_user=UserManager::instance()->getCurrentUser();
$user=$current_user->getEmail();
$res = $this->_mailingDAO->userIsMonitoring($user,$this->getName());
if (!$res) {
$this->setError(_('Error On Query:').db_error());
return false;
}
$row_count = $res->getRow();
return $row_count['count'] > 0;
}
/**
* getExternalAdminUrl - get the url to admin the list with the external tools used
*
* @return string url of the admin
*/
function getExternalAdminUrl() {
$iframe_url = '/mailman/admin/'.$this->getName();
htmlIframe($iframe_url, array('class' => 'iframe_service'));
}
/**
* delete - permanently delete this mailing list
*
* @param boolean I'm Sure.
* @param boolean I'm Really Sure.
* @return boolean success;
*/
function deleteList($sure,$really_sure) {
$current_user=UserManager::instance()->getCurrentUser();
if (!$sure || !$really_sure) {
$this->setError(_('Missing params'));
return false;
}
if (!$current_user->isMember($this->Group->getID(),'A')) {
exit_permission_denied();
return false;
}
$res = $this->_mailingDAO->deleteList($this->Group->getID(),$this->getID());
if (!$res) {
$this->setError(_('Could Not Delete List: ').db_error());
return false;
}
require_once 'mailman/include/events/SystemEvent_MAILMAN_LIST_DELETE.class.php';
$systemevent = SystemEventManager::instance();
$systemevent->createEvent('MAILMAN_LIST_DELETE', $this->groupMailmanListId,SystemEvent::PRIORITY_MEDIUM);
return true;
}
}
// Local Variables:
// mode: php
// c-file-style: "bsd"
// End:
|