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

Services/Mail/classes/class.ilMailAddressbookGUI.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 require_once "Services/Mail/classes/class.ilAddressbookTableGUI.php";
00029 
00030 
00038 class ilMailAddressbookGUI
00039 {
00040         private $tpl = null;
00041         private $ctrl = null;
00042         private $lng = null;
00043         private $tabs_gui = null;
00044         
00045         private $umail = null;
00046         private $abook = null;
00047 
00048         public function __construct()
00049         {
00050                 global $tpl, $ilCtrl, $lng, $ilUser, $ilTabs;
00051 
00052                 $this->tpl = $tpl;
00053                 $this->ctrl = $ilCtrl;
00054                 $this->lng = $lng;
00055                 $this->tabs_gui =& $ilTabs;
00056                 
00057                 $this->ctrl->saveParameter($this, "mobj_id");
00058 
00059                 $this->umail = new ilFormatMail($ilUser->getId());
00060                 $this->abook = new ilAddressbook($ilUser->getId());
00061         }
00062 
00063         public function executeCommand()
00064         {
00065                 $this->showSubTabs();
00066 
00067                 $forward_class = $this->ctrl->getNextClass($this);
00068                 switch($forward_class)
00069                 {
00070                         case 'ilmailformgui':
00071                                 include_once 'Services/Mail/classes/class.ilMailFormGUI.php';
00072 
00073                                 $this->ctrl->forwardCommand(new ilMailFormGUI());
00074                                 break;
00075 
00076                         case 'ilmailsearchcoursesgui':
00077                                 include_once 'Services/Mail/classes/class.ilMailSearchCoursesGUI.php';
00078 
00079                                 $this->tabs_gui->setSubTabActive('mail_my_courses');
00080 
00081                                 $this->ctrl->setReturn($this, "showAddressbook");
00082                                 $this->ctrl->forwardCommand(new ilMailSearchCoursesGUI());
00083                                 break;
00084 
00085                         case 'ilmailsearchgroupsgui':
00086                                 include_once 'Services/Mail/classes/class.ilMailSearchGroupsGUI.php';
00087 
00088                                 $this->tabs_gui->setSubTabActive('mail_my_groups');
00089 
00090                                 $this->ctrl->setReturn($this, "showAddressbook");
00091                                 $this->ctrl->forwardCommand(new ilMailSearchGroupsGUI());
00092                                 break;
00093                         
00094                         case 'ilmailinglistsgui':
00095                                 include_once 'Services/Mail/classes/class.ilMailingListsGUI.php';
00096 
00097                                 $this->tabs_gui->setSubTabActive('mail_my_mailing_lists');
00098 
00099                                 $this->ctrl->setReturn($this, "showAddressbook");
00100                                 $this->ctrl->forwardCommand(new ilMailingListsGUI());
00101                                 break;
00102 
00103                         default:
00104                                 $this->tabs_gui->setSubTabActive('mail_my_entries');
00105 
00106                                 if (!($cmd = $this->ctrl->getCmd()))
00107                                 {
00108                                         $cmd = "showAddressbook";
00109                                 }
00110 
00111                                 $this->$cmd();
00112                                 break;
00113                 }
00114                 return true;
00115         }
00116 
00120         function checkInput($addr_id = 0)
00121         {
00122                 // check if user login and e-mail-address are empty 
00123                 if (!strcmp(trim($_POST["login"]), "") &&
00124                         !strcmp(trim($_POST["email"]), ""))
00125                 {
00126                         ilUtil::sendInfo($this->lng->txt("mail_enter_login_or_email_addr"));
00127                         $error = true;
00128                 }
00129                 else if ($_POST["login"] != "" && 
00130                                  !(ilObjUser::_lookupId(ilUtil::stripSlashes($_POST["login"]))))
00131                 {
00132                         ilUtil::sendInfo($this->lng->txt("mail_enter_valid_login"));
00133                         $error = true;
00134                 }
00135                 else if ($_POST["email"] &&
00136                                  !(ilUtil::is_email($_POST["email"])))
00137                 {
00138                         ilUtil::sendInfo($this->lng->txt("mail_enter_valid_email_addr"));
00139                         $error = true;
00140                 }
00141 
00142                 if (($this->existingEntry = $this->abook->checkEntryByLogin(ilUtil::stripSlashes($_POST["login"]))) > 0 &&
00143                         (($this->existingEntry != $addr_id && $addr_id > 0) || !$addr_id))
00144                 {
00145                         ilUtil::sendInfo($this->lng->txt("mail_entry_exists"));
00146                         $error = true;
00147                 }
00148 
00149                 return $error ? false : true; 
00150         }
00151 
00155         public function saveEntry()
00156         {
00157                 global $lng;
00158                 
00159                 if ($this->checkInput($_GET["addr_id"]))
00160                 {
00161                         if ($_GET["addr_id"])
00162                         {
00163                                 $this->abook->updateEntry(ilUtil::stripSlashes($_GET["addr_id"]),
00164                                                                                   ilUtil::stripSlashes($_POST["login"]),
00165                                                                               ilUtil::stripSlashes($_POST["firstname"]),
00166                                                                                   ilUtil::stripSlashes($_POST["lastname"]),
00167                                                                                   ilUtil::stripSlashes($_POST["email"]));
00168                                 ilUtil::sendInfo($lng->txt("mail_entry_changed"));
00169                         }
00170                         else
00171                         {
00172                                 $this->abook->addEntry(ilUtil::stripSlashes($_POST["login"]),
00173                                                                            ilUtil::stripSlashes($_POST["firstname"]),
00174                                                                            ilUtil::stripSlashes($_POST["lastname"]),
00175                                                                            ilUtil::stripSlashes($_POST["email"]));
00176                                 ilUtil::sendInfo($lng->txt("mail_entry_added"));
00177                         }
00178                         
00179                         unset($_SESSION['addr_search']);
00180                         
00181                         $this->showAddressbook();
00182                 }
00183                 else
00184                 {
00185                         $this->showAddressForm();
00186                 }
00187                 
00188                 return true;
00189         }
00190         
00194         function confirmDelete()
00195         {
00196                 global $lng;
00197                 
00198                 if (!isset($_POST['addr_id']))
00199                 {
00200                         ilUtil::sendInfo($this->lng->txt('mail_select_one_entry'));
00201                         $this->showAddressbook();                       
00202                         return true;
00203                 }
00204                 
00205                 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
00206                 $c_gui = new ilConfirmationGUI();
00207                 
00208                 // set confirm/cancel commands
00209                 $c_gui->setFormAction($this->ctrl->getFormAction($this, "performDelete"));
00210                 $c_gui->setHeaderText($this->lng->txt("mail_sure_delete_entry"));
00211                 $c_gui->setCancel($this->lng->txt("cancel"), "showAddressbook");
00212                 $c_gui->setConfirm($this->lng->txt("confirm"), "performDelete");
00213 
00214                 // add items to delete
00215                 foreach($_POST["addr_id"] as $addr_id)
00216                 {
00217                         $entry = $this->abook->getEntry($addr_id);
00218                         $c_gui->addItem("addr_id[]", $addr_id, $entry["login"] ? $entry["login"] : $entry["email"]);
00219                 }
00220                 
00221                 $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
00222                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook.html", "Services/Mail");
00223                 $this->tpl->setVariable('DELETE_CONFIRMATION', $c_gui->getHTML());
00224                 
00225                 $this->tpl->show();
00226                 
00227                 return true;
00228         }
00229         
00233         function performDelete()
00234         {
00235                 global $lng;
00236                 
00237                 if (is_array($_POST['addr_id']))
00238                 {                       
00239                         if ($this->abook->deleteEntries($_POST['addr_id']))
00240                         {
00241                                 ilUtil::sendInfo($lng->txt("mail_deleted_entry"));
00242                         }
00243                         else
00244                         {
00245                                 ilUtil::sendInfo($lng->txt("mail_delete_error"));
00246                         }
00247                 }
00248                 else
00249                 {
00250                         ilUtil::sendInfo($lng->txt("mail_delete_error"));
00251                 }
00252                 
00253                 $this->showAddressbook();
00254         
00255                 return true;    
00256         }
00257 
00261         function cancel()
00262         {
00263                 $this->showAddressbook();
00264         }
00265         
00266         public function showAddressForm()
00267         {
00268                 global $rbacsystem, $lng, $ilUser;
00269 
00270                 $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));             
00271                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook_form.html", "Services/Mail");
00272                 
00273                 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
00274                 $form = new ilPropertyFormGUI();                
00275                 $form->setTitle($_GET['addr_id'] ? $lng->txt("mail_edit_entry") : $lng->txt("mail_new_entry")); 
00276                 
00277                 if ($_GET['addr_id'])
00278                 {
00279                         $this->ctrl->setParameter($this, 'addr_id', $_GET['addr_id']);
00280                 }
00281                 
00282                 $entry = $this->abook->getEntry($_GET['addr_id']);
00283                 $form->setFormAction($this->ctrl->getFormAction($this, "saveEntry"));
00284                 
00285                 $formItem = new ilTextInputGUI($this->lng->txt("username"), "login");
00286                 $formItem->setValue(isset($_POST['login']) ? ilUtil::prepareFormOutput($_POST['login'], true) : ilUtil::prepareFormOutput($entry['login']));
00287                 $form->addItem($formItem);
00288                 
00289                 $formItem = new ilTextInputGUI($this->lng->txt("firstname"), "firstname");
00290                 $formItem->setValue(isset($_POST['firstname']) ? ilUtil::prepareFormOutput($_POST['firstname'], true) : ilUtil::prepareFormOutput($entry['firstname']));
00291                 $form->addItem($formItem);
00292                 
00293                 $formItem = new ilTextInputGUI($this->lng->txt("lastname"), "lastname");
00294                 $formItem->setValue(isset($_POST['lastname']) ? ilUtil::prepareFormOutput($_POST['lastname'], true) : ilUtil::prepareFormOutput($entry['lastname']));
00295                 $form->addItem($formItem);
00296                 
00297                 $formItem = new ilTextInputGUI($this->lng->txt("email"), "email");
00298                 $formItem->setValue(isset($_POST['email']) ? ilUtil::prepareFormOutput($_POST['email'], true) : ilUtil::prepareFormOutput($entry['email']));
00299                 $form->addItem($formItem);
00300                 
00301                 $form->addCommandButton('saveEntry',$this->lng->txt('save'));
00302                 $form->addCommandButton('cancel',$this->lng->txt('cancel'));
00303                 
00304                 $this->tpl->setVariable('FORM', $form->getHTML());
00305                 
00306                 $this->tpl->show();
00307 
00308                 return true;
00309         }
00310         
00311         public function mailToUsers()
00312         {
00313                 global $ilUser;
00314                 
00315                 if (!isset($_POST['addr_id']))
00316                 {
00317                         ilUtil::sendInfo($this->lng->txt('mail_select_one_entry'));
00318                         $this->showAddressbook();                       
00319                         return true;
00320                 }               
00321                 
00322                 $mail_data = $this->umail->getSavedData();              
00323                 if(!is_array($mail_data))
00324                 {
00325                         $this->umail->savePostData($ilUser->getId(), array(), '', '', '', '', '', '', '', '');
00326                 }       
00327                 
00328                 $members = array();     
00329                 foreach ($_POST['addr_id'] as $addr_id)
00330                 {
00331                         $entry = $this->abook->getEntry($addr_id);
00332                         
00333                         if(!$this->umail->doesRecipientStillExists($entry['login'], $mail_data['rcp_to']))
00334                         {
00335                                 $members[] = $entry['login'];
00336                         }
00337                 }
00338                 
00339                 if(count($members))
00340                 {
00341                         $mail_data = $this->umail->appendSearchResult($members, 'to');
00342                         $this->umail->savePostData(
00343                                 $mail_data['user_id'],
00344                                 $mail_data['attachments'],
00345                                 $mail_data['rcp_to'],
00346                                 $mail_data['rcp_cc'],
00347                                 $mail_data['rcp_bcc'],
00348                                 $mail_data['m_type'],
00349                                 $mail_data['m_email'],
00350                                 $mail_data['m_subject'],
00351                                 $mail_data['m_message'],
00352                                 $mail_data['use_placeholders']
00353                         );
00354                 }       
00355 
00356                 ilUtil::redirect('ilias.php?baseClass=ilMailGUI&type=search_res');
00357         }
00358         
00359         public function search()
00360         {
00361                 $_SESSION['addr_search'] = $_POST['search_qry'];
00362                 
00363                 $this->showAddressbook();
00364                 
00365                 return true;
00366         }
00367         
00371         public function showAddressbook()
00372         {
00373                 global $rbacsystem, $lng, $ilUser;
00374 
00375                 $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));             
00376                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook.html", "Services/Mail");           
00377 
00378                 $this->tpl->setVariable('ACTION', $this->ctrl->getFormAction($this, "saveEntry"));
00379                 $this->tpl->setVariable("TXT_SEARCH_FOR",$this->lng->txt("search_for"));
00380                 $this->tpl->setVariable("BUTTON_SEARCH",$this->lng->txt("send"));
00381                 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("reset"));
00382                 if (strlen(trim($_SESSION["addr_search"])) > 0)
00383                 {
00384                         $this->tpl->setVariable("VALUE_SEARCH_FOR", ilUtil::prepareFormOutput(trim($_SESSION["addr_search"]), true));
00385                 }
00386                 
00387                 $this->ctrl->setParameter($this, "cmd", "post");                
00388                 $tbl = new ilAddressbookTableGUI($this);
00389                 $tbl->setTitle($lng->txt("mail_addr_entries"));
00390                 $tbl->setRowTemplate("tpl.mail_addressbook_row.html", "Services/Mail");                         
00391 
00392                 $tbl->setDefaultOrderField('login');    
00393                 
00394                 $result = array();
00395                 $this->abook->setSearchQuery($_SESSION['addr_search']);
00396                 $entries = $this->abook->getEntries();
00397                 
00398                 $tbl->addColumn('', 'check', '10%');
00399                 $tbl->addColumn($this->lng->txt('login'), 'login', '20%');
00400                 $tbl->addColumn($this->lng->txt('firstname'), 'firstname', '20%');
00401                 $tbl->addColumn($this->lng->txt('lastname'), 'lastname', '20%');
00402                 $tbl->addColumn($this->lng->txt('email'), 'email', '20%');
00403                 $tbl->addColumn('', 'edit', '10%');
00404                 
00405                 if (count($entries))
00406                 {               
00407                         $tbl->enable('select_all');                             
00408                         $tbl->setSelectAllCheckbox('addr_id');
00409                         
00410                         $counter = 0;
00411                         foreach ($entries as $entry)
00412                         {                               
00413                                 $result[$counter]['check'] = ilUtil::formCheckbox(0, 'addr_id[]', $entry["addr_id"]);
00414                                 
00415                                 if ($entry["login"] != "")
00416                                 {
00417                                         $this->ctrl->setParameterByClass("ilmailformgui", "type", "address");
00418                                         $this->ctrl->setParameterByClass("ilmailformgui", "rcp", urlencode($entry["login"]));
00419                                         $result[$counter]['login'] = "<a class=\"navigation\" href=\"" .  $this->ctrl->getLinkTargetByClass("ilmailformgui") . "\">" . $entry["login"] . "</a>";
00420                                         $this->ctrl->clearParametersByClass("ilmailformgui");
00421                                 }                               
00422                                 
00423                                 $result[$counter]['firstname'] = $entry["firstname"];
00424                                 $result[$counter]['lastname'] = $entry["lastname"];
00425                                 
00426                                 if ($rbacsystem->checkAccess("smtp_mail", $this->umail->getMailObjectReferenceId()))
00427                                 {
00428                                         $this->ctrl->setParameterByClass("ilmailformgui", "type", "address");
00429                                         $this->ctrl->setParameterByClass("ilmailformgui", "rcp", urlencode($entry["email"]));
00430                                         $result[$counter]['email'] = "<a class=\"navigation\" href=\"" .  $this->ctrl->getLinkTargetByClass("ilmailformgui") . "\">" . $entry["email"] . "</a>";
00431                                         $this->ctrl->clearParametersByClass("ilmailformgui");
00432                                 }
00433                                 else
00434                                 {
00435                                         $result[$counter]['email'] = $entry["email"];
00436                                 }
00437                                 
00438                                 $this->ctrl->setParameter($this, 'addr_id',  $entry['addr_id']);
00439                                 $result[$counter]['edit_text'] = $this->lng->txt("edit");
00440                                 $result[$counter]['edit_url'] = $this->ctrl->getLinkTarget($this, "showAddressForm");
00441                                 
00442                                 ++$counter;
00443                         }                       
00444                         
00445                         $tbl->addMultiCommand('mailToUsers', $this->lng->txt('send_mail_to'));
00446                         $tbl->addMultiCommand('confirmDelete', $this->lng->txt('delete'));                      
00447                 }
00448                 else
00449                 {
00450                         $tbl->disable('header');
00451                         $tbl->disable('footer');
00452 
00453                         $tbl->setNoEntriesText($this->lng->txt('mail_search_no'));                      
00454                 }
00455 
00456                 $tbl->setData($result);
00457                 
00458                 $tbl->addCommandButton('showAddressForm', $this->lng->txt('add'));
00459                 
00460                 $this->tpl->setVariable('TABLE', $tbl->getHTML());              
00461                 
00462                 $this->tpl->show();
00463                 
00464                 return true;
00465         }
00466 
00467         function showSubTabs()
00468         {
00469                 $this->tabs_gui->addSubTabTarget('mail_my_entries',
00470                                                                                  $this->ctrl->getLinkTarget($this));
00471                 $this->tabs_gui->addSubTabTarget('mail_my_mailing_lists',
00472                                                                                  $this->ctrl->getLinkTargetByClass('ilmailinglistsgui'));
00473                 $this->tabs_gui->addSubTabTarget('mail_my_courses',
00474                                                                                  $this->ctrl->getLinkTargetByClass('ilmailsearchcoursesgui'));
00475                 $this->tabs_gui->addSubTabTarget('mail_my_groups',
00476                                                                                  $this->ctrl->getLinkTargetByClass('ilmailsearchgroupsgui'));           
00477         }
00478 }
00479 ?>

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