Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 1 | <?php |
Adrià Vilanova Martínez | 5af8651 | 2023-12-02 20:44:16 +0100 | [diff] [blame] | 2 | /* |
| 3 | * hores |
| 4 | * Copyright (c) 2023 Adrià Vilanova Martínez |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU Affero General Public License as |
| 8 | * published by the Free Software Foundation, either version 3 of the |
| 9 | * License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU Affero General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Affero General Public |
| 17 | * License along with this program. |
| 18 | * If not, see http://www.gnu.org/licenses/. |
| 19 | */ |
| 20 | |
Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame] | 21 | class companies { |
| 22 | public static function add($company, $cif) { |
| 23 | global $con; |
| 24 | |
| 25 | $scompany = db::sanitize($company); |
| 26 | $scif = db::sanitize($cif); |
| 27 | return mysqli_query($con, "INSERT INTO companies (name, cif) VALUES ('$scompany', '$scif')"); |
| 28 | } |
| 29 | |
| 30 | public static function edit($id, $name, $cif) { |
| 31 | global $con; |
| 32 | |
| 33 | $sid = (int)$id; |
| 34 | $sname = db::sanitize($name); |
| 35 | $scif = db::sanitize($cif); |
| 36 | |
| 37 | return mysqli_query($con, "UPDATE companies SET name = '$sname', cif = '$scif' WHERE id = $sid LIMIT 1"); |
| 38 | } |
| 39 | |
| 40 | public static function get($id) { |
| 41 | global $con; |
| 42 | |
| 43 | $sid = (int)$id; |
| 44 | |
| 45 | $query = mysqli_query($con, "SELECT * FROM companies WHERE id = $sid"); |
| 46 | |
| 47 | if (!mysqli_num_rows($query)) return false; |
| 48 | |
| 49 | return mysqli_fetch_assoc($query); |
| 50 | } |
| 51 | |
| 52 | public static function getAll($simplified = true, $mixed = false) { |
| 53 | global $con; |
| 54 | |
| 55 | $query = mysqli_query($con, "SELECT * FROM companies ORDER BY id ASC"); |
| 56 | |
| 57 | $categories = []; |
| 58 | |
| 59 | while ($row = mysqli_fetch_assoc($query)) { |
| 60 | if ($simplified) $categories[$row["id"]] = $row["name"]; |
| 61 | elseif ($mixed) $categories[$row["id"]] = $row; |
| 62 | else $categories[] = $row; |
| 63 | } |
| 64 | |
| 65 | return $categories; |
| 66 | } |
| 67 | |
| 68 | public static function exists($id) { |
| 69 | global $con; |
| 70 | |
| 71 | if ($id == -1) return true; |
| 72 | |
| 73 | $query = mysqli_query($con, "SELECT id FROM companies WHERE id = ".(int)$id); |
| 74 | |
| 75 | return (mysqli_num_rows($query) > 0); |
| 76 | } |
| 77 | } |