I am trying to programmatically import 1000 quizzes. I am preparing the quizzes in Aiken format and using a perl script to "automate" the process of uploading the quiz. At present it consists of following steps:
1. Going to Home Page
2. Logging in as admin
3. Navigating to admin page
4. Navigating to "Import and export of quiz" page
5. Navigating to "Import Quiz Questions" page
6. Filling the form (including new quiz name, and uploading the quiz file) and going to "Import" page which is basically "Manage Questions" page
7. STUCK
Attempting to select the 10 quiz questions I added - but they are not getting ticked at all.
If I could "tick" them, I would be happy. For the moment, I am wondering if there is any way of having the newly added questions "pre-checked"? I actually do not know where the checkbox is getting generated, and how to make its default state "checked" instead of "unchecked".
Originally, I expected the newly uploaded questions to have been already assigned to the quiz. May be I am importing the quizzes in an unintended manner? What is the right way to import 1000 quizzes, complete with their subjects, unique names/titles and descriptions?

Comments
OK - I found how to hardcode
OK - I found how to hardcode the default value of the checkbox to be "checked" ... it involves modifying the quiz module quiz.admin.inc file, but I am guessing one could do it just for the duration of bulk import and then revert.
In the function function _quiz_add_questions_to_form , Right after the line
*** // Add checkboxes to remove questions in js disabled browsers... ***
Add just one line: $question->staying = TRUE;
So your code will look like
function _quiz_add_questions_to_form ( ... ){:
:
:
// Add checkboxes to remove questions in js disabled browsers...
$question->staying = TRUE;
:
:
:
}
And here is the wonderful WWW::Mechanize code to automate the inputting of quiz forms.
#!/usr/bin/perl
use strict;
use WWW::Mechanize;
use HTML::TokeParser;
my $url = "http://myurl";
my $username = "admin_username";
my $password = "admin_password";
my $agent = WWW::Mechanize->new();
$agent->get($url);
$agent->form_number(1);
$agent->field("name" => $username);
$agent->field("pass" => $password);
$agent->click();
$agent->follow_link(text_regex => qr/admin/i);
$agent->follow_link(text_regex => qr/quiz/i);
$agent->follow_link(text_regex => qr/import/i);
$agent->follow_link(n => 22);
$agent->form_id("questions-import-form");
$agent->field("destination_title" => "$ARGV[0]");
$agent->field("import_type" => "moodle_aiken");
$agent->field("files[upload]" => $ARGV[2]);
$agent->click();
$agent->form_id("quiz-questions-form");
$agent->click();