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 /****************************************************************/
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 * When the file name is a remote URL, this function reduces the full URL
30 * @return the reduced name
32 function get_display_filename($filename)
34 if (substr($filename, 0 , 7) == 'http://' || substr($filename, 0 , 8) == 'https://') {
35 if (substr($filename, 0 , 7) == 'http://') $prefix = 'http://';
36 if (substr($filename, 0 , 8) == 'https://') $prefix = 'https://';
37 $name = substr($filename, strrpos($filename, '/'));
38 $filename = $prefix.'...'.$name;
44 * Display alternative table cell
45 * @param $secondary_result mysql result of all secondary alternatives
46 * $alternative type the resource type of the alternative to display. Must be one of the values in resource_types.type_id
47 * $content_id used to pass into file_manager/index.php
48 * $ps used to pass into file_manager/index.php
49 * @return html of the table cell "<td>...</td>"
51 function display_alternative_cell($secondary_result, $alternative_type, $content_id, $pid, $td_header_id)
55 $found_alternative = false;
57 echo ' <td headers="'.$td_header_id.'">'."\n";
59 if (mysql_num_rows($secondary_result) > 0)
61 mysql_data_seek($secondary_result, 0); // move the mysql result cursor back to the first row
62 while ($secondary_resource = mysql_fetch_assoc($secondary_result))
64 if ($secondary_resource['type_id'] == $alternative_type)
66 echo ' <div id="'.$pid.'_'.$alternative_type.'">'."\n";
67 echo ' <a href="'.$secondary_resource['secondary_resource'].'" title="'._AT('new_window').'" target="_new">'.get_display_filename($secondary_resource['secondary_resource']).'</a><br />'."\n";
68 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";
69 echo ' <img src="'.AT_BASE_HREF.'images/home-tests_sm.png" border="0" title="'._AT('alter').'" alt="'._AT('alter').'" />'."\n";
71 echo ' <a href="#" onclick="removeAlternative(\''.$content_row['content_path'].'\', '.$content_id.','.$pid.','.$alternative_type.');return false;">'."\n";
72 echo ' <img src="'.AT_BASE_HREF.'images/icon_delete.gif" border="0" title="'._AT('remove').'" alt="'._AT('remove').'" />'."\n";
75 $found_alternative = true;
80 if (!$found_alternative)
82 echo ' <div id="'.$pid.'_'.$alternative_type.'">'."\n";
83 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";
90 if ($_POST['formatting'] <> 1)
92 $msg->addFeedback('NO_A4A_FOR_PLAIN_TEXT');
95 global $db, $content_row, $stripslashes;
96 populate_a4a($cid, $stripslashes($_POST['body_text']), $_POST['formatting']);
98 include_once(AT_INCLUDE_PATH.'../mods/_core/imsafa/classes/A4a.class.php');
100 $a4a = new A4a($cid);
101 $primary_resources = $a4a->getPrimaryResources();
103 if (count($primary_resources)==0)
105 $msg->addFeedback('NO_RESOURCES');
110 $is_post_indicator_set = false;
111 // get all resource types
112 $sql = "SELECT * FROM ".TABLE_PREFIX."resource_types";
113 $resource_types_result = mysql_query($sql, $db);
115 echo '<table class="data" rules="all">'."\n";
116 echo ' <thead>'."\n";
118 echo ' <th rowspan="2" id="header1">'._AT('original_resource').'</th>'."\n";
119 echo ' <th rowspan="2" id="header2">'._AT('resource_type').'</th>'."\n";
120 echo ' <th colspan="4">'._AT('alternatives').'</th>'."\n";
123 echo ' <th id="header3">'._AT('text').'</th>'."\n";
124 echo ' <th id="header4">'._AT('audio').'</th>'."\n";
125 echo ' <th id="header5">'._AT('visual').'</th>'."\n";
126 echo ' <th id="header6">'._AT('sign_lang').'</th>'."\n";
128 echo ' </thead>'."\n";
132 foreach($primary_resources as $primary_resource_id => $primary_resource_row)
134 $primary_resource = $primary_resource_row['resource'];
136 $sql = "SELECT prt.type_id, rt.type
137 FROM ".TABLE_PREFIX."primary_resources pr, ".
138 TABLE_PREFIX."primary_resources_types prt, ".
139 TABLE_PREFIX."resource_types rt
140 WHERE pr.content_id = ".$cid."
141 AND pr.language_code = '".$_SESSION['lang']."'
142 AND pr.primary_resource_id='".$primary_resource_id."'
143 AND pr.primary_resource_id = prt.primary_resource_id
144 AND prt.type_id = rt.type_id";
145 $primary_type_result = mysql_query($sql, $db);
147 if (!$is_post_indicator_set)
149 echo ' <input type="hidden" name="use_post_for_alt" value="1" />'."\n";
150 $is_post_indicator_set = true;
153 // get secondary resources for the current primary resource
154 $sql = "SELECT pr.primary_resource_id, sr.secondary_resource, srt.type_id
155 FROM ".TABLE_PREFIX."primary_resources pr, ".
156 TABLE_PREFIX."secondary_resources sr, ".
157 TABLE_PREFIX."secondary_resources_types srt
158 WHERE pr.content_id = ".$cid."
159 AND pr.language_code = '".$_SESSION['lang']."'
160 AND pr.primary_resource_id='".$primary_resource_id."'
161 AND pr.primary_resource_id = sr.primary_resource_id
162 AND sr.secondary_resource_id = srt.secondary_resource_id";
163 $secondary_result = mysql_query($sql, $db);
167 // table cell "original resource"
168 echo ' <td headers="header1">'."\n";
169 echo ' <a href="'.$primary_resource.'" title="'._AT('new_window').'" target="_new">'.get_display_filename($primary_resource).'</a>'."\n";
172 // table cell "original resource type"
173 echo ' <td headers="header2">'."\n";
175 mysql_data_seek($resource_types_result, 0); // move the mysql result cursor back to the first row
176 while ($resource_type = mysql_fetch_assoc($resource_types_result))
178 if ($resource_type['type'] == 'sign_language')
182 echo '<input type="checkbox" name="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'" value="1" id="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'"';
183 if ($_POST['use_post_for_alt'])
185 if (isset($_POST['alt_'.$primary_resource_id.'_'.$resource_type['type_id']])) {
186 echo 'checked="checked"';
190 if (mysql_num_rows($primary_type_result)> 0) mysql_data_seek($primary_type_result, 0);
191 while ($primary_resource_type = mysql_fetch_assoc($primary_type_result)) {
192 if ($primary_resource_type['type_id'] == $resource_type['type_id']){
193 echo 'checked="checked"';
199 echo '<label for="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'">'. _AT($resource_type['type']).'</label><br/>'."\n";
204 // table cell "text alternative"
205 display_alternative_cell($secondary_result, 3, $cid, $primary_resource_id, "header3");
207 // table cell "audio"
208 display_alternative_cell($secondary_result, 1, $cid, $primary_resource_id, "header4");
210 // table cell "visual"
211 display_alternative_cell($secondary_result, 4, $cid, $primary_resource_id, "header5");
213 // table cell "sign language"
214 display_alternative_cell($secondary_result, 2, $cid, $primary_resource_id, "header6");
218 echo ' </tbody>'."\n";
219 echo '</table>'."\n";
221 echo '<br style="clear:both;"/>'."\n";
224 <script type="text/javascript">
226 // This function does:
227 // 1. save the removal into db via ajax
228 // 2. set the according field to "add" button
229 function removeAlternative(contentPath, cid, pid, a_type)
231 jQuery.post("<?php echo AT_BASE_HREF; ?>mods/_core/editor/remove_alternative.php",
232 {"pid":pid, "a_type":a_type},
235 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;" />';
236 eval("document.getElementById(\""+pid+"_"+a_type+"\").innerHTML = '"+button_html+"'");
241 } // else ($_POST['formatting'] <> 0)