YaWK  24.1
Yet another WebKit
buildForm.php
Go to the documentation of this file.
1 <?php
2 namespace YAWK\PLUGINS\SIGNUP {
3  /**
4  * <b>Class buildForm</b>
5  * <p>serve all methods to draw the user signup form</p>
6  * @author Daniel Retzl <[email protected]>
7  * @version 1.0.0
8  */
10  {
11  /** * @param string html output */
12  public $html = '';
13  /** * @param string html form */
14  public $form = '';
15 
16  /**
17  * @brief initialize form (build it)
18  * @param object $db database
19  * @return string return html code
20  */
21  public function init($db){
22  $this->form = $this->buildForm($db);
23  return $this->html;
24  }
25 
26  /**
27  * @brief loads the header, layout and footer of the form
28  * @param object $db database
29  * @return string return html form
30  */
31  public function buildForm($db){
32  $this->form .= $this->getHeader();
33  $this->form .= $this->getLayout($db);
34  $this->form .= $this->getFooter();
35  return $this->form;
36  }
37 
38  /**
39  * @brief build the form
40  * @param object $db database
41  * @return string return html form
42  */
43  public function getForm($db){
44  $this->form .= $this->getGroupSelect($db);
45  $this->form .= $this->getMandatoryFields();
46  $this->form .= $this->getAdditionalFields($db);
47  $this->form .= $this->getTerms($db);
48  $this->form .= $this->getSubmitButton($db);
49  return $this->form;
50  }
51 
52  /**
53  * @brief get form header
54  */
55  public function getHeader()
56  {
57  // form header
58  $this->html .= "<form id=\"form\" action=\"welcome.html\" method=\"POST\">";
59  }
60 
61  /**
62  * @brief get form title
63  * @param object $db database
64  */
65  public function getTitle($db)
66  {
67  // form title
68  $this->html .= \YAWK\settings::getSetting($db, "signup_title");
69  }
70 
71  /**
72  * @brief get form legend
73  * @param object $db database
74  */
75  public function getLegend($db)
76  {
77  // gid 0 form legend (public) -- default --
78  $this->html .= "<div id=\"0_hidden\">";
79  $this->html .= \YAWK\settings::getLongSetting($db, "signup_legend0");
80  $this->html .= "</div>";
81  // gid 1 form legend (guest)
82  $this->html .= "<div id=\"1_hidden\">";
83  $this->html .= \YAWK\settings::getLongSetting($db, "signup_legend1");
84  $this->html .= "</div>";
85  // gid 1 form legend (guest)
86  $this->html .= "<div id=\"2_hidden\">";
87  $this->html .= \YAWK\settings::getLongSetting($db, "signup_legend2");
88  $this->html .= "</div>";
89  // gid 1 form legend (guest)
90  $this->html .= "<div id=\"3_hidden\">";
91  $this->html .= \YAWK\settings::getLongSetting($db, "signup_legend3");
92  $this->html .= "</div>";
93  // gid 1 form legend (guest)
94  $this->html .= "<div id=\"4_hidden\">";
95  $this->html .= \YAWK\settings::getLongSetting($db, "signup_legend4");
96  $this->html .= "</div>";
97  // gid 1 form legend (guest)
98  $this->html .= "<div id=\"5_hidden\">";
99  $this->html .= \YAWK\settings::getLongSetting($db, "signup_legend5");
100  $this->html .= "</div>";
101  }
102 
103  /**
104  * @brief build form on depending layout
105  * @param object $db database
106  */
107  public function getLayout($db)
108  {
109  // get selected form layout (left, right, 1,2, or 3 cols...)
110  $layout = \YAWK\settings::getSetting($db, "signup_layout");
111  // layout row
112  // switch case layout and load corresponding htmlcode
113  switch ($layout) {
114  case "left":
115  // form title
116  $this->html .= "<div class=\"col-md-6\">";
117  $this->html .= self::getLegend($db);
118  $this->html .= "</div>";
119  $this->html .= "<div class=\"col-md-6\">";
120  $this->html .= self::getTitle($db);
121  $this->html .= self::getForm($db);
122  $this->html .= "</div>";
123  break;
124  case "right":
125  $this->html .= "<div class=\"col-md-6\">";
126  $this->html .= self::getTitle($db);
127  $this->html .= self::getForm($db);
128  $this->html .= "</div><div class=\"col-md-6\">";
129  $this->html .= self::getLegend($db);
130  $this->html .= "</div>";
131  break;
132  case "plain":
133  $this->html .= "<div class=\"col-lg-12\">";
134  $this->html .= self::getTitle($db);
135  $this->html .= self::getForm($db);
136  $this->html .= "</div>";
137  break;
138  case "center":
139  $this->html .= "<div class=\"col-md-4\">&nbsp;</div>";
140  $this->html .= "<div class=\"col-md-4\">";
141  $this->html .= self::getTitle($db);
142  $this->html .= self::getForm($db);
143  $this->html .= "</div>";
144  $this->html .= "<div class=\"col-md-4\">&nbsp;</div>";
145  break;
146  }
147  }
148 
149  /**
150  * @brief html form footer (closing tag)
151  */
152  public function getFooter(){
153  // form end
154  $this->html .= "</form>";
155  }
156 
157  /**
158  * @brief get and return a select field with all groups as option values
159  * @param object $db database
160  */
161  public function getGroupSelect($db)
162  { /** @var $db \YAWK\db */
163  if (\YAWK\settings::getSetting($db, "signup_gid") === '1')
164  { // user group select field is allowed, fetch groups...
165  if ($res = $db->query("SELECT * FROM {user_groups} WHERE signup_allowed = '1'"))
166  { // and build select field
167  $this->html.= "<label for=\"gid\">Signup as:</label>
168  <select id=\"gid\" name=\"gid\" class=\"form-control\">
169  <option value=\"\" disabled selected>please select</option>";
170  while ($row = mysqli_fetch_assoc($res))
171  { // loop items
172  $this->html .= "<option value=\"".$row['id']."\">".$row['value']."</option>";
173  }
174  $this->html .= "</select>";
175  }
176  }
177  else
178  { // empty html, because signup group selector (signup_gid) is disabled
179  $this->html .= "";
180  }
181  }
182 
183  /**
184  * @brief draw html output: all mandatory fields
185  */
186  public function getMandatoryFields(){
187  $this->html .= "<label for=\"username\">Username</label>
188  <input type=\"text\" id=\"username\" name=\"username\" class=\"form-control\" placeholder=\"Benutzername\">
189 
190  <label for=\"email\">Email</label>
191  <input type=\"text\" id=\"email\" name=\"email\" class=\"form-control\" placeholder=\"[email protected]\">
192 
193  <label for=\"password1\">Password</label>
194  <input type=\"password\" id=\"password1\" name=\"password1\" class=\"form-control\" placeholder=\"Passwort\">
195 
196  <label for=\"password2\">Password (repeat)</label>
197  <input type=\"password\" id=\"password2\" name=\"password2\" class=\"form-control\" placeholder=\"Passwort wiederholen\">
198  <input type=\"hidden\" name=\"sent\" value=\"1\">";
199  }
200 
201  /**
202  * @brief draw html output: checkbox for terms of service
203  * @param $db
204  */
205  public function getTerms($db){
206  $this->html .= "<input type=\"checkbox\" id=\"checkTerms\" name=\"checkTerms\" class=\"form-control\" checked=\"checked\">
207  <div class=\"text-center\">
208  <label for=\"checkTerms\">
209  <a target=\"_blank\" style=\"color:#";$this->html .= \YAWK\settings::getSetting($db, "signup_toscolor");$this->html .= "\" href=\"";$this->html .= \YAWK\settings::getSetting($db, "signup_tospage");$this->html .= ".html\">";$this->html .= \YAWK\settings::getSetting($db, "signup_tostext"); $this->html .= "</a> akzeptieren</label>
210  </div>";
211  }
212 
213  /**
214  * @brief draw html output of all additional fields
215  * @param object $db database
216  */
217  public function getAdditionalFields($db){
218  // get additional field settings from db
219  $firstname = \YAWK\settings::getSetting($db, "signup_firstname");
220  $lastname = \YAWK\settings::getSetting($db, "signup_lastname");
221  $street = \YAWK\settings::getSetting($db, "signup_street");
222  $zipcode = \YAWK\settings::getSetting($db, "signup_zipcode");
223  $city = \YAWK\settings::getSetting($db, "signup_city");
224  $country = \YAWK\settings::getSetting($db, "signup_country");
225  // check if fields are required
226  if ($firstname ==='1'){
227  $this->html .= "<label for=\"firstname\">Firstname</label>
228  <input type=\"text\" id=\"firstname\" name=\"firstname\" class=\"form-control\" placeholder=\"Vorname\">";
229  }
230  if ($lastname ==='1'){
231  $this->html .= "<label for=\"lastname\">Lastname</label>
232  <input type=\"text\" id=\"lastname\" name=\"lastname\" class=\"form-control\" placeholder=\"Nachname\">";
233  }
234  if ($street ==='1'){
235  $this->html .= "<label for=\"street\">Street</label>
236  <input type=\"text\" id=\"street\" name=\"street\" class=\"form-control\" placeholder=\"Stra&szlig;e\">";
237  }
238  if ($zipcode ==='1'){
239  $this->html .= "<label for=\"zipcode\">ZIP Code</label>
240  <input type=\"text\" id=\"zipcode\" name=\"zipcode\" class=\"form-control\" placeholder=\"Postleitzahl\">";
241  }
242  if ($city ==='1'){
243  $this->html .= "<label for=\"city\">City</label>
244  <input type=\"text\" id=\"city\" name=\"city\" class=\"form-control\" placeholder=\"Stadt\">";
245  }
246  if ($country ==='1'){
247  $this->html .= "<label for=\"country\">Country</label>
248  <input type=\"text\" id=\"country\" name=\"country\" class=\"form-control\" placeholder=\"Land\">";
249  }
250  }
251 
252  /**
253  * @brief draw the submit button
254  * @param object $db database
255  */
256  public function getSubmitButton($db){
257  // get selected form layout (left, right, 1,2, or 3 cols...)
258  $layout = \YAWK\settings::getSetting($db, "signup_layout");
259  $btnStyle = \YAWK\settings::getSetting($db, "signup_submitstyle");
260  $btnText = \YAWK\settings::getSetting($db, "signup_submittext");
261  if ($layout === 'center' or $layout === 'plain'){
262  $this->html .= "<div class=\"text-center\"><input type=\"submit\" class=\"btn btn-$btnStyle\" value=\"$btnText\"></div>";
263  } else {
264  $this->html .= "<br><input type=\"submit\" class=\"btn btn-$btnStyle\" value=\"$btnText\">";
265  }
266  }
267 
268  }
269 }
init($db)
initialize form (build it)
Definition: buildForm.php:21
getTitle($db)
get form title
Definition: buildForm.php:65
getLayout($db)
build form on depending layout
Definition: buildForm.php:107
getTerms($db)
draw html output: checkbox for terms of service
Definition: buildForm.php:205
getMandatoryFields()
draw html output: all mandatory fields
Definition: buildForm.php:186
getSubmitButton($db)
draw the submit button
Definition: buildForm.php:256
getHeader()
get form header
Definition: buildForm.php:55
getForm($db)
build the form
Definition: buildForm.php:43
getAdditionalFields($db)
draw html output of all additional fields
Definition: buildForm.php:217
getFooter()
html form footer (closing tag)
Definition: buildForm.php:152
getLegend($db)
get form legend
Definition: buildForm.php:75
buildForm($db)
loads the header, layout and footer of the form
Definition: buildForm.php:31
Handles the Blog System.
Definition: signup.php:15
static getSetting($db, $property)
Get and return value for property from settings database.
Definition: settings.php:470
static getLongSetting($db, $property)
Get and return longValue for property from settings database.
Definition: settings.php:527
This class serves methods to create backup from files.
Definition: AdminLTE.php:2
if(isset($_POST['sent'])) $layout
Definition: signup.php:98
$country
Definition: user-new.php:100
$lastname
Definition: user-new.php:96
$firstname
Definition: user-new.php:95
$city
Definition: user-new.php:99
$zipcode
Definition: user-new.php:98
$street
Definition: user-new.php:97