function prepDisplayString($str = '') { if (preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})( [0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $str, $amatch)) { $str = "{$amatch['3']}.{$amatch['2']}.{$amatch['1']}"; } else { if (strpos($str, '<') !== FALSE) { $htt = new Html2Text($str, XOX_NLS_MAX_STRLEN); $str = $htt->convert(); } if (strlen($str) > XOX_NLS_MAX_STRLEN) { $str = substr($str, 0, XOX_NLS_MAX_STRLEN - 3) . '...'; } } return $str; }
function convertNL2Text($html, $type) { global $encoding; $text = $html; if ($type == "html" || $type == "text/html") { #$text=str_replace("<br>","\n", $text); #$text=strip_htmltags($text); #$text=strip_tags($text); $htmlToText = new Html2Text($html, 80); //class has apache license, may be in conflict with gpl??? #$text=htmlspecialchars_decode($text);//php5 only #$text=html_entity_decode($text); $text = $htmlToText->convert(); #$text=strip_tags($text); #$text=html_entity_decode($text,ENT_NOQUOTES,$encoding); $text = preg_replace('~<[^>]+>~', '', $text); // remove any HTML tags that are still left #$text=str_replace(""","'",$text); } return $text; }
function setNewsletter($newsletter_id, $issue_id = 0) { $this->error = ''; $this->c_newsletter = new cNewsletter($newsletter_id); $ai = $this->c_newsletter->getIssues(); if (count($ai) < 1) { $this->error = 'No Valid Newsletter Issues Set'; return false; } $this->c_issue = $ai[0]; foreach ($ai as $is) { if ($is->id == $issue_id) { $this->c_issue = $is; } } /*if (!isset($ai[$issue_id])) { $this->error='No Valid Newsletter Issue Set'; return false; } $this->c_issue = $ai[$issue_id];*/ $ac = $this->c_issue->getContents(); #$c->debug(); #$i->debug(); #foreach($ac as $content) $content->debug(); $mainvars = array(); // add mail replacement variables foreach ($this->mailvars as $var) { $mainvars[$var] = '{$' . $var . '}'; } // add date and unsubscription url $mainvars['DATE'] = date('d.m.Y'); // TODO: get correct unsubscribe url (config or database?) $mainvars['UNSUBSCRIBE_URL'] = ''; // check if text template is used if ($this->text_template) { $this->text_template->setVar($mainvars); // create converter class $html = new Html2Text($this->c_issue->introduction, 80); // issue title and introduction in text style $this->text_template->setVar('TITLE', $this->c_issue->title); $this->text_template->setVar('INTRODUCTION', trim($html->convert())); // copy content $content_count = 1; foreach ($ac as $content) { // text content $this->text_template->setVar('TITLE', $content->title, $content->flags, $content_count); $html->iHtmlText = $content->body; $this->text_template->setVar('BODY', trim($html->convert()), $content->flags, $content_count); $this->text_template->setVar('URL', (empty($content->url) ? '' : "-> " . $content->url) . "\n\n", $content->flags, $content_count); $content_count++; } } // check if html template is used if ($this->html_template) { $this->html_template->setVar($mainvars); // issue title and introduction in html style $this->html_template->setVar('TITLE', $this->c_issue->title); $this->html_template->setVar('INTRODUCTION', $this->c_issue->introduction); // copy content $content_count = 1; foreach ($ac as $content) { // html content $this->html_template->setVar('TITLE', $content->title, $content->flags, $content_count); $this->html_template->setVar('BODY', $content->body, $content->flags, $content_count); $this->html_template->setVar('URL', (empty($content->url) ? '' : '<a href="' . $content->url) . '">>>></a>', $content->flags, $content_count); $content_count++; } } return true; }
// => html foreach ($show_val as $key => $data) { if (!$data) { $data = "N/A"; } $emailInfo['et_subject'] = str_replace("[" . $key . "]", $data, $emailInfo['et_subject']); $emailInfo['et_htmlformat'] = str_replace("[" . $key . "]", $data, $emailInfo['et_htmlformat']); } $emailInfo['et_from'] = $fromaddress; // => sales@etelegate.com $emailInfo['et_from_title'] = $fromaddress; // => Etelegate Sales $emailInfo['et_htmlformat'] = stripslashes($emailInfo['et_htmlformat']); $Html2Text = new Html2Text($emailInfo['et_htmlformat'], 900000); // 900 columns maximum $emailInfo['et_textformat'] = $Html2Text->convert(); $emailInfo['et_textformat'] = str_replace(" ", " ", $emailInfo['et_textformat']); $emailInfo['et_to'] = $to_id; // => techsupport@ecommerceglobal.com $emailInfo['full_name'] = $to_id; // => Etelegate Merchant ) if (!send_email_data($emailInfo, $attachments)) { $mails_sentid .= "'" . $to_id . "' could not be sent. No mail sent to {$company_name}.<br>"; } else { $mails_sentid .= $to_id . "<br>"; $mails_sent_num++; } } else { $mails_sentid .= "'" . $to_id . "' is unsubscribed. No mail sent to {$company_name}.<br>"; } }
public function getSmartyTpl() { $currentUser = $this->getCurrentUser(); $rules = $this->getRules(); $smarty = $this->getSmartyVar(); if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') { $currentLesson = $this->getCurrentLesson(); $currentLessonID = $currentLesson->lesson['id']; if (!isset($_SESSION['module_journal_dimension']) || count($_GET) == 2 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' || count($_GET) == 3 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' && $_GET['new_lesson_id'] == $currentLessonID) { $_SESSION['module_journal_dimension'] = 'small'; } if (!isset($_SESSION['module_journal_entries_from']) || count($_GET) == 2 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' || count($_GET) == 3 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' && $_GET['new_lesson_id'] == $currentLessonID) { $_SESSION['module_journal_entries_from'] = '-1'; } if (isset($_SESSION['module_journal_scroll_position'])) { $smarty->assign("T_JOURNAL_SCROLL_POSITION", $_SESSION['module_journal_scroll_position']); } $smarty->assign("T_JOURNAL_DIMENSIONS", $_SESSION['module_journal_dimension']); $smarty->assign("T_JOURNAL_ENTRIES_FROM", $_SESSION['module_journal_entries_from']); $entries = $this->getEntries($currentUser->user['login'], $_SESSION['module_journal_entries_from']); global $popup; isset($popup) && $popup == 1 ? $popup_ = '&popup=1' : ($popup_ = ''); } $smarty->assign("T_JOURNAL_BASEURL", $this->moduleBaseUrl); $smarty->assign("T_JOURNAL_BASELINK", $this->moduleBaseLink); if (isset($_GET['edit_allow_export']) && $_GET['edit_allow_export'] == '1' && isset($_GET['allow'])) { try { $object = eF_getTableData("module_journal_settings", "id", "name='export'"); eF_updateTableData("module_journal_settings", array("value" => $_GET['allow']), "id=" . $object[0]['id']); } catch (Exception $e) { handleAjaxExceptions($e); } exit; } if (isset($_GET['edit_professor_preview']) && $_GET['edit_professor_preview'] == '1' && isset($_GET['preview'])) { try { $object = eF_getTableData("module_journal_settings", "id", "name='preview'"); eF_updateTableData("module_journal_settings", array("value" => $_GET['preview']), "id=" . $object[0]['id']); } catch (Exception $e) { handleAjaxExceptions($e); } exit; } if (isset($_GET['dimension']) && eF_checkParameter($_GET['dimension'], 'string')) { $smarty->assign("T_JOURNAL_DIMENSIONS", $_GET['dimension']); $_SESSION['module_journal_dimension'] = $_GET['dimension']; } if (isset($_GET['entries_from'])) { $smarty->assign("T_JOURNAL_ENTRIES_FROM", $_GET['entries_from']); $_SESSION['module_journal_entries_from'] = $_GET['entries_from']; } if (isset($_GET['delete_rule']) && eF_checkParameter($_GET['delete_rule'], 'id') && in_array($_GET['delete_rule'], array_keys($rules))) { try { eF_deleteTableData("module_journal_rules", "id=" . $_GET['delete_rule']); } catch (Exception $e) { handleAjaxExceptions($e); } exit; } if (isset($_GET['deactivate_rule']) && eF_checkParameter($_GET['deactivate_rule'], 'id') && in_array($_GET['deactivate_rule'], array_keys($rules))) { eF_updateTableData("module_journal_rules", array('active' => 0), "id=" . $_GET['deactivate_rule']); } if (isset($_GET['activate_rule']) && eF_checkParameter($_GET['activate_rule'], 'id') && in_array($_GET['activate_rule'], array_keys($rules))) { eF_updateTableData("module_journal_rules", array('active' => 1), "id=" . $_GET['activate_rule']); } if (isset($_GET['delete_entry']) && eF_checkParameter($_GET['delete_entry'], 'id') && in_array($_GET['delete_entry'], array_keys($entries))) { $object = eF_getTableData("module_journal_entries", "users_LOGIN", "id=" . $_GET['delete_entry']); if ($object[0]['users_LOGIN'] != $_SESSION['s_login']) { eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_JOURNAL_NOACCESS) . $popup_); exit; } eF_deleteTableData("module_journal_entries", "id=" . $_GET['delete_entry']); } if (isset($_GET['saveas']) && $_GET['saveas'] == 'pdf') { $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor(PDF_AUTHOR); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setFontSubsetting(false); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->setHeaderFont(array('Freeserif', 'I', 11)); $pdf->setFooterFont(array('Freeserif', '', 8)); $pdf->setHeaderData('', '', '', _JOURNAL_NAME); $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->SetFont('Freeserif', '', 10); $pdf->SetTextColor(0, 0, 0); foreach ($entries as $entry) { $pdf->Cell(0, 0, $entry['entry_date_formatted'], 0, 1, L, 0); $pdf->writeHTML('<br/>', true, false, true, false, ''); $pdf->writeHTML($entry['entry_body'], true, false, true, false, ''); $pdf->writeHTML('<div style="height: 5px;"></div>', true, false, true, false, ''); $pdf->writeHTML('<hr>', true, false, true, false, ''); } $fileNamePdf = "journal.pdf"; header("Content-type: application/pdf"); header("Content-disposition: attachment; filename=" . $fileNamePdf); echo $pdf->Output('', 'S'); exit(0); } if (isset($_GET['saveas']) && $_GET['saveas'] == 'doc') { include dirname(__FILE__) . "/classes/html_to_doc.inc.php"; $entriesHTML = ''; foreach ($entries as $entry) { $entriesHTML .= $entry['entry_date_formatted']; $entriesHTML .= $entry['entry_body']; $entriesHTML .= '<hr><br/>'; } $htmltodoc = new HTML_TO_DOC(); $htmltodoc->createDoc($entriesHTML, "journal", true); exit(0); } if (isset($_GET['saveas']) && $_GET['saveas'] == 'txt') { include dirname(__FILE__) . "/classes/html2text.inc"; header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename="journal.txt"'); $entriesHTML = ''; foreach ($entries as $entry) { $entriesHTML .= $entry['entry_date_formatted']; $entriesHTML .= $entry['entry_body']; $entriesHTML .= '<p></p>'; $entriesHTML .= '_______________________________________________________'; $entriesHTML .= '<p></p>'; } $htmlToText = new Html2Text($entriesHTML, 100); $entriesHTMLtext = $htmlToText->convert(); echo $entriesHTMLtext; exit(0); } if (isset($_GET['check_students_journals']) && $_GET['check_students_journals'] == '1') { $professorJournalLessons = $this->getProfessorJournalLessons($currentUser); $journalLessonsStudents = $this->getJournalLessonsStudents($professorJournalLessons); $smarty->assign("T_JOURNAL_STUDENTS", $journalLessonsStudents); } if (isset($_GET['preview_journal']) && $_GET['preview_journal'] == '1' && isset($_GET['student']) && eF_checkParameter($_GET['student'], 'login')) { $userLogin = $_GET['student']; $professorJournalLessons = $this->getProfessorJournalLessons($currentUser); $studentEntries = $this->getStudentEntries($userLogin, $professorJournalLessons); $smarty->assign("T_JOURNAL_STUDENT_ENTRIES", $studentEntries); } if (isset($_REQUEST['autosave']) && $_REQUEST['autosave'] == "1" && isset($_REQUEST['entry_body']) && isset($_REQUEST['edit_entry'])) { if ($_REQUEST['edit_entry'] != "-1") { if (eF_checkParameter($_GET['edit_entry'], 'id')) { $object = eF_getTableData("module_journal_entries", "lessons_ID", "id=" . $_GET['edit_entry']); $fields = array("entry_body" => $_REQUEST['entry_body'], "entry_date" => date('Y') . '-' . date('m') . '-' . date('d') . ' ' . date('H') . ':' . date('i') . ':' . date('s'), "lessons_ID" => $object[0]['lessons_ID'], "users_LOGIN" => $currentUser->user['login']); eF_updateTableData("module_journal_entries", $fields, "id=" . $_REQUEST['edit_entry']); } } else { $fields = array("entry_body" => $_REQUEST['entry_body'], "entry_date" => date('Y') . '-' . date('m') . '-' . date('d') . ' ' . date('H') . ':' . date('i') . ':' . date('s'), "lessons_ID" => $currentLessonID, "users_LOGIN" => $currentUser->user['login']); $id = eF_insertTableData("module_journal_entries", $fields); if ($id) { if (isset($_SESSION['module_journal_autosave_entry'])) { $this->deleteAutoSaveEntry(); $_SESSION['module_journal_autosave_entry'] = $id; } else { $_SESSION['module_journal_autosave_entry'] = $id; } } } exit(0); } if (isset($_REQUEST['show_right']) && $_REQUEST['show_right'] == "1" && isset($_REQUEST['entry_body']) && $_REQUEST['entry_body'] != "" && isset($_REQUEST['edit']) && isset($_REQUEST['edit_entry'])) { if (isset($_SESSION['module_journal_show_right_entry'])) { unset($_SESSION['module_journal_show_right_entry']); } $_SESSION['module_journal_show_right_entry'] = $_REQUEST['entry_body']; } if (isset($_REQUEST['hide_right']) && $_REQUEST['hide_right'] == "1" && isset($_REQUEST['entry_body']) && $_REQUEST['entry_body'] != "" && isset($_REQUEST['edit']) && isset($_REQUEST['edit_entry'])) { if (isset($_SESSION['module_journal_hide_right_entry'])) { unset($_SESSION['module_journal_hide_right_entry']); } $_SESSION['module_journal_hide_right_entry'] = $_REQUEST['entry_body']; } if (isset($_REQUEST['hide_left']) && $_REQUEST['hide_left'] == "1" && isset($_REQUEST['entry_body']) && $_REQUEST['entry_body'] != "" && isset($_REQUEST['edit']) && isset($_REQUEST['edit_entry'])) { if (isset($_SESSION['module_journal_hide_left_entry'])) { unset($_SESSION['module_journal_hide_left_entry']); } $_SESSION['module_journal_hide_left_entry'] = $_REQUEST['entry_body']; } if (isset($_REQUEST['scroll_position']) && eF_checkParameter($_REQUEST['scroll_position'], 'id')) { $_SESSION['module_journal_scroll_position'] = $_REQUEST['scroll_position']; } if (isset($_GET['add_rule']) || isset($_GET['edit_rule']) && eF_checkParameter($_GET['edit_rule'], 'id') && in_array($_GET['edit_rule'], array_keys($rules))) { if ($_SESSION['s_type'] != "administrator") { eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_JOURNAL_NOACCESS)); } isset($_GET['add_rule']) ? $postTarget = "&add_rule=1" : ($postTarget = "&edit_rule=" . $_GET['edit_rule']); global $load_editor; $load_editor = true; $form = new HTML_QuickForm("add_edit_rule_form", "post", $this->moduleBaseUrl . $postTarget, "", null, true); $form->addElement('text', 'title', _TITLE, 'class="inputText" style="width:498px;"'); $form->addRule('title', _THEFIELD . ' "' . _TITLE . '" ' . _ISMANDATORY, 'required', null, 'client'); $form->addElement('textarea', 'description', _DESCRIPTION, 'class="inputContentTextarea simpleEditor" style="width:500px;height:20em;"'); $form->addElement('submit', 'submit', _SUBMIT, 'class="flatButton"'); if (isset($_GET['edit_rule'])) { $editRule = $rules[$_GET['edit_rule']]; $form->setDefaults($editRule); } if ($form->isSubmitted() && $form->validate()) { $values = $form->exportValues(); $fields = array("title" => $values['title'], "description" => $values['description']); if ($values['description'] == '') { $message = _JOURNAL_EMPTY_RULE_DESCRIPTION; if (isset($_GET['add_rule'])) { eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure&add_rule=1"); } else { eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure&edit_rule=" . $_GET['edit_rule']); } } if (isset($_GET['add_rule'])) { if (eF_insertTableData("module_journal_rules", $fields)) { $message = _JOURNAL_RULE_SUCCESSFULLY_ADDED; eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=success"); } else { $message = _JOURNAL_RULE_ADD_PROBLEM; eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure"); } } else { if (eF_updateTableData("module_journal_rules", $fields, "id=" . $_GET['edit_rule'])) { $message = _JOURNAL_RULE_SUCCESSFULLY_EDITED; eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=success"); } else { $message = _JOURNAL_RULE_EDIT_PROBLEM; eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure"); } } } $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty); $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR); $form->setRequiredNote(_REQUIREDNOTE); $form->accept($renderer); $smarty->assign('T_JOURNAL_ADD_EDIT_RULE_FORM', $renderer->toArray()); } else { $rules = $this->getRules(); $smarty->assign("T_JOURNAL_RULES", $rules); $object = eF_getTableData("module_journal_settings", "value", "name='export'"); $smarty->assign("T_JOURNAL_ALLOW_EXPORT", $object[0]['value']); $object = eF_getTableData("module_journal_settings", "value", "name='preview'"); $smarty->assign("T_JOURNAL_ALLOW_PROFESSOR_PREVIEW", $object[0]['value']); if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') { $activeRules = $this->getRules(true); $smarty->assign("T_JOURNAL_ACTIVE_RULES", $activeRules); $entries = $this->getEntries($currentUser->user['login'], $_SESSION['module_journal_entries_from']); $smarty->assign("T_JOURNAL_ENTRIES", $entries); $journalLessons = $this->getJournalLessons($currentUser->user['login']); $smarty->assign("T_JOURNAL_LESSONS", $journalLessons); /* */ global $load_editor; $load_editor = true; if (isset($_GET['edit_entry']) && $_GET['edit_entry'] != '-1') { $postTarget = "&edit_entry=" . $_GET['edit_entry']; } else { $postTarget = "&add_entry=1"; } if (isset($_GET['hide_right']) && $_GET['hide_right'] == '1') { $editorStyle = array('small' => 'width:588px; height:320px;', 'medium' => 'width:673px; height:375px;', 'large' => 'width:759px; height:430px;'); } else { $editorStyle = array('small' => 'width:300px; height:320px;', 'medium' => 'width:344px; height:375px;', 'large' => 'width:388px; height:430px;'); } $form = new HTML_QuickForm("add_edit_entry_form", "post", $this->moduleBaseUrl . $postTarget, "", null, true); $form->addElement('textarea', 'entry_body', _DESCRIPTION, 'class="inputContentTextarea simpleEditor" style="' . $editorStyle[$_SESSION['module_journal_dimension']] . '"'); if (isset($_GET['edit_entry']) && $_GET['edit_entry'] != '-1') { $form->addElement('submit', 'submit', _UPDATE . ' ' . _JOURNAL_ENTRY, 'class="flatButton"'); } else { $form->addElement('submit', 'submit', _SAVE . ' ' . _JOURNAL_ENTRY, 'class="flatButton"'); } if (isset($_GET['edit_entry']) && $_GET['edit_entry'] != '-1') { $editEntry = $entries[$_GET['edit_entry']]; $form->setDefaults($editEntry); if (!in_array($_GET['edit_entry'], array_keys($entries))) { eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_JOURNAL_NOACCESS) . $popup_); } $object = eF_getTableData("module_journal_entries", "lessons_ID, users_LOGIN, entry_date", "id=" . $_GET['edit_entry']); if ($object[0]['users_LOGIN'] != $_SESSION['s_login']) { eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_JOURNAL_NOACCESS) . $popup_); } } if (isset($_GET['show_left']) && $_GET['show_left'] == '1' && isset($_GET['edit']) && isset($_GET['edit_entry'])) { if (isset($_SESSION['module_journal_hide_left_entry'])) { $form->setDefaults(array("entry_body" => $_SESSION['module_journal_hide_left_entry'])); unset($_SESSION['module_journal_hide_left_entry']); } } if (isset($_GET['show_right']) && $_GET['show_right'] == '1' && isset($_GET['edit']) && isset($_GET['edit_entry'])) { if (isset($_SESSION['module_journal_show_right_entry'])) { $form->setDefaults(array("entry_body" => $_SESSION['module_journal_show_right_entry'])); unset($_SESSION['module_journal_show_right_entry']); } } if (isset($_GET['hide_right']) && $_GET['hide_right'] == '1' && isset($_GET['edit']) && isset($_GET['edit_entry'])) { if (isset($_SESSION['module_journal_hide_right_entry'])) { $form->setDefaults(array("entry_body" => $_SESSION['module_journal_hide_right_entry'])); unset($_SESSION['module_journal_hide_right_entry']); } } if ($form->isSubmitted() && $form->validate()) { $values = $form->exportValues(); isset($_GET['add_entry']) ? $lessonID = $currentLessonID : ($lessonID = $object[0]['lessons_ID']); if (isset($_GET['add_entry'])) { $date = date('Y') . '-' . date('m') . '-' . date('d') . ' ' . date('H') . ':' . date('i') . ':' . date('s'); } else { $date = $object[0]['entry_date']; } $fields = array("entry_body" => $values['entry_body'], "entry_date" => $date, "lessons_ID" => $lessonID, "users_LOGIN" => $currentUser->user['login']); if ($values['entry_body'] == '') { $message = _JOURNAL_EMPTY_ENTRY_BODY; eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure" . $popup_); } if (isset($_GET['add_entry'])) { if (eF_insertTableData("module_journal_entries", $fields)) { if (isset($_SESSION['module_journal_autosave_entry'])) { $this->deleteAutoSaveEntry(); } $message = _JOURNAL_ENTRY_SUCCESSFULLY_ADDED; eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=success" . $popup_); } else { $message = _JOURNAL_ENTRY_ADD_PROBLEM; eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure" . $popup_); } } else { if (eF_updateTableData("module_journal_entries", $fields, "id=" . $_GET['edit_entry'])) { $message = _JOURNAL_ENTRY_SUCCESSFULLY_EDITED; eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=success" . $popup_); } else { $message = _JOURNAL_ENTRY_EDIT_PROBLEM; eF_redirect($this->moduleBaseUrl . "&message=" . $message . "&message_type=failure" . $popup_); } } } $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty); $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR); $form->setRequiredNote(_REQUIREDNOTE); $form->accept($renderer); $smarty->assign('T_JOURNAL_ADD_ENTRY_FORM', $renderer->toArray()); if ($currentUser->getRole($this->getCurrentLesson()) == 'professor') { $popupInfo[] = array('text' => _JOURNAL_POPUP_INFO, 'image' => $this->moduleBaseLink . 'images/info.png', 'href' => $this->moduleBaseUrl . '&popup_info=1&popup=1', 'onClick' => "eF_js_showDivPopup(event, '" . _JOURNAL_POPUP_INFO . "', 2)", 'target' => 'POPUP_FRAME', 'id' => 'popup_info'); $smarty->assign("T_JOURNAL_POPUP_INFO", $popupInfo); } } } if ($currentUser->getType() == 'administrator') { return $this->moduleBaseDir . "module_journal_admin.tpl"; } else { if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') { if (isset($_GET['hide_left']) && $_GET['hide_left'] == '1') { return $this->moduleBaseDir . "module_journal_user_right.tpl"; } if (isset($_GET['hide_right']) && $_GET['hide_right'] == '1') { return $this->moduleBaseDir . "module_journal_user_left.tpl"; } return $this->moduleBaseDir . "module_journal_user.tpl"; } } }
/** * Email sending wrapper */ public static function send_email($to, $subject, $html, $plain = null, $headers = array()) { //Validate arguments $html = str_replace(array('\\n\\r', '\\r\\n', '\\n', '\\r'), '<br/>', $html); if (empty($to) || empty($subject) || (empty($html) && empty($plain) || !is_array($headers))) { error_log("attempted to send an empty or misconfigured message"); return false; } $nameAndAddressRegex = '/(.*)<(.*)>/'; $toIncludesNameAndAddress = preg_match($nameAndAddressRegex, $to, $toDetails); if ($toIncludesNameAndAddress) { $toName = $toDetails[1]; $toAddress = $toDetails[2]; } else { $toName = $to; $toAddress = $to; } // If no 'From' address specified, use default if (empty($headers['From'])) { $fromName = DEFAULT_SENDER_NAME; $fromAddress = DEFAULT_SENDER; } else { $fromIncludesNameAndAddress = preg_match($nameAndAddressRegex, $headers['From'], $fromDetails); if ($fromIncludesNameAndAddress) { $fromName = str_replace('"', '', $fromDetails[1]); $fromAddress = str_replace(' ', '-', $fromDetails[2]); } else { $fromName = $headers['From']; $fromAddress = str_replace(' ', '-', $headers['From']); } } if (!empty($html)) { if (empty($plain)) { $h2t = new Html2Text(html_entity_decode($html, ENT_QUOTES), 75); $plain = $h2t->convert(); } } else { if (empty($plain)) { // if both HTML & Plain bodies are empty, don't send mail return false; } } $curl = new CURLHandler(); $postArray = array('from' => $fromAddress, 'fromname' => $fromName, 'to' => $toAddress, 'toname' => $toName, 'subject' => $subject, 'html' => $html, 'text' => $plain, 'api_user' => SENDGRID_API_USER, 'api_key' => SENDGRID_API_KEY); if (!empty($headers['Reply-To'])) { $replyToIncludesNameAndAddress = preg_match($nameAndAddressRegex, $headers['Reply-To'], $replyToDetails); if ($replyToIncludesNameAndAddress) { $postArray['replyto'] = str_replace(' ', '-', $replyToDetails[2]); } else { $postArray['replyto'] = $headers['Reply-To']; } } // check for copy, using bcc since cc is not present in Sendgrid api if (!empty($headers['Cc'])) { $ccIncludesNameAndAddress = preg_match($nameAndAddressRegex, $headers['Cc'], $ccDetails); if ($ccIncludesNameAndAddress) { $postArray['bcc'] = str_replace(' ', '-', $ccDetails[2]); } else { $postArray['bcc'] = $headers['Cc']; } } try { $result = json_decode(CURLHandler::Post(SENDGRID_API_URL, $postArray)); if ($result->message == 'error') { throw new Exception(implode('; ', $result->errors)); } } catch (Exception $e) { error_log("[ERROR] Unable to send message through SendGrid API - Exception: " . $e->getMessage()); return false; } return true; }
} $custom_id_sql_orderby = ""; $custom_id_sql_where = ""; if ($et_custom_id) { $custom_id_sql_orderby = "(`et_custom_id` = '{$et_custom_id}') DESC, "; $custom_id_sql_where = "and (`et_custom_id` = '{$et_custom_id}' OR `et_custom_id` is null)"; } $lang_sql = "(`et_language` = '{$et_language}') DESC"; $sql = "select * from `cs_email_templates` where et_name = '{$et_name}' {$custom_id_sql_where} order by {$custom_id_sql_orderby} {$lang_sql} Limit 1"; $result = mysql_query($sql) or dieLog(mysql_errno() . ": " . mysql_error() . "<BR>"); if (mysql_num_rows($result)) { $emailInfo = mysql_fetch_assoc($result); if ($_POST['Submit'] == 'Generate PlainText') { $asciiText = new Html2Text($emailInfo['et_htmlformat'], 900); // 900 columns maximum $emailInfo['et_textformat'] = $asciiText->convert(); } ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="22" align="left" valign="top" width="1%" background="../images/menucenterbg.gif" nowrap><img border="0" SRC="<?php echo $tmpl_dir; ?> /images/menutopleft.gif" width="8" height="22"></td> <td height="22" align="center" valign="middle" width="50%" background="../images/menucenterbg.gif" ><span class="whitehd">Edit Email Templates </span></td> <td height="22" align="left" valign="top" width="3%" nowrap><img border="0" SRC="<?php echo $tmpl_dir; ?> /images/menutopcurve.gif" width="49" height="22"></td> <td height="22" align="left" valign="top" width="45%" background="../images/menutoprightbg.gif" ><img alt="" SRC="<?php
<?php // Example: html2text // Converts HTML to formatted ASCII text. // Run with: php < ex_html2text.php include "html2text.inc"; $htmlText = "Html2text is a tool that allows you to<br>" . "convert HTML to text.<p>" . "Does it work?"; $htmlToText = new Html2Text($htmlText, 15); $text = $htmlToText->convert(); echo "Conversion follows:\r\n"; echo "-------------------\r\n"; echo $text;
function _convert($aHtmlText, $aMaxColumns) { $html2text = new Html2Text($aHtmlText, $aMaxColumns); return $html2text->convert(); }
} $tickets_thread = findTicketThread(&$emailInfo, $tickets_users_username); if ($tickets_thread['tickets_id']) { $log .= " Found Thread '" . $tickets_thread['tickets_reference'] . "'\n"; $send_auto_response = 1; } else { $log .= " No Thread Found.\n"; } $content = $imap->get_message($emailId); $message = new DecodeMessage(); $message->InitMessage($content); $emailInfo = array_merge($message->ResultInfo(), $emailInfo); if ($emailInfo['type'] == 'text/html') { $asciiText = new Html2Text($emailInfo['body'], 70); // 900 columns maximum $emailInfo['body'] = $asciiText->convert(); } $new_ticket = createNewTicket(&$emailInfo, $tickets_users_username, $tickets_thread, $account['category']); if ($new_ticket['tickets_id']) { $log .= " Created New Ticket '{$new_ticket}' on thread '" . $new_ticket['tickets_reference'] . "'\n"; } if (!$new_ticket['tickets_reference']) { dieLog("Invalid Reference ID", "Invalid Reference ID"); } if ($send_auto_response) { $data = array(); $data['ticket_id'] = $new_ticket['tickets_reference']; $data['subject'] = $emailInfo['Subject']; $data['category'] = $category; $data['full_name'] = $emailInfo['FromEmail']; $data['email'] = $emailInfo['FromEmail'];