ona  18.1.1
About: OpenNetAdmin provides a database managed inventory of your IP network (with Web and CLI interface).
  Fossies Dox: ona-18.1.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

xajax_setup.inc.php
Go to the documentation of this file.
1 <?php
3 //
4 // Xajax Setup
5 // This file is a site specific file that loads Xajax and several "modules"
6 // that we use. We are currently loading at least xajax,
7 //
9 
10 // Load Xajax and create an xajax object
11 
12 // xajax 0.5.x formatting
13 //require_once("{$include}/xajax/xajax_core/xajax.inc.php");
14 //$xajaxProcReq='processRequest';
15 
16 
17 
18 
19 
20 
21 // xajax 0.2.x formatting
22 require_once("{$include}/xajax/xajax.inc.php");
23 $xajaxProcReq='processRequests';
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 $xajax = new xajax();
34 
35 
36 
37 // Load various modules
38 // (registering several functions with xajax and loading additional js into the page)
39 require_once("{$include}/xajax_drag/drag.inc.php");
40 $conf['html_headers'] .= '<script type="text/javascript" src="'.$baseURL.'/include/xajax_drag/drag.js"></script>' . "\n";
41 
42 require_once("{$include}/xajax_suggest/suggest.inc.php");
43 $conf['html_headers'] .= '<script type="text/javascript" src="'.$baseURL.'/include/xajax_suggest/suggest.js"></script>' . "\n";
44 $conf['html_headers'] .= '<link rel="stylesheet" type="text/css" href="'.$baseURL.'/include/xajax_suggest/suggest.css" />' . "\n";
45 
46 require_once("{$include}/xajax_webwin/webwin.inc.php");
47 $conf['html_headers'] .= '<script type="text/javascript" src="'.$baseURL.'/include/xajax_webwin/webwin.js"></script>' . "\n";
48 $conf['html_headers'] .= '<script type="text/javascript" src="'.$baseURL.'/include/xajax_webwin/webwinTT.js"></script>' . "\n";
49 $conf['html_headers'] .= '<link rel="stylesheet" type="text/css" href="'.$baseURL.'/include/xajax_webwin/webwin.css" />' . "\n";
50 
51 
52 // These aren't AJAX, but it's part of our "Advanced Development Kit" ;-)
53 
54 // NIFTY CORNERS
55 // $conf['html_headers'] .= '<script type="text/javascript" src="'.$baseURL.'/include/js/nifty_corners/nifty.js"></script>' . "\n";
56 // $conf['html_headers'] .= '<link rel="stylesheet" type="text/css" href="'.$baseURL.'/include/js/nifty_corners/nifty_styles.css" />' . "\n";
57 // $conf['html_headers'] .= '<link rel="stylesheet" type="text/css" href="'.$baseURL.'/include/js/nifty_corners/nifty_print.css" media="print"/>' . "\n";
58 
59 // DomTT
60 // $conf['html_headers'] .= '<script type="text/javascript" src="'.$baseURL.'/include/js/domTT/domLib.js"></script>' . "\n";
61 // $conf['html_headers'] .= '<script type="text/javascript" src="'.$baseURL.'/include/js/domTT/domTT.js"></script>' . "\n";
62 
63 
64 
65 // Process xajax requests
66 $xajax->$xajaxProcReq();
67 
68 
69 // Include the xajax javascript in our html headers
70 $conf['html_headers'] .= $xajax->getJavascript($baseURL . '/include/xajax');
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
82 // Function: parse_options_string($string)
83 // Returns an array from a string of comma separated key => value pairs.
84 // If $string doesn't look like an array the original string is returned.
85 // I.E. "id => 14, name=>this is a test" becomes:
86 // array('id' => 14, 'name' => 'this is a test');
88 function parse_options_string($input) {
89  $array = array();
90 
91  // If the user supplied an array in a string, build the array and store it in $array
92  if (is_string($input) and preg_match('/=>/', $input)) {
93  $parts = explode(',', $input);
94  foreach ($parts as $part) {
95  $part = explode('=>', $part, 2);
96  $array[trim($part[0])] = trim($part[1]);
97  }
98  return($array);
99  }
100  return($input);
101 }
102 
103 
104 
105 
106 
108 // Function: get_page_links()
109 // Returns html links for paging lists of data.
110 // When a link is clicked it sends an xajax callback to
111 // window_submit($window_name, $page_num, 'change_page');
112 // That means in your "winc/{$window_name}.inc.php" you need to have a
113 // function called 'change_page()' defined!
115 function get_page_links($page=1, $per_page=1, $total=1, $window_name='', $form_id='') {
116  $html = '';
117 
118  // Build some variables
119  $max_page_links = 10; // MUST be divisible by 2
120 
121  // Number of total pages available
122  $total_pages = ceil($total/$per_page);
123  if ($total_pages == 1) { return(''); }
124 
125  // Find the first page link to display
126  $first_link = 1;
127  if ($page > ($max_page_links/2)) {
128  $first_link = (($page+1) - ($max_page_links/2));
129  }
130 
131  $html .= <<<EOL
132 
133  <!-- Page Links -->
134  <table width="100%" cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 0.2em;">
135  <tr>
136  <td id="page_links" style="font-weight: bold; " class="padding" align="center">
137 EOL;
138 
139 // Previous Page
140 if ($page > 1) {
141  $tmp = $page - 1;
142  $html .= <<<EOL
143  <a title="Previous page"
144  style="cursor: pointer;"
145  onClick="xajax_window_submit('{$window_name}', 'page=>{$tmp},form_id=>{$form_id}', 'change_page');"
146  >Back</a>&nbsp;&nbsp;
147 EOL;
148 }
149 
150 // Page Links
151 $i = $first_link;
152 while ($i <= $total_pages and ($i <= $max_page_links or $i <= ($page + ($max_page_links/2))) ) {
153  if ($page == $i) {
154  $html .= "\n<font color=\"#FF6F5F\">{$i}</font>&nbsp;";
155  }
156  else {
157  $html .= <<<EOL
158  <a title="Page {$i}"
159  style="cursor: pointer;"
160  onClick="xajax_window_submit('{$window_name}', 'page=>{$i},form_id=>{$form_id}', 'change_page');"
161  >{$i}</a>&nbsp;
162 EOL;
163  }
164  $i++;
165 }
166 $i--;
167 $html .= "&nbsp;";
168 
169 // Next Page Link
170 if ($i > $page) {
171  $tmp = $page + 1;
172  $html .= <<<EOL
173  <a title="Next page"
174  style="cursor: pointer;"
175  onClick="xajax_window_submit('{$window_name}', 'page=>{$tmp},form_id=>{$form_id}', 'change_page');"
176  >Next</a>
177 EOL;
178 }
179 
180 
181 $html .= <<<EOL
182 
183  </td>
184  </tr>
185  </table>
186 
187 EOL;
188 
189  return($html);
190 }
191 
192 
193 
194 
195 
197 // Function:
198 // change_page (string $window_name, int $page)
199 //
200 // Description:
201 // This function changes the "page" a person is viewing by setting the
202 // new page value in a hidden input field and then instructing the
203 // browser to do an xajax callback to the display_list() function.
204 //
205 // $form NEEDS form_id => id && page => page number
207 function ws_change_page($window_name, $form) {
208  global $conf, $self;
209 
210  // If the user supplied an array in a string, build the array and store it in $form
211  $form = parse_options_string($form);
212 
213  // Instantiate the xajaxResponse object
214  $response = new xajaxResponse();
215  $js = '';
216 
217  // Basically we're going to update the value of the input field called "page"
218  // in the "filter" form. Then we just have the browser do an xajax callback to
219  // update the list being displayed.
220  $js .= "el('{$form['form_id']}_page').value = '{$form['page']}';";
221  $js .= "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');";
222 
223  // Send an XML response to the window
224  $response->addScript($js);
225  return($response->getXML());
226 }
227 
228 
229 
230 
231 
232 
234 // Queries the database and returns an array of suggestions
235 // based on the criteria provided. Note that $q should usually
236 // have a % on the beginning or end of the string.
238 function get_text_suggestions($q="", $table="", $field="", $max_results=10) {
239  global $conf, $self, $onadb;
240  $results = array();
241 
242  // Don't return anything if we didn't get anything
243  if (!$q or ($max_results < 1) or !$table or !$field) { return($results); }
244 
245  $where = "{$field} LIKE " . $onadb->qstr($q);
246  $order = "{$field} ASC";
247 
248 
249  // Search the db for results
250  list ($status, $rows, $records) = db_get_records(
251  $onadb,
252  $table,
253  $where,
254  $order,
255  $max_results
256  );
257 
258  // If the query didn't work return the error message
259  if ($status) { $results[] = "Internal Error: {$self['error']}"; }
260 
261  foreach ($records as $record) {
262  $results[] = $record[$field];
263  }
264 
265  // Return the records
266  return($results);
267 }
268 
269 
270 
271 function get_username_suggestions($q, $max_results=10) {
272  return(get_text_suggestions($q.'%', 'users', 'username', $max_results));
273 }
274 
275 
276 
277 
279 // xajax server
280 // This function is called by the suggest() function.
282 function suggest_username($q, $el_input, $el_suggest) {
283  global $conf;
284 
285  // Instantiate the xajaxResponse object
286  $response = new xajaxResponse();
287  if (!$q or !$el_input or !$el_suggest) { return($response->getXML()); }
288  $js = "";
289 
290  // Search the DB
291  $results = get_username_suggestions($q);
292  $results = array_merge($results, get_username_suggestions('%'.$q, $conf['suggest_max_results'] - count($results)));
293  $results = array_unique($results);
294 
295  // Build the javascript to return
296  $js .= "suggestions = Array(";
297  $comma = "";
298  foreach ($results as $suggestion) {
299  $suggestion = str_replace("'", "\\'", $suggestion);
300  $js .= $comma . "'{$suggestion}'";
301  if (!$comma) { $comma = ", "; }
302  }
303  $js .= ");";
304 
305  // Tell the browser to execute the javascript in $js by sending an XML response
306  $js .= "suggest_display('{$el_input}', '{$el_suggest}');";
307  $response->addScript($js);
308  return($response->getXML());
309 }
310 function suggest_tse_username($q, $el_input, $el_suggest) {
311  return(suggest_username($q, $el_input, $el_suggest));
312 }
313 
314 
315 
316 ?>
$record
$record['display_name']
Definition: app_advanced_search.inc.php:12
db_get_records
db_get_records($dbh=0, $table="", $where="", $order="", $rows=-1, $offset=-1)
Definition: functions_db.inc.php:891
$status
$status
Definition: install.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
xajax
ws_change_page
ws_change_page($window_name, $form)
Definition: xajax_setup.inc.php:207
get_username_suggestions
get_username_suggestions($q, $max_results=10)
Definition: xajax_setup.inc.php:271
$xajaxProcReq
$xajaxProcReq
Definition: xajax_setup.inc.php:23
$baseURL
$baseURL
Definition: config.inc.php:25
suggest_tse_username
suggest_tse_username($q, $el_input, $el_suggest)
Definition: xajax_setup.inc.php:310
$form_id
$form_id
Definition: app_config_type_list.inc.php:28
EOL
< a style="text-decoration: none;" href="/">< input class='edit' type="button" value="I don't like free stuff?" onclick=""/></a ></center ></div > EOL
Definition: install.php:40
suggest_username
suggest_username($q, $el_input, $el_suggest)
Definition: xajax_setup.inc.php:282
xajaxResponse
Definition: xajaxResponse.inc.php:68
nbsp
& nbsp
Definition: install.php:36
get_page_links
get_page_links($page=1, $per_page=1, $total=1, $window_name='', $form_id='')
Definition: xajax_setup.inc.php:115
$self
global $self
Definition: 2-to-3.php:15
$conf
$conf['html_headers']
Definition: xajax_setup.inc.php:40
$xajax
$xajax
Definition: xajax_setup.inc.php:33
get_text_suggestions
get_text_suggestions($q="", $table="", $field="", $max_results=10)
Definition: xajax_setup.inc.php:238
parse_options_string
parse_options_string($input)
Definition: xajax_setup.inc.php:88