Documentation is available at classes_people.php
- <?php
- class person extends b_object {
- //NOTE - object type definition "people"
- var $email;
- var $firstName;
- var $lastName;
- var $userName;
- var $password;
- var $description;
- var $sessionID;
- var $sessionIP;
- var $sessionTimestamp;
- function person( $constructID = NULL ) {
- parent::b_object( $constructID, 'people' );
- }
- //NOTE: these functions are here to overload the base class functions if special data validation etc is needed
- //function &get_attribute( $attribute ) { }
- //function set_attribute( $attribute, $value ) { }
- //function set_db( $values ) { }
- //function set_object( $values ) { }
- //function delete() { }
- function get_contents( $navArray = NULL, $rawFieldArray = NULL ) {
- //format navigation field
- unset( $navArray['permissions'] );
- //format object display fields
- if( !isset( $rawFieldArray ) ) { $rawFieldArray = $this->type->get_attribute( 'type_object_field_list' ); }
- foreach( $rawFieldArray as $field ) {
- if( $field['type'] == 'password' ) {
- if( $this->password && !isset( $GLOBALS['errorArray'] ) ) {
- //if the password has been set
- $fieldArray[] = array( 'type'=>'text', 'src'=>'string', 'label'=>'password', 'value'=>'<a href="'.$_SERVER['DOCUMENT_ROOT'].'/pi/Modules/people/login.php?object='.$this->id.'" '.mouseover().'>change password</a>' );
- } else {
- //if no password has been set, insert a confirm password field
- $fieldArray[] = array( 'type'=>'text', 'src'=>'string', 'label'=>'password', 'value'=>form_input( 'password', NULL, true ) );
- $fieldArray[] = array( 'type'=>'text', 'src'=>'string', 'label'=>'confirm password', 'value'=>form_input( 'passwordConfirm', NULL, true ) );
- }
- } else {
- $fieldArray[] = $field;
- }
- }
- return parent::get_contents( $navArray, $fieldArray );
- }
- function get_index() {
- if( $this->firstName && $this->lastName ) {
- $objectIndex = $this->firstName.' '.$this->lastName;
- } else if( $this->firstName ) {
- $objectIndex = $this->firstName;
- } else if( $this->lastName ) {
- $objectIndex = $this->lastName;
- } else if( $this->username ) {
- $objectIndex = $this->username;
- } else if( $this->email ) {
- $objectIndex = $this->email;
- } else {
- $objectIndex = "new person";
- }
- return $objectIndex;
- }
- function verify_set( $post ) {
- //verifies data before setting the object's values - returns an error array if problems are found
- global $db;
- $returnArray = array();
- $definedPerson = $db->get_var( "SELECT id FROM object_people WHERE username = '".$post['username']."'" ); // this is sort of crappy - see if it can be revised
- if( $post['username'] && $definedPerson && $definedPerson != $this->id ) {
- $returnArray['username'] = 'username taken - please choose another';
- }
- if( ( $post['password'] || $post['passwordConfirm'] ) && !( $post['username'] || $post['email'] ) ) {
- $returnArray['username'] = 'to set a password, you must have a username or an email';
- }
- if( ($post['password'] || $post['passwordConfirm']) && ($post['password'] != $post['passwordConfirm']) ) {
- $returnArray['password'] = 'passwords do not match';
- $returnArray['passwordConfirm'] = NULL;
- }
- if( !count($returnArray) ) {
- $this->set( $post );
- } else {
- $GLOBALS['errorArray'] = $returnArray;
- $this->set_object( $post );
- }
- }
- function verify_change_password( $oldPassword, $newPassword, $newPasswordConfirm ) {
- //verifies data before setting the person's password - returns an error array if problems are found
- $returnArray = array();
- global $db;
- $hashedOldPassword = sha1($oldPassword);
- if( $hashedOldPassword != $this->password ) {
- $GLOBALS['errorArray']['old_password'] = 'old password is incorrect';
- }
- if( $newPassword != $newPasswordConfirm ) {
- $GLOBALS['errorArray']['new_password'] = 'new passwords do not match';
- $GLOBALS['errorArray']['new_password_confirm'] = NULL;
- }
- if( !count($returnArray) ) {
- $this->set_password( $newPassword );
- }
- }
- function set( $values ) {
- if( $password = $values['password'] ) {
- unset( $values['password'] );
- }
- if( isset($values['passwordConfirm']) ) { unset( $values['passwordConfirm'] ); }
- parent::set( $values );
- if( $password ) {
- $this->set_password( $password );
- }
- }
- function set_password( $new_password ) {
- //sets the given person's password
- global $db;
- if( strlen( $new_password ) ) {
- $updateString = "UPDATE object_people SET password = '".sha1($new_password)."' WHERE id = '".$this->id."'";
- $db->query( $updateString);
- $this->password = sha1($new_password);
- }
- }
- }
- ?>
Documentation generated on Tue, 24 May 2005 03:57:12 -0400 by phpDocumentor 1.3.0RC3