PHP File Manager
Editing File: Notes.php
<?php /* * Copyright (C) Wayne Purton-Smith - All Rights Reserved * Unauthorized copying of this file or removing this paragraph, via any medium is strictly prohibited * Proprietary and confidential * Written by Wayne Purton-Smith <waynepurtonsmith@hotmail.co.uk> February 2014 */ class Notes extends CI_Model { public function get($note_id = 0, $url = NULL, $order_completed = false) { $limit = NULL; $sql = "SELECT `pn`.*, `m`.`first_name`, IF(`pn`.`solved` IS NOT NULL, 1, 0) AS `is_solved` FROM `page_notes` `pn` INNER JOIN `members` `m` ON `m`.`user_id` = `pn`.`created_by` WHERE `pn`.`is_deleted` = 0"; if(($note_id = (int) $note_id) > 0) { $sql .= " AND `pn`.`note_id` = $note_id "; $limit = 1; } if($url !== NULL) { $url = '/' . trim($url, '/'); $sql .= " AND `pn`.`page` = " . $this->db->escape($url) . " "; } $sql .= " ORDER BY " . (($order_completed) ? '`is_solved` ASC, ' : '') . " `pn`.`date` DESC, `pn`.`page` "; $result = $this->db->query($sql); if($result->num_rows()) { if($limit === 1) return $result->row(); $rows = $result->result(); $result->free_result(); return $rows; } } public function save($data = array(), $note_id = 0) { $note_id = (($note_id = (int) $note_id) > 0) ? $note_id : 0; $is_update = ($note_id > 0); $note_contents = trim($data['note']); if(strlen($note_contents)) { $sql_data = array ( 'created_by' => $this->users->user_id, 'page' => $data['url'], 'note' => $data['note'], 'date' => time() ); if($is_update) { unset($sql_data['created_by'], $sql_data['page'], $sql_data['date']); $sql = $this->db->update_string('page_notes', $sql_data, "`note_id` = $note_id"); } else { $sql = $this->db->insert_string('page_notes', $sql_data); } $this->db->query($sql); return ($this->db->affected_rows() === 1); } return false; } public function solve($note_id = 0) { if(($note_id = (int) $note_id) > 0) { $this->db->query($this->db->update_string('page_notes', array('solved' => time()), "`note_id` = $note_id")); return true; } return false; } public function delete($note_id = 0) { if(($note_id = (int) $note_id) > 0) { $this->db->query($this->db->update_string('page_notes', array('is_deleted' => true), "`note_id` = $note_id")); return true; } return false; } }
Cancel