1. Improved DAO.class.php, when no results returned for "select" sql, return false;
[acontent.git] / docs / home / editor / editor_tabs / alternatives.inc.php
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