/**
  * Show_Send_Step_30
  * This shows a summary report of the split test campaign
  * after a user has paused the campaign
  * and they want to resume sending it
  *
  * It shows:
  * - which lists/segments it will be sent to
  * - the split test name
  * - which campaigns it will send
  *
  * and a "resume" button.
  *
  * If cron is enabled, then it will mark the job as "waiting" to send again in the database,
  * set a flash message and redirect the user back to the "manage split tests" page.
  *
  * @uses GetApi
  * @uses Splittest_API::Load
  * @uses Jobs_API::LoadJob
  * @uses CheckCronEnabled
  * @uses Splittest_Send_API::ResumeJob
  */
 public function Show_Send_Step_30()
 {
     $splitid = 0;
     if (isset($_GET['id'])) {
         $splitid = (int) $_GET['id'];
     }
     $api = $this->GetApi();
     $split_campaign_details = $api->Load($splitid);
     if (empty($split_campaign_details)) {
         FlashMessage(GetLang('Addon_splittest_Send_InvalidSplitTest'), SS_FLASH_MSG_ERROR, $this->admin_url);
         return;
     }
     $jobid = 0;
     if (isset($split_campaign_details['jobid'])) {
         $jobid = (int) $split_campaign_details['jobid'];
     }
     require_once SENDSTUDIO_API_DIRECTORY . '/jobs.php';
     $jobApi = new Jobs_API();
     $job = $jobApi->LoadJob($jobid);
     if (empty($job)) {
         FlashMessage(GetLang('Addon_splittest_Send_InvalidSplitTest'), SS_FLASH_MSG_ERROR, $this->admin_url);
         return;
     }
     /**
      * If we're sending via cron,
      * then mark the job as "waiting" to send again
      * and then show an appropriate message.
      */
     if (self::CheckCronEnabled()) {
         $send_api = $this->GetApi('SplitTest_Send');
         $resumed = $send_api->ResumeJob($jobid, $splitid);
         if ($resumed) {
             FlashMessage(GetLang('Addon_splittest_Send_Resumed_Success'), SS_FLASH_MSG_SUCCESS, $this->admin_url);
         } else {
             FlashMessage(GetLang('Addon_splittest_Send_Resumed_Failure'), SS_FLASH_MSG_ERROR, $this->admin_url);
         }
         return;
     }
     $sendingCampaigns = array();
     $send_details['newsletters'] = array();
     foreach ($split_campaign_details['splittest_campaigns'] as $campaignid => $campaignname) {
         $sendingCampaigns[$campaignid] = htmlspecialchars($campaignname, ENT_QUOTES, SENDSTUDIO_CHARSET);
         $send_details['newsletters'][] = $campaignid;
     }
     $send_list = array();
     switch ($job['jobdetails']['sendingto']['sendtype']) {
         case 'list':
             require_once SENDSTUDIO_API_DIRECTORY . '/lists.php';
             $list_api = new Lists_API();
             foreach ($job['jobdetails']['sendingto']['sendids'] as $listid) {
                 $list_api->Load($listid);
                 $send_list[] = htmlspecialchars($list_api->Get('name'), ENT_QUOTES, SENDSTUDIO_CHARSET);
             }
             $this->template_system->Assign('SendingToLists', true);
             break;
         case 'segment':
             require_once SENDSTUDIO_API_DIRECTORY . '/segment.php';
             $segment_api = new Segment_API();
             foreach ($job['jobdetails']['sendingto']['sendids'] as $segmentid) {
                 $segment_api->Load($segmentid);
                 $send_list[] = htmlspecialchars($segment_api->Get('segmentname'), ENT_QUOTES, SENDSTUDIO_CHARSET);
             }
             $this->template_system->Assign('SendingToSegments', true);
             break;
     }
     /**
      * Set everything in the session ready to go.
      */
     $job['jobdetails']['Job'] = $job['jobid'];
     IEM::sessionSet('SplitTestSendDetails', $job['jobdetails']);
     /**
      * Work out how many more emails there are to send.
      */
     $send_size = $job['jobdetails']['sendinfo']['sendsize_left'];
     if ($send_size == 1) {
         $send_size_msg = GetLang('Addon_splittest_Send_Step3_Size_One');
     } else {
         $send_size_msg = sprintf(GetLang('Addon_splittest_Send_Step3_Size_Many'), $this->PrintNumber($send_size));
     }
     $this->template_system->Assign('SendingToNumberOfContacts', $send_size_msg);
     $this->template_system->Assign('sendingCampaigns', $sendingCampaigns);
     $this->template_system->Assign('sendLists', $send_list);
     $this->template_system->Assign('AdminUrl', $this->admin_url, false);
     $this->template_system->ParseTemplate('send_step3');
 }
	/**
	 * FetchSubscribersFromSegment
	 * Returns all subscriber information based on "Segment" descriptor
	 *
	 * @param Int $pageid Which 'page' of results to return. Used with perpage it handles paging of results.
	 * @param Mixed $perpage How many results to return (int or 'all').
	 * @param Mixed $segments Segment ID(s) of which subscribers are going to be fetched (Integer|Array)
	 * @param Array $sortdetails How to sort the resulting subscriber information (OPTIONAL)
	 * @param String $searchemail Search for this particular email within the segment
	 *
	 * @return Array Returns an empty array if there is no search info or no subscribers found. Otherwise returns subscriber info based on the criteria.
	 *
	 * @uses Segment_API::GetSearchInfo()
	 * @uses Segment_API::ReplaceLists()
	 * @uses Segment_API::ReplaceRules()
	 * @uses Segment_API::AppendRule()
	 * @uses Segment_API::GetSubscribersQueryString()
	 * @uses Segment_API::GetSubscribersCount()
	 * @uses Db::AddLimit()
	 * @uses Db::Query()
	 * @uses Db::Fetch()
	 */
	function FetchSubscribersFromSegment($pageid=1, $perpage=20, $segments, $sortdetails=array(), $searchemail = null)
	{
		if ($pageid < 1) {
			$pageid = 1;
		}

		if ($perpage <= 0 && $perpage != 'all') {
			$perpage = 20;
		}

		if (empty($sortdetails)) {
			$sortdetails = array('SortBy' => 'emailaddress', 'Direction' => 'asc');
		}

		require_once(dirname(__FILE__) . '/segment.php');

		$return = array('count' => 0, 'subscriberlist' => array());
		$segmentAPI = new Segment_API();

		/**
		 * Construct new segment if more than one segment ID is parsed in,
		 * otherwise, load segment ID into the API
		 */
		if (is_array($segments)) {
			$segmentInfo = $segmentAPI->GetSearchInfo($segments);
			if ($segmentInfo === false) {
				trigger_error('Cannot get segment search info', E_USER_WARNING);
				return array();
			}

			$status = $segmentAPI->ReplaceLists($segmentInfo['Lists']);
			if ($status === false) {
				trigger_error('Cannot replace segment lists', E_USER_WARNING);
				return array();
			}

			$status = $segmentAPI->ReplaceRules($segmentInfo['Rules']);
			if ($status === false) {
				trigger_error('Cannot replace segment rules', E_USER_WARNING);
				return array();
			}
		} else {
			$segments = intval($segments);
			if ($segments == 0) {
				trigger_error('Invalid Segment ID was passed in', E_USER_WARNING);
				return array();
			}

			$status = $segmentAPI->Load($segments);
			if (!$status) {
				trigger_error('Cannot load Segment', E_USER_WARNING);
				return array();
			}
		}

		if (!is_null($searchemail)) {
			$status = $segmentAPI->AppendRule('AND', array('ruleName' => 'email', 'ruleOperator' => 'like', 'ruleValues' => array($searchemail)));
			if ($status === false) {
				return array();
			}
		}

		$return['count'] = $segmentAPI->GetSubscribersCount();

		$selectQuery = $segmentAPI->GetSubscribersQueryString();

		/**
		 * Add in sort details
		 */
		$selectQuery .= ' ORDER BY ';

		if (strtolower($sortdetails['SortBy']) == 'sd.data') {
			$selectQuery = preg_replace(	'/^(SELECT .*? FROM ' . SENDSTUDIO_TABLEPREFIX . 'list_subscribers AS subscribers)(.*)/i',
			('$1 LEFT JOIN ' . SENDSTUDIO_TABLEPREFIX . 'subscribers_data AS subscriberdata'
			. ' ON subscribers.subscriberid = subscriberdata.subscriberid AND subscriberdata.fieldid=' . intval($sortdetails['CustomFields'][0]) . ' $2'),
			$selectQuery);

			$selectQuery .= 'subscriberdata.data';

		} elseif (strtolower($sortdetails['SortBy']) == 'status') {
			$selectQuery .= 'CASE WHEN (bounced=0 AND unsubscribed=0) THEN 1 WHEN (unsubscribed > 0) THEN 2 WHEN (bounced > 0) THEN 3 END';

		} else {
			$selectQuery .= $sortdetails['SortBy'];
		}
		$selectQuery .= (strtolower($sortdetails['Direction']) == 'asc') ? ' asc ' : ' desc ';
		$selectQuery .= (strtolower($sortdetails['SortBy']) != 'emailaddress') ? ', emailaddress' : '';
		/**
		 * -----
		 */

		// Add pagination
		if ($perpage != 'all') {
			$selectQuery .= $this->Db->AddLimit((($pageid - 1) * $perpage), $perpage);
		}

		/**
		 * Get subscriber records
		 */
		$tempRecords = array();
		$result = $this->Db->Query($selectQuery);
		while ($row = $this->Db->Fetch($result)) {
			array_push($tempRecords, $row);
		}

		$return['subscriberlist'] = $tempRecords;
		/**
		 * -----
		 */

		return $return;
	}
	/**
	 * _GetSearchInfo
	 * Get search info for segment.
	 *
	 * @param Mixed $segments IDs of the segments (Integer|Array)
	 * @return Mixed Returns an array of list id used by segment, FALSE otherwise
	 *
	 * @access private
	 */
	function _GetSearchInfo($segments)
	{
		if (!is_array($segments)) {
			$segments = array($segments);
		}

		$lists = array();
		$rules = array();
		$api = new Segment_API();
		foreach ($segments as $id) {
			$status = $api->Load(intval($id));
			if ($status === false) {
				return false;
			}

			$temp = $api->GetMailingListUsed();
			if (is_array($temp) && !is_null($temp)) {
				$lists = array_merge($lists, $temp);
			}

			$temp = $api->GetRules();
			if (is_array($temp) && !is_null($temp)) {
				$temp = array('type' => 'group', 'connector' => 'or', 'rules' => $temp);
				$rules = array_merge($rules, array($temp));
			}
		}
		unset($api);

		return array('Lists' => $lists, 'Rules' => $rules);
	}
Exemple #4
0
    /**
     * GetSegmentList
     * Gets a list of segments that this user owns / has access to.
     * If this user is an admin or list admin user, returns everything.
     *
     * The returned array will contains associated array,
     * whereby the array index is the segment id
     *
     * @param Int $userid Userid to check segments for. If it's not supplied, it checks whether this user is an admin or list admin. If they aren't, only returns segments this user owns / has access to.
     *
     * @uses Segment_API::GetSegmentByUserID()
     *
     * @return Array Returns an array - list of segments this user has created (or if the user is an admin/listadmin, returns everything).
     */
    function GetSegmentList($userid=0) {
        if (!$userid) {
            $userid = $this->userid;
        }

        require_once(dirname(__FILE__) . '/segment.php');

        if ($this->SegmentAdmin() || $this->SegmentAdminType() == 'a') {
            $userid = null;
        }

        $segment_api = new Segment_API();
        return $segment_api->GetSegmentByUserID($userid, array(), false, 0, 'all');
    }