preferences.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 = ApplicationMenu::GetFavoriteSiloQuery();
  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. if ($('#user_prefs table.pagination').length > 0)
  62. {
  63. // paginated display, restore the selection
  64. var pager = $('#user_prefs form .pager');
  65. $(':input[name=selectionMode]', pager).val('negative');
  66. $('#user_prefs table.listResults').trigger('load_selection');
  67. }
  68. else
  69. {
  70. CheckAll('#user_prefs .listResults :checkbox:not(:disabled)', true);
  71. }
  72. EOF
  73. );
  74. }
  75. else
  76. {
  77. $sChecked = implode('","', $aFavoriteOrgs);
  78. $oP->add_ready_script(
  79. <<<EOF
  80. var aChecked = ["$sChecked"];
  81. if ($('#user_prefs table.pagination').length > 0)
  82. {
  83. // paginated display, restore the selection
  84. var pager = $('#user_prefs form .pager');
  85. $(':input[name=selectionMode]', pager).val('positive');
  86. for (i=0; i<aChecked.length; i++)
  87. {
  88. pager.append('<input type="hidden" name="storedSelection[]" id="'+aChecked[i]+'" value="'+aChecked[i]+'"/>');
  89. }
  90. $('#user_prefs table.listResults').trigger('load_selection');
  91. }
  92. else
  93. {
  94. $('#user_prefs form :checkbox[name^=selectObject]').each( function()
  95. {
  96. if ($.inArray($(this).val(), aChecked) > -1)
  97. {
  98. $(this).attr('checked', true);
  99. $(this).trigger('change');
  100. }
  101. });
  102. }
  103. EOF
  104. );
  105. }}
  106. /////////////////////////////////////////////////////////////////////////////
  107. //
  108. // Main program
  109. //
  110. /////////////////////////////////////////////////////////////////////////////
  111. require_once(APPROOT.'/application/loginwebpage.class.inc.php');
  112. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  113. $iStep = utils::ReadParam('step', 1);
  114. $oPage = new iTopWebPage(Dict::S('UI:Preferences'));
  115. $sOperation = utils::ReadParam('operation', '');
  116. try
  117. {
  118. switch($sOperation)
  119. {
  120. case 'apply':
  121. $oFilter = DBObjectSearch::FromOQL('SELECT Organization');
  122. $sSelectionMode = utils::ReadParam('selectionMode', '');
  123. $aExceptions = utils::ReadParam('storedSelection', array());
  124. if (($sSelectionMode == 'negative') && (count($aExceptions) == 0))
  125. {
  126. // All Orgs selected
  127. appUserPreferences::SetPref('favorite_orgs', null);
  128. }
  129. else
  130. {
  131. // Some organizations selected... store them
  132. $aSelectOrgs = utils::ReadMultipleSelection($oFilter);
  133. appUserPreferences::SetPref('favorite_orgs', $aSelectOrgs);
  134. }
  135. DisplayPreferences($oPage);
  136. break;
  137. case 'display':
  138. default:
  139. DisplayPreferences($oPage);
  140. }
  141. $oPage->output();
  142. }
  143. catch(CoreException $e)
  144. {
  145. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  146. $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
  147. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  148. $oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
  149. $oP->output();
  150. if (MetaModel::IsLogEnabledIssue())
  151. {
  152. if (MetaModel::IsValidClass('EventIssue'))
  153. {
  154. $oLog = new EventIssue();
  155. $oLog->Set('message', $e->getMessage());
  156. $oLog->Set('userinfo', '');
  157. $oLog->Set('issue', $e->GetIssue());
  158. $oLog->Set('impact', 'Page could not be displayed');
  159. $oLog->Set('callstack', $e->getTrace());
  160. $oLog->Set('data', $e->getContextData());
  161. $oLog->DBInsertNoReload();
  162. }
  163. IssueLog::Error($e->getMessage());
  164. }
  165. // For debugging only
  166. //throw $e;
  167. }
  168. catch(Exception $e)
  169. {
  170. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  171. $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
  172. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  173. $oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
  174. $oP->output();
  175. if (MetaModel::IsLogEnabledIssue())
  176. {
  177. if (MetaModel::IsValidClass('EventIssue'))
  178. {
  179. $oLog = new EventIssue();
  180. $oLog->Set('message', $e->getMessage());
  181. $oLog->Set('userinfo', '');
  182. $oLog->Set('issue', 'PHP Exception');
  183. $oLog->Set('impact', 'Page could not be displayed');
  184. $oLog->Set('callstack', $e->getTrace());
  185. $oLog->Set('data', array());
  186. $oLog->DBInsertNoReload();
  187. }
  188. IssueLog::Error($e->getMessage());
  189. }
  190. }
  191. ?>