Go to the documentation of this file.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 require_once "Services/Mail/classes/class.ilFormatMail.php";
00025 require_once "classes/class.ilFileDataMail.php";
00026
00033 class ilMailAttachmentGUI
00034 {
00035 private $tpl = null;
00036 private $ctrl = null;
00037 private $lng = null;
00038
00039 private $umail = null;
00040 private $mfile = null;
00041
00042 private $errorDelete = false;
00043
00044 public function __construct()
00045 {
00046 global $tpl, $ilCtrl, $lng, $ilUser;
00047
00048 $this->tpl = $tpl;
00049 $this->ctrl = $ilCtrl;
00050 $this->lng = $lng;
00051
00052 $this->ctrl->saveParameter($this, "mobj_id");
00053
00054 $this->umail = new ilFormatMail($ilUser->getId());
00055 $this->mfile = new ilFileDataMail($ilUser->getId());
00056 }
00057
00058 public function executeCommand()
00059 {
00060 $forward_class = $this->ctrl->getNextClass($this);
00061 switch($forward_class)
00062 {
00063 default:
00064 if (!($cmd = $this->ctrl->getCmd()))
00065 {
00066 $cmd = "showAttachments";
00067 }
00068
00069 $this->$cmd();
00070 break;
00071 }
00072 return true;
00073 }
00074
00075 public function saveAttachments()
00076 {
00077 global $ilUser;
00078
00079 $files = array();
00080
00081 if(is_array($_POST['filename']) && count($_POST['filename']))
00082 {
00083 foreach($_POST['filename'] as $file)
00084 {
00085 if(file_exists($this->mfile->getMailPath().'/'.basename($ilUser->getId().'_'.$file)))
00086 {
00087 $files[] = $file;
00088 }
00089 }
00090 }
00091
00092 $this->umail->saveAttachments($files);
00093
00094 $this->ctrl->returnToParent($this);
00095 }
00096
00097 public function cancelSaveAttachments()
00098 {
00099 $this->ctrl->setParameter($this, "type", "attach");
00100 $this->ctrl->returnToParent($this);
00101 }
00102
00103 public function deleteAttachments()
00104 {
00105 if(!$_POST["filename"])
00106 {
00107 ilUtil::sendInfo($this->lng->txt("mail_select_one_file"));
00108 $this->errorDelete = true;
00109 }
00110 else
00111 {
00112 ilUtil::sendInfo($this->lng->txt("mail_sure_delete_file"));
00113 }
00114
00115 $this->showAttachments();
00116 }
00117
00118 public function confirmDeleteAttachments()
00119 {
00120 if(!$_POST["filename"])
00121 {
00122 ilUtil::sendInfo($this->lng->txt("mail_select_one_mail"));
00123 }
00124 else if($error = $this->mfile->unlinkFiles($_POST["filename"]))
00125 {
00126 ilUtil::sendInfo($this->lng->txt("mail_error_delete_file")." ".$error);
00127 }
00128 else
00129 {
00130 $mailData = $this->umail->getSavedData();
00131 if (is_array($mailData["attachments"]))
00132 {
00133 $tmp = array();
00134 for ($i = 0; $i < count($mailData["attachments"]); $i++)
00135 {
00136 if (!in_array($mailData["attachments"][$i], $_POST["filename"]))
00137 {
00138 $tmp[] = $mailData["attachments"][$i];
00139 }
00140 }
00141 $mailData["attachments"] = $tmp;
00142 $this->umail->saveAttachments($tmp);
00143 }
00144
00145 ilUtil::sendInfo($this->lng->txt("mail_files_deleted"));
00146 }
00147
00148 $this->showAttachments();
00149 }
00150
00151 public function cancelDeleteAttachments()
00152 {
00153 $this->showAttachments();
00154 }
00155
00156 public function uploadFile()
00157 {
00158 if (trim($_FILES["userfile"]["name"]) != "")
00159 {
00160 if($this->mfile->storeUploadedFile($_FILES["userfile"]) == 1)
00161 {
00162 ilUtil::sendInfo($this->lng->txt("mail_maxsize_attachment_error")." ".$this->mfile->getUploadLimit()." K".$this->lng->txt("mail_byte"));
00163 }
00164 }
00165
00166 $this->showAttachments();
00167 }
00168
00169 public function showAttachments()
00170 {
00171 global $rbacsystem;
00172
00173 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_attachment.html", "Services/Mail");
00174 $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
00175 $this->tpl->setVariable("TXT_ATTACHMENT",$this->lng->txt("attachment"));
00176
00177 $mailData = $this->umail->getSavedData();
00178
00179 $this->ctrl->setParameter($this, "cmd", "post");
00180 $this->tpl->setVariable("ACTION", $this->ctrl->getLinkTarget($this));
00181 $this->tpl->setVariable("UPLOAD", $this->ctrl->getLinkTarget($this));
00182 $this->ctrl->clearParameters($this);
00183
00184
00185 if (isset($_POST["cmd"]["deleteAttachments"]) &&
00186 !$this->errorDelete &&
00187 !isset($_POST["cmd"]["confirm"]))
00188 {
00189 $this->tpl->setCurrentBlock("confirm_delete");
00190 $this->tpl->setVariable("BUTTON_CONFIRM",$this->lng->txt("confirm"));
00191 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00192 $this->tpl->parseCurrentBlock();
00193 }
00194
00195
00196 $this->tpl->setVariable("TXT_ATTACHMENT",$this->lng->txt("attachment"));
00197 $this->tpl->setVariable("TXT_FILENAME",$this->lng->txt("mail_file_name"));
00198 $this->tpl->setVariable("TXT_FILESIZE",$this->lng->txt("mail_file_size"));
00199 $this->tpl->setVariable("TXT_CREATE_TIME",$this->lng->txt("create_date"));
00200 $this->tpl->setVariable("TXT_NEW_FILE",$this->lng->txt("mail_new_file"));
00201
00202
00203 $this->tpl->setVariable("BUTTON_ATTACHMENT_ADOPT",$this->lng->txt("adopt"));
00204 $this->tpl->setVariable("BUTTON_ATTACHMENT_CANCEL",$this->lng->txt("cancel"));
00205 $this->tpl->setVariable("BUTTON_ATTACHMENT_DELETE",$this->lng->txt("delete"));
00206
00207
00208 $this->tpl->setVariable("BUTTON_SUBMIT",$this->lng->txt("submit"));
00209 $this->tpl->setVariable("BUTTON_UPLOAD",$this->lng->txt("upload"));
00210
00211
00212 if($files = $this->mfile->getUserFilesData())
00213 {
00214 $counter = 0;
00215 foreach($files as $file)
00216 {
00217 $this->tpl->setCurrentBlock('files');
00218 if((!isset($_POST["cmd"]["deleteAttachments"]) && is_array($mailData["attachments"]) && in_array($file["name"],$mailData["attachments"])) ||
00219 (isset($_POST["cmd"]["deleteAttachments"]) && is_array($_POST["filename"]) && in_array($file["name"],$_POST["filename"])))
00220 {
00221 $this->tpl->setVariable("CHECKED",'checked');
00222 }
00223 $this->tpl->setVariable('CSSROW',++$counter%2 ? 'tblrow1' : 'tblrow2');
00224 $this->tpl->setVariable('FILE_NAME',$file["name"]);
00225 $this->tpl->setVariable("NAME",$file["name"]);
00226 $this->tpl->setVariable("SIZE",$file["size"]);
00227 $this->tpl->setVariable("CTIME",$file["ctime"]);
00228 $this->tpl->parseCurrentBlock();
00229 }
00230 }
00231 else
00232 {
00233 $this->tpl->setCurrentBlock("no_content");
00234 $this->tpl->setVariable("TXT_ATTACHMENT_NO",$this->lng->txt("mail_no_attachments_found"));
00235 $this->tpl->parseCurrentBlock();
00236 }
00237
00238 $this->tpl->setVariable("TXT_MARKED_ENTRIES",$this->lng->txt("marked_entries"));
00239
00240 $this->tpl->show();
00241 }
00242
00243 }
00244
00245 ?>