Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
design_area_password_change_form.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/designs/design_area/design_area.inc';
19 
33 {
34 
35 
42  function __construct($assetid=0)
43  {
44  parent::__construct($assetid);
45 
46  }//end constructor
47 
48 
60  public function printVar($var, Array $args, $value_prefix='', $value_suffix='')
61  {
62 
63  // make sure that this var is being painted only within it's valid sections
64  switch ($var) {
65  case 'form_open' :
66  case 'form_close' :
67  case 'submit_button' :
68  case 'password_change_message' :
69  case 'password_old_box' :
70  case 'password_new_box' :
71  case 'password_confirm_box' :
72  if ($this->_tmp['painting_section'] != 'password_change') {
73  trigger_localised_error('CORE0179', E_USER_WARNING, $var, $this->attr('id_name'));
74  return FALSE;
75  }
76  break;
77 
78  }// end switch
79 
80  switch ($var) {
81  case 'password_change_heading' :
82  echo '<', '?php if (!empty($GLOBALS[\'SQ_PASSWORD_CHANGE_FORM\'])) { echo ', $this->_escapeVar('$GLOBALS[\'SQ_PASSWORD_CHANGE_FORM\'][\'heading\']', $args), '; } ?', '>';
83  break;
84 
85  case 'password_change_message' :
86  echo '<', '?php if (!empty($GLOBALS[\'SQ_PASSWORD_CHANGE_FORM\'])) { echo ', $this->_escapeVar('$GLOBALS[\'SQ_PASSWORD_CHANGE_FORM\'][\'msg\']', $args), '; } ?', '>';
87  break;
88 
89  case 'form_open' :
90 
91  $qry_str_extra = '';
92  if ($this->attr('forward_www_vars')) {
93  $qry_str_extra = '&amp;<'.'?php echo htmlentities(preg_replace(\'/SQ_ACTION=[^\&]+\&?/\', \'\', $_SERVER[\'QUERY_STRING\'])); ?'.'>';
94  }
95 
96  // open change password form
97  if ($this->_tmp['painting_section'] == 'password_change') {
98  echo '<form action="<', '?php echo $_SERVER[\'PHP_SELF\']; ?','>?SQ_ACTION=password_change'.$qry_str_extra.'" id="'.$this->attr('id_name').'_password_change_prompt" method="post" onsubmit="return checkEntry();">';
99  // open logout form
100  } else {
101  echo '<form action="<', '?php echo $_SERVER[\'PHP_SELF\']; ?','>?SQ_ACTION=logout'.$qry_str_extra.'" id="'.$this->attr('id_name').'_password_change_prompt" method="post">';
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_PASSWORD_CHANGE_OLD\']);
110  unset($'.$this->attr('id_name').'_post_vars[\'SQ_PASSWORD_CHANGE_NEW\']);
111  unset($'.$this->attr('id_name').'_post_vars[\'SQ_PASSWORD_CHANGE_CONFIRM\']);
112  unset($'.$this->attr('id_name').'_post_vars[\'SQ_ACTION\']);
113  var_to_hidden_field($'.$this->attr('id_name').'_post_vars);
114  ?', '>';
115  }// end if
116 
117  break;
118 
119  case 'form_close' :
120  echo '</form>
121  <script type="text/javascript"><!--
122  //<![CDATA[
123  var passwordChangeForm = document.forms[\''.$this->attr('id_name').'_password_change_prompt\'];
124  function checkEntry() {
125  return (passwordChangeForm.SQ_PASSWORD_CHANGE_OLD.value.length > 0 && passwordChangeForm.SQ_PASSWORD_CHANGE_NEW.value.length > 0 && passwordChangeForm.SQ_PASSWORD_CHANGE_CONFIRM.value.length > 0);
126  }
127  //]]> -->
128  </script>
129  ';
130  break;
131 
132  case 'system_messages' :
133  echo '<', '?php echo implode(\'<br/>\', $GLOBALS[\'SQ_SYSTEM\']->messages()); ?', '>';
134  break;
135 
136  case 'password_old_box' :
137  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
138  $extras = 'onfocus="this.select();"';
139  foreach ($args As $k => $v) {
140  if ($k = 'size') continue;
141  $extras .= ' '.$k.'="'.htmlspecialchars($v).'"';
142  }
143  password_box('SQ_PASSWORD_CHANGE_OLD', '', empty($args['size']) ? 10 : $args['size'], 0, $extras);
144  if ($this->attr('give_password_old_focus')) {
145  echo '<script type="text/javascript"><!--
146  //<![CDATA[
147  function set_'.$this->attr('id_name').'_password_old_box_focus() {
148  document.getElementById("'.$this->attr('id_name').'_password_change_prompt").elements["SQ_PASSWORD_CHANGE_OLD"].focus();
149  }
150  window.onload = set_'.$this->attr('id_name').'_password_old_box_focus;
151  //]]>
152  -->
153  </script>';
154  }
155  break;
156 
157  case 'password_new_box' :
158  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
159  $extras = 'onfocus="this.select();"';
160  foreach ($args As $k => $v) {
161  if ($k = 'size') continue;
162  $extras .= ' '.$k.'="'.htmlspecialchars($v).'"';
163  }
164  password_box('SQ_PASSWORD_CHANGE_NEW', '', empty($args['size']) ? 10 : $args['size'], 0, $extras);
165  break;
166 
167  case 'password_confirm_box' :
168  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
169  $extras = 'onfocus="this.select();"';
170  foreach ($args As $k => $v) {
171  if ($k = 'size') continue;
172  $extras .= ' '.$k.'="'.htmlspecialchars($v).'"';
173  }
174  password_box('SQ_PASSWORD_CHANGE_CONFIRM', '', empty($args['size']) ? 10 : $args['size'], 0, $extras);
175  break;
176 
177  case 'submit_button' :
178  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
179  $extras = '';
180  foreach ($args As $k => $v) {
181  if ($k == 'value') continue;
182  $extras .= ' '.$k.'="'.htmlspecialchars($v).'"';
183  }
184  submit_button('change_password_logout_button', empty($args['value']) ? ucfirst($this->_tmp['painting_section']) : $args['value'], '', $extras);
185  break;
186 
187  case 'password_rules_note':
188  echo '<','?php
189  echo $GLOBALS["SQ_SYSTEM"]->user->getPasswordRulesDescription();
190  ?', '>';
191  break;
192 
193  default :
194  parent::printVar($var, $args);
195  }//end switch
196 
197  }//end printVar()
198 
199 
208  protected function _printContentItemCode(Array $element)
209  {
210  switch (array_get_index($element, 'operation')) {
211  case 'password_change_section':
212  $this->_tmp['painting_section'] = 'password_change';
213  foreach ($this->attr('password_change_contents') as $item) {
214  parent::_printContentItemCode($item);
215  }
216  $this->_tmp['painting_section'] = '';
217  break;
218 
219  default :
220  return parent::_printContentItemCode($element);
221 
222  }//end switch
223 
224  }//end _printContentItemCode()
225 
226 
236  public function getProtectedAttrs()
237  {
238  $res = parent::getProtectedAttrs();
239  $res[] = 'password_change_contents';
240  return $res;
241 
242  }//end getProtectedAttrs()
243 
244 
245 }//end class
246 ?>