I want to bulk upload users in the moodle plugin face-to-face, using .csv.
The user upload has to take place in the session and be made by admin or manager.
Using the file picker element from the File API
$mform->addElement('filepicker', 'userfile', get_string('file'), null,
array('maxbytes' => $maxbytes, 'accepted_types' => '*'));
Then I need to extract this data and show the names, emails etc. in the attendees list and then in reports. Is fgetcsv the right choise?:
$fields=fgetcsv($filehandle,0,$this->config->delimiter);
var_dump($fields)
$data=array();
while($row=fgetcsv($filehandle,0,$this->config->delimiter))
{
$data_row->startdate=$row[0]
$data_row->enddate=$row[0]
$data_row->room=$row[0]
$data_row->status=$row[0]
$data_row->firstname=$row[0]
$data_row->lastname=$row[0]
$data_row->username=$row[0]
$data_row->useremail=$row[0]
$data_row->attendance=$row[0]
$data_row->signupdate=$row[0]
array_push($data,$data_row)
$DB->insert_record('facetoface',$data_row, false);
}
There isn't a plugin with user upload function in face-to-face sessions, nor there is something similar.
Where to place the right code lines (in the different files of the plugin), or better said, which is the right way to proceed?
I would preffer to make a custom plugin, if that is easier,just need a guidence for the structure of it. The functionality is still similar to face-to-face, the sessions atendees are just uploaded.
There is an option to bulk upload users in Totara.
https://github.com/totara/seedlings/tree/totara-seedlings-2.7/mod/facetoface
But for your plugin you might want to use the csv_import_reader class
For an example have a look at /admin/tool/uploaduser/index.php
Related
I'm new to moodle plugin development and am trying to create a plugin that displays a page to the admin where I can add my on php code.
In brief, what I want the plugin to do I have already achieved in a standard php file that I upload to the moodle root. From here you can call the file e.g. yourdomain.co.uk/moodlelocation/myfile.php and it will run as expected.
The problem with this is it isn't secure since anyone can load the myfile.php and in turn run the scripts on the page. It also means any one else using this script (it will be given away for free when complete) would need to FTP into their hosting and upload two php files to their moodle install.
Due to this, I thought a plugin (a very very basic plugin) may be the best solution. They could then load the page in the admin via the "site administration". e.g. site administration > Development > MyPlugin. I am assuming I could then also restrict the plugin's main page to admins only (??).
So to recap, I can create a php page that has my script all rocking and rolling BUT I need to make this into a plugin.
I did some reading and I think a "local" plugin was the easiest way to go (??).
I have managed to get the local plugin up and running using the below in local/webguides/inex.php :
<?php
// Standard config file and local library.
require_once(__DIR__ . '/../../config.php');
// Setting up the page.
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('standard');
$PAGE->set_title("webguides");
$PAGE->set_heading("webguides");
$PAGE->set_url(new moodle_url('/local/webguides/index.php'));
// Ouput the page header.
echo $OUTPUT->header();
echo 'MY php CODE here etc';
?>
This works fine but with two problems:
Anyone can access it via http://domain/local/webguides/index.php
There is no link to it in the site administration (so the user would need to type the URL in).
Can anyone shed any light how I would achieve the two steps above?
Thanks in advance
p.s. ideally I'd like to keep the plugin to as few files as possible so if the required code could be added to the local/webguides/index.php file it would be preferred.
You need to create a capability, then require that capability before displaying the page.
First, have a look at local/readme.txt - this gives an overview of the files needed for a local plugin.
Or read the documentation at https://docs.moodle.org/dev/Local_plugins
Also have a look at existing local plugins so you can see how they are created - https://moodle.org/plugins/?q=type:local
At a bare minimum, you need
local/webguides/db/access.php - this will have the capability
local/webguides/lang/en/local_webguides.php
local/webguides/version.php
Plus your index file
local/webguides/index.php
In the db/access.php file have something like
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'local/webguides:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
),
),
);
You might also need 'riskbitmask' => RISK_XXX depending on if there are any risks in you code. Such as RISK_CONFIG, RISK_PERSONAL, etc.
In lang/en/local_webguides.php have something like
defined('MOODLE_INTERNAL') || die();
$string['pluginname'] = 'Webguides';
$string['webguides:view'] = 'Able to view webguids';
In version.php have something like
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2020051901; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2015051109; // Requires this Moodle version.
$plugin->component = 'local_webguides'; // Full name of the plugin (used for diagnostics).
Replace 2015051109 with the version of Moodle you are using - this will be in version.php in the root folder.
Then in your index.php file use this near the top.
require_capability('local/webguides:view', context_system::instance());
So only users with that capability will have access to the page.
EDIT:
You can add a link via settings.php using something like
defined('MOODLE_INTERNAL') || die;
if ($hassiteconfig) {
$page = new admin_externalpage(
'local_webguides',
get_string('pluginname', 'local_webguides'),
new moodle_url('/local/webguides/index.php'),
'local/webguides:view'
);
$ADMIN->add('localplugins', $page);
}
Then in your index page ad this
require_once($CFG->libdir.'/adminlib.php');
and remove require_login() and require_capability() and replace with
admin_externalpage_setup('local_webguides');
We are using wordpress for blogs (hosted via Godaddy). I am not a wordpress developer and hence this basic question. We have the wordpress post api like blog.domainname.com/wp-json/wp/v2/posts. This returns a json object of most of the fields. Now i have added a custom field to be returned with this object. i have seen lot of videos and study on what changes that needs to be done especially the one here.
https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
My Question is - Where do I make these changes? What file do I need add these changes? I am using WP as an admin. I installed a File Explorer plugin and I am able to see three main folders - wp-admin, wp-content, wp-includes.
Is there a particular file i need to make changes? Based on my learning - i wrote the following snippet. not sure where to add this :(
function addCustomField_register_fields() {
register_rest_field('post',
'custom_Field_name',
array(
'get_callback' =>'get_custom_field',
'update_callback' => null,
'schema' => null
));
}
function get_custom_field($object, $field_name , $request) {
return get_post('custom_field');
}
add_action('rest_api_init', 'addCustomField_register_fields');
Also would appreciate if you can let me know if my method is correct.
Typically theme customisations are added to the functions.php file in the root directory of your active theme.
As for your code, what are you trying to do? Your callback in particular doesn't look like it will work. get_post() loads a WordPress post by ID. 'custom_field' isn't a valid post ID, so this will always fail.
I am trying to add google identity toolkit in php. Signin option is working correctly but when i am clicking on problem in sign in link it is showing capthca after submitting captcha it is not navigating to any url.
email.php
<?php
include "identity-toolkit-php-client-master/src/GitkitClient.php";
$gitkitClient=new Gitkit_Client();
$oob_response = $gitkitClient->getOobResults($_POST);
$oob_link = $oob_response['oobLink'];
echo json_encode($oob_response);
?>
email.php is the oobactionurl file. when i am using this code I am getting this error .image
You need to create a php file to retrieve and send the reset link to the user. Make sure the oobActionUrl widget option points to this file. Within the file, you'll get the generated link and additional information by calling $gitkitClient->getOobResults($_POST). It should also work if you exclude $_POST, as the function will check the post contents if no arguments are passed. Then, you can get the link itself like this:
$oob_response = $gitkitClient->getOobResults($_POST);
$oob_link = $oob_response['oobLink'];
From there, you can use your email function of choice to send it to the user. The returned array should contain the following.
'email' => email of the user,
'oldEmail' => old email (for ChangeEmail only),
'newEmail' => new email (for ChangeEmail only),
'oobLink' => url for user click to finish the operation,
'action' => 'RESET_PASSWORD', or 'CHANGE_EMAIL',
'response_body' => http response to be sent back to Gitkit widget
Let me know if you have any further questions.
I'm building a CakePHP application, and I'm trying to allow users to pick an email template from a list and then send it to the addresses that they choose. I'd like to avoid hard-coding the names of the templates, as they are likely to change and be updated over time. How can I generate a list (in my controller) of the filenames of all the email templates I have? I've tried accessing the contents of app/view/Emails/text using the CakePHP Folder class as described here: http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html
However, that didn't work; I'm unable to get the contents of that directory. I just need to access the filenames; I can do the rest of the logic once I get them.
Try this in any method in your controller:
App::uses('Folder', 'Utility');
$dir = new Folder(APP . 'View/Emails/text/');
$files = $dir->find('.*\.ctp');
//print the array to inspect
pr($files);
It should show you all the .ctp template files in /app/View/Emails/text/
In bigcommerce site I want functionality like anonymous users can upload image for products which he wants to purchase and add to cart.Like this (http://www.woowoonails.com/) site.
When you will open this link you will see Design Your Own Nail Wraps! container on home containing link user your own photos when you will click on this you will be on this link (http://www.woowoonails.com/designer/layout).Here you can upload your photos and click on add to bag. Same functionality I want on my site but I did not get any idea.Bigcommerce team does now allow to upload php file to their server.Then I tried to use api.
But I am not able to configure it.I have downloaded the api from (github.com/bigcommerce/bigcommerce-api-php) .But I am not getting idea how to configure it and use.
I have also download the single php file(raw.github.com/bigcommerce/bigcommerce-api-php/master/bigcommerce.php) and put it inside the Bigcommerce1 folder and then include in my file containing code:
require 'Bigcommerce1/bigcommerce.php';
BigCommerce_Api::configure(array(
'store_url' => 'siteurl',
'username' => 'admin',
'api_key' => 'df38dd10e9665a3cfa667817d78ec91ee9384bc3'
));
But nothing work.Can you give me some light about how can I achieve the functionality to upload photos and also about api configuration.
Thanks
You want to use the FTP not the BigCommerce API to capture the image... BigCommerce does support file uploading, but from what I have read it is an afterthought and is not configurable via the API. It is easier therefore to have an iframe for file upload, capturing the file contents and uploading it to the bigC (s)FTP server for storage...
This means you could post a file to any other site (so hosted externally) upload it to the FTP under some unique id, and when the order was submitted re-join the two.
Also to connect to the BigCommerce API, it is best to write or use a wrapper function library around BigCommerce
so for example we made the library object-based due to errors and undesirable functionality in the PHP version of the API, and a difference in coding styles, so we just use the following to get all orders 'Awaiting Fulfillment' and work from there...
$bcAPI = new bigcommerceAPI();
$orders = $bcAPI->getOrders();
$orders = array_filter($orders,function($data){ if($data->status == 'Awaiting Fulfillment'){ return true; } return false; });