+++ /dev/null
-<?php\r
-/****************************************************************/\r
-/* Atutor-OpenCaps Module \r
-/****************************************************************/\r
-/* Copyright (c) 2010 \r
-/* Written by Antonio Gamba \r
-/* Adaptive Technology Resource Centre / University of Toronto\r
-/*\r
-/* This program is free software. You can redistribute it and/or\r
-/* modify it under the terms of the GNU General Public License\r
-/* as published by the Free Software Foundation.\r
-/****************************************************************/\r
-\r
-class ATOCProjectManager\r
-{\r
- /*\r
- private $id;\r
- private $login;\r
- private $courseId;\r
- private $name;\r
- private $mediaFile;\r
- private $captionFile;\r
- private $date;\r
- */\r
- \r
- /**\r
- * @desc Load Projects\r
- * @param String $theLogin\r
- * @param int $theCourseId\r
- * @param int $theId\r
- * @return Array $myProjects\r
- */\r
- public function _loadProjects($theLogin, $theCourseId, $theId)\r
- {\r
- //echo '<h3>START method: _loadProjects()</h3>';\r
-\r
- global $db;\r
- \r
- $myProjects = array();\r
- $myGetMediaObj = new OcJsonFileProject();\r
- \r
- $sql = "SELECT * FROM ".TABLE_PREFIX."atopencaps_mod WHERE login = '".$theLogin."' AND courseId = ".$theCourseId;\r
- $sqlWhere = '';\r
-\r
- if($theId!=0)\r
- {\r
- $sqlWhere .= ' AND id = '.$theId;\r
- } \r
- \r
- $sqlOrder = ' ORDER BY id DESC';\r
- $sql .= $sqlWhere.$sqlOrder;\r
- //echo "<p>".$sql.'</p>';\r
-\r
- $result = mysql_query($sql, $db);\r
- $num_affected = mysql_affected_rows($db);\r
- \r
- if ($ocAtSettings['debugMode'] && $num_affected==0)\r
- {\r
- $ocAtSettings['messages'] = '<p>_loadProjects(): no data to load </p>';\r
- }\r
- \r
- // get all project data into an array. \r
- $myCounter = 0;\r
- while ($row = @mysql_fetch_assoc($result)) \r
- {\r
- //$existing_accounts[$row['public_field']];\r
- $myProjects[$myCounter]['id'] = $row['id'];\r
- $myProjects[$myCounter]['login'] = $row['login'];\r
- $myProjects[$myCounter]['courseId'] = $row['courseId'];\r
- $myProjects[$myCounter]['name'] = $row['name'];\r
- $myProjects[$myCounter]['mediaFile'] = $row['mediaFile'];\r
- $myProjects[$myCounter]['captionFile'] = $row['captionFile'];\r
- $myProjects[$myCounter]['timeStamp'] = $row['timeStamp'];\r
- $myProjects[$myCounter]['width'] = $row['width'];\r
- $myProjects[$myCounter]['height'] = $row['height'];\r
- \r
- $myCounter++;\r
- //echo "<BR/>ID: ".$row['id'];\r
- } // end while\r
-\r
- return $myProjects;\r
-\r
- } // _loadProjects()\r
-\r
-\r
- /**\r
- * @desc _createCcFile\r
- * @param String $theMediaFile\r
- * @return String $theCaptionFile\r
- */\r
- public function _createCcFile($theMediaFile)\r
- {\r
- global $ocAtSettings; //\r
-\r
- $theNewFileName = '';\r
- $bol=false;\r
- $theCaptionFile = '';\r
- $theCaptionFilePath = '';\r
- $theCaptionFilePathFull = '';\r
- $i = 0;\r
- \r
- while (!$bol)\r
- {\r
- $ccNameTemp = explode('.',$theMediaFile);\r
- //print_r($ccNameTemp);\r
- if ($i==0)\r
- {\r
- $theCaptionFile = $ccNameTemp[0].'.'.$ocAtSettings['defaultCcExt'];\r
- } else {\r
- $theCaptionFile = $ccNameTemp[0].'_'.$i.'.'.$ocAtSettings['defaultCcExt'];\r
- }\r
-\r
- // fix path\r
- $theCaptionFilePath = str_replace('/',$ocAtSettings['dirSep'],$theCaptionFile);\r
- \r
- $theCaptionFilePathFull = AT_CONTENT_DIR.$_SESSION['course_id'].$ocAtSettings['dirSep'].$theCaptionFilePath;\r
- \r
- if (!file_exists($theCaptionFilePathFull))\r
- {\r
- $bol=true;\r
- }\r
- $i++;\r
- \r
- } // end while\r
- \r
- file_put_contents($theCaptionFilePathFull, '');\r
- return $theCaptionFile;\r
-\r
- } // end createNewCcFile\r
- \r
-\r
- /**\r
- * @desc Set Active Project\r
- * @param int $theId\r
- * @param string $theLogin\r
- * @param int $theCourseId\r
- * @param string $theSessionId\r
- */\r
- public function _setActiveProject($theId, $theLogin, $theCourseId, $theSessionId)\r
- {\r
- global $db, $ocAtSettings; // load AT db object\r
- \r
- // split id \r
- $temId = explode('-',$theId);\r
- \r
- if($theId!=0 && $theLogin!='' && $theCourseId!=0 && $theSessionId!='')\r
- {\r
- $sql = "UPDATE ".TABLE_PREFIX."atopencaps_mod SET sessionId='$theSessionId'";\r
- $sql .= " WHERE id = $theId AND login='$theLogin' AND courseId=$theCourseId";\r
- $result = mysql_query($sql, $db);\r
- $num_affected = mysql_affected_rows($db);\r
- //echo '<br/>'.$sql;\r
- $result = null;\r
- }\r
- \r
- } // end _setActiveProject\r
- \r
- \r
- /**\r
- * @desc Add/Edit/Delete captioning Project.\r
- * @param int $theId\r
- * @param string $theLogin\r
- * @param int $theCourseId\r
- * @param string $theName\r
- * @param string $theMediaFile\r
- * @param string $theCaptionFile\r
- * @param int $theWidth\r
- * @param int $theHeight\r
- * @param int $theAction\r
- */\r
- public function _addEditProject($theId, $theLogin, $theCourseId, $theName, $theMediaFile, $theCaptionFile, $theWidth, $theHeight, $theAction='')\r
- {\r
-\r
- global $db, $ocAtSettings; // load AT db object\r
- \r
- if ($theAction=="deleteProject")\r
- {\r
- $sql = "DELETE FROM ".TABLE_PREFIX."atopencaps_mod";\r
- $sql .= " WHERE id = $theId AND login='$theLogin'";\r
- \r
- } else if ($theId != 0)\r
- {\r
- // UPDATE\r
- $sql = "UPDATE ".TABLE_PREFIX."atopencaps_mod SET name='$theName', mediaFile='$theMediaFile', captionFile='$theCaptionFile', width='".$theWidth."', height='".$theHeight."'";\r
- $sql .= " WHERE id = $theId AND login='$theLogin'";\r
-\r
- } else {\r
- \r
- // create caption file if does not exist\r
- if($theCaptionFile=='')\r
- {\r
- $theCaptionFile = $this->_createCcFile($theMediaFile);\r
- }\r
-\r
- // INSERT\r
- $sql = "INSERT INTO ".TABLE_PREFIX."atopencaps_mod (`login`, `courseId`, `name`, `mediaFile`, `captionFile`, `width`, `height`) VALUES";\r
- $sql .= "('".$theLogin."', ".$theCourseId.", '".$theName."', '".$theMediaFile."', '".$theCaptionFile."', '".$theWidth."', '".$theHeight."')";\r
- \r
- }\r
- \r
- //echo $sql;\r
- // run SQL \r
- $result = mysql_query($sql, $db);\r
- $num_affected = mysql_affected_rows($db);\r
- $result = null;\r
- \r
- } // end addProject()\r
- \r
- /**\r
- * @desc _getProjecDataJson\r
- * @param unknown_type $theId\r
- * @param unknown_type $theBaseUrl\r
- * @return unknown\r
- */\r
- public function _getProjecDataJson($theId, $theBaseUrl)\r
- \r
- {\r
- global $db, $ocAtSettings;\r
- \r
- // split id \r
- $temId = explode('-',$theId);\r
- \r
- $myProjects = array();\r
- $myGetMediaObj = new OcJsonFileProject();\r
- \r
- $sql = "SELECT * FROM ".TABLE_PREFIX."atopencaps_mod WHERE id = $temId[0] AND sessionId ='$temId[1]'";\r
- \r
- $result = mysql_query($sql, $db);\r
- $num_affected = mysql_affected_rows($db);\r
- \r
- // debug\r
- if ($ocAtSettings['debugMode'] && $num_affected==0)\r
- {\r
- echo "<p>_getProjecDataJson() function reported that: there are no Captioning Projects matching the criteria \r
- <br/>SQL: ".$sql.'</p>';\r
- }\r
- \r
- // get all project data into an array. \r
- $myCounter = 0;\r
- while ($row = mysql_fetch_assoc($result)) \r
- {\r
- // build object to JSON\r
- $myGetMediaObj->setVars('id',$theId);\r
- $myGetMediaObj->setVars('login',$row['login']);\r
- $myGetMediaObj->setVars('title',$row['name']);\r
- \r
- $rex1 = '/(http:|https:)/i';\r
- \r
- if (preg_match($rex1, $row['mediaFile']))\r
- {\r
- $myGetMediaObj->setVars('mediaFile',''.$row['mediaFile']);\r
- $myGetMediaObj->setVars('captionFile',$theBaseUrl.'content/'.$row['courseId'].'/'.$row['captionFile']);\r
- \r
- } else if ($ocAtSettings['contentUrlType']== 0) {\r
- $myGetMediaObj->setVars('mediaFile',$theBaseUrl.'get.php/'.''.$row['mediaFile']);\r
- $myGetMediaObj->setVars('captionFile',$theBaseUrl.'get.php/'.''.$row['captionFile']);\r
- \r
- } else if ($ocAtSettings['contentUrlType']== 1) {\r
- $myGetMediaObj->setVars('mediaFile',$theBaseUrl.'content/'.$row['courseId'].'/'.$row['mediaFile']);\r
- $myGetMediaObj->setVars('captionFile',$theBaseUrl.'content/'.$row['courseId'].'/'.$row['captionFile']);\r
- \r
- }\r
- \r
- $myGetMediaObj->setVars('timeStamp',$row['timeStamp']);\r
- $myGetMediaObj->setVars('returnFormat',$ocAtSettings['ccReturnFormat']);\r
- \r
- } // end while\r
- \r
- $jsonFile = json_encode($myGetMediaObj);\r
- \r
- return $jsonFile;\r
-\r
-\r
- } // _getProjecDataJason()\r
- \r
- \r
- /**\r
- * @desc _saveCaptionData\r
- * @param String $theId\r
- * @param String $theCcData\r
- * @param int $theWidth\r
- * @param int $theHeight\r
- */\r
- public function _saveCaptionData($theId,$theCcData,$theWidth,$theHeight)\r
- {\r
- global $db, $ocAtSettings;\r
- \r
- $temId = explode('-',$theId);\r
- \r
- $sql = "SELECT * FROM ".TABLE_PREFIX."atopencaps_mod WHERE id = $temId[0] AND sessionId ='$temId[1]'";\r
- \r
- $result = mysql_query($sql, $db);\r
- $num_affected = mysql_affected_rows($db);\r
- \r
- $row = mysql_fetch_assoc($result);\r
-\r
- if ($row['captionFile']!='')\r
- {\r
- // fix path\r
- $theCaptionFilePath = str_replace('/',$ocAtSettings['dirSep'],$row['captionFile']);\r
- \r
- $theCaptionFilePathFull = AT_CONTENT_DIR.$row['courseId'].$ocAtSettings['dirSep'].$theCaptionFilePath;\r
- \r
- file_put_contents($theCaptionFilePathFull, $theCcData);\r
-\r
- // update metadata\r
- if ($theWidth!='' && $theHeight!='')\r
- {\r
- $sqlUpdateMetadata = "UPDATE ".TABLE_PREFIX."atopencaps_mod SET width='".$theWidth."', height='".$theHeight."'";\r
- $sqlUpdateMetadata .= " WHERE id = $temId[0] AND sessionId ='$temId[1]'";\r
- //$sqlUpdateMetadata .= " AND login='$theLogin'";\r
- //echo '<br/>'.$sqlUpdateMetadata;\r
- $result1 = mysql_query($sqlUpdateMetadata, $db);\r
- $result1 = null;\r
- }\r
- $result = null;\r
- \r
- //return '<h3>Data Saved in : '.$row['captionFile'].'</h3>';\r
- return '<p>Data Saved in : '.$theCaptionFilePathFull.'</p>';\r
- }\r
-\r
- } // _saveCaptionData()\r
- \r
- \r
-} // end class\r
-?>
\ No newline at end of file