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

mail.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.ilMailbox.php";
00037 require_once "classes/class.ilMail.php";
00038 
00039 $lng->loadLanguageModule("mail");
00040 $umail = new ilMail($_SESSION["AccountId"]);
00041 $mbox = new ilMailBox($_SESSION["AccountId"]);
00042 
00043 // CHECK HACK
00044 if (!$rbacsystem->checkAccess("mail_visible",$umail->getMailObjectReferenceId()))
00045 {
00046         $ilias->raiseError($lng->txt("permission_denied"),$ilias->error_obj->WARNING);
00047 }
00048 
00049 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
00050 $tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail.html");
00051 $tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
00052 $tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
00053 
00054 
00055 // display infopanel if something happened
00056 $tpl->setCurrentBlock("header_image");
00057 $tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_mail_b.gif"));
00058 $tpl->parseCurrentBlock();
00059 
00060 $tpl->setVariable("HEADER", $lng->txt("mail"));
00061 infoPanel();
00062 
00063 
00064 // IF THERE IS NO OBJ_ID GIVEN GET THE ID OF MAIL ROOT NODE
00065 if(!$_GET["mobj_id"])
00066 {
00067         $_GET["mobj_id"] = $mbox->getInboxFolder();
00068 }
00069 
00070 if(isset($_GET["sent"]))
00071 {
00072         sendInfo($lng->txt("mail_message_send"));
00073 }
00074 
00075 // IF REQUESTED FROM mail_read.php
00076 if(isset($_GET["mail_id"]))
00077 {
00078         $_POST["cmd"]["submit"] = true;
00079         $_POST["action"] = 'delete';
00080         $_POST["mail_id"] = array($_GET["mail_id"]);
00081 }
00082 setLocator($_GET["mobj_id"],'mail.php',$_SESSION["AccountId"],"");
00083 
00084 if (isset($_POST["cmd"]["submit"]))
00085 {
00086         switch ($_POST["action"])
00087         {
00088                 case 'mark_read':
00089                         if(is_array($_POST["mail_id"]))
00090                         {
00091                                 $umail->markRead($_POST["mail_id"]);
00092                         }
00093                         else
00094                         {
00095                                 sendInfo($lng->txt("mail_select_one"));
00096                         }
00097                         break;
00098                 case 'mark_unread':
00099                         if(is_array($_POST["mail_id"]))
00100                         {
00101                                 $umail->markUnread($_POST["mail_id"]);
00102                         }
00103                         else
00104                         {
00105                                 sendInfo($lng->txt("mail_select_one"));
00106                         }
00107                         break;
00108 
00109                 case 'delete':
00110                         // IF MAILBOX IS TRASH ASK TO CONFIRM
00111                         if($mbox->getTrashFolder() == $_GET["mobj_id"])
00112                         {
00113                                 if(!is_array($_POST["mail_id"]))
00114                                 {
00115                                         sendInfo($lng->txt("mail_select_one"));
00116                                         $error_delete = true;
00117                                 }
00118                                 else
00119                                 {
00120                                         sendInfo($lng->txt("mail_sure_delete"));
00121                                 }
00122                         } // END IF MAILBOX IS TRASH FOLDER
00123                         else
00124                         {
00125                                 // MOVE MAILS TO TRASH
00126                                 if(!is_array($_POST["mail_id"]))
00127                                 {
00128                                         sendInfo($lng->txt("mail_select_one"));
00129                                 }
00130                                 else if($umail->moveMailsToFolder($_POST["mail_id"],$mbox->getTrashFolder()))
00131                                 {
00132                                         sendInfo($lng->txt("mail_moved_to_trash"));
00133                                 }
00134                                 else
00135                                 {
00136                                         sendInfo($lng->txt("mail_move_error"));
00137                                 }
00138                         }
00139                         break;
00140 
00141                 case 'add':
00142                         header("location: mail_options.php?mobj_id=$_GET[mobj_id]&cmd=add");
00143                         exit;
00144 
00145                 default:
00146                         if(!is_array($_POST["mail_id"]))
00147                         {
00148                                 sendInfo($lng->txt("mail_select_one"));
00149                         }
00150                         else if($umail->moveMailsToFolder($_POST["mail_id"],$_POST["action"]))
00151                         {
00152                                 sendInfo($lng->txt("mail_moved"));
00153                         }
00154                         else
00155                         {
00156                                 sendInfo($lng->txt("mail_move_error"));
00157                         }
00158                         break;
00159         }
00160 }
00161 // ONLY IF FOLDER IS TRASH, IT WAS ASKED FOR CONFIRMATION
00162 if($mbox->getTrashFolder() == $_GET["mobj_id"])
00163 {
00164         if(isset($_POST["cmd"]["confirm"]))
00165         {
00166                 if(!is_array($_POST["mail_id"]))
00167                 {
00168                         sendInfo($lng->txt("mail_select_one"));
00169                 }
00170                 else if($umail->deleteMails($_POST["mail_id"]))
00171                 {
00172                         sendInfo($lng->txt("mail_deleted"));
00173                 }
00174                 else
00175                 {
00176                         sendInfo($lng->txt("mail_delete_error"));
00177                 }
00178         }
00179         if(isset($_POST["cmd"]["cancel"]))
00180         {
00181                 header("location: mail.php?mobj_id=$_GET[mobj_id]");
00182                 exit;
00183         }
00184 }
00185 
00186 include("./include/inc.mail_buttons.php");
00187 
00188 $tpl->setVariable("ACTION", "mail.php?mobj_id=$_GET[mobj_id]");
00189 
00190 // BEGIN CONFIRM_DELETE
00191 if($_POST["action"] == "delete" and !$error_delete and !isset($_POST["cmd"]["confirm"]) and $mbox->getTrashFolder() == $_GET["mobj_id"])
00192 {
00193         $tpl->setCurrentBlock("CONFIRM_DELETE");
00194         $tpl->setVariable("BUTTON_CONFIRM",$lng->txt("confirm"));
00195         $tpl->setVariable("BUTTON_CANCEL",$lng->txt("cancel"));
00196         $tpl->parseCurrentBlock();
00197 }
00198 
00199 // BEGIN MAIL ACTIONS
00200 $actions = $mbox->getActions($_GET["mobj_id"]);
00201 
00202 $tpl->setCurrentBlock("mailactions");
00203 foreach($actions as $key => $action)
00204 {
00205         if($key == 'move')
00206         {
00207                 $folders = $mbox->getSubFolders();
00208                 foreach($folders as $folder)
00209                 {
00210                         $tpl->setVariable("MAILACTION_VALUE", $folder["obj_id"]);
00211                         if($folder["type"] != 'user_folder')
00212                         {
00213                                 $tpl->setVariable("MAILACTION_NAME",$action." ".$lng->txt("mail_".$folder["title"]));
00214                         }
00215                         else
00216                         {
00217                                 $tpl->setVariable("MAILACTION_NAME",$action." ".$folder["title"]);
00218                         }
00219                         $tpl->parseCurrentBlock();
00220                 }
00221         }
00222         else
00223         {
00224                 $tpl->setVariable("MAILACTION_NAME", $action);
00225                 $tpl->setVariable("MAILACTION_VALUE", $key);
00226                 $tpl->setVariable("MAILACTION_SELECTED",$_POST["action"] == 'delete' ? 'selected' : '');
00227                 $tpl->parseCurrentBlock();
00228         }
00229 }
00230 // END MAIL ACTIONS
00231 
00232 
00233 // SHOW_FOLDER ONLY IF viewmode is flatview
00234 if(!isset($_SESSION["viewmode"]) or $_SESSION["viewmode"] == 'flat')
00235 {
00236         $tpl->setCurrentBlock("show_folder");
00237         $tpl->setCurrentBLock("flat_select");
00238    
00239         foreach($folders as $folder)
00240         {
00241                 if($folder["obj_id"] == $_GET["mobj_id"])
00242                 {
00243                         $tpl->setVariable("FLAT_SELECTED","selected");
00244                 }
00245                 $tpl->setVariable("FLAT_VALUE",$folder["obj_id"]);
00246                 if($folder["type"] == 'user_folder')
00247                 {
00248                         $tpl->setVariable("FLAT_NAME", $folder["title"]);
00249                 }
00250                 else
00251                 {
00252                         $tpl->setVariable("FLAT_NAME", $lng->txt("mail_".$folder["title"]));
00253                 }
00254                 $tpl->parseCurrentBlock();
00255         }
00256         $tpl->setVariable("TXT_FOLDERS", $lng->txt("mail_change_to_folder"));
00257         $tpl->setVariable("FOLDER_VALUE",$lng->txt("submit"));
00258         $tpl->parseCurrentBlock();
00259 }
00260 // END SHOW_FOLDER
00261 $tpl->setVariable("ACTION_FLAT","mail.php");
00262 
00263 // BEGIN MAILS
00264 $mail_data = $umail->getMailsOfFolder($_GET["mobj_id"]);
00265 $mail_count = count($mail_data);
00266 
00267 // TODO: READ FROM MAIL_OPTIONS
00268 $mail_max_hits = 20;
00269 $counter = 0;
00270 foreach ($mail_data as $mail)
00271 {
00272         if($mail["sender_id"] and !ilObjectFactory::ObjectIdExists($mail["sender_id"]))
00273         {
00274                 --$mail_count;
00275                 continue;
00276         }
00277         // LINKBAR
00278         if($mail_count > $mail_max_hits)
00279         {
00280                 $params = array(
00281                         "mobj_id"               => $_GET["mobj_id"]);
00282         }
00283         $start = $_GET["offset"];
00284         $linkbar = ilUtil::Linkbar(basename($_SERVER["PHP_SELF"]),$mail_count,$mail_max_hits,$start,$params);
00285         if ($linkbar)
00286         {
00287                 $tpl->setVariable("LINKBAR", $linkbar);
00288         }
00289         if($counter >= ($start+$mail_max_hits))
00290         {
00291                 break;
00292         }
00293         if($counter < $start)
00294         {
00295                 ++$counter;
00296                 continue;
00297         }
00298 
00299         // END LINKBAR
00300         ++$counter;
00301         $tpl->setCurrentBlock("mails");
00302         $tpl->setVariable("ROWCOL","tblrow".(($counter % 2)+1));
00303         $tpl->setVariable("MAIL_ID", $mail["mail_id"]);
00304 
00305         if(is_array($_POST["mail_id"]))
00306         {
00307                 $tpl->setVariable("CHECKBOX_CHECKED",in_array($mail["mail_id"],$_POST["mail_id"]) ? 'checked' : "");
00308         }
00309 
00310         // GET FULLNAME OF SENDER
00311         
00312         if($_GET['mobj_id'] == $mbox->getSentFolder() or $_GET['mobj_id'] == $mbox->getDraftsFolder())
00313         {
00314                 if($mail['rcp_to'])
00315                 {
00316                         $tpl->setVariable("MAIL_LOGIN",$mail['rcp_to']);
00317                 }
00318                 else
00319                 {
00320                         $tpl->setVariable("MAIL_LOGIN",$lng->txt('not_available'));
00321                 }
00322         }
00323         else
00324         {
00325                 $tmp_user = new ilObjUser($mail["sender_id"]);
00326                 $tpl->setVariable("MAIL_FROM", $tmp_user->getFullname());
00327                 if(!($login = $tmp_user->getLogin()))
00328                 {
00329                         $login = $mail["import_name"]." (".$lng->txt("imported").")";
00330                 }
00331                 $pic_path = $tmp_user->getPersonalPicturePath("xxsmall");
00332                 
00333                 $tpl->setCurrentBlock("pers_image");
00334                 $tpl->setVariable("IMG_SENDER", $pic_path);
00335                 $tpl->setVariable("ALT_SENDER", $login);
00336                 $tpl->parseCurrentBlock();
00337                 $tpl->setCurrentBlock("mails");
00338 
00339                 $tpl->setVariable("MAIL_LOGIN",$login);
00340         }
00341         $tpl->setVariable("MAILCLASS", $mail["m_status"] == 'read' ? 'mailread' : 'mailunread');
00342         // IF ACTUAL FOLDER IS DRAFT BOX, DIRECT TO COMPOSE MESSAGE
00343         if($_GET["mobj_id"] == $mbox->getDraftsFolder())
00344         {
00345                 $tpl->setVariable("MAIL_LINK_READ", "mail_new.php?mail_id=".
00346                                                   $mail["mail_id"]."&mobj_id=$_GET[mobj_id]&type=draft");
00347         }
00348         else
00349         {
00350                 $tpl->setVariable("MAIL_LINK_READ", "mail_read.php?mail_id=".
00351                                                   $mail["mail_id"]."&mobj_id=$_GET[mobj_id]");
00352         }
00353         $tpl->setVariable("MAIL_SUBJECT", htmlspecialchars($mail["m_subject"]));
00354         $tpl->setVariable("MAIL_DATE", ilFormat::formatDate($mail["send_time"]));
00355         $tpl->parseCurrentBlock();
00356 }
00357 // END MAILS
00358 
00359 $mtree = new ilTree($ilUser->getId());
00360 $mtree->setTableNames('mail_tree','mail_obj_data');
00361 $folder_node = $mtree->getNodeData($_GET[mobj_id]);
00362 
00363 
00364 // folder_image
00365 if($folder_node["type"] == 'user_folder')
00366 {
00367         $tpl->setVariable("TXT_FOLDER", $folder_node["title"]);
00368         $tpl->setVariable("IMG_FOLDER", ilUtil::getImagePath("icon_user_folder.gif"));
00369 }
00370 else
00371 {
00372         $tpl->setVariable("TXT_FOLDER", $lng->txt("mail_".$folder_node["title"]));
00373         $tpl->setVariable("IMG_FOLDER", ilUtil::getImagePath("icon".substr($folder_node["title"], 1).".gif"));
00374 }
00375 $tpl->setVariable("TXT_MAIL", $lng->txt("mail"));
00376 $tpl->setVariable("TXT_MAIL_S", $lng->txt("mail_s"));
00377 $tpl->setVariable("TXT_UNREAD", $lng->txt("unread"));
00378 $tpl->setVariable("TXT_SUBMIT",$lng->txt("submit"));
00379 $tpl->setVariable("TXT_SELECT_ALL", $lng->txt("select_all"));
00380 $tpl->setVariable("IMGPATH",$tpl->tplPath);
00381 
00382 // MAIL SUMMARY
00383 $mail_counter = $umail->getMailCounterData();
00384 $tpl->setVariable("MAIL_COUNT", $mail_counter["total"]);
00385 $tpl->setVariable("MAIL_COUNT_UNREAD", $mail_counter["unread"]);
00386 $tpl->setVariable("TXT_UNREAD_MAIL_S",$lng->txt("mail_s_unread"));
00387 $tpl->setVariable("TXT_MAIL_S",$lng->txt("mail_s"));
00388 
00389 //columns headlines
00390 if($_GET['mobj_id'] == $mbox->getSentFolder() or $_GET['mobj_id'] == $mbox->getDraftsFolder())
00391 {
00392         $tpl->setVariable("TXT_SENDER", $lng->txt("recipient"));
00393 }
00394 else
00395 {
00396         $tpl->setVariable("TXT_SENDER", $lng->txt("sender"));
00397 }
00398 $tpl->setVariable("TXT_SUBJECT", $lng->txt("subject"));
00399 //      $tpl->setVariable("MAIL_SORT_SUBJ","link");
00400 $tpl->setVariable("TXT_DATE",$lng->txt("date"));
00401 $tpl->setVariable("DIRECTION", "up");
00402 
00403 $tpl->show();
00404 
00405 ?>

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