Displaying videos on the 'purchase' page

#1

In the web video script that I’m using, it has been modified(improved) so that purchases are made via a new ‘paid-list’ php file, essentially by-passing the script’s original pay system. Yet, the script currently has a Users’ purchases page, which remains blank, although the improved script works successfully (just no User purchase page info).
I’m seeking assistance with modifying the new ‘paid-list’ php file so that purchases appear on the script’s original Users’ purchases page. The new ‘paid-list’ php file displays the purchased videos for viewing, but I’d like what was purchased by the User to also appear on his purchases page, so he has a history of what he has purchased.

The new ‘paid-list’ php file code is this:

<?php

if (IS_LOGGED == false) {
    header("Location: " . PT_Link('login'));
    exit();
}
$user_id               = $user->id;
$pt->is_admin          = PT_IsAdmin();
$pt->is_settings_admin = false;


$list = '<div class="text-center no-content-found empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-video-off"><path d="M16 16v1a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2m5.66 0H14a2 2 0 0 1 2 2v3.34l1 1L23 7v10"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg>' . $lang->no_videos_found_for_now . '</div>';
$list2 = '<div class="text-center no-content-found empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-video-off"><path d="M16 16v1a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2m5.66 0H14a2 2 0 0 1 2 2v3.34l1 1L23 7v10"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg></div>';
$final = '';


$get_videos = $db->rawQuery("SELECT DISTINCT(v.id), v.* 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.session_key = '{$_SESSION['session_key']}' ORDER BY upv.id DESC");


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;
        }

        $final .= PT_LoadPage('paid-list/list', array(
            'ID' => $video->id,
            'USER_DATA' => $video->owner,
            'THUMBNAIL' => $video->thumbnail,
            'URL' => $video->url,
            'TITLE' => $video->title,
            'DESC' => $video->markup_description,
            'VIEWS' => $video->views,
            'VIEWS_NUM' => number_format($video->views),
            'TIME' => $video->time_ago,
            'DURATION' => $video->duration
        ));

    }
}
if (empty($final)) {
	$final = $list;
}

$pt->videos      = $get_videos;
$pt->page        = 'paid-list';
$pt->title       = $lang->search . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = $pt->config->keyword;
$pt->content     = PT_LoadPage('paid-list/content', array(
    'VIDEOS' => $final,
    'KEYWORD' => $keyword
));

and the original ‘paid-videos’ file (that works generates the Users’ purchase page) is this:

<?php

if (IS_LOGGED == false || $pt->config->sell_videos_system == 'off' ) {
    header("Location: " . PT_Link('login'));
    exit();
}

$list = '<div class="text-center no-content-found empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-video-off"><path d="M16 16v1a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2m5.66 0H14a2 2 0 0 1 2 2v3.34l1 1L23 7v10"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg>' . $lang->no_videos_found_paid . '</div>';
$final = '';
$type = 'videos';
if (!empty($_GET['type']) && $_GET['type'] == 'movies' && $pt->config->movies_videos == 'on') {
    $get = $db->rawQuery('SELECT * FROM '.T_VIDEOS_TRSNS.' t WHERE `paid_id` = '.$user->id.' AND (SELECT id FROM '.T_VIDEOS.' WHERE id = t.video_id AND `is_movie` = 1) = video_id ORDER BY id DESC LIMIT 20');
    $type = 'movies';

}
else{
    $get = $db->rawQuery('SELECT * FROM '.T_VIDEOS_TRSNS.' t WHERE `paid_id` = '.$user->id.' AND (SELECT id FROM '.T_VIDEOS.' WHERE id = t.video_id AND `is_movie` != 1) = video_id ORDER BY id DESC LIMIT 20');
   //$get = $db->where('paid_id', $user->id)->orderby('id', 'DESC')->get(T_VIDEOS_TRSNS, 20); 
}
$get_paid_videos = array();
if (!empty($get)) {
    foreach ($get as $key => $video_) {
       $fetched_video = $db->where('id', $video_->video_id)->getOne(T_VIDEOS);
       if (!empty($fetched_video)) {
           $fetched_video->tr_id = $video_->id;
           $get_paid_videos[] = $fetched_video;
       }
    }
}
if (!empty($get_paid_videos)) {
    $len = count($get_paid_videos);
    foreach ($get_paid_videos as $key => $video) {
        $video = PT_GetVideoByID($video, 0, 0, 0);
        $pt->last_video = false;
        if ($key == $len - 1) {
            $pt->last_video = true;
        }
        $final .= PT_LoadPage('paid-videos/list', array(
            'ID' => $video->tr_id,
            'USER_DATA' => $video->owner,
            'THUMBNAIL' => $video->thumbnail,
            'URL' => $video->url,
            'TITLE' => $video->title,
            'DESC' => $video->markup_description,
            'VIEWS' => $video->views,
            'TIME' => $video->time_ago,
            'VIDEO_ID_' => PT_Slug($video->title, $video->video_id)
        ));
    }
}
if (empty($final)) {
	$final = $list;
}
$pt->page_url_ = $pt->config->site_url.'/paid-videos?type='.$type;
$pt->videos      = $get_paid_videos;
$pt->page        = 'paid-videos';
$pt->title       = $lang->paid_videos . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = $pt->config->keyword;
$pt->content     = PT_LoadPage('paid-videos/content', array(
    'PAID_LIST' => $final
));

would copying/adding this part:


        $final .= PT_LoadPage('paid-videos/list', array(
            'ID' => $video->tr_id,
            'USER_DATA' => $video->owner,
            'THUMBNAIL' => $video->thumbnail,
            'URL' => $video->url,
            'TITLE' => $video->title,
            'DESC' => $video->markup_description,
            'VIEWS' => $video->views,
            'TIME' => $video->time_ago,
            'VIDEO_ID_' => PT_Slug($video->title, $video->video_id)
        ));
    }
}
if (empty($final)) {
	$final = $list;
}
$pt->page_url_ = $pt->config->site_url.'/paid-videos?type='.$type;
$pt->videos      = $get_paid_videos;
$pt->page        = 'paid-videos';
$pt->title       = $lang->paid_videos . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = $pt->config->keyword;
$pt->content     = PT_LoadPage('paid-videos/content', array(
    'PAID_LIST' => $final
));

over to the new ‘paid-list’ file, be a good start in reaching my goal of having current purchases appear at site_url.’/paid-videos page?

I look forward any assistance.

#2

just rewrite the new page to use the new system.

#3

Thanks for your reply.
I am sure you’re correct regarding modifying the page/file, but as I asked, I’m wondering if that modification just needs the code I asked about.

Any additional, more specific help would be appreciated

#4

Not on its own, because that is just adding data into the page as far as I can see. You’d have to have the (or a ) query before it, to actually generate that data.

Back to basics. What table does your new “paid list” file use, and what table does the “original users purchases page” access? You would accept that the two need to be the same. Your “paid-list” code seems to be looking in u_paid_videos, but your “original paid-videos” file looks in T_VIDEOS_TRSNS, which seems to be a constant that will be defined somewhere.

#5

Thanks for your reply. Yes you are correct about the tables. Can you please give me an example of what you mean by the (or a) query?
I look forward to any additional assistance

#6

The query is in the code you posted as “paid-videos”. It isn’t in the section of code you were asking about adding in to the other page. It starts in the line that includes the function rawQuery.

#7

Thanks for your reply/assistance.

Based on that, I have added this at the very bottom of paid-list.php code, but it just got a white page upon processing a purchase:

$get = $db->rawQuery('SELECT * FROM '.T_U_PAID_VIDEOS.' t WHERE `id` = '.$user->id.' AND (SELECT id FROM '.T_VIDEOS.' WHERE id = t.id_video AND `is_movie` != 1) = id_video ORDER BY id DESC LIMIT 20');

$get_paid_videos = array();
if (!empty($get)) {
    foreach ($get as $key => $video_) {
       $fetched_video = $db->where('id', $video_->id_video)->getOne(T_VIDEOS);
       if (!empty($fetched_video)) {
           $fetched_video->tr_id = $video_->id;
           $get_paid_videos[] = $fetched_video;
       }
    }
}
if (!empty($get_paid_videos)) {
    $len = count($get_paid_videos);
    foreach ($get_paid_videos as $key => $video) {
        $video = PT_GetVideoByID($video, 0, 0, 0);
        $pt->last_video = false;
        if ($key == $len - 1) {
            $pt->last_video = true;
        }
        $final .= PT_LoadPage('paid-videos/list', array(
            'ID' => $video->tr_id,
            'USER_DATA' => $video->owner,
            'THUMBNAIL' => $video->thumbnail,
            'URL' => $video->url,
            'TITLE' => $video->title,
            'DESC' => $video->markup_description,
            'VIEWS' => $video->views,
            'TIME' => $video->time_ago,
            'VIDEO_ID_' => PT_Slug($video->title, $video->id_video)
        ));
    }
}
if (empty($final)) {
	$final = $list;
}
$pt->page_url_ = $pt->config->site_url.'/paid-videos?type='.$type;
$pt->videos      = $get_paid_videos;
$pt->page        = 'paid-videos';
$pt->title       = $lang->paid_videos . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = $pt->config->keyword;
$pt->content     = PT_LoadPage('paid-videos/content', array(
    'PAID_LIST' => $final
));

any additional guidance is welcomed

#8

If you expect any output that doesn’t show up, have look in the error log of your hoster.

#9

Are all the values for stuff like T_U_PAID_VIDEOS and T_VIDEOS defined somewhere?

What does the PT_LoadPage() function do?

#10

Thanks for your reply.

Regarding this from the script’s original ‘paid-videos’ file, I not sure all of what that line is requesting, can you shed light on that?:

$get = $db->rawQuery('SELECT * FROM '.T_VIDEOS_TRSNS.' t WHEREpaid_id= '.$user->id.' AND (SELECT id FROM '.T_VIDEOS.' WHERE id = t.video_id ANDis_movie!= 1) = video_id ORDER BY id DESC LIMIT 20');

I tried this,

$get = $db->rawQuery('SELECT * FROM u_paid_videos WHEREid= '.$user->id_user.' AND (SELECT id FROM '.T_VIDEOS.' WHERE id = id_video ANDis_movie!= 1) = id_video ORDER BY id DESC LIMIT 20');

the first is referencing the video transactions table(T_VIDEOS_TRSNS) which I changed to the modified/replaced script’s tansactions table: u_paid_videos.

Their ‘paid_id’ is just ‘id’ in ‘u_paid_videos’ table. T_VIDEOS is the table where all videos are stored. They have ‘video_id’. The u_paid_videos table has ‘id_video’. Based on that do you think my changes are correct?

Regarding PT_LoadPage() function, I believe it generates the data that appears on the Users’ purchases html page. Which, as I stated earlier is currently blank.

Any additional guidance is appreciated

#11

Looking at the query, it’s retrieving everything from the T_VIDEOS_TRSNS table for the specified user-id, as long as the value of is_movie in the T_VIDEOS table is not equal to 1, sorting it by id and only returning 20 rows.

And what happened? Do the various column names work properly for that query? Does it work in phpmyadmin if you put values in for the user-id?

First thing must be to make sure the query is returning data. If it’s giving a blank page, that signifies something is just stopping somewhere, so you could perhaps enable error reporting or, as @chorn said above, look at the server error logs.

#12

Thanks for your replies.

My latest attempt at integrating the files(below) proceeds as normal(successfully), but accomplish my goal of populating the paid-videos html page:

<?php

if (IS_LOGGED == false) {
    header("Location: " . PT_Link('login'));
    exit();
}
$user_id               = $user->id;
$pt->is_admin          = PT_IsAdmin();
$pt->is_settings_admin = false;


$list = '<div class="text-center no-content-found empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-video-off"><path d="M16 16v1a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2m5.66 0H14a2 2 0 0 1 2 2v3.34l1 1L23 7v10"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg>' . $lang->no_videos_found_for_now . '</div>';
$list2 = '<div class="text-center no-content-found empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-video-off"><path d="M16 16v1a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2m5.66 0H14a2 2 0 0 1 2 2v3.34l1 1L23 7v10"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg></div>';
$final = '';


$get_videos = $db->rawQuery("SELECT DISTINCT(v.id), v.* 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.session_key = '{$_SESSION['session_key']}' ORDER BY upv.id DESC");

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;
        }

        $final .= PT_LoadPage('paid-list/list', array(
            'ID' => $video->id,
            'USER_DATA' => $video->owner,
            'THUMBNAIL' => $video->thumbnail,
            'URL' => $video->url,
            'TITLE' => $video->title,
            'DESC' => $video->markup_description,
            'VIEWS' => $video->views,
            'VIEWS_NUM' => number_format($video->views),
            'TIME' => $video->time_ago,
            'DURATION' => $video->duration
        ));

    }
}
if (empty($final)) {
	$final = $list;
}

$pt->videos      = $get_videos;
$pt->page        = 'paid-list';
$pt->title       = $lang->search . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = $pt->config->keyword;
$pt->content     = PT_LoadPage('paid-list/content', array(
    'VIDEOS' => $final,
    'KEYWORD' => $keyword
));




$get_videos = $db->rawQuery("SELECT DISTINCT(v.id), v.* 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.session_key = '{$_SESSION['session_key']}' ORDER BY upv.id DESC");

$get_videos = array();
if (!empty($get)) {
    foreach ($get as $key => $video_) {
       $fetched_video = $db->where('id', $video_->id_video)->getOne(T_VIDEOS);
       if (!empty($fetched_video)) {
           $fetched_video->tr_id = $video_->id;
           $get_videos[] = $fetched_video;
       }
    }
}

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;
        }


$final .= PT_LoadPage('paid-videos/list', array(
            'ID' => $video->tr_id,
            'USER_DATA' => $video->owner,
            'THUMBNAIL' => $video->thumbnail,
            'URL' => $video->url,
            'TITLE' => $video->title,
            'DESC' => $video->markup_description,
            'VIEWS' => $video->views,
            'TIME' => $video->time_ago,
            'VIDEO_ID_' => PT_Slug($video->title, $video->video_id)
        ));
    }
}
if (empty($final)) {
	$final = $list;
}
$pt->page_url_ = $pt->config->site_url.'/paid-videos?type='.$type;
$pt->videos      = $get_paid_videos;
$pt->page        = 'paid-videos';
$pt->title       = $lang->paid_videos . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = $pt->config->keyword;
$pt->content     = PT_LoadPage('paid-videos/content', array(
    'PAID_LIST' => $final
));

here is the paid-video html page code:

<div class="content">
	<div class="col-md-12">
		<div class="upload-head">
			<h4 class="page_head"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-dollar-sign"><line x1="12" y1="1" x2="12" y2="23"></line><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"></path></svg> {{LANG purchased}}</h4>
			<ul class="list-unstyled vid_stud_links">
				<li <?php echo empty($_GET['type']) || $_GET['type'] != 'movies' ? 'class="active"' : ''; ?>>
					<a href="{{LINK paid-videos?type=videos}}" data-load="?link1=paid-videos&type=videos"><svg class="feather feather-video" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polygon points="23 7 16 12 23 17 23 7"></polygon><rect x="1" y="5" width="15" height="14" rx="2" ry="2"></rect></svg> {{LANG videos}}</a>
				</li>
				<?php if ($pt->config->movies_videos == 'on') { ?>
				<li <?php echo !empty($_GET['type']) && $_GET['type'] == 'movies' ? 'class="active"' : ''; ?>>
					<a href="{{LINK paid-videos?type=movies}}" data-load="?link1=paid-videos&type=movies"><svg class="feather feather-film" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2" y="2" width="20" height="20" rx="2.18" ry="2.18"></rect><line x1="7" y1="2" x2="7" y2="22"></line><line x1="17" y1="2" x2="17" y2="22"></line><line x1="2" y1="12" x2="22" y2="12"></line><line x1="2" y1="7" x2="7" y2="7"></line><line x1="2" y1="17" x2="7" y2="17"></line><line x1="17" y1="17" x2="22" y2="17"></line><line x1="17" y1="7" x2="22" y2="7"></line></svg> {{LANG movies}}</a>
				</li>
				<?php } ?>
			</ul>
			<div class="clear"></div>
			<hr>
		</div>
      	<div class="videos-latest-list row">
      		{{PAID_LIST}}
      	</div>
      	<?php if (count($pt->videos) > 0) { ?>
            <div class="watch-video-show-more desc load-more" data-type="paid_videos">
                {{LANG show_more}}
            </div>
      	<?php } ?>
		<div class="clear"></div>
	</div>
	<div class="clear"></div>
</div>

any additional guidance is welcomed