2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 require_once('initialize.php');
31 import('ttUserHelper');
32 import('ttRoleHelper');
35 if (!ttAccessAllowed('administer_site')) {
36 header('Location: access_denied.php');
40 if ($request->isPost()) {
41 $cl_team_name = trim($request->getParameter('team_name'));
42 $cl_lang = $request->getParameter('lang');
43 $cl_manager_name = trim($request->getParameter('manager_name'));
44 $cl_manager_login = trim($request->getParameter('manager_login'));
45 if (!$auth->isPasswordExternal()) {
46 $cl_password1 = $request->getParameter('password1');
47 $cl_password2 = $request->getParameter('password2');
49 $cl_manager_email = trim($request->getParameter('manager_email'));
51 $cl_lang = $i18n->lang; // Browser setting from initialize.php.
53 $form = new Form('teamForm');
54 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'team_name','value'=>$cl_team_name));
56 // Prepare an array of available languages.
57 $lang_files = I18n::getLangFileList();
58 foreach ($lang_files as $lfile) {
59 $content = file(RESOURCE_DIR."/".$lfile);
61 foreach ($content as $line) {
62 if (strstr($line, 'i18n_language')) {
63 $a = explode('=', $line);
64 $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
69 $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
71 $longname_lang = mu_sort($longname_lang, 'name');
72 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 200px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
74 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_name','value'=>$cl_manager_name));
75 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_login','value'=>$cl_manager_login));
76 if (!$auth->isPasswordExternal()) {
77 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password1','value'=>$cl_password1));
78 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password2','value'=>$cl_password2));
80 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_email','value'=>$cl_manager_email));
81 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.submit')));
83 if ($request->isPost()) {
86 * Note: creating a group by admin is pretty much the same as self-registration,
87 * except that created_by fields for group and user must be set to admin account.
88 * Therefore, we'll reuse ttRegistrator instance to create a group here
89 * and override created_by fields using ttRegistrator::setCreatedBy() function.
92 // Create fields array for ttRegistrator instance.
93 if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
95 'user_name' => $cl_manager_name,
96 'login' => $cl_manager_login,
97 'password1' => $cl_password1,
98 'password2' => $cl_password2,
99 'email' => $cl_manager_email,
100 'group_name' => $cl_team_name,
101 'currency' => CURRENCY_DEFAULT,
104 // Create an instance of ttRegistrator class.
105 import('ttRegistrator');
106 $registrator = new ttRegistrator($fields, $err);
107 $registrator->register();
108 $registrator->setCreatedBy($user->id); // Override created_by to admin account.
110 header('Location: admin_groups.php');
115 $smarty->assign('auth_external', $auth->isPasswordExternal());
116 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
117 $smarty->assign('onload', 'onLoad="document.teamForm.team.focus()"');
118 $smarty->assign('content_page_name', 'admin_team_add.tpl');
119 $smarty->assign('title', $i18n->get('title.create_group'));
120 $smarty->display('index.tpl');