1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
<?php
/**
* $Horde: imp/stationery.php,v 2.1.2.10 2008/04/08 04:48:53 slusarz Exp $
*
* Copyright 2005-2008 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
*
* @author Jan Schneider <jan@horde.org>
*/
@define('IMP_BASE', dirname(__FILE__));
$authentication = 'horde';
require_once IMP_BASE . '/lib/base.php';
require_once IMP_BASE . '/lib/Template.php';
require_once 'Horde/Prefs/UI.php';
$compose_url = Util::addParameter(Horde::url($registry->get('webroot', 'horde') . '/services/prefs.php', true), 'app', 'imp', false);
/* Is the preference locked? */
if ($prefs->isLocked('stationery')) {
header('Location: ' . $compose_url);
exit;
}
/* Retrieve stationery. */
$stationery_list = @unserialize($prefs->getValue('stationery', false));
if (is_array($stationery_list)) {
$stationery_list = String::convertCharset($stationery_list, $prefs->getCharset());
} else {
$stationery_list = array();
}
/* Get form data. */
$selected = Util::getFormData('stationery');
if (strlen($selected)) {
$selected = (int)$selected;
}
/* Always check for stationery type switches. */
$content = Util::getFormData('content', '');
$last_type = Util::getFormData('last_type');
$name = Util::getFormData('name', '');
$type = Util::getFormData('type', 'plain');
if (!empty($last_type) && $last_type != $type) {
if ($type == 'plain') {
require_once 'Horde/Text/Filter.php';
$content = Text_Filter::filter($content, 'html2text');
} else {
$content = nl2br(htmlspecialchars(htmlspecialchars($content)));
}
}
$stationery = array('n' => $name, 't' => $type, 'c' => $content);
/* Run through the action handlers. */
$actionID = Util::getFormData('actionID');
$updated = false;
switch ($actionID) {
case 'update':
if (Util::getFormData('edit')) {
/* Stationery has been switched. */
if (strlen($selected)) {
/* Edit existing. */
$stationery = array('n' => $stationery_list[$selected]['n'],
't' => $stationery_list[$selected]['t'],
'c' => $stationery_list[$selected]['c']);
} else {
$stationery = array('n' => '', 't' => 'plain', 'c' => '');
}
} elseif (Util::getFormData('delete')) {
/* Delete stationery. */
if (isset($stationery_list[$selected])) {
$updated = sprintf(_("The stationery \"%s\" has been deleted."), $stationery_list[$selected]['n']);
unset($stationery_list[$selected]);
$selected = null;
}
$stationery = array('n' => '', 't' => 'plain', 'c' => '');
} elseif (Util::getFormData('save')) {
/* Saving stationery. */
if (!strlen($selected)) {
$selected = count($stationery_list);
$stationery_list[] = $stationery;
$updated = sprintf(_("The stationery \"%s\" has been added."), $stationery['n']);
} else {
$stationery_list[$selected] = $stationery;
$updated = sprintf(_("The stationery \"%s\" has been updated."), $stationery['n']);
}
}
break;
}
if ($updated) {
$prefs->setValue('stationery', serialize(String::convertCharset($stationery_list, NLS::getCharset(), $prefs->getCharset())), false);
$notification->push($updated, 'horde.success');
}
if ($stationery['t'] == 'html') {
require_once 'Horde/Editor.php';
$editor = &Horde_Editor::singleton($prefs->getValue('jseditor'), array('id' => 'content'));
}
/* Show the header. */
require_once 'Horde/Prefs/UI.php';
if (is_callable(array('Horde', 'loadConfiguration'))) {
$result = Horde::loadConfiguration('prefs.php', array('prefGroups', '_prefs'), 'imp');
if (!is_a($result, 'PEAR_Error')) {
extract($result);
}
} else {
require IMP_BASE . '/config/prefs.php';
}
$app = 'imp';
$chunk = Util::nonInputVar('chunk');
Prefs_UI::generateHeader(null, $chunk);
$t = new IMP_Template();
$t->setOption('gettext', true);
$t->set('action', Horde::selfUrl());
$t->set('forminput', Util::formInput());
$t->set('navcell', Util::bufferOutput(array('Prefs_UI', 'generateNavigationCell'), 'compose'));
$slist = array();
foreach ($stationery_list as $key => $choice) {
$slist[] = array(
'val' => $key,
'selected' => ($selected === $key),
'text' => $choice['n'] . ' ' . ($choice['t'] == 'html' ? _("(HTML)") : _("(Plain Text)"))
);
}
$t->set('slist', $slist);
$t->set('selected', strlen($selected));
$t->set('last_type', $stationery['t']);
$t->set('name_label', Horde::label('name', _("Stationery name:")));
$t->set('name', $stationery['n']);
$t->set('type_label', Horde::label('name', _("Stationery type:")));
$t->set('plain', $stationery['t'] == 'plain');
$t->set('html', $stationery['t'] == 'html');
$t->set('content_label', Horde::label('content', _("Stationery:")));
$t->set('content', $stationery['c']);
$t->set('button_href', Util::addParameter($compose_url, 'group', 'compose'));
$t->set('button_val', htmlspecialchars(_("Return to Message Composition"), ENT_COMPAT, NLS::getCharset()));
echo $t->fetch(IMP_TEMPLATES . '/stationery/stationery.html');
if (!$chunk) {
require $registry->get('templates', 'horde') . '/common-footer.inc';
}
|