예제 #1
0
	/**
	* Delete
	* Delete a list from the database. First we delete the list (and check the result for that), then we delete the subscribers for the list, the 'custom field data' for the list, the user permissions for the list, and finally reset all class vars.
	*
	* @param Int $listid Listid of the list to delete. If not passed in, it will delete 'this' list.
	* @param Int $userid The userid that is deleting the list. This is used so the stats api can "hide" stats.
	*
	* @see Stats_API::HideStats
	* @see DeleteAllSubscribers
	*
	* @return Boolean True if it deleted the list, false otherwise.
	*
	*/
	function Delete($listid=0, $userid=0)
	{
		$listid = (int)$listid;
		if ($listid == 0) {
			$listid = $this->listid;
		}

		$this->Db->StartTransaction();

		$query = "DELETE FROM " . SENDSTUDIO_TABLEPREFIX . "lists WHERE listid=" . $listid;
		$result = $this->Db->Query($query);
		if (!$result) {
			list($error, $level) = $this->Db->GetError();
			$this->Db->RollbackTransaction();
			trigger_error($error, $level);
			return false;
		}

		$this->DeleteAllSubscribers($listid, true);

		$query = "DELETE FROM " . SENDSTUDIO_TABLEPREFIX . "customfield_lists WHERE listid=" . $listid;
		$result = $this->Db->Query($query);

		$query = "DELETE FROM " . SENDSTUDIO_TABLEPREFIX . "form_lists WHERE listid=" . $listid;
		$result = $this->Db->Query($query);

		$query = "DELETE FROM " . SENDSTUDIO_TABLEPREFIX . "usergroups_access WHERE resourcetype='lists' AND resourceid=" . $listid;
		$result = $this->Db->Query($query);

		if (!class_exists('stats_api', false)) {
			require_once(dirname(__FILE__) . '/stats.php');
		}
		$stats_api = new Stats_API();

		// clean up stats
		$stats = array('0');
		$query = "SELECT statid FROM " . SENDSTUDIO_TABLEPREFIX . "stats_newsletter_lists WHERE listid=" . $listid;
		$result = $this->Db->Query($query);
		while ($row = $this->Db->Fetch($result)) {
			$stats[] = $row['statid'];
		}

		$stats_api->HideStats($stats, 'newsletter', $userid);

		$stats = array('0');

		$query = "SELECT statid FROM " . SENDSTUDIO_TABLEPREFIX . "stats_autoresponders sa, " . SENDSTUDIO_TABLEPREFIX . "autoresponders a WHERE a.autoresponderid=sa.autoresponderid AND a.listid=" . $listid;
		$result = $this->Db->Query($query);
		while ($row = $this->Db->Fetch($result)) {
			$stats[] = $row['statid'];
		}

		$stats_api->HideStats($stats, 'autoresponder', $userid);

		// autoresponder queues are cleaned up in DeleteAllSubscribers.
		// we just need to clean up the autoresponders.
		$query = "DELETE FROM " . SENDSTUDIO_TABLEPREFIX . "autoresponders WHERE listid=" . $listid;
		$result = $this->Db->Query($query);

		// clean up banned emails.
		$query = "DELETE FROM " . SENDSTUDIO_TABLEPREFIX . "banned_emails WHERE list='" . $listid . "'";
		$result = $this->Db->Query($query);

		if ($listid == $this->listid) {
			$this->listid = 0;
			$this->name = '';
			$this->ownername = '';
			$this->owneremail = '';
			$this->bounceemail = '';
			$this->replytoemail = '';
			$this->bounceserver = '';
			$this->bounceusername = '';
			$this->bouncepassword = '';
			$this->extramailsettings = '';
			$this->subscribecount = 0;
			$this->unsubscribecount = 0;
		}

		/**
		 * Clear out list cache
		 */
		if (array_key_exists('Lists_API::GetListByUserID[listCache]', $GLOBALS)) {
			unset($GLOBALS['Lists_API::GetListByUserID[listCache]']);
		}

		$this->Db->CommitTransaction();

		return true;
	}
예제 #2
0
	/**
	* Delete
	* Delete an autoresponder from the database. Also deletes the queue associated with it.
	*
	* @param Int $autoresponderid Autoresponderid of the autoresponder to delete. If not passed in, it will delete 'this' autoresponder. We delete the autoresponder, then reset all class vars.
	* @param Int $userid The user doing the deleting of the autoresponder. This is so the stats api can "hide" autoresponder stats.
	*
	* @see Stats_API::HideStats
	* @see ClearQueue
	*
	* @return Boolean True if it deleted the autoresponder, false otherwise.
	*
	*/
	function Delete($autoresponderid=0, $userid=0)
	{
		if ($autoresponderid == 0) {
			$autoresponderid = $this->autoresponderid;
		}

		$this->Load($autoresponderid);

		$query = "DELETE FROM " . SENDSTUDIO_TABLEPREFIX . "autoresponders WHERE autoresponderid='" . $autoresponderid. "'";
		$result = $this->Db->Query($query);
		if (!$result) {
			list($error, $level) = $this->Db->GetError();
			trigger_error($error, $level);
			return false;
		}

		$this->ClearQueue($this->queueid, 'autoresponder');

		$autoresponder_dir = TEMP_DIRECTORY . '/autoresponders/' . $autoresponderid;
		remove_directory($autoresponder_dir);

		$this->autoresponderid = 0;
		$this->name = '';
		$this->format = 'h';
		$this->hoursaftersubscription = 0;
		$this->queueid = 0;
		$this->archive = 0;
		$this->SetBody('text', '');
		$this->SetBody('html', '');
		$this->ownerid = 0;
		$this->autorespondersize = 0;

		$stats = array();
		$query = "SELECT statid FROM " . SENDSTUDIO_TABLEPREFIX . "stats_autoresponders WHERE autoresponderid='" . $autoresponderid . "'";
		$result = $this->Db->Query($query);
		while ($row = $this->Db->Fetch($result)) {
			$stats[] = $row['statid'];
		}

		// clean up stats
		if (!class_exists('stats_api', false)) {
			require_once(dirname(__FILE__) . '/stats.php');
		}

		$stats_api = new Stats_API();

		$stats_api->HideStats($stats, 'autoresponder', $userid);

		return true;
	}
예제 #3
0
	/**
	* Delete
	* Delete a newsletter from the database
	*
	* @param Int $newsletterid Newsletterid of the newsletter to delete. If not passed in, it will delete 'this' newsletter. We delete the newsletter, then reset all class vars.
	* @param Int $userid The user doing the deleting of the newsletter. This is passed through to the stats api to "hide" statistics rather than deleting them.
	*
	* @see Stats_API::HideStats
	*
	* @return Boolean True if it deleted the newsletter, false otherwise.
	*
	* @uses module_TrackerFactory
	* @uses module_Tracker
	* @uses module_Tracker::DeleteRecordsForAllTrackerByID()
	*/
	function Delete($newsletterid=0, $userid=0)
	{
		if ($newsletterid == 0) {
			$newsletterid = $this->newsletterid;
		}

		$newsletterid = intval($newsletterid);

		/**
		 * Status being 'true' means
		 * it's ok to delete the newsletter.
		 * If it's not true, then the delete method returns false.
		 */
		$trigger_details = array (
			'status' => true,
			'newsletterid' => $newsletterid
		);

		/**
		 * Trigger event
		 */
			$tempEventData = new EventData_IEM_NEWSLETTERSAPI_DELETE();
			$tempEventData->status = &$trigger_details['status'];
			$tempEventData->newsletterid = &$trigger_details['newsletterid'];
			$tempEventData->trigger();

			unset($tempEventData);
		/**
		 * -----
		 */

		if ($trigger_details['status'] !== true) {
			return false;
		}

		$this->Db->StartTransaction();

		/**
		 * Cleanup trackers
		 *
		 * When newsletter are deleted, delete associated tracker record too
		 *
		 * This was added here, because it's not calling the stats API to clear it's statistic
		 */
			$tempContinue = false;
			if (!class_exists('module_TrackerFactory', false)) {
				$tempFile = dirname(__FILE__) . '/module_trackerfactory.php';
				if (is_file($tempFile)) {
					require_once($tempFile);
					$tempContinue = true;
				}
			} else {
				$tempContinue = true;
			}

			if ($tempContinue) {
				module_Tracker::DeleteRecordForAllTrackerByNewsletterID($newsletterid);
			}
		/**
		 * -----
		 */

		$query = "DELETE FROM " . SENDSTUDIO_TABLEPREFIX . "newsletters WHERE newsletterid=" . $newsletterid;
		$result = $this->Db->Query($query);
		if (!$result) {
			$this->Db->RollbackTransaction();
			list($error, $level) = $this->Db->GetError();
			trigger_error($error, $level);
			return false;
		}

		$newsletter_dir = TEMP_DIRECTORY . '/newsletters/' . $newsletterid;
		remove_directory($newsletter_dir);

		$this->newsletterid = 0;
		$this->name = '';
		$this->format = 'h';
		$this->active = 0;
		$this->archive = 0;
		$this->SetBody('text', '');
		$this->SetBody('html', '');
		$this->ownerid = 0;

		$stats = array();
		$query = "SELECT statid FROM " . SENDSTUDIO_TABLEPREFIX . "stats_newsletters WHERE newsletterid=" . $newsletterid;
		$result = $this->Db->Query($query);
		if (!$result) {
			$this->Db->RollbackTransaction();
			list($error, $level) = $this->Db->GetError();
			trigger_error($error, $level);
			return false;
		}

		while ($row = $this->Db->Fetch($result)) {
			$stats[] = $row['statid'];
		}

		// clean up stats
		if (!class_exists('stats_api', false)) {
			require_once(dirname(__FILE__) . '/stats.php');
		}

		$stats_api = new Stats_API();

		$stats_api->HideStats($stats, 'newsletter', $userid);

		$this->Db->CommitTransaction();

		return true;
	}