/** * EditNewsletter * Loads up stage 1 of editing a newsletter (choosing format, templates etc). * * @param Int $newsletterid Newsletter to load up. * * @see GetApi * @see GetTemplateList * @see Newsletter_API::Load * @see Newsletter_API::GetAllFormats * * @return Void Prints out the form, doesn't return anything. */ function EditNewsletter($newsletterid=0) { $newsletter = $this->GetApi(); if ($newsletterid <= 0 || !$newsletter->Load($newsletterid)) { $GLOBALS['Error'] = GetLang('UnableToLoadNewsletter'); $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); $this->ManageNewsletters(); return; } // Log this to "User Activity Log" IEM::logUserActivity($_SERVER['REQUEST_URI'], 'images/newsletters_view.gif', $newsletter->name); $GLOBALS['Action'] = 'Edit&SubAction=Step2&id=' . $newsletterid; $GLOBALS['CancelButton'] = GetLang('EditNewsletterCancelButton'); $GLOBALS['Heading'] = GetLang('EditNewsletter'); $GLOBALS['Intro'] = GetLang('EditNewsletterIntro'); $GLOBALS['NewsletterDetails'] = GetLang('EditNewsletterHeading'); $GLOBALS['FormatList'] = ''; $allformats = $newsletter->GetAllFormats(); foreach ($allformats as $id => $name) { $selected = ''; if ($id == $newsletter->format) { $selected = ' SELECTED'; } if ($name == 'TextAndHTML') { $recommended = ' ' . GetLang('Recommended'); } else { $recommended = ''; } $GLOBALS['FormatList'] .= '<option value="' . $id . '"' . $selected . '>' . GetLang('Format_' . $name) . $recommended . '</option>'; } $GLOBALS['Name'] = htmlspecialchars($newsletter->name, ENT_QUOTES, SENDSTUDIO_CHARSET); $GLOBALS['DisplayTemplateList'] = 'none'; $this->ParseTemplate('Newsletter_Form_Step1'); }
/** * Process * Takes the appropriate action based on the action and user permissions * * @see GetUser * @see User_API::HasAccess * @see PrintHeader * @see PrintFooter * * @return Void Doesn't return anything. Takes the appropriate action. */ function Process() { $GLOBALS['Message'] = ''; $action = (isset($_GET['Action'])) ? strtolower($_GET['Action']) : null; $user = GetUser(); $secondary_actions = array('step2', 'sendpreview', 'view', 'processpaging', 'activate', 'deactivate', 'pause', 'resume', 'change', 'checkspam', 'viewcompatibility'); if (in_array($action, $secondary_actions)) { $access = $user->HasAccess('Autoresponders'); } else { $access = $user->HasAccess('Autoresponders', $action); } $popup = (in_array($action, $this->PopupWindows)) ? true : false; if (!in_array($action, $this->SuppressHeaderFooter)) { $this->PrintHeader($popup); } if (!$access) { if (!$popup) { $this->DenyAccess(); return; } } /** * Check user permission to see whether or not they have access to the autoresponder */ $tempAPI = null; $tempCheckActions = array('activate', 'deactivate', 'copy', 'change', 'pause', 'resume', 'delete', 'step2', 'sendpreview', 'view', 'edit'); $tempID = null; if (isset($_GET['id'])) { $tempID = $_GET['id']; } elseif(isset($_POST['autoresponders'])) { $tempID = $_POST['autoresponders']; } if (!is_null($tempID)) { $_GET['id'] = $tempID; $_POST['autoresponders'] = $tempID; if (!$user->Admin() && in_array($action, $tempCheckActions)) { if (!is_array($tempID)) { $tempID = array($tempID); } $tempAPI = $this->GetApi(); foreach ($tempID as $tempEachID) { $tempEachID = intval($tempEachID); if ($tempEachID == 0) { continue; } if (!$tempAPI->Load($tempEachID)) { continue; } if ($tempAPI->ownerid != $user->userid) { $this->DenyAccess(); return; } } } } unset($tempID); unset($tempCheckActions); unset($tempAPI); /** * ----- */ if ($action == 'processpaging') { $this->SetPerPage($_GET['PerPageDisplay']); $action = 'step2'; } switch ($action) { case 'pause': case 'resume': $autoresponderAPI = $this->GetApi(); $autoresponderID = IEM::requestGetGET('id', 0, 'intval'); $listID = IEM::requestGetGET('list', 0, 'intval'); if ($action == 'pause') { $autoresponderAPI->PauseAutoresponder($autoresponderID); } else { $autoresponderAPI->ResumeAutoresponder($autoresponderID); } $this->ManageAutoresponders($listID); break; case 'viewcompatibility': $auto_info = IEM::sessionGet('Autoresponders'); $html = (isset($_POST['myDevEditControl_html'])) ? $_POST['myDevEditControl_html'] : false; $text = (isset($_POST['TextContent'])) ? $_POST['TextContent'] : false; $showBroken = isset($_REQUEST['ShowBroken']) && $_REQUEST['ShowBroken'] == 1; $details = array(); $details['htmlcontent'] = $html; $details['textcontent'] = $text; $details['format'] = $auto_info['Format']; $this->PreviewWindow($details, $showBroken); exit; break; case 'checkspamdisplay': $force = IEM::ifsetor($_GET['Force'], false); $this->CheckContentForSpamDisplay($force); break; case 'checkspam': $text = (isset($_POST['TextContent'])) ? $_POST['TextContent'] : false; $html = (isset($_POST['myDevEditControl_html'])) ? $_POST['myDevEditControl_html'] : false; $this->CheckContentForSpam($text, $html); break; case 'activate': case 'deactivate': $access = $user->HasAccess('Autoresponders', 'Approve'); if (!$access) { $this->DenyAccess(); break; } $id = (int)$_GET['id']; $autoapi = $this->GetApi(); $autoapi->Load($id); if ($action == 'activate') { $prob_found = false; $max_size = (SENDSTUDIO_EMAILSIZE_MAXIMUM*1024); if ($max_size > 0) { if ($autoapi->Get('autorespondersize') > $max_size) { $prob_found = true; if ($autoapi->Get('embedimages')) { $error_langvar = 'Autoresponder_Size_Over_EmailSize_Maximum_Embed'; } else { $error_langvar = 'Autoresponder_Size_Over_EmailSize_Maximum_No_Embed'; } $GLOBALS['Error'] = sprintf(GetLang($error_langvar), $this->EasySize($max_size, 0)); $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); } } if (!$prob_found) { $allow_attachments = $this->CheckForAttachments($id, 'autoresponders'); if ($allow_attachments) { $autoapi->Set('active', $user->Get('userid')); $GLOBALS['Message'] = $this->PrintSuccess('AutoresponderActivatedSuccessfully'); } else { $GLOBALS['Error'] = GetLang('AutoresponderActivateFailed_HasAttachments'); $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); } } } else { $autoapi->Set('active', 0); $GLOBALS['Message'] = $this->PrintSuccess('AutoresponderDeactivatedSuccessfully'); } $autoapi->Save(); if (isset($_GET['list'])) { $listid = (int)$_GET['list']; } $this->ManageAutoresponders($listid); break; case 'copy': $id = (isset($_GET['id'])) ? (int)$_GET['id'] : 0; $api = $this->GetApi(); list($result, $files_copied) = $api->Copy($id); if (!$result) { $GLOBALS['Error'] = GetLang('AutoresponderCopyFail'); $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); } else { $api->Set('active', 0); $api->Save(); $GLOBALS['Message'] = $this->PrintSuccess('AutoresponderCopySuccess'); $GLOBALS['Message'] .= $this->PrintWarning('AutoresponderHasBeenDisabled'); if (!$files_copied) { $GLOBALS['Error'] = GetLang('AutoresponderFilesCopyFail'); $GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false); } } if (isset($_GET['list'])) { $listid = (int)$_GET['list']; } $this->ManageAutoresponders($listid); break; case 'change': $subaction = strtolower($_POST['ChangeType']); $autolist = $_POST['autoresponders']; switch ($subaction) { case 'delete': $access = $user->HasAccess('Autoresponders', 'Delete'); if ($access) { $this->DeleteAutoresponders($autolist); } else { $this->DenyAccess(); } break; case 'approve': case 'disapprove': $access = $user->HasAccess('Autoresponders', 'Approve'); if ($access) { $this->ActionAutoresponders($autolist, $subaction); } else { $this->DenyAccess(); } break; } break; case 'delete': $id = (int)$_GET['id']; $autolist = array($id); $access = $user->HasAccess('Autoresponders', 'Delete'); if ($access) { $this->DeleteAutoresponders($autolist); } else { $this->DenyAccess(); } break; case 'step2': $listid = 0; if (isset($_GET['list'])) { $listid = (int)$_GET['list']; } $this->ManageAutoresponders($listid); break; case 'sendpreviewdisplay': $this->SendPreviewDisplay(); break; case 'sendpreview': $this->SendPreview(); break; case 'view': $id = (isset($_GET['id'])) ? (int)$_GET['id'] : 0; $type = strtolower(get_class($this)); $autoresponderapi = $this->GetApi(); if (!$autoresponderapi->Load($id)) { break; } // Log this to "User Activity Log" $logURL = SENDSTUDIO_APPLICATION_URL . '/admin/index.php?Page=' . __CLASS__ . '&Action=Edit&id=' . $_GET['id']; IEM::logUserActivity($logURL, 'images/autoresponders_view.gif', $autoresponderapi->name); $details = array(); $details['htmlcontent'] = $autoresponderapi->GetBody('HTML'); $details['textcontent'] = $autoresponderapi->GetBody('Text'); $details['format'] = $autoresponderapi->format; $this->PreviewWindow($details); break; case 'edit': $subaction = (isset($_GET['SubAction'])) ? strtolower($_GET['SubAction']) : false; switch ($subaction) { case 'save': case 'complete': $user = IEM::getCurrentUser(); $session_autoresponder = IEM::sessionGet('Autoresponders'); $listid = $session_autoresponder['list']; if (!$session_autoresponder || !isset($session_autoresponder['autoresponderid'])) { $this->ManageAutoresponders($listid); break; } $text_unsubscribelink_found = true; $html_unsubscribelink_found = true; $id = $session_autoresponder['autoresponderid']; $autoapi = $this->GetApi(); $autoapi->Load($id); $autoapi->Set('listid', $listid); if (isset($_POST['TextContent'])) { $textcontent = $_POST['TextContent']; $autoapi->SetBody('Text', $textcontent); $text_unsubscribelink_found = $this->CheckForUnsubscribeLink($textcontent, 'text'); $session_autoresponder['contents']['text'] = $textcontent; } if (isset($_POST['myDevEditControl_html'])) { $htmlcontent = $_POST['myDevEditControl_html']; /** * This is an effort not to overwrite the eixsting HTML contents * if there isn't any contents in it (DevEdit will have '<html><body></body></html>' as a minimum * that will be passed to here) */ if (trim($htmlcontent) == '') { $GLOBALS['Error'] = GetLang('UnableToUpdateAutoresponder'); $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); $this->EditAutoresponderStep4($id); break; } $autoapi->SetBody('HTML', $htmlcontent); $html_unsubscribelink_found = $this->CheckForUnsubscribeLink($htmlcontent, 'html'); $session_autoresponder['contents']['html'] = $htmlcontent; } if (isset($_POST['subject'])) { $autoapi->Set('subject', $_POST['subject']); } foreach (array('name', 'format', 'searchcriteria', 'sendfromname', 'sendfromemail', 'replytoemail', 'bounceemail', 'tracklinks', 'trackopens', 'multipart', 'embedimages', 'hoursaftersubscription', 'charset', 'includeexisting', 'to_firstname', 'to_lastname') as $p => $area) { $autoapi->Set($area, $session_autoresponder[$area]); } $autoapi->Set('active', 0); $dest = strtolower(get_class($this)); $movefiles_result = $this->MoveFiles($dest, $id); if ($movefiles_result) { if (isset($textcontent)) { $textcontent = $this->ConvertContent($textcontent, $dest, $id); $autoapi->SetBody('Text', $textcontent); } if (isset($htmlcontent)) { $htmlcontent = $this->ConvertContent($htmlcontent, $dest, $id); $autoapi->SetBody('HTML', $htmlcontent); } } // Delete any attachments we're meant to first if (SENDSTUDIO_ALLOW_ATTACHMENTS) { list($del_attachments_status, $del_attachments_status_msg) = $this->CleanupAttachments($dest, $id); if ($del_attachments_status) { if ($del_attachments_status_msg) { $GLOBALS['Success'] = $del_attachments_status_msg; $GLOBALS['Message'] .= $this->ParseTemplate('SuccessMsg', true, false); } } else { $GLOBALS['Error'] = $del_attachments_status_msg; $GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false); } // Only save the new attachments after deleting the old ones list($attachments_status, $attachments_status_msg) = $this->SaveAttachments($dest, $id); if ($attachments_status) { if ($attachments_status_msg != '') { $GLOBALS['Success'] = $attachments_status_msg; $GLOBALS['Message'] .= $this->ParseTemplate('SuccessMsg', true, false); } } else { $GLOBALS['AttachmentError'] = $attachments_status_msg; $GLOBALS['Error'] = $attachments_status_msg; $GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false); } } list($autoresponder_size, $autoresponder_img_warnings) = $this->GetSize($session_autoresponder); $GLOBALS['Message'] .= $this->PrintSuccess('AutoresponderUpdated', sprintf(GetLang('Autoresponder_Size_Approximate'), $this->EasySize($autoresponder_size))); $max_size = (SENDSTUDIO_EMAILSIZE_MAXIMUM*1024); if (SENDSTUDIO_EMAILSIZE_WARNING > 0) { $warning_size = SENDSTUDIO_EMAILSIZE_WARNING * 1024; if ($autoresponder_size > $warning_size && ($max_size > 0 && $autoresponder_size < $max_size)) { if ($session_autoresponder['embedimages']) { $warning_langvar = 'Autoresponder_Size_Over_EmailSize_Warning_Embed'; } else { $warning_langvar = 'Autoresponder_Size_Over_EmailSize_Warning_No_Embed'; } $GLOBALS['Message'] .= $this->PrintWarning($warning_langvar, $this->EasySize($warning_size)); } } if ($max_size > 0 && $autoresponder_size >= $max_size) { if ($session_autoresponder['embedimages']) { $error_langvar = 'Autoresponder_Size_Over_EmailSize_Maximum_Embed'; } else { $error_langvar = 'Autoresponder_Size_Over_EmailSize_Maximum_No_Embed'; } $GLOBALS['Error'] = sprintf(GetLang($error_langvar), $this->EasySize($max_size, 0)); $GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false); } $autoapi->Set('autorespondersize', $autoresponder_size); $result = $autoapi->Save(); if (!$result) { $GLOBALS['Error'] = GetLang('UnableToUpdateAutoresponder'); $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); $this->ManageAutoresponders($listid); break; } if ($autoresponder_img_warnings) { if ($session_autoresponder['embedimages']) { $warning_var = 'UnableToLoadImage_Autoresponder_List_Embed'; } else { $warning_var = 'UnableToLoadImage_Autoresponder_List'; } $GLOBALS['Message'] .= $this->PrintWarning($warning_var, $autoresponder_img_warnings); } if (!$html_unsubscribelink_found) { $GLOBALS['Message'] .= $this->PrintWarning('NoUnsubscribeLinkInHTMLContent'); } if (!$text_unsubscribelink_found) { $GLOBALS['Message'] .= $this->PrintWarning('NoUnsubscribeLinkInTextContent'); } if(is_dir(TEMP_DIRECTORY . "/autoresponders/".$user->userid."_tmp")){remove_directory(TEMP_DIRECTORY . "/autoresponders/".$user->userid."_tmp");} if ($subaction == 'save') { $GLOBALS['Message'] .= $this->PrintWarning('AutoresponderHasBeenDisabled_Save'); $GLOBALS['Message'] = str_replace('<br><br>', '<br>', $GLOBALS['Message']); $this->EditAutoresponderStep4($id); break; } $GLOBALS['Message'] .= $this->PrintWarning('AutoresponderHasBeenDisabled'); $GLOBALS['Message'] = str_replace('<br><br>', '<br>', $GLOBALS['Message']); $this->ManageAutoresponders($listid); break; case 'step4': $sessionauto = IEM::sessionGet('Autoresponders'); $sessionauto['sendfromname'] = $_POST['sendfromname']; $sessionauto['sendfromemail'] = $_POST['sendfromemail']; $sessionauto['replytoemail'] = $_POST['replytoemail']; $sessionauto['bounceemail'] = $_POST['bounceemail']; $sessionauto['charset'] = $_POST['charset']; $sessionauto['format'] = $_POST['format']; $sessionauto['hoursaftersubscription'] = (int)$_POST['hoursaftersubscription']; $sessionauto['trackopens'] = (isset($_POST['trackopens'])) ? true : false; $sessionauto['tracklinks'] = (isset($_POST['tracklinks'])) ? true : false; $sessionauto['multipart'] = (isset($_POST['multipart'])) ? true : false; $sessionauto['embedimages'] = (isset($_POST['embedimages'])) ? true : false; $sessionauto['includeexisting'] = (isset($_POST['includeexisting'])) ? true : false; $sessionauto['to_lastname'] = 0; if (isset($_POST['to_lastname'])) { $sessionauto['to_lastname'] = (int)$_POST['to_lastname']; } $sessionauto['to_firstname'] = 0; if (isset($_POST['to_firstname'])) { $sessionauto['to_firstname'] = (int)$_POST['to_firstname']; } IEM::sessionSet('Autoresponders', $sessionauto); $this->EditAutoresponderStep4($sessionauto['autoresponderid']); break; case 'step3': $sessionauto = IEM::sessionGet('Autoresponders'); $sessionauto['name'] = $_POST['name']; $sessionauto['searchcriteria'] = array( 'emailaddress' => '', 'format' => '-1', 'confirmed' => '1', 'search_options' => array(), 'customfields' => array() ); if ($_POST['ShowFilteringOptions'] == 1) { $sessionauto['searchcriteria']['emailaddress'] = $_POST['emailaddress']; $sessionauto['searchcriteria']['format'] = $_POST['format']; $sessionauto['searchcriteria']['confirmed'] = $_POST['confirmed']; $search_options = (isset($_POST['Search_Options'])) ? $_POST['Search_Options'] : array(); $sessionauto['searchcriteria']['search_options'] = $search_options; $customfields = (isset($_POST['CustomFields'])) ? $_POST['CustomFields'] : array(); $sessionauto['searchcriteria']['customfields'] = $customfields; foreach ($sessionauto['searchcriteria']['customfields'] as $fieldid => $fieldvalue) { if (!$fieldvalue) { unset($sessionauto['searchcriteria']['customfields'][$fieldid]); continue; } } if (isset($_POST['clickedlink']) && isset($_POST['linkid'])) { $sessionauto['searchcriteria']['linktype'] = 'clicked'; if (isset($_POST['linktype']) && $_POST['linktype'] == 'not_clicked') { $sessionauto['searchcriteria']['linktype'] = 'not_clicked'; } $sessionauto['searchcriteria']['link'] = $_POST['linkid']; } if (isset($_POST['openednewsletter']) && isset($_POST['newsletterid'])) { $sessionauto['searchcriteria']['opentype'] = 'opened'; if (isset($_POST['opentype']) && $_POST['opentype'] == 'not_opened') { $sessionauto['searchcriteria']['opentype'] = 'not_opened'; } $sessionauto['searchcriteria']['newsletter'] = $_POST['newsletterid']; } } IEM::sessionSet('Autoresponders', $sessionauto); $this->EditAutoresponderStep3($sessionauto['autoresponderid']); break; default: $id = (int)$_GET['id']; IEM::sessionRemove('Autoresponders'); $autosession = array('list' => (int)$_GET['list'], 'autoresponderid' => $id); IEM::sessionSet('Autoresponders', $autosession); $this->EditAutoresponderStep1($id); } break; case 'create': $subaction = (isset($_GET['SubAction'])) ? strtolower($_GET['SubAction']) : false; switch ($subaction) { case 'save': case 'complete': $autoresponder = $this->GetApi(); $user = IEM::getCurrentUser(); $session_autoresponder = IEM::sessionGet('Autoresponders'); if (!$session_autoresponder || !isset($session_autoresponder['name'])) { $this->ManageAutoresponders($listid); break; } $text_unsubscribelink_found = true; $html_unsubscribelink_found = true; $listid = $session_autoresponder['list']; $autoresponder->Set('listid', $listid); if (isset($_POST['TextContent'])) { $textcontent = $_POST['TextContent']; $autoresponder->SetBody('Text', $textcontent); $text_unsubscribelink_found = $this->CheckForUnsubscribeLink($textcontent, 'text'); $session_autoresponder['contents']['text'] = $textcontent; } if (isset($_POST['myDevEditControl_html'])) { $htmlcontent = $_POST['myDevEditControl_html']; $autoresponder->SetBody('HTML', $htmlcontent); $html_unsubscribelink_found = $this->CheckForUnsubscribeLink($htmlcontent, 'html'); $session_autoresponder['contents']['html'] = $htmlcontent; } if (isset($_POST['subject'])) { $autoresponder->Set('subject', $_POST['subject']); } foreach (array('name', 'format', 'searchcriteria', 'sendfromname', 'sendfromemail', 'replytoemail', 'bounceemail', 'tracklinks', 'trackopens', 'multipart', 'embedimages', 'hoursaftersubscription', 'charset', 'includeexisting', 'to_firstname', 'to_lastname') as $p => $area) { $autoresponder->Set($area, $session_autoresponder[$area]); } $autoresponder->Set('active', 0); $autoresponder->ownerid = $user->userid; $result = $autoresponder->Create(); if (!$result) { $GLOBALS['Error'] = GetLang('UnableToCreateAutoresponder'); $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); $this->ManageAutoresponders($listid); break; } /** * explicitly set the 'includeexisting' flag to false so we don't import the existing subscribers twice. * Create() & Save() both call ImportQueue if this flag is set, so ensure we don't do it twice. */ $autoresponder->Set('includeexisting', false); $session_autoresponder['autoresponderid'] = $result; IEM::sessionSet('Autoresponders', $session_autoresponder); if (SENDSTUDIO_ALLOW_ATTACHMENTS) { $dest = strtolower(get_class($this)); $movefiles_result = $this->MoveFiles($dest, $result); if ($movefiles_result) { if (isset($textcontent)) { $textcontent = $this->ConvertContent($textcontent, $dest, $result); $autoresponder->SetBody('Text', $textcontent); } if (isset($htmlcontent)) { $htmlcontent = $this->ConvertContent($htmlcontent, $dest, $result); $autoresponder->SetBody('HTML', $htmlcontent); } } list($attachments_status, $attachments_status_msg) = $this->SaveAttachments($dest, $result); if ($attachments_status) { if ($attachments_status_msg != '') { $GLOBALS['Success'] = $attachments_status_msg; $GLOBALS['Message'] .= $this->ParseTemplate('SuccessMsg', true, false); } } else { $GLOBALS['Error'] = $attachments_status_msg; $GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false); } } list($autoresponder_size, $autoresponder_img_warnings) = $this->GetSize($session_autoresponder); $GLOBALS['Message'] .= $this->PrintSuccess('AutoresponderUpdated', sprintf(GetLang('Autoresponder_Size_Approximate'), $this->EasySize($autoresponder_size))); $max_size = (SENDSTUDIO_EMAILSIZE_MAXIMUM*1024); if (SENDSTUDIO_EMAILSIZE_WARNING > 0) { $warning_size = SENDSTUDIO_EMAILSIZE_WARNING * 1024; if ($autoresponder_size > $warning_size && ($max_size > 0 && $autoresponder_size < $max_size)) { if ($session_autoresponder['embedimages']) { $warning_langvar = 'Autoresponder_Size_Over_EmailSize_Warning_Embed'; } else { $warning_langvar = 'Autoresponder_Size_Over_EmailSize_Warning_No_Embed'; } $GLOBALS['Message'] .= $this->PrintWarning($warning_langvar, $this->EasySize($warning_size)); } } if ($max_size > 0 && $autoresponder_size >= $max_size) { if ($session_autoresponder['embedimages']) { $error_langvar = 'Autoresponder_Size_Over_EmailSize_Maximum_Embed'; } else { $error_langvar = 'Autoresponder_Size_Over_EmailSize_Maximum_No_Embed'; } $GLOBALS['Error'] = sprintf(GetLang($error_langvar), $this->EasySize($max_size, 0)); $GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false); } $autoresponder->Set('autorespondersize', $autoresponder_size); $autoresponder->Save(); if ($autoresponder_img_warnings) { if ($session_autoresponder['embedimages']) { $warning_var = 'UnableToLoadImage_Autoresponder_List_Embed'; } else { $warning_var = 'UnableToLoadImage_Autoresponder_List'; } $GLOBALS['Message'] .= $this->PrintWarning($warning_var, $autoresponder_img_warnings); } if (!$html_unsubscribelink_found) { $GLOBALS['Message'] .= $this->PrintWarning('NoUnsubscribeLinkInHTMLContent'); } if (!$text_unsubscribelink_found) { $GLOBALS['Message'] .= $this->PrintWarning('NoUnsubscribeLinkInTextContent'); } if ($subaction == 'save') { $GLOBALS['Message'] .= $this->PrintWarning('AutoresponderHasBeenDisabled_Save'); $GLOBALS['Message'] = str_replace('<br><br>', '<br>', $GLOBALS['Message']); $this->EditAutoresponderStep4($result); break; } $GLOBALS['Message'] .= $this->PrintWarning('AutoresponderHasBeenDisabled'); $GLOBALS['Message'] = str_replace('<br><br>', '<br>', $GLOBALS['Message']); $this->ManageAutoresponders($listid); break; case 'step4': $sessionauto = IEM::sessionGet('Autoresponders'); $sessionauto['sendfromname'] = $_POST['sendfromname']; $sessionauto['sendfromemail'] = $_POST['sendfromemail']; $sessionauto['replytoemail'] = $_POST['replytoemail']; $sessionauto['bounceemail'] = $_POST['bounceemail']; $sessionauto['charset'] = $_POST['charset']; $sessionauto['format'] = $_POST['format']; $sessionauto['hoursaftersubscription'] = (int)$_POST['hoursaftersubscription']; $sessionauto['trackopens'] = (isset($_POST['trackopens'])) ? true : false; $sessionauto['tracklinks'] = (isset($_POST['tracklinks'])) ? true : false; $sessionauto['multipart'] = (isset($_POST['multipart'])) ? true : false; $sessionauto['embedimages'] = (isset($_POST['embedimages'])) ? true : false; $sessionauto['includeexisting'] = (isset($_POST['includeexisting'])) ? true : false; $sessionauto['to_lastname'] = 0; if (isset($_POST['to_lastname'])) { $sessionauto['to_lastname'] = (int)$_POST['to_lastname']; } $sessionauto['to_firstname'] = 0; if (isset($_POST['to_firstname'])) { $sessionauto['to_firstname'] = (int)$_POST['to_firstname']; } if (isset($_POST['TemplateID'])) { $sessionauto['TemplateID'] = $_POST['TemplateID']; } IEM::sessionSet('Autoresponders', $sessionauto); $this->EditAutoresponderStep4(); break; case 'step3': $sessionauto = IEM::sessionGet('Autoresponders'); $sessionauto['name'] = $_POST['name']; $sessionauto['searchcriteria'] = array( 'emailaddress' => '', 'format' => '-1', 'confirmed' => '1', 'search_options' => array(), 'customfields' => array() ); if ($_POST['ShowFilteringOptions'] == 1) { $sessionauto['searchcriteria']['emailaddress'] = $_POST['emailaddress']; $sessionauto['searchcriteria']['format'] = $_POST['format']; $sessionauto['searchcriteria']['confirmed'] = $_POST['confirmed']; $search_options = (isset($_POST['Search_Options'])) ? $_POST['Search_Options'] : array(); $sessionauto['searchcriteria']['search_options'] = $search_options; $customfields = (isset($_POST['CustomFields'])) ? $_POST['CustomFields'] : array(); $sessionauto['searchcriteria']['customfields'] = $customfields; foreach ($sessionauto['searchcriteria']['customfields'] as $fieldid => $fieldvalue) { if (!$fieldvalue) { unset($sessionauto['searchcriteria']['customfields'][$fieldid]); continue; } } if (isset($_POST['clickedlink']) && isset($_POST['linkid'])) { $sessionauto['searchcriteria']['linktype'] = 'clicked'; if (isset($_POST['linktype']) && $_POST['linktype'] == 'not_clicked') { $sessionauto['searchcriteria']['linktype'] = 'not_clicked'; } $sessionauto['searchcriteria']['link'] = $_POST['linkid']; } if (isset($_POST['openednewsletter']) && isset($_POST['newsletterid'])) { $sessionauto['searchcriteria']['opentype'] = 'opened'; if (isset($_POST['opentype']) && $_POST['opentype'] == 'not_opened') { $sessionauto['searchcriteria']['opentype'] = 'not_opened'; } $sessionauto['searchcriteria']['newsletter'] = $_POST['newsletterid']; } } IEM::sessionSet('Autoresponders', $sessionauto); $this->EditAutoresponderStep3(); break; case 'step2': $listid = 0; if (isset($_POST['list'])) { $listid = (int)$_POST['list']; } if (isset($_GET['list'])) { $listid = (int)$_GET['list']; } $auto = array('list' => $listid); IEM::sessionSet('Autoresponders', $auto); $this->EditAutoresponderStep1(); break; default: IEM::sessionRemove('Autoresponders'); $this->ChooseCreateList(); } break; default: $this->SetCurrentPage(1); $this->ChooseList('Autoresponders', 'step2'); break; } if (!in_array($action, $this->SuppressHeaderFooter)) { $this->PrintFooter($popup); } }
/** * ViewSubscriber * Prints the 'view subscriber' page and all appropriate options including custom fields. * * @param Int $listid The list the subscriber is on. This is checked to make sure the user has 'manage' access to the list before anything else. * @param Int $subscriberid The subscriberid to view. * @param Int $segmentid The ID of the segment that the subscriber is going to be fetched from * @param String $msgtype The heading to show when viewing a subscriber. This can be either error or success. Used with $msg to display something. * @param String $msg The message to display in the heading. If this is not present, no message is displayed. * * @see GetApi * @see Subscribers_API::GetCustomFieldSettings * @see Lists_API::GetCustomFields * @see Lists_API::Load * @see Lists_API::GetListFormat * * @return Void Doesn't return anything. Prints out the view form and that's it. */ function ViewSubscriber($listid = 0, $subscriberid = 0, $segmentid = 0, $msgtype = 'Error', $msg = false) { $user = GetUser(); $access = $user->HasAccess('Subscribers', 'Manage'); if (!$access) { $this->DenyAccess(); return; } $this->SetupGoogleCalendar(); $search_info = IEM::sessionGet('Search_Subscribers'); $GLOBALS['list'] = $listid; if ($msg && $msgtype) { switch (strtolower($msgtype)) { case 'success': $GLOBALS['Success'] = $msg; $GLOBALS['Message'] = $this->ParseTemplate('SuccessMsg', true, false); break; default: $GLOBALS['Error'] = $msg; $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); } } $SubscriberApi = $this->GetApi('Subscribers'); $subscriberinfo = false; /** * Get Subscriber record from the database */ $adminAccess = false; // If this user is an admin/list admin/list admintype == a then give permission if ($user->Admin() || $user->ListAdminType() == 'a' || $user->ListAdmin()) { $adminAccess = true; } // Get subscribers from list if ($segmentid == 0) { if (!$adminAccess && !$SubscriberApi->CheckPermission($user->userid, $subscriberid)) { $this->DenyAccess(); return; } $subscriberinfo = $SubscriberApi->LoadSubscriberList($subscriberid, $listid); // Get subscribers from segment } else { if (!$adminAccess) { $segmentapi = $this->GetApi('Segment', true); $segmentapi->Load($segmentid); if ($segmentapi->ownerid != $user->userid && !$user->HasAccess('Segments', 'View', $segmentid)) { $this->DenyAccess(); return; } } $subscriberinfo = $SubscriberApi->LoadSubscriberSegment($subscriberid, $segmentid); } /** * ----- */ // hmm, the subscriber doesn't exist or can't be loaded? show an error. if (empty($subscriberinfo)) { $GLOBALS['ErrorMessage'] = GetLang('SubscriberDoesntExist_View'); $this->DenyAccess(); return; } // Log this to "User Activity Log" $logURL = SENDSTUDIO_APPLICATION_URL . '/admin/index.php?Page=Subscribers&Action=Edit&List=' . $_GET['List'] . '&id=' . $_GET['id']; IEM::logUserActivity($logURL, 'images/contacts_view.gif', $subscriberinfo['emailaddress']); $list_api = $this->GetApi('Lists'); $list_api->Load($listid); $GLOBALS['emailaddress'] = $subscriberinfo['emailaddress']; $GLOBALS['subscriberid'] = $subscriberid; if ($subscriberinfo['requestdate'] == 0) { $GLOBALS['requestdate'] = GetLang('Unknown'); } else { $GLOBALS['requestdate'] = $this->PrintTime($subscriberinfo['requestdate']); } $GLOBALS['requestip'] = ($subscriberinfo['requestip'] == '') ? GetLang('Unknown') : $subscriberinfo['requestip']; if ($subscriberinfo['confirmdate'] == 0) { $GLOBALS['confirmdate'] = GetLang('Unknown'); } else { $GLOBALS['confirmdate'] = $this->PrintTime($subscriberinfo['confirmdate']); } $GLOBALS['confirmip'] = ($subscriberinfo['confirmip'] == '') ? GetLang('Unknown') : $subscriberinfo['confirmip']; if ($subscriberinfo['confirmed'] == 1) { $confirmed = 'Confirmed'; } elseif ($subscriberinfo['confirmed'] == 0) { $confirmed = 'Unconfirmed'; } $GLOBALS['ConfirmedList'] = GetLang($confirmed); $GLOBALS['ShowUnsubscribeInfo'] = 'none'; $subscriber_status = 'a'; if ($subscriberinfo['unsubscribed'] > 0) { $subscriber_status = 'u'; $GLOBALS['unsubscribetime'] = $this->PrintTime($subscriberinfo['unsubscribed']); $GLOBALS['unsubscribeip'] = ($subscriberinfo['unsubscribeip'] == '') ? GetLang('Unknown') : $subscriberinfo['unsubscribeip']; $GLOBALS['ShowUnsubscribeInfo'] = ''; } if ($subscriberinfo['bounced'] > 0) { $subscriber_status = 'b'; } switch ($subscriber_status) { case 'a': $status = 'Active'; break; case 'u': $status = 'Unsubscribed'; break; case 'b': $status = 'Bounced'; break; default: } // this is used both by the 'edit' and 'delete' buttons. $GLOBALS['subscriberid'] = $subscriberid; if ($segmentid != 0) { $GLOBALS['SegmentID'] = $segmentid; $GLOBALS['ExtraParameter'] = '&SegmentID=' . $segmentid; } else { $GLOBALS['SegmentID'] = 0; $GLOBALS['ExtraParameter'] = ''; } $GLOBALS['EditButton'] = ''; if ($user->HasAccess('Subscribers', 'Edit')) { $GLOBALS['EditButton'] = $this->ParseTemplate('Subscribers_View_Button_Edit', true, false); } $GLOBALS['DeleteButton'] = ''; if ($user->HasAccess('Subscribers', 'Delete')) { $GLOBALS['DeleteButton'] = $this->ParseTemplate('Subscribers_View_Button_Delete', true, false); } $GLOBALS['StatusList'] = GetLang($status); $listformat = $list_api->GetListFormat(); if ($subscriberinfo['format'] == 'h') { $format = GetLang('Format_HTML'); } elseif ($subscriberinfo['format'] == 't') { $format = GetLang('Format_Text'); } $GLOBALS['FormatList'] = $format; $customfields = $list_api->GetCustomFields($listid); $customfield_display = array(); $customfieldinfo = ''; if (!empty($customfields)) { $customfields_api = $this->GetApi('CustomFields'); $customfieldinfo .= $this->ParseTemplate('Subscribers_Edit_Step2_CustomFields', true, false); foreach ($customfields as $pos => $customfield_info) { $GLOBALS['FieldID'] = $customfield_info['fieldid']; if ($customfield_info['required']) { $GLOBALS['Required'] = $this->ParseTemplate('Required', true, false); } else { $GLOBALS['Required'] = $this->ParseTemplate('Not_Required', true, false); } $subscriber_settings = $SubscriberApi->GetCustomFieldSettings($customfield_info['fieldid']); $customfields_api->fieldid = $customfield_info['fieldid']; $customfields_api->fieldtype = $customfield_info['fieldtype']; $subfield = $customfields_api->LoadSubField(); $GLOBALS['FieldName'] = htmlspecialchars($customfield_info['name'], ENT_QUOTES, SENDSTUDIO_CHARSET); $GLOBALS['FieldValue'] = htmlspecialchars($subfield->GetRealValue($subscriber_settings), ENT_QUOTES, SENDSTUDIO_CHARSET); switch ($customfield_info['fieldtype']) { case 'textarea': $template_name = 'Subscribers_View_CustomField_TextArea'; break; case 'date': $fieldsettings = unserialize($customfield_info['fieldsettings']); $GLOBALS['DateJSON'] = ''; $GLOBALS['GoogleCalendarButton'] = ''; if (strlen($GLOBALS['FieldValue'])) { $date = explode('/',$GLOBALS['FieldValue']); $datejson = array_combine(array_slice($fieldsettings['Key'],0,3),$date); $GLOBALS['DateJSON'] = GetJSON($datejson); if (strlen($user->googlecalendarusername) && strlen($user->googlecalendarpassword)) { $GLOBALS['GoogleCalendarButton'] = $this->ParseTemplate('google_calendar_button',true); } else { $GLOBALS['GoogleCalendarButton'] = $this->ParseTemplate('google_calendar_button_disabled',true); } } $template_name = 'Subscribers_View_CustomField_Date'; break; default: $template_name = 'Subscribers_View_CustomField'; } $customfield_display[] = $this->ParseTemplate($template_name, true, false); unset($subfield); } $column1 = $column2 = array(); if (count($customfield_display) > 9) { $customfieldinfo_template = 'Subscribers_customfieldinfo_twocolumns'; $split = ceil(count($customfield_display) / 2); for ($i = 0; $i < $split; $i++) { $column1[] = $customfield_display[$i]; if (isset($customfield_display[$i + $split])) { $column2[] = $customfield_display[$i + $split]; } else { $column2[] = '<td> </td><td> </td>'; } } $GLOBALS['CustomFieldInfo_1'] = '<tr>' . implode('</tr><tr>',$column1) . '</tr>'; $GLOBALS['CustomFieldInfo_2'] = '<tr>' . implode('</tr><tr>',$column2) . '</tr>'; } else { $customfieldinfo_template = 'Subscribers_customfieldinfo_onecolumn'; $GLOBALS['CustomFieldInfo_1'] = ''; foreach ($customfield_display as $field) { $GLOBALS['CustomFieldInfo_1'] .= '<tr>' . $field . '</tr>'; } } $GLOBALS['CustomFieldInfo'] = $customfieldinfo . $this->ParseTemplate($customfieldinfo_template,true); } $GLOBALS['listid'] = $listid; $actions = $user->GetEventActivityType(); $GLOBALS['Actions'] = ''; foreach ($actions as $action) { $GLOBALS['Actions'] .= '<option value="' . htmlspecialchars($action,ENT_QUOTES, SENDSTUDIO_CHARSET) . '">'. htmlspecialchars($action,ENT_QUOTES, SENDSTUDIO_CHARSET) . "</option>"; } $GLOBALS['EventTypesJSON'] = GetJSON($actions); $GLOBALS['EventAddForm'] = $this->ParseTemplate('Subscriber_Event_Add',true,false); $GLOBALS['DatePickerJavascript'] = $this->ParseTemplate('ui.datepicker.custom_iem',true,false); if (IEM::sessionGet('gcal_allday')) { $GLOBALS['GoogleCalendarAllDay'] = 'true'; } else { $GLOBALS['GoogleCalendarAllDay'] = 'false'; } $GLOBALS['SubscriberEvents_Intro'] = GetLang('SubscriberEvents_Intro'); if ($user->HasAccess('Subscribers','EventSave')) { $GLOBALS['SubscriberEvents_Intro'] .= GetLang('SubscriberEvents_Intro_AddEvent'); } $this->ParseTemplate('Subscribers_View_Step2'); }
/** * EditCustomField * Allows editing of a custom field. This also handles whether to show more options (if it's a checkbox/dropdown) and so on. * * @param Int $fieldid Fieldid to load and edit. * * @see GetApi * @see CustomFields_API::Load * @see CustomFields_API::Settings * @see MoreOptions * @see MoreOptionsToShow * * @return Void Doesn't return anything, just prints out the results. */ function EditCustomField($fieldid=0) { if ($fieldid <= 0) { return false; } $api = $this->GetApi(); if (!$api->Load($fieldid)) { $GLOBALS['ErrorMessage'] = GetLang('CustomFieldDoesntExist'); $this->DenyAccess(); return; } $fieldapi = $this->GetApi('CustomFields_' . $api->fieldtype); $fieldapi->Load($fieldid); // Log this to "User Activity Log" IEM::logUserActivity($_SERVER['REQUEST_URI'], 'images/customfields.gif', $api->Settings['FieldName']); $GLOBALS['CustomFieldDetails'] = GetLang('EditCustomField'); $GLOBALS['Action'] = 'Edit&SubAction=Update&id=' . $fieldid; $GLOBALS['CancelButton'] = GetLang('EditCustomField_CancelPrompt'); $GLOBALS['Heading'] = GetLang('EditCustomField'); $GLOBALS['Intro'] = GetLang('EditCustomFieldIntro'); $type = $fieldapi->fieldtype; $GLOBALS['FieldType'] = GetLang('CustomFieldType_' . strtolower($type)); $GLOBALS['FieldName'] = htmlspecialchars($fieldapi->Settings['FieldName'], ENT_QUOTES, SENDSTUDIO_CHARSET); $fieldoptions = $fieldapi->GetOptions(); foreach ($fieldoptions as $name => $val) { if (!is_array($fieldapi->Settings[$name])) { $GLOBALS[$name] = htmlspecialchars($fieldapi->Settings[$name], ENT_QUOTES, SENDSTUDIO_CHARSET); continue; } foreach ($fieldapi->Settings[$name] as $p => $pname) { $GLOBALS['Display'.$p] = htmlspecialchars($pname, ENT_QUOTES, SENDSTUDIO_CHARSET); } } $required = ''; if ($fieldapi->Settings['FieldRequired']) { $required = ' CHECKED'; } $GLOBALS['FieldRequired'] = $required; if (isset($fieldapi->Settings['ApplyDefault'])) { $required = ' CHECKED'; } $GLOBALS['ApplyDefault'] = $required; $GLOBALS['CancelButton'] = GetLang('EditCustomField_CancelPrompt'); $currentlist = ''; $extralist = ''; $extralistdisplay = 'none'; $addmorelinkdisplay = ''; if (in_array($fieldapi->fieldtype, $this->MoreOptions)) { $extralist_template = 'CustomField_Form_Step2_' . $fieldapi->fieldtype . '_list_edit'; $keysize = sizeof($fieldapi->Settings['Key']); for ($i = 1; $i <= $keysize; $i++) { $GLOBALS['KeyNumber'] = $i; $GLOBALS['Key'] = htmlspecialchars($fieldapi->Settings['Key'][$i-1], ENT_QUOTES, SENDSTUDIO_CHARSET); $GLOBALS['Value'] = htmlspecialchars($fieldapi->Settings['Value'][$i-1], ENT_QUOTES, SENDSTUDIO_CHARSET); $currentlist .= $this->ParseTemplate($extralist_template, true, false); } $end = $i; $GLOBALS['Key'] = ''; $GLOBALS['Value'] = ''; $GLOBALS['KeyNumber'] = $i; $extralist .= $this->ParseTemplate($extralist_template, true, false); $GLOBALS['CurrentSize'] = $i; } $GLOBALS['CurrentList'] = $currentlist; $GLOBALS['ExtraList'] = $extralist; $GLOBALS['ExtraListDisplay'] = $extralistdisplay; $GLOBALS['AddMoreLinkDisplay'] = $addmorelinkdisplay; $GLOBALS['HideMoreLinkDisplay'] = (strtolower($addmorelinkdisplay) == 'none') ? '' : 'none'; // Load up the edit template specific to custom fields with multiple options if we're editing if (in_array($fieldapi->fieldtype, $this->MoreOptions) && isset($_GET['Action']) && $_GET['Action'] == 'Edit') { $type .= '_edit'; } $GLOBALS['SubForm'] = $this->ParseTemplate('CustomField_Form_Step2_' . $type, true, false); $this->ParseTemplate('CustomField_Form_Edit'); }
/** * PrintEditForm * Prints a form to edit a user. If you pass in a userid, it will load up that user and print their information. If you pass in the details array, it will prefill the form with that information (eg if you tried to create a user with a duplicate username). Also checks whether you are allowed to edit this user. If you are not an admin, you are only allowed to edit your own account. * * @param Int $userid Userid to load up. * @param Array $details Details to prefill the form with (in case there was a problem creating the user). * * @see User_API::Admin * @see User_API::Status * @see User_API::ListAdmin * @see User_API::EditOwnSettings * @see GetUser * * @return Void Returns nothing. If you don't have access to edit a particular user, it prints an error message and exits. Otherwise it prints the correct form (either edit-own or edit) and then exits. */ function PrintEditForm($userid = 0, $details = array()) { $thisuser = IEM::getCurrentUser(); if (!$thisuser->UserAdmin()) { if ($userid != $thisuser->userid) { $this->DenyAccess(); } if (!$thisuser->EditOwnSettings()) { $this->DenyAccess(); } } $user = $this->GetApi('User'); $listapi = $this->GetApi('Lists'); $all_lists = $listapi->GetLists(0, array('SortBy' => 'name', 'Direction' => 'asc'), false, 0, 0); $segmentapi = $this->GetApi('Segment'); $all_segments = $segmentapi->GetSegments(array('SortBy' => 'segmentname', 'Direction' => 'asc'), false, 0, 'all'); $templateapi = $this->GetApi('Templates'); $all_templates = $templateapi->GetTemplates(0, array('SortBy' => 'name', 'Direction' => 'asc'), false, 0, 0); $all_groups = API_USERGROUPS::getRecords(false, false, 0, 0, 'groupname'); $GLOBALS['CustomSmtpServer_Display'] = '0'; $GLOBALS['XmlPath'] = SENDSTUDIO_APPLICATION_URL . '/xml.php'; if ($userid > 0) { $user = GetUser($userid); if ($user->Get('userid') <= 0) { $GLOBALS['ErrorMessage'] = GetLang('UserDoesntExist'); $this->DenyAccess(); return; } $GLOBALS['UserID'] = $user->Get('userid'); $GLOBALS['UserName'] = htmlspecialchars($user->Get('username'), ENT_QUOTES, SENDSTUDIO_CHARSET); $GLOBALS['FullName'] = htmlspecialchars($user->Get('fullname'), ENT_QUOTES, SENDSTUDIO_CHARSET); $GLOBALS['EmailAddress'] = htmlspecialchars($user->Get('emailaddress'), ENT_QUOTES, SENDSTUDIO_CHARSET); $activity = $user->GetEventActivityType(); if (!is_array($activity)) { $activity = array(); } $GLOBALS['EventActivityType'] = implode("\n", $activity); $GLOBALS['MaxLists'] = $user->group->limit_list; $GLOBALS['MaxEmails'] = $user->group->limit_totalemailslimit; $GLOBALS['PerMonth'] = $user->group->limit_emailspermonth; $GLOBALS['PerHour'] = $user->group->limit_hourlyemailsrate; $GLOBALS['DisplayMaxLists'] = ''; if ($user->Get('maxlists') == 0) { $GLOBALS['LimitListsChecked'] = ' CHECKED'; $GLOBALS['DisplayMaxLists'] = 'none'; } $GLOBALS['DisplayEmailsPerHour'] = ''; if ($user->Get('perhour') == 0) { $GLOBALS['LimitPerHourChecked'] = ' CHECKED'; $GLOBALS['DisplayEmailsPerHour'] = 'none'; } $GLOBALS['DisplayEmailsPerMonth'] = ''; if ($user->Get('permonth') == 0) { $GLOBALS['LimitPerMonthChecked'] = ' CHECKED'; $GLOBALS['DisplayEmailsPerMonth'] = 'none'; } $GLOBALS['LimitMaximumEmailsChecked'] = ' CHECKED'; $GLOBALS['DisplayEmailsMaxEmails'] = 'none'; if (!$user->hasUnlimitedCredit()) { $GLOBALS['LimitMaximumEmailsChecked'] = ''; $GLOBALS['DisplayEmailsMaxEmails'] = ''; } if ($user->Get('usewysiwyg')) { $GLOBALS['UseWysiwyg'] = ' CHECKED'; $GLOBALS['UseXHTMLDisplay'] = ' style="display:block;"'; } else { $GLOBALS['UseXHTMLDisplay'] = ' style="display:none;"'; } if ($user->Get('enableactivitylog')) { $GLOBALS['EnableActivityLog'] = ' CHECKED'; } else { $GLOBALS['EnableActivityLog'] = ''; } $GLOBALS['UseXHTMLCheckbox'] = $user->Get('usexhtml')? ' CHECKED' : ''; $GLOBALS['Xmlapi'] = $user->Get('xmlapi')? ' CHECKED' : ''; $GLOBALS['XMLTokenDisplay'] = ' style="display:none;"'; if ($user->Get('xmlapi')) { $GLOBALS['XMLTokenDisplay'] = ' style="display:block;"'; } $GLOBALS['XmlToken'] = htmlspecialchars($user->Get('xmltoken'), ENT_QUOTES, SENDSTUDIO_CHARSET); $GLOBALS['TextFooter'] = $user->Get('textfooter'); $GLOBALS['HTMLFooter'] = $user->Get('htmlfooter'); $GLOBALS['SmtpServer'] = $user->Get('smtpserver'); $GLOBALS['SmtpUsername'] = $user->Get('smtpusername'); $GLOBALS['SmtpPassword'] = $user->Get('smtppassword'); $GLOBALS['SmtpPort'] = $user->Get('smtpport'); if ($GLOBALS['SmtpServer']) { $GLOBALS['CustomSmtpServer_Display'] = '1'; } $GLOBALS['googlecalendarusername'] = htmlspecialchars($user->Get('googlecalendarusername'), ENT_QUOTES, SENDSTUDIO_CHARSET); $GLOBALS['googlecalendarpassword'] = htmlspecialchars($user->Get('googlecalendarpassword'), ENT_QUOTES, SENDSTUDIO_CHARSET); $GLOBALS['FormAction'] = 'Action=Save&UserID=' . $user->userid; if (!$thisuser->UserAdmin()) { $smtp_access = $thisuser->HasAccess('User', 'SMTP'); $GLOBALS['ShowSMTPInfo'] = 'none'; $GLOBALS['DisplaySMTP'] = '0'; if ($smtp_access) { $GLOBALS['ShowSMTPInfo'] = ''; } if ($GLOBALS['SmtpServer']) { $GLOBALS['CustomSmtpServer_Display'] = '1'; if ($smtp_access) { $GLOBALS['DisplaySMTP'] = '1'; } } $this->ParseTemplate('User_Edit_Own'); return; } $GLOBALS['StatusChecked'] = ($user->Status()) ? ' CHECKED' : ''; $GLOBALS['ForceDoubleOptInChecked'] = ($user->Get('forcedoubleoptin')) ? ' CHECKED' : ''; $GLOBALS['ForceSpamCheckChecked'] = ($user->Get('forcespamcheck')) ? ' CHECKED' : ''; $GLOBALS['InfoTipsChecked'] = ($user->InfoTips()) ? ' CHECKED' : ''; $editown = ''; if ($user->UserAdmin()) { $editown = ' CHECKED'; } else { if ($user->EditOwnSettings()) { $editown = ' CHECKED'; } } $GLOBALS['EditOwnSettingsChecked'] = $editown; $timezone = $user->usertimezone; $GLOBALS['TimeZoneList'] = $this->TimeZoneList($timezone); $admintype = $user->AdminType(); $listadmintype = $user->ListAdminType(); $segmentadmintype = $user->SegmentAdminType(); $templateadmintype = $user->TemplateAdminType(); $admin = $user->Admin(); $listadmin = $user->ListAdmin(); $segmentadmin = $user->SegmentAdmin(); $templateadmin = $user->TemplateAdmin(); $permissions = $user->Get('permissions'); $area_access = $user->Get('access'); $GLOBALS['Heading'] = GetLang('EditUser'); $GLOBALS['Help_Heading'] = GetLang('Help_EditUser'); $GLOBALS['AdminNotifyEmailAddress'] = $user->Get('adminnotify_email'); if (empty($GLOBALS['AdminNotifyEmailAddress'])) { $GLOBALS['AdminNotifyEmailAddress'] = constant('SENDSTUDIO_EMAIL_ADDRESS'); } $GLOBALS['AdminNotifications_Send_Email'] = $user->Get('adminnotify_send_emailtext'); if (empty($GLOBALS['AdminNotifications_Send_Email'])) { $GLOBALS['AdminNotifications_Send_Email'] = GetLang('AdminNotifications_Send_Email'); } $GLOBALS['AdminNotifications_Import_Email'] = $user->Get('adminnotify_import_emailtext'); if (empty($GLOBALS['AdminNotifications_Import_Email'])) { $GLOBALS['AdminNotifications_Import_Email'] = GetLang('AdminNotifications_Import_Email'); } $GLOBALS['SendLimit'] = $user->Get('adminnotify_send_threshold'); $GLOBALS['ImportLimit'] = $user->Get('adminnotify_import_threshold'); if (empty($GLOBALS['SendLimit'])) { $GLOBALS['SendLimit'] = 1000; } if (empty($GLOBALS['ImportLimit'])) { $GLOBALS['ImportLimit'] = 1000; } $admin_flag = $user->Get('adminnotify_send_flag'); if ($user->Get('adminnotify_send_flag') == 1) { $GLOBALS['AdminNotificationsSend'] = 'CHECKED'; $GLOBALS['UseNotifySend'] = ''; } else { $GLOBALS['UseNotifySend'] = "style=display:none;"; } if ($user->Get('adminnotify_import_flag') == 1) { $GLOBALS['AdminNotificationsImport'] = 'CHECKED'; $GLOBALS['UseNotifyImport'] = ''; } else { $GLOBALS['UseNotifyImport'] = "style=display:none;"; } $GLOBALS['SmtpPort'] = $user->Get('smtpport'); // Log this to "User Activity Log" IEM::logUserActivity(IEM::urlFor('users', array('Action' => 'Edit', 'UserID' => $userid)), 'images/user.gif', $user->username); } else { $timezone = (isset($details['timezone'])) ? $details['timezone'] : SENDSTUDIO_SERVERTIMEZONE; $GLOBALS['TimeZoneList'] = $this->TimeZoneList($timezone); $activity = $thisuser->defaultEventActivityType; if (!is_array($activity)) { $activity = array(); } $GLOBALS['EventActivityType'] = implode("\n", $activity); $GLOBALS['FormAction'] = 'Action=Create'; if (!empty($details)) { foreach ($details as $area => $val) { $GLOBALS[$area] = $val; } } $GLOBALS['Heading'] = GetLang('CreateUser'); $GLOBALS['Help_Heading'] = GetLang('Help_CreateUser'); $listadmintype = 'c'; $segmentadmintype = 'c'; $admintype = 'c'; $templateadmintype = 'c'; $GLOBALS['DisplayMaxLists'] = 'none'; $GLOBALS['DisplayEmailsPerHour'] = 'none'; $GLOBALS['DisplayEmailsPerMonth'] = 'none'; $GLOBALS['DisplayEmailsMaxEmails'] = 'none'; $GLOBALS['MaxLists'] = '0'; $GLOBALS['PerHour'] = '0'; $GLOBALS['PerMonth'] = '0'; $GLOBALS['MaxEmails'] = '0'; $GLOBALS['StatusChecked'] = ' CHECKED'; $GLOBALS['ForceDoubleOptInChecked'] = ''; $GLOBALS['ForceSpamCheckChecked'] = ''; $GLOBALS['InfoTipsChecked'] = ' CHECKED'; $GLOBALS['EditOwnSettingsChecked'] = ' CHECKED'; $GLOBALS['LimitListsChecked'] = ' CHECKED'; $GLOBALS['LimitPerHourChecked'] = ' CHECKED'; $GLOBALS['LimitPerMonthChecked'] = ' CHECKED'; $GLOBALS['LimitMaximumEmailsChecked'] = ' CHECKED'; $GLOBALS['UseWysiwyg'] = ' CHECKED'; $GLOBALS['EnableLastViewed'] = ''; $GLOBALS['UseXHTMLCheckbox'] = ' CHECKED'; $GLOBALS['HTMLFooter'] = GetLang('Default_Global_HTML_Footer'); $GLOBALS['TextFooter'] = GetLang('Default_Global_Text_Footer'); $GLOBALS['EnableActivityLog'] = ' CHECKED'; $GLOBALS['Xmlapi'] = ''; $GLOBALS['XMLTokenDisplay'] = ' style="display:none;"'; $admin = $listadmin = $segmentadmin = $templateadmin = false; $permissions = array(); $area_access = array('lists' => array(), 'templates' => array(), 'segments' => array()); $GLOBALS['AdminNotifyEmailAddress'] = constant('SENDSTUDIO_EMAIL_ADDRESS'); $GLOBALS['UseNotifySend'] = "style=display:none;"; $GLOBALS['UseNotifyImport'] = "style=display:none;"; $GLOBALS['SendLimit'] = 1000; $GLOBALS['ImportLimit'] = 1000; $GLOBALS['AdminNotifications_Send_Email'] = GetLang('AdminNotifications_Send_Email'); $GLOBALS['AdminNotifications_Import_Email'] = GetLang('AdminNotifications_Import_Email'); } $agencyid = defined('IEM_SYSTEM_LICENSE_AGENCY') ? IEM_SYSTEM_LICENSE_AGENCY : ''; $available_users = $user->AvailableUsers(); $template = GetTemplateSystem(); $template->Assign('UserID', $user->userid); $template->Assign('groupid', $user->groupid); $template->Assign('canChangeUserGroup', !$user->isLastAdmin()); $template->Assign('AgencyEdition', get_agency_license_variables()); $template->Assign('EditOwn', ($user->userid != 0 && $user->userid == $thisuser->userid)); $template->Assign('TrialUser', $user->trialuser); $template->Assign('EditMode', !empty($user->userid)); $template->Assign('AvailableNormalUsers', isset($available_users['normal']) ? $available_users['normal'] : 0); $template->Assign('AvailableTrialUsers', isset($available_users['trial']) ? $available_users['trial'] : 0); $template->Assign('AvailableGroups', $all_groups); $template->Assign('record_groupid', $user->groupid); $template->Assign('DefaultIdTab', IEM::requestGetPOST('id_tab_num', 1, 'intval')); $template->Assign('showSmtpInfo', (bool) $user->smtpserver); $template->ParseTemplate('User_Form'); }
/** * Process * Works out where you are in the process and prints / processes the appropriate step. * * @see GetUser * @see User_API::HasAccess * @see PrintHeader * @see PopupWindows * @see PreviewWindow * @see ManageForms * @see EditForm * @see CreateForm */ function Process() { $GLOBALS['Message'] = ''; $action = (isset($_GET['Action'])) ? strtolower($_GET['Action']) : null; $user = GetUser(); $secondary_actions = array('preview', 'gethtml', 'view', 'finish', 'step2', 'step3', 'step4', 'step5', 'manage', 'processpaging'); if (in_array($action, $secondary_actions)) { $access = $user->HasAccess('Forms'); } else { $access = $user->HasAccess('Forms', $action); } $popup = (in_array($action, $this->PopupWindows)) ? true : false; if (!in_array($action, $this->DontShowHeader)) { $this->PrintHeader($popup); } /** * Check user permission to see whether or not they have access to the autoresponder */ $tempAPI = null; $tempCheckActions = array('view', 'copy', 'delete', 'edit', 'gethtml'); $tempID = null; if (isset($_GET['id'])) { $tempID = $_GET['id']; } elseif (isset($_POST['forms'])) { $tempID = $_POST['forms']; } if (!is_null($tempID)) { $_GET['id'] = $tempID; $_POST['forms'] = $tempID; if (!$user->Admin() && in_array($action, $tempCheckActions)) { if (!is_array($tempID)) { $tempID = array($tempID); } $tempAPI = $this->GetApi(); foreach ($tempID as $tempEachID) { $tempEachID = intval($tempEachID); if ($tempEachID == 0) { continue; } if (!$tempAPI->Load($tempEachID)) { continue; } if ($tempAPI->ownerid != $user->userid) { $this->DenyAccess(); return; } } } } unset($tempID); unset($tempCheckActions); unset($tempAPI); /** * ----- */ if (!$popup && !$access) { $this->DenyAccess(); return; } if ($action == 'processpaging') { $this->SetPerPage($_GET['PerPageDisplay']); $action = ''; } switch ($action) { case 'preview': $formapi = $this->GetApi(); $design = (isset($_POST['FormDesign'])) ? $_POST['FormDesign'] : false; $formtype = (isset($_POST['FormType'])) ? $_POST['FormType'] : false; $chooseformat = (isset($_POST['SubscriberChooseFormat'])) ? $_POST['SubscriberChooseFormat'] : false; $changeformat = false; if ($formtype == 'm') { if (isset($_POST['SubscriberChangeFormat'])) { $changeformat = true; } } $lists = array(); if (isset($_POST['IncludeLists'])) { $lists = $_POST['IncludeLists']; } if (!is_array($lists)) { $lists = array($lists); } $formapi->Set('lists', $lists); $field_order = array(); if (isset($_POST['hidden_fieldorder'])) { $order = explode(';', $_POST['hidden_fieldorder']); foreach ($order as $order_pos => $order_field) { if (!$order_field) { continue; } $field_order[] = $order_field; } } $usecaptcha = false; if (isset($_POST['UseCaptcha']) && in_array($formtype, array('s', 'u', 'm'))) { $usecaptcha = true; } $formapi->Set('customfields', $field_order); $formapi->Set('design', $design); $formapi->Set('formtype', $formtype); $formapi->Set('chooseformat', $chooseformat); $formapi->Set('changeformat', $changeformat); $formapi->Set('usecaptcha', $usecaptcha); $html = $formapi->GetHTML(true); echo $html; exit(); break; case 'gethtml': $this->GetFormHTML(); break; case 'view': $this->PrintHeader(true); $id = (isset($_GET['id'])) ? (int)$_GET['id'] : false; $formapi = $this->GetApi(); $loaded = $formapi->Load($id); if (!$id || !$loaded) { $GLOBALS['Error'] = GetLang('NoSuchForm'); $html = $this->ParseTemplate('ErrorMsg', true, false); } else { // Log this to "User Activity Log" $logURL = SENDSTUDIO_APPLICATION_URL . '/admin/index.php?Page=' . __CLASS__ . '&Action=Edit&id=' . $_GET['id']; IEM::logUserActivity($logURL, 'images/forms_view.gif', $formapi->name); $formtype = $formapi->Get('formtype'); // if it's a 'm'odify-details form or 'f'riend form, // get the user modified html instead of the built in html. if (in_array($formtype, array('m', 'f'))) { $html = $formapi->Get('formhtml'); } else { $html = $formapi->GetHTML(true); } } header('Content-type: text/html; charset="' . SENDSTUDIO_CHARSET . '"'); print '<html><head><meta http-equiv="Content-Type" content="text/html; charset='.SENDSTUDIO_CHARSET.'"></head><body>'; echo $html; print '</body></html>'; exit(); break; case 'copy': $id = (isset($_GET['id'])) ? (int)$_GET['id'] : 0; $api = $this->GetApi(); $result = $api->Copy($id); if (!$result) { $GLOBALS['Error'] = GetLang('FormCopyFail'); $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); } else { $GLOBALS['Message'] = $this->PrintSuccess('FormCopySuccess'); } $this->ManageForms(); break; case 'delete': $formlist = (isset($_POST['forms'])) ? $_POST['forms'] : array(); if (isset($_GET['id'])) { $formlist = $_GET['id']; } if (!is_array($formlist)) { $formlist = array($formlist); } $formlist = array_map('intval', $formlist); $this->RemoveForms($formlist); break; case 'finish': $session_form = IEM::sessionGet('Form'); if (!$session_form) { $this->ManageForms(); break; } $errorpage = array(); $errorpage['html'] = $_POST['errorhtml_html']; if ($_POST['userrorhtmlurl'] == '1') { $errorpage['url'] = $_POST['errorpageurl']; } else { $errorpage['url'] = 'http://'; } foreach (array('ThanksPage', 'ErrorPage', 'ConfirmPage') as $p => $pagename) { if (!isset($session_form['Pages'][$pagename])) { $session_form['Pages'][$pagename] = array(); } } $formapi = $this->GetApi(); if (isset($session_form['FormID']) && $session_form['FormID'] > 0) { $formapi->Load($session_form['FormID']); /** * If the email text for the confirm page is empty, most likely we've changed the form from requiring a confirmation to not requiring one. * In that case, we'll get what the page was before so we can at least fill it in if the form is changed back. */ if (empty($session_form['Pages']['ConfirmPage']['emailtext'])) { $confirm_page = $formapi->GetPage('ConfirmPage'); foreach (array('html', 'url', 'sendfromname', 'sendfromemail', 'replytoemail', 'bounceemail', 'emailsubject', 'emailhtml', 'emailtext') as $k => $area) { $session_form['Pages']['ConfirmPage'][$area] = $confirm_page[$area]; } } /** * We then do the same for the thanks page. */ if (empty($session_form['Pages']['ThanksPage']['emailtext'])) { $thanks_page = $formapi->GetPage('ThanksPage'); foreach (array('sendfromname', 'sendfromemail', 'replytoemail', 'bounceemail', 'emailsubject', 'emailhtml', 'emailtext') as $k => $area) { $session_form['Pages']['ThanksPage'][$area] = $thanks_page[$area]; } } } $formhtml = ''; if (isset($_POST['formhtml'])) { $formhtml = $_POST['formhtml']; } $session_form['Pages']['ErrorPage'] = $errorpage; $formapi->Set('formtype', $session_form['FormType']); $formapi->Set('pages', $session_form['Pages']); $formapi->Set('lists', $session_form['IncludeLists']); $formapi->Set('customfields', $session_form['CustomFields']); $formapi->Set('name', $session_form['FormName']); $formapi->Set('design', $session_form['FormDesign']); $formapi->Set('chooseformat', $session_form['SubscriberChooseFormat']); $formapi->Set('changeformat', $session_form['SubscriberChangeFormat']); $formapi->Set('requireconfirm', $session_form['RequireConfirmation']); $formapi->Set('sendthanks', $session_form['SendThanks']); $formapi->Set('fieldorder', $session_form['CustomFieldsOrder']); $formapi->Set('contactform', $session_form['ContactForm']); $formapi->Set('usecaptcha', $session_form['UseCaptcha']); $formapi->Set('formhtml', $formhtml); if (isset($session_form['FormID']) && $session_form['FormID'] > 0) { $result = $formapi->Save(); if (!$result) { $GLOBALS['Error'] = GetLang('UnableToUpdateForm'); $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); } else { $GLOBALS['Message'] = $this->PrintSuccess('FormUpdated'); } } else { $formapi->ownerid = $user->userid; $result = $formapi->Create(); if (!$result) { $GLOBALS['Error'] = GetLang('UnableToCreateForm'); $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); } else { $GLOBALS['Message'] = $this->PrintSuccess('FormCreated'); } } if (in_array($formapi->formtype, array('s', 'u'))) { $this->GetFormHTML($formapi); } else { $this->ManageForms(); } break; case 'step5': $session_form = IEM::sessionGet('Form'); $sendfriendsettings = array(); $sendfriendsettings['emailhtml'] = $_POST['myDevEditControl_html']; $sendfriendsettings['emailtext'] = $_POST['TextContent']; $thankssettings = array(); $thankssettings['html'] = $_POST['thankspage_html_html']; $thankssettings['url'] = $_POST['thankspageurl']; $session_form['Pages']['SendFriendPage'] = $sendfriendsettings; $session_form['Pages']['ThanksPage'] = $thankssettings; IEM::sessionSet('Form', $session_form); $this->ShowFinalStep(); break; case 'step4': $session_form = IEM::sessionGet('Form'); $thankssettings = array(); if ($session_form['SendThanks']) { $thankssettings['sendfromname'] = $_POST['sendfromname']; $thankssettings['sendfromemail'] = $_POST['sendfromemail']; $thankssettings['replytoemail'] = $_POST['replytoemail']; $thankssettings['bounceemail'] = $_POST['bounceemail']; $thankssettings['emailsubject'] = $_POST['thankssubject']; $thankssettings['emailhtml'] = $_POST['thanksemail_html_html']; $thankssettings['emailtext'] = $_POST['TextContent']; } $thankssettings['html'] = $_POST['thankspage_html_html']; if ($_POST['usethankspageurl'] == '1') { $thankssettings['url'] = $_POST['thankspageurl']; } else { $thankssettings['url'] = 'http://'; } $session_form['Pages']['ThanksPage'] = $thankssettings; IEM::sessionSet('Form', $session_form); $this->ShowFinalStep(); break; case 'step3': $session_form = IEM::sessionGet('Form'); $confirmsettings = array(); $confirmsettings['html'] = $_POST['confirmhtml_html']; if ($_POST['useconfirmpageurl'] == '1') { $confirmsettings['url'] = $_POST['confirmpageurl']; } else { $confirmsettings['url'] = 'http://'; } $confirmsettings['sendfromname'] = $_POST['sendfromname']; $confirmsettings['sendfromemail'] = $_POST['sendfromemail']; $confirmsettings['replytoemail'] = $_POST['replytoemail']; $confirmsettings['bounceemail'] = $_POST['bounceemail']; $confirmsettings['emailsubject'] = $_POST['confirmsubject']; $confirmsettings['emailhtml'] = $_POST['confirmemail_html_html']; $confirmsettings['emailtext'] = $_POST['TextContent']; $session_form['Pages']['ConfirmPage'] = $confirmsettings; IEM::sessionSet('Form', $session_form); if ($session_form['SendThanks']) { $this->ShowThanksStep(); } $this->ShowThanksHTML(); break; case 'step2': $session_form = array(); $optional_fields = array(); if (isset($_POST['FormType'])) { $formtype = $_POST['FormType']; $session_form['ContactForm'] = false; $session_form['UseCaptcha'] = false; switch ($formtype) { case 'u': $checkfields = array('FormName', 'FormDesign', 'FormType', 'IncludeLists'); $optional_fields = array('RequireConfirmation', 'SendThanks', 'UseCaptcha'); $session_form['SubscriberChangeFormat'] = false; $session_form['SubscriberChooseFormat'] = ''; break; case 'm': $session_form['RequireConfirmation'] = false; $session_form['SendThanks'] = false; $checkfields = array('FormName', 'FormDesign', 'FormType', 'IncludeLists'); $optional_fields = array('SubscriberChangeFormat', 'UseCaptcha'); $session_form['SubscriberChooseFormat'] = ''; break; case 'f': $session_form['RequireConfirmation'] = false; $session_form['SendThanks'] = false; $session_form['IncludeLists'] = array(); $session_form['SubscriberChangeFormat'] = false; $session_form['SubscriberChooseFormat'] = ''; $checkfields = array('FormName', 'FormDesign', 'FormType'); break; default: $session_form['SubscriberChangeFormat'] = false; $optional_fields = array('ContactForm', 'RequireConfirmation', 'SendThanks', 'UseCaptcha'); $checkfields = array('FormName', 'FormDesign', 'FormType', 'SubscriberChooseFormat', 'IncludeLists'); } } $valid = true; $errors = array(); foreach ($checkfields as $p => $field) { if (!isset($_POST[$field])) { $valid = false; $errors[] = GetLang('Form'.$field.'IsNotValid'); break; } if (!is_array($_POST[$field])) { if ($_POST[$field] == '') { $valid = false; $errors[] = GetLang('Form'.$field.'IsNotValid'); break; } else { $value = $_POST[$field]; $session_form[$field] = $value; } } else { if (empty($_POST[$field])) { $valid = false; $errors[] = GetLang('Form'.$field.'IsNotValid'); break; } else { $session_form[$field] = $_POST[$field]; } } } foreach ($optional_fields as $p => $field) { if (isset($_POST[$field])) { $session_form[$field] = $_POST[$field]; } else { $session_form[$field] = false; } } if (isset($_GET['id'])) { $session_form['FormID'] = (int)$_GET['id']; } if (!$valid) { if (!isset($session_form['FormID'])) { $id = 0; $GLOBALS['Error'] = GetLang('UnableToCreateForm') . '<br/>- ' . implode('<br/>- ',$errors); } else { $id = $session_form['FormID']; $GLOBALS['Error'] = GetLang('UnableToUpdateForm') . '<br/>- ' . implode('<br/>- ',$errors); } $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); $this->Form_Step1($id); break; } $session_form['CustomFieldsOrder'] = array(); if (isset($_POST['hidden_fieldorder'])) { $order = explode(';', $_POST['hidden_fieldorder']); foreach ($order as $order_pos => $order_field) { if (!$order_field) { continue; } $session_form['CustomFieldsOrder'][] = $order_field; } } $session_form['CustomFields'] = array(); $ftypes = array('s','m'); if (in_array($session_form['FormType'], $ftypes)) { foreach ($session_form['CustomFieldsOrder'] as $each) { if (is_numeric($each)) { array_push($session_form['CustomFields'], $each); } } } IEM::sessionSet('Form', $session_form); if ($session_form['FormType'] == 'f') { $this->ShowFriendStep(); $this->ShowThanksHTML('Step5'); break; } if ($session_form['RequireConfirmation'] == '1') { $this->ShowConfirmationStep(); break; } if ($session_form['SendThanks'] == '1') { $this->ShowThanksStep(); } if (isset($session_form['FormID']) && $session_form['FormID'] > 0) { $GLOBALS['CancelButton'] = GetLang('EditFormCancelButton'); $GLOBALS['Heading'] = GetLang('EditForm'); $GLOBALS['Intro'] = GetLang('ThanksPageIntro_Edit'); if ($session_form['FormType'] == 'm' || $session_form['SendThanks'] != 1) { $GLOBALS['Intro'] = GetLang('ThanksPageIntro_Edit_NoEmail'); } } else { $GLOBALS['CancelButton'] = GetLang('CreateFormCancelButton'); $GLOBALS['Heading'] = GetLang('CreateForm'); $GLOBALS['Intro'] = GetLang('ThanksPageIntro'); if ($session_form['FormType'] == 'm' || $session_form['SendThanks'] != 1) { $GLOBALS['Intro'] = GetLang('ThanksPageIntro_NoEmail'); } } $this->ShowThanksHTML(); break; case 'edit': IEM::sessionRemove('Form'); $id = (isset($_GET['id'])) ? (int)$_GET['id'] : 0; $this->Form_Step1($id); break; case 'create': IEM::sessionRemove('Form'); $this->Form_Step1(); break; default: $this->ManageForms(); } if (!in_array($action, $this->DontShowHeader)) { $this->PrintFooter($popup); } }
/** * ManageSubscribers_Step3 * Prints out the subscribers for the list chosen and criteria selected in steps 1 & 2. This handles sorting, paging and searching. If you are coming in for the first time, it remembers your search criteria in the session. If you change number per page, sorting criteria, it fetches the search criteria from the session again before continuing. * * @see ManageSubscribers_Step2 * @see GetApi * @see GetPerPage * @see GetCurrentPage * @see GetSortDetails * @see Subscribers_API::FetchSubscribers * @see SetupPaging * @see Lists_API::Load * * @return Void Doesn't return anything. Prints out the results and that's it. */ function ManageSubscribers_Step3($change=false) { $subscriber_api = $this->GetApi('Subscribers'); $user = IEM::getCurrentUser(); $search_info = IEM::sessionGet('Search_Subscribers'); $this->SetupGoogleCalendar(); $user_lists = $user->GetLists(); if (!isset($GLOBALS['Message'])) { $GLOBALS['Message'] = ''; } // if we are posting a form, we are most likely resetting the search criteria. // we are also resetting the search criteria once we detect "Lists" variable in the GET Request $resetsearch = ((isset($_POST) && !empty($_POST)) || isset($_GET['Lists']) || isset($_GET['Segment'])) ? true : false; // except if we're changing paging! if (isset($_GET['SubAction'])) { $subaction = strtolower($_GET['SubAction']); if ($subaction == 'processpaging' || $subaction == 'change') { $resetsearch = false; } } if (!$search_info || $resetsearch) { $this->SetCurrentPage(1); // forget current page $search_details = array(); if (isset($_POST['emailaddress']) && $_POST['emailaddress'] != '') { $search_details['Email'] = trim($_POST['emailaddress']); } if (isset($_POST['format']) && $_POST['format'] != '-1') { $search_details['Format'] = $_POST['format']; } if (isset($_POST['confirmed']) && $_POST['confirmed'] != '-1') { $search_details['Confirmed'] = $_POST['confirmed']; } if (isset($_POST['status']) && $_POST['status'] != '-1') { $search_details['Status'] = $_POST['status']; } if (isset($_POST['datesearch']) && isset($_POST['datesearch']['filter'])) { $search_details['DateSearch'] = $_POST['datesearch']; $search_details['DateSearch']['StartDate'] = AdjustTime(array(0, 0, 1, $_POST['datesearch']['mm_start'], $_POST['datesearch']['dd_start'], $_POST['datesearch']['yy_start'])); $search_details['DateSearch']['EndDate'] = AdjustTime(array(0, 0, 1, $_POST['datesearch']['mm_end'], $_POST['datesearch']['dd_end'], $_POST['datesearch']['yy_end'])); } $customfields = array(); if (isset($_POST['CustomFields']) && !empty($_POST['CustomFields'])) { $customfields = $_POST['CustomFields']; } $search_details['CustomFields'] = $customfields; if (isset($_GET['Lists']) || isset($_GET['List'])) { $search_details['List'] = isset($_GET['Lists'])? $_GET['Lists'] : $_GET['List']; } else { $search_details['List'] = 'any'; } // Get segment, and make sure user have access permission to it if ($user->HasAccess('Segments')) { $search_details['Segment'] = null; if (isset($_GET['Segment'])) { $tempSegmentList = array_keys($user->GetSegmentList()); $tempSegment = $_GET['Segment']; // Make sure that selected segment is allowed for user if (!is_array($tempSegment)) { if (!in_array($tempSegment, $tempSegmentList)) { $tempSegment = null; } } else { $tempSegment = array_intersect($tempSegment, $tempSegmentList); } if (!is_null($tempSegment)) { $search_details['Segment'] = $tempSegment; } } } if (is_array($search_details['List'])) { // Make sure that "any" is not selected when you are selecting multiple list if (count($search_details['List']) > 1) { if (($index = array_search('any', $search_details['List'])) !== false) { unset($search_details['List'][$index]); } } // If the array only contain 1 id, make take it out of the array if (count($search_details['List']) == 1) { $search_details['List'] = array_pop($search_details['List']); } } // Get allowable list if (!$user->ListAdmin()) { $search_details['AvailableLists'] = array_keys($user_lists); } if (is_array($search_details['List'])) { // Make sure IDs are numerics if (is_array($search_details['List'])) { $listIDs = array(); foreach ($search_details['List'] as $id) { array_push($listIDs, intval($id)); } $search_details['List'] = $listIDs; } } // Make sure that user can only select newsletter from his/her allowable list if (isset($search_details['AvailableLists']) && (is_numeric($search_details['List']) || is_array($search_details['List']))) { if (is_array($search_details['List'])) { $search_details['List'] = array_intersect($search_details['List'], $search_details['AvailableLists']); } else { $temp = in_array($search_details['List'], $search_details['AvailableLists']); if (!$temp) { $search_details['List'] = null; } } if (empty($search_details['List'])) { $search_details['List'] = $search_details['AvailableLists']; } // Make sure to unset available list, otherwise Subscribers API will think // we are looking to query all list unset($search_details['AvailableLists']); } if (isset($_POST['clickedlink']) && isset($_POST['linkid'])) { $search_details['LinkType'] = 'clicked'; if (isset($_POST['linktype']) && $_POST['linktype'] == 'not_clicked') { $search_details['LinkType'] = 'not_clicked'; } $search_details['Link'] = $_POST['linkid']; } if (isset($_POST['openednewsletter']) && isset($_POST['newsletterid'])) { $search_details['OpenType'] = 'opened'; if (isset($_POST['opentype']) && $_POST['opentype'] == 'not_opened') { $search_details['OpenType'] = 'not_opened'; } $search_details['Newsletter'] = $_POST['newsletterid']; } if (isset($_POST['Search_Options'])) { $search_details['Search_Options'] = $_POST['Search_Options']; } // Flag to differentiate where the search details are coming from $GLOBALS['Search'] = ''; if (!empty($_POST) || !empty($search_details['Email'])) { $search_details['Source'] = 'search'; $GLOBALS['Search'] = isset($search_details['Email'])? $search_details['Email'] : ''; } else { if (!empty($search_details['Segment'])) { $search_details['Source'] = 'segment'; } else { $search_details['Source'] = 'list'; } } IEM::sessionSet('Search_Subscribers', $search_details); } $search_info = IEM::sessionGet('Search_Subscribers'); // Process segmenting information if (!empty($search_info['Segment'])) { $segmentAPI = $this->GetApi('Segment'); if (is_array($search_info['Segment'])) { $search_info['List'] = $segmentAPI->GetMailingListUsed($search_info['Segment']); } else { $segmentAPI->Load($search_info['Segment']); $search_info['List'] = $segmentAPI->GetMailingListUsed(); } $subscriber_header_template = 'Subscribers_Manage_AnyList'; $subscriber_row_template = 'Subscribers_Manage_AnyList_Row'; $GLOBALS['Segment'] = is_array($search_info['Segment'])? implode('&Segment[]=', $search_info['Segment']) : $search_info['Segment']; } $GLOBALS['List'] = is_array($search_info['List'])? implode('&Lists[]=', $search_info['List']) : $search_info['List']; // Load visible fields for each list if (isset($_POST['VisibleFields'])) { IEM::sessionSet('visiblefields', $_POST['VisibleFields']); $visiblefields_set = $_POST['VisibleFields']; } elseif (IEM::sessionGet('visiblefields')) { $visiblefields_set = IEM::sessionGet('visiblefields'); } else { list(,$visiblefields_set) = $this->GetVisibleFields($search_info['List']); } $perpage = $this->GetPerPage(); $pageid = $this->GetCurrentPage(); $sortinfo = $this->GetSortDetails(); // Check if we are sorting by a custom field if (is_numeric($sortinfo['SortBy'])) { if (in_array($sortinfo['SortBy'], $visiblefields_set)) { $sortinfo['CustomFields'] = array($sortinfo['SortBy']); $sortinfo['SortBy'] = 'sd.data'; } else { $sortinfo['SortBy'] = 'emailaddress'; } } if (!empty($search_info['Segment'])) { $tempEmail = null; if (!empty($search_details['Email'])) { $tempEmail = $search_details['Email']; } $subscriber_list = $subscriber_api->FetchSubscribersFromSegment($pageid, $perpage, $search_info['Segment'], $sortinfo, $tempEmail); } else { $subscriber_list = $subscriber_api->FetchSubscribers($pageid, $perpage, $search_info, $sortinfo); } $subscriber_edited = (isset($_GET['Edit'])) ? true : false; $totalsubscribers = $subscriber_list['count']; unset($subscriber_list['count']); if ($subscriber_edited) { $GLOBALS['Message'] .= $this->PrintSuccess('SubscriberEditSuccess'); } $GLOBALS['TotalSubscriberCount'] = $this->FormatNumber($totalsubscribers); $tempMessageStringSubfix = ''; switch ($search_info['Source']) { case 'list': if ($search_info['List'] == 'any') { $tempMessageStringSubfix = 'AllList_'; } elseif (is_array($search_info['List'])) { $tempMessageStringSubfix = 'ManyList_'; } else { $tempMessageStringSubfix = 'OneList_'; } break; case 'segment': $tempMessageStringSubfix = 'Segment_'; break; } $DisplayPage = $pageid; $GLOBALS['PAGE'] = 'Subscribers&Action=Manage&SubAction=Step3'; // set up paging before we add the Lists[]= part, as we never want paging links to reset a search $this->SetupPaging($totalsubscribers, $DisplayPage, $perpage); $GLOBALS['FormAction'] = 'SubAction=ProcessPaging'; $paging = $this->ParseTemplate('Paging', true, false); if (!empty($search_info['Segment'])) { $GLOBALS['PAGE'] .= '&Segment[]=' . $GLOBALS['Segment']; } else { $GLOBALS['PAGE'] .= '&Lists[]=' . $GLOBALS['List']; } $subscriberdetails = ''; // If no visible fields are selected, make emailaddress visible if (count($visiblefields_set) == 0) { array_unshift($visiblefields_set,'emailaddress'); } // Make "View" PopUp menu $GLOBALS['SubscriberViewPickerMenu'] = $this->MakeViewPopupMenu($search_info, $user); $loaded_customfields = array(); $customfields = array(); $visiblefields = array(); $visiblefields_lists = array(); $subscriber_header_template = 'Subscribers_Manage_AnyList'; $subscriber_row_template = 'Subscribers_Manage_AnyList_Row'; if (!$user->HasAccess('Subscribers', 'Add')) { $GLOBALS['AddButtonDisplay'] = 'none'; } if (!empty($search_info['Segment'])) { $segmentAPI = $this->GetApi('Segment'); $tempSegmentID = $search_info['Segment']; $usedLists = array(); if (!is_array($tempSegmentID)) { $tempSegmentID = array($tempSegmentID); } foreach ($tempSegmentID as $id) { $segmentAPI->Load($id); $tempList = $segmentAPI->GetMailingListUsed(); $usedLists = array_merge($usedLists, $tempList); } $search_info['List'] = $usedLists; /** * Segments contain lists (as they can go across multiple lists) */ $listids = $search_info['List']; if ($search_info['Source'] == 'search' || is_array($search_info['Segment'])) { $title = GetLang('SubscribersManageSearchResult'); } else { $title = sprintf(GetLang('SubscribersManageSegment'), htmlspecialchars($segmentAPI->segmentname, ENT_QUOTES, SENDSTUDIO_CHARSET)); } $GLOBALS['AddButtonURL'] = 'index.php?Page=Subscribers&Action=Add'; } else { /** * Only viewing one list here. */ if (is_numeric($search_info['List'])) { $listids = array($search_info['List']); $subscriber_header_template = 'Subscribers_Manage'; $subscriber_row_template = 'Subscribers_Manage_Row'; $GLOBALS['ColumnCount'] = 3; if ($search_info['Source'] == 'search') { $title = GetLang('SubscribersManageSearchResult'); } else { $listname = $user_lists[$search_info['List']]['name']; $title = sprintf(GetLang('SubscribersManageSingleList'), htmlspecialchars($listname, ENT_QUOTES, SENDSTUDIO_CHARSET)); } $GLOBALS['AddButtonURL'] = 'index.php?Page=Subscribers&Action=Add&SubAction=Step2&list=' . $search_info['List']; } else { /** * If we're viewing more than one list, use those id's. */ if (is_array($search_info['List'])) { $listids = $search_info['List']; $title = GetLang('SubscribersManageMultipleList'); } else { /** * The default is all of the users lists. */ $listids = array_keys($user_lists); $title = GetLang('SubscribersManageAnyList'); } /** * Override the title if we're coming from a search result. */ if ($search_info['Source'] == 'search') { $title = GetLang('SubscribersManageSearchResult'); } $GLOBALS['AddButtonURL'] = 'index.php?Page=Subscribers&Action=Add'; $GLOBALS['ColumnCount'] = 4; } } $GLOBALS['SubscribersManage'] = $title; // Log this to "User Activity Log" except when is deleting. if (!(isset($_GET['SubAction']) && strtolower($_GET['SubAction']) != "delete")) { IEM::logUserActivity($_SERVER['REQUEST_URI'], 'images/lists_view.gif', $title); } if ($totalsubscribers < 1) { IEM::sessionRemove('Search_Subscribers'); if ($subscriber_edited) { $GLOBALS['Message'] .= $this->PrintSuccess('SubscriberEditSuccess'); } else { $GLOBALS['Message'] .= $this->PrintSuccess('NoSubscribersMatch', true); } $this->ParseTemplate('Subscribers_Manage_Empty'); return; } if ($totalsubscribers == 1) { $GLOBALS['Message'] .= $this->PrintSuccess('Subscribers_' . $tempMessageStringSubfix . 'FoundOne'); } else { $GLOBALS['Message'] .= $this->PrintSuccess('Subscribers_' . $tempMessageStringSubfix . 'FoundMany', $GLOBALS['TotalSubscriberCount']); } $CustomFieldsApi = $this->GetApi('CustomFields'); $customfields_for_all_lists = $CustomFieldsApi->GetCustomFieldsForLists($listids, $visiblefields_set); $listNames = array(); foreach ($listids as $listid) { array_push($listNames, $user_lists[$listid]['name']); foreach ($this->BuiltinFields as $key => $name) { if (in_array($key,$visiblefields_set) && !in_array($key,$visiblefields)) { if (!isset($visiblefields_lists[$key])) { $visiblefields_lists[$key] = array(); } $visiblefields_lists[$key][] = (int)$listid; $visiblefields[] = $key; } } foreach ($customfields_for_all_lists as $key => $details) { if (in_array($details['fieldid'],$visiblefields_set)) { if (!isset($visiblefields_lists[$details['fieldid']])) { $visiblefields_lists[$details['fieldid']] = array(); } $visiblefields_lists[$details['fieldid']][] = (int)$listid; if (!in_array($details['fieldid'],$visiblefields)) { $visiblefields[] = $details['fieldid']; } } } } $customfield_data = array(); $GLOBALS['Columns'] = ''; foreach ($visiblefields as $name) { if (!in_array($name,$visiblefields_set)) { continue; } if (is_numeric($name)) { $customfieldinfo = array(); foreach ($customfields_for_all_lists as $pos => $details) { if ($details['fieldid'] === $name) { $customfieldinfo = $details; break; } } /** * Check we got some data here. * We may have just changed the lists we are viewing and the custom field isn't associated with this new list */ if (!empty($customfieldinfo)) { $GLOBALS['FieldName'] = htmlspecialchars($customfieldinfo['name'], ENT_QUOTES, SENDSTUDIO_CHARSET); $subfield = $CustomFieldsApi->LoadSubField($customfieldinfo); $loaded_customfields[$name] = $subfield; $customfield_data[] = array ( 'fieldid' => $name, 'fieldtype' => $subfield->fieldtype, 'defaultvalue' => $subfield->GetDefaultValue(), 'name' => $subfield->GetFieldName(), ); } } elseif (in_array($name,array_keys($this->BuiltinFields))) { $GLOBALS['FieldName'] = GetLang($this->BuiltinFields[$name]); } if ($name == 'emailaddress') { $GLOBALS['Width'] = 'width="17%"'; } else { $GLOBALS['Width'] = ''; } $GLOBALS['SortName'] = htmlspecialchars($name, ENT_QUOTES, SENDSTUDIO_CHARSET); $GLOBALS['Columns'] .= $this->ParseTemplate('Subscribers_Manage_Column_Sortable',true,false); } if (isset($GLOBALS['Segment'])) { $GLOBALS['URLQueryString'] = '&Segment[]=' . $GLOBALS['Segment']; } else { $GLOBALS['URLQueryString'] = '&Lists[]=' . $GLOBALS['List']; } $actions = $user->GetEventActivityType(); $GLOBALS['Actions'] = ''; foreach ($actions as $action) { $GLOBALS['Actions'] .= '<option value="' . htmlspecialchars($action,ENT_QUOTES, SENDSTUDIO_CHARSET) . '">'. htmlspecialchars($action,ENT_QUOTES, SENDSTUDIO_CHARSET) . "</option>"; } $GLOBALS['EventTypesJSON'] = GetJSON($actions); $GLOBALS['EventAddForm'] = $this->ParseTemplate('Subscriber_Event_Add',true,false); $GLOBALS['EventJavascript'] = $this->ParseTemplate('Subscribers_Events_Javascript',true,false); $GLOBALS['DatePickerJavascript'] = $this->ParseTemplate('ui.datepicker.custom_iem',true,false); $template = $this->ParseTemplate($subscriber_header_template, true, false); $GLOBALS['List'] = $search_info['List']; $subscriber_customfields = array(); $customfield_ids = $visiblefields; $customfield_ids = $subscriber_api->CheckIntVars($customfield_ids); if (!empty($customfield_ids)) { $subids = array(); foreach ($subscriber_list['subscriberlist'] as $info) { $subids[] = $info['subscriberid']; } $subscriber_customfields = $subscriber_api->GetAllSubscriberCustomFields($listids, array(), $subids, $customfield_ids); unset($subids); } if (!isset($GLOBALS['ColumnCount'])) { $GLOBALS['ColumnCount'] = 0; } $GLOBALS['ColumnCount'] += count($visiblefields); foreach ($subscriber_list['subscriberlist'] as $pos => $subscriberinfo) { $GLOBALS['Columns'] = ''; $GLOBALS['FieldValue'] = ''; $subscriberfields = array(); foreach ($visiblefields as $fieldname) { switch ($fieldname) { case 'emailaddress': $GLOBALS['FieldValue'] = htmlspecialchars($subscriberinfo[$fieldname], ENT_QUOTES, SENDSTUDIO_CHARSET); break; case 'subscribedate': $GLOBALS['FieldValue'] = $this->PrintDate($subscriberinfo['subscribedate']); break; case 'format': $GLOBALS['FieldValue'] = ($subscriberinfo['format'] == 't') ? GetLang('Format_Text') : GetLang('Format_HTML'); break; case 'confirmed': $GLOBALS['FieldValue'] = ($subscriberinfo['confirmed'] == '1') ? GetLang('Confirmed') : GetLang('Unconfirmed'); break; case 'status': $status = GetLang('Active'); if ($subscriberinfo['unsubscribed'] > 0) { $status = GetLang('Unsubscribed'); } if ($subscriberinfo['bounced'] > 0) { $status = GetLang('Bounced'); } $GLOBALS['FieldValue'] = $status; break; default: $GLOBALS['FieldValue'] = ' '; if (is_numeric($fieldname)) { $subfield = $loaded_customfields[$fieldname]; $subid = $subscriberinfo['subscriberid']; /** * If there is no custom field for this subscriber, go to the next field. * This could happen if you view all lists but a field is only associated with one particular list */ if (!isset($subscriber_customfields[$subid])) { continue; } foreach ($subscriber_customfields[$subid] as $cf_p => $cf_details) { if ($cf_details['fieldid'] != $fieldname) { continue; } $GLOBALS['FieldValue'] = htmlspecialchars($subfield->GetRealValue($cf_details['data'],','), ENT_QUOTES, SENDSTUDIO_CHARSET); } } } $GLOBALS['Columns'] .= $this->ParseTemplate('Subscribers_Manage_Row_Column',true,false); } // if we are searching "any" list then we need to adjust the link. if (isset($subscriberinfo['listid'])) { $GLOBALS['List'] = $subscriberinfo['listid']; } if (isset($subscriberinfo['listname'])) { $GLOBALS['MailingListName'] = htmlspecialchars($subscriberinfo['listname'], ENT_QUOTES, SENDSTUDIO_CHARSET); } $GLOBALS['subscriberid'] = $subscriberinfo['subscriberid']; $GLOBALS['SubscriberID'] = $subscriberinfo['subscriberid']; $GLOBALS['EditSubscriberID'] = $subscriberinfo['subscriberid']; if (array_key_exists('Segment', $search_info) && $search_info['Segment'] != 0) { $GLOBALS['SegmentID'] = $search_info['Segment']; $GLOBALS['ExtraParameter'] = '&SegmentID=' . $search_info['Segment']; } else { $GLOBALS['SegmentID'] = 0; $GLOBALS['ExtraParameter'] = ''; } $GLOBALS['SubscriberAction'] = $this->ParseTemplate('Subscribers_Manage_ViewLink', true, false); if ($user->HasAccess('Subscribers', 'Eventsave')) { $GLOBALS['SubscriberAction'] .= $this->ParseTemplate('Subscribers_Manage_EventAddLink', true, false); } if ($user->HasAccess('Subscribers', 'Edit')) { $GLOBALS['SubscriberAction'] .= $this->ParseTemplate('Subscribers_Manage_EditLink', true, false); } if ($user->HasAccess('Subscribers', 'Delete')) { $GLOBALS['DeleteSubscriberID'] = $subscriberinfo['subscriberid']; $GLOBALS['SubscriberAction'] .= $this->ParseTemplate('Subscribers_Manage_DeleteLink', true, false); } $events = $subscriber_api->CountEvents($subscriberinfo['subscriberid']); $GLOBALS['EventButton'] = ''; if ($events) { $GLOBALS['EventButton'] = $this->ParseTemplate('Subscribers_Manage_Row_Eventbutton',true,false); } $subscriberdetails .= $this->ParseTemplate($subscriber_row_template, true, false); } $template = str_replace('%%TPL_' . $subscriber_row_template . '%%', $subscriberdetails, $template); $template = str_replace('%%TPL_Paging%%', $paging, $template); $template = str_replace('%%TPL_Paging_Bottom%%', $GLOBALS['PagingBottom'], $template); echo $template; }
/** * EditSubscriber * Prints the 'edit subscriber' form and all appropriate options including custom fields. * * @param Int $listid The list the subscriber is on. This is checked to make sure the user has 'edit' access to the list before anything else. * @param Int $subscriberid The subscriberid to edit. * @param Int $segmentid The segment the subscriber is on. * @param String $msgtype The heading to show when editing a subscriber. This can be either error or success. Used with $msg to display something. * @param String $msg The message to display in the heading. If this is not present, no message is displayed. * * @see GetApi * @see Subscribers_API::GetCustomFieldSettings * @see Lists_API::GetCustomFields * @see Lists_API::Load * @see Lists_API::GetListFormat * * @return Void Doesn't return anything. Prints out the edit form and that's it. */ function EditSubscriber($listid = 0, $subscriberid = 0, $segmentid = 0, $msgtype = 'Error', $msg = false) { $user = GetUser(); $access = $user->HasAccess('Subscribers', 'Edit'); if (!$access) { $this->DenyAccess(); return; } $this->SetupGoogleCalendar(); $search_info = IEM::sessionGet('Search_Subscribers'); $GLOBALS['list'] = $listid; if ($msg && $msgtype) { switch (strtolower($msgtype)) { case 'success': $GLOBALS['Success'] = $msg; $GLOBALS['Message'] = $this->ParseTemplate('SuccessMsg', true, false); break; default: $GLOBALS['Error'] = $msg; $GLOBALS['Message'] = $this->ParseTemplate('ErrorMsg', true, false); } } $SubscriberApi = $this->GetApi('Subscribers'); /** * Get Subscriber record from the database */ $adminAccess = false; // If this user is an admin/list admin/list admintype == a then give permission if ($user->Admin() || $user->ListAdminType() == 'a' || $user->ListAdmin()) { $adminAccess = true; } // Get subscribers from list if ($segmentid == 0) { if (!$adminAccess && !$SubscriberApi->CheckPermission($user->userid, $subscriberid)) { $this->DenyAccess(); return; } $subscriberinfo = $SubscriberApi->LoadSubscriberList($subscriberid, $listid); // Get subscribers from segment } else { if (!$adminAccess) { $segmentapi = $this->GetApi('Segment', true); $segmentapi->Load($segmentid); if ($segmentapi->ownerid != $user->userid && !$user->HasAccess('Segments', 'View', $segmentid)) { $this->DenyAccess(); return; } } $subscriberinfo = $SubscriberApi->LoadSubscriberSegment($subscriberid, $segmentid); $GLOBALS['SegmentID'] = $segmentid; } /** * ----- */ // hmm, the subscriber doesn't exist or can't be loaded? show an error. if (empty($subscriberinfo)) { $GLOBALS['ErrorMessage'] = GetLang('SubscriberDoesntExist_Edit'); $this->DenyAccess(); return; } $list_api = $this->GetApi('Lists'); $list_api->Load($listid); // Log this to "User Activity Log" if (IEM::requestGetGET('Action', '', 'strtolower') != 'save') { IEM::logUserActivity($_SERVER['REQUEST_URI'], 'images/contacts_view.gif', $subscriberinfo['emailaddress']); } $GLOBALS['emailaddress'] = $subscriberinfo['emailaddress']; $GLOBALS['subscriberid'] = $subscriberid; if ($subscriberinfo['requestdate'] == 0) { $GLOBALS['requestdate'] = GetLang('Unknown'); } else { $GLOBALS['requestdate'] = $this->PrintTime($subscriberinfo['requestdate']); } $GLOBALS['requestip'] = ($subscriberinfo['requestip'] == '') ? GetLang('Unknown') : $subscriberinfo['requestip']; if ($subscriberinfo['confirmdate'] == 0) { $GLOBALS['confirmdate'] = GetLang('Unknown'); } else { $GLOBALS['confirmdate'] = $this->PrintTime($subscriberinfo['confirmdate']); } $GLOBALS['confirmip'] = ($subscriberinfo['confirmip'] == '') ? GetLang('Unknown') : $subscriberinfo['confirmip']; $confirmed = ''; foreach (array('1' => 'Confirmed', '0' => 'Unconfirmed') as $confirmoption => $option) { $selected = ($confirmoption == $subscriberinfo['confirmed']) ? ' SELECTED' : ''; $confirmed .= '<option value="' . $confirmoption . '"' . $selected . '>' . GetLang($option) . '</option>'; } $GLOBALS['ConfirmedList'] = $confirmed; $GLOBALS['ShowUnsubscribeInfo'] = 'none'; $subscriber_status = 'a'; if ($subscriberinfo['unsubscribed'] > 0) { $subscriber_status = 'u'; $GLOBALS['unsubscribetime'] = $this->PrintTime($subscriberinfo['unsubscribed']); $GLOBALS['unsubscribeip'] = ($subscriberinfo['unsubscribeip'] == '') ? GetLang('Unknown') : $subscriberinfo['unsubscribeip']; $GLOBALS['ShowUnsubscribeInfo'] = ''; } if ($subscriberinfo['bounced'] > 0) { $subscriber_status = 'b'; } $status = ''; foreach (array('a' => 'Active', 'u' => 'Unsubscribed', 'b' => 'Bounced') as $statusoption => $option) { $selected = ($statusoption == $subscriber_status) ? ' SELECTED' : ''; $status .= '<option value="' . $statusoption . '"' . $selected . '>' . GetLang($option) . '</option>'; } $GLOBALS['StatusList'] = $status; $listformat = $list_api->GetListFormat(); switch ($listformat) { case 't': $format = '<option value="t" SELECTED>' . GetLang('Format_Text') . '</option>'; break; case 'h': $format = '<option value="h" SELECTED>' . GetLang('Format_HTML') . '</option>'; break; case 'b': $selected = ''; if ($subscriberinfo['format'] == 'h') { $selected = ' SELECTED'; } $format = '<option value="h"' . $selected . '>' . GetLang('Format_HTML') . '</option>'; $selected = ''; if ($subscriberinfo['format'] == 't') { $selected = ' SELECTED'; } $format .= '<option value="t"' . $selected . '>' . GetLang('Format_Text') . '</option>'; break; } $GLOBALS['FormatList'] = $format; $customfields = $list_api->GetCustomFields($listid); $extra_javascript = ''; $customfield_display = array(); $customfieldinfo = ''; if (!empty($customfields)) { $customfieldinfo .= $this->ParseTemplate('Subscribers_Edit_Step2_CustomFields', true, false); foreach ($customfields as $pos => $customfield_info) { $GLOBALS['FieldID'] = $customfield_info['fieldid']; if ($customfield_info['required']) { $GLOBALS['Required'] = $this->ParseTemplate('Required', true, false); } else { $GLOBALS['Required'] = $this->ParseTemplate('Not_Required', true, false); } $subscriber_settings = $SubscriberApi->GetCustomFieldSettings($customfield_info['fieldid']); $customfields_api = $this->GetApi('CustomFields'); $customfields_api->fieldid = $customfield_info['fieldid']; $customfields_api->fieldtype = $customfield_info['fieldtype']; $subfield = $customfields_api->LoadSubField(); $subscriber_settings_old = $subscriber_settings; $subscriber_settings = $realValue = $subfield->GetRealValue($subscriber_settings); switch ($customfield_info['fieldtype']) { case 'date': $optionlist = ''; $date_info = array(); if ($subscriber_settings) { $date_parts = explode('/', $subscriber_settings); $date_part_check = $date_parts[0] + $date_parts[1] + $date_parts[2]; if($date_part_check != 0){ for ($i = 0; $i <= 2; $i++) { if(strtolower($subfield->Settings['Key'][$i]) == 'month'){ $date_info['mm'] = $date_parts[$i]; } if(strtolower($subfield->Settings['Key'][$i]) == 'day'){ $date_info['dd'] = $date_parts[$i]; } if(strtolower($subfield->Settings['Key'][$i]) == 'year'){ $date_info['yy'] = $date_parts[$i]; } } } } $extra_javascript .= ' field_'.$customfield_info['fieldid'].'_check = CheckDate("CustomFields['.$customfield_info['fieldid'].']"); if (!field_'.$customfield_info['fieldid'].'_check) { alert("' . sprintf(GetLang('EnterValidDate'), htmlspecialchars($customfield_info['name'], ENT_QUOTES, SENDSTUDIO_CHARSET)) . '"); return false; } '; $template_name = 'Subscribers_View_CustomField_Date'; $fieldsettings = unserialize($customfield_info['fieldsettings']); $GLOBALS['GoogleCalendarButton'] = ''; $GLOBALS['DateJSON'] ='{}'; if (strlen($subscriber_settings)) { $date = explode('/', $subscriber_settings); $datejson = array_combine(array_slice($fieldsettings['Key'], 0, 3), $date); $GLOBALS['DateJSON'] = GetJSON($datejson); $GLOBALS['GoogleCalendarParameters'] = ",true"; } if (strlen($user->googlecalendarusername) && strlen($user->googlecalendarpassword)) { $GLOBALS['GoogleCalendarButton'] = $this->ParseTemplate('google_calendar_button', true); } else { $GLOBALS['GoogleCalendarButton'] = $this->ParseTemplate('google_calendar_button_disabled', true); } $this->Display_CustomField($customfield_info, $date_info); break; case 'radiobutton': $fieldsettings = (is_array($customfield_info['fieldsettings'])) ? $customfield_info['fieldsettings'] : unserialize($customfield_info['fieldsettings']); $default_value = ($subscriber_settings) ? $subscriber_settings : ''; $optionlist = ''; $c = 1; foreach ($fieldsettings['Key'] as $pos => $key) { $selected = ''; if ($key == $default_value) { $selected = ' CHECKED'; } $label_id = htmlspecialchars('CustomFields_' . $customfield_info['fieldid'] . '_'.$key, ENT_QUOTES, SENDSTUDIO_CHARSET); $optionlist .= '<label for="'.$label_id.'"><input type="radio" id="'.$label_id.'" name="CustomFields[' . $customfield_info['fieldid'] . ']" value="' . htmlspecialchars($key, ENT_QUOTES, SENDSTUDIO_CHARSET) . '"' . $selected . '>' . htmlspecialchars($fieldsettings['Value'][$pos], ENT_QUOTES, SENDSTUDIO_CHARSET) . '</label>'; if ($c % 4 == 0) { $optionlist .= '<br/>'; } $c++; } if ($customfield_info['required']) { $extra_javascript .= ' field_'.$customfield_info['fieldid'].'_check = CheckRadio("CustomFields_'.$customfield_info['fieldid'].'"); if (!field_'.$customfield_info['fieldid'].'_check) { alert("' . sprintf(GetLang('ChooseValueForCustomField'), htmlspecialchars($customfield_info['name'], ENT_QUOTES, SENDSTUDIO_CHARSET)) . '"); return false; } '; } break; case 'dropdown': $fieldsettings = (is_array($customfield_info['fieldsettings'])) ? $customfield_info['fieldsettings'] : unserialize($customfield_info['fieldsettings']); $optionlist = ''; $default_value = ($subscriber_settings_old) ? $subscriber_settings_old : ''; $optionlist .= '<option value="">' . $customfield_info['defaultvalue'] . '</option>'; foreach ($fieldsettings['Key'] as $pos => $key) { $selected = ''; if ($key == $default_value) { $selected = ' SELECTED'; } $optionlist .= '<option value="' . htmlspecialchars($key, ENT_QUOTES, SENDSTUDIO_CHARSET) . '"' . $selected . '>' . htmlspecialchars($fieldsettings['Value'][$pos], ENT_QUOTES, SENDSTUDIO_CHARSET) . '</option>'; } if ($customfield_info['required']) { $extra_javascript .= ' fld = document.getElementById("CustomFields['.$customfield_info['fieldid'].']"); selIndex = fld.selectedIndex; if (selIndex < 1) { alert("'.sprintf(GetLang('ChooseOptionForCustomField'), htmlspecialchars($customfield_info['name'], ENT_QUOTES, SENDSTUDIO_CHARSET)) . '"); fld.focus(); return false; } '; } break; case 'checkbox': $fieldsettings = (is_array($customfield_info['fieldsettings'])) ? $customfield_info['fieldsettings'] : unserialize($customfield_info['fieldsettings']); $default_values = (unserialize($subscriber_settings_old)) ? unserialize($subscriber_settings_old) : array(); $optionlist = ''; $c = 1; foreach ($fieldsettings['Key'] as $pos => $key) { $selected = ''; if (in_array($key, $default_values)) { $selected = ' CHECKED'; } $label = htmlspecialchars('CustomFields[' . $customfield_info['fieldid'] . '][' . $key . ']', ENT_QUOTES, SENDSTUDIO_CHARSET); $optionlist .= '<label for="' . $label . '"><input type="checkbox" name="CustomFields[' . $customfield_info['fieldid'] . '][' . $pos . ']" id="' . $label . '" value="' . htmlspecialchars($key, ENT_QUOTES, SENDSTUDIO_CHARSET) . '"' . $selected . '>' . htmlspecialchars($fieldsettings['Value'][$pos], ENT_QUOTES, SENDSTUDIO_CHARSET) . '</label>'; if ($c % 4 == 0) { $optionlist .= '<br/>'; } $c++; } if ($customfield_info['required']) { $extra_javascript .= ' CheckboxCheck = CheckMultiple("CustomFields[' . $customfield_info['fieldid'] . ']", f); if (!CheckboxCheck) { alert("' . sprintf(GetLang('ChooseValueForCustomField'), htmlspecialchars($customfield_info['name'], ENT_QUOTES, SENDSTUDIO_CHARSET)) . '"); return false; } '; } break; default: if ($customfield_info['required']) { $extra_javascript .= ' if (document.getElementById("CustomFields['.$customfield_info['fieldid'].']").value == "") { alert("' . sprintf(GetLang('EnterValueForCustomField'), htmlspecialchars($customfield_info['name'], ENT_QUOTES, SENDSTUDIO_CHARSET)) . '"); document.getElementById("CustomFields['.$customfield_info['fieldid'].']").focus(); return false; } '; } $optionlist = ''; $subscriber_settings = $subscriber_settings; } $GLOBALS['OptionList'] = $optionlist; $GLOBALS['DefaultValue'] = ''; if ( $realValue || $realValue == 0){ $GLOBALS['DefaultValue'] = htmlspecialchars($realValue, ENT_QUOTES, SENDSTUDIO_CHARSET); }elseif( $customfield_info['required'] ){ $GLOBALS['DefaultValue'] = htmlspecialchars($subscriber_settings_old, ENT_QUOTES, SENDSTUDIO_CHARSET); } $GLOBALS['FieldName'] = htmlspecialchars($customfield_info['name'], ENT_QUOTES, SENDSTUDIO_CHARSET); $GLOBALS['CustomFieldID'] = $customfield_info['fieldid']; $customfield_display[] = $this->ParseTemplate('CustomField_Edit_' . $customfield_info['fieldtype'], true, false); } $column1 = $column2 = array(); if (count($customfield_display) > 9) { $customfieldinfo_template = 'Subscribers_customfieldinfo_twocolumns'; $split = ceil(count($customfield_display) / 2); for ($i = 0; $i < $split; $i++) { $column1[] = $customfield_display[$i]; if (isset($customfield_display[$i + $split])) { $column2[] = $customfield_display[$i + $split]; } else { $column2[] = '<td> </td><td> </td>'; } } $GLOBALS['CustomFieldInfo_1'] = '<tr>' . implode('</tr><tr>',$column1) . '</tr>'; $GLOBALS['CustomFieldInfo_2'] = '<tr>' . implode('</tr><tr>',$column2) . '</tr>'; } else { $customfieldinfo_template = 'Subscribers_customfieldinfo_onecolumn'; $GLOBALS['CustomFieldInfo_1'] = ''; foreach ($customfield_display as $field) { $GLOBALS['CustomFieldInfo_1'] .= '<tr>' . $field . '</tr>'; } } $GLOBALS['CustomFieldInfo'] = $customfieldinfo . $this->ParseTemplate($customfieldinfo_template,true); $GLOBALS['ExtraJavascript'] = $extra_javascript; } $GLOBALS['listid'] = $listid; $GLOBALS['CustomDatepickerUI'] = $this->ParseTemplate('UI.DatePicker.Custom_IEM', true); $actions = $user->GetEventActivityType(); $GLOBALS['Actions'] = ''; foreach ($actions as $action) { $GLOBALS['Actions'] .= '<option value="' . htmlspecialchars($action,ENT_QUOTES, SENDSTUDIO_CHARSET) . '">'. htmlspecialchars($action,ENT_QUOTES, SENDSTUDIO_CHARSET) . "</option>"; } $GLOBALS['SubscriberEvents_Intro'] = GetLang('SubscriberEvents_Intro'); if ($user->HasAccess('Subscribers','EventSave')) { $GLOBALS['SubscriberEvents_Intro'] .= GetLang('SubscriberEvents_Intro_AddEvent'); } if (IEM::sessionGet('gcal_allday')) { $GLOBALS['GoogleCalendarAllDay'] = 'true'; } else { $GLOBALS['GoogleCalendarAllDay'] = 'false'; } if (strlen($user->googlecalendarusername) && strlen($user->googlecalendarpassword)) { $GLOBALS['GoogleCalendarEnabled'] = 'true'; } else { $GLOBALS['GoogleCalendarEnabled'] = 'false'; } $GLOBALS['EventTypesJSON'] = GetJSON($actions); $GLOBALS['EventAddForm'] = $this->ParseTemplate('Subscriber_Event_Add',true,false); $this->ParseTemplate('Subscribers_Edit_Step2'); }
/** * _edit * Display the editor page foe editing existing record * * @param Array $parameters Any parameters that need to be parsed to this function (OPTIONAL) * @return String Returns response string that can be outputted to the browser * * @uses SendStudio_Functions::_getGETRequest() * @uses SendStudio_Functions::GetApi() * @uses TriggerEmails_API::GetRecordByID() * @uses TriggerEmails::_manage() * @uses TriggerEmails::_getEditor() * @uses FlashMessage() * * @test permission */ private function _edit($parameters = array()) { if (!$parameters['user']->HasAccess('triggeremails', 'edit')) { $this->DenyAccess(); exit(); } $id = intval($this->_getGETRequest('id', 0)); if ($id == 0) { return $this->_manage($parameters); } $api = $this->GetApi(); if (!$parameters['user']->Admin() && !$api->IsOwner($id, $parameters['user']->userid)) { $this->DenyAccess(); exit(); } $record = $api->GetRecordByID($id); if ($record === false || empty($record)) { FlashMessage(GetLang('TriggerEmails_Cannot_Load_Record'), SS_FLASH_MSG_ERROR, 'index.php?Page=TriggerEmails'); } // ----- Fetch trigger data $tempData = $api->GetData($id); if ($tempData === false) { FlashMessage(GetLang('TriggerEmails_Cannot_Load_Record'), SS_FLASH_MSG_ERROR, 'index.php?Page=TriggerEmails'); } if (array_key_exists($id, $tempData)) { $record['data'] = $tempData[$id]; } unset($tempData); // ----- // ----- Fetch trigger actions $tempActions = $api->GetActions($id); if ($tempActions === false) { FlashMessage(GetLang('TriggerEmails_Cannot_Load_Record'), SS_FLASH_MSG_ERROR, 'index.php?Page=TriggerEmails'); } if (array_key_exists($id, $tempActions)) { $record['triggeractions'] = $tempActions[$id]; } unset($tempActions); // ----- // Log this to "User Activity Log" IEM::logUserActivity($_SERVER['REQUEST_URI'], 'images/triggeremails_view.gif', $record['name']); return $this->_getEditor($parameters, $record); }
/** * TriggerEmailsStats_View * Handle listing of the trigger emails statistics * * @return Void Prints output directly to stdout without returning anything. * * @uses Stats_API::GetTriggerEmailsStats() */ function TriggerEmailsStats_View() { // ----- Sanitize and declare variables that is going to be used in this function $user = IEM::userGetCurrent(); $id = intval($this->_getGETRequest('id', '')); $record = array(); $triggerrecord = array(); $api = $this->GetApi(); $triggerapi = $this->GetApi('TriggerEmails'); $page = array( 'messages' => GetFlashMessages(), 'whichtab' => intval($this->_getGETRequest('tab', 1)), 'unique_open' => ($this->_getGETRequest('Unique', false) ? true : false), 'session_token' => md5(uniqid(rand())) ); $tabs = array( 'snapshot' => array(), 'open' => array(), 'links' => array(), 'bounces' => array(), 'unsubscribe' => array(), 'forward' => array(), 'recipients' => array() ); // ---- if ($id == 0) { return $this->TriggerEmailsStats_List(); } // Make sure that user can access this particular trigger email statistics if (!$this->_TriggerEmailsStats_Access($id)) { return $this->TriggerEmailsStats_List(); } // ----- Load trigger emails statistics record $record = $api->GetTriggerEmailsStatsRecord($id); $triggerrecord = $triggerapi->GetRecordByID($id, true, true); if (!isset($triggerrecord['triggeractions']) || !is_array($triggerrecord['triggeractions'])) { $triggerrecord['triggeractions'] = array(); } if (!isset($triggerrecord['triggeractions']['send']) || !is_array($triggerrecord['triggeractions']['send'])) { $triggerrecord['triggeractions']['send'] = array(); } $temp = array('trackopens', 'tracklinks'); foreach ($temp as $each) { if (!isset($triggerrecord['triggeractions']['send'][$each])) { $triggerrecord['triggeractions']['send'][$each] = 0; } } if (empty($record)) { return $this->TriggerEmailsStats_List(); } // ----- // Log this to "User Activity Log" IEM::logUserActivity($_SERVER['REQUEST_URI'], 'images/chart_bar.gif', $record['triggeremailsname']); // ----- Calculate some common variables for the record $record['processed_totalsent'] = intval($record['htmlrecipients']) + intval($record['textrecipients']) + intval($record['multipartrecipients']); $record['processed_unopened'] = abs($record['processed_totalsent'] - $record['emailopens_unique']); $record['processed_totalbounced'] = intval($record['bouncecount_soft']) + intval($record['bouncecount_hard']) + intval($record['bouncecount_unknown']); if ($record['processed_totalsent'] != 0) { if ($triggerrecord['triggeractions']['send']['trackopens'] != 0) { $record['processed_timeframe_emailopens_total'] = intval($api->GetOpens($record['statid'], 1, 'all', $page['unique_open'], $this->CalendarRestrictions['opens'], true)); $record['processed_timeframe_emailopens_unique'] = intval($api->GetOpens($record['statid'], 1, 'all', $page['unique_open'], $this->CalendarRestrictions['opens'], true)); } if ($triggerrecord['triggeractions']['send']['tracklinks'] != 0) { $record['processed_timeframe_linkclicks_total'] = intval($api->GetClicks($record['statid'], 1, 'all', 'a', $this->CalendarRestrictions['clicks'], true)); $record['processed_timeframe_linkclicks_unique'] = intval($api->GetUniqueClicks($record['statid'], 'a', $this->CalendarRestrictions['clicks'])); $record['processed_timeframe_linkclicks_individuals'] = intval($api->GetUniqueClickRecipients($record['statid'], $this->CalendarRestrictions['clicks'], 'a')); } $record['processed_timeframe_bounces'] = intval($api->GetBounces($record['statid'], 1, 'all', 'any', $this->CalendarRestrictions['bounces'], true)); $record['processed_timeframe_unsubscribes'] = intval($api->GetUnsubscribes($record['statid'], 1, 'all', $this->CalendarRestrictions['unsubscribes'], true)); if (array_key_exists('forwards', $this->CalendarRestrictions) && !empty($this->CalendarRestrictions['forwards'])) { $record['processed_timeframe_forwards'] = intval($api->GetForwards($record['statid'], 1, 'all', $this->CalendarRestrictions['forwards'], true)); } else { $record['processed_timeframe_forwards'] = intval($record['emailforwards']); } $record['processed_timeframe_totalsent'] = 0; // Set up session information that correspond to the current stats (this information in the session will not be cleaned up, need to refactor) // The session infromation is used to print out a table that list email addressess for "open" and "link" tabs IEM::sessionSet($page['session_token'], array( 'statid' => $record['statid'], 'calendar_restrictions' => $this->CalendarRestrictions, 'unique_open_only' => $page['unique_open'], 'summary' => $record )); } // ----- // Load additional language variable for displaying trigger email statistics $this->LoadLanguageFile('TriggerEmails'); // Include the charting tool include_once (SENDSTUDIO_FUNCTION_DIRECTORY . '/amcharts/amcharts.php'); // ----- Tab 1: Snapshot $tabs['snapshot']['intro'] = sprintf(GetLang('TriggerEmails_Stats_Snapshots_Intro'), $record['triggeremailsname']); $tabs['snapshot']['newsletter_uniqueopen'] = sprintf(GetLang('EmailOpens_Unique'), $this->FormatNumber($record['emailopens_unique'])); $tabs['snapshot']['newsletter_totalopen'] = sprintf(GetLang('EmailOpens_Total'), $this->FormatNumber($record['emailopens'])); $tabs['snapshot']['newsletter_bounce'] = $this->FormatNumber($record['processed_totalbounced']); $tabs['snapshot']['url_open_url'] = 'index.php?Page=Stats&Action=TriggerEmails&SubAction=view&tab=2&id=' . $id; $tabs['snapshot']['url_openunique_url'] = $tabs['snapshot']['url_open_url'] . '&Unique=1'; $tabs['snapshot']['summary_chart'] = InsertChart( 'pie', 'stats_chart.php?Opens=' . $record['emailopens_unique'] . '&Unopened=' . $record['processed_unopened'] . '&Bounced=' . $record['processed_totalbounced'] . '&Area=TriggerEmails&'. IEM::SESSION_NAME . '=' . IEM::sessionID(), array('graph_title' => sprintf(GetLang('TriggerEmails_Stats_Snapshots_ChartTitle'), $record['triggeremailsname']))); // ----- // ----- Tab 2: Open rates $tabs['open']['intro'] = sprintf(GetLang('TriggerEmails_Stats_Open_Intro'), $record['triggeremailsname']); // setup calendar $GLOBALS['TabID'] = '1'; $this->SetupCalendar('Action=ProcessCalendar&SubAction=TriggerEmails&NextAction=View&tab=2&id=' . $id); $tabs['open']['calendar'] = $GLOBALS['Calendar']; unset($GLOBALS['TabID']); unset($GLOBALS['Calendar']); // Set up error message if no "opens" count is not available if (!array_key_exists('processed_timeframe_emailopens_total', $record) || !$record['processed_timeframe_emailopens_total']) { $tempMessage = 'TriggerEmails_Stats_Open_Error_HasNotBeenOpened'; $tempRestriction = $this->CalendarRestrictions; if ($triggerrecord['triggeractions']['send']['trackopens'] == 0) { $tempMessage = 'TriggerEmails_Stats_Open_Error_NotOpenTracked'; } elseif (array_key_exists('opens', $tempRestriction) && !empty($tempRestriction['opens'])) { $tempMessage = 'TriggerEmails_Stats_Open_Error_HasNotBeenOpened_CalendarProblem'; } $GLOBALS['Error'] = GetLang($tempMessage); $tabs['open']['message'] = $this->ParseTemplate('ErrorMsg', true, false); unset($GLOBALS['Error']); // Set up open information otherwise } else { $tabs['open']['email_opens_total'] = $this->FormatNumber($record['processed_timeframe_emailopens_total']); $tabs['open']['email_opens_unique'] = $this->FormatNumber($record['processed_timeframe_emailopens_unique']); // ----- Most opens $tempMostOpens = $api->GetMostOpens($record['statid'], $this->CalendarRestrictions['opens']); $tempNow = getdate(); if (isset($tempMostOpens['mth'])) { $tabs['open']['most_open_date'] = $this->Months[$tempMostOpens['mth']] . ' ' . $tempMostOpens['yr']; } elseif (isset($tempMostOpens['hr'])) { $tabs['open']['most_open_date'] = date(GetLang('Daily_Time_Display'),mktime($tempMostOpens['hr'], 1, 1, 1, 1, $tempNow['year'])); } elseif (isset($tempMostOpens['dow'])) { $pos = array_search($tempMostOpens['dow'], array_keys($this->days_of_week)); $tabs['open']['most_open_date'] = date(GetLang('Date_Display_Display'), strtotime("last " . $this->days_of_week[$pos])); } elseif (isset($tempMostOpens['dom'])) { $month = $tempNow['mon']; // if the day-of-month is after "today", it's going to be for "last month" so adjust the month accordingly. if ($tempMostOpens['dom'] > $tempNow['mday']) { $month = $tempNow['mon'] - 1; } $tabs['open']['most_open_date'] = date(GetLang('Date_Display_Display'),mktime(0, 0, 1, $month, $tempMostOpens['dom'], $tempNow['year'])); } unset($tempNow); unset($tempMostOpens); // ----- // ----- Average opens $tabs['open']['average_opens'] = 0; if ($record['processed_totalsent'] > 0) { $tempAverage = $record['processed_timeframe_emailopens_total'] / $record['processed_totalsent']; $tabs['open']['average_opens'] = $this->FormatNumber($tempAverage, 3); unset($tempAverage); } // ----- // ----- Open rate $tabs['open']['open_rate'] = '0%'; if ($record['processed_totalsent'] > 0) { $tempOpenRate = $record['processed_timeframe_emailopens_unique'] / $record['processed_totalsent'] * 100; $tabs['open']['open_rate'] = $this->FormatNumber($tempOpenRate, 2) . '%' ; unset($tempOpenRate); } // ----- // Setup chart $this->DisplayChart('OpenChart', 'triggeremails', $record['statid'], 'column', array('graph_title' => GetLang('OpensChart'))); $tabs['open']['open_chart'] = $GLOBALS['OpenChart']; unset($GLOBALS['OpenChart']); } // ----- // ----- Tab 3: Links (TODO: when user chooses a specific link. Currently this is being ignored) $tabs['links']['intro'] = sprintf(GetLang('TriggerEmails_Stats_Links_Intro'), $record['triggeremailsname']); // setup calendar $GLOBALS['TabID'] = '2'; $this->SetupCalendar('Action=ProcessCalendar&SubAction=TriggerEmails&NextAction=View&tab=3&id=' . $id); $tabs['links']['calendar'] = $GLOBALS['Calendar']; unset($GLOBALS['TabID']); unset($GLOBALS['Calendar']); // Set up error message if no "links" count is not available if (!array_key_exists('processed_timeframe_linkclicks_total', $record) || !$record['processed_timeframe_linkclicks_total']) { $tempMessage = 'TriggerEmails_Stats_Links_Error_NoLinksFound'; $tempRestriction = $this->CalendarRestrictions; if ($triggerrecord['triggeractions']['send']['tracklinks'] == 0) { $tempMessage = 'TriggerEmails_Stats_Links_Error_NotLinkTracked'; } elseif (array_key_exists('clicks', $tempRestriction) && !empty($tempRestriction['clicks'])) { $tempMessage = 'TriggerEmails_Stats_Links_Error_NoLinksFound_CalendarProblem'; } $GLOBALS['Error'] = GetLang($tempMessage); $tabs['links']['message'] = $this->ParseTemplate('ErrorMsg', true, false); unset($GLOBALS['Error']); // Set up open information otherwise } else { $tabs['links']['linkclicks_total'] = $this->FormatNumber($record['processed_timeframe_linkclicks_total']); $tabs['links']['linkclicks_unique'] = $this->FormatNumber($record['processed_timeframe_linkclicks_unique']); $tabs['links']['linkclicks_individuals'] = $this->FormatNumber($record['processed_timeframe_linkclicks_individuals']); // ----- Most popular $most_popular_link = $api->GetMostPopularLink($record['statid'], 'a', $this->CalendarRestrictions['clicks']); $most_popular_link = htmlspecialchars($most_popular_link, ENT_QUOTES, SENDSTUDIO_CHARSET); $tabs['links']['most_popular_link'] = $most_popular_link; $tabs['links']['most_popular_link_short'] = $this->TruncateName($most_popular_link, 20); unset($most_popular_link); // ----- // ----- Average clicks per-email-opens $tabs['links']['average_clicks'] = '0'; if ($record['emailopens'] > 0) { $tabs['links']['average_clicks'] = $this->FormatNumber(($record['linkclicks'] / $record['emailopens']), 3); } // ----- // ----- Clickthrough rate $tabs['links']['click_through'] = '0%'; if ($record['processed_totalsent'] > 0) { $tempClickThroughRate = $record['processed_timeframe_linkclicks_unique'] / $record['processed_totalsent'] * 100; $tabs['links']['click_through'] = $this->FormatNumber($tempClickThroughRate, 2) . '%'; unset($tempClickThroughRate); } // ----- // Setup chart $this->DisplayChart('LinksChart', 'triggeremails', $record['statid'], 'column', array('graph_title' => GetLang('LinksClickedChart'))); $tabs['links']['link_chart'] = $GLOBALS['LinksChart']; unset($GLOBALS['LinksChart']); } // ----- // ----- Tab 4: Bounces (TODO: Cannot filter the bounce under soft/hard) $tabs['bounces']['intro'] = sprintf(GetLang('TriggerEmails_Stats_Bounces_Intro'), $record['triggeremailsname']); // setup calendar $GLOBALS['TabID'] = '3'; $this->SetupCalendar('Action=ProcessCalendar&SubAction=TriggerEmails&NextAction=View&tab=4&id=' . $id); $tabs['bounces']['calendar'] = $GLOBALS['Calendar']; unset($GLOBALS['TabID']); unset($GLOBALS['Calendar']); // Set up error message if no "bounces" count is not available if (!array_key_exists('processed_timeframe_bounces', $record) || !$record['processed_timeframe_bounces']) { $tempMessage = 'TriggerEmails_Stats_Bounces_Error_NoBouncesFound'; $tempRestriction = $this->CalendarRestrictions; if (array_key_exists('clicks', $tempRestriction) && !empty($tempRestriction['clicks'])) { $tempMessage = 'TriggerEmails_Stats_Links_Error_NoLinksFound_CalendarProblem'; } $GLOBALS['Error'] = GetLang($tempMessage); $tabs['bounces']['message'] = $this->ParseTemplate('ErrorMsg', true, false); unset($GLOBALS['Error']); // Set up open information otherwise } else { $tabs['bounces']['bounces_total'] = $this->FormatNumber($record['processed_totalbounced']); $tabs['bounces']['bounces_soft'] = $this->FormatNumber(intval($record['bouncecount_soft'])); $tabs['bounces']['bounces_hard'] = $this->FormatNumber(intval($record['bouncecount_hard'])); $tabs['bounces']['bounces_unknown'] = $this->FormatNumber(intval($record['bouncecount_unknown'])); // Setup chart $this->DisplayChart('BounceChart', 'triggeremails', $record['statid'], 'column', array('graph_title' => GetLang('BounceChart'))); $tabs['bounces']['bounce_chart'] = $GLOBALS['BounceChart']; unset($GLOBALS['BounceChart']); } // ----- // ----- Tab 5: Unsubscribe $tabs['unsubscribes']['intro'] = sprintf(GetLang('TriggerEmails_Stats_Unsubscribes_Intro'), $record['triggeremailsname']); // setup calendar $GLOBALS['TabID'] = '4'; $this->SetupCalendar('Action=ProcessCalendar&SubAction=TriggerEmails&NextAction=View&tab=5&id=' . $id); $tabs['unsubscribes']['calendar'] = $GLOBALS['Calendar']; unset($GLOBALS['TabID']); unset($GLOBALS['Calendar']); // Set up error message if no "unsubscribes" count is not available if (!array_key_exists('processed_timeframe_unsubscribes', $record) || !$record['processed_timeframe_unsubscribes']) { $tempMessage = 'TriggerEmails_Stats_Unsubscribes_Error_NoUnsubscribesFound'; $tempRestriction = $this->CalendarRestrictions; if (array_key_exists('bounces', $tempRestriction) && !empty($tempRestriction['bounces'])) { $tempMessage = 'TriggerEmails_Stats_Unsubscribes_Error_NoUnsubscribesFound_CalendarProblem'; } $GLOBALS['Error'] = GetLang($tempMessage); $tabs['unsubscribes']['message'] = $this->ParseTemplate('ErrorMsg', true, false); unset($GLOBALS['Error']); // Set up open information otherwise } else { $tabs['unsubscribes']['unsubscribes_total'] = $this->FormatNumber($record['processed_timeframe_unsubscribes']); // ----- Most unsubscribe $tempMostUnsubscribes = $api->GetMostUnsubscribes($record['statid'], $this->CalendarRestrictions['unsubscribes']); $tempNow = getdate(); if (isset($tempMostUnsubscribes['mth'])) { $tabs['unsubscribes']['unsubscribes_most'] = $this->Months[$tempMostUnsubscribes['mth']] . ' ' . $tempMostUnsubscribes['yr']; } elseif (isset($tempMostUnsubscribes['hr'])) { $tabs['unsubscribes']['unsubscribes_most'] = $this->PrintDate(mktime($tempMostUnsubscribes['hr'], 1, 1, 1, 1, $tempNow['year']), GetLang('Daily_Time_Display')); } elseif (isset($tempMostUnsubscribes['dow'])) { $pos = array_search($tempMostUnsubscribes['dow'], array_keys($this->days_of_week)); // we need to add 1 hour here otherwise we get the wrong day from strtotime. $tabs['unsubscribes']['unsubscribes_most'] = $this->PrintDate(strtotime("last " . $this->days_of_week[$pos] . " +1 hour"), GetLang('Date_Display_Display')); } elseif (isset($tempMostUnsubscribes['dom'])) { $month = $tempNow['mon']; // if the day-of-month is after "today", it's going to be for "last month" so adjust the month accordingly. if ($tempMostUnsubscribes['dom'] > $tempNow['mday']) { $month = $tempNow['mon'] - 1; } $tabs['unsubscribes']['unsubscribes_most'] = $this->PrintDate(mktime(0, 0, 1, $month, $tempMostUnsubscribes['dom'], $tempNow['year']), GetLang('Date_Display_Display')); } unset($tempNow); unset($tempMostUnsubscribes); // ----- // Setup chart $this->DisplayChart('UnsubscribeChart', 'triggeremails', $record['statid'], 'column', array('graph_title' => GetLang('UnsubscribesChart'))); $tabs['unsubscribes']['unsubscribe_chart'] = $GLOBALS['UnsubscribeChart']; unset($GLOBALS['UnsubscribeChart']); } // ----- // ----- Tab 6: Forwards $tabs['forwards']['intro'] = sprintf(GetLang('TriggerEmails_Stats_Forwards_Intro'), $record['triggeremailsname']); // setup calendar $GLOBALS['TabID'] = '5'; $this->SetupCalendar('Action=ProcessCalendar&SubAction=TriggerEmails&NextAction=View&tab=6&id=' . $id); $tabs['forwards']['calendar'] = $GLOBALS['Calendar']; unset($GLOBALS['TabID']); unset($GLOBALS['Calendar']); // Set up error message if no "forwards" count is not available if (!array_key_exists('processed_timeframe_forwards', $record) || !$record['processed_timeframe_forwards']) { $tempMessage = 'TriggerEmails_Stats_Forwards_Error_NoForwardFound'; $tempRestriction = $this->CalendarRestrictions; if (array_key_exists('forwards', $tempRestriction) && !empty($tempRestriction['forwards'])) { $tempMessage = 'TriggerEmails_Stats_Forwards_Error_NoForwardFound_CalendarProblem'; } $GLOBALS['Error'] = GetLang($tempMessage); $tabs['forwards']['message'] = $this->ParseTemplate('ErrorMsg', true, false); unset($GLOBALS['Error']); // Set up open information otherwise } else { $tabs['forwards']['forward_total'] = $this->FormatNumber($record['processed_timeframe_forwards']); // ----- Total new Signups $temp = intval($api->GetForwards($record['statid'], 1, 'all', $this->CalendarRestrictions['forwards'], true, true)); $tabs['forwards']['forward_signups'] = $this->FormatNumber($temp); unset($temp); // ----- // Setup chart $this->DisplayChart('ForwardsChart', 'triggeremails', $record['statid'], 'column', array('graph_title' => GetLang('ForwardsChart'))); $tabs['forwards']['forwards_chart'] = $GLOBALS['ForwardsChart']; unset($GLOBALS['ForwardsChart']); } // ----- // ----- Tab 7: Contact info $tabs['recipients'] = $this->_TriggerEmailsStats_View_Tab7($record); // ----- // ----- Tab 8: Failed sending info $tabs['failed'] = $this->_TriggerEmailsStats_View_Tab8($record); // ----- // ----- Print HTML $tpl = GetTemplateSystem(); $tpl->Assign('PAGE', $page); $tpl->Assign('record', $record); $tpl->Assign('tabs', $tabs); return $tpl->ParseTemplate('Stats_Triggeremails_Summary', true); // ----- }