ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailForm.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 class ilMailForm
9 {
10  private $allow_smtp = null;
11  private $user_id = null;
12  private $setMap = array();
13  private $result;
14  private $max_entries = 20;
15 
23  public function __construct()
24  {
25  global $ilUser, $rbacsystem;
26 
27  $this->allow_smtp = $rbacsystem->checkAccess('smtp_mail', MAIL_SETTINGS_ID);
28  $this->user_id = $ilUser->getId();
29 
30  $this->result = new stdClass();
31  $this->result->response = new stdClass();
32  $this->result->response->results = array();
33  }
34 
43  private function addResult($login, $firstname, $lastname, $type)
44  {
45  if(count($this->result->response->results) > $this->max_entries)
46  {
47  throw new ilException();
48  }
49 
50  if (isset($this->setMap[$login]))
51  return;
52 
53  $tmp = new stdClass();
54  $tmp->login = $login;
55  $tmp->firstname = $firstname;
56  $tmp->lastname = $lastname;
57 
58  $this->result->response->results[] = $tmp;
59 
60  $this->setMap[$login] = 1;
61  }
62 
73  public function getRecipientAsync($a_search, $a_native_search)
74  {
75  global $ilDB;
76 
77  $query =
78  "SELECT DISTINCT
79  abook.login login,
80  abook.firstname firstname,
81  abook.lastname lastname,
82  'addressbook' type
83  FROM addressbook abook
84  WHERE abook.user_id = ".$ilDB->quote($this->user_id,'integer')."
85  AND abook.login IS NOT NULL
86  AND (". $ilDB->like('abook.login', 'text', $a_search)."
87  OR ".$ilDB->like('abook.firstname', 'text', $a_search)."
88  OR ".$ilDB->like('abook.lastname', 'text', $a_search)."
89  )";
90 
91  $union_query_1 = "SELECT DISTINCT
92  abook.email login,
93  abook.firstname firstname,
94  abook.lastname lastname,
95  'addressbook' type
96  FROM addressbook abook
97  WHERE abook.user_id = ".$ilDB->quote($this->user_id,'integer')."
98  AND abook.login IS NULL
99  AND (".$ilDB->like('abook.email', 'text', $a_search)."
100  OR ".$ilDB->like('abook.firstname', 'text', $a_search)."
101  OR ".$ilDB->like('abook.lastname', 'text', $a_search)."
102  )";
103 
104  $union_query_2 = "SELECT DISTINCT
105  mail.rcp_to login,
106  '' firstname,
107  '' lastname,
108  'mail' type
109  FROM mail
110  WHERE ".$ilDB->like('mail.rcp_to', 'text', $a_search)."
111  AND sender_id = ".$ilDB->quote($this->user_id,'integer')."
112  AND mail.sender_id = mail.user_id";
113 
114  $queries = array(
115  'addressbook_1' => $query,
116  'mail' => $union_query_2
117  );
118 
119  if($this->allow_smtp == 1)
120  $queries['addressbook_2'] = $union_query_1;
121 
122  include_once 'Services/Utilities/classes/class.ilStr.php';
123 
124  try
125  {
126  // MySql: Join the array values for mysql to one select statement
127  if($ilDB->getDbType() != 'oracle')
128  $queries['all'] = implode(' UNION ', $queries);
129 
130  foreach($queries as $type => $query)
131  {
132  // Oracle: Distincts do no work with clobs
133  if('mail' == $type && $ilDB->getDbType() == 'oracle')
134  {
135  $query = str_replace('DISTINCT', '', $query);
136  }
137 
138  $ilDB->setLimit(0,20);
139  $query_res = $ilDB->query( $query );
140 
141  while($row = $ilDB->fetchObject($query_res))
142  {
143  if($row->type == 'mail')
144  {
145  if(strpos($row->login, ',') || strpos($row->login, ';'))
146  {
147  $parts = preg_split("/[ ]*[;,][ ]*/", trim($row->login));
148  foreach($parts as $part)
149  {
150  if(ilStr::strPos(ilStr::strToLower($part), ilStr::strToLower($a_native_search)) !== false)
151  {
152  $this->addResult($part, '', '', 'mail');
153  }
154  }
155  }
156  else
157  {
158  $this->addResult($row->login, '', '', 'mail');
159  }
160  }
161  else
162  {
163  $this->addResult($row->login, $row->firstname, $row->lastname, 'addressbook');
164  }
165  }
166  }
167  } catch(ilException $e) {}
168 
170  $result->response->total = count($this->result->response->results);
171 
172  return $result;
173  }
174 }
175 ?>