m_category.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. Category-manager (add, edit & delete)
  5. */
  6. require_once 'rsys.php';
  7. // TODO: The global initialization scripts loads once again here. To be checked.
  8. $language_file = 'admin';
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. //
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_admin_script();
  14. Rsys :: protect_script('m_category');
  15. $tool_name = get_lang('BookingSystem');
  16. $interbreadcrumb[] = array ('url' => '../admin/index.php', 'name' => get_lang('PlatformAdmin'));
  17. /**
  18. * Filter to display the modify-buttons
  19. *
  20. * @param - int $id The ResourceType-id
  21. */
  22. function modify_filter($id) {
  23. return '<a href="m_category.php?action=edit&amp;id='.$id.'" title="'.get_lang("EditResourceType").'"><img alt="" src="../img/edit.gif" /></a>'.' <a href="m_category.php?action=delete&amp;id='.$id.'" title="'.get_lang("DeleteResourceType").'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmDeleteResourceType")))."'".')) return false;"><img alt="" src="../img/delete.gif" /></a>';
  24. }
  25. switch ($_GET['action']) {
  26. case 'add' :
  27. $interbreadcrumb[] = array ("url" => "m_category.php", "name" => $tool_name);
  28. Display :: display_header(get_lang('AddNewResourceType'));
  29. api_display_tool_title(get_lang('AddNewResourceType'));
  30. $form = new FormValidator('category', 'post', 'm_category.php?action=add');
  31. $form->add_textfield('name', get_lang('ResourceTypeName'), true, array ('maxlength' => '128'));
  32. $form->addElement('style_submit_button', 'submit', get_lang('CreateResourceType'),'class="add"');
  33. if ($form->validate()) {
  34. $values = $form->exportValues();
  35. if (Rsys :: add_category($values['name']))
  36. Display :: display_normal_message(Rsys :: get_return_msg(get_lang('ResourceTypeAdded'), "m_category.php", $tool_name),false);
  37. else
  38. Display :: display_normal_message(Rsys :: get_return_msg(get_lang('ResourceTypeExist'), "m_category.php?action=add", get_lang('AddNewResourceType')),false);
  39. } else
  40. $form->display();
  41. break;
  42. case 'edit' :
  43. $interbreadcrumb[] = array ("url" => "m_category.php", "name" => $tool_name);
  44. Display :: display_header(get_lang('EditResourceType'));
  45. api_display_tool_title(get_lang('EditResourceType'));
  46. $form = new FormValidator('category', 'post', 'm_category.php?action=edit');
  47. $form->add_textfield('name', get_lang('ResourceTypeName'), true, array ('maxlength' => '128'));
  48. $form->addElement('hidden', 'id', $_GET['id']);
  49. $form->addElement('style_submit_button', 'submit', get_lang('ModifyResourceType'),'class="save"');
  50. $form->setDefaults(Rsys :: get_category($_GET['id']));
  51. if ($form->validate()) {
  52. $values = $form->exportValues();
  53. if (Rsys :: edit_category($values['id'], $values['name']))
  54. Display :: display_normal_message(Rsys :: get_return_msg(get_lang('ResourceTypeEdited'), "m_category.php", $tool_name),false);
  55. else
  56. Display :: display_normal_message(Rsys :: get_return_msg(get_lang('ResourceTypeExist'), "m_category.php?action=edit&id=".$values['id'], get_lang('EditRight')),false);
  57. } else
  58. $form->display();
  59. break;
  60. case 'delete' :
  61. $result = Rsys :: delete_category($_GET['id']);
  62. ob_start();
  63. if ($result == 0)
  64. Display :: display_normal_message(get_lang('ResourceTypeDeleted'),false);
  65. else
  66. Display :: display_normal_message(str_replace('#NUM#', $result, get_lang('ResourceTypeHasItems')),false);
  67. $msg = ob_get_contents();
  68. ob_end_clean();
  69. default :
  70. $NoSearchResults = get_lang('NoCategories');
  71. Display :: display_header($tool_name);
  72. api_display_tool_title($tool_name);
  73. echo $msg;
  74. echo '<div class="actions">';
  75. echo '<a href="m_category.php?action=add"><img src="../img/view_more_stats.gif" border="0" alt="" title="'.get_lang('AddNewBookingPeriod').'"/>'.get_lang('AddNewResourceType').'</a><br />';
  76. echo '</div>';
  77. if (isset ($_POST['action'])) {
  78. switch ($_POST['action']) {
  79. case 'delete_categories' :
  80. $ids = $_POST['categories'];
  81. if (count($ids) > 0) {
  82. foreach ($ids as $index => $id) {
  83. $result = Rsys :: delete_category($id);
  84. if ($result != 0)
  85. $warning = true;
  86. }
  87. }
  88. if ($warning) {
  89. ob_start();
  90. Display :: display_normal_message(get_lang('ResourceTypeNotDeleted'),false);
  91. $msg2 = ob_get_contents();
  92. ob_end_clean();
  93. }
  94. break;
  95. }
  96. }
  97. echo $msg2;
  98. $table = new SortableTable('category', array ('Rsys', 'get_num_categories'), array ('Rsys', 'get_table_categories'), 1);
  99. $table->set_header(0, '', false, array ('style' => 'width:10px'));
  100. $table->set_header(1, '', false);
  101. $table->set_header(2, '', false, array ('style' => 'width:50px;'));
  102. $table->set_column_filter(2, 'modify_filter');
  103. $table->set_form_actions(array ('delete_categories' => get_lang('DeleteSelectedCategories')), 'categories');
  104. $table->display();
  105. }
  106. /**
  107. ---------------------------------------------------------------------
  108. */
  109. Display :: display_footer();
  110. ?>