AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / docs / include / classes / DAO / MyownPatchesDAO.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 "myown_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 MyownPatchesDAO extends DAO {
25
26         /**
27          * Create new row
28          * @access  public
29          * @param   system_patch_id, applied_versin, description, sql_statement
30          * @return  myown_patch_id, if successful
31          *          false and add error into global var $msg, if unsuccessful
32          * @author  Cindy Qi Li
33          */
34         public function Create($system_patch_id, $applied_version, 
35                                $description, $sql_statement)
36         {
37                 global $addslashes;
38
39                 $sql = "INSERT INTO ".TABLE_PREFIX."myown_patches 
40                        (system_patch_id, 
41                         applied_version,
42                         description,
43                         sql_statement,
44                         status,
45                         last_modified)
46                         VALUES ('".$system_patch_id."', 
47                                 '".$applied_version."', 
48                                 '".$description."', 
49                                 '".$sql_statement."', 
50                                 'Created',
51                                 now())";
52                 
53                 if (!$this->execute($sql))
54                 {
55                         $msg->addError('DB_NOT_UPDATED');
56                         return false;
57                 }
58                 else
59                 {
60                         return mysql_insert_id();
61                 }
62         }
63
64         /**
65          * Update a row
66          * @access  public
67          * @param   myown_patch_id, system_patch_id, applied_versin, description, sql_statement
68          * @return  true, if successful. Otherwise, false
69          * @author  Cindy Qi Li
70          */
71         public function Update($myown_patch_id, $system_patch_id, $applied_version, 
72                                $description, $sql_statement)
73         {
74                 global $addslashes;
75
76                 $sql = "UPDATE ".TABLE_PREFIX."myown_patches 
77                            SET system_patch_id = '". $system_patch_id ."',
78                                applied_version = '". $applied_version ."',
79                                description = '". $description ."',
80                                sql_statement = '". $sql_statement ."',
81                                status = 'Created',
82                                last_modified = now()
83                          WHERE myown_patch_id = ". $myown_patch_id;
84         
85                 return $this->execute($sql);
86         }
87
88         /**
89          * Update an existing myown_patches record
90          * @access  public
91          * @param   myownPatchID: myown_patches.myown_patch_id
92          *          fieldName: the name of the table field to update
93          *          fieldValue: the value to update
94          * @return  true if successful
95          *          error message array if failed; false if update db failed
96          * @author  Cindy Qi Li
97          */
98         public function UpdateField($myownPatchID, $fieldName, $fieldValue)
99         {
100                 global $addslashes;
101
102                 // check if the required fields are filled
103                 if (($fieldName == 'system_patch_id' || $fieldName == 'applied_version') && $fieldValue == '')
104                         return array(_AT('TR_ERROR_EMPTY_FIELD'));
105
106                 $sql = "UPDATE ".TABLE_PREFIX."myown_patches 
107                            SET ".$addslashes($fieldName)."='".$addslashes($fieldValue)."'
108                          WHERE myown_patch_id = ".$myownPatchID;
109                 
110                 return $this->execute($sql);
111         }
112         
113         /**
114          * Delete a patch
115          * @access  public
116          * @param   patchID
117          * @return  true, if successful
118          *          false and add error into global var $msg, if unsuccessful
119          * @author  Cindy Qi Li
120          */
121         public function Delete($patchID)
122         {
123                 $sql = "DELETE FROM ".TABLE_PREFIX."myown_patches
124                          WHERE myown_patch_id = ".$patchID;
125
126                 return $this->execute($sql);
127         }
128
129         /**
130          * Return all my own patches
131          * @access  public
132          * @param   none
133          * @return  all table rows
134          * @author  Cindy Qi Li
135          */
136         public function getAll()
137         {
138                 $sql = "SELECT * from ".TABLE_PREFIX."myown_patches m order by last_modified desc";
139                 
140                 return $this->execute($sql);
141         }
142
143         /**
144          * Return the patch info with the given patch id
145          * @access  public
146          * @param   $patchID
147          * @return  patch row
148          * @author  Cindy Qi Li
149          */
150         public function getByID($patchID)
151         {
152                 $sql = "SELECT * from ".TABLE_PREFIX."myown_patches where myown_patch_id=". $patchID;
153                 
154                 $rows = $this->execute($sql);
155                 
156                 if (is_array($rows)) return $rows[0];
157                 else return false;
158         }
159
160 }
161 ?>