Comparing revisions for ShowCsv

Additions:
""{{showcsv file="uploads/file.csv" seperator="," header="on"}}""
- if you set header="on", the first entry in the file will be printed **strong**
===Bugs===
At the moment, there is a bug if you use a , as seperator or in your file. the explode of the entries on a line won't work. I have no clue why. You can see it [[http://niehle.info/SandBox here]].
* @author mjwilco at yahoo dot com
* @author Stefan Lindenberg (http://wikka.jsnx.com/NilsLindenberg)
* file string mandatory the name of the file which should be shown
* delimeter char optional the delimeter of the entries in the csv-file. standard is ","
* header string optional if set to "on", the first entry will be used as header. Standard is "off";
//parameters
$filename = $vars['file'];
if ($vars['seperator']) $seperator = $vars['seperator'];
else $seperator = ",";
else $header = "off";
if (file_exists($filename))
$id = fopen($filename, "r");
while ($data = fgetcsv($id, filesize($filename)))
{
$table[] = $data; //put each line into its own entry in the $table array
}
fclose($id);
//print the table
echo "<table border=1>\n";
//first entry handeld seperate, possible header
$entry = explode($seperator, $table[0][0]);
echo "<tr>\n";
for ($j = 0; $j < count($entry); $j++)
{
if ($header == 'on') echo "<th>";
else echo "<td>";
echo $entry[$j];
if ($header == 'on') echo "</th>\n";
else echo "</td>\n";
}
echo "</tr>\n";
for($i=1;$i<count($table);$i++)
{
$entry = explode($seperator, $table[$i][0]);
for ($j=0; $j < count($entry); $j++)
echo "<td>";
echo $entry[$j];
echo "</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
else print("File not found.");
table="<TR>";
if (inputs.containsKey(args[compt])) table+="<TD> <INPUT type=text size=8 value="+temp+" ></TD>";
else table+="<TD>"+temp+"</TD>";
if (inputs.containsKey(args[compt])) table+="<TD> <INPUT type=text size=8 value="+value.substring(1,value.length()-1)+" ></TD>";
else table+="<TD>"+value.substring(1,value.length()-1)+"</TD>";
table+="</TR>";
str += "<TD>"+args[i]+"</TD>";
str+= "</TR>";
result[0] += "</TABLE>";
<SCRIPT LANGUAGE="JavaScript">
</HEAD>
<BODY>
Get the comments of a java expert: looking at the user nicknames in this wiki we should find some ;-)
Deletions:
""{{showcsv file="uploads/file" seperator="," header="on" class="csvtableclass"}}""
- if you set header="on", the first line will be used as the table-header.
- class is the css-class for the table. Standard is csvtable.
''use this only with trusted files or not at all till the possible security hole are closed (see below)!''
==To do==
- test if its possible to include files from other servers. Perhaps better to allow only files in the upload-path of wikka (possible security hole).
- add "csvtable" css
- documentation!!
==Notes==
- The file now requieres the HandleCsvData library.
- html tags in a csv-file are stripped (note that everything between <?php ?> will not be shown, too)
*
* @param string file mandatory: the name of the file which should be shown
* @param char delimeter optional: the delimeter of the entries in the csv-file. Standard is ","
* @param ? header optional: if set to "on", the first entry will be shown strong. Standard is "off";
require_once('library/handlecsvdata.php');
// ***Get the params ***
$header= 'off';
$separator = ",";
$filename = $vars['file'].".csv";
$tableclass = $vars['tableclass'];
if ($vars['separator']) $separator = $vars['separator'];
// *** Get the data and print the table ***
if (is_array($table = GetCsvData($filename, $separator, $tableclass))) PrintCsvTable($table, $header);
table="<tr>";
if (inputs.containsKey(args[compt])) table+="<td> <INPUT type=text size=8 value="+temp+" ></td>";
else table+="<td>"+temp+"</td>";
if (inputs.containsKey(args[compt])) table+="<td> <INPUT type=text size=8 value="+value.substring(1,value.length()-1)+" ></td>";
else table+="<td>"+value.substring(1,value.length()-1)+"</td>";
table+="</tr>";
str += "<td>"+args[i]+"</td>";
str+= "</tr>";
result[0] += "</table>";
<script LANGUAGE="JavaScript">
</head>
<body>
Get the comments of a java expert: looking at the user nicknames in this wiki we should find some ;-)
~&Although a Java-based solution may sound nice, there are actually some big disadvantages to this:
~~-People who choose Wikka as a solution because they already know PHP or would be prepared to learn some, may be disappointed to also have to learn Java (which is, frankly, not as easy to learn as PHP); and one language is quite enough to deal with for a beginner. And apart from learning the language, not everyone has a Java compiler to build an applet either: A PHP solution could at least be "easily" adapted by anyone who needs a tweak.
~~-The solution requires an applet to be embedded rather than an action code - which is not something even experienced Wiki page authors are likely to be be familiar with (at the very least there should be an action "wrapper" which outputs the ##applet## HTML element (or better: an ##object## since ##applet## is deprecated)).
~~-This solution requires the site visitor to have Java (JRE at least) installed **and** enabled **and** of the correct version (I just went through downloading and installing a new JRE just to be able to see a FreeMind mindmap example...); this would exclude many visitors fom seeing the data.
~~-The solution requires JavaScript which many site vistotors have diabled (or don't have available at all); relying on JavaScript for functionality is therefore not a good idea (although it's fine to use as //enhancement// of functionality that is provided without JavaScript. Again, this would exclude many visitors from seeing thr data.
~&All that said, it may not be so hard to translate the code from Java to PHP, and would welcome a proposal so we can compare the two alternatives in the same language. --JavaWoman (who is not a Java expert ;-))
----
CategoryUserContributions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki