• 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.adm_content.html");
00051 $tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook.html");
00052 $tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
00053 $tpl->setCurrentBlock("header_image");
00054 $tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_mail_b.gif"));
00055 $tpl->parseCurrentBlock();
00056 $tpl->setVariable("HEADER",$lng->txt("mail"));
00057 infoPanel();
00058 
00059 // LOCATOR
00060 setLocator($_GET["mobj_id"],'mail_addressbook.php',$_SESSION["AccountId"],"");
00061 
00062 // BUTTONS
00063 include "./include/inc.mail_buttons.php";
00064 
00065 $abook = new ilAddressbook($_SESSION["AccountId"]);
00066 
00067 // ADD MAIL SENDER TO ADDRESSBOOK
00068 if($_GET["type"] == 'add')
00069 {
00070         $umail = new ilMail($_SESSION["AccountId"]);
00071         $mail_data = $umail->getMail($_GET["mail_id"]);
00072 
00073         $tmp_user = new ilObjUser($mail_data["sender_id"]);
00074         $abook->addEntry($tmp_user->getLogin(),
00075                                          $tmp_user->getFirstname(),
00076                                          $tmp_user->getLastname(),
00077                                          $tmp_user->getEmail());
00078         sendInfo($lng->txt("mail_entry_added"));
00079 }
00080 // ACTIONS
00081 if(isset($_POST["cmd"]["submit"]))
00082 {
00083         switch($_POST["action"])
00084         {
00085                 case 'edit':
00086                         if(!is_array($_POST["entry_id"]))
00087                         {
00088                                 unset($_POST["action"]);
00089                                 sendInfo($lng->txt("mail_select_one_entry"));
00090                         }
00091                         else
00092                         {
00093                                 $tmp_abook = new ilAddressbook($_SESSION["AccountId"]);
00094                                 $data = $tmp_abook->getEntry($_POST["entry_id"][0]);
00095                         }
00096                         break;
00097                 case 'delete':
00098                                 if(!is_array($_POST["entry_id"]))
00099                                 {
00100                                         sendInfo($lng->txt("mail_select_one_entry"));
00101                                         $error_delete = true;
00102                                 }
00103                                 else
00104                                 {
00105                                         sendInfo($lng->txt("mail_sure_delete_entry"));
00106                                 }
00107         }
00108 }
00109 // CHANGE ENTRY DATA
00110 if(isset($_POST["cmd"]["change"]))
00111 {
00112         if(!is_array($_POST["entry_id"]))
00113         {
00114                 sendInfo($lng->txt("mail_select_one"));
00115         }
00116         // check if user login and e-mail-address are empty 
00117         else if (!strcmp(trim($_POST["login"]),"") &&
00118                          !strcmp(trim($_POST["email"]),""))
00119         {
00120                 sendInfo($lng->txt("mail_enter_login_or_email_addr"));
00121                 $error_add = true;
00122         }
00123         else if ($_POST["login"] != "" && 
00124                          !(ilObjUser::_lookupId($_POST["login"])))
00125         {
00126                 sendInfo($lng->txt("mail_enter_valid_login"));
00127                 $error_add = true;
00128         }
00129         else if ($_POST["email"] &&
00130                          !(ilUtil::is_email($_POST["email"])))
00131         {
00132                 sendInfo($lng->txt("mail_enter_valid_email_addr"));
00133                 $error_add = true;
00134         }
00135         else if (($existing_entry = $abook->checkEntry($_POST["login"])) > 0 &&
00136                          $existing_entry != $_POST["entry_id"][0])
00137         {
00138                 sendInfo($lng->txt("mail_entry_exists"));
00139                 $error_add = true;
00140         }
00141         else
00142         {
00143                 $abook->updateEntry($_POST["entry_id"][0],
00144                                                         $_POST["login"],
00145                                                         $_POST["firstname"],
00146                                                         $_POST["lastname"],
00147                                                         $_POST["email"]);
00148                 unset($_POST["entry_id"]);
00149                 unset($existing_entry);
00150                 sendInfo($lng->txt("mail_entry_changed"));
00151         }
00152 }       
00153 
00154 // CANCEL CONFIRM DELETE
00155 if(isset($_POST["cmd"]["cancel"]))
00156 {
00157         header("location:mail_addressbook.php?mobj_id=$_GET[mobj_id]");
00158         exit();
00159 }
00160 
00161 // ADD NEW ENTRY
00162 if(isset($_POST["cmd"]["add"]))
00163 {
00164         // check if user login and e-mail-address are empty 
00165         if (!strcmp(trim($_POST["login"]),"") &&
00166                 !strcmp(trim($_POST["email"]),""))
00167         {
00168                 sendInfo($lng->txt("mail_enter_login_or_email_addr"));
00169                 $error_add = true;
00170         }
00171         else if ($_POST["login"] != "" && 
00172                          !(ilObjUser::_lookupId($_POST["login"])))
00173         {
00174                 sendInfo($lng->txt("mail_enter_valid_login"));
00175                 $error_add = true;
00176         }
00177         else if ($_POST["email"] &&
00178                          !(ilUtil::is_email($_POST["email"])))
00179         {
00180                 sendInfo($lng->txt("mail_enter_valid_email_addr"));
00181                 $error_add = true;
00182         }
00183         else if (($existing_entry = $abook->checkEntry($_POST["login"])) > 0)
00184         {
00185                 sendInfo($lng->txt("mail_entry_exists"));
00186                 $error_add = true;
00187         }
00188         else
00189         {
00190                 $abook->addEntry($_POST["login"],
00191                                          $_POST["firstname"],
00192                                          $_POST["lastname"],
00193                                          $_POST["email"]);
00194                 sendInfo($lng->txt("mail_entry_added"));
00195         }
00196         
00197 }
00198 
00199 // CONFIRM DELETE
00200 if(isset($_POST["cmd"]["confirm"]))
00201 {
00202         if(!is_array($_POST["entry_id"]))
00203         {
00204                 sendInfo($lng->txt("mail_select_one_entry"));
00205         }
00206         else if($abook->deleteEntries($_POST["entry_id"]))
00207         {
00208                 sendInfo($lng->txt("mail_deleted_entry"));
00209         }
00210         else
00211         {
00212                 sendInfo($lng->txt("mail_delete_error"));
00213         }
00214 }
00215 
00216 $tpl->setVariable("ACTION","mail_addressbook.php?mobj_id=$_GET[mobj_id]");
00217 $tpl->setVariable("TXT_ENTRIES",$lng->txt("mail_addr_entries"));
00218 
00219 // CASE ENTRY EXISTS
00220 if ((isset($_POST["cmd"]["add"]) || isset($_POST["cmd"]["change"])) &&
00221         $existing_entry > 0)
00222 {
00223         $tpl->setCurrentBlock("entry_exists");
00224         $tpl->setVariable("ENTRY_EXISTS_ENTRY_ID",$existing_entry);
00225         $tpl->setVariable("ENTRY_EXISTS_BUTTON_OVERWRITE",$lng->txt("overwrite"));
00226         $tpl->setVariable("ENTRY_EXISTS_BUTTON_CANCEL",$lng->txt("cancel"));
00227         $tpl->parseCurrentBlock();
00228 }
00229 
00230 // CASE CONFIRM DELETE
00231 if($_POST["action"] == "delete" and !$error_delete and !isset($_POST["cmd"]["confirm"]))
00232 {
00233         $tpl->setCurrentBlock("confirm_delete");
00234         $tpl->setVariable("BUTTON_CONFIRM",$lng->txt("confirm"));
00235         $tpl->setVariable("BUTTON_CANCEL",$lng->txt("cancel"));
00236         $tpl->parseCurrentBlock();
00237 }
00238 
00239 // SET TXT VARIABLES ADDRESSBOOK
00240 $tpl->setVariable("TXT_LOGIN",$lng->txt("username"));
00241 $tpl->setVariable("TXT_FIRSTNAME",$lng->txt("firstname"));
00242 $tpl->setVariable("TXT_LASTNAME",$lng->txt("lastname"));
00243 $tpl->setVariable("TXT_EMAIL",$lng->txt("email"));
00244 $tpl->setVariable("BUTTON_SUBMIT",$lng->txt("submit"));
00245 
00246 // ACTIONS
00247 $tpl->setCurrentBlock("actions");
00248 $tpl->setVariable("ACTION_NAME","edit");
00249 $tpl->setVariable("ACTION_VALUE",$lng->txt("edit"));
00250 $tpl->parseCurrentBlock();
00251 
00252 $tpl->setVariable("ACTION_NAME","delete");
00253 $tpl->setVariable("ACTION_VALUE",$lng->txt("delete"));
00254 $tpl->setVariable("ACTION_SELECTED",$_POST["cmd"] == 'delete' ? 'selected' : '');
00255 $tpl->parseCurrentBlock();
00256 
00257 $entries = $abook->getEntries();
00258 $entries_count = count($entries);
00259 
00260 // TODO: READ FROM MAIL_OPTIONS
00261 $entries_max_hits = $ilUser->getPref('hits_per_page');
00262 
00263 // SHOW ENTRIES
00264 if($entries)
00265 {
00266         $counter = 0;
00267 
00268         foreach($entries as $entry)
00269         {
00270                 // LINKBAR
00271                 if($entries_count > $entries_max_hits)
00272                 {
00273                         $params = array(
00274                                 "mobj_id"               => $_GET["mobj_id"]);
00275                 }
00276                 $start = $_GET["offset"];
00277                 $linkbar = ilUtil::Linkbar(basename($_SERVER["PHP_SELF"]),$entries_count,$entries_max_hits,$start,$params);
00278                 if ($linkbar)
00279                 {
00280                         $tpl->setVariable("LINKBAR", $linkbar);
00281                 }
00282                 if($counter >= ($start+$entries_max_hits))
00283                 {
00284                         break;
00285                 }
00286                 if($counter < $start)
00287                 {
00288                         ++$counter;
00289                         continue;
00290                 }
00291                 // END LINKBAR
00292 
00293                 if($rbacsystem->checkAccess("smtp_mail",$umail->getMailObjectReferenceId()))
00294                 {
00295                         $tpl->setCurrentBlock("smtp");
00296                         $tpl->setVariable("EMAIL_SMTP",$entry["email"]);
00297                         $tpl->setVariable("EMAIL_LINK","./mail_new.php?mobj_id=".$_GET["mobj_id"].
00298                                                                         "&type=address&rcp=".urlencode($entry["email"]));
00299                         $tpl->parseCurrentBlock();
00300                 }
00301                 else
00302                 {
00303                         $tpl->setCurrentBlock("no_smtp");
00304                         $tpl->setVariable("EMAIL",$entry["email"]);
00305                         $tpl->parseCurrentBlock();
00306                 }
00307                 $tpl->setCurrentBlock("addr_search");
00308 
00309                 $tpl->setVariable("CSSROW",++$counter%2 ? 'tblrow1' : 'tblrow2');
00310                 if(is_array($_POST["entry_id"]))
00311                 {
00312                         $tpl->setVariable("CHECKED",in_array($entry["addr_id"],$_POST["entry_id"]) ? 'checked' : '');
00313                 }
00314                 $tpl->setVariable("ENTRY_ID",$entry["addr_id"]);
00315                 $tpl->setVariable("LOGIN_LINK","./mail_new.php?mobj_id=".$_GET["mobj_id"]."&type=address&rcp=".urlencode($entry["login"]));
00316                 $tpl->setVariable("LOGIN",$entry["login"]);
00317                 $tpl->setVariable("FIRSTNAME",$entry["firstname"]);
00318                 $tpl->setVariable("LASTNAME",$entry["lastname"]);
00319                 $tpl->parseCurrentBlock();
00320         }               
00321 }
00322 else
00323 {
00324         $tpl->setCurrentBlock("addr_no_content");
00325         $tpl->setVariable("TXT_ADDR_NO",$lng->txt("mail_search_no"));
00326         $tpl->parseCurrentBlock();
00327 }
00328 
00329 if (isset($_POST["cmd"]["add"]) &&
00330         $error_add)
00331 {
00332         $data["login"] = $_POST["login"];
00333         $data["firstname"] = $_POST["firstname"];
00334         $data["lastname"] = $_POST["lastname"];
00335         $data["email"] = $_POST["email"];
00336 }
00337 
00338 // SHOW EDIT FIELD
00339 $tpl->setVariable("CSSROW_LOGIN",'tblrow1');
00340 $tpl->setVariable("HEADER_LOGIN",$lng->txt("username"));
00341 $tpl->setVariable("VALUE_LOGIN",$data["login"]);
00342 $tpl->setVariable("CSSROW_FIRSTNAME",'tblrow2');
00343 $tpl->setVariable("HEADER_FIRSTNAME",$lng->txt("firstname"));
00344 $tpl->setVariable("VALUE_FIRSTNAME",$data["firstname"]);
00345 $tpl->setVariable("CSSROW_LASTNAME",'tblrow1');
00346 $tpl->setVariable("HEADER_LASTNAME",$lng->txt("lastname"));
00347 $tpl->setVariable("VALUE_LASTNAME",$data["lastname"]);
00348 $tpl->setVariable("CSSROW_EMAIL",'tblrow2');
00349 $tpl->setVariable("HEADER_EMAIL",$lng->txt("email"));
00350 $tpl->setVariable("VALUE_EMAIL",$data["email"]);
00351 
00352 // SUBMIT VALUE DEPENDS ON $_POST["cmd"]
00353 
00354 $tpl->setVariable("BUTTON_EDIT_ADD",(($_POST["action"] == "edit") and $_POST["cmd"]["submit"]) ? $lng->txt("change") : $lng->txt("add"));
00355 $tpl->setVariable("BUTTON_EDIT_ADD_NAME",(($_POST["action"] == "edit") and $_POST["cmd"]["submit"]) ? "cmd[change]" : "cmd[add]");
00356 
00357 $tpl->show();
00358 ?>

Generated on Fri Dec 13 2013 11:57:58 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1