/programs/widgets/babfilepicker.class.php

https://bitbucket.org/cantico/widgets · PHP · 108 lines · 54 code · 21 blank · 33 comment · 5 complexity · 721825a27f21960c73abaceb464cadb8 MD5 · raw file

  1. <?php
  2. //-------------------------------------------------------------------------
  3. // OVIDENTIA http://www.ovidentia.org
  4. // Ovidentia is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2, or (at your option)
  7. // any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful, but
  10. // WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. // See the GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. // USA.
  18. //-------------------------------------------------------------------------
  19. /**
  20. * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
  21. * @copyright Copyright (c) 2006 by CANTICO ({@link http://www.cantico.fr})
  22. */
  23. //include_once 'base.php';
  24. require_once dirname(__FILE__) . '/inputwidget.class.php';
  25. require_once dirname(__FILE__) . '/select.class.php';
  26. /**
  27. * Constructs a Widget_BabFilePicker.
  28. *
  29. * @param string $id The item unique id.
  30. * @return Widget_BabFilePicker
  31. */
  32. function Widget_BabFilePicker($id = null)
  33. {
  34. return new Widget_BabFilePicker($id);
  35. }
  36. /**
  37. * A Widget_BabFilePicker is a widget that let the user select an ovidentia babFolder.
  38. *
  39. * It currently opens a popup window displaying a babFolder treeview with clickable nodes.
  40. */
  41. class Widget_BabFilePicker extends Widget_Select implements Widget_Displayable_Interface
  42. {
  43. public function getClasses()
  44. {
  45. $classes = parent::getClasses();
  46. $classes[] = 'widget-babfilepicker';
  47. $classes[] = 'icon';
  48. return $classes;
  49. }
  50. public function display(Widget_Canvas $canvas)
  51. {
  52. require_once $GLOBALS['babInstallPath'] . 'utilit/tree.php';
  53. $treeView = new bab_FileTreeView('bab_tv_file', bab_isUserAdministrator());
  54. $attributes = bab_FileTreeView::SHOW_SUB_FOLDERS /* | bab_FileTreeView::SHOW_FILES */;
  55. $treeView->setAttributes($attributes);
  56. $treeView->printTemplate();
  57. $rootNode = $treeView->getRootNode();
  58. $this->addOption('', '');
  59. $it = $rootNode->createNodeIterator($rootNode);
  60. $optGroup = self::NOGROUPKEY;
  61. while ($node = $it->nextNode()) {
  62. $data = $node->getData();
  63. if (!$data) {
  64. continue;
  65. }
  66. $path = explode(':', $data->_id);
  67. array_shift($path);
  68. if ($data->_type === 'foldercategory') {
  69. $currentDelegation = str_replace('d', 'DG', $data->_id);
  70. $optGroup = $data->_title;
  71. continue;
  72. }
  73. if ($data->_type === 'gfile') {
  74. $path = $currentFolderPath;
  75. $path[] = $data->_title;
  76. } else {
  77. $currentFolderPath = $path;
  78. }
  79. array_unshift($path, $currentDelegation);
  80. $fullpath = implode('/', $path);
  81. $level = explode('/', $fullpath);
  82. $padding = str_repeat(bab_nbsp(), 4 * (count($level) - 2));
  83. $this->addOption($fullpath, $padding . $data->_title, $optGroup);
  84. }
  85. return parent::display($canvas);
  86. }
  87. }