ee096db2d06bcc74e62b98cde1561e24c820ab88
[acontent.git] / docs / include / classes / DAO / MyownPatchesFilesDAO.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_files" 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 MyownPatchesFilesDAO extends DAO {
25
26         /**
27          * Create new row
28          * @access  public
29          * @param   $myown_patch_id, $action, $name, $location,
30          *          $code_from, $code_to, $uploaded_file
31          * @return  myown_patches_files_id, if successful
32          *          false and add error into global var $msg, if unsuccessful
33          * @author  Cindy Qi Li
34          */
35         public function Create($myown_patch_id, $action, $name, $location,
36                                $code_from, $code_to, $uploaded_file)
37         {
38                 global $addslashes;
39
40                 $sql = "INSERT INTO ".TABLE_PREFIX."myown_patches_files
41                (myown_patch_id, 
42                 action,
43                 name,
44                 location,
45                 code_from,
46                 code_to,
47                 uploaded_file)
48                 VALUES ('".$myown_patch_id."', 
49                         '".$action."', 
50                         '".$name."', 
51                         '".$location."', 
52                         '".$code_from."', 
53                         '".$code_to."',
54                         '".$addslashes($uploaded_file)."')";
55                 
56                 if (!$this->execute($sql))
57                 {
58                         $msg->addError('DB_NOT_UPDATED');
59                         return false;
60                 }
61                 else
62                 {
63                         return mysql_insert_id();
64                 }
65         }
66
67         /**
68          * Create new user
69          * @access  public
70          * @param   user_group_id: user group ID (1 [admin] or 2 [user])
71          *          login: login name
72          *          pwd: password
73          *          email: email
74          *          first_name: first name
75          *          last_name: last name
76          * @return  user id, if successful
77          *          false and add error into global var $msg, if unsuccessful
78          * @author  Cindy Qi Li
79          */
80         public function Update($userID, $user_group_id, $login, $email, $first_name, $last_name, $status)
81         {
82                 global $addslashes, $msg;
83
84                 /* email check */
85                 $login = $addslashes(strtolower(trim($login)));
86                 $email = $addslashes(trim($email));
87                 $first_name = $addslashes(str_replace('<', '', trim($first_name)));
88                 $last_name = $addslashes(str_replace('<', '', trim($last_name)));
89
90                 if ($this->isFieldsValid('update', $user_group_id,$login, $email,$first_name, $last_name))
91                 {
92                         /* insert into the db */
93                         $sql = "UPDATE ".TABLE_PREFIX."users
94                                    SET login = '".$login."',
95                                        user_group_id = '".$user_group_id."',
96                                        first_name = '".$first_name."',
97                                        last_name = '".$last_name."',
98                                        email = '".$email."',
99                                        status = '".$status."'
100                                  WHERE user_id = ".$userID;
101
102                         return $this->execute($sql);
103                 }
104         }
105
106         /**
107          * Delete rows by given patch id
108          * @access  public
109          * @param   patchID
110          * @return  true, if successful
111          *          false and add error into global var $msg, if unsuccessful
112          * @author  Cindy Qi Li
113          */
114         public function DeleteByPatchID($patchID)
115         {
116                 $sql = "DELETE FROM ".TABLE_PREFIX."myown_patches_files
117                          WHERE myown_patch_id = ".$patchID;
118                 
119                 return $this->execute($sql);
120         }
121
122         /**
123          * Return the patch files info with the given patch id
124          * @access  public
125          * @param   $patchID
126          * @return  patch row
127          * @author  Cindy Qi Li
128          */
129         public function getByPatchID($patchID)
130         {
131                 $sql = "SELECT * from ".TABLE_PREFIX."myown_patches_files
132                          WHERE myown_patch_id=". $patchID."
133                          ORDER BY myown_patches_files_id";
134                 
135                 return $this->execute($sql);
136         }
137
138 }
139 ?>