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