<commit_before><?php
/** Credential related Database functions
*
* Copyright (C) 2012 <NAME>
* Released under GNU AGPL V3
* See LICENSE
*
*/ 
defined('_CREDLOCK') or die;


class CredDB extends BTDB{


/** Check Cred Types are specified
*
* @return boolean
*/
function checkCredTypesDefined(){

$sql = "SELECT * FROM #__CredTypes";
$this->setQuery($sql);
return $this->loadResult();
}



/** Delete the credential specified
*
* @arg id INT
*
* @return boolena
*/
function DelCredential($id){
// Log the request
$log = new Logging;
$log->logEntry($id,10);
$ACL = BTMain::buildACLQuery();
$id = $this->stringEscape($id);
$sql = "DELETE FROM #__Cred WHERE id='$id' AND ($ACL)";
$this->setQuery($sql);
return $this->runQuery();

}



/** Retrieve the credential specified
*
* @arg id INT
*
* @return object
*/
function FetchCredential($id){
// Log the request
$log = new Logging;
$log->logEntry($id,9);

$ACL = BTMain::buildACLQuery();

$id = $this->stringEscape($id);

$sql = "SELECT Hash, Clicky, Address, UName, CredType, `hidden`, `Group` FROM #__Cred WHERE id='$id' AND ($ACL)";
$this->setQuery($sql);


return $this->loadResult();
}


/** Fetch All Credentials for a given type
*
* @arg type id
*
* @return object
*/
function getCredsbyType($id){
$id = $this->stringEscape($id);
$ACL = BTMain::buildACLQuery('a');
$CustACL = BTMain::buildACLQuery('b');

$sql = "SELECT a.id, b.Name FROM #__Cred as a LEFT JOIN #__Cust as b on a.cust=b.id WHERE CredType='$id' AND ($ACL) AND ($CustACL)";
$this->setQuery($sql);

return $this->loadResults();



}




/** Add a new Credential Type
*
* @arg Name string
*
* @return boolean
*/
function AddCredType($name){
$crypt = new Crypto;
$name = $crypt->encrypt($name,'CredType');

$name = $this->stringEscape($name);

$sql = "INSERT INTO #__CredTypes (`Name`) VALUES ('$name')";
$this->setQuery($sql);

$id = $this->insertID();

if ($id){
$log = new Logging;
$log->logEntry($id,15);
return $id;
}else{
return false;
}
}



/** Retrieve the available credential types
*
*/
function getCredTypes(){

$sql = "SELECT * FROM #__CredTypes";
$this->setQuery($sql);
return $this->loadResults();
}


/** Retrieve credential type
*
* @arg id INT
*
* @return object
*/
function getCredType($id){
$id = $this->stringEscape($id);
$sql = "SELECT * FROM #__CredTypes WHERE id='$id'";
$this->setQuery($sql);
return $this->loadResult();
}



/** Edit Credential Type
*
* @arg id - INT
* @arg name - string
*
* @return boolean
*/
function editCredType($id,$name){
$crypt = new Crypto;
$id = $this->stringEscape($id);

$name = $crypt->encrypt($name,'CredType');
$name = $this->stringEscape($name);

$sql = "UPDATE #__CredTypes SET `Name`='$name' WHERE id='$id'";
$this->setQuery($sql);

return $this->runQuery();

}



/** Delete credential type and all associated creds
*
* @arg id INT
*
* @return boolean
*/
function DelCredentialType($id){
$id = $this->stringEscape($id);

$sql = "DELETE FROM #__Cred WHERE `CredType`='$id'";
$this->setQuery($sql);
$this->runQuery();

$sql = "DELETE FROM #__CredTypes WHERE id='$id'";
$this->setQuery($sql);
if ($this->runQuery()){
$log = new Logging;
$log->logEntry($id,16);
return true;<commit_msg>Added logging to Credential Type editing. See PHPCRED-34<commit_after><?php
/** Credential related Database functions
*
* Copyright (C) 2012 <NAME>
* Released under GNU AGPL V3
* See LICENSE
*
*/ 
defined('_CREDLOCK') or die;


class CredDB extends BTDB{


/** Check Cred Types are specified
*
* @return boolean
*/
function checkCredTypesDefined(){

$sql = "SELECT * FROM #__CredTypes";
$this->setQuery($sql);
return $this->loadResult();
}



/** Delete the credential specified
*
* @arg id INT
*
* @return boolena
*/
function DelCredential($id){
// Log the request
$log = new Logging;
$log->logEntry($id,10);
$ACL = BTMain::buildACLQuery();
$id = $this->stringEscape($id);
$sql = "DELETE FROM #__Cred WHERE id='$id' AND ($ACL)";
$this->setQuery($sql);
return $this->runQuery();

}



/** Retrieve the credential specified
*
* @arg id INT
*
* @return object
*/
function FetchCredential($id){
// Log the request
$log = new Logging;
$log->logEntry($id,9);

$ACL = BTMain::buildACLQuery();

$id = $this->stringEscape($id);

$sql = "SELECT Hash, Clicky, Address, UName, CredType, `hidden`, `Group` FROM #__Cred WHERE id='$id' AND ($ACL)";
$this->setQuery($sql);


return $this->loadResult();
}


/** Fetch All Credentials for a given type
*
* @arg type id
*
* @return object
*/
function getCredsbyType($id){
$id = $this->stringEscape($id);
$ACL = BTMain::buildACLQuery('a');
$CustACL = BTMain::buildACLQuery('b');

$sql = "SELECT a.id, b.Name FROM #__Cred as a LEFT JOIN #__Cust as b on a.cust=b.id WHERE CredType='$id' AND ($ACL) AND ($CustACL)";
$this->setQuery($sql);

return $this->loadResults();



}




/** Add a new Credential Type
*
* @arg Name string
*
* @return boolean
*/
function AddCredType($name){
$crypt = new Crypto;
$name = $crypt->encrypt($name,'CredType');

$name = $this->stringEscape($name);

$sql = "INSERT INTO #__CredTypes (`Name`) VALUES ('$name')";
$this->setQuery($sql);

$id = $this->insertID();

if ($id){
$log = new Logging;
$log->logEntry($id,15);
return $id;
}else{
return false;
}
}



/** Retrieve the available credential types
*
*/
function getCredTypes(){

$sql = "SELECT * FROM #__CredTypes";
$this->setQuery($sql);
return $this->loadResults();
}


/** Retrieve credential type
*
* @arg id INT
*
* @return object
*/
function getCredType($id){
$id = $this->stringEscape($id);
$sql = "SELECT * FROM #__CredTypes WHERE id='$id'";
$this->setQuery($sql);
return $this->loadResult();
}



/** Edit Credential Type
*
* @arg id - INT
* @arg name - string
*
* @return boolean
*/
function editCredType($id,$name){
$crypt = new Crypto;
$sqid = $this->stringEscape($id);

$name = $crypt->encrypt($name,'CredType');
$name = $this->stringEscape($name);

$sql = "UPDATE #__CredTypes SET `Name`='$name' WHERE id='$sqid'";
$this->setQuery($sql);

$stat = $this->runQuery();

$log = new Logging;
$log->logEntry($id,17);

return $stat;

}



/** Delete credential type and all associated creds
*
* @arg id INT
*
* @return boolean
*/
function DelCredentialType($id){
$id = $this->stringEscape($id);

$sql = "DELETE FROM #__Cred WHERE `CredType`='$id'";
$this->setQuery($sql);
$this->runQuery();

$sql = "DELETE FROM #__CredTypes WHERE id='$id'";
$this->setQuery($sql);
if ($this->runQuery()){
$log = new Logging;
$log->logEntry($id,16);
return true;
{'fraction_non_alphanumeric': 0.19828660436137072, 'fraction_numerical': 0.004361370716510903, 'mean_word_length': 5.051837888784166, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 74, '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': '5272207', 'n_tokens_mistral': 2415, 'n_tokens_neox': 2324, 'n_words': 616}