services_add.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * Create new Services for the Buy Courses plugin.
  5. *
  6. * @package chamilo.plugin.buycourses
  7. */
  8. $cidReset = true;
  9. require_once '../../../main/inc/global.inc.php';
  10. $plugin = BuyCoursesPlugin::create();
  11. $currency = $plugin->getSelectedCurrency();
  12. $em = Database::getManager();
  13. $users = UserManager::getRepository()->findAll();
  14. $userOptions = [];
  15. if (!empty($users)) {
  16. foreach ($users as $user) {
  17. $userOptions[$user->getId()] = $user->getCompleteNameWithUsername();
  18. }
  19. }
  20. api_protect_admin_script(true);
  21. $htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
  22. $htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
  23. //view
  24. $interbreadcrumb[] = [
  25. 'url' => 'list.php',
  26. 'name' => $plugin->get_lang('Configuration'),
  27. ];
  28. $globalSettingsParams = $plugin->getGlobalParameters();
  29. $formDefaultValues = [
  30. 'price' => 0,
  31. 'tax_perc' => $globalSettingsParams['global_tax_perc'],
  32. 'duration_days' => 0,
  33. 'applies_to' => 0,
  34. 'visibility' => true,
  35. ];
  36. $form = new FormValidator('Services');
  37. $form->addText('name', $plugin->get_lang('ServiceName'));
  38. $form->addHtmlEditor('description', $plugin->get_lang('Description'));
  39. $form->addElement(
  40. 'number',
  41. 'price',
  42. [$plugin->get_lang('Price'), null, $currency['iso_code']],
  43. ['step' => 0.01]
  44. );
  45. $form->addElement(
  46. 'number',
  47. 'tax_perc',
  48. [$plugin->get_lang('TaxPerc'), $plugin->get_lang('TaxPercDescription'), '%'],
  49. ['step' => 1, 'placeholder' => $globalSettingsParams['global_tax_perc'].'% '.$plugin->get_lang('ByDefault')]
  50. );
  51. $form->addElement(
  52. 'number',
  53. 'duration_days',
  54. [$plugin->get_lang('Duration'), null, get_lang('Days')],
  55. ['step' => 1]
  56. );
  57. $form->addElement(
  58. 'radio',
  59. 'applies_to',
  60. $plugin->get_lang('AppliesTo'),
  61. get_lang('None'),
  62. 0
  63. );
  64. $form->addElement(
  65. 'radio',
  66. 'applies_to',
  67. null,
  68. get_lang('User'),
  69. 1
  70. );
  71. $form->addElement(
  72. 'radio',
  73. 'applies_to',
  74. null,
  75. get_lang('Course'),
  76. 2
  77. );
  78. $form->addElement(
  79. 'radio',
  80. 'applies_to',
  81. null,
  82. get_lang('Session'),
  83. 3
  84. );
  85. $form->addElement(
  86. 'radio',
  87. 'applies_to',
  88. null,
  89. get_lang('TemplateTitleCertificate'),
  90. 4
  91. );
  92. $form->addSelect(
  93. 'owner_id',
  94. get_lang('Owner'),
  95. $userOptions
  96. );
  97. $form->addCheckBox('visibility', $plugin->get_lang('VisibleInCatalog'));
  98. $form->addFile(
  99. 'picture',
  100. (get_lang(
  101. 'AddImage'
  102. )),
  103. ['id' => 'picture', 'class' => 'picture-form', 'crop_image' => true, 'crop_ratio' => '16 / 9']
  104. );
  105. $form->addText('video_url', get_lang('VideoUrl'), false);
  106. $form->addHtmlEditor('service_information', $plugin->get_lang('ServiceInformation'), false);
  107. $form->addButtonSave(get_lang('Add'));
  108. $form->setDefaults($formDefaultValues);
  109. if ($form->validate()) {
  110. $values = $form->getSubmitValues();
  111. $plugin->storeService($values);
  112. Display::addFlash(
  113. Display::return_message($plugin->get_lang('ServiceAdded'), 'success')
  114. );
  115. header('Location: list.php');
  116. exit;
  117. }
  118. $templateName = $plugin->get_lang('NewService');
  119. $tpl = new Template($templateName);
  120. $tpl->assign('header', $templateName);
  121. $tpl->assign('content', $form->returnForm());
  122. $tpl->display_one_col_template();