File: prefs.php

package info (click to toggle)
horde3 3.0.4-4sarge7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 15,980 kB
  • ctags: 16,295
  • sloc: php: 68,726; xml: 2,382; sql: 498; makefile: 74; sh: 63; pascal: 6
file content (145 lines) | stat: -rw-r--r-- 4,522 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
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
<?php
/**
 * $Horde: horde/lib/prefs.php,v 1.19.4.4 2005/02/16 21:55:30 jan Exp $
 *
 * Copyright 1999-2005 Charles J. Hagenbuch <chuck@horde.org>
 * Copyright 1999-2005 Jon Parise <jon@horde.org>
 *
 * See the enclosed file COPYING for license information (LGPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

function handle_showsummaryselect($updated)
{
    global $prefs;

    $show_summaries = Util::getFormData('show_summaries');
    if (!is_null($show_summaries)) {
        $prefs->setValue('show_summaries', $show_summaries);
        $updated = true;
    }

    return $updated;
}

function handle_themeselect($updated)
{
    global $prefs;

    $theme = Util::getFormData('theme');
    if (!is_null($theme)) {
        $prefs->setValue('theme', $theme);
        $updated = true;
    }

    return $updated;
}

function handle_categorymanagement($updated)
{
    require_once 'Horde/Prefs/CategoryManager.php';
    $cManager = &new Prefs_CategoryManager();

    /* Always save colors of all categories. */
    $colors = array_unique(array_merge($cManager->get(), array_keys($cManager->colors())));
    foreach ($colors as $category) {
        if ($color = Util::getFormData('color_' . base64_encode($category))) {
            $colors[$category] = $color;
        }
    }
    $cManager->setColors($colors);

    $action = Util::getFormData('cAction');
    $category = Util::getFormData('category');

    switch ($action) {
    case 'add':
        $cManager->add($category);
        break;

    case 'remove':
        $cManager->remove($category);
        break;

    default:
        /* Save button. */
        $updated = true;
    }

    return $updated;
}

/**
 * Do anything that we need to do as a result of certain preferences
 * changing.
 */
function prefs_callback()
{
    global $prefs, $registry, $notification;

    if ($prefs->isDirty('language')) {
        NLS::setLang($prefs->getValue('language'));
        NLS::setTextdomain($registry->getApp(), $registry->get('fileroot') . '/locale', NLS::getCharset());
        String::setDefaultCharset(NLS::getCharset());
    }

    if ($prefs->isDirty('language')) {
        $url = $registry->get('webroot', 'horde');
        if (substr($url, -1) != '/') {
            $url .= '/';
        }
        $url = Util::addParameter($url . 'index.php', 'url', Horde::selfUrl(true));
        $notification->push('if (window.parent.frames) window.parent.frames.location = \'' . addslashes(Horde::url($url, true)) . '\';', 'javascript');
    }

    if ($prefs->isDirty('sidebar_width')) {
        $notification->push('if (window.parent && window.parent.document.getElementById(\'hf\') && window.parent.horde_menu && window.parent.horde_menu.expandedSidebar.shown()) window.parent.document.getElementById(\'hf\').cols = window.parent.horde_menu.rtl ? \'*,' . $prefs->getValue('sidebar_width') . '\' : \'' . $prefs->getValue('sidebar_width') . ',*\';', 'javascript');
    }

    if ($prefs->isDirty('theme') ||
        $prefs->isDirty('menu_view')) {
        $notification->push('if (window.parent.frames.horde_menu) window.parent.frames.horde_menu.location.reload();', 'javascript');
    }
}

/* Assign variables for select lists. */
if (!$prefs->isLocked('timezone')) {
    $timezone_options = &$tz;
    array_unshift($timezone_options, _("Default"));
}
if (!$prefs->isLocked('initial_application')) {
    global $perms;

    $initial_application_options = array();
    $apps = $registry->listApps(array('active'));
    foreach ($apps as $a) {
        if (file_exists($registry->get('fileroot', $a)) &&
            (($perms->exists($a) && ($perms->hasPermission($a, Auth::getAuth(), PERMS_READ) || Auth::isAdmin())) ||
             !$perms->exists($a))) {
            $initial_application_options[$a] = $registry->get('name', $a);
        }
    }
    asort($initial_application_options);
}
if (!$prefs->isLocked('theme')) {
    $theme_options = array();
    $theme_base = $registry->get('themesfs', 'horde');
    $dh = @opendir($theme_base);
    if (!$dh) {
        $notification->push("Theme directory can't be opened", 'horde.error');
    } else {
        while (($dir = readdir($dh)) !== false) {
            if ($dir == '.' || $dir == '..') {
                continue;
            }

            $theme_name = null;
            @include $theme_base . '/' . $dir . '/info.php';
            if (!empty($theme_name)) {
                $theme_options[$dir] = $theme_name;
            }
        }
    }

    asort($theme_options);
}