[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare - Admin - Global categories * |
---|
| 4 | * http://www.egroupware.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 | var $filter; |
---|
| 22 | var $cat_id; |
---|
| 23 | var $total; |
---|
| 24 | |
---|
| 25 | var $debug = False; |
---|
| 26 | |
---|
| 27 | function bocategories() |
---|
| 28 | { |
---|
| 29 | if ($_GET['appname']) |
---|
| 30 | { |
---|
| 31 | $this->cats = CreateObject('phpgwapi.categories',-1,$_GET['appname']); |
---|
| 32 | } |
---|
| 33 | else |
---|
| 34 | { |
---|
| 35 | $this->cats = CreateObject('phpgwapi.categories',$GLOBALS['phpgw_info']['user']['account_id'],'phpgw'); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | $this->read_sessiondata(); |
---|
| 39 | |
---|
| 40 | /* _debug_array($_POST); */ |
---|
| 41 | /* Might change this to '' at the end---> */ |
---|
| 42 | $start = get_var('start',array('POST','GET')); |
---|
| 43 | $query = get_var('query',array('POST','GET')); |
---|
| 44 | $sort = get_var('sort', array('POST','GET')); |
---|
| 45 | $order = get_var('order',array('POST','GET')); |
---|
| 46 | $cat_id = get_var('cat_id',array('POST','GET')); |
---|
| 47 | |
---|
| 48 | if(!empty($start) || $start == '0' || $start == 0) |
---|
| 49 | { |
---|
| 50 | if($this->debug) { echo '<br>overriding start: "' . $this->start . '" now "' . $start . '"'; } |
---|
| 51 | $this->start = $start; |
---|
| 52 | } |
---|
| 53 | if((empty($query) && !empty($this->query)) || !empty($query)) |
---|
| 54 | { |
---|
| 55 | if($this->debug) { echo '<br>setting query to: "' . $query . '"'; } |
---|
| 56 | $this->query = $query; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | if(isset($cat_id)) |
---|
| 60 | { |
---|
| 61 | $this->cat_id = $cat_id; |
---|
| 62 | } |
---|
| 63 | if($cat_id == '0' || $cat_id == 0 || $cat_id == '') |
---|
| 64 | { |
---|
| 65 | unset($this->cat_id); |
---|
| 66 | } |
---|
| 67 | if(isset($sort) && !empty($sort)) |
---|
| 68 | { |
---|
| 69 | $this->sort = $sort; |
---|
| 70 | } |
---|
| 71 | if(isset($order) && !empty($order)) |
---|
| 72 | { |
---|
| 73 | $this->order = $order; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | function save_sessiondata($data) |
---|
| 78 | { |
---|
| 79 | if($this->debug) { echo '<br>Save:'; _debug_array($data); } |
---|
| 80 | $GLOBALS['phpgw']->session->appsession('session_data','admin_cats',$data); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | function read_sessiondata() |
---|
| 84 | { |
---|
| 85 | $data = $GLOBALS['phpgw']->session->appsession('session_data','admin_cats'); |
---|
| 86 | if($this->debug) { echo '<br>Read:'; _debug_array($data); } |
---|
| 87 | |
---|
| 88 | $this->start = $data['start']; |
---|
| 89 | $this->query = $data['query']; |
---|
| 90 | $this->sort = $data['sort']; |
---|
| 91 | $this->order = $data['order']; |
---|
| 92 | if(isset($data['cat_id'])) |
---|
| 93 | { |
---|
| 94 | $this->cat_id = $data['cat_id']; |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
[577] | 98 | function get_list($id_group) |
---|
[2] | 99 | { |
---|
[577] | 100 | if($this->debug) { echo '<br>querying: "' . $this->query . '"'; } |
---|
| 101 | return $this->cats->return_sorted_array($this->start,True,$this->query,$this->sort,$this->order,True,'',$id_group); |
---|
[2] | 102 | } |
---|
| 103 | |
---|
| 104 | function save_cat($values) |
---|
| 105 | { |
---|
| 106 | if ($values['id'] && $values['id'] != 0) |
---|
| 107 | { |
---|
| 108 | return $this->cats->edit($values); |
---|
| 109 | } |
---|
| 110 | else |
---|
| 111 | { |
---|
| 112 | return $this->cats->add($values); |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | function exists($data) |
---|
| 117 | { |
---|
| 118 | $data['type'] = $data['type'] ? $data['type'] : ''; |
---|
| 119 | $data['cat_id'] = $data['cat_id'] ? $data['cat_id'] : ''; |
---|
| 120 | return $this->cats->exists($data['type'],$data['cat_name'],$data['cat_id']); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | function formatted_list($data) |
---|
| 124 | { |
---|
| 125 | return $this->cats->formated_list($data['select'],$data['all'],$data['cat_parent'],True); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | function delete($cat_id,$subs=False) |
---|
| 129 | { |
---|
| 130 | return $this->cats->delete($cat_id,$subs,!$subs); // either delete the subs or modify them |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | function check_values($values) |
---|
| 134 | { |
---|
| 135 | if (strlen($values['descr']) >= 255) |
---|
| 136 | { |
---|
| 137 | $error[] = lang('Description can not exceed 255 characters in length !'); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | if (!$values['name']) |
---|
| 141 | { |
---|
| 142 | $error[] = lang('Please enter a name'); |
---|
| 143 | } |
---|
| 144 | else |
---|
| 145 | { |
---|
| 146 | if (!$values['parent']) |
---|
| 147 | { |
---|
| 148 | $exists = $this->exists(array |
---|
| 149 | ( |
---|
| 150 | 'type' => 'appandmains', |
---|
| 151 | 'cat_name' => $values['name'], |
---|
| 152 | 'cat_id' => $values['id'] |
---|
| 153 | )); |
---|
| 154 | } |
---|
| 155 | else |
---|
| 156 | { |
---|
| 157 | $exists = $this->exists(array |
---|
| 158 | ( |
---|
| 159 | 'type' => 'appandsubs', |
---|
| 160 | 'cat_name' => $values['name'], |
---|
| 161 | 'cat_id' => $values['id'] |
---|
| 162 | )); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | if ($exists == True) |
---|
| 166 | { |
---|
| 167 | $error[] = lang('That name has been used already'); |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | if (is_array($error)) |
---|
| 172 | { |
---|
| 173 | return $error; |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | } |
---|