escreva.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. // To be used in development version of backup/restore process.
  3. // Write information about each {iassignment_submission} in directory: /mod/iassign/ilm_debug/output_restore_after_execute_*.txt
  4. //
  5. // @calledby ./mod/iassign/backup/moodle2/restore_iassign_stepslib.php:
  6. // require_once dirname(__FILE__); // /var/www/html/moodle
  7. // require_once(realpath(dirname(__FILE__)); //
  8. // Moodle 4.x : /var/www/html/moodle/mod/iassign
  9. // Moodle 5.0 : /var/www/html/moodle/mod/iassign
  10. // Moodle 5.1 : /var/www/html/moodle/public/mod/iassign
  11. //CAUTION: Since on Moodle 5 iAssing is under /var/www/html/moodle/public/mod, need to use "../../../../config.php"
  12. require_once("../../../config.php"); // Not necessary, since who loads this
  13. // (/mod/iassign/backup/moodle2/restore_iassign_stepslib.php), already has "config.php"!
  14. // Teste paprika3:
  15. // require_once("/var/www/html/saw_limpo/config.php");
  16. //_ echo "CFG->wwwroot=" . $CFG->wwwroot . "<br/>" . "_SERVER['DOCUMENT_ROOT']=" . $_SERVER['DOCUMENT_ROOT'] . "<br/>";
  17. //_ $doc_root = $_SERVER['DOCUMENT_ROOT'];
  18. //_ if ($doc_root=="/var/www/html")
  19. //_ $pathbase = $doc_root . "/" . get_moodle_name($CFG->wwwroot) . "/mod/iassign/ilm_debug/"; // "/var/www/html/...(moodle).../mod/iassign/ilm_debug/";
  20. //_ echo "get_moodle_name=" . get_moodle_name($CFG->wwwroot) . "<br/>" . "pathbase=" . $pathbase . "<br/>";
  21. //_ // CFG->wwwroot=http://localhost/saw_limpo
  22. //_ // _SERVER['DOCUMENT_ROOT']=/var/www/html
  23. //_ // get_moodle_name=saw_limpo
  24. //_ // pathbase=/var/www/html/saw_limpo/mod/iassign/ilm_debug/
  25. //_ exit;
  26. // Givem URL (usually from $CFG->wwwroot) return the Moodle name
  27. function get_moodle_name ($wwwroot) {
  28. // No "http://saw.atp.usp.br" usar a linha abaixo e comentar as demais, senao devolvera: saw.atp.usp.br
  29. // $CFG->wwwroot = 'http://localhost/saw_limpo';
  30. $items = explode("/", $wwwroot);
  31. $num = count($items);
  32. // echo "get_moodle_name(.): num=" . $num . ", items[" . ($num-1) . "]= " . $items[$num-1] . "<br/>";
  33. if ($num==3) { // "saw.atp.usp.br"
  34. $wwwroot = $items[$num-1];
  35. $items = explode(".", $wwwroot);
  36. return $items[0]; // apenas "saw" de "saw.atp.usp.br"
  37. }
  38. if ($num>0) return $items[$num-1];
  39. return $wwwroot;
  40. }
  41. // Write each personal student file in './<turma>/<N>_<name>.txt'
  42. // Param: $filetype1 in "student", "log", "sendemail"
  43. // Return 1 in case of success; -1 in case do not overwrite
  44. function writeContent ($filetype1, $pathbase, $outputFile, $msgToRegister) {
  45. global $CFG, $GROUP, $WRITEMSG, $OVERWRITE;
  46. $doc_root = $_SERVER['DOCUMENT_ROOT']; // Get absolut path only until HTML structure. Usually: /var/www/html
  47. if ($doc_root=="/var/www/html" || $doc_root=="/var/www/html/") {
  48. // Na Paprika3: doc_root=/var/www/html/
  49. $doc_root = "/var/www/html"; // remove last "/" (if is the case)
  50. $moodle_name = get_moodle_name($CFG->wwwroot);
  51. echo "1: get_moodle_name(CFG->wwwroot)=" . $moodle_name . "<br/>\n";
  52. if (!$moodle_name || $moodle_name=="html") $moodle_name = "saw_limpo"; // para Paprika3
  53. $pathbase = $doc_root . "/" . $moodle_name . "/mod/iassign/ilm_debug/"; // "/var/www/html/...(moodle).../mod/iassign/ilm_debug/";
  54. echo "2: pathbase=" . $pathbase . "<br/>\n";
  55. }
  56. else // no 'homologacao.saw.atp.usp.br' ou 'saw.atp.usp.br'
  57. $pathbase = $doc_root . "mod/iassign/ilm_debug/"; // "/var/www/...(moodle).../mod/iassign/ilm_debug/";
  58. $complete_outputFile = $pathbase . $outputFile;
  59. echo "escreva.php: doc_root=_SERVER['DOCUMENT_ROOT']=" . $_SERVER['DOCUMENT_ROOT'] . "<br/> &nbsp; pathbase = " . $pathbase . "<br/>\n"; //paprika3: /var/www/html
  60. //_ // CFG->wwwroot=http://localhost/saw_limpo
  61. //_ // _SERVER['DOCUMENT_ROOT']=/var/www/html
  62. //_ // get_moodle_name=saw_limpo
  63. //_ // pathbase=/var/www/html/saw_limpo/mod/iassign/ilm_debug/
  64. if (!is_writable($pathbase)) { // TRUE se arquivo existe e pode ser escrito
  65. // $file_debug .= "Error: '" . $completfilepath . "' could not be registered! Perhaps the directory or the file has permission problem?<br/>\n";
  66. //D echo "$complete_outputFile, $filetype1<br/>";
  67. print "Erro! Problema de acesso ao servidor! Por favor, avise ao administrador (<tt>" . $pathbase . "</tt> nao acessivel para escrita).<br/>"; // . $file_debug . "
  68. exit(0);
  69. }
  70. // $result = writeContent("file", $pathbase, $filename, $msgToRegister);
  71. // print "escreva.php: result=$result<br/>";
  72. //D echo "escreva.php: writeContent($filetype1, $pathbase, $outputFile, $msgToRegister): complete_outputFile = " . $complete_outputFile . "<br/>";
  73. // write personal email file
  74. // To write: verify if the file does not exists or have permission to overwrite
  75. if (is_file($complete_outputFile)) { // already exist this file
  76. // $complete_outputFile .= $outputFile . '_' . date('Y_m_d_h_m');
  77. } // if (is_file($complete_outputFile))
  78. if (1==1) { // write/overwrite the file
  79. //D echo "escreva.php!writeContent(.): outputFile=" . $outputFile . ", complete_outputFile=" . $complete_outputFile . "<br/>\n";
  80. $fpointer = fopen($complete_outputFile, "a"); // a=append; w=write - if executed, it clear the previou content at this file
  81. if (!$fpointer) {
  82. $file_debug .= "Erro: nao foi possivel abrir o roteiro (" . $complete_outputFile . ")!<br/>\n";
  83. // it was not possible to open the file '$completfilepath" . $file_name . "'!<br/>\n";
  84. print "<br/>" . $file_debug . "<br/>\n";
  85. //D echo "writeContent: $filetype1, outputFile=$complete_outputFile<br/>\n";
  86. return 0;
  87. }
  88. fwrite($fpointer, $msgToRegister . "\n");
  89. // echo " - outputFile=$complete_outputFile : WRITEMSG=$WRITEMSG, OVERWRITE=$OVERWRITE, gerado com sucesso!<br/>\n";
  90. fclose($fpointer);
  91. }
  92. else {
  93. // print "Nao gera os arquivos personalizados para email aos alunos ('$complete_outputFile')<br/>\n"; // admin/<turma>/<N>_<name>.txt
  94. }
  95. return 1;
  96. } // function writeContent($outputFile, $msgToRegister)
  97. /*
  98. $date_aux = date('Y_m_d_H_i_s');
  99. //xxx $msgD = "Inicio: " . $date_aux . "\n";
  100. $msgD = "Inicio: " . $date_aux . "<br/>\n"; //xxx
  101. // echo $msgD . "<br/>\n"; //xxx
  102. $timeWrite = $date_aux; // Year_Month_Day_Hour_Minutes_Seconds
  103. $filenamewrite = "output_restore_after_execute_" . $timeWrite . ".txt";
  104. echo "filenamewrite=" . $filenamewrite . "<br/>";
  105. //DEBUG path:
  106. if (!isset($CFG->wwwroot)) { $CFG = new stdClass(); $CFG->wwwroot = "/var/www/html"; }
  107. $outputFile = "";
  108. $doc_root = $_SERVER['DOCUMENT_ROOT'];
  109. echo "doc_root=" . $doc_root. "<br/>\n";
  110. if ($doc_root=="/var/www/html" || $doc_root=="/var/www/html/") {
  111. // Na Paprika3: doc_root=/var/www/html/
  112. $doc_root = "/var/www/html"; // remove last "/" (if is the case)
  113. $moodle_name = get_moodle_name($CFG->wwwroot);
  114. echo "1: get_moodle_name(CFG->wwwroot)=" . $moodle_name . "<br/>\n";
  115. if (!$moodle_name || $moodle_name=="html") $moodle_name = "saw_limpo"; // para Paprika3
  116. $pathbase = $doc_root . "/" . $moodle_name . "/mod/iassign/ilm_debug/"; // "/var/www/html/...(moodle).../mod/iassign/ilm_debug/";
  117. echo "2: pathbase=" . $pathbase . "<br/>\n";
  118. }
  119. else { // no 'homologacao.saw.atp.usp.br' ou 'saw.atp.usp.br'
  120. $pathbase = $doc_root . "mod/iassign/ilm_debug/"; // "/var/www/...(moodle).../mod/iassign/ilm_debug/";
  121. echo "3: pathbase=" . $pathbase . "<br/>\n";
  122. }
  123. echo "pathbase=" . $pathbase . "<br/>\n";
  124. $complete_outputFile = $pathbase . $outputFile;
  125. echo "complete_outputFile=" . $complete_outputFile . "<br/>\n";
  126. echo "escreva.php: doc_root=_SERVER['DOCUMENT_ROOT']=" . $_SERVER['DOCUMENT_ROOT'] . "<br/> &nbsp; pathbase = " . $pathbase . "<br/>\n"; //paprika3: /var/www/html
  127. $resp = writeContent("", "", $filenamewrite, $msgD);
  128. // $resp2 = writeContent("", "", $filenamewrite, "Segunda escrita!\n" . $msgD);
  129. echo "Final " . $resp . "<br/>\n";
  130. // echo "Final " . $resp2 . "<br/>\n";
  131. */
  132. ?>