Marc Kupietz | d871d88 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 1 | <?php |
| 2 | require_once 'vendor/autoload.php'; |
| 3 | |
| 4 | class User |
| 5 | { |
Marc Kupietz | ce67631 | 2023-03-10 08:29:41 +0100 | [diff] [blame^] | 6 | public $id; |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 7 | public $username; |
| 8 | public $first_name; |
| 9 | public $last_name; |
| 10 | public $organization; |
| 11 | public $user_hash; |
| 12 | public $password; |
| 13 | public $street; |
| 14 | public $zip; |
| 15 | public $city; |
| 16 | public $country; |
| 17 | public $email; |
| 18 | public $phone; |
| 19 | public bool $eula_signed; |
| 20 | public bool $privacy_policy_signed; |
Marc Kupietz | 2f3a419 | 2023-03-09 08:14:12 +0100 | [diff] [blame] | 21 | public bool $author; |
| 22 | public $accepted_paper_id; |
Marc Kupietz | 87a1431 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 23 | public bool $participation_confirmed; |
Marc Kupietz | 2f3a419 | 2023-03-09 08:14:12 +0100 | [diff] [blame] | 24 | public $participation_confirmed_at; |
| 25 | public bool $student; |
| 26 | public bool $conference_dinner; |
Marc Kupietz | ce67631 | 2023-03-10 08:29:41 +0100 | [diff] [blame^] | 27 | public $registered_at; |
| 28 | public bool $earlybird_registration; |
Marc Kupietz | 87a1431 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 29 | public float $total_due; |
Marc Kupietz | ce67631 | 2023-03-10 08:29:41 +0100 | [diff] [blame^] | 30 | public $invoice; |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 31 | |
| 32 | function __construct() |
| 33 | { |
Marc Kupietz | ce67631 | 2023-03-10 08:29:41 +0100 | [diff] [blame^] | 34 | $this->id = ""; |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 35 | $this->username = ""; |
| 36 | $this->first_name = ""; |
| 37 | $this->last_name = ""; |
| 38 | $this->email = ""; |
| 39 | $this->organization = ""; |
| 40 | $this->user_hash = ""; |
| 41 | $this->password = ""; |
| 42 | $this->city = ""; |
| 43 | $this->country = ""; |
| 44 | $this->zip = ""; |
| 45 | $this->street = ""; |
| 46 | $this->phone = ""; |
| 47 | $this->eula_signed = false; |
| 48 | $this->privacy_policy_signed = false; |
Marc Kupietz | 2f3a419 | 2023-03-09 08:14:12 +0100 | [diff] [blame] | 49 | $this->author = false; |
| 50 | $this->accepted_paper_id = ""; |
| 51 | $this->participation_confirmed = false; |
| 52 | $this->participation_confirmed_at = ""; |
| 53 | $this->student = false; |
| 54 | $this->conference_dinner = false; |
Marc Kupietz | ce67631 | 2023-03-10 08:29:41 +0100 | [diff] [blame^] | 55 | $this->registered_at = date("Y-m-d H:i:s") . "UTC"; |
| 56 | $this->earlybird_registration = false; |
Marc Kupietz | 87a1431 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 57 | $this->total_due = 0.0; |
Marc Kupietz | ce67631 | 2023-03-10 08:29:41 +0100 | [diff] [blame^] | 58 | $this->invoice = ""; |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | function __construct1(object $data) |
| 62 | { |
| 63 | foreach ($data as $key => $value) { |
| 64 | if (array_key_exists($key, (array) $this)) |
| 65 | $this->{$key} = $value; |
Marc Kupietz | a57befa | 2023-03-06 21:39:23 +0100 | [diff] [blame] | 66 | } |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 67 | if (isset($data->password)) $this->set_password($data->password); |
| 68 | } |
Marc Kupietz | d871d88 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 69 | |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 70 | function init_from_object(object $data) |
| 71 | { |
| 72 | foreach ($data as $key => $value) { |
| 73 | if (array_key_exists($key, (array) $this)) |
| 74 | $this->{$key} = $value; |
Marc Kupietz | a57befa | 2023-03-06 21:39:23 +0100 | [diff] [blame] | 75 | } |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 76 | if (isset($data->password)) $this->set_password($data->password); |
| 77 | } |
Marc Kupietz | a57befa | 2023-03-06 21:39:23 +0100 | [diff] [blame] | 78 | |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 79 | function init_from_array(array $data) |
| 80 | { |
| 81 | foreach ($data as $key => $value) { |
| 82 | if (array_key_exists($key, (array) $this)) { |
| 83 | if (is_bool(gettype($this->{$key})) && is_string($value)) |
| 84 | $this->{$key} = !empty($value); |
| 85 | else |
| 86 | $this->{$key} = $value; |
| 87 | } |
| 88 | } |
| 89 | if (!empty($data["password"])) $this->set_password($data["password"]); |
| 90 | } |
| 91 | |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 92 | |
| 93 | function set_password(string $password) |
| 94 | { |
| 95 | include 'config.php'; |
| 96 | if ($ENCRYPT_PASSWORDS) { |
| 97 | $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$'); |
| 98 | # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true)); |
| 99 | } else { |
| 100 | $this->user_hash = "{CLEAR}" . $password; |
| 101 | } |
| 102 | $this->password = $this->user_hash; |
| 103 | } |
| 104 | |
| 105 | function to_string() |
| 106 | { |
| 107 | $tmp_user = $this; |
Marc Kupietz | ce67631 | 2023-03-10 08:29:41 +0100 | [diff] [blame^] | 108 | $tmp_user->invoice = ""; |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 109 | $tmp_user->password = "***"; |
| 110 | $tmp_user->user_hash = "***"; |
| 111 | return json_encode($tmp_user); |
| 112 | } |
| 113 | |
| 114 | function backup_in_session() |
| 115 | { |
| 116 | global $_SESSION; |
| 117 | foreach ($this as $key => $value) { |
| 118 | $_SESSION[$key] = $value; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | function to_table() { |
| 123 | $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>"; |
| 124 | foreach ($this as $key => $value) { |
Marc Kupietz | ce67631 | 2023-03-10 08:29:41 +0100 | [diff] [blame^] | 125 | if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") { |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 126 | if (is_bool($value)) { |
| 127 | if ($value) $value = "yes"; |
| 128 | else $value = "no"; |
Marc Kupietz | 87a1431 | 2023-03-09 20:39:31 +0100 | [diff] [blame] | 129 | } elseif(is_float($value)) { |
| 130 | $key .= " €"; |
Marc Kupietz | d871d88 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 131 | } |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 132 | $value = str_replace("\r\n", "<br>", $value); |
| 133 | $key = str_replace("_", " ", ucfirst($key)); |
| 134 | $table .= " <tr> |
| 135 | <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td> |
| 136 | <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td> |
| 137 | </tr>\n"; |
| 138 | } |
Marc Kupietz | d871d88 | 2023-03-05 18:34:16 +0100 | [diff] [blame] | 139 | } |
Marc Kupietz | 3417c88 | 2023-03-07 12:03:21 +0100 | [diff] [blame] | 140 | $table .= "</table>"; |
| 141 | return $table; |
| 142 | } |
| 143 | } |