Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
search_manager_prefs.inc
1 <?php
18 require_once SQ_LIB_PATH.'/config/prefs.inc';
19 
32 {
33 
34  var $pref_vars = Array (
35  'SQ_SEARCH_BACKEND_PAGE_SIZE' => Array(
36  'name' => 'sch_pref_backend_page_size',
37  'description' => 'Set how many results are displayed to a page when a keyword search is performed from the Quick Search box',
38  'default' => 5,
39  'protected' => FALSE,
40  ),
41  'SQ_SEARCH_BACKEND_RESULT_LIMIT' => Array(
42  'name' => 'sch_pref_backend_result_limit',
43  'description' => 'The maximum number of results displayed in backend search (0 = no limit)',
44  'default' => 0,
45  'protected' => FALSE,
46  ),
47  );
48 
49 
54  function Content_Type_Raw_HTML_Prefs($pref_file='')
55  {
56  $this->Prefs($pref_file);
57 
58  }//end constructor
59 
60 
71  function paintBackend(&$o, $have_lock, $pref=NULL)
72  {
73  $is_root = $GLOBALS['SQ_SYSTEM']->userRoot();
74  $is_admin = ($is_root || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
75  if (is_null($pref) || $pref == 'SQ_SEARCH_BACKEND_PAGE_SIZE') {
76  if (is_null($pref)) {
77  $o->openField(translate($this->pref_vars['SQ_SEARCH_BACKEND_PAGE_SIZE']['name']));
78  }
79 
80  if ($have_lock && $is_admin) {
81  text_box('prefs[SQ_SEARCH_BACKEND_PAGE_SIZE]', $this->pref_vars['SQ_SEARCH_BACKEND_PAGE_SIZE']['default'], 10);
82  } else {
83  echo array_get_index($this->pref_vars['SQ_SEARCH_BACKEND_PAGE_SIZE'], 'default', 5);
84  }
85  echo ' '.translate('asset(s)');
86 
87  echo $o->note(translate('sch_pref_backend_page_size_note'));
88  if (is_null($pref)) $o->closeField();
89  }//end if
90 
91  if (is_null($pref) || $pref == 'SQ_SEARCH_BACKEND_RESULT_LIMIT') {
92  if (is_null($pref)) {
93  $o->openField(translate($this->pref_vars['SQ_SEARCH_BACKEND_RESULT_LIMIT']['name']));
94  }
95 
96  if ($have_lock && $is_admin) {
97  text_box('prefs[SQ_SEARCH_BACKEND_RESULT_LIMIT]', $this->pref_vars['SQ_SEARCH_BACKEND_RESULT_LIMIT']['default'], 10);
98  } else {
99  $result_limit = array_get_index($this->pref_vars['SQ_SEARCH_BACKEND_RESULT_LIMIT'], 'default', 0);
100  if ($result_limit == '0') {
101  echo translate('unlimited');
102  } else {
103  echo $result_limit.' '.translate('asset(s)');
104  }
105  }
106 
107 
108  echo $o->note(translate('sch_pref_backend_result_limit_note'));
109  if (is_null($pref)) $o->closeField();
110  }//end if
111 
112  return TRUE;
113 
114  }//end paintBackend()
115 
116 
127  function processBackend($o, $have_lock, $pref=NULL)
128  {
129  $is_root = $GLOBALS['SQ_SYSTEM']->userRoot();
130  $is_admin = ($is_root || $GLOBALS['SQ_SYSTEM']->userSystemAdmin());
131  if (!$is_admin) return FALSE;
132 
133  $changed = FALSE;
134 
135  // Backend page size
136  if (isset($_POST['prefs']['SQ_SEARCH_BACKEND_PAGE_SIZE'])) {
137 
138  // Not an integer = user mistake, or possible script injection?
139  if (!is_numeric($_POST['prefs']['SQ_SEARCH_BACKEND_PAGE_SIZE'])) {
140  trigger_localised_error('SCH0029', E_USER_WARNING);
141  return FALSE;
142  }
143 
144  $page_size = (int)$_POST['prefs']['SQ_SEARCH_BACKEND_PAGE_SIZE'];
145 
146  // Page size needs to be at least 1
147  if ($page_size <= 0) {
148  trigger_localised_error('SCH0029', E_USER_WARNING);
149  return FALSE;
150  }
151 
152  $this->pref_vars['SQ_SEARCH_BACKEND_PAGE_SIZE']['default'] = $page_size;
153 
154  $changed = TRUE;
155  }
156 
157  if (isset($_POST['prefs']['SQ_SEARCH_BACKEND_RESULT_LIMIT'])) {
158 
159  // Not an integer = user mistake, or possible script injection?
160  if (!is_numeric($_POST['prefs']['SQ_SEARCH_BACKEND_RESULT_LIMIT'])) {
161  trigger_localised_error('SCH0030', E_USER_WARNING);
162  return FALSE;
163  }
164 
165  $result_limit = (int)$_POST['prefs']['SQ_SEARCH_BACKEND_RESULT_LIMIT'];
166 
167  // Page size needs to be at least 1
168  if ($result_limit < 0) {
169  trigger_localised_error('SCH0030', E_USER_WARNING);
170  return FALSE;
171  }
172 
173  $this->pref_vars['SQ_SEARCH_BACKEND_RESULT_LIMIT']['default'] = $result_limit;
174 
175  $changed = TRUE;
176  }
177 
178  return TRUE;
179 
180  }//end processBackend()
181 
182 
183 }//end class
184 
185 ?>