public function approve_request($id, $option) { check_if_admin(); if ($option == 1) { $data = array('accepted_by' => $this->session->userdata('id')); $this->db->where('id', $id); $this->db->update('download_requests', $data); } else { $this->db->delete('download_requests', array('id' => $id)); } redirect('requests', 'location', 301); }
public function summary() { check_if_admin(); $data['newline'] = '<br />'; $data["unum"] = $this->Generator_Model->users_count(); $data["dnum"] = $this->Generator_Model->download_count(); $data["tnum"] = $this->Generator_Model->tool_count(); $data['most_id'] = $this->Generator_Model->most_downloaded(); $data['most_name'] = $this->Generator_Model->find_toolname($data['most_id']['tool_id']); $data['weekly_tools'] = $this->Generator_Model->weekly(); $data['total_tools'] = $this->Generator_Model->top_5(); $data['all_tools'] = $this->Tools_Model->all(); $this->load->view('templates/header'); $this->load->view('generator/summary', $data); $this->load->view('templates/footer'); }
public function add() { check_if_admin(); $data; if (isset($_POST['btnAdd'])) { $input = array("title" => $_POST['title'], "author" => $_POST['author'], "year" => $_POST['year'], "url" => $_POST['url']); $data["error"] = verify_data($input); if ($data["error"]["count"] == 0) { $pubdetails["title"] = $input["title"]; $pubdetails["author"] = $input["author"]; $pubdetails["year"] = $input["year"]; $pubdetails["url"] = $input["url"]; $pub = $this->publication_model->insert($pubdetails); header('Location: new'); } } $this->load->view('templates/header'); if (empty($data)) { $this->load->view('publication/new'); } else { $this->load->view('publication/new', $data); } $this->load->view('templates/footer'); }
return $problems; } // checks if the user has admin privileges // magic cookie contains hash of the username and either "is_an_admin" or // "just_a_user" appended based on the privileges function check_if_admin($username, $magic_cookie) { // check if the user that is logged in has admin privileges if (strcmp($magic_cookie, md5($username . "is_an_admin")) == 0) { return true; } return false; } /*---------------------------------------------------------------------------*/ require 'database.php'; // the PlatesPHP template engine require 'lib/vendor/autoload.php'; $title = "Problemset"; // check if the user is logged in $user_logged_in = isset($_COOKIE['username']); // check whether the user is an admin $admin = $user_logged_in == true ? check_if_admin($_COOKIE['username'], $_COOKIE['huehuehue']) : false; // 1D array of problems which user already solved $solved_problems = $user_logged_in == true ? get_solved_problems($_COOKIE['username'], $dbc) : array(); // 2D array of problems as it is passed to the template // row keys: problem_id, problem_name, published, solved $all_problems = get_problems($solved_problems, $dbc); $data = array('title' => $title, 'problems' => $all_problems, 'admin' => $admin); // render the webpage $templates = new League\Plates\Engine('templates'); echo $templates->render('problemset', $data);
public function add() { check_if_admin(); $data["page"] = "upload"; $data; if (isset($_POST['btnUpload'])) { $input = array("title" => $_POST['title'], "abstract" => $_POST['abstract'], "author" => $_POST['author'], "year" => $_POST['year'], "file" => $_FILES['fileToUpload']["name"], "version" => $_POST['version']); $data["error"] = verify_data($input); if ($data["error"]["count"] == 0) { $toolsdata["name"] = $input["title"]; $toolsdata["abstract"] = $input["abstract"]; $toolsdata["authors"] = $input["author"]; $toolsdata["year"] = $input["year"]; $otherinfo["version"] = $input["version"]; $otherinfo["file"] = $input["file"]; $user = $this->Tools_model->insert($toolsdata, $otherinfo); $config['hostname'] = 'localhost'; $config['username'] = '******'; $config['password'] = '******'; $config['port'] = 21; $config['debug'] = TRUE; $this->ftp->connect($config); $this->ftp->upload($_FILES['fileToUpload']['tmp_name'], '/public/tools/' . $_FILES['fileToUpload']['name'], 'auto'); $this->ftp->close(); header('Location: new'); } } $this->load->view('templates/header'); if (empty($data)) { $this->load->view('tools/new'); } else { $this->load->view('tools/new', $data); } $this->load->view('templates/footer'); }