1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Prefs_Special_Flag implements Horde_Core_Prefs_Ui_Special
24: {
25: 26:
27: public function init(Horde_Core_Prefs_Ui $ui)
28: {
29: global $prefs;
30:
31: if ($prefs->isLocked('msgflags') && $prefs->isLocked('msgflags_user')) {
32: $ui->nobuttons = true;
33: }
34: }
35:
36: 37:
38: public function display(Horde_Core_Prefs_Ui $ui)
39: {
40: global $injector, $page_output, $prefs;
41:
42: if (!$ui->nobuttons) {
43: $page_output->addScriptFile('hordecore.js', 'horde');
44: $page_output->addScriptFile('colorpicker.js', 'horde');
45: $page_output->addScriptFile('flagprefs.js');
46: }
47:
48: $page_output->addInlineJsVars(array(
49: 'ImpFlagPrefs.new_prompt' => _("Please enter the label for the new flag:"),
50: 'ImpFlagPrefs.confirm_delete' => _("Are you sure you want to delete this flag?")
51: ));
52:
53: $view = new Horde_View(array(
54: 'templatePath' => IMP_TEMPLATES . '/prefs'
55: ));
56: $view->addHelper('FormTag');
57: $view->addHelper('Tag');
58:
59: $view->locked = $prefs->isLocked('msgflags');
60: $view->picker_img = Horde_Themes_Image::tag('colorpicker.png', array(
61: 'alt' => _("Color Picker")
62: ));
63:
64: $out = array();
65: $flaglist = $injector->getInstance('IMP_Flags')->getList();
66: foreach ($flaglist as $val) {
67: $hash = $val->hash;
68: $bgid = 'bg_' . $hash;
69: $color = $val->bgdefault ? '' : $val->bgcolor;
70: $tmp = array();
71:
72: if ($val instanceof IMP_Flag_User) {
73: $tmp['label'] = htmlspecialchars($val->label);
74: $tmp['label_name'] = 'label_' . $hash;
75: $tmp['user'] = true;
76: } else {
77: $tmp['icon'] = $val->span;
78: $tmp['label'] = Horde::label($bgid, $val->label);
79: }
80:
81: $tmp['color'] = $color;
82: $tmp['colorid'] = $bgid;
83: $tmp['colorstyle'] = 'color:' . $val->fgcolor . ';' .
84: (strlen($color) ? ('background-color:' . $color . ';') : '');
85:
86: $out[] = $tmp;
87: }
88: $view->flags = $out;
89:
90: return $view->render('flags');
91: }
92:
93: 94:
95: public function update(Horde_Core_Prefs_Ui $ui)
96: {
97: global $injector, $notification;
98:
99: $imp_flags = $injector->getInstance('IMP_Flags');
100:
101: if ($ui->vars->flag_action == 'add') {
102: $notification->push(sprintf(_("Added flag \"%s\"."), $ui->vars->flag_data), 'horde.success');
103: $imp_flags->addFlag($ui->vars->flag_data);
104: return;
105: }
106:
107:
108:
109: $update = false;
110: foreach ($imp_flags->getList() as $val) {
111: $hash = $val->hash;
112:
113: switch ($ui->vars->flag_action) {
114: case 'delete':
115: if ($ui->vars->flag_data == ('bg_' . $hash)) {
116: unset($imp_flags[$val->id]);
117: $notification->push(sprintf(_("Deleted flag \"%s\"."), $val->label), 'horde.success');
118: }
119: break;
120:
121: default:
122:
123: if ($val instanceof IMP_Flag_User) {
124: $label = $ui->vars->get('label_' . $hash);
125: if (strlen($label) && ($label != $val->label)) {
126: $imp_flags->updateFlag($val->id, 'label', $label);
127: $update = true;
128: }
129: }
130:
131:
132: $bg = strtolower($ui->vars->get('bg_' . $hash));
133: if ($bg != $val->bgcolor) {
134: $imp_flags->updateFlag($val->id, 'bgcolor', $bg);
135: $update = true;
136: }
137: break;
138: }
139: }
140:
141: return $update;
142: }
143:
144: }
145: