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)  

list_configs.inc.php
Go to the documentation of this file.
1 <?php
2 
3 
4 
6 // Function: ws_display()
7 //
8 // Description:
9 // Displays A list of configs based on search criteria.
10 // Input: An array from xajaxGetFormValues() from a quick filter form.
12 function ws_display_list($window_name, $form='') {
13  global $conf, $self, $onadb, $baseURL;
14  global $images, $color, $style;
15  $html = '';
16  $js = '';
17  $debug_val = 3; // used in the auth() calls to supress logging
18 
19  // If the user supplied an array in a string, build the array and store it in $form
20  $form = parse_options_string($form);
21 
22  // Find the "tab" we're on
23  $tab = $_SESSION['ona'][$form['form_id']]['tab'];
24 
25  // Build js to refresh this list
26  $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');";
27 
28  // If it's not a new query, load the previous query from the session
29  // into $form and save the current page and filter in the session.
30  // Also find/set the "page" we're viewing
31  $page = 1;
32  if ($form['page'] and is_numeric($form['page'])) {
33  $form = array_merge($form, (array)$_SESSION['ona'][$form['form_id']][$tab]['q']);
34  $_SESSION['ona'][$form['form_id']][$tab]['page'] = $page = $form['page'];
35  $_SESSION['ona'][$form['form_id']][$tab]['filter'] = $form['filter'];
36  }
37 
38  // Calculate the SQL query offset (based on the page being displayed)
39  $offset = ($conf['search_results_per_page'] * ($page - 1));
40  if ($offset == 0) { $offset = -1; }
41 
42  // Search results go in here
43  $results = array();
44  $count = 0;
45 
46  // Start building the "where" clause for the sql query to find the records to display
47  $where = '';
48  $and = '';
49 
50  // DISPLAY ALL CONFIGS
51  if ($form['all_flag']) {
52  $where .= $and . "id > 0";
53  $and = " AND ";
54  }
55 
56  if ($form['host_id']) {
57  $where .= 'host_id = '.$form['host_id'];
58  $and = " AND ";
59  }
60 
61  // Do the SQL Query
62  $filter = '';
63  if ($form['filter']) {
64  $filter = $and . ' configuration_type_id in (select id from configuration_types where name like "%' . $form['filter'] . '%")';
65  }
66  list ($status, $rows, $results) =
68  $onadb,
69  'configurations',
70  $where . $filter,
71  'configuration_type_id ASC, ctime DESC',
72  $conf['search_results_per_page'],
73  $offset
74  );
75 
76  // If we got less than search_results_per_page, add the current offset to it
77  // so that if we're on the last page $rows still has the right number in it.
78  if ($rows > 0 and $rows < $conf['search_results_per_page']) {
79  $rows += ($conf['search_results_per_page'] * ($page - 1));
80  }
81 
82  // If there were more than $conf['search_results_per_page'] find out how many records there really are
83  else if ($rows >= $conf['search_results_per_page']) {
84  list ($status, $rows, $records) =
86  $onadb,
87  'configurations',
88  $where . $filter,
89  "",
90  0
91  );
92  }
93  $count = $rows;
94 
95  $html .= <<<EOL
96  <!-- Config List -->
97  <table id="{$form['form_id']}_config_list" class="list-box" cellspacing="0" border="0" cellpadding="0">
98 
99  <!-- Table Header -->
100  <tr>
101  <td class="list-header" align="center" style="{$style['borderR']};">A</td>
102  <td class="list-header" align="center" style="{$style['borderR']};">B</td>
103  <td class="list-header" align="center" style="{$style['borderR']};">Date</td>
104  <td class="list-header" align="center" style="{$style['borderR']};">Type</td>
105  <td class="list-header" align="center" style="{$style['borderR']};">MD5 Checksum</td>
106  <td class="list-header" align="center" style="{$style['borderR']};">Size (chars)</td>
107  <td class="list-header" align="center">&nbsp;</td>
108  </tr>
109 EOL;
110 
111  // Loop and display each record
112  foreach($results as $record) {
113  $id++; // Counter used for comparison seleciton
114 
115  // Grab some info from the associated record
116  list($status, $rows, $ctype) = ona_get_config_type_record(array('id' => $record['configuration_type_id']));
117  $record['config_type_name'] = $ctype['name'];
118 
119  // Escape data for display in html
120  foreach(array_keys($record) as $key) {
121  $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
122  }
123 
124  // MP: FIXME still not working right for encoded stings.. always returns 0
125  $confsize = mb_strlen(html_entity_decode($record['config_body'], ENT_QUOTES, $conf['php_charset']), $conf['php_charset']);
126 
127  $html .= <<<EOL
128  <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">
129 
130  <td align="center" class="list-row" style="padding-right: 4px; width: 20px;"
131  ><input id="old{$id}" name="old" type="radio" value="{$record['id']}"
132  onClick="
133  var tmp = 1; var obj = el('new' + tmp);
134  while (obj) {
135  obj.style.visibility = (tmp <= {$id}) ? 'visible' : 'hidden';
136  if (tmp > {$id}) obj.checked = false;
137  obj = el('new' + tmp++);
138  }"
139  >
140  </td>
141 
142  <td class="list-row" align="center" style="width: 20px;">
143  <input id="new{$id}" style="visibility: hidden;" name="new" type="radio" value="{$record['id']}">
144  </td>
145 
146  <td class="list-row" align="center">
147  {$record['ctime']}&nbsp;
148  </td>
149 
150  <td class="list-row" align="center">
151  {$record['config_type_name']}&nbsp;
152  </td>
153 
154  <td class="list-row" align="center">
155  {$record['md5_checksum']}&nbsp;
156  </td>
157 
158  <td class="list-row" align="center">
159  {$confsize}
160  </td>
161  <td class="list-row" align="right">
162  <form id="{$form['form_id']}_list_configs_{$record['id']}"
163  ><input type="hidden" name="config_id" value="{$record['id']}"
164  ><input type="hidden" name="js" value="{$refresh}"
165  ></form>
166 EOL;
167 
168  if (auth('host_config_admin',$debug_val)) {
169  $html .= <<<EOL
170 
171  <a title="View config. ID: {$record['id']}"
172  class="act"
173  onClick="xajax_window_submit('work_space', 'xajax_window_submit(\'display_config_text\', \'host_id=>{$record['host_id']},type_id=>{$record['configuration_type_id']},displayconf=>{$record['id']}\', \'display\')');"
174  ><img src="{$images}/silk/zoom.png" border="0"></a>&nbsp;
175 
176  <a title="Download config"
177  class="act"
178  target="null"
179  href="{$baseURL}/config_dnld.php?config_id={$record['id']}&download=1"
180  ><img src="{$images}/silk/disk.png" alt="Download config" border="0"></a>&nbsp;
181 
182  <a title="Delete config"
183  class="nav"
184  onClick="var doit=confirm('Are you sure you want to delete this config record?');
185  if (doit == true)
186  xajax_window_submit('display_config_text', xajax.getFormValues('{$form['form_id']}_list_configs_{$record['id']}'), 'delete_config');"
187  ><img src="{$images}/silk/delete.png" alt="Delete config" border="0"></a>&nbsp;
188 
189 EOL;
190  }
191 
192  $html .= <<<EOL
193  &nbsp;
194  </td>
195 
196  </tr>
197 
198 EOL;
199  }
200 
201 
202  $html .= <<<EOL
203  </table>
204 EOL;
205  // Build page links if there are any
206  $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
207 
208 
209 
210  // Insert the new html into the content div specified
211  // Instantiate the xajaxResponse object
212  $response = new xajaxResponse();
213  $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})");
214  $response->addAssign($form['content_id'], "innerHTML", $html);
215  if ($js) { $response->addScript($js); }
216  return($response->getXML());
217 }
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 ?>
$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
$tab
$tab
Definition: app_config_type_list.inc.php:29
$baseURL
$baseURL
Definition: config.inc.php:25
$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
$_SESSION
$_SESSION['ona']['auth']
Definition: login.php:14
$conf
global $conf
Definition: 2-to-3.php:15
xajaxResponse
Definition: xajaxResponse.inc.php:68
$style
$style['font-family']
Definition: config.inc.php:158
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
ona_get_config_type_record
ona_get_config_type_record($array='', $order='')
Definition: functions_db.inc.php:1171
auth
auth($resource, $msg_level=1)
Definition: functions_general.inc.php:1330
$color
if($_SERVER['SERVER_PORT']==443) $color['bg']
Definition: config.inc.php:119
ws_display_list
ws_display_list($window_name, $form='')
Definition: list_configs.inc.php:12
parse_options_string
parse_options_string($input)
Definition: xajax_setup.inc.php:88