Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
design_area_login_form.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/designs/design_area/design_area.inc';
19 
32 {
33 
34 
46  public function printVar($var, Array $args, $value_prefix='', $value_suffix='')
47  {
48  // make sure that this var is being painted only within its valid sections
49  switch ($var) {
50  case 'form_open' :
51  case 'form_close' :
52  case 'submit_button' :
53  if ($this->_tmp['painting_section'] != 'login' && $this->_tmp['painting_section'] != 'logout') {
54  trigger_localised_error('CORE0178', E_USER_WARNING, $var, $this->attr('id_name'));
55  return FALSE;
56  }
57  break;
58 
59  case 'login_message' :
60  case 'username_box' :
61  case 'password_box' :
62  if ($this->_tmp['painting_section'] != 'login') {
63  trigger_localised_error('CORE0179', E_USER_WARNING, $var, $this->attr('id_name'));
64  return FALSE;
65  }
66  break;
67 
68  }// end switch
69 
70  // this is needed by a couple of vars
71  $referer = '(isset($_POST[\'SQ_LOGIN_REFERER\']) ? $_POST[\'SQ_LOGIN_REFERER\'] : (empty($_SERVER[\'HTTP_REFERER\']) ? \'\' : $_SERVER[\'HTTP_REFERER\']))';
72 
73  switch ($var) {
74  case 'login_heading' :
75  echo '<', '?php if (!empty($GLOBALS[\'SQ_LOGIN_FORM\'])) { echo ', $this->_escapeVar('$GLOBALS[\'SQ_LOGIN_FORM\'][\'heading\']', $args), '; } ?', '>';
76  break;
77 
78  case 'login_message' :
79  echo '<', '?php if (!empty($GLOBALS[\'SQ_LOGIN_FORM\'])) { echo ', $this->_escapeVar('$GLOBALS[\'SQ_LOGIN_FORM\'][\'msg\']', $args), '; } ?', '>';
80  break;
81 
82  case 'referer' :
83  echo '<', '?php echo ', $this->_escapeVar($referer, $args), '; ?', '>';
84  break;
85 
86  case 'form_open' :
87 
88  $qry_str_extra = '';
89  if ($this->attr('forward_www_vars')) {
90  $qry_str_extra = '&amp;<'.'?php echo htmlentities(preg_replace(\'/SQ_ACTION=[^\&]+\&?/\', \'\', $_SERVER[\'QUERY_STRING\'])); ?'.'>';
91  }
92 
93  // open login form
94  if ($this->_tmp['painting_section'] == 'login') {
95  echo '
96  <form action="<', '?php echo $_SERVER[\'PHP_SELF\']; ?','>?SQ_ACTION=login'.$qry_str_extra.'" id="'.$this->attr('id_name').'_login_prompt" method="post" onsubmit="return checkEntry();">
97  ';
98  // open logout form
99  } else {
100  echo '<form action="<', '?php echo $_SERVER[\'PHP_SELF\']; ?','>?SQ_ACTION=logout'.$qry_str_extra.'" id="'.$this->attr('id_name').'_login_prompt" method="post">
101  <input type="hidden" name="SQ_LOGIN_REFERER" value="<', '?php echo htmlspecialchars('.$referer.'); ?', '>" />';
102  }
103 
104  if ($this->attr('forward_www_vars')) {
105  echo '<', '?php
106  // Take all the post vars and whack em in the form - important ones are removed
107  require_once SQ_LIB_PATH.\'/html_form/html_form.inc\';
108  $'.$this->attr('id_name').'_post_vars = $_POST;
109  unset($'.$this->attr('id_name').'_post_vars[\'SQ_LOGIN_USERNAME\']);
110  unset($'.$this->attr('id_name').'_post_vars[\'SQ_LOGIN_PASSWORD\']);
111  unset($'.$this->attr('id_name').'_post_vars[\'SQ_LOGIN_KEY\']);
112  unset($'.$this->attr('id_name').'_post_vars[\'SQ_LOGIN_REFERER\']);
113  unset($'.$this->attr('id_name').'_post_vars[\'SQ_ACTION\']);
114  unset($'.$this->attr('id_name').'_post_vars[\'log_in_out_button\']);
115  var_to_hidden_field($'.$this->attr('id_name').'_post_vars);
116  ?', '>';
117  }// end if
118 
119  break;
120 
121  case 'form_close' :
122  echo '
123  </form>
124  <script type="text/javascript"><!--
125  //<![CDATA[
126  var loginForm = document.forms[\''.$this->attr('id_name').'_login_prompt\'];
127  function checkEntry() {
128  return (loginForm.SQ_LOGIN_USERNAME.value.length > 0 && loginForm.SQ_LOGIN_PASSWORD.value.length > 0);
129  }
130  //]]> -->
131  </script>
132  ';
133  break;
134 
135  case 'system_messages' :
136  echo '<', '?php echo implode(\'<br />\', $GLOBALS[\'SQ_SYSTEM\']->messages()); ?', '>';
137  break;
138 
139  case 'username_box' :
140  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
141  $extras = 'onfocus="this.select();"';
142  foreach ($args As $k => $v) {
143  if ($k == 'size') continue;
144  $extras .= ' '.$k.'="'.htmlspecialchars($v).'"';
145  }
146  echo '<input type="hidden" name="SQ_LOGIN_KEY" value="<', '?php echo $GLOBALS[\'SQ_SYSTEM\']->generateLoginKey(); ?', '>" />
147  <input type="hidden" name="SQ_LOGIN_REFERER" value="<', '?php echo htmlspecialchars('.$referer.'); ?', '>" />';
148 
149  text_box('SQ_LOGIN_USERNAME', '', empty($args['size']) ? 10 : $args['size'], 0, FALSE, $extras);
150  if ($this->attr('give_username_focus')) {
151  echo '
152  <script type="text/javascript"><!--
153  //<![CDATA[
154  var '.$this->attr('id_name').'_username_box_other_onload = (window.onload) ? window.onload : new Function;
155  function set_'.$this->attr('id_name').'_username_box_focus() {
156  '.$this->attr('id_name').'_username_box_other_onload();
157  document.getElementById("'.$this->attr('id_name').'_login_prompt").elements["SQ_LOGIN_USERNAME"].focus();
158  }
159  window.onload = set_'.$this->attr('id_name').'_username_box_focus;
160  //]]>-->
161  </script>
162  ';
163  }
164  break;
165 
166  case 'password_box' :
167  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
168  $extras = 'onfocus="this.select();"';
169  foreach ($args As $k => $v) {
170  if ($k == 'size') continue;
171  $extras .= ' '.$k.'="'.htmlspecialchars($v).'"';
172  }
173  password_box('SQ_LOGIN_PASSWORD', '', empty($args['size']) ? 10 : $args['size'], 0, $extras);
174  break;
175 
176  case 'submit_button' :
177  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
178  $extras = '';
179  foreach ($args As $k => $v) {
180  if ($k == 'value') continue;
181  $extras .= ' '.$k.'="'.htmlspecialchars($v).'"';
182  }
183  submit_button('log_in_out_button', empty($args['value']) ? ucfirst($this->_tmp['painting_section']) : $args['value'], '', $extras);
184  break;
185 
186  default :
187  parent::printVar($var, $args);
188  }//end switch
189 
190  }//end printVar()
191 
192 
199  public function canBeCached()
200  {
201  return FALSE;
202 
203  }//end canBeCached()
204 
205 
212  protected function _printInitCode()
213  {
214  echo '<', '?php
215  if (!empty($GLOBALS[\'SQ_LOGIN_FORM\'])) {
216  $'.$this->attr('id_name').'_paint_login = ($GLOBALS[\'SQ_LOGIN_FORM\'][\'paint\'] == \'login\');
217  } else {
218  $'.$this->attr('id_name').'_paint_login = $GLOBALS[\'SQ_SYSTEM\']->userPublic();
219  }
220  ?', '>';
221 
222  }//end _printInitCode()
223 
224 
233  protected function _printContentItemCode(Array $element)
234  {
235  switch (array_get_index($element, 'operation')) {
236  case 'login_section':
237  $this->_tmp['painting_section'] = 'login';
238  echo '<', '?php
239  if ($'.$this->attr('id_name').'_paint_login) {
240  // login section
241  ?', '>
242  ';
243  foreach ($this->attr('login_contents') as $item) {
244  parent::_printContentItemCode($item);
245  }
246  echo '
247  <', '?php
248  }//end login section
249  ?', '>';
250  $this->_tmp['painting_section'] = '';
251  break;
252 
253  case 'logout_section':
254  $this->_tmp['painting_section'] = 'logout';
255  echo '<', '?php
256  if (!$'.$this->attr('id_name').'_paint_login) {
257  // logout section
258  ?', '>
259  ';
260  foreach ($this->attr('logout_contents') as $item) {
261  parent::_printContentItemCode($item);
262  }
263  echo '
264  <', '?php
265  }//end logout section
266  ?', '>';
267  $this->_tmp['painting_section'] = '';
268  break;
269 
270  default :
271  return parent::_printContentItemCode($element);
272 
273  }//end switch
274 
275  }//end _printContentItemCode()
276 
277 
287  public function getProtectedAttrs()
288  {
289  $res = parent::getProtectedAttrs();
290  $res[] = 'login_contents';
291  $res[] = 'logout_contents';
292  return $res;
293 
294  }//end getProtectedAttrs()
295 
296 
297 }//end class
298 ?>