public function delete($id = 0) { if ($id != 0) { // Create and delete profile $profile = new profile($id); $profile->delete(); } else { $database = $_SESSION['database']; $this->id = $database->prepare_input($this->id); $profiles_query = $database->query("delete from " . TABLE_PROFILES . " where profiles_id = '" . (int) $this->id . "'"); // Reset id, otherwise one might think this profile (still) exists in db $this->id = 0; } }
function run() { global $user; global $layout; global $DB; $out = ''; $item = new profile(); switch ($_REQUEST['act']) { case 'json': case 1: // json data retrieval & operations switch ($_REQUEST['oper']) { case 'del': // remove rows $ids = $_REQUEST['ids']; foreach ($ids as $id) { $item->load($id); $item->delete(); } echo json_encode(true); break; default: // list or search $page = intval($_REQUEST['page']); $max = intval($_REQUEST['rows']); $offset = ($page - 1) * $max; $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord']; $where = " 1=1 "; if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) { if (isset($_REQUEST['quicksearch'])) { $where .= $item->quicksearch($_REQUEST['quicksearch']); } else { if (isset($_REQUEST['filters'])) { $where .= navitable::jqgridsearch($_REQUEST['filters']); } else { // single search $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']); } } } $DB->queryLimit('id,name', 'nv_profiles', $where, $orderby, $offset, $max); $dataset = $DB->result(); $total = $DB->foundRows(); //echo $DB->get_last_error(); $out = array(); for ($i = 0; $i < count($dataset); $i++) { $out[$i] = array(0 => $dataset[$i]['id'], 1 => $dataset[$i]['name']); } navitable::jqgridJson($out, $page, $offset, $max, $total); break; } session_write_close(); exit; break; case 'edit': case 2: // edit/new form if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); } if (isset($_REQUEST['form-sent'])) { $item->load_from_post(); try { $item->save(); permission::update_permissions(json_decode($_REQUEST['navigate_permissions_changes'], true), $item->id, 0); $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } } $out = profiles_form($item); break; case 'delete': case 4: // remove if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); if ($item->delete() > 0) { $layout->navigate_notification(t(55, 'Item removed successfully.'), false); $out = profiles_list(); } else { $layout->navigate_notification(t(56, 'Unexpected error.'), false); $out = profiles_form($item); } } break; case 'list': case 0: // list / search result // list / search result default: $out = profiles_list(); break; } return $out; }
} } } break; case 'delete_entry': // Check for dependencies $administration_profile = new profile($_POST['profiles_id']); if ($administration_profile->has_dependencies()) { $error_level = 2; // Related employee(s) exist $_POST['action'] = ''; } break; case 'delete_entry_confirmed': $administration_profile = new profile($_POST['profiles_id']); $administration_profile->delete(); unset($_POST['profiles_id']); $_POST['action'] = ''; break; } // Create a new profile object with id == 0 (default) $_SESSION['profile'] = new profile(); // header // require DIR_WS_INCLUDES . 'header.php'; ?> <!-- body //--> <table border="0" width="100%" cellspacing="3" cellpadding="3"> <tr> <td width="<?php echo BOX_WIDTH; ?>