123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php
- require_once("../../config.php");
- global $DB;
- $DEBUG = 0;
- class ilm_security {
-
-
- static function warning_message_iassign ($strcode) {
- return "<div classs='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
- }
-
- static function remove_records ($userid) {
- if (!isset($userid) || !isset($iassign_statementid)) {
-
- print self::warning_message_iassign('error_security_no_userid');
- return null;
- }
- if (!isset($iassign_statementid) || $iassign_statementid<1)
- $array_param = array("userid" => $userid);
- else
- $array_param = array("userid" => $userid, "iassign_statementid" => $iassign_statementid);
- $DB->delete_records("iassign_security", $array_param);
- }
-
- static function remove_old_iLM_security_entries ($userid) {
- global $DB;
-
- $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND view>1", null);
- }
-
-
-
-
-
-
-
-
- static function write_iLM_security ($userid, $timecreated, $iassign_statementid = -1, $content_or_id_from_ilm_security) {
- global $DB;
- $newentry = new stdClass();
- $newentry->iassign_statementid = $iassign_statementid;
- $newentry->userid = $userid;
- $newentry->file = $content_or_id_from_ilm_security;
- $newentry->timecreated = $timecreated;
- $newentry->view = 1;
- $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
- if (!$id_iLM_security) {
- print_error('error_security', 'iassign');
- }
-
-
-
-
-
- return $id_iLM_security;
- }
-
-
-
- }
- $view = optional_param('view', NULL, PARAM_TEXT);
- $token = optional_param('token', NULL, PARAM_TEXT);
- $id = optional_param('id', NULL, PARAM_TEXT);
- $stringDebugAux = "";
- $strFileContent = "";
- if ($DEBUG) {
- $file_name = "ilm_debug/" . date('Y') . "_" . date('m') . "_" . date('d') . "_" . date('H_i') . "_" . $id;
- $file_debug = "id=" . $id . "<br/>\nview=" . $view . "<br/>\ntoken=" . $token;
- $stringDebugAux = "user.id=" . $USER->id . ", user.name=" . $USER->firstname . " " . $USER->lastname . "\n";
- }
- if ($view == -1) {
-
- $fs = get_file_storage();
- $file = $fs->get_file_by_id($id);
- $strFileContent .= $file->get_content();
- $stringDebugAux .= "1: file content:" . $strFileContent;
- print $strFileContent;
- ilm_security::remove_old_iLM_security_entries($USER->id);
- }
- else {
-
- $iassign_security = $DB->get_record("iassign_security", array("id" => $id));
-
- if ($DEBUG) {
- $strAux = "iassign_security = { id=" . $iassign_security->id . ", " . $iassign_security->iassign_statementid . ", | " . $iassign_security->file . " |, " . $iassign_security->view . " }";
- $stringDebugAux .= $strAux;
- }
- if ($iassign_security) {
- $fileid = $iassign_security->file;
- if ($iassign_security) {
- $update = new stdClass();
- $update->id = $iassign_security->id;
- $update->view = $iassign_security->view + 1;
- $DB->update_record("iassign_security", $update);
- if ($DEBUG) $stringDebugAux .= " view++ = " . $iassign_security->view . "\n";
- if ($update->view >= 2 && $token == md5($iassign_security->timecreated)) {
-
-
- if ($view) {
-
-
-
- $fs = get_file_storage();
- $file = $fs->get_file_by_id($fileid);
- $strFileContent = $file->get_content();
- $stringDebugAuxFile = $file->get_filename() . "/";
- if ($DEBUG) {
- $stringDebugAux .= "view>=2: view=$view: update->view=" . $update->view . "\n" . $token . "=" . md5($iassign_security->timecreated) . "?\n";
- }
- }
- else {
-
-
-
- $strFileContent = $iassign_security->file;
-
- if ($DEBUG) {
- $stringDebugAux .= "view>=2: else view=$view: update->view=" . $update->view . "\n" . $token . "=" . md5($iassign_security->timecreated) . "?\n";
- $stringDebugAux .= " " . $iassign_security->id . ", " . $iassign_security->timecreated . "\n";
- }
- }
-
-
- print $strFileContent;
- ilm_security::remove_old_iLM_security_entries($USER->id);
- }
- else {
- if ($DEBUG) {
- $countF = 0;
- foreach ($files as $thefile) {
- $strFileName = $thefile->get_filename();
- $stringDebugAux .= " " . ($countF++) . ": " . $strFileName . "\n";
- $stringDebugAuxFile = $strFileName . "/";
- if ($strFileName != '.') {
- $strFileContent = $thefile->get_content();
- }
- }
- $stringDebugAux .= "view<=2: NOT update->view=" . $update->view . "\n" . $token . "=" . md5($iassign_security->timecreated) . "?\nstrFileContent=" . $strFileContent . "\n";
- }
- }
- }
- }
- }
- if ($DEBUG) {
-
- $fpointer = fopen($file_name, "w");
- $file_debug .= "\nAuxiliary information: " . $stringDebugAux . "";
- $file_debug .= "\nContent iLM file: |" . $strFileContent . "|";
- fwrite($fpointer, "From: ./mod/iassign/ilm_security.php<br/>\n" . $file_debug);
- fclose($fpointer);
- }
|