2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
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 /************************************************************************/
14 * This script creates the interface of "edit content" => "adapted content"
17 if (!defined('TR_INCLUDE_PATH')) { exit; }
18 include_once(TR_INCLUDE_PATH.'classes/DAO/ResourceTypesDAO.class.php');
19 include_once(TR_INCLUDE_PATH.'classes/DAO/DAO.class.php');
22 $resourceTypesDAO = new ResourceTypesDAO();
24 global $_content_id, $content_row, $msg;
28 $msg->printErrors('SAVE_BEFORE_PROCEED');
29 require_once(TR_INCLUDE_PATH.'footer.inc.php');
33 * This function returns the preview link of the given file
34 * @param $file the file location in "file manager"
35 * @return the relative URL to preview the file
37 function get_preview_link($file)
39 global $content_row, $_course_id;
41 if (substr($file, 0 , 7) == 'http://' || substr($file, 0 , 8) == 'https://') {
44 if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) {
45 $get_file = 'get.php/';
47 $get_file = 'content/' . $_course_id . '/';
51 return $get_file.$content_row['content_path'].'/'.$file;
55 * When the file name is a remote URL, this function reduces the full URL
57 * @return the reduced name
59 function get_display_filename($filename)
61 if (substr($filename, 0 , 7) == 'http://' || substr($filename, 0 , 8) == 'https://') {
62 if (substr($filename, 0 , 7) == 'http://') $prefix = 'http://';
63 if (substr($filename, 0 , 8) == 'https://') $prefix = 'https://';
64 $name = substr($filename, strrpos($filename, '/'));
65 $filename = $prefix.'...'.$name;
71 * Display alternative table cell
72 * @param $secondary_result mysql result of all secondary alternatives
73 * $alternative type the resource type of the alternative to display. Must be one of the values in resource_types.type_id
74 * $content_id used to pass into file_manager/index.php
75 * $pid primary resource id
76 * $td_header_id the id of the table header cell, to comply with accessibility rule
77 * @return html of the table cell "<td>...</td>"
79 function display_alternative_cell($secondary_resources, $alternative_type, $content_id, $pid, $td_header_id)
81 global $content_row, $_course_id;
83 $found_alternative = false;
85 echo ' <td headers="'.$td_header_id.'">'."\n";
87 if (is_array($secondary_resources))
89 // mysql_data_seek($secondary_result, 0); // move the mysql result cursor back to the first row
90 foreach ($secondary_resources as $secondary_resource)
92 if ($secondary_resource['type_id'] == $alternative_type)
94 echo ' <div id="'.$pid.'_'.$alternative_type.'">'."\n";
95 echo ' <a href="'.get_preview_link($secondary_resource['secondary_resource']).'" title="'._AT('new_window').'" target="_new">'.get_display_filename($secondary_resource['secondary_resource']).'</a><br />'."\n";
96 echo ' <a href="#" onclick="trans.utility.poptastic(\''.TR_BASE_HREF.'file_manager/index.php?framed=1'. SEP.'popup=1'. SEP.'cp='. $content_row['content_path'].SEP.'_cid='.$content_id.SEP.'pid='.$pid.SEP.'a_type='.$alternative_type.'\');return false;" title="'._AT('new_window').'">'."\n";
97 echo ' <img src="'.TR_BASE_HREF.'images/alter.png" border="0" title="'._AT('alter').'" alt="'._AT('alter').'" />'."\n";
99 echo ' <a href="#" onclick="removeAlternative(\''.$content_row['content_path'].'\', '.$content_id.','.$pid.','.$alternative_type.');return false;">'."\n";
100 echo ' <img src="'.TR_BASE_HREF.'images/remove.gif" border="0" title="'._AT('remove').'" alt="'._AT('remove').'" />'."\n";
103 $found_alternative = true;
108 if (!$found_alternative)
110 echo ' <div id="'.$pid.'_'.$alternative_type.'">'."\n";
111 echo ' <input type="button" value="'._AT('add').'" title="'._AT('new_window').'" onclick="trans.utility.poptastic(\''.TR_BASE_HREF.'file_manager/index.php?framed=1'. SEP.'popup=1'. SEP.'cp='. $content_row['content_path'].SEP.'_cid='.$content_id.SEP.'pid='.$pid.SEP.'a_type='.$alternative_type.'\');return false;" />'."\n";
118 require(TR_INCLUDE_PATH.'lib/resources_parser.inc.php');
120 if (count($resources)==0)
122 echo '<p>'. _AT('No_resources'). '</p>';
126 $is_post_indicator_set = false;
127 // get all resource types
128 // $sql = "SELECT * FROM ".TABLE_PREFIX."resource_types";
129 // $resource_types_result = mysql_query($sql, $db);
130 $resource_types = $resourceTypesDAO->getAll();
132 echo '<br /><table class="data" rules="all">'."\n";
133 echo ' <thead>'."\n";
135 echo ' <th rowspan="2" id="header1">'._AT('original_resource').'</th>'."\n";
136 echo ' <th rowspan="2" id="header2">'._AT('resource_type').'</th>'."\n";
137 echo ' <th colspan="4">'._AT('alternatives').'</th>'."\n";
140 echo ' <th id="header3">'._AT('text').'</th>'."\n";
141 echo ' <th id="header4">'._AT('audio').'</th>'."\n";
142 echo ' <th id="header5">'._AT('visual').'</th>'."\n";
143 echo ' <th id="header6">'._AT('sign_lang').'</th>'."\n";
145 echo ' </thead>'."\n";
148 foreach($resources as $primary_resource)
150 // check whether the primary resource is in the table
151 $sql = "SELECT * FROM ".TABLE_PREFIX."primary_resources
152 WHERE content_id = ".$cid."
153 AND language_code = '".$_SESSION['lang']."'
154 AND resource='".$primary_resource."'";
155 // $primary_result = mysql_query($sql, $db);
156 $existing_primary_resource = $dao->execute($sql);
158 // insert primary resource if it's not in db
159 if (!is_array($existing_primary_resource))
160 // if (mysql_num_rows($primary_result) == 0)
162 $sql = "INSERT INTO ".TABLE_PREFIX."primary_resources (content_id, resource, language_code)
163 VALUES (".$cid.", '".$primary_resource."', '".$_SESSION['lang']."')";
164 // $result = mysql_query($sql, $db);
166 $primary_resource_id = mysql_insert_id();
170 // get primary resource id
171 // $primary_resource_row = mysql_fetch_assoc($primary_result);
172 $primary_resource_id = $existing_primary_resource[0]['primary_resource_id'];
175 $sql = "SELECT prt.type_id, rt.type
176 FROM ".TABLE_PREFIX."primary_resources pr, ".
177 TABLE_PREFIX."primary_resources_types prt, ".
178 TABLE_PREFIX."resource_types rt
179 WHERE pr.content_id = ".$cid."
180 AND pr.language_code = '".$_SESSION['lang']."'
181 AND pr.resource='".$primary_resource."'
182 AND pr.primary_resource_id = prt.primary_resource_id
183 AND prt.type_id = rt.type_id";
184 // $primary_type_result = mysql_query($sql, $db);
185 $primary_types = $dao->execute($sql);
187 if (!$is_post_indicator_set)
189 echo ' <input type="hidden" name="use_post_for_alt" value="1" />'."\n";
190 $is_post_indicator_set = true;
193 // get secondary resources for the current primary resource
194 $sql = "SELECT pr.primary_resource_id, sr.secondary_resource, srt.type_id
195 FROM ".TABLE_PREFIX."primary_resources pr, ".
196 TABLE_PREFIX."secondary_resources sr, ".
197 TABLE_PREFIX."secondary_resources_types srt
198 WHERE pr.content_id = ".$cid."
199 AND pr.language_code = '".$_SESSION['lang']."'
200 AND pr.resource='".$primary_resource."'
201 AND pr.primary_resource_id = sr.primary_resource_id
202 AND sr.secondary_resource_id = srt.secondary_resource_id";
203 // $secondary_result = mysql_query($sql, $db);
204 $secondary_resources = $dao->execute($sql);
208 // table cell "original resource"
209 echo ' <td headers="header1">'."\n";
210 echo ' <a href="'.get_preview_link($primary_resource).'" title="'._AT('new_window').'" target="_new">'.get_display_filename($primary_resource).'</a>'."\n";
213 // table cell "original resource type"
214 echo ' <td headers="header2">'."\n";
216 // mysql_data_seek($resource_types_result, 0); // move the mysql result cursor back to the first row
217 // while ($resource_type = mysql_fetch_assoc($resource_types_result))
218 if (is_array($resource_types))
220 foreach ($resource_types as $resource_type) {
221 if ($resource_type['type'] == 'sign_language')
225 echo '<input type="checkbox" name="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'" value="1" id="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'"';
226 if ($_POST['use_post_for_alt'])
228 if (isset($_POST['alt_'.$primary_resource_id.'_'.$resource_type['type_id']])) {
229 echo 'checked="checked"';
233 if (is_array($primary_types)) {
234 foreach ($primary_types as $primary_resource_type) {
235 if ($primary_resource_type['type_id'] == $resource_type['type_id']){
236 echo 'checked="checked"';
243 echo '<label for="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'">'. _AT($resource_type['type']).'</label><br/>'."\n";
249 // table cell "text alternative"
250 display_alternative_cell($secondary_resources, 3, $cid, $primary_resource_id, "header3");
252 // table cell "audio"
253 display_alternative_cell($secondary_resources, 1, $cid, $primary_resource_id, "header4");
255 // table cell "visual"
256 display_alternative_cell($secondary_resources, 4, $cid, $primary_resource_id, "header5");
258 // table cell "sign language"
259 display_alternative_cell($secondary_resources, 2, $cid, $primary_resource_id, "header6");
263 echo ' </tbody>'."\n";
264 echo '</table><br /><br />'."\n";
268 <script type="text/javascript">
270 // This function does:
271 // 1. save the removal into db via ajax
272 // 2. set the according field to "add" button
273 function removeAlternative(contentPath, cid, pid, a_type)
275 jQuery.post("<?php echo TR_BASE_HREF; ?>home/editor/remove_alternative.php",
276 {"pid":pid, "a_type":a_type},
279 var button_html = ' <input type="button" value="<?php echo _AT('add'); ?>" title="<?php echo _AT('new_window'); ?>" onclick="trans.utility.poptastic(\\\'<?php echo TR_BASE_HREF; ?>file_manager/index.php?framed=1<?php echo SEP; ?>popup=1<?php echo SEP; ?>cp='+contentPath+'<?php echo SEP; ?>_cid='+cid+'<?php echo SEP; ?>pid='+pid+'<?php echo SEP; ?>a_type='+a_type+'\\\');return false;" />';
280 eval("document.getElementById(\""+pid+"_"+a_type+"\").innerHTML = '"+button_html+"'");