Skip to content
Snippets Groups Projects
Commit 1ad0420a authored by vtigerosm's avatar vtigerosm
Browse files

Vtlib api to add settings link in CRM

parents d318e9cc 3ad65038
No related branches found
No related tags found
No related merge requests found
......@@ -764,4 +764,55 @@ function vtlib_mime_content_type($filename) {
return Vtiger_Functions::mime_content_type($filename);
}
/**
* Function to add settings entry in CRM settings page
* @param string $linkName
* @param string $linkURL
* @param string $blockName
* @return boolean true/false
*/
function vtlib_addSettingsLink($linkName, $linkURL, $blockName = false) {
$success = true;
$db = PearDatabase::getInstance();
//Check entry name exist in DB or not
$result = $db->pquery('SELECT 1 FROM vtiger_settings_field WHERE name=?', array($linkName));
if ($result && !$db->num_rows($result)) {
$blockId = 0;
if ($blockName) {
$blockId = getSettingsBlockId($blockName);//Check block name exist in DB or not
}
if (!$blockId) {
$blockName = 'LBL_OTHER_SETTINGS';
$blockId = getSettingsBlockId($blockName);//Check block name exist in DB or not
}
//Add block in to DB if not exists
if (!$blockId) {
$blockSeqResult = $db->pquery('SELECT MAX(sequence) AS sequence FROM vtiger_settings_blocks', array());
if ($db->num_rows($blockSeqResult)) {
$blockId = $db->getUniqueID('vtiger_settings_blocks');
$blockSequence = $db->query_result($blockSeqResult, 0, 'sequence');
$db->pquery('INSERT INTO vtiger_settings_blocks(blockid, label, sequence) VALUES(?,?,?)', array($blockId, 'LBL_OTHER_SETTINGS', $blockSequence++));
}
}
//Add settings field in to DB
if ($blockId) {
$fieldSeqResult = $db->pquery('SELECT MAX(sequence) AS sequence FROM vtiger_settings_field WHERE blockid=?', array($blockId));
if ($db->num_rows($fieldSeqResult)) {
$fieldId = $db->getUniqueID('vtiger_settings_field');
$linkURL = ($linkURL) ? $linkURL : '';
$fieldSequence = $db->query_result($fieldSeqResult, 0, 'sequence');
$db->pquery('INSERT INTO vtiger_settings_field(fieldid, blockid, name, iconpath, description, linkto, sequence, active, pinned) VALUES(?,?,?,?,?,?,?,?,?)', array($fieldId, $blockId, $entryName, '', $entryName, $linkURL, $fieldSequence++, 0, 0));
}
} else {
$success = false;
}
}
return $success;
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment