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 if ($_POST['formatting'] <> 1)
99 $msg->addFeedback('NO_A4A_FOR_PLAIN_TEXT');
102 global $db, $content_row, $stripslashes;
103 populate_a4a($cid, $stripslashes($_POST['body_text']), $_POST['formatting']);
105 include_once(TR_INCLUDE_PATH.'classes/A4a/A4a.class.php');
107 $a4a = new A4a($cid);
108 $primary_resources = $a4a->getPrimaryResources();
110 if (count($primary_resources)==0)
112 $msg->addFeedback('NO_RESOURCES');
117 $is_post_indicator_set = false;
118 // get all resource types
119 $resource_types = $resourceTypesDAO->getAll();
121 echo '<br /><table class="data" rules="all">'."\n";
122 echo ' <thead>'."\n";
124 echo ' <th rowspan="2" id="header1">'._AT('original_resource').'</th>'."\n";
125 echo ' <th rowspan="2" id="header2">'._AT('resource_type').'</th>'."\n";
126 echo ' <th colspan="4">'._AT('alternatives').'</th>'."\n";
129 echo ' <th id="header3">'._AT('text').'</th>'."\n";
130 echo ' <th id="header4">'._AT('audio').'</th>'."\n";
131 echo ' <th id="header5">'._AT('visual').'</th>'."\n";
132 echo ' <th id="header6">'._AT('sign_lang').'</th>'."\n";
134 echo ' </thead>'."\n";
137 foreach($primary_resources as $primary_resource_id => $primary_resource_row)
139 $primary_resource = $primary_resource_row['resource'];
141 $sql = "SELECT prt.type_id, rt.type
142 FROM ".TABLE_PREFIX."primary_resources pr, ".
143 TABLE_PREFIX."primary_resources_types prt, ".
144 TABLE_PREFIX."resource_types rt
145 WHERE pr.content_id = ".$cid."
146 AND pr.language_code = '".$_SESSION['lang']."'
147 AND pr.primary_resource_id='".$primary_resource_id."'
148 AND pr.primary_resource_id = prt.primary_resource_id
149 AND prt.type_id = rt.type_id";
150 // $primary_type_result = mysql_query($sql, $db);
151 $primary_types = $dao->execute($sql);
153 if (!$is_post_indicator_set)
155 echo ' <input type="hidden" name="use_post_for_alt" value="1" />'."\n";
156 $is_post_indicator_set = true;
159 // get secondary resources for the current primary resource
160 $sql = "SELECT pr.primary_resource_id, sr.secondary_resource, srt.type_id
161 FROM ".TABLE_PREFIX."primary_resources pr, ".
162 TABLE_PREFIX."secondary_resources sr, ".
163 TABLE_PREFIX."secondary_resources_types srt
164 WHERE pr.content_id = ".$cid."
165 AND pr.language_code = '".$_SESSION['lang']."'
166 AND pr.primary_resource_id='".$primary_resource_id."'
167 AND pr.primary_resource_id = sr.primary_resource_id
168 AND sr.secondary_resource_id = srt.secondary_resource_id";
169 // $secondary_result = mysql_query($sql, $db);
170 $secondary_resources = $dao->execute($sql);
174 // table cell "original resource"
175 echo ' <td headers="header1">'."\n";
176 echo ' <a href="'.$primary_resource.'" title="'._AT('new_window').'" target="_new">'.get_display_filename($primary_resource).'</a>'."\n";
179 // table cell "original resource type"
180 echo ' <td headers="header2">'."\n";
182 // mysql_data_seek($resource_types_result, 0); // move the mysql result cursor back to the first row
183 // while ($resource_type = mysql_fetch_assoc($resource_types_result))
184 if (is_array($resource_types))
186 foreach ($resource_types as $resource_type) {
187 if ($resource_type['type'] == 'sign_language')
191 echo '<input type="checkbox" name="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'" value="1" id="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'"';
192 if ($_POST['use_post_for_alt'])
194 if (isset($_POST['alt_'.$primary_resource_id.'_'.$resource_type['type_id']])) {
195 echo 'checked="checked"';
199 if (is_array($primary_types)) {
200 foreach ($primary_types as $primary_resource_type) {
201 if ($primary_resource_type['type_id'] == $resource_type['type_id']){
202 echo 'checked="checked"';
209 echo '<label for="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'">'. _AT($resource_type['type']).'</label><br/>'."\n";
215 // table cell "text alternative"
216 display_alternative_cell($secondary_resources, 3, $cid, $primary_resource_id, "header3");
218 // table cell "audio"
219 display_alternative_cell($secondary_resources, 1, $cid, $primary_resource_id, "header4");
221 // table cell "visual"
222 display_alternative_cell($secondary_resources, 4, $cid, $primary_resource_id, "header5");
224 // table cell "sign language"
225 display_alternative_cell($secondary_resources, 2, $cid, $primary_resource_id, "header6");
229 echo ' </tbody>'."\n";
230 echo '</table><br /><br />'."\n";
234 <script type="text/javascript">
236 // This function does:
237 // 1. save the removal into db via ajax
238 // 2. set the according field to "add" button
239 function removeAlternative(contentPath, cid, pid, a_type)
241 jQuery.post("<?php echo TR_BASE_HREF; ?>home/editor/remove_alternative.php",
242 {"pid":pid, "a_type":a_type},
245 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;" />';
246 eval("document.getElementById(\""+pid+"_"+a_type+"\").innerHTML = '"+button_html+"'");
251 } // else ($_POST['formatting'] <> 0)