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)  

permissions.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 
7 // Function: add_permission (string $options='')
8 //
9 // Input Options:
10 // $options = key=value pairs of options for this function.
11 // multiple sets of key=value pairs should be separated
12 // by an "&" symbol.
13 //
14 // Output:
15 // Returns a two part list:
16 // 1. The exit status of the function. 0 on success, non-zero on
17 // error. All errors messages are stored in $self['error'].
18 // 2. A textual message for display on the console or web interface.
19 //
20 // Example: list($status, $result) = add_permission('');
22 function add_permission($options="") {
23  global $conf, $self, $onadb;
24  printmsg('DEBUG => add_permission('.$options.') called', 3);
25 
26  // Version - UPDATE on every edit!
27  $version = '1.00';
28 
29  // Parse incoming options string to an array
30  $options = parse_options($options);
31 
32  // Return the usage summary if we need to
33  if ($options['help'] or !$options['name']) {
34  $self['error'] = 'ERROR => Insufficient parameters';
35  // NOTE: Help message lines should not exceed 80 characters for proper display on a console
36  return(array(1,
37 <<<EOM
38 
40 Registers a new permission, this should be used by install scripts that are
41 creating new functionality that requires a registered permission.
42 
43  Synopsis: add_permission(OPTIONS)
44 
45  Options:
46  name=STRING Name of permission
47  desc=STRING Quoted string to describe this permission
48 
49 
50 EOM
51 
52  ));
53  }
54 
55 
56  // Get a list of the valid "permissions" and their descriptions.
57  list($status, $rows, $permissions) = db_get_record($onadb, 'permissions', array('name' => $options['name']), '');
58  if ($rows) {
59  $self['error'] = "ERROR => add_permission() Permission already exists: {$options['name']}";
60  printmsg($self['error'],0);
61  return(array(1, $self['error'] . "\n"));
62  }
63 
64 
65  // Get the next ID for the new host record
66  $id = ona_get_next_id('permissions');
67  if (!$id) {
68  $self['error'] = "ERROR => The ona_get_next_id('permissions') call failed!";
69  printmsg($self['error'], 0);
70  return(array(7, $self['error'] . "\n"));
71  }
72  printmsg("DEBUG => ID for new permission record: $id", 3);
73 
74  // Add the record
75  list($status, $rows) =
77  $onadb,
78  'permissions',
79  array(
80  'id' => $id,
81  'name' => $options['name'],
82  'description' => $options['desc']
83  )
84  );
85  if ($status or !$rows) {
86  $self['error'] = "ERROR => add_permission() SQL Query failed: " . $self['error'];
87  printmsg($self['error'],0);
88  return(array(2, $self['error'] . "\n"));
89  }
90 
91 
92  // Return the success notice
93  $self['error'] = "INFO => Permission ADDED: {$options['name']} [{$options['desc']}]";
94  printmsg($self['error'],0);
95  return(array(0, $self['error'] . "\n"));
96 }
97 
98 
99 
100 ?>
db_insert_record
db_insert_record($dbh=0, $table="", $insert="")
Definition: functions_db.inc.php:375
add_permission
add_permission($options="")
Definition: permissions.inc.php:22
ona_get_next_id
ona_get_next_id($tablename)
Definition: functions_db.inc.php:1369
Name
Full Name
Definition: app_user_info.inc.php:101
$status
$status
Definition: install.php:12
$onadb
global $onadb
Definition: 2-to-3.php:15
$permissions
$permissions
Definition: app_user_info.inc.php:24
printmsg
if(6<=$conf['debug']) printmsg($msg="", $debugLevel=0)
Definition: functions_general.inc.php:48
$conf
global $conf
Definition: 2-to-3.php:15
$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