| <?php | 
 | require_once 'vendor/autoload.php'; | 
 | include_once 'utils.php'; | 
 |  | 
 | class User | 
 | { | 
 |     public $id; | 
 |     public $username; | 
 |     public $first_name; | 
 |     public $last_name; | 
 |     public $organization; | 
 |     public $user_hash; | 
 |     public $password; | 
 |     public $street; | 
 |     public $zip; | 
 |     public $city; | 
 |     public $country; | 
 |     public $email; | 
 |     public $phone; | 
 |     public bool $eula_signed; | 
 |     public bool $privacy_policy_signed; | 
 |     public bool $author; | 
 |     public $accepted_paper_id; | 
 |     public bool $participation_confirmed; | 
 |     public $participation_confirmed_at; | 
 |     public bool $student; | 
 |     public bool $conference_dinner; | 
 |     public bool $vegetarian_dinner; | 
 |     public $registered_at; | 
 |     public bool $earlybird_registration; | 
 |     public $lunch_day_1; | 
 |     public $lunch_day_2; | 
 |     public $lunch_day_3; | 
 |     public float $total_due; | 
 |     public $invoice; | 
 |  | 
 |     function __construct() | 
 |     { | 
 |         $this->id = ""; | 
 |         $this->username = ""; | 
 |         $this->first_name = ""; | 
 |         $this->last_name = ""; | 
 |         $this->email = ""; | 
 |         $this->organization = ""; | 
 |         $this->user_hash = ""; | 
 |         $this->password = ""; | 
 |         $this->city = ""; | 
 |         $this->country = ""; | 
 |         $this->zip = ""; | 
 |         $this->street = ""; | 
 |         $this->phone = ""; | 
 |         $this->eula_signed = false; | 
 |         $this->privacy_policy_signed = false; | 
 |         $this->author = false; | 
 |         $this->accepted_paper_id = ""; | 
 |         $this->participation_confirmed = false; | 
 |         $this->participation_confirmed_at = ""; | 
 |         $this->student = false; | 
 |         $this->conference_dinner = false; | 
 |         $this->vegetarian_dinner = false; | 
 |         $this->registered_at = date("Y-m-d H:i:s") . "UTC"; | 
 |         $this->earlybird_registration = false; | 
 |         $this->total_due = 0.0; | 
 |         $this->invoice = ""; | 
 |     } | 
 |  | 
 |     function __construct1(object $data) | 
 |     { | 
 |         foreach ($data as $key => $value) { | 
 |             if (array_key_exists($key, (array) $this)) | 
 |                 $this->{$key} = $value; | 
 |         } | 
 |         if (isset($data->password)) $this->set_password($data->password); | 
 |     } | 
 |  | 
 |     function init_from_object(object $data) | 
 |     { | 
 |         foreach ($data as $key => $value) { | 
 |             if (array_key_exists($key, (array) $this)) | 
 |                 $this->{$key} = $value; | 
 |         } | 
 |         if (isset($data->password)) $this->set_password($data->password); | 
 |     } | 
 |  | 
 |     function init_from_array(array $data) | 
 |     { | 
 |         foreach ($data as $key => $value) { | 
 |             if (array_key_exists($key, (array) $this)) { | 
 |                 if (is_bool(gettype($this->{$key})) && is_string($value)) | 
 |                     $this->{$key} = !empty($value); | 
 |                 else | 
 |                     $this->{$key} = $value; | 
 |             } | 
 |         } | 
 |         if (!empty($data["password"])) $this->set_password($data["password"]); | 
 |     } | 
 |  | 
 |  | 
 |     function set_password(string $password) | 
 |     { | 
 |         include 'config.php'; | 
 |         if ($CONFERENCE_REGISTRATION) { | 
 |             $this->password = generateRandomString(32); | 
 |             # $this->user_hash = "{SHA}" .  base64_encode(sha1($password, true)); | 
 |         } else { | 
 |             if ($ENCRYPT_PASSWORDS) { | 
 |                 $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$'); | 
 |                 # $this->user_hash = "{SHA}" .  base64_encode(sha1($password, true)); | 
 |             } else { | 
 |                 $this->user_hash = "{CLEAR}" . $password; | 
 |             } | 
 |             $this->password = $this->user_hash; | 
 |         } | 
 |     } | 
 |  | 
 |     function to_string() | 
 |     { | 
 |         $tmp_user = $this; | 
 |         $tmp_user->invoice = ""; | 
 |         $tmp_user->password = "***"; | 
 |         $tmp_user->user_hash = "***"; | 
 |         return  json_encode($tmp_user); | 
 |     } | 
 |  | 
 |     function backup_in_session() | 
 |     { | 
 |         global $_SESSION; | 
 |         foreach ($this as $key => $value) { | 
 |             $_SESSION[$key] = $value; | 
 |         } | 
 |     } | 
 |  | 
 |     function to_table() { | 
 |         $table = "<table  style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>"; | 
 |         foreach ($this as $key => $value) { | 
 |             if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") { | 
 |                 if (is_bool($value)) { | 
 |                     if ($value) $value = "yes"; | 
 |                     else $value = "no"; | 
 |                 } elseif(is_float($value)) { | 
 |                     $key .= " €"; | 
 |                     $value = number_format($value, 2, '.', ' '); | 
 |                 } | 
 |                 $value = str_replace("\r\n", "<br>", $value); | 
 |                 $key = str_replace("_", " ", ucfirst($key)); | 
 |                 $table .= " <tr> | 
 |   <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td> | 
 |   <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td> | 
 |  </tr>\n"; | 
 |             } | 
 |         } | 
 |         $table .= "</table>"; | 
 |         return $table; | 
 |     } | 
 | } |