/**
  * Constructor
  */
 function ilEphorusMemberTableGUI($a_parent_obj, $a_parent_cmd, $a_eph, $a_ass_id)
 {
     global $ilCtrl, $lng, $ilAccess, $lng;
     $this->eph = $a_eph;
     $this->eph_id = $this->eph->getId();
     $this->setId("eph_mem_" . $a_ass_id);
     include_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus/classes/class.ilFSStorageEphorus.php";
     $this->storage = new ilFSStorageEphorus($this->eph_id, $a_ass_id);
     include_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus/classes/class.ilEphAssignment.php";
     $this->ass_id = $a_ass_id;
     //var_dump(ilEphAssignment::getMemberListData($this->eph_id, $this->ass_id));
     parent::__construct($a_parent_obj, $a_parent_cmd);
     $this->setData(ilEphAssignment::getMemberListData($this->eph_id, $this->ass_id));
     $this->setTitle($lng->txt("rep_robj_xeph_assignment") . ": " . ilEphAssignment::lookupTitle($a_ass_id));
     $this->setTopCommands(true);
     //$this->setLimit(9999);
     $this->addColumn("", "", "1", true);
     $this->addColumn($this->lng->txt("image"), "", "1");
     $this->addColumn($this->lng->txt("name"), "name");
     $this->addColumn($this->lng->txt("login"), "login");
     $this->sent_col = ilEphAssignment::lookupAnyEphorusSent($this->eph->getId(), $this->ass_id);
     if ($this->sent_col) {
         $this->addColumn($this->lng->txt("rep_robj_xeph_exercise_sent"), "sent_time");
     }
     $this->addColumn($this->lng->txt("rep_robj_xeph_submission"), "submission");
     $this->addColumn($this->lng->txt("rep_robj_xeph_reports"), "reports");
     $this->addColumn($this->lng->txt("rep_robj_xeph_grading"), "solved_time");
     $this->addColumn($this->lng->txt("feedback"), "feedback_time");
     $this->setDefaultOrderField("name");
     $this->setDefaultOrderDirection("asc");
     $this->setEnableHeader(true);
     $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
     $this->setRowTemplate("tpl.eph_members_row.html", "Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus");
     //$this->disable("footer");
     $this->setEnableTitle(true);
     $this->setSelectAllCheckbox("member");
     $this->addMultiCommand("saveStatus", $lng->txt("rep_robj_xeph_save"));
     $this->addMultiCommand("redirectFeedbackMail", $lng->txt("rep_robj_xeph_send_mail"));
     $this->addMultiCommand("sendMembers", $lng->txt("rep_robj_xeph_send_assignment"));
     $this->addMultiCommand("confirmDeassignMembers", $lng->txt("rep_robj_xeph_deassign_members"));
     if (count(ilEphAssignment::getAllDeliveredFiles($this->eph_id, $this->ass_id))) {
         $this->addCommandButton("downloadAllDeliveredFiles", $lng->txt("download_all_returned_files"));
     }
 }
 /**
  * Constructor
  */
 function __construct($a_parent_obj, $a_parent_cmd, $a_eph, $a_ass_id)
 {
     global $ilCtrl, $lng, $ilAccess, $lng;
     $this->eph = $a_eph;
     $this->eph_id = $this->eph->getId();
     include_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus/classes/class.ilEphAssignment.php";
     $this->ass_id = $a_ass_id;
     parent::__construct($a_parent_obj, $a_parent_cmd);
     $this->setData(ilEphAssignment::getMemberListData($this->eph_id, $this->ass_id));
     $this->setTitle($lng->txt("rep_robj_xeph_assignment") . ": " . ilEphAssignment::lookupTitle($a_ass_id));
     $this->setTopCommands(true);
     //$this->setLimit(9999);
     $this->addColumn($this->lng->txt("name"), "name");
     $this->addColumn($this->lng->txt("rep_robj_xeph_submission"), "");
     $this->setDefaultOrderField("name");
     $this->setDefaultOrderDirection("asc");
     $this->setEnableHeader(true);
     $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
     $this->setRowTemplate("tpl.eph_public_submissions_row.html", "Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus");
     //$this->disable("footer");
     $this->setEnableTitle(true);
 }
 /**
  * Download all submitted files of an assignment (all user)
  *
  * @param	$members		array of user names, key is user id
  */
 function downloadAllDeliveredFiles($a_eph_id, $a_ass_id, $members)
 {
     global $lng, $ilObjDataCache, $ilias;
     include_once "./Services/Utilities/classes/class.ilUtil.php";
     include_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus/classes/class.ilFSStorageEphorus.php";
     $storage = new ilFSStorageEphorus($a_eph_id, $a_ass_id);
     $storage->create();
     ksort($members);
     //$savepath = $this->getEphorusPath() . "/" . $this->obj_id . "/";
     $savepath = $storage->getAbsoluteSubmissionPath();
     $cdir = getcwd();
     // important check: if the directory does not exist
     // ILIAS stays in the current directory (echoing only a warning)
     // and the zip command below archives the whole ILIAS directory
     // (including the data directory) and sends a mega file to the user :-o
     if (!is_dir($savepath)) {
         return;
     }
     // Safe mode fix
     //		chdir($this->getEphorusPath());
     chdir($storage->getTempPath());
     $zip = PATH_TO_ZIP;
     // check first, if we have enough free disk space to copy all files to temporary directory
     $tmpdir = ilUtil::ilTempnam();
     ilUtil::makeDir($tmpdir);
     chdir($tmpdir);
     $dirsize = 0;
     foreach ($members as $id => $object) {
         $directory = $savepath . DIRECTORY_SEPARATOR . $id;
         $dirsize += ilUtil::dirsize($directory);
     }
     if ($dirsize > disk_free_space($tmpdir)) {
         return -1;
     }
     // copy all member directories to the temporary folder
     // switch from id to member name and append the login if the member name is double
     // ensure that no illegal filenames will be created
     // remove timestamp from filename
     $cache = array();
     foreach ($members as $id => $user) {
         $sourcedir = $savepath . DIRECTORY_SEPARATOR . $id;
         if (!is_dir($sourcedir)) {
             continue;
         }
         $userName = ilObjUser::_lookupName($id);
         $directory = ilUtil::getASCIIFilename(trim($userName["lastname"]) . "_" . trim($userName["firstname"]));
         if (array_key_exists($directory, $cache)) {
             // first try is to append the login;
             $directory = ilUtil::getASCIIFilename($directory . "_" . trim(ilObjUser::_lookupLogin($id)));
             if (array_key_exists($directory, $cache)) {
                 // second and secure: append the user id as well.
                 $directory .= "_" . $id;
             }
         }
         $cache[$directory] = $directory;
         ilUtil::makeDir($directory);
         $sourcefiles = scandir($sourcedir);
         foreach ($sourcefiles as $sourcefile) {
             if ($sourcefile == "." || $sourcefile == "..") {
                 continue;
             }
             $targetfile = trim(basename($sourcefile));
             $pos = strpos($targetfile, "_");
             if ($pos === false) {
             } else {
                 $targetfile = substr($targetfile, $pos + 1);
             }
             $targetfile = $directory . DIRECTORY_SEPARATOR . $targetfile;
             $sourcefile = $sourcedir . DIRECTORY_SEPARATOR . $sourcefile;
             if (!copy($sourcefile, $targetfile)) {
                 //echo 'Could not copy '.$sourcefile.' to '.$targetfile;
                 $ilias->raiseError('Could not copy ' . basename($sourcefile) . " to '" . $targetfile . "'.", $ilias->error_obj->MESSAGE);
             } else {
                 // preserve time stamp
                 touch($targetfile, filectime($sourcefile));
             }
         }
     }
     $tmpfile = ilUtil::ilTempnam();
     $tmpzipfile = $tmpfile . ".zip";
     // Safe mode fix
     $zipcmd = $zip . " -r " . ilUtil::escapeShellArg($tmpzipfile) . " .";
     exec($zipcmd);
     ilUtil::delDir($tmpdir);
     $assTitle = ilEphAssignment::lookupTitle($a_ass_id);
     chdir($cdir);
     ilUtil::deliverFile($tmpzipfile, (strlen($assTitle) == 0 ? strtolower($lng->txt("rep_robj_xeph_ephorus_assignment")) : $assTitle) . ".zip", "", false, true);
 }
 function viewReport()
 {
     global $ilCtrl, $ilTabs, $lng, $tpl;
     include_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus/classes/class.ilEphorusReportTableGUI.php";
     include_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus/classes/class.ilEphorusReportGUI.php";
     include_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus/include/class.DLEApi.php";
     include_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus/include/class.EphorusApi.php";
     $document = DLEApi::getDocument($_GET['doc_id']);
     $mode = isset($_GET["mode"]) ? $_GET["mode"] : "summary";
     $ephorus_report = new EphorusReport($_GET['doc_id'], $mode);
     $tpl->setTitle(sprintf($lng->txt("rep_robj_xeph_report_for assignment"), ilEphAssignment::lookupTitle($_GET["ass_id"])));
     $tpl->setDescription("");
     $tpl->addCss($this->object->plugin->getStyleSheetLocation("report.css"));
     $ilTabs->clearTargets();
     $ilTabs->setBackTarget($lng->txt("back"), $ilCtrl->getLinkTarget($this, "showSubmissions"));
     $eph_tab = new ilEphorusReportHeaderTableGUI($this, "viewReport", $document);
     $header = $eph_tab->getHTML() . "<br />";
     $matches = "";
     $eph_content = new ilEphorusReportGUI($this);
     if ($document->status == 1) {
         $pre_header = "<div class=\"small xephModeSelection\">";
         $ilCtrl->setParameter($this, "mode", "summary");
         $pre_header .= ($mode == "summary" ? "<span style=>Summary</span>" : "<a href=\"" . $ilCtrl->getLinkTarget($this, "viewReport") . "\">Summary</a>") . " / ";
         $ilCtrl->setParameter($this, "mode", "detailed");
         $pre_header .= $mode == "detailed" ? "<span>Detailed</span>" : "<a href=\"" . $ilCtrl->getLinkTarget($this, "viewReport") . "\">Detailed</a>";
         $header = $pre_header . "</div>" . $header;
         $ilCtrl->setParameter($this, "mode", $mode);
         $results = DLEApi::getResults($document->guid);
         if ($mode == "detailed") {
             $js = "\$('input[name=\"diff\"]').change(function() {\n                    \$(this).parents('form').append('<input type=\"hidden\" name=\"cmd[viewReport]\">');\n                    \$(this).parents('form').submit();\n                 });";
             $tpl->addOnLoadCode($js);
             $result = isset($_POST['diff']) ? $_POST["diff"] : reset($results)->guid;
             $eph_matches = new ilEphorusReportMatchesDetailedTableGUI($this, "viewReport", $document, $ephorus_report->getHeader($result));
             $matches = $eph_matches->getHTML() . "<br />";
             $content = $eph_content->getReport($ephorus_report->getReport(array(), $results[$result]->comparison));
         } else {
             $guids = isset($_POST['guids_use']) ? $_POST["guids_use"] : array_keys($results);
             $eph_matches = new ilEphorusReportMatchesTableGUI($this, "viewReport", $document, $ephorus_report->getHeader($guids));
             $matches = $eph_matches->getHTML() . "<br />";
             $content = $eph_content->getReport($ephorus_report->getReport($guids));
         }
     } else {
         $content = $eph_content->getReport($ephorus_report->getReport());
     }
     $tpl->setContent($header . $matches . $content);
 }
 /**
  * send ephorus per mail to members
  */
 function sendAssignment($a_eph_id, $a_ass_id, $a_members)
 {
     include_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus/classes/class.ilEphAssignment.php";
     $ass_title = ilEphAssignment::lookupTitle($a_ass_id);
     include_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/Ephorus/classes/class.ilFSStorageEphorus.php";
     $storage = new ilFSStorageEphorus($a_eph_id, $a_ass_id);
     $files = $storage->getFiles();
     if (count($files)) {
         include_once "./Services/Mail/classes/class.ilFileDataMail.php";
         $mfile_obj = new ilFileDataMail($_SESSION["AccountId"]);
         foreach ($files as $file) {
             $mfile_obj->copyAttachmentFile($file["fullpath"], $file["name"]);
             $file_names[] = $file["name"];
         }
     }
     include_once "Services/Mail/classes/class.ilMail.php";
     $tmp_mail_obj = new ilMail($_SESSION["AccountId"]);
     $message = $tmp_mail_obj->sendMail($this->__formatRecipients($a_members), "", "", $this->__formatSubject($ass_title), $this->__formatBody($a_ass_id), count($file_names) ? $file_names : array(), array("normal"));
     unset($tmp_mail_obj);
     if (count($file_names)) {
         $mfile_obj->unlinkFiles($file_names);
         unset($mfile_obj);
     }
     // SET STATUS SENT FOR ALL RECIPIENTS
     foreach ($a_members as $member_id => $value) {
         ilEphAssignment::updateStatusSentForUser($a_ass_id, $member_id, 1);
     }
     return true;
 }