Subversion Repositories php_users

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
16 rodolico 1
<!DOCTYPE html>
2
<?php
3
   include_once( '../UsersPermissionsDataSourceMySQLi.class.php' );
4
   /*
5
    * this is an example of adding additional fields to a user record
6
    * In this case, we have added a MySQL text field named where_clause
7
    * to the database. It will be displayed as a textarea in the input
8
    * forms.
9
    * While the "For Users Class" is needed only for the new User call
10
    * and the For Data Source is only used for the new usersDataSource
11
    * call, it is completely acceptable to pass all the data to both
12
    * since they will ignore any array entries they don't know how to 
13
    * handle.
14
    */
15
   $customFields = array( 
16
      'tables' => array(
17
         'users' => array(
18
            'fields' => array(
19
               'where_clause' => array(
20
                  // For Users class
21
                     // this will be the display label on the form
22
                     'label'  => 'Limit via SQL where clause',
23
                     // the input type to use for data entry
24
                     'html type' => 'textarea',
25
                     // you can only edit this if an admin and changing someone
26
                     // else' record
27
                     'restrict' => true,
28
                     // will be displayed on a hover in HTML5 (ie, title=)
29
                     'instructions' => 'This will be added to every SQL query to limit access, or 1=1 for everything',
30
                     // this is entered in an empty box, ie placeholder=
31
                     'hint'     => 'Enter an SQL where clause',
32
                     // for Data Source
33
                     'dbColumn'  =>  'where_clause',
34
                     // actual mySQL column type
35
                     'type'      => 'text',
36
                     // set it to not null if we build the table ourselves
37
                     'required'  => false,
38
                     // set a default value
39
                     'default'   => '1=1'
40
                     )
41
                  )
42
               )
43
            )
44
      );
45
 
46
 
47
   $connection = new usersPermissionsDataSource( 
48
         null,
49
         $customFields, 
50
         array( 'username' => 'test', 'password' => 'test', 'database' => 'test' ) 
51
      );
52
   $initValues = array( 
53
      'users' => array( 
54
         'login' => 'admin', 
55
         'pass' => password_hash( 'admin', PASSWORD_DEFAULT ),
56
         'admin' => 1, 
57
      )
58
      );
59
   $connection->buildTable( );
60
   $connection->initTables( $initValues );
61
   $connection->addPermission ( 'Main', 'P1', 'Permission All', 1 );
62
   $connection->addPermission ( 'Main', 'P2', 'Permission Some', 0 );
63
   $connection->setUsersPermissions();
64
?>
65
<html>
66
	<head>
67
		<meta charset="utf-8">
68
		<title>Build Table</title>
69
	</head>
70
	<body>
71
      <h1>
72
      <?php
73
         if ( $connection->test() ) {
74
            print "Table (re)built";
75
         } else {
76
            print "Something went wrong, check apache2 logs";
77
         }
78
      ?>
79
      </h1>
80
	</body>
81
</html>