Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
remap_manager_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
19 
33 {
34 
43  private $num_per_page = 100;
44 
45 
51  function __construct()
52  {
53  parent::__construct();
54 
55  $this->static_screens['details']['force_unlock'] = FALSE;
56  $this->static_screens['details']['lock_type'] = 'all';
57 
58  unset($this->static_screens['settings']);
59  unset($this->static_screens['preview']);
60  unset($this->static_screens['lookupValues']);
61  unset($this->static_screens['web_paths']);
62  unset($this->static_screens['metadata']);
63  unset($this->static_screens['metadataSchemas']);
64  unset($this->static_screens['workflow']);
65  unset($this->static_screens['tagging']);
66  unset($this->static_screens['dependants']);
67  unset($this->static_screens['linking']);
68  unset($this->static_screens['roles']);
69  unset($this->static_screens['permissions']);
70 
71  }//end __construct()
72 
73 
94  private function _fetchRemapUrls($url_filter='', $remap_url_filter='', $page_num=1, $return_count=TRUE)
95  {
96  require_once SQ_FUDGE_PATH.'/db_extras/db_extras.inc';
97 
98  $offset = $this->num_per_page * ($page_num - 1);
99 
100  $remap_urls = Array();
101  if ( (!empty($url_filter)) || (!empty($remap_url_filter))) {
102  $bind_vars = Array(
103  'url' => (string) '%'.$url_filter.'%',
104  'remap_url' => (string) '%'.$remap_url_filter.'%',
105  );
106 
107  $where = ' WHERE url LIKE :url AND remap_url LIKE :remap_url';
108 
109  } else {
110  $bind_vars = Array();
111 
112  $where = '';
113  }
114 
115  $count_query = 'SELECT COUNT(url) FROM sq_ast_lookup_remap '.$where;
116 
121  $query = 'SELECT url, remap_url, expires, never_delete, auto_remap FROM sq_ast_lookup_remap '.$where.' ORDER BY url';
122 
123  $query = db_extras_modify_limit_clause($query, MatrixDAL::getDbType(), $this->num_per_page, $offset);
124 
125  try {
126  if ($return_count) {
127  $count_result = MatrixDAL::preparePdoQuery($count_query);
128  }
129  $result = MatrixDAL::preparePdoQuery($query);
130 
131  if (!empty($bind_vars)) {
132  foreach ($bind_vars as $bind_var => $bind_value) {
133  if ($return_count) {
134  MatrixDAL::bindValueToPdo($count_result, $bind_var, $bind_value);
135  }
136  MatrixDAL::bindValueToPdo($result, $bind_var, $bind_value);
137  }
138  }
139  if ($return_count) {
140  $total_assets = MatrixDAL::executePdoOne($count_result);
141  }
142 
143  $remap_urls = MatrixDAL::executePdoAll($result);
144  } catch (Exception $e) {
145  throw new Exception('Unable to get remap urls due to the following database error: '.$e->getMessage());
146  }
147 
148  if ($return_count) {
149  return Array(
150  'total_remaps' => $total_assets,
151  'remap_rows' => $remap_urls,
152  );
153  }
154  return $remap_urls;
155  }// end _fetchRemapUrls()
156 
157 
168  public function paintEditRemapURLs(Remap_Manager $asset, Backend_Outputter $o, $prefix)
169  {
170  $write_access = $asset->writeAccess('all');
171 
172  // check if we need to filter the url or remap url
173  $url_filter = array_get_index($_POST, $prefix.'_URL_FILTER', '');
174  $remap_url_filter = array_get_index($_POST, $prefix.'_REMAP_URL_FILTER', '');
175 
176  if ( (!empty($url_filter)) || (!empty($remap_url_filter))) {
177  $remap_entries_tag = 'remap_entries_filtered';
178  $no_entries_tag = 'no_url_remappings_filtered';
179  } else {
180  $remap_entries_tag = 'remap_entries';
181  $no_entries_tag = 'no_url_remappings';
182  }
183 
184  $page_num = array_get_index($_POST, $prefix.'_remap_urls_page', 1);
185  $page_num = max($page_num, 1);
186 
187  $remap_info = $this->_fetchRemapUrls($url_filter, $remap_url_filter, $page_num, TRUE);
188  $total_assets = $remap_info['total_remaps'];
189  $remap_urls = $remap_info['remap_rows'];
190 
191  $o->openField(translate('purge_all_remaps'));
192  combo_box($prefix.'_purge_all_remaps', Array(0 => translate('no'), 1 => translate('yes')), FALSE, 0, 0, "onChange=\"Javascript: if (this.value == 1) { if(!confirm(js_translate('confirm_purge_all_remaps'))) { this.value = 0; } } \"". ($write_access ? '' : "disabled"));
193  $o->note(translate('purge_all_remaps_note'));
194  $o->closeField();
195 
196 
197  $o->openField('Original URL Filter');
198  text_box($prefix.'_URL_FILTER', $url_filter, 30);
199  $o->note(translate('remap_manager_url_filter_note'));
200  $o->closeField();
201  $o->openField('Remapped URL Filter');
202  text_box($prefix.'_REMAP_URL_FILTER', $remap_url_filter, 30);
203  $o->note(translate('remap_manager_remap_url_filter_note'));
204  $o->closeField();
205 
206  $o->openField('&nbsp;');
207 
208  if (empty($remap_urls)) {
209  echo translate($no_entries_tag);
210  return FALSE;
211  }
212 
213  $num_pages = ceil($total_assets / $this->num_per_page);
214 
215  if ($num_pages == 1) {
216  $page_tag = translate('page_number', $page_num, $num_pages);
217  } else {
218  $page_tag = translate('page_number_with_pager', $page_num, $num_pages, $prefix.'_remap_urls_page');
219  }
220  $asset_count_tag = translate('item_range', ($page_num - 1) * $this->num_per_page + 1, $total_assets, $total_assets, strtolower(translate($remap_entries_tag)));
221 
222  $links = Array(
223  'first' => '&lt;&lt;',
224  'previous' => '&lt;',
225  'page' => $page_tag,
226  'next' => '&gt;',
227  'last' => '&gt;&gt;',
228  );
229 
230  if ($page_num > 1) {
231  $links['first'] = '<a title="'.translate('pagination_go_to_first').'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.'_remap_urls_page\', 1)">'.$links['first'].'</a>';
232  $links['previous'] = '<a title="'.translate('pagination_go_to_previous').'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.'_remap_urls_page\', '.($page_num - 1).')">'.$links['previous'].'</a>';
233  } else {
234  $links['first'] = '<span title="'.translate('pagination_cannot_go_further_back').'." style="color: #333">'.$links['first'].'</span>';
235  $links['previous'] = '<span title="'.translate('pagination_cannot_go_further_back').'." style="color: #333">'.$links['previous'].'</span>';
236  }
237 
238  if ($page_num < $num_pages) {
239  $links['last'] = '<a title="'.translate('pagination_go_to_last').'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.'_remap_urls_page\', '.$num_pages.')">'.$links['last'].'</a>';
240  $links['next'] = '<a title="'.translate('pagination_go_to_next').'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.'_remap_urls_page\', '.($page_num + 1).')">'.$links['next'].'</a>';
241  } else {
242  $links['last'] = '<span title="'.translate('pagination_cannot_go_further_forward').'." style="color: #333">'.$links['last'].'</span>';
243  $links['next'] = '<span title="'.translate('pagination_cannot_go_further_forward').'." style="color: #333">'.$links['next'].'</span>';
244  }
245 
246  hidden_field($prefix.'_remap_urls_page', $page_num); ?>
247 
248  <table class="sq-backend-table">
249  <tr class="sq-backend-table-row">
250  <td class="sq-backend-table-header-header"><?php echo implode(' &nbsp; &nbsp; ', $links) ?></td>
251  <td class="sq-backend-table-header-header" colspan="<?php echo ($write_access === TRUE) ? 5 : 4 ?>" style="text-align: right; font-weight: normal"><?php echo $asset_count_tag; ?></span></td>
252  </tr>
253  <tr>
254  <td class="sq-backend-table-header"><?php echo translate('url'); ?></td>
255  <td class="sq-backend-table-header"><?php echo translate('remap_url'); ?></td>
256  <td class="sq-backend-table-header"><?php echo translate('expires'); ?></td>
257  <td class="sq-backend-table-header"><?php echo translate('type'); ?></td>
258  <?php
259  if ($write_access) {
260  ?>
261  <td class="sq-backend-table-header">
262  <?php
263  label(translate('delete_question'), $prefix.'_select_all');
264  check_box($prefix.'_select_all', '1', FALSE, "check_all(document.main_form, '{$prefix}_delete_remap', this.checked);");
265  ?>
266  </td>
267 
268  <?php
269  }
270  ?>
271  <td class="sq-backend-table-header">
272  <?php echo translate('never_delete');
273 
274  if ($write_access) {
275  check_box($prefix.'never_delete_select_all', '1', FALSE, "check_all(document.main_form, '{$prefix}_never_delete_remap', this.checked);");
276  }
277  ?>
278  </td>
279 
280  </tr>
281  <?php
282  foreach ($remap_urls as $url_info) {
283  if (empty($url_info['expires'])) {
284  $expires = translate('never');
285  } else {
286  $expires = $GLOBALS['SQ_SYSTEM']->datetime(iso8601_ts($url_info['expires']));
287  }
288 
289  // any warning text to show for this remapped URL (any possible problems)
290  $warning = '';
291 
292  // To let the process function know the remaps on the current page
293  hidden_field($prefix.'_current_page_remaps['.$url_info['url'].']', $page_num);
294 
295  // check to see if the URL is actually being used by a real asset within the system
296  // because if it is, this remap will never be used
297  if (strpos($url_info['url'], '://') !== FALSE) {
298  list($protocol, $url) = explode('://', $url_info['url']);
299  $url_asset = $GLOBALS['SQ_SYSTEM']->am->getAssetFromURL($protocol, $url, TRUE, TRUE);
300  if (!is_null($url_asset)) {
301  $warning .= translate('url_currently_in_use', $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($url_asset->type(), 'name'), translate('asset_format', $url_asset->name, $url_asset->id));
302  }
303  }
304  ?>
305  <tr>
306  <td class="sq-backend-table-cell"><?php echo $url_info['url']; ?><br/><span style="color: #FF0000;"><b><?php echo $warning; ?></b></span></td>
307  <td class="sq-backend-table-cell"><?php echo $url_info['remap_url']; ?></td>
308  <td class="sq-backend-table-cell"><?php echo $expires; ?></td>
309  <td class="sq-backend-table-cell"><?php echo ((int)$url_info['auto_remap'] === 1) ? translate('automatic') : (($url_info['auto_remap'] === NULL) ? translate('unknown') : translate('manual')); ?></td>
310  <?php
311  if ($write_access) {
312  $never_delete_remap = (isset($_POST[$prefix.'_never_delete_remap']) && array_key_exists($url_info['url'],$_POST[$prefix.'_never_delete_remap'])) || $url_info['never_delete'];
313  ?>
314  <td class="sq-backend-table-cell">
315  <?php
316  check_box($prefix.'_delete_remap['.$url_info['url'].']', 1, FALSE, '', $never_delete_remap ? 'disabled' : '');
317  ?>
318  </td>
319  <td class="sq-backend-table-cell">
320  <?php
321  check_box($prefix.'_never_delete_remap['.$url_info['url'].']', 1, $never_delete_remap);
322  ?>
323  </td>
324  <?php
325  } else {
326  if ((isset($_POST[$prefix.'_never_delete_remap']) && array_key_exists($url_info['url'],$_POST[$prefix.'_never_delete_remap'])) || $url_info['never_delete']) {
327  ?>
328  <td class="sq-backend-table-cell">
329  <img src="<?php echo sq_web_path('lib'); ?>/web/images/tick.gif" width="12" height="12" />
330  </td>
331  <?php
332  } else {
333  ?>
334  <td class="sq-backend-table-cell">
335  <img src="<?php echo sq_web_path('lib'); ?>/web/images/cross.gif" width="12" height="12" />
336  </td>
337  <?php
338  }
339  }
340  ?>
341  </tr>
342  <?php
343  }//end foreach
344  ?>
345  </table>
346  <?php
347 
348  return $write_access;
349 
350  }//end paintEditRemapURLs()
351 
352 
363  public function processEditRemapURLs(Remap_Manager $asset, Backend_Outputter $o, $prefix)
364  {
365  if (!$asset->writeAccess('all')) return FALSE;
366 
367  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
368  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
369 
370  // Only update the remaps in current page
371  $urls_to_check = (isset($_POST[$prefix.'_never_delete_remap'])) ? array_keys($_POST[$prefix.'_never_delete_remap']) : array();
372  $current_page_remaps = array_get_index($_POST, $prefix.'_current_page_remaps', Array());
373  $urls_in_current_page = array_keys($current_page_remaps);
374  $urls_to_uncheck = array_diff($urls_in_current_page, $urls_to_check);
375 
376  try {
377  $bind_vars = Array(
378  'never_delete' => '0',
379  'urls_to_update' => $urls_to_uncheck,
380  );
381  $bind_vars_add = Array(
382  'never_delete' => '1',
383  'urls_to_update' => $urls_to_check,
384  );
385 
386  if (!empty($urls_to_uncheck)) {
387  MatrixDAL::executeQuery('remap_manager', 'addNeverDeleteToCurrentRemapURL', $bind_vars);
388  }
389  if (!empty($urls_to_check)) {
390  MatrixDAL::executeQuery('remap_manager', 'addNeverDeleteToCurrentRemapURL', $bind_vars_add);
391  }
392  } catch (DALException $e) {
393  throw new Exception('Unable to delete remaps due to database error: '.$e->getMessage());
394  }
395 
396  // Purge all remaps with "Never Delete" option set to "No"
397  if (isset($_POST[$prefix.'_purge_all_remaps']) && $_POST[$prefix.'_purge_all_remaps']) {
398  try {
399  $bind_vars = Array('never_delete' => '0');
400  MatrixDAL::executeQuery('remap_manager', 'deleteRemapsByNeverDeleteOption', $bind_vars);
401  } catch (DALException $e) {
402  throw new Exception('Unable to delete remaps due to database error: '.$e->getMessage());
403  }
404  }
405 
406  if (isset($_POST[$prefix.'_delete_remap'])) {
407  $urls = array_keys($_POST[$prefix.'_delete_remap']);
408  if (isset($_POST[$prefix.'_never_delete_remap'])) {
409  foreach ($_POST[$prefix.'_never_delete_remap'] as $url => $not_deletable) {
410  foreach ($urls as $index => $url_to_delete) {
411  if ($url == $url_to_delete && !$not_deletable == 0) {
412  unset($urls[$index]);
413  }
414  }
415  }
416  }
417 
418  try {
419  $bind_vars = Array('urls' => $urls);
420  MatrixDAL::executeQuery('remap_manager', 'deleteRemapsByURL', $bind_vars);
421  } catch (DALException $e) {
422  throw new Exception('Unable to delete remaps due to database error: '.$e->getMessage());
423  }
424  }
425 
426  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
427  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
428 
429  return TRUE;
430 
431  }//end processEditRemapURLs()
432 
433 
444  public function paintAddRemapURLs(Remap_Manager $asset, Backend_Outputter $o, $prefix)
445  {
446  $o->note(translate('url_remap_explanation'));
447  $o->closeField();
448 
449  $o->openField(translate('old_url'));
450  text_box($prefix.'_add_remap_old_url', '', 50);
451  $o->closeField();
452 
453  $o->openField(translate('new_url'));
454  text_box($prefix.'_add_remap_new_url', '', 50);
455  $o->closeField();
456 
457  $o->openField(translate('never_delete'));
458  check_box($prefix.'_add_never_delete_option');
459  $o->closeField();
460 
461  $o->openField(translate('expires'));
462  text_box($prefix.'_add_remap_expires_days', '', 5);
463  label(translate('days'), $prefix.'_add_remap_expires_days');
464  $o->closeField();
465 
466  $o->openField(translate('csv_upload'));
467  file_upload($prefix.'_add_remap_csv');
468 
469  // csv upload instructions
470  $o->note(translate('csv_upload_instructions'));
471  $o->note(translate('csv_upload_instructions_example_1').'<br />'.translate('csv_upload_instructions_example_2').'<br />'.translate('csv_upload_instructions_example_3'));
472  $o->closeField();
473 
474  $o->openField(translate('csv_upload_header'));
475  check_box($prefix.'_csv_header');
476  $o->note(translate('csv_upload_header_example'));
477  $o->closeField();
478 
479  }//end paintAddRemapURLs()
480 
481 
492  public function processAddRemapURLs(Remap_Manager $asset, Backend_Outputter $o, $prefix)
493  {
494  if (!$asset->writeAccess('all')) return FALSE;
495 
496  // do the CSV upload first
497  $file_info = get_file_upload_info($prefix.'_add_remap_csv');
498  if (!empty($file_info)) {
499  require_once SQ_FUDGE_PATH.'/csv/csv.inc';
500  $csv = new CSV($file_info['tmp_name']);
501  $csv_start = 1;
502  if (isset($_POST[$prefix.'_csv_header'])) {
503  $csv_start = 2;
504  }
505  $csv->import($csv_start);
506 
507  foreach ($csv->values as $line_value) {
508  $old_url = trim($line_value[0]);
509  $new_url = trim($line_value[1]);
510  if (empty($old_url) || empty($new_url)) {
511  return FALSE;
512  }
513 
514  $expires = array_key_exists(2, $line_value) ? trim($line_value[2]) : '';
515 
516  if (empty($expires)) {
517  $int_expires = NULL;
518  } else {
519  $int_expires = iso8601_ts($expires);
520  }
521 
522  // if the value is not set or isnt what we expect
523  // set never_delete option to the default behaviour
524  // configured on the remap_manager details screen
525  if (!isset($line_value[3]) || trim($line_value[3]) == '') {
526  $never_delete = $asset->attr('never_delete_remap_default');
527  } else {
528  $never_delete = trim($line_value[3]);
529  }
530 
531  $asset->addRemapURL($old_url, $new_url, $int_expires, $never_delete, FALSE);
532  }
533  }
534 
535  // now add a manually set remap if we have on to set
536  if (!isset($_POST[$prefix.'_add_remap_old_url']) || !isset($_POST[$prefix.'_add_remap_new_url'])) {
537  return FALSE;
538  }
539  $old_url = trim($_POST[$prefix.'_add_remap_old_url']);
540  $new_url = trim($_POST[$prefix.'_add_remap_new_url']);
541  $expires = NULL;
542  if (isset($_POST[$prefix.'_add_never_delete_option'])) {
543  $never_delete = trim($_POST[$prefix.'_add_never_delete_option']);
544  } else {
545  $never_delete = '0' ;
546  }
547 
548  if (empty($old_url) || empty($new_url)) {
549  return FALSE;
550  }
551 
552  if (isset($_POST[$prefix.'_add_remap_expires_days'])) {
553  $expires_days = (int)$_POST[$prefix.'_add_remap_expires_days'];
554  if ($expires_days > 0) {
555  $expires = strtotime('+ '.$expires_days.' days');
556  }
557  }
558 
559  $asset->addRemapURL($old_url, $new_url, $expires, $never_delete, FALSE);
560 
561  return TRUE;
562 
563  }//end processAddRemapURLs()
564 
565 
576  public function paintAddPageNotFoundRemap(Remap_Manager $asset, Backend_Outputter $o, $prefix)
577  {
578  $link_to_404 = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'asset', FALSE, '404');
579  $write_access = $asset->writeAccess('links');
580 
581  if (!$write_access) {
582  if (!empty($link_to_404)) {
583  echo get_asset_tag_line($link_to_404['minorid']);
584  } else {
585  echo '<em>'.translate('none').'</em>';
586  }
587  } else {
588  asset_finder($prefix.'_404asset', (!empty($link_to_404)) ? $link_to_404['minorid'] : '');
589  }
590 
591  return $write_access;
592 
593  }//end paintAddPageNotFoundRemap()
594 
595 
606  public function processAddPageNotFoundRemap(Remap_Manager $asset, Backend_Outputter $o, $prefix)
607  {
608  if (!isset($_POST[$prefix.'_404asset']['assetid'])) {
609  return FALSE;
610  }
611  $new_404_asset = $_POST[$prefix.'_404asset']['assetid'];
612 
613  // getting existing root link
614  $root_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', FALSE, '404');
615 
616  // dont process anything if the root node has not changed
617  if (!empty($root_link) && $root_link['minorid'] == $new_404_asset) {
618  return FALSE;
619  }
620 
621  $ok = TRUE;
622 
623  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
624  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
625 
626  // deleting old root link if any found...
627  if (!empty($root_link) && !$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($root_link['linkid'])) {
628  $ok = FALSE;
629  } else if ($new_404_asset) {
630  $root = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_404_asset);
631  if (!is_null($root)) {
632  if (!$asset->createLink($root, SQ_LINK_NOTICE, '404')) {
633  $ok = FALSE;
634  trigger_localised_error('CORE0027', E_USER_WARNING, $root->name, $root->id);
635  }
636  }
637  }
638 
639  if ($ok) {
640  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
641  } else {
642  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
643  }
644 
645  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
646  return $ok;
647 
648  }//end processAddPageNotFoundRemap()
649 
650 
662  {
663  $write_access = $asset->writeAccess('attributes');
664  $remap_upon_webpath_change = $asset->attr('remap_upon_webpath_change');
665 
666  $o->closeField();
667  $o->openField(translate('remap_manager_automatically_add_remaps_question'));
668 
669  // paint checkbox
670  if ($write_access) {
671  check_box($prefix.'_remap_upon_webpath_change', TRUE, $remap_upon_webpath_change);
672  } else {
673  ?>
674  <img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $remap_upon_webpath_change ? 'tick' : 'cross'; ?>.gif" width="15" height="15" />
675  <?php
676  }
677 
678  $o->note(translate('remap_manager_auto_add_remaps_note'));
679 
680  $o->closeField();
681 
682  return $write_access;
683 
684  }//end paintAutomaticRemappingCheckbox()
685 
686 
698  {
699  if (!$asset->writeAccess('attributes')) return FALSE;
700 
701  $remap_upon_webpath_change = isset($_POST[$prefix.'_remap_upon_webpath_change']);
702  $asset->setAttrValue('remap_upon_webpath_change', $remap_upon_webpath_change);
703 
704  return TRUE;
705 
706  }//end processAutomaticRemappingCheckbox()
707 
708 
719  public function paintNeverDeleteRemapCheckbox(Remap_Manager $asset, Backend_Outputter $o, $prefix)
720  {
721  $write_access = $asset->writeAccess('attributes');
722  $never_delete_remap_default = $asset->attr('never_delete_remap_default');
723 
724  $o->closeField();
725  $o->openField(translate('remap_manager_never_delete_remap_default_question'));
726 
727  // paint checkbox
728  if ($write_access) {
729  check_box($prefix.'_never_delete_remap_default', TRUE, $never_delete_remap_default);
730  } else {
731  ?>
732  <img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $never_delete_remap_default ? 'tick' : 'cross'; ?>.gif" width="15" height="15" />
733  <?php
734  }
735 
736  $o->note(translate('remap_manager_never_delete_remap_default_note'));
737 
738  $o->closeField();
739 
740  return $write_access;
741 
742  }//end paintNeverDeleteRemapCheckbox()
743 
744 
756  {
757  if (!$asset->writeAccess('attributes')) return FALSE;
758 
759  $never_delete_remap_default = isset($_POST[$prefix.'_never_delete_remap_default']);
760  $asset->setAttrValue('never_delete_remap_default', $never_delete_remap_default);
761 
762  return TRUE;
763 
764  }//end processNeverDeleteRemapCheckbox()
765 
766 
776  public function paintExportEntriesToCSV(Remap_Manager $asset, Backend_Outputter $o, $prefix)
777  {
778  $write_access = $asset->writeAccess();
779 
780  if ($write_access === TRUE) {
781  $this->processExportEntriesToCSV($asset, $o, $prefix);
782 
783  normal_button($prefix.'_export_to_csv', translate('download_file'), 'this.form.'.$prefix.'_download_file.value = 1; this.form.submit(); SQ_FORM_SUBMITTED = false; this.form.'.$prefix.'_download_file.value = 0; return true;');
784  hidden_field($prefix.'_download_file', 0);
785  }
786 
787  return FALSE;
788 
789  }//end paintExportEntriesToCSV()
790 
791 
803  public function processExportEntriesToCSV(Remap_Manager $asset, Backend_Outputter $o, $prefix)
804  {
805  if ($asset->writeAccess() === FALSE) {
806  return FALSE;
807  }
808 
809  $download_file = (int)array_get_index($_POST, $prefix.'_download_file', 0);
810 
811  if ($download_file === 1) {
812  // check if we need to filter the url or remap url
813  $url_filter = array_get_index($_POST, $prefix.'_URL_FILTER', '');
814  $remap_url_filter = array_get_index($_POST, $prefix.'_REMAP_URL_FILTER', '');
815 
816  $page = 1;
817 
818  // since we're going to be downloading this file, lets set a bigger per_page size
819  $this->num_per_page = 10000;
820 
821  $remap_urls = $this->_fetchRemapUrls($url_filter, $remap_url_filter, $page, FALSE);
822 
823  if (empty($remap_urls)) {
824  // Cannot export remap entries to CSV, there are no entries to export
825  trigger_localised_error('CORE0287', E_USER_WARNING);
826  } else {
827 
828  require_once SQ_FUDGE_PATH.'/csv/csv.inc';
829 
830  $csv = new CSV();
831  $csv->setFilename('remap_entries.csv');
832  $csv->setDeliminator(',');
833 
834  $headers = Array('Original URL', 'Remapped URL', 'Expiry', 'Never Delete', 'Automatic');
835  $csv->setFieldHeaders($headers);
836 
837  $header_printed = FALSE;
838  while (!empty($remap_urls)) {
839  $values = Array();
840  foreach ($remap_urls as $remap_url) {
841  $value_row = Array(
842  $remap_url['url'],
843  $remap_url['remap_url'],
844  $remap_url['expires'],
845  );
846  if ($remap_url['never_delete'] !== NULL) {
847  $value_row[] = (boolean)($remap_url['never_delete']) ? 1 : 0;
848  } else {
849  $value_row[] = NULL;
850  }
851  if ($remap_url['auto_remap'] !== NULL) {
852  $value_row[] = (boolean)($remap_url['auto_remap']) ? 1 : 0;
853  } else {
854  $value_row[] = NULL;
855  }
856  $values[] = $value_row;
857  }
858 
859  $csv->setValues($values);
860 
861  if (!$header_printed) {
862  $csv->export(FALSE);
863  $header_printed = TRUE;
864  } else {
865  $csv->exportValues(FALSE);
866  }
867  $page++;
868  // see if we have more remaps to get,
869  // eventually this will be an empty array.
870  $remap_urls = $this->_fetchRemapUrls($url_filter, $remap_url_filter, $page, FALSE);
871  }
872 
873  // We don't want the rest of the interface printed, so exit.
874  exit(0);
875 
876  }//end else if there are any remaps (or not)
877  }//end if download is 1
878 
879  return FALSE;
880 
881  }//end processExportEntriesToCSV()
882 
883 
895  {
896  $write_access = $asset->writeAccess('attributes');
897  $preserve_url_parameters = $asset->attr('preserve_url_parameters');
898 
899 
900 
901  // paint checkbox
902  if ($write_access) {
903  check_box($prefix.'_preserve_url_parameters', TRUE, $preserve_url_parameters);
904  } else {
905  ?>
906  <img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $preserve_url_parameters ? 'tick' : 'cross'; ?>.gif" width="15" height="15" />
907  <?php
908  }
909 
910 
911  return $write_access;
912 
913  }//end paintPreserveUrlParametersCheckbox()
914 
915 
927  {
928  if (!$asset->writeAccess('attributes')) return FALSE;
929 
930  $preserve_url_parameters = isset($_POST[$prefix.'_preserve_url_parameters']);
931  $asset->setAttrValue('preserve_url_parameters', $preserve_url_parameters);
932 
933  return TRUE;
934 
935  }//end processPreserveUrlParametersCheckbox()
936 
937 
938 }//end class
939 
940 ?>