echo json_encode(array('errors' => $errorMessages)); break; /** * add or edit a activity */ /** * add or edit a activity */ case "activity": $data['name'] = $_REQUEST['name']; $data['comment'] = $_REQUEST['comment']; $data['visible'] = getRequestBool('visible'); $data['filter'] = $_REQUEST['activityFilter']; $data['defaultRate'] = getRequestDecimal($_REQUEST['defaultRate']); $data['myRate'] = getRequestDecimal($_REQUEST['myRate']); $data['fixedRate'] = getRequestDecimal($_REQUEST['fixedRate']); $oldGroups = array(); if ($id) { $oldGroups = $database->activity_get_groupIDs($id); } // validate data $errorMessages = array(); if (count($_REQUEST['activityGroups']) == 0) { $errorMessages['activityGroups'] = $kga['lang']['atLeastOneGroup']; } if (!checkGroupedObjectPermission('Activity', $id ? 'edit' : 'add', $oldGroups, $_REQUEST['activityGroups'])) { $errorMessages[''] = $kga['lang']['errorMessages']['permissionDenied']; } if (count($errorMessages) == 0) { // add or update the project if (!$id) {
} if (!isset($_REQUEST['multiplier']) || empty($_REQUEST['multiplier'])) { $errors['multiplier'] = sprintf($kga['lang']['errorMessages']['emptyField'], $kga['lang']['multiplier']); } if (count($errors) > 0) { echo json_encode(array('errors' => $errors)); break; } // get new data $data['projectID'] = $_REQUEST['projectID']; $data['designation'] = $_REQUEST['designation']; $data['comment'] = isset($_REQUEST['comment']) && !empty($_REQUEST['comment']) ? $_REQUEST['comment'] : ''; $data['commentType'] = $_REQUEST['commentType']; $data['refundable'] = getRequestBool('refundable'); $data['multiplier'] = getRequestDecimal($_REQUEST['multiplier']); $data['value'] = getRequestDecimal($_REQUEST['edit_value']); $data['userID'] = $kga['user']['userID']; if (!is_numeric($data['multiplier']) || $data['multiplier'] <= 0) { $errors['multiplier'] = $kga['lang']['errorMessages']['multiplierNegative']; } // parse new day and time $edit_day = Kimai_Format::expand_date_shortcut($_REQUEST['edit_day']); $edit_time = Kimai_Format::expand_time_shortcut($_REQUEST['edit_time']); // validate day and time $new = "{$edit_day}-{$edit_time}"; if (!Kimai_Format::check_time_format($new)) { $errors[''] = $kga['lang']['TimeDateInputError']; } // convert to internal time format $new_time = convert_time_strings($new, $new); $data['timestamp'] = $new_time['in'];
$errorMessages[''] = $kga['lang']['errorMessages']['permissionDenied']; } if (count($errorMessages) == 0) { // add or update the activity if (!$id) { $id = $database->activity_create($data, $activityGroups); } else { $database->activity_edit($id, $data, $activityGroups); } if (isset($_REQUEST['assignedProjects'])) { $database->assignActivityToProjectsForGroup($id, $_REQUEST['assignedProjects'], $kga['user']['groups']); foreach ($_REQUEST['assignedProjects'] as $index => $projectID) { if ($projectID <= 0) { continue; } $value = getRequestDecimal($_REQUEST['fixedRates'][$index]); if ($value !== null) { $database->save_fixed_rate($projectID, $id, $value); } else { $database->remove_fixed_rate($projectID, $id); } } } else { $database->assignActivityToProjectsForGroup($id, array(), $kga['user']['groups']); } // set the activity group and activity project mappings if (isset($_REQUEST['activityGroups'])) { $database->assign_activityToGroups($id, $_REQUEST['activityGroups']); } } header('Content-Type: application/json;charset=utf-8');