80ca44132a0dcc676eb7c2b7b703d491731b0cdf
[atutor.git] / mods / atutor_opencaps / opencaps / include / classes / db_class.php
1 <?php
2 /*
3  * OpenCaps
4  * http://opencaps.atrc.utoronto.ca
5  * 
6  * Copyright 2009 Heidi Hazelton
7  * Adaptive Technology Resource Centre, University of Toronto
8  * 
9  * Licensed under the Educational Community License (ECL), Version 2.0. 
10  * You may not use this file except in compliance with this License.
11  * http://www.opensource.org/licenses/ecl2.php
12  * 
13  */
14
15 class database { 
16         public $db;
17         
18         public function __construct() {
19                 $this->connect();                                       
20         }
21
22         private function connect() {
23                                                 
24                 require(INCLUDE_PATH.'config.inc.php');
25                 $this->db = @mysql_connect(DB_HOST . ':' . DB_PORT, DB_USER, DB_PASSWORD);
26                 if (!$this->db) {
27                         $_SESSION['errors'][] = 'Unable to connect to database. <br />';
28                 }
29                 if (!@mysql_select_db(DB_NAME, $this->db)) {
30                         $_SESSION['errors'][] = 'Connection established, but database "'.DB_NAME.'" cannot be selected. <br />';
31                 }               
32                 
33                 if (isset($_SESSION['errors'])) {
34                         include(INCLUDE_PATH."basic_header.inc.php");
35                         include(INCLUDE_PATH."footer.inc.php");                 
36                         exit;
37                 }
38                 
39                 return true;
40         }
41         
42         /* adds a new proj to the db, returns proj id */
43         public function addProj($proj) {
44                                 
45                 $sql = "INSERT INTO projects VALUES (0, $_SESSION[mid], '$proj->name', '$proj->media_loc', 0, NOW())";          
46                 if (!$result = mysql_query($sql, $this->db)) {
47                         $_SESSION['errors'][] = 'Database error - could not add project.';
48                         return false;
49                 }
50                 return mysql_insert_id();
51         }       
52         
53         public function updateProj($proj) {
54                 $sql = "UPDATE projects SET name='".$proj->name."', video_file='".$proj->media_loc."' WHERE project_id=".$proj->id;             
55                 if (!$result = mysql_query($sql, $this->db)) {
56                         $err = 'Database error <br />';
57                         exit;   
58                 }
59                 return true;            
60         }
61         
62
63         
64         /*public function getProjInfo($id) {
65                 global $db;
66                 
67                 $sql = "SELECT name, video_file, layout_preset, last_accessed FROM projects WHERE project_id=".intval($id);
68                 $result = mysql_query($sql, $db);
69         
70                 if ($row = mysql_fetch_assoc($result)) {
71                         return $row;
72                 }       
73         }
74         
75         public function getMovie() {
76                 global $db;
77                 
78                 $sql = "SELECT video_file FROM projects WHERE project_id=".intval($_SESSION['pid']);
79                 $result = mysql_query($sql, $db);
80         
81                 if ($row = mysql_fetch_assoc($result)) {
82                         return 'projects/'.$_SESSION['pid'].'/movies/'.$row['video_file'];
83                 }       
84         
85         }*/     
86 }
87
88
89
90 ?>