PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/mods/_core/editor/editor_tabs/alternatives.inc.php

https://github.com/harriswong/ATutor
PHP | 242 lines | 171 code | 29 blank | 42 comment | 31 complexity | 4facb81ca1f4f125e2ed7218b013f187 MD5 | raw file
  1. <?php
  2. /****************************************************************/
  3. /* ATutor */
  4. /****************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* Inclusive Design Institute */
  7. /* http://atutor.ca */
  8. /* */
  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$
  14. /**
  15. * This script creates the interface of "edit content" => "adapted content"
  16. */
  17. if (!defined('AT_INCLUDE_PATH')) { exit; }
  18. if ($cid == 0) {
  19. $msg->printErrors('SAVE_BEFORE_PROCEED');
  20. require_once(AT_INCLUDE_PATH.'footer.inc.php');
  21. exit;
  22. }
  23. /**
  24. * When the file name is a remote URL, this function reduces the full URL
  25. * @param $filename
  26. * @return the reduced name
  27. */
  28. function get_display_filename($filename)
  29. {
  30. if (substr($filename, 0 , 7) == 'http://' || substr($filename, 0 , 8) == 'https://') {
  31. if (substr($filename, 0 , 7) == 'http://') $prefix = 'http://';
  32. if (substr($filename, 0 , 8) == 'https://') $prefix = 'https://';
  33. $name = substr($filename, strrpos($filename, '/'));
  34. $filename = $prefix.'...'.$name;
  35. }
  36. return $filename;
  37. }
  38. /**
  39. * Display alternative table cell
  40. * @param $secondary_result mysql result of all secondary alternatives
  41. * $alternative type the resource type of the alternative to display. Must be one of the values in resource_types.type_id
  42. * $content_id used to pass into file_manager/index.php
  43. * $ps used to pass into file_manager/index.php
  44. * @return html of the table cell "<td>...</td>"
  45. */
  46. function display_alternative_cell($secondary_result, $alternative_type, $content_id, $pid, $td_header_id)
  47. {
  48. global $content_row;
  49. $found_alternative = false;
  50. echo ' <td headers="'.$td_header_id.'">'."\n";
  51. if (mysql_num_rows($secondary_result) > 0)
  52. {
  53. mysql_data_seek($secondary_result, 0); // move the mysql result cursor back to the first row
  54. while ($secondary_resource = mysql_fetch_assoc($secondary_result))
  55. {
  56. if ($secondary_resource['type_id'] == $alternative_type)
  57. {
  58. echo ' <div id="'.$pid.'_'.$alternative_type.'">'."\n";
  59. echo ' <a href="'.$secondary_resource['secondary_resource'].'" title="'._AT('new_window').'" target="_new">'.get_display_filename($secondary_resource['secondary_resource']).'</a><br />'."\n";
  60. 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";
  61. echo ' <img src="'.AT_BASE_HREF.'images/home-tests_sm.png" border="0" title="'._AT('alter').'" alt="'._AT('alter').'" />'."\n";
  62. echo ' </a>'."\n";
  63. echo ' <a href="#" onclick="removeAlternative(\''.$content_row['content_path'].'\', '.$content_id.','.$pid.','.$alternative_type.');return false;">'."\n";
  64. echo ' <img src="'.AT_BASE_HREF.'images/icon_delete.gif" border="0" title="'._AT('remove').'" alt="'._AT('remove').'" />'."\n";
  65. echo ' </a>'."\n";
  66. echo ' </div>'."\n";
  67. $found_alternative = true;
  68. break;
  69. }
  70. }
  71. }
  72. if (!$found_alternative)
  73. {
  74. echo ' <div id="'.$pid.'_'.$alternative_type.'">'."\n";
  75. 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";
  76. echo ' </div>'."\n";
  77. }
  78. echo ' </td>'."\n";
  79. }
  80. // Main program
  81. if ($_POST['formatting'] <> 1)
  82. {
  83. $msg->addFeedback('NO_A4A_FOR_PLAIN_TEXT');
  84. $msg->printAll();
  85. } else {
  86. global $db, $content_row, $stripslashes;
  87. populate_a4a($cid, $stripslashes($_POST['body_text']), $_POST['formatting']);
  88. include_once(AT_INCLUDE_PATH.'../mods/_core/imsafa/classes/A4a.class.php');
  89. $a4a = new A4a($cid);
  90. $primary_resources = $a4a->getPrimaryResources();
  91. if (count($primary_resources)==0)
  92. {
  93. $msg->addFeedback('NO_RESOURCES');
  94. $msg->printAll();
  95. }
  96. else
  97. {
  98. $is_post_indicator_set = false;
  99. // get all resource types
  100. $sql = "SELECT * FROM ".TABLE_PREFIX."resource_types";
  101. $resource_types_result = mysql_query($sql, $db);
  102. echo '<table class="data" rules="all">'."\n";
  103. echo ' <thead>'."\n";
  104. echo ' <tr>'."\n";
  105. echo ' <th rowspan="2" id="header1">'._AT('original_resource').'</th>'."\n";
  106. echo ' <th rowspan="2" id="header2">'._AT('resource_type').'</th>'."\n";
  107. echo ' <th colspan="4">'._AT('alternatives').'</th>'."\n";
  108. echo ' </tr>'."\n";
  109. echo ' <tr>'."\n";
  110. echo ' <th id="header3">'._AT('text').'</th>'."\n";
  111. echo ' <th id="header4">'._AT('audio').'</th>'."\n";
  112. echo ' <th id="header5">'._AT('visual').'</th>'."\n";
  113. echo ' <th id="header6">'._AT('sign_lang').'</th>'."\n";
  114. echo ' </tr>'."\n";
  115. echo ' </thead>'."\n";
  116. echo ' <tbody>';
  117. foreach($primary_resources as $primary_resource_id => $primary_resource_row)
  118. {
  119. $primary_resource = $primary_resource_row['resource'];
  120. $sql = "SELECT prt.type_id, rt.type
  121. FROM ".TABLE_PREFIX."primary_resources pr, ".
  122. TABLE_PREFIX."primary_resources_types prt, ".
  123. TABLE_PREFIX."resource_types rt
  124. WHERE pr.content_id = ".$cid."
  125. AND pr.language_code = '".$_SESSION['lang']."'
  126. AND pr.primary_resource_id='".$primary_resource_id."'
  127. AND pr.primary_resource_id = prt.primary_resource_id
  128. AND prt.type_id = rt.type_id";
  129. $primary_type_result = mysql_query($sql, $db);
  130. if (!$is_post_indicator_set)
  131. {
  132. echo ' <input type="hidden" name="use_post_for_alt" value="1" />'."\n";
  133. $is_post_indicator_set = true;
  134. }
  135. // get secondary resources for the current primary resource
  136. $sql = "SELECT pr.primary_resource_id, sr.secondary_resource, srt.type_id
  137. FROM ".TABLE_PREFIX."primary_resources pr, ".
  138. TABLE_PREFIX."secondary_resources sr, ".
  139. TABLE_PREFIX."secondary_resources_types srt
  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 = sr.primary_resource_id
  144. AND sr.secondary_resource_id = srt.secondary_resource_id";
  145. $secondary_result = mysql_query($sql, $db);
  146. echo ' <tr>'."\n";
  147. // table cell "original resource"
  148. echo ' <td headers="header1">'."\n";
  149. echo ' <a href="'.$primary_resource.'" title="'._AT('new_window').'" target="_new">'.get_display_filename($primary_resource).'</a>'."\n";
  150. echo ' </td>'."\n";
  151. // table cell "original resource type"
  152. echo ' <td headers="header2">'."\n";
  153. mysql_data_seek($resource_types_result, 0); // move the mysql result cursor back to the first row
  154. while ($resource_type = mysql_fetch_assoc($resource_types_result))
  155. {
  156. if ($resource_type['type'] == 'sign_language')
  157. continue;
  158. else
  159. {
  160. echo '<input type="checkbox" name="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'" value="1" id="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'"';
  161. if ($_POST['use_post_for_alt'])
  162. {
  163. if (isset($_POST['alt_'.$primary_resource_id.'_'.$resource_type['type_id']])) {
  164. echo 'checked="checked"';
  165. }
  166. }
  167. else {
  168. if (mysql_num_rows($primary_type_result)> 0) mysql_data_seek($primary_type_result, 0);
  169. while ($primary_resource_type = mysql_fetch_assoc($primary_type_result)) {
  170. if ($primary_resource_type['type_id'] == $resource_type['type_id']){
  171. echo 'checked="checked"';
  172. break;
  173. }
  174. }
  175. }
  176. echo '/>'."\n";
  177. echo '<label for="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'">'. _AT($resource_type['type']).'</label><br/>'."\n";
  178. }
  179. }
  180. echo ' </td>'."\n";
  181. // table cell "text alternative"
  182. display_alternative_cell($secondary_result, 3, $cid, $primary_resource_id, "header3");
  183. // table cell "audio"
  184. display_alternative_cell($secondary_result, 1, $cid, $primary_resource_id, "header4");
  185. // table cell "visual"
  186. display_alternative_cell($secondary_result, 4, $cid, $primary_resource_id, "header5");
  187. // table cell "sign language"
  188. display_alternative_cell($secondary_result, 2, $cid, $primary_resource_id, "header6");
  189. echo ' </tr>'."\n";
  190. }
  191. echo ' </tbody>'."\n";
  192. echo '</table>'."\n";
  193. }
  194. echo '<br style="clear:both;"/>'."\n";
  195. ?>
  196. <script type="text/javascript">
  197. //<!--
  198. // This function does:
  199. // 1. save the removal into db via ajax
  200. // 2. set the according field to "add" button
  201. function removeAlternative(contentPath, cid, pid, a_type)
  202. {
  203. jQuery.post("<?php echo AT_BASE_HREF; ?>mods/_core/editor/remove_alternative.php",
  204. {"pid":pid, "a_type":a_type},
  205. function(data) {});
  206. 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;" />';
  207. eval("document.getElementById(\""+pid+"_"+a_type+"\").innerHTML = '"+button_html+"'");
  208. }
  209. //-->
  210. </script>
  211. <?php
  212. } // else ($_POST['formatting'] <> 0)
  213. ?>