File: stationery.php

package info (click to toggle)
imp4 4.1.3-4
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 14,988 kB
  • ctags: 3,720
  • sloc: xml: 17,038; php: 16,350; makefile: 64
file content (118 lines) | stat: -rw-r--r-- 4,065 bytes parent folder | download
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
<?php
/**
 * $Horde: imp/stationery.php,v 2.1.2.3 2006/02/20 15:08:50 jan Exp $
 *
 * Copyright 2005-2006 Jan Schneider <jan@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.
 */

@define('IMP_BASE', dirname(__FILE__));
$authentication = OP_HALFOPEN;
require_once IMP_BASE . '/lib/base.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();
}
$stationery = null;

/* Get form data. */
$id = Util::getFormData('id');
if (!is_null($id)) {
    $id = (int)$id;
}
$selected = Util::getFormData('stationery');
if (strlen($selected)) {
    $selected = (int)$selected;
}

/* 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']);
            $id = $selected;
        } else {
            /* Create new. */
            $stationery = array('n' => '', 't' => 'plain', 'c' => '');
        }
    } elseif (Util::getFormData('delete')) {
        /* Delete stationery. */
        if (isset($stationery_list[$id])) {
            $updated = sprintf(_("The stationery \"%s\" has been deleted."), $stationery_list[$id]['n']);
            unset($stationery_list[$id]);
        }
    } else {
        $last_type = Util::getFormData('last_type');
        $type = Util::getFormData('type', 'plain');
        $name = Util::getFormData('name', '');
        $content = Util::getFormData('content', '');
        $stationery = array('n' => $name, 't' => $type, 'c' => $content);
        if (!empty($last_type)) {
            if ($last_type != $type) {
                /* Switching text format. */
                if ($type == 'plain') {
                    require_once 'Horde/Text/Filter.php';
                    $content = Text_Filter::filter($content, 'html2text');
                }
                $stationery['c'] = $content;
            } else {
                /* Saving stationery. */
                if (is_null($id)) {
                    $id = count($stationery_list);
                    $stationery_list[] = $stationery;
                    $updated = sprintf(_("The stationery \"%s\" has been added."), $stationery['n']);
                } else {
                    $stationery_list[$id] = $stationery;
                    $updated = sprintf(_("The stationery \"%s\" has been updated."), $stationery['n']);
                }
            }
        } elseif (!is_null($id)) {
            $stationery = $stationery_list[$id];
        }
    }

    break;
}

if ($updated) {
    $prefs->setValue('stationery', serialize(String::convertCharset($stationery_list, NLS::getCharset(), $prefs->getCharset())), false);
    $notification->push($updated, 'horde.success');
}

if (!is_null($stationery) && $stationery['t'] == 'html') {
    require_once 'Horde/Editor.php';
    $editor = &Horde_Editor::singleton('xinha', array('id' => 'content'));
}

/* Show the header. */
require_once 'Horde/Prefs/UI.php';
require IMP_BASE . '/config/prefs.php';
$app = 'imp';
$group = 'compose';

Prefs_UI::generateHeader();
require IMP_TEMPLATES . '/stationery/prefs.inc';

require $registry->get('templates', 'horde') . '/common-footer.inc';