2017-03-21, 07:55:48
(This post was last modified: 2017-03-22, 20:54:37 by vish93.
Edit Reason: Added more detial
)
Hi guys I would like to create a plugin where for example you can provide feedback on some apprenticeship programmes like 1 to 10 ratings and a simple message box and this is then collected into an excel file that can be downloaded in the backend. How could I achire this ? I guess a plugin is required? Would anyone know how I would go about achieving this ?
Update
So far I have created a plugin following the hello-world example and got a csv file creating when I go to my plugin page in admin if none exists, and a download link if it does. Simple! but progress nonetheless.
Now, I get forbidden when I click to download the the file. Thus, what is the best place to store this csv file ?
Currently, I have created a my_plugin folder within the plugin folder, and within this the csv file is stored.
Also, now I have also got it write to the file if it exists when I go to the plugins admin page. But, I need to write the post data from a form! Therefore, How can I get the post data in the plugin php file to be able to use in a function I guess that will convert it to an array that could be appended to the file?
Is this possible in GET SIMPLE? like are you able to globally use plugin functions or get form to post to the plugin ?
My code so far:
Update
So far I have created a plugin following the hello-world example and got a csv file creating when I go to my plugin page in admin if none exists, and a download link if it does. Simple! but progress nonetheless.
Now, I get forbidden when I click to download the the file. Thus, what is the best place to store this csv file ?
Currently, I have created a my_plugin folder within the plugin folder, and within this the csv file is stored.
Also, now I have also got it write to the file if it exists when I go to the plugins admin page. But, I need to write the post data from a form! Therefore, How can I get the post data in the plugin php file to be able to use in a function I guess that will convert it to an array that could be appended to the file?
Is this possible in GET SIMPLE? like are you able to globally use plugin functions or get form to post to the plugin ?
My code so far:
PHP Code:
<?php
/*
Plugin Name: Hello World
Description: Gather Feedback
Version: 1.0
Author: Vish Patel
*/
# get correct id for plugin
$thisfile=basename(__FILE__, ".php");
$plugin_folder_name = 'hello-world';
$plugin_folder_path = GSPLUGINPATH.$plugin_folder_name.'/';
$rel_plugin_folder_path = substr(GSPLUGINPATH, strlen(GSROOTPATH)).$plugin_folder_name.'/';
# register plugin
register_plugin(
$thisfile, //Plugin id
'Vish Feedback', //Plugin name
'1.0', //Plugin version
'Vish Patel', //Plugin author
'http://www.cagintranet.com/', //author website
'Gather feedback and save to a CSV file', //Plugin description
'plugins', //page type - on which admin tab to display
'Feedback_admin' //main function (administration)
);
# activate filter
add_action('index-posttemplate','hello_world');
# add a link in the admin tab 'theme'
add_action('plugins-sidebar','createSideMenu',array($thisfile,'Vish Feedback'));
# functions
function hello_world() {
echo '<p>Hello World</p>';
}
function createPath($path) {
if (is_dir($path)) return true;
$prev_path = substr($path, 0, strrpos($path, '/', -2) + 1 );
$return = createPath($prev_path);
return ($return && is_writable($prev_path)) ? mkdir($path) : false;
}
function Feedback_admin() {
global $plugin_folder_path;
global $filename;
global $year;
global $month;
global $path;
global $rel_plugin_folder_path;
$year = date("Y");
$month = date("m");
$path = $plugin_folder_path.$year.'/'.$month.'/';
createPath($path);
$filename = $path."vish.csv";
if (file_exists($filename)) {
/*
echo "The file $filename exists";
$list = array("vish,n/a,nonw,na/n");
$file = fopen($filename,"a");
foreach ($list as $line)
{
fputcsv($file,explode(',',$line));
}
fclose($file);
*/
echo("<a href='../{$rel_plugin_folder_path}{$year}/{$month}/vish.csv' download>Download Current months feedback spreadsheet</a>");
} else {
$ourFileHandle = fopen($filename, 'w') or die("can't open file");
$headers = ['Apprenticeship_Programme', 'Rating', 'Programme_Performance', 'Quality_Of_Programme'];
fputcsv($ourFileHandle, $headers);
fclose($ourFileHandle);
}
}
?>