[5595] | 1 | <?php |
---|
| 2 | |
---|
| 3 | class Expresso { |
---|
| 4 | |
---|
[5633] | 5 | protected $expressoVersion; |
---|
[5707] | 6 | protected $ldapCatalog; |
---|
[5595] | 7 | var $result; |
---|
| 8 | var $error; |
---|
| 9 | var $id; |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | function __construct($id){ |
---|
[5633] | 13 | $this->expressoVersion = substr($GLOBALS['phpgw_info']['server']['versions']['phpgwapi'],0,3); |
---|
[5714] | 14 | $this->result = array(); |
---|
[5595] | 15 | $this->error = null; |
---|
| 16 | $this-> id = $id; |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | protected function getResponse(){ |
---|
| 20 | return array( |
---|
| 21 | 'result' => $this->result, |
---|
| 22 | 'error' => $this->error, |
---|
| 23 | 'id' => $this->id |
---|
| 24 | ); |
---|
| 25 | } |
---|
| 26 | |
---|
[5889] | 27 | protected function getUserProfile(){ |
---|
| 28 | return array( |
---|
[5896] | 29 | 'contactID' => $GLOBALS['phpgw_info']['user']['account_id'], |
---|
| 30 | 'contactMails' => array($GLOBALS['phpgw_info']['user']['email']), |
---|
| 31 | 'contactPhones' => array($GLOBALS['phpgw_info']['user']['telephonenumber']), |
---|
| 32 | 'contactFullName' => $GLOBALS['phpgw_info']['user']['fullname'] |
---|
[5889] | 33 | ); |
---|
[5681] | 34 | } |
---|
[5707] | 35 | protected function getLdapCatalog(){ |
---|
| 36 | if(!$this->ldapCatalog) { |
---|
| 37 | $catalog_config = CreateObject("contactcenter.bo_ldap_manager"); |
---|
| 38 | $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $catalog_config ? $catalog_config->srcs[1] : null; |
---|
| 39 | $this->ldapCatalog = CreateObject("expressoMail1_2.ldap_functions"); |
---|
[5681] | 40 | } |
---|
| 41 | |
---|
[5707] | 42 | return $this->ldapCatalog; |
---|
[5681] | 43 | } |
---|
| 44 | |
---|
| 45 | protected function getDb(){ |
---|
| 46 | return $GLOBALS['phpgw']->db; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | |
---|
[5595] | 50 | protected function isLoggedIn($params){ |
---|
[5954] | 51 | if($params['auth'] != null) { |
---|
| 52 | list($sessionid, $kp3) = explode(":", $params['auth']); |
---|
| 53 | if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){ |
---|
| 54 | return true; |
---|
| 55 | } |
---|
| 56 | else{ |
---|
| 57 | $this-> error = Errors::get(Errors::LOGIN_AUTH_INVALID); |
---|
| 58 | return false; |
---|
| 59 | } |
---|
[5595] | 60 | } |
---|
| 61 | else{ |
---|
[5954] | 62 | $this-> error = Errors::get(Errors::LOGIN_NOT_LOGGED_IN); |
---|
[5595] | 63 | return false; |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
[5633] | 67 | public function getExpressoVersion(){ |
---|
| 68 | $this->result = array('expressoVersion' => $this->expressoVersion); |
---|
| 69 | return $this->getResponse(); |
---|
| 70 | } |
---|
[5595] | 71 | |
---|
| 72 | public function login($params){ |
---|
| 73 | if(!$this-> isLoggedIn($params)) |
---|
| 74 | { |
---|
[5954] | 75 | if($sessionid = $GLOBALS['phpgw']->session->create($params['user'], $params['password'])) |
---|
[5595] | 76 | { |
---|
| 77 | $this->error = null; |
---|
[5889] | 78 | $this->result = array( |
---|
| 79 | 'auth' => $sessionid.":".$GLOBALS['phpgw']->session->kp3, |
---|
[5896] | 80 | 'profile' => array($this->getUserProfile()) |
---|
[5889] | 81 | ); |
---|
[5595] | 82 | } |
---|
| 83 | else |
---|
| 84 | { |
---|
[5954] | 85 | $this-> error = Errors::get($GLOBALS['phpgw']->session->cd_reason); |
---|
[5595] | 86 | } |
---|
| 87 | } |
---|
| 88 | else |
---|
| 89 | { |
---|
| 90 | $this->result = array('auth' => $params['auth']); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | return $this->getResponse(); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | public function logout($params){ |
---|
| 97 | |
---|
| 98 | if($this->isLoggedIn($params)) |
---|
| 99 | { |
---|
| 100 | if (file_exists($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id'])) |
---|
| 101 | { |
---|
| 102 | $dh = opendir($GLOBALS['phpgw_info']['server']['temp_dir']. SEP . $_SESSION['phpgw_session']['session_id']); |
---|
| 103 | while ($file = readdir($dh)) |
---|
| 104 | { |
---|
| 105 | if ($file != '.' && $file != '..') |
---|
| 106 | { |
---|
| 107 | unlink($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id'].SEP.$file); |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | rmdir($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id']); |
---|
| 111 | } |
---|
| 112 | $GLOBALS['phpgw']->hooks->process('logout'); |
---|
| 113 | $GLOBALS['phpgw']->session->destroy($_SESSION['phpgw_session']['session_id'], $GLOBALS['kp3']); |
---|
| 114 | $this->result = true; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | return $this->getResponse(); |
---|
| 118 | } |
---|
| 119 | } |
---|