1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * phpGroupWare - Preferences - categories * |
---|
4 | * http://www.phpgroupware.org * |
---|
5 | * Written by Bettina Gille [ceb@phpgroupware.org] * |
---|
6 | * ----------------------------------------------- * |
---|
7 | * This program is free software; you can redistribute it and/or modify it * |
---|
8 | * under the terms of the GNU General Public License as published by the * |
---|
9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
10 | * option) any later version. * |
---|
11 | \**************************************************************************/ |
---|
12 | |
---|
13 | class bocategories |
---|
14 | { |
---|
15 | var $cats; |
---|
16 | |
---|
17 | var $start; |
---|
18 | var $query; |
---|
19 | var $sort; |
---|
20 | var $order; |
---|
21 | |
---|
22 | function bocategories($cats_app='') |
---|
23 | { |
---|
24 | $this->cats = CreateObject('phpgwapi.categories'); |
---|
25 | $this->cats->app_name = $cats_app; |
---|
26 | |
---|
27 | $this->read_sessiondata($cats_app); |
---|
28 | |
---|
29 | $start = $GLOBALS['HTTP_POST_VARS']['start'] ? $GLOBALS['HTTP_POST_VARS']['start'] : $GLOBALS['HTTP_GET_VARS']['start']; |
---|
30 | $query = $GLOBALS['HTTP_POST_VARS']['query'] ? $GLOBALS['HTTP_POST_VARS']['query'] : $GLOBALS['HTTP_GET_VARS']['query']; |
---|
31 | $sort = $GLOBALS['HTTP_POST_VARS']['sort'] ? $GLOBALS['HTTP_POST_VARS']['sort'] : $GLOBALS['HTTP_GET_VARS']['sort']; |
---|
32 | $order = $GLOBALS['HTTP_POST_VARS']['order'] ? $GLOBALS['HTTP_POST_VARS']['order'] : $GLOBALS['HTTP_GET_VARS']['order']; |
---|
33 | |
---|
34 | if(!empty($start) || $start == '0' || $start == 0) |
---|
35 | { |
---|
36 | $this->start = $start; |
---|
37 | } |
---|
38 | if((empty($query) && !empty($this->query)) || !empty($query)) |
---|
39 | { |
---|
40 | $this->query = $query; |
---|
41 | } |
---|
42 | |
---|
43 | if(isset($sort) && !empty($sort)) |
---|
44 | { |
---|
45 | $this->sort = $sort; |
---|
46 | } |
---|
47 | if(isset($order) && !empty($order)) |
---|
48 | { |
---|
49 | $this->order = $order; |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | function save_sessiondata($data, $cats_app) |
---|
54 | { |
---|
55 | $colum = $cats_app . '_cats'; |
---|
56 | $GLOBALS['phpgw']->session->appsession('session_data',$column,$data); |
---|
57 | } |
---|
58 | |
---|
59 | function read_sessiondata($cats_app) |
---|
60 | { |
---|
61 | $colum = $cats_app . '_cats'; |
---|
62 | $data = $GLOBALS['phpgw']->session->appsession('session_data',$column); |
---|
63 | |
---|
64 | $this->start = $data['start']; |
---|
65 | $this->query = $data['query']; |
---|
66 | $this->sort = $data['sort']; |
---|
67 | $this->order = $data['order']; |
---|
68 | } |
---|
69 | |
---|
70 | function get_list($global_cats) |
---|
71 | { |
---|
72 | return $this->cats->return_sorted_array($this->start,True,$this->query,$this->sort,$this->order,$global_cats); |
---|
73 | } |
---|
74 | |
---|
75 | function save_cat($values) |
---|
76 | { |
---|
77 | if ($values['access']) |
---|
78 | { |
---|
79 | $values['access'] = 'private'; |
---|
80 | } |
---|
81 | else |
---|
82 | { |
---|
83 | $values['access'] = 'public'; |
---|
84 | } |
---|
85 | |
---|
86 | if ($values['id'] && $values['id'] != 0) |
---|
87 | { |
---|
88 | return $this->cats->edit($values); |
---|
89 | } |
---|
90 | else |
---|
91 | { |
---|
92 | return $this->cats->add($values); |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | function exists($data) |
---|
97 | { |
---|
98 | $data['type'] = $data['type'] ? $data['type'] : ''; |
---|
99 | $data['cat_id'] = $data['cat_id'] ? $data['cat_id'] : ''; |
---|
100 | return $this->cats->exists($data['type'],$data['cat_name'],$data['cat_id']); |
---|
101 | } |
---|
102 | |
---|
103 | function formatted_list($format,$type,$cat_parent,$global_cats) |
---|
104 | { |
---|
105 | return $this->cats->formated_list($format,$type,$cat_parent,$global_cats); |
---|
106 | } |
---|
107 | |
---|
108 | function delete($cat_id,$subs) |
---|
109 | { |
---|
110 | return $this->cats->delete($cat_id,$subs,!$subs); // either delete the subs or modify them |
---|
111 | } |
---|
112 | |
---|
113 | function check_values($values) |
---|
114 | { |
---|
115 | if (strlen($values['descr']) >= 255) |
---|
116 | { |
---|
117 | $error[] = lang('Description can not exceed 255 characters in length !'); |
---|
118 | } |
---|
119 | |
---|
120 | if (!$values['name']) |
---|
121 | { |
---|
122 | $error[] = lang('Please enter a name'); |
---|
123 | } |
---|
124 | else |
---|
125 | { |
---|
126 | if (!$values['parent']) |
---|
127 | { |
---|
128 | $exists = $this->exists(array |
---|
129 | ( |
---|
130 | 'type' => 'appandmains', |
---|
131 | 'cat_name' => $values['name'], |
---|
132 | 'cat_id' => $values['id'] |
---|
133 | )); |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | $exists = $this->exists(array |
---|
138 | ( |
---|
139 | 'type' => 'appandsubs', |
---|
140 | 'cat_name' => $values['name'], |
---|
141 | 'cat_id' => $values['id'] |
---|
142 | )); |
---|
143 | } |
---|
144 | |
---|
145 | if ($exists == True) |
---|
146 | { |
---|
147 | $error[] = lang('This name has been used already'); |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | if (is_array($error)) |
---|
152 | { |
---|
153 | return $error; |
---|
154 | } |
---|
155 | } |
---|
156 | } |
---|