Contact.class.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. class Contact extends Entity{
  3. public $id,$label,$phone,$birth,$hour,$manager,$author,$address,$vehicle,$story,$storyShort,$login,$password,$icon,$mycheckbox1;
  4. protected $TABLE_NAME = 'plugin_contact';
  5. public $fields =
  6. array(
  7. 'id' => 'key',
  8. 'label' => 'string',
  9. 'phone' => 'string',
  10. 'birth' => 'date',
  11. 'hour' => 'date',
  12. 'manager'=> 'string',
  13. 'author' => 'string',
  14. 'address' => 'string',
  15. 'vehicle' => 'int',
  16. 'story' => 'longstring',
  17. 'storyShort' => 'longstring',
  18. 'login' => 'string',
  19. 'password' => 'string',
  20. 'icon'=>'string',
  21. 'mycheckbox1'=>'boolean'
  22. );
  23. function picture(){
  24. return $this->get_image();
  25. }
  26. function get_image($key=null){
  27. $finded = false;
  28. $image = array();
  29. $paths = array(
  30. 'jpg' => FILE_PATH.'contact'.SLASH.$this->id.'.jpg',
  31. 'png' => FILE_PATH.'contact'.SLASH.$this->id.'.png',
  32. 'jpeg' => FILE_PATH.'contact'.SLASH.$this->id.'.jpeg',
  33. );
  34. $image['url'] = $image['path'] = 'img'.SLASH.'default-avatar.png';
  35. foreach ($paths as $extension => $path) {
  36. if (file_exists( __ROOT__.$path) && !$finded) {
  37. $image['path'] = __ROOT__.$path;
  38. $finded = true;
  39. $image['url'] = 'action.php?action=contact_download_picture&contact='.$this->id.'&extension='.$extension;
  40. }
  41. }
  42. return isset($key) && isset($image[$key]) ? $image[$key] : $image['url'];
  43. }
  44. function documents(){
  45. $documents = array();
  46. foreach(glob(__ROOT__.FILE_PATH.'contact'.SLASH.'documents'.SLASH.$this->id.SLASH.'*.*') as $file){
  47. if(get_OS() === 'WIN') $file = utf8_encode($file);
  48. $documents[] = array(
  49. 'path' => 'contact'.SLASH.'documents'.SLASH.$this->id.SLASH.basename($file),
  50. 'url' => 'action.php?action=contact_download_document&path='.$this->id.SLASH.rawurlencode(basename($file)),
  51. 'name' => basename($file),
  52. 'icon' => getExtIcon(getExt($file))
  53. );
  54. }
  55. return $documents;
  56. }
  57. }
  58. ?>