usermanagement_profileproj.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program 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; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Specific to the addon 'user management by profile'
  18. * Was developed for testing purposes only
  19. *
  20. * @author Erwan Taloc <erwan.taloc@combodo.com>
  21. * @author Romain Quetiez <romain.quetiez@combodo.com>
  22. * @author Denis Flaven <denis.flaven@combodo.com>
  23. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  24. */
  25. require_once('../application/application.inc.php');
  26. require_once('../application/itopwebpage.class.inc.php');
  27. require_once('../application/startup.inc.php');
  28. function ComputeProjections($oPage)
  29. {
  30. // Load the profiles for a further usage
  31. //
  32. $aProfiles = array();
  33. $oProfileSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Profiles"));
  34. while ($oProfile = $oProfileSet->Fetch())
  35. {
  36. $aProfiles[$oProfile->GetKey()] = $oProfile;
  37. }
  38. // Load the dimensions for a further usage
  39. //
  40. $aDimensions = array();
  41. $oDimensionSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Dimensions"));
  42. while ($oDimension = $oDimensionSet->Fetch())
  43. {
  44. $aDimensions[$oDimension->GetKey()] = $oDimension;
  45. }
  46. // Load the profile projections for a further usage
  47. //
  48. $aProPro = array();
  49. $oProProSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_ProfileProjection"));
  50. while ($oProPro = $oProProSet->Fetch())
  51. {
  52. $aProPros[$oProPro->Get('profileid')][$oProPro->Get('dimensionid')] = $oProPro;
  53. }
  54. // Setup display structure
  55. //
  56. $aDisplayConfig = array();
  57. $aDisplayConfig['user'] = array('label' => Dict::S('UI:UserManagement:User'), 'description' => Dict::S('UI:UserManagement:User+'));
  58. $aDisplayConfig['profile'] = array('label' => Dict::S('UI:UserManagement:Profile'), 'description' => Dict::S('UI:UserManagement:Profile+'));
  59. foreach ($aDimensions as $iDimension => $oDimension)
  60. {
  61. $aDisplayConfig['dim'.$oDimension->GetKey()] = array('label' => $oDimension->GetName(), 'description' => $oDimension->Get('description'));
  62. }
  63. // Load users, and create a record per couple user/profile
  64. //
  65. $aDisplayData = array();
  66. $oUserSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Users"));
  67. while ($oUser = $oUserSet->Fetch())
  68. {
  69. $oUserProfileSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_UserProfile WHERE userid = :user->id"), array(), array('user' => $oUser));
  70. while ($oUserProfile = $oUserProfileSet->Fetch())
  71. {
  72. $iProfile = $oUserProfile->Get('profileid');
  73. $oProfile = $aProfiles[$iProfile];
  74. $aUserProfileProj = array();
  75. $aUserProfileProj['user'] = $oUser->GetName();
  76. $aUserProfileProj['profile'] = $oProfile->GetName();
  77. foreach ($aDimensions as $iDimension => $oDimension)
  78. {
  79. // #@# to be moved, may be time consuming
  80. $oDimension->CheckProjectionSpec($aProPros[$iProfile][$iDimension], get_class($oUser));
  81. $aValues = $aProPros[$iProfile][$iDimension]->ProjectUser($oUser);
  82. if (is_null($aValues))
  83. {
  84. $sValues = htmlentities(Dict::S('UI:UserManagement:AnyObject'));
  85. }
  86. else
  87. {
  88. $sValues = implode(', ', $aValues);
  89. }
  90. $aUserProfileProj['dim'.$oDimension->GetKey()] = $sValues;
  91. }
  92. $aDisplayData[] = $aUserProfileProj;
  93. }
  94. }
  95. $oPage->table($aDisplayConfig, $aDisplayData);
  96. //$oPage->SetCurrentTab('Attributes');
  97. //$oPage->p("[<a href=\"?operation='list'\">All classes</a>]");
  98. //$oPage->add("</ul>\n");
  99. }
  100. require_once('../application/loginwebpage.class.inc.php');
  101. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  102. // Display the menu on the left
  103. $oContext = new UserContext();
  104. $oAppContext = new ApplicationContext();
  105. $iActiveNodeId = utils::ReadParam('menu', -1);
  106. $currentOrganization = utils::ReadParam('org_id', 1);
  107. $oPage = new iTopWebPage(Dict::S('UI:PageTitle:ProfileProjections'), $currentOrganization);
  108. $oPage->no_cache();
  109. ComputeProjections($oPage);
  110. $oPage->output();
  111. ?>