From 3bca3cec702991a700626fe455f2b4373e62aeaf Mon Sep 17 00:00:00 2001 From: Cindy Li Date: Mon, 18 Oct 2010 19:11:34 +0000 Subject: [PATCH] 1. Improved DAO.class.php, when no results returned for "select" sql, return false; 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 | 6 - docs/home/editor/editor_tab_functions.inc.php | 12 +- .../editor/editor_tabs/alternatives.inc.php | 235 +++++++++--------- docs/home/editor/import_export_content.php | 15 +- docs/include/classes/DAO/DAO.class.php | 19 +- 5 files changed, 156 insertions(+), 131 deletions(-) diff --git a/docs/home/classes/ContentUtility.class.php b/docs/home/classes/ContentUtility.class.php index cb18256..bc0834f 100644 --- a/docs/home/classes/ContentUtility.class.php +++ b/docs/home/classes/ContentUtility.class.php @@ -790,12 +790,6 @@ class ContentUtility { return array($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative); } } - // All a4a resources have "&" converted to "&". To match content with resources, - // need the same conversion on content. - $content = convertAmp($content); - - // keep < (content saved in plain text format) as it is instead of &lt; - $content = str_replace('&lt;', '<', $content); // get all relations between primary resources and their alternatives $sql = "SELECT DISTINCT c.content_path, pr.resource, "; diff --git a/docs/home/editor/editor_tab_functions.inc.php b/docs/home/editor/editor_tab_functions.inc.php index c7fdda1..63a0c6e 100644 --- a/docs/home/editor/editor_tab_functions.inc.php +++ b/docs/home/editor/editor_tab_functions.inc.php @@ -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"].'/'; } diff --git a/docs/home/editor/editor_tabs/alternatives.inc.php b/docs/home/editor/editor_tabs/alternatives.inc.php index 7fe20db..714b8d2 100644 --- a/docs/home/editor/editor_tabs/alternatives.inc.php +++ b/docs/home/editor/editor_tabs/alternatives.inc.php @@ -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 '

'. _AT('No_resources'). '

'; -} -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 '
'."\n"; - echo ' '."\n"; - echo ' '."\n"; - echo ' '."\n"; - echo ' '."\n"; - echo ' '."\n"; - echo ' '."\n"; - echo ' '."\n"; - echo ' '."\n"; - echo ' '."\n"; - echo ' '."\n"; - echo ' '."\n"; - echo ' '."\n"; - echo ' '."\n"; + $a4a = new A4a($cid); + $primary_resources = $a4a->getPrimaryResources(); - echo ' '; - 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 ' '."\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 '
'._AT('original_resource').''._AT('resource_type').''._AT('alternatives').'
'._AT('text').''._AT('audio').''._AT('visual').''._AT('sign_lang').'
'."\n"; + echo ' '."\n"; echo ' '."\n"; - - // table cell "original resource" - echo ' '."\n"; - - // table cell "original resource type" - echo ' '."\n"; + echo ' '."\n"; + echo ' '."\n"; + echo ' '."\n"; + echo ' '."\n"; + echo ' '."\n"; + echo ' '."\n"; + echo ' '."\n"; + echo ' '."\n"; + echo ' '."\n"; + echo ' '."\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 ' '; + 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 'execute($sql); + + if (!$is_post_indicator_set) + { + echo ' '."\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 ' '."\n"; + + // table cell "original resource" + echo ' '."\n"; + + // table cell "original resource type" + echo ' '."\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 ' '."\n"; } - echo ' '."\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 ' '."\n"; + echo ' '."\n"; + echo '
'."\n"; - echo ' '.get_display_filename($primary_resource).''."\n"; - echo ' '."\n"; + echo ' '._AT('original_resource').''._AT('resource_type').''._AT('alternatives').'
'._AT('text').''._AT('audio').''._AT('visual').''._AT('sign_lang').'
'."\n"; + echo ' '.get_display_filename($primary_resource).''."\n"; + echo ' '."\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 ''."\n"; + echo '
'."\n"; } - echo '/>'."\n"; - echo '
'."\n"; } } + echo '


'."\n"; } - echo ' '."\n"; - echo '

'."\n"; -} ?> \ No newline at end of file + + 0) +?> \ No newline at end of file diff --git a/docs/home/editor/import_export_content.php b/docs/home/editor/import_export_content.php index 1c70b6f..51b9900 100644 --- a/docs/home/editor/import_export_content.php +++ b/docs/home/editor/import_export_content.php @@ -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'].''; + 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.''; print_menu_sections($menu, $only_print_content_folder, $children['content_id'], $depth+1, $new_ordering); } diff --git a/docs/include/classes/DAO/DAO.class.php b/docs/include/classes/DAO/DAO.class.php index 8516b95..905a4b3 100644 --- a/docs/include/classes/DAO/DAO.class.php +++ b/docs/include/classes/DAO/DAO.class.php @@ -52,17 +52,22 @@ class DAO { $result = mysql_query($sql, $this->db) or die($sql . "
". 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; + } } } -- 2.17.1