1. Improved DAO.class.php, when no results returned for "select" sql, return false;
authorCindy Li <cli@ocad.ca>
Mon, 18 Oct 2010 19:11:34 +0000 (19:11 -0000)
committerCindy Li <cli@ocad.ca>
Mon, 18 Oct 2010 19:11:34 +0000 (19:11 -0000)
2. On "import/export course" page, truncate folder/content titles in the drop down list box to 65 chars;
3. Only when content type is "html", parse content and extract primary resources
4. In output.inc.php -> provide_alternative(), don't call convert_amp() on content since the plain text would not have alternatives defined.

docs/home/classes/ContentUtility.class.php
docs/home/editor/editor_tab_functions.inc.php
docs/home/editor/editor_tabs/alternatives.inc.php
docs/home/editor/import_export_content.php
docs/include/classes/DAO/DAO.class.php

index cb18256..bc0834f 100644 (file)
@@ -790,12 +790,6 @@ class ContentUtility {
                                return array($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative);\r
                        }\r
                }\r
-               // All a4a resources have "&" converted to "&amp;". To match content with resources, \r
-        // need the same conversion on content. \r
-        $content = convertAmp($content);\r
-        \r
-        // keep &lt; (content saved in plain text format) as it is instead of &amp;lt;\r
-        $content = str_replace('&amp;lt;', '&lt;', $content);\r
         \r
                // get all relations between primary resources and their alternatives\r
         $sql = "SELECT DISTINCT c.content_path, pr.resource, ";\r
index c7fdda1..63a0c6e 100644 (file)
@@ -93,15 +93,21 @@ function isValidURL($url) {
 function populate_a4a($cid, $content, $formatting){
        global $my_files, $content_base_href, $contentManager;
        
-    include_once(TR_INCLUDE_PATH.'classes/A4a/A4a.class.php');
+       // Defining alternatives is only available for content type "html".
+       // But don't clean up the a4a tables at other content types in case the user needs them back at html.
+       if ($formatting <> 1) return;
+
+       include_once(TR_INCLUDE_PATH.'classes/A4a/A4a.class.php');
        include_once(TR_INCLUDE_PATH.'classes/XML/XML_HTMLSax/XML_HTMLSax.php');        /* for XML_HTMLSax */
        include_once(TR_INCLUDE_PATH.'classes/ContentOutputParser.class.php');  /* for parser */
        
        // initialize content_base_href; used in format_content
        if (!isset($content_base_href)) {
-               $result = $contentManager->getContentPage($cid);
+               $content_row = $contentManager->getContentPage($cid);
                // return if the cid is not found
-               if (!($content_row = @mysql_fetch_assoc($result))) return;
+               if (!is_array($content_row)) {
+                       return;
+               }
                $content_base_href = $content_row["content_path"].'/';
        }
        
index 7fe20db..714b8d2 100644 (file)
@@ -94,137 +94,141 @@ function display_alternative_cell($secondary_resources, $alternative_type, $cont
 }
 
 // Main program
-global $db, $content_row;
-populate_a4a($cid, $_POST['body_text'], $_POST['formatting']);
-
-include_once(TR_INCLUDE_PATH.'classes/A4a/A4a.class.php');
-
-$a4a = new A4a($cid);
-$primary_resources = $a4a->getPrimaryResources();
-
-if (count($primary_resources)==0)
-{
-       echo '<p>'. _AT('No_resources'). '</p>';
-}
-else
+if ($_POST['formatting'] <> 1)
 {
-       $is_post_indicator_set = false;
-       // get all resource types
-//     $sql = "SELECT * FROM ".TABLE_PREFIX."resource_types";
-//     $resource_types_result = mysql_query($sql, $db);
-       $resource_types = $resourceTypesDAO->getAll();
+       $msg->addFeedback('NO_A4A_FOR_PLAIN_TEXT');
+       $msg->printAll();
+} else {
+       global $db, $content_row;
+       populate_a4a($cid, $_POST['body_text'], $_POST['formatting']);
+       
+       include_once(TR_INCLUDE_PATH.'classes/A4a/A4a.class.php');
        
-       echo '<br /><table class="data" rules="all">'."\n";
-       echo '  <thead>'."\n";
-       echo '  <tr>'."\n";
-       echo '    <th rowspan="2" id="header1">'._AT('original_resource').'</th>'."\n";
-       echo '    <th rowspan="2" id="header2">'._AT('resource_type').'</th>'."\n";
-       echo '    <th colspan="4">'._AT('alternatives').'</th>'."\n";
-       echo '  </tr>'."\n";
-       echo '  <tr>'."\n";
-       echo '    <th id="header3">'._AT('text').'</th>'."\n";
-       echo '    <th id="header4">'._AT('audio').'</th>'."\n";
-       echo '    <th id="header5">'._AT('visual').'</th>'."\n";
-       echo '    <th id="header6">'._AT('sign_lang').'</th>'."\n";
-       echo '  </tr>'."\n";
-       echo '  </thead>'."\n";
+       $a4a = new A4a($cid);
+       $primary_resources = $a4a->getPrimaryResources();
        
-       echo '  <tbody>';
-       foreach($primary_resources as $primary_resource_id => $primary_resource_row)
+       if (count($primary_resources)==0)
        {
-               $primary_resource = $primary_resource_row['resource'];
-               
-               $sql = "SELECT prt.type_id, rt.type
-                         FROM ".TABLE_PREFIX."primary_resources pr, ".
-                                TABLE_PREFIX."primary_resources_types prt, ".
-                                TABLE_PREFIX."resource_types rt
-                        WHERE pr.content_id = ".$cid."
-                          AND pr.language_code = '".$_SESSION['lang']."'
-                          AND pr.primary_resource_id='".$primary_resource_id."'
-                          AND pr.primary_resource_id = prt.primary_resource_id
-                          AND prt.type_id = rt.type_id";
-//             $primary_type_result = mysql_query($sql, $db);
-               $primary_types = $dao->execute($sql);
-               
-               if (!$is_post_indicator_set)
-               {
-                       echo '  <input type="hidden" name="use_post_for_alt" value="1" />'."\n";
-                       $is_post_indicator_set = true;
-               }
-               
-               // get secondary resources for the current primary resource
-               $sql = "SELECT pr.primary_resource_id, sr.secondary_resource, srt.type_id
-                         FROM ".TABLE_PREFIX."primary_resources pr, ".
-                                TABLE_PREFIX."secondary_resources sr, ".
-                                TABLE_PREFIX."secondary_resources_types srt
-                        WHERE pr.content_id = ".$cid."
-                          AND pr.language_code = '".$_SESSION['lang']."'
-                          AND pr.primary_resource_id='".$primary_resource_id."'
-                          AND pr.primary_resource_id = sr.primary_resource_id
-                          AND sr.secondary_resource_id = srt.secondary_resource_id";
-//             $secondary_result = mysql_query($sql, $db);
-               $secondary_resources = $dao->execute($sql);
+               $msg->addFeedback('NO_RESOURCES');
+               $msg->printAll();
+       }
+       else
+       {
+               $is_post_indicator_set = false;
+               // get all resource types
+               $resource_types = $resourceTypesDAO->getAll();
                
+               echo '<br /><table class="data" rules="all">'."\n";
+               echo '  <thead>'."\n";
                echo '  <tr>'."\n";
-
-               // table cell "original resource"
-               echo '    <td headers="header1">'."\n";
-               echo '    <a href="'.$primary_resource.'" title="'._AT('new_window').'" target="_new">'.get_display_filename($primary_resource).'</a>'."\n";
-               echo '    </td>'."\n";
-
-               // table cell "original resource type"
-               echo '    <td headers="header2">'."\n";
+               echo '    <th rowspan="2" id="header1">'._AT('original_resource').'</th>'."\n";
+               echo '    <th rowspan="2" id="header2">'._AT('resource_type').'</th>'."\n";
+               echo '    <th colspan="4">'._AT('alternatives').'</th>'."\n";
+               echo '  </tr>'."\n";
+               echo '  <tr>'."\n";
+               echo '    <th id="header3">'._AT('text').'</th>'."\n";
+               echo '    <th id="header4">'._AT('audio').'</th>'."\n";
+               echo '    <th id="header5">'._AT('visual').'</th>'."\n";
+               echo '    <th id="header6">'._AT('sign_lang').'</th>'."\n";
+               echo '  </tr>'."\n";
+               echo '  </thead>'."\n";
                
-//             mysql_data_seek($resource_types_result, 0);  // move the mysql result cursor back to the first row
-//             while ($resource_type = mysql_fetch_assoc($resource_types_result))
-               if (is_array($resource_types))
+               echo '  <tbody>';
+               foreach($primary_resources as $primary_resource_id => $primary_resource_row)
                {
-                       foreach ($resource_types as $resource_type) {
-                               if ($resource_type['type'] == 'sign_language')
-                                       continue;
-                               else 
-                               {
-                                       echo '<input type="checkbox" name="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'" value="1" id="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'"';
-                                       if ($_POST['use_post_for_alt'])
+                       $primary_resource = $primary_resource_row['resource'];
+                       
+                       $sql = "SELECT prt.type_id, rt.type
+                                 FROM ".TABLE_PREFIX."primary_resources pr, ".
+                                        TABLE_PREFIX."primary_resources_types prt, ".
+                                        TABLE_PREFIX."resource_types rt
+                                WHERE pr.content_id = ".$cid."
+                                  AND pr.language_code = '".$_SESSION['lang']."'
+                                  AND pr.primary_resource_id='".$primary_resource_id."'
+                                  AND pr.primary_resource_id = prt.primary_resource_id
+                                  AND prt.type_id = rt.type_id";
+       //              $primary_type_result = mysql_query($sql, $db);
+                       $primary_types = $dao->execute($sql);
+                       
+                       if (!$is_post_indicator_set)
+                       {
+                               echo '  <input type="hidden" name="use_post_for_alt" value="1" />'."\n";
+                               $is_post_indicator_set = true;
+                       }
+                       
+                       // get secondary resources for the current primary resource
+                       $sql = "SELECT pr.primary_resource_id, sr.secondary_resource, srt.type_id
+                                 FROM ".TABLE_PREFIX."primary_resources pr, ".
+                                        TABLE_PREFIX."secondary_resources sr, ".
+                                        TABLE_PREFIX."secondary_resources_types srt
+                                WHERE pr.content_id = ".$cid."
+                                  AND pr.language_code = '".$_SESSION['lang']."'
+                                  AND pr.primary_resource_id='".$primary_resource_id."'
+                                  AND pr.primary_resource_id = sr.primary_resource_id
+                                  AND sr.secondary_resource_id = srt.secondary_resource_id";
+       //              $secondary_result = mysql_query($sql, $db);
+                       $secondary_resources = $dao->execute($sql);
+                       
+                       echo '  <tr>'."\n";
+       
+                       // table cell "original resource"
+                       echo '    <td headers="header1">'."\n";
+                       echo '    <a href="'.$primary_resource.'" title="'._AT('new_window').'" target="_new">'.get_display_filename($primary_resource).'</a>'."\n";
+                       echo '    </td>'."\n";
+       
+                       // table cell "original resource type"
+                       echo '    <td headers="header2">'."\n";
+                       
+       //              mysql_data_seek($resource_types_result, 0);  // move the mysql result cursor back to the first row
+       //              while ($resource_type = mysql_fetch_assoc($resource_types_result))
+                       if (is_array($resource_types))
+                       {
+                               foreach ($resource_types as $resource_type) {
+                                       if ($resource_type['type'] == 'sign_language')
+                                               continue;
+                                       else 
                                        {
-                                               if (isset($_POST['alt_'.$primary_resource_id.'_'.$resource_type['type_id']])) {
-                                                       echo 'checked="checked"';
+                                               echo '<input type="checkbox" name="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'" value="1" id="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'"';
+                                               if ($_POST['use_post_for_alt'])
+                                               {
+                                                       if (isset($_POST['alt_'.$primary_resource_id.'_'.$resource_type['type_id']])) {
+                                                               echo 'checked="checked"';
+                                                       }
                                                }
-                                       }
-                                       else {
-                                               if (is_array($primary_types)) {
-                                                       foreach ($primary_types as $primary_resource_type) {
-                                                               if ($primary_resource_type['type_id'] == $resource_type['type_id']){
-                                                                       echo 'checked="checked"';
-                                                                       break;
+                                               else {
+                                                       if (is_array($primary_types)) {
+                                                               foreach ($primary_types as $primary_resource_type) {
+                                                                       if ($primary_resource_type['type_id'] == $resource_type['type_id']){
+                                                                               echo 'checked="checked"';
+                                                                               break;
+                                                                       }
                                                                }
                                                        }
                                                }
+                                               echo '/>'."\n";
+                                               echo '<label for="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'">'. _AT($resource_type['type']).'</label><br/>'."\n";      
                                        }
-                                       echo '/>'."\n";
-                                       echo '<label for="alt_'.$primary_resource_id.'_'.$resource_type['type_id'].'">'. _AT($resource_type['type']).'</label><br/>'."\n";      
                                }
                        }
+                       echo '    </td>'."\n";
+                       
+                       // table cell "text alternative"
+                       display_alternative_cell($secondary_resources, 3, $cid, $primary_resource_id, "header3");
+                       
+                       // table cell "audio"
+                       display_alternative_cell($secondary_resources, 1, $cid, $primary_resource_id, "header4");
+                       
+                       // table cell "visual"
+                       display_alternative_cell($secondary_resources, 4, $cid, $primary_resource_id, "header5");
+                       
+                       // table cell "sign language"
+                       display_alternative_cell($secondary_resources, 2, $cid, $primary_resource_id, "header6");
+                       
+                       echo '  </tr>'."\n";
                }
-               echo '    </td>'."\n";
-               
-               // table cell "text alternative"
-               display_alternative_cell($secondary_resources, 3, $cid, $primary_resource_id, "header3");
-               
-               // table cell "audio"
-               display_alternative_cell($secondary_resources, 1, $cid, $primary_resource_id, "header4");
-               
-               // table cell "visual"
-               display_alternative_cell($secondary_resources, 4, $cid, $primary_resource_id, "header5");
-               
-               // table cell "sign language"
-               display_alternative_cell($secondary_resources, 2, $cid, $primary_resource_id, "header6");
-               
-               echo '  </tr>'."\n";
+               echo '  </tbody>'."\n";
+               echo '</table><br /><br />'."\n";
        }
-       echo '  </tbody>'."\n";
-       echo '</table><br /><br />'."\n";
-}
 ?>
 
 <script type="text/javascript">
@@ -242,4 +246,7 @@ function removeAlternative(contentPath, cid, pid, a_type)
        eval("document.getElementById(\""+pid+"_"+a_type+"\").innerHTML = '"+button_html+"'");
 }
 //-->
-</script>
\ No newline at end of file
+</script>
+<?php 
+} // else ($_POST['formatting'] <> 0)
+?>
\ No newline at end of file
index 1c70b6f..51b9900 100644 (file)
@@ -22,7 +22,14 @@ if (!isset($_main_menu)) {
        $_main_menu = $contentManager->getContent();
 }
 
+// The length of the content/folder title to display. 
+// This is to fix the issue that, when any one of the content title is too long, 
+// the dropdown box for the export selection stretches out of the "export" fieldset border.
+$len_of_title_to_display = 65;
+
 function print_menu_sections(&$menu, $only_print_content_folder = false, $parent_content_id = 0, $depth = 0, $ordering = '') {
+       global $len_of_title_to_display;
+       
        $my_children = $menu[$parent_content_id];
        $cid = $_GET['cid'];
 
@@ -53,7 +60,13 @@ function print_menu_sections(&$menu, $only_print_content_folder = false, $parent
                        $new_ordering = $ordering.'.'.$children['ordering'];
                        echo $ordering . '.'. $children['ordering'];
                }
-               echo ' '.$children['title'].'</option>';
+               if (strlen($children['title']) > $len_of_title_to_display) {
+                       $title = substr($children['title'], 0, $len_of_title_to_display).' ...';
+               } else {
+                       $title = $children['title'];
+               }
+               
+               echo ' '.$title.'</option>';
 
                print_menu_sections($menu, $only_print_content_folder, $children['content_id'], $depth+1, $new_ordering);
        }
index 8516b95..905a4b3 100644 (file)
@@ -52,17 +52,22 @@ class DAO {
                $result = mysql_query($sql, $this->db) or die($sql . "<br />". mysql_error());
 
                // for 'select' SQL, return retrieved rows
-               if (strtolower(substr($sql, 0, 6)) == 'select' && mysql_num_rows($result) > 0
+               if (strtolower(substr($sql, 0, 6)) == 'select') 
                {
-                       for($i = 0; $i < mysql_num_rows($result); $i++) 
-                       {
-                               $rows[] = mysql_fetch_assoc($result);
+                       if (mysql_num_rows($result) > 0) {
+                               for($i = 0; $i < mysql_num_rows($result); $i++) 
+                               {
+                                       $rows[] = mysql_fetch_assoc($result);
+                               }
+                               mysql_free_result($result);
+                               return $rows;
+                       } else {
+                               return false;
                        }
-                       mysql_free_result($result);
-                       return $rows;
                }
-               else
+               else {
                        return true;
+               }
        }
 
 }