Subversion Repositories php_users

Rev

Rev 16 | Details | Compare with Previous | Last modification | View Log | RSS feed

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