File: Category.php

package info (click to toggle)
php-horde 5.2.1%2Bdebian0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 12,196 kB
  • sloc: php: 11,089; xml: 6,460; sh: 96; makefile: 33; sql: 1
file content (141 lines) | stat: -rw-r--r-- 4,179 bytes parent folder | download | duplicates (2)
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
<?php
/**
 * Special prefs handling for the 'categorymanagement' preference.
 *
 * Copyright 2012-2014 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl.
 *
 * @author   Michael Slusarz <slusarz@horde.org>
 * @category Horde
 * @license  http://www.horde.org/licenses/lgpl LGPL
 * @package  Horde
 */
class Horde_Prefs_Special_Category implements Horde_Core_Prefs_Ui_Special
{
    /**
     */
    public function init(Horde_Core_Prefs_Ui $ui)
    {
    }

    /**
     */
    public function display(Horde_Core_Prefs_Ui $ui)
    {
        global $page_output, $prefs;

        $page_output->addScriptFile('categoryprefs.js', 'horde');
        $page_output->addScriptFile('colorpicker.js', 'horde');
        $page_output->addInlineJsVars(array(
            'HordeCategoryPrefs.category_text' => _("Enter a name for the new category:")
        ));

        $cManager = new Horde_Prefs_CategoryManager();
        $categories = $cManager->get();
        $colors = $cManager->colors();
        $fgcolors = $cManager->fgColors();

        $view = new Horde_View(array(
            'templatePath' => HORDE_TEMPLATES . '/prefs'
        ));
        $view->addHelper('Horde_Core_View_Helper_Image');
        $view->addHelper('Horde_Core_View_Helper_Label');
        $view->addHelper('Text');

        $view->picker_img = !$prefs->isLocked('category_colors');

        // Default Color
        $color = isset($colors['_default_'])
            ? $colors['_default_']
            : '#FFFFFF';
        $fgcolor = isset($fgcolors['_default_'])
            ? $fgcolors['_default_']
            : '#000000';
        $color_b = 'color_' . hash('md5', '_default_');

        $view->default_color = $color;
        $view->default_fgcolor = $fgcolor;
        $view->default_id = $color_b;

        // Unfiled Color
        $color = isset($colors['_unfiled_'])
            ? $colors['_unfiled_']
            : '#FFFFFF';
        $fgcolor = isset($fgcolors['_unfiled_'])
            ? $fgcolors['_unfiled_']
            : '#000000';
        $color_b = 'color_' . hash('md5', '_unfiled_');

        $view->unfiled_color = $color;
        $view->unfiled_fgcolor = $fgcolor;
        $view->unfiled_id = $color_b;

        $entries = array();
        foreach ($categories as $name) {
            $color = isset($colors[$name])
                ? $colors[$name]
                : '#FFFFFF';
            $fgcolor = isset($fgcolors[$name])
                ? $fgcolors[$name]
                : '#000000';
            $color_b = 'color_' . hash('md5', $name);

            $entries[] = array(
                'color' => $color,
                'fgcolor' => $fgcolor,
                'id' => $color_b,
                'name' => $name
            );
        }
        $view->categories = $entries;

        return $view->render('category');
    }

    /**
     */
    public function update(Horde_Core_Prefs_Ui $ui)
    {
        global $page_output;

        $cManager = new Horde_Prefs_CategoryManager();

        /* Always save colors of all categories. */
        $colors = array();
        $categories = $cManager->get();
        foreach ($categories as $category) {
            if ($color = $ui->vars->get('color_' . hash('md5', $category))) {
                $colors[$category] = $color;
            }
        }
        if ($color = $ui->vars->get('color_' . hash('md5', '_default_'))) {
            $colors['_default_'] = $color;
        }
        if ($color = $ui->vars->get('color_' . hash('md5', '_unfiled_'))) {
            $colors['_unfiled_'] = $color;
        }
        $cManager->setColors($colors);

        switch ($ui->vars->cAction) {
        case 'add':
            $cManager->add($ui->vars->category);
            break;

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

        default:
            /* Save button. */
            $page_output->addInlineScript(array(
                'if (window.opener && window.name) window.close();'
            ));
            return true;
        }

        return false;
    }

}