2 /********************************************************************/
4 /********************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /********************************************************************/
17 * Accessforall General class.
18 * Based on the specification at:
19 * http://www.imsglobal.org/accessibility/index.html
26 var $cid = 0; //content id
27 var $resource_types = array(); //resource types hash mapping
28 var $relative_path = ''; //relative path to the file
32 $this->cid = intval($cid);
36 // Return resources type hash mapping.
37 function getResourcesType($type_id=0){
40 $type_id = intval($type_id);
42 //if this is the first time calling this function, grab the list from db
43 if (empty($resource_types)){
44 $sql = 'SELECT * FROM '.TABLE_PREFIX.'resource_types';
45 $result = mysql_query($sql, $db);
46 while ($row = mysql_fetch_assoc($result)){
47 $this->resource_types[$row['type_id']] = $row['type'];
51 if (!empty($this->resource_types[$type_id])){
52 return $this->resource_types[$type_id];
54 return $this->resource_types;
58 // Get primary resources
59 function getPrimaryResources(){
62 $pri_resources = array(); // cid=>[resource, language code]
63 $sql = 'SELECT * FROM '.TABLE_PREFIX.'primary_resources WHERE content_id='.$this->cid.' ORDER BY primary_resource_id';
64 $result = mysql_query($sql, $db);
65 if (mysql_numrows($result) > 0){
66 while ($row = mysql_fetch_assoc($result)){
67 $pri_resources[$row['primary_resource_id']]['resource'] = $row['resource'];
68 if ($row['language_code'] != ''){
69 $pri_resources[$row['primary_resource_id']]['language_code'] = $row['language_code'];
73 return $pri_resources;
77 // Get primary resources by resource name
78 function getPrimaryResourceByName($primary_resource){
81 $sql = "SELECT * FROM ".TABLE_PREFIX."primary_resources
82 WHERE content_id=".$this->cid."
83 AND language_code = '".$_SESSION['lang']."'
84 AND resource='".$primary_resource."'";
85 $result = mysql_query($sql, $db);
86 if (mysql_numrows($result) > 0){
87 return mysql_fetch_assoc($result);
94 // Get primary resources types
95 function getPrimaryResourcesTypes($pri_resource_id=0){
98 $pri_resource_id = intval($pri_resource_id);
100 //quit if id not specified
101 if ($pri_resource_id == 0) {
105 $pri_resources_types = array(); // cid=>[type id]+
106 $sql = 'SELECT * FROM '.TABLE_PREFIX.'primary_resources_types WHERE primary_resource_id='.$pri_resource_id;
107 $result = mysql_query($sql, $db);
109 while ($row = mysql_fetch_assoc($result)){
110 $pri_resources_types[$pri_resource_id][] = $row['type_id'];
113 return $pri_resources_types;
117 // Get secondary resources
118 function getSecondaryResources($pri_resource_id=0){
121 $pri_resource_id = intval($pri_resource_id);
123 //quit if id not specified
124 if ($pri_resource_id == 0) {
128 $sec_resources = array(); // cid=>[resource, language code]
129 $sql = 'SELECT * FROM '.TABLE_PREFIX.'secondary_resources WHERE primary_resource_id='.$pri_resource_id;
130 $result = mysql_query($sql, $db);
132 while ($row = mysql_fetch_assoc($result)){
133 $sec_resources[$row['secondary_resource_id']]['resource'] = $row['secondary_resource'];
134 if ($row['language_code'] != ''){
135 $sec_resources[$row['secondary_resource_id']]['language_code'] = $row['language_code'];
139 return $sec_resources;
143 // Get secondary resources types
144 function getSecondaryResourcesTypes($sec_resource_id=0){
147 $sec_resource_id = intval($sec_resource_id);
149 //quit if id not specified
150 if ($sec_resource_id == 0) {
154 $sec_resources_types = array(); // cid=>[type id]+
155 $sql = 'SELECT * FROM '.TABLE_PREFIX.'secondary_resources_types WHERE secondary_resource_id='.$sec_resource_id;
156 $result = mysql_query($sql, $db);
158 while ($row = mysql_fetch_assoc($result)){
159 $sec_resources_types[] = $row['type_id'];
162 return $sec_resources_types;
166 // Insert primary resources into the db
167 // @return primary resource id.
168 function setPrimaryResource($content_id, $file_name, $lang){
169 global $addslashes, $db;
171 $content_id = intval($content_id);
172 $file_name = $addslashes(convert_amp($file_name));
173 $lang = $addslashes($lang);
175 $sql = "INSERT INTO ".TABLE_PREFIX."primary_resources SET content_id=$content_id, resource='$file_name', language_code='$lang'";
176 $result = mysql_query($sql, $db);
178 return mysql_insert_id();
183 // Insert primary resource type
184 function setPrimaryResourceType($primary_resource_id, $type_id){
187 $primary_resource_id= intval($primary_resource_id);
188 $type_id = intval($type_id);
190 $sql = "INSERT INTO ".TABLE_PREFIX."primary_resources_types SET primary_resource_id=$primary_resource_id, type_id=$type_id";
191 $result = mysql_query($sql, $db);
194 // Insert secondary resource
195 // @return secondary resource id
196 function setSecondaryResource($primary_resource_id, $file_name, $lang){
197 global $addslashes, $db;
199 $primary_resource_id = intval($primary_resource_id);
200 $file_name = $addslashes(convert_amp($file_name));
201 $lang = $addslashes($lang);
203 $sql = "INSERT INTO ".TABLE_PREFIX."secondary_resources SET primary_resource_id=$primary_resource_id, secondary_resource='$file_name', language_code='$lang'";
204 $result = mysql_query($sql, $db);
206 return mysql_insert_id();
211 // Insert secondary resource
212 function setSecondaryResourceType($secondary_resource, $type_id){
215 $secondary_resource = intval($secondary_resource);
216 $type_id = intval($type_id);
218 $sql = "INSERT INTO ".TABLE_PREFIX."secondary_resources_types SET secondary_resource_id=$secondary_resource, type_id=$type_id";
219 $result = mysql_query($sql, $db);
223 // Set the relative path to all files
224 function setRelativePath($path){
225 $this->relative_path = $path . '/';
230 * Delete this primary resource and all its associated secondary resources
231 * @param int primary resournce id
233 function deletePrimaryResource($primary_rid){
235 // Delete all secondary a4a
236 $sql = 'DELETE c, d FROM '.TABLE_PREFIX.'secondary_resources c LEFT JOIN '.TABLE_PREFIX."secondary_resources_types d ON c.secondary_resource_id=d.secondary_resource_id WHERE primary_resource_id=$primary_rid";
237 $result = mysql_query($sql, $db);
239 // If successful, remove all primary resources
241 $sql = 'DELETE a, b FROM '.TABLE_PREFIX.'primary_resources a LEFT JOIN '.TABLE_PREFIX."primary_resources_types b ON a.primary_resource_id=b.primary_resource_id WHERE a.primary_resource_id=$primary_rid";
242 mysql_query($sql, $db);
246 // Delete all materials associated with this content
247 function deleteA4a(){
250 $pri_resource_ids = array();
252 // Get all primary resources ID out that're associated with this content
253 $sql = 'SELECT a.primary_resource_id FROM '.TABLE_PREFIX.'primary_resources a LEFT JOIN '.TABLE_PREFIX.'primary_resources_types b ON a.primary_resource_id=b.primary_resource_id WHERE content_id='.$this->cid;
254 $result = mysql_query($sql);
256 while($row=mysql_fetch_assoc($result)){
257 $pri_resource_ids[] = $row['primary_resource_id'];
260 //If the are primary resources found
261 if (!empty($pri_resource_ids)){
262 $glued_pri_ids = implode(",", $pri_resource_ids);
264 // Delete all secondary a4a
265 $sql = 'DELETE c, d FROM '.TABLE_PREFIX.'secondary_resources c LEFT JOIN '.TABLE_PREFIX.'secondary_resources_types d ON c.secondary_resource_id=d.secondary_resource_id WHERE primary_resource_id IN ('.$glued_pri_ids.')';
266 $result = mysql_query($sql);
268 // If successful, remove all primary resources
270 $sql = 'DELETE a, b FROM '.TABLE_PREFIX.'primary_resources a LEFT JOIN '.TABLE_PREFIX.'primary_resources_types b ON a.primary_resource_id=b.primary_resource_id WHERE content_id='.$this->cid;