return false;
}
- // The getRoleByRank looks up a role by its rank.
+ // The getTopManagerRoleID obtains an ID for top manager role.
+ static function getTopManagerRoleID() {
+ $mdb2 = getConnection();
+
+ $sql = "select id from tt_roles where team_id = 0 and rank = 512";
+ $res = $mdb2->query($sql);
+
+ if (!is_a($res, 'PEAR_Error')) {
+ $val = $res->fetchRow();
+ if ($val['id'])
+ return $val['id'];
+ }
+ return false;
+ }
+
+ // The getRoleID looks up a role by its rank.
static function getRoleByRank($rank) {
global $user;
$mdb2 = getConnection();
return false;
}
+ // createPredefinedRoles - creates a set of predefined roles for the team to use.
+ static function createPredefinedRoles($team_id, $lang)
+ {
+ // We need localized role names and a new I18n object to obtain them.
+ import('I18n');
+ $i18n = new I18n();
+ $i18n->load($lang);
+
+ $mdb2 = getConnection();
+
+ $rights_client = 'view_own_data,manage_own_settings';
+ $rights_user = 'data_entry,view_own_data,manage_own_settings,view_users';
+ $rights_supervisor = $rights_user.',on_behalf_data_entry,view_data,override_punch_mode,swap_roles,approve_timesheets';
+ $rights_comanager = $rights_supervisor.',manage_users,manage_projects,manage_tasks,manage_custom_fields,manage_clients,manage_invoices';
+ $rights_manager = $rights_comanager.',manage_features,manage_basic_settings,manage_advanced_settings,manage_roles,export_data,manage_subgroups';
+
+ // Active roles.
+ $name = $mdb2->quote($i18n->getKey('role.user.label'));
+ $description = $mdb2->quote($i18n->getKey('role.user.description'));
+ $rights = $mdb2->quote($rights_user);
+ $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($team_id, $name, $description, 4, $rights, 1)";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
+
+ $name = $mdb2->quote($i18n->getKey('role.client.label'));
+ $description = $mdb2->quote($i18n->getKey('role.client.description'));
+ $rights = $mdb2->quote($rights_client);
+ $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($team_id, $name, $description, 16, $rights, 1)";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
+
+ $name = $mdb2->quote($i18n->getKey('role.comanager.label'));
+ $description = $mdb2->quote($i18n->getKey('role.comanager.description'));
+ $rights = $mdb2->quote($rights_comanager);
+ $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($team_id, $name, $description, 68, $rights, 1)";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
+
+ $name = $mdb2->quote($i18n->getKey('role.manager.label'));
+ $description = $mdb2->quote($i18n->getKey('role.manager.description'));
+ $rights = $mdb2->quote($rights_manager);
+ $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($team_id, $name, $description, 324, $rights, 1)";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
+
+ // Inactive roles.
+ $name = $mdb2->quote($i18n->getKey('role.supervisor.label'));
+ $description = $mdb2->quote($i18n->getKey('role.supervisor.description'));
+ $rights = $mdb2->quote($rights_supervisor);
+ $sql = "insert into tt_roles (team_id, name, description, rank, rights, status) values($team_id, $name, $description, 12, $rights, 0)";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
+
+ return true;
+ }
+
// createDefaultRoles - creates a set of predefined roles for the team to use.
static function createDefaultRoles()
{
$status_v = ', '.$mdb2->quote($fields['status']);
}
- $sql = "insert into tt_users (name, login, password, team_id, role, client_id, rate, email $status_f) values (".
+ $sql = "insert into tt_users (name, login, password, team_id, role, role_id, client_id, rate, email $status_f) values (".
$mdb2->quote($fields['name']).", ".$mdb2->quote($fields['login']).
- ", $password, $team_id, $role, ".$mdb2->quote($fields['client_id']).", $rate, ".$mdb2->quote($email)." $status_v)";
+ ", $password, $team_id, $role, ".$mdb2->quote($fields['role_id']).", ".$mdb2->quote($fields['client_id']).", $rate, ".$mdb2->quote($email)." $status_v)";
$affected = $mdb2->exec($sql);
// Now deal with project assignment.
<td align="right" nowrap>{$i18n.label.team_name}:</td>
<td>{$forms.teamForm.team_name.control}</td>
</tr>
+ <tr>
+ <td align="right" nowrap>{$i18n.label.language}:</td>
+ <td>{$forms.teamForm.lang.control}</td>
+ </tr>
<tr><td> </td></tr>
<tr>
<td align="right" nowrap>{$i18n.label.manager_name} (*):</td>
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.17.36.4048 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.17.36.4049 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
<a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
<a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
<a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
<td align="right">{$i18n.label.currency}:</td>
<td>{$forms.profileForm.currency.control}</td>
</tr>
+ <tr>
+ <td align="right" nowrap>{$i18n.label.language}:</td>
+ <td>{$forms.profileForm.lang.control}</td>
+ </tr>
<tr><td> </td></tr>
<tr>
<td align="right" nowrap>{$i18n.label.manager_name} (*):</td>
require_once('initialize.php');
import('form.Form');
import('ttUserHelper');
+import('ttRoleHelper');
// Access check.
if (!ttAccessCheck(right_administer_site)) {
if ($request->isPost()) {
$cl_team_name = trim($request->getParameter('team_name'));
+ $cl_lang = $request->getParameter('lang');
$cl_manager_name = trim($request->getParameter('manager_name'));
$cl_manager_login = trim($request->getParameter('manager_login'));
if (!$auth->isPasswordExternal()) {
$cl_password2 = $request->getParameter('password2');
}
$cl_manager_email = trim($request->getParameter('manager_email'));
-}
+} else
+ $cl_lang = $i18n->lang; // Browser setting from initialize.php.
$form = new Form('teamForm');
$form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'team_name','value'=>$cl_team_name));
+
+// Prepare an array of available languages.
+$lang_files = I18n::getLangFileList();
+foreach ($lang_files as $lfile) {
+ $content = file(RESOURCE_DIR."/".$lfile);
+ $lname = '';
+ foreach ($content as $line) {
+ if (strstr($line, 'i18n_language')) {
+ $a = explode('=', $line);
+ $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
+ break;
+ }
+ }
+ unset($content);
+ $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
+}
+$longname_lang = mu_sort($longname_lang, 'name');
+$form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 200px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
+
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_name','value'=>$cl_manager_name));
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_login','value'=>$cl_manager_login));
if (!$auth->isPasswordExternal()) {
if (!ttUserHelper::getUserByLogin($cl_manager_login)) {
// Create a new team.
if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
- $team_id = ttTeamHelper::insert(array('name'=>$cl_team_name,'currency'=>CURRENCY_DEFAULT));
+ $team_id = ttTeamHelper::insert(array('name'=>$cl_team_name,'currency'=>CURRENCY_DEFAULT,'lang'=>$cl_lang));
if ($team_id) {
+ if (!ttRoleHelper::createPredefinedRoles($team_id, $cl_lang))
+ $err->add($i18n->getKey('error.db'));
+
+ $role_id = ttRoleHelper::getTopManagerRoleID();
+
// Team created, now create a team manager.
$user_id = ttUserHelper::insert(array(
'team_id' => $team_id,
'role' => ROLE_MANAGER,
+ 'role_id' => $role_id,
'name' => $cl_manager_name,
'login' => $cl_manager_login,
'password' => $cl_password1,
require_once('initialize.php');
import('form.Form');
import('ttUserHelper');
+import('ttRoleHelper');
if (!isTrue(MULTITEAM_MODE) || $auth->isPasswordExternal()) {
header('Location: login.php');
$cl_team_name = trim($request->getParameter('team_name'));
$cl_currency = trim($request->getParameter('currency'));
if (!$cl_currency) $cl_currency = CURRENCY_DEFAULT;
+ $cl_lang = $request->getParameter('lang');
$cl_manager_name = trim($request->getParameter('manager_name'));
$cl_manager_login = trim($request->getParameter('manager_login'));
$cl_password1 = $request->getParameter('password1');
$cl_password2 = $request->getParameter('password2');
$cl_manager_email = trim($request->getParameter('manager_email'));
-} else
+} else {
$cl_currency = CURRENCY_DEFAULT;
+ $cl_lang = $i18n->lang; // Browser setting from initialize.php.
+}
$form = new Form('profileForm');
$form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'team_name','value'=>$cl_team_name));
$form->addInput(array('type'=>'text','maxlength'=>'7','name'=>'currency','value'=>$cl_currency));
+
+// Prepare an array of available languages.
+$lang_files = I18n::getLangFileList();
+foreach ($lang_files as $lfile) {
+ $content = file(RESOURCE_DIR."/".$lfile);
+ $lname = '';
+ foreach ($content as $line) {
+ if (strstr($line, 'i18n_language')) {
+ $a = explode('=', $line);
+ $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
+ break;
+ }
+ }
+ unset($content);
+ $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
+}
+$longname_lang = mu_sort($longname_lang, 'name');
+$form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 200px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
+
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_name','value'=>$cl_manager_name));
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_login','value'=>$cl_manager_login));
$form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password1','value'=>$cl_password1));
if ($err->no()) {
if (!ttUserHelper::getUserByLogin($cl_manager_login)) {
// Create a new team.
- $team_id = ttTeamHelper::insert(array('name'=>$cl_team_name,'currency'=>$cl_currency));
+ $team_id = ttTeamHelper::insert(array('name'=>$cl_team_name,'currency'=>$cl_currency,'lang'=>$cl_lang));
if ($team_id) {
+ if (!ttRoleHelper::createPredefinedRoles($team_id, $cl_lang))
+ $err->add($i18n->getKey('error.db'));
+
+ $role_id = ttRoleHelper::getTopManagerRoleID();
+
// Team created, now create a team manager.
$user_id = ttUserHelper::insert(array(
'team_id' => $team_id,
- 'role' => ROLE_MANAGER,
+ 'role' => ROLE_MANAGER, // TODO: this is now out of sync (324 vs 512 for new role id). Work in progress.
+ 'role_id' => $role_id,
'name' => $cl_manager_name,
'login' => $cl_manager_login,
'password' => $cl_password1,