@@ -33,7 +33,10 @@ discard block |
||
| 33 | 33 | { |
| 34 | 34 | $form_name = self::form_name($cname, $this->id, $expand); |
| 35 | 35 | $value =& self::get_array(self::$request->content, $form_name, true); |
| 36 | - if(!is_array($value)) $value = array(); |
|
| 36 | + if(!is_array($value)) |
|
| 37 | + { |
|
| 38 | + $value = array(); |
|
| 39 | + } |
|
| 37 | 40 | |
| 38 | 41 | foreach($value as &$events) |
| 39 | 42 | { |
@@ -43,7 +46,10 @@ discard block |
||
| 43 | 46 | } |
| 44 | 47 | foreach($events as &$event) |
| 45 | 48 | { |
| 46 | - if(!is_array($event)) continue; |
|
| 49 | + if(!is_array($event)) |
|
| 50 | + { |
|
| 51 | + continue; |
|
| 52 | + } |
|
| 47 | 53 | foreach(array('start','end') as $date) |
| 48 | 54 | { |
| 49 | 55 | $event[$date] = Api\DateTime::to($event[$date],'Y-m-d\TH:i:s\Z'); |
@@ -41,7 +41,10 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public static function read($country, $year=null) |
| 43 | 43 | { |
| 44 | - if (!$year) $year = (int)Api\DateTime::to('now', 'Y'); |
|
| 44 | + if (!$year) |
|
| 45 | + { |
|
| 46 | + $year = (int)Api\DateTime::to('now', 'Y'); |
|
| 47 | + } |
|
| 45 | 48 | $level = self::is_url($country) ? Api\Cache::INSTANCE : Api\Cache::TREE; |
| 46 | 49 | |
| 47 | 50 | $holidays = Api\Cache::getCache($level, __CLASS__, $country.':'.$year); |
@@ -68,7 +71,10 @@ discard block |
||
| 68 | 71 | */ |
| 69 | 72 | public static function render($country, $year=null, $until_year=null) |
| 70 | 73 | { |
| 71 | - if (!$year) $year = (int)Api\DateTime::to('now', 'Y'); |
|
| 74 | + if (!$year) |
|
| 75 | + { |
|
| 76 | + $year = (int)Api\DateTime::to('now', 'Y'); |
|
| 77 | + } |
|
| 72 | 78 | $end_year = $until_year && $year < $until_year ? $until_year : $year; |
| 73 | 79 | |
| 74 | 80 | $starttime = microtime(true); |
@@ -81,22 +87,40 @@ discard block |
||
| 81 | 87 | { |
| 82 | 88 | $start = new Api\DateTime($event['start']); |
| 83 | 89 | $end = new Api\DateTime($event['end']); |
| 84 | - if ($start->format('Y') > $end_year) continue; |
|
| 85 | - if ($end->format('Y') < $year && !$event['recur_type']) continue; |
|
| 90 | + if ($start->format('Y') > $end_year) |
|
| 91 | + { |
|
| 92 | + continue; |
|
| 93 | + } |
|
| 94 | + if ($end->format('Y') < $year && !$event['recur_type']) |
|
| 95 | + { |
|
| 96 | + continue; |
|
| 97 | + } |
|
| 86 | 98 | |
| 87 | 99 | // recuring events |
| 88 | 100 | if ($event['recur_type']) |
| 89 | 101 | { |
| 90 | 102 | // calendar_rrule limits no enddate, to 5 years |
| 91 | - if (!$event['recur_enddate']) $event['recur_enddate'] = (1+$end_year).'0101'; |
|
| 103 | + if (!$event['recur_enddate']) |
|
| 104 | + { |
|
| 105 | + $event['recur_enddate'] = (1+$end_year).'0101'; |
|
| 106 | + } |
|
| 92 | 107 | |
| 93 | 108 | $rrule = calendar_rrule::event2rrule($event); |
| 94 | - if ($rrule->enddate && $rrule->enddate->format('Y') < $year) continue; |
|
| 109 | + if ($rrule->enddate && $rrule->enddate->format('Y') < $year) |
|
| 110 | + { |
|
| 111 | + continue; |
|
| 112 | + } |
|
| 95 | 113 | |
| 96 | 114 | foreach($rrule as $rtime) |
| 97 | 115 | { |
| 98 | - if (($y = (int)$rtime->format('Y')) < $year) continue; |
|
| 99 | - if ($y > $end_year) break; |
|
| 116 | + if (($y = (int)$rtime->format('Y')) < $year) |
|
| 117 | + { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 120 | + if ($y > $end_year) |
|
| 121 | + { |
|
| 122 | + break; |
|
| 123 | + } |
|
| 100 | 124 | |
| 101 | 125 | $ymd = (int)$rtime->format('Ymd'); |
| 102 | 126 | $years[$y][(string)$ymd][] = array( |
@@ -15,7 +15,8 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * import ical for calendar |
| 17 | 17 | */ |
| 18 | -class calendar_import_ical implements importexport_iface_import_plugin { |
|
| 18 | +class calendar_import_ical implements importexport_iface_import_plugin |
|
| 19 | +{ |
|
| 19 | 20 | |
| 20 | 21 | private static $plugin_options = array( |
| 21 | 22 | 'fieldsep', // char |
@@ -104,7 +105,8 @@ discard block |
||
| 104 | 105 | * @param string $_charset |
| 105 | 106 | * @param definition $_definition |
| 106 | 107 | */ |
| 107 | - public function import( $_stream, importexport_definition $_definition ) { |
|
| 108 | + public function import( $_stream, importexport_definition $_definition ) |
|
| 109 | + { |
|
| 108 | 110 | |
| 109 | 111 | $this->definition = $_definition; |
| 110 | 112 | |
@@ -154,7 +156,8 @@ discard block |
||
| 154 | 156 | * |
| 155 | 157 | * @return string name |
| 156 | 158 | */ |
| 157 | - public static function get_name() { |
|
| 159 | + public static function get_name() |
|
| 160 | + { |
|
| 158 | 161 | return lang('Calendar iCal import'); |
| 159 | 162 | } |
| 160 | 163 | |
@@ -163,7 +166,8 @@ discard block |
||
| 163 | 166 | * |
| 164 | 167 | * @return string descriprion |
| 165 | 168 | */ |
| 166 | - public static function get_description() { |
|
| 169 | + public static function get_description() |
|
| 170 | + { |
|
| 167 | 171 | return lang("Imports events into your Calendar from an iCal File."); |
| 168 | 172 | } |
| 169 | 173 | |
@@ -172,7 +176,8 @@ discard block |
||
| 172 | 176 | * |
| 173 | 177 | * @return string suffix (comma seperated) |
| 174 | 178 | */ |
| 175 | - public static function get_filesuffix() { |
|
| 179 | + public static function get_filesuffix() |
|
| 180 | + { |
|
| 176 | 181 | return 'ics'; |
| 177 | 182 | } |
| 178 | 183 | |
@@ -188,7 +193,8 @@ discard block |
||
| 188 | 193 | * preserv => array, |
| 189 | 194 | * ) |
| 190 | 195 | */ |
| 191 | - public function get_options_etpl() { |
|
| 196 | + public function get_options_etpl() |
|
| 197 | + { |
|
| 192 | 198 | // lets do it! |
| 193 | 199 | } |
| 194 | 200 | |
@@ -197,7 +203,8 @@ discard block |
||
| 197 | 203 | * |
| 198 | 204 | * @return string etemplate name |
| 199 | 205 | */ |
| 200 | - public function get_selectors_etpl() { |
|
| 206 | + public function get_selectors_etpl() |
|
| 207 | + { |
|
| 201 | 208 | // lets do it! |
| 202 | 209 | } |
| 203 | 210 | |
@@ -209,7 +216,8 @@ discard block |
||
| 209 | 216 | * record_# => warning message |
| 210 | 217 | * ) |
| 211 | 218 | */ |
| 212 | - public function get_warnings() { |
|
| 219 | + public function get_warnings() |
|
| 220 | + { |
|
| 213 | 221 | return $this->warnings; |
| 214 | 222 | } |
| 215 | 223 | |
@@ -221,7 +229,8 @@ discard block |
||
| 221 | 229 | * record_# => error message |
| 222 | 230 | * ) |
| 223 | 231 | */ |
| 224 | - public function get_errors() { |
|
| 232 | + public function get_errors() |
|
| 233 | + { |
|
| 225 | 234 | return $this->errors; |
| 226 | 235 | } |
| 227 | 236 | |
@@ -233,7 +242,8 @@ discard block |
||
| 233 | 242 | * action => record count |
| 234 | 243 | * ) |
| 235 | 244 | */ |
| 236 | - public function get_results() { |
|
| 245 | + public function get_results() |
|
| 246 | + { |
|
| 237 | 247 | return $this->results; |
| 238 | 248 | } |
| 239 | 249 | } |
| 240 | 250 | \ No newline at end of file |
@@ -188,10 +188,18 @@ discard block |
||
| 188 | 188 | { |
| 189 | 189 | $updated = false; |
| 190 | 190 | $msg = self::import_zones($updated); |
| 191 | - if ($updated) error_log($msg); // log that timezones have been updated |
|
| 191 | + if ($updated) |
|
| 192 | + { |
|
| 193 | + error_log($msg); |
|
| 194 | + } |
|
| 195 | + // log that timezones have been updated |
|
| 192 | 196 | |
| 193 | 197 | $alias_msg = self::import_tz_aliases($updated); |
| 194 | - if ($updated) error_log($alias_msg); // log that timezone aliases have been updated |
|
| 198 | + if ($updated) |
|
| 199 | + { |
|
| 200 | + error_log($alias_msg); |
|
| 201 | + } |
|
| 202 | + // log that timezone aliases have been updated |
|
| 195 | 203 | |
| 196 | 204 | self::$import_msg = $msg.'<br/>'.$alias_msg; |
| 197 | 205 | |
@@ -249,7 +257,11 @@ discard block |
||
| 249 | 257 | if ($type == 'aliases') |
| 250 | 258 | { |
| 251 | 259 | $data = array('alias' => $tz2id[$data['aliasTo']]); |
| 252 | - if (!$data['alias']) continue; // there's no such tzid |
|
| 260 | + if (!$data['alias']) |
|
| 261 | + { |
|
| 262 | + continue; |
|
| 263 | + } |
|
| 264 | + // there's no such tzid |
|
| 253 | 265 | } |
| 254 | 266 | // check if already in database |
| 255 | 267 | $tz2id[$tzid] = $GLOBALS['egw']->db->select('egw_cal_timezones','tz_id',array( |
@@ -266,7 +278,10 @@ discard block |
||
| 266 | 278 | ),__LINE__,__FILE__,'calendar'); |
| 267 | 279 | |
| 268 | 280 | // only query last insert id, if not already in database (gives warning for PostgreSQL) |
| 269 | - if (!$tz2id[$tzid]) $tz2id[$tzid] = $GLOBALS['egw']->db->get_last_insert_id('egw_cal_timezones','tz_id'); |
|
| 281 | + if (!$tz2id[$tzid]) |
|
| 282 | + { |
|
| 283 | + $tz2id[$tzid] = $GLOBALS['egw']->db->get_last_insert_id('egw_cal_timezones','tz_id'); |
|
| 284 | + } |
|
| 270 | 285 | } |
| 271 | 286 | } |
| 272 | 287 | Api\Config::save_value('tz_version', $tz_version, 'phpgwapi'); |
@@ -306,13 +321,16 @@ discard block |
||
| 306 | 321 | foreach($tz_aliases as $alias => $tzid) |
| 307 | 322 | { |
| 308 | 323 | if ((!($alias_id=self::tz2id($alias, 'alias')) || self::id2tz($alias_id, 'tzid') !== $tzid) && // not in DB or different |
| 309 | - ($tz_id = self::tz2id($tzid))) // given tzid for alias exists in DB |
|
| 324 | + ($tz_id = self::tz2id($tzid))) |
|
| 325 | + { |
|
| 326 | + // given tzid for alias exists in DB |
|
| 310 | 327 | { |
| 311 | 328 | $GLOBALS['egw']->db->insert('egw_cal_timezones',array( |
| 312 | 329 | 'tz_alias' => $tz_id, |
| 313 | 330 | ),array( |
| 314 | 331 | 'tz_tzid' => $alias, |
| 315 | 332 | ),__LINE__,__FILE__,'calendar'); |
| 333 | + } |
|
| 316 | 334 | ++$updates; |
| 317 | 335 | } |
| 318 | 336 | //error_log(__METHOD__."() alias=$alias, tzid=$tzid --> self::tz2id('$alias', 'alias') = ".array2string($alias_id).", self::tz2id('$tzid')=".array2string($tz_id)); |
@@ -402,7 +420,10 @@ discard block |
||
| 402 | 420 | $prefs = $prefs_obj->read(); |
| 403 | 421 | $tzid = $prefs['common']['tz']; |
| 404 | 422 | } |
| 405 | - if (!$tzid) $tzid = Api\DateTime::$server_timezone->getName(); |
|
| 423 | + if (!$tzid) |
|
| 424 | + { |
|
| 425 | + $tzid = Api\DateTime::$server_timezone->getName(); |
|
| 426 | + } |
|
| 406 | 427 | |
| 407 | 428 | switch ($type) |
| 408 | 429 | { |
@@ -77,16 +77,31 @@ discard block |
||
| 77 | 77 | $ui = new calendar_uiviews(); |
| 78 | 78 | if ($this->favorite) |
| 79 | 79 | { |
| 80 | - if($this->favorite['state']['start']) $ui->search_params['start'] = $this->favorite['state']['start']; |
|
| 81 | - if($this->favorite['state']['cat_id']) $ui->search_params['cat_id'] = $this->favorite['state']['cat_id']; |
|
| 80 | + if($this->favorite['state']['start']) |
|
| 81 | + { |
|
| 82 | + $ui->search_params['start'] = $this->favorite['state']['start']; |
|
| 83 | + } |
|
| 84 | + if($this->favorite['state']['cat_id']) |
|
| 85 | + { |
|
| 86 | + $ui->search_params['cat_id'] = $this->favorite['state']['cat_id']; |
|
| 87 | + } |
|
| 82 | 88 | // Owner can be 0 for current user |
| 83 | - if(array_key_exists('owner',$this->favorite['state'])) $ui->search_params['users'] = $this->favorite['state']['owner']; |
|
| 89 | + if(array_key_exists('owner',$this->favorite['state'])) |
|
| 90 | + { |
|
| 91 | + $ui->search_params['users'] = $this->favorite['state']['owner']; |
|
| 92 | + } |
|
| 84 | 93 | if($ui->search_params['users'] && !is_array($ui->search_params['users'])) |
| 85 | 94 | { |
| 86 | 95 | $ui->search_params['users'] = explode(',',$ui->search_params['users']); |
| 87 | 96 | } |
| 88 | - if($this->favorite['state']['filter']) $ui->search_params['filter'] = $this->favorite['state']['filter']; |
|
| 89 | - if($this->favorite['state']['sortby']) $ui->search_params['sortby'] = $this->favorite['state']['sortby']; |
|
| 97 | + if($this->favorite['state']['filter']) |
|
| 98 | + { |
|
| 99 | + $ui->search_params['filter'] = $this->favorite['state']['filter']; |
|
| 100 | + } |
|
| 101 | + if($this->favorite['state']['sortby']) |
|
| 102 | + { |
|
| 103 | + $ui->search_params['sortby'] = $this->favorite['state']['sortby']; |
|
| 104 | + } |
|
| 90 | 105 | $ui->search_params['weekend'] = $this->favorite['state']['weekend']; |
| 91 | 106 | } |
| 92 | 107 | $etemplate->read('home.legacy'); |
@@ -246,7 +261,8 @@ discard block |
||
| 246 | 261 | return $properties; |
| 247 | 262 | } |
| 248 | 263 | |
| 249 | - public function get_actions() { |
|
| 264 | + public function get_actions() |
|
| 265 | + { |
|
| 250 | 266 | if($this->favorite['state']['view'] == 'listview' || !$this->actions) |
| 251 | 267 | { |
| 252 | 268 | return array(); |
@@ -154,16 +154,32 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | protected function cal_range_view($start, $end, array $_where=null, $deleted=false) |
| 156 | 156 | { |
| 157 | - if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start) // using view without start-date is slower! |
|
| 157 | + if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start) |
|
| 158 | 158 | { |
| 159 | - return $this->cal_table; // no need / use for a view |
|
| 159 | + // using view without start-date is slower! |
|
| 160 | + { |
|
| 161 | + return $this->cal_table; |
|
| 162 | + } |
|
| 163 | + // no need / use for a view |
|
| 160 | 164 | } |
| 161 | 165 | |
| 162 | 166 | $where = array(); |
| 163 | - if (isset($deleted)) $where[] = "cal_deleted IS ".($deleted ? '' : 'NOT').' NULL'; |
|
| 164 | - if ($end) $where[] = "range_start<".(int)$end; |
|
| 165 | - if ($start) $where[] = "(range_end IS NULL OR range_end>".(int)$start.")"; |
|
| 166 | - if ($_where) $where = array_merge($where, $_where); |
|
| 167 | + if (isset($deleted)) |
|
| 168 | + { |
|
| 169 | + $where[] = "cal_deleted IS ".($deleted ? '' : 'NOT').' NULL'; |
|
| 170 | + } |
|
| 171 | + if ($end) |
|
| 172 | + { |
|
| 173 | + $where[] = "range_start<".(int)$end; |
|
| 174 | + } |
|
| 175 | + if ($start) |
|
| 176 | + { |
|
| 177 | + $where[] = "(range_end IS NULL OR range_end>".(int)$start.")"; |
|
| 178 | + } |
|
| 179 | + if ($_where) |
|
| 180 | + { |
|
| 181 | + $where = array_merge($where, $_where); |
|
| 182 | + } |
|
| 167 | 183 | |
| 168 | 184 | $sql = "(SELECT * FROM $this->cal_table WHERE ".$this->db->expression($this->cal_table, $where).") $this->cal_table"; |
| 169 | 185 | |
@@ -184,16 +200,32 @@ discard block |
||
| 184 | 200 | */ |
| 185 | 201 | protected function dates_range_view($start, $end, array $_where=null, $deleted=false) |
| 186 | 202 | { |
| 187 | - if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start || !$end) // using view without start- AND end-date is slower! |
|
| 203 | + if ($GLOBALS['egw_info']['server']['no_timerange_views'] || !$start || !$end) |
|
| 204 | + { |
|
| 205 | + // using view without start- AND end-date is slower! |
|
| 188 | 206 | { |
| 189 | - return $this->dates_table; // no need / use for a view |
|
| 207 | + return $this->dates_table; |
|
| 208 | + } |
|
| 209 | + // no need / use for a view |
|
| 190 | 210 | } |
| 191 | 211 | |
| 192 | 212 | $where = array(); |
| 193 | - if (isset($deleted)) $where['recur_exception'] = $deleted; |
|
| 194 | - if ($end) $where[] = "cal_start<".(int)$end; |
|
| 195 | - if ($start) $where[] = "cal_end>".(int)$start; |
|
| 196 | - if ($_where) $where = array_merge($where, $_where); |
|
| 213 | + if (isset($deleted)) |
|
| 214 | + { |
|
| 215 | + $where['recur_exception'] = $deleted; |
|
| 216 | + } |
|
| 217 | + if ($end) |
|
| 218 | + { |
|
| 219 | + $where[] = "cal_start<".(int)$end; |
|
| 220 | + } |
|
| 221 | + if ($start) |
|
| 222 | + { |
|
| 223 | + $where[] = "cal_end>".(int)$start; |
|
| 224 | + } |
|
| 225 | + if ($_where) |
|
| 226 | + { |
|
| 227 | + $where = array_merge($where, $_where); |
|
| 228 | + } |
|
| 197 | 229 | |
| 198 | 230 | // Api\Db::union uses Api\Db::select which check if join contains "WHERE" |
| 199 | 231 | // to support old join syntax like ", other_table WHERE ...", |
@@ -243,7 +275,10 @@ discard block |
||
| 243 | 275 | throw new Api\Exception\AssertionFailed("Unsupported value for parameters!"); |
| 244 | 276 | } |
| 245 | 277 | $where = is_array($params['query']) ? $params['query'] : array(); |
| 246 | - if ($cat_id) $where[] = $this->cat_filter($cat_id); |
|
| 278 | + if ($cat_id) |
|
| 279 | + { |
|
| 280 | + $where[] = $this->cat_filter($cat_id); |
|
| 281 | + } |
|
| 247 | 282 | $egw_cal = $this->cal_range_view($start, $end, $where, $filter == 'everything' ? null : $filter != 'deleted'); |
| 248 | 283 | |
| 249 | 284 | $status_filter = $this->status_filter($filter, $params['enum_recuring']); |
@@ -264,7 +299,10 @@ discard block |
||
| 264 | 299 | if ($users) |
| 265 | 300 | { |
| 266 | 301 | // fix $users to also prefix system users and groups (with 'u') |
| 267 | - if (!is_array($users)) $users = $users ? (array)$users : array(); |
|
| 302 | + if (!is_array($users)) |
|
| 303 | + { |
|
| 304 | + $users = $users ? (array)$users : array(); |
|
| 305 | + } |
|
| 268 | 306 | foreach($users as &$uid) |
| 269 | 307 | { |
| 270 | 308 | $user_type = $user_id = null; |
@@ -284,15 +322,22 @@ discard block |
||
| 284 | 322 | $sql .= " AND\n ".$params['sql_filter']; |
| 285 | 323 | } |
| 286 | 324 | |
| 287 | - if ($params['order']) // only order if requested |
|
| 325 | + if ($params['order']) |
|
| 288 | 326 | { |
| 289 | - if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start'; // gard against SQL injection |
|
| 327 | + // only order if requested |
|
| 328 | + { |
|
| 329 | + if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start'; |
|
| 330 | + } |
|
| 331 | + // gard against SQL injection |
|
| 290 | 332 | $sql .= "\nORDER BY ".$params['order']; |
| 291 | 333 | } |
| 292 | 334 | |
| 293 | - if ($offset === false) // return all rows --> Api\Db::query wants offset=0, num_rows=-1 |
|
| 335 | + if ($offset === false) |
|
| 336 | + { |
|
| 337 | + // return all rows --> Api\Db::query wants offset=0, num_rows=-1 |
|
| 294 | 338 | { |
| 295 | 339 | $offset = 0; |
| 340 | + } |
|
| 296 | 341 | $num_rows = -1; |
| 297 | 342 | } |
| 298 | 343 | $events =& $this->get_events($this->db->query($sql, __LINE__, __FILE__, $offset, $num_rows)); |
@@ -318,26 +363,35 @@ discard block |
||
| 318 | 363 | $join = "LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id"; |
| 319 | 364 | |
| 320 | 365 | $where = array(); |
| 321 | - if (is_scalar($ids) && !is_numeric($ids)) // a single uid |
|
| 366 | + if (is_scalar($ids) && !is_numeric($ids)) |
|
| 367 | + { |
|
| 368 | + // a single uid |
|
| 322 | 369 | { |
| 323 | 370 | // We want only the parents to match |
| 324 | 371 | $where['cal_uid'] = $ids; |
| 372 | + } |
|
| 325 | 373 | $where['cal_reference'] = 0; |
| 326 | 374 | } |
| 327 | - elseif(is_array($ids) && isset($ids[count($ids)-1]) || is_scalar($ids)) // one or more cal_id's |
|
| 375 | + elseif(is_array($ids) && isset($ids[count($ids)-1]) || is_scalar($ids)) |
|
| 376 | + { |
|
| 377 | + // one or more cal_id's |
|
| 328 | 378 | { |
| 329 | 379 | $where['cal_id'] = $ids; |
| 330 | 380 | } |
| 381 | + } |
|
| 331 | 382 | else // array with column => value pairs |
| 332 | 383 | { |
| 333 | 384 | $where = $ids; |
| 334 | 385 | unset($ids); // otherwise users get not read! |
| 335 | 386 | } |
| 336 | - if (isset($where['cal_id'])) // prevent non-unique column-name cal_id |
|
| 387 | + if (isset($where['cal_id'])) |
|
| 388 | + { |
|
| 389 | + // prevent non-unique column-name cal_id |
|
| 337 | 390 | { |
| 338 | 391 | $where[] = $this->db->expression($this->cal_table, $this->cal_table.'.',array( |
| 339 | 392 | 'cal_id' => $where['cal_id'], |
| 340 | 393 | )); |
| 394 | + } |
|
| 341 | 395 | unset($where['cal_id']); |
| 342 | 396 | } |
| 343 | 397 | if ((int) $recur_date) |
@@ -387,10 +441,16 @@ discard block |
||
| 387 | 441 | $row['recur_exception'] = $row['alarm'] = array(); |
| 388 | 442 | $events[$row['cal_id']] = Api\Db::strip_array_keys($row,'cal_'); |
| 389 | 443 | } |
| 390 | - if (!$events) return $events; |
|
| 444 | + if (!$events) |
|
| 445 | + { |
|
| 446 | + return $events; |
|
| 447 | + } |
|
| 391 | 448 | |
| 392 | 449 | $ids = array_keys($events); |
| 393 | - if (count($ids) == 1) $ids = $ids[0]; |
|
| 450 | + if (count($ids) == 1) |
|
| 451 | + { |
|
| 452 | + $ids = $ids[0]; |
|
| 453 | + } |
|
| 394 | 454 | |
| 395 | 455 | foreach ($events as &$event) |
| 396 | 456 | { |
@@ -464,10 +524,13 @@ discard block |
||
| 464 | 524 | 'cal_id' => $ids, |
| 465 | 525 | 'cal_recur_date' => $recur_date, |
| 466 | 526 | "cal_status NOT IN ('X','E')", |
| 467 | - ),__LINE__,__FILE__,false,'ORDER BY cal_user_type DESC,cal_recur_date ASC,'.self::STATUS_SORT,'calendar') as $row) // DESC puts users before resources and contacts |
|
| 527 | + ),__LINE__,__FILE__,false,'ORDER BY cal_user_type DESC,cal_recur_date ASC,'.self::STATUS_SORT,'calendar') as $row) |
|
| 528 | + { |
|
| 529 | + // DESC puts users before resources and contacts |
|
| 468 | 530 | { |
| 469 | 531 | // combine all participant data in uid and status values |
| 470 | 532 | $uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']); |
| 533 | + } |
|
| 471 | 534 | $status = self::combine_status($row['cal_status'],$row['cal_quantity'],$row['cal_role']); |
| 472 | 535 | |
| 473 | 536 | $events[$row['cal_id']]['participants'][$uid] = $status; |
@@ -524,7 +587,10 @@ discard block |
||
| 524 | 587 | $last_request = time(); |
| 525 | 588 | } |
| 526 | 589 | $signature = serialize(func_get_args()); |
| 527 | - if (isset($ctags[$signature])) return $ctags[$signature]; |
|
| 590 | + if (isset($ctags[$signature])) |
|
| 591 | + { |
|
| 592 | + return $ctags[$signature]; |
|
| 593 | + } |
|
| 528 | 594 | |
| 529 | 595 | $types = array(); |
| 530 | 596 | foreach((array)$users as $uid) |
@@ -557,7 +623,10 @@ discard block |
||
| 557 | 623 | // owner can only by users, no groups or resources |
| 558 | 624 | foreach($users as $key => $user) |
| 559 | 625 | { |
| 560 | - if (!($user > 0)) unset($users[$key]); |
|
| 626 | + if (!($user > 0)) |
|
| 627 | + { |
|
| 628 | + unset($users[$key]); |
|
| 629 | + } |
|
| 561 | 630 | } |
| 562 | 631 | $where = $this->db->expression($this->user_table, '(', $where, ' OR '). |
| 563 | 632 | $this->db->expression($this->cal_table, array( |
@@ -579,7 +648,10 @@ discard block |
||
| 579 | 648 | */ |
| 580 | 649 | function get_cal_data(array $query, $cols='cal_id,cal_reference,cal_etag,cal_modified,cal_user_modified') |
| 581 | 650 | { |
| 582 | - if (!is_array($cols)) $cols = explode(',', $cols); |
|
| 651 | + if (!is_array($cols)) |
|
| 652 | + { |
|
| 653 | + $cols = explode(',', $cols); |
|
| 654 | + } |
|
| 583 | 655 | |
| 584 | 656 | // special handling of cal_user_modified "pseudo" column |
| 585 | 657 | if (($key = array_search('cal_user_modified', $cols)) !== false) |
@@ -604,7 +676,10 @@ discard block |
||
| 604 | 676 | { |
| 605 | 677 | $cats = $GLOBALS['egw']->categories->return_all_children($cat_id); |
| 606 | 678 | array_walk($cats,create_function('&$val,$key','$val = (int) $val;')); |
| 607 | - if (is_array($cat_id) && count($cat_id)==1) $cat_id = $cat_id[0]; |
|
| 679 | + if (is_array($cat_id) && count($cat_id)==1) |
|
| 680 | + { |
|
| 681 | + $cat_id = $cat_id[0]; |
|
| 682 | + } |
|
| 608 | 683 | $sql = '(cal_category'.(count($cats) > 1 ? " IN ('".implode("','",$cats)."')" : '='.$this->db->quote((int)$cat_id)); |
| 609 | 684 | foreach($cats as $cat) |
| 610 | 685 | { |
@@ -663,10 +738,13 @@ discard block |
||
| 663 | 738 | $where[] = "$this->user_table.cal_status NOT IN ('X','E')"; |
| 664 | 739 | break; |
| 665 | 740 | default: |
| 666 | - if ($enum_recuring) // regular UI |
|
| 741 | + if ($enum_recuring) |
|
| 742 | + { |
|
| 743 | + // regular UI |
|
| 667 | 744 | { |
| 668 | 745 | $where[] = "$this->user_table.cal_status NOT IN ('R','X','E')"; |
| 669 | 746 | } |
| 747 | + } |
|
| 670 | 748 | else // CalDAV / eSync / iCal need to include 'E' = exceptions |
| 671 | 749 | { |
| 672 | 750 | $where[] = "$this->user_table.cal_status NOT IN ('R','X')"; |
@@ -798,7 +876,10 @@ discard block |
||
| 798 | 876 | $user_ids = array(); |
| 799 | 877 | foreach($ids as $user_id) |
| 800 | 878 | { |
| 801 | - if ($GLOBALS['egw']->accounts->get_type($user_id) === 'u') $user_ids[] = $user_id; |
|
| 879 | + if ($GLOBALS['egw']->accounts->get_type($user_id) === 'u') |
|
| 880 | + { |
|
| 881 | + $user_ids[] = $user_id; |
|
| 882 | + } |
|
| 802 | 883 | } |
| 803 | 884 | $owner_or = $this->db->expression($cal_table_def,array('cal_owner' => $user_ids)); |
| 804 | 885 | } |
@@ -818,7 +899,10 @@ discard block |
||
| 818 | 899 | } |
| 819 | 900 | } |
| 820 | 901 | // this is only used, when we cannot use UNIONS |
| 821 | - if (!$useUnionQuery) $where[] = '('.implode(' OR ',$to_or).')'; |
|
| 902 | + if (!$useUnionQuery) |
|
| 903 | + { |
|
| 904 | + $where[] = '('.implode(' OR ',$to_or).')'; |
|
| 905 | + } |
|
| 822 | 906 | |
| 823 | 907 | $where = $this->status_filter($filter, $params['enum_recuring'], $where); |
| 824 | 908 | } |
@@ -837,7 +921,11 @@ discard block |
||
| 837 | 921 | $where[] = '('.((int)$start).' < range_end OR range_end IS NULL)'; |
| 838 | 922 | } |
| 839 | 923 | } |
| 840 | - if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) $params['order'] = 'cal_start'; // gard against SQL injection |
|
| 924 | + if (!preg_match('/^[a-z_ ,c]+$/i',$params['order'])) |
|
| 925 | + { |
|
| 926 | + $params['order'] = 'cal_start'; |
|
| 927 | + } |
|
| 928 | + // gard against SQL injection |
|
| 841 | 929 | |
| 842 | 930 | // if not enum recuring events, we have to use minimum start- AND end-dates, otherwise we get more then one event per cal_id! |
| 843 | 931 | if (!$params['enum_recuring']) |
@@ -847,9 +935,15 @@ discard block |
||
| 847 | 935 | // in case cal_start is used in a query, eg. calendar_ical::find_event |
| 848 | 936 | $where = str_replace(array('cal_start','cal_end'), array('range_start','(SELECT MIN(cal_end) FROM egw_cal_dates WHERE egw_cal.cal_id=egw_cal_dates.cal_id)'), $where); |
| 849 | 937 | $params['order'] = str_replace('cal_start', 'range_start', $params['order']); |
| 850 | - if ($end) $where[] = (int)$end.' > range_start'; |
|
| 938 | + if ($end) |
|
| 939 | + { |
|
| 940 | + $where[] = (int)$end.' > range_start'; |
|
| 941 | + } |
|
| 851 | 942 | } |
| 852 | - elseif ($end) $where[] = (int)$end.' > cal_start'; |
|
| 943 | + elseif ($end) |
|
| 944 | + { |
|
| 945 | + $where[] = (int)$end.' > cal_start'; |
|
| 946 | + } |
|
| 853 | 947 | |
| 854 | 948 | if ($remove_rejected_by_user && $filter != 'everything') |
| 855 | 949 | { |
@@ -863,7 +957,10 @@ discard block |
||
| 863 | 957 | 'rejected_by_user.cal_status IS NULL', |
| 864 | 958 | "rejected_by_user.cal_status NOT IN ('R','X')", |
| 865 | 959 | ); |
| 866 | - if ($filter == 'owner') $or_required[] = 'cal_owner='.(int)$remove_rejected_by_user; |
|
| 960 | + if ($filter == 'owner') |
|
| 961 | + { |
|
| 962 | + $or_required[] = 'cal_owner='.(int)$remove_rejected_by_user; |
|
| 963 | + } |
|
| 867 | 964 | $where[] = '('.implode(' OR ',$or_required).')'; |
| 868 | 965 | } |
| 869 | 966 | // using a time-range and deleted attribute limited view instead of full table |
@@ -885,7 +982,10 @@ discard block |
||
| 885 | 982 | if ($useUnionQuery) |
| 886 | 983 | { |
| 887 | 984 | // allow apps to supply participants and/or icons |
| 888 | - if (!isset($params['cols'])) $cols .= ',NULL AS participants,NULL AS icons'; |
|
| 985 | + if (!isset($params['cols'])) |
|
| 986 | + { |
|
| 987 | + $cols .= ',NULL AS participants,NULL AS icons'; |
|
| 988 | + } |
|
| 889 | 989 | |
| 890 | 990 | // changed the original OR in the query into a union, to speed up the query execution under MySQL 5 |
| 891 | 991 | // with time-range views benefit is now at best slim for huge tables or none at all! |
@@ -940,9 +1040,12 @@ discard block |
||
| 940 | 1040 | $selects[count($selects)-1]['where'][] = "$this->user_table.cal_recur_date=cal_start"; |
| 941 | 1041 | } |
| 942 | 1042 | } |
| 943 | - if (is_numeric($offset) && !$params['no_total']) // get the total too |
|
| 1043 | + if (is_numeric($offset) && !$params['no_total']) |
|
| 1044 | + { |
|
| 1045 | + // get the total too |
|
| 944 | 1046 | { |
| 945 | 1047 | $save_selects = $selects; |
| 1048 | + } |
|
| 946 | 1049 | // we only select cal_table.cal_id (and not cal_table.*) to be able to use DISTINCT (eg. MsSQL does not allow it for text-columns) |
| 947 | 1050 | foreach(array_keys($selects) as $key) |
| 948 | 1051 | { |
@@ -953,14 +1056,20 @@ discard block |
||
| 953 | 1056 | array('range_start AS cal_start','range_end AS cal_end'), $selects[$key]['cols']); |
| 954 | 1057 | } |
| 955 | 1058 | } |
| 956 | - if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']); |
|
| 1059 | + if (!isset($params['cols']) && !$params['no_integration']) |
|
| 1060 | + { |
|
| 1061 | + self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']); |
|
| 1062 | + } |
|
| 957 | 1063 | |
| 958 | 1064 | $this->total = $this->db->union($selects,__LINE__,__FILE__)->NumRows(); |
| 959 | 1065 | |
| 960 | 1066 | // restore original cols / selects |
| 961 | 1067 | $selects = $save_selects; unset($save_selects); |
| 962 | 1068 | } |
| 963 | - if (!isset($params['cols']) && !$params['no_integration']) self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']); |
|
| 1069 | + if (!isset($params['cols']) && !$params['no_integration']) |
|
| 1070 | + { |
|
| 1071 | + self::get_union_selects($selects,$start,$end,$users,$cat_id,$filter,$params['query'],$params['users']); |
|
| 1072 | + } |
|
| 964 | 1073 | |
| 965 | 1074 | $rs = $this->db->union($selects,__LINE__,__FILE__,$params['order'],$offset,$num_rows); |
| 966 | 1075 | } |
@@ -978,9 +1087,12 @@ discard block |
||
| 978 | 1087 | 'table_def' => $cal_table_def, |
| 979 | 1088 | )); |
| 980 | 1089 | |
| 981 | - if (is_numeric($offset) && !$params['no_total']) // get the total too |
|
| 1090 | + if (is_numeric($offset) && !$params['no_total']) |
|
| 1091 | + { |
|
| 1092 | + // get the total too |
|
| 982 | 1093 | { |
| 983 | 1094 | $save_selects = $selects; |
| 1095 | + } |
|
| 984 | 1096 | // we only select cal_table.cal_id (and not cal_table.*) to be able to use DISTINCT (eg. MsSQL does not allow it for text-columns) |
| 985 | 1097 | $selects[0]['cols'] = "$this->cal_table.cal_id,cal_start"; |
| 986 | 1098 | if (!isset($params['cols']) && !$params['no_integration'] && $this->db->capabilities['union']) |
@@ -1008,7 +1120,10 @@ discard block |
||
| 1008 | 1120 | foreach($rs as $row) |
| 1009 | 1121 | { |
| 1010 | 1122 | $id = $row['cal_id']; |
| 1011 | - if (is_numeric($id)) $ids[] = $id; |
|
| 1123 | + if (is_numeric($id)) |
|
| 1124 | + { |
|
| 1125 | + $ids[] = $id; |
|
| 1126 | + } |
|
| 1012 | 1127 | |
| 1013 | 1128 | if ($row['cal_recur_date']) |
| 1014 | 1129 | { |
@@ -1028,7 +1143,10 @@ discard block |
||
| 1028 | 1143 | $row['recur_exception'] = $row['alarm'] = array(); |
| 1029 | 1144 | |
| 1030 | 1145 | // compile a list of recurrences per cal_id |
| 1031 | - if (!in_array($id,(array)$recur_ids[$row['cal_id']])) $recur_ids[$row['cal_id']][] = $id; |
|
| 1146 | + if (!in_array($id,(array)$recur_ids[$row['cal_id']])) |
|
| 1147 | + { |
|
| 1148 | + $recur_ids[$row['cal_id']][] = $id; |
|
| 1149 | + } |
|
| 1032 | 1150 | |
| 1033 | 1151 | $events[$id] = Api\Db::strip_array_keys($row,'cal_'); |
| 1034 | 1152 | } |
@@ -1047,10 +1165,16 @@ discard block |
||
| 1047 | 1165 | //'cal_id' => array_unique($ids), |
| 1048 | 1166 | 'cal_recur_date' => $recur_dates, |
| 1049 | 1167 | ),__LINE__,__FILE__,false,'ORDER BY cal_id,cal_user_type DESC,'.self::STATUS_SORT,'calendar',$num_rows,$join='', |
| 1050 | - $this->db->get_table_definitions('calendar',$this->user_table)) as $row) // DESC puts users before resources and contacts |
|
| 1168 | + $this->db->get_table_definitions('calendar',$this->user_table)) as $row) |
|
| 1169 | + { |
|
| 1170 | + // DESC puts users before resources and contacts |
|
| 1051 | 1171 | { |
| 1052 | 1172 | $id = $row['cal_id']; |
| 1053 | - if ($row['cal_recur_date']) $id .= '-'.$row['cal_recur_date']; |
|
| 1173 | + } |
|
| 1174 | + if ($row['cal_recur_date']) |
|
| 1175 | + { |
|
| 1176 | + $id .= '-'.$row['cal_recur_date']; |
|
| 1177 | + } |
|
| 1054 | 1178 | |
| 1055 | 1179 | // combine all participant data in uid and status values |
| 1056 | 1180 | $uid = self::combine_user($row['cal_user_type'], $row['cal_user_id'], $row['cal_user_attendee']); |
@@ -1069,7 +1193,10 @@ discard block |
||
| 1069 | 1193 | } |
| 1070 | 1194 | |
| 1071 | 1195 | // set data, if recurrence is requested |
| 1072 | - if (isset($events[$id])) $events[$id]['participants'][$uid] = $status; |
|
| 1196 | + if (isset($events[$id])) |
|
| 1197 | + { |
|
| 1198 | + $events[$id]['participants'][$uid] = $status; |
|
| 1199 | + } |
|
| 1073 | 1200 | } |
| 1074 | 1201 | // query recurrance exceptions, if needed: enum_recuring && !daywise is used in calendar_groupdav::get_series($uid,...) |
| 1075 | 1202 | if (!$params['enum_recuring'] || !$params['daywise']) |
@@ -1085,7 +1212,10 @@ discard block |
||
| 1085 | 1212 | { |
| 1086 | 1213 | foreach($events as $id => $event) |
| 1087 | 1214 | { |
| 1088 | - if ($event['id'] == $row['cal_id']) break; |
|
| 1215 | + if ($event['id'] == $row['cal_id']) |
|
| 1216 | + { |
|
| 1217 | + break; |
|
| 1218 | + } |
|
| 1089 | 1219 | } |
| 1090 | 1220 | } |
| 1091 | 1221 | $events[$id]['recur_exception'][] = $row['cal_start']; |
@@ -1095,7 +1225,10 @@ discard block |
||
| 1095 | 1225 | if (!is_null($params['cfs'])) |
| 1096 | 1226 | { |
| 1097 | 1227 | $where = array('cal_id' => $ids); |
| 1098 | - if ($params['cfs']) $where['cal_extra_name'] = $params['cfs']; |
|
| 1228 | + if ($params['cfs']) |
|
| 1229 | + { |
|
| 1230 | + $where['cal_extra_name'] = $params['cfs']; |
|
| 1231 | + } |
|
| 1099 | 1232 | foreach($this->db->select($this->extra_table,'*',$where, |
| 1100 | 1233 | __LINE__,__FILE__,false,'','calendar') as $row) |
| 1101 | 1234 | { |
@@ -1115,14 +1248,20 @@ discard block |
||
| 1115 | 1248 | { |
| 1116 | 1249 | $event_start = $alarm['time'] + $alarm['offset']; |
| 1117 | 1250 | |
| 1118 | - if (isset($events[$cal_id])) // none recuring event |
|
| 1251 | + if (isset($events[$cal_id])) |
|
| 1252 | + { |
|
| 1253 | + // none recuring event |
|
| 1119 | 1254 | { |
| 1120 | 1255 | $events[$cal_id]['alarm'][$id] = $alarm; |
| 1121 | 1256 | } |
| 1122 | - elseif (isset($events[$cal_id.'-'.$event_start])) // recuring event |
|
| 1257 | + } |
|
| 1258 | + elseif (isset($events[$cal_id.'-'.$event_start])) |
|
| 1259 | + { |
|
| 1260 | + // recuring event |
|
| 1123 | 1261 | { |
| 1124 | 1262 | $events[$cal_id.'-'.$event_start]['alarm'][$id] = $alarm; |
| 1125 | 1263 | } |
| 1264 | + } |
|
| 1126 | 1265 | } |
| 1127 | 1266 | } |
| 1128 | 1267 | } |
@@ -1222,10 +1361,13 @@ discard block |
||
| 1222 | 1361 | } |
| 1223 | 1362 | foreach((array)$cols as $col) |
| 1224 | 1363 | { |
| 1225 | - if (substr($col,0,7) == 'egw_cal') // remove table name |
|
| 1364 | + if (substr($col,0,7) == 'egw_cal') |
|
| 1365 | + { |
|
| 1366 | + // remove table name |
|
| 1226 | 1367 | { |
| 1227 | 1368 | $col = preg_replace('/^egw_cal[a-z_]*\./','',$col); |
| 1228 | 1369 | } |
| 1370 | + } |
|
| 1229 | 1371 | if (isset($app_cols[$col])) |
| 1230 | 1372 | { |
| 1231 | 1373 | $return_cols[] = $app_cols[$col]; |
@@ -1319,7 +1461,11 @@ discard block |
||
| 1319 | 1461 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
| 1320 | 1462 | { |
| 1321 | 1463 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
| 1322 | - if (empty($minimum_uid_length) || $minimum_uid_length<=1) $minimum_uid_length = 8; // we just do not accept no uid, or uid way to short! |
|
| 1464 | + if (empty($minimum_uid_length) || $minimum_uid_length<=1) |
|
| 1465 | + { |
|
| 1466 | + $minimum_uid_length = 8; |
|
| 1467 | + } |
|
| 1468 | + // we just do not accept no uid, or uid way to short! |
|
| 1323 | 1469 | } |
| 1324 | 1470 | else |
| 1325 | 1471 | { |
@@ -1367,7 +1513,10 @@ discard block |
||
| 1367 | 1513 | } |
| 1368 | 1514 | } |
| 1369 | 1515 | // set range_start/_end, but only if we have cal_start/_end, as otherwise we destroy present values! |
| 1370 | - if (isset($event['cal_start'])) $event['range_start'] = $event['cal_start']; |
|
| 1516 | + if (isset($event['cal_start'])) |
|
| 1517 | + { |
|
| 1518 | + $event['range_start'] = $event['cal_start']; |
|
| 1519 | + } |
|
| 1371 | 1520 | if (isset($event['cal_end'])) |
| 1372 | 1521 | { |
| 1373 | 1522 | $event['range_end'] = $event['recur_type'] == MCAL_RECUR_NONE ? $event['cal_end'] : |
@@ -1388,7 +1537,10 @@ discard block |
||
| 1388 | 1537 | $event['cal_category'] = implode(',',$categories); |
| 1389 | 1538 | |
| 1390 | 1539 | // make sure recurring events never reference to an other recurrent event |
| 1391 | - if ($event['recur_type'] != MCAL_RECUR_NONE) $event['cal_reference'] = 0; |
|
| 1540 | + if ($event['recur_type'] != MCAL_RECUR_NONE) |
|
| 1541 | + { |
|
| 1542 | + $event['cal_reference'] = 0; |
|
| 1543 | + } |
|
| 1392 | 1544 | |
| 1393 | 1545 | if ($cal_id) |
| 1394 | 1546 | { |
@@ -1405,7 +1557,10 @@ discard block |
||
| 1405 | 1557 | { |
| 1406 | 1558 | $old_tz_id = $this->db->select($this->cal_table,'tz_id',$where,__LINE__,__FILE__,'calendar')->fetchColumn(); |
| 1407 | 1559 | } |
| 1408 | - if (!is_null($etag)) $where['cal_etag'] = $etag; |
|
| 1560 | + if (!is_null($etag)) |
|
| 1561 | + { |
|
| 1562 | + $where['cal_etag'] = $etag; |
|
| 1563 | + } |
|
| 1409 | 1564 | |
| 1410 | 1565 | unset($event['cal_etag']); |
| 1411 | 1566 | $event[] = 'cal_etag=cal_etag+1'; // always update the etag, even if none given to check |
@@ -1416,14 +1571,24 @@ discard block |
||
| 1416 | 1571 | { |
| 1417 | 1572 | return 0; // wrong etag, someone else updated the entry |
| 1418 | 1573 | } |
| 1419 | - if (!is_null($etag)) ++$etag; |
|
| 1574 | + if (!is_null($etag)) |
|
| 1575 | + { |
|
| 1576 | + ++$etag; |
|
| 1577 | + } |
|
| 1420 | 1578 | } |
| 1421 | 1579 | else |
| 1422 | 1580 | { |
| 1423 | 1581 | // new event |
| 1424 | - if (!$event['cal_owner']) $event['cal_owner'] = $GLOBALS['egw_info']['user']['account_id']; |
|
| 1582 | + if (!$event['cal_owner']) |
|
| 1583 | + { |
|
| 1584 | + $event['cal_owner'] = $GLOBALS['egw_info']['user']['account_id']; |
|
| 1585 | + } |
|
| 1425 | 1586 | |
| 1426 | - if (!$event['cal_id'] && !isset($event['cal_uid'])) $event['cal_uid'] = ''; // uid is NOT NULL! |
|
| 1587 | + if (!$event['cal_id'] && !isset($event['cal_uid'])) |
|
| 1588 | + { |
|
| 1589 | + $event['cal_uid'] = ''; |
|
| 1590 | + } |
|
| 1591 | + // uid is NOT NULL! |
|
| 1427 | 1592 | |
| 1428 | 1593 | $this->db->insert($this->cal_table,$event,false,__LINE__,__FILE__,'calendar'); |
| 1429 | 1594 | if (!($cal_id = $this->db->get_last_insert_id($this->cal_table,'cal_id'))) |
@@ -1575,8 +1740,7 @@ discard block |
||
| 1575 | 1740 | // recurrences need to be truncated |
| 1576 | 1741 | if((int)$event['recur_enddate'] > 0 && |
| 1577 | 1742 | ((int)$old_repeats['recur_enddate'] == 0 || (int)$old_repeats['recur_enddate'] > (int)$event['recur_enddate']) |
| 1578 | - ) |
|
| 1579 | - { |
|
| 1743 | + ) { |
|
| 1580 | 1744 | $this->db->delete($this->user_table,array('cal_id' => $cal_id,'cal_recur_date >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar'); |
| 1581 | 1745 | $this->db->delete($this->dates_table,array('cal_id' => $cal_id,'cal_start >= '.($event['recur_enddate'] + 1*DAY_s)),__LINE__,__FILE__,'calendar'); |
| 1582 | 1746 | } |
@@ -1584,8 +1748,7 @@ discard block |
||
| 1584 | 1748 | // recurrences need to be expanded |
| 1585 | 1749 | if(((int)$event['recur_enddate'] == 0 && (int)$old_repeats['recur_enddate'] > 0) |
| 1586 | 1750 | || ((int)$event['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] > 0 && (int)$old_repeats['recur_enddate'] < (int)$event['recur_enddate']) |
| 1587 | - ) |
|
| 1588 | - { |
|
| 1751 | + ) { |
|
| 1589 | 1752 | $set_recurrences = true; |
| 1590 | 1753 | $set_recurrences_start = ($old_repeats['recur_enddate'] + 1*DAY_s); |
| 1591 | 1754 | } |
@@ -1732,12 +1895,18 @@ discard block |
||
| 1732 | 1895 | { |
| 1733 | 1896 | //echo "<p>socal::move($cal_id,$start,$end,$change_since,$old_start,$old_end)</p>\n"; |
| 1734 | 1897 | |
| 1735 | - if (!(int) $cal_id) return false; |
|
| 1898 | + if (!(int) $cal_id) |
|
| 1899 | + { |
|
| 1900 | + return false; |
|
| 1901 | + } |
|
| 1736 | 1902 | |
| 1737 | 1903 | if (!$old_start) |
| 1738 | 1904 | { |
| 1739 | - if ($change_since !== false) $row = $this->db->select($this->dates_table,'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end', |
|
| 1905 | + if ($change_since !== false) |
|
| 1906 | + { |
|
| 1907 | + $row = $this->db->select($this->dates_table,'MIN(cal_start) AS cal_start,MIN(cal_end) AS cal_end', |
|
| 1740 | 1908 | array('cal_id'=>$cal_id),__LINE__,__FILE__,false,'','calendar')->fetch(); |
| 1909 | + } |
|
| 1741 | 1910 | // if no recurrence found, create one with the new dates |
| 1742 | 1911 | if ($change_since === false || !$row || !$row['cal_start'] || !$row['cal_end']) |
| 1743 | 1912 | { |
@@ -1839,7 +2008,10 @@ discard block |
||
| 1839 | 2008 | $user_type = $uid[0]; |
| 1840 | 2009 | $email = substr($uid, 1); |
| 1841 | 2010 | $matches = null; |
| 1842 | - if (preg_match('/<([^<>]+)>$/', $email, $matches)) $email = $matches[1]; |
|
| 2011 | + if (preg_match('/<([^<>]+)>$/', $email, $matches)) |
|
| 2012 | + { |
|
| 2013 | + $email = $matches[1]; |
|
| 2014 | + } |
|
| 1843 | 2015 | $user_id = md5(trim(strtolower($email))); |
| 1844 | 2016 | } |
| 1845 | 2017 | else |
@@ -1859,8 +2031,14 @@ discard block |
||
| 1859 | 2031 | */ |
| 1860 | 2032 | static function combine_status($status,$quantity=1,$role='REQ-PARTICIPANT') |
| 1861 | 2033 | { |
| 1862 | - if ((int)$quantity > 1) $status .= (int)$quantity; |
|
| 1863 | - if ($role != 'REQ-PARTICIPANT') $status .= $role; |
|
| 2034 | + if ((int)$quantity > 1) |
|
| 2035 | + { |
|
| 2036 | + $status .= (int)$quantity; |
|
| 2037 | + } |
|
| 2038 | + if ($role != 'REQ-PARTICIPANT') |
|
| 2039 | + { |
|
| 2040 | + $status .= $role; |
|
| 2041 | + } |
|
| 1864 | 2042 | |
| 1865 | 2043 | return $status; |
| 1866 | 2044 | } |
@@ -1881,8 +2059,14 @@ discard block |
||
| 1881 | 2059 | $matches = null; |
| 1882 | 2060 | if (is_string($status) && strlen($status) > 1 && preg_match('/^.([0-9]*)(.*)$/',$status,$matches)) |
| 1883 | 2061 | { |
| 1884 | - if ((int)$matches[1] > 0) $quantity = (int)$matches[1]; |
|
| 1885 | - if ($matches[2]) $role = $matches[2]; |
|
| 2062 | + if ((int)$matches[1] > 0) |
|
| 2063 | + { |
|
| 2064 | + $quantity = (int)$matches[1]; |
|
| 2065 | + } |
|
| 2066 | + if ($matches[2]) |
|
| 2067 | + { |
|
| 2068 | + $role = $matches[2]; |
|
| 2069 | + } |
|
| 1886 | 2070 | $status = $status[0]; |
| 1887 | 2071 | } |
| 1888 | 2072 | elseif ($status === true) |
@@ -1993,9 +2177,13 @@ discard block |
||
| 1993 | 2177 | } |
| 1994 | 2178 | } |
| 1995 | 2179 | |
| 1996 | - if (count($participants)) // participants which need to be added |
|
| 2180 | + if (count($participants)) |
|
| 2181 | + { |
|
| 2182 | + // participants which need to be added |
|
| 1997 | 2183 | { |
| 1998 | - if (!count($recurrences)) $recurrences[] = 0; // insert the default recurrence |
|
| 2184 | + if (!count($recurrences)) $recurrences[] = 0; |
|
| 2185 | + } |
|
| 2186 | + // insert the default recurrence |
|
| 1999 | 2187 | |
| 2000 | 2188 | $delete_deleted = array(); |
| 2001 | 2189 | |
@@ -2067,7 +2255,10 @@ discard block |
||
| 2067 | 2255 | return false; |
| 2068 | 2256 | } |
| 2069 | 2257 | |
| 2070 | - if (is_numeric($status)) $status = $status_code_short[$status]; |
|
| 2258 | + if (is_numeric($status)) |
|
| 2259 | + { |
|
| 2260 | + $status = $status_code_short[$status]; |
|
| 2261 | + } |
|
| 2071 | 2262 | |
| 2072 | 2263 | $uid = self::combine_user($user_type, $user_id); |
| 2073 | 2264 | $user_id_md5 = null; |
@@ -2087,16 +2278,25 @@ discard block |
||
| 2087 | 2278 | $where[] = '(cal_recur_date=0 OR cal_recur_date >= '.time().')'; |
| 2088 | 2279 | } |
| 2089 | 2280 | |
| 2090 | - if ($status == 'G') // remove group invitations, as we dont store them in the db |
|
| 2281 | + if ($status == 'G') |
|
| 2282 | + { |
|
| 2283 | + // remove group invitations, as we dont store them in the db |
|
| 2091 | 2284 | { |
| 2092 | 2285 | $this->db->delete($this->user_table,$where,__LINE__,__FILE__,'calendar'); |
| 2286 | + } |
|
| 2093 | 2287 | $ret = $this->db->affected_rows(); |
| 2094 | 2288 | } |
| 2095 | 2289 | else |
| 2096 | 2290 | { |
| 2097 | 2291 | $set = array('cal_status' => $status); |
| 2098 | - if ($user_type == 'e' || $attendee) $set['cal_user_attendee'] = $attendee ? $attendee : $user_id; |
|
| 2099 | - if (!is_null($role) && $role != 'REQ-PARTICIPANT') $set['cal_role'] = $role; |
|
| 2292 | + if ($user_type == 'e' || $attendee) |
|
| 2293 | + { |
|
| 2294 | + $set['cal_user_attendee'] = $attendee ? $attendee : $user_id; |
|
| 2295 | + } |
|
| 2296 | + if (!is_null($role) && $role != 'REQ-PARTICIPANT') |
|
| 2297 | + { |
|
| 2298 | + $set['cal_role'] = $role; |
|
| 2299 | + } |
|
| 2100 | 2300 | $this->db->insert($this->user_table,$set,$where,__LINE__,__FILE__,'calendar'); |
| 2101 | 2301 | // for new or changed group-invitations, remove previously deleted members, so they show up again |
| 2102 | 2302 | if (($ret = $this->db->affected_rows()) && $user_type == 'u' && $user_id < 0) |
@@ -2129,7 +2329,10 @@ discard block |
||
| 2129 | 2329 | { |
| 2130 | 2330 | //error_log(__METHOD__."($cal_id, $start, $end, ".array2string($participants).", ".array2string($exception)); |
| 2131 | 2331 | $update = array('cal_end' => $end); |
| 2132 | - if (isset($exception)) $update['recur_exception'] = $exception; |
|
| 2332 | + if (isset($exception)) |
|
| 2333 | + { |
|
| 2334 | + $update['recur_exception'] = $exception; |
|
| 2335 | + } |
|
| 2133 | 2336 | |
| 2134 | 2337 | $this->db->insert($this->dates_table, $update, array( |
| 2135 | 2338 | 'cal_id' => $cal_id, |
@@ -2144,7 +2347,11 @@ discard block |
||
| 2144 | 2347 | { |
| 2145 | 2348 | foreach($participants as $uid => $status) |
| 2146 | 2349 | { |
| 2147 | - if ($status == 'G') continue; // dont save group-invitations |
|
| 2350 | + if ($status == 'G') |
|
| 2351 | + { |
|
| 2352 | + continue; |
|
| 2353 | + } |
|
| 2354 | + // dont save group-invitations |
|
| 2148 | 2355 | |
| 2149 | 2356 | $type = ''; |
| 2150 | 2357 | $id = null; |
@@ -2373,7 +2580,10 @@ discard block |
||
| 2373 | 2580 | } |
| 2374 | 2581 | $alarm['cal_id'] = $cal_id; // we need the back-reference |
| 2375 | 2582 | // add an alarm uid, if none is given |
| 2376 | - if (empty($alarm['uid']) && class_exists('Horde_Support_Uuid')) $alarm['uid'] = (string)new Horde_Support_Uuid; |
|
| 2583 | + if (empty($alarm['uid']) && class_exists('Horde_Support_Uuid')) |
|
| 2584 | + { |
|
| 2585 | + $alarm['uid'] = (string)new Horde_Support_Uuid; |
|
| 2586 | + } |
|
| 2377 | 2587 | //error_log(__METHOD__.__LINE__.' Save Alarm for CalID:'.$cal_id.'->'.array2string($alarm).'-->'.$id.'#'.function_backtrace()); |
| 2378 | 2588 | // allways store job with the alarm owner as job-owner to get eg. the correct from address |
| 2379 | 2589 | if (!$this->async->set_timer($alarm['time'],$id,'calendar.calendar_boupdate.send_alarm',$alarm,$alarm['owner'])) |
@@ -2382,10 +2592,16 @@ discard block |
||
| 2382 | 2592 | } |
| 2383 | 2593 | |
| 2384 | 2594 | // update the modification information of the related event |
| 2385 | - if ($update_modified) $this->updateModified($cal_id, true); |
|
| 2595 | + if ($update_modified) |
|
| 2596 | + { |
|
| 2597 | + $this->updateModified($cal_id, true); |
|
| 2598 | + } |
|
| 2386 | 2599 | |
| 2387 | 2600 | // update cache, if used |
| 2388 | - if (isset(self::$alarm_cache)) $this->read_alarms($cal_id, true); |
|
| 2601 | + if (isset(self::$alarm_cache)) |
|
| 2602 | + { |
|
| 2603 | + $this->read_alarms($cal_id, true); |
|
| 2604 | + } |
|
| 2389 | 2605 | |
| 2390 | 2606 | return $id; |
| 2391 | 2607 | } |
@@ -2408,7 +2624,10 @@ discard block |
||
| 2408 | 2624 | $this->async->cancel_timer($id); |
| 2409 | 2625 | } |
| 2410 | 2626 | // update cache, if used |
| 2411 | - if (isset(self::$alarm_cache)) $this->read_alarms($cal_id, false); |
|
| 2627 | + if (isset(self::$alarm_cache)) |
|
| 2628 | + { |
|
| 2629 | + $this->read_alarms($cal_id, false); |
|
| 2630 | + } |
|
| 2412 | 2631 | } |
| 2413 | 2632 | return count($alarms); |
| 2414 | 2633 | } |
@@ -2431,7 +2650,10 @@ discard block |
||
| 2431 | 2650 | $ret = $this->async->cancel_timer($id); |
| 2432 | 2651 | |
| 2433 | 2652 | // update cache, if used |
| 2434 | - if (isset(self::$alarm_cache)) $this->read_alarms($cal_id, true); |
|
| 2653 | + if (isset(self::$alarm_cache)) |
|
| 2654 | + { |
|
| 2655 | + $this->read_alarms($cal_id, true); |
|
| 2656 | + } |
|
| 2435 | 2657 | |
| 2436 | 2658 | return $ret; |
| 2437 | 2659 | } |
@@ -2455,11 +2677,14 @@ discard block |
||
| 2455 | 2677 | $user_id = null; |
| 2456 | 2678 | self::split_user($old_user,$user_type,$user_id); |
| 2457 | 2679 | |
| 2458 | - if ($user_type == 'u') // only accounts can be owners of events |
|
| 2680 | + if ($user_type == 'u') |
|
| 2681 | + { |
|
| 2682 | + // only accounts can be owners of events |
|
| 2459 | 2683 | { |
| 2460 | 2684 | foreach($this->db->select($this->cal_table,'cal_id',array('cal_owner' => $old_user),__LINE__,__FILE__,false,'','calendar') as $row) |
| 2461 | 2685 | { |
| 2462 | 2686 | $this->delete($row['cal_id']); |
| 2687 | + } |
|
| 2463 | 2688 | } |
| 2464 | 2689 | } |
| 2465 | 2690 | $this->db->delete($this->user_table,array( |
@@ -2487,11 +2712,14 @@ discard block |
||
| 2487 | 2712 | { |
| 2488 | 2713 | $ids[] = $row['cal_id']; |
| 2489 | 2714 | } |
| 2490 | - if ($ids) $this->db->delete($this->user_table,array( |
|
| 2715 | + if ($ids) |
|
| 2716 | + { |
|
| 2717 | + $this->db->delete($this->user_table,array( |
|
| 2491 | 2718 | 'cal_user_type' => 'u', |
| 2492 | 2719 | 'cal_user_id' => $old_user, |
| 2493 | 2720 | 'cal_id' => $ids, |
| 2494 | 2721 | ),__LINE__,__FILE__,'calendar'); |
| 2722 | + } |
|
| 2495 | 2723 | // now change participant in the rest to contain new user instead of old user |
| 2496 | 2724 | $this->db->update($this->user_table,array( |
| 2497 | 2725 | 'cal_user_id' => $new_user, |
@@ -2516,8 +2744,14 @@ discard block |
||
| 2516 | 2744 | { |
| 2517 | 2745 | $participant_status = array(); |
| 2518 | 2746 | $where = array('cal_id' => $cal_id); |
| 2519 | - if ($start != 0 && $end == 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')'; |
|
| 2520 | - if ($start == 0 && $end != 0) $where[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')'; |
|
| 2747 | + if ($start != 0 && $end == 0) |
|
| 2748 | + { |
|
| 2749 | + $where[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')'; |
|
| 2750 | + } |
|
| 2751 | + if ($start == 0 && $end != 0) |
|
| 2752 | + { |
|
| 2753 | + $where[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')'; |
|
| 2754 | + } |
|
| 2521 | 2755 | if ($start != 0 && $end != 0) |
| 2522 | 2756 | { |
| 2523 | 2757 | $where[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start . |
@@ -2528,7 +2762,10 @@ discard block |
||
| 2528 | 2762 | // inititalize the array |
| 2529 | 2763 | $participant_status[$row['cal_recur_date']] = null; |
| 2530 | 2764 | } |
| 2531 | - if (is_null($uid)) return $participant_status; |
|
| 2765 | + if (is_null($uid)) |
|
| 2766 | + { |
|
| 2767 | + return $participant_status; |
|
| 2768 | + } |
|
| 2532 | 2769 | $user_type = $user_id = null; |
| 2533 | 2770 | self::split_user($uid, $user_type, $user_id, true); |
| 2534 | 2771 | |
@@ -2537,8 +2774,14 @@ discard block |
||
| 2537 | 2774 | 'cal_user_type' => $user_type ? $user_type : 'u', |
| 2538 | 2775 | 'cal_user_id' => $user_id, |
| 2539 | 2776 | ); |
| 2540 | - if ($start != 0 && $end == 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')'; |
|
| 2541 | - if ($start == 0 && $end != 0) $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')'; |
|
| 2777 | + if ($start != 0 && $end == 0) |
|
| 2778 | + { |
|
| 2779 | + $where2[] = '(cal_recur_date = 0 OR cal_recur_date >= ' . (int)$start . ')'; |
|
| 2780 | + } |
|
| 2781 | + if ($start == 0 && $end != 0) |
|
| 2782 | + { |
|
| 2783 | + $where2[] = '(cal_recur_date = 0 OR cal_recur_date <= ' . (int)$end . ')'; |
|
| 2784 | + } |
|
| 2542 | 2785 | if ($start != 0 && $end != 0) |
| 2543 | 2786 | { |
| 2544 | 2787 | $where2[] = '(cal_recur_date = 0 OR (cal_recur_date >= ' . (int)$start . |
@@ -2628,17 +2871,26 @@ discard block |
||
| 2628 | 2871 | */ |
| 2629 | 2872 | function get_recurrence_exceptions($event, $tz_id=null, $start=0, $end=0, $filter='all') |
| 2630 | 2873 | { |
| 2631 | - if (!is_array($event)) return false; |
|
| 2874 | + if (!is_array($event)) |
|
| 2875 | + { |
|
| 2876 | + return false; |
|
| 2877 | + } |
|
| 2632 | 2878 | $cal_id = (int) $event['id']; |
| 2633 | 2879 | //error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. |
| 2634 | 2880 | // "($cal_id, $tz_id, $filter): " . $event['tzid']); |
| 2635 | - if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE) return false; |
|
| 2881 | + if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE) |
|
| 2882 | + { |
|
| 2883 | + return false; |
|
| 2884 | + } |
|
| 2636 | 2885 | |
| 2637 | 2886 | $days = array(); |
| 2638 | 2887 | |
| 2639 | 2888 | $expand_all = (!$this->isWholeDay($event) && $tz_id && $tz_id != $event['tzid']); |
| 2640 | 2889 | |
| 2641 | - if ($filter == 'tz_only' && !$expand_all) return $days; |
|
| 2890 | + if ($filter == 'tz_only' && !$expand_all) |
|
| 2891 | + { |
|
| 2892 | + return $days; |
|
| 2893 | + } |
|
| 2642 | 2894 | |
| 2643 | 2895 | $remote = in_array($filter, array('tz_rrule', 'rrule')); |
| 2644 | 2896 | |
@@ -2681,7 +2933,10 @@ discard block |
||
| 2681 | 2933 | $remote_rrule->next_no_exception(); |
| 2682 | 2934 | } |
| 2683 | 2935 | $egw_rrule->next_no_exception(); |
| 2684 | - if (!$egw_rrule->valid()) return $days; |
|
| 2936 | + if (!$egw_rrule->valid()) |
|
| 2937 | + { |
|
| 2938 | + return $days; |
|
| 2939 | + } |
|
| 2685 | 2940 | } |
| 2686 | 2941 | $day = $egw_rrule->current(); |
| 2687 | 2942 | $locts = (int)Api\DateTime::to($day,'server'); |
@@ -2835,7 +3090,11 @@ discard block |
||
| 2835 | 3090 | } |
| 2836 | 3091 | } |
| 2837 | 3092 | |
| 2838 | - if (empty($participants)) return false; // occurrence does not exist at all yet |
|
| 3093 | + if (empty($participants)) |
|
| 3094 | + { |
|
| 3095 | + return false; |
|
| 3096 | + } |
|
| 3097 | + // occurrence does not exist at all yet |
|
| 2839 | 3098 | |
| 2840 | 3099 | foreach ($recurrence_zero as $uid => $status) |
| 2841 | 3100 | { |
@@ -2892,7 +3151,9 @@ discard block |
||
| 2892 | 3151 | } |
| 2893 | 3152 | if (!isset($participants[$uid]) |
| 2894 | 3153 | || $participants[$uid] != $status) |
| 2895 | - return true; |
|
| 3154 | + { |
|
| 3155 | + return true; |
|
| 3156 | + } |
|
| 2896 | 3157 | unset($participants[$uid]); |
| 2897 | 3158 | } |
| 2898 | 3159 | return (!empty($participants)); |
@@ -2906,7 +3167,10 @@ discard block |
||
| 2906 | 3167 | */ |
| 2907 | 3168 | function isWholeDay($event) |
| 2908 | 3169 | { |
| 2909 | - if (!isset($event['start']) || !isset($event['end'])) return false; |
|
| 3170 | + if (!isset($event['start']) || !isset($event['end'])) |
|
| 3171 | + { |
|
| 3172 | + return false; |
|
| 3173 | + } |
|
| 2910 | 3174 | |
| 2911 | 3175 | if (empty($event['tzid'])) |
| 2912 | 3176 | { |
@@ -2968,8 +3232,14 @@ discard block |
||
| 2968 | 3232 | */ |
| 2969 | 3233 | function updateModified($id, $update_master=false, $time=null, $modifier=null) |
| 2970 | 3234 | { |
| 2971 | - if (is_null($time) || !$time) $time = time(); |
|
| 2972 | - if (is_null($modifier)) $modifier = $GLOBALS['egw_info']['user']['account_id']; |
|
| 3235 | + if (is_null($time) || !$time) |
|
| 3236 | + { |
|
| 3237 | + $time = time(); |
|
| 3238 | + } |
|
| 3239 | + if (is_null($modifier)) |
|
| 3240 | + { |
|
| 3241 | + $modifier = $GLOBALS['egw_info']['user']['account_id']; |
|
| 3242 | + } |
|
| 2973 | 3243 | |
| 2974 | 3244 | $this->db->update($this->cal_table, |
| 2975 | 3245 | array('cal_modified' => $time, 'cal_modifier' => $modifier), |
@@ -17,7 +17,8 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * class import_csv for addressbook |
| 19 | 19 | */ |
| 20 | -class import_events_csv implements iface_import_plugin { |
|
| 20 | +class import_events_csv implements iface_import_plugin |
|
| 21 | +{ |
|
| 21 | 22 | |
| 22 | 23 | private static $plugin_options = array( |
| 23 | 24 | 'fieldsep', // char |
@@ -97,7 +98,8 @@ discard block |
||
| 97 | 98 | * @param string $_charset |
| 98 | 99 | * @param definition $_definition |
| 99 | 100 | */ |
| 100 | - public function import( $_stream, definition $_definition ) { |
|
| 101 | + public function import( $_stream, definition $_definition ) |
|
| 102 | + { |
|
| 101 | 103 | $import_csv = new import_csv( $_stream, array( |
| 102 | 104 | 'fieldsep' => $_definition->plugin_options['fieldsep'], |
| 103 | 105 | 'charset' => $_definition->plugin_options['charset'], |
@@ -122,7 +124,8 @@ discard block |
||
| 122 | 124 | $import_csv->conversion = $_definition->plugin_options['field_conversion']; |
| 123 | 125 | |
| 124 | 126 | //check if file has a header lines |
| 125 | - if ( isset( $_definition->plugin_options['num_header_lines'] ) ) { |
|
| 127 | + if ( isset( $_definition->plugin_options['num_header_lines'] ) ) |
|
| 128 | + { |
|
| 126 | 129 | $import_csv->skip_records( $_definition->plugin_options['num_header_lines'] ); |
| 127 | 130 | } |
| 128 | 131 | |
@@ -131,12 +134,16 @@ discard block |
||
| 131 | 134 | $_definition->plugin_options['events_owner'] : $this->user; |
| 132 | 135 | |
| 133 | 136 | // trash_users_records ? |
| 134 | - if ( $_definition->plugin_options['trash_users_records'] === true ) { |
|
| 135 | - if ( !$_definition->plugin_options['dry_run'] ) { |
|
| 137 | + if ( $_definition->plugin_options['trash_users_records'] === true ) |
|
| 138 | + { |
|
| 139 | + if ( !$_definition->plugin_options['dry_run'] ) |
|
| 140 | + { |
|
| 136 | 141 | $socal = new calendar_socal(); |
| 137 | 142 | $this->bocalupdate->so->deleteaccount( $_definition->plugin_options['events_owner']); |
| 138 | 143 | unset( $socal ); |
| 139 | - } else { |
|
| 144 | + } |
|
| 145 | + else |
|
| 146 | + { |
|
| 140 | 147 | $lid = $GLOBALS['egw']->accounts->id2name( $_definition->plugin_options['events_owner'] ); |
| 141 | 148 | echo "Attension: All Events of '$lid' would be deleted!\n"; |
| 142 | 149 | } |
@@ -145,38 +152,63 @@ discard block |
||
| 145 | 152 | $this->errors = array(); |
| 146 | 153 | $this->results = array(); |
| 147 | 154 | |
| 148 | - while ( $record = $import_csv->get_record() ) { |
|
| 155 | + while ( $record = $import_csv->get_record() ) |
|
| 156 | + { |
|
| 149 | 157 | |
| 150 | 158 | // don't import empty events |
| 151 | - if( count( array_unique( $record ) ) < 2 ) continue; |
|
| 159 | + if( count( array_unique( $record ) ) < 2 ) |
|
| 160 | + { |
|
| 161 | + continue; |
|
| 162 | + } |
|
| 152 | 163 | |
| 153 | - if ( $_definition->plugin_options['events_owner'] != -1 ) { |
|
| 164 | + if ( $_definition->plugin_options['events_owner'] != -1 ) |
|
| 165 | + { |
|
| 154 | 166 | $record['owner'] = $_definition->plugin_options['events_owner']; |
| 155 | - } else unset( $record['owner'] ); |
|
| 167 | + } |
|
| 168 | + else { |
|
| 169 | + unset( $record['owner'] ); |
|
| 170 | + } |
|
| 156 | 171 | |
| 157 | - if ( $_definition->plugin_options['conditions'] ) { |
|
| 158 | - foreach ( $_definition->plugin_options['conditions'] as $condition ) { |
|
| 159 | - switch ( $condition['type'] ) { |
|
| 172 | + if ( $_definition->plugin_options['conditions'] ) |
|
| 173 | + { |
|
| 174 | + foreach ( $_definition->plugin_options['conditions'] as $condition ) |
|
| 175 | + { |
|
| 176 | + switch ( $condition['type'] ) |
|
| 177 | + { |
|
| 160 | 178 | // exists |
| 161 | 179 | case 'exists' : |
| 162 | 180 | |
| 163 | - if ( is_array( $event = $this->bocalupdate->read( $record['uid'], null, $this->is_admin ) ) ) { |
|
| 181 | + if ( is_array( $event = $this->bocalupdate->read( $record['uid'], null, $this->is_admin ) ) ) |
|
| 182 | + { |
|
| 164 | 183 | // apply action to event matching this exists condition |
| 165 | 184 | $record['id'] = $event['id']; |
| 166 | 185 | |
| 167 | - if ( $_definition->plugin_options['update_cats'] == 'add' ) { |
|
| 168 | - if ( !is_array( $event['cat_id'] ) ) $event['cat_id'] = explode( ',', $event['cat_id'] ); |
|
| 169 | - if ( !is_array( $record['cat_id'] ) ) $record['cat_id'] = explode( ',', $record['cat_id'] ); |
|
| 186 | + if ( $_definition->plugin_options['update_cats'] == 'add' ) |
|
| 187 | + { |
|
| 188 | + if ( !is_array( $event['cat_id'] ) ) |
|
| 189 | + { |
|
| 190 | + $event['cat_id'] = explode( ',', $event['cat_id'] ); |
|
| 191 | + } |
|
| 192 | + if ( !is_array( $record['cat_id'] ) ) |
|
| 193 | + { |
|
| 194 | + $record['cat_id'] = explode( ',', $record['cat_id'] ); |
|
| 195 | + } |
|
| 170 | 196 | $record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $event['cat_id'] ) ) ); |
| 171 | 197 | } |
| 172 | 198 | |
| 173 | 199 | // check if entry is modiefied |
| 174 | 200 | $event = array_intersect_key( $event, $record ); |
| 175 | 201 | $diff = array_diff( $event, $record ); |
| 176 | - if( !empty( $diff ) ) $record['modified'] = time(); |
|
| 202 | + if( !empty( $diff ) ) |
|
| 203 | + { |
|
| 204 | + $record['modified'] = time(); |
|
| 205 | + } |
|
| 177 | 206 | |
| 178 | 207 | $action = $condition['true']; |
| 179 | - } else $action = $condition['false']; |
|
| 208 | + } |
|
| 209 | + else { |
|
| 210 | + $action = $condition['false']; |
|
| 211 | + } |
|
| 180 | 212 | |
| 181 | 213 | $this->action( $action['action'], $record ); |
| 182 | 214 | break; |
@@ -190,9 +222,14 @@ discard block |
||
| 190 | 222 | throw new Exception('condition not supported!!!'); |
| 191 | 223 | break; |
| 192 | 224 | } |
| 193 | - if ($action['last']) break; |
|
| 225 | + if ($action['last']) |
|
| 226 | + { |
|
| 227 | + break; |
|
| 228 | + } |
|
| 194 | 229 | } |
| 195 | - } else { |
|
| 230 | + } |
|
| 231 | + else |
|
| 232 | + { |
|
| 196 | 233 | // unconditional insert |
| 197 | 234 | $this->action( 'insert', $record ); |
| 198 | 235 | } |
@@ -206,8 +243,10 @@ discard block |
||
| 206 | 243 | * @param array $_data event data for the action |
| 207 | 244 | * @return bool success or not |
| 208 | 245 | */ |
| 209 | - private function action ( $_action, $_data ) { |
|
| 210 | - switch ( $_action ) { |
|
| 246 | + private function action ( $_action, $_data ) |
|
| 247 | + { |
|
| 248 | + switch ( $_action ) |
|
| 249 | + { |
|
| 211 | 250 | case 'none' : |
| 212 | 251 | return true; |
| 213 | 252 | |
@@ -217,32 +256,42 @@ discard block |
||
| 217 | 256 | // paticipants handling |
| 218 | 257 | $participants = $_data['participants'] ? split( '[,;]', $_data['participants'] ) : array(); |
| 219 | 258 | $_data['participants'] = array(); |
| 220 | - if ( $this->definition->plugin_options['owner_joins_event'] && $this->definition->plugin_options['events_owner'] > 0 ) { |
|
| 259 | + if ( $this->definition->plugin_options['owner_joins_event'] && $this->definition->plugin_options['events_owner'] > 0 ) |
|
| 260 | + { |
|
| 221 | 261 | $_data['participants'][$this->definition->plugin_options['events_owner']] = 'A'; |
| 222 | 262 | } |
| 223 | - foreach( $participants as $participant ) { |
|
| 263 | + foreach( $participants as $participant ) |
|
| 264 | + { |
|
| 224 | 265 | list( $participant, $status ) = explode( '=', $participant ); |
| 225 | 266 | $valid_staties = array('U'=>'U','u'=>'U','A'=>'A','a'=>'A','R'=>'R','r'=>'R','T'=>'T','t'=>'T'); |
| 226 | 267 | $status = isset( $valid_staties[$status] ) ? $valid_staties[$status] : 'U'; |
| 227 | - if ( $participant && is_numeric($participant ) ) { |
|
| 268 | + if ( $participant && is_numeric($participant ) ) |
|
| 269 | + { |
|
| 228 | 270 | $_data['participants'][$participant] = $status; |
| 229 | 271 | } |
| 230 | 272 | } |
| 231 | 273 | // no valid participants so far --> add the importing user/owner |
| 232 | - if ( empty( $_data['participants'] ) ) { |
|
| 274 | + if ( empty( $_data['participants'] ) ) |
|
| 275 | + { |
|
| 233 | 276 | $_data['participants'][$this->user] = 'A'; |
| 234 | 277 | } |
| 235 | 278 | |
| 236 | 279 | // are we serious? |
| 237 | - if ( $this->dry_run ) { |
|
| 280 | + if ( $this->dry_run ) |
|
| 281 | + { |
|
| 238 | 282 | print_r($_data); |
| 239 | 283 | $this->results[$_action]++; |
| 240 | - } else { |
|
| 284 | + } |
|
| 285 | + else |
|
| 286 | + { |
|
| 241 | 287 | $messages = array(); |
| 242 | 288 | $result = $this->bocalupdate->update( $_data, true, !$_data['modified'], $this->is_admin, true, $messages); |
| 243 | - if(!$result) { |
|
| 289 | + if(!$result) |
|
| 290 | + { |
|
| 244 | 291 | $this->errors = implode(',', $messages); |
| 245 | - } else { |
|
| 292 | + } |
|
| 293 | + else |
|
| 294 | + { |
|
| 246 | 295 | $this->results[$_action]++; |
| 247 | 296 | } |
| 248 | 297 | return $result; |
@@ -257,7 +306,8 @@ discard block |
||
| 257 | 306 | * |
| 258 | 307 | * @return string name |
| 259 | 308 | */ |
| 260 | - public static function get_name() { |
|
| 309 | + public static function get_name() |
|
| 310 | + { |
|
| 261 | 311 | return lang('Calendar CSV export'); |
| 262 | 312 | } |
| 263 | 313 | |
@@ -266,7 +316,8 @@ discard block |
||
| 266 | 316 | * |
| 267 | 317 | * @return string descriprion |
| 268 | 318 | */ |
| 269 | - public static function get_description() { |
|
| 319 | + public static function get_description() |
|
| 320 | + { |
|
| 270 | 321 | return lang("Imports events into your Calendar from a CSV File. CSV means 'Comma Seperated Values'. However in the options Tab you can also choose other seperators."); |
| 271 | 322 | } |
| 272 | 323 | |
@@ -275,7 +326,8 @@ discard block |
||
| 275 | 326 | * |
| 276 | 327 | * @return string suffix (comma seperated) |
| 277 | 328 | */ |
| 278 | - public static function get_filesuffix() { |
|
| 329 | + public static function get_filesuffix() |
|
| 330 | + { |
|
| 279 | 331 | return 'csv'; |
| 280 | 332 | } |
| 281 | 333 | |
@@ -291,7 +343,8 @@ discard block |
||
| 291 | 343 | * preserv => array, |
| 292 | 344 | * ) |
| 293 | 345 | */ |
| 294 | - public function get_options_etpl() { |
|
| 346 | + public function get_options_etpl() |
|
| 347 | + { |
|
| 295 | 348 | // lets do it! |
| 296 | 349 | } |
| 297 | 350 | |
@@ -300,7 +353,8 @@ discard block |
||
| 300 | 353 | * |
| 301 | 354 | * @return string etemplate name |
| 302 | 355 | */ |
| 303 | - public function get_selectors_etpl() { |
|
| 356 | + public function get_selectors_etpl() |
|
| 357 | + { |
|
| 304 | 358 | // lets do it! |
| 305 | 359 | } |
| 306 | 360 | |
@@ -312,7 +366,8 @@ discard block |
||
| 312 | 366 | * record_# => error message |
| 313 | 367 | * ) |
| 314 | 368 | */ |
| 315 | - public function get_errors() { |
|
| 369 | + public function get_errors() |
|
| 370 | + { |
|
| 316 | 371 | return $this->errors; |
| 317 | 372 | } |
| 318 | 373 | |
@@ -324,7 +379,8 @@ discard block |
||
| 324 | 379 | * action => record count |
| 325 | 380 | * ) |
| 326 | 381 | */ |
| 327 | - public function get_results() { |
|
| 382 | + public function get_results() |
|
| 383 | + { |
|
| 328 | 384 | return $this->results; |
| 329 | 385 | } |
| 330 | 386 | } // end of iface_export_plugin |
@@ -14,7 +14,10 @@ |
||
| 14 | 14 | |
| 15 | 15 | use EGroupware\Api\Asyncservice; |
| 16 | 16 | |
| 17 | -if (!isset($_REQUEST['domain'])) $_REQUEST['domain'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'default'; |
|
| 17 | +if (!isset($_REQUEST['domain'])) |
|
| 18 | +{ |
|
| 19 | + $_REQUEST['domain'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 'default'; |
|
| 20 | +} |
|
| 18 | 21 | $path_to_egroupware = realpath(__DIR__.'/..'); // need to be adapted if this script is moved somewhere else |
| 19 | 22 | |
| 20 | 23 | // remove the comment from one of the following lines to enable loging |
@@ -48,7 +48,10 @@ |
||
| 48 | 48 | exit; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | -if (empty($_GET['debug'])) $content = 'egw.set_images('.$content.", egw && egw.window !== window);\n"; |
|
| 51 | +if (empty($_GET['debug'])) |
|
| 52 | +{ |
|
| 53 | + $content = 'egw.set_images('.$content.", egw && egw.window !== window);\n"; |
|
| 54 | +} |
|
| 52 | 55 | |
| 53 | 56 | // we run our own gzip compression, to set a correct Content-Length of the encoded content |
| 54 | 57 | if (in_array('gzip', explode(',',$_SERVER['HTTP_ACCEPT_ENCODING'])) && function_exists('gzencode')) |