dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
dbxUser_profil.class.php
Go to the documentation of this file.
1<?php
2namespace dbx\dbxUser;
3
5
6 private string $ddUser = 'dbxUser';
7
8 private function design_options(): array {
9 $options = array();
10 foreach (glob(dbx_get_base_dir() . 'dbx/design/*', GLOB_ONLYDIR) ?: array() as $dir) {
11 $name = basename($dir);
12 if ($name !== '') {
13 $options[$name] = $name;
14 }
15 }
16
17 return $options ?: array('dbxapp' => 'dbxapp');
18 }
19
20 private function color_options(): array {
21 return array(
22 'hell' => 'Hell',
23 'gelb' => 'Gelb',
24 'rot' => 'Rot',
25 'gruen' => 'Gruen',
26 'blau' => 'Blau',
27 'dunkel' => 'Dunkel',
28 );
29 }
30
31 public function run() {
32 $uid = (int)dbx()->user();
33
34 $db = dbx()->get_system_obj('dbxDB');
35 $data = $db->select1($this->ddUser, $uid);
36 if (!is_array($data)) {
37 return '<div class="alert alert-warning">Benutzerprofil nicht gefunden.</div>';
38 }
39 $data['password_new'] = '';
40 $data['password_new2'] = '';
41 $designOptions = $this->design_options();
42 $colorOptions = $this->color_options();
43 if (!isset($designOptions[(string)($data['design'] ?? '')])) {
44 $data['design'] = array_key_first($designOptions);
45 }
46 if (!isset($colorOptions[(string)($data['color'] ?? '')])) {
47 $data['color'] = 'hell';
48 }
49
50 $oForm = dbx()->get_system_obj('dbxForm');
51 $oForm->init('dbxUser_profil', 'form-profil');
52 $oForm->set_workflow_scope('self-' . $uid);
53 $oForm->_dd = $this->ddUser;
54 $oForm->_fld_id = 'id';
55 $oForm->_data = $data;
56 $oForm->_msg_info = 'Eigene Benutzer- und Profileinstellungen bearbeiten.';
57 $oForm->_action = '?dbx_modul=dbxUser&dbx_run1=user&dbx_run2=edit_profil';
58 $oForm->set_activ_id($uid);
59 $oForm->_rid = $uid;
60 $oForm->set_state_value('rid', $uid);
61 $oForm->add_module_bar(
62 'Mein Profil',
63 'bi-person-circle',
64 'Eigene Stammdaten, Kontakt, Adresse und Oberflaeche'
65 );
66 $oForm->prepare_form_shell(array(
67 'class' => 'dbx-user-profile-form',
68 'form_attrs' => 'enctype="multipart/form-data"',
69 ));
70 $oForm->add_module_bar_form_actions(array(
71 'save' => true,
72 'delete' => false,
73 'reload' => true,
74 'reload_url' => '?dbx_modul=dbxUser&dbx_run1=user&dbx_run2=edit_profil',
75 ));
76
77 $avatarObj = dbx()->get_include_obj('dbxUser_avatar');
78 $oForm->add_obj('obs_rid', 'dbx|observe', 'name=usr_rid&value=' . (int)$uid);
79 $oForm->add_obj('avatar', 'obj-value', $avatarObj->run());
80
81 $oForm->add_fld('name', 'text-label', 'Name', 'varchar|max=255');
82 $oForm->add_fld('name2', 'text-label', 'Zusatz', 'varchar|max=255');
83 $oForm->add_fld('email', 'text-label', 'E-Mail', 'email|max=255');
84 $oForm->add_fld('telefon', 'text-label', 'Telefon', 'varchar|max=64');
85 $oForm->add_fld('handy', 'text-label', 'Mobil', 'varchar|max=64');
86 $oForm->add_fld('strasse', 'text-label', 'Strasse', 'varchar|max=255');
87 $oForm->add_fld('plz', 'text-label', 'PLZ', 'varchar|max=16');
88 $oForm->add_fld('ort', 'text-label', 'Ort', 'varchar|max=255');
89 $oForm->add_fld('land', 'text-label', 'Land', 'parameter|max=32');
90 $oForm->add_fld('language', 'select-single-label', 'Sprache', 'parameter|max=3', options: array('de' => 'Deutsch', 'en' => 'English'));
91 $oForm->add_fld('design', 'select-single-label', 'Design', 'parameter|max=32', options: $designOptions);
92 $oForm->add_fld('color', 'select-single-label', 'Farbe', 'parameter|max=32', options: $colorOptions);
93 $oForm->add_fld('password_new', 'password-label', 'Neues Passwort', 'varchar|max=128', placeholder: 'Leer lassen, wenn es unveraendert bleiben soll');
94 $oForm->add_fld('password_new2', 'password-label', 'Passwort wiederholen', 'varchar|max=128', placeholder: 'Neues Passwort erneut eingeben');
95
96
97 if ($oForm->submit()) {
98 $passwordNew = (string)$oForm->get_post_data('password_new', '', '*');
99 $passwordNew2 = (string)$oForm->get_post_data('password_new2', '', '*');
100 $passwordChanged = false;
101
102 if ($passwordNew !== '' || $passwordNew2 !== '') {
103 if ($passwordNew !== $passwordNew2) {
104 $oForm->add_fld_error('password_new2', 'Die Passwoerter stimmen nicht ueberein.');
105 } elseif (mb_strlen($passwordNew) < 6) {
106 $oForm->add_fld_error('password_new', 'Das Passwort muss mindestens 6 Zeichen lang sein.');
107 } else {
108 $passwordChanged = true;
109 }
110 }
111
112 if (!$oForm->errors() && !$oForm->warnings()) {
113 $values = array(
114 'name' => $oForm->get_post('name', '', 'varchar|max=255'),
115 'name2' => $oForm->get_post('name2', '', 'varchar|max=255'),
116 'email' => $oForm->get_post('email', '', 'email|max=255'),
117 'telefon' => $oForm->get_post('telefon', '', 'varchar|max=64'),
118 'handy' => $oForm->get_post('handy', '', 'varchar|max=64'),
119 'strasse' => $oForm->get_post('strasse', '', 'varchar|max=255'),
120 'plz' => $oForm->get_post('plz', '', 'varchar|max=16'),
121 'ort' => $oForm->get_post('ort', '', 'varchar|max=255'),
122 'land' => $oForm->get_post('land', '', 'parameter|max=32'),
123 'language' => $oForm->get_post('language', 'de', 'parameter|max=3'),
124 'design' => $oForm->get_post('design', (string)array_key_first($designOptions), 'parameter|max=32'),
125 'color' => $oForm->get_post('color', 'hell', 'parameter|max=32'),
126 'settings' => $oForm->get_post('settings', '', '*'),
127 );
128 if (!isset($designOptions[$values['design']])) {
129 $values['design'] = (string)array_key_first($designOptions);
130 }
131 if (!isset($colorOptions[$values['color']])) {
132 $values['color'] = 'hell';
133 }
134 if ($passwordChanged) {
135 $values['pass'] = password_hash($passwordNew, PASSWORD_DEFAULT);
136 }
137
138 $ok = $db->update($this->ddUser, $values, $uid);
139 $avatarSaved = false;
140 $avatarError = '';
141 if ($ok && is_object($avatarObj) && method_exists($avatarObj, 'save_upload')) {
142 $avatarSaved = $avatarObj->save_upload($uid, $db, $data, $avatarError);
143 if ($avatarError !== '') {
144 $ok = false;
145 $oForm->_msg_error = $avatarError;
146 }
147 }
148 $oForm->_msg_success = $ok
149 ? ($passwordChanged && $avatarSaved
150 ? 'Profil, Passwort und Profilbild gespeichert.'
151 : ($passwordChanged
152 ? 'Profil und Passwort gespeichert.'
153 : ($avatarSaved ? 'Profil und Profilbild gespeichert.' : 'Profil gespeichert.')))
154 : 'Profil konnte nicht gespeichert werden.';
155 } else {
156 $oForm->_msg_error = 'Pruefen sie bitte ihre Eingaben.';
157 }
158 }
159
160 return $oForm->run();
161 }
162}
163?>
dbx_get_base_dir($cut_Data=0)
Definition index.php:157
DBX schema administration.