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 include_once("Services/Block/classes/class.ilBlockGUI.php");
00025
00034 class ilPDMailBlockGUI extends ilBlockGUI
00035 {
00036 static $block_type = "pdmail";
00037
00041 function ilPDMailBlockGUI()
00042 {
00043 global $ilCtrl, $lng, $ilUser;
00044
00045 #include_once "./include/inc.mail.php";
00046 include_once './Services/User/classes/class.ilObjUser.php';
00047 include_once "Services/Mail/classes/class.ilMailbox.php";
00048 include_once "Services/Mail/classes/class.ilMail.php";
00049
00050
00051 parent::ilBlockGUI();
00052
00053 $this->setLimit(5);
00054 $this->setImage(ilUtil::getImagePath("icon_mail_s.gif"));
00055 $this->setTitle($lng->txt("mail"));
00056 $this->setAvailableDetailLevels(3);
00057 }
00058
00064 static function getBlockType()
00065 {
00066 return self::$block_type;
00067 }
00068
00074 static function isRepositoryObject()
00075 {
00076 return false;
00077 }
00078
00082 static function getScreenMode()
00083 {
00084 switch($_GET["cmd"])
00085 {
00086 case "showMail":
00087 return IL_SCREEN_CENTER;
00088 break;
00089
00090 default:
00091 return IL_SCREEN_SIDE;
00092 break;
00093 }
00094 }
00095
00099 function &executeCommand()
00100 {
00101 global $ilCtrl;
00102
00103 $next_class = $ilCtrl->getNextClass();
00104 $cmd = $ilCtrl->getCmd("getHTML");
00105
00106 return $this->$cmd();
00107 }
00108
00109 function getHTML()
00110 {
00111 global $ilUser, $rbacsystem;
00112
00113 $umail = new ilMail($ilUser->getId());
00114 if(!$rbacsystem->checkAccess('mail_visible', $umail->getMailObjectReferenceId()))
00115 {
00116 return '';
00117 }
00118
00119 if ($this->getCurrentDetailLevel() == 0)
00120 {
00121 return '';
00122 }
00123 else
00124 {
00125 $html = parent::getHTML();
00126 return $html;
00127 }
00128 }
00129
00133 function getMails()
00134 {
00135 global $ilUser;
00136
00137
00138 $umail = new ilMail($_SESSION["AccountId"]);
00139 $mbox = new ilMailBox($_SESSION["AccountId"]);
00140 $inbox = $mbox->getInboxFolder();
00141
00142
00143 $mail_data = $umail->getMailsOfFolder($inbox);
00144 $mail_counter = $umail->getMailCounterData();
00145 $unreadmails = 0;
00146
00147 $this->mails = array();
00148 foreach ($mail_data as $mail)
00149 {
00150
00151 if($mail["m_status"] == 'unread' &&
00152 in_array('normal',$mail['m_type']))
00153 {
00154 $this->mails[] = $mail;
00155 }
00156 }
00157 }
00158
00162 function fillDataSection()
00163 {
00164 $this->getMails();
00165 $this->setData($this->mails);
00166
00167 if ($this->getCurrentDetailLevel() > 1 && count($this->mails) > 0)
00168 {
00169 $this->setRowTemplate("tpl.pd_mail_row.html", "Services/Mail");
00170 if ($this->getCurrentDetailLevel() > 2)
00171 {
00172 $this->setColSpan(2);
00173 }
00174 parent::fillDataSection();
00175 }
00176 else
00177 {
00178 $this->setEnableNumInfo(false);
00179 if (count($this->mails) == 0)
00180 {
00181 $this->setEnableDetailRow(false);
00182 }
00183 $this->setDataSection($this->getOverview());
00184 }
00185 }
00186
00190 function fillRow($mail)
00191 {
00192 global $ilUser, $ilCtrl, $lng;
00193
00194
00195 $user = new ilObjUser($mail["sender_id"]);
00196 if ($this->getCurrentDetailLevel() > 2)
00197 {
00198 $this->tpl->setCurrentBlock("image");
00199 $this->tpl->setVariable("IMG_SENDER", $user->getPersonalPicturePath("xxsmall"));
00200 $this->tpl->setVariable("ALT_SENDER", $user->getLogin());
00201 $this->tpl->parseCurrentBlock();
00202 $this->tpl->setCurrentBlock("long");
00203 if($mail['sender_id'] != ANONYMOUS_USER_ID)
00204 {
00205 if(ilObjUser::_lookupPref($mail['sender_id'], 'public_profile') == 'y')
00206 {
00207 if(!($fullname = $user->getFullname()))
00208 {
00209 $fullname = $lng->txt("unknown");
00210 }
00211 $this->tpl->setVariable("NEW_MAIL_FROM", $fullname);
00212 }
00213 $this->tpl->setVariable("NEW_MAIL_FROM_LOGIN", $user->getLogin());
00214 }
00215 else
00216 {
00217 $this->tpl->setVariable('NEW_MAIL_FROM_LOGIN', ilMail::_getAnonymousName());
00218 }
00219 $this->tpl->setVariable('NEW_MAIL_DATE', ilFormat::formatDate($mail['send_time'], 'date', true));
00220 $this->tpl->setVariable("TXT_FROM", $lng->txt("from"));
00221 $this->tpl->parseCurrentBlock();
00222 }
00223 else
00224 {
00225 if($mail['sender_id'] != ANONYMOUS_USER_ID)
00226 {
00227 $this->tpl->setCurrentBlock('short');
00228 $this->tpl->setVariable('NEW_MAIL_FROM_LOGIN', $user->getLogin());
00229 $this->tpl->parseCurrentBlock();
00230 }
00231 else
00232 {
00233 $this->tpl->setCurrentBlock('short');
00234 $this->tpl->setVariable('NEW_MAIL_FROM_LOGIN', ilMail::_getAnonymousName());
00235 $this->tpl->parseCurrentBlock();
00236 }
00237 }
00238
00239 $this->tpl->setVariable("NEW_MAIL_SUBJ", htmlentities($mail["m_subject"],ENT_NOQUOTES,'UTF-8'));
00240 $ilCtrl->setParameter($this, "mobj_id", $inbox);
00241 $ilCtrl->setParameter($this, "mail_id", $mail["mail_id"]);
00242 $ilCtrl->setParameter($this, "mail_mode", $this->mail_mode);
00243 $this->tpl->setVariable("NEW_MAIL_LINK_READ",
00244 $ilCtrl->getLinkTarget($this, "showMail"));
00245 $ilCtrl->clearParameters($this);
00246 }
00247
00251 function getOverview()
00252 {
00253 global $ilUser, $lng, $ilCtrl;
00254
00255 return '<div class="small">'.((int) count($this->mails))." ".$lng->txt("mails_pl")."</div>";
00256 }
00257
00261 function showMail()
00262 {
00263 global $lng, $ilCtrl;
00264
00265 include_once("./Services/Mail/classes/class.ilPDMailGUI.php");
00266 $mail_gui = new ilPDMailGUI();
00267
00268 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
00269 $content_block = new ilPDContentBlockGUI();
00270 $content_block->setContent($mail_gui->getPDMailHTML($_GET["mail_id"],
00271 $_GET["mobj_id"]));
00272 $content_block->setTitle($lng->txt("message"));
00273 $content_block->setColSpan(2);
00274 $content_block->setImage(ilUtil::getImagePath("icon_mail.gif"));
00275 $content_block->addHeaderCommand($ilCtrl->getLinkTargetByClass("ilpersonaldesktopgui", "show"),
00276 $lng->txt("selected_items_back"));
00277
00278 if ($_GET["mail_mode"] != "system")
00279 {
00280 $content_block->addBlockCommand("ilias.php?baseClass=ilMailGUI&mail_id=".
00281 $_GET["mail_id"]."&mobj_id".$_GET["mobj_id"]."&type=reply",
00282 $lng->txt("reply"));
00283 $content_block->addBlockCommand("ilias.php?baseClass=ilMailGUI&mail_id=".
00284 $_GET["mail_id"]."&mobj_id".$_GET["mobj_id"]."&type=read",
00285 $lng->txt("inbox"));
00286
00287 $ilCtrl->setParameter($this, 'mail_id', (int) $_GET['mail_id']);
00288 $content_block->addBlockCommand($ilCtrl->getLinkTarget($this, 'deleteMail'), $lng->txt('delete'));
00289
00290
00291 }
00292 else
00293 {
00294 $ilCtrl->setParameter($this, "mail_id", $_GET["mail_id"]);
00295 $ilCtrl->setParameter($this, "mobj_id", $_GET["mobj_id"]);
00296 $content_block->addBlockCommand(
00297 $ilCtrl->getLinkTarget($this, "deleteMail"),
00298 $lng->txt("delete"));
00299 $ilCtrl->clearParameters($this);
00300 }
00301
00302 return $content_block->getHTML();
00303 }
00304
00308 function deleteMail()
00309 {
00310 global $lng, $ilCtrl;
00311
00312 $lng->loadLanguageModule('mail');
00313
00314 $umail = new ilMail($_SESSION['AccountId']);
00315 $mbox = new ilMailBox($_SESSION['AccountId']);
00316
00317
00318 if(!$_GET['mobj_id'])
00319 {
00320 $_GET['mobj_id'] = $mbox->getInboxFolder();
00321 }
00322
00323 if ($umail->moveMailsToFolder(array($_GET['mail_id']),
00324 $mbox->getTrashFolder()))
00325 {
00326 ilUtil::sendInfo($lng->txt('mail_moved_to_trash'), true);
00327 }
00328 else
00329 {
00330 ilUtil::sendInfo($lng->txt('mail_move_error'), true);
00331 }
00332 $ilCtrl->redirectByClass('ilpersonaldesktopgui', 'show');
00333 }
00334 }
00335 ?>