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');
 
  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()) {
 
  87    * Note: creating a group by admin is pretty much the same as self-registration,
 
  88    * except that created_by fields for group and user must be set to admin account.
 
  89    * Therefore, we'll reuse ttRegistrator instance to create a group here
 
  90    * and override created_by fields using ttRegistrator::setCreatedBy() function.
 
  93   // Create fields array for ttRegistrator instance.
 
  94   if (!defined('CURRENCY_DEFAULT')) define('CURRENCY_DEFAULT', '$');
 
  96     'user_name' => $cl_manager_name,
 
  97     'login' => $cl_manager_login,
 
  98     'password1' => $cl_password1,
 
  99     'password2' => $cl_password2,
 
 100     'email' => $cl_manager_email,
 
 101     'group_name' => $cl_group_name,
 
 102     'currency' => CURRENCY_DEFAULT,
 
 104     'created_by_id' => $user->id);
 
 106   // Create an instance of ttRegistrator class.
 
 107   import('ttRegistrator');
 
 108   $registrator = new ttRegistrator($fields, $err);
 
 109   $registrator->register();
 
 111     header('Location: admin_groups.php');
 
 116 $smarty->assign('auth_external', $auth->isPasswordExternal());
 
 117 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
 
 118 $smarty->assign('onload', 'onLoad="document.groupForm.group_name.focus()"');
 
 119 $smarty->assign('content_page_name', 'admin_group_add.tpl');
 
 120 $smarty->assign('title', $i18n->get('title.create_group'));
 
 121 $smarty->display('index.tpl');