AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / include / classes / DAO / OAuthClientServersDAO.class.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
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 /************************************************************************/
12
13 /**
14 * DAO for "oauth_client_servers" table
15 * @access       public
16 * @author       Cindy Qi Li
17 * @package      DAO
18 */
19
20 if (!defined('TR_INCLUDE_PATH')) exit;
21
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
23 require_once(TR_INCLUDE_PATH. 'classes/Utility.class.php');
24
25 class OAuthClientServersDAO extends DAO {
26
27         /**
28          * Create a new oauth server record
29          * @access  public
30          * @param   server
31          *          consumer key
32          *          consumer secret
33          *          expire threshold
34          * @return  server id, if successful
35          *          false and add error into global var $msg, if unsuccessful
36          * @author  Cindy Qi Li
37          */
38         public function Create($oauth_server, $consumer_key, $consumer_secret, $expire_threshold)
39         {
40                 global $addslashes, $msg;
41
42                 $missing_fields = array();
43
44                 /* email check */
45                 $oauth_server = $addslashes(trim($oauth_server));
46                 $expire_threshold = intval($expire_threshold);
47
48                 /* login name check */
49                 if ($oauth_server == '')
50                 {
51                         $missing_fields[] = _AT('oauth_server');
52                 }
53
54                 if ($missing_fields)
55                 {
56                         $missing_fields = implode(', ', $missing_fields);
57                         $msg->addError(array('EMPTY_FIELDS', $missing_fields));
58                 }
59
60                 if (!$msg->containsErrors())
61                 {
62                         /* insert into the db */
63                         $sql = "INSERT INTO ".TABLE_PREFIX."oauth_client_servers
64                                       (oauth_server,
65                                        consumer_key,
66                                        consumer_secret,
67                                        expire_threshold,
68                                        create_date
69                                        )
70                                VALUES ('".$oauth_server."',
71                                        '".$consumer_key."',
72                                        '".$consumer_secret."',
73                                        ".$expire_threshold.",
74                                        now()
75                                       )";
76
77                         if (!$this->execute($sql))
78                         {
79                                 $msg->addError('DB_NOT_UPDATED');
80                                 return false;
81                         }
82                         else
83                         {
84                                 return mysql_insert_id();
85                         }
86                 }
87                 else
88                 {
89                         return false;
90                 }
91         }
92
93         /**
94          * update an existing oauth server record
95          * @access  public
96          * @param   server
97          *          consumer key
98          *          consumer secret
99          *          expire threshold
100          * @return  true, if successful
101          *          false and add error into global var $msg, if unsuccessful
102          * @author  Cindy Qi Li
103          */
104         public function Update($oauth_server, $consumer_key, $consumer_secret, $expire_threshold)
105         {
106                 global $addslashes, $msg;
107
108                 $missing_fields = array();
109
110                 /* email check */
111                 $oauth_server = $addslashes(trim($oauth_server));
112                 $expire_threshold = intval($expire_threshold);
113
114                 /* login name check */
115                 if ($oauth_server == '')
116                 {
117                         $missing_fields[] = _AT('oauth_server');
118                 }
119
120                 if ($missing_fields)
121                 {
122                         $missing_fields = implode(', ', $missing_fields);
123                         $msg->addError(array('EMPTY_FIELDS', $missing_fields));
124                 }
125
126                 if (!$msg->containsErrors())
127                 {
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."'";
133
134                         if (!$this->execute($sql))
135                         {
136                                 $msg->addError('DB_NOT_UPDATED');
137                                 return false;
138                         }
139                         else
140                         {
141                                 return true;
142                         }
143                 }
144                 else
145                 {
146                         return false;
147                 }
148         }
149
150         /**
151         * Return row by oauth server ID
152         * @access  public
153         * @param   $oauth_server_id
154         * @return  table row
155         * @author  Cindy Qi Li
156         */
157         function get($oauth_server_id)
158         {
159             $sql = "SELECT * FROM ".TABLE_PREFIX."oauth_client_servers WHERE oauth_server_id='".$oauth_server_id."'";
160             $rows = $this->execute($sql);
161             return $rows[0];
162         }
163
164         /**
165         * Return row by oauth server name
166         * @access  public
167         * @param   $oauth_server
168         * @return  table row
169         * @author  Cindy Qi Li
170         */
171         function getByOauthServer($oauth_server)
172         {
173             $sql = "SELECT * FROM ".TABLE_PREFIX."oauth_client_servers WHERE oauth_server='".$oauth_server."'";
174             return $this->execute($sql);
175         }
176
177 }
178 ?>