2 /****************************************************************/
\r
3 /* Atutor-OpenCaps Module
\r
4 /****************************************************************/
\r
5 /* Copyright (c) 2010
\r
6 /* Written by Antonio Gamba
\r
7 /* Adaptive Technology Resource Centre / University of Toronto
\r
9 /* This program is free software. You can redistribute it and/or
\r
10 /* modify it under the terms of the GNU General Public License
\r
11 /* as published by the Free Software Foundation.
\r
12 /****************************************************************/
\r
14 class ATOCProjectManager
\r
22 private $captionFile;
\r
27 * @desc Load Projects
\r
28 * @param String $theLogin
\r
29 * @param int $theCourseId
\r
31 * @return Array $myProjects
\r
33 public function _loadProjects($theLogin, $theCourseId, $theId)
\r
35 //echo '<h3>START method: _loadProjects()</h3>';
\r
39 $myProjects = array();
\r
40 $myGetMediaObj = new OcJsonFileProject();
\r
42 $sql = "SELECT * FROM ".TABLE_PREFIX."atopencaps_mod WHERE login = '".$theLogin."' AND courseId = ".$theCourseId;
\r
47 $sqlWhere .= ' AND id = '.$theId;
\r
50 $sqlOrder = ' ORDER BY id DESC';
\r
51 $sql .= $sqlWhere.$sqlOrder;
\r
52 //echo "<p>".$sql.'</p>';
\r
54 $result = mysql_query($sql, $db);
\r
55 $num_affected = mysql_affected_rows($db);
\r
57 if ($ocAtSettings['debugMode'] && $num_affected==0)
\r
59 $ocAtSettings['messages'] = '<p>_loadProjects(): no data to load </p>';
\r
62 // get all project data into an array.
\r
64 while ($row = @mysql_fetch_assoc($result))
\r
66 //$existing_accounts[$row['public_field']];
\r
67 $myProjects[$myCounter]['id'] = $row['id'];
\r
68 $myProjects[$myCounter]['login'] = $row['login'];
\r
69 $myProjects[$myCounter]['courseId'] = $row['courseId'];
\r
70 $myProjects[$myCounter]['name'] = $row['name'];
\r
71 $myProjects[$myCounter]['mediaFile'] = $row['mediaFile'];
\r
72 $myProjects[$myCounter]['captionFile'] = $row['captionFile'];
\r
73 $myProjects[$myCounter]['timeStamp'] = $row['timeStamp'];
\r
74 $myProjects[$myCounter]['width'] = $row['width'];
\r
75 $myProjects[$myCounter]['height'] = $row['height'];
\r
78 //echo "<BR/>ID: ".$row['id'];
\r
83 } // _loadProjects()
\r
87 * @desc _createCcFile
\r
88 * @param String $theMediaFile
\r
89 * @return String $theCaptionFile
\r
91 public function _createCcFile($theMediaFile)
\r
93 global $ocAtSettings; //
\r
95 $theNewFileName = '';
\r
97 $theCaptionFile = '';
\r
98 $theCaptionFilePath = '';
\r
99 $theCaptionFilePathFull = '';
\r
104 $ccNameTemp = explode('.',$theMediaFile);
\r
105 //print_r($ccNameTemp);
\r
108 $theCaptionFile = $ccNameTemp[0].'.'.$ocAtSettings['defaultCcExt'];
\r
110 $theCaptionFile = $ccNameTemp[0].'_'.$i.'.'.$ocAtSettings['defaultCcExt'];
\r
114 $theCaptionFilePath = str_replace('/',$ocAtSettings['dirSep'],$theCaptionFile);
\r
116 $theCaptionFilePathFull = AT_CONTENT_DIR.$_SESSION['course_id'].$ocAtSettings['dirSep'].$theCaptionFilePath;
\r
118 if (!file_exists($theCaptionFilePathFull))
\r
126 file_put_contents($theCaptionFilePathFull, '');
\r
127 return $theCaptionFile;
\r
129 } // end createNewCcFile
\r
133 * @desc Set Active Project
\r
134 * @param int $theId
\r
135 * @param string $theLogin
\r
136 * @param int $theCourseId
\r
137 * @param string $theSessionId
\r
139 public function _setActiveProject($theId, $theLogin, $theCourseId, $theSessionId)
\r
141 global $db, $ocAtSettings; // load AT db object
\r
144 $temId = explode('-',$theId);
\r
146 if($theId!=0 && $theLogin!='' && $theCourseId!=0 && $theSessionId!='')
\r
148 $sql = "UPDATE ".TABLE_PREFIX."atopencaps_mod SET sessionId='$theSessionId'";
\r
149 $sql .= " WHERE id = $theId AND login='$theLogin' AND courseId=$theCourseId";
\r
150 $result = mysql_query($sql, $db);
\r
151 $num_affected = mysql_affected_rows($db);
\r
152 //echo '<br/>'.$sql;
\r
156 } // end _setActiveProject
\r
160 * @desc Add/Edit/Delete captioning Project.
\r
161 * @param int $theId
\r
162 * @param string $theLogin
\r
163 * @param int $theCourseId
\r
164 * @param string $theName
\r
165 * @param string $theMediaFile
\r
166 * @param string $theCaptionFile
\r
167 * @param int $theWidth
\r
168 * @param int $theHeight
\r
169 * @param int $theAction
\r
171 public function _addEditProject($theId, $theLogin, $theCourseId, $theName, $theMediaFile, $theCaptionFile, $theWidth, $theHeight, $theAction='')
\r
174 global $db, $ocAtSettings; // load AT db object
\r
176 if ($theAction=="deleteProject")
\r
178 $sql = "DELETE FROM ".TABLE_PREFIX."atopencaps_mod";
\r
179 $sql .= " WHERE id = $theId AND login='$theLogin'";
\r
181 } else if ($theId != 0)
\r
184 $sql = "UPDATE ".TABLE_PREFIX."atopencaps_mod SET name='$theName', mediaFile='$theMediaFile', captionFile='$theCaptionFile', width='".$theWidth."', height='".$theHeight."'";
\r
185 $sql .= " WHERE id = $theId AND login='$theLogin'";
\r
189 // create caption file if does not exist
\r
190 if($theCaptionFile=='')
\r
192 $theCaptionFile = $this->_createCcFile($theMediaFile);
\r
196 $sql = "INSERT INTO ".TABLE_PREFIX."atopencaps_mod (`login`, `courseId`, `name`, `mediaFile`, `captionFile`, `width`, `height`) VALUES";
\r
197 $sql .= "('".$theLogin."', ".$theCourseId.", '".$theName."', '".$theMediaFile."', '".$theCaptionFile."', '".$theWidth."', '".$theHeight."')";
\r
203 $result = mysql_query($sql, $db);
\r
204 $num_affected = mysql_affected_rows($db);
\r
207 } // end addProject()
\r
210 * @desc _getProjecDataJson
\r
211 * @param unknown_type $theId
\r
212 * @param unknown_type $theBaseUrl
\r
215 public function _getProjecDataJson($theId, $theBaseUrl)
\r
218 global $db, $ocAtSettings;
\r
221 $temId = explode('-',$theId);
\r
223 $myProjects = array();
\r
224 $myGetMediaObj = new OcJsonFileProject();
\r
226 $sql = "SELECT * FROM ".TABLE_PREFIX."atopencaps_mod WHERE id = $temId[0] AND sessionId ='$temId[1]'";
\r
228 $result = mysql_query($sql, $db);
\r
229 $num_affected = mysql_affected_rows($db);
\r
232 if ($ocAtSettings['debugMode'] && $num_affected==0)
\r
234 echo "<p>_getProjecDataJson() function reported that: there are no Captioning Projects matching the criteria
\r
235 <br/>SQL: ".$sql.'</p>';
\r
238 // get all project data into an array.
\r
240 while ($row = mysql_fetch_assoc($result))
\r
242 // build object to JSON
\r
243 $myGetMediaObj->setVars('id',$theId);
\r
244 $myGetMediaObj->setVars('login',$row['login']);
\r
245 $myGetMediaObj->setVars('title',$row['name']);
\r
247 $rex1 = '/(http:|https:)/i';
\r
249 if (preg_match($rex1, $row['mediaFile']))
\r
251 $myGetMediaObj->setVars('mediaFile',''.$row['mediaFile']);
\r
252 $myGetMediaObj->setVars('captionFile',$theBaseUrl.'content/'.$row['courseId'].'/'.$row['captionFile']);
\r
254 } else if ($ocAtSettings['contentUrlType']== 0) {
\r
255 $myGetMediaObj->setVars('mediaFile',$theBaseUrl.'get.php/'.''.$row['mediaFile']);
\r
256 $myGetMediaObj->setVars('captionFile',$theBaseUrl.'get.php/'.''.$row['captionFile']);
\r
258 } else if ($ocAtSettings['contentUrlType']== 1) {
\r
259 $myGetMediaObj->setVars('mediaFile',$theBaseUrl.'content/'.$row['courseId'].'/'.$row['mediaFile']);
\r
260 $myGetMediaObj->setVars('captionFile',$theBaseUrl.'content/'.$row['courseId'].'/'.$row['captionFile']);
\r
264 $myGetMediaObj->setVars('timeStamp',$row['timeStamp']);
\r
265 $myGetMediaObj->setVars('returnFormat',$ocAtSettings['ccReturnFormat']);
\r
269 $jsonFile = json_encode($myGetMediaObj);
\r
274 } // _getProjecDataJason()
\r
278 * @desc _saveCaptionData
\r
279 * @param String $theId
\r
280 * @param String $theCcData
\r
281 * @param int $theWidth
\r
282 * @param int $theHeight
\r
284 public function _saveCaptionData($theId,$theCcData,$theWidth,$theHeight)
\r
286 global $db, $ocAtSettings;
\r
288 $temId = explode('-',$theId);
\r
290 $sql = "SELECT * FROM ".TABLE_PREFIX."atopencaps_mod WHERE id = $temId[0] AND sessionId ='$temId[1]'";
\r
292 $result = mysql_query($sql, $db);
\r
293 $num_affected = mysql_affected_rows($db);
\r
295 $row = mysql_fetch_assoc($result);
\r
297 if ($row['captionFile']!='')
\r
300 $theCaptionFilePath = str_replace('/',$ocAtSettings['dirSep'],$row['captionFile']);
\r
302 $theCaptionFilePathFull = AT_CONTENT_DIR.$row['courseId'].$ocAtSettings['dirSep'].$theCaptionFilePath;
\r
304 file_put_contents($theCaptionFilePathFull, $theCcData);
\r
307 if ($theWidth!='' && $theHeight!='')
\r
309 $sqlUpdateMetadata = "UPDATE ".TABLE_PREFIX."atopencaps_mod SET width='".$theWidth."', height='".$theHeight."'";
\r
310 $sqlUpdateMetadata .= " WHERE id = $temId[0] AND sessionId ='$temId[1]'";
\r
311 //$sqlUpdateMetadata .= " AND login='$theLogin'";
\r
312 //echo '<br/>'.$sqlUpdateMetadata;
\r
313 $result1 = mysql_query($sqlUpdateMetadata, $db);
\r
318 //return '<h3>Data Saved in : '.$row['captionFile'].'</h3>';
\r
319 return '<p>Data Saved in : '.$theCaptionFilePathFull.'</p>';
\r
322 } // _saveCaptionData()
\r