/**
 * Display alternative table cell
 * @param $rows_secondary_resources   db 2d array of all secondary alternatives
 *        $alternative type   the resource type of the alternative to display. Must be one of the values in resource_types.type_id
 *        $content_id         used to pass into file_manager/index.php
 *        $ps                 used to pass into file_manager/index.php
 * @return html of the table cell "<td>...</td>"
 */
function display_alternative_cell($rows_secondary_resources, $alternative_type, $content_id, $pid, $td_header_id)
{
    global $content_row;
    $found_alternative = false;
    echo '    <td headers="' . $td_header_id . '">' . "\n";
    if (count($rows_secondary_resources) > 0) {
        foreach ($rows_secondary_resources as $secondary_resource) {
            if ($secondary_resource['type_id'] == $alternative_type) {
                echo '    <div id="' . $pid . '_' . $alternative_type . '">' . "\n";
                echo '      <a href="' . $secondary_resource['secondary_resource'] . '" title="' . _AT('new_window') . '" target="_new">' . get_display_filename($secondary_resource['secondary_resource']) . '</a><br />' . "\n";
                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";
                echo '        <img src="' . AT_BASE_HREF . 'images/home-tests_sm.png" border="0" title="' . _AT('alter') . '" alt="' . _AT('alter') . '" />' . "\n";
                echo '      </a>' . "\n";
                echo '      <a href="#" onclick="removeAlternative(\'' . $content_row['content_path'] . '\', ' . $content_id . ',' . $pid . ',' . $alternative_type . ');return false;">' . "\n";
                echo '        <img src="' . AT_BASE_HREF . 'images/icon_delete.gif" border="0" title="' . _AT('remove') . '" alt="' . _AT('remove') . '" />' . "\n";
                echo '      </a>' . "\n";
                echo '    </div>' . "\n";
                $found_alternative = true;
                break;
            }
        }
    }
    if (!$found_alternative) {
        echo '    <div id="' . $pid . '_' . $alternative_type . '">' . "\n";
        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";
        echo '    </div>' . "\n";
    }
    echo '    </td>' . "\n";
}
/**
 * Display alternative table cell
 * @param $secondary_result   mysql result of all secondary alternatives
 *        $alternative type   the resource type of the alternative to display. Must be one of the values in resource_types.type_id
 *        $content_id         used to pass into file_manager/index.php
 *        $pid                primary resource id
 *        $td_header_id       the id of the table header cell, to comply with accessibility rule
 * @return html of the table cell "<td>...</td>"
 */
function display_alternative_cell($secondary_resources, $alternative_type, $content_id, $pid, $td_header_id)
{
    global $content_row, $_course_id;
    $found_alternative = false;
    echo '    <td headers="' . $td_header_id . '">' . "\n";
    if (is_array($secondary_resources)) {
        //		mysql_data_seek($secondary_result, 0);  // move the mysql result cursor back to the first row
        foreach ($secondary_resources as $secondary_resource) {
            if ($secondary_resource['type_id'] == $alternative_type) {
                echo '    <div id="' . $pid . '_' . $alternative_type . '">' . "\n";
                echo '      <a href="' . $secondary_resource['secondary_resource'] . '" title="' . _AT('new_window') . '" target="_new">' . get_display_filename($secondary_resource['secondary_resource']) . '</a><br />' . "\n";
                echo '      <a href="#" onclick="trans.utility.poptastic(\'' . TR_BASE_HREF . '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";
                echo '        <img src="' . TR_BASE_HREF . 'images/alter.png" border="0" title="' . _AT('alter') . '" alt="' . _AT('alter') . '" />' . "\n";
                echo '      </a>' . "\n";
                echo '      <a href="#" onclick="removeAlternative(\'' . $content_row['content_path'] . '\', ' . $content_id . ',' . $pid . ',' . $alternative_type . ');return false;">' . "\n";
                echo '        <img src="' . TR_BASE_HREF . 'images/remove.gif" border="0" title="' . _AT('remove') . '" alt="' . _AT('remove') . '" />' . "\n";
                echo '      </a>' . "\n";
                echo '    </div>' . "\n";
                $found_alternative = true;
                break;
            }
        }
    }
    if (!$found_alternative) {
        echo '    <div id="' . $pid . '_' . $alternative_type . '">' . "\n";
        echo '      <input type="button" value="' . _AT('add') . '" title="' . _AT('new_window') . '" onclick="trans.utility.poptastic(\'' . TR_BASE_HREF . '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";
        echo '    </div>' . "\n";
    }
    echo '    </td>' . "\n";
}