Subversion Repositories php_users

Rev

Rev 4 | Rev 8 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

<!DOCTYPE html>
<?php
   include_once( '../UsersDataSourceMySQLi.class.php' );
   include_once( '../Users.class.php' );
   session_start();
   //session_destroy(); die;
   
   /*
    * 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
                     )
                  )
               )
            )
      );
         

   $connection = new usersDataSource( 
         null,
         $customFields, 
         array( 'username' => 'test', 'password' => 'test', 'database' => 'test' ) 
      );
   // ensure we always have a (possibly invalid) instance of user
   if ( ! isset( $_SESSION['user'] ) ) { 
      //print "Creating session users<br />";
      $_SESSION['user'] = new Users( $customFields );
   }
   if ( isset( $_REQUEST['logout'] ) )
      $_SESSION['user']->logout();

   $url = htmlentities($_SERVER["PHP_SELF"]);
   
?>
<html>
        <head>
                <meta charset="utf-8">
                <title>Login</title>
     <link href='users.css' rel='stylesheet' type='text/css'>
        </head>
        <body>
      <?php
         //print '<pre>' . print_r( $_SESSION, true ) . "</pre>\n";
         //print '<pre>' . print_r( $_REQUEST, true ) . "</pre>\n";
      ?>
      <div class="login">
         <?php 
            if ( isset( $_SESSION['user'] ) )
               print $_SESSION['user']->HTML($connection); 
         ?>
      </div>
      <div class='menu'>
         <ul>
         <?php
            if ( isset( $_SESSION['user'] ) && $_SESSION['user']->name() ) {
               print "<p>Logged in as " . $_SESSION['user']->name() . '</p>';
               print "<li><a href='$url?doAdmin=1'>Change Password</a></li>\n";
               print "<li><a href='$url?logout=1'>Log Out</a></li>";
            }
         ?>
         </ul>
      </div>
      <div class='content'>
         <?php
            if ( isset( $_REQUEST['doAdmin'] ) ) {
               print $_SESSION['user']->admin($connection);
               print $_SESSION['user']->errors();
               $_SESSION['user']->clearErrors();
            }
         ?>
      </div>
      
        </body>
</html>