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

mail_addressbook.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 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 
00033 require_once "./include/inc.header.php";
00034 require_once "./include/inc.mail.php";
00035 require_once "classes/class.ilObjUser.php";
00036 require_once "classes/class.ilMail.php";
00037 require_once "classes/class.ilAddressbook.php";
00038 require_once "classes/class.ilFormatMail.php";
00039 
00040 $lng->loadLanguageModule("mail");
00041 
00042 $umail = new ilFormatMail($_SESSION["AccountId"]);
00043 
00044 // catch hack attempts
00045 if (!$rbacsystem->checkAccess("mail_visible",$umail->getMailObjectReferenceId()))
00046 {
00047         $ilias->raiseError($lng->txt("permission_denied"),$ilias->error_obj->WARNING);
00048 }
00049 
00050 $tpl->addBlockFile("CONTENT", "content", "tpl.mail_addressbook.html");
00051 $tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
00052 $tpl->setVariable("TXT_ADDRESSBOOK",$lng->txt("mail_addressbook"));
00053 infoPanel();
00054 
00055 // LOCATOR
00056 setLocator($_GET["mobj_id"],$_SESSION["AccountId"],"");
00057 
00058 // BUTTONS
00059 include "./include/inc.mail_buttons.php";
00060 
00061 $abook = new ilAddressbook($_SESSION["AccountId"]);
00062 
00063 // ADD MAIL SENDER TO ADDRESSBOOK
00064 if($_GET["type"] == 'add')
00065 {
00066         $umail = new ilMail($_SESSION["AccountId"]);
00067         $mail_data = $umail->getMail($_GET["mail_id"]);
00068 
00069         $tmp_user = new ilObjUser($mail_data["sender_id"]);
00070         $abook->addEntry($tmp_user->getLogin(),
00071                                          $tmp_user->getFirstname(),
00072                                          $tmp_user->getLastname(),
00073                                          $tmp_user->getEmail());
00074         sendInfo($lng->txt("mail_entry_added"));
00075 }
00076 // ACTIONS
00077 if(isset($_POST["cmd"]["submit"]))
00078 {
00079         switch($_POST["action"])
00080         {
00081                 case 'edit':
00082                         if(!is_array($_POST["entry_id"]))
00083                         {
00084                                 unset($_POST["action"]);
00085                                 sendInfo($lng->txt("mail_select_one_entry"));
00086                         }
00087                         else
00088                         {
00089                                 $tmp_abook = new ilAddressbook($_SESSION["AccountId"]);
00090                                 $data = $tmp_abook->getEntry($_POST["entry_id"][0]);
00091                         }
00092                         break;
00093                 case 'delete':
00094                                 if(!is_array($_POST["entry_id"]))
00095                                 {
00096                                         sendInfo($lng->txt("mail_select_one_entry"));
00097                                         $error_delete = true;
00098                                 }
00099                                 else
00100                                 {
00101                                         sendInfo($lng->txt("mail_sure_delete_entry"));
00102                                 }
00103         }
00104 }
00105 // CHANGE ENTRY DATA
00106 if(isset($_POST["cmd"]["change"]))
00107 {
00108         if(!is_array($_POST["entry_id"]))
00109         {
00110                 sendInfo($lng->txt("mail_select_one"));
00111         }
00112         else
00113         {
00114                 $abook->updateEntry($_POST["entry_id"][0],
00115                                                         $_POST["login"],
00116                                                         $_POST["firstname"],
00117                                                         $_POST["lastname"],
00118                                                         $_POST["email"]);
00119                 unset($_POST["entry_id"]);
00120                 sendInfo($lng->txt("mail_entry_changed"));
00121         }
00122 }       
00123 // CANCEL CONFIRM DELETE
00124 if(isset($_POST["cmd"]["cancel"]))
00125 {
00126         header("location:mail_addressbook.php?mobj_id=$_GET[mobj_id]");
00127         exit();
00128 }
00129 
00130 // ADD NEW ENTRY
00131 if(isset($_POST["cmd"]["add"]))
00132 {
00133         // check if user login is empty 
00134         if ( !strcmp(trim($_POST["login"]),"") 
00135         or   !strcmp(trim($_POST["email"]),"") 
00136            ) {
00137                 sendInfo($lng->txt("mail_check_your_email_addr"));
00138         }
00139         else {
00140                 $abook->addEntry($_POST["login"],
00141                                          $_POST["firstname"],
00142                                          $_POST["lastname"],
00143                                          $_POST["email"]);
00144         sendInfo($lng->txt("mail_entry_added"));
00145         }
00146         
00147 }
00148 
00149 // CONFIRM DELETE
00150 if(isset($_POST["cmd"]["confirm"]))
00151 {
00152         if(!is_array($_POST["entry_id"]))
00153         {
00154                 sendInfo($lng->txt("mail_select_one_entry"));
00155         }
00156         else if($abook->deleteEntries($_POST["entry_id"]))
00157         {
00158                 sendInfo($lng->txt("mail_deleted_entry"));
00159         }
00160         else
00161         {
00162                 sendInfo($lng->txt("mail_delete_error"));
00163         }
00164 }
00165 
00166 $tpl->setVariable("ACTION","mail_addressbook.php?mobj_id=$_GET[mobj_id]");
00167 $tpl->setVariable("TXT_ENTRIES",$lng->txt("mail_addr_entries"));
00168 
00169 // CASE CONFIRM DELETE
00170 if($_POST["action"] == "delete" and !$error_delete and !isset($_POST["cmd"]["confirm"]))
00171 {
00172         $tpl->setCurrentBlock("confirm_delete");
00173         $tpl->setVariable("BUTTON_CONFIRM",$lng->txt("confirm"));
00174         $tpl->setVariable("BUTTON_CANCEL",$lng->txt("cancel"));
00175         $tpl->parseCurrentBlock();
00176 }
00177 
00178 // SET TXT VARIABLES ADDRESSBOOK
00179 $tpl->setVariable("TXT_LOGIN",$lng->txt("login"));
00180 $tpl->setVariable("TXT_FIRSTNAME",$lng->txt("firstname"));
00181 $tpl->setVariable("TXT_LASTNAME",$lng->txt("lastname"));
00182 $tpl->setVariable("TXT_EMAIL",$lng->txt("email"));
00183 $tpl->setVariable("BUTTON_SUBMIT",$lng->txt("submit"));
00184 
00185 // ACTIONS
00186 $tpl->setCurrentBlock("actions");
00187 $tpl->setVariable("ACTION_NAME","edit");
00188 $tpl->setVariable("ACTION_VALUE",$lng->txt("edit"));
00189 $tpl->parseCurrentBlock();
00190 
00191 $tpl->setVariable("ACTION_NAME","delete");
00192 $tpl->setVariable("ACTION_VALUE",$lng->txt("delete"));
00193 $tpl->setVariable("ACTION_SELECTED",$_POST["cmd"] == 'delete' ? 'selected' : '');
00194 $tpl->parseCurrentBlock();
00195 
00196 $entries = $abook->getEntries();
00197 $entries_count = count($entries);
00198 
00199 // TODO: READ FROM MAIL_OPTIONS
00200 $entries_max_hits = 20;
00201 
00202 // SHOW ENTRIES
00203 if($entries)
00204 {
00205         $counter = 0;
00206 
00207         foreach($entries as $entry)
00208         {
00209                 if($rbacsystem->checkAccess("smtp_mail",$umail->getMailObjectReferenceId()))
00210                 {
00211                         $tpl->setCurrentBlock("smtp");
00212                         $tpl->setVariable("EMAIL_SMTP",$entry["email"]);
00213                         $tpl->setVariable("EMAIL_LINK","./mail_new.php?mobj_id=".$_GET["mobj_id"].
00214                                                                         "&type=address&rcp=".urlencode($entry["email"]));
00215                         $tpl->parseCurrentBlock();
00216                 }
00217                 else
00218                 {
00219                         $tpl->setCurrentBlock("no_smtp");
00220                         $tpl->setVariable("EMAIL",$entry["email"]);
00221                         $tpl->parseCurrentBlock();
00222                 }
00223 
00224                 $tpl->setCurrentBlock("addr_search");
00225                 // LINKBAR
00226                 if($entries_count > $entries_max_hits)
00227                 {
00228                         $params = array(
00229                                 "mobj_id"               => $_GET["mobj_id"]);
00230                 }
00231                 $start = $_GET["offset"];
00232                 $linkbar = ilUtil::Linkbar(basename($_SERVER["PHP_SELF"]),$entries_count,$entries_max_hits,$start,$params);
00233                 if ($linkbar)
00234                 {
00235                         $tpl->setVariable("LINKBAR", $linkbar);
00236                 }
00237                 if($counter >= ($start+$entries_max_hits))
00238                 {
00239                         break;
00240                 }
00241                 if($counter < $start)
00242                 {
00243                         ++$counter;
00244                         continue;
00245                 }
00246                 // END LINKBAR
00247 
00248                 $tpl->setVariable("CSSROW",++$counter%2 ? 'tblrow1' : 'tblrow2');
00249                 if(is_array($_POST["entry_id"]))
00250                 {
00251                         $tpl->setVariable("CHECKED",in_array($entry["addr_id"],$_POST["entry_id"]) ? 'checked' : '');
00252                 }
00253                 $tpl->setVariable("ENTRY_ID",$entry["addr_id"]);
00254                 $tpl->setVariable("LOGIN_LINK","./mail_new.php?mobj_id=".$_GET["mobj_id"]."&type=address&rcp=".urlencode($entry["login"]));
00255                 $tpl->setVariable("LOGIN",$entry["login"]);
00256                 $tpl->setVariable("FIRSTNAME",$entry["firstname"]);
00257                 $tpl->setVariable("LASTNAME",$entry["lastname"]);
00258                 $tpl->parseCurrentBlock();
00259         }               
00260 }
00261 else
00262 {
00263         $tpl->setCurrentBlock("addr_no_content");
00264         $tpl->setVariable("TXT_ADDR_NO",$lng->txt("mail_search_no"));
00265         $tpl->parseCurrentBlock();
00266 }
00267 
00268 // SHOW EDIT FIELD
00269 $tpl->setVariable("CSSROW_LOGIN",'tblrow1');
00270 $tpl->setVariable("HEADER_LOGIN",$lng->txt("username"));
00271 $tpl->setVariable("VALUE_LOGIN",$data["login"]);
00272 $tpl->setVariable("CSSROW_FIRSTNAME",'tblrow2');
00273 $tpl->setVariable("HEADER_FIRSTNAME",$lng->txt("firstname"));
00274 $tpl->setVariable("VALUE_FIRSTNAME",$data["firstname"]);
00275 $tpl->setVariable("CSSROW_LASTNAME",'tblrow1');
00276 $tpl->setVariable("HEADER_LASTNAME",$lng->txt("lastname"));
00277 $tpl->setVariable("VALUE_LASTNAME",$data["lastname"]);
00278 $tpl->setVariable("CSSROW_EMAIL",'tblrow2');
00279 $tpl->setVariable("HEADER_EMAIL",$lng->txt("email"));
00280 $tpl->setVariable("VALUE_EMAIL",$data["email"]);
00281 
00282 // SUBMIT VALUE DEPENDS ON $_POST["cmd"]
00283 
00284 $tpl->setVariable("BUTTON_EDIT_ADD",(($_POST["action"] == "edit") and $_POST["cmd"]["submit"]) ? $lng->txt("change") : $lng->txt("add"));
00285 $tpl->setVariable("BUTTON_EDIT_ADD_NAME",(($_POST["action"] == "edit") and $_POST["cmd"]["submit"]) ? "cmd[change]" : "cmd[add]");
00286 
00287 $tpl->show();
00288 ?>

Generated on Fri Dec 13 2013 09:06:36 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1