Subversion Repositories php_users

Rev

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

<!DOCTYPE html>
<?php
   include_once( '../UsersDataSourceMySQLi.class.php' );
   include_once( '../Users.class.php' );
   /*
    * this is an example of adding additional fields to a user record
    * In this case, we have added a MySQL text field named where_clause
    * to the database. It will be displayed as a textarea in the input
    * forms.
    * While the "For Users Class" is needed only for the new User call
    * and the For Data Source is only used for the new usersDataSource
    * call, it is completely acceptable to pass all the data to both
    * since they will ignore any array entries they don't know how to 
    * handle.
    */
   $customFields = array( 
      'tables' => array(
         'users' => array(
            'fields' => array(
               'where_clause' => array(
                  // For Users class
                     // this will be the display label on the form
                     'label'  => 'Limit via SQL where clause',
                     // the input type to use for data entry
                     'html type' => 'textarea',
                     // you can only edit this if an admin and changing someone
                     // else' record
                     'restrict' => true,
                     // will be displayed on a hover in HTML5 (ie, title=)
                     'instructions' => 'This will be added to every SQL query to limit access, or 1=1 for everything',
                     // this is entered in an empty box, ie placeholder=
                     'hint'     => 'Enter an SQL where clause',
                     // for Data Source
                     'dbColumn'  =>  'where_clause',
                     // actual mySQL column type
                     'type'      => 'text',
                     // set it to not null if we build the table ourselves
                     'required'  => false,
                     // set a default value
                     'default'   => '1=1'
                     )
                  )
               )
            )
      );
         
   try {
      $connection = new usersDataSourceMySQLi( 
            array( 'username' => 'test', 'password' => 'test', 'database' => 'test' ),
            $customFields, 
         );
   } catch ( Exception $e ) {
      print "<pre>$e</pre>";
      die;
   }
   $initValues = array( 
      'users' => array( 
         'login' => 'admin', 
         'pass' => password_hash( 'admin', PASSWORD_DEFAULT ),
         'admin' => 1, 
      )
      );
   $connection->buildTable( );
   $connection->initTables( $initValues );
?>
<html>
        <head>
                <meta charset="utf-8">
                <title>Build Table</title>
        </head>
        <body>
      <h1>
      <?php
         if ( $connection->test() ) {
            print "Table (re)built";
         } else {
            print "Something went wrong, check apache2 logs";
         }
      ?>
      </h1>
        </body>
</html>