From: Nik Okuntseff Date: Wed, 30 Mar 2016 16:32:40 +0000 (+0000) Subject: Wrote ttUser::isPluginEnabled() function. X-Git-Tag: timetracker_1.19-1~1762 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=7ddf5c391598126ec473db7b25884ee0bd94f153;p=timetracker.git Wrote ttUser::isPluginEnabled() function. --- diff --git a/WEB-INF/lib/common.lib.php b/WEB-INF/lib/common.lib.php index 3644c058..124b78f5 100644 --- a/WEB-INF/lib/common.lib.php +++ b/WEB-INF/lib/common.lib.php @@ -340,10 +340,3 @@ function ttAccessCheck($required_rights) return true; } - -// ttPluginEnabled is used to check whether a plugin is enabled for user. -function ttPluginEnabled($plugin) -{ - global $user; - return in_array($plugin, explode(',', $user->plugins)); -} diff --git a/WEB-INF/lib/ttExpenseHelper.class.php b/WEB-INF/lib/ttExpenseHelper.class.php index 86ccbcd8..23ea3908 100644 --- a/WEB-INF/lib/ttExpenseHelper.class.php +++ b/WEB-INF/lib/ttExpenseHelper.class.php @@ -109,17 +109,17 @@ class ttExpenseHelper { // getItem - retrieves an entry from tt_expense_items table. static function getItem($id, $user_id) { - global $user; + global $user; $mdb2 = getConnection(); $client_field = null; - if (ttPluginEnabled('cl')) + if ($user->isPluginEnabled('cl')) $client_field = ", c.name as client_name"; $left_joins = ""; $left_joins = " left join tt_projects p on (ei.project_id = p.id)"; - if (ttPluginEnabled('cl')) + if ($user->isPluginEnabled('cl')) $left_joins .= " left join tt_clients c on (ei.client_id = c.id)"; $sql = "select ei.id, ei.date, ei.client_id, ei.project_id, ei.name, ei.cost, ei.invoice_id $client_field, p.name as project_name @@ -159,18 +159,18 @@ class ttExpenseHelper { // getItems - returns expense items for a user for a given date. static function getItems($user_id, $date) { - global $user; + global $user; $result = array(); $mdb2 = getConnection(); $client_field = null; - if (ttPluginEnabled('cl')) + if ($user->isPluginEnabled('cl')) $client_field = ", c.name as client"; $left_joins = ""; $left_joins = " left join tt_projects p on (ei.project_id = p.id)"; - if (ttPluginEnabled('cl')) + if ($user->isPluginEnabled('cl')) $left_joins .= " left join tt_clients c on (ei.client_id = c.id)"; $sql = "select ei.id as id $client_field, p.name as project, ei.name as item, ei.cost as cost, diff --git a/WEB-INF/lib/ttInvoiceHelper.class.php b/WEB-INF/lib/ttInvoiceHelper.class.php index d5068309..b5a3c59e 100644 --- a/WEB-INF/lib/ttInvoiceHelper.class.php +++ b/WEB-INF/lib/ttInvoiceHelper.class.php @@ -129,7 +129,7 @@ class ttInvoiceHelper { } // If we have expenses, we need to do a union with a separate query for expense items from tt_expense_items table. - if (ttPluginEnabled('ex')) { // if ex(penses) plugin is enabled + if ($user->isPluginEnabled('ex')) { $sql_for_expense_items = "select ei.date as date, 2 as type, u.name as user_name, p.name as project_name, null as task_name, ei.name as note, null as duration, ei.cost as cost from tt_expense_items ei @@ -336,7 +336,7 @@ class ttInvoiceHelper { foreach($invoice_items as $item) $subtotal += $item['cost']; if ($tax_percent) { - $tax_expenses = ttPluginEnabled('et'); + $tax_expenses = $user->isPluginEnabled('et'); foreach($invoice_items as $item) { if ($item['type'] == 2 && !$tax_expenses) continue; diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index 3520dfd9..9d0fc87f 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -286,7 +286,7 @@ class ttReportHelper { $left_joins .= " left join tt_clients c on (c.id = l.client_id)"; if (($user->canManageTeam() || $user->isClient()) && $bean->getAttribute('chinvoice')) $left_joins .= " left join tt_invoices i on (i.id = l.invoice_id and i.status = 1)"; - if ($user->canManageTeam() || $user->isClient() || ttPluginEnabled('ex')) + if ($user->canManageTeam() || $user->isClient() || $user->isPluginEnabled('ex')) $left_joins .= " left join tt_users u on (u.id = l.user_id)"; if ($bean->getAttribute('chproject') || 'project' == $group_by_option) $left_joins .= " left join tt_projects p on (p.id = l.project_id)"; @@ -311,7 +311,7 @@ class ttReportHelper { // with an exception of sorting part, that is added in the end. // However, when we have expenses, we need to do a union with a separate query for expense items from tt_expense_items table. - if ($bean->getAttribute('chcost') && ttPluginEnabled('ex')) { // if ex(penses) plugin is enabled + if ($bean->getAttribute('chcost') && $user->isPluginEnabled('ex')) { // if ex(penses) plugin is enabled $fields = array(); // An array of fields for database query. array_push($fields, 'ei.id'); @@ -492,7 +492,7 @@ class ttReportHelper { $left_joins .= " left join tt_clients c on (c.id = l.client_id)"; if (($user->canManageTeam() || $user->isClient()) && $report['show_invoice']) $left_joins .= " left join tt_invoices i on (i.id = l.invoice_id and i.status = 1)"; - if ($user->canManageTeam() || $user->isClient() || ttPluginEnabled('ex')) + if ($user->canManageTeam() || $user->isClient() || $user->isPluginEnabled('ex')) $left_joins .= " left join tt_users u on (u.id = l.user_id)"; if ($report['show_project'] || 'project' == $group_by_option) $left_joins .= " left join tt_projects p on (p.id = l.project_id)"; diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index 959649e3..84b229fc 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -31,8 +31,8 @@ class ttUser { var $name = null; // User name. var $id = null; // User id. var $team_id = null; // Team id. - var $role = null; // User role (user, client, comanager, manager, admin). - var $client_id = null; // Client id for client user role. + var $role = null; // User role (user, client, comanager, manager, admin). + var $client_id = null; // Client id for client user role. var $behalf_id = null; // User id, on behalf of whom we are working. var $behalf_name = null; // User name, on behalf of whom we are working. var $email = null; // User email. @@ -45,10 +45,10 @@ class ttUser { var $record_type = 0; // Record type (duration vs start and finish, or both). var $currency = null; // Currency. var $plugins = null; // Comma-separated list of enabled plugins. - var $team = null; // Team name. + var $team = null; // Team name. var $custom_logo = 0; // Whether to use a custom logo for team. - var $address = null; // Address for invoices. - var $lock_interval = 0; // Lock interval in days for time records. + var $address = null; // Address for invoices. + var $lock_interval = 0; // Lock interval in days for time records. var $rights = 0; // A mask of user rights. // Constructor. @@ -149,6 +149,12 @@ class ttUser { return (right_manage_team & $this->role); } + // isPluginEnabled checks whether a plugin is enabled for user. + function isPluginEnabled($plugin) + { + return in_array($plugin, explode(',', $this->plugins)); + } + // getAssignedProjects - returns an array of assigned projects. function getAssignedProjects() { diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 1a1cf38f..b1b27b00 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.9.20.3457 | Copyright © Anuko | +  Anuko Time Tracker 1.9.20.3458 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/time.php b/time.php index d5a28bbb..193f7a2b 100644 --- a/time.php +++ b/time.php @@ -57,7 +57,7 @@ if(!$cl_date) $_SESSION['date'] = $cl_date; // Use custom fields plugin if it is enabled. -if (ttPluginEnabled('cf')) { +if ($user->isPluginEnabled('cf')) { require_once('plugins/CustomFields.class.php'); $custom_fields = new CustomFields($user->team_id); $smarty->assign('custom_fields', $custom_fields);