123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068 |
- <?php
- defined('MOODLE_INTERNAL') || die();
- $SEP = ";";
- function get_iassign_id ($DB) {
-
-
- $str_query = "SELECT id, name, visible FROM {modules} WHERE upper(name) = 'IASSIGN'";
-
- $iassign_module = $DB->get_records_sql($str_query);
-
- if (!$iassign_module) return -1;
- foreach ($iassign_module as $ia) {
-
- return $ia->id;
- }
- return -1;
- }
- function get_user ($DB, $name1, $name2) {
- $str_query = "SELECT id, firstname, lastname FROM {user} WHERE firstname='" . $name1 . "' AND lastname='" . $name2 . "'";
- $tmp_list_all_files = $DB->get_records_sql($str_query);
- $num = count($tmp_list_all_files);
-
- if ($num==0) return -1;
- $ii = 0;
- foreach ($tmp_list_all_files as $elem) {
- echo " - id=" . $elem->id . "; firstname=" . $elem->firstname . "; lastname=" . $elem->lastname . "<br/>";
- $ii++;
- }
- echo "Total: " . $ii . "<br/>";
- }
- function print_vector ($vec) {
- $SEP = ";";
- if (!is_array($vec)) print $vec . "<br/>";
- $sizeOfVector = count($vec);
- if ($sizeOfVector==0) print "[]<br/>";
- else {
- for ($ii=0; $ii<$sizeOfVector; $ii++) print $vec[$ii] . $SEP . " ";
-
- }
- }
- function get_name ($name) {
- $items = explode(" ", $name);
- $name1 = $items[0].trim();
- $name2 = $items[1].trim();
- return [$name1, $name2];
- }
- function binary_search ($vec_elements, $x_element) {
- $sizeOfVector = count($vec_elements);
- $leftI = 0; $rightI = $sizeOfVector-1;
- while ($leftI <= $rightI) {
- $middle = floor(($leftI + $rightI)/2);
- $elem_file = $vec_elements[$middle];
-
- if ($elem_file < $x_element) { $leftI = $middle + 1; }
- else
- if ($elem_file > $x_element) { $rightI = $middle - 1; }
- else { return $middle; }
- }
- return [-1, $leftI, $rightI];
- }
- function insert_ordered_name (&$vec_elements, $name, $i) {
- $sizeOfVector = count($vec_elements);
-
- $j = $sizeOfVector;
- while ($j > $i) {
- $vec_elements[$j] = $vec_elements[$j-1];
- $j--;
- }
- $vec_elements[$i] = $name;
- }
- function get_all_iassign_statement ($DB) {
- $str_query = "SELECT * FROM {iassign_statement}";
- $tmp_list_all_iassign_statement = $DB->get_records_sql($str_query);
- $num_is = count($tmp_list_all_iassign_statement);
- print "#tmp_list_all_iassign_statement = " . $num_is . "<br/>\n";
-
- $vec_all_names_ord = array();
- $count1 = 0;
- foreach ($tmp_list_all_iassign_statement as $ias) {
- [$name1, $name2] = get_name($ias->author_name);
-
- if ($count1>=5) break;
- $name = $name1 . " " . $name2;
- $answer = binary_search($vec_all_names_ord, $name);
- if (count($answer)>1) {
- $ind = $answer[0];
- }
- else {
- $ind = $answer;
- }
- if ($ind == -1) {
- $userid = get_user($DB, $name1, $name2);
- insert_ordered_name($vec_all_names_ord, $name, $answer[1]);
- $count1++;
- }
-
- }
- $total = count($vec_all_names_ord);
- print "Total: " . $total . "<br/> Vector: "; print_vector($vec_all_names_ord); print "<br/>";
- }
- function get_all_files ($DB, $list_iassign) {
- global $USER, $SEP;
- $sizeAC = count($list_iassign);
-
-
-
-
-
- $str_query = "SELECT * FROM {files} WHERE component='mod_iassign'";
- $tmp_list_all_files = $DB->get_records_sql($str_query);
-
- $numf = count($tmp_list_all_files);
-
- $list_all_files = array();
- $ii = 0;
- foreach ($tmp_list_all_files as $elem) {
-
-
- $elem->ias_id = -1;
- $elem->courseid = -1;
- $elem->missing_ias = TRUE;
- $list_all_files[$ii] = $elem;
- $ii++;
- }
-
-
-
-
-
- $sizeof_list_all_files = $ii;
- return $list_all_files;
- }
- function search_files (&$list_all_files, $element_ias) {
- $sizeOfFiles = count($list_all_files);
- $sizeC = count($element_ias->contextid);
-
- for ($ii=0; $ii<$sizeOfFiles; $ii++) {
-
- $element_file = $list_all_files[$ii];
- for ($jj=0; $jj<$sizeC; $jj++) {
- $contextid = $element_ias->contextid[$jj];
- if ($contextid == $element_file->contextid) {
- if ($element_ias->file == $element_file->itemid) {
-
-
- $element_file->ias_id = $element_ias->id;
- $element_file->missing_ias = FALSE;
- return [$ii, $jj];
- }
- else
- if ($element_ias->filesid == $element_file->itemid) {
-
-
- $element_file->ias_id = $element_ias->id;
- $element_file->missing_ias = FALSE;
- return [$ii, $jj];
- }
- else
- if ($element_ias->id == $element_file->itemid) {
-
-
-
-
- $element_file->ias_id = $element_ias->id;
- $element_file->missing_ias = FALSE;
- return [$ii, $jj];
- }
- }
- }
- }
-
- return -1;
- }
- function get_iassignstatement_or_files ($DB, $table, $element_id) {
-
- if ($table != 'iassign_statement' && $table != 'files') return NULL;
- $ia_obj = $DB->get_record($table, array('id' => $element_id));
-
- return $ia_obj;
-
- }
- function update_iassignstatement_files ($DB, $ia_id, $filesid, $is_obj, $f1_obj, $f2_obj) {
-
-
- $ma = "{iassign_statement}.filesid=" . $is_obj->filesid;
- $mf1 = "{files}: id=" . $f1_obj->id . ": itemid=" . $f1_obj->itemid;
- $mf2 = "{files}: id=" . $f2_obj->id . ": itemid=" . $f2_obj->itemid;
- $is_obj->filesid = $filesid;
- $f1_obj->itemid = $ia_id;
- $f2_obj->itemid = $ia_id;
- $ma .= " -> " . $is_obj->filesid;
- $mf1 .= " -> " . $f1_obj->itemid;
- $mf2 .= " -> " . $f2_obj->itemid;
- $error = FALSE;
- if (!$DB->update_record('iassign_statement', $is_obj)) $error = TRUE;
- if (!$DB->update_record('files', $f1_obj)) $error = TRUE;
- if (!$DB->update_record('files', $f2_obj)) $error = TRUE;
- if (!$error) {
- echo " * " . $ma . " / " . $mf1 . " / " . $mf2 . "<br/>\n";
- return TRUE;
- }
- echo " x " . $ma . " / " . $mf1 . " / " . $mf2 . " --- ERROR!<br/>\n";
- return FALSE;
-
- }
- function search_lost_files_in_context ($type, $ii, $courseid, $ias_id, &$list_all_files, $array_contextid, $countErr) {
- $sizeOfFiles = count($list_all_files);
- $sizeC = count($array_contextid);
- $files_index_candidates = array();
- $files_filename_candidates = array();
- $contextid_candidates = array();
- $list_candidate_files = array();
- $msg = "ERRO: <select name='selected_filesid[" . $countErr . "]'>\n <option value=''>select one file</option>\n";
- $msgHidden = "";
- for ($jj=0; $jj<$sizeOfFiles; $jj++) {
- $sizeC = count($array_contextid);
- $hascandidate = 0;
- for ($kk=0; $kk<$sizeC; $kk++) {
- $contextid = $array_contextid[$kk];
- if ($list_all_files[$jj]->contextid==$contextid && $list_all_files[$jj]->ias_id==-1) {
- $hascandidate = 1;
- if ($type == 2)
- $list_all_files[$jj]->ias_id = $ias_id;
- $list_all_files[$jj]->courseid = $courseid;
- break;
- }
- }
- if ($hascandidate == 1) {
- $files_index_candidates[] = $jj;
- $files_filename_candidates[] = $list_all_files[$jj]->filename;
- $contextid_candidates[] = $contextid;
- $fileid = $list_all_files[$jj]->id;
- $list_candidate_files[$fileid] = $jj;
- if ($list_all_files[$jj]->filename != ".") {
- $msg .= " <option value='" . $fileid . "'>" . $fileid . " - " . $list_all_files[$jj]->filename . " ii=" . $list_candidate_files[$fileid] . "</option>\n";
- $msgHidden .= " <input value='" . $list_all_files[$jj]->filename . "' name='list_filesname[" . $ii . "][]' type='hidden' />\n";
- $msgHidden .= " <input value='" . $list_all_files[$jj]->id . "' name='list_filesid[" . $ii . "][]' type='hidden' />\n";
- $msgHidden .= " <input value='" . $contextid . "' name='list_contextid[" . $ii . "][]' type='hidden' title='#array_contextid=" . count($array_contextid) . "'/>\n";
- $msgHidden .= " <input value='" . $ias_id . "' name='list_iassign_statement_id[" . $ii . "][]' type='hidden' />\n";
- }
- }
- }
- $msg .= "</select><table>\n";
- $sizeCandidates = sizeof($files_index_candidates);
- for ($jj=0; $jj<$sizeCandidates; $jj++) {
- if ($files_filename_candidates[$jj] == ".") continue;
- $kk = $files_index_candidates[$jj];
- $contextid = $contextid_candidates[$jj];
- $fileid = $list_all_files[$kk]->id;
- $msg .= " <tr><td title='coourse.id'>" . $list_all_files[$kk]->courseid . "</td>";
- $msg .= " <td title='context.id'>" . $contextid . "</td>";
- $msg .= " <td title='files.id'>" . $list_all_files[$kk]->id . "</td>";
- $msg .= " <td title='files.name'>" .
- $list_all_files[$kk]->filename . "</td><td title='files.timecreated=" . date("d/m/Y H:i:s", $list_all_files[$kk]->timecreated) . "'>" .
- $list_all_files[$kk]->timecreated . "</td><td title='files.author'>" . $list_all_files[$kk]->author . "</td></tr>\n";
- }
- $msg .= "</table>\n";
- return [$msg, $msgHidden, $files_index_candidates, $contextid_candidates, $list_candidate_files];
- }
- function find_course_context ($list_iassign, $iassignid) {
- $sizeI = count($list_iassign);
- for ($ii=0; $ii<$sizeI; $ii++)
- if ($list_iassign[$ii]->ia_id == $iassignid)
- return [$list_iassign[$ii]->id, $list_iassign[$ii]->course];
- print "*** ERRROR: coudn't find {iassign}.id = " . $iassignid . "<br/>\n";
- return [-1, -1];
- }
- function list_all_iass_files ($DB, $modules_iassignid) {
- global $SEP;
-
-
-
-
-
-
-
-
-
-
-
- $str_query = "SELECT {context}.id, {course_modules}.id AS cmid, {iassign}.id AS ia_id, {iassign}.course, {iassign}.name FROM {iassign}, {context}, {course_modules} WHERE " .
- "{course_modules}.module=" . $modules_iassignid . " AND {iassign}.course={course_modules}.course AND {course_modules}.id={context}.instanceid AND {course_modules}.instance={iassign}.id";
- $tmp_list_iassign = $DB->get_records_sql($str_query);
-
-
-
-
- $list_iassign = array();
- $ii = 0;
- foreach ($tmp_list_iassign as $element) {
- if ($ii==0 || $list_iassign[$ii-1]->ia_id != $element->ia_id) {
- $item = array();
- $item[] = $element->id;
- $element->id = $item;
- $list_iassign[$ii] = $element;
- $ii++;
- }
- else {
- $list_iassign[$ii-1]->id[] = $element->id;
- }
- }
- $sizeOf_list_iassign = $ii;
-
-
-
-
- $str_query = "SELECT {iassign_statement}.id, {iassign_statement}.name, {iassign_statement}.iassignid, {iassign_statement}.author_name, {iassign_statement}.iassign_ilmid, " .
- " {iassign_statement}.file, {iassign_statement}.filesid, {iassign_statement}.timecreated, {iassign}.course AS courseid, {iassign}.name AS ias_name " .
- " FROM {iassign}, {iassign_statement} WHERE {iassign_statement}.iassignid = {iassign}.id ORDER BY {iassign}.course, {iassign_statement}.iassignid, {iassign_statement}.id";
-
- $list_ias = array();
- $tmp_list_ias = $DB->get_records_sql($str_query);
- $jj = 0;
- foreach ($tmp_list_ias as $element) {
- $answer = find_course_context($list_iassign, $element->iassignid);
- $element->contextid = $answer[0];
- if ($element->courseid != $answer[1]) echo " x Error: (" . $jj . ", id=" . $element->id . ") courseid=" . $element->courseid . "!=" . $answer[1] . "<br/>\n";
- $list_ias[$jj] = $element;
- $jj++;
- }
- $sizeOf_list_ias = $jj;
-
-
-
-
-
-
-
-
-
-
- $list_all_files = get_all_files($DB, $list_iassign);
-
-
- $countErr = 0;
- $countIA = 0;
- for ($jj=0; $jj<$sizeOf_list_ias; $jj++) {
- $element = $list_ias[$jj];
- $answerSF = search_files($list_all_files, $element);
- if ($answerSF == -1) {
- $element->missingfile = TRUE;
-
-
- [$msgCandidates, $msgHidden, $files_index_candidates, $contextid_candidates, $list_candidate_filesbyID] = search_lost_files_in_context(2, $countErr, $element->courseid, $element->id, $list_all_files, $element->contextid, $countErr);
- if (count($files_index_candidates)==0) $msgCandidates = "";
- else $msgCandidates = "<br/>" . $msgCandidates;
-
-
-
- $countErr++;
- }
- else {
- $countIA++;
- $element->missingfile = FALSE;
- }
- }
- print "<style> .error { background-color: #f4d6d2; color: #ca3120; }</style>\n";
- $msgErr = " class='error' ";
- $msgTErr = "";
- print "List of all {iassign_statement} with no {files} associated<br/>\n";
- print "<table id='outlinetable' class='generaltable boxaligncenter' width='100%'>\n";
- print "<tr><td title='count'>count</td><td>course.id</td><td title='iAssign id'>iassign.id</td><td>iAssign statement id</td><td title='iLM id'>iLM id</td><td title='context.id'>contextid</td>" .
- " <td title='iassign_statement.file'>file</td><td title='iassign_statement.filesid'>filesid</td><td title='date(timecreated)'>timecreated</td><td title='author'>Author</td>" .
- " <td title='{iassign}.name'>ia.name</td> <td title='{iassign_statement}.name'>ias.name</td></tr>\n";
- $countMIAS = 0;
- for ($jj=0; $jj<$sizeOf_list_ias; $jj++) {
- $element = $list_ias[$jj];
- if ($element->missingfile) {
- $msgC = "["; $sizeC = count($element->contextid); for ($kk=0; $kk<$sizeC; $kk++) $msgC .= $element->contextid[$kk] . $SEP; $msgC .= "]";
- print "<tr " . $msgTErr . "><td>" . $countMIAS . "</td><td title='course.id'>" . $element->courseid . "</td><td title='iassign.id=iassign_statement.iassignid'>" . $element->iassignid . "</td>" .
- " <td title='iassign_statement.id'>" . $element->id . "</td><td title='iassign_statement.iassign_ilmid'>" . $element->iassign_ilmid . "</td>\n" .
- " <td title='not found file possible array of context.id'>" . $msgC . "</td><td title='iassign_statement.file'>" . $element->file . "</td>\n" .
- " <td title='iassign_statement.filesid'>" . $element->filesid . "</td><td>" .
- date("d/m/Y H:i:s", $element->timecreated) . "</td><td>" . $element->author_name . "</td>" .
- " <td title='{iassign}.name'>" . $element->ias_name . "</td> <td title='{iassign_statement}.name'>" . $element->name . "</td></tr>\n";
- $countMIAS++;
- }
- }
- print "</table><br/><br/>----------------------------<br/><br/>\n";
- print "List of all {files} with no {iassign_statement} associated<br/>\n";
- print "<table id='outlinetable' class='generaltable boxaligncenter' width='100%'>\n";
- print "<tr><td title='count'>count</td> <td>course.id</td> <td title='{files}.ias_id=iAssign id'>iassign.id</td> <td title='context.id'>contextid</td>" .
- " <td title='files.id'>id</td> <td title='{files}.itemid'>itemid</td> <td title='date(timecreated)'>date(timecreated)</td>" .
- " <td title='author'>author</td> <td title='{file}.filename'>filename</td></tr>\n";
- $countErrF = 0;
- $sizeOf_files = count($list_all_files);
- for ($jj=0; $jj<$sizeOf_files; $jj++) {
- $element = $list_all_files[$jj];
- if ($element->missing_ias) {
- print "<tr " . $msgTErr . "><td>" . $countErrF . "</td><td title='course.id'>" . $element->courseid . "</td> <td title='iassign.id=iassign_statement.iassignid'>" . $element->ias_id . "</td>" .
- " <td title='context.id''>" . $element->contextid . "</td> <td title='files.id'>" . $element->id . "</td> " .
- " <td title='{files}.itemid'>" . $element->itemid . "</td> <td title='date(timecreated)'>" . date("d/m/Y H:i:s", $element->timecreated) . "</td>" .
- " <td title='author'>" . $element->author . "</td> <td title='{file}.filename'>" . $element->filename . "</td></tr>\n";
- $countErrF++;
- }
- }
- print "</table>\n";
- print "Total of {iassign_statement}: " . $countIA . "<br/>\n";
- print "Total of {iassign_statement} without any {files}: " . $countErr . "<br/>\n";
- print "Total of {files} without any {iassign_statement}: " . $countErrF . "<br/>\n";
- return $list_iassign;
- }
- function see_all_iass_files ($DB, $modules_iassignid) {
- global $SEP;
-
-
-
-
-
-
-
-
-
-
-
-
- print "---<br/>Get {iassign} :: list_iassign[] = { id (context.id) ; cmid ; ia_id (iassign.id) ; course (course.id) ; name ({iassign}.name) }<br/>\n";
-
-
- $str_query = "SELECT {context}.id, {course_modules}.id AS cmid, {iassign}.id AS ia_id, {iassign}.course, {iassign}.name FROM {iassign}, {context}, {course_modules} WHERE " .
- "{course_modules}.module=" . $modules_iassignid . " AND {iassign}.course={course_modules}.course AND {course_modules}.id={context}.instanceid AND {course_modules}.instance={iassign}.id";
-
-
- $tmp_list_iassign = $DB->get_records_sql($str_query);
- print " - #tmp_list_iassign=" . count($tmp_list_iassign). "<br/>";
-
-
-
-
- $list_iassign = array();
- $ii = 0;
- foreach ($tmp_list_iassign as $element) {
- if ($ii==0 || $list_iassign[$ii-1]->ia_id != $element->ia_id) {
-
- $item = array();
- $item[] = $element->id;
- $element->id = $item;
- $list_iassign[$ii] = $element;
- $ii++;
- }
- else {
-
-
-
- $list_iassign[$ii-1]->id[] = $element->id;
-
- }
- }
- $sizeOf_list_iassign = $ii;
- print " - #list_iassign=" . $sizeOf_list_iassign . "<br/>";
-
-
-
-
-
-
-
-
-
-
-
-
-
- print "---<br/>Get {iassign_statement} :: list_ias[] = { courseid (iassign.course) ; id (iassign_statement.id) ; name ; iassignid ; author_name ; iassign_ilmid ; file ; filesid ; timecreated ; array of context.id }<br/>\n";
-
-
-
- $str_query = "SELECT {iassign_statement}.id, {iassign_statement}.name, {iassign_statement}.iassignid, {iassign_statement}.author_name, {iassign_statement}.iassign_ilmid, " .
- " {iassign_statement}.file, {iassign_statement}.filesid, {iassign_statement}.timecreated, " .
- " {iassign}.course AS courseid FROM {iassign}, {iassign_statement} WHERE {iassign_statement}.iassignid = {iassign}.id ORDER BY {iassign}.course, {iassign_statement}.iassignid, {iassign_statement}.id";
-
-
-
-
-
-
- $list_ias = array();
- $tmp_list_ias = $DB->get_records_sql($str_query);
- $jj = 0;
- foreach ($tmp_list_ias as $element) {
- $answer = find_course_context($list_iassign, $element->iassignid);
- $element->contextid = $answer[0];
-
- if ($element->courseid != $answer[1]) echo " x Error: (" . $jj . ", id=" . $element->id . ") courseid=" . $element->courseid . "!=" . $answer[1] . "<br/>\n";
- $list_ias[$jj] = $element;
- $jj++;
- }
- $sizeOf_list_ias = $jj;
-
-
-
-
-
-
-
-
- print " - #list_ias=" . $sizeOf_list_ias . "<br/>";
-
-
-
-
- print "---<br/>Get {files} :: list_all_files[] = { id ; contenthash ; contextid ; component ; filearea ; itemid ; filepath ; filename ; userid ; author ; timecreated ; ias.id }<br/>\n";
-
-
-
-
- $list_all_files = get_all_files($DB, $list_iassign);
- echo " - #list_files=" . count($list_all_files) . "<br/>\n";
- print "<style> .error { background-color: #f4d6d2; color: #ca3120; }</style>\n";
- $msgErr = " class='error' ";
- $msgTErr = "";
- print "<form action='settings_process_files_form.php' method='post' class='form-example'>\n";
- print "<button type='submit' class='button action has-icon search-button'>Enviar</button>\n";
- print "<input type='hidden' name='ilm_id' value='" . $modules_iassignid . "'>\n";
- print "<table id='outlinetable' class='generaltable boxaligncenter' width='100%'>\n";
- print "<tr><td title='count'>count</td><td>course.id</td><td title='iAssign id'>iassign.id</td><td>iAssign statement id</td><td title='iLM id'>iLM id</td><td title='context.id'>contextid</td>" .
- "<td title='iassign_statement.file'>file</td><td title='iassign_statement.filesid'>filesid</td><td title='date(timecreated)'>timecreated</td><td title='author'>Author</td><td title='name'>ias.name</td>" .
- "<td title='{file}.filename'>{files}.filename</td><td title='{file}.id'>id</td><td title='{files}.itemid'>itemid</td></tr>\n";
-
-
- $err_iassignid = array();
- $err_iassignstatementid = array();
- $err_selectedfilesid = array();
- $countErr = 0;
- $countIA = 0;
- for ($jj=0; $jj<$sizeOf_list_ias; $jj++) {
-
- $element = $list_ias[$jj];
- $answerSF = search_files($list_all_files, $element);
- if ($answerSF == -1) {
-
-
- [$msgCandidates, $msgHidden, $files_index_candidates, $contextid_candidates, $list_candidate_filesbyID] = search_lost_files_in_context(1, $countErr, $element->courseid, $element->id, $list_all_files, $element->contextid, $countErr);
- if (count($files_index_candidates)==0) $msgCandidates = "";
- else $msgCandidates = "<br/>" . $msgCandidates;
-
- $msgC = "["; $sizeC = count($element->contextid); for ($kk=0; $kk<$sizeC; $kk++) $msgC .= $element->contextid[$kk] . $SEP; $msgC .= "]";
- print $msgHidden;
- print "<tr " . $msgTErr . "><td>" . $countErr . "</td><td title='course.id'>" . $element->courseid . "</td><td title='iassign.id=iassign_statement.iassignid'>" . $element->iassignid . "</td>" .
- " <td title='iassign_statement.id'>" . $element->id . "</td><td title='iassign_statement.iassign_ilmid'>" . $element->iassign_ilmid . "</td>\n" .
- " <td title='not found file possible array of context.id'>" . $msgC . "</td><td title='iassign_statement.file'>" . $element->file . "</td>\n" .
- " <td title='iassign_statement.filesid'>" . $element->filesid . "</td><td>" .
- date("d/m/Y H:i:s", $element->timecreated) . "</td><td>" .
- $element->author_name . "</td> <td>" . $element->name . "</td><td colspan='3' " . $msgErr . ">\n" . $msgCandidates . "</td></tr>\n";
- $err_iassignid[] = $element->iassignid;
- $err_iassignstatementid[] = $element->id;
- $err_selectedfilesid[] = countErr;
- $countErr++;
- }
- else {
- $countIA++;
- }
- }
- print "</table>\n";
- print "</form>\n";
- print "Total of {iassign_statement}: " . $countIA . "<br>";
- print "Total of {iassign_statement} without any {files}: " . $countErr . "<br>";
- return $list_iassign;
- }
- function createNewEntry ($iassign_statement, $element_file) {
- $new_file = new stdClass();
- $new_file->ia_id = $iassign_statement->id;
- $new_file->ia_name = $iassign_statement->name;
- $new_file->ia_file = $iassign_statement->file;
- $new_file->ia_filesid = $iassign_statement->filesid;
- if ($element_file != NULL) {
- $new_file->filesid = $element_file->id;
- $new_file->filename = $element_file->filename;
- $new_file->itemid = $element_file->itemid;
- $new_file->contextid = $element_file->contextid;
- }
- else {
- $new_file->filesid = NULL;
- $new_file->filename = NULL;
- $new_file->itemid = NULL;
- $new_file->contextid = NULL;
- }
- return $new_file;
- }
- function get_associated_files ($DB, $iassign_statement, $all_context, &$all_context_final, $ii) {
- global $USER;
- $array_context_element = $all_context[$ii];
- $sizeAC = count($array_context_element);
- if (!is_array($array_context_element)) {
- $array_context_elements = array();
- $array_context_elements[] = $all_context[$ii];
- }
- else
- $array_context_elements = $all_context[$ii];
- $sizeAC = count($array_context_elements);
-
- $countF = 0;
- $jj = 0;
- while ($jj<$sizeAC) {
- $context_element = $array_context_elements[$jj];
- $contextid = $context_element->contextid;
- $files = $DB->get_records('files', array('contextid' => $contextid, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_statement->id));
- $numf = count($files); $countF += $numf; $msgO = "iassign_statement.id";
-
- $files = $DB->get_records('files', array('contextid' => $contextid, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_statement->id));
- $numf = count($files); $countF += $numf; $msgO = "iassign_statement.id";
- if ($numf == 0) {
- if (isset($iassign_statement->file))
- $files = $DB->get_records('files', array('contextid' => $contextid, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_statement->file));
- $numf = count($files); $countF += $numf; $msgO = "iassign_statement.file";
- if ($numf == 0) {
- if (isset($iassign_statement->filesid))
- $files = $DB->get_records('files', array('contextid' => $contextid, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_statement->filesid));
- $numf = count($files); $countF += $numf; $msgO = "iassign_statement.filesid";
- if ($numf == 0) {
- if (isset($iassign_statement->filesid))
- $files = $DB->get_records('files', array('id' => $iassign_statement->filesid));
- $numf = count($files); $countF += $numf; $msgO = "files.id=iassign_statement.filesid";
-
-
-
-
-
- if ($numf == 0) {
-
- }
- }
- }
- }
- if ($numf>0) { $msgF = ""; foreach ($files as $element_file) $msgF .= "id=" . $element_file->id . ", filename='" . $element_file->filename . "'; ";
- $all_context_final[$ii] = $context_element;
- return [ $files, $contextid, $numf, $msg0 ];
- }
- $jj++;
- }
- $all_context_final[$ii] = $context_element;
- return [ null, -1, 0, $msg0 ];
- }
- function get_files ($course_id, $DB) {
-
-
- if (isset($course_id) && $course_id)
- $answer_list_iassign = $DB->get_records('iassign', array('course' => $course_id));
- else
- $answer_list_iassign = $DB->get_records('iassign');
-
-
-
-
- $list_all_instances_of_iassign = array();
- $all_context_final = array();
- $all_context = array();
- $ii = 0;
- foreach ($answer_list_iassign as $iassign) {
- $list_all_instances_of_iassign[] = $iassign;
-
-
-
-
-
- $str_query = "SELECT {context}.id AS contextid, {course}.id, {course}.fullname, {course}.shortname, {course_modules}.id AS course_module_id, {context}.instanceid " .
- " FROM {course}, {context}, {course_modules} WHERE " .
- " {course}.id={course_modules}.course AND {course_modules}.id={context}.instanceid AND {course_modules}.instance=" . $iassign->id;
-
-
- $answer_list = $DB->get_records_sql($str_query);
-
-
- $list1 = array();
- $strAux = "";
- foreach ($answer_list as $item) {
- $list1[] = $item;
-
-
-
-
- }
- $all_context[$ii] = $list1;
-
- $ii++;
- }
-
-
-
-
- $list_of_ia_files = array();
- $sizeofList = $ii;
- for ($ii=0; $ii<$sizeofList; $ii++) {
- $iassign = $list_all_instances_of_iassign[$ii];
- $list_all_iassign_statement = $DB->get_records('iassign_statement', array('iassignid' => $iassign->id));
- $list_of_files = array();
-
- foreach ($list_all_iassign_statement as $iassign_statement) {
-
-
- [$files, $contextid, $numf, $msg0 ] = get_associated_files($DB, $iassign_statement, $all_context, $all_context_final, $ii);
-
- if ($numf > 0) {
-
- $filename = array();
- foreach ($files as $element_file) {
-
- $new_file = createNewEntry($iassign_statement, $element_file);
- if ($element_file->filename != '.') {
- $filename = explode(".", $element_file->filename);
- if ($iassign_statement->filesid != $element_file->id) {
-
- $iassign_statement->filesid = $element_file->id;
- }
- }
- if ($element_file->itemid != $iassign_statement->id) {
- $newentry_be_updated = new stdClass();
- $newentry_be_updated->id = $element_file->id; $newentry_be_updated->itemid = $iassign_statement->id;
- }
- if (isset($new_file->ia_id) && $new_file->ia_id>0) {
- $list_of_files[] = $new_file;
- }
- }
- $list_of_ia_files[$ii] = $list_of_files;
- $extension = "";
- if (count($filename) > 1) $extension = strtolower($filename[count($filename) - 1]);
- foreach ($list_all_iassign_ilm as $iassign_ilm) {
- $extensions_of_ilm = explode(",", $iassign_ilm->extension);
- if (in_array($extension, $extensions_of_ilm)) {
- $iassign_statement->iassign_ilmid = $iassign_ilm->id;
-
- }
- }
- }
- else {
-
- $list_of_files[] = createNewEntry($iassign_statement, NULL);
- $list_of_ia_files[$ii] = $list_of_files;
- }
- }
- }
- return [$list_all_instances_of_iassign, $all_context_final, $list_of_ia_files];
- }
- function see_all_files_context ($course_id, $DB) {
-
-
- $context_id = 1;
- echo "files_functions.php: context.id=" . $context_id . "<br/>\n";
- $countF = 0;
-
- $list_all_iassign_ilm = $DB->get_records('iassign_ilm', array('parent' => 0, 'enable' => 1));
-
- $answer_list_iassign = $DB->get_records('iassign', array('course' => $course_id));
-
- $list_all_instances_of_iassign = array();
- $all_context = array();
- $ii = 0;
- foreach ($answer_list_iassign as $iassign) {
- $list_all_instances_of_iassign[] = $iassign;
- $str_query = "SELECT {course}.id, {course}.shortname, {context}.id AS contextid FROM {course}, {context}, {course_modules} WHERE " .
- "{course}.id={course_modules}.course AND {course_modules}.id={context}.instanceid AND {course_modules}.course=" . $course_id . " AND {course_modules}.instance=" . $iassign->id;
- $answer_list = $DB->get_records_sql($str_query);
- $list1 = array();
- $strAux = "";
- foreach ($answer_list as $item) { $list1[] = $item; $strAux .= "[" . $item->id . "," . $item->contextid . "," . $item->shortname . "] "; }
- $all_context[$ii] = $list1[0];
- echo " - iassign.id=" . $list_all_instances_of_iassign[$ii]->id . ", contextid=" . $all_context[$ii]->contextid . " : " . $strAux . "<br/>\n";
- $ii++;
- }
- $sizeofList = $ii;
- for ($ii=0; $ii<$sizeofList; $ii++) {
- $iassign = $list_all_instances_of_iassign[$ii];
- $list_all_iassign_statement = $DB->get_records('iassign_statement', array('iassignid' => $iassign->id));
- $contextid = $all_context[$ii]->contextid;
- foreach ($list_all_iassign_statement as $iassign_statement) {
-
- $files = $DB->get_records('files', array('contextid' => $contextid, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_statement->id));
- $numf = count($files); $countF += $numf; $msgO = "iassign_statement.id";
- if ($numf == 0) {
- if (isset($iassign_statement->file))
- $files = $DB->get_records('files', array('contextid' => $contextid, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_statement->file));
- $numf = count($files); $countF += $numf; $msgO = "iassign_statement.file";
- if ($numf == 0) {
- if (isset($iassign_statement->filesid))
- $files = $DB->get_records('files', array('id' => $iassign_statement->filesid));
- $numf = count($files); $countF += $numf; $msgO = "iassign_statement.filesid";
- if ($numf == 0) {
- if (isset($iassign_statement->filesid))
- $files = $DB->get_records('files', array('contextid' => $contextid, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_statement->filesid));
- $numf = count($files); $countF += $numf; $msgO = "iassign_statement.filesid=files.itemid";
- if ($numf == 0)
- echo " * files: " . $numf . " - ERRO 'id' 'file' 'filesid'<br/>\n";
- }
- }
- }
- if ($numf > 0) { echo " * files: " . $numf . ": " . $msgO . "<br/>\n";
- $filename = array();
- foreach ($files as $element_file) {
- echo " * files: id = " . $element_file->id . ", contextid = " . $element_file->contextid . ", itemid=" . $element_file->itemid . " : " . $element_file->filename . "<br/>\n";
- if ($element_file->filename != '.') {
- $filename = explode(".", $element_file->filename);
- if ($iassign_statement->filesid != $element_file->id) {
- echo " Update 'iassign_statement.filesid'=" . $iassign_statement->filesid . " <- " . $element_file->id . " : " . $element_file->filename . "<br/>";
- $iassign_statement->filesid = $element_file->id;
- }
- }
- if ($element_file->itemid != $iassign_statement->id) {
- $newentry_be_updated = new stdClass(); $newentry_be_updated->id = $element_file->id; $newentry_be_updated->itemid = $iassign_statement->id;
- echo " Update 'files.itemid': id=" . $newentry_be_updated->id . ", itemid=" . $element_file->itemid . "<-" . $newentry_be_updated->itemid . " : " . $element_file->filename . "<br/>";
- }
- }
- $extension = "";
- if (count($filename) > 1) $extension = strtolower($filename[count($filename) - 1]);
- foreach ($list_all_iassign_ilm as $iassign_ilm) {
- $extensions_of_ilm = explode(",", $iassign_ilm->extension);
- if (in_array($extension, $extensions_of_ilm)) {
- $iassign_statement->iassign_ilmid = $iassign_ilm->id;
- echo " Update 'iassign_statement.iassign_ilmid': " . $iassign_statement->iassign_ilmid . " <- " . $iassign_ilm->id . "<br/>\n";
- }
- }
- }
- }
- }
- $timeWrite = date('Y_m_d_H_i_s');
- $filenamewrite = "_output_restore_after_execute_" . $timeWrite . ".txt";
- echo "restore_iassign_stepslib: " . $filenamewrite . "<br/>\nUsando: " . __DIR__ . "/../../ilm_debug/escreva.php" . "<br/>\n";
- echo "restore_iassign_stepslib: resp=" . $resp . ", #files=" . $countF . "<br/>\n";
- }
|