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)  

webwin.inc.php
Go to the documentation of this file.
1 <?php
3 //
4 // Documentation: Before using this you MUST have a div in your web page like this one:
5 // <div id="window_container"></div>
6 // All windows will be a child of this div. Also initial position of new
7 // windows will be based on the location of this div on the page.
8 //
9 // FIXME: Shouldn't rely on site specific variables like $style, $color, etc.
10 // FIXME: Requires javascript function RemoveElement() from global.js
11 // FIXME: Uses the "padding" style from the global stylesheet
12 //
13 // CHANGELOG:
14 // 2006-02-28 - Updated window_submit() - submitted functions must be prefixed with "ws_"
15 // 2006-03-28 - Fix new window creation to prevent "flicker"
16 //
18 global $color;
19 $color['window_title_bg'] = '#69A6DE';
20 $color['window_title_font'] = '#294157';
21 $color['window_tab_active_bg'] = '#E5E3F0';
22 $color['window_tab_inactive_bg'] = '#FFFFFF';
23 $color['window_content_bg'] = '#F2F2F2';
24 
25 
26 // These are the functions we'll be exposing via Xajax
27 // xajax 0.2.x format
28 $xajax->registerFunction("window_open");
29 $xajax->registerFunction("window_submit");
30 
31 // for when and if I switch to xajax 0.5.x
32 //$xajax->register(XAJAX_FUNCTION,"window_submit");
33 //$xajax->register(XAJAX_FUNCTION,"window_open");
34 
35 
36 
37 
39 // Xajax Server
40 // Generic xajax "server" to opens a new "window" in the current web page.
41 //
42 // Is typically called from the javascript toggle_window() function, but
43 // can by called by any other PHP function assuming the web client is
44 // expecting an xajax response.
45 //
46 // If only a window_name is provided it will attempt to find/load the html
47 // to be inserted into the new window. If no "header" or "footer" is provided
48 // a default header/footer will be used to provide the new "window" with
49 // a standardized title-bar and close button.
50 //
51 // Valid array elements for $window[]
52 // title
53 // header
54 // html
55 // footer
56 // js (extra javascript to run after window is built)
57 //
59 function window_open($window_name, $window=array()) {
60  // Instantiate the xajaxResponse object
61  $response = new xajaxResponse();
62  if (!$window_name) { return($response->getXML()); }
63 
64  // Variables that might be used in building HTML :: FIXME this is site specific!
66 
67  // Load $window_html and $window_title from an include file
68  $file = window_find_include($window_name);
69  if ($file) { require_once($file); }
70 
71  // Setup a header and footer for the new window
72  if (!$window['header']) {
73  $window['header'] = <<<EOL
74 
75  <!-- This wrapper table is so that internal tables can be set to 100% width and they won't stretch the box too wide. -->
76  <table id="{$window_name}_table" cellspacing="0" border="0" cellpadding="0">
77  <tr>
78  <td>
79 
80  <!-- Window bar and close button -->
81  <table id="{$window_name}_title_table" class="window_title" style="border-bottom: 1px solid #69A6DE;background-color: {$color['window_title_bg']};" width="100%" cellspacing="0" border="0" cellpadding="0">
82  <tr>
83 
84  <td id="{$window_name}_title"
85  width="99%"
86  align="left"
87  nowrap="true"
88  onMouseDown="focus_window('$window_name'); dragStart(event, '{$window_name}');"
89  style="cursor: move;
90  white-space: nowrap;
91  font-weight: bold;
92  text-align: left;
93  padding: 2px 4px;">{$window['title']}</td>
94 
95  <td id="{$window_name}_title_r"
96  align="right"
97  nowrap="true"
98  style="color: {$color['window_title_font']};
99  white-space: nowrap;
100  text-align: right;
101  padding: 2px 4px;"><span id="{$window_name}_title_help"></span>&nbsp;<a title="Close window" style="cursor: pointer;" onClick="removeElement('{$window_name}');"><img src="{$images}/icon_close.gif" border="0" /></a></td>
102 
103  </tr>
104  </table>
105 EOL;
106  }
107  if (!$window['footer']) {
108  $window['footer'] = <<<EOL
109  </td>
110  </tr>
111  </table>
112 EOL;
113  }
114 
115  // Create a new div to display the content in
116  $response->addScript("removeElement('{$window_name}');");
117  $response->addCreate("window_container", "div", $window_name);
118  $response->addScript(
119  "initialize_window('{$window_name}');" .
120  "el('$window_name').style.display = 'none';" .
121  "el('$window_name').style.visibility = 'hidden';" .
122  "el('$window_name').onclick = function(ev) { focus_window(this.id); };"
123  );
124  $response->addAssign($window_name, "innerHTML", $window['header'] . $window['html'] . $window['footer']);
125  $response->addScript("toggle_window('{$window_name}');" . $window['js']);
126 
127  // Send an XML response to the web browser
128  return($response->getXML());
129 }
130 
131 
132 
133 
135 // Xajax Server
136 // Function:
137 // window_submit ($window_name, [$form_data], [$function])
138 //
139 // Description:
140 // Generic wrapper to handle window form submits.
141 // Is typically called when a client pushes a submit-like button in
142 // their web application.
143 //
144 // Input:
145 // $window_name The name of the "window" submitting data
146 // $form[] An optional array/string containing the (form?) data
147 // being submitted.
148 // This will often be generated by using this javascript
149 // xajax call: xajax.getFormValues('form_id')
150 // $function The optional name of a PHP function to pass the first two
151 // parameters to. For security reasons, the actual function
152 // called will be "ws_{$function}".
153 // If a function name is not specified, the default is
154 // "ws_{$window_name}_submit" or "ws_submit"
155 //
157 function window_submit($window_name, $form='', $function='') {
158  // Instantiate the xajaxResponse object
159  $response = new xajaxResponse();
160  if (!$window_name or !$form) { return($response->getXML()); }
161  $js = "";
162 
163  printmsg("DEBUG => webwin_submit() Window: {$window_name} Function: {$function} Form: {$form}", 1);
164 
165  // If a function name wasn't provided, we look for a function called:
166  // $window_name . '_submit'
167  if (!$function) {
168  $function = "{$window_name}_submit";
169  }
170  $function = 'ws_' . $function;
171 
172  // If the function exists, run it and return it's output (an xml response)
173  if (function_exists($function)) { return($function($window_name, $form)); }
174 
175  // Try looking for the same function in an include file
176  $file = window_find_include($window_name);
177  if ($file) { require_once($file); }
178  else { $response->addAssign("work_space_content", "innerHTML", "<br><center><font color=\"red\"><b>Invalid window requested: {$window_name}</b></font></center>"); }
179 
180  // Now see if our function is available...
181  if (function_exists($function)) { return($function($window_name, $form)); }
182 
183  // Ok, I couldn't find anything to do.. just return an empty XML response
184  printmsg("NOTICE => webwin_submit() invalid function called! Window: {$window_name} Function: {$function}", 0);
185  return($response->getXML());
186 }
187 
188 
189 
190 
191 
192 
193 
195 // Function:
196 // window_find_include ($window_name)
197 //
198 // Description:
199 // Internally used function that searches several places for an include
200 // file containing information about a "window" named $window_name.
201 // Returns the filename if one is found.
202 //
204 function window_find_include($window_name) {
205  if (!$window_name) { return(''); }
206 
207  $file = '';
208 
209  // Check the usual directories, now inlucdes the local plugins as well.
210  // local plugins should override the builtin stuff if they are named the same.
211  $directories = array('.',
212  './local/plugins/'.$window_name,
213  './winc',
214  './plugins/'.$window_name,
215  './inc',
216  );
217 
218  // Find the file if at all possible!
219 //MP: disabled this as we do not use _win_ anywhere
220 // foreach ($directories as $directory) {
221 // $file = "{$directory}/_win_{$window_name}.inc.php";
222 // if (is_file($file)) {
223 // return($file);
224 // }
225 // }
226 
227  // If we still didn't find it, try it without the '_win_' in the file prefix
228  // but with a .inc.php extension.
229  foreach ($directories as $directory) {
230  if (!file_exists($directory.'/plugin_disabled')){
231  $file = "{$directory}/{$window_name}.inc.php";
232  if (is_file($file)) {
233  return($file);
234  }
235  }
236  }
237 
238  // If we still have not found it, lets just try the windowname as the file itself
239  if (is_file('.'.$window_name)) {
240  return('.'.$window_name);
241  }
242 
243  // Couldn't find it :|
244  return(FALSE);
245 }
246 
247 
248 
249 
250 
251 ?>
window_find_include
window_find_include($window_name)
Definition: webwin.inc.php:204
$window
$window['title']
Definition: install.php:26
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
window_open
window_open($window_name, $window=array())
Definition: webwin.inc.php:59
$images
$images
Definition: config.inc.php:26
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
xajaxResponse
Definition: xajaxResponse.inc.php:68
$style
$style['font-family']
Definition: config.inc.php:158
$font_family
global $font_family
Definition: app_admin_tools.inc.php:4
$xajax
$xajax
Definition: xajax_setup.inc.php:33
$color
global $color
Definition: webwin.inc.php:18