Javascript 为Joomla创建回调脚本

Javascript 为Joomla创建回调脚本,javascript,callback,joomla3.0,Javascript,Callback,Joomla3.0,在线评估有API回调Url,当学生提交我需要捕获的测验到joomla数据库用户帐户时,该Url调用joomla根目录中的网页/脚本/php文件以异步传递信息 我需要一个脚本放入这个php文件,检查用户名是否不存在,然后将用户创建为注册组并添加信息。如果用户名存在,那么只需将信息添加到他的帐户中,这里的密钥就是用户名。学生现在可以登录到Joomla并查看测试历史记录 以下是在线评估中支持的变量: username :the username of the user, if avail

在线评估有API回调Url,当学生提交我需要捕获的测验到joomla数据库用户帐户时,该Url调用joomla根目录中的网页/脚本/php文件以异步传递信息

我需要一个脚本放入这个php文件,检查用户名是否不存在,然后将用户创建为注册组并添加信息。如果用户名存在,那么只需将信息添加到他的帐户中,这里的密钥就是用户名。学生现在可以登录到Joomla并查看测试历史记录

以下是在线评估中支持的变量:

username        :the username of the user, if available.
firstname       :the first name of the user, if available.
lastname        :the last name of the user, if available.
cf_label        :the value of this custom field (for example, cf_company if you have a custom field labelled mpany).
title           :the title of the publication.
accesscode      :the access code entered by the user, if available.
id              :the id of the response.
ispreview       :indicates if it's a preview (1) or a real response (0).
pin             :the PIN of the publication (empty if it's a preview).
score           :the score (points) got by the user.
scorepercent    :the score (percent) got by the user.
startdate       :the date/time (UTC, yyyy-mm-ddThh:mm:ss) when the response was started.
enddate         :the date/time (UTC, yyyy-mm-ddThh:mm:ss) when the response was completed.
status          :the status of the response (2=completed, 3=passed, 4=not passed, 5=to be graded).
gr_label        :the value of this custom grade (for example, gr_passed if you have a custom grade labelled passed).
maxscore        :the maximum score available for the publication.
minscore        :the minimum score available for the publication.
它们提供了一个具有两种方法POST和GET的通用示例:

<?php

    // === GET SINGLE PARAMETER (VIA POST) ===
    $accessCode = $_POST["accesscode"];
    $cfCompany = $_POST["cf_company"];

    echo "Access Code: ".$accessCode."<br />";
    echo "Company (Custom Field): ".$cfCompany."<br />";

    // === GET SINGLE PARAMETER (VIA GET) ===
    $pin = $_GET["pin"];
    $grPassed = $_GET["gr_passed"];

    echo "Pin: ".$pin."<br />";
    echo "Grade: ".$grPassed."<br />";

    // === GET ALL PARAMETERS (VIA POST) ===
    foreach ($_POST as $key => $value)
        echo htmlspecialchars($key).": ".htmlspecialchars($value)."<br>";

?>
你能帮我写剧本吗。。 感谢,

更新1: 据我所知,我从中获得了这个脚本,并将其放在html中,但是这是否正确,以及如何让它首先通过post检查用户名,如上面的示例所示

<!DOCTYPE html>
<html>
<body>

<script>
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();


//Check for request forgeries: comment this since tokens are not generated in the html 
//JRequest::checkToken() or jexit( 'Invalid Token' );

//Get required system objects
$user         = clone(JFactory::getUser());
$pathway          = & $mainframe->getPathway();
$config       = & JFactory::getConfig();
$authorize        = & JFactory::getACL();
$document       = & JFactory::getDocument();

//Initialize new usertype setting
$newUsertype = $usersConfig->get( 'new_usertype' );
if (!$newUsertype)
{
$newUsertype = 'Registered';
}

//Bind the post array to the user object
if (!$user->bind( JRequest::get('post'), 'usertype' ))
{
JError::raiseError( 500, $user->getError());
}

//Set some initial user values
$user->set('id', 0);
$user->set('usertype', '');
$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));

$date =& JFactory::getDate();
$user->set('registerDate', $date->toMySQL());

//Save the details of the user
$user->save();


</script> 

</body>
</html>
更新2:我试过这个,但没有成功

<?php 

function register_user ($username, $email, $firstname, $lastname, $password){ 

//This is the original code which I comment to get via POST
 //$firstname = $email; // generate $firstname
 //$lastname = ''; // generate $lastname
 //$username = $email; // username is the same as email

// === GET SINGLE PARAMETER (VIA POST) ===
    $username = $_POST["username"];
    $email = $_POST["email"];
    $firstname = $_POST["firstname"];
    $lastname = $_POST["lastname"];
    $password = $_POST["username"];

 /*
 I handle this code as if it is a snippet of a method or function!!
 First set up some variables/objects     */

 // get the ACL
 $acl =& JFactory::getACL();

 /* get the com_user params */
 jimport('joomla.application.component.helper'); // include libraries/application/component/helper.php
 $usersParams = &JComponentHelper::getParams( 'com_users' ); // load the Params

 // "generate" a new JUser Object
 $user = JFactory::getUser(0); // it's important to set the "0" otherwise your admin user information will be loaded

 $data = array(); // array for all user settings

 // get the default usertype
 $usertype = $usersParams->get( 'new_usertype' );
 if (!$usertype) {
     $usertype = 'Registered';
 }

 // set up the "main" user information
 //original logic of name creation
 //$data['name'] = $firstname.' '.$lastname; // add first- and lastname
 $data['name'] = $firstname.$lastname; // add first- and lastname

 $data['username'] = $username; // add username
 $data['email'] = $email; // add email
 $data['gid'] = $acl->get_group_id( '', $usertype, 'ARO' );  // generate the gid from the usertype

 /* no need to add the usertype, it will be generated automaticaly from the gid */

 $data['password'] = $password; // set the password
 $data['password2'] = $password; // confirm the password
 $data['sendEmail'] = 1; // should the user receive system mails?

 /* Now we can decide, if the user will need an activation */
 $useractivation = $usersParams->get( 'useractivation' ); // in this example, we load the config-setting
 if ($useractivation == 1) { // yeah we want an activation

     jimport('joomla.user.helper'); // include libraries/user/helper.php
     $data['block'] = 1; // block the User
     $data['activation'] =JUtility::getHash( JUserHelper::genRandomPassword() ); // set activation hash (don't forget to send an activation email)

 }
 else { // no we need no activation

     $data['block'] = 1; // don't block the user

 }

 if (!$user->bind($data)) { // now bind the data to the JUser Object, if it not works....

     JError::raiseWarning('', JText::_( $user->getError())); // ...raise an Warning
     return false; // if you're in a method/function return false

 }

 if (!$user->save()) { // if the user is NOT saved...

     JError::raiseWarning('', JText::_( $user->getError())); // ...raise an Warning
     return false; // if you're in a method/function return false

 }

 return $user; // else return the new JUser object

 }

 $email = JRequest::getVar('email');
 $password = JRequest::getVar('password');

 //echo 'User registration...'.'<br/>';
 register_user($email, $password);
 //echo '<br/>'.'User registration is completed'.'<br/>';
?>

欢迎来到SO!请说出您尝试过的内容和遇到的问题,而不是将您的问题作为代码编写请求。感谢您的参与,我搜索并尝试了在操作系统中找到的许多脚本!但还是没弄明白。