1 | <?php |
---|
2 | |
---|
3 | class Expresso { |
---|
4 | |
---|
5 | protected $expressoVersion; |
---|
6 | protected $ldapCatalog; |
---|
7 | var $result; |
---|
8 | var $error; |
---|
9 | var $id; |
---|
10 | |
---|
11 | |
---|
12 | function __construct($id){ |
---|
13 | $this->expressoVersion = substr($GLOBALS['phpgw_info']['server']['versions']['phpgwapi'],0,3); |
---|
14 | $this->result = array(); |
---|
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 | |
---|
27 | protected function getUserProfile(){ |
---|
28 | return array( |
---|
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'] |
---|
33 | ); |
---|
34 | } |
---|
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"); |
---|
40 | } |
---|
41 | |
---|
42 | return $this->ldapCatalog; |
---|
43 | } |
---|
44 | |
---|
45 | protected function getDb(){ |
---|
46 | return $GLOBALS['phpgw']->db; |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | protected function isLoggedIn($params){ |
---|
51 | list($sessionid, $kp3) = explode(":", $params['auth']); |
---|
52 | if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){ |
---|
53 | return true; |
---|
54 | } |
---|
55 | else{ |
---|
56 | $this-> error = "You are not logged in"; |
---|
57 | return false; |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | public function getExpressoVersion(){ |
---|
62 | $this->result = array('expressoVersion' => $this->expressoVersion); |
---|
63 | return $this->getResponse(); |
---|
64 | } |
---|
65 | |
---|
66 | public function login($params){ |
---|
67 | if(!$this-> isLoggedIn($params)) |
---|
68 | { |
---|
69 | if($params['auth'] != "") |
---|
70 | { |
---|
71 | $this->error = "Your auth is invalid"; |
---|
72 | |
---|
73 | } |
---|
74 | elseif($sessionid = $GLOBALS['phpgw']->session->create($params['user'], $params['password'])) |
---|
75 | { |
---|
76 | $this->error = null; |
---|
77 | $this->result = array( |
---|
78 | 'auth' => $sessionid.":".$GLOBALS['phpgw']->session->kp3, |
---|
79 | 'profile' => array($this->getUserProfile()) |
---|
80 | ); |
---|
81 | } |
---|
82 | else |
---|
83 | { |
---|
84 | $this-> error = $GLOBALS['phpgw']->session->reason; |
---|
85 | } |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | $this->result = array('auth' => $params['auth']); |
---|
90 | } |
---|
91 | |
---|
92 | return $this->getResponse(); |
---|
93 | } |
---|
94 | |
---|
95 | public function logout($params){ |
---|
96 | |
---|
97 | if($this->isLoggedIn($params)) |
---|
98 | { |
---|
99 | if (file_exists($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id'])) |
---|
100 | { |
---|
101 | $dh = opendir($GLOBALS['phpgw_info']['server']['temp_dir']. SEP . $_SESSION['phpgw_session']['session_id']); |
---|
102 | while ($file = readdir($dh)) |
---|
103 | { |
---|
104 | if ($file != '.' && $file != '..') |
---|
105 | { |
---|
106 | unlink($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id'].SEP.$file); |
---|
107 | } |
---|
108 | } |
---|
109 | rmdir($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id']); |
---|
110 | } |
---|
111 | $GLOBALS['phpgw']->hooks->process('logout'); |
---|
112 | $GLOBALS['phpgw']->session->destroy($_SESSION['phpgw_session']['session_id'], $GLOBALS['kp3']); |
---|
113 | $this->result = true; |
---|
114 | } |
---|
115 | |
---|
116 | return $this->getResponse(); |
---|
117 | } |
---|
118 | } |
---|