PageRenderTime 48ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/jfx-private/modules/core/actions/sort-pages.php

http://jfxcms.googlecode.com/
PHP | 157 lines | 69 code | 68 blank | 20 comment | 5 complexity | 34c58d160e58d423e399f3cb290cbd9a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. ############### COPYLEFT GPLv3 LICENSE ###############
  3. ##
  4. ## JFX Version 0.2.9
  5. ## Website Management Software
  6. ## www.jfxcms.com
  7. ##
  8. ## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
  9. ##
  10. ## Anthony Gallon
  11. ## oi_antz@hotmail.com
  12. ##
  13. ## Permission is hereby granted to any person having a copy of this software
  14. ## to freely use and modify as required so long as the copyright notices
  15. ## and branding remain intact.
  16. ##
  17. ## Full license details available at http://www.jfxcms.com/license
  18. ##
  19. ############### COPYLEFT GPLv3 LICENSE ###############
  20. $THEME->addBreadcrumb($this->adminUrl.'/sort-pages/', $this->lang('ap_title_sort-pages'));
  21. $pagesRecursive = JFX::getPageTree(0, $USER->workspace);
  22. $tree = '<ul id="jfx-sort-page-tree">'.JFX_SortPage_MakeTree($pagesRecursive).'</ul>';
  23. $SMARTY->assign('sortTree', $tree);
  24. $VIEW->addTemplate('main', 'admin/sort-pages.tpl');
  25. $SMARTY->assign('showPages', false);
  26. $VIEW->addJs('
  27. $(document).ready(function(){
  28. var sortableStop = function(){
  29. var sorted = $("#jfx-sort-pages").sortable("serialize");
  30. //alert(sorted);
  31. //$("#jfx-sort-pages").css("display", "none");
  32. //$("#jfx-workspace-inner").get(0).innerHTML = \'<div align="center"><img src="'.$CONFIG->imageUrl.'/admin/loadingAnimation.gif" alt="Loading..." /></div>\';
  33. $.post("'.$CONFIG->adminUrl.'/sort-pages/?page='.$pageid.'&sorted=1", sorted, function(){});
  34. }
  35. $("#jfx-sort-pages").sortable({cursor : "pointer", stop : sortableStop });
  36. $("#jfx-sort-page-tree").treeview({
  37. persist: "location",
  38. collapsed: true,
  39. unique: true
  40. });
  41. });
  42. ');
  43. if(get('page')!=''){
  44. $pageid = (int) get('page');
  45. if($DB->countRows($CONFIG->dbprefix.'pages', "id = '{$pageid}'")==0){
  46. JFX::addError($this->lang('invalid_page_selected'));
  47. JFX::redirect($CONFIG->adminUrl.'/sort-pages');
  48. }
  49. }else{
  50. return;
  51. }
  52. // now have a valid page id
  53. $SMARTY->assign('showPages', true);
  54. if(get('sorted')==1){
  55. // update the sort order
  56. $DB->showOutput(true);
  57. $count = 0;
  58. foreach($_POST['page'] as $sortOrder => $id){
  59. $id = (int) $id;
  60. $DB->update($CONFIG->dbprefix.'pages', array('sorting'=>$count), "id = '{$id}'");
  61. $count++;
  62. }
  63. exit;
  64. while(ob_get_level()>0) ob_end_clean();
  65. exit;
  66. }
  67. $pageTitle = $LANG->getContent('core', 'heading', $pageid);
  68. $SMARTY->assign('pageTitle', $pageTitle);
  69. $pages = $DB->fetchAll("SELECT * FROM {$CONFIG->dbprefix}pages WHERE parent_id = '{$pageid}' ORDER BY sorting ASC");
  70. foreach($pages as $k=>$v){
  71. $pages[$k]['title'] = $LANG->getContent('core', 'heading', $v['id']);
  72. }
  73. $SMARTY->assign('pages', $pages);
  74. function JFX_SortPage_MakeTree($arr){
  75. $CONFIG = JFX::registry('config');
  76. $LANG = JFX::registry('lang');
  77. $returnString = '';
  78. foreach($arr as $k=>$v){
  79. $link = '<a href="'.$CONFIG->adminUrl.'/sort-pages/?page='.$v['id'].'">'.$LANG->getContent('core', 'heading', $v['id']).'</a>';
  80. if(isset($v['subpages']) && count($v['subpages'])>0){
  81. $subpages = '<ul>'.JFX_SortPage_MakeTree($v['subpages']).'</ul>';
  82. }else{
  83. $subpages = '';
  84. }
  85. $returnString .= '<li>'.$link.$subpages.'</li>';
  86. }
  87. return $returnString;
  88. }