--- /dev/null
+<?php
+// +----------------------------------------------------------------------+
+// | Anuko Time Tracker
+// +----------------------------------------------------------------------+
+// | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
+// +----------------------------------------------------------------------+
+// | LIBERAL FREEWARE LICENSE: This source code document may be used
+// | by anyone for any purpose, and freely redistributed alone or in
+// | combination with other software, provided that the license is obeyed.
+// |
+// | There are only two ways to violate the license:
+// |
+// | 1. To redistribute this code in source form, with the copyright
+// | notice or license removed or altered. (Distributing in compiled
+// | forms without embedded copyright notices is permitted).
+// |
+// | 2. To redistribute modified versions of this code in *any* form
+// | that bears insufficient indications that the modifications are
+// | not the work of the original author(s).
+// |
+// | This license applies to this document only, not any other software
+// | that it may be combined with.
+// |
+// +----------------------------------------------------------------------+
+// | Contributors:
+// | https://www.anuko.com/time_tracker/credits.htm
+// +----------------------------------------------------------------------+
+
+import('ttConfigHelper');
+import('ttGroupHelper');
+
+// ttBehalfUser class stores a set of "on behalf user" attributes.
+// An instance in kept in ttUser class when user is working on behalf of someone.
+class ttBehalfUser {
+ // Work in progress, build on when need arises.
+ // Currently, we need it for quota_percent work (and perhaps in profile_edit.php).
+ var $name = null; // User name.
+ var $id = null; // User id.
+ var $quota_percent = 100.0; // Time quota percent for quotas plugin.
+
+ // Constructor.
+ // Note: org_id isneeded because we may construct an object in
+ // ttUser constructor, when global $user object does not yet exist.
+ function __construct($id, $org_id) {
+ $mdb2 = getConnection();
+
+ $sql = "select u.name, u.id, u.quota_percent".
+ " from tt_users u".
+ " where u.id = $id and u.org_id = $org_id and u.status = 1";
+
+ $res = $mdb2->query($sql);
+ if (is_a($res, 'PEAR_Error')) return;
+
+ $val = $res->fetchRow();
+ if ($val['id'] > 0) {
+ $this->name = $val['name'];
+ $this->id = $val['id'];
+ if ($val['quota_percent']) $this->quota_percent = $val['quota_percent'];
+ }
+ }
+}
import('ttConfigHelper');
import('ttGroupHelper');
+import('ttBehalfUser');
import('ttGroup');
import('form.Form');
import('form.ActionForm');
var $role_name = null; // Role name.
var $rank = null; // User role rank.
var $client_id = null; // Client id for client user role.
+ var $quota_percent = 100.0; // Time quota percent for quotas plugin.
var $behalf_id = null; // User id, on behalf of whom we are working.
var $behalf_group_id = null; // Group id, on behalf of which we are working.
var $behalf_name = null; // User name, on behalf of whom we are working.
var $rights = array(); // An array of user rights such as 'track_own_time', etc.
var $is_client = false; // Whether user is a client as determined by missing 'track_own_time' right.
+ var $behalfUser = null; // A ttBehalfUser instance with on behalf user attributes.
var $behalfGroup = null; // A ttGroup instance with on behalf group attributes.
// Constructor.
$mdb2 = getConnection();
- $sql = "SELECT u.id, u.login, u.name, u.group_id, u.role_id, r.rank, r.name as role_name, r.rights, u.client_id, u.email,
- g.org_id, g.name as group_name, g.currency, g.lang, g.decimal_mark, g.date_format, g.time_format, g.week_start,
- g.tracking_mode, g.project_required, g.task_required, g.record_type,
- g.bcc_email, g.allow_ip, g.password_complexity, g.plugins, g.config, g.lock_spec, g.workday_minutes, g.custom_logo
- FROM tt_users u LEFT JOIN tt_groups g ON (u.group_id = g.id) LEFT JOIN tt_roles r on (r.id = u.role_id) WHERE ";
+ $sql = "SELECT u.id, u.login, u.name, u.group_id, u.role_id, r.rank, r.name as role_name, r.rights, u.client_id,".
+ " u.quota_percent, u.email, g.org_id, g.name as group_name, g.currency, g.lang, g.decimal_mark, g.date_format,".
+ " g.time_format, g.week_start, g.tracking_mode, g.project_required, g.task_required, g.record_type,".
+ " g.bcc_email, g.allow_ip, g.password_complexity, g.plugins, g.config, g.lock_spec, g.workday_minutes, g.custom_logo".
+ " FROM tt_users u LEFT JOIN tt_groups g ON (u.group_id = g.id) LEFT JOIN tt_roles r on (r.id = u.role_id) WHERE ";
if ($id)
$sql .= "u.id = $id";
else
$this->rank = $val['rank'];
$this->client_id = $val['client_id'];
$this->is_client = $this->client_id && !in_array('track_own_time', $this->rights);
+ if ($val['quota_percent']) $this->quota_percent = $val['quota_percent'];
$this->email = $val['email'];
$this->lang = $val['lang'];
$this->decimal_mark = $val['decimal_mark'];
if (isset($_SESSION['behalf_id'])) {
$this->behalf_id = $_SESSION['behalf_id'];
$this->behalf_name = $_SESSION['behalf_name'];
+
+ $this->behalfUser = new ttBehalfUser($this->behalf_id, $this->org_id);
}
// Set "on behalf" id and name (group).
if (isset($_SESSION['behalf_group_id'])) {
// Unset things first.
$this->behalf_id = null;
$this->behalf_name = null;
+ unset($this->behalfUser);
unset($_SESSION['behalf_id']);
unset($_SESSION['behalf_name']);
$_SESSION['behalf_name'] = $onBehalfUserName;
$this->behalf_id = $user_id;
$this->behalf_name = $onBehalfUserName;
+
+ $this->behalfUser = new ttBehalfUser($this->behalf_id, $this->org_id);
return;
}