}
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.
+ }
}
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;
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.18.26.4491 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.18.26.4492 | 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>
require_once('initialize.php');
import('form.Form');
+import('ttGroupHelper');
// Access checks.
if (!ttAccessAllowed('manage_subgroups')) {
}
$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')));
// 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');