• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Mail/classes/class.ilMailSearchGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 require_once './Services/User/classes/class.ilObjUser.php';
00025 require_once "Services/Mail/classes/class.ilMailbox.php";
00026 require_once "Services/Mail/classes/class.ilFormatMail.php";
00027 require_once "Services/Mail/classes/class.ilAddressbook.php";
00028 include_once('Services/Table/classes/class.ilTable2GUI.php');
00029 
00036 class ilMailSearchGUI
00037 {
00038         private $tpl = null;
00039         private $ctrl = null;
00040         private $lng = null;
00041         
00042         private $umail = null;
00043 
00044         private $errorDelete = false;
00045 
00046         public function __construct()
00047         {
00048                 global $tpl, $ilCtrl, $lng, $ilUser;
00049 
00050                 $this->tpl = $tpl;
00051                 $this->ctrl = $ilCtrl;
00052                 $this->lng = $lng;
00053                 
00054                 $this->ctrl->saveParameter($this, "mobj_id");
00055 
00056                 $this->umail = new ilFormatMail($ilUser->getId());
00057         }
00058 
00059         public function executeCommand()
00060         {
00061                 $forward_class = $this->ctrl->getNextClass($this);
00062                 switch($forward_class)
00063                 {
00064                         default:
00065                                 if (!($cmd = $this->ctrl->getCmd()))
00066                                 {
00067                                         $cmd = "showResults";
00068                                 }
00069 
00070                                 $this->$cmd();
00071                                 break;
00072                 }
00073                 return true;
00074         }
00075 
00076         public function adopt()
00077         {
00078                 $_SESSION["mail_search_results_to"] = $_POST["search_name_to"];
00079                 $_SESSION["mail_search_results_cc"] = $_POST["search_name_cc"];
00080                 $_SESSION["mail_search_results_bcc"] = $_POST["search_name_bcc"];
00081                 
00082                 $this->saveMailData();
00083                 
00084                 $this->ctrl->returnToParent($this);
00085         }
00086         
00087         private function saveMailData()
00088         {
00089                 $mail_data = $this->umail->getSavedData();
00090                 
00091                 $this->umail->savePostData(
00092                         $mail_data["user_id"],
00093                         $mail_data["attachments"],
00094                         $mail_data["rcp_to"],
00095                         $mail_data["rcp_cc"],
00096                         $mail_data["rcp_bcc"],
00097                         $mail_data["m_type"],
00098                         $mail_data["m_email"],
00099                         $mail_data["m_subject"],
00100                         $mail_data["m_message"],
00101                         $mail_data["use_placeholders"]
00102                 );
00103         }
00104         
00105         public function cancel()
00106         {
00107                 $this->ctrl->returnToParent($this);
00108         }
00109         
00110         function search()
00111         {
00112                 $_SESSION["mail_search_search"] = $_POST["search"];
00113                 $_SESSION["mail_search_type_system"] = $_POST["type_system"];
00114                 $_SESSION["mail_search_type_addressbook"] = $_POST["type_addressbook"];
00115 
00116                 // IF NO TYPE IS GIVEN SEARCH IN BOTH 'system' and 'addressbook'
00117                 if(!$_SESSION["mail_search_type_system"] &&
00118                    !$_SESSION["mail_search_type_addressbook"])
00119                 {
00120                         $_SESSION["mail_search_type_system"] = 1;
00121                         $_SESSION["mail_search_type_addressbook"] = 1;
00122                 }
00123                 if (strlen(trim($_SESSION["mail_search_search"])) == 0)
00124                 {
00125                         ilUtil::sendInfo($this->lng->txt("mail_insert_query"));
00126                 }
00127                 else if(strlen(trim($_SESSION["mail_search_search"])) < 3)
00128                 {
00129                         $this->lng->loadLanguageModule('search');
00130                         ilUtil::sendInfo($this->lng->txt('search_minimum_three'));
00131                 }
00132                 
00133                 $this->showResults();
00134                 
00135                 return true;
00136         }
00137 
00138         public function showResults()
00139         {       
00140                 global $rbacsystem, $lng, $ilUser;
00141                 
00142                 $this->saveMailData();
00143 
00144                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_search.html", "Services/Mail");
00145                 $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
00146 
00147                 $this->ctrl->setParameter($this, "cmd", "post");
00148                 $this->tpl->setVariable("ACTION", $this->ctrl->getLinkTarget($this));
00149                 $this->ctrl->clearParameters($this);
00150                 
00151                 $this->tpl->setVariable("TXT_SEARCH_FOR",$this->lng->txt("search_for"));
00152                 $this->tpl->setVariable("TXT_SEARCH_SYSTEM",$this->lng->txt("mail_search_system"));
00153                 $this->tpl->setVariable("TXT_SEARCH_ADDRESS",$this->lng->txt("mail_search_addressbook"));
00154                 $this->tpl->setVariable("BUTTON_SEARCH",$this->lng->txt("search"));
00155                 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00156                 
00157                 if (strlen(trim($_SESSION["mail_search_search"])) > 0)
00158                 {
00159                         $this->tpl->setVariable("VALUE_SEARCH_FOR", ilUtil::prepareFormOutput(trim($_SESSION["mail_search_search"]), true));
00160                 }
00161                 
00162                 if (!$_SESSION['mail_search_type_system'] && !$_SESSION['mail_search_type_addressbook'])
00163                 {
00164                         $this->tpl->setVariable('CHECKED_TYPE_SYSTEM', "checked=\"checked\"");
00165                 }
00166                 else
00167                 {
00168                         if ($_SESSION['mail_search_type_addressbook']) $this->tpl->setVariable('CHECKED_TYPE_ADDRESSBOOK', "checked=\"checked\"");
00169                         if ($_SESSION['mail_search_type_system'])$this->tpl->setVariable('CHECKED_TYPE_SYSTEM', "checked=\"checked\"");
00170                 }               
00171 
00172                 if ($_SESSION['mail_search_type_addressbook'] && strlen(trim($_SESSION["mail_search_search"])) > 3)
00173                 {
00174                         $abook = new ilAddressbook($ilUser->getId());
00175                         $entries = $abook->searchUsers(addslashes(urldecode($_SESSION['mail_search_search'])));
00176 
00177                         if (count($entries))
00178                         {
00179                                 $tbl_addr = new ilTable2GUI($this);
00180                                 $tbl_addr->setTitle($lng->txt('mail_addressbook'));
00181                                 $tbl_addr->setRowTemplate('tpl.mail_search_addr_row.html', 'Services/Mail');                            
00182                                 
00183                                 $result = array();
00184                                 $counter = 0;           
00185                                 foreach ($entries as $entry)
00186                                 {
00187                                         $result[$counter]['check']      = ilUtil::formCheckbox(0, 'search_name_to[]', ($entry['login'] ? $entry['login'] : $entry['email'])) . 
00188                                                                                           ilUtil::formCheckbox(0, 'search_name_cc[]', ($entry['login'] ? $entry['login'] : $entry['email'])) .
00189                                                                                           ilUtil::formCheckbox(0, 'search_name_bcc[]', ($entry['login'] ? $entry['login'] : $entry['email']));          
00190                                         $result[$counter]['login'] = $entry['login'];
00191                                         $result[$counter]['firstname'] = $entry['firstname'];
00192                                         $result[$counter]['lastname'] = $entry['lastname'];     
00193                                         
00194                                         $id = ilObjUser::_lookupId($entry['login']);                                            
00195                                         if (ilObjUser::_lookupPref($id, 'public_email') == 'y' || !$entry['login'])
00196                                         {
00197                                                 $has_mail_addr = true;
00198                                                 $result[$counter]['email'] = $entry['email'];
00199                                         }                                       
00200                                         
00201                                         ++$counter;
00202                                 }                                                       
00203 
00204                                 $tbl_addr->addColumn($this->lng->txt('mail_to') . '/' . $this->lng->txt('cc') . '/' . $this->lng->txt('bc'), 'check', '10%');
00205                                 $tbl_addr->addColumn($this->lng->txt('login'), 'login', "15%");
00206                                 $tbl_addr->addColumn($this->lng->txt('firstname'), 'firstname', "15%");
00207                                 $tbl_addr->addColumn($this->lng->txt('lastname'), 'lastname', "15%");
00208                                 if ($has_mail_addr)
00209                                 {
00210                                         foreach ($result as $key => $val)
00211                                         {
00212                                                 if ($val['email'] == '') $result[$key]['email'] = '&nbsp;';
00213                                         }
00214                                         
00215                                         $tbl_addr->addColumn($this->lng->txt('email'), 'email', "15%");
00216                                 }
00217                                 $tbl_addr->setData($result);
00218 
00219                                 $tbl_addr->setDefaultOrderField('login');                                                       
00220                                 $tbl_addr->setPrefix('addr_');                  
00221                                 $tbl_addr->enable('select_all');                                
00222                                 $tbl_addr->setSelectAllCheckbox('search_name_to');                                      
00223 
00224                                 $this->tpl->setVariable('TABLE_ADDR', $tbl_addr->getHTML());                            
00225                         }
00226                 }               
00227                 if ($_SESSION['mail_search_type_system'] && strlen(trim($_SESSION["mail_search_search"])) > 3)
00228                 {
00229                         include_once 'Services/Search/classes/class.ilQueryParser.php';
00230                         include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
00231                         include_once 'Services/Search/classes/class.ilSearchResult.php';
00232                 
00233                         $all_results = new ilSearchResult();
00234                 
00235                         $query_parser = new ilQueryParser(ilUtil::stripSlashes($_SESSION['mail_search_search']));
00236                         $query_parser->setCombination(QP_COMBINATION_OR);
00237                         $query_parser->setMinWordLength(3);
00238                         $query_parser->parse();
00239                 
00240                         $user_search =& ilObjectSearchFactory::_getUserSearchInstance($query_parser);
00241                         $user_search->enableActiveCheck(true);
00242                         $user_search->setFields(array('login'));
00243                         $result_obj = $user_search->performSearch();
00244                         $all_results->mergeEntries($result_obj);
00245                 
00246                         $user_search->setFields(array('firstname'));
00247                         $result_obj = $user_search->performSearch();
00248                         $all_results->mergeEntries($result_obj);                
00249                         
00250                         $user_search->setFields(array('lastname'));
00251                         $result_obj = $user_search->performSearch();
00252                         $all_results->mergeEntries($result_obj);
00253                 
00254                         $all_results->filter(ROOT_FOLDER_ID,QP_COMBINATION_OR);
00255                         
00256                         $users = $all_results->getResults();
00257                         if (count($users))
00258                         {
00259                                 $tbl_users = new ilTable2GUI($this);
00260                                 $tbl_users->setTitle($lng->txt('system').': '.$lng->txt('persons'));
00261                                 $tbl_users->setRowTemplate('tpl.mail_search_users_row.html','Services/Mail');
00262                                 
00263                                 $result = array();                              
00264                                 $counter = 0;                           
00265                                 foreach ($users as $user)
00266                                 {                                       
00267                                         $login = ilObjUser::_lookupLogin($user['obj_id']);                      
00268 
00269                                         $result[$counter]['check']      = ilUtil::formCheckbox(0, 'search_name_to[]', $login) . 
00270                                                                                                   ilUtil::formCheckbox(0, 'search_name_cc[]', $login) .
00271                                                                                                   ilUtil::formCheckbox(0, 'search_name_bcc[]', $login);         
00272                                         $result[$counter]['login'] = $login;
00273                                         
00274                                         if (ilObjUser::_lookupPref($user['obj_id'], 'public_profile') == 'y')
00275                                         {
00276                                                 $name = ilObjUser::_lookupName($user['obj_id']);
00277                                                 $result[$counter]['firstname'] = $name['firstname'];
00278                                                 $result[$counter]['lastname'] = $name['lastname'];
00279                                         }
00280                                         else
00281                                         {
00282                                                 $result[$counter]['firstname'] = '';
00283                                                 $result[$counter]['lastname'] = '';
00284                                         }
00285                                         
00286                                         if (ilObjUser::_lookupPref($user['obj_id'], 'public_email') == 'y')
00287                                         {
00288                                                 $has_mail_usr = true;
00289                                                 $result[$counter]['email'] = ilObjUser::_lookupEmail($user['obj_id']);
00290                                         }
00291                                                 
00292                                         ++$counter;
00293                                 }                                                       
00294                                 
00295                                 $tbl_users->addColumn($this->lng->txt('mail_to') . '/' . $this->lng->txt('cc') . '/' . $this->lng->txt('bc'), 'check', '10%');
00296                                 $tbl_users->addColumn($this->lng->txt('login'), 'login', '15%');
00297                                 $tbl_users->addColumn($this->lng->txt('firstname'), 'firstname', '15%');
00298                                 $tbl_users->addColumn($this->lng->txt('lastname'), 'lastname', '15%');
00299                                 if ($has_mail_usr == true)
00300                                 {
00301                                         foreach ($result as $key => $val)
00302                                         {
00303                                                 if ($val['email'] == '') $result[$key]['email'] = '&nbsp;';
00304                                         }
00305                                         
00306                                         $tbl_users->addColumn($this->lng->txt('email'), 'email', '15%');
00307                                 }
00308                                 $tbl_users->setData($result);
00309 
00310                                 $tbl_users->setDefaultOrderField('login');                                              
00311                                 $tbl_users->setPrefix('usr_');                  
00312                                 $tbl_users->enable('select_all');                               
00313                                 $tbl_users->setSelectAllCheckbox('search_name_to');                             
00314         
00315                                 $this->tpl->setVariable('TABLE_USERS', $tbl_users->getHTML());
00316                         }                       
00317                 
00318                         $groups = ilUtil::searchGroups(addslashes(urldecode($_SESSION['mail_search_search'])));
00319                         if (count($groups))
00320                         {                                       
00321                                 $tbl_grp = new ilTable2GUI($this);
00322                                 $tbl_grp->setTitle($lng->txt('system').': '.$lng->txt('groups'));
00323                                 $tbl_grp->setRowTemplate('tpl.mail_search_groups_row.html','Services/Mail');
00324                                 
00325                                 $result = array();                              
00326                                 $counter = 0;
00327                                 foreach ($groups as $grp)
00328                                 {       
00329                                         $result[$counter]['check']      = ilUtil::formCheckbox(0, 'search_name_to[]', '#'.$grp['title']) . 
00330                                                                                                   ilUtil::formCheckbox(0, 'search_name_cc[]', '#'.$grp['title']) .
00331                                                                                                   ilUtil::formCheckbox(0, 'search_name_bcc[]', '#'.$grp['title']);              
00332                                         $result[$counter]['title'] = $grp['title'];
00333                                         $result[$counter]['description'] = $grp['description'];
00334                                                                                         
00335                                         ++$counter;
00336                                 }
00337                                 $tbl_grp->setData($result);                     
00338 
00339                                 $tbl_grp->addColumn($this->lng->txt('mail_to') . '/' . $this->lng->txt('cc') . '/' . $this->lng->txt('bc'), 'check', '10%');
00340                                 $tbl_grp->addColumn($this->lng->txt('title'), 'title', '15%');
00341                                 $tbl_grp->addColumn($this->lng->txt('description'), 'description', '15%');
00342 
00343                                 $tbl_grp->setDefaultOrderField('title');                                                        
00344                                 $tbl_grp->setPrefix('grp_');                    
00345                                 $tbl_grp->enable('select_all');                         
00346                                 $tbl_grp->setSelectAllCheckbox('search_name_to');                               
00347         
00348                                 $this->tpl->setVariable('TABLE_GRP', $tbl_grp->getHTML());
00349                         }
00350                 }
00351                 
00352                 if (count($users) || count($groups) || count($entries))
00353                 {
00354                         $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00355                         $this->tpl->setVariable("ALT_ARROW", '');
00356                         $this->tpl->setVariable('BUTTON_ADOPT', $this->lng->txt('adopt'));      
00357                 }
00358                 else if (strlen(trim($_SESSION["mail_search_search"])) > 3)
00359                 {
00360                         $this->lng->loadLanguageModule('search');                       
00361                         ilUtil::sendInfo($this->lng->txt('search_no_match'));
00362                 }               
00363                 
00364                 $this->tpl->show();
00365         }
00366 }
00367 ?>

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1