From 4070ac772a00d8ffb9590ffdeca10e5d494c26e2 Mon Sep 17 00:00:00 2001 From: Taylor Hurt Date: Tue, 30 Aug 2016 18:39:07 -0400 Subject: [PATCH] adds delete button to edit pages (#10) --- WEB-INF/templates/mobile/client_edit.tpl | 2 +- WEB-INF/templates/mobile/project_edit.tpl | 2 +- WEB-INF/templates/mobile/task_edit.tpl | 2 +- WEB-INF/templates/mobile/user_edit.tpl | 2 +- mobile/client_edit.php | 6 ++ mobile/expense_delete.php | 6 +- mobile/project_edit.php | 6 ++ mobile/task_edit.php | 7 ++ mobile/user_edit.php | 120 ++++++++++++---------- 9 files changed, 90 insertions(+), 63 deletions(-) diff --git a/WEB-INF/templates/mobile/client_edit.tpl b/WEB-INF/templates/mobile/client_edit.tpl index 578aa64e..5cee575b 100644 --- a/WEB-INF/templates/mobile/client_edit.tpl +++ b/WEB-INF/templates/mobile/client_edit.tpl @@ -32,7 +32,7 @@ {/if}   - {$forms.clientForm.btn_save.control} {$forms.clientForm.btn_copy.control} + {$forms.clientForm.btn_save.control} {$forms.clientForm.btn_copy.control} {$forms.clientForm.btn_delete.control} diff --git a/WEB-INF/templates/mobile/project_edit.tpl b/WEB-INF/templates/mobile/project_edit.tpl index c94e4754..b8266f47 100644 --- a/WEB-INF/templates/mobile/project_edit.tpl +++ b/WEB-INF/templates/mobile/project_edit.tpl @@ -36,7 +36,7 @@   - {$forms.projectForm.btn_save.control} {$forms.projectForm.btn_copy.control} + {$forms.projectForm.btn_save.control} {$forms.projectForm.btn_copy.control} {$forms.projectForm.btn_delete.control} diff --git a/WEB-INF/templates/mobile/task_edit.tpl b/WEB-INF/templates/mobile/task_edit.tpl index 5af8d935..f9136284 100644 --- a/WEB-INF/templates/mobile/task_edit.tpl +++ b/WEB-INF/templates/mobile/task_edit.tpl @@ -28,7 +28,7 @@   - {$forms.taskForm.btn_save.control} {$forms.taskForm.btn_copy.control} + {$forms.taskForm.btn_save.control} {$forms.taskForm.btn_copy.control} {$forms.taskForm.btn_delete.control} diff --git a/WEB-INF/templates/mobile/user_edit.tpl b/WEB-INF/templates/mobile/user_edit.tpl index 7f81ca03..cbfded78 100644 --- a/WEB-INF/templates/mobile/user_edit.tpl +++ b/WEB-INF/templates/mobile/user_edit.tpl @@ -105,7 +105,7 @@ function handleClientControl() { {$i18n.label.required_fields} - {$forms.userForm.btn_submit.control} + {$forms.userForm.btn_submit.control} {$forms.userForm.btn_delete.control} diff --git a/mobile/client_edit.php b/mobile/client_edit.php index 2c553daf..cd6266da 100644 --- a/mobile/client_edit.php +++ b/mobile/client_edit.php @@ -70,6 +70,7 @@ if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->t $form->addInput(array('type'=>'checkboxgroup','name'=>'projects','data'=>$projects,'datakeys'=>array('id','name'),'layout'=>'H','value'=>$cl_projects)); $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->getKey('button.save'))); $form->addInput(array('type'=>'submit','name'=>'btn_copy','value'=>$i18n->getKey('button.copy'))); +$form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->getKey('label.delete'))); if ($request->isPost()) { // Validate user input. @@ -112,6 +113,11 @@ if ($request->isPost()) { } else $err->add($i18n->getKey('error.client_exists')); } + + if ($request->getParameter('btn_delete')) { + header("Location: client_delete.php?id=$cl_id"); + exit(); + } } } // isPost diff --git a/mobile/expense_delete.php b/mobile/expense_delete.php index 38800b62..b027bd94 100644 --- a/mobile/expense_delete.php +++ b/mobile/expense_delete.php @@ -26,7 +26,7 @@ // | https://www.anuko.com/time_tracker/credits.htm // +----------------------------------------------------------------------+ -require_once('initialize.php'); +require_once('../initialize.php'); import('form.Form'); import('DateAndTime'); import('ttExpenseHelper'); @@ -74,5 +74,5 @@ $form->addInput(array('type'=>'submit','name'=>'cancel_button','value'=>$i18n->g $smarty->assign('expense_item', $expense_item); $smarty->assign('forms', array($form->getName() => $form->toArray())); $smarty->assign('title', $i18n->getKey('title.delete_expense')); -$smarty->assign('content_page_name', 'expense_delete.tpl'); -$smarty->display('index.tpl'); +$smarty->assign('content_page_name', 'mobile/expense_delete.tpl'); +$smarty->display('mobile/index.tpl'); diff --git a/mobile/project_edit.php b/mobile/project_edit.php index c1eb1804..490a11e2 100644 --- a/mobile/project_edit.php +++ b/mobile/project_edit.php @@ -81,6 +81,7 @@ if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode) $form->addInput(array('type'=>'checkboxgroup','name'=>'tasks','data'=>$all_tasks,'layout'=>'H','value'=>$cl_tasks)); $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->getKey('button.save'))); $form->addInput(array('type'=>'submit','name'=>'btn_copy','value'=>$i18n->getKey('button.copy'))); +$form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->getKey('label.delete'))); if ($request->isPost()) { // Validate user input. @@ -123,6 +124,11 @@ if ($request->isPost()) { } else $err->add($i18n->getKey('error.project_exists')); } + + if ($request->getParameter('btn_delete')) { + header("Location: project_delete.php?id=$cl_project_id"); + exit(); + } } } // isPost diff --git a/mobile/task_edit.php b/mobile/task_edit.php index fd5b35bb..248167ff 100644 --- a/mobile/task_edit.php +++ b/mobile/task_edit.php @@ -65,6 +65,8 @@ $form->addInput(array('type'=>'combobox','name'=>'status','value'=>$cl_status, $form->addInput(array('type'=>'checkboxgroup','name'=>'projects','layout'=>'H','data'=>$projects,'datakeys'=>array('id','name'),'value'=>$cl_projects)); $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->getKey('button.save'))); $form->addInput(array('type'=>'submit','name'=>'btn_copy','value'=>$i18n->getKey('button.copy'))); +$form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->getKey('label.delete'))); + if ($request->isPost()) { // Validate user input. @@ -105,6 +107,11 @@ if ($request->isPost()) { } else $err->add($i18n->getKey('error.task_exists')); } + + if ($request->getParameter('btn_delete')) { + header("Location: task_delete.php?id=$cl_task_id"); + exit(); + } } } // isPost diff --git a/mobile/user_edit.php b/mobile/user_edit.php index 156e320a..6077a13a 100644 --- a/mobile/user_edit.php +++ b/mobile/user_edit.php @@ -161,67 +161,75 @@ $form->addInputElement($table); $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$user_id)); $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.save'))); +$form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->getKey('label.delete'))); if ($request->isPost()) { - // Validate user input. - if (!ttValidString($cl_name)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.person_name')); - if (!ttValidString($cl_login)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.login')); - if (!$auth->isPasswordExternal() && ($cl_password1 || $cl_password2)) { - if (!ttValidString($cl_password1)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.password')); - if (!ttValidString($cl_password2)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password')); - if ($cl_password1 !== $cl_password2) - $err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password')); - } - if (!ttValidEmail($cl_email, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.email')); - if (!ttValidFloat($cl_rate, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('form.users.default_rate')); - - if ($err->no()) { - $existing_user = ttUserHelper::getUserByLogin($cl_login); - if (!$existing_user || ($user_id == $existing_user['id'])) { - - $fields = array( - 'name' => $cl_name, - 'login' => $cl_login, - 'password' => $cl_password1, - 'email' => $cl_email, - 'status' => $cl_status, - 'rate' => $cl_rate, - 'projects' => $assigned_projects); - if (right_assign_roles & $user->rights) { - $fields['role'] = $cl_role; - $fields['client_id'] = $cl_client_id; - } - - if (ttUserHelper::update($user_id, $fields)) { - - // If our own login changed, set new one in cookie to remember it. - if (($user_id == $user->id) && ($user->login != $cl_login)) { - setcookie('tt_login', $cl_login, time() + COOKIE_EXPIRE, '/'); - } - - // In case the name of the "on behalf" user has changed - set it in session. - if (($user->behalf_id == $user_id) && ($user->behalf_name != $cl_name)) { - $_SESSION['behalf_name'] = $cl_name; + if ($request->getParameter('btn_submit')) { + // Validate user input. + if (!ttValidString($cl_name)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.person_name')); + if (!ttValidString($cl_login)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.login')); + if (!$auth->isPasswordExternal() && ($cl_password1 || $cl_password2)) { + if (!ttValidString($cl_password1)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.password')); + if (!ttValidString($cl_password2)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password')); + if ($cl_password1 !== $cl_password2) + $err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password')); + } + if (!ttValidEmail($cl_email, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.email')); + if (!ttValidFloat($cl_rate, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('form.users.default_rate')); + + if ($err->no()) { + $existing_user = ttUserHelper::getUserByLogin($cl_login); + if (!$existing_user || ($user_id == $existing_user['id'])) { + + $fields = array( + 'name' => $cl_name, + 'login' => $cl_login, + 'password' => $cl_password1, + 'email' => $cl_email, + 'status' => $cl_status, + 'rate' => $cl_rate, + 'projects' => $assigned_projects); + if (right_assign_roles & $user->rights) { + $fields['role'] = $cl_role; + $fields['client_id'] = $cl_client_id; } - - // If we deactivated our own account, do housekeeping and logout. - if ($user->id == $user_id && !is_null($cl_status) && $cl_status == INACTIVE) { - // Remove tt_login cookie that stores login name. - unset($_COOKIE['tt_login']); - setcookie('tt_login', NULL, -1); - - $auth->doLogout(); - header('Location: login.php'); + + if (ttUserHelper::update($user_id, $fields)) { + + // If our own login changed, set new one in cookie to remember it. + if (($user_id == $user->id) && ($user->login != $cl_login)) { + setcookie('tt_login', $cl_login, time() + COOKIE_EXPIRE, '/'); + } + + // In case the name of the "on behalf" user has changed - set it in session. + if (($user->behalf_id == $user_id) && ($user->behalf_name != $cl_name)) { + $_SESSION['behalf_name'] = $cl_name; + } + + // If we deactivated our own account, do housekeeping and logout. + if ($user->id == $user_id && !is_null($cl_status) && $cl_status == INACTIVE) { + // Remove tt_login cookie that stores login name. + unset($_COOKIE['tt_login']); + setcookie('tt_login', NULL, -1); + + $auth->doLogout(); + header('Location: login.php'); + exit(); + } + + header('Location: users.php'); exit(); - } - - header('Location: users.php'); - exit(); - + + } else + $err->add($i18n->getKey('error.db')); } else - $err->add($i18n->getKey('error.db')); - } else - $err->add($i18n->getKey('error.user_exists')); + $err->add($i18n->getKey('error.user_exists')); + } + } + + if ($request->getParameter('btn_delete')) { + header("Location: user_delete.php?id=$user_id"); + exit(); } } // isPost -- 2.20.1