function set_attendance($raider, $night, $status, $comment = '') { global $error, $success, $db; $data = array('raider_id' => $raider->id, 'night' => $night, 'status' => $status, 'time' => time(), 'comment' => $comment); if (!is_numeric($night) && $status == STATUS_CLEAR) { // A range of nights, convert all nights from start till end to the state $sql = 'SELECT time, comment, status FROM ' . RAIDATTENDANCE_TABLE . " WHERE raider_id={$raider->id} AND night='{$night}'"; $res = $db->sql_query($sql); $row = $db->sql_fetchrow($res); $time = $row['time']; $old_comment = $row['comment']; $old_status = $row['status']; $db->sql_freeresult($res); $day_num = get_day_number($night); $all_nights = get_raiding_dates($time, $data['time'], array($day_num)); $ary = array(); foreach ($all_nights as $raid_night) { // Check whether the night already has another status $sql = 'SELECT COUNT(status) cnt FROM ' . RAIDATTENDANCE_TABLE . " WHERE raider_id={$raider->id} AND night='{$raid_night}'"; $res = $db->sql_query($sql); $row = $db->sql_fetchrow($res); $already_have_status = $row['cnt'] > 0; $db->sql_freeresult($res); if (!$already_have_status) { $ary[] = array('raider_id' => $raider->id, 'night' => $raid_night, 'status' => $old_status, 'time' => $time, 'comment' => $old_comment); } } $res = $db->sql_multi_insert(RAIDATTENDANCE_TABLE, $ary); if (is_dbal_error()) { $error[] = $res; } } // One night $up_array = array('status' => $status, 'comment' => $comment); $sql = 'UPDATE ' . RAIDATTENDANCE_TABLE . " SET " . $db->sql_build_array('UPDATE', $up_array) . " WHERE raider_id={$raider->id} AND night='{$night}'"; $res = $db->sql_query($sql, 0); if ($db->sql_affectedrows() >= 1) { return; } $ary = array($data); $res = $db->sql_multi_insert(RAIDATTENDANCE_TABLE, $ary); if (is_dbal_error()) { $error[] = $res; } }
function delete_checked_raiders(&$rows) { global $error, $success, $user, $db; // TODO: Optimize this so we use the checked array directly $deleted = array(); foreach ($rows as $k => $raider) { if ($raider->is_checked()) { $sql = 'DELETE FROM ' . RAIDER_TABLE . " WHERE id={$raider->id}"; $res = $db->sql_query($sql); if (is_dbal_error()) { $error[] = sprintf($user->lang['ERROR_DELETING_RAIDER'], $raider->name, $res); } else { $deleted[] = $raider->name; } unset($rows[$k]); } } $success[] = sprintf($user->lang['SUCCESS_DELETING_RAIDER'], implode(', ', $deleted)); }
function save() { global $error, $success, $db; if ($this->id) { $sql = 'UPDATE ' . TABLE_WWS_RAID . ' SET ' . $db->sql_build_array('UPDATE', $this->as_row()) . " WHERE id={$this->id}"; if (is_dbal_error()) { $error[] = 'Error updating WWS entry with id ' . $this->id . '<br/>' . $res; } else { $success[] = 'Successfully updated WWS entry with wws_id ' . $this->wws_id . '<br/>' . $res; } } else { $ary = array($this->as_row()); $res = $db->sql_multi_insert(TABLE_WWS_RAID, $ary); if (is_dbal_error()) { $error[] = 'Error inserting WWS entry with wws_id ' . $this->wws_id . '<br/>' . $res; } else { $success[] = 'Successfully inserted WWS entry with wws_id ' . $this->wws_id . ' <br/>' . $res; } } }