Changeset 577 for trunk/phpgwapi/inc/class.categories.inc.php
- Timestamp:
- 01/07/09 17:14:51 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpgwapi/inc/class.categories.inc.php
r2 r577 56 56 $this->app_name = $GLOBALS['phpgw']->db->db_addslashes($app_name); 57 57 $this->db = $GLOBALS['phpgw']->db; 58 $this->db2 = $this->db; 58 $this->db2 = $this->db; 59 59 $this->grants = $GLOBALS['phpgw']->acl->get_grants($app_name); 60 60 } … … 137 137 @param $order order by 138 138 @param $globals True or False, includes the global egroupware categories or not 139 @param $parent_id 140 @param $lastmod integer defaults to -1 141 @param column string default to '' (All), includes the column returned. 139 142 @result $cats array 140 143 */ 141 144 function return_array($type,$start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '', $lastmod = -1, $column = '') 142 145 { 143 //casting and addslashes for security 144 $start = (int)$start; 145 $parent_id = (int)$parent_id; 146 $query = $this->db->db_addslashes($query); 147 $sort = $this->db->db_addslashes($sort); 148 $order = $this->db->db_addslashes($order); 149 150 if ($globals) 151 { 152 $global_cats = " OR cat_appname='phpgw'"; 153 } 154 155 $filter = $this->filter($type); 156 146 return $this -> return_sorted_array( $start, $limit, $query, $sort, $order, $globals, $parent_id, NULL, $lastmod, $column); 147 } 148 /*! 149 @function return_sorted_array 150 @abstract return an array populated with categories 151 @param $type string defaults to 'all' 152 @param $start ? 153 @param $limit ? 154 @param $query string defaults to '' 155 @param $sort string sort order, either defaults to 'ASC' 156 @param $order order by 157 @param $globals True or False, includes the global egroupware categories or not 158 @param $parent_id string defaults to '', includes the parent category ID 159 @param $group_id integer defaults to NULL, includes the gidNumber 160 @param $lastmod integer defaults to -1 161 @param column string default to '' (All), includes the column returned. 162 @result $cats array 163 */ 164 function return_sorted_array($start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '',$group_id = NULL,$lastmod = -1, $column = '') 165 { 166 //casting and slashes for security 167 $start = (int)$start; 168 $query = $this->db->db_addslashes($query); 169 $sort = $this->db->db_addslashes($sort); 170 $order = $this->db->db_addslashes($order); 171 $parent_id = (int)$parent_id; 172 173 if ($globals && !$group_id) 174 { 175 $global_cats = " cat_appname='phpgw'"; 176 } 177 157 178 if (!$sort) 158 179 { … … 160 181 } 161 182 162 if (!empty($order) && preg_match('/^[a-zA-Z_ (), ]+$/',$order) && (empty($sort) || preg_match('/^(ASC|DESC|asc|desc)$/',$sort)))183 if (!empty($order) && preg_match('/^[a-zA-Z_, ]+$/',$order) && (empty($sort) || preg_match('/^(ASC|DESC|asc|desc)$/',$sort))) 163 184 { 164 185 $ordermethod = " ORDER BY $order $sort"; … … 166 187 else 167 188 { 168 $ordermethod = ' ORDER BY cat_main, cat_level, cat_name ASC'; 169 } 170 171 if ($this->account_id == '-1') 172 { 173 $grant_cats = ' cat_owner=-1 '; 174 } 175 else 176 { 189 $ordermethod = ' ORDER BY cat_name ASC'; 190 } 191 192 if($group_id){ 193 $grant_cats .= " cat_owner='".$group_id."' "; 194 } 195 else if ($this->account_id != '-1'){ 196 $grants = $this->grants; 197 $groups = $GLOBALS['phpgw']->accounts->membership(); 198 177 199 if (is_array($this->grants)) 178 200 { 179 $grants = $this->grants; 180 while(list($user) = each($grants)) 181 { 182 $public_user_list[] = $user; 183 } 184 reset($public_user_list); 185 $grant_cats = ' (cat_owner=' . $this->account_id . " OR cat_owner=-1 OR cat_access='public' AND cat_owner in(" . implode(',',$public_user_list) . ')) '; 201 202 foreach($grants as $idx => $user){ 203 $public_user_list[$user] = $user; 204 } 205 if(is_array($groups)){ 206 foreach($groups as $idx => $group) { 207 $public_user_list[$group['account_id']] = $group['account_id']; 208 } 209 } 210 @reset($public_user_list); 211 $grant_cats = " (cat_owner='" . $this->account_id . "' ".(is_array($public_user_list) ? "OR (cat_owner in(" . implode(',',$public_user_list) . ") AND cat_access='public')" : "").") "; 212 186 213 } 187 214 else 188 215 { 189 $grant_cats = ' cat_owner=' . $this->account_id . ' OR cat_owner=-1 '; 190 } 191 } 192 193 if ($parent_id > 0) 194 { 195 $parent_filter = ' AND cat_parent=' . $parent_id; 196 } 216 $grant_cats = " cat_owner='" . $this->account_id . "' or cat_owner='-1' "; 217 } 218 } 219 220 221 $parent_select = ' AND cat_parent=' . $parent_id; 197 222 198 223 if ($query) 199 224 { 200 $querymethod = " AND (cat_name LIKE '%$query%' OR cat_descriptionLIKE '%$query%') ";225 $querymethod = " AND (cat_name ILIKE '%$query%' OR cat_description ILIKE '%$query%') "; 201 226 } 202 227 … … 228 253 } 229 254 230 $sql = "SELECT $table_column FROM phpgw_categories WHERE (cat_appname='" . $this->app_name . "' AND" . $grant_cats . $global_cats . ')' 231 . $parent_filter . $querymethod . $filter; 232 233 $this->db2->query($sql,__LINE__,__FILE__); 234 $this->total_records = $this->db2->num_rows(); 235 236 if ($limit) 237 { 238 $this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__); 239 } 240 else 241 { 242 $this->db->query($sql . $ordermethod,__LINE__,__FILE__); 243 } 244 245 while ($this->db->next_record()) 246 { 247 if ($column) 248 { 249 $cats[] = array 250 ( 251 $column => $this->db->f(0) 252 ); 253 } 254 else 255 { 256 $cats[] = array 257 ( 258 'id' => $this->db->f('cat_id'), 259 'owner' => $this->db->f('cat_owner'), 260 'access' => $this->db->f('cat_access'), 261 'app_name' => $this->db->f('cat_appname'), 262 'main' => $this->db->f('cat_main'), 263 'level' => $this->db->f('cat_level'), 264 'parent' => $this->db->f('cat_parent'), 265 'name' => $this->db->f('cat_name'), 266 'description' => $this->db->f('cat_description'), 267 'data' => $this->db->f('cat_data'), 268 'last_mod' => $this->db->f('last_mod') 269 ); 270 } 271 } 272 return $cats; 273 } 274 275 function return_sorted_array($start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '') 276 { 277 //casting and slashes for security 278 $start = (int)$start; 279 $query = $this->db->db_addslashes($query); 280 $sort = $this->db->db_addslashes($sort); 281 $order = $this->db->db_addslashes($order); 282 $parent_id = (int)$parent_id; 283 284 if ($globals) 285 { 286 $global_cats = " OR cat_appname='phpgw'"; 287 } 288 289 if (!$sort) 290 { 291 $sort = 'ASC'; 292 } 293 294 if (!empty($order) && preg_match('/^[a-zA-Z_, ]+$/',$order) && (empty($sort) || preg_match('/^(ASC|DESC|asc|desc)$/'))) 295 { 296 $ordermethod = " ORDER BY $order $sort"; 297 } 298 else 299 { 300 $ordermethod = ' ORDER BY cat_name ASC'; 301 } 302 303 if ($this->account_id == '-1') 304 { 305 $grant_cats = " cat_owner='-1' "; 306 } 307 else 308 { 309 if (is_array($this->grants)) 310 { 311 $grants = $this->grants; 312 while(list($user) = each($grants)) 313 { 314 $public_user_list[] = $user; 315 } 316 reset($public_user_list); 317 $grant_cats = " (cat_owner='" . $this->account_id . "' OR cat_owner='-1' OR cat_access='public' AND cat_owner in(" . implode(',',$public_user_list) . ")) "; 318 } 319 else 320 { 321 $grant_cats = " cat_owner='" . $this->account_id . "' or cat_owner='-1' "; 322 } 323 } 324 325 $parent_select = ' AND cat_parent=' . $parent_id; 326 327 if ($query) 328 { 329 $querymethod = " AND (cat_name LIKE '%$query%' OR cat_description LIKE '%$query%') "; 330 } 331 332 $sql = "SELECT * FROM phpgw_categories WHERE (cat_appname='" . $this->app_name . "' AND" . $grant_cats . $global_cats . ")" 333 . $querymethod; 334 255 256 $sql = "SELECT".$table_column."FROM phpgw_categories WHERE (cat_appname='" . $this->app_name. "' ". 257 ($grant_cats ? " AND".$grant_cats : "") .($global_cats ? " OR".$global_cats: ""). 258 ")".$querymethod; 259 335 260 $this->db2->query($sql . $parent_select,__LINE__,__FILE__); 336 261 $total = $this->db2->num_rows(); … … 350 275 $cats[$i]['id'] = (int)$this->db->f('cat_id'); 351 276 $cats[$i]['owner'] = (int)$this->db->f('cat_owner'); 277 if($cats[$i]['owner'] > 0){ 278 // Load Name Group. 279 $group = $this->get_group($cats[$i]['owner']); 280 $cats[$i]['owner'] = $group['name']; 281 } 352 282 $cats[$i]['access'] = $this->db->f('cat_access'); 353 283 $cats[$i]['app_name'] = $this->db->f('cat_appname'); … … 358 288 $cats[$i]['description'] = $this->db->f('cat_description'); 359 289 $cats[$i]['data'] = $this->db->f('cat_data'); 290 360 291 $i++; 361 292 } … … 365 296 { 366 297 $sub_select = ' AND cat_parent=' . $cats[$i]['id'] . ' AND cat_level=' . ($cats[$i]['level']+1); 367 368 /*$this->db2->query($sql . $sub_select,__LINE__,__FILE__); 369 $total_subs += $this->db2->num_rows(); 370 371 if ($limit) 372 { 373 $this->db->limit_query($sql . $sub_select . $ordermethod,$start,__LINE__,__FILE__); 374 } 375 else 376 {*/ 377 $this->db->query($sql . $sub_select . $ordermethod,__LINE__,__FILE__); 378 $total += $this->db->num_rows(); 379 //} 298 $this->db->query($sql . $sub_select . $ordermethod,__LINE__,__FILE__); 299 $total += $this->db->num_rows(); 380 300 381 301 $subcats = array(); … … 429 349 { 430 350 $this->db->query('SELECT * FROM phpgw_categories WHERE cat_id=' . (int)$id,__LINE__,__FILE__); 431 432 351 if ($this->db->next_record()) 433 352 { … … 442 361 $cats[0]['description'] = $this->db->f('cat_description'); 443 362 $cats[0]['data'] = $this->db->f('cat_data'); 363 if($cats[0]['owner'] > 0){ 364 // Load Group. 365 $group = $this->get_group($cats[0]['owner']); 366 $cats[0]['id_group'] = $group['id']; 367 $cats[0]['name_group'] = $group['name']; 368 } 444 369 } 445 370 return $cats; … … 459 384 return $this->formated_list($format,$type,$selected,$globals,$site_link); 460 385 } 386 function get_group($id) 387 { 388 if (!IsSet($id)) 389 return ""; 390 return array("id" => $id, "name" => $GLOBALS['phpgw']->accounts->id2name($id)); 391 } 392 461 393 function formated_list($format,$type='',$selected = '',$globals = False,$site_link = 'site') 462 394 { … … 591 523 $id_val = $values['id'] . ','; 592 524 } 593 594 525 $this->db->query('INSERT INTO phpgw_categories (' . $id_col . 'cat_parent,cat_owner,cat_access,cat_appname,cat_name,cat_description,cat_data,' 595 . 'cat_main,cat_level, last_mod) VALUES (' . $id_val . (int)$values['parent'] . ',' . $this->account_id. ",'" . $values['access']526 . 'cat_main,cat_level, last_mod) VALUES (' . $id_val . (int)$values['parent'] . ',' . ($values['group']!= 0 ? $values['group'] : $this->account_id) . ",'" . $values['access'] 596 527 . "','" . $this->app_name . "','" . $values['name'] . "','" . $values['descr'] . "','" . $values['data'] 597 528 . "'," . (int)$values['main'] . ',' . (int)$values['level'] . ',' . time() . ')',__LINE__,__FILE__); … … 687 618 $values['id'] = (int)$values['id']; 688 619 $values['parent'] = (int)$values['parent']; 689 620 $values['owner'] = (int)$values['group']; 621 if($values['owner']){ 622 $owner = "cat_owner = ".$values['owner'].","; 623 } 690 624 if (isset($values['old_parent']) && (int)$values['old_parent'] != $values['parent']) 691 625 { … … 710 644 $values['name'] = $this->db->db_addslashes($values['name']); 711 645 712 $sql = "UPDATE phpgw_categories SET cat_name='" . $values['name'] . "', cat_description='" . $values['descr']646 $sql = "UPDATE phpgw_categories SET $owner cat_name='" . $values['name'] . "', cat_description='" . $values['descr'] 713 647 . "', cat_data='" . $values['data'] . "', cat_parent=" . $values['parent'] . ", cat_access='" 714 648 . $values['access'] . "', cat_main=" . $values['main'] . ', cat_level=' . $values['level'] . ',last_mod=' . time()
Note: See TracChangeset
for help on using the changeset viewer.