PageRenderTime 28ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/jfx-private/modules/jfxmenu/admin-actions/new-menu.php

http://jfxcms.googlecode.com/
PHP | 198 lines | 125 code | 55 blank | 18 comment | 6 complexity | 1ce12bff44ae48fb06dd790fda7fb80d 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. $VIEW->template = $dirname.'/templates/thickbox.tpl';
  21. ob_start();
  22. if(Antz_IntelliForm::submitted('create-menu')){
  23. $error = false;
  24. $keyname = preg_replace('/[^a-zA-Z0-9]/', '', post('keyname'));
  25. $title = post('title');
  26. $template = $_POST['template'];
  27. $parentid = (int) post('parent');
  28. if($DB->countRows($CONFIG->dbprefix.'jfxmenu_menus', "keyname = '{$keyname}'")>0){
  29. $error = true;
  30. JFX::addError($this->lang('keyname_already_registered'));
  31. JFX::addFormError('keyname');
  32. }
  33. if($DB->countRows($CONFIG->dbprefix.'pages', "id = '{$parentid}'")==0){
  34. $error = true;
  35. JFX::addError($this->lang('invalid_parent'));
  36. }
  37. if(!$error){
  38. $dbParams = array(
  39. 'keyname' => $keyname,
  40. 'template' => $template,
  41. 'parent_id' => $parentid
  42. );
  43. $this->updateContentLang('title', $keyname, $title, '*', '*');
  44. $DB->insert($CONFIG->dbprefix.'jfxmenu_menus', $dbParams);
  45. JFX::addSuccess($this->lang('new_menu_success'));
  46. }
  47. }
  48. $VIEW->addJs('
  49. $(document).ready(function(){
  50. $("#jfxcore-new-menu-tree").treeview({
  51. persist: "location",
  52. collapsed: true,
  53. unique: true
  54. });
  55. $("#jfxcore-new-menu-tree a").click(function(){
  56. $("#parent-id").get(0).value = this.id.replace("page_", "");
  57. $("#disabled-parent").get(0).value = $(this).text();
  58. });
  59. });
  60. ');
  61. $pagesRecursive = JFX::getPageTree(0, $USER->workspace);
  62. $tree = '<ul id="jfxcore-new-menu-tree">'.JFXMenu_MakeTree($pagesRecursive, 'page_').'</ul>';
  63. $parentTitle = $LANG->getContent('core', 'heading', post('parent', $mData['parent_id']));
  64. $parent = array(
  65. 'name' => 'parent',
  66. 'value' => post('parent', $pData['parent_id']),
  67. 'type' => 'hidden',
  68. 'id' => 'parent-id',
  69. 'label' => ''
  70. );
  71. $parentList = array(
  72. 'type' => 'longtag',
  73. 'tag' => 'div',
  74. 'class' => 'form-field',
  75. 'id' => 'parent-page-tree',
  76. 'content' => '<label>'.$LANG->get('core', 'page_parent').'</label>
  77. <div class="input-area">'.$tree.'</div>'
  78. );
  79. $selectedParent = array(
  80. 'name' => 'disabled_parent',
  81. 'value' => $parentTitle,
  82. 'type' => 'text',
  83. 'id' => 'disabled-parent',
  84. 'extra' => array(
  85. array(
  86. 'command' => 'addAttribute',
  87. 'params' => array(
  88. '"disabled"', '"disabled"'
  89. )
  90. )
  91. ),
  92. 'label' => $this->lang('selected_parent')
  93. );
  94. $formFields = array(
  95. array(
  96. 'type' => 'text',
  97. 'name' => 'keyname',
  98. 'value' => post('keyname', 'mymenu'),
  99. 'label' => $this->lang('new_keyname')
  100. ),
  101. array(
  102. 'type' => 'text',
  103. 'name' => 'title',
  104. 'value' => post('title', 'My Menu'),
  105. 'label' => $this->lang('new_title')
  106. ),
  107. $parent,
  108. $parentList,
  109. $selectedParent,
  110. array(
  111. 'type' => 'code',
  112. 'id' => 'jfxmenunew',
  113. 'class' => 'html',
  114. 'name' => 'template',
  115. 'value' => post('template', $this->lang('default_template'), 5000),
  116. 'label' => $this->lang('new_template')
  117. ),
  118. array(
  119. 'type' => 'submit',
  120. 'name' => 'submitBtn',
  121. 'value' => $this->lang('new_submit'),
  122. 'label' => '&nbsp;'
  123. )
  124. );
  125. echo JFX::makeRapidForm($formFields, 'New Menu Details', 'create-menu');
  126. $content = ob_get_contents();
  127. ob_end_clean();
  128. $SMARTY->assign('_CST_BODY', $content.' ------');
  129. function JFXMenu_MakeTree($arr, $idprefix){
  130. $CONFIG = JFX::registry('config');
  131. $LANG = JFX::registry('lang');
  132. $returnString = '';
  133. foreach($arr as $k=>$v){
  134. $link = '<a href="javascript: void(null)" id="'.$idprefix.$v['id'].'">'.$LANG->getContent('core', 'heading', $v['id']).'</a>';
  135. if(isset($v['subpages']) && count($v['subpages'])>0){
  136. $subpages = '<ul>'.JFXMenu_MakeTree($v['subpages'], $idprefix).'</ul>';
  137. }else{
  138. $subpages = '';
  139. }
  140. $returnString .= '<li>'.$link.$subpages.'</li>';
  141. }
  142. return $returnString;
  143. }