profile.class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. class PluginSinglesignonProfile extends CommonDBTM {
  3. const READMY = 1;
  4. const CHANGENAME = 1024;
  5. //Não usa tabela própria
  6. static protected $notable = true;
  7. function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
  8. if (!$withtemplate) {
  9. if ($item->getType() == 'Profile') {
  10. return __('Live Helper Chat');
  11. }
  12. }
  13. return '';
  14. }
  15. function getRights($interface = 'central') {
  16. $values = [
  17. self::READMY => 'Visualizar',
  18. self::CHANGENAME => 'Alterar Nome',
  19. ];
  20. return $values;
  21. }
  22. /**
  23. *
  24. * @param Profile $profile
  25. */
  26. function showForm($profile) {
  27. $canedit = Session::haveRightsOr(Profile::$rightname, [CREATE, UPDATE, PURGE]);
  28. echo "<div class='spaced'>";
  29. if ($canedit) {
  30. echo "<form name='form' action=\"" . Toolbox::getItemTypeFormURL('Profile') . "\" method='post'>";
  31. }
  32. $matrix_options = [
  33. 'canedit' => $canedit,
  34. 'default_class' => 'tab_bg_2',
  35. ];
  36. $rights = [
  37. [
  38. 'rights' => Profile::getRightsFor('PluginLivehelperchatProfile', 'central'),
  39. 'label' => 'Widget',
  40. 'field' => 'plugin_livehelperchat_widget'
  41. ],
  42. [
  43. 'rights' => Profile::getRightsFor('PluginLivehelperchatChat', 'central'),
  44. 'label' => 'Visualizar Chat do Ticket',
  45. 'field' => 'plugin_livehelperchat_chat'
  46. ],
  47. ];
  48. $matrix_options['title'] = 'Live Helper Chat';
  49. $profile->displayRightsChoiceMatrix($rights, $matrix_options);
  50. if ($canedit) {
  51. //Botão
  52. echo "<div class='center'>";
  53. echo "<input type='hidden' name='id' value='" . $profile->fields['id'] . "'>";
  54. echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit'>";
  55. echo "</div>\n";
  56. Html::closeForm();
  57. }
  58. echo "</div>";
  59. }
  60. static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
  61. if ($item->getType() == 'Profile') {
  62. $config = new self();
  63. $config->showForm($item);
  64. }
  65. return true;
  66. }
  67. static function install() {
  68. $profile_widget = 'plugin_livehelperchat_widget';
  69. $profile_chat = 'plugin_livehelperchat_chat';
  70. $profileRight = new ProfileRight();
  71. $profiles = $profileRight->find("`name` = 'livehelperchat'", '', '');
  72. //Se existir permissões antigas, renomea-las
  73. if (!empty($profiles)) {
  74. foreach ($profiles as $profile) {
  75. $profile['name'] = $profile_widget;
  76. $profileRight->update($profile);
  77. }
  78. }
  79. /**
  80. * Widget
  81. */
  82. $profileWidget = $profileRight->find("`name` = '$profile_widget'", '', 1);
  83. //Caso não existir, criar novos profiles
  84. if (empty($profileWidget)) {
  85. ProfileRight::addProfileRights([$profile_widget]);
  86. ProfileRight::updateProfileRightAsOtherRight($profile_widget, PluginLivehelperchatProfile::READMY, '');
  87. ProfileRight::updateProfileRightAsOtherRight($profile_widget, PluginLivehelperchatProfile::CHANGENAME, '');
  88. }
  89. /**
  90. * Chat Ticket
  91. */
  92. $profileChat = $profileRight->find("`name` = '$profile_chat'", '', 1);
  93. //Caso não existir, criar novos profiles
  94. if (empty($profileChat)) {
  95. ProfileRight::addProfileRights([$profile_chat]);
  96. ProfileRight::updateProfileRightAsOtherRight($profile_chat, READ, '');
  97. }
  98. }
  99. static function uninstall() {
  100. ProfileRight::deleteProfileRights(['plugin_livehelperchat_widget']);
  101. }
  102. }