コード例 #1
0
ファイル: AdminTools.class.php プロジェクト: hungnv0789/vhtm
 /**
  * Disguise action
  *
  * Administrator is able to disguise (and login) as other users.
  * This method will facilitate this functionalities.
  *
  * TODO better PHPDOC
  */
 public function page_disguise()
 {
     // newUserID variable need to be passed in as a POST variable
     $reqUserID = IEM::requestGetPOST('newUserID', 0, 'intval');
     if (empty($reqUserID)) {
         IEM::redirectTo('index');
         return false;
     }
     // Attempt to login user with different ID
     if (!IEM::userLogin($reqUserID, false)) {
         IEM::redirectTo('index');
         return false;
     }
     IEM::redirectTo('index');
     return true;
 }
コード例 #2
0
    /**
     * DeleteNewsletters
     * Deletes a list of newsletter id's passed in.
     *
     * @param Array $newsletterids An array of newsletters you want to delete. If it's a single id, it's turned into an array for easy processing.
     *
     * @see GetApi
     * @see Newsletters_API::Delete
     * @see ManageNewsletters
     *
     * @return Void Doesn't return anything. Prints out a message based on what happened and prints out the list of newsletters again.
     */
    function DeleteNewsletters($newsletterids=array()) {
        if (!is_array($newsletterids)) {
            $newsletterids = array($newsletterids);
        }

        $api = $this->GetApi();
        $jobapi = $this->GetApi('Jobs');

        $newsletterids = $api->CheckIntVars($newsletterids);

        if (empty($newsletterids)) {
            $GLOBALS['Error'] = GetLang('NoNewslettersToDelete');
            $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false);
            $this->ManageNewletters();
            return;
        }

        $user = GetUser();

        $sends_in_progress = array();
        $delete_ok = $delete_fail = 0;
        foreach ($newsletterids as $p => $newsletterid) {

            $job = $jobapi->FindJob('send', 'newsletter', $newsletterid);
            if ($job) {
                if ($job['jobstatus'] == 'i') {
                    $api->Load($newsletterid);
                    $newsletter_name = $api->Get('name');
                    $sends_in_progress[] = $newsletter_name;
                    continue;
                }
                $jobapi->Delete($job['jobid']);

                while ($job = $jobapi->FindJob('send', 'newsletter', $newsletterid)) {
                    if ($job['jobstatus'] == 'i') {
                        $api->Load($newsletterid);
                        $newsletter_name = $api->Get('name');
                        $sends_in_progress[] = $newsletter_name;
                        break;
                    }
                    $jobapi->Delete($job['jobid']);
                }
            }

            $status = $api->Delete($newsletterid, $user->Get('userid'));
            if ($status) {
                $delete_ok++;
            } else {
                $delete_fail++;
            }
        }

        $msg = '';

        if (!empty($sends_in_progress)) {
            if (sizeof($sends_in_progress) == 1) {
                $GLOBALS['Error'] = sprintf(GetLang('Newsletter_NotDeleted_SendInProgress'), current($sends_in_progress));
            } else {
                $GLOBALS['Error'] = sprintf(GetLang('Newsletters_NotDeleted_SendInProgress'), implode('\',\'', $sends_in_progress));
            }
            $msg .= $this->ParseTemplate('ErrorMsg', true, false);
        }

        if ($delete_ok > 0) {
            if ($delete_ok == 1) {
                $msg .= $this->PrintSuccess('Newsletter_Deleted');
            } else {
                $msg .= $this->PrintSuccess('Newsletters_Deleted', $this->FormatNumber($delete_ok));
            }
        }
        $GLOBALS['Message'] = $msg;

        IEM::sessionSet('Newsletters_deletion['.$user->Get('userid').']',$GLOBALS['Message']);
        IEM::redirectTo("Newsletters",array("Action" => "Manage"));
    }
コード例 #3
0
ファイル: users.php プロジェクト: hungnv0789/vhtm
	/**
	* DeleteUsers
	* Deletes a list of users from the database via the api. Each user is checked to make sure you're not going to accidentally delete your own account and that you're not going to delete the 'last' something (whether it's the last active user, admin user or other).
	* If you aren't an admin user, you can't do anything at all.
	*
	* @param integer[] $users An array of userid's to delete
	* @param boolean $deleteData Whether or not to delete data owned by user along
	*
	* @see GetUser
	* @see User_API::UserAdmin
	* @see DenyAccess
	* @see CheckUserSystem
	* @see PrintManageUsers
	*
	* @return Void Doesn't return anything. Works out the relevant message about who was/wasn't deleted and prints that out. Returns control to PrintManageUsers.
	*/
	function DeleteUsers($users = array(), $deleteData = false)
	{
		$thisuser = GetUser();
		if (!$thisuser->UserAdmin()) {
			$this->DenyAccess();
			return;
		}

		if (!is_array($users)) {
			$users = array($users);
		}

		$not_deleted_list = array();
		$not_deleted = $deleted = 0;
		foreach ($users as $p => $userid) {
			if ($userid == $thisuser->Get('userid')) {
				$not_deleted++;
				$not_deleted_list[$userid] = array('username' => $thisuser->Get('username'), 'reason' => GetLang('User_CantDeleteOwn'));
				continue;
			}

			$error = $this->CheckUserSystem($userid);
			if (!$error) {
				$result = API_USERS::deleteRecordByID($userid, $deleteData);

				if ($result) {
					$deleted++;
				} else {
					$not_deleted++;
					$user = GetUser($userid);
					if ($user instanceof User_API) {
						$not_deleted_list[$userid] = array('username' => $user->Get('username'), 'reason' => '');
					} else {
						$not_deleted_list[$userid] = array('username' => $userid, 'reason' => '');
					}
				}
			} else {
				$not_deleted++;
				$user = GetUser($userid);
				if ($user instanceof User_API) {
					$not_deleted_list[$userid] = array('username' => $user->Get('username'), 'reason' => $error);
				} else {
					$not_deleted_list[$userid] = array('username' => $userid, 'reason' => $error);
				}
			}
		}


		if ($not_deleted > 0) {
			foreach ($not_deleted_list as $uid => $details) {
				FlashMessage(sprintf(GetLang('UserDeleteFail'), htmlspecialchars($details['username'], ENT_QUOTES, SENDSTUDIO_CHARSET), htmlspecialchars($details['reason'], ENT_QUOTES, SENDSTUDIO_CHARSET)), SS_FLASH_MSG_ERROR);
			}
		}

		if ($deleted > 0) {
			if ($deleted == 1) {
				FlashMessage(GetLang('UserDeleteSuccess_One'), SS_FLASH_MSG_SUCCESS, IEM::urlFor('Users'));
			} else {
				FlashMessage(sprintf(GetLang('UserDeleteSuccess_Many'), $this->FormatNumber($deleted)), SS_FLASH_MSG_SUCCESS, IEM::urlFor('Users'));
			}
		}

		IEM::redirectTo('Users');
	}
コード例 #4
0
	/**
	 * ChangeList
	 * Performs the following actions:
	 * - Deletes lists,
	 * - Deletes all subscribers within lists,
	 * - Changes the format of all subscribers within lists,
	 * - Changes the confirmed status of all subscribers within lists, or
	 * - Merges lists.
	 *
	 * @param Array $param Any parameters that needed to be passed into this function
	 *
	 * @return Void Redirects to the Manage Lists page or Edit List page depending on action or error.
	 */
	private function ChangeList($param)
	{
		$user =& $param['user'];

		// The User should be able to view the lists they want to merge, but there is no 'View' permission for lists.
		// For now we will just require that they have 'edit' permissions.
		foreach ($_POST['Lists'] as $lid) {
			if (!$user->HasAccess('lists', 'edit', $lid)) {
				$this->DenyAccess();
			}
		}
		$subaction = strtolower($_POST['ChangeType']);
		$listApi = $this->GetApi();

		$success_format = 0; $failure_format = 0;
		$success_status = 0; $failure_status = 0;
		$success_confirmed = 0; $failure_confirmed = 0;

		if ($subaction == 'mergelists') {
			if ($user->CanCreateList() !== true) {
				FlashMessage(GetLang('TooManyLists'), SS_FLASH_MSG_ERROR, IEM::urlFor('Lists'));
			}

			if (sizeof($_POST['Lists']) < 2) {
				FlashMessage(GetLang('UnableToMergeLists'), SS_FLASH_MSG_ERROR, IEM::urlFor('Lists'));
			}

			$message = '';

			$userdetails = array();
			$userdetails['userid'] = $user->userid;
			$userdetails['name'] = $user->fullname;
			$userdetails['emailaddress'] = $user->emailaddress;

			list($newid, $msg, $results) = $listApi->MergeLists($_POST['Lists'], $userdetails);

			$success_merged = $results['Success'];
			$failure_merged = $results['Failure'];
			$duplicates_success_removed = $results['DuplicatesSuccess'];
			$duplicates_failure_removed = $results['DuplicatesFailure'];

			if ($success_merged > 0) {
				$message .= sprintf(GetLang('MergeSuccessful'), $this->FormatNumber($success_merged));
				FlashMessage($message, SS_FLASH_MSG_SUCCESS);
			}

			if ($failure_merged > 0) {
				$message = sprintf(GetLang('MergeUnsuccessful'), $this->FormatNumber($success_merged));
				FlashMessage($message, SS_FLASH_MSG_ERROR);
			}

			if ($duplicates_success_removed > 0) {
				$message = sprintf(GetLang('MergeDuplicatesRemoved_Success'), $this->FormatNumber($duplicates_success_removed));
				FlashMessage($message, SS_FLASH_MSG_SUCCESS);
			}

			if ($duplicates_failure_removed > 0) {
				$message = sprintf(GetLang('MergeDuplicatesRemoved_Fail'), $this->FormatNumber($duplicates_failure_removed));
				FlashMessage($message, SS_FLASH_MSG_ERROR);
			}

			if (!$newid) {
				IEM::redirectTo('Lists');
			}

			$user->LoadPermissions($user->userid);
			$user->GrantListAccess($newid);
			$user->SavePermissions();
			IEM::redirectTo('Lists', array('Action' => 'Edit', 'id' => $newid));
		}

		$lists_deleted_success = $lists_deleted_failure = 0;
		$subscribers_deleted_success = $subscribers_deleted_failure = 0;

		foreach ($_POST['Lists'] as $pos => $list) {
			$listApi->Load((int)$list);
			switch ($subaction) {

				case 'delete':
                                    // ----- get jobs running for this user
                                    $db = IEM::getDatabase();
                                    $jobs_to_check = array();
                                    $query = "SELECT jobid FROM [|PREFIX|]jobs_lists WHERE listid = {$list}";
                                    $result = $db->Query($query);
                                    if(!$result){
                                            trigger_error(mysql_error()."<br />".$query);
                                            FlashMessage("Unable to load list jobs. <br /> ". mysql_error(), SS_FLASH_MSG_ERROR, IEM::urlFor('Lists'));
                                            exit();
                                    }
                                    while($row = $db->Fetch($result)){
                                            $jobs_to_check[] = $row['jobid'];
                                    }
                                    $db->FreeResult($result);
                                    if(!empty($jobs_to_check)){
                                            $query = "SELECT jobstatus FROM [|PREFIX|]jobs WHERE jobid IN (" . implode(',', $jobs_to_check) . ")";	
                                            $result = $db->Query($query);
                                            if(!$result){
                                                    trigger_error(mysql_error()."<br />".$query);
                                                    FlashMessage("Unable to load jobs. <br /> ". mysql_error() . "<br />Query: " . $query, SS_FLASH_MSG_ERROR, IEM::urlFor('Lists'));
                                                    exit();
                                            }
                                            while($row = $db->Fetch($result)){
                                                    if($row['jobstatus'] != 'c'){
                                                            FlashMessage('Unable to delete contacts from list(s). Please cancel any campaigns sending to the list(s) in order to delete them.', SS_FLASH_MSG_ERROR, IEM::urlFor('Lists'));
                                                            exit();
                                                    }
                                            }
                                            $db->FreeResult($result);
                                    }
                                    // -----
                                    $status = $listApi->Delete($list, $user->Get('userid'));
                                    if ($status) {
                                            $lists_deleted_success++;
                                            $user->RevokeListAccess($list);
                                            $user->SavePermissions();
                                    } else {
                                            $lists_deleted_failure++;
                                    }
				break;

				case 'deleteallsubscribers':
                                    // ----- get jobs running for this user
                                    $db = IEM::getDatabase();
                                    $jobs_to_check = array();
                                    $query = "SELECT jobid FROM [|PREFIX|]jobs_lists WHERE listid = {$list}";
                                    $result = $db->Query($query);
                                    if(!$result){
                                            trigger_error(mysql_error()."<br />".$query);
                                            FlashMessage("Unable to load list jobs. <br /> ". mysql_error(), SS_FLASH_MSG_ERROR, IEM::urlFor('Lists'));
                                            exit();
                                    }
                                    while($row = $db->Fetch($result)){
                                            $jobs_to_check[] = $row['jobid'];
                                    }
                                    $db->FreeResult($result);
                                    if(!empty($jobs_to_check)){
                                            $query = "SELECT jobstatus FROM [|PREFIX|]jobs WHERE jobid IN (" . implode(',', $jobs_to_check) . ")";	
                                            $result = $db->Query($query);
                                            if(!$result){
                                                    trigger_error(mysql_error()."<br />".$query);
                                                    FlashMessage("Unable to load jobs. <br /> ". mysql_error() . "<br />Query: " . $query, SS_FLASH_MSG_ERROR, IEM::urlFor('Lists'));
                                                    exit();
                                            }
                                            while($row = $db->Fetch($result)){
                                                    if($row['jobstatus'] != 'c'){
                                                            FlashMessage('Unable to delete contacts from list(s). Please cancel any campaigns sending to the list(s) in order to delete them.', SS_FLASH_MSG_ERROR, IEM::urlFor('Lists'));
                                                            exit();
                                                    }
                                            }
                                            $db->FreeResult($result);
                                    }
                                    // -----
                                    
                                    $status = $listApi->DeleteAllSubscribers($list);
                                    if ($status) {
                                            $subscribers_deleted_success++;
                                    } else {
                                            $subscribers_deleted_failure++;
                                    }
				break;

				case 'changeformat_text':
					$newformat = 'Text';
					list($status, $msg) = $listApi->ChangeSubscriberFormat($newformat, $list);
					if ($status) {
						$success_format++;
					} else {
						$failure_format++;
					}
				break;
				case 'changeformat_html':
					$newformat = 'HTML';
					list($status, $msg) = $listApi->ChangeSubscriberFormat($newformat, $list);
					if ($status) {
						$success_format++;
					} else {
						$failure_format++;
					}
				break;

				case 'changestatus_confirm':
					$newstatus = 'Confirmed';
					list($status, $msg) = $listApi->ChangeSubscriberConfirm('confirm', $list);
					if ($status) {
						$success_confirmed++;
					} else {
						$failure_confirmed++;
					}
				break;
				case 'changestatus_unconfirm':
					$newstatus = 'Unconfirmed';
					list($status, $msg) = $listApi->ChangeSubscriberConfirm('unconfirm', $list);
					if ($status) {
						$success_confirmed++;
					} else {
						$failure_confirmed++;
					}
				break;
			}
		}

		$message = '';

		if ($lists_deleted_success > 0) {
			$message = sprintf(GetLang('ListsDeleteSuccess'), $this->FormatNumber($lists_deleted_success));
			if ($lists_deleted_success == 1) {
				$message = GetLang('ListDeleteSuccess');
			}
			FlashMessage($message, SS_FLASH_MSG_SUCCESS);
		}

		if ($lists_deleted_failure > 0) {
			$message = GetLang('ListsDeleteFail');
			if ($lists_deleted_failure == 1) {
				$message = GetLang('ListDeleteFail');
			}
			FlashMessage($message, SS_FLASH_MSG_ERROR);
		}

		if ($subscribers_deleted_success > 0) {
			$message = sprintf(GetLang('ListsDeleteAllSubscribersSuccess'), $this->FormatNumber($subscribers_deleted_success));
			if ($subscribers_deleted_success == 1) {
				$message = GetLang('ListDeleteAllSubscribersSuccess');
			}
			FlashMessage($message, SS_FLASH_MSG_SUCCESS);
		}

		if ($subscribers_deleted_failure > 0) {
			$message = GetLang('ListsDeleteAllSubscribersFail');
			if ($subscribers_deleted_failure == 1) {
				$message = GetLang('ListDeleteAllSubscribersFail');
			}
			FlashMessage($message, SS_FLASH_MSG_ERROR);
		}

		if ($success_format > 0) {
			$message = sprintf(GetLang('AllListSubscribersChangedFormat'), GetLang('Format_' . $newformat));
			FlashMessage($message, SS_FLASH_MSG_SUCCESS);
		}
		if ($failure_format > 0) {
			$message = sprintf(GetLang('AllListSubscribersNotChangedFormat'), GetLang('Format_' . $newformat));
			FlashMessage($message, SS_FLASH_MSG_ERROR);
		}

		if ($success_status > 0) {
			$message = sprintf(GetLang('AllListSubscribersChangedStatus'), GetLang('Status_' . $newstatus));
			FlashMessage($message, SS_FLASH_MSG_SUCCESS);
		}
		if ($failure_status > 0) {
			$message = sprintf(GetLang('AllListSubscribersNotChangedStatus'), GetLang('Status_' . $newstatus));
			FlashMessage($message, SS_FLASH_MSG_ERROR);
		}

		if ($success_confirmed > 0) {
			$message = sprintf(GetLang('AllListSubscribersChangedConfirm'), GetLang('Status_' . $newstatus));
			FlashMessage($message, SS_FLASH_MSG_SUCCESS);
		}
		if ($failure_confirmed > 0) {
			$message = sprintf(GetLang('AllListSubscribersNotChangedConfirm'), GetLang('Status_' . $newstatus));
			FlashMessage($message, SS_FLASH_MSG_ERROR);
		}
		IEM::redirectTo('Lists');
	}
コード例 #5
0
	/**
	* RemoveBans
	* Removes an array of bans from the list passed in. It calls the API to do the actual removal, then prints out a report of actions taken.
	*
	* @param Array $banlist An array of bans to remove (their id's anyway). If it's not an array (it's a single ban to remove), it gets converted to an array for easy use.
	* @param Mixed $list List to remove the bans from. This can either be a numeric value (listid), or if it's 'global' it will cover the 'global' bans.
	*
	* @see GetApi
	* @see Subscriber_API::RemoveBannedSubscriber
	*
	* @return Void Prints out the report, doesn't return anything.
	*/
	function RemoveBans($banlist=array(), $list=null)
	{
		if (!is_array($banlist)) {
			$banlist = array($banlist);
		}

		$subscriber_api = $this->GetApi('Subscribers');

		$banned_search_info = IEM::sessionGet('Banned_Search_Subscribers');

		if (is_numeric($list)) {
			$ListApi = $this->GetApi('Lists');
			$ListApi->Load($banned_search_info['List']);
			$listname = $ListApi->name;
		} else {
			$listname = GetLang('Subscribers_GlobalBan');
		}

		$subscriber_api->Db->StartTransaction();

		$removed = 0; $notremoved = 0;
		foreach ($banlist as $pos => $banid) {
			list($status, $statusmsg) = $subscriber_api->RemoveBannedSubscriber($banid, $list);
			if ($status) {
				$removed++;
			} else {
				$notremoved++;
			}
		}

		$subscriber_api->Db->CommitTransaction();

		$msg = '';

		if ($notremoved > 0) {
			if ($notremoved == 1) {
				$GLOBALS['Error'] = sprintf(GetLang('Subscriber_Ban_NotDeleted_One'), htmlspecialchars($listname, ENT_QUOTES, SENDSTUDIO_CHARSET));
			} else {
				$GLOBALS['Error'] = sprintf(GetLang('Subscriber_Ban_NotDeleted_Many'), $this->FormatNumber($notremoved), htmlspecialchars($listname, ENT_QUOTES, SENDSTUDIO_CHARSET));
			}
			$msg .= $this->ParseTemplate('ErrorMsg', true, false);
		}

		if ($removed > 0) {
			if ($removed == 1) {
				$msg .= $this->PrintSuccess('Subscriber_Ban_Deleted_One', htmlspecialchars($listname, ENT_QUOTES, SENDSTUDIO_CHARSET));
			} else {
				$msg .= $this->PrintSuccess('Subscriber_Ban_Deleted_Many', $this->FormatNumber($removed), htmlspecialchars($listname, ENT_QUOTES, SENDSTUDIO_CHARSET));
			}
		}
		$GLOBALS['Message'] = $msg;
		$GLOBALS['List'] = $list;

		IEM::sessionSet('DeleteBannedSubscriberMessage', $msg);

		$banscount = IEM::sessionGet('ListBansCount');
		$newcount = $banscount - $removed;

		if ($newcount < 1) {
			IEM::redirectTo('Subscribers', array('Action' => 'Banned'));
			exit();
		}
		$this->ShowBannedList($list);
	}
コード例 #6
0
ファイル: basePage.class.php プロジェクト: hungnv0789/vhtm
 /**
  * page_index
  * The "controller" assume that this function always exists.
  * If the method is not overwritten, user will be re-directed to index page.
  *
  * TODO: becareful with index page... This can create infinite loop when the page_Index class
  * does not overwrite this method.
  */
 public function page_index()
 {
     IEM::redirectTo('index');
     return false;
 }