public function action_edit() { $type = $this->request->param('id'); $id = Arr::get($_GET, 'id'); $uoms = DB::select('id', 'name')->from('uoms')->execute()->as_array('id', 'name'); $form = new Form('items/edit/' . $type . '?id=' . ($id ?: '')); $form->add('code', 'Code', Form::STRING, '', array('not_empty'))->add('name', 'Name', Form::STRING, '', array('not_empty')); if ($type == 'item') { $table = 'items'; $form->add('descr', 'Description', Form::TEXT); } else { $table = 'bom_items'; } $form->add('uom', 'UOM', Form::SELECT, array(0 => 'Not selected') + $uoms); $item = DB::select()->from($table)->where('id', '=', $id)->execute()->current(); $form->values($item); if ($_POST) { $value = $form->filter($_POST); if (!$form->validate($value)) { if ($id) { DB::update($table)->set($value)->where('id', '=', $id)->execute(); } else { $id = Arr::get(DB::insert($table, array_keys($value))->values(array_values($value))->execute(), 0, 0); } $value['id'] = $id; $value['success'] = true; $value['uom'] = Arr::get($uoms, $value['uom'], 'Unknown'); if (isset($value['descr'])) { $value['descr'] = nl2br($value['descr']); } die(json_encode($value)); } } $this->response->body($form->render()); }
public function action_edit() { $id = $this->request->param('id'); $form = new Form('security/groups/edit' . ($id ? '/' . $id : '')); $form->add("name", 'Name', Form::STRING, '', array('not_empty'))->add('is_admin', 'Administrative group', Form::BOOL)->add('show_all_jobs', 'Show all jobs (unchecked - show only assigned jobs)', Form::BOOL)->add('allow_assign', 'Allow assigning jobs', Form::BOOL)->add('allow_reports', 'Allow tracking changes', Form::BOOL)->add('allow_submissions', 'Allow tracking submissions', Form::BOOL)->add('allow_finance', 'Financial reports', Form::BOOL)->add('allow_forms', 'Forms submission', Form::BOOL)->add('allow_custom_forms', 'Custom forms submission', Form::BOOL)->add('edit_custom_forms', 'Edit custom forms reports', Form::BOOL)->add('time_machine', 'Time Machine', Form::BOOL); $form->add('columns', 'Show columns in job search', Form::INFO); foreach (Columns::$fixed as $key => $value) { $form->add($key, $value, Form::BOOL); } $item = $id ? Group::get($id) : array(); if ($item) { $columns = explode(',', $item['columns']); foreach ($columns as $column) { $item[$column] = 1; } unset($item['columns']); } $form->values($item); if ($_POST) { $value = $form->filter($_POST); if ($value['is_admin']) { $value['show_all_jobs'] = 1; $value['allow_assign'] = 1; $value['allow_reports'] = 1; $value['allow_submissions'] = 1; $value['allow_finance'] = 1; $value['allow_forms'] = 0; $value['allow_custom_forms'] = 1; $value['edit_custom_forms'] = 1; $value['time_machine'] = 1; $value['columns'] = implode(',', array_keys(Columns::$fixed)); } else { $columns = array(); foreach (Columns::$fixed as $key => $name) { if (Arr::get($value, $key)) { $columns[] = $key; } } $value['columns'] = implode(',', $columns); } $value = array_diff_key($value, Columns::$fixed); if (!$form->validate($value)) { if ($id) { DB::update('groups')->set($value)->where('id', '=', $id)->execute(); } else { $origin = Arr::get($_POST, 'permissions'); unset($_POST['permissions']); $id = Arr::get(DB::insert('groups', array_keys($value))->values(array_values($value))->execute(), 0); DB::query(Database::INSERT, DB::expr("INSERT INTO `group_columns` (`group_id`, `column_id`, `permissions`) \n (SELECT :id, `column_id`, `permissions` FROM `group_columns` WHERE `group_id` = :origin)")->param(':id', $id)->param(':origin', $origin)->compile())->execute(); } Messages::save('Group successfully saved!', 'success'); $this->redirect('/security/groups'); } } if (!$id) { $groups = DB::select('id', 'name')->from('groups')->execute()->as_array('id', 'name'); $form->add('permissions', 'Copy permissions from group', Form::SELECT, $groups); } $this->response->body($form->render()); }
public function action_edit() { $id = $this->request->param('id'); $groups = DB::select()->from('groups')->execute()->as_array('id', 'name'); $companies = DB::select()->from('companies')->execute()->as_array('id', 'name'); $form = new Form('users/edit' . ($id ? '/' . $id : '')); $form->add("login", 'Login', Form::STRING, '', array('not_empty', 'min_length' => array(':value', 4)))->add('name', 'Real Name', Form::STRING)->add('group_id', 'Group', Form::SELECT, array(0 => 'Not selected') + $groups, array('not_empty'))->add('company_id', 'Company', Form::SELECT, array(0 => 'Not selected') + $companies, array('not_empty'))->add("email", 'E-Mail', Form::STRING, '', array('not_empty', 'email'))->add('is_admin', 'Admin', Form::BOOL); $form->add('passw', 'Password', Form::PASSWORD, '', $id ? false : array('not_empty', 'min_length' => array(':value', 6)))->add('pass2', 'Confirm password', Form::PASSWORD, '', array('matches' => array(':validation', 'pass2', 'passw'))); $item = $id ? User::get($id) : array(); $form->values($item); $error = false; if ($_POST) { $item = $form->filter($_POST); $error = $form->validate($item); if (!$error) { unset($item['pass2']); $exists = DB::select('id')->from('users')->where_open()->where('login', '=', $item['login'])->or_where('email', '=', $item['email'])->where_close()->and_where('id', '<>', $id)->execute()->get('id'); if ($exists) { if ($this->request->is_ajax()) { $item['success'] = false; $item['error'] = 'exists'; header('Content-type: application/json'); die(json_encode($item)); } Messages::save("User with given login or email already exists! Please, enter different login/email!"); } else { if ($id) { if (!Arr::get($item, 'passw')) { unset($item['passw']); } DB::update('users')->set($item)->where('id', '=', $id)->execute(); } else { $result = DB::insert('users', array_keys($item))->values(array_values($item))->execute(); $id = Arr::get($result, 0); } $item['id'] = $id; $item['success'] = true; $item['group'] = Arr::get($groups, $item['group_id'], 'Unknown'); $item['company'] = Arr::get($companies, $item['company_id'], 'Unknown'); if ($this->request->is_ajax()) { header('Content-type: application/json'); die(json_encode($item)); } Messages::save('User successfully saved!', 'success'); $this->redirect('/users'); } } elseif ($this->request->is_ajax()) { $item['success'] = false; $item['error'] = $error; header('Content-type: application/json'); die(json_encode($item)); } $form->values($item); } $this->response->body($form->render($error)); }
public function action_edit() { $id = $this->request->param('id'); $form = new Form('security/users/edit' . ($id ? '/' . $id : '')); $groups = DB::select('id', 'name')->from('groups')->execute()->as_array('id', 'name'); $partners = DB::select('id', 'name')->from('companies')->execute()->as_array('id', 'name'); $regions = DB::select('id', 'name')->from('regions')->execute()->as_array('id', 'name'); $form->add("login", 'Login', Form::STRING, '', array('not_empty', 'min_length' => array(':value', 4)))->add("email", 'E-Mail', Form::STRING, '', array('not_empty', 'email'))->add('group_id', 'Group', Form::SELECT, array('' => 'Please select...') + $groups, array('not_empty'), array('class' => 'multiselect'))->add('company_id', 'Partner', Form::SELECT, array('' => 'None') + $partners, null, array('class' => 'multiselect'))->add('default_region', 'Default region', Form::SELECT, array(0 => 'None') + $regions, null, array('class' => 'multiselect')); $form->add('region[]', 'Available regions', Form::SELECT, $regions, null, array('multiple' => 'multiple', 'class' => 'multiselect')); $form->add('passw', 'Password', Form::PASSWORD, '', $id ? false : array('not_empty', 'min_length' => array(':value', 6)))->add('pass2', 'Confirm password', Form::PASSWORD, '', array('matches' => array(':validation', 'pass2', 'passw'))); $item = $id ? User::get($id) : array(); if ($id) { $item['region[]'] = DB::select('region_id')->from('user_regions')->where('user_id', '=', $id)->execute()->as_array(NULL, 'region_id') ?: false; } $form->values($item); $error = false; if ($_POST) { $item = $form->filter($_POST); if (!$form->validate($item)) { unset($item['pass2']); $exists = DB::select('id')->from('users')->where_open()->where('login', '=', $item['login'])->or_where('email', '=', $item['email'])->where_close()->and_where('id', '<>', $id)->execute()->get('id'); if ($exists) { Messages::save("User with given login or email already exists! Please, enter different login/email!"); } else { $regs = Arr::get($_POST, 'region'); if ($id) { if (!Arr::get($item, 'passw')) { unset($item['passw']); } DB::update('users')->set($item)->where('id', '=', $id)->execute(); DB::delete('user_regions')->where('user_id', '=', $id)->execute(); } else { $result = DB::insert('users', array_keys($item))->values(array_values($item))->execute(); $id = Arr::get($result, 0); } if ($regs) { $result = DB::insert('user_regions', array('user_id', 'region_id')); foreach ($regs as $reg) { $result->values(array($id, $reg)); } $result->execute(); } Messages::save('User successfully saved!', 'success'); $this->redirect('/security/users'); } } $form->values($item); } $this->response->body($form->render($error)); }
public function action_edit() { $id = $this->request->param('id'); if (!User::current('is_admin') && !(Group::current('item_create') && !$id) && !(Group::current('item_edit') && $id)) { throw new HTTP_Exception_403('Forbidden'); } $uoms = DB::select()->from('uoms')->execute()->as_array('id', 'name'); $form = new Form('items/edit' . ($id ? '/' . $id : '')); $form->add("sku", 'SKU/Barcode', Form::STRING, '', array('not_empty'))->add("name", 'Description', Form::STRING, '', array('not_empty'))->add("uom", 'UOM', Form::SELECT, array(0 => 'Not selected') + $uoms, array('not_empty'))->add("cost", 'Cost (each)', Form::NUMBER, '', array('not_empty'))->add("qty", 'Qty Tracked', Form::BOOL); if ($id) { $item = DB::select()->from('items')->where('id', '=', $id)->execute()->current(); } else { $item = array(); } $form->values($item); $error = false; if ($_POST) { $item = $form->filter($_POST); $error = $form->validate($item); if (!$error) { if ($id) { DB::update('items')->set($item)->where('id', '=', $id)->execute(); } else { $result = DB::insert('items', array_keys($item))->values(array_values($item))->execute(); $id = Arr::get($result, 0); } $item['id'] = $id; $item['success'] = true; if ($this->request->is_ajax()) { $item['uom'] = Arr::get($uoms, Arr::get($item, 'uom', 0), 'Unknown'); header('Content-type: application/json'); die(json_encode($item)); } Messages::save('Item successfully saved!', 'success'); $this->redirect('/items'); } elseif ($this->request->is_ajax()) { $item['success'] = false; $item['error'] = $error; header('Content-type: application/json'); die(json_encode($item)); } $form->values($item); } $this->response->body($form->render($error)); }
public function action_edit() { $id = $this->request->param('id'); $form = new Form('groups/edit' . ($id ? '/' . $id : '')); $form->add("name", 'Name', Form::STRING, '', array('not_empty')); $roles = DB::select()->from('roles')->execute()->as_array('id', 'name'); foreach ($roles as $key => $role) { $form->add($key, $role, Form::BOOL); } $item = $id ? Group::get($id) : array(); $form->values($item); if ($_POST) { $value = $form->filter($_POST); if (!$form->validate($value)) { Database::instance()->begin(); if ($id) { DB::update('groups')->set(array('name' => $value['name']))->where('id', '=', $id)->execute(); DB::delete('group_roles')->where('group_id', '=', $id)->execute(); } else { $id = Arr::get(DB::insert('groups', array('name'))->values(array($value['name']))->execute(), 0); } $list = array(); foreach ($roles as $key => $role) { if (Arr::get($_POST, $key)) { $list[] = array($id, $key); } } if ($list) { $query = DB::insert('group_roles', array('group_id', 'role_id')); foreach ($list as $role) { $query->values($role); } $query->execute(); } Database::instance()->commit(); $value['id'] = $id; $value['success'] = true; die(json_encode($value)); //Messages::save('Group successfully saved!', 'success'); //$this->redirect('/groups'); } } $this->response->body($form->render()); }
public function action_edit() { $id = $this->request->param('id'); $form = new Form('address/edit' . ($id ? '/' . $id : '')); $form->add("name", 'Site Name', Form::STRING, '', array('not_empty'))->add("address", 'Delivery Address', Form::STRING, '', array('not_empty'))->add("contact", 'Attention to', Form::STRING, '', array('not_empty'))->add("phone", 'Phone Number', Form::STRING, '', array('not_empty'))->add("note", 'Note', Form::TEXT); if ($id) { $item = DB::select()->from('address')->where('id', '=', $id)->execute()->current(); } else { $item = array(); } $form->values($item); $error = false; if ($_POST) { $item = $form->filter($_POST); $error = $form->validate($item); if (!$error) { if ($id) { DB::update('address')->set($item)->where('id', '=', $id)->execute(); } else { $result = DB::insert('address', array_keys($item))->values(array_values($item))->execute(); $id = Arr::get($result, 0); } $item['id'] = $id; $item['success'] = true; if ($this->request->is_ajax()) { header('Content-type: application/json'); die(json_encode($item)); } Messages::save('Address successfully saved!', 'success'); $this->redirect('/address'); } elseif ($this->request->is_ajax()) { $item['success'] = false; $item['error'] = $error; header('Content-type: application/json'); die(json_encode($item)); } $form->values($item); } $this->response->body($form->render($error)); }
public function action_edit() { $id = $this->request->param('id'); $form = new Form('projects/edit' . ($id ? '/' . $id : '')); $form->add("client_code", 'Client Code', Form::STRING, '', array('not_empty'))->add("internal_code", 'Internal Code', Form::STRING, '', array('not_empty'))->add("name", 'Project Name', Form::STRING, '', array('not_empty')); if ($id) { $item = DB::select()->from('projects')->where('id', '=', $id)->execute()->current(); } else { $item = array(); } $form->values($item); $error = false; if ($_POST) { $item = $form->filter($_POST); $error = $form->validate($item); if (!$error) { if ($id) { DB::update('projects')->set($item)->where('id', '=', $id)->execute(); } else { $result = DB::insert('projects', array_keys($item))->values(array_values($item))->execute(); $id = Arr::get($result, 0); } $item['id'] = $id; $item['success'] = true; if ($this->request->is_ajax()) { header('Content-type: application/json'); die(json_encode($item)); } Messages::save('Project successfully saved!', 'success'); $this->redirect('/projects'); } elseif ($this->request->is_ajax()) { $item['success'] = false; $item['error'] = $error; header('Content-type: application/json'); die(json_encode($item)); } $form->values($item); } $this->response->body($form->render($error)); }
public function action_edit() { $id = $this->request->param('id'); $form = new Form('companies/edit' . ($id ? '/' . $id : '')); $form->add("logo", 'Logo', Form::IMAGE)->add("name", 'Project Name', Form::STRING, '', array('not_empty'))->add("prefix", 'Order Number Prefix', Form::STRING, '', array('not_empty'))->add("abn", 'ABN', Form::STRING, '', array('not_empty'))->add("address", 'Address', Form::STRING, '', array('not_empty'))->add("contact", 'Contact Name', Form::STRING, '', array('not_empty'))->add("phone", 'Contact Phone', Form::STRING, '', array('not_empty'))->add("email", 'E-Mail', Form::STRING, '', array('not_empty', 'email'))->add("note", 'Note', Form::TEXT)->add("note2", 'Note2', Form::TEXT); if ($id) { $item = DB::select()->from('companies')->where('id', '=', $id)->execute()->current(); } else { $item = array(); } $form->values($item); $error = false; if ($_POST) { $item = $form->filter($_POST); $error = $form->validate($item); if (!$error) { if ($id) { DB::update('companies')->set($item)->where('id', '=', $id)->execute(); } else { $result = DB::insert('companies', array_keys($item))->values(array_values($item))->execute(); $id = Arr::get($result, 0); } $item['id'] = $id; $item['success'] = true; if ($this->request->is_ajax()) { header('Content-type: application/json'); die(json_encode($item)); } Messages::save('Company successfully saved!', 'success'); $this->redirect('/companies'); } elseif ($this->request->is_ajax()) { $item['success'] = false; $item['error'] = $error; header('Content-type: application/json'); die(json_encode($item)); } $form->values($item); } $this->response->body($form->render($error)); }
public function action_edit() { $id = $this->request->param('id'); $form = new Form('security/companies/edit' . ($id ? '/' . $id : '')); $types = DB::select('id', 'name')->from('company_types')->execute()->as_array('id', 'name'); $form->add("name", 'Name', Form::STRING, '', array('not_empty'))->add('type', 'Company type', Form::SELECT, $types, array('not_empty')); $item = DB::select()->from('companies')->where('id', '=', $id)->execute()->current(); $form->values($item); if ($_POST) { $value = $form->filter($_POST); if (!$form->validate($value)) { if ($id) { DB::update('companies')->set($value)->where('id', '=', $id)->execute(); } else { DB::insert('companies', array_keys($value))->values(array_values($value))->execute(); } Messages::save('Company successfully saved!', 'success'); $this->redirect('/security/companies'); } } $this->response->body($form->render()); }
public function action_edit() { $id = $this->request->param('id'); $form = new Form('companies/edit' . ($id ? '/' . $id : '')); $form->add("name", 'Name', Form::STRING, '', array('not_empty')); $item = DB::select()->from('companies')->where('id', '=', $id)->execute()->current(); $form->values($item); if ($_POST) { $value = $form->filter($_POST); if (!$form->validate($value)) { Database::instance()->begin(); if ($id) { DB::update('companies')->set(array('name' => $value['name']))->where('id', '=', $id)->execute(); } else { $id = Arr::get(DB::insert('companies', array('name'))->values(array($value['name']))->execute(), 0); } Database::instance()->commit(); $value['id'] = $id; $value['success'] = true; die(json_encode($value)); } } $this->response->body($form->render()); }