Source for file classes_people.php

Documentation is available at classes_people.php

  1. <?php
  2.  
  3.  
  4.  
  5. class person extends b_object {
  6.  
  7. //NOTE - object type definition "people"
  8.  
  9.  
  10. var $email;
  11.  
  12. var $firstName;
  13.  
  14. var $lastName;
  15.  
  16. var $userName;
  17.  
  18. var $password;
  19.  
  20. var $description;
  21.  
  22. var $sessionID;
  23.  
  24. var $sessionIP;
  25.  
  26. var $sessionTimestamp;
  27.  
  28.  
  29.  
  30. function person( $constructID = NULL ) {
  31.  
  32. parent::b_object( $constructID, 'people' );
  33.  
  34. }
  35.  
  36.  
  37. //NOTE: these functions are here to overload the base class functions if special data validation etc is needed
  38.  
  39. //function &get_attribute( $attribute ) { }
  40.  
  41. //function set_attribute( $attribute, $value ) { }
  42.  
  43. //function set_db( $values ) { }
  44.  
  45. //function set_object( $values ) { }
  46.  
  47. //function delete() { }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. function get_contents( $navArray = NULL, $rawFieldArray = NULL ) {
  55.  
  56. //format navigation field
  57.  
  58. unset( $navArray['permissions'] );
  59.  
  60.  
  61. //format object display fields
  62.  
  63. if( !isset( $rawFieldArray ) ) { $rawFieldArray = $this->type->get_attribute( 'type_object_field_list' ); }
  64.  
  65. foreach( $rawFieldArray as $field ) {
  66.  
  67. if( $field['type'] == 'password' ) {
  68.  
  69. if( $this->password && !isset( $GLOBALS['errorArray'] ) ) {
  70.  
  71. //if the password has been set
  72.  
  73. $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>' );
  74.  
  75. } else {
  76.  
  77. //if no password has been set, insert a confirm password field
  78.  
  79. $fieldArray[] = array( 'type'=>'text', 'src'=>'string', 'label'=>'password', 'value'=>form_input( 'password', NULL, true ) );
  80.  
  81. $fieldArray[] = array( 'type'=>'text', 'src'=>'string', 'label'=>'confirm password', 'value'=>form_input( 'passwordConfirm', NULL, true ) );
  82.  
  83. }
  84.  
  85. } else {
  86.  
  87. $fieldArray[] = $field;
  88.  
  89. }
  90.  
  91. }
  92.  
  93. return parent::get_contents( $navArray, $fieldArray );
  94.  
  95. }
  96.  
  97.  
  98.  
  99. function get_index() {
  100.  
  101. if( $this->firstName && $this->lastName ) {
  102.  
  103. $objectIndex = $this->firstName.' '.$this->lastName;
  104.  
  105. } else if( $this->firstName ) {
  106.  
  107. $objectIndex = $this->firstName;
  108.  
  109. } else if( $this->lastName ) {
  110.  
  111. $objectIndex = $this->lastName;
  112.  
  113. } else if( $this->username ) {
  114.  
  115. $objectIndex = $this->username;
  116.  
  117. } else if( $this->email ) {
  118.  
  119. $objectIndex = $this->email;
  120.  
  121. } else {
  122.  
  123. $objectIndex = "new person";
  124.  
  125. }
  126.  
  127. return $objectIndex;
  128.  
  129. }
  130.  
  131.  
  132.  
  133. function verify_set( $post ) {
  134.  
  135. //verifies data before setting the object's values - returns an error array if problems are found
  136.  
  137. global $db;
  138.  
  139. $returnArray = array();
  140.  
  141. $definedPerson = $db->get_var( "SELECT id FROM object_people WHERE username = '".$post['username']."'" ); // this is sort of crappy - see if it can be revised
  142.  
  143.  
  144.  
  145. if( $post['username'] && $definedPerson && $definedPerson != $this->id ) {
  146.  
  147. $returnArray['username'] = 'username taken - please choose another';
  148.  
  149. }
  150.  
  151. if( ( $post['password'] || $post['passwordConfirm'] ) && !( $post['username'] || $post['email'] ) ) {
  152.  
  153. $returnArray['username'] = 'to set a password, you must have a username or an email';
  154.  
  155. }
  156.  
  157. if( ($post['password'] || $post['passwordConfirm']) && ($post['password'] != $post['passwordConfirm']) ) {
  158.  
  159. $returnArray['password'] = 'passwords do not match';
  160.  
  161. $returnArray['passwordConfirm'] = NULL;
  162.  
  163. }
  164.  
  165. if( !count($returnArray) ) {
  166.  
  167. $this->set( $post );
  168.  
  169. } else {
  170.  
  171. $GLOBALS['errorArray'] = $returnArray;
  172.  
  173. $this->set_object( $post );
  174.  
  175. }
  176.  
  177. }
  178.  
  179.  
  180. function verify_change_password( $oldPassword, $newPassword, $newPasswordConfirm ) {
  181.  
  182. //verifies data before setting the person's password - returns an error array if problems are found
  183.  
  184. $returnArray = array();
  185.  
  186. global $db;
  187.  
  188. $hashedOldPassword = sha1($oldPassword);
  189.  
  190.  
  191. if( $hashedOldPassword != $this->password ) {
  192.  
  193. $GLOBALS['errorArray']['old_password'] = 'old password is incorrect';
  194.  
  195. }
  196.  
  197. if( $newPassword != $newPasswordConfirm ) {
  198.  
  199. $GLOBALS['errorArray']['new_password'] = 'new passwords do not match';
  200.  
  201. $GLOBALS['errorArray']['new_password_confirm'] = NULL;
  202.  
  203. }
  204.  
  205. if( !count($returnArray) ) {
  206.  
  207. $this->set_password( $newPassword );
  208.  
  209. }
  210.  
  211. }
  212.  
  213.  
  214. function set( $values ) {
  215.  
  216. if( $password = $values['password'] ) {
  217.  
  218. unset( $values['password'] );
  219.  
  220. }
  221.  
  222. if( isset($values['passwordConfirm']) ) { unset( $values['passwordConfirm'] ); }
  223.  
  224.  
  225.  
  226. parent::set( $values );
  227.  
  228.  
  229. if( $password ) {
  230.  
  231. $this->set_password( $password );
  232.  
  233. }
  234.  
  235. }
  236.  
  237.  
  238. function set_password( $new_password ) {
  239.  
  240. //sets the given person's password
  241.  
  242. global $db;
  243.  
  244. if( strlen( $new_password ) ) {
  245.  
  246. $updateString = "UPDATE object_people SET password = '".sha1($new_password)."' WHERE id = '".$this->id."'";
  247.  
  248. $db->query( $updateString);
  249.  
  250. $this->password = sha1($new_password);
  251.  
  252. }
  253.  
  254. }
  255.  
  256. }
  257.  
  258.  
  259.  
  260. ?>

Documentation generated on Tue, 24 May 2005 03:57:12 -0400 by phpDocumentor 1.3.0RC3