summaryrefslogtreecommitdiff
path: root/includes/model/ShiftTypes_model.php
blob: 89704a658466c820b23b4b895e7e6a2e572d5325 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php

/**
 * Delete a shift type.
 * @param int $shifttype_id
 */
function ShiftType_delete($shifttype_id) {
  return sql_query("DELETE FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
}

/**
 * Update a shift type.
 *
 * @param int $shifttype_id          
 * @param string $name          
 * @param int $angeltype_id          
 * @param string $description          
 */
function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) {
  return sql_query("UPDATE `ShiftTypes` SET
      `name`='" . sql_escape($name) . "', 
      `angeltype_id`=" . sql_null($angeltype_id) . ",
      `description`='" . sql_escape($description) . "'
      WHERE `id`='" . sql_escape($shifttype_id) . "'");
}

/**
 * Create a shift type.
 *
 * @param string $name          
 * @param int $angeltype_id          
 * @param string $description          
 * @return new shifttype id
 */
function ShiftType_create($name, $angeltype_id, $description) {
  $result = sql_query("INSERT INTO `ShiftTypes` SET
      `name`='" . sql_escape($name) . "', 
      `angeltype_id`=" . sql_null($angeltype_id) . ",
      `description`='" . sql_escape($description) . "'");
  if ($result === false) {
    return false;
  }
  return sql_id();
}

/**
 * Get a shift type by id.
 *
 * @param int $shifttype_id          
 */
function ShiftType($shifttype_id) {
  $shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
  if ($shifttype === false) {
    engelsystem_error('Unable to load shift type.');
  }
  if ($shifttype == null) {
    return null;
  }
  return $shifttype[0];
}

/**
 * Get all shift types.
 */
function ShiftTypes() {
  return sql_select("SELECT * FROM `ShiftTypes` ORDER BY `name`");
}

?>