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)  

get_module_list.inc.php
Go to the documentation of this file.
1 <?php
2 // DON'T put whitespace at the beginning or end of this file!!!
3 
4 
5 
6 
8 // Function: get_module_list (string $options='')
9 //
10 // Input Options:
11 // $options = key=value pairs of options for this function.
12 // multiple sets of key=value pairs should be separated
13 // by an "&" symbol.
14 //
15 // Output:
16 // Returns a two part list:
17 // 1. The exit status of the function. 0 on success, non-zero on
18 // error. All errors messages are stored in $self['error'].
19 // 2. A textual message for display on the console or web interface.
20 //
21 // Example: list($status, $result) = get_module_list('type=string');
23 function get_module_list($options="type=string") {
24  global $conf, $self, $onadb;
25  printmsg('DEBUG => get_module_list('.$options.') called', 3);
26 
27  // Version - UPDATE on every edit!
28  $version = '1.01';
29 
30  // Parse incoming options string to an array
31  $options = parse_options($options);
32 
33  // Return the usage summary if we need to
34  if ($options['help'] or !$options['type']) {
35  $self['error'] = 'ERROR => Insufficient parameters';
36  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
37  return(array(1,
38 <<<EOM
39 
41 Returns a list of available DCM modules
42 
43  Synopsis: get_module_list(OPTIONS)
44 
45  Options:
46  type=<string|perl|array> format module list in the specified format
47  string = human readable for console
48  perl = hash for perl parsing
49  array = php array
50 \n
51 EOM
52 
53  ));
54  }
55 
56  // $pad_length is the amount of padding to put after each NAME.
57  $pad_length = 25;
58  $modules_string = str_pad('NAME', $pad_length) . " :: DESCRIPTION\n";
59  $modules_perl = "";
60  $modules_array = array();
61 
62  // Get a list of the valid "modules" and their descriptions.
63 
64  // FIXME: move this to the db later!
65  list($status, $rows, $modules) = db_get_records($onadb, 'dcm_module_list', '1', 'name');
66  printmsg("DEBUG => get_module_list() found {$rows} modules in db", 4);
67  foreach ($modules as $module) {
68  if ($module['name'] != 'get_module_list') {
69  $modules_string .= str_pad($module['name'], $pad_length) . " :: {$module['description']}\n";
70  }
71  $modules_array[$module['name']] = $module['description'];
72  $modules_perl .= "\$modules{'{$module['name']}'} = \"{$module['description']}\";\n";
73  }
74 
75  // Return the list of modules as a string or array.
76  if ($options['type'] == 'string')
77  return (array(0, "\n" . $modules_string . "\n"));
78  else if ($options['type'] == 'array')
79  return(array(0, $modules_array));
80  else if ($options['type'] == 'perl')
81  return(array(0, $modules_perl));
82  else
83  return(array(3, "ERROR => get_module_list() Invalid \"type\" specified!"));
84 }
85 
86 
88 // Function: add_module (string $options='')
89 //
90 // Input Options:
91 // $options = key=value pairs of options for this function.
92 // multiple sets of key=value pairs should be separated
93 // by an "&" symbol.
94 //
95 // Output:
96 // Returns a two part list:
97 // 1. The exit status of the function. 0 on success, non-zero on
98 // error. All errors messages are stored in $self['error'].
99 // 2. A textual message for display on the console or web interface.
100 //
101 // Example: list($status, $result) = add_module('');
103 function add_module($options="") {
104  global $conf, $self, $onadb;
105  printmsg('DEBUG => add_module('.$options.') called', 3);
106 
107  // Version - UPDATE on every edit!
108  $version = '1.00';
109 
110  // Parse incoming options string to an array
111  $options = parse_options($options);
112 
113  // Return the usage summary if we need to
114  if ($options['help'] or !$options['name']) {
115  $self['error'] = 'ERROR => Insufficient parameters';
116  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
117  return(array(1,
118 <<<EOM
119 
121 Registers a new DCM module, this should be used by install scripts that are
122 creating new functionality that requires a registered module.
123 
124  Synopsis: add_module(OPTIONS)
125 
126  Options:
127  name=STRING Name of DCM module
128  desc=STRING Quoted string to describe this module
129  file=STRING Path to php file, relative to {$conf['dcm_module_dir']}
130 
131 \n
132 EOM
133 
134  ));
135  }
136 
137 
138  // Get a list of the valid "modules" and their descriptions.
139  list($status, $rows, $modules) = db_get_record($onadb, 'dcm_module_list', array('name' => $options['name']), '');
140  if ($rows) {
141  $self['error'] = "ERROR => add_module() Module name already exists: {$options['name']}";
142  printmsg($self['error'],0);
143  return(array(1, $self['error'] . "\n"));
144  }
145 
146  // Add the record
147  list($status, $rows) =
149  $onadb,
150  'dcm_module_list',
151  array(
152  'name' => $options['name'],
153  'description' => $options['desc'],
154  'file' => $options['file'],
155  )
156  );
157  if ($status or !$rows) {
158  $self['error'] = "ERROR => add_module() SQL Query failed: " . $self['error'];
159  printmsg($self['error'],0);
160  return(array(2, $self['error'] . "\n"));
161  }
162 
163 
164  // Return the success notice
165  $self['error'] = "INFO => Module ADDED: {$options['name']} [{$options['desc']}] => {$options['file']}";
166  printmsg($self['error'],0);
167  return(array(0, $self['error'] . "\n"));
168 }
169 
170 
171 
172 ?>
db_insert_record
db_insert_record($dbh=0, $table="", $insert="")
Definition: functions_db.inc.php:375
Name
Full Name
Definition: app_user_info.inc.php:101
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
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
get_module_list
get_module_list($options="type=string")
Definition: get_module_list.inc.php:23
$conf
global $conf
Definition: 2-to-3.php:15
add_module
add_module($options="")
Definition: get_module_list.inc.php:103
$self
global $self
Definition: 2-to-3.php:15
db_get_record
db_get_record($dbh=0, $table="", $where="", $order="")
Definition: functions_db.inc.php:708
parse_options
parse_options($options="")
Definition: functions_general.inc.php:1579
$version
$version
Definition: main.inc.php:22