preferences.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. * User preferences page
  18. * Displays / edit some user preferences
  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('../approot.inc.php');
  26. require_once(APPROOT.'/application/application.inc.php');
  27. require_once(APPROOT.'/application/itopwebpage.class.inc.php');
  28. require_once(APPROOT.'/application/startup.inc.php');
  29. /**
  30. * Displays the user's changeable preferences
  31. * @param $oP WebPage The web page used for the output
  32. */
  33. function DisplayPreferences($oP)
  34. {
  35. $oAppContext = new ApplicationContext();
  36. // Favorite organizations: the organizations listed in the drop-down menu
  37. $sOQL = 'SELECT Organization';
  38. $oFilter = DBObjectSearch::FromOQL($sOQL);
  39. $oBlock = new DisplayBlock($oFilter, 'list', false);
  40. $oP->add('<div class="page_header"><h1><img style="vertical-align:middle" src="../images/preferences.png"/>&nbsp;'.Dict::S('UI:Preferences')."</h1></div>\n");
  41. $oP->add('<div id="user_prefs" style="max-width:800px; min-width:400px;">');
  42. $oP->add('<fieldset><legend>'.Dict::S('UI:FavoriteOrganizations').'</legend>');
  43. $oP->p(Dict::S('UI:FavoriteOrganizations+'));
  44. $oP->add('<form method="post">');
  45. $oBlock->Display($oP, 1, array('menu' => false, 'selection_mode' => true, 'selection_type' => 'multiple', 'cssCount'=> '.selectedCount'));
  46. $oP->add($oAppContext->GetForForm());
  47. $oP->add('<input type="hidden" name="operation" value="apply"/>');
  48. $oP->add('</fieldset>');
  49. $sURL = utils::GetAbsoluteUrlAppRoot().'pages/UI.php';
  50. $oP->add('<p><input type="button" onClick="window.location.href=\''.$sURL.'\'" value="'.Dict::S('UI:Button:Cancel').'"/>');
  51. $oP->add('&nbsp;&nbsp;');
  52. $oP->add('<input type="submit" value="'.Dict::S('UI:Button:Apply').'"/></p>');
  53. $oP->add('</form>');
  54. $oP->add('</div>');
  55. $aFavoriteOrgs = appUserPreferences::GetPref('favorite_orgs', null);
  56. if ($aFavoriteOrgs == null)
  57. {
  58. // All checked
  59. $oP->add_ready_script(
  60. <<<EOF
  61. CheckAll('#user_prefs .listResults :checkbox:not(:disabled)', true);
  62. EOF
  63. );
  64. }
  65. else
  66. {
  67. $sChecked = implode('","', $aFavoriteOrgs);
  68. $oP->add_ready_script(
  69. <<<EOF
  70. $('#user_prefs form :checkbox[name^=selectObject]').each( function()
  71. {
  72. var aChecked = ["$sChecked"];
  73. if ($.inArray($(this).val(), aChecked) > -1)
  74. {
  75. $(this).attr('checked', true);
  76. $(this).trigger('change');
  77. }
  78. });
  79. EOF
  80. );
  81. }}
  82. /////////////////////////////////////////////////////////////////////////////
  83. //
  84. // Main program
  85. //
  86. /////////////////////////////////////////////////////////////////////////////
  87. require_once(APPROOT.'/application/loginwebpage.class.inc.php');
  88. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  89. $iStep = utils::ReadParam('step', 1);
  90. $oPage = new iTopWebPage(Dict::S('UI:Preferences'));
  91. $sOperation = utils::ReadParam('operation', '');
  92. try
  93. {
  94. switch($sOperation)
  95. {
  96. case 'apply':
  97. $oFilter = DBObjectSearch::FromOQL('SELECT Organization');
  98. $sSelectionMode = utils::ReadParam('selectionMode', '');
  99. $aExceptions = utils::ReadParam('storedSelection', array());
  100. if (($sSelectionMode == 'negative') && (count($aExceptions) == 0))
  101. {
  102. // All Orgs selected
  103. appUserPreferences::SetPref('favorite_orgs', null);
  104. }
  105. else
  106. {
  107. // Some organizations selected... store them
  108. $aSelectOrgs = utils::ReadMultipleSelection($oFilter);
  109. appUserPreferences::SetPref('favorite_orgs', $aSelectOrgs);
  110. }
  111. DisplayPreferences($oPage);
  112. break;
  113. case 'display':
  114. default:
  115. DisplayPreferences($oPage);
  116. }
  117. $oPage->output();
  118. }
  119. catch(CoreException $e)
  120. {
  121. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  122. $oP = new SetupWebPage(Dict::S('UI:PageTitle:FatalError'));
  123. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  124. $oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
  125. $oP->output();
  126. if (MetaModel::IsLogEnabledIssue())
  127. {
  128. if (MetaModel::IsValidClass('EventIssue'))
  129. {
  130. $oLog = new EventIssue();
  131. $oLog->Set('message', $e->getMessage());
  132. $oLog->Set('userinfo', '');
  133. $oLog->Set('issue', $e->GetIssue());
  134. $oLog->Set('impact', 'Page could not be displayed');
  135. $oLog->Set('callstack', $e->getTrace());
  136. $oLog->Set('data', $e->getContextData());
  137. $oLog->DBInsertNoReload();
  138. }
  139. IssueLog::Error($e->getMessage());
  140. }
  141. // For debugging only
  142. //throw $e;
  143. }
  144. catch(Exception $e)
  145. {
  146. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  147. $oP = new SetupWebPage(Dict::S('UI:PageTitle:FatalError'));
  148. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  149. $oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
  150. $oP->output();
  151. if (MetaModel::IsLogEnabledIssue())
  152. {
  153. if (MetaModel::IsValidClass('EventIssue'))
  154. {
  155. $oLog = new EventIssue();
  156. $oLog->Set('message', $e->getMessage());
  157. $oLog->Set('userinfo', '');
  158. $oLog->Set('issue', 'PHP Exception');
  159. $oLog->Set('impact', 'Page could not be displayed');
  160. $oLog->Set('callstack', $e->getTrace());
  161. $oLog->Set('data', array());
  162. $oLog->DBInsertNoReload();
  163. }
  164. IssueLog::Error($e->getMessage());
  165. }
  166. }
  167. ?>