Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | <?php |
| 2 | class companies { |
| 3 | public static function add($company, $cif) { |
| 4 | global $con; |
| 5 | |
| 6 | $scompany = db::sanitize($company); |
| 7 | $scif = db::sanitize($cif); |
| 8 | return mysqli_query($con, "INSERT INTO companies (name, cif) VALUES ('$scompany', '$scif')"); |
| 9 | } |
| 10 | |
| 11 | public static function edit($id, $name, $cif) { |
| 12 | global $con; |
| 13 | |
| 14 | $sid = (int)$id; |
| 15 | $sname = db::sanitize($name); |
| 16 | $scif = db::sanitize($cif); |
| 17 | |
| 18 | return mysqli_query($con, "UPDATE companies SET name = '$sname', cif = '$scif' WHERE id = $sid LIMIT 1"); |
| 19 | } |
| 20 | |
| 21 | public static function get($id) { |
| 22 | global $con; |
| 23 | |
| 24 | $sid = (int)$id; |
| 25 | |
| 26 | $query = mysqli_query($con, "SELECT * FROM companies WHERE id = $sid"); |
| 27 | |
| 28 | if (!mysqli_num_rows($query)) return false; |
| 29 | |
| 30 | return mysqli_fetch_assoc($query); |
| 31 | } |
| 32 | |
| 33 | public static function getAll($simplified = true, $mixed = false) { |
| 34 | global $con; |
| 35 | |
| 36 | $query = mysqli_query($con, "SELECT * FROM companies ORDER BY id ASC"); |
| 37 | |
| 38 | $categories = []; |
| 39 | |
| 40 | while ($row = mysqli_fetch_assoc($query)) { |
| 41 | if ($simplified) $categories[$row["id"]] = $row["name"]; |
| 42 | elseif ($mixed) $categories[$row["id"]] = $row; |
| 43 | else $categories[] = $row; |
| 44 | } |
| 45 | |
| 46 | return $categories; |
| 47 | } |
| 48 | |
| 49 | public static function exists($id) { |
| 50 | global $con; |
| 51 | |
| 52 | if ($id == -1) return true; |
| 53 | |
| 54 | $query = mysqli_query($con, "SELECT id FROM companies WHERE id = ".(int)$id); |
| 55 | |
| 56 | return (mysqli_num_rows($query) > 0); |
| 57 | } |
| 58 | } |