Around here at RJM Programming we encourage the adage “keeping busy” and “keep moving forward” (and sometimes sideways) even if that movement is a very nuanced moving forward. Today’s tutorial is a case in point, because even though a regular reader might say “what is new with this Google Chart Pie Chart macOS Korn Shell Tutorial to the recent Google Chart Geo Chart macOS Korn Shell Tutorial?” … we found the exercise of interest …
- partly because when you get in there and code, environmental differences can surprise … and …
- don’t underestimate how good it is to “retry a similar concept” and learn better ways (perhaps) of approaching coding problems, as it is very seldom we code a problem twice the same way (ask someone to quietly hive away some code you wrote, but ask you to rewrite it even a day later, compare, and I’d be surprised that the code is the same, if it involves any complexity)
At the macOS command line Korn Shell pie_chart.ksh end, different to Google Chart Geo Chart macOS Korn Shell Tutorial we involved …
- a new “__” forced delimitation regime between the “?” and “=” (ie. within the one web application’s argument’s name) to be certain of a one to one association of data items …
- we use (good ‘ol) sed as that brilliant command line “stream editor” … and can imagine more involved applications might benefit from the use of awk
- with the prompting progression, we back reference (via the good ‘ol Unix `[interpret me and clobber me with it]` backtick methodologies) variables we’ve already gleaned the value of, more … hence the use of echo “blah ${blah} blah” rather than echo ‘blah ${blah} blah’
At the PHP Google Chart Pie Chart pie_chart.php (web application changed …
<?php
// Command line Korn Shell interfacing code
if (!isset($_GET['data']) && !isset($_POST['data'])) {
if (strpos(strtolower(('' . $_SERVER['QUERY_STRING'])), 'listis=') !== false) {
$urlbase="https://www.rjmprogramming.com.au/PHP/PieChart/pie_chart.php";
$proposedform="<ht" . "ml><bo" . "dy onload=\"document.getElementById('clickme').click();\"><form id=myf style=display:none; target=_self action='" . $urlbase . "' method=POST><input type=hidden name=onclick value=y></input><input id=clickme type=submit value=Submit></input></form></body></html>";
$datavalis=explode("=", ('' . $_SERVER['QUERY_STRING']))[1];
$bitsbetween=["?title=", "&onclick=y&task=", "&desc=", "&data="];
$bitsap=explode("__", explode("=", explode("?", ('?' . $_SERVER['QUERY_STRING']))[1])[0]);
for ($iuy=0; $iuy<sizeof($bitsap); $iuy++) {
if (strtolower(str_replace("_", "%20", $bitsap[$iuy])) == "listis") {
$proposedform=str_replace(" method=POST>", " method=POST><input type=hidden name='" . explode("=", explode("&", substr($bitsbetween[$iuy],1))[-1 + sizeof(explode("&", substr($bitsbetween[$iuy],1)))])[0] . "' value='" . str_replace("+"," ",urldecode($datavalis)) . "'></input>", $proposedform);
$urlbase.=$bitsbetween[$iuy] . '' . str_replace(" ", "%20", str_replace("+"," ",urldecode($datavalis)));
} else {
$proposedform=str_replace(" method=POST>", " method=POST><input type=hidden name='" . explode("=", explode("&", substr($bitsbetween[$iuy],1))[-1 + sizeof(explode("&", substr($bitsbetween[$iuy],1)))])[0] . "' value='" . str_replace("_", " ", $bitsap[$iuy]) . "'></input>", $proposedform);
$urlbase.=$bitsbetween[$iuy] . '' . urlencode(str_replace("_", "%20", $bitsap[$iuy]));
}
}
if (strlen($urlbase) > 800) {
echo $proposedform;
} else {
header('Location: ' . $urlbase);
}
exit;
}
}
?>
… this way) interfacing end to allow for this command line “front interface” … different feeling to Google Chart Geo Chart macOS Korn Shell Tutorial …
- we do not resort to Javascript at all for short URL cases … and for the long ones …
- check for proposed URL length within PHP and navigate via an HTML form method=POST methodology
We’ll leave you with some Korn Shell code for this …
#!/bin/ksh
echo 'Interface to Google Chart Pie Chart interfacer created by RJM Programming ...'
echo ''
equl="="
prefd=",%20[~"
suffd="]%20"
echo "Verb for command line eg. open eg. curl "
read verb
if [ -z "$verb" ]; then
verb="open"
fi
if [ ! -z "$verb" ]; then
echo ''
echo "Enter Pie Chart title [My Daily Activities] "
read pie_chart_title
if [ -z "$pie_chart_title" ]; then
pie_chart_title="My Daily Activities"
fi
echo ''
echo "Enter ${pie_chart_title} Activity Type title [Task] "
pie_chart_title="`echo ${pie_chart_title} | sed '/ /s//_/g'`"
read activity_type_title
if [ -z "$activity_type_title" ]; then
activity_type_title="Task"
fi
if [ ! -z "$activity_type_title" ]; then
activitytypetitle="`echo ${activity_type_title}`"
echo ''
echo "Enter ${activity_type_title} Measure title [Percentage] "
activity_type_title="`echo ${activity_type_title} | sed '/ /s//_/g'`"
read measure_title
if [ -z "$measure_title" ]; then
measure_title="Percentage"
fi
measuretitle="`echo ${measure_title}`"
measure_title="`echo ${measure_title} | sed '/ /s//_/g'`"
echo ''
echo "Enter semicolon separated list of Pie Chart comma separated ${activitytypetitle},${measuretitle} data sets eg. Sleep,30;Work,30;Eating,10;Entertainment,20;Daily Chores,10 "
read commastring
if [ ! -z "$commastring" ]; then
cstring="`echo ${commastring} | sed '/,/s//~,/g' | sed '/;/s//]%20,%20[~/g'`"
commastring="`echo ${prefd}${cstring}${suffd}`"
echo ''
echo 'Starting the call ...'
rhs="`echo https://www.rjmprogramming.com.au/PHP/PieChart/pie_chart.php?${pie_chart_title}__${activity_type_title}__${measure_title}__listis${equl}${commastring} | sed '/ /s//%20/g'`"
echo "$verb ${rhs}"
ksh -c "$verb ${rhs}"
exit
fi
fi
fi
exit
If this was interesting you may be interested in this too.