00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
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
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
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
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 }
00123 else
00124 {
00125
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 $_GET["offset"] = 0;
00133 sendInfo($lng->txt("mail_moved_to_trash"));
00134 }
00135 else
00136 {
00137 sendInfo($lng->txt("mail_move_error"));
00138 }
00139 }
00140 break;
00141
00142 case 'add':
00143 header("location: mail_options.php?mobj_id=$_GET[mobj_id]&cmd=add");
00144 exit;
00145
00146 default:
00147 if(!is_array($_POST["mail_id"]))
00148 {
00149 sendInfo($lng->txt("mail_select_one"));
00150 }
00151 else if($umail->moveMailsToFolder($_POST["mail_id"],$_POST["action"]))
00152 {
00153 sendInfo($lng->txt("mail_moved"));
00154 }
00155 else
00156 {
00157 sendInfo($lng->txt("mail_move_error"));
00158 }
00159 break;
00160 }
00161 }
00162
00163 if($mbox->getTrashFolder() == $_GET["mobj_id"])
00164 {
00165 if(isset($_POST["cmd"]["confirm"]))
00166 {
00167 if(!is_array($_POST["mail_id"]))
00168 {
00169 sendInfo($lng->txt("mail_select_one"));
00170 }
00171 else if($umail->deleteMails($_POST["mail_id"]))
00172 {
00173 $_GET["offset"] = 0;
00174 sendInfo($lng->txt("mail_deleted"));
00175 }
00176 else
00177 {
00178 sendInfo($lng->txt("mail_delete_error"));
00179 }
00180 }
00181 if(isset($_POST["cmd"]["cancel"]))
00182 {
00183 header("location: mail.php?mobj_id=$_GET[mobj_id]&offset=$_GET[offset]");
00184 exit;
00185 }
00186 }
00187
00188 include("./include/inc.mail_buttons.php");
00189
00190 $tpl->setVariable("ACTION", "mail.php?mobj_id=$_GET[mobj_id]&offset=$_GET[offset]");
00191
00192
00193 if($_POST["action"] == "delete" and !$error_delete and !isset($_POST["cmd"]["confirm"]) and $mbox->getTrashFolder() == $_GET["mobj_id"])
00194 {
00195 $tpl->setCurrentBlock("CONFIRM_DELETE");
00196 $tpl->setVariable("BUTTON_CONFIRM",$lng->txt("confirm"));
00197 $tpl->setVariable("BUTTON_CANCEL",$lng->txt("cancel"));
00198 $tpl->parseCurrentBlock();
00199 }
00200
00201
00202 $actions = $mbox->getActions($_GET["mobj_id"]);
00203
00204 $tpl->setCurrentBlock("mailactions");
00205 foreach($actions as $key => $action)
00206 {
00207 if($key == 'move')
00208 {
00209 $folders = $mbox->getSubFolders();
00210 foreach($folders as $folder)
00211 {
00212 $tpl->setVariable("MAILACTION_VALUE", $folder["obj_id"]);
00213 if($folder["type"] != 'user_folder')
00214 {
00215 $tpl->setVariable("MAILACTION_NAME",$action." ".$lng->txt("mail_".$folder["title"]));
00216 }
00217 else
00218 {
00219 $tpl->setVariable("MAILACTION_NAME",$action." ".$folder["title"]);
00220 }
00221 $tpl->parseCurrentBlock();
00222 }
00223 }
00224 else
00225 {
00226 $tpl->setVariable("MAILACTION_NAME", $action);
00227 $tpl->setVariable("MAILACTION_VALUE", $key);
00228 $tpl->setVariable("MAILACTION_SELECTED",$_POST["action"] == 'delete' ? 'selected' : '');
00229 $tpl->parseCurrentBlock();
00230 }
00231 }
00232
00233
00234
00235
00236 if(!isset($_SESSION["viewmode"]) or $_SESSION["viewmode"] == 'flat')
00237 {
00238 $tpl->setCurrentBlock("show_folder");
00239 $tpl->setCurrentBLock("flat_select");
00240
00241 foreach($folders as $folder)
00242 {
00243 if($folder["obj_id"] == $_GET["mobj_id"])
00244 {
00245 $tpl->setVariable("FLAT_SELECTED","selected");
00246 }
00247 $tpl->setVariable("FLAT_VALUE",$folder["obj_id"]);
00248 if($folder["type"] == 'user_folder')
00249 {
00250 $tpl->setVariable("FLAT_NAME", $folder["title"]);
00251 }
00252 else
00253 {
00254 $tpl->setVariable("FLAT_NAME", $lng->txt("mail_".$folder["title"]));
00255 }
00256 $tpl->parseCurrentBlock();
00257 }
00258 $tpl->setVariable("TXT_FOLDERS", $lng->txt("mail_change_to_folder"));
00259 $tpl->setVariable("FOLDER_VALUE",$lng->txt("submit"));
00260 $tpl->parseCurrentBlock();
00261 }
00262
00263 $tpl->setVariable("ACTION_FLAT","mail.php?offset=$_GET[offset]");
00264
00265
00266 $mail_data = $umail->getMailsOfFolder($_GET["mobj_id"]);
00267 $mail_count = count($mail_data);
00268
00269
00270 $mail_max_hits = $ilUser->getPref('hits_per_page');
00271 $counter = 0;
00272 foreach ($mail_data as $mail)
00273 {
00274 if($mail["sender_id"] and !ilObjectFactory::ObjectIdExists($mail["sender_id"]))
00275 {
00276 --$mail_count;
00277 continue;
00278 }
00279
00280 if($mail_count > $mail_max_hits)
00281 {
00282 $params = array(
00283 "mobj_id" => $_GET["mobj_id"]);
00284 }
00285 $start = $_GET["offset"];
00286 $linkbar = ilUtil::Linkbar(basename($_SERVER["PHP_SELF"]),$mail_count,$mail_max_hits,$start,$params);
00287 if ($linkbar)
00288 {
00289 $tpl->setVariable("LINKBAR", $linkbar);
00290 }
00291 if($counter >= ($start+$mail_max_hits))
00292 {
00293 break;
00294 }
00295 if($counter < $start)
00296 {
00297 ++$counter;
00298 continue;
00299 }
00300
00301
00302 ++$counter;
00303 $tpl->setCurrentBlock("mails");
00304 $tpl->setVariable("ROWCOL","tblrow".(($counter % 2)+1));
00305 $tpl->setVariable("MAIL_ID", $mail["mail_id"]);
00306
00307 if(is_array($_POST["mail_id"]))
00308 {
00309 $tpl->setVariable("CHECKBOX_CHECKED",in_array($mail["mail_id"],$_POST["mail_id"]) ? 'checked' : "");
00310 }
00311
00312
00313
00314 if($_GET['mobj_id'] == $mbox->getSentFolder() or $_GET['mobj_id'] == $mbox->getDraftsFolder())
00315 {
00316 if($mail['rcp_to'])
00317 {
00318 $tpl->setVariable("MAIL_LOGIN",str_replace(",", ", ", $mail['rcp_to']));
00319 }
00320 else
00321 {
00322 $tpl->setVariable("MAIL_LOGIN",$lng->txt('not_available'));
00323 }
00324 }
00325 else
00326 {
00327 $tmp_user = new ilObjUser($mail["sender_id"]);
00328 $tpl->setVariable("MAIL_FROM", $tmp_user->getFullname());
00329 if(!($login = $tmp_user->getLogin()))
00330 {
00331 $login = $mail["import_name"]." (".$lng->txt("imported").")";
00332 }
00333 $pic_path = $tmp_user->getPersonalPicturePath("xxsmall");
00334
00335 $tpl->setCurrentBlock("pers_image");
00336 $tpl->setVariable("IMG_SENDER", $pic_path);
00337 $tpl->setVariable("ALT_SENDER", $login);
00338 $tpl->parseCurrentBlock();
00339 $tpl->setCurrentBlock("mails");
00340
00341 $tpl->setVariable("MAIL_LOGIN",$login);
00342 }
00343 $tpl->setVariable("MAILCLASS", $mail["m_status"] == 'read' ? 'mailread' : 'mailunread');
00344
00345 if($_GET["mobj_id"] == $mbox->getDraftsFolder())
00346 {
00347 $tpl->setVariable("MAIL_LINK_READ", "mail_new.php?mail_id=".
00348 $mail["mail_id"]."&mobj_id=$_GET[mobj_id]&type=draft");
00349 }
00350 else
00351 {
00352 $tpl->setVariable("MAIL_LINK_READ", "mail_read.php?mail_id=".
00353 $mail["mail_id"]."&mobj_id=$_GET[mobj_id]");
00354 }
00355 $tpl->setVariable("MAIL_SUBJECT", htmlspecialchars($mail["m_subject"]));
00356 $tpl->setVariable("MAIL_DATE", ilFormat::formatDate($mail["send_time"]));
00357 $tpl->parseCurrentBlock();
00358 }
00359
00360
00361 $mtree = new ilTree($ilUser->getId());
00362 $mtree->setTableNames('mail_tree','mail_obj_data');
00363 $folder_node = $mtree->getNodeData($_GET[mobj_id]);
00364
00365
00366
00367 if($folder_node["type"] == 'user_folder')
00368 {
00369 $tpl->setVariable("TXT_FOLDER", $folder_node["title"]);
00370 $tpl->setVariable("IMG_FOLDER", ilUtil::getImagePath("icon_user_folder.gif"));
00371 }
00372 else
00373 {
00374 $tpl->setVariable("TXT_FOLDER", $lng->txt("mail_".$folder_node["title"]));
00375 $tpl->setVariable("IMG_FOLDER", ilUtil::getImagePath("icon".substr($folder_node["title"], 1).".gif"));
00376 }
00377 $tpl->setVariable("TXT_MAIL", $lng->txt("mail"));
00378 $tpl->setVariable("TXT_MAIL_S", $lng->txt("mail_s"));
00379 $tpl->setVariable("TXT_UNREAD", $lng->txt("unread"));
00380 $tpl->setVariable("TXT_SUBMIT",$lng->txt("submit"));
00381 $tpl->setVariable("TXT_SELECT_ALL", $lng->txt("select_all"));
00382 $tpl->setVariable("IMGPATH",$tpl->tplPath);
00383
00384
00385 $mail_counter = $umail->getMailCounterData();
00386 $tpl->setVariable("MAIL_COUNT", $mail_counter["total"]);
00387 $tpl->setVariable("MAIL_COUNT_UNREAD", $mail_counter["unread"]);
00388 $tpl->setVariable("TXT_UNREAD_MAIL_S",$lng->txt("mail_s_unread"));
00389 $tpl->setVariable("TXT_MAIL_S",$lng->txt("mail_s"));
00390
00391
00392 if($_GET['mobj_id'] == $mbox->getSentFolder() or $_GET['mobj_id'] == $mbox->getDraftsFolder())
00393 {
00394 $tpl->setVariable("TXT_SENDER", $lng->txt("recipient"));
00395 }
00396 else
00397 {
00398 $tpl->setVariable("TXT_SENDER", $lng->txt("sender"));
00399 }
00400 $tpl->setVariable("TXT_SUBJECT", $lng->txt("subject"));
00401
00402 $tpl->setVariable("TXT_DATE",$lng->txt("date"));
00403 $tpl->setVariable("DIRECTION", "up");
00404
00405 $tpl->show();
00406
00407 ?>