Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_account_manager_edit_fns.inc
1 <?php
18 require_once dirname(__FILE__).'/../../page_templates/page_asset_builder/page_asset_builder_edit_fns.inc';
19 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
20 
33 {
34 
39  var $location_types = Array('user_group' => 'D');
40 
41 
46  function __construct()
47  {
48  parent::__construct();
49 
50  }//end constructor
51 
52 
63  function paintAddCreateType(&$asset, &$o, $prefix)
64  {
65  if (!$asset->writeAccess('attributes')) {
66  parent::paintAssetTypes($asset, $o, $prefix);
67  } else {
68  $user_types = $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants('user');
69 
70  $options = Array('user' => 'User');
71  foreach ($user_types as $type_code) {
72  $info = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type_code);
73  if ($info['allowed_access'] != 'system' && $info['instantiable']) {
74  $options[$type_code] = $info['name'];
75  }
76  }
77  combo_box($prefix.'_create_type', $options, FALSE, array_keys($asset->attr('create_type')));
78  }
79 
80  }//end paintAddCreateType()
81 
82 
96  function processAddCreateType(&$asset, &$o, $prefix)
97  {
98  if (isset($_POST[$prefix.'_create_type'])) {
99  $type = trim($_POST[$prefix.'_create_type']);
100  if (empty($type)) return FALSE;
101  $types = Array($type => TRUE);
102  $asset->setAttrValue('create_type', $types);
103  return TRUE;
104  }
105  return FALSE;
106 
107  }//end processAddCreateType()
108 
109 
120  function paintPostValidationRedirect(&$asset, &$o, $prefix)
121  {
122  return $this->paintNoticeLinkedAsset($asset, 'login_redirect');
123 
124  }//end paintPostValidationRedirect()
125 
126 
137  function processPostValidationRedirect(&$asset, &$o, $prefix)
138  {
139  return $this->processNoticeLinkedAsset($asset, 'login_redirect');
140 
141  }//end processPostValidationRedirect()
142 
143 
153  function usingEmailValidation(&$asset, $prefix)
154  {
155  return $asset->attr('use_email_validation');
156 
157  }//end usingEmailValidation()
158 
159 
170  function paintValidateAccounts(&$asset, &$o, $prefix)
171  {
172  $write_access = $asset->writeAccess('attributes');
173 
174  // grab the list of users currently waiting validation
175  $all_users = $asset->_getPendingUserIds();
176 
177  // pagination
178  $total_assets = count($all_users);
179  $num_per_page = 15;
180  $num_pages = ceil($total_assets / $num_per_page);
181 
182  $asset_offset = array_get_index($_POST, $prefix.'_asset_offset', 0);
183  hidden_field($prefix.'_asset_offset', $asset_offset);
184 
185  if ($num_pages <= 1) {
186  $users = $all_users;
187  } else {
188  $users = array_slice($all_users, $asset_offset, $num_per_page);
189  }
190 
191  ?>
192  <table class="sq-backend-table">
193  <tr>
194  <td class="sq-backend-table-header-header" <?php echo ($write_access ? 'colspan="4"' : ''); ?>>
195  <?php
196  if ($asset_offset > 0) {
197  ?><a title="<?php echo translate('pagination_go_to_first') ?>" style="text-decoration: none; color: #fff" href="#" onClick="Javascript: set_hidden_field('<?php echo $prefix ?>_asset_offset', '0'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
198  } else {
199  ?><span title="<?php echo translate('pagination_cannot_go_further_back') ?>" style="color: #333"><?php
200  }
201  ?>
202  &lt;&lt;
203  <?php
204  if ($asset_offset > 0) {
205  ?></a><?php
206  } else {
207  ?></span><?php
208  }
209  ?> &nbsp; &nbsp; <?php
210  if ($asset_offset > 0) {
211  ?><a title="<?php echo translate('pagination_go_to_previous') ?>" style="text-decoration: none; color: #fff" href="#" onClick="Javascript: set_hidden_field('<?php echo $prefix ?>_asset_offset', '<?php echo $asset_offset - $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
212  } else {
213  ?><span title="<?php echo translate('pagination_cannot_go_further_back') ?>" style="color: #333"><?php
214  }
215  ?>
216  &lt;
217  <?php
218  if ($asset_offset > 0) {
219  ?></a><?php
220  } else {
221  ?></span><?php
222  }
223  ?>
224  &nbsp; &nbsp; <?php echo translate('page_number', round(($asset_offset + $num_per_page) / $num_per_page), ($total_assets > 0 ? ceil($total_assets / $num_per_page) : 1)); ?> &nbsp; &nbsp;
225  <?php
226  if (($asset_offset + $num_per_page) < $total_assets) {
227  ?><a title="<?php echo translate('pagination_go_to_next') ?>" style="text-decoration: none; color: #fff" href="#" onClick="Javascript: set_hidden_field('<?php echo $prefix ?>_asset_offset', '<?php echo $asset_offset + $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
228  } else {
229  ?><span title="<?php echo translate('pagination_cannot_go_further_forward') ?>" style="color: #333"><?php
230  }
231  ?>
232  &gt;
233  <?php
234  if (($asset_offset + $num_per_page) < $total_assets) {
235  ?></a><?php
236  } else {
237  ?></span><?php
238  }
239  ?> &nbsp; &nbsp; <?php
240  if (($asset_offset + $num_per_page) < $total_assets) {
241  ?><a title="<?php echo translate('pagination_go_to_last') ?>" style="text-decoration: none; color: #fff" href="#" onClick="Javascript: set_hidden_field('<?php echo $prefix ?>_asset_offset', '<?php echo ($num_pages - 1) * $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
242  } else {
243  ?><span title="<?php echo translate('pagination_cannot_go_further_forward') ?>" style="color: #333"><?php
244  }
245  ?>
246  &gt;&gt;
247  <?php
248  if (($asset_offset + $num_per_page) < $total_assets) {
249  ?></a><?php
250  } else {
251  ?></span><?php
252  }
253  ?>
254  </td>
255  </tr>
256  <tr>
257  <td class="sq-backend-table-header"><?php echo translate('user'); ?></td>
258  <?php
259  if ($write_access) {
260  ?><td class="sq-backend-table-header"><?php echo translate('cms_account_manager_validate'); ?></td><?php
261  ?><td class="sq-backend-table-header"><?php echo translate('delete_question'); ?></td><?php
262  }
263  ?>
264  </tr>
265  <?php
266 
267  $user_details = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($users, Array(), TRUE, 'name');
268  foreach ($users as $userid) {
269  ?><tr>
270  <td class="sq-backend-table-cell"><?php echo get_asset_tag_line($userid, 'details'); ?></td>
271  <?php
272  if ($write_access) {
273  // javascript to uncheck the other option when one is checked
274  $name = $prefix.'_validate_action['.$userid.']';
275  ?><td width="10%" class="sq-backend-table-cell" style="text-align: center;"><?php
276  check_box($name, 'validate', FALSE, 'document.getElementById(\''.$prefix.'_delete_'.$userid.'\').checked=0', 'id="'.$prefix.'_validate_'.$userid.'"');
277  ?></td><?php
278  ?><td width="10%" class="sq-backend-table-cell" style="text-align: center;"><?php
279  check_box($name, 'delete', FALSE, 'document.getElementById(\''.$prefix.'_validate_'.$userid.'\').checked=0', 'id="'.$prefix.'_delete_'.$userid.'"');
280  ?></td><?php
281  }
282  ?>
283 
284  </tr><?php
285  }
286 
287  ?>
288  </table>
289  <?php
290 
291 
292  return $write_access;
293 
294  }//end paintValidateAccounts()
295 
296 
307  function processValidateAccounts(&$asset, &$o, $prefix)
308  {
309  $write_access = $asset->writeAccess('attributes');
310  if ($write_access) {
311  $pending_users = array_get_index($_REQUEST, $prefix.'_validate_action', Array());
312 
313  $user_actions = Array();
314  foreach ($pending_users as $userid => $action) {
315  if (empty($action)) continue;
316  $user_actions[$action][] = $userid;
317  }
318 
319  // validate some users
320  if (!empty($user_actions['validate'])) {
321  // queue up a hipo to loop through the users, validating each one
322  quick_hipo($asset->id, 'hipoValidateUser', $user_actions['validate'], Array(), TRUE);
323  }
324 
325  // delete some users
326  if (!empty($user_actions['delete'])) {
327  // queue up a hipo to loop through the users, deleting them
328  quick_hipo($asset->id, 'hipoDeleteUser', $user_actions['delete'], Array(), TRUE);
329  }
330  }
331  return $write_access;
332 
333  }//end processValidateAccounts()
334 
335 
346  function paintCreateFormCustomisation(&$asset, &$o, $prefix)
347  {
348  $customised_types = $asset->attr('create_form_customisations');
349  $wa = $asset->writeAccess('attributes');
350  if ($wa) {
351  hidden_field($prefix.'_customise_form_submitted', 1);
352  echo check_box($prefix.'_customise_form', 1, !empty($customised_types));
353  label(translate('cms_account_manager_customise_create_form'), $prefix.'_customise_form');
354  } else {
355  $fn = !empty($customised_types) ? 'tick' : 'cross';
356  echo '<img src="'.sq_web_path('lib').'/web/images/'.$fn.'.gif" />';
357  echo translate('cms_account_manager_customise_create_form');
358  }
359 
360  }//end paintCreateFormCustomisation()
361 
362 
373  function processCreateFormCustomisation(&$asset, &$o, $prefix)
374  {
375  if ($asset->writeAccess('attributes') && isset($_POST[$prefix.'_customise_form_submitted'])) {
376  $customise = array_get_index($_POST, $prefix.'_customise_form');
377  $customised_types = $customise ? array_keys($asset->attr('create_type')) : Array();
378  return $asset->setAttrValue('create_form_customisations', $customised_types);
379  }
380  return FALSE;
381 
382  }//end processCreateFormCustomisation()
383 
384 
395  function paintUseEmailValidation(&$asset, &$o, $prefix)
396  {
397  $write_access = $asset->writeAccess('links');
398  $current_value = $asset->attr('use_email_validation');
399  $options = Array(1 => 'Yes', 0 => 'No');
400 
401  if ($write_access) {
402  combo_box($prefix.'_use_email_validation', $options, FALSE, $current_value);
403  } else {
404  echo $options[$current_value];
405  }
406 
407  return $write_access;
408 
409  }//end paintEmailValidation()
410 
411 
422  function processUseEmailValidation(&$asset, &$o, $prefix)
423  {
424  if (isset($_POST[$prefix.'_use_email_validation'])) {
425 
426  $use_email_validation = $_POST[$prefix.'_use_email_validation'];
427  if ($asset->setAttrValue('use_email_validation', $use_email_validation) && $use_email_validation) {
428 
429  // if we are using email validation - create validation assets
430  $pending_accounts_groupid = $asset->_getPendingAccountsGroupId();
431  if (empty($pending_accounts_groupid)) {
432  $asset->_createPendingAccountsGroup();
433  }
434  }
435 
436  }
437 
438  return TRUE;
439 
440  }//end processEmailValidation()
441 
442 }//end class
443 
444 ?>