function add_note($userid, $adminid, $source, $content) { $db = new DbConn(); $db->exec('insert into notes (userid, adminid, source, content, created) values (?, ?, ?, ?, ?)', $userid, $adminid, $source, $content, date_create()); $noteId = $db->last_insert_id(); log_event(LOG_NOTE_ADDED, $userid, $noteId); }
function create_user($firstname, $lastname, $email, $password) { $db = new DbConn(); if (0 == $db->exec('insert into users (firstname, lastname, email, password) values (?, ?, ?, ?)', $firstname, $lastname, $email, $password)) { throw new RuntimeException('A database error occurred'); } $newId = $db->last_insert_id(); log_event(LOG_USER_CREATED, $newId); schedule_mail($newId, MAIL_INTRO); return get_user($newId); }
<?php require_once 'common.inc'; $id = $_POST['id']; $subject = $_POST['subject']; $htmlbody = $_POST['htmlbody']; $textbody = html_to_plaintext($htmlbody); $db = new DbConn(); if (!$id) { # New template $db->exec('insert into mail_templates () values ()'); $id = $db->last_insert_id(); } $rows = $db->exec('insert into mail_template_versions (templateid, subject, html, plaintext) values (?, ?, ?, ?)', (int) $id, $subject, $htmlbody, $textbody); if ($rows != 1) { throw new RuntimeException("Insertion failed!"); } redirect("list.php?highlight={$id}");
function upload() { if ($_FILES['file']['error'] !== UPLOAD_ERR_OK) { echo 'File upload failed'; die($_FILES['file']['error']); } $filename = $_FILES['file']['name']; $filetype = $_FILES['file']['type']; $filesize = filesize($_FILES['file']['tmp_name']); $db = new DbConn(); $db->exec('insert into mail_attachments (filename, type, size) values (?, ?, ?)', $filename, $filetype, $filesize); $fileId = $db->last_insert_id(); $destfile = make_attachment_path($fileId); if (!move_uploaded_file($_FILES['file']['tmp_name'], $destfile)) { die('Upload failed'); } $this->load->view('admin/header'); $this->load->view('admin/mail/uploaded', array('fileid' => $fileId, 'filename' => $filename, 'filesize' => $filesize, 'filetype' => $filetype)); $this->load->view('admin/footer'); }