Jump to content

Somewhat simple question


rayyes

Recommended Posts

Hi all, first post. I'll try to make it short and sweet.

[b]SHORT VERSION:[/b]
if you don't feel like looking at the file, my question boils down to:
HOW Do I convert this
  [code]$value = '<a href="' . $value . '" target="_blank">' . $value . '</a>';[/code]
so that the 2nd $value in bold can be different from the 1st (ie having a 'clean' hyperlink such as [url=http://my/site/]this one [/url]

[b]LONG  VERSION:[/b]
I'm using joomla for a car dealer site. I want to use the "Table manager" extension which basically formats entries from a DB nicely in a table (you can sort by colums, and all the editing is done through the admin interface, etc).

Each row of fields is a record (duh). You can set the fields of type TEXT,IMAGE,URL,EMAIL ADDRESS,NUMERAL(dates, numbers etc). so basically I called the 1st field 'Make and model' and type is TEXT. The next is called 'Pic' of type IMG. The third is called 'details', of TYPE A (for Anchor) which is a URL.
You're supposed to click on the 'details' field for this record and it takes you to another page with more info.

THE PROBLEM:
The author of this extension wrote it so that you can only have 1 type per field. ie, you cannot have an IMG embedded within a URL (ie a picture link).
In the same way, he made it so that the only way the A (Anchor) type works, is if you enter the whole URL in the field ie: http://my/site/location/.com and it will convert it to [url=http://my/site/location/.com]http://my/site/location/.com[/url]
You cannot have a hyperlink like this: [url=http://my/site/]this is a nice clean link [/url]

I traced the 'meat' of the script to a php file, but being a noob with php, i wasn't able to fix it to my liking.

I've attached the file, and I'm sure that by looking at it, someone experienced with php will know what i'm talking about and how to fix it.

please help! ??? thanks  ;D

[attachment deleted by admin]
Link to comment
Share on other sites

as per the recommendation of a mod here (thank you), i am posting the file with the code that does needs to be changed. thanks for looking:

[code]

<?php
// FILE: geda_include.php
/*
* Table Manager (GeDa) - Mambo/Joomla component
* Copyright (C) 2005 by IW1QLH
* License http://www.gnu.org/copyleft/gpl.html GNU/GPL
* Official website: http://www.iw1qlh.net/projects/table-manager
*/

// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

function Geda_get_data($id_table, $sort_col, $limit, &$limitstart, &$total) {
global $database;

// get the total number of records
$database->setQuery('DROP TABLE IF EXISTS #__geda_tmp_id_row');
$database->query();
$database->setQuery("CREATE TEMPORARY TABLE #__geda_tmp_id_row (`id_row` int(11) NOT NULL)");
$database->query();
$database->setQuery("INSERT INTO #__geda_tmp_id_row SELECT DISTINCT td_row FROM #__geda_data where id_table = $id_table");
$database->query();
$database->setQuery('SELECT COUNT(*) AS c FROM #__geda_tmp_id_row');
$total = $database->loadResult();

$database->setQuery('DROP TABLE IF EXISTS #__geda_tmp_value');
$database->query();
$database->setQuery("CREATE TEMPORARY TABLE #__geda_tmp_value (`id_row` int(11) NOT NULL,  `td_numeric` float, `td_char` varchar(255), `td_date` datetime)");
$database->query();
$database->setQuery("INSERT INTO #__geda_tmp_value SELECT td_row, td_numeric, td_char, td_date FROM #__geda_data where id_table = $id_table and id_column = " . abs($sort_col));
$database->query();

$database->setQuery("SELECT cn_type FROM #__geda_columns WHERE id_table = $id_table AND id = " . abs($sort_col));
$cn_type = $database->loadResult();
switch ($cn_type) {
case 'C':
$field = 'td_char';
break;
case 'N':
$field = 'td_numeric';
break;
case 'D':
$field = 'td_date';
break;
default:
$field = 'td_numeric, td_char, td_date';
}

if ( $total <= $limit ) $limitstart = 0;

$database->setQuery('DROP TABLE IF EXISTS #__geda_tmp_id_sort');
$database->query();
$database->setQuery("CREATE TEMPORARY TABLE #__geda_tmp_id_sort (`ordering` int(11) NOT NULL auto_increment, `id_row` int(11) NOT NULL, PRIMARY KEY  (`ordering`))");
$database->query();
$database->setQuery("INSERT INTO #__geda_tmp_id_sort SELECT 0, a.id_row FROM #__geda_tmp_id_row AS a LEFT JOIN #__geda_tmp_value AS b ON b.id_row = a.id_row ORDER BY $field " . (($sort_col < 0) ? 'DESC' : 'ASC') . " LIMIT $limitstart, $limit");
$database->query();

$database->setQuery("SELECT b.td_row, b.id_column, b.td_char, b.td_numeric, UNIX_TIMESTAMP(b.td_date) AS td_date, c.cn_type FROM #__geda_tmp_id_sort AS a, #__geda_data AS b, #__geda_columns AS c WHERE b.td_row = a.id_row AND b.id_column = c.id AND b.id_table = $id_table AND c.id_table = $id_table ORDER BY a.ordering, id_column");
$datas = $database->loadObjectList();

$rowid = -1;
$rows = array();

foreach ($datas as $data) {

        if ($rowid != $data->td_row) {
            $rowid = $data->td_row;
            if ($row) {
                $rows[] = $row;
            }
            $row = array();
            $row['rowid'] = $rowid;
        }
        $value = '-';
switch ($data->cn_type) {
case 'C':
$value = $data->td_char;
break;
case 'N':
$value = $data->td_numeric;
break;
case 'D':
$value = $data->td_date;
break;
}
$row[$data->id_column] = $value;
    }
if ($row)
$rows[] = $row;

// drop temporary tables
$database->setQuery('DROP TABLE IF EXISTS #__geda_tmp_id_row');
$database->query();
$database->setQuery('DROP TABLE IF EXISTS #__geda_tmp_value');
$database->query();
$database->setQuery('DROP TABLE IF EXISTS #__geda_tmp_id_sort');
$database->query();

return $rows;
}

function Geda_view($table) {
global $database, $mosConfig_list_limit;

if (!$table)
    return '<font color="#FF0000">Table manager error: you must insert table=<i>tablename</i> in the parameters !</font><br />';

session_start();

if ($sort_col = mosGetParam( $_REQUEST, $table . 'order', 0 )) {
$_SESSION[$table . 'order'] = $sort_col;
} else {
$sort_col = $_SESSION[$table . 'order'];
}

// get the table name
$database->setQuery( "SELECT id, tn_description FROM #__geda_tables where tn_name = '$table'" );
if (!$tableData = $database->loadRow())
    return "<font color='#FF0000'>Table-manager error: $table isn't a valid table name !</font><br />";
$id_table = $tableData[0];
$tablename = $tableData[1];

    // get the columns name
$database->setQuery( "SELECT id, cn_description, cn_type, cn_format, published FROM #__geda_columns where id_table = $id_table ORDER BY ordering" );
$columns = $database->loadObjectList();

if ((!$sort_col) && ($columns[0]->id))
    $sort_col = $columns[0]->id;

$limit = intval( mosGetParam( $_REQUEST, 'limit', '' ) );
$limitstart = intval( mosGetParam( $_REQUEST, 'limitstart', 0 ) );
$limit = $limit ? $limit : $mosConfig_list_limit ;
$total = 0;

// get datas
$rows = Geda_get_data($id_table, $sort_col, $limit, $limitstart, $total);

mosCache::cleanCache();

require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php' );
$pageNav = new mosPageNav( $total, $limitstart, $limit );

    return HTML_Geda_view::show($rows, $pageNav, $table, $tablename, $columns, $sort_col);

}

class HTML_Geda_view {

function show($rows, $pageNav, $table, $tablename, $columns, $sort_col) {

$html  = "\n<!-- Table-manager (Geda) Start    -->";
$html .= "\n<!-- http://www.iw1qlh.net/projects -->\n\n";
$html .= "\n<form method='POST' name='" . $table . "Form'>";
$html .= "\n<input type='hidden' name='" . $table . "order' value=$sort_col>";
$html .= '<table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="contentpane">';
$html .= "\n<tr>";
$html .= "<td colspan=" . count($columns) . ' class="componentheading">' . $tablename . '</td>';
$html .= '</tr>';

$html .= "\n<tr>";
foreach ($columns as $col) {
            $html .= '<td class="sectiontableheader"><strong>' . (($col->id == abs($sort_col)) ? '<u>' : '') . $col->cn_description . (($col->id == abs($sort_col)) ? '</u>' : '') . '</strong>';
//$html .= '&nbsp;<a href="' . $url . '&gedaorder=' . $col->id . '">&#187;</a></td>';
$html .= '&nbsp;<a href="javascript:document.' . $table . 'Form.' . $table . 'order.value=' . (($col->id == abs($sort_col)) ? -$sort_col : $col->id) . ';document.' . $table . 'Form.submit();">&#187;</a></td>';

}
$html .= '</tr>';

$k = 0;
foreach ($rows as $row) {
$html .= "\n<tr class='sectiontableentry" . (($k % 2) + 1) ."'>";
foreach ($columns as $col) {
        $align = 'left';
        $value = $row[$col->id];
        $format = $col->cn_format;
      switch ($col->cn_type) {
    case 'C':
$align = 'left';
if ($value) {
switch ($format) {
case 'A':      // ANCHOR
    $value = '<a href="' . $value . '" target="_blank">' . $value . '</a>';
    break;
case 'M':      // MAILTO
    $value = '<a href="mailto:' . $value . '">' . $value . '</a>';
    break;
case 'IMG':      // IMAGE
    $value = '<img src="' . $value . '">';
    break;
case 'L':      // LOWER
    $value = strtolower($value);
    break;
case 'U':      // UPPER
    $value = strtoupper($value);
    break;
}
}
    break;
    case 'N':
    $align = 'right';
    if ($value && $format) {
$params = explode("/", $format);
if (!$params[1]) $params[1] = '.';
if (!$params[2]) $params[2] = ',';
$value = number_format($value, $params[0], $params[1], $params[2]);
}
    break;
    case 'D':
    $align = 'left';
    if ($value) $value = date(!$format ? 'Y-m-d H:i:s' : $format, $value);
    break;
      }
      $value = $value ? $value : '&nbsp;';
  $html .= "<td align='$align'>$value</td>";
            }
            $html .= '</tr>';
            $k++;
}

// http://www.domain.com/$option/$task/$sectionid/$id/$Itemid/$limit/$limitstart

$link = "index.php?"
. "option=" . mosGetParam($_REQUEST, 'option', '' ) . "&amp;";
if ($_REQUEST['task'])
    $link .= "task="  . mosGetParam($_REQUEST, 'task') . "&amp;";
if ($_REQUEST['sectionid'])
$link .= "sectionid=" . mosGetParam($_REQUEST, 'sectionid') . "&amp;";
if ($_REQUEST['id'])
$link .= "id=" . mosGetParam($_REQUEST, 'id') . "&amp;";
$link .= "Itemid=" . mosGetParam($_REQUEST, 'Itemid', '' );

$html .= '<tr>';
$html .= '<td colspan=' . count($columns) . '">&nbsp;</td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td align="center" colspan=' . count($columns) . ' class="sectiontablefooter">' . $pageNav->writePagesLinks($link) . '</th>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td align="center" colspan=' . count($columns) .'>' . _PN_DISPLAY_NR . '&nbsp;' . $pageNav->getLimitBox($link) . $pageNav->writePagesCounter() . '</td>';
$html .= '</tr>';
$html .= '</table>';
$html .= '</form>';
$html .= "\n<!-- Table-manager (Geda) End    -->";

return $html;

}
}
?>



[/code]

What i tried doing so far is replace:
[code] <?php  $value = '<a href="' . $value . '" target="_blank">' . $value . '</a>'; ?>[/code]
by
[code]
<?php
$value = '<a href="' . $value  . '</a>';
?>
[/code]
and putting the following value inside $value:
[code]
http://my/site">click here for details[/code]
hoping that it would convert the whole thing to: <a href="http://my/site">click here for details</a>

well that obviously didnt' work..

ideas anyone?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.