<commit_before><?php
/**
 * ownCloud - passman
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright <NAME> 2014
 */
namespace OCA\Passman\Db;

use \OCP\IDb;
use \OCP\DB\insertid;

class ItemManager {
	private $userid;
	private $db;
	public function __construct($db) {
		$this -> db = $db;

	}

	/**
	 * List items in a folder
	 */
	public function listItems($folderId, $userId) {
		$sql = 'SELECT id,label,folderid FROM `*PREFIX*passman_items` WHERE `folderid`= ? AND `user_id` = ?';
		$query = $this -> db -> prepareQuery($sql);
		$query -> bindParam(1, $folderId, \PDO::PARAM_INT);
		$query -> bindParam(2, $userId, \PDO::PARAM_INT);
		$result = $query -> execute();
		$rows = array();
		while ($row = $result -> fetchRow()) {
			$rows[$row['id']] = $row;
		}
		return $rows;
	}

	/**
	 * Move an item to another folder
	 */
	public function moveItem($itemId,$folderId,$userId){
		$sql = 'UPDATE `*PREFIX*passman_items` SET folderid=? where id=? and user_id=?';
		$query = $this -> db -> prepareQuery($sql);
		$query -> bindParam(1, $folderId, \PDO::PARAM_INT);
		$query -> bindParam(2, $itemId, \PDO::PARAM_INT);
		$query -> bindParam(3, $userId, \PDO::PARAM_STR);
		$result = $query -> execute();
		return array('success'=>'true');
	}
	/**
	 * List items in a folder
	 */
	public function search($itemName, $userId) {
		$sql = 'SELECT i.id,i.label,i.folderid,i.description,i.account,i.email,f.title as foldername FROM `oc_passman_items` as i inner join `oc_passman_folders` as f on i.folderid=f.id WHERE `label` LIKE ? AND `i`.`user_id` = ?;';
		$sql .= ' UNION '; 
		$sql .= 'SELECT id as folderid, title as label, null as description, null as account, null as email,null as id null as foldername FROM `*PREFIX*passman_folders` WHERE `title` LIKE ? AND `user_id` = ? ORDER BY folderid asc;';
		$result = $this -> db -> prepareQuery($sql) -> execute(array('%'.$itemName . '%', $userId,'%'.$itemName . '%', $userId));
		$rows = array(); 
		while ($row = $result -> fetchRow()) {
			$rows[] = $row;
		}
		return $rows;
	}

	/**
	 * Get A single item
	 */
	public function get($itemId, $userId) {
		$sql = 'SELECT * FROM `*PREFIX*passman_items` WHERE `id`= ? AND `user_id` = ?';
		$query = $this -> db -> prepareQuery($sql);
		$query -> bindParam(1, $itemId, \PDO::PARAM_INT);
		$query -> bindParam(2, $userId, \PDO::PARAM_STR);
		$result = $query -> execute();
		return $result -> fetchRow();
	}

	/**
	 * Insert item
	 */
	public function insert($item) {
		$sql = 'INSERT INTO `*PREFIX*passman_items` (`user_id`,`folderid`,`label`,`description`,`password`,`account`,`email`,`url`,`expire_time`)';
		$sql .= ' VALUES (?,?,?,?,?,?,?,?,?)';
		$query = $this -> db -> prepareQuery($sql);<commit_msg>SQL Fix<commit_after><?php
/**
 * ownCloud - passman
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright S<NAME> 2014
 */
namespace OCA\Passman\Db;

use \OCP\IDb;
use \OCP\DB\insertid;

class ItemManager {
	private $userid;
	private $db;
	public function __construct($db) {
		$this -> db = $db;

	}

	/**
	 * List items in a folder
	 */
	public function listItems($folderId, $userId) {
		$sql = 'SELECT id,label,folderid FROM `*PREFIX*passman_items` WHERE `folderid`= ? AND `user_id` = ?';
		$query = $this -> db -> prepareQuery($sql);
		$query -> bindParam(1, $folderId, \PDO::PARAM_INT);
		$query -> bindParam(2, $userId, \PDO::PARAM_INT);
		$result = $query -> execute();
		$rows = array();
		while ($row = $result -> fetchRow()) {
			$rows[$row['id']] = $row;
		}
		return $rows;
	}

	/**
	 * Move an item to another folder
	 */
	public function moveItem($itemId,$folderId,$userId){
		$sql = 'UPDATE `*PREFIX*passman_items` SET folderid=? where id=? and user_id=?';
		$query = $this -> db -> prepareQuery($sql);
		$query -> bindParam(1, $folderId, \PDO::PARAM_INT);
		$query -> bindParam(2, $itemId, \PDO::PARAM_INT);
		$query -> bindParam(3, $userId, \PDO::PARAM_STR);
		$result = $query -> execute();
		return array('success'=>'true');
	}
	/**
	 * List items in a folder
	 */
	public function search($itemName, $userId) {
		$sql = 'SELECT i.id,i.label,i.folderid,i.description,i.account,i.email,f.title as foldername FROM `oc_passman_items` as i inner join `oc_passman_folders` as f on i.folderid=f.id WHERE `label` LIKE ? AND `i`.`user_id` = ?';
		$sql .= ' UNION '; 
		$sql .= 'SELECT id as folderid, title as label, null as description, null as account, null as email,null as id, null as foldername FROM `*PREFIX*passman_folders` WHERE `title` LIKE ? AND `user_id` = ? ORDER BY folderid asc;';
		$result = $this -> db -> prepareQuery($sql) -> execute(array('%'.$itemName . '%', $userId,'%'.$itemName . '%', $userId));
		$rows = array(); 
		while ($row = $result -> fetchRow()) {
			$rows[] = $row;
		}
		return $rows;
	}

	/**
	 * Get A single item
	 */
	public function get($itemId, $userId) {
		$sql = 'SELECT * FROM `*PREFIX*passman_items` WHERE `id`= ? AND `user_id` = ?';
		$query = $this -> db -> prepareQuery($sql);
		$query -> bindParam(1, $itemId, \PDO::PARAM_INT);
		$query -> bindParam(2, $userId, \PDO::PARAM_STR);
		$result = $query -> execute();
		return $result -> fetchRow();
	}

	/**
	 * Insert item
	 */
	public function insert($item) {
		$sql = 'INSERT INTO `*PREFIX*passman_items` (`user_id`,`folderid`,`label`,`description`,`password`,`account`,`email`,`url`,`expire_time`)';
		$sql .= ' VALUES (?,?,?,?,?,?,?,?,?)';
		$query = $this -> db -> prepareQuery($sql);
{'fraction_non_alphanumeric': 0.19960721299767897, 'fraction_numerical': 0.004284949116229245, 'mean_word_length': 3.931338028169014, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3347960', 'n_tokens_mistral': 2125, 'n_tokens_neox': 2002, 'n_words': 518}