@@ -85,11 +85,17 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | function __construct() |
| 87 | 87 | { |
| 88 | - if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() started',True); |
|
| 88 | + if ($this->debug > 0) |
|
| 89 | + { |
|
| 90 | + $this->debug_message('calendar_boupdate::__construct() started',True); |
|
| 91 | + } |
|
| 89 | 92 | |
| 90 | 93 | parent::__construct(); // calling the parent constructor |
| 91 | 94 | |
| 92 | - if ($this->debug > 0) $this->debug_message('calendar_boupdate::__construct() finished',True); |
|
| 95 | + if ($this->debug > 0) |
|
| 96 | + { |
|
| 97 | + $this->debug_message('calendar_boupdate::__construct() finished',True); |
|
| 98 | + } |
|
| 93 | 99 | } |
| 94 | 100 | |
| 95 | 101 | /** |
@@ -120,7 +126,10 @@ discard block |
||
| 120 | 126 | { |
| 121 | 127 | unset($updateTS); // ignored, as updating timestamps is required for sync! |
| 122 | 128 | //error_log(__METHOD__."(".array2string($event).",$ignore_conflicts,$touch_modified,$ignore_acl)"); |
| 123 | - if (!is_array($messages)) $messages = $messages ? (array)$messages : array(); |
|
| 129 | + if (!is_array($messages)) |
|
| 130 | + { |
|
| 131 | + $messages = $messages ? (array)$messages : array(); |
|
| 132 | + } |
|
| 124 | 133 | |
| 125 | 134 | if ($this->debug > 1 || $this->debug == 'update') |
| 126 | 135 | { |
@@ -140,10 +149,13 @@ discard block |
||
| 140 | 149 | |
| 141 | 150 | $status_reset_to_unknown = false; |
| 142 | 151 | |
| 143 | - if (($new_event = !$event['id'])) // some defaults for new entries |
|
| 152 | + if (($new_event = !$event['id'])) |
|
| 153 | + { |
|
| 154 | + // some defaults for new entries |
|
| 144 | 155 | { |
| 145 | 156 | // if no owner given, set user to owner |
| 146 | 157 | if (!$event['owner']) $event['owner'] = $this->user; |
| 158 | + } |
|
| 147 | 159 | // set owner as participant if none is given |
| 148 | 160 | if (!is_array($event['participants']) || !count($event['participants'])) |
| 149 | 161 | { |
@@ -183,7 +195,10 @@ discard block |
||
| 183 | 195 | // check category based ACL |
| 184 | 196 | if ($event['category']) |
| 185 | 197 | { |
| 186 | - if (!is_array($event['category'])) $event['category'] = explode(',',$event['category']); |
|
| 198 | + if (!is_array($event['category'])) |
|
| 199 | + { |
|
| 200 | + $event['category'] = explode(',',$event['category']); |
|
| 201 | + } |
|
| 187 | 202 | if (!$old_event || !isset($old_event['category'])) |
| 188 | 203 | { |
| 189 | 204 | $old_event['category'] = array(); |
@@ -235,13 +250,16 @@ discard block |
||
| 235 | 250 | if (!$ignore_conflicts && !$event['non_blocking'] && isset($event['start']) && isset($event['end']) && |
| 236 | 251 | (($conflicts = $this->conflicts($event, $checked_excluding)) || $checked_excluding)) |
| 237 | 252 | { |
| 238 | - if ($checked_excluding) // warn user if not all recurrences have been checked |
|
| 253 | + if ($checked_excluding) |
|
| 254 | + { |
|
| 255 | + // warn user if not all recurrences have been checked |
|
| 239 | 256 | { |
| 240 | 257 | $conflicts['warning'] = array( |
| 241 | 258 | 'start' => $checked_excluding, |
| 242 | 259 | 'title' => lang('Only recurrences until %1 (excluding) have been checked!', $checked_excluding->format(true)), |
| 243 | 260 | ); |
| 244 | 261 | } |
| 262 | + } |
|
| 245 | 263 | return $conflicts; |
| 246 | 264 | } |
| 247 | 265 | |
@@ -305,7 +323,10 @@ discard block |
||
| 305 | 323 | $types_with_quantity = array(); |
| 306 | 324 | foreach($this->resources as $type => $data) |
| 307 | 325 | { |
| 308 | - if ($data['max_quantity']) $types_with_quantity[] = $type; |
|
| 326 | + if ($data['max_quantity']) |
|
| 327 | + { |
|
| 328 | + $types_with_quantity[] = $type; |
|
| 329 | + } |
|
| 309 | 330 | } |
| 310 | 331 | // get all NOT rejected participants and evtl. their quantity |
| 311 | 332 | $quantity = $users = array(); |
@@ -313,12 +334,19 @@ discard block |
||
| 313 | 334 | { |
| 314 | 335 | $q = $role = null; |
| 315 | 336 | calendar_so::split_status($status, $q, $role); |
| 316 | - if ($status == 'R' || $role == 'NON-PARTICIPANT') continue; // ignore rejected or non-participants |
|
| 337 | + if ($status == 'R' || $role == 'NON-PARTICIPANT') |
|
| 338 | + { |
|
| 339 | + continue; |
|
| 340 | + } |
|
| 341 | + // ignore rejected or non-participants |
|
| 317 | 342 | |
| 318 | - if ($uid < 0) // group, check it's members too |
|
| 343 | + if ($uid < 0) |
|
| 344 | + { |
|
| 345 | + // group, check it's members too |
|
| 319 | 346 | { |
| 320 | 347 | $users = array_unique(array_merge($users, (array)$GLOBALS['egw']->accounts->members($uid,true))); |
| 321 | 348 | } |
| 349 | + } |
|
| 322 | 350 | $users[] = $uid; |
| 323 | 351 | if (in_array($uid[0],$types_with_quantity)) |
| 324 | 352 | { |
@@ -349,18 +377,24 @@ discard block |
||
| 349 | 377 | $startts = $date->format('ts'); |
| 350 | 378 | |
| 351 | 379 | // skip past events or recurrences |
| 352 | - if ($startts+$duration < $this->now_su) continue; |
|
| 380 | + if ($startts+$duration < $this->now_su) |
|
| 381 | + { |
|
| 382 | + continue; |
|
| 383 | + } |
|
| 353 | 384 | |
| 354 | 385 | // abort check if configured limits are exceeded |
| 355 | 386 | if ($event['recur_type'] && |
| 356 | 387 | (++$checked > $max_checked && $max_checked > 0 || // maximum number of checked recurrences exceeded |
| 357 | 388 | microtime(true) > $start+$max_check_time || // max check time exceeded |
| 358 | - $startts > $this->config['horizont'])) // we are behind horizon for which recurrences are rendered |
|
| 389 | + $startts > $this->config['horizont'])) |
|
| 390 | + { |
|
| 391 | + // we are behind horizon for which recurrences are rendered |
|
| 359 | 392 | { |
| 360 | 393 | if ($this->debug > 2 || $this->debug == 'conflicts') |
| 361 | 394 | { |
| 362 | 395 | $this->debug_message(__METHOD__.'() conflict check limited to %1 recurrences, %2 seconds, until (excluding) %3', |
| 363 | 396 | $checked, microtime(true)-$start, $date); |
| 397 | + } |
|
| 364 | 398 | } |
| 365 | 399 | $checked_excluding = $date; |
| 366 | 400 | break; |
@@ -384,10 +418,13 @@ discard block |
||
| 384 | 418 | { |
| 385 | 419 | if ($overlap['id'] == $event['id'] || // that's the event itself |
| 386 | 420 | $overlap['id'] == $event['reference'] || // event is an exception of overlap |
| 387 | - $overlap['non_blocking']) // that's a non_blocking event |
|
| 421 | + $overlap['non_blocking']) |
|
| 422 | + { |
|
| 423 | + // that's a non_blocking event |
|
| 388 | 424 | { |
| 389 | 425 | continue; |
| 390 | 426 | } |
| 427 | + } |
|
| 391 | 428 | if ($this->debug > 3 || $this->debug == 'conflicts') |
| 392 | 429 | { |
| 393 | 430 | $this->debug_message(__METHOD__.'() checking overlapping event %1',false,$overlap); |
@@ -507,7 +544,11 @@ discard block |
||
| 507 | 544 | */ |
| 508 | 545 | public function check_acl_invite($uid) |
| 509 | 546 | { |
| 510 | - if (!is_numeric($uid)) return true; // nothing implemented for resources so far |
|
| 547 | + if (!is_numeric($uid)) |
|
| 548 | + { |
|
| 549 | + return true; |
|
| 550 | + } |
|
| 551 | + // nothing implemented for resources so far |
|
| 511 | 552 | |
| 512 | 553 | if (!$this->require_acl_invite) |
| 513 | 554 | { |
@@ -847,14 +888,20 @@ discard block |
||
| 847 | 888 | $startdate = new Api\DateTime($event['start']); |
| 848 | 889 | $enddate = new Api\DateTime($event['end']); |
| 849 | 890 | $modified = new Api\DateTime($event['modified']); |
| 850 | - if ($old_event) $olddate = new Api\DateTime($old_event['start']); |
|
| 891 | + if ($old_event) |
|
| 892 | + { |
|
| 893 | + $olddate = new Api\DateTime($old_event['start']); |
|
| 894 | + } |
|
| 851 | 895 | //error_log(__METHOD__."() date_default_timezone_get()=".date_default_timezone_get().", user-timezone=".Api\DateTime::$user_timezone->getName().", startdate=".$startdate->format().", enddate=".$enddate->format().", updated=".$modified->format().", olddate=".($olddate ? $olddate->format() : '')); |
| 852 | 896 | $owner_prefs = $ics = null; |
| 853 | 897 | foreach($to_notify as $userid => $statusid) |
| 854 | 898 | { |
| 855 | 899 | $res_info = $quantity = $role = null; |
| 856 | 900 | calendar_so::split_status($statusid, $quantity, $role); |
| 857 | - if ($this->debug > 0) error_log(__METHOD__." trying to notify $userid, with $statusid ($role)"); |
|
| 901 | + if ($this->debug > 0) |
|
| 902 | + { |
|
| 903 | + error_log(__METHOD__." trying to notify $userid, with $statusid ($role)"); |
|
| 904 | + } |
|
| 858 | 905 | |
| 859 | 906 | if (!is_numeric($userid)) |
| 860 | 907 | { |
@@ -873,7 +920,11 @@ discard block |
||
| 873 | 920 | |
| 874 | 921 | if (!isset($userid)) |
| 875 | 922 | { |
| 876 | - if (empty($res_info['email'])) continue; // no way to notify |
|
| 923 | + if (empty($res_info['email'])) |
|
| 924 | + { |
|
| 925 | + continue; |
|
| 926 | + } |
|
| 927 | + // no way to notify |
|
| 877 | 928 | // check if event-owner wants non-EGroupware users notified |
| 878 | 929 | if (is_null($owner_prefs)) |
| 879 | 930 | { |
@@ -947,7 +998,10 @@ discard block |
||
| 947 | 998 | $details['to-lastname'] = isset($tln)? $tln: ''; |
| 948 | 999 | |
| 949 | 1000 | // event is in user-time of current user, now we need to calculate the tz-difference to the notified user and take it into account |
| 950 | - if (!isset($part_prefs['common']['tz'])) $part_prefs['common']['tz'] = $GLOBALS['egw_info']['server']['server_timezone']; |
|
| 1001 | + if (!isset($part_prefs['common']['tz'])) |
|
| 1002 | + { |
|
| 1003 | + $part_prefs['common']['tz'] = $GLOBALS['egw_info']['server']['server_timezone']; |
|
| 1004 | + } |
|
| 951 | 1005 | $timezone = new DateTimeZone($part_prefs['common']['tz']); |
| 952 | 1006 | $timeformat = $part_prefs['common']['timeformat']; |
| 953 | 1007 | switch($timeformat) |
@@ -982,9 +1036,12 @@ discard block |
||
| 982 | 1036 | switch($msg_type == MSG_ALARM ? 'extended' : $part_prefs['calendar']['update_format']) |
| 983 | 1037 | { |
| 984 | 1038 | case 'ical': |
| 985 | - if (is_null($ics) || $m_type != $msg_type) // need different ical for organizer notification |
|
| 1039 | + if (is_null($ics) || $m_type != $msg_type) |
|
| 1040 | + { |
|
| 1041 | + // need different ical for organizer notification |
|
| 986 | 1042 | { |
| 987 | 1043 | $calendar_ical = new calendar_ical(); |
| 1044 | + } |
|
| 988 | 1045 | $calendar_ical->setSupportedFields('full'); // full iCal fields+event TZ |
| 989 | 1046 | // we need to pass $event[id] so iCal class reads event again, |
| 990 | 1047 | // as event is in user TZ, but iCal class expects server TZ! |
@@ -998,7 +1055,10 @@ discard block |
||
| 998 | 1055 | 'encoding' => '8bit', |
| 999 | 1056 | 'type' => 'text/calendar; method='.$method, |
| 1000 | 1057 | ); |
| 1001 | - if ($m_type != $msg_type) unset($ics); |
|
| 1058 | + if ($m_type != $msg_type) |
|
| 1059 | + { |
|
| 1060 | + unset($ics); |
|
| 1061 | + } |
|
| 1002 | 1062 | $subject = isset($cleared_event) ? $cleared_event['title'] : $event['title']; |
| 1003 | 1063 | // fall through |
| 1004 | 1064 | case 'extended': |
@@ -1049,7 +1109,9 @@ discard block |
||
| 1049 | 1109 | $notification->set_popupmessage($notify_body."\n\n".$details['description']."\n\n".$details_body); |
| 1050 | 1110 | $notification->set_popuplinks(array($details['link_arr'])); |
| 1051 | 1111 | |
| 1052 | - if(is_array($attachment)) { $notification->set_attachments(array($attachment)); } |
|
| 1112 | + if(is_array($attachment)) |
|
| 1113 | + { |
|
| 1114 | +$notification->set_attachments(array($attachment)); } |
|
| 1053 | 1115 | $notification->send(); |
| 1054 | 1116 | foreach(notifications::errors(true) as $error) |
| 1055 | 1117 | { |
@@ -1085,7 +1147,10 @@ discard block |
||
| 1085 | 1147 | Api\Translation::init(); |
| 1086 | 1148 | } |
| 1087 | 1149 | // restore timezone, in case we had to reset it to server-timezone |
| 1088 | - if ($restore_tz) date_default_timezone_set($restore_tz); |
|
| 1150 | + if ($restore_tz) |
|
| 1151 | + { |
|
| 1152 | + date_default_timezone_set($restore_tz); |
|
| 1153 | + } |
|
| 1089 | 1154 | |
| 1090 | 1155 | return true; |
| 1091 | 1156 | } |
@@ -1120,10 +1185,13 @@ discard block |
||
| 1120 | 1185 | { |
| 1121 | 1186 | $to_notify = $event['participants']; |
| 1122 | 1187 | } |
| 1123 | - elseif ($this->check_perms(Acl::READ,$event)) // checks agains $this->owner set to $alarm[owner] |
|
| 1188 | + elseif ($this->check_perms(Acl::READ,$event)) |
|
| 1189 | + { |
|
| 1190 | + // checks agains $this->owner set to $alarm[owner] |
|
| 1124 | 1191 | { |
| 1125 | 1192 | $to_notify[$alarm['owner']] = 'A'; |
| 1126 | 1193 | } |
| 1194 | + } |
|
| 1127 | 1195 | else |
| 1128 | 1196 | { |
| 1129 | 1197 | return False; // no rights |
@@ -1172,14 +1240,20 @@ discard block |
||
| 1172 | 1240 | if ($event['id']) |
| 1173 | 1241 | { |
| 1174 | 1242 | // invalidate the read-cache if it contains the event we store now |
| 1175 | - if ($event['id'] == self::$cached_event['id']) self::$cached_event = array(); |
|
| 1243 | + if ($event['id'] == self::$cached_event['id']) |
|
| 1244 | + { |
|
| 1245 | + self::$cached_event = array(); |
|
| 1246 | + } |
|
| 1176 | 1247 | $old_event = $this->read($event['id'], $event['recurrence'], false, 'server'); |
| 1177 | 1248 | } |
| 1178 | 1249 | else |
| 1179 | 1250 | { |
| 1180 | 1251 | $old_event = null; |
| 1181 | 1252 | } |
| 1182 | - if (!isset($event['whole_day'])) $event['whole_day'] = $this->isWholeDay($event); |
|
| 1253 | + if (!isset($event['whole_day'])) |
|
| 1254 | + { |
|
| 1255 | + $event['whole_day'] = $this->isWholeDay($event); |
|
| 1256 | + } |
|
| 1183 | 1257 | |
| 1184 | 1258 | // set recur-enddate/range-end to real end-date of last recurrence |
| 1185 | 1259 | if ($event['recur_type'] != MCAL_RECUR_NONE && $event['recur_enddate'] && $event['start']) |
@@ -1256,7 +1330,10 @@ discard block |
||
| 1256 | 1330 | foreach($timestamps as $ts) |
| 1257 | 1331 | { |
| 1258 | 1332 | // we convert here from user-time to timestamps in server-time! |
| 1259 | - if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2ts($event[$ts],true) : 0; |
|
| 1333 | + if (isset($event[$ts])) |
|
| 1334 | + { |
|
| 1335 | + $event[$ts] = $event[$ts] ? $this->date2ts($event[$ts],true) : 0; |
|
| 1336 | + } |
|
| 1260 | 1337 | } |
| 1261 | 1338 | // convert tzid name to integer tz_id, of set user default |
| 1262 | 1339 | if (empty($event['tzid']) || !($event['tz_id'] = calendar_timezones::tz2id($event['tzid']))) |
@@ -1306,7 +1383,10 @@ discard block |
||
| 1306 | 1383 | if (!isset($event['alarm'][$id])) |
| 1307 | 1384 | { |
| 1308 | 1385 | $alarm['time'] = $event['start'] - $alarm['offset']; |
| 1309 | - if ($alarm['time'] < time()) calendar_so::shift_alarm($event, $alarm); |
|
| 1386 | + if ($alarm['time'] < time()) |
|
| 1387 | + { |
|
| 1388 | + calendar_so::shift_alarm($event, $alarm); |
|
| 1389 | + } |
|
| 1310 | 1390 | // remove (not store) alarms belonging to not longer existing or rejected participants |
| 1311 | 1391 | $status = isset($event['participants']) ? $event['participants'][$alarm['owner']] : |
| 1312 | 1392 | $old_event['participants'][$alarm['owner']]; |
@@ -1362,7 +1442,10 @@ discard block |
||
| 1362 | 1442 | |
| 1363 | 1443 | // Update history |
| 1364 | 1444 | $tracking = new calendar_tracking($this); |
| 1365 | - if (empty($event['id']) && !empty($cal_id)) $event['id']=$cal_id; |
|
| 1445 | + if (empty($event['id']) && !empty($cal_id)) |
|
| 1446 | + { |
|
| 1447 | + $event['id']=$cal_id; |
|
| 1448 | + } |
|
| 1366 | 1449 | $tracking->track($event, $old_event); |
| 1367 | 1450 | |
| 1368 | 1451 | return $cal_id; |
@@ -1379,9 +1462,12 @@ discard block |
||
| 1379 | 1462 | */ |
| 1380 | 1463 | function check_status_perms($uid,$event) |
| 1381 | 1464 | { |
| 1382 | - if ($uid[0] == 'c' || $uid[0] == 'e') // for contact we use the owner of the event |
|
| 1465 | + if ($uid[0] == 'c' || $uid[0] == 'e') |
|
| 1466 | + { |
|
| 1467 | + // for contact we use the owner of the event |
|
| 1383 | 1468 | { |
| 1384 | 1469 | if (!is_array($event) && !($event = $this->read($event))) return false; |
| 1470 | + } |
|
| 1385 | 1471 | |
| 1386 | 1472 | return $this->check_perms(Acl::EDIT,0,$event['owner']); |
| 1387 | 1473 | } |
@@ -1392,13 +1478,19 @@ discard block |
||
| 1392 | 1478 | return $access; |
| 1393 | 1479 | } |
| 1394 | 1480 | // no access or denied access because of category acl --> regular check |
| 1395 | - if (!is_numeric($uid)) // this is eg. for resources (r123) |
|
| 1481 | + if (!is_numeric($uid)) |
|
| 1482 | + { |
|
| 1483 | + // this is eg. for resources (r123) |
|
| 1396 | 1484 | { |
| 1397 | 1485 | $resource = $this->resource_info($uid); |
| 1486 | + } |
|
| 1398 | 1487 | |
| 1399 | 1488 | return Acl::EDIT & $resource['rights']; |
| 1400 | 1489 | } |
| 1401 | - if (!is_array($event) && !($event = $this->read($event))) return false; |
|
| 1490 | + if (!is_array($event) && !($event = $this->read($event))) |
|
| 1491 | + { |
|
| 1492 | + return false; |
|
| 1493 | + } |
|
| 1402 | 1494 | |
| 1403 | 1495 | // regular user and groups (need to check memberships too) |
| 1404 | 1496 | if (!isset($event['participants'][$uid])) |
@@ -1422,7 +1514,10 @@ discard block |
||
| 1422 | 1514 | */ |
| 1423 | 1515 | function check_cat_acl($right,$event) |
| 1424 | 1516 | { |
| 1425 | - if (!is_array($event)) $event = $this->read($event); |
|
| 1517 | + if (!is_array($event)) |
|
| 1518 | + { |
|
| 1519 | + $event = $this->read($event); |
|
| 1520 | + } |
|
| 1426 | 1521 | |
| 1427 | 1522 | $ret = null; |
| 1428 | 1523 | if ($event['category']) |
@@ -1479,7 +1574,10 @@ discard block |
||
| 1479 | 1574 | public static function set_cat_rights($cat_id,$user,$rights) |
| 1480 | 1575 | { |
| 1481 | 1576 | //echo "<p>".__METHOD__."($cat_id,$user,$rights)</p>\n"; |
| 1482 | - if (!isset(self::$cat_rights_cache)) self::get_cat_rights($cat_id); |
|
| 1577 | + if (!isset(self::$cat_rights_cache)) |
|
| 1578 | + { |
|
| 1579 | + self::get_cat_rights($cat_id); |
|
| 1580 | + } |
|
| 1483 | 1581 | |
| 1484 | 1582 | if ((int)$rights != (int)self::$cat_rights_cache['L'.$cat_id][$user]) |
| 1485 | 1583 | { |
@@ -1491,7 +1589,10 @@ discard block |
||
| 1491 | 1589 | else |
| 1492 | 1590 | { |
| 1493 | 1591 | unset(self::$cat_rights_cache['L'.$cat_id][$user]); |
| 1494 | - if (!self::$cat_rights_cache['L'.$cat_id]) unset(self::$cat_rights_cache['L'.$cat_id]); |
|
| 1592 | + if (!self::$cat_rights_cache['L'.$cat_id]) |
|
| 1593 | + { |
|
| 1594 | + unset(self::$cat_rights_cache['L'.$cat_id]); |
|
| 1595 | + } |
|
| 1495 | 1596 | $GLOBALS['egw']->acl->delete_repository('calendar','L'.$cat_id,$user); |
| 1496 | 1597 | } |
| 1497 | 1598 | Api\Cache::setSession('calendar','cat_rights',self::$cat_rights_cache); |
@@ -1524,7 +1625,10 @@ discard block |
||
| 1524 | 1625 | foreach($cat_rights as $uid => $value) |
| 1525 | 1626 | { |
| 1526 | 1627 | $all |= $value; |
| 1527 | - if (in_array($uid,$memberships)) $own |= $value; |
|
| 1628 | + if (in_array($uid,$memberships)) |
|
| 1629 | + { |
|
| 1630 | + $own |= $value; |
|
| 1631 | + } |
|
| 1528 | 1632 | } |
| 1529 | 1633 | } |
| 1530 | 1634 | foreach(array(self::CAT_ACL_ADD,self::CAT_ACL_STATUS) as $mask) |
@@ -1571,13 +1675,16 @@ discard block |
||
| 1571 | 1675 | is_numeric($uid)?$uid:substr($uid,1),$status, |
| 1572 | 1676 | $recur_date?$this->date2ts($recur_date,true):0,$role))) |
| 1573 | 1677 | { |
| 1574 | - if ($status == 'R') // remove alarms belonging to rejected participants |
|
| 1678 | + if ($status == 'R') |
|
| 1679 | + { |
|
| 1680 | + // remove alarms belonging to rejected participants |
|
| 1575 | 1681 | { |
| 1576 | 1682 | foreach(is_array($event) && isset($event['alarm']) ? $event['alarm'] : $old_event['alarm'] as $id => $alarm) |
| 1577 | 1683 | { |
| 1578 | 1684 | if ((string)$alarm['owner'] === (string)$uid) |
| 1579 | 1685 | { |
| 1580 | 1686 | $this->so->delete_alarm($id); |
| 1687 | + } |
|
| 1581 | 1688 | //error_log(__LINE__.': '.__METHOD__."(".array2string($event).", '$uid', '$status', ...) deleting alarm=".array2string($alarm).", $status=".array2string($alarm)); |
| 1582 | 1689 | } |
| 1583 | 1690 | } |
@@ -1594,8 +1701,15 @@ discard block |
||
| 1594 | 1701 | |
| 1595 | 1702 | if (isset($status2msg[$status]) && !$skip_notification) |
| 1596 | 1703 | { |
| 1597 | - if (!is_array($event)) $event = $this->read($cal_id); |
|
| 1598 | - if (isset($recur_date)) $event = $this->read($event['id'],$recur_date); //re-read the actually edited recurring event |
|
| 1704 | + if (!is_array($event)) |
|
| 1705 | + { |
|
| 1706 | + $event = $this->read($cal_id); |
|
| 1707 | + } |
|
| 1708 | + if (isset($recur_date)) |
|
| 1709 | + { |
|
| 1710 | + $event = $this->read($event['id'],$recur_date); |
|
| 1711 | + } |
|
| 1712 | + //re-read the actually edited recurring event |
|
| 1599 | 1713 | $this->send_update($status2msg[$status],$event['participants'],$event); |
| 1600 | 1714 | } |
| 1601 | 1715 | |
@@ -1618,12 +1732,16 @@ discard block |
||
| 1618 | 1732 | */ |
| 1619 | 1733 | function update_status($new_event, $old_event , $recur_date=0, $skip_notification=false) |
| 1620 | 1734 | { |
| 1621 | - if (!isset($new_event['participants'])) return; |
|
| 1735 | + if (!isset($new_event['participants'])) |
|
| 1736 | + { |
|
| 1737 | + return; |
|
| 1738 | + } |
|
| 1622 | 1739 | |
| 1623 | 1740 | // check the old list against the new list |
| 1624 | 1741 | foreach ($old_event['participants'] as $userid => $status) |
| 1625 | - { |
|
| 1626 | - if (!isset($new_event['participants'][$userid])){ |
|
| 1742 | + { |
|
| 1743 | + if (!isset($new_event['participants'][$userid])) |
|
| 1744 | + { |
|
| 1627 | 1745 | // Attendee will be deleted this way |
| 1628 | 1746 | $new_event['participants'][$userid] = 'G'; |
| 1629 | 1747 | } |
@@ -1706,7 +1824,10 @@ discard block |
||
| 1706 | 1824 | } |
| 1707 | 1825 | else |
| 1708 | 1826 | { |
| 1709 | - if (!($exception = $this->read($id))) continue; |
|
| 1827 | + if (!($exception = $this->read($id))) |
|
| 1828 | + { |
|
| 1829 | + continue; |
|
| 1830 | + } |
|
| 1710 | 1831 | $exception['uid'] = Api\CalDAV::generate_uid('calendar', $id); |
| 1711 | 1832 | $exception['reference'] = $exception['recurrence'] = 0; |
| 1712 | 1833 | $this->update($exception, true, true, false, true, $msg=null, true); |
@@ -1777,7 +1898,10 @@ discard block |
||
| 1777 | 1898 | $event_arr = $this->event2array($event); |
| 1778 | 1899 | foreach($event_arr as $key => $val) |
| 1779 | 1900 | { |
| 1780 | - if ($key == 'recur_type') $key = 'repetition'; |
|
| 1901 | + if ($key == 'recur_type') |
|
| 1902 | + { |
|
| 1903 | + $key = 'repetition'; |
|
| 1904 | + } |
|
| 1781 | 1905 | $details[$key] = $val['data']; |
| 1782 | 1906 | } |
| 1783 | 1907 | $details['participants'] = $details['participants'] ? implode("\n",$details['participants']) : ''; |
@@ -1950,7 +2074,10 @@ discard block |
||
| 1950 | 2074 | */ |
| 1951 | 2075 | function check_move_alarms(Array &$event, Array $old_event = null, Api\DateTime $instance_date = null) |
| 1952 | 2076 | { |
| 1953 | - if ($old_event !== null && $event['start'] == $old_event['start']) return; |
|
| 2077 | + if ($old_event !== null && $event['start'] == $old_event['start']) |
|
| 2078 | + { |
|
| 2079 | + return; |
|
| 2080 | + } |
|
| 1954 | 2081 | |
| 1955 | 2082 | $time = new Api\DateTime($event['start']); |
| 1956 | 2083 | if(!is_array($event['alarm'])) |
@@ -2024,7 +2151,10 @@ discard block |
||
| 2024 | 2151 | if (is_array($old_event) || $old_event > 0) |
| 2025 | 2152 | { |
| 2026 | 2153 | // preserve categories without users read access |
| 2027 | - if (!is_array($old_event)) $old_event = $this->read($old_event); |
|
| 2154 | + if (!is_array($old_event)) |
|
| 2155 | + { |
|
| 2156 | + $old_event = $this->read($old_event); |
|
| 2157 | + } |
|
| 2028 | 2158 | $old_categories = explode(',',$old_event['category']); |
| 2029 | 2159 | $old_cats_preserve = array(); |
| 2030 | 2160 | if (is_array($old_categories) && count($old_categories) > 0) |
@@ -2115,7 +2245,10 @@ discard block |
||
| 2115 | 2245 | "($filter)[EVENT]:" . array2string($event)."\n",3,$this->logfile); |
| 2116 | 2246 | } |
| 2117 | 2247 | |
| 2118 | - if (!isset($event['recurrence'])) $event['recurrence'] = 0; |
|
| 2248 | + if (!isset($event['recurrence'])) |
|
| 2249 | + { |
|
| 2250 | + $event['recurrence'] = 0; |
|
| 2251 | + } |
|
| 2119 | 2252 | |
| 2120 | 2253 | if ($filter == 'master') |
| 2121 | 2254 | { |
@@ -2169,19 +2302,26 @@ discard block |
||
| 2169 | 2302 | $matchingEvents[] = $egwEvent['id'] . ':' . (int)$event['recurrence']; |
| 2170 | 2303 | } |
| 2171 | 2304 | } |
| 2172 | - } elseif ($filter != 'master' && ($filter == 'exact' || |
|
| 2305 | + } |
|
| 2306 | + elseif ($filter != 'master' && ($filter == 'exact' || |
|
| 2173 | 2307 | $event['recur_type'] == $egwEvent['recur_type'] && |
| 2174 | 2308 | strpos($egwEvent['title'], $event['title']) === 0)) |
| 2175 | 2309 | { |
| 2176 | 2310 | $matchingEvents[] = $egwEvent['id']; // we found the event |
| 2177 | 2311 | } |
| 2178 | 2312 | } |
| 2179 | - if (!empty($matchingEvents) || $filter == 'exact') return $matchingEvents; |
|
| 2313 | + if (!empty($matchingEvents) || $filter == 'exact') |
|
| 2314 | + { |
|
| 2315 | + return $matchingEvents; |
|
| 2316 | + } |
|
| 2180 | 2317 | } |
| 2181 | 2318 | unset($event['id']); |
| 2182 | 2319 | |
| 2183 | 2320 | // No chance to find a master without [U]ID |
| 2184 | - if ($filter == 'master' && empty($event['uid'])) return $matchingEvents; |
|
| 2321 | + if ($filter == 'master' && empty($event['uid'])) |
|
| 2322 | + { |
|
| 2323 | + return $matchingEvents; |
|
| 2324 | + } |
|
| 2185 | 2325 | |
| 2186 | 2326 | // only query calendars of users, we have READ-grants from |
| 2187 | 2327 | $users = array(); |
@@ -2190,17 +2330,23 @@ discard block |
||
| 2190 | 2330 | $user = trim($user); |
| 2191 | 2331 | if ($this->check_perms(Acl::READ|self::ACL_READ_FOR_PARTICIPANTS|self::ACL_FREEBUSY,0,$user)) |
| 2192 | 2332 | { |
| 2193 | - if ($user && !in_array($user,$users)) // already added? |
|
| 2333 | + if ($user && !in_array($user,$users)) |
|
| 2334 | + { |
|
| 2335 | + // already added? |
|
| 2194 | 2336 | { |
| 2195 | 2337 | $users[] = $user; |
| 2196 | 2338 | } |
| 2339 | + } |
|
| 2197 | 2340 | } |
| 2198 | 2341 | elseif ($GLOBALS['egw']->accounts->get_type($user) != 'g') |
| 2199 | 2342 | { |
| 2200 | 2343 | continue; // for non-groups (eg. users), we stop here if we have no read-rights |
| 2201 | 2344 | } |
| 2202 | 2345 | // the further code is only for real users |
| 2203 | - if (!is_numeric($user)) continue; |
|
| 2346 | + if (!is_numeric($user)) |
|
| 2347 | + { |
|
| 2348 | + continue; |
|
| 2349 | + } |
|
| 2204 | 2350 | |
| 2205 | 2351 | // for groups we have to include the members |
| 2206 | 2352 | if ($GLOBALS['egw']->accounts->get_type($user) == 'g') |
@@ -2280,7 +2426,10 @@ discard block |
||
| 2280 | 2426 | } |
| 2281 | 2427 | foreach ($matchFields as $key) |
| 2282 | 2428 | { |
| 2283 | - if (isset($event[$key])) $query['cal_'.$key] = $event[$key]; |
|
| 2429 | + if (isset($event[$key])) |
|
| 2430 | + { |
|
| 2431 | + $query['cal_'.$key] = $event[$key]; |
|
| 2432 | + } |
|
| 2284 | 2433 | } |
| 2285 | 2434 | } |
| 2286 | 2435 | |
@@ -2320,7 +2469,10 @@ discard block |
||
| 2320 | 2469 | '[FOUND]: ' . array2string($egwEvent)."\n",3,$this->logfile); |
| 2321 | 2470 | } |
| 2322 | 2471 | |
| 2323 | - if (in_array($egwEvent['id'], $matchingEvents)) continue; |
|
| 2472 | + if (in_array($egwEvent['id'], $matchingEvents)) |
|
| 2473 | + { |
|
| 2474 | + continue; |
|
| 2475 | + } |
|
| 2324 | 2476 | |
| 2325 | 2477 | // convert timezone id of event to tzid (iCal id like 'Europe/Berlin') |
| 2326 | 2478 | if (!$egwEvent['tz_id'] || !($egwEvent['tzid'] = calendar_timezones::id2tz($egwEvent['tz_id']))) |
@@ -2487,13 +2639,16 @@ discard block |
||
| 2487 | 2639 | foreach ($event['participants'] as $attendee => $status) |
| 2488 | 2640 | { |
| 2489 | 2641 | if (!isset($egwEvent['participants'][$attendee]) && |
| 2490 | - $attendee != $egwEvent['owner']) // || |
|
| 2642 | + $attendee != $egwEvent['owner']) |
|
| 2643 | + { |
|
| 2644 | + // || |
|
| 2491 | 2645 | //(!$relax && $egw_event['participants'][$attendee] != $status)) |
| 2492 | 2646 | { |
| 2493 | 2647 | if ($this->log) |
| 2494 | 2648 | { |
| 2495 | 2649 | error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. |
| 2496 | 2650 | "() additional event['participants']: $attendee\n",3,$this->logfile); |
| 2651 | + } |
|
| 2497 | 2652 | } |
| 2498 | 2653 | continue 2; |
| 2499 | 2654 | } |
@@ -2815,7 +2970,10 @@ discard block |
||
| 2815 | 2970 | foreach(array('start','end','recur_enddate','recurrence') as $ts) |
| 2816 | 2971 | { |
| 2817 | 2972 | // we convert here from server-time to timestamps in user-time! |
| 2818 | - if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2usertime($event[$ts]) : 0; |
|
| 2973 | + if (isset($event[$ts])) |
|
| 2974 | + { |
|
| 2975 | + $event[$ts] = $event[$ts] ? $this->date2usertime($event[$ts]) : 0; |
|
| 2976 | + } |
|
| 2819 | 2977 | } |
| 2820 | 2978 | // same with the recur exceptions |
| 2821 | 2979 | if (isset($event['recur_exception']) && is_array($event['recur_exception'])) |
@@ -2843,9 +3001,12 @@ discard block |
||
| 2843 | 3001 | */ |
| 2844 | 3002 | function purge($age) |
| 2845 | 3003 | { |
| 2846 | - if (is_numeric($age) && $age > 0) // just make sure bogus values dont delete everything |
|
| 3004 | + if (is_numeric($age) && $age > 0) |
|
| 3005 | + { |
|
| 3006 | + // just make sure bogus values dont delete everything |
|
| 2847 | 3007 | { |
| 2848 | 3008 | $this->so->purge(time() - 365*24*3600*(float)$age); |
| 2849 | 3009 | } |
| 3010 | + } |
|
| 2850 | 3011 | } |
| 2851 | 3012 | } |
@@ -83,10 +83,10 @@ discard block |
||
| 83 | 83 | * @param string $_resource resource containing data. May be each valid php-stream |
| 84 | 84 | * @param array $_options options for the resource array with keys: charset and fieldsep |
| 85 | 85 | */ |
| 86 | - public function __construct( $_resource, array $_options ) { |
|
| 86 | + public function __construct($_resource, array $_options) { |
|
| 87 | 87 | $this->resource = $_resource; |
| 88 | 88 | $this->csv_fieldsep = $_options['fieldsep']; |
| 89 | - if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
| 89 | + if ($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
| 90 | 90 | $this->csv_charset = $_options['charset']; |
| 91 | 91 | return; |
| 92 | 92 | } // end of member function __construct |
@@ -103,20 +103,20 @@ discard block |
||
| 103 | 103 | * @param mixed _position may be: {current|first|last|next|previous|somenumber} |
| 104 | 104 | * @return mixed array with data / false if no furtor records |
| 105 | 105 | */ |
| 106 | - public function get_record( $_position = 'next' ) { |
|
| 106 | + public function get_record($_position = 'next') { |
|
| 107 | 107 | |
| 108 | - if ($this->get_raw_record( $_position ) === false) { |
|
| 108 | + if ($this->get_raw_record($_position) === false) { |
|
| 109 | 109 | return false; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // skip empty records |
| 113 | - if( count( array_unique( $this->record ) ) < 2 ) return $this->get_record( $_position ); |
|
| 113 | + if (count(array_unique($this->record)) < 2) return $this->get_record($_position); |
|
| 114 | 114 | |
| 115 | - if ( !empty( $this->conversion ) ) { |
|
| 115 | + if (!empty($this->conversion)) { |
|
| 116 | 116 | $this->do_conversions(); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if ( !empty( $this->mapping ) ) { |
|
| 119 | + if (!empty($this->mapping)) { |
|
| 120 | 120 | $this->do_fieldmapping(); |
| 121 | 121 | } |
| 122 | 122 | |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @param int $_numToSkip |
| 130 | 130 | */ |
| 131 | - public function skip_records( $_numToSkip ) { |
|
| 132 | - while ( (int)$_numToSkip-- !== 0 ) { |
|
| 133 | - fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep); |
|
| 131 | + public function skip_records($_numToSkip) { |
|
| 132 | + while ((int)$_numToSkip-- !== 0) { |
|
| 133 | + fgetcsv($this->resource, self::csv_max_linelength, $this->csv_fieldsep); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @param mixed $_position |
| 141 | 141 | * @return bool |
| 142 | 142 | */ |
| 143 | - private function get_raw_record( $_position = 'next' ) { |
|
| 143 | + private function get_raw_record($_position = 'next') { |
|
| 144 | 144 | switch ($_position) { |
| 145 | 145 | case 'current' : |
| 146 | 146 | if ($this->current_position == 0) { |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | case 'next' : |
| 157 | - $csv_data = fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep); |
|
| 157 | + $csv_data = fgetcsv($this->resource, self::csv_max_linelength, $this->csv_fieldsep); |
|
| 158 | 158 | if (!is_array($csv_data)) { |
| 159 | 159 | return false; |
| 160 | 160 | } |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $this->record = array(); |
| 236 | 236 | foreach ($this->mapping as $cvs_idx => $new_idx) |
| 237 | 237 | { |
| 238 | - if( $new_idx == '' ) continue; |
|
| 238 | + if ($new_idx == '') continue; |
|
| 239 | 239 | $this->record[$new_idx] = $record[$cvs_idx]; |
| 240 | 240 | } |
| 241 | 241 | return true; |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | * @return bool |
| 248 | 248 | */ |
| 249 | 249 | protected function do_conversions() { |
| 250 | - if ( $record = importexport_helper_functions::conversion( $this->record, $this->conversion, $this->conversion_class )) { |
|
| 250 | + if ($record = importexport_helper_functions::conversion($this->record, $this->conversion, $this->conversion_class)) { |
|
| 251 | 251 | $this->record = $record; |
| 252 | 252 | return; |
| 253 | 253 | } |
@@ -264,25 +264,25 @@ discard block |
||
| 264 | 264 | * |
| 265 | 265 | * @return string warnings, if any |
| 266 | 266 | */ |
| 267 | - public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0) { |
|
| 267 | + public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format = 0) { |
|
| 268 | 268 | $warnings = array(); |
| 269 | 269 | |
| 270 | 270 | // Automatic conversions |
| 271 | - if($appname) { |
|
| 271 | + if ($appname) { |
|
| 272 | 272 | |
| 273 | 273 | // Load translations |
| 274 | 274 | Api\Translation::add_app($appname); |
| 275 | 275 | |
| 276 | - if(!self::$cf_parse_cache[$appname]) { |
|
| 276 | + if (!self::$cf_parse_cache[$appname]) { |
|
| 277 | 277 | $c_fields = importexport_export_csv::convert_parse_custom_fields($appname, $selects, $links, $methods); |
| 278 | 278 | self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods); |
| 279 | 279 | } |
| 280 | 280 | list($c_fields, $c_selects, $links, $methods) = self::$cf_parse_cache[$appname]; |
| 281 | 281 | |
| 282 | 282 | // Add in any fields that are keys to another app |
| 283 | - foreach((array)$fields['links'] as $link_field => $app) |
|
| 283 | + foreach ((array)$fields['links'] as $link_field => $app) |
|
| 284 | 284 | { |
| 285 | - if(is_numeric($link_field)) continue; |
|
| 285 | + if (is_numeric($link_field)) continue; |
|
| 286 | 286 | $links[$link_field] = $app; |
| 287 | 287 | // Set it as a normal link field |
| 288 | 288 | $fields['links'][] = $link_field; |
@@ -290,9 +290,9 @@ discard block |
||
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // Not quite a recursive merge, since only one level |
| 293 | - foreach($fields as $type => &$list) |
|
| 293 | + foreach ($fields as $type => &$list) |
|
| 294 | 294 | { |
| 295 | - if($c_fields[$type]) { |
|
| 295 | + if ($c_fields[$type]) { |
|
| 296 | 296 | $list = array_merge($c_fields[$type], $list); |
| 297 | 297 | unset($c_fields[$type]); |
| 298 | 298 | } |
@@ -300,26 +300,26 @@ discard block |
||
| 300 | 300 | $fields += $c_fields; |
| 301 | 301 | $selects += $c_selects; |
| 302 | 302 | } |
| 303 | - if($fields) { |
|
| 304 | - foreach((array)$fields['select'] as $name) { |
|
| 303 | + if ($fields) { |
|
| 304 | + foreach ((array)$fields['select'] as $name) { |
|
| 305 | 305 | $record[$name] = static::find_select_key($record[$name], $selects[$name]); |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - foreach((array)$fields['links'] as $name) { |
|
| 309 | - if($record[$name] && $links[$name]) |
|
| 308 | + foreach ((array)$fields['links'] as $name) { |
|
| 309 | + if ($record[$name] && $links[$name]) |
|
| 310 | 310 | { |
| 311 | 311 | // Primary key to another app, not a link |
| 312 | 312 | // Text - search for a matching record |
| 313 | - if(!is_numeric($record[$name])) |
|
| 313 | + if (!is_numeric($record[$name])) |
|
| 314 | 314 | { |
| 315 | 315 | $results = Link::query($links[$name], $record[$name]); |
| 316 | - if(count($results) >= 1) |
|
| 316 | + if (count($results) >= 1) |
|
| 317 | 317 | { |
| 318 | 318 | // More than 1 result. Check for exact match |
| 319 | 319 | $exact_count = 0; |
| 320 | - foreach($results as $id => $title) |
|
| 320 | + foreach ($results as $id => $title) |
|
| 321 | 321 | { |
| 322 | - if($title == $record[$name]) |
|
| 322 | + if ($title == $record[$name]) |
|
| 323 | 323 | { |
| 324 | 324 | $exact_count++; |
| 325 | 325 | $app_id = $id; |
@@ -328,11 +328,11 @@ discard block |
||
| 328 | 328 | unset($results[$id]); |
| 329 | 329 | } |
| 330 | 330 | // Too many exact matches, or none good enough |
| 331 | - if($exact_count > 1 || count($results) == 0) |
|
| 331 | + if ($exact_count > 1 || count($results) == 0) |
|
| 332 | 332 | { |
| 333 | 333 | $warnings[] = lang('Unable to link to %1 "%2"', |
| 334 | 334 | lang($links[$name]), $record[$name]). |
| 335 | - ' - ' .lang('too many matches'); |
|
| 335 | + ' - '.lang('too many matches'); |
|
| 336 | 336 | continue; |
| 337 | 337 | } |
| 338 | 338 | elseif ($exact_count == 1) |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | { |
| 346 | 346 | $warnings[] = lang('Unable to link to %1 "%2"', |
| 347 | 347 | lang($links[$name]), $record[$name]). |
| 348 | - ' - ' . lang('no matches'); |
|
| 348 | + ' - '.lang('no matches'); |
|
| 349 | 349 | continue; |
| 350 | 350 | } else { |
| 351 | 351 | $record[$name] = key($results); |
@@ -353,17 +353,17 @@ discard block |
||
| 353 | 353 | } |
| 354 | 354 | } |
| 355 | 355 | } |
| 356 | - foreach((array)$fields['select-account'] as $name) { |
|
| 356 | + foreach ((array)$fields['select-account'] as $name) { |
|
| 357 | 357 | // Compare against null to deal with empty arrays |
| 358 | 358 | if ($record[$name]) { |
| 359 | 359 | // Automatically handle text owner without explicit translation |
| 360 | 360 | $new_owner = importexport_helper_functions::account_name2id($record[$name]); |
| 361 | - if(count($new_owner) != count(explode(',',$record[$name]))) |
|
| 361 | + if (count($new_owner) != count(explode(',', $record[$name]))) |
|
| 362 | 362 | { |
| 363 | 363 | // Unable to parse value into account |
| 364 | - $warnings[] = $name . ': ' .lang('%1 is not a known user or group', $record[$name]); |
|
| 364 | + $warnings[] = $name.': '.lang('%1 is not a known user or group', $record[$name]); |
|
| 365 | 365 | } |
| 366 | - if($new_owner != '') { |
|
| 366 | + if ($new_owner != '') { |
|
| 367 | 367 | $record[$name] = $new_owner; |
| 368 | 368 | } else { |
| 369 | 369 | // Clear it to prevent trouble later on |
@@ -371,24 +371,24 @@ discard block |
||
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | - foreach((array)$fields['select-bool'] as $name) { |
|
| 375 | - if($record[$name] != null && $record[$name] != '') { |
|
| 374 | + foreach ((array)$fields['select-bool'] as $name) { |
|
| 375 | + if ($record[$name] != null && $record[$name] != '') { |
|
| 376 | 376 | $record[$name] = ($record[$name] == lang('Yes') || $record[$name] == '1' ? 1 : 0); |
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | - foreach((array)$fields['date-time'] as $name) { |
|
| 379 | + foreach ((array)$fields['date-time'] as $name) { |
|
| 380 | 380 | if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0) |
| 381 | 381 | { |
| 382 | 382 | // Need to handle format first |
| 383 | - if($format == 1) |
|
| 383 | + if ($format == 1) |
|
| 384 | 384 | { |
| 385 | 385 | $formatted = Api\DateTime::createFromFormat( |
| 386 | - '!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat, |
|
| 386 | + '!'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat, |
|
| 387 | 387 | $record[$name], |
| 388 | 388 | Api\DateTime::$user_timezone |
| 389 | 389 | ); |
| 390 | 390 | |
| 391 | - if(!$formatted && $errors = Api\DateTime::getLastErrors()) |
|
| 391 | + if (!$formatted && $errors = Api\DateTime::getLastErrors()) |
|
| 392 | 392 | { |
| 393 | 393 | // Try again, without time |
| 394 | 394 | $formatted = Api\DateTime::createFromFormat( |
@@ -397,70 +397,70 @@ discard block |
||
| 397 | 397 | Api\DateTime::$user_timezone |
| 398 | 398 | ); |
| 399 | 399 | |
| 400 | - if(!$formatted && $errors = Api\DateTime::getLastErrors()) |
|
| 400 | + if (!$formatted && $errors = Api\DateTime::getLastErrors()) |
|
| 401 | 401 | { |
| 402 | 402 | // Try again, anything goes |
| 403 | 403 | try { |
| 404 | 404 | $formatted = new Api\DateTime($record[$name]); |
| 405 | 405 | } catch (Exception $e) { |
| 406 | - $warnings[] = $name.': ' . $e->getMessage() . "\n" . |
|
| 407 | - 'Format: '.'!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat; |
|
| 406 | + $warnings[] = $name.': '.$e->getMessage()."\n". |
|
| 407 | + 'Format: '.'!'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat; |
|
| 408 | 408 | continue; |
| 409 | 409 | } |
| 410 | 410 | $errors = Api\DateTime::getLastErrors(); |
| 411 | - foreach($errors['errors'] as $char => $msg) |
|
| 411 | + foreach ($errors['errors'] as $char => $msg) |
|
| 412 | 412 | { |
| 413 | 413 | $warnings[] = "$name: [$char] $msg\n". |
| 414 | - 'Format: '.'!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat; |
|
| 414 | + 'Format: '.'!'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat; |
|
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | - if($formatted) |
|
| 418 | + if ($formatted) |
|
| 419 | 419 | { |
| 420 | 420 | $record[$name] = $formatted->getTimestamp(); |
| 421 | 421 | // Timestamp is apparently in server time, but apps will do the same conversion |
| 422 | - $record[$name] = Api\DateTime::server2user($record[$name],'ts'); |
|
| 422 | + $record[$name] = Api\DateTime::server2user($record[$name], 'ts'); |
|
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - if(is_array(self::$cf_parse_cache[$appname][0]['date-time']) && |
|
| 426 | + if (is_array(self::$cf_parse_cache[$appname][0]['date-time']) && |
|
| 427 | 427 | in_array($name, self::$cf_parse_cache[$appname][0]['date-time'])) { |
| 428 | 428 | // Custom fields stored in a particular format (from customfields_widget) |
| 429 | 429 | $record[$name] = date('Y-m-d H:i:s', $record[$name]); |
| 430 | 430 | } |
| 431 | 431 | } |
| 432 | - if(array_key_exists($name, $record) && strlen(trim($record[$name])) == 0) |
|
| 432 | + if (array_key_exists($name, $record) && strlen(trim($record[$name])) == 0) |
|
| 433 | 433 | { |
| 434 | 434 | $record[$name] = null; |
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | - foreach((array)$fields['date'] as $name) { |
|
| 437 | + foreach ((array)$fields['date'] as $name) { |
|
| 438 | 438 | if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0) |
| 439 | 439 | { |
| 440 | 440 | // Need to handle format first |
| 441 | - if($format == 1) |
|
| 441 | + if ($format == 1) |
|
| 442 | 442 | { |
| 443 | 443 | $formatted = Api\DateTime::createFromFormat('!'.Api\DateTime::$user_dateformat, $record[$name]); |
| 444 | - if($formatted && $errors = Api\DateTime::getLastErrors() && $errors['error_count'] == 0) |
|
| 444 | + if ($formatted && $errors = Api\DateTime::getLastErrors() && $errors['error_count'] == 0) |
|
| 445 | 445 | { |
| 446 | 446 | $record[$name] = $formatted->getTimestamp(); |
| 447 | 447 | } |
| 448 | 448 | } |
| 449 | - $record[$name] = Api\DateTime::server2user($record[$name],'ts'); |
|
| 450 | - if(is_array(self::$cf_parse_cache[$appname][0]['date']) && |
|
| 449 | + $record[$name] = Api\DateTime::server2user($record[$name], 'ts'); |
|
| 450 | + if (is_array(self::$cf_parse_cache[$appname][0]['date']) && |
|
| 451 | 451 | in_array($name, self::$cf_parse_cache[$appname][0]['date'])) { |
| 452 | 452 | // Custom fields stored in a particular format (from customfields_widget) |
| 453 | 453 | $record[$name] = date('Y-m-d', $record[$name]); |
| 454 | 454 | } |
| 455 | 455 | } |
| 456 | - if(array_key_exists($name, $record) && strlen(trim($record[$name])) == 0) |
|
| 456 | + if (array_key_exists($name, $record) && strlen(trim($record[$name])) == 0) |
|
| 457 | 457 | { |
| 458 | 458 | $record[$name] = null; |
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | - foreach((array)$fields['float'] as $name) |
|
| 461 | + foreach ((array)$fields['float'] as $name) |
|
| 462 | 462 | { |
| 463 | - if($record[$name] != null && $record[$name] != '') { |
|
| 463 | + if ($record[$name] != null && $record[$name] != '') { |
|
| 464 | 464 | $dec_point = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
| 465 | 465 | if (empty($dec_point)) $dec_point = '.'; |
| 466 | 466 | $record[$name] = floatval(str_replace($dec_point, '.', preg_replace('/[^\d'.preg_quote($dec_point).']/', '', $record[$name]))); |
@@ -468,23 +468,23 @@ discard block |
||
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | // Some custom methods for conversion |
| 471 | - foreach((array)$methods as $name => $method) { |
|
| 472 | - if($record[$name]) $record[$name] = ExecMethod($method, $record[$name]); |
|
| 471 | + foreach ((array)$methods as $name => $method) { |
|
| 472 | + if ($record[$name]) $record[$name] = ExecMethod($method, $record[$name]); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | // cat_name2id will use currentapp to create new categories |
| 476 | 476 | $current_app = $GLOBALS['egw_info']['flags']['currentapp']; |
| 477 | - if($appname) { |
|
| 477 | + if ($appname) { |
|
| 478 | 478 | $GLOBALS['egw_info']['flags']['currentapp'] = $appname; |
| 479 | 479 | } |
| 480 | - $categories = new Api\Categories('',$appname); |
|
| 481 | - foreach((array)$fields['select-cat'] as $name) { |
|
| 482 | - if($record[$name]) { |
|
| 480 | + $categories = new Api\Categories('', $appname); |
|
| 481 | + foreach ((array)$fields['select-cat'] as $name) { |
|
| 482 | + if ($record[$name]) { |
|
| 483 | 483 | // Only parse name if it needs it |
| 484 | - if($format == 1) |
|
| 484 | + if ($format == 1) |
|
| 485 | 485 | { |
| 486 | - $existing_cat = $categories->exists('all',$record[$name]); |
|
| 487 | - if($existing_cat) |
|
| 486 | + $existing_cat = $categories->exists('all', $record[$name]); |
|
| 487 | + if ($existing_cat) |
|
| 488 | 488 | { |
| 489 | 489 | $cat_id = $existing_cat; |
| 490 | 490 | } |
@@ -493,14 +493,14 @@ discard block |
||
| 493 | 493 | $cat_id = importexport_helper_functions::cat_name2id($record[$name]); |
| 494 | 494 | } |
| 495 | 495 | // Don't clear it if it wasn't found |
| 496 | - if($cat_id) $record[$name] = $cat_id; |
|
| 496 | + if ($cat_id) $record[$name] = $cat_id; |
|
| 497 | 497 | } |
| 498 | 498 | } |
| 499 | 499 | } |
| 500 | 500 | $GLOBALS['egw_info']['flags']['currentapp'] = $current_app; |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | - return implode("\n",$warnings); |
|
| 503 | + return implode("\n", $warnings); |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | /** |
@@ -514,36 +514,36 @@ discard block |
||
| 514 | 514 | */ |
| 515 | 515 | protected static function find_select_key($record_value, $selects) |
| 516 | 516 | { |
| 517 | - if($record_value != null && is_array($selects)) { |
|
| 518 | - if(is_array($record_value) || is_string($record_value) && strpos($record_value, ',') !== FALSE) |
|
| 517 | + if ($record_value != null && is_array($selects)) { |
|
| 518 | + if (is_array($record_value) || is_string($record_value) && strpos($record_value, ',') !== FALSE) |
|
| 519 | 519 | { |
| 520 | 520 | // Array, or CSV |
| 521 | 521 | $key = array(); |
| 522 | - $subs = explode(',',$record_value); |
|
| 523 | - for($sub_index = 0; $sub_index < count($subs); $sub_index++) |
|
| 522 | + $subs = explode(',', $record_value); |
|
| 523 | + for ($sub_index = 0; $sub_index < count($subs); $sub_index++) |
|
| 524 | 524 | { |
| 525 | 525 | $sub_key = static::find_select_key(trim($subs[$sub_index]), $selects); |
| 526 | - if(!$sub_key) |
|
| 526 | + if (!$sub_key) |
|
| 527 | 527 | { |
| 528 | - $sub_key = static::find_select_key(trim($subs[$sub_index]).','.trim($subs[$sub_index+1]), $selects); |
|
| 529 | - if($sub_key) $sub_index++; |
|
| 528 | + $sub_key = static::find_select_key(trim($subs[$sub_index]).','.trim($subs[$sub_index + 1]), $selects); |
|
| 529 | + if ($sub_key) $sub_index++; |
|
| 530 | 530 | } |
| 531 | - if($sub_key) |
|
| 531 | + if ($sub_key) |
|
| 532 | 532 | { |
| 533 | 533 | $key[] = $sub_key; |
| 534 | 534 | } |
| 535 | 535 | } |
| 536 | 536 | return $key; |
| 537 | 537 | } |
| 538 | - $key = array_search(strtolower($record_value), array_map('strtolower',$selects)); |
|
| 539 | - if($key !== false) |
|
| 538 | + $key = array_search(strtolower($record_value), array_map('strtolower', $selects)); |
|
| 539 | + if ($key !== false) |
|
| 540 | 540 | { |
| 541 | 541 | $record_value = $key; |
| 542 | 542 | } |
| 543 | 543 | else |
| 544 | 544 | { |
| 545 | - $key = array_search(strtolower($record_value), array_map('strtolower',array_map('lang',$selects))); |
|
| 546 | - if($key !== false) $record_value = $key; |
|
| 545 | + $key = array_search(strtolower($record_value), array_map('strtolower', array_map('lang', $selects))); |
|
| 546 | + if ($key !== false) $record_value = $key; |
|
| 547 | 547 | } |
| 548 | 548 | } |
| 549 | 549 | |
@@ -22,7 +22,9 @@ discard block |
||
| 22 | 22 | * @todo Throw away spechial chars and trim() entries ? |
| 23 | 23 | * @todo Check for XSS like userinput! (see common_functions) |
| 24 | 24 | */ |
| 25 | -class importexport_import_csv implements importexport_iface_import_record { //, Iterator { |
|
| 25 | +class importexport_import_csv implements importexport_iface_import_record |
|
| 26 | +{ |
|
| 27 | +//, Iterator { |
|
| 26 | 28 | |
| 27 | 29 | const csv_max_linelength = 8000; |
| 28 | 30 | |
@@ -83,10 +85,14 @@ discard block |
||
| 83 | 85 | * @param string $_resource resource containing data. May be each valid php-stream |
| 84 | 86 | * @param array $_options options for the resource array with keys: charset and fieldsep |
| 85 | 87 | */ |
| 86 | - public function __construct( $_resource, array $_options ) { |
|
| 88 | + public function __construct( $_resource, array $_options ) |
|
| 89 | + { |
|
| 87 | 90 | $this->resource = $_resource; |
| 88 | 91 | $this->csv_fieldsep = $_options['fieldsep']; |
| 89 | - if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
| 92 | + if($_options['charset'] == 'user') |
|
| 93 | + { |
|
| 94 | + $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset']; |
|
| 95 | + } |
|
| 90 | 96 | $this->csv_charset = $_options['charset']; |
| 91 | 97 | return; |
| 92 | 98 | } // end of member function __construct |
@@ -94,7 +100,8 @@ discard block |
||
| 94 | 100 | /** |
| 95 | 101 | * cleanup |
| 96 | 102 | */ |
| 97 | - public function __destruct( ) { |
|
| 103 | + public function __destruct( ) |
|
| 104 | + { |
|
| 98 | 105 | } // end of member function __destruct |
| 99 | 106 | |
| 100 | 107 | /** |
@@ -103,20 +110,27 @@ discard block |
||
| 103 | 110 | * @param mixed _position may be: {current|first|last|next|previous|somenumber} |
| 104 | 111 | * @return mixed array with data / false if no furtor records |
| 105 | 112 | */ |
| 106 | - public function get_record( $_position = 'next' ) { |
|
| 113 | + public function get_record( $_position = 'next' ) |
|
| 114 | + { |
|
| 107 | 115 | |
| 108 | - if ($this->get_raw_record( $_position ) === false) { |
|
| 116 | + if ($this->get_raw_record( $_position ) === false) |
|
| 117 | + { |
|
| 109 | 118 | return false; |
| 110 | 119 | } |
| 111 | 120 | |
| 112 | 121 | // skip empty records |
| 113 | - if( count( array_unique( $this->record ) ) < 2 ) return $this->get_record( $_position ); |
|
| 122 | + if( count( array_unique( $this->record ) ) < 2 ) |
|
| 123 | + { |
|
| 124 | + return $this->get_record( $_position ); |
|
| 125 | + } |
|
| 114 | 126 | |
| 115 | - if ( !empty( $this->conversion ) ) { |
|
| 127 | + if ( !empty( $this->conversion ) ) |
|
| 128 | + { |
|
| 116 | 129 | $this->do_conversions(); |
| 117 | 130 | } |
| 118 | 131 | |
| 119 | - if ( !empty( $this->mapping ) ) { |
|
| 132 | + if ( !empty( $this->mapping ) ) |
|
| 133 | + { |
|
| 120 | 134 | $this->do_fieldmapping(); |
| 121 | 135 | } |
| 122 | 136 | |
@@ -128,8 +142,10 @@ discard block |
||
| 128 | 142 | * |
| 129 | 143 | * @param int $_numToSkip |
| 130 | 144 | */ |
| 131 | - public function skip_records( $_numToSkip ) { |
|
| 132 | - while ( (int)$_numToSkip-- !== 0 ) { |
|
| 145 | + public function skip_records( $_numToSkip ) |
|
| 146 | + { |
|
| 147 | + while ( (int)$_numToSkip-- !== 0 ) |
|
| 148 | + { |
|
| 133 | 149 | fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep); |
| 134 | 150 | } |
| 135 | 151 | } |
@@ -140,22 +156,27 @@ discard block |
||
| 140 | 156 | * @param mixed $_position |
| 141 | 157 | * @return bool |
| 142 | 158 | */ |
| 143 | - private function get_raw_record( $_position = 'next' ) { |
|
| 144 | - switch ($_position) { |
|
| 159 | + private function get_raw_record( $_position = 'next' ) |
|
| 160 | + { |
|
| 161 | + switch ($_position) |
|
| 162 | + { |
|
| 145 | 163 | case 'current' : |
| 146 | - if ($this->current_position == 0) { |
|
| 164 | + if ($this->current_position == 0) |
|
| 165 | + { |
|
| 147 | 166 | return; |
| 148 | 167 | } |
| 149 | 168 | break; |
| 150 | 169 | case 'first' : |
| 151 | - if (!$this->current_position == 0) { |
|
| 170 | + if (!$this->current_position == 0) |
|
| 171 | + { |
|
| 152 | 172 | $this->current_position = 0; |
| 153 | 173 | rewind($this->resource); |
| 154 | 174 | } |
| 155 | 175 | |
| 156 | 176 | case 'next' : |
| 157 | 177 | $csv_data = fgetcsv( $this->resource, self::csv_max_linelength, $this->csv_fieldsep); |
| 158 | - if (!is_array($csv_data)) { |
|
| 178 | + if (!is_array($csv_data)) |
|
| 179 | + { |
|
| 159 | 180 | return false; |
| 160 | 181 | } |
| 161 | 182 | $this->current_position++; |
@@ -163,33 +184,41 @@ discard block |
||
| 163 | 184 | break; |
| 164 | 185 | |
| 165 | 186 | case 'previous' : |
| 166 | - if ($this->current_position < 2) { |
|
| 187 | + if ($this->current_position < 2) |
|
| 188 | + { |
|
| 167 | 189 | throw new Exception('Error: There is no previous record!'); |
| 168 | 190 | } |
| 169 | 191 | $final_position = --$this->current_position; |
| 170 | 192 | $this->current_position = 0; |
| 171 | 193 | rewind($this->resource); |
| 172 | - while ($this->current_position !== $final_position) { |
|
| 194 | + while ($this->current_position !== $final_position) |
|
| 195 | + { |
|
| 173 | 196 | $this->get_raw_record(); |
| 174 | 197 | } |
| 175 | 198 | break; |
| 176 | 199 | |
| 177 | 200 | case 'last' : |
| 178 | - while ($this->get_raw_record()) {} |
|
| 201 | + while ($this->get_raw_record()) |
|
| 202 | + { |
|
| 203 | +} |
|
| 179 | 204 | break; |
| 180 | 205 | |
| 181 | 206 | default: //somenumber |
| 182 | - if (!is_int($_position)) { |
|
| 207 | + if (!is_int($_position)) |
|
| 208 | + { |
|
| 183 | 209 | throw new Exception('Error: $position must be one of {current|first|last|next|previous} or an integer value'); |
| 184 | 210 | } |
| 185 | - if ($_position == $this->current_position) { |
|
| 211 | + if ($_position == $this->current_position) |
|
| 212 | + { |
|
| 186 | 213 | break; |
| 187 | 214 | } |
| 188 | - elseif ($_position < $this->current_position) { |
|
| 215 | + elseif ($_position < $this->current_position) |
|
| 216 | + { |
|
| 189 | 217 | $this->current_position = 0; |
| 190 | 218 | rewind($this->resource); |
| 191 | 219 | } |
| 192 | - while ($this->current_position !== $_position) { |
|
| 220 | + while ($this->current_position !== $_position) |
|
| 221 | + { |
|
| 193 | 222 | $this->get_raw_record(); |
| 194 | 223 | } |
| 195 | 224 | break; |
@@ -202,12 +231,16 @@ discard block |
||
| 202 | 231 | * |
| 203 | 232 | * @return int |
| 204 | 233 | */ |
| 205 | - public function get_num_of_records( ) { |
|
| 206 | - if ($this->num_of_records > 0) { |
|
| 234 | + public function get_num_of_records( ) |
|
| 235 | + { |
|
| 236 | + if ($this->num_of_records > 0) |
|
| 237 | + { |
|
| 207 | 238 | return $this->num_of_records; |
| 208 | 239 | } |
| 209 | 240 | $current_position = $this->current_position; |
| 210 | - while ($this->get_raw_record()) {} |
|
| 241 | + while ($this->get_raw_record()) |
|
| 242 | + { |
|
| 243 | +} |
|
| 211 | 244 | $this->num_of_records = $this->current_position; |
| 212 | 245 | $this->get_record($current_position); |
| 213 | 246 | return $this->num_of_records; |
@@ -218,7 +251,8 @@ discard block |
||
| 218 | 251 | * |
| 219 | 252 | * @return int |
| 220 | 253 | */ |
| 221 | - public function get_current_position( ) { |
|
| 254 | + public function get_current_position( ) |
|
| 255 | + { |
|
| 222 | 256 | |
| 223 | 257 | return $this->current_position; |
| 224 | 258 | |
@@ -230,12 +264,16 @@ discard block |
||
| 230 | 264 | * |
| 231 | 265 | * @return |
| 232 | 266 | */ |
| 233 | - protected function do_fieldmapping( ) { |
|
| 267 | + protected function do_fieldmapping( ) |
|
| 268 | + { |
|
| 234 | 269 | $record = $this->record; |
| 235 | 270 | $this->record = array(); |
| 236 | 271 | foreach ($this->mapping as $cvs_idx => $new_idx) |
| 237 | 272 | { |
| 238 | - if( $new_idx == '' ) continue; |
|
| 273 | + if( $new_idx == '' ) |
|
| 274 | + { |
|
| 275 | + continue; |
|
| 276 | + } |
|
| 239 | 277 | $this->record[$new_idx] = $record[$cvs_idx]; |
| 240 | 278 | } |
| 241 | 279 | return true; |
@@ -246,8 +284,10 @@ discard block |
||
| 246 | 284 | * |
| 247 | 285 | * @return bool |
| 248 | 286 | */ |
| 249 | - protected function do_conversions() { |
|
| 250 | - if ( $record = importexport_helper_functions::conversion( $this->record, $this->conversion, $this->conversion_class )) { |
|
| 287 | + protected function do_conversions() |
|
| 288 | + { |
|
| 289 | + if ( $record = importexport_helper_functions::conversion( $this->record, $this->conversion, $this->conversion_class )) |
|
| 290 | + { |
|
| 251 | 291 | $this->record = $record; |
| 252 | 292 | return; |
| 253 | 293 | } |
@@ -264,16 +304,19 @@ discard block |
||
| 264 | 304 | * |
| 265 | 305 | * @return string warnings, if any |
| 266 | 306 | */ |
| 267 | - public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0) { |
|
| 307 | + public static function convert(Array &$record, Array $fields = array(), $appname = null, Array $selects = array(), $format=0) |
|
| 308 | + { |
|
| 268 | 309 | $warnings = array(); |
| 269 | 310 | |
| 270 | 311 | // Automatic conversions |
| 271 | - if($appname) { |
|
| 312 | + if($appname) |
|
| 313 | + { |
|
| 272 | 314 | |
| 273 | 315 | // Load translations |
| 274 | 316 | Api\Translation::add_app($appname); |
| 275 | 317 | |
| 276 | - if(!self::$cf_parse_cache[$appname]) { |
|
| 318 | + if(!self::$cf_parse_cache[$appname]) |
|
| 319 | + { |
|
| 277 | 320 | $c_fields = importexport_export_csv::convert_parse_custom_fields($appname, $selects, $links, $methods); |
| 278 | 321 | self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods); |
| 279 | 322 | } |
@@ -282,7 +325,10 @@ discard block |
||
| 282 | 325 | // Add in any fields that are keys to another app |
| 283 | 326 | foreach((array)$fields['links'] as $link_field => $app) |
| 284 | 327 | { |
| 285 | - if(is_numeric($link_field)) continue; |
|
| 328 | + if(is_numeric($link_field)) |
|
| 329 | + { |
|
| 330 | + continue; |
|
| 331 | + } |
|
| 286 | 332 | $links[$link_field] = $app; |
| 287 | 333 | // Set it as a normal link field |
| 288 | 334 | $fields['links'][] = $link_field; |
@@ -292,7 +338,8 @@ discard block |
||
| 292 | 338 | // Not quite a recursive merge, since only one level |
| 293 | 339 | foreach($fields as $type => &$list) |
| 294 | 340 | { |
| 295 | - if($c_fields[$type]) { |
|
| 341 | + if($c_fields[$type]) |
|
| 342 | + { |
|
| 296 | 343 | $list = array_merge($c_fields[$type], $list); |
| 297 | 344 | unset($c_fields[$type]); |
| 298 | 345 | } |
@@ -300,12 +347,15 @@ discard block |
||
| 300 | 347 | $fields += $c_fields; |
| 301 | 348 | $selects += $c_selects; |
| 302 | 349 | } |
| 303 | - if($fields) { |
|
| 304 | - foreach((array)$fields['select'] as $name) { |
|
| 350 | + if($fields) |
|
| 351 | + { |
|
| 352 | + foreach((array)$fields['select'] as $name) |
|
| 353 | + { |
|
| 305 | 354 | $record[$name] = static::find_select_key($record[$name], $selects[$name]); |
| 306 | 355 | } |
| 307 | 356 | |
| 308 | - foreach((array)$fields['links'] as $name) { |
|
| 357 | + foreach((array)$fields['links'] as $name) |
|
| 358 | + { |
|
| 309 | 359 | if($record[$name] && $links[$name]) |
| 310 | 360 | { |
| 311 | 361 | // Primary key to another app, not a link |
@@ -347,15 +397,19 @@ discard block |
||
| 347 | 397 | lang($links[$name]), $record[$name]). |
| 348 | 398 | ' - ' . lang('no matches'); |
| 349 | 399 | continue; |
| 350 | - } else { |
|
| 400 | + } |
|
| 401 | + else |
|
| 402 | + { |
|
| 351 | 403 | $record[$name] = key($results); |
| 352 | 404 | } |
| 353 | 405 | } |
| 354 | 406 | } |
| 355 | 407 | } |
| 356 | - foreach((array)$fields['select-account'] as $name) { |
|
| 408 | + foreach((array)$fields['select-account'] as $name) |
|
| 409 | + { |
|
| 357 | 410 | // Compare against null to deal with empty arrays |
| 358 | - if ($record[$name]) { |
|
| 411 | + if ($record[$name]) |
|
| 412 | + { |
|
| 359 | 413 | // Automatically handle text owner without explicit translation |
| 360 | 414 | $new_owner = importexport_helper_functions::account_name2id($record[$name]); |
| 361 | 415 | if(count($new_owner) != count(explode(',',$record[$name]))) |
@@ -363,20 +417,26 @@ discard block |
||
| 363 | 417 | // Unable to parse value into account |
| 364 | 418 | $warnings[] = $name . ': ' .lang('%1 is not a known user or group', $record[$name]); |
| 365 | 419 | } |
| 366 | - if($new_owner != '') { |
|
| 420 | + if($new_owner != '') |
|
| 421 | + { |
|
| 367 | 422 | $record[$name] = $new_owner; |
| 368 | - } else { |
|
| 423 | + } |
|
| 424 | + else |
|
| 425 | + { |
|
| 369 | 426 | // Clear it to prevent trouble later on |
| 370 | 427 | $record[$name] = ''; |
| 371 | 428 | } |
| 372 | 429 | } |
| 373 | 430 | } |
| 374 | - foreach((array)$fields['select-bool'] as $name) { |
|
| 375 | - if($record[$name] != null && $record[$name] != '') { |
|
| 431 | + foreach((array)$fields['select-bool'] as $name) |
|
| 432 | + { |
|
| 433 | + if($record[$name] != null && $record[$name] != '') |
|
| 434 | + { |
|
| 376 | 435 | $record[$name] = ($record[$name] == lang('Yes') || $record[$name] == '1' ? 1 : 0); |
| 377 | 436 | } |
| 378 | 437 | } |
| 379 | - foreach((array)$fields['date-time'] as $name) { |
|
| 438 | + foreach((array)$fields['date-time'] as $name) |
|
| 439 | + { |
|
| 380 | 440 | if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0) |
| 381 | 441 | { |
| 382 | 442 | // Need to handle format first |
@@ -402,7 +462,8 @@ discard block |
||
| 402 | 462 | // Try again, anything goes |
| 403 | 463 | try { |
| 404 | 464 | $formatted = new Api\DateTime($record[$name]); |
| 405 | - } catch (Exception $e) { |
|
| 465 | + } |
|
| 466 | + catch (Exception $e) { |
|
| 406 | 467 | $warnings[] = $name.': ' . $e->getMessage() . "\n" . |
| 407 | 468 | 'Format: '.'!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat; |
| 408 | 469 | continue; |
@@ -424,7 +485,8 @@ discard block |
||
| 424 | 485 | } |
| 425 | 486 | |
| 426 | 487 | if(is_array(self::$cf_parse_cache[$appname][0]['date-time']) && |
| 427 | - in_array($name, self::$cf_parse_cache[$appname][0]['date-time'])) { |
|
| 488 | + in_array($name, self::$cf_parse_cache[$appname][0]['date-time'])) |
|
| 489 | + { |
|
| 428 | 490 | // Custom fields stored in a particular format (from customfields_widget) |
| 429 | 491 | $record[$name] = date('Y-m-d H:i:s', $record[$name]); |
| 430 | 492 | } |
@@ -434,7 +496,8 @@ discard block |
||
| 434 | 496 | $record[$name] = null; |
| 435 | 497 | } |
| 436 | 498 | } |
| 437 | - foreach((array)$fields['date'] as $name) { |
|
| 499 | + foreach((array)$fields['date'] as $name) |
|
| 500 | + { |
|
| 438 | 501 | if (isset($record[$name]) && !is_numeric($record[$name]) && strlen(trim($record[$name])) > 0) |
| 439 | 502 | { |
| 440 | 503 | // Need to handle format first |
@@ -448,7 +511,8 @@ discard block |
||
| 448 | 511 | } |
| 449 | 512 | $record[$name] = Api\DateTime::server2user($record[$name],'ts'); |
| 450 | 513 | if(is_array(self::$cf_parse_cache[$appname][0]['date']) && |
| 451 | - in_array($name, self::$cf_parse_cache[$appname][0]['date'])) { |
|
| 514 | + in_array($name, self::$cf_parse_cache[$appname][0]['date'])) |
|
| 515 | + { |
|
| 452 | 516 | // Custom fields stored in a particular format (from customfields_widget) |
| 453 | 517 | $record[$name] = date('Y-m-d', $record[$name]); |
| 454 | 518 | } |
@@ -460,26 +524,37 @@ discard block |
||
| 460 | 524 | } |
| 461 | 525 | foreach((array)$fields['float'] as $name) |
| 462 | 526 | { |
| 463 | - if($record[$name] != null && $record[$name] != '') { |
|
| 527 | + if($record[$name] != null && $record[$name] != '') |
|
| 528 | + { |
|
| 464 | 529 | $dec_point = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0]; |
| 465 | - if (empty($dec_point)) $dec_point = '.'; |
|
| 530 | + if (empty($dec_point)) |
|
| 531 | + { |
|
| 532 | + $dec_point = '.'; |
|
| 533 | + } |
|
| 466 | 534 | $record[$name] = floatval(str_replace($dec_point, '.', preg_replace('/[^\d'.preg_quote($dec_point).']/', '', $record[$name]))); |
| 467 | 535 | } |
| 468 | 536 | } |
| 469 | 537 | |
| 470 | 538 | // Some custom methods for conversion |
| 471 | - foreach((array)$methods as $name => $method) { |
|
| 472 | - if($record[$name]) $record[$name] = ExecMethod($method, $record[$name]); |
|
| 539 | + foreach((array)$methods as $name => $method) |
|
| 540 | + { |
|
| 541 | + if($record[$name]) |
|
| 542 | + { |
|
| 543 | + $record[$name] = ExecMethod($method, $record[$name]); |
|
| 544 | + } |
|
| 473 | 545 | } |
| 474 | 546 | |
| 475 | 547 | // cat_name2id will use currentapp to create new categories |
| 476 | 548 | $current_app = $GLOBALS['egw_info']['flags']['currentapp']; |
| 477 | - if($appname) { |
|
| 549 | + if($appname) |
|
| 550 | + { |
|
| 478 | 551 | $GLOBALS['egw_info']['flags']['currentapp'] = $appname; |
| 479 | 552 | } |
| 480 | 553 | $categories = new Api\Categories('',$appname); |
| 481 | - foreach((array)$fields['select-cat'] as $name) { |
|
| 482 | - if($record[$name]) { |
|
| 554 | + foreach((array)$fields['select-cat'] as $name) |
|
| 555 | + { |
|
| 556 | + if($record[$name]) |
|
| 557 | + { |
|
| 483 | 558 | // Only parse name if it needs it |
| 484 | 559 | if($format == 1) |
| 485 | 560 | { |
@@ -493,7 +568,10 @@ discard block |
||
| 493 | 568 | $cat_id = importexport_helper_functions::cat_name2id($record[$name]); |
| 494 | 569 | } |
| 495 | 570 | // Don't clear it if it wasn't found |
| 496 | - if($cat_id) $record[$name] = $cat_id; |
|
| 571 | + if($cat_id) |
|
| 572 | + { |
|
| 573 | + $record[$name] = $cat_id; |
|
| 574 | + } |
|
| 497 | 575 | } |
| 498 | 576 | } |
| 499 | 577 | } |
@@ -514,7 +592,8 @@ discard block |
||
| 514 | 592 | */ |
| 515 | 593 | protected static function find_select_key($record_value, $selects) |
| 516 | 594 | { |
| 517 | - if($record_value != null && is_array($selects)) { |
|
| 595 | + if($record_value != null && is_array($selects)) |
|
| 596 | + { |
|
| 518 | 597 | if(is_array($record_value) || is_string($record_value) && strpos($record_value, ',') !== FALSE) |
| 519 | 598 | { |
| 520 | 599 | // Array, or CSV |
@@ -526,7 +605,10 @@ discard block |
||
| 526 | 605 | if(!$sub_key) |
| 527 | 606 | { |
| 528 | 607 | $sub_key = static::find_select_key(trim($subs[$sub_index]).','.trim($subs[$sub_index+1]), $selects); |
| 529 | - if($sub_key) $sub_index++; |
|
| 608 | + if($sub_key) |
|
| 609 | + { |
|
| 610 | + $sub_index++; |
|
| 611 | + } |
|
| 530 | 612 | } |
| 531 | 613 | if($sub_key) |
| 532 | 614 | { |
@@ -543,7 +625,10 @@ discard block |
||
| 543 | 625 | else |
| 544 | 626 | { |
| 545 | 627 | $key = array_search(strtolower($record_value), array_map('strtolower',array_map('lang',$selects))); |
| 546 | - if($key !== false) $record_value = $key; |
|
| 628 | + if($key !== false) |
|
| 629 | + { |
|
| 630 | + $record_value = $key; |
|
| 631 | + } |
|
| 547 | 632 | } |
| 548 | 633 | } |
| 549 | 634 | |