function save($id, $vars, &$errors) { if (!$vars['grace_period']) { $errors['grace_period'] = 'Grace period required'; } elseif (!is_numeric($vars['grace_period'])) { $errors['grace_period'] = 'Numeric value required (in hours)'; } if (!$vars['name']) { $errors['name'] = 'Name required'; } elseif (($sid = SLA::getIdByName($vars['name'])) && $sid != $id) { $errors['name'] = 'Name already exists'; } if ($errors) { return false; } $sql = ' updated=NOW() ' . ',isactive=' . db_input($vars['isactive']) . ',name=' . db_input($vars['name']) . ',grace_period=' . db_input($vars['grace_period']) . ',disable_overdue_alerts=' . db_input(isset($vars['disable_overdue_alerts']) ? 1 : 0) . ',enable_priority_escalation=' . db_input(isset($vars['enable_priority_escalation']) ? 1 : 0) . ',notes=' . db_input($vars['notes']); if ($id) { $sql = 'UPDATE ' . SLA_TABLE . ' SET ' . $sql . ' WHERE id=' . db_input($id); if (db_query($sql)) { return true; } $errors['err'] = 'Unable to update SLA. Internal error occurred'; } else { $sql = 'INSERT INTO ' . SLA_TABLE . ' SET ' . $sql . ',created=NOW() '; if (db_query($sql) && ($id = db_insert_id())) { return $id; } $errors['err'] = 'Unable to add SLA. Internal error'; } return false; }