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');
35 if (!ttAccessAllowed('administer_site')) {
36 header('Location: access_denied.php');
39 // End of access checks.
41 if ($request->isPost()) {
42 $cl_group_name = trim($request->getParameter('group_name'));
43 $cl_lang = $request->getParameter('lang');
44 $cl_manager_name = trim($request->getParameter('manager_name'));
45 $cl_manager_login = trim($request->getParameter('manager_login'));
46 if (!$auth->isPasswordExternal()) {
47 $cl_password1 = $request->getParameter('password1');
48 $cl_password2 = $request->getParameter('password2');
50 $cl_manager_email = trim($request->getParameter('manager_email'));
52 $cl_lang = $i18n->lang; // Browser setting from initialize.php.
54 $form = new Form('groupForm');
55 $form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'group_name','value'=>$cl_group_name));
57 // Prepare an array of available languages.
58 $lang_files = I18n::getLangFileList();
59 foreach ($lang_files as $lfile) {
60 $content = file(RESOURCE_DIR."/".$lfile);
62 foreach ($content as $line) {
63 if (strstr($line, 'i18n_language')) {
64 $a = explode('=', $line);
65 $lname = trim(str_replace(';','',str_replace("'","",$a[1])));
70 $longname_lang[] = array('id'=>I18n::getLangFromFilename($lfile),'name'=>$lname);
72 $longname_lang = mu_sort($longname_lang, 'name');
73 $form->addInput(array('type'=>'combobox','name'=>'lang','style'=>'width: 200px','data'=>$longname_lang,'datakeys'=>array('id','name'),'value'=>$cl_lang));
75 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_name','value'=>$cl_manager_name));
76 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_login','value'=>$cl_manager_login));
77 if (!$auth->isPasswordExternal()) {
78 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password1','value'=>$cl_password1));
79 $form->addInput(array('type'=>'password','maxlength'=>'30','name'=>'password2','value'=>$cl_password2));
81 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'manager_email','value'=>$cl_manager_email));
82 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.submit')));
84 if ($request->isPost()) {
85 // Validate user input.
86 if (!ttValidString($cl_group_name))
87 $err->add($i18n->get('error.field'), $i18n->get('label.group_name'));
88 if (!ttValidString($cl_manager_name))
89 $err->add($i18n->get('error.field'), $i18n->get('label.manager_name'));
90 if (!ttValidString($cl_manager_login))
91 $err->add($i18n->get('error.field'), $i18n->get('label.manager_login'));
92 if (ttUserHelper::getUserByLogin($cl_manager_login))
93 $err->add($i18n->get('error.user_exists'));
94 if (!ttValidString($cl_password1))
95 $err->add($i18n->get('error.field'), $i18n->get('label.password'));
96 if (!ttValidString($cl_password2))
97 $err->add($i18n->get('error.field'), $i18n->get('label.confirm_password'));
98 if ($cl_password1 !== $cl_password2)
99 $err->add($i18n->get('error.not_equal'), $i18n->get('label.password'), $i18n->get('label.confirm_password'));
100 if (!ttValidEmail($cl_manager_email, true))
101 $err->add($i18n->get('error.field'), $i18n->get('label.email'));
102 if (!ttUserHelper::canAdd())
103 $err->add($i18n->get('error.user_count'));
105 if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
108 if (ttAdmin::createOrg(array('group_name' => $cl_group_name,
109 'currency' => CURRENCY_DEFAULT,
111 'user_name' => $cl_manager_name,
112 'login' => $cl_manager_login,
113 'password' => $cl_password1,
114 'email' => $cl_manager_email))) {
115 header('Location: admin_groups.php');
118 $err->add($i18n->get('error.db'));
123 $smarty->assign('auth_external', $auth->isPasswordExternal());
124 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
125 $smarty->assign('onload', 'onLoad="document.groupForm.group_name.focus()"');
126 $smarty->assign('content_page_name', 'admin_group_add.tpl');
127 $smarty->assign('title', $i18n->get('title.add_group'));
128 $smarty->display('index.tpl');