http://www.atutor.ca/atutor/mantis/view.php?id=4179
authorcindy li <cli@ocad.ca>
Tue, 20 Apr 2010 15:40:42 +0000 (15:40 -0000)
committercindy li <cli@ocad.ca>
Tue, 20 Apr 2010 15:40:42 +0000 (15:40 -0000)
docs/content.php
docs/images/audio_alternative.png [new file with mode: 0644]
docs/images/pause.png [new file with mode: 0644]
docs/images/sign_lang_alternative.png [new file with mode: 0644]
docs/images/text_alternative.png [new file with mode: 0644]
docs/images/visual_alternative.png [new file with mode: 0644]
docs/include/lib/output.inc.php
docs/themes/default/content.tmpl.php
docs/themes/default/styles.css

index 23b4179..81da96a 100644 (file)
@@ -217,16 +217,29 @@ if ($released_status === TRUE || authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN))
                // if one of the prerequisite test(s) has expired, student cannot view the content 
                if (intval($pre_test_id) != -1 || authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN))
                {
-                       //Silvia: to provide appropriated content on the basis of users' preferences
-                       $content = provide_alternatives($cid, $content_row['text']);
-                       
+                       // find whether the body has alternatives defined
+                       list($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative)
+                       = provide_alternatives($cid, $content_row['text'], true);
+                       
+                       // apply alternatives
+                       if (intval($_GET['alternative']) > 0) {
+                               $content = provide_alternatives($cid, $content_row['text'], false, intval($_GET['alternative']));
+                       } else {
+                               $content = provide_alternatives($cid, $content_row['text']);
+                       }
+               
                        $content = format_content($content, $content_row['formatting'], $glossary);
        
                        $content_array = get_content_table($content);
                        
                        $savant->assign('content_table', $content_array[0]);
                        $savant->assign('body', $content_array[1]);
-       
+                       $savant->assign('cid', $cid);
+                       $savant->assign('has_text_alternative', $has_text_alternative);
+                       $savant->assign('has_audio_alternative', $has_audio_alternative);
+                       $savant->assign('has_visual_alternative', $has_visual_alternative);
+                       $savant->assign('has_sign_lang_alternative', $has_sign_lang_alternative);
+                                               
                        //assign test pages if there are tests associated with this content page
                        if (!empty($content_test_ids)){
                                $savant->assign('test_message', $content_row['test_message']);
diff --git a/docs/images/audio_alternative.png b/docs/images/audio_alternative.png
new file mode 100644 (file)
index 0000000..ead0370
Binary files /dev/null and b/docs/images/audio_alternative.png differ
diff --git a/docs/images/pause.png b/docs/images/pause.png
new file mode 100644 (file)
index 0000000..df812fb
Binary files /dev/null and b/docs/images/pause.png differ
diff --git a/docs/images/sign_lang_alternative.png b/docs/images/sign_lang_alternative.png
new file mode 100644 (file)
index 0000000..7810880
Binary files /dev/null and b/docs/images/sign_lang_alternative.png differ
diff --git a/docs/images/text_alternative.png b/docs/images/text_alternative.png
new file mode 100644 (file)
index 0000000..6ae9a76
Binary files /dev/null and b/docs/images/text_alternative.png differ
diff --git a/docs/images/visual_alternative.png b/docs/images/visual_alternative.png
new file mode 100644 (file)
index 0000000..25397f9
Binary files /dev/null and b/docs/images/visual_alternative.png differ
index b551ca4..aea6558 100644 (file)
@@ -1507,22 +1507,41 @@ function provide_alternatives1($cid, $content_page){
 * @access      public
 * @param       $cid:                           content id.
 * @param       $content:                       the original content page ($content_row['text'], from content.php).
+* @param    $info_only:         boolean. Default value is "false". When it's "true", returns an array of 4 values:
+*                               $has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative
+* @param    $only_on_secondary_type: Default value is "". Accept one of the values: 1(auditory), 2(sign_language), 3(text), 4(visual)
+*                               When the value is given, ignore the alternative preference settings and only replace/append 
+*                               (replace or append is still from session preference) the objects with the alternatives with
+*                               the given alternative types.
 * @return      string                          $content: the content page with the appropriated resources.
 * @see         $db                             from include/vitals.inc.php
 * @author      Cindy Qi Li
 */
-function provide_alternatives($cid, $content){
+function provide_alternatives($cid, $content, $info_only = false, $only_on_secondary_type = 0){
        global $db;
        
        $video_exts = array("mpg", "avi", "wmv", "mov", "swf", "mp3", "wav", "ogg", "mid", "mp4", "flv");
        $txt_exts = array("txt", "html", "htm");
        $image_exts = array("gif", "bmp", "png", "jpg", "jpeg", "png", "tif");
+       $only_on_secondary_type = intval($only_on_secondary_type);
        
-       if (($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_TEXT']==0) && ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_AUDIO']==0) && ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_VISUAL']==0)) 
+       if (!$info_only && !$only_on_secondary_type && 
+           ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_TEXT']==0) && 
+           ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_AUDIO']==0) && 
+           ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_VISUAL']==0)) 
        {
                //No user's preferences related to content format are declared
                return $content;
        }
+       
+       // intialize the 4 returned values when $info_only is on
+       if ($info_only)
+       {
+               $has_text_alternative = false;
+               $has_audio_alternative = false;
+               $has_visual_alternative = false;
+               $has_sign_lang_alternative = false;
+       }
 
        // get all relations between primary resources and their alternatives
        $sql = "SELECT c.content_path, pr.resource, prt.type_id primary_type, sr.secondary_resource, srt.type_id secondary_type
@@ -1536,15 +1555,20 @@ function provide_alternatives($cid, $content){
                       AND pr.primary_resource_id = sr.primary_resource_id
                       AND sr.language_code='".$_SESSION['prefs']['PREF_ALT_AUDIO_PREFER_LANG']."'
                       AND sr.secondary_resource_id = srt.secondary_resource_id
-                  AND pr.content_id = c.content_id
-                    ORDER BY pr.primary_resource_id, prt.type_id";
+                  AND pr.content_id = c.content_id";
+       if ($only_on_secondary_type > 0) {
+               $sql .= " AND srt.type_id=".$only_on_secondary_type;
+       }
+       $sql .= " ORDER BY pr.primary_resource_id, prt.type_id";
+       
        $result = mysql_query($sql, $db);
 //debug($sql);
        if (mysql_num_rows($result) == 0) return $content;
        
        while ($row = mysql_fetch_assoc($result)) 
        {
-               if (($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_TEXT']==1 && $row['primary_type']==3 &&
+               if ($info_only || $only_on_secondary_type ||
+                   ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_TEXT']==1 && $row['primary_type']==3 &&
                    ($_SESSION['prefs']['PREF_ALT_TO_TEXT']=="audio" && $row['secondary_type']==1 || 
                     $_SESSION['prefs']['PREF_ALT_TO_TEXT']=="visual" && $row['secondary_type']==4 || 
                     $_SESSION['prefs']['PREF_ALT_TO_TEXT']=="sign_lang" && $row['secondary_type']==2)) ||
@@ -1574,7 +1598,7 @@ function provide_alternatives($cid, $content){
                                        $file_location = $row['secondary_resource'];
                                
                                $file = AT_CONTENT_DIR.$_SESSION['course_id'] . '/'.$file_location;
-                               $target = file_get_contents($file);
+                               $target = '<br />'.file_get_contents($file);
                                
                                // check whether html file
                                if (preg_match('/.*\<html.*\<\/html\>.*/s', $target))
@@ -1608,41 +1632,92 @@ function provide_alternatives($cid, $content){
                                $pattern_replace_to = '${1}'.$target.'${3}';
                        else
                                $pattern_replace_to = '${1}${2}'.$target.'${3}';
-                               
+
+                       // *** Alternative replace/append starts from here ***
+                       $img_processed = false;    // The indicator to tell the source image is found (or not) 
+                                                  // and processed (or not) in an <img> tag. If found and processed, 
+                                                  // SKIP the found/process for <a> tag because the source is a image
+                                                  // and <a> is very likely the tag wrapping around <img>
+                                                   
                        // append/replace target alternative to [media]source[/media]
-                       $content = preg_replace("/(.*)(".preg_quote("[media").".*".preg_quote("]".$row['resource']."[/media]", "/").")(.*)/sU", 
-                                    $pattern_replace_to, $content);
-                       
-                       // append/replace target alternative to <a>...source...</a> or <a ...source...>...</a>
-                       if (preg_match("/\<a.*".preg_quote($row['resource'], "/").".*\<\/a\>/sU", $content))
+                       if (preg_match("/".preg_quote("[media").".*".preg_quote("]".$row['resource']."[/media]", "/")."/sU", $content))
                        {
-                               $content = preg_replace("/(.*)(\<a.*".preg_quote($row['resource'], "/").".*\<\/a\>)(.*)/sU", 
-                                               $pattern_replace_to, $content);
+                               if (!$info_only) {
+                                       $content = preg_replace("/(.*)(".preg_quote("[media").".*".preg_quote("]".$row['resource']."[/media]", "/").")(.*)/sU", 
+                                    $pattern_replace_to, $content);
+                               } else {
+                                       if ($row['secondary_type'] == 1) $has_audio_alternative = true;
+                                       if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
+                                       if ($row['secondary_type'] == 3) $has_text_alternative = true;
+                                       if ($row['secondary_type'] == 4) $has_visual_alternative = true;
+                               }
                        }
-
+                       
                        // append/replace target alternative to <img ... src="source" ...></a>
                        if (preg_match("/\<img.*src=\"".preg_quote($row['resource'], "/")."\".*\/\>/sU", $content))
                        {
-                               $content = preg_replace("/(.*)(\<img.*src=\"".preg_quote($row['resource'], "/")."\".*\/\>)(.*)/sU", 
+                               $img_processed = true;
+                               if (!$info_only) {
+                                       $content = preg_replace("/(.*)(\<img.*src=\"".preg_quote($row['resource'], "/")."\".*\/\>)(.*)/sU", 
                                                $pattern_replace_to, $content);
+                               } else {
+                                       if ($row['secondary_type'] == 1) $has_audio_alternative = true;
+                                       if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
+                                       if ($row['secondary_type'] == 3) $has_text_alternative = true;
+                                       if ($row['secondary_type'] == 4) $has_visual_alternative = true;
+                               }
                        }
                        
+                       // append/replace target alternative to <a>...source...</a> or <a ...source...>...</a>
+                       // skip this "if" when the source object has been processed in aboved <img> tag
+                       if (!$img_processed && preg_match("/\<a.*".preg_quote($row['resource'], "/").".*\<\/a\>/sU", $content))
+                       {
+                               if (!$info_only) {
+                                       $content = preg_replace("/(.*)(\<a.*".preg_quote($row['resource'], "/").".*\<\/a\>)(.*)/sU", 
+                                               $pattern_replace_to, $content);
+                               } else {
+                                       if ($row['secondary_type'] == 1) $has_audio_alternative = true;
+                                       if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
+                                       if ($row['secondary_type'] == 3) $has_text_alternative = true;
+                                       if ($row['secondary_type'] == 4) $has_visual_alternative = true;
+                               }
+                       }
+
                        // append/replace target alternative to <object ... source ...></object>
                        if (preg_match("/\<object.*".preg_quote($row['resource'], "/").".*\<\/object\>/sU", $content))
                        {
-                               $content = preg_replace("/(.*)(\<object.*".preg_quote($row['resource'], "/").".*\<\/object\>)(.*)/sU", 
+                               if (!$info_only) {
+                                       $content = preg_replace("/(.*)(\<object.*".preg_quote($row['resource'], "/").".*\<\/object\>)(.*)/sU", 
                                                $pattern_replace_to, $content);
+                               } else {
+                                       if ($row['secondary_type'] == 1) $has_audio_alternative = true;
+                                       if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
+                                       if ($row['secondary_type'] == 3) $has_text_alternative = true;
+                                       if ($row['secondary_type'] == 4) $has_visual_alternative = true;
+                               }
                        }
 
                        // append/replace target alternative to <embed ... source ...>
                        if (preg_match("/\<embed.*".preg_quote($row['resource'], "/").".*\>/sU", $content))
                        {
-                               $content = preg_replace("/(.*)(\<embed.*".preg_quote($row['resource'], "/").".*\>)(.*)/sU", 
+                               if (!$info_only) {
+                                       $content = preg_replace("/(.*)(\<embed.*".preg_quote($row['resource'], "/").".*\>)(.*)/sU", 
                                                $pattern_replace_to, $content);
+                               } else {
+                                       if ($row['secondary_type'] == 1) $has_audio_alternative = true;
+                                       if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
+                                       if ($row['secondary_type'] == 3) $has_text_alternative = true;
+                                       if ($row['secondary_type'] == 4) $has_visual_alternative = true;
+                               }
                        }
                }
        }
-       return $content;
+       
+       if (!$info_only) {
+               return $content;
+       } else {
+               return array($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative);
+       }
 }      
                
 /**
index 199d46e..8ab55f7 100644 (file)
 /****************************************************************/\r
 if (!defined('AT_INCLUDE_PATH')) { exit; } ?>\r
 \r
+<?php if ($this->has_text_alternative || $this->has_audio_alternative || $this->has_visual_alternative || $this->has_sign_lang_alternative): ?>\r
+<div id="alternatives_shortcuts">\r
+<?php if ($this->has_text_alternative) :?>\r
+  <a href="<?php echo $_SERVER['PHP_SELF'].'?cid='.$this->cid.(($_GET['alternative'] == 3) ? '' : SEP.'alternative=3'); ?>">\r
+    <img src="<?php echo AT_BASE_HREF; ?>images/<?php echo (($_GET['alternative'] == 3) ? 'pause.png' : 'text_alternative.png'); ?>" \r
+      alt="<?php echo (($_GET['alternative'] == 3) ? _AT('stop_apply_text_alternatives') : _AT('apply_text_alternatives')); ?>" \r
+      title="<?php echo (($_GET['alternative'] == 3) ? _AT('stop_apply_text_alternatives') : _AT('apply_text_alternatives')); ?>" \r
+      border="0" />\r
+  </a>\r
+<?php endif; // END OF has text alternative?>\r
+<?php if ($this->has_audio_alternative) :?>\r
+  <a href="<?php echo $_SERVER['PHP_SELF'].'?cid='.$this->cid.(($_GET['alternative'] == 1) ? '' : SEP.'alternative=1'); ?>">\r
+    <img src="<?php echo AT_BASE_HREF; ?>images/<?php echo (($_GET['alternative'] == 1) ? 'pause.png' : 'audio_alternative.png'); ?>" \r
+      alt="<?php echo (($_GET['alternative'] == 1) ? _AT('stop_apply_audio_alternatives') : _AT('apply_audio_alternatives')); ?>" \r
+      title="<?php echo (($_GET['alternative'] == 1) ? _AT('stop_apply_audio_alternatives') : _AT('apply_audio_alternatives')); ?>" \r
+      border="0" />\r
+  </a>\r
+<?php endif; // END OF has audio alternative?>\r
+<?php if ($this->has_visual_alternative) :?>\r
+  <a href="<?php echo $_SERVER['PHP_SELF'].'?cid='.$this->cid.(($_GET['alternative'] == 4) ? '' : SEP.'alternative=4'); ?>">\r
+    <img src="<?php echo AT_BASE_HREF; ?>images/<?php echo (($_GET['alternative'] == 4) ? 'pause.png' : 'visual_alternative.png'); ?>" \r
+      alt="<?php echo (($_GET['alternative'] == 4) ? _AT('stop_apply_visual_alternatives') : _AT('apply_visual_alternatives')); ?>" \r
+      title="<?php echo (($_GET['alternative'] == 4) ? _AT('stop_apply_visual_alternatives') : _AT('apply_visual_alternatives')); ?>" \r
+      border="0" />\r
+  </a>\r
+<?php endif; // END OF has visual alternative?>\r
+<?php if ($this->has_sign_lang_alternative) :?>\r
+  <a href="<?php echo $_SERVER['PHP_SELF'].'?cid='.$this->cid.(($_GET['alternative'] == 2) ? '' : SEP.'alternative=2'); ?>">\r
+    <img src="<?php echo AT_BASE_HREF; ?>images/<?php echo (($_GET['alternative'] == 2) ? 'pause.png' : 'sign_lang_alternative.png'); ?>" \r
+      alt="<?php echo (($_GET['alternative'] == 2) ? _AT('stop_apply_sign_lang_alternatives') : _AT('apply_sign_lang_alternatives')); ?>" \r
+      title="<?php echo (($_GET['alternative'] == 2) ? _AT('stop_apply_sign_lang_alternatives') : _AT('apply_sign_lang_alternatives')); ?>" \r
+      border="0" />\r
+  </a>\r
+<?php endif; // END OF has sign language alternative?>\r
+</div>\r
+<?php endif; // END OF displaying alternative shortcut icons?>\r
+\r
 <?php if ($this->shortcuts): ?>\r
 <fieldset id="shortcuts"><legend><?php echo _AT('shortcuts'); ?></legend>\r
        <ul>\r
index 33adf22..63d5645 100644 (file)
@@ -1142,6 +1142,11 @@ div.course div.shortcuts {
        vertical-align: middle;
 }
 
+div#alternatives_shortcuts {
+       float: right;
+       margin: -2em 5pt;
+}
+
 fieldset#shortcuts {
        float: right;
        background-color: #FEFDEF;
@@ -1152,8 +1157,6 @@ fieldset#shortcuts {
        padding-left: 10pt;
 }
 
-
-
 fieldset {
        margin-bottom: 10pt;
        border-radius:.5em;