Skip to content

Commit 5f443e8

Browse files
committed
3.2.0; added setting for export timeout, closes #26
1 parent 2aeb904 commit 5f443e8

File tree

4 files changed

+193
-174
lines changed

4 files changed

+193
-174
lines changed

code/General.class.php

Lines changed: 114 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -10,123 +10,118 @@
1010

1111
class General
1212
{
13-
/**
14-
* Returns a list of all export icons, found in the /modules/export_manager/images/icons/ folder.
15-
*
16-
* return array an array of image filenames.
17-
*/
18-
public static function getExportIcons()
19-
{
20-
$root_dir = Core::getRootDir();
21-
$icon_folder = "$root_dir/modules/export_manager/images/icons/";
22-
23-
// store all the icon filenames in an array
24-
$filenames = array();
25-
if ($handle = opendir($icon_folder)) {
26-
while (false !== ($file = readdir($handle))) {
27-
$extension = Files::getFilenameExtension($file, true);
28-
if ($extension == "jpg" || $extension == "gif" || $extension == "bmp" || $extension == "png") {
29-
$filenames[] = $file;
30-
}
31-
}
32-
}
33-
34-
return $filenames;
35-
}
36-
37-
38-
/**
39-
* Called on the Settings page. Updates the generated file folder information.
40-
*
41-
* @param array $info
42-
* @return array [0] T/F [1] Error / notification message
43-
*/
44-
public static function updateSettings($info, $L)
45-
{
46-
$settings = array(
47-
"file_upload_dir" => $info["file_upload_dir"],
48-
"file_upload_url" => $info["file_upload_url"]
49-
);
50-
51-
//$settings["cache_multi_select_fields"] = (isset($info["cache_multi_select_fields"]) && !empty($info["cache_multi_select_fields"])) ?
52-
// $info["cache_multi_select_fields"] : "no";
53-
54-
Modules::setModuleSettings($settings);
55-
56-
// $_SESSION["ft"]["export_manager"]["cache_multi_select_fields"] = $settings["cache_multi_select_fields"];
57-
58-
return array(true, $L["notify_settings_updated"]);
59-
}
60-
61-
62-
/**
63-
* Used in generating the filenames; this builds most of the placeholder values (the date-oriented ones)
64-
* to which the form and export-specific placeholders are added.
65-
*
66-
* @return array the placeholder array
67-
*/
68-
public static function getExportFilenamePlaceholderHash()
69-
{
70-
$offset = CoreGeneral::getCurrentTimezoneOffset();
71-
$date_str = CoreGeneral::getDate($offset, CoreGeneral::getCurrentDatetime(), "Y|y|F|M|m|n|d|D|j|g|h|H|s|U|a|G|i");
72-
list($Y, $y, $F, $M, $m, $n, $d, $D, $j, $g, $h, $H, $s, $U, $a, $G, $i) = explode("|", $date_str);
73-
74-
$placeholders = array(
75-
"datetime" => "$Y-$m-$d.$H-$i-$s",
76-
"date" => "$Y-$m-$d",
77-
"time" => "$H-$i-$s",
78-
"Y" => $Y,
79-
"y" => $y,
80-
"F" => $F,
81-
"M" => $M,
82-
"m" => $m,
83-
"G" => $G,
84-
"i" => $i,
85-
"n" => $n,
86-
"d" => $d,
87-
"D" => $D,
88-
"j" => $j,
89-
"g" => $g,
90-
"h" => $h,
91-
"H" => $H,
92-
"s" => $s,
93-
"U" => $U,
94-
"a" => $a
95-
);
96-
97-
return $placeholders;
98-
}
99-
100-
101-
public static function removeTables()
102-
{
103-
$db = Core::$db;
104-
105-
$db->query("DROP TABLE {PREFIX}module_export_groups");
106-
$db->execute();
107-
108-
$db->query("DROP TABLE {PREFIX}module_export_group_clients");
109-
$db->execute();
110-
111-
$db->query("DROP TABLE {PREFIX}module_export_types");
112-
$db->execute();
113-
}
114-
115-
116-
public static function clearTableData()
117-
{
118-
$db = Core::$db;
119-
120-
$db->query("TRUNCATE {PREFIX}module_export_group_clients");
121-
$db->execute();
122-
123-
$db->query("TRUNCATE {PREFIX}module_export_groups");
124-
$db->execute();
125-
126-
$db->query("TRUNCATE {PREFIX}module_export_types");
127-
$db->execute();
128-
129-
$db->query("DELETE FROM {PREFIX}settings WHERE module = 'export_manager'");
130-
$db->execute();
131-
}
13+
/**
14+
* Returns a list of all export icons, found in the /modules/export_manager/images/icons/ folder.
15+
*
16+
* return array an array of image filenames.
17+
*/
18+
public static function getExportIcons()
19+
{
20+
$root_dir = Core::getRootDir();
21+
$icon_folder = "$root_dir/modules/export_manager/images/icons/";
22+
23+
// store all the icon filenames in an array
24+
$filenames = array();
25+
if ($handle = opendir($icon_folder)) {
26+
while (false !== ($file = readdir($handle))) {
27+
$extension = Files::getFilenameExtension($file, true);
28+
if ($extension == "jpg" || $extension == "gif" || $extension == "bmp" || $extension == "png") {
29+
$filenames[] = $file;
30+
}
31+
}
32+
}
33+
34+
return $filenames;
35+
}
36+
37+
38+
/**
39+
* Called on the Settings page. Updates the generated file folder information.
40+
*
41+
* @param array $info
42+
* @return array [0] T/F [1] Error / notification message
43+
*/
44+
public static function updateSettings($info, $L)
45+
{
46+
$settings = array(
47+
"file_upload_dir" => $info["file_upload_dir"],
48+
"file_upload_url" => $info["file_upload_url"],
49+
"export_timeout" => $info["export_timeout"]
50+
);
51+
52+
Modules::setModuleSettings($settings);
53+
return array(true, $L["notify_settings_updated"]);
54+
}
55+
56+
57+
/**
58+
* Used in generating the filenames; this builds most of the placeholder values (the date-oriented ones)
59+
* to which the form and export-specific placeholders are added.
60+
*
61+
* @return array the placeholder array
62+
*/
63+
public static function getExportFilenamePlaceholderHash()
64+
{
65+
$offset = CoreGeneral::getCurrentTimezoneOffset();
66+
$date_str = CoreGeneral::getDate($offset, CoreGeneral::getCurrentDatetime(), "Y|y|F|M|m|n|d|D|j|g|h|H|s|U|a|G|i");
67+
list($Y, $y, $F, $M, $m, $n, $d, $D, $j, $g, $h, $H, $s, $U, $a, $G, $i) = explode("|", $date_str);
68+
69+
$placeholders = array(
70+
"datetime" => "$Y-$m-$d.$H-$i-$s",
71+
"date" => "$Y-$m-$d",
72+
"time" => "$H-$i-$s",
73+
"Y" => $Y,
74+
"y" => $y,
75+
"F" => $F,
76+
"M" => $M,
77+
"m" => $m,
78+
"G" => $G,
79+
"i" => $i,
80+
"n" => $n,
81+
"d" => $d,
82+
"D" => $D,
83+
"j" => $j,
84+
"g" => $g,
85+
"h" => $h,
86+
"H" => $H,
87+
"s" => $s,
88+
"U" => $U,
89+
"a" => $a
90+
);
91+
92+
return $placeholders;
93+
}
94+
95+
96+
public static function removeTables()
97+
{
98+
$db = Core::$db;
99+
100+
$db->query("DROP TABLE {PREFIX}module_export_groups");
101+
$db->execute();
102+
103+
$db->query("DROP TABLE {PREFIX}module_export_group_clients");
104+
$db->execute();
105+
106+
$db->query("DROP TABLE {PREFIX}module_export_types");
107+
$db->execute();
108+
}
109+
110+
111+
public static function clearTableData()
112+
{
113+
$db = Core::$db;
114+
115+
$db->query("TRUNCATE {PREFIX}module_export_group_clients");
116+
$db->execute();
117+
118+
$db->query("TRUNCATE {PREFIX}module_export_groups");
119+
$db->execute();
120+
121+
$db->query("TRUNCATE {PREFIX}module_export_types");
122+
$db->execute();
123+
124+
$db->query("DELETE FROM {PREFIX}settings WHERE module = 'export_manager'");
125+
$db->execute();
126+
}
132127
}

code/Module.class.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class Module extends FormToolsModule
2626
protected $author = "Ben Keen";
2727
protected $authorEmail = "[email protected]";
2828
protected $authorLink = "https://formtools.org";
29-
protected $version = "3.1.0";
30-
protected $date = "2019-04-27";
29+
protected $version = "3.2.0";
30+
protected $date = "2019-11-09";
3131
protected $originLanguage = "en_us";
3232
protected $jsFiles = array(
3333
"{MODULEROOT}/scripts/admin.js",
@@ -96,6 +96,9 @@ public function upgrade($module_id, $old_module_version)
9696

9797
// upgrading to 3.1.0
9898
self::addExportGroupContentType();
99+
100+
// upgrading to 3.2.0
101+
self::addExportTimeoutSetting();
99102
}
100103

101104

@@ -514,7 +517,8 @@ private function addModuleSettings()
514517

515518
Settings::set(array(
516519
"file_upload_dir" => $upload_dir,
517-
"file_upload_url" => "$root_url/upload"
520+
"file_upload_url" => "$root_url/upload",
521+
"export_timeout" => 300
518522
), "export_manager");
519523
}
520524

@@ -579,6 +583,8 @@ public function export($params)
579583
$root_dir = Core::getRootDir();
580584
$root_url = Core::getRootUrl();
581585

586+
$module_settings = Settings::get("", "export_manager");
587+
582588
// if any of the required fields weren't entered, just output a simple blank message
583589
if (empty($params["form_id"]) || empty($params["view_id"]) || empty($params["order"]) ||
584590
empty($params["search_fields"]) || empty($params["export_group_id"])) {
@@ -594,7 +600,7 @@ public function export($params)
594600
$export_type_id = $params["export_type_id"];
595601
$results = $params["results"];
596602

597-
set_time_limit(300);
603+
set_time_limit($module_settings["export_timeout"]);
598604

599605
// if the user only wants to display the currently selected rows, limit the query to those submission IDs
600606
$submission_ids = array();
@@ -700,9 +706,8 @@ public function export($params)
700706

701707
// create a file on the server
702708
} else {
703-
$settings = Settings::get("", "export_manager");
704-
$file_upload_dir = $settings["file_upload_dir"];
705-
$file_upload_url = $settings["file_upload_url"];
709+
$file_upload_dir = $module_settings["file_upload_dir"];
710+
$file_upload_url = $module_settings["file_upload_url"];
706711

707712
$file = "$file_upload_dir/{$placeholders["filename"]}";
708713
if ($handle = @fopen($file, "w")) {
@@ -802,4 +807,12 @@ private function addExportGroupContentType()
802807
}
803808
}
804809
}
810+
811+
private function addExportTimeoutSetting()
812+
{
813+
$settings = Settings::get("", "export_manager");
814+
if (!array_key_exists($settings, "export_timeout")) {
815+
Settings::set(array("export_timeout" => 300), "export_manager");
816+
}
817+
}
805818
}

lang/en_us.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
$L["phrase_export_group_name"] = "Export Group Name";
4141
$L["phrase_smarty_template"] = "Smarty Template";
4242
$L["phrase_admin_export_only"] = "Only the administrator may use this export type";
43+
$L["phrase_export_timeout"] = "Export timeout";
4344
$L["phrase_export_type_name"] = "Export type name";
4445
$L["phrase_view_available_placeholders"] = "view available placeholders";
4546
$L["phrase_generate_file"] = "Generate a file on the server";

0 commit comments

Comments
 (0)