From caa61e7cf00098a2cd64d0d716abb2d6b09982e7 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Mon, 3 Dec 2018 20:24:43 +0000 Subject: [PATCH] Refactoring of client config pages for subgroups. --- WEB-INF/lib/ttClientHelper.class.php | 75 ++++++++++++++++--------- WEB-INF/templates/client_add.tpl | 4 +- WEB-INF/templates/client_edit.tpl | 2 +- WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/mobile/client_add.tpl | 4 +- client_add.php | 10 ++-- mobile/client_add.php | 10 ++-- 7 files changed, 63 insertions(+), 44 deletions(-) diff --git a/WEB-INF/lib/ttClientHelper.class.php b/WEB-INF/lib/ttClientHelper.class.php index 9009f570..42eb128a 100644 --- a/WEB-INF/lib/ttClientHelper.class.php +++ b/WEB-INF/lib/ttClientHelper.class.php @@ -54,14 +54,16 @@ class ttClientHelper { } // getClients - returns an array of active and inactive clients in a group. - static function getClients() - { + static function getClients() { global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; $result = array(); - $mdb2 = getConnection(); - $sql = "select id, name from tt_clients where group_id = ".$user->getGroup()." and (status = 0 or status = 1) order by upper(name)"; + $sql = "select id, name from tt_clients where group_id = $group_id and org_id = $org_id and (status = 0 or status = 1) order by upper(name)"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { @@ -73,13 +75,14 @@ class ttClientHelper { // The getClientByName looks up a client by name. static function getClientByName($client_name) { - - $mdb2 = getConnection(); global $user; + $mdb2 = getConnection(); - $sql = "select id from tt_clients where group_id = ".$user->getGroup(). - " and name = ".$mdb2->quote($client_name)." and (status = 1 or status = 0)"; + $group_id = $user->getGroup(); + $org_id = $user->org_id; + $sql = "select id from tt_clients where group_id = $group_id and org_id = $org_id". + " and name = ".$mdb2->quote($client_name)." and (status = 1 or status = 0)"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { $val = $res->fetchRow(); @@ -92,11 +95,13 @@ class ttClientHelper { // The getDeletedClient looks up a deleted client by id. static function getDeletedClient($client_id) { - - $mdb2 = getConnection(); global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; - $sql = "select name, address from tt_clients where group_id = ".$user->getGroup(). + $sql = "select name, address from tt_clients where group_id = $group_id and org_id = $org_id". " and id = $client_id and status is NULL"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { @@ -108,22 +113,26 @@ class ttClientHelper { // The delete function marks client as deleded. static function delete($id, $delete_client_entries) { - - $mdb2 = getConnection(); global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; // Handle custom field log records. if ($delete_client_entries) { - $sql = "update tt_custom_field_log set status = NULL where log_id in (select id from tt_log where client_id = $id and status = 1)"; + $sql = "update tt_custom_field_log set status = null". + " where log_id in (select id from tt_log where client_id = $id and status = 1) and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); - if (is_a($affected, 'PEAR_Error')) - return false; + if (is_a($affected, 'PEAR_Error')) + return false; } // Handle time records. $modified_part = ', modified = now(), modified_ip = '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', modified_by = '.$user->id; if ($delete_client_entries) { - $sql = 'update tt_log set status = NULL'.$modified_part." where client_id = $id"; + $sql = 'update tt_log set status = null'.$modified_part. + " where client_id = $id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -131,7 +140,8 @@ class ttClientHelper { // Handle expense items. if ($delete_client_entries) { - $sql = 'update tt_expense_items set status = NULL'.$modified_part." where client_id = $id"; + $sql = 'update tt_expense_items set status = null'.$modified_part. + " where client_id = $id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -139,26 +149,30 @@ class ttClientHelper { // Handle invoices. if ($delete_client_entries) { - $sql = "update tt_invoices set status = NULL where client_id = $id and group_id = ".$user->getGroup(); + $sql = "update tt_invoices set status = null". + " where client_id = $id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; } // Delete project binds to this client. - $sql = "delete from tt_client_project_binds where client_id = $id"; + $sql = "delete from tt_client_project_binds". + " where client_id = $id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; // Handle users for client. - $sql = 'update tt_users set status = NULL'.$modified_part." where client_id = $id and group_id = ".$user->getGroup(); + $sql = 'update tt_users set status = null'.$modified_part. + " where client_id = $id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; // Mark client deleted. - $sql = "update tt_clients set status = NULL where id = $id and group_id = ".$user->getGroup(); + $sql = "update tt_clients set status = null". + " where id = $id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } @@ -169,8 +183,9 @@ class ttClientHelper { global $user; $mdb2 = getConnection(); - $group_id = (int) $fields['group_id']; - $org_id = (int) $fields['org_id']; + $group_id = $user->getGroup(); + $org_id = $user->org_id; + $name = $fields['name']; $address = $fields['address']; $tax = $fields['tax']; @@ -204,8 +219,11 @@ class ttClientHelper { // The update function updates a client record in tt_clients table. static function update($fields) { - $mdb2 = getConnection(); global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; $id = $fields['id']; $name = $fields['name']; @@ -218,13 +236,14 @@ class ttClientHelper { if ($tax == '') $tax = 0; // Insert client to project binds into tt_client_project_binds table. - $sql = "delete from tt_client_project_binds where client_id = $id"; + $sql = "delete from tt_client_project_binds". + " where client_id = $id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) die($affected->getMessage()); if (count($projects) > 0) foreach ($projects as $p_id) { - $sql = "insert into tt_client_project_binds (client_id, project_id) values($id, $p_id)"; + $sql = "insert into tt_client_project_binds (client_id, project_id, group_id, org_id) values($id, $p_id, $group_id, $org_id)"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -234,7 +253,7 @@ class ttClientHelper { $comma_separated = implode(",", $projects); // This is a comma-separated list of associated project ids. $sql = "update tt_clients set name = ".$mdb2->quote($name).", address = ".$mdb2->quote($address). ", tax = $tax, projects = ".$mdb2->quote($comma_separated).", status = $status". - " where group_id = ".$user->getGroup()." and id = ".$id; + " where id = $id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } diff --git a/WEB-INF/templates/client_add.tpl b/WEB-INF/templates/client_add.tpl index 8db93a41..db10ede4 100644 --- a/WEB-INF/templates/client_add.tpl +++ b/WEB-INF/templates/client_add.tpl @@ -13,14 +13,14 @@ {$i18n.label.tax}, %: - {$forms.clientForm.tax.control} (0{$user->decimal_mark}00) + {$forms.clientForm.tax.control} (0{$user->getDecimalMark()}00) {$i18n.label.required_fields}   -{if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)} +{if $show_projects} {$i18n.label.projects}: {$forms.clientForm.projects.control} diff --git a/WEB-INF/templates/client_edit.tpl b/WEB-INF/templates/client_edit.tpl index 92319b68..12f6bf0d 100644 --- a/WEB-INF/templates/client_edit.tpl +++ b/WEB-INF/templates/client_edit.tpl @@ -13,7 +13,7 @@ {$i18n.label.tax}, %: - {$forms.clientForm.tax.control} (0{$user->decimal_mark}00) + {$forms.clientForm.tax.control} (0{$user->getDecimalMark()}00) {$i18n.label.status}: diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index ba7efd42..2031cbf1 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- - + -{if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)} +{if $show_projects} diff --git a/client_add.php b/client_add.php index b14e8b45..4d26e2a1 100644 --- a/client_add.php +++ b/client_add.php @@ -54,11 +54,13 @@ if ($request->isPost()) { // $cl_projects[] = $project_item['id']; } +$show_projects = (MODE_PROJECTS == $user->getTrackingMode() || MODE_PROJECTS_AND_TASKS == $user->getTrackingMode()) && count($projects) > 0; + $form = new Form('clientForm'); $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','style'=>'width: 350px;','value'=>$cl_name)); $form->addInput(array('type'=>'textarea','name'=>'address','maxlength'=>'255','style'=>'width: 350px; height: 80px;','value'=>$cl_address)); $form->addInput(array('type'=>'floatfield','name'=>'tax','size'=>'10','format'=>'.2','value'=>$cl_tax)); -if (MODE_PROJECTS == $user->getTrackingMode() || MODE_PROJECTS_AND_TASKS == $user->getTrackingMode()) +if ($show_projects) $form->addInput(array('type'=>'checkboxgroup','name'=>'projects','data'=>$projects,'layout'=>'H','datakeys'=>array('id','name'),'value'=>$cl_projects)); $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.add'))); @@ -70,10 +72,7 @@ if ($request->isPost()) { if ($err->no()) { if (!ttClientHelper::getClientByName($cl_name)) { - if (ttClientHelper::insert(array( - 'group_id' => $user->getGroup(), - 'org_id' => $user->org_id, - 'name' => $cl_name, + if (ttClientHelper::insert(array('name' => $cl_name, 'address' => $cl_address, 'tax' => $cl_tax, 'projects' => $cl_projects, @@ -89,6 +88,7 @@ if ($request->isPost()) { $smarty->assign('forms', array($form->getName()=>$form->toArray())); $smarty->assign('onload', 'onLoad="document.clientForm.name.focus()"'); +$smarty->assign('show_projects',$show_projects); $smarty->assign('title', $i18n->get('title.add_client')); $smarty->assign('content_page_name', 'client_add.tpl'); $smarty->display('index.tpl'); diff --git a/mobile/client_add.php b/mobile/client_add.php index f5cc5b69..2050204a 100644 --- a/mobile/client_add.php +++ b/mobile/client_add.php @@ -54,11 +54,13 @@ if ($request->isPost()) { // $cl_projects[] = $project_item['id']; } +$show_projects = (MODE_PROJECTS == $user->getTrackingMode() || MODE_PROJECTS_AND_TASKS == $user->getTrackingMode()) && count($projects) > 0; + $form = new Form('clientForm'); $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','value'=>$cl_name)); $form->addInput(array('type'=>'textarea','name'=>'address','maxlength'=>'255','class'=>'mobile-textarea','value'=>$cl_address)); $form->addInput(array('type'=>'floatfield','name'=>'tax','size'=>'10','format'=>'.2','value'=>$cl_tax)); -if (MODE_PROJECTS == $user->getTrackingMode() || MODE_PROJECTS_AND_TASKS == $user->getTrackingMode()) +if ($show_projects) $form->addInput(array('type'=>'checkboxgroup','name'=>'projects','data'=>$projects,'layout'=>'H','datakeys'=>array('id','name'),'value'=>$cl_projects)); $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.add'))); @@ -70,10 +72,7 @@ if ($request->isPost()) { if ($err->no()) { if (!ttClientHelper::getClientByName($cl_name)) { - if (ttClientHelper::insert(array( - 'group_id' => $user->getGroup(), - 'org_id' => $user->org_id, - 'name' => $cl_name, + if (ttClientHelper::insert(array('name' => $cl_name, 'address' => $cl_address, 'tax' => $cl_tax, 'projects' => $cl_projects, @@ -89,6 +88,7 @@ if ($request->isPost()) { $smarty->assign('forms', array($form->getName()=>$form->toArray())); $smarty->assign('onload', 'onLoad="document.clientForm.name.focus()"'); +$smarty->assign('show_projects',$show_projects); $smarty->assign('title', $i18n->get('title.add_client')); $smarty->assign('content_page_name', 'mobile/client_add.tpl'); $smarty->display('mobile/index.tpl'); -- 2.20.1
 Anuko Time Tracker 1.18.29.4575 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4576 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/mobile/client_add.tpl b/WEB-INF/templates/mobile/client_add.tpl index 8db93a41..db10ede4 100644 --- a/WEB-INF/templates/mobile/client_add.tpl +++ b/WEB-INF/templates/mobile/client_add.tpl @@ -13,14 +13,14 @@
{$i18n.label.tax}, %:{$forms.clientForm.tax.control} (0{$user->decimal_mark}00){$forms.clientForm.tax.control} (0{$user->getDecimalMark()}00)
{$i18n.label.required_fields}
 
{$i18n.label.projects}: {$forms.clientForm.projects.control}