Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
benkeen committed Oct 7, 2017
1 parent 914e030 commit 190661a
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 94 deletions.
56 changes: 32 additions & 24 deletions code/General.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
use FormTools\Core;
use FormTools\Forms;
use FormTools\Modules;
use FormTools\Sessions;
use FormTools\Views;

use Smarty;


class General
Expand Down Expand Up @@ -41,13 +45,13 @@ public static function addReportBuilderMenuItems($params, $L)
* @param mixed $form_id a valid form ID, or empty string for all
* @return array
*/
public function getReports($form_id)
public static function getReports($form_id)
{
$LANG = Core::$L;
$smarty = Core::$smarty;
$root_dir = Core::getRootDir();
$root_url = Core::getRootUrl();
$sub_dirs = Core::shouldUseSmartySubDirs();

$smarty = new Smarty();

$return_info = array(
"heading" => "",
Expand All @@ -56,9 +60,8 @@ public function getReports($form_id)
);

// first off, find out if we want to display a single form or all of them
$smarty->template_dir = "$root_dir/themes/default";
$smarty->compile_dir = "$root_dir/themes/default/cache/";
$smarty->use_sub_dirs = $sub_dirs;
$smarty->setTemplateDir("$root_dir/themes/default");
$smarty->setCompileDir("$root_dir/themes/default/cache/");
$smarty->assign("LANG", $LANG);
$smarty->assign("g_root_url", $root_url);
$smarty->assign("is_single_form", false);
Expand All @@ -67,21 +70,24 @@ public function getReports($form_id)
$is_valid_single_form = null;
if (!empty($form_id)) {
$is_single_form = true;
$is_valid_single_form = Forms::checkFormExists($form_id, false));
$is_valid_single_form = Forms::checkFormExists($form_id, false);
}
$smarty->assign("is_single_form", $is_single_form);
$smarty->assign("is_valid_single_form", $is_valid_single_form);

$export_manager_available = Modules::checkModuleUsable("export_manager"));
$export_manager_available = Modules::checkModuleUsable("export_manager");
$smarty->assign("export_manager_available", $export_manager_available);

$account_id = isset($_SESSION["ft"]["account"]["account_id"]) ? $_SESSION["ft"]["account"]["account_id"] : "";
$report_builder = Modules::getModuleInstance("report_builder");
$L = $report_builder->getLangStrings();

$smarty->assign("L", $L);
$account_id = Core::$user->getAccountId();

// deeply klutzy function, that ft_search_forms...
if (Core::$user->isAdmin()) {
$account_id = "";
}

$forms = Forms::searchForms(array(
"account_id" => $account_id,
"is_admin" => true
Expand Down Expand Up @@ -109,54 +115,55 @@ public function getReports($form_id)
if (empty($forms)) {
return array(
"heading" => "", // give 'em no information :)
"error" => $LANG["report_builder"]["notify_form_no_permissions"],
"error" => $L["notify_form_no_permissions"],
"content" => ""
);
}

// generate the heading
$return_info["heading"] = $smarty->fetch(realpath(dirname(__FILE__) . "/../../templates/heading.tpl"));
$return_info["heading"] = $smarty->fetch(realpath(__DIR__ . "/../templates/heading.tpl"));

if (!$export_manager_available) {
$return_info["error"] = $LANG["report_builder"]["text_export_manager_not_available"];
$return_info["error"] = $L["text_export_manager_not_available"];
return $return_info;
}

// include the Export Manager. We're going to need it
ft_include_module("export_manager");
$export_manager = Modules::getModuleInstance("export_manager");

$form_views = array();
foreach ($forms as $form_info) {
$curr_form_id = $form_info["form_id"];
$views = ft_get_form_views($curr_form_id, $account_id);
$views = Views::getFormViews($curr_form_id, $account_id);

$updated_views = array();
foreach ($views as $view_info) {
$view_id = $view_info["view_id"];
if (!isset($_SESSION["ft"]["view_{$view_id}_num_submissions"])) {
_ft_cache_view_stats($curr_form_id, $view_id);

if (!Sessions::exists("view_{$view_id}_num_submissions")) {
Views::cacheViewStats($curr_form_id, $view_id);
}

if (!isset($_SESSION["ft"]["view_{$view_id}_num_submissions"]) || empty($_SESSION["ft"]["view_{$view_id}_num_submissions"]) || !is_numeric($_SESSION["ft"]["view_{$view_id}_num_submissions"])) {
$_SESSION["ft"]["view_{$view_id}_num_submissions"] = 0;
if (!Sessions::isNonEmpty("view_{$view_id}_num_submissions") || !is_numeric(Sessions::get("view_{$view_id}_num_submissions"))) {
Sessions::set("view_{$view_id}_num_submissions", 0);
}

$view_info["num_submissions_in_view"] = number_format($_SESSION["ft"]["view_{$view_id}_num_submissions"]);
$view_info["num_submissions_in_view"] = number_format(Sessions::get("view_{$view_id}_num_submissions"));
$updated_views[] = $view_info;
}

$form_views["form_{$curr_form_id}"] = $updated_views;
}

$groups = exp_get_export_groups();
$groups = $export_manager->getExportGroups();
$export_options = array();
foreach ($groups as $group_info) {
if ($group_info["visibility"] != "show") {
continue;
}

$group_id = $group_info["export_group_id"];
$export_types = exp_get_export_types($group_id, true);
$export_types = $export_manager->getExportTypes($group_id, true);

foreach ($export_types as $export_type_info) {
if ($export_type_info["visibility"] == "hide") {
Expand All @@ -174,14 +181,15 @@ public function getReports($form_id)
}
}

$module_settings = ft_get_module_settings("", "report_builder");
$module_settings = Modules::getModuleSettings("", "report_builder");
$expand_by_default = isset($module_settings["expand_by_default"]) ? $module_settings["expand_by_default"] : "no";

$smarty->assign("forms", $forms);
$smarty->assign("form_views", $form_views);
$smarty->assign("export_options", $export_options);
$smarty->assign("expand_by_default", $expand_by_default);
$return_info["content"] = $smarty->fetch(realpath(dirname(__FILE__) . "/../../templates/report.tpl"));

$return_info["content"] = $smarty->fetch(realpath(__DIR__ . "/../templates/report.tpl"));

return $return_info;
}
Expand Down
66 changes: 37 additions & 29 deletions code/Module.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

use FormTools\Core;
use FormTools\Hooks;
use FormTools\Menus;
use FormTools\Module as FormToolsModule;
use FormTools\Modules;
use FormTools\Settings;
use FormTools\Sessions;


class Module extends FormToolsModule
Expand All @@ -17,12 +20,8 @@ class Module extends FormToolsModule
protected $authorEmail = "ben.keen@gmail.com";
protected $authorLink = "http://formtools.org";
protected $version = "2.0.0";
protected $date = "2017-10-06";
protected $date = "2017-10-07";
protected $originLanguage = "en_us";
protected $jsFiles = array(
// "{FTROOT}/global/codemirror/js/codemirror.js",
// "{MODULEROOT}/scripts/pages.js"
);

protected $nav = array(
"module_name" => array("index.php", false),
Expand All @@ -31,11 +30,11 @@ class Module extends FormToolsModule

public function install($module_id)
{
Hooks::registerHook("code", "report_builder", "start", "ft_construct_page_url", "constructPageUrl", 50, true);
Hooks::registerHook("code", "report_builder", "middle", "ft_get_admin_menu_pages_dropdown", "addReportBuilderMenuItems", 50, true);
Hooks::registerHook("code", "report_builder", "middle", "ft_get_client_menu_pages_dropdown", "addReportBuilderMenuItems", 50, true);
Hooks::registerHook("code", "report_builder", "start", "FormTools\\Pages::constructPageUrl", "constructPageUrl", 50, true);
Hooks::registerHook("code", "report_builder", "middle", "FormTools\\Menus::getAdminMenuPagesDropdown", "addReportBuilderMenuItems", 50, true);
Hooks::registerHook("code", "report_builder", "middle", "FormTools\\Menus::getClientMenuPagesDropdown", "addReportBuilderMenuItems", 50, true);
Hooks::registerHook("template", "report_builder", "head_bottom", "", "includeInHead");
Hooks::registerHook("code", "report_builder", "main", "ft_display_submission_listing_quicklinks", "addQuicklink", 50, true);
Hooks::registerHook("code", "report_builder", "main", "FormTools\\Submissions::displaySubmissionListingQuicklinks", "addQuicklink", 50, true);

$settings = array(
"show_reports_icon_on_submission_listing_page" => "yes",
Expand All @@ -59,6 +58,9 @@ public function uninstall($module_id)
");
$db->execute();

// ensure the menu is re-cached
Menus::cacheAccountMenu(Core::$user->getAccountId());

return array(true, "");
}

Expand Down Expand Up @@ -87,27 +89,29 @@ public function constructPageUrl($params)
* @param string $location
* @param array $params
*/
function rb_include_in_head($location, $params)
public static function includeInHead($location, $params)
{
global $g_root_url, $LANG;
$LANG = Core::$L;
$root_url = Core::getRootUrl();

if ($params["page"] == "report_builder_reports_page") {
echo <<< END
<link type="text/css" rel="stylesheet" href="$g_root_url/modules/report_builder/global/css/reports.css">
<script src="$g_root_url/modules/report_builder/global/scripts/reports.js?v=2"></script>
<link type="text/css" rel="stylesheet" href="$root_url/modules/report_builder/css/reports.css">
<script src="$root_url/modules/report_builder/scripts/reports.js"></script>
END;
}

if ($params["page"] == "admin_forms" || $params["page"] == "client_forms") {
$L = ft_get_module_lang_file_contents("report_builder");
$module = Modules::getModuleInstance("report_builder");
$L = $module->getLangStrings();

echo <<< END
<link type="text/css" rel="stylesheet" href="$g_root_url/modules/report_builder/global/css/reports.css">
<script src="$g_root_url/modules/report_builder/global/scripts/reports.js"></script>
<link type="text/css" rel="stylesheet" href="$root_url/modules/report_builder/css/reports.css">
<script src="$root_url/modules/report_builder/scripts/reports.js"></script>
<script>
g.reports_dialog = $("<div id=\"rb_reports_dialog\"><div style=\"text-align: center; padding: 30px\"><img src=\"{$g_root_url}/global/images/loading.gif\" /></div></div>");
g.reports_dialog = $("<div id=\"rb_reports_dialog\"><div style=\"text-align: center; padding: 30px\"><img src=\"{$root_url}/global/images/loading.gif\" /></div></div>");
g.preload_loading_icon = new Image(32, 32);
g.preload_loading_icon.src = "{$g_root_url}/global/images/loading.gif";
g.preload_loading_icon.src = "{$root_url}/global/images/loading.gif";
g.show_reports_dialog = function() {
ft.create_dialog({
Expand All @@ -118,7 +122,7 @@ function rb_include_in_head($location, $params)
min_height: 400,
open: function() {
$.ajax({
url: g.root_url + "/modules/report_builder/global/code/actions.php",
url: g.root_url + "/modules/report_builder/code/actions.php",
data: {
action: "get_reports",
form_id: ms.form_id,
Expand All @@ -144,17 +148,13 @@ function rb_include_in_head($location, $params)
}


public function addQuicklink($params)
public function addQuicklink()
{
$root_url = Core::getRootUrl();
$smarty = Core::$smarty;
$module = Modules::getModuleInstance("report_builder");
$L = $module->getLangStrings();

// $g_smarty;

print_r($smarty->getTemplateVars());
return "";

$form_id = $smarty->_tpl_vars["SESSION"]["curr_form_id"];
$form_id = Sessions::get("curr_form_id");

$settings = array("show_reports_icon_on_submission_listing_page", "icon_behaviour");
$results = Settings::get($settings, "report_builder");
Expand All @@ -165,8 +165,6 @@ public function addQuicklink($params)

$icon_behaviour = $results["icon_behaviour"];

$L = ft_get_module_lang_file_contents("report_builder");

$quicklinks = array(
"icon_url" => "{$root_url}/modules/report_builder/images/icon_report_builder16x16.png",
"title_text" => $L["phrase_view_reports"]
Expand All @@ -183,6 +181,16 @@ public function addQuicklink($params)
}


public function addReportBuilderMenuItems($params)
{
$module = Modules::getModuleInstance("report_builder");
return General::addReportBuilderMenuItems($params, $module->getLangStrings());
}

public function getReports($form_id)
{
return General::getReports($form_id);
}
}


Expand Down
12 changes: 7 additions & 5 deletions code/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require_once("../../../global/library.php");

use FormTools\Core;
use FormTools\General;
use FormTools\Modules;

$module = Modules::initModulePage("client");
Expand All @@ -18,7 +20,7 @@
if (isset($request["return_vals"])) {
$vals = array();
foreach ($request["return_vals"] as $pair) {
list($key, $value) = split(":", $pair);
list($key, $value) = mb_split(":", $pair);
$vals[] = "$key: \"$value\"";
}
$return_val_str = ", " . join(", ", $vals);
Expand All @@ -34,14 +36,14 @@
exit;
}

if (!ft_is_admin()) {
$account_id = isset($_SESSION["ft"]["account"]["account_id"]) ? $_SESSION["ft"]["account"]["account_id"] : "";
if (!ft_check_client_may_view($account_id, $form_id, $view_id)) {
if (!Core::$user->isAdmin()) {
$account_id = Core::$user->getAccountId();
if (!General::checkClientMayView($account_id, $form_id, $view_id)) {
exit;
}
}

$report_info = rb_get_reports($form_id);
$report_info = $module->getReports($form_id);
echo $report_info["content"];
break;
}
Expand Down
2 changes: 1 addition & 1 deletion css/reports.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
.rb_view_row {
border-bottom: 1px solid #efefef;
padding: 3px 3px 3px 15px;
padding: 8px 3px 1px 15px;
}
.rb_view_row:hover {
background-color: #ddf9df;
Expand Down
Loading

0 comments on commit 190661a

Please sign in to comment.