AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / include / classes / DAO / PatchesDAO.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 "patches" 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
24 class PatchesDAO extends DAO {
25
26         /**
27          * Create new patch
28          * @access  public
29          * @param   system_patch_id: atutor patch id, 
30          *          applied_version
31          *          patch_folder
32          *          description
33          *          available_to
34          *          sql_statement, 
35          *          status
36          *          remove_permission_files,
37          *          backup_files
38          *          patch_files
39          *          author
40          * @return  patch id, if successful
41          *          false and add error into global var $msg, if unsuccessful
42          * @author  Cindy Qi Li
43          */
44         public function Create($system_patch_id, $applied_version, 
45                                $patch_folder, $description, 
46                                $available_to, $sql_statement, 
47                                $status, $remove_permission_files,
48                                $backup_files, $patch_files, $author)
49         {
50                 global $addslashes;
51
52                 $sql = "INSERT INTO " . TABLE_PREFIX. "patches " .
53                                          "(system_patch_id, 
54                                            applied_version,
55                                            patch_folder,
56                                            description,
57                                            available_to,
58                                            sql_statement,
59                                            status,
60                                            remove_permission_files,
61                                            backup_files,
62                                            patch_files,
63                                            author,
64                                            installed_date)
65                                           VALUES
66                                           ('".$addslashes($system_patch_id)."',
67                                            '".$addslashes($applied_version)."',
68                                            '".$addslashes($patch_folder)."',
69                                            '".$addslashes($description)."',
70                                            '".$addslashes($available_to)."',
71                                            '".$addslashes($sql_statement)."',
72                                            '".$addslashes($status)."',
73                                            '".$addslashes($remove_permission_files)."',
74                                            '".$addslashes($backup_files)."',
75                                            '".$addslashes($patch_files)."',
76                                            '".$addslashes($author)."',
77                                            now()
78                                            )";
79
80                 if (!$this->execute($sql))
81                 {
82                         $msg->addError('DB_NOT_UPDATED');
83                         return false;
84                 }
85                 else
86                 {
87                         return mysql_insert_id();
88                 }
89         }
90
91         /**
92         * update table "patches" accroding to the fields/values in the given array
93         * @access  public
94         * @param   patchID, fieldArray
95         * @author  Cindy Qi Li
96         */
97         public function UpdateByArray($patchID, $fieldArray)
98         {
99                 $sql_prefix = "Update ". TABLE_PREFIX. "patches set ";
100                 
101                 foreach ($fieldArray as $key => $value)
102                 {
103                         $sql_middle .= $key . "='" . $value . "', ";
104                 }
105                 
106                 $sql = substr($sql_prefix . $sql_middle, 0, -2) . 
107                        " WHERE patches_id = " . $patchID;
108                 
109                 return $this->execute($sql);
110         }
111
112         /**
113          * Return the patch info with the given patch id
114          * @access  public
115          * @param   $patchID
116          * @return  patch row
117          * @author  Cindy Qi Li
118          */
119         public function getByID($patchID)
120         {
121                 $sql = "SELECT * from ".TABLE_PREFIX."patches where patches_id=". $patchID;
122                 
123                 $rows = $this->execute($sql);
124                 
125                 if (is_array($rows)) return $rows[0];
126                 else return false;
127         }
128         
129         /**
130          * Return patch information by given version
131          * @access  public
132          * @param   version
133          * @return  patch row
134          * @author  Cindy Qi Li
135          */
136         public function getPatchByVersion($version)
137         {
138                 $sql = "SELECT * FROM ".TABLE_PREFIX."patches 
139                          WHERE applied_version = '" . $version . "' 
140                          ORDER BY system_patch_id";
141                 
142                 return $this->execute($sql);
143         }
144
145         /**
146          * Return user information by given web service ID
147          * @access  public
148          * @param   web service ID
149          * @return  user row
150          * @author  Cindy Qi Li
151          */
152         public function getInstalledPatchByIDAndVersion($patchID, $version)
153         {
154                 $sql = "select * from ".TABLE_PREFIX."patches " .
155                        "where system_patch_id = '" . $patchID ."'".
156                        " and applied_version = '".$version."'".
157                        " and status like '%Installed'";
158
159                 return $this->execute($sql);
160         }
161
162 }
163 ?>