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 /****************************************************************/
13 // $Id: alternatives.inc.php 7208 2008-07-04 16:07:24Z silvia $
16 * This script creates the interface of "edit content" => "adapted content"
19 if (!defined('AT_INCLUDE_PATH')) { exit; }
22 $msg->printErrors('SAVE_BEFORE_PROCEED');
23 require_once(AT_INCLUDE_PATH.'footer.inc.php');
28 * This function returns the preview link of the given file
29 * @param $file the file location in "file manager"
30 * @return the relative URL to preview the file
32 function get_preview_link($file)
36 if (substr($file, 0 , 7) == 'http://' || substr($file, 0 , 8) == 'https://') {
39 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
40 $get_file = 'get.php/';
42 $get_file = 'content/' . $_SESSION['course_id'] . '/';
45 return $get_file.$content_row['content_path'].'/'.$file;
50 * When the file name is a remote URL, this function reduces the full URL
52 * @return the reduced name
54 function get_display_filename($filename)
56 if (substr($filename, 0 , 7) == 'http://' || substr($filename, 0 , 8) == 'https://') {
57 if (substr($filename, 0 , 7) == 'http://') $prefix = 'http://';
58 if (substr($filename, 0 , 8) == 'https://') $prefix = 'https://';
59 $name = substr($filename, strrpos($filename, '/'));
60 $filename = $prefix.'...'.$name;
66 * Display alternative table cell
67 * @param $secondary_result mysql result of all secondary alternatives
68 * $alternative type the resource type of the alternative to display. Must be one of the values in resource_types.type_id
69 * $content_id used to pass into file_manager/index.php
70 * $ps used to pass into file_manager/index.php
71 * @return html of the table cell "<td>...</td>"
73 function display_alternative_cell($secondary_result, $alternative_type, $content_id, $pid, $td_header_id)
77 $found_alternative = false;
79 echo ' <td headers="'.$td_header_id.'">'."\n";
81 if (mysql_num_rows($secondary_result) > 0)
83 mysql_data_seek($secondary_result, 0); // move the mysql result cursor back to the first row
84 while ($secondary_resource = mysql_fetch_assoc($secondary_result))
86 if ($secondary_resource['type_id'] == $alternative_type)
88 echo ' <div id="'.$pid.'_'.$alternative_type.'">'."\n";
89 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";
90 echo ' <a href="#" onclick="ATutor.poptastic(\''.AT_BASE_HREF.'mods/_core/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";
91 echo ' <img src="'.AT_BASE_HREF.'images/home-tests_sm.png" border="0" title="'._AT('alter').'" alt="'._AT('alter').'" />'."\n";
93 echo ' <a href="#" onclick="removeAlternative(\''.$content_row['content_path'].'\', '.$content_id.','.$pid.','.$alternative_type.');return false;">'."\n";
94 echo ' <img src="'.AT_BASE_HREF.'images/icon_delete.gif" border="0" title="'._AT('remove').'" alt="'._AT('remove').'" />'."\n";
97 $found_alternative = true;
102 if (!$found_alternative)
104 echo ' <div id="'.$pid.'_'.$alternative_type.'">'."\n";
105 echo ' <input type="button" value="'._AT('add').'" title="'._AT('new_window').'" onclick="ATutor.poptastic(\''.AT_BASE_HREF.'mods/_core/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";
112 global $db, $content_row;
113 require(AT_INCLUDE_PATH.'../mods/_core/imsafa/html/resources_parser.inc.php');
115 if (count($resources)==0)
117 echo '<p>'. _AT('No_resources'). '</p>';
121 $is_post_indicator_set = false;
122 // get all resource types
123 $sql = "SELECT * FROM ".TABLE_PREFIX."resource_types";
124 $resource_types_result = mysql_query($sql, $db);
126 echo '<table class="data" rules="all" style="width:100%">'."\n";
127 echo ' <thead>'."\n";
129 echo ' <th rowspan="2" id="header1">'._AT('original_resource').'</th>'."\n";
130 echo ' <th rowspan="2" id="header2">'._AT('resource_type').'</th>'."\n";
131 echo ' <th colspan="4">'._AT('alternatives').'</th>'."\n";
134 echo ' <th id="header3">'._AT('text').'</th>'."\n";
135 echo ' <th id="header4">'._AT('audio').'</th>'."\n";
136 echo ' <th id="header5">'._AT('visual').'</th>'."\n";
137 echo ' <th id="header6">'._AT('sign_lang').'</th>'."\n";
139 echo ' </thead>'."\n";
142 foreach($resources as $primary_resource)
144 // check whether the primary resource is in the table
145 $sql = "SELECT * FROM ".TABLE_PREFIX."primary_resources
146 WHERE content_id = ".$cid."
147 AND language_code = '".$_SESSION['lang']."'
148 AND resource='".$primary_resource."'";
149 $primary_result = mysql_query($sql, $db);
151 // insert primary resource if it's not in db
152 if (mysql_num_rows($primary_result) == 0)
154 $sql = "INSERT INTO ".TABLE_PREFIX."primary_resources (content_id, resource, language_code)
155 VALUES (".$cid.", '".$primary_resource."', '".$_SESSION['lang']."')";
156 $result = mysql_query($sql, $db);
157 $primary_resource_id = mysql_insert_id();
161 // get primary resource id
162 $primary_resource_row = mysql_fetch_assoc($primary_result);
163 $primary_resource_id = $primary_resource_row['primary_resource_id'];
165 $sql = "SELECT prt.type_id, rt.type
166 FROM ".TABLE_PREFIX."primary_resources pr, ".
167 TABLE_PREFIX."primary_resources_types prt, ".
168 TABLE_PREFIX."resource_types rt
169 WHERE pr.content_id = ".$cid."
170 AND pr.language_code = '".$_SESSION['lang']."'
171 AND pr.resource='".$primary_resource."'
172 AND pr.primary_resource_id = prt.primary_resource_id
173 AND prt.type_id = rt.type_id";
174 $primary_type_result = mysql_query($sql, $db);
176 if (!$is_post_indicator_set)
178 echo ' <input type="hidden" name="use_post_for_alt" value="1" />'."\n";
179 $is_post_indicator_set = true;
182 // get secondary resources for the current primary resource
183 $sql = "SELECT pr.primary_resource_id, sr.secondary_resource, srt.type_id
184 FROM ".TABLE_PREFIX."primary_resources pr, ".
185 TABLE_PREFIX."secondary_resources sr, ".
186 TABLE_PREFIX."secondary_resources_types srt
187 WHERE pr.content_id = ".$cid."
188 AND pr.language_code = '".$_SESSION['lang']."'
189 AND pr.resource='".$primary_resource."'
190 AND pr.primary_resource_id = sr.primary_resource_id
191 AND sr.secondary_resource_id = srt.secondary_resource_id";
192 $secondary_result = mysql_query($sql, $db);
196 // table cell "original resource"
197 echo ' <td headers="header1">'."\n";
198 echo ' <a href="'.get_preview_link($primary_resource).'" title="'._AT('new_window').'" target="_new">'.get_display_filename($primary_resource).'</a>'."\n";
201 // table cell "original resource type"
202 echo ' <td headers="header2">'."\n";
204 mysql_data_seek($resource_types_result, 0); // move the mysql result cursor back to the first row
205 while ($resource_type = mysql_fetch_assoc($resource_types_result))
207 if ($resource_type['type'] == 'sign_language')
211 echo '<input type="checkbox" name="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'" value="1" id="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'"';
212 if ($_POST['use_post_for_alt'])
214 if (isset($_POST['alt_'.$primary_resource_id.'_'.$resource_type['type_id']])) {
215 echo 'checked="checked"';
219 if (mysql_num_rows($primary_type_result)> 0) mysql_data_seek($primary_type_result, 0);
220 while ($primary_resource_type = mysql_fetch_assoc($primary_type_result)) {
221 if ($primary_resource_type['type_id'] == $resource_type['type_id']){
222 echo 'checked="checked"';
228 echo '<label for="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'">'. _AT($resource_type['type']).'</label><br/>'."\n";
233 // table cell "text alternative"
234 display_alternative_cell($secondary_result, 3, $cid, $primary_resource_id, "header3");
236 // table cell "audio"
237 display_alternative_cell($secondary_result, 1, $cid, $primary_resource_id, "header4");
239 // table cell "visual"
240 display_alternative_cell($secondary_result, 4, $cid, $primary_resource_id, "header5");
242 // table cell "sign language"
243 display_alternative_cell($secondary_result, 2, $cid, $primary_resource_id, "header6");
247 echo ' </tbody>'."\n";
248 echo '</table>'."\n";
252 <script type="text/javascript">
254 // This function does:
255 // 1. save the removal into db via ajax
256 // 2. set the according field to "add" button
257 function removeAlternative(contentPath, cid, pid, a_type)
259 jQuery.post("<?php echo AT_BASE_HREF; ?>mods/_core/editor/remove_alternative.php",
260 {"pid":pid, "a_type":a_type},
263 var button_html = ' <input type="button" value="<?php echo _AT('add'); ?>" title="<?php echo _AT('new_window'); ?>" onclick="ATutor.poptastic(\\\'<?php echo AT_BASE_HREF; ?>mods/_core/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;" />';
264 eval("document.getElementById(\""+pid+"_"+a_type+"\").innerHTML = '"+button_html+"'");