Admin setting a minimum price

Thanks for your reply.

Just to clarify, yes, if the Admin changed the amount in the minimum price field in the admin panel, it would change the min price for all. Yet, currently all Users, after their upload, can change the minimum price, in their videos > edit area.

I’m wondering if the code can be modified so that a particular User (named ‘Admin’ for example) can have the option to price an upload below the set minimum price, at 0, for example.

Any thoughts, comments, suggestions are appreciated

I need more info.

So you want to allow users to change the price below the minimum, or only a certain user/ user group?

then just present the admin with an input field and apply the necessary update statements via SQL.

Thanks for the replies.
“only a certain user” yes

Also, I don’t understand this: “present the admin with an input field and apply the necessary update statements via SQL”, any additional info is appreciated

input field: <input type="number" name="amount" />
SQL: UPDATE whateveryouwant set amount = ? and execute the prepared statement

Thanks for your reply.
The existing script has an edit video page that all Users’ use to edit their price of their video:

 <div class="form-group">
  <label class="col-md-12" for="cost">{{LANG up_video_price}}</label>
    	 <div class="col-md-12">
    	<input id="cost" input type="number" name="video_play_price" class="form-control input-md" value="{{video_play_price_user}}">
    				</div>
    				</div>

I am trying to modify the script so that the admin can price his uploads at below minimum price if he chooses.

Any additional help is appreciated

Your code should be general purpose and should not have hard-coded logic in it based on specific user name(s). The ability to override the price should be based on granting/giving that specific permission (price override) to specific user(s) or user groups.

See the following general purpose example -

// if you don't already have a user permission system, use defined constants for a simple permission system
define('PRICE_OVERRIDE_PERMISSION',1);


$set_price = 10.75; // retrieve the set price for a video from wherever it is stored
$global_min_price = 15.50; // retrieve the global minimum price from wherever it is stored
$user_permissions = [PRICE_OVERRIDE_PERMISSION]; // retrieve the user permissions from wherever they are stored
// $user_permissions = []; // a user that has no extra permissions = an empty array


// at the point of determining the price, for display or for use by the application code -
if(!in_array(PRICE_OVERRIDE_PERMISSION,$user_permissions))
{
	// user is not able to override the price, get the larger of the two prices
	$price = max($set_price,$global_min_price);
} else {
	// user is able to override the price, get the set price
	$price = $set_price;
}

echo number_format($price,2);
1 Like

Much thanks for your reply.
Yes, I agree with your logic. Although I understand it is a general purpose example, and I have to figure out how to incorporate that into the existing script, maybe you can guide me as to which php file it should be added to, the ajax/edit.php file?:

<?php
if (IS_LOGGED == false) {
    $data = array('status' => 400, 'error' => 'Not logged in');
    echo json_encode($data);
    exit();
}


if (empty($_POST['title']) || empty($_POST['description']) || empty($_POST['tags']) || empty($_POST['video-id'])) {
    $error = $lang->please_check_details;
}

if (($pt->config->sell_videos_system == 'on' && $pt->config->who_sell == 'pro_users' && $pt->user->is_pro) || ($pt->config->sell_videos_system == 'on' && $pt->config->who_sell == 'users') || ($pt->config->sell_videos_system == 'on' && $pt->user->admin)) {
    if (!empty($_POST['set_p_v']) || $_POST['set_p_v'] < 0) {
        if (!is_numeric($_POST['set_p_v']) || $_POST['set_p_v'] < 0 || (($pt->config->com_type == 0 && $_POST['set_p_v'] <= $pt->config->admin_com_sell_videos)) ) {
            $error = $lang->video_price_error." ".($pt->config->com_type == 0 ? $pt->config->admin_com_sell_videos : 0);
        }
    }
}

if (PT_IsAdmin()) {
	if (!empty($_POST['assign_to_user'])) {
		$id = PT_Secure($_POST['video-id']);
		$username_ = PT_Secure($_POST['assign_to_user']);
		$user_  = $db->where('username', $username_)->getOne(T_USERS);
		if (!empty($user_)) {
			$db->where('id', $id)->update(T_VIDEOS, array('user_id' => $user_->id));
		}
		else{
			$error = $lang->user_not_exists;
		}
	}
}

if (empty($error)) {
    $id = PT_Secure($_POST['video-id']);
    $video = $db->where('id', $id)->getOne(T_VIDEOS);
    $can_update = false;
    if (PT_IsAdmin() == false) {
    	if ($db->where('user_id', $user->id)->where('id', $id)->getValue(T_VIDEOS, 'count(*)') > 0) {
    		$can_update = true;
    	}
    } else {
    	$can_update = true;
    }
    if (!empty($_POST['set_p_v']) && $video->sell_video == 0) {
    	$can_update = false;
    }
    if ($can_update == true && !empty($video)) {
    	$video = PT_GetVideoByID($video, 0, 0, 0);
    	$thumbnail = $video->org_thumbnail;
    	if (!empty($_FILES['thumbnail']['tmp_name'])) {
	        $file_info   = array(
	            'file' => $_FILES['thumbnail']['tmp_name'],
	            'size' => $_FILES['thumbnail']['size'],
	            'name' => $_FILES['thumbnail']['name'],
	            'type' => $_FILES['thumbnail']['type'],
	            'allowed' => 'jpg,png,jpeg,gif',
	            'crop' => array(
	                'width' => 1076,
	                'height' => 604
	            )
	        );
	        $file_upload = PT_ShareFile($file_info);
	        if (!empty($file_upload['filename'])) {
	            $thumbnail = PT_Secure($file_upload['filename']);
	        }
	    }
	    $category_id = 0;
	    if (!empty($_POST['category_id'])) {
	        if (in_array($_POST['category_id'], array_keys(get_object_vars($pt->categories)))) {
	            $category_id = PT_Secure($_POST['category_id']);
	        }
	    }
	    $link_regex = '/(http\:\/\/|https\:\/\/|www\.)([^\ ]+)/i';
	    $i          = 0;
	    preg_match_all($link_regex, PT_Secure($_POST['description']), $matches);
	    foreach ($matches[0] as $match) {
	        $match_url           = strip_tags($match);
	        $syntax              = '[a]' . urlencode($match_url) . '[/a]';
	        $_POST['description'] = str_replace($match, $syntax, $_POST['description']);
	    }
	    $featured = $video->featured;
	    if (isset($_POST['featured']) && PT_IsAdmin()) {
	    	$featured = PT_Secure($_POST['featured']);
	    }
	    $video_privacy = 0;
	    if (!empty($_POST['privacy'])) {
	        if (in_array($_POST['privacy'], array(0, 1, 2))) {
	            $video_privacy = PT_Secure($_POST['privacy']);
	        }
	    }
	    $age_restriction = 1;
        if (!empty($_POST['age_restriction'])) {
            if (in_array($_POST['age_restriction'], array(1, 2))) {
                $age_restriction = PT_Secure($_POST['age_restriction']);
            }
        }
        $sub_category = 0;

	    if (!empty($_POST['sub_category_id'])) {
	        $is_found = $db->where('type',PT_Secure($_POST['category_id']))->where('lang_key',PT_Secure($_POST['sub_category_id']))->getValue(T_LANGS,'COUNT(*)');
	        if ($is_found > 0) {
	            $sub_category = PT_Secure($_POST['sub_category_id']);
	        }
	    }
	    $continents_list = array();
	    if (!empty($_POST['continents-list'])) {
	        foreach ($_POST['continents-list'] as $key => $value) {
	            if (in_array($value, $pt->continents)) {
	                $continents_list[] = $value;
	            }
	        }
	    }

	    $video_play_price = floatval(PT_Secure($_POST['video_play_price']));
		if ( $video_play_price < $config['video_play_price'] ) {
 	$video_play_price = $config['video_play_price'];
	}

	    $data_update = array(
	        'title' => PT_Secure($_POST['title']),
	        'description' => PT_Secure($_POST['description']),
	        'tags' => PT_Secure($_POST['tags']),
	        'category_id' => $category_id,
	        'featured' => $featured,
	        'thumbnail' => $thumbnail,
	        'privacy' => $video_privacy,
	        'age_restriction' => $age_restriction,
	        'sub_category' => $sub_category,
	        'geo_blocking' => json_encode($continents_list),
	        'video_play_price' => $video_play_price,
	    );
	    if (!empty($_POST['set_p_v']) && is_numeric($_POST['set_p_v']) && $_POST['set_p_v'] > 0) {
            $data_update['sell_video'] = PT_Secure($_POST['set_p_v']);
        }
	    $update  = $db->where('id', $id)->update(T_VIDEOS, $data_update);

	    if ($update) {
	        $data = array(
	            'status' => 200,
	            'message' => $success_icon . $lang->video_saved
	        );
	    }
    }
} else {
    $data = array(
        'status' => 400,
        'message' => $error_icon . $error
    );
}
?>

or the sources/edit.php file?:

<?php
if (IS_LOGGED == false) {
    header("Location: " . PT_Link('login'));
    exit();
}
if (empty($_GET['id'])) {
    header("Location: " . PT_Link('login'));
    exit();
}
$id    = PT_Secure($_GET['id']);
$video = $db->where('id', $id)->getOne(T_VIDEOS);
if (empty($video)) {
    header("Location: " . PT_Link('login'));
    exit();
}
if (!PT_IsAdmin()) {
    if (empty($db->where('id', $id)->where('user_id', $user->id)->getValue(T_VIDEOS, 'count(*)'))) {
        header("Location: " . PT_Link('login'));
        exit();
    }
}
$video           = PT_GetVideoByID($video, 0, 0, 0);
$pt->video       = $video;
$pt->page        = 'edit-video';
$pt->title       = $lang->edit_video . ' | ' . $pt->config->title;
$pt->description = $pt->config->description;
$pt->keyword     = $pt->config->keyword;


$min_price=$config[‘video_play_price’];
$temp_price = $videos[‘video_play_price’];
if ($temp_price<$min_price) { $temp_price = $min_price;}


$pt->content     = PT_LoadPage('edit-video/content', array(
    'ID' => $video->id,
    'USER_DATA' => $video->owner,
    'THUMBNAIL' => $video->thumbnail,
    'URL' => $video->url,
    'TITLE' => $video->title,
    'DESC' => br2nl($video->edit_description),
    'DESC_2' => $video->markup_description,
    'VIEWS' => $video->views,
    'TIME' => $video->time_ago,
    'TAGS' => $video->tags,
	'video_play_price_user' => number_format( $video->video_play_price < $config['video_play_price'] ? $config['video_play_price'] : $video->video_play_price)
));

Any additional assistance is appreciated

Seems that would give the permissions, depending on how granular you are going.

Thanks for your reply.
However, I don’t understand what you’re saying. Can you give me an example pertaining to my goal, please?
Any additional assistance is welcomed.

this statement doesn’t make sense at all. Phdr is a master programmer and it is very nice that you have example code with comments. Astonecipher is also a master programmer. You have all the ammo you need to solve your problems. Not to be rude but you should take some time to review the help in this thread and try to understand the code. It’s not everyday that you get working examples in forums.

Thank you for your message.
I have looked at the code, but I am still not sure which of those files that it should be integrated with

what? i don’t know what is going on here.
you place the code where you check permissions and set the price.
what is PT_IsAdmin() doing? checking for permissions?

Thanks for your reply.
I don’t know, I didn’t write this script, I’m just trying to get help to modify it.
“what is PT_IsAdmin() doing”? I don’t know. I’m not sure what PT_IsAdmin() is for.
Can you tell me?
“checking for permissions”? I don’t know, can you tell me?

regarding " place the code where you check permissions and set the price". Is this where the price is being set?:

min_price=$config[‘video_play_price’]; $temp_price = $videos[‘video_play_price’]; if ($temp_price&lt;$min_price) { $temp_price = $min_price;}

I look forward to any additional guidance

why not trying to understand the code first? use a debugger like XDEBUG, you will learn a lot from that.

Thanks for your reply, however I’d prefer to get code assistance on line for this modification, rather download more software.
Any additional help is welcomed

if you take your time and follow the flow of the program, then you should be able to answer your own questions. for one thing, the following code is processing input:

$video_play_price = floatval(PT_Secure($_POST['video_play_price'])); if ( $video_play_price < $config['video_play_price'] ) { $video_play_price = $config['video_play_price']; }

price of video = price of video posted
if that posted price is less than the set price in config then set price to config price.
does this sound like the correct place to set a price?
read the code and follow the flow of the application.

on the other hand, the following code seems to be setting a price.

$min_price=$config[‘video_play_price’];
$temp_price = $videos[‘video_play_price’];
if ($temp_price<$min_price) { $temp_price = $min_price;}

now let’s reaxmine the previous code:

if ( $video_play_price < $config['video_play_price'] )
$min_price=$config[‘video_play_price’];
$temp_price = $videos[‘video_play_price’];
if ($temp_price<$min_price) { $temp_price = $min_price;}

so it seems like config holds a price that is used in comparison to a posted price. thus, the place that is controlling the price is … drumroll …

the place where config is set. it is important for you to understand this code since you are the one trying to use it in a commerce environment. Try harder for your own sake. Also, the code offered by Phdr is superb and i recommend that you implement this code. But you need to read the comments. Such as:

// at the point of determining the price, for display or for use by the application code

Much thanks for taking the time to lay that out.
Do you mean something like this:

define('PRICE_OVERRIDE_PERMISSION',1);

$min_price=$config[‘video_play_price’];

if(!in_array(PRICE_OVERRIDE_PERMISSION,$user_permissions))
{
	$price = max($temp_price,$min_price);
} else {
	$video_play_price = $set_price;
}

$temp_price = $videos[‘video_play_price’];
if ($temp_price<$min_price) { $temp_price = $min_price;}

$user_permissions = [PRICE_OVERRIDE_PERMISSION];
Sponsor our Newsletter | Privacy Policy | Terms of Service