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