tools.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * Group edit form
  4. *
  5. * This view contains the group tool options provided by the different plugins
  6. *
  7. * @package ElggGroups
  8. */
  9. $entity = elgg_extract("entity", $vars);
  10. $tools = elgg_get_config("group_tool_options");
  11. if (empty($tools)) {
  12. return;
  13. }
  14. // if the form comes back from a failed save we can't use the presets
  15. $sticky_form = (bool) elgg_extract('group_tools_presets', $vars, false);
  16. $presets = false;
  17. if (!$sticky_form) {
  18. $presets = group_tools_get_tool_presets();
  19. }
  20. // we need to be able to tell if we came from a sticky form
  21. echo elgg_view('input/hidden', array('name' => 'group_tools_presets', 'value' => '1'));
  22. // new group can choose from preset (if any)
  23. if (empty($entity) && !empty($presets)) {
  24. echo elgg_view("output/longtext", array("value" => elgg_echo("group_tools:create_group:tool_presets:description")));
  25. $preset_selectors = "";
  26. $preset_descriptions = "";
  27. $presets_tools = array();
  28. foreach ($presets as $index => $values) {
  29. $preset_selectors .= elgg_view("output/url", array(
  30. "text" => elgg_extract("title", $values),
  31. "href" => "#",
  32. "class" => "elgg-button elgg-button-action mrm",
  33. "rel" => $index,
  34. "title" => elgg_strip_tags(elgg_extract("description", $values)),
  35. ));
  36. $preset_tools = elgg_extract("tools", $values);
  37. foreach ($preset_tools as $tool_name => $tool) {
  38. if ($tool == "yes") {
  39. $presets_tools[$tool_name][] = "group-tools-preset-" . $index;
  40. }
  41. }
  42. $preset_descriptions .= "<div id='group-tools-preset-description-" . $index . "' class='hidden'>" . elgg_extract("description", $values) . "</div>";
  43. }
  44. // blank preset
  45. $preset_selectors .= elgg_view("output/url", array(
  46. "text" => elgg_echo("group_tools:create_group:tool_presets:blank:title"),
  47. "href" => "#",
  48. "class" => "elgg-button elgg-button-action mrm",
  49. "rel" => "blank"
  50. ));
  51. $preset_descriptions .= "<div id='group-tools-preset-description-blank' class='hidden'>" . elgg_echo("group_tools:create_group:tool_presets:blank:description") . "</div>";
  52. echo "<label class='mbs'>" . elgg_echo("group_tools:create_group:tool_presets:select") . ":</label>";
  53. echo "<div id='group-tools-preset-selector'>" . $preset_selectors . "</div>";
  54. echo "<div id='group-tools-preset-descriptions'>" . $preset_descriptions . "</div>";
  55. $more_link = elgg_view("output/url", array(
  56. "text" => elgg_echo("group_tools:create_group:tool_presets:show_more"),
  57. "href" => "#group-tools-preset-more",
  58. "rel" => "toggle",
  59. "class" => "float-alt"
  60. ));
  61. echo elgg_view_module("info", elgg_echo("group_tools:create_group:tool_presets:active_header"), $more_link, array("id" => "group-tools-preset-active", "class" => "hidden"));
  62. $tools_content = "";
  63. foreach ($tools as $group_option) {
  64. $group_option_toggle_name = $group_option->name . "_enable";
  65. $value = "no";
  66. $options = array(
  67. "group_tool" => $group_option,
  68. "value" => $value,
  69. "class" => "mbm"
  70. );
  71. if (array_key_exists($group_option_toggle_name, $presets_tools)) {
  72. $options["class"] .= " " . implode(" ", $presets_tools[$group_option_toggle_name]);
  73. }
  74. $tools_content .= elgg_view("group_tools/elements/group_tool", $options);
  75. }
  76. echo elgg_view_module("info", elgg_echo("group_tools:create_group:tool_presets:more_header"), $tools_content, array("id" => "group-tools-preset-more", "class" => "hidden"));
  77. ?>
  78. <script type="text/javascript">
  79. require(["group_tools/ToolsPreset"], function(ToolsPreset) {
  80. ToolsPreset.init("#group-tools-group-edit-tools");
  81. });
  82. </script>
  83. <?php
  84. } else {
  85. usort($tools, create_function('$a, $b', 'return strcmp($a->label, $b->label);'));
  86. foreach ($tools as $group_option) {
  87. $group_option_toggle_name = $group_option->name . "_enable";
  88. $value = elgg_extract($group_option_toggle_name, $vars);
  89. echo elgg_view("group_tools/elements/group_tool", array("group_tool" => $group_option, "value" => $value));
  90. }
  91. }
  92. ?>
  93. <script type="text/javascript">
  94. require(["group_tools/ToolsEdit"], function(ToolsEdit) {
  95. ToolsEdit.init("#group-tools-group-edit-tools");
  96. });
  97. </script>