2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
14 * DAO for "oauth_client_servers" table
20 if (!defined('TR_INCLUDE_PATH')) exit;
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
23 require_once(TR_INCLUDE_PATH. 'classes/Utility.class.php');
25 class OAuthClientServersDAO extends DAO {
28 * Create a new oauth server record
34 * @return server id, if successful
35 * false and add error into global var $msg, if unsuccessful
38 public function Create($oauth_server, $consumer_key, $consumer_secret, $expire_threshold)
40 global $addslashes, $msg;
42 $missing_fields = array();
45 $oauth_server = $addslashes(trim($oauth_server));
46 $expire_threshold = intval($expire_threshold);
48 /* login name check */
49 if ($oauth_server == '')
51 $missing_fields[] = _AT('oauth_server');
56 $missing_fields = implode(', ', $missing_fields);
57 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
60 if (!$msg->containsErrors())
62 /* insert into the db */
63 $sql = "INSERT INTO ".TABLE_PREFIX."oauth_client_servers
70 VALUES ('".$oauth_server."',
72 '".$consumer_secret."',
73 ".$expire_threshold.",
77 if (!$this->execute($sql))
79 $msg->addError('DB_NOT_UPDATED');
84 return mysql_insert_id();
94 * update an existing oauth server record
100 * @return true, if successful
101 * false and add error into global var $msg, if unsuccessful
102 * @author Cindy Qi Li
104 public function Update($oauth_server, $consumer_key, $consumer_secret, $expire_threshold)
106 global $addslashes, $msg;
108 $missing_fields = array();
111 $oauth_server = $addslashes(trim($oauth_server));
112 $expire_threshold = intval($expire_threshold);
114 /* login name check */
115 if ($oauth_server == '')
117 $missing_fields[] = _AT('oauth_server');
122 $missing_fields = implode(', ', $missing_fields);
123 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
126 if (!$msg->containsErrors())
128 $sql = "UPDATE ".TABLE_PREFIX."oauth_client_servers
129 SET consumer_key = '".$consumer_key."',
130 consumer_secret = '".$consumer_secret."',
131 expire_threshold = ".$expire_threshold."
132 WHERE oauth_server = '".$oauth_server."'";
134 if (!$this->execute($sql))
136 $msg->addError('DB_NOT_UPDATED');
151 * Return row by oauth server ID
153 * @param $oauth_server_id
155 * @author Cindy Qi Li
157 function get($oauth_server_id)
159 $sql = "SELECT * FROM ".TABLE_PREFIX."oauth_client_servers WHERE oauth_server_id='".$oauth_server_id."'";
160 $rows = $this->execute($sql);
165 * Return row by oauth server name
167 * @param $oauth_server
169 * @author Cindy Qi Li
171 function getByOauthServer($oauth_server)
173 $sql = "SELECT * FROM ".TABLE_PREFIX."oauth_client_servers WHERE oauth_server='".$oauth_server."'";
174 return $this->execute($sql);