diff --git a/plugins/Xpa1Rntal/user-preferences/KTUserPreferences.php b/plugins/Xpa1Rntal/user-preferences/KTUserPreferences.php new file mode 100644 index 0000000..35c9cf8 --- /dev/null +++ b/plugins/Xpa1Rntal/user-preferences/KTUserPreferences.php @@ -0,0 +1,89 @@ +verify(); + if ($sessionStatus !== true) { + return false; + } + return true; + } +} + +$oKTUserPreferences = new KTUserPreferences(); + +if (!$oKTUserPreferences->isLoggedIn()) { + echo _kt('Session has expired. Refresh page and login.'); + exit; +} + +switch($_GET['action']){ + case 'getUserPreferences': + + break; + case 'addUserPreferences': + + break; + default: + echo "No action defined"; + break; +} + +exit; +?> \ No newline at end of file diff --git a/plugins/Xpa1Rntal/user-preferences/UserPreferences.inc.php b/plugins/Xpa1Rntal/user-preferences/UserPreferences.inc.php new file mode 100644 index 0000000..98df0d3 --- /dev/null +++ b/plugins/Xpa1Rntal/user-preferences/UserPreferences.inc.php @@ -0,0 +1,212 @@ + "id", + "iUserId" => "user_id", + "sKey" => "prefkey", + "sValue" => "prefvalue", + ); + + public $_bUsePearError = true; + + function UserPreferences($iUserId, $sKey, $sValue) { + $this->iId = -1; + $this->iUserId = $iUserId; + $this->sKey = $sKey; + $this->sValue = $sValue; + } + + /** + * Retrieve UserPreferences objects database table name + * + * @author KnowledgeTree Team + * @access public + * @param none + * @return string + */ + function _table () { return KTUtil::getTableName('user_preferences'); } + + // --------------- + // Getters/setters + // --------------- + /** + * Retrieve a list of UserPreferences objects + * + * @author KnowledgeTree Team + * @access public + * @param $sWhereClause - string + * @param $aOptions - array + * @return UserPreferences objects - array + */ + public function getList($sWhereClause = null, $aOptions = null) { + if (is_null($aOptions)) { $aOptions = array(); } + $aOptions['orderby'] = KTUtil::arrayGet($aOptions, 'orderby','name'); + + return KTEntityUtil::getList2('UserPreferences', $sWhereClause, $aOptions); + } + + public function getUserPreferences($iUserId, $sKey, $aOptions = null) { + $sWhereClause = "WHERE user_id = '$iUserId' AND prefkey = '$sKey'"; + + return KTEntityUtil::getList2('UserPreferences', $sWhereClause, $aOptions); + } + + /** + * Retrieve a UserPreferences object + * + * @author KnowledgeTree Team + * @access public + * @param $iId - int - Id of template + * @return UserPreferences object + */ + public function get($iId) { return KTEntityUtil::get('UserPreferences', $iId); } + + /** + * Retrieve UserPreferences user id + * + * @author KnowledgeTree Team + * @access public + * @param none + * @return string + */ + public function getUserId() { return $this->iUserId; } + + /** + * Set the user id + * + * @author KnowledgeTree Team + * @access public + * @param $iUserId - string - the user id + * @return none + */ + public function setUserId($iUserId) { $this->iUserId = $iUserId; } + + /** + * + * + * @author KnowledgeTree Team + * @access public + * @param + * @return none + */ + public function setKey($sKey) { $this->sKey = $sKey; } + + /** + * + * + * @author KnowledgeTree Team + * @access public + * @param none + * @return string + */ + public function getKey() { return $this->sKey; } + + /** + * + * + * @author KnowledgeTree Team + * @access public + * @param + * @return none + */ + public function setValue($sValue) { $this->sValue = $sValue; } + + /** + * + * + * @author KnowledgeTree Team + * @access public + * @param none + * @return string + */ + public function getValue() { return $this->sValue; } + + // Utility + + /** + * Set the template name + * + * @author KnowledgeTree Team + * @access public + * @param $sName - string - the template node name + * @param $iParentId - int - the template id + * @return boolean + */ + public function exists($iUserId, $sKey, $sValue) { + return UserPreferencesUtil::userPreferenceExists($iUserId, $sKey, $sValue); + } + + /** + * + * + * @author KnowledgeTree Team + * @access public + * @param $aOptions - array + * @return + */ + public function getAllUserPreferences($userId, $aOptions = null) { + if (is_null($aOptions)) { $aOptions = array(); } + $aOptions['orderby'] = KTUtil::arrayGet($aOptions, 'orderby','name'); + $sWhereClause = "WHERE user_id = '$userId'"; + return KTEntityUtil::getList2('UserPreferences', $sWhereClause, $aOptions); + } +} + +class UserPreferencesUtil { + + /** + * + * + * @author KnowledgeTree Team + * + * @return + */ + function userPreferenceExists($iUserId, $sKey, $sValue) { + $sQuery = "SELECT id, name FROM " . KTUtil::getTableName('user_preferences') . " WHERE user_id = ? AND prefkey = ? AND prefvalue = ?";/*ok*/ + $aParams = array($iUserId, $sKey, $sValue); + $res = DBUtil::getResultArray(array($sQuery, $aParams)); + if (count($res) != 0) { + foreach ($res as $user_pref){ + $userid = isset($user_pref['user_id']) ? $user_pref['user_id'] : ''; + $key = isset($user_pref['prefkey']) ? $user_pref['prefkey'] : ''; + if($sKey == $key && $iUserId == $userid) { + return true; + } + } + return false; + } + return false; + } +} + +?> diff --git a/plugins/Xpa1Rntal/user-preferences/UserPreferencesPlugin.php b/plugins/Xpa1Rntal/user-preferences/UserPreferencesPlugin.php new file mode 100644 index 0000000..95e9650 --- /dev/null +++ b/plugins/Xpa1Rntal/user-preferences/UserPreferencesPlugin.php @@ -0,0 +1,143 @@ +sFriendlyName = _kt('User Preferences Plugin'); + $this->sSQLDir = PLUGINDIR_UserPreferencesPlugin . DIRECTORY_SEPARATOR. 'sql' . DIRECTORY_SEPARATOR; + $this->dir = dirname(__FILE__); + } + + /** + * Basic plugin setup + * + * @param none + * @return none + */ + function setup() { + $this->registerAdminPage("adminuserpreferencesmanagement", + 'adminManageUserPreferencesDispatcher', + 'misc', + _kt('User Preferences'), + _kt('User Preferences'), + 'manageUserPreferences.php', + null); + $this->registerPage('userpreferencesmanagement', 'ManageUserPreferencesDispatcher', 'manageUserPreferences.php'); + $plugin_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR; + require_once(KT_LIB_DIR . '/templating/templating.inc.php'); + $oTemplating =& KTTemplating::getSingleton(); + $oTemplating->addLocation('UserPreferencesPlugin', $plugin_dir.'templates', 'fs.UserPreferencesPlugin.plugin'); + $this->applySQL(); // Create Table + } + + function applySQL() + { + $sql = "select * from user_preferences"; + $result = DBUtil::getResultArray($sql); + + if (!PEAR::isError($result)) + { + return; // if we find the table, we assume it has been applied + } + $filename = $this->sSQLDir . 'user_preferences.sql'; + $content = file_get_contents($filename); + + global $default; + DBUtil::setupAdminDatabase(); + $db = $default->_admindb; + $aQueries = SQLFile::splitSQL($content); + DBUtil::startTransaction(); + $res = DBUtil::runQueries($aQueries, $db); + if (PEAR::isError($res)) { + DBUtil::rollback(); + return $res; + } + DBUtil::commit(); + } + + /** + * Method to setup the plugin on rendering it + * + * @param none + * @return boolean + */ + function run_setup() { + + return true; + } + + /** + * Register the plugin + * + * @return unknown + */ + function register() { + $oEnt = parent::register(); + + return $oEnt; + } + + public function getUserPreferences($iUserId, $sKey) { + $aPref = UserPreferences::getUserPreferences($iUserId, $sKey); + if(PEAR::isError($aPref)) { + return false; + } + if(count($aPref) > 1) { + return false; + } + + foreach ($aPref as $oPref) { + return $oPref->getValue(); + } + } +} + +$oPluginRegistry =& KTPluginRegistry::getSingleton(); +$oPluginRegistry->registerPlugin('UserPreferencesPlugin', 'up.UserPreferencesPlugin.plugin', __FILE__); +?> \ No newline at end of file diff --git a/plugins/Xpa1Rntal/user-preferences/manageUserPreferences.php b/plugins/Xpa1Rntal/user-preferences/manageUserPreferences.php new file mode 100644 index 0000000..a9c7229 --- /dev/null +++ b/plugins/Xpa1Rntal/user-preferences/manageUserPreferences.php @@ -0,0 +1,103 @@ +oUser->getId(), 'zohoWarning'); // Get user preference + if(empty($aUserPreference) || is_null($aUserPreference)) { // Create the prefernce + $oUserPreference = new UserPreferences( $this->oUser->getId(), 'zohoWarning', $sValue); + DBUtil::startTransaction(); + $oUserPreference->create(); + DBUtil::commit(); + } else { + foreach ($aUserPreference as $oUserPreference) { // Access object + if($oUserPreference->getValue() != $sValue) { // Update preference + $oUserPreference->setValue($sValue); + DBUtil::startTransaction(); + $oUserPreference->update(); + DBUtil::commit(); + } + } + } + } + exit(); + } + + public function do_setPreference($sKey, $sValue) { + + } +} + +class adminManageUserPreferencesDispatcher extends ManageUserPreferencesDispatcher { + var $bAdminRequired = true; + var $sSection = 'administration'; + + function adminManageUserPreferencesDispatcher() { + $this->aBreadcrumbs = array(array('action' => 'administration', 'name' => _kt('Administration')),); + + return parent::KTStandardDispatcher(); + } +} + +class manageUserPreferencesNavigationPortlet extends KTPortlet { + var $bActive = true; + + function manageUserPreferencesNavigationPortlet($sTitle) { + parent::KTPortlet($sTitle); + } +} + +?> diff --git a/plugins/Xpa1Rntal/user-preferences/sql/user_preferences.sql b/plugins/Xpa1Rntal/user-preferences/sql/user_preferences.sql new file mode 100644 index 0000000..d3036c8 --- /dev/null +++ b/plugins/Xpa1Rntal/user-preferences/sql/user_preferences.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS `user_preferences` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `user_id` int(11) unsigned NOT NULL, + `prefkey` varchar(255) NOT NULL, + `prefvalue` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + KEY `user_id` (`user_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; \ No newline at end of file diff --git a/plugins/Xpa1Rntal/user-preferences/templates/manage.smarty b/plugins/Xpa1Rntal/user-preferences/templates/manage.smarty new file mode 100644 index 0000000..ca69ef1 --- /dev/null +++ b/plugins/Xpa1Rntal/user-preferences/templates/manage.smarty @@ -0,0 +1 @@ +Coming Soon \ No newline at end of file