13 Replies - 533 Views - Last Post: 16 August 2019 - 05:41 PM Rate Topic: -----

#1 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 04-February 19

Help with modifying script’s array

Posted 03 August 2019 - 01:17 PM

The php web script that I’m trying to modify shows an html page of transactions. I’d like to change what is displayed there. The array begins on approx line 184 (in bold, near the bottom of the code below, with the line:

$ads_list .= PT_LoadPage('transactions/list',array(



I’d like help to change the html transaction page to reflect what appears in the ‘u_paid_videos’ table, which has these columns:
id, id_user, id_video, video_title, time, user_id_uploaded, time_date, earned_amount, currency

to replace what is in the array now:

'ID' => $tr->id,
'PAID_USER' => substr($user_data->name, 0,20),
'USER_NAME' => $user_data->username,
'VIDEO_NAME' => substr($video->title, 0,20) ,
'VIDEO_ID_' => PT_Slug($video->title, $video->video_id),
'AMOUNT' => $tr->earned_amount,
"CURRENCY" => $currency,
"TIME" => PT_Time_Elapsed_String($tr->time)



the change, for example, would change:
‘PAYER_NAME’ to be ‘id_user’
‘USER_NAME’’ to be ‘user_id_uploaded’
‘VIDEO_ID_’ to be ‘id_video’
‘AMOUNT’ to be ‘earned_amount’
“TIME” to be ‘time_date’

here’s the php code:

<?php

error_reporting(-1); // set maximum errors
ini_set('display_errors' , 'true');

if (!IS_LOGGED || ($pt->config->sell_videos_system == 'off' && $pt->config->usr_v_mon == 'off') ) {
	header('Location: ' . PT_Link('404'));
	exit;
}

$currency        = '$';

if ($pt->config->payment_currency == 'EUR') {
	$currency    = '€';
}
$types = array('today','this_week','this_month','this_year');
$type = 'today';

if (!empty($_GET['type']) && in_array($_GET['type'], $types)) {
	$type = $_GET['type'];
}

if ($type == 'today') {
	$start = strtotime(date('M')." ".date('d').", ".date('Y')." 12:00am");
	$end = strtotime(date('M')." ".date('d').", ".date('Y')." 11:59pm");

	$array = array('00' => 0 ,'01' => 0 ,'02' => 0 ,'03' => 0 ,'04' => 0 ,'05' => 0 ,'06' => 0 ,'07' => 0 ,'08' => 0 ,'09' => 0 ,'10' => 0 ,'11' => 0 ,'12' => 0 ,'13' => 0 ,'14' => 0 ,'15' => 0 ,'16' => 0 ,'17' => 0 ,'18' => 0 ,'19' => 0 ,'20' => 0 ,'21' => 0 ,'22' => 0 ,'23' => 0);
	$ads_array = $array;
	$date_type = 'H';
	$pt->cat_type = 'today';
    $pt->chart_title = $lang->today;
    $pt->chart_text = date("l");
}
elseif ($type == 'this_week') {

	$time = strtotime(date('l').", ".date('M')." ".date('d').", ".date('Y'));
	if (date('l') == 'Saturday') {
		$start = strtotime(date('M')." ".date('d').", ".date('Y')." 12:00am");
	}
	else{
		$start = strtotime('last saturday, 12:00am', $time);
	}

	if (date('l') == 'Friday') {
		$end = strtotime(date('M')." ".date('d').", ".date('Y')." 11:59pm");
	}
	else{
		$end = strtotime('next Friday, 11:59pm', $time);
	}

	$array = array('Saturday' => 0 , 'Sunday' => 0 , 'Monday' => 0 , 'Tuesday' => 0 , 'Wednesday' => 0 , 'Thursday' => 0 , 'Friday' => 0);
	$ads_array = $array;
	$date_type = 'l';
	$pt->cat_type = 'this_week';
    $pt->chart_title = $lang->this_week;
    $pt->chart_text = date('y/M/d',$start)." To ".date('y/M/d',$end);
}
elseif ($type == 'this_month') {
	$start = strtotime("1 ".date('M')." ".date('Y')." 12:00am");
	$end = strtotime(cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'))." ".date('M')." ".date('Y')." 11:59pm");
	if (cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y')) == 31) {
		$array = array('01' => 0 ,'02' => 0 ,'03' => 0 ,'04' => 0 ,'05' => 0 ,'06' => 0 ,'07' => 0 ,'08' => 0 ,'09' => 0 ,'10' => 0 ,'11' => 0 ,'12' => 0 ,'13' => 0 ,'14' => 0 ,'15' => 0 ,'16' => 0 ,'17' => 0 ,'18' => 0 ,'19' => 0 ,'20' => 0 ,'21' => 0 ,'22' => 0 ,'23' => 0,'24' => 0 ,'25' => 0 ,'26' => 0 ,'27' => 0 ,'28' => 0 ,'29' => 0 ,'30' => 0 ,'31' => 0);
	}elseif (cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y')) == 30) {
		$array = array('01' => 0 ,'02' => 0 ,'03' => 0 ,'04' => 0 ,'05' => 0 ,'06' => 0 ,'07' => 0 ,'08' => 0 ,'09' => 0 ,'10' => 0 ,'11' => 0 ,'12' => 0 ,'13' => 0 ,'14' => 0 ,'15' => 0 ,'16' => 0 ,'17' => 0 ,'18' => 0 ,'19' => 0 ,'20' => 0 ,'21' => 0 ,'22' => 0 ,'23' => 0,'24' => 0 ,'25' => 0 ,'26' => 0 ,'27' => 0 ,'28' => 0 ,'29' => 0 ,'30' => 0);
	}elseif (cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y')) == 29) {
		$array = array('01' => 0 ,'02' => 0 ,'03' => 0 ,'04' => 0 ,'05' => 0 ,'06' => 0 ,'07' => 0 ,'08' => 0 ,'09' => 0 ,'10' => 0 ,'11' => 0 ,'12' => 0 ,'13' => 0 ,'14' => 0 ,'15' => 0 ,'16' => 0 ,'17' => 0 ,'18' => 0 ,'19' => 0 ,'20' => 0 ,'21' => 0 ,'22' => 0 ,'23' => 0,'24' => 0 ,'25' => 0 ,'26' => 0 ,'27' => 0 ,'28' => 0 ,'29' => 0);
	}elseif (cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y')) == 28) {
		$array = array('01' => 0 ,'02' => 0 ,'03' => 0 ,'04' => 0 ,'05' => 0 ,'06' => 0 ,'07' => 0 ,'08' => 0 ,'09' => 0 ,'10' => 0 ,'11' => 0 ,'12' => 0 ,'13' => 0 ,'14' => 0 ,'15' => 0 ,'16' => 0 ,'17' => 0 ,'18' => 0 ,'19' => 0 ,'20' => 0 ,'21' => 0 ,'22' => 0 ,'23' => 0,'24' => 0 ,'25' => 0 ,'26' => 0 ,'27' => 0 ,'28' => 0);
	}
	$ads_array = $array;
	$pt->month_days = count($array);
	$date_type = 'd';
	$pt->cat_type = 'this_month';
    $pt->chart_title = $lang->this_month;
    $pt->chart_text = date("M");
}
elseif ($type == 'this_year') {
	$start = strtotime("1 January ".date('Y')." 12:00am");
	$end = strtotime("31 December ".date('Y')." 11:59pm");
	$array = array('01' => 0 ,'02' => 0 ,'03' => 0 ,'04' => 0 ,'05' => 0 ,'06' => 0 ,'07' => 0 ,'08' => 0 ,'09' => 0 ,'10' => 0 ,'11' => 0 ,'12' => 0);
	$ads_array = $array;
	$date_type = 'm';
	$pt->cat_type = 'this_year';
    $pt->chart_title = $lang->this_year;
    $pt->chart_text = date("Y");
}

$day_start = strtotime(date('M')." ".date('d').", ".date('Y')." 12:00am");
$day_end = strtotime(date('M')." ".date('d').", ".date('Y')." 11:59pm");


$this_day_ads_earn = $db->rawQuery("SELECT SUM(amount) AS sum FROM ".T_ADS_TRANS." c WHERE `time` >= ".$day_start." AND `time` <= ".$day_end."  AND type = 'video' AND video_owner = ".$pt->user->id);
//$this_day_video_earn = $db->rawQuery("SELECT * FROM ".T_VIDEOS_TRSNS." c WHERE `time` >= ".$day_start." AND `time` <= ".$day_end." AND user_id = ".$pt->user->id);
$this_day_video_earn = $db->rawQuery("SELECT * FROM u_paid_videos c WHERE `time` >= ".$day_start." AND `time` <= ".$day_end." AND user_id_uploaded = ".$pt->user->id);

$day_net = 0;
foreach ($this_day_video_earn as $tr) {
	if ($tr->currency == "USD") {
		//$day_net = $day_net + ($tr->amount - $tr->admin_com);
		$day_net = $day_net + ($tr->earned_amount);
	}

}
$today_earn = $this_day_ads_earn[0]->sum + $day_net ;

$month_start = strtotime("1 ".date('M')." ".date('Y')." 12:00am");
$month_end = strtotime(cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'))." ".date('M')." ".date('Y')." 11:59pm");
$this_month_ads_earn = $db->rawQuery("SELECT SUM(amount) AS sum FROM ".T_ADS_TRANS." c WHERE `time` >= ".$month_start." AND `time` <= ".$month_end."  AND type = 'video' AND video_owner = ".$pt->user->id);
//$this_month_video_earn = $db->rawQuery("SELECT * FROM ".T_VIDEOS_TRSNS." c WHERE `time` >= ".$month_start." AND `time` <= ".$month_end." AND user_id = ".$pt->user->id);
$this_month_video_earn = $db->rawQuery("SELECT * FROM u_paid_videos c WHERE `time` >= ".$month_start." AND `time` <= ".$month_end." AND user_id_uploaded = ".$pt->user->id);
$month_net = 0;
foreach ($this_month_video_earn as $tr) {
	if ($tr->currency == "USD") {
		//$month_net = $month_net + ($tr->amount - $tr->admin_com);
		$month_net = $month_net + ($tr->earned_amount);
	}

}
$month_earn = $this_month_ads_earn[0]->sum + $month_net ;

//$trans        = $db->where('user_id',$user->id)->orderBy('id','DESC')->get(T_VIDEOS_TRSNS);
$trans        = $db->where('user_id_uploaded',$user->id)->orderBy('id_user')->get('u_paid_videos');

$ads_trans = $db->where('time',$start,'>=')->where('time',$end,'<=')->where('video_owner',$pt->user->id)->where('type','video')->get(T_ADS_TRANS);
$total_ads = 0;
if (!empty($ads_trans)) {
	foreach ($ads_trans as $key => $ad) {
		if ($ad->time >= $start && $ad->time <= $end) {
			$day = date($date_type,$ad->time);
			if (in_array($day, array_keys($ads_array))) {
				$ads_array[$day] += $ad->amount;
				$total_ads += $ad->amount;
			}
		}
	}
}
$ads_list        = "";


$total_earn = 0;
if (!empty($trans)) {
	foreach ($trans as $tr) {
		//$video = PT_GetVideoByID($tr->video_id, 0, 0, 2);
		$video = PT_GetVideoByID($tr->id_video, 0, 0, 2);

		$user_data   = PT_UserData($tr->id);

		$currency         = "";
		$admin_currency         = "";
		$net = 0;
		if ($tr->currency == "USD") {
			$currency     = "$";
			//$admin_currency     = "$".$tr->admin_com;
			$net = $tr->earned_amount;
		}
		else if($tr->currency == "EUR"){
			$currency     = "€";
			//$admin_currency     = "€".$tr->admin_com;
			//$net = $tr->amount - $tr->admin_com;
			$net = $tr->earned_amount;
		}
		elseif ($tr->currency == "EUR_PERCENT") {
			$currency     = "€";
			//$admin_currency = $tr->admin_com."%";
			//$net = $tr->amount - ($tr->admin_com * $tr->amount)/100;
			$net = $tr->earned_amount;
		}
		elseif ($tr->currency == "USD_PERCENT") {
			$currency     = "$";
			//$admin_currency = $tr->admin_com."%";
			//$net = $tr->amount - ($tr->admin_com * $tr->amount)/100;
			$net = $tr->earned_amount;
		}

		if ($tr->time >= $start && $tr->time <= $end) {
			$day = date($date_type,$tr->time);
			if (in_array($day, array_keys($array))) {
				$array[$day] += $net;
			}
		}

		$total_earn = $total_earn + (float)$net;
		if (!empty($video) && !empty($user_data)) {
			**$ads_list   .= PT_LoadPage('transactions/list',array(**
				'ID' => $tr->id,
				'PAID_USER' => substr($user_data->name, 0,20),
				//'PAID_URL' => $user_data->url,
				'USER_NAME' => $user_data->username,
				'VIDEO_NAME' => substr($video->title, 0,20) ,
				//'VIDEO_URL' => $video->url,
				'VIDEO_ID_' => PT_Slug($video->title, $video->video_id),
				'AMOUNT' => $tr->earned_amount,
				"CURRENCY" => $currency,
				"A_CURRENCY" => $admin_currency,
				//"NET" => $net,
				"TIME" => PT_Time_Elapsed_String($tr->time)
			));
		}
	}
}
$total_earn = $total_earn + $total_ads;

$pt->array = implode(', ', $array);
$pt->ads_array = implode(', ', $ads_array);
$pt->page_url_ = $pt->config->site_url.'/transactions';
$pt->title       = $lang->earnings . ' | ' . $pt->config->title;
$pt->page        = "transactions";
$pt->description = $pt->config->description;
$pt->keyword     = @$pt->config->keyword;
$pt->currency    = $currency;
$pt->content     = PT_LoadPage('transactions/content',array(
	'CURRENCY'   => $currency,
	'ADS_LIST'   => $ads_list,
	'TOTAL_EARN' => $total_earn,
	'TODAY_EARN' => $today_earn,
	'MONTH_EARN' => $month_earn
));







any help will be appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with modifying script’s array

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6813
  • View blog
  • Posts: 28,186
  • Joined: 12-December 12

Re: Help with modifying script’s array

Posted 04 August 2019 - 12:48 AM

What have you attempted or considered?
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3825
  • View blog
  • Posts: 13,933
  • Joined: 08-August 08

Re: Help with modifying script’s array

Posted 04 August 2019 - 09:56 AM

That code looks more like a grocery list than a program. You really should use functions. That act alone will make debugging far easier.
Was This Post Helpful? 0
  • +
  • -

#4 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 04-February 19

Re: Help with modifying script’s array

Posted 04 August 2019 - 10:40 AM

Thanks for your replies.

I have tried this:

'ID' => $tr->id,
'PAID_USER' => $tr->id_user,
'USER_NAME' => $tr->user_id_uploaded,
'VIDEO_ID_' => $tr->id_video,
'AMOUNT' => $tr->earned_amount,
"CURRENCY" => $currency,
"TIME" => $tr->time_date



Regarding "grocery list", I'm not the developer of the script I'm just trying to make this one modification.

Any additional guidance is welcomed


p.s. Also, everytime lately that I access dreamincode.net, I now see a Trojan warning from my pc's malware program.

This post has been edited by chrisjchrisj: 04 August 2019 - 10:41 AM

Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3825
  • View blog
  • Posts: 13,933
  • Joined: 08-August 08

Re: Help with modifying script’s array

Posted 04 August 2019 - 11:27 AM

Well, if you're going to be a copy/paste (bad idea) programmer, you'll need to learn to copy better code.

You need to start thinking about what you're trying to do and what you expect to happen. That's important even when posting questions. You should need to be prodded for what you've done, and you shouldn't need to be prodded for information about what happens when you tried doing it. What errors did you see? Did something work, but something else did not? What is in $tr?
Was This Post Helpful? 0
  • +
  • -

#6 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 04-February 19

Re: Help with modifying script’s array

Posted 04 August 2019 - 01:07 PM

Much thanks again for your reply.
Yes, my coding skill level needs improvement, that's why I'm looking for help.
As far as "about what you're trying to do and what you expect to happen", I’m trying to modify the array, that I've pointed out, to show different info on the html page which displays what is listed in that array.

As far as 'what have I attempted', when I try this:

		$total_earn = $total_earn + (float)$net;
		if (!empty($video) && !empty($user_data)) {
			$ads_list   .= PT_LoadPage('transactions/list',array(
			'ID' => $tr->id,
			'PAID_USER' => $tr->id_user,
			'USER_NAME' => $tr->user_id_uploaded,
			'VIDEO_ID_' => $tr->id_video,
			'AMOUNT' => $tr->earned_amount,
			"CURRENCY" => $currency,
			"TIME" => $tr->time_date


				//'ID' => $tr->id,
				//'PAID_USER' => substr($user_data->name, 0,20),
				//'PAID_USER' =>id_user,
				//'PAID_URL' => $user_data->url,
				//'USER_NAME' => $user_data->username,
				//'VIDEO_NAME' => substr($video->title, 0,20) ,
				//'VIDEO_URL' => $video->url,
				//'VIDEO_ID_' => PT_Slug($video->title, $video->video_id),
				//'AMOUNT' => $tr->earned_amount,
				//"CURRENCY" => $currency,
				//"A_CURRENCY" => $admin_currency,
				//"NET" => $net,
				//"TIME" => PT_Time_Elapsed_String($tr->time)
			));
		}
	}
}



on the html page I see this: see attached image

and in the console I see: "Uncaught SyntaxError: Unexpected token"

regarding $tr, I believe the script uses that for transaction? but, I'm not sure. I am hoping that might be determined from the original page code I posted.


I look forward to any additional comments/suggestions

Attached image(s)

  • Attached Image

This post has been edited by chrisjchrisj: 04 August 2019 - 01:08 PM

Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3825
  • View blog
  • Posts: 13,933
  • Joined: 08-August 08

Re: Help with modifying script’s array

Posted 04 August 2019 - 05:57 PM

What does PT_LoadPage look like? You need to trace the code to the point where something is going wrong. Try to remember that we're not looking over your shoulder as you work. We can only see the tiny bit of information you provide.
Was This Post Helpful? 0
  • +
  • -

#8 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 04-February 19

Re: Help with modifying script’s array

Posted 05 August 2019 - 10:45 AM

Thanks for your reply.
Regarding what does it look like, it produces what is displayed in the image I had posted.
Regarding "where something is going wrong", as far as I can tell the only thing incorrect is I am not getting what is to the right of =>
in the array list, correct.

I am looking over the code I have originally posted, but can see how I can get: id_user, and user_id_uploaded and id_video to display when a transaction takes place.

Any ideas/suggestions will be appreciated
Was This Post Helpful? 0
  • +
  • -

#9 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3825
  • View blog
  • Posts: 13,933
  • Joined: 08-August 08

Re: Help with modifying script’s array

Posted 05 August 2019 - 06:49 PM

Please show the code in PT_LoadPage.
Was This Post Helpful? 0
  • +
  • -

#10 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 04-February 19

Re: Help with modifying script’s array

Posted 06 August 2019 - 07:38 AM

Thanks for your reply.
I don't know the answer to 'please show the code in PT_LoadPage', so I asked the developer about it and the reply was "it works same as include or require function of PHP its custom constructed function which allows loading files".

If that helps you to help me to substitute what displays on the transaction html page, with the new output, I look forward to any ideas/suggestions.

This post has been edited by chrisjchrisj: 06 August 2019 - 10:52 AM

Was This Post Helpful? 0
  • +
  • -

#11 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 04-February 19

Re: Help with modifying script’s array

Posted 16 August 2019 - 04:31 PM

I have made progress where all columns of the html table populate correctly, except for the PAYER_NAME column:

$ads_list1 = '';

$pt->videos      = $get_videos;

$get_videos = $db->rawQuery("SELECT DISTINCT(v.id), v.*, upv.earned_amount as earned_amount, upv.id_user as id_user, upv.time_date as time_date FROM u_paid_videos AS upv LEFT JOIN " . T_VIDEOS . " AS v ON (upv.id_video = v.id) WHERE upv.id_user = {$user->id} AND upv.time_date ORDER BY upv.id DESC");

$pt->videos      = $get_videos;

if (!empty($get_videos)) {
$len = count($get_videos);
foreach ($get_videos as $key => $video) {
$video = PT_GetVideoByID($video, 0, 0, 0);
$pt->last_video = false; if ($key == $len - 1) { $pt->last_video = true;

}
        $ads_list1 .= PT_LoadPage('transactions/list',array(
            'ID' => $video->id,
                        'PAYER_NAME' => $user->id,
			'VIDEO_NAME' =>  $video->title,
			'AMOUNT' => $video->earned_amount,
			"CURRENCY" => $currency,
			'TIME' => date("Y-m-d h:i A (T)", strtotime($video->time_date))
        ));
    }
}



I'd like the PAYER_NAME data to come from the db table: 'u_paid_videos' > 'id_user' column.

Any ideas, suggestions are appreciated

This post has been edited by chrisjchrisj: 16 August 2019 - 04:38 PM

Was This Post Helpful? 0
  • +
  • -

#12 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2365
  • View blog
  • Posts: 7,219
  • Joined: 15-January 14

Re: Help with modifying script’s array

Posted 16 August 2019 - 04:54 PM

You're getting that value in the query and passing the results to PT_GetVideoByID to return an object, so does that object make that field available somehow?
Was This Post Helpful? 0
  • +
  • -

#13 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 04-February 19

Re: Help with modifying script’s array

Posted 16 August 2019 - 05:10 PM

Much thanks for your reply.

That sounds like a great question but I don't know the answer.

My knowledge regarding sql is on-going, so please let me ask:

You are saying that I am "getting that value", by "that value" do you mean the data that appears in the PAYER_NAME html table column?

I'm not clear on what you mean by "to return an object", or "that field".

Any additional clarification or restatement is welcomed.
Was This Post Helpful? 0
  • +
  • -

#14 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2365
  • View blog
  • Posts: 7,219
  • Joined: 15-January 14

Re: Help with modifying script’s array

Posted 16 August 2019 - 05:41 PM

You are getting the value that you want to use from the database, and you're passing the entire database record to some function which then returns an object. The answer to the question is in the code for that function and the definition of whatever object it's creating.

I'm sure that you're figuring out that it's difficult to do this stuff if you don't understand what you're using, have you gone through any PHP tutorials to try to learn the basics?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1