25 error_reporting(E_ALL);
26 if ((php_sapi_name() !=
'cli')) {
27 trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
31 $args = $_SERVER[
'argv'];
37 $MATRIX_ROOT_DIR = array_shift($args);
38 if (empty($MATRIX_ROOT_DIR)) {
39 print_usage(
"ERROR: You need to supply the path to the System Root as the first argument");
42 if (!is_dir($MATRIX_ROOT_DIR) || !is_readable($MATRIX_ROOT_DIR.
'/core/include/init.inc')) {
43 print_usage(
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.");
46 require $MATRIX_ROOT_DIR.
'/core/include/init.inc';
49 $root_user = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
50 $GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user);
53 $form_assetid = array_shift($args);
54 if (empty($form_assetid)) {
55 print_usage(
"ERROR: You need to enter the Form asset ID as the second argument.");
59 $form = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($form_assetid,
'form_email', TRUE);
61 print_usage(
"ERROR: Invalid Form asset ID.");
65 $from_time = array_shift($args);
66 if (empty($from_time)) {
67 print_usage(
"ERROR: You need to enter the From Time as the third argument.");
70 $from_time = strtotime($from_time);
71 if ($from_time === FALSE) {
72 print_usage(
"ERROR: Invalid From Time.");
76 $to_time = array_shift($args);
77 if (empty($to_time)) {
78 print_usage(
"ERROR: You need to enter the To Time as the forth argument.");
81 $to_time = strtotime($to_time);
82 if ($to_time === FALSE) {
83 print_usage(
"ERROR: Invalid To Time.");
87 $export_file = array_shift($args);
90 $form_edit_fns = $form->getEditFns();
91 $csv = $form_edit_fns->createCSVSubmissionLogs($form, $from_time, $to_time);
94 if (!is_null($export_file)) {
95 $csv->setFilepath($export_file);
102 $GLOBALS[
'SQ_SYSTEM']->restoreCurrentUser();
113 function print_usage($err_msg =
'')
117 echo
"\tphp export_form_submission_logs.php MATRIX_ROOT_DIRECTORY FORM_ASSET_ID FROM_TIME T0_TIME [EXPORT_FILE]\n\n";
118 echo
"\t\tMATRIX_ROOT_DIRECTORY The Matrix System Root directory.\n";
119 echo
"\t\tFORM_ASSET_ID The asset ID of the Form asset. Note that this is not the Custom Form asset but the Form Contents asset under it.\n";
120 echo
"\t\tFROM_TIME The start time of a specific period to get Form Submissions from. It can be a specific time string like 'Y-m-d H:i:s' or a relative one like 'yesterday H:i:s'. For more information on the accepted formats, refer at http://uk3.php.net/manual/en/datetime.formats.php\n";
121 echo
"\t\tT0_TIME The end time of a specific period to get Form Submissions from. It has the same format as FROM_TIME.\n";
122 echo
"\t\tEXPORT_FILE The file name or file path to write the export file to. If no file name is specified, the CSV export will be printed to the screen.\n";