Subversion Repositories php_users

Rev

Rev 16 | Details | Compare with Previous | 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
 
21 rodolico 47
   $connection = new usersPermissionsDataSourceMySQLi( 
48
         array( 'username' => 'test', 'password' => 'test', 'database' => 'test' ),
49
         $customFields
16 rodolico 50
      );
51
   $initValues = array( 
52
      'users' => array( 
53
         'login' => 'admin', 
54
         'pass' => password_hash( 'admin', PASSWORD_DEFAULT ),
55
         'admin' => 1, 
56
      )
57
      );
58
   $connection->buildTable( );
59
   $connection->initTables( $initValues );
60
   $connection->addPermission ( 'Main', 'P1', 'Permission All', 1 );
61
   $connection->addPermission ( 'Main', 'P2', 'Permission Some', 0 );
62
   $connection->setUsersPermissions();
63
?>
64
<html>
65
	<head>
66
		<meta charset="utf-8">
67
		<title>Build Table</title>
68
	</head>
69
	<body>
70
      <h1>
71
      <?php
72
         if ( $connection->test() ) {
73
            print "Table (re)built";
74
         } else {
75
            print "Something went wrong, check apache2 logs";
76
         }
77
      ?>
78
      </h1>
79
	</body>
80
</html>