Ejemplo n.º 1
0
	/**
	* 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 = '&nbsp;';
				}

				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 . ' />&nbsp;' . $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;
	}
Ejemplo n.º 2
0
 /**
  * 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');
 }
Ejemplo n.º 3
0
        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);
        $emailapi->Set('ReplyTo', $function_params['emailaddress']);