Beispiel #1
0
		/**
		 * DO_CheckNewsletterAvailable
		 * Data Object Method: Check whether or not newsletter record exists
		 * Method should only be called by DataObject class
		 * If the newsletter can be loaded, this returns true. Otherwise it returns false.
		 *
		 * @param Int $newsletterID The newsletter id to check for.
		 *
		 * @uses Newsletters_API
		 * @uses Newsletters_API::Load()
		 *
		 * @return Boolean Returns TRUE if exists, FALSE otherwise
		 */
		function DO_CheckNewsletterAvailable($newsletterID)
		{
			if (is_null($this->_cachedNewsletterAPI)) {
				require_once(SENDSTUDIO_API_DIRECTORY . '/newsletters.php');

				$this->_cachedNewsletterAPI = new Newsletters_API();
			}

			$status = $this->_cachedNewsletterAPI->Load($newsletterID);

			// It should only return boolean AND NOTHING ELSE
			if ($status == false) {
				return false;
			}

			return true;
		}
Beispiel #2
0
 /**
  * CampaignSent
  * Logs an event when a user is sent a campaign
  *
  * @uses Subscriber_API::AddEvent
  *
  * @return Void Returns nothing
  */
 public static function CampaignSent($eventdata)
 {
     if (!($me = self::LoadSelf())) {
         return;
     }
     if ($eventdata->emailsent) {
         $newsletterapi = new Newsletters_API();
         $newsletter = $newsletterapi->Load($eventdata->jobdetails['Newsletter']);
         $subscribersapi = new Subscribers_API();
         $event = array('type' => GetLang('Addon_emaileventlog_email'), 'eventdate' => $subscribersapi->GetServerTime(), 'subject' => sprintf(GetLang('Addon_emaileventlog_sent_campaign_subject'), htmlspecialchars($newsletterapi->Get('name'), ENT_QUOTES, SENDSTUDIO_CHARSET)), 'notes' => GetLang('Addon_emaileventlog_sent_campaign'));
         $subscribersapi->AddEvent($eventdata->subscriberinfo['subscriberid'], $eventdata->subscriberinfo['listid'], $event);
     }
 }
Beispiel #3
0
	/**
	 * _validateRecord
	 * Validate records
	 *
	 * Check whether or not specified resources exists
	 *
	 * @param Array $record Associated array of the trigger record
	 * @param Array $data Associated array of trigger record data
	 * @param Array $actions Associated array of trigger actions data
	 *
	 * @return Boolean Returns TRUE if everything is verified, FALSE otherwise
	 */
	private function _validateRecord($record, $data, $actions)
	{
		$actions_specified = array();

		// The follwing are needed for each trigger type
		switch ($record['triggertype']) {
			case 'f':
				// listid and customfieldid needs to be populated
				if (!isset($data['listid']) || empty($data['listid']) || !isset($data['customfieldid']) || empty($data['customfieldid'])) {
					trigger_error('listid and customfieldid data must be sepecified', E_USER_NOTICE);
					return false;
				}

				require_once(dirname(__FILE__) . '/lists.php');
				$listapi = new Lists_API();

				$customfields = $listapi->GetCustomFields($data['listid']);
				if (!array_key_exists($data['customfieldid'], $customfields)) {
					trigger_error('Custom field is not available', E_USER_NOTICE);
					return false;
				}
			break;

			case 'l':
				// linkid_newsletterid and linkid must be populated
				if (!isset($data['linkid_newsletterid']) || empty($data['linkid_newsletterid']) || !isset($data['linkid']) || empty($data['linkid'])) {
					trigger_error('linkid_newsletterid and linkid data must be specified', E_USER_NOTICE);
					return false;
				}

				require_once(dirname(__FILE__) . '/newsletters.php');
				$newsletterapi = new Newsletters_API();

				$links = $newsletterapi->GetLinks($data['linkid_newsletterid']);
				if (!array_key_exists($data['linkid'], $links)) {
					trigger_error('Links does not exists', E_USER_NOTICE);
					return false;
				}
			break;

			case 'n':
				// newsletterid must be populated
				if (!isset($data['newsletterid']) || empty($data['newsletterid'])) {
					trigger_error('newsletterid data must be sepecified', E_USER_NOTICE);
					return false;
				}

				require_once(dirname(__FILE__) . '/newsletters.php');
				$newsletterapi = new Newsletters_API();

				if (!is_array($newsletterapi->GetRecordByID($data['newsletterid']))) {
					trigger_error('Newsletter does not exits', E_USER_NOTICE);
					return false;
				}
			break;

			case 's':
				// staticdate must be populated
				if (!isset($data['staticdate']) || empty($data['staticdate'])) {
					trigger_error('staticdate data must be sepecified', E_USER_NOTICE);
					return false;
				}

				list($year, $month, $day) = explode('-', $data['staticdate']);
				$tempTime = mktime(0, 0, 0, $month, $day, $year);
				if (!$tempTime || $tempTime == -1) {
					trigger_error('Invalid date specified', E_USER_NOTICE);
					return false;
				}

				if (!isset($data['staticdate_listids']) || empty($data['staticdate_listids'])) {
					trigger_error('staticdate must be assigned to a specific list', E_USER_NOTICE);
					return false;
				}

				if (!is_array($data['staticdate_listids'])) {
					$data['staticdate_listids'] = array($data['staticdate_listids']);
				}

				require_once(dirname(__FILE__) . '/lists.php');
				$listapi = new Lists_API();
				$count = $listapi->GetLists($data['staticdate_listids'], array(), true);
				if (!$count || count($data['staticdate_listids']) != $count) {
					trigger_error('Some (or All) the contact list assigned to this record is not available', E_USER_NOTICE);
					return false;
				}
			break;

			default:
				trigger_error('Unknown trigger type', E_USER_NOTICE);
				return false;
			break;
		}

		// ----- The following are required for "send" action
			if (isset($actions['send']) && isset($actions['send']['enabled']) && $actions['send']['enabled']) {
				$temp = array('newsletterid', 'sendfromname', 'sendfromemail', 'replyemail', 'bounceemail');
				foreach ($temp as $each) {
					if (!isset($actions['send'][$each])) {
						trigger_error('Required parameter for send actions are not passed in', E_USER_NOTICE);
						return false;
					}
				}

				// Check if newsletterid is available
				require_once(dirname(__FILE__) . '/newsletters.php');
				$newsletterapi = new Newsletters_API();

				if (!is_array($newsletterapi->GetRecordByID($actions['send']['newsletterid']))) {
					trigger_error('Newsletter does not exits', E_USER_NOTICE);
					return false;
				}

				array_push($actions_specified, 'send');
			}
		// -----

		// ----- The following are required for "addlist" action
			if (isset($actions['addlist']) && isset($actions['addlist']['enabled']) && $actions['addlist']['enabled']) {
				if (!isset($actions['addlist']['listid']) || empty($actions['addlist']['listid'])) {
					trigger_error('Required parameter for "addlist" actions are not passed in', E_USER_NOTICE);
					return false;
				}

				if (!is_array($actions['addlist']['listid'])) {
					$actions['addlist']['listid'] = array($actions['addlist']['listid']);
				}

				// Check if selected lists are available
				require_once(dirname(__FILE__) . '/lists.php');
				$listapi = new Lists_API();
				$count = $listapi->GetLists($actions['addlist']['listid'], array(), true);
				if (!$count || count($actions['addlist']['listid']) != $count) {
					trigger_error('Some (or All) the contact list assigned to this record is not available', E_USER_NOTICE);
					return false;
				}

				array_push($actions_specified, 'addlist');
			}
		// -----

		// ----- The following are required for "removelist" action
			if (isset($actions['removelist']) && isset($actions['removelist']['enabled']) && $actions['removelist']['enabled']) {
				// removelist action does not need anything, but we will need to add it to the "actions_specified" array
				array_push($actions_specified, 'removelist');
			}
		// -----

		// At least one action needs to be specified:
		if (empty($actions_specified)) {
			trigger_error('At least one trigger actions need to be specified', E_USER_NOTICE);
			return false;
		}

		return true;
	}
Beispiel #4
0
 /**
  * _ShowForm
  * This is a private function that both creating a split test and editing a split test uses.
  * If an id is passed through (ie when editing), it will fill in the relevant details in the form for processing.
  * Based on whether an id is passed through and whether a test is successfully loaded, it will also change the form action.
  *
  * It uses the newsletters api to get the newsletters/email campaigns the user has access to so they are shown in the dropdown list.
  * It only shows "live" (active) newsletters the user has access to.
  * If the user creating/editing a split test is an admin user, then all live newsletters are shown.
  * If they are not an admin user, then only the live newsletters the user created are shown.
  *
  * @param Int $splitid The split test id to load for editing if applicable. If none is supplied, then we assume you're creating a new split test.
  * @param Array $chosen_campaigns A list of campaign ids to select by default when displaying the form. This will be overridden if $splitid is provided.
  *
  * @uses GetUser
  * @uses Newsletters_API::GetNewsletters
  * @uses GetApi
  *
  * @return Void Just prints out the form. It does not return anything.
  */
 private function _ShowForm($splitid = null, $chosen_campaigns = array())
 {
     $user = GetUser();
     $admin_url = $this->admin_url;
     $action = $this->_getGETRequest('Action', null);
     $show_send = true;
     if (!empty($chosen_campaigns)) {
         $chosen_campaigns = array_map('intval', $chosen_campaigns);
         foreach ($chosen_campaigns as $k => $v) {
             unset($chosen_campaigns[$k]);
             $chosen_campaigns[$v] = $v;
         }
     }
     $formtype = 'create';
     $splittype = 'distributed';
     $percentage_percentage = self::percentage_default;
     $splitHoursAfter = self::percentage_hoursafter_default;
     $weight_openrate = self::weight_openrate_default;
     $weight_linkclick = self::weight_linkclick_default;
     $this->template_system->Assign('Percentage_Minimum', self::percentage_minimum);
     $this->template_system->Assign('Percentage_Maximum', self::percentage_maximum);
     $this->template_system->Assign('Percentage_HoursAfter_Minimum', self::percentage_hoursafter_minimum);
     $this->template_system->Assign('Percentage_HoursAfter_Maximum', self::percentage_hoursafter_maximum);
     $this->template_system->Assign('Percentage_HoursAfter_Maximum_Days', floor(self::percentage_hoursafter_maximum / 24));
     $this->template_system->Assign('splitHoursAfter_TimeRange', 'hours');
     if ($splitid !== null) {
         $splitid = (int) $splitid;
         if ($splitid <= 0) {
             FlashMessage(GetLang('Addon_splittest_UnableToLoadSplitTest'), SS_FLASH_MSG_ERROR, $this->admin_url);
             return;
         }
         $split_api = $this->GetApi();
         $split_details = $split_api->Load($splitid);
         if (empty($split_details)) {
             FlashMessage(GetLang('Addon_splittest_UnableToLoadSplitTest'), SS_FLASH_MSG_ERROR, $this->admin_url);
             return;
         }
         if (!isset($split_details['splitid'])) {
             FlashMessage(GetLang('Addon_splittest_UnableToLoadSplitTest'), SS_FLASH_MSG_ERROR, $this->admin_url);
             return;
         }
         $jobstatus = $split_details['jobstatus'];
         if (in_array($jobstatus, $split_api->GetSendingJobStatusCodes())) {
             FlashMessage(GetLang('Addon_splittest_UnableToEdit_SendInProgress'), SS_FLASH_MSG_ERROR, $this->admin_url);
             return;
         }
         $formtype = 'edit';
         $this->template_system->Assign('splitid', $splitid);
         $this->template_system->Assign('splitname', htmlspecialchars($split_details['splitname'], ENT_QUOTES, SENDSTUDIO_CHARSET));
         $chosen_campaigns = $split_details['splittest_campaigns'];
         $splittype = $split_details['splittype'];
         $show_send = empty($split_details['jobstatus']) || $split_details['jobstatus'] == 'c';
         if ($splittype == 'percentage') {
             $splitHoursAfter = (double) $split_details['splitdetails']['hoursafter'];
             if ($splitHoursAfter % 24 == 0) {
                 $splitHoursAfter = $splitHoursAfter / 24;
                 $this->template_system->Assign('splitHoursAfter_TimeRange', 'days');
             }
             $percentage_percentage = $split_details['splitdetails']['percentage'];
         }
         $weight_openrate = $split_details['splitdetails']['weights']['openrate'];
         $weight_linkclick = $split_details['splitdetails']['weights']['linkclick'];
     }
     $this->template_system->Assign('FormType', $formtype);
     $this->template_system->Assign('TemplateUrl', $this->template_url, false);
     $this->template_system->Assign('BaseAdminUrl', $this->admin_url, false);
     $this->template_system->Assign('AdminUrl', $admin_url, false);
     $this->template_system->Assign('ShowSend', $show_send);
     $flash_messages = GetFlashMessages();
     $this->template_system->Assign('FlashMessages', $flash_messages, false);
     require_once SENDSTUDIO_API_DIRECTORY . '/newsletters.php';
     $news_api = new Newsletters_API();
     $owner = $user->Get('userid');
     if ($user->Admin()) {
         $owner = 0;
     }
     $campaigns = $news_api->GetLiveNewsletters($owner);
     if (!empty($chosen_campaigns)) {
         foreach ($campaigns as $row => $details) {
             $id = $details['newsletterid'];
             $campaigns[$row]['selected'] = false;
             if (isset($chosen_campaigns[$id])) {
                 $campaigns[$row]['selected'] = true;
             }
         }
     }
     $this->template_system->Assign('splitHoursAfter', $splitHoursAfter);
     $this->template_system->Assign('splitType', $splittype);
     $this->template_system->Assign('action', $action);
     $this->template_system->Assign('percentage_percentage', $percentage_percentage);
     $this->template_system->Assign('weight_openrate', $weight_openrate);
     $this->template_system->Assign('weight_linkclick', $weight_linkclick);
     $this->template_system->Assign('campaigncounter', sizeof($chosen_campaigns));
     $this->template_system->Assign('campaigns', $campaigns);
     $this->template_system->ParseTemplate('splittest_form');
 }