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');
34 * When the file name is a remote URL, this function reduces the full URL
36 * @return the reduced name
38 function get_display_filename($filename)
40 if (substr($filename, 0 , 7) == 'http://' || substr($filename, 0 , 8) == 'https://') {
41 if (substr($filename, 0 , 7) == 'http://') $prefix = 'http://';
42 if (substr($filename, 0 , 8) == 'https://') $prefix = 'https://';
43 $name = substr($filename, strrpos($filename, '/'));
44 $filename = $prefix.'...'.$name;
50 * Display alternative table cell
51 * @param $secondary_result mysql result of all secondary alternatives
52 * $alternative type the resource type of the alternative to display. Must be one of the values in resource_types.type_id
53 * $content_id used to pass into file_manager/index.php
54 * $pid primary resource id
55 * $td_header_id the id of the table header cell, to comply with accessibility rule
56 * @return html of the table cell "<td>...</td>"
58 function display_alternative_cell($secondary_resources, $alternative_type, $content_id, $pid, $td_header_id)
60 global $content_row, $_course_id;
62 $found_alternative = false;
64 echo ' <td headers="'.$td_header_id.'">'."\n";
66 if (is_array($secondary_resources))
68 // mysql_data_seek($secondary_result, 0); // move the mysql result cursor back to the first row
69 foreach ($secondary_resources as $secondary_resource)
71 if ($secondary_resource['type_id'] == $alternative_type)
73 echo ' <div id="'.$pid.'_'.$alternative_type.'">'."\n";
74 echo ' <a href="'.$secondary_resource['secondary_resource'].'" title="'._AT('new_window').'" target="_new">'.get_display_filename($secondary_resource['secondary_resource']).'</a><br />'."\n";
75 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";
76 echo ' <img src="'.TR_BASE_HREF.'images/alter.png" border="0" title="'._AT('alter').'" alt="'._AT('alter').'" />'."\n";
78 echo ' <a href="#" onclick="removeAlternative(\''.$content_row['content_path'].'\', '.$content_id.','.$pid.','.$alternative_type.');return false;">'."\n";
79 echo ' <img src="'.TR_BASE_HREF.'images/remove.gif" border="0" title="'._AT('remove').'" alt="'._AT('remove').'" />'."\n";
82 $found_alternative = true;
87 if (!$found_alternative)
89 echo ' <div id="'.$pid.'_'.$alternative_type.'">'."\n";
90 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";
97 global $db, $content_row;
98 populate_a4a($cid, $_POST['body_text'], $_POST['formatting']);
100 include_once(TR_INCLUDE_PATH.'classes/A4a/A4a.class.php');
102 $a4a = new A4a($cid);
103 $primary_resources = $a4a->getPrimaryResources();
105 if (count($primary_resources)==0)
107 echo '<p>'. _AT('No_resources'). '</p>';
111 $is_post_indicator_set = false;
112 // get all resource types
113 // $sql = "SELECT * FROM ".TABLE_PREFIX."resource_types";
114 // $resource_types_result = mysql_query($sql, $db);
115 $resource_types = $resourceTypesDAO->getAll();
117 echo '<br /><table class="data" rules="all">'."\n";
118 echo ' <thead>'."\n";
120 echo ' <th rowspan="2" id="header1">'._AT('original_resource').'</th>'."\n";
121 echo ' <th rowspan="2" id="header2">'._AT('resource_type').'</th>'."\n";
122 echo ' <th colspan="4">'._AT('alternatives').'</th>'."\n";
125 echo ' <th id="header3">'._AT('text').'</th>'."\n";
126 echo ' <th id="header4">'._AT('audio').'</th>'."\n";
127 echo ' <th id="header5">'._AT('visual').'</th>'."\n";
128 echo ' <th id="header6">'._AT('sign_lang').'</th>'."\n";
130 echo ' </thead>'."\n";
133 foreach($primary_resources as $primary_resource_id => $primary_resource_row)
135 $primary_resource = $primary_resource_row['resource'];
137 $sql = "SELECT prt.type_id, rt.type
138 FROM ".TABLE_PREFIX."primary_resources pr, ".
139 TABLE_PREFIX."primary_resources_types prt, ".
140 TABLE_PREFIX."resource_types rt
141 WHERE pr.content_id = ".$cid."
142 AND pr.language_code = '".$_SESSION['lang']."'
143 AND pr.primary_resource_id='".$primary_resource_id."'
144 AND pr.primary_resource_id = prt.primary_resource_id
145 AND prt.type_id = rt.type_id";
146 // $primary_type_result = mysql_query($sql, $db);
147 $primary_types = $dao->execute($sql);
149 if (!$is_post_indicator_set)
151 echo ' <input type="hidden" name="use_post_for_alt" value="1" />'."\n";
152 $is_post_indicator_set = true;
155 // get secondary resources for the current primary resource
156 $sql = "SELECT pr.primary_resource_id, sr.secondary_resource, srt.type_id
157 FROM ".TABLE_PREFIX."primary_resources pr, ".
158 TABLE_PREFIX."secondary_resources sr, ".
159 TABLE_PREFIX."secondary_resources_types srt
160 WHERE pr.content_id = ".$cid."
161 AND pr.language_code = '".$_SESSION['lang']."'
162 AND pr.primary_resource_id='".$primary_resource_id."'
163 AND pr.primary_resource_id = sr.primary_resource_id
164 AND sr.secondary_resource_id = srt.secondary_resource_id";
165 // $secondary_result = mysql_query($sql, $db);
166 $secondary_resources = $dao->execute($sql);
170 // table cell "original resource"
171 echo ' <td headers="header1">'."\n";
172 echo ' <a href="'.$primary_resource.'" title="'._AT('new_window').'" target="_new">'.get_display_filename($primary_resource).'</a>'."\n";
175 // table cell "original resource type"
176 echo ' <td headers="header2">'."\n";
178 // mysql_data_seek($resource_types_result, 0); // move the mysql result cursor back to the first row
179 // while ($resource_type = mysql_fetch_assoc($resource_types_result))
180 if (is_array($resource_types))
182 foreach ($resource_types as $resource_type) {
183 if ($resource_type['type'] == 'sign_language')
187 echo '<input type="checkbox" name="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'" value="1" id="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'"';
188 if ($_POST['use_post_for_alt'])
190 if (isset($_POST['alt_'.$primary_resource_id.'_'.$resource_type['type_id']])) {
191 echo 'checked="checked"';
195 if (is_array($primary_types)) {
196 foreach ($primary_types as $primary_resource_type) {
197 if ($primary_resource_type['type_id'] == $resource_type['type_id']){
198 echo 'checked="checked"';
205 echo '<label for="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'">'. _AT($resource_type['type']).'</label><br/>'."\n";
211 // table cell "text alternative"
212 display_alternative_cell($secondary_resources, 3, $cid, $primary_resource_id, "header3");
214 // table cell "audio"
215 display_alternative_cell($secondary_resources, 1, $cid, $primary_resource_id, "header4");
217 // table cell "visual"
218 display_alternative_cell($secondary_resources, 4, $cid, $primary_resource_id, "header5");
220 // table cell "sign language"
221 display_alternative_cell($secondary_resources, 2, $cid, $primary_resource_id, "header6");
225 echo ' </tbody>'."\n";
226 echo '</table><br /><br />'."\n";
230 <script type="text/javascript">
232 // This function does:
233 // 1. save the removal into db via ajax
234 // 2. set the according field to "add" button
235 function removeAlternative(contentPath, cid, pid, a_type)
237 jQuery.post("<?php echo TR_BASE_HREF; ?>home/editor/remove_alternative.php",
238 {"pid":pid, "a_type":a_type},
241 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;" />';
242 eval("document.getElementById(\""+pid+"_"+a_type+"\").innerHTML = '"+button_html+"'");