/** * _getCustomFieldUsedByList * This function get a list of custom fields by list * * @param array $listIDs An array of list where its custom fields to be retrieved * * @return array A list of custom fields used by the lists. */ function _getCustomFieldUsedByList($listIDs) { require_once SENDSTUDIO_API_DIRECTORY . '/lists.php'; $cacheid = implode(':', $listIDs); if (!array_key_exists($cacheid, $this->_cacheCustomFieldsUsedByLists)) { $listapi = new Lists_API(); $tempOutput = array('list' => array(), 'customfields' => array(), 'values' => array()); foreach ($listIDs as $tempID) { $tempStatus = $listapi->GetCustomFields($tempID); if (!array_key_exists($tempID, $tempOutput['list'])) { $tempOutput['list'][$tempID] = array(); } foreach ($tempStatus as $tempEach) { array_push($tempOutput['list'][$tempID], $tempEach['fieldid']); /** * Get list of custom fields */ if (!array_key_exists($tempEach['fieldid'], $tempOutput['customfields'])) { $tempFieldType = 'text'; switch ($tempEach['fieldtype']) { case 'date': $tempFieldType = 'date'; break; case 'number': $tempFieldType = 'number'; break; case 'checkbox': $tempFieldType = 'multiple'; break; case 'radiobutton': case 'dropdown': $tempFieldType = 'dropdown'; break; } $tempOutput['customfields'][$tempEach['fieldid']] = array('name' => htmlspecialchars($tempEach['name'], ENT_QUOTES, SENDSTUDIO_CHARSET), 'fieldtype' => $tempEach['fieldtype'], 'defaultvalue' => $tempEach['defaultvalue'], 'operatortype' => $tempFieldType); } /** * ----- */ /** * Get list of values the custom field uses */ if (!array_key_exists($tempEach['fieldid'], $tempOutput['values'])) { $tempFieldValues = array(); $temp = unserialize($tempEach['fieldsettings']); if (is_array($temp) && array_key_exists('Key', $temp) && array_key_exists('Value', $temp)) { foreach ($temp['Key'] as $index => $value) { array_push($tempFieldValues, array('value' => $value, 'text' => htmlspecialchars($temp['Value'][$index], ENT_QUOTES, SENDSTUDIO_CHARSET))); } } if (count($tempFieldValues) != 0) { $tempOutput['values'][$tempEach['fieldid']] = $tempFieldValues; } } } } if (count($tempOutput['list']) == 0) { $tempOutput['list'] = null; } if (count($tempOutput['customfields']) == 0) { $tempOutput['customfields'] = null; } if (count($tempOutput['values']) == 0) { $tempOutput['values'] = null; } $this->_cacheCustomFieldsUsedByLists[$cacheid] = $tempOutput; } return $this->_cacheCustomFieldsUsedByLists[$cacheid]; }
/** * _ProcessJob_RemoveList * Add subscriber to another list(s) * * This function will return an associative array with the following value: * - error => Boolean => Indicates whether or not the function is successful * - halt => Boolean => Indicates whether or not to halt the operation * * @param Array $queue Queue record * @param Array $trigger Trigger record * @param Integer $subscriberid Subscriber ID to be copied to another list * @return Array Returns an array of the status (see comment above) */ private function _ProcessJob_AddList($queueid, $trigger, $subscriberid) { $return = array( 'error' => true, 'halt' => false ); $subscriberapi = new Subscribers_API(); $listapi = new Lists_API(); $subscriber_record = $subscriberapi->LoadSubscriberList($subscriberid); if(empty($subscriber_record)){ trigger_error("Cannot check database for particular subscriber ({$subscriberid})"); $this->_log("Cannot check database for particular subscriber ({$subscriberid})"); $return['halt'] = true; $return['error'] = true; return $return; } $subscriber_customfields = (isset($subscriber_record['CustomFields']) && is_array($subscriber_record['CustomFields'])) ? $subscriber_record['CustomFields'] : array(); $lists = $trigger['triggeractions']['addlist']['listid']; if (!is_array($lists)) { $lists = array($lists); } $this->Db->StartTransaction(); foreach ($lists as $list) { if ($list == $subscriber_record['listid']) { continue; } $duplicate = $subscriberapi->IsSubscriberOnList($subscriber_record['emailaddress'], $list); if ($duplicate) { $unsubscribed_check = $subscriberapi->IsUnSubscriber(false, $list, $duplicate); if ($unsubscribed_check) { $this->_log('Cannot add contact to this list: Is already in the list as unsubscriber'); } else { $this->_log('Cannot add contact to this list: Is already in the list'); } continue; } list($banned, $msg) = $subscriberapi->IsBannedSubscriber($subscriber_record['emailaddress'], $list, false); if ($banned) { $this->_log('Cannot add contact to this list: Email is banned to be added to the list'); continue; } // ----- Save subscriber and custom fields $this->Db->StartTransaction(); $subscriberapi->confirmcode = false; $subscriberapi->confirmed = $subscriber_record['confirmed']; $subscriberapi->confirmdate = 0; $subscriberid = $subscriberapi->AddToList($subscriber_record['emailaddress'], $list); if (!$subscriberid) { $this->Db->RollbackTransaction(); $this->_log('Cannot add contact to this list: API returned FALSE value'); continue; } $ListCustomFields = $listapi->GetCustomFields($list); $allfieldok = true; if (!empty($ListCustomFields)) { $transferred = array(); if (!empty($subscriber_customfields)) { // Match custom field foreach ($subscriber_customfields as $field) { // Found an exact match if (array_key_exists($field['fieldid'], $lists)) { $subscriberapi->SaveSubscriberCustomField($subscriberid, $field['fieldid'], $field['data']); $transferred[] = $field['fieldid']; continue; } // Check if there are any "name" and "type" match foreach ($ListCustomFields as $fieldid => $listfield) { if ((strtolower($listfield['name']) == strtolower($field['fieldname'])) && ($listfield['fieldtype'] == $field['fieldtype'])) { $subscriberapi->SaveSubscriberCustomField($subscriberid, $fieldid, $field['data']); $transferred[] = $field['fieldid']; continue; } } } } // Check if list required fields are all added in $allfieldok = true; foreach ($ListCustomFields as $fieldid => $field) { if ($field['required'] && !in_array($fieldid, $transferred)) { $allfieldok = false; break; } } } if ($allfieldok) { $this->Db->CommitTransaction(); } else { $this->_log('Cannot add contact to this list: Not all of the required custom fields are available to copied across'); $this->Db->RollbackTransaction(); continue; } // ----- } $this->Db->CommitTransaction(); // Record log if (!$this->RecordLogActions($trigger['triggeremailsid'], $subscriberid, 'addlist')) { $this->_log('Cannot write log to the database...'); } $return['error'] = false; return $return; }
/** * 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'); }
/** * GenerateQueryFromSegmentRules * Generate query string from segemnt record * * Successful return array wil have the following structure: * - selectQuery => Query to select the subscribers described by the rules * - countQuery => Query to count the subscribers described by the rules * * @param Array $listIDs An array of list IDs to be queried for * @param Array $rules An array of segment rules * * @return Mixed Returns an array of SQL statement (Please see description above) (Array|FALSE) * * @uses Subscribers_API::_GenerateSegmentRuleQuery() * @uses Subscribers_API::$_cacheCustomfields */ function GenerateQueryFromSegmentRules($listIDs, $rules) { $listIDs = $this->CheckIntVars($listIDs); $tables = array( 'subscribers' => SENDSTUDIO_TABLEPREFIX . 'list_subscribers AS subscribers', ); $joins = array(); $conditions = array( 'subscribers.listid IN (' . implode(', ', $listIDs) . ')', ); $columns = array( 'subscribers.subscriberid AS subscriberid', ', subscribers.emailaddress AS emailaddress', ', subscribers.subscribedate AS subscribedate', ', subscribers.format AS format', ', subscribers.unsubscribed AS unsubscribed', ', subscribers.bounced AS bounced', ', subscribers.confirmed AS confirmed', ', subscribers.listid AS listid' ); // Adding list names, as it is always going to be required $tables['lists'] = ''; $tables['subscribers'] .= ' JOIN ' . SENDSTUDIO_TABLEPREFIX . 'lists AS lists' . ' ON lists.listid = subscribers.listid' . ' AND lists.listid IN (' . implode(', ', $listIDs) . ')'; array_push($columns, ', lists.name AS listname'); // Get custom fields cache used by this segment if (is_null($this->_cacheCustomfields)) { require_once(dirname(__FILE__) . '/lists.php'); $listAPI = new Lists_API(); $temp = $listAPI->GetCustomFields($listIDs); $this->_cacheCustomfields = array(); if (is_array($temp)) { foreach ($temp as $each) { $this->_cacheCustomfields[$each['fieldid']] = $each['fieldtype']; } } } $status = $this->_GenerateSegmentRuleQuery($rules, 'AND', $tables, $joins, $conditions, $listIDs); if ($status === false) { return false; } $tempQuery = ' FROM ' . implode(' ', $tables) . ' WHERE ' . (count($joins) > 0? implode(' AND ', $joins) . ' AND ' : '') . implode(' ', $conditions); return array( 'selectQuery' => 'SELECT DISTINCT ' . implode(' ', $columns) . $tempQuery, 'countQuery' => 'SELECT COUNT(DISTINCT subscribers.subscriberid) AS count' . $tempQuery); }
/** * GetLists * Gets a list of lists that this user owns / has access to. * If this user is an admin or list admin user, returns everything. * * The function will delegate it's database query to Lists API. * This is because we need to cache the lists result to reduce the number of redundant queries * that resulted by this function gets called multiple times within a request. * * @param Int $userid Userid to check lists for. If it's not supplied, it checks whether this user is an admin or list admin. If they aren't, only returns lists this user owns / has access to. * @param Boolean $getUnconfirmedCount Get unconfirmed count along with the query (OPTIONAL) * * @see ListAdmin * @uses Lists_API::GetListByUserID() * * @return Array Returns an array - list of listid's this user has created (or if the user is an admin/listadmin, returns everything). */ function GetLists($userid = 0, $getUnconfirmedCount = false) { if (!$userid && !$this->userid) { trigger_error('This user object is not loaded with any user.... You will need to supply the userid as a parameter.', E_USER_NOTICE); return false; } if (!$userid) { $userid = $this->userid; } // If user is a "System Admin" or a "List Admin", allow to access all lists if ($userid == $this->userid) { if ($this->ListAdmin() || $this->listadmintype == 'a') { $userid = 0; } } require_once(dirname(__FILE__) . '/lists.php'); $listapi = new Lists_API(); return $listapi->GetListByUserID($userid, $getUnconfirmedCount); }
/** * GetHTML * Gets the html for the particular form type and form design that is loaded. * This will also load up custom fields, put them into the form, add format choice dropdown (if applicable) and finally return the form html for displaying or putting on a website. * If it's a modify details form, then there are placeholders put into the form so the calling object/method can pre-fill the form as necessary. * * @param Boolean $inside_sendstudio Pass in whether we are viewing the form from inside the application or not. This allows us to include/exclude information accordingly. This stops a problem where viewing a form will log you out of the admin control panel. * * @see GetFormDesign * @see FetchFile * @see formtype * @see chooseformat * @see changeformat * @see lists * @see customfields * * @return String Returns the form's html content. */ function GetHTML($inside_sendstudio=false) { /** * This file lets us get api's, load language files and parse templates. */ if (!class_exists('sendstudio_functions', false)) { require_once(SENDSTUDIO_FUNCTION_DIRECTORY . '/sendstudio_functions.php'); } $sendstudio_functions = new Sendstudio_Functions(); $sendstudio_functions->LoadLanguageFile('frontend'); $sendstudio_functions->LoadLanguageFile('forms'); $content = $this->GetFormDesign($this->design, $this->formtype, true); $displayoption = $this->FetchFile($this->design, $this->formtype, '_options'); $requiredoption = $this->FetchFile($this->design, false, 'required'); $notrequiredoption = $this->FetchFile($this->design, false, 'notrequired'); $javascript = ' function CheckMultiple' . $this->formid . '(frm, name) { for (var i=0; i < frm.length; i++) { fldObj = frm.elements[i]; fldId = fldObj.id; if (fldId) { var fieldnamecheck=fldObj.id.indexOf(name); if (fieldnamecheck != -1) { if (fldObj.checked) { return true; } } } } return false; } '; $javascript .= 'function CheckForm' . $this->formid . '(f) {'; $email_placeholder = ''; if ($this->formtype == 'm' || $this->formtype == 'f') { $email_placeholder = '%%Email%%'; } $alert = GetLang('Form_Javascript_EnterEmailAddress'); $javascript .= ' var email_re = /[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i; if (!email_re.test(f.email.value)) { alert("' . $alert . '"); f.email.focus(); return false; } '; $formatlist = ''; if ($this->formtype != 'u') { if ($this->formtype == 'm' && $this->changeformat) { $optionname = $requiredoption . GetLang('Form_ChooseFormat') . ':'; $option = '<select name="format">'; $option .= '<option value="h"%%Format_html%%>' . GetLang('Format_HTML') . '</option>'; $option .= '<option value="t"%%Format_text%%>' . GetLang('Format_Text') . '</option>'; $option .= '</select>'; $formatlist = str_replace(array('%%GLOBAL_OptionName%%', '%%GLOBAL_Option%%'), array($optionname, $option), $displayoption); } elseif ($this->formtype != 'm') { if ($this->chooseformat == 'c') { $optionname = $requiredoption . GetLang('Form_ChooseFormat') . ':'; $option = '<select name="format">'; $option .= '<option value="h">' . GetLang('Format_HTML') . '</option>'; $option .= '<option value="t">' . GetLang('Format_Text') . '</option>'; $option .= '</select>'; $alert = GetLang('Form_Javascript_ChooseFormat'); $javascript .= ' if (f.format.selectedIndex == -1) { alert("' . $alert . '"); f.format.focus(); return false; } '; $formatlist = str_replace(array('%%GLOBAL_OptionName%%', '%%GLOBAL_Option%%'), array($optionname, $option), $displayoption); } else { $formatlist = '<input type="hidden" name="format" value="' . str_replace('f', '', $this->chooseformat) . '" />'; } } } if ($this->usecaptcha) { $alert = GetLang('Form_Javascript_EnterCaptchaAnswer'); $javascript .= ' if (f.captcha.value == "") { alert("' . $alert . '"); f.captcha.focus(); return false; } '; } $placeholder_lists = ''; $list_intro_shown = false; if (sizeof($this->lists) > 1) { if (!class_exists('Lists_API', false)) { require_once(dirname(__FILE__) . '/lists.php'); } $lists_api = new Lists_API(0, false); $lists_api->Set('Db', $this->Db); $listlist = ''; foreach ($this->lists as $p => $listid) { $lists_api->Load($listid); $optionname = ''; if (!$list_intro_shown) { $optionname = $notrequiredoption . GetLang('MailingLists') . ':'; $list_intro_shown = true; } else { $optionname = ' '; } if ($this->formtype == 'm') { $placeholder_lists = '%%Lists_' . $listid . '%%'; } $option = '<label for="lists_' . $listid . '"><input type="checkbox" id="lists_' . $listid . '" name="lists[]" value="' . $listid . '"' . $placeholder_lists . ' /> ' . $lists_api->Get('name') . '</label>'; $listlist .= str_replace(array('%%GLOBAL_OptionName%%', '%%GLOBAL_Option%%'), array($optionname, $option), $displayoption); $alert = GetLang('Form_Javascript_ChooseLists'); $javascript .= ' lists_chosen = CheckMultiple' . $this->formid . '(f, "lists"); if (!lists_chosen) { alert("' . $alert . '"); return false; } '; } } else { $listid = current($this->lists); if ($this->formtype == 'm') { $placeholder_lists = '%%Lists_' . $listid . '%%'; } $listlist = '<input type="hidden" name="lists" value="' . $listid . '" />'; } $formcontents = ''; // custom fields is a multidimensional array with list as the key. // The subarray contains fields to show for that list. // $displayfields = array(); $displayfields = $this->fieldorder; foreach ($this->customfields as $p => $field) { if (!in_array($field, $displayfields)) { $displayfields[] = $field; } } if (!class_exists('CustomFields_API', false)) { require_once(dirname(__FILE__) . '/customfields.php'); } $customfields_api = new CustomFields_API(0, false); $customfields_api->Db = $this->Db; $shown_list_options = false; foreach ($displayfields as $p => $field) { if ($field == 'e') { $optionname = $requiredoption . GetLang('Form_EmailAddress') . ':'; $option = '<input type="text" name="email" value="' . $email_placeholder . '" />'; $formcontents .= str_replace(array('%%GLOBAL_OptionName%%', '%%GLOBAL_Option%%'), array($optionname, $option), $displayoption); continue; } if ($field == 'cl') { $shown_list_options = true; $formcontents .= $listlist; continue; } if ($this->formtype == 'u') { continue; } if ($field == 'cf') { $formcontents .= $formatlist; continue; } $option = ''; $optionvalue = ''; $loaded = $customfields_api->Load($field); if (!$loaded) { continue; } $subfield = $customfields_api->LoadSubField(); $javascript .= $subfield->CreateJavascript($this->formid); if ($subfield->IsRequired()) { $optionname = $requiredoption; } else { $optionname = $notrequiredoption; } $optionname .= $subfield->GetFieldName() . ':'; $option = $subfield->DisplayFieldOptions($customfields_api->Settings['DefaultValue'], true, $this->formid); if ($this->formtype == 'm') { switch ($subfield->fieldtype) { case 'dropdown': $option = preg_replace('/<option value="(.*?)">/', "<option value=\"\${1}\"%%CustomField_".$field."_\${1}%%>", $option); break; case 'checkbox': $option = preg_replace('/name="(.*?)" value="(.*?)">/', "name=\"\${1}\" value=\"\${2}\"%%CustomField_".$field."_\${2}%%>", $option); break; case 'radiobutton': $option = preg_replace('/value="(.*?)">/', "value=\"\${1}\"%%CustomField_".$field."_\${1}%%>", $option); break; case 'date': foreach (array('dd', 'mm', 'yy') as $p => $datepart) { $match_string = preg_quote('<select name="CustomFields[' . $field . '][' . $datepart . ']"', '%') . '.*?\>(.*?)' . preg_quote('</select>', '%'); if (preg_match('%'.$match_string.'%i', $option, $matches)) { $orig_text = $full_text = $matches[0]; $full_text = preg_replace('/value="(.*?)">/', "value=\"\${1}\"%%CustomField_" . $field . "_\${1}_" . $datepart . "%%>", $full_text); $option = str_replace($orig_text, $full_text, $option); } } break; case 'textarea': $option = str_replace('</textarea>', '%%CustomField_' . $field . '%%</textarea>', $option); break; case 'number': $option = str_replace('value="0"', 'value="%%CustomField_' . $field . '%%"', $option); break; default: $option = str_replace('value=""', 'value="%%CustomField_' . $field . '%%"', $option); break; } } $formcontents .= str_replace(array('%%GLOBAL_OptionName%%', '%%GLOBAL_Option%%'), array($optionname, $option), $displayoption); } if ($this->formtype == 'm' && !$shown_list_options) { $formcontents .= $listlist; } switch ($this->formtype) { case 's': $formaction = SENDSTUDIO_APPLICATION_URL . '/form.php?form=' . $this->formid; break; case 'u': $formaction = SENDSTUDIO_APPLICATION_URL . '/unsubform.php?form=' . $this->formid; break; case 'f': case 'm': /** * We don't hardcode the form action in case we are generating the form. Since a modify details form stays inside sendstudio, we don't want to hardcode the url (instead it's generated by the modifydetails.php file). * Why? In case we change the url - we don't want to have to change database values at the same time. */ $formaction = '%%FORMACTION%%'; break; default: $formaction = false; } if (!in_array('cf', $displayfields)) { $formcontents .= $formatlist; } if (!class_exists('captcha_api', false)) { require_once(dirname(__FILE__) . '/captcha.php'); } $captcha_api = new Captcha_API($inside_sendstudio); if ($this->usecaptcha) { $optionname = $requiredoption . GetLang('Form_EnterCaptcha') . ':'; if ($this->formtype == 'm') { $option = '%%captchaimage%%'; } else { $option = $captcha_api->ShowCaptcha(); } $option .= '<br/><input type="text" name="captcha" value="" />'; $formcontents .= str_replace(array('%%GLOBAL_OptionName%%', '%%GLOBAL_Option%%'), array($optionname, $option), $displayoption); } $javascript .= ' return true; } '; $content = str_replace(array('%%FormContents%%', '%%FormAction%%', '%%FormID%%', '%%Javascript%%'), array($formcontents, $formaction, $this->formid, $javascript), $content); $content = $sendstudio_functions->ReplaceLanguageVariables($content); return $content; }
/** * _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; }
$subscriber_id = call_user_func_array(array($handlerObject, 'AddToList'), $params); if (!$subscriber_id) { $db->RollbackTransaction(); SendResponse(false, 'Failed adding subcriber to the list'); } $send_notification = false; require_once(SENDSTUDIO_LANGUAGE_DIRECTORY . '/default/frontend.php'); /** * we don't need to include the api/lists.php file * because the AddToList function in the subscribers api does it already * because it checks the list exists before anything else. */ $lists_api = new Lists_API(); $lists_api->Load($function_params['mailinglist']); $listowneremail = $lists_api->Get('owneremail'); $listownername = $lists_api->Get('ownername'); require_once(IEM_PATH . '/ext/interspire_email/email.php'); $emailapi = new Email_API(); $emailapi->SetSMTP(SENDSTUDIO_SMTP_SERVER, SENDSTUDIO_SMTP_USERNAME, @base64_decode(SENDSTUDIO_SMTP_PASSWORD), SENDSTUDIO_SMTP_PORT); $emailapi->Set('CharSet', SENDSTUDIO_CHARSET); $emailapi->Set('Subject', GetLang('SubscriberNotification_Subject')); $emailapi->Set('FromName', false); $emailapi->Set('FromAddress', $listowneremail);