Some more work in progress on group editor.
authorNik Okuntseff <support@anuko.com>
Wed, 21 Nov 2018 23:05:10 +0000 (23:05 +0000)
committerNik Okuntseff <support@anuko.com>
Wed, 21 Nov 2018 23:05:10 +0000 (23:05 +0000)
WEB-INF/lib/ttGroupHelper.class.php
WEB-INF/lib/ttUser.class.php
WEB-INF/templates/footer.tpl
group_add.php

index 6ddffaa..41c0311 100644 (file)
@@ -59,4 +59,45 @@ class ttGroupHelper {
     }
     return false;
   }
+
+  // The getSubgroupByName obtain an immediate subgroup by name if one exists.
+  static function getSubgroupByName($name) {
+    global $user;
+
+    $mdb2 = getConnection();
+    $parent_id = $user->getActiveGroup();
+    $org_id = $user->org_id;
+
+    $sql = "select id from tt_groups where parent_id = $parent_id and org_id = $org_id".
+      " and name = ".$mdb2->quote($name)." and status is not null";
+    $res = $mdb2->query($sql);
+    if (!is_a($res, 'PEAR_Error')) {
+      $val = $res->fetchRow();
+      if ($val && $val['id'])
+        return $val;
+    }
+    return false;
+  }
+
+  // The insertSubgroup inserts a new subgroup in database.
+  static function insertSubgroup($fields) {
+    global $user;
+
+    $mdb2 = getConnection();
+    $parent_id = $user->getActiveGroup();
+    $org_id = $user->org_id;
+
+    // TODO: inherit all attributes from the parent group, if not supplied.
+    $name = $fields['name'];
+    $description = $fields['description'];
+
+    $created = 'now()';
+    $created_ip = $mdb2->quote($_SERVER['REMOTE_ADDR']);
+
+    $sql = "insert into tt_groups (parent_id, org_id, name, description, created, created_ip)".
+      " values($parent_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($description).", $created, $created_ip)";
+    $affected = $mdb2->exec($sql);
+    return (!is_a($affected, 'PEAR_Error'));
+    // TODO: design subgroup roles carefully. Perhaps roles are not to be touched in subgroups at all.
+  }
 }
index 8617454..8e9a8f2 100644 (file)
@@ -414,11 +414,11 @@ class ttUser {
   function getSubgroups() {
     $mdb2 = getConnection();
 
-    $sql = "select id, name from tt_groups where org_id = $this->org_id and parent_id = ".$this->getActiveGroup();;
+    $sql = "select id, name, description from tt_groups where org_id = $this->org_id and parent_id = ".$this->getActiveGroup();;
     $res = $mdb2->query($sql);
     if (!is_a($res, 'PEAR_Error')) {
       while ($val = $res->fetchRow()) {
-        $groups[] = array('id'=>$val['id'],'name'=>$val['name']);
+        $groups[] = $val; // array('id'=>$val['id'],'name'=>$val['name']);
       }
     }
     return $groups;
index c1be43a..4a73172 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.18.26.4491 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.18.26.4492 | Copyright &copy; <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>
index 4e8cb91..f39ec01 100644 (file)
@@ -28,6 +28,7 @@
 
 require_once('initialize.php');
 import('form.Form');
+import('ttGroupHelper');
 
 // Access checks.
 if (!ttAccessAllowed('manage_subgroups')) {
@@ -42,7 +43,7 @@ if ($request->isPost()) {
 }
 
 $form = new Form('groupForm');
-$form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'group_name','value'=>$cl_group,'enable'=>$advanced_settings));
+$form->addInput(array('type'=>'text','maxlength'=>'200','name'=>'group_name','value'=>$cl_name));
 $form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
 $form->addInput(array('type'=>'submit','name'=>'btn_add','value'=>$i18n->get('button.add')));
 
@@ -50,29 +51,23 @@ if ($request->isPost()) {
   // Validate user input.
   if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name'));
   if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
-/*
+
   if ($err->no()) {
-    if (!ttProjectHelper::getProjectByName($cl_name)) {
-      if (ttProjectHelper::insert(array(
-        'group_id' => $user->getActiveGroup(),
-        'org_id' => $user->org_id,
+    if (!ttGroupHelper::getSubgroupByName($cl_name)) {
+       if (ttGroupHelper::insertSubgroup(array(
         'name' => $cl_name,
-        'description' => $cl_description,
-        'users' => $cl_users,
-        'tasks' => $cl_tasks,
-        'status' => ACTIVE))) {
-          header('Location: projects.php');
+        'description' => $cl_description))) {
+          header('Location: groups.php');
           exit();
         } else
           $err->add($i18n->get('error.db'));
     } else
       $err->add($i18n->get('error.object_exists'));
   }
-*/
 } // isPost
 
 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
-//$smarty->assign('onload', 'onLoad="document.projectForm.project_name.focus()"');
+$smarty->assign('onload', 'onLoad="document.groupForm.group_name.focus()"');
 $smarty->assign('title', $i18n->get('title.add_group'));
 $smarty->assign('content_page_name', 'group_add.tpl');
 $smarty->display('index.tpl');