ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
ilMailForm Class Reference
+ Collaboration diagram for ilMailForm:

Public Member Functions

 __construct ()
 Constructor. More...
 
 getRecipientAsync ($a_search, $a_native_search)
 Called by class ilMailFormGUI. More...
 

Private Member Functions

 addResult ($login, $firstname, $lastname, $type)
 Adds a result for mail recipient auto complete. More...
 

Private Attributes

 $allow_smtp = null
 
 $user_id = null
 
 $setMap = array()
 
 $result
 
 $max_entries = 20
 

Detailed Description

Author
Nadia Krzywon
Version
$Id$

Definition at line 8 of file class.ilMailForm.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailForm::__construct ( )

Constructor.

public

Definition at line 23 of file class.ilMailForm.php.

References $ilUser.

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 = array();
31  }
global $ilUser
Definition: imgupload.php:15

Member Function Documentation

◆ addResult()

ilMailForm::addResult (   $login,
  $firstname,
  $lastname,
  $type 
)
private

Adds a result for mail recipient auto complete.

private

Exceptions
ilException

Definition at line 41 of file class.ilMailForm.php.

Referenced by getRecipientAsync().

42  {
43  if(count($this->result) > $this->max_entries)
44  {
45  throw new ilException('exceeded_max_entries');
46  }
47 
48  if (isset($this->setMap[$login]))
49  return;
50 
51  $tmp = new stdClass();
52  $tmp->value = $login;
53 
54  $label = $login;
55  if($firstname && $lastname)
56  {
57  $label .= " [" . $firstname . ", " . $lastname . "]";
58  }
59  $tmp->label = $label;
60 
61  $this->result[] = $tmp;
62 
63  $this->setMap[$login] = 1;
64  }
Base class for ILIAS Exception handling.
+ Here is the caller graph for this function:

◆ getRecipientAsync()

ilMailForm::getRecipientAsync (   $a_search,
  $a_native_search 
)

Called by class ilMailFormGUI.

Parameters
stringsearch string surrounded with wildcards
stringnative search string
Returns
stdClass search result as an object of type stdClass public

Definition at line 76 of file class.ilMailForm.php.

References $query, $result, $row, addResult(), ilStr\strPos(), and ilStr\strToLower().

77  {
78  global $ilDB;
79 
80  $query =
81  "SELECT DISTINCT
82  abook.login login,
83  abook.firstname firstname,
84  abook.lastname lastname,
85  'addressbook' type
86  FROM addressbook abook
87  WHERE abook.user_id = ".$ilDB->quote($this->user_id,'integer')."
88  AND abook.login IS NOT NULL
89  AND (". $ilDB->like('abook.login', 'text', $a_search)."
90  OR ".$ilDB->like('abook.firstname', 'text', $a_search)."
91  OR ".$ilDB->like('abook.lastname', 'text', $a_search)."
92  )";
93 
94  $union_query_1 = "SELECT DISTINCT
95  abook.email login,
96  abook.firstname firstname,
97  abook.lastname lastname,
98  'addressbook' type
99  FROM addressbook abook
100  WHERE abook.user_id = ".$ilDB->quote($this->user_id,'integer')."
101  AND abook.login IS NULL
102  AND (".$ilDB->like('abook.email', 'text', $a_search)."
103  OR ".$ilDB->like('abook.firstname', 'text', $a_search)."
104  OR ".$ilDB->like('abook.lastname', 'text', $a_search)."
105  )";
106 
107  $union_query_2 = "SELECT DISTINCT
108  mail.rcp_to login,
109  '' firstname,
110  '' lastname,
111  'mail' type
112  FROM mail
113  WHERE ".$ilDB->like('mail.rcp_to', 'text', $a_search)."
114  AND sender_id = ".$ilDB->quote($this->user_id,'integer')."
115  AND mail.sender_id = mail.user_id";
116 
117  $queries = array(
118  'addressbook_1' => $query,
119  'mail' => $union_query_2
120  );
121 
122  if($this->allow_smtp == 1)
123  $queries['addressbook_2'] = $union_query_1;
124 
125  include_once 'Services/Utilities/classes/class.ilStr.php';
126 
127  try
128  {
129  // MySql: Join the array values for mysql to one select statement
130  if($ilDB->getDbType() != 'oracle')
131  $queries['all'] = implode(' UNION ', $queries);
132 
133  foreach($queries as $type => $query)
134  {
135  // Oracle: Distincts do no work with clobs
136  if('mail' == $type && $ilDB->getDbType() == 'oracle')
137  {
138  $query = str_replace('DISTINCT', '', $query);
139  }
140 
141  $ilDB->setLimit(0,20);
142  $query_res = $ilDB->query( $query );
143 
144  while($row = $ilDB->fetchObject($query_res))
145  {
146  if($row->type == 'mail')
147  {
148  if(strpos($row->login, ',') || strpos($row->login, ';'))
149  {
150  $parts = preg_split("/[ ]*[;,][ ]*/", trim($row->login));
151  foreach($parts as $part)
152  {
153  if(ilStr::strPos(ilStr::strToLower($part), ilStr::strToLower($a_native_search)) !== false)
154  {
155  $this->addResult($part, '', '', 'mail');
156  }
157  }
158  }
159  else
160  {
161  $this->addResult($row->login, '', '', 'mail');
162  }
163  }
164  else
165  {
166  $this->addResult($row->login, $row->firstname, $row->lastname, 'addressbook');
167  }
168  }
169  }
170  } catch(ilException $e) {}
171 
172  return $this->result;
173  }
Base class for ILIAS Exception handling.
static strToLower($a_string)
Definition: class.ilStr.php:91
strPos($a_haystack, $a_needle, $a_offset=NULL)
Definition: class.ilStr.php:46
addResult($login, $firstname, $lastname, $type)
Adds a result for mail recipient auto complete.
+ Here is the call graph for this function:

Field Documentation

◆ $allow_smtp

ilMailForm::$allow_smtp = null
private

Definition at line 10 of file class.ilMailForm.php.

◆ $max_entries

ilMailForm::$max_entries = 20
private

Definition at line 14 of file class.ilMailForm.php.

◆ $result

ilMailForm::$result
private

Definition at line 13 of file class.ilMailForm.php.

Referenced by getRecipientAsync().

◆ $setMap

ilMailForm::$setMap = array()
private

Definition at line 12 of file class.ilMailForm.php.

◆ $user_id

ilMailForm::$user_id = null
private

Definition at line 11 of file class.ilMailForm.php.


The documentation for this class was generated from the following file: