EGL Group Permissions Add/Manage - php

For those of you that have dealt with EGL (Elite Gaming Ladders) Tournament & Ladders script... I'm having a problem figuring out how to add new group permissions for customized mods I've made. I've created a new type of "General Rules" mod that I would like to store the permission as shown:
case "select_genrules";
if($group['genrules_manager']=="yes"){
include("./includes/rules.php");
select_genrules();
}else{
return warning("<b>" . LANG_WARNING_NO_PERMISSIONS_TO_ACCESS_PAGE . " </b>");
}
break;
where "genrules_manager" formatted the same as all of the others is added to the group_permissions set. I added it to the groups_permissions table and it actually does show in the list of permissions in the ACP under the category "Misc" but I would like to add "Lang" so that it doesn't just say "genrules_manager" etc... Any help as to how to access/modify those keys in the admincp/includes/addmembergroup.php and admincp/includes/managemembergroup.php would be greatly appreciated!

This is actually found in groups.php under the functions addmembergroup and editmembergroup. You will need to add a key that links to the "lang" you have written in admincp/language/english.php like so:
if($key=='genrules_manager'){$descr='' . LANG_GRO_PERMISSIONS_DESCR_GENRULES_MANAGER . ''; $site .= group_radio($key, $value, $descr);}
It has to be done in both functions in order for you to see when adding and editing. Simply place it inline with the keys under whichever category you'd like...

Related

OpenCart - PHP - Check if a product (download) is already purchased

Regarding OpenCart store selling digital downloads.
I am trying to add a script to the product page to warn the customer if that specific product (download) is already purchased and exists in Account>Downloads.
The reason is to avoid customers purchasing the same product twice.
Appreciate your help.
Edit:
I have tried getting the product IDs of all orders by a customer using a SQL query and that works fine externally but inside OpenCart I am facing issues.
A query such as:
SELECT product_id
FROM ocuk_order_product
WHERE order_id IN (
SELECT order_id
FROM ocuk_order
WHERE customer_id = 'xxxx'
)
My main problem is not being sure how to get similar results in OpenCart Product page. (Which pages and path exactly and where inside the files)
Tried this post as well: Opencart get product downloads
But it is not exactly working on product page (product.php)
Opencart Version 3.0.2.0
Ok I'll take a stab at this but let's clarify a few things:
1) DB_PREFIX is simply a php constant that's declared in your config.php file. Based on the query you provided it's probably equal to ocuk. The point is, you write queries using this constant and they become portable across installations regardless of the users' chosen database prefix.
2) Opencart is based on the MCVL (an extension of MVC which includes language files) structure. The place to execute queries is in the model. The place to call model methods is in the controller. The controller passes output to the view and often uses language variables from language files.
So what I would do is write function and put it in your product model – in this case that's catalog/model/catalog/product.php. This function is called a method since it's now part of your model class. The function will output the rows in your table that a logged in customer has purchased the given product. It's also important to check (a) that the customer is logged in and (b) that the orders you are querying against are real orders - with an order_status_id > 0. We can go into that but suffice to say that you always need to check the order_status_id if you want to know about actual completed orders. Such a method could look something like this:
public function getOrderProductHistory($product_id) {
$result = [];
if ($customer_id = $this->customer->getId()) {
$sql = "
SELECT *
FROM " . DB_PREFIX . "order o
JOIN " . DB_PREFIX . "order_product op USING (order_id)
WHERE o.order_status_id > 0
AND o.customer_id = '" . (int)$customer_id . "'
";
$query = $this->db->query($sql);
$result = $query->rows;
}
return $result;
}
Now in your controller (on a product page that's catalog/controller/product/product.php) you can call this method to get results like this:
$order_product_history = $this->model_catalog_product->getOrderProductHistory($product_id);
And then do something based on the output:
if ($order_product_history) {
$data['has_been_ordered'] = true;
} else {
$data['has_been_ordered'] = false;
}
Now $has_been_ordered is a boolean that you can access in your view to display a message to the customer. There's still a bit more code for you to write but hopefully this helps get you off to a good start.

Anyone Added Custom Field in to Task List Show into Dashboard (Phabricator)

I have added due_date into the Manifest Custom Field. Now I want that where ever task list showing to the user then Due Date also displayed over there.
I know its very small change in codebase but I am not able to debug this.
I missed a step you need I think to call $fields->readFieldsFromStoage($task) and then I used $field->getValueForStorage()
I can't say how correct or legal, of even efficient it is, but it does what I think you wanted
$fields = PhabricatorCustomField::getObjectFields(
$task,PhabricatorCustomField::ROLE_VIEW);
if ($fields){
$fields->readFieldsFromStorage($task);
foreach ($fields->getFields() as $field){
if ($field->getModernFieldKey()=='custom.mycustomfield'){
// in theory you might be able to add it like this
$item->addByline(pht('Due Date:%s', $field->getValueForStorage()));
$item->addByline(pht('Assigned: %s', $owner->renderLink()));
}
}
Hope that helps
Ok not a solution, but a place to start...
To alter this you need to edit
ManiphestTaskListView.php in
phabricator/src/applications/maniphest/view
Where you want to put due date is where "Assigned:" is put
if ($task->getOwnerPHID()) {
$owner = $handles[$task->getOwnerPHID()];
$item->addByline(pht('Assigned: %s', $owner->renderLink()));
}
Pulling in the custom fields may require a little more research, I think you can get to the tasks custom fields via the following
$fields = PhabricatorCustomField::getObjectFields(
$task,PhabricatorCustomField::ROLE_VIEW);
You could then pull out the field you want like this if you have to, I suspect there is a better way of doing this...so you just ask for the specific field
if ($fields){
foreach ($fields->getFields() as $field){
if ($field->getModernFieldKey()=='custom.mycustomfield'){
// in theory you might be able to add it like this
$item->addByline(pht('%s', $field->getXXXX()));
}
}
I'm not sure what you need to do to get the custom field value, i'm using getXXXX() to represent the sort of thing you might need to do, I think the custom fields often have a render() method but again I'm not completely sure how you go about getting that to render in your listview

Wordpress custom query

I have a wordpress blog. I created a db table which stores dictionary information and I want to publish this data from a URL . (For ex: "myblogaddress.com/mytest.php")
I have been researching for 2 days but nothing works I tried.
In my page; I use the php code shown in blow.
<?php
global $wpdb;
$words = $wpdb->get_results("SELECT * FROM $wpdb->words")
echo $words[0]->ENG;
?>
I wonder that;
- Which directory does my php page to be into ?
- What I need to do (other config, permission etc.) to do what I want.
Regards.
If you're loading it from a standalone PHP file (ie not from within your WordPress theme), you'll have to call wp-load.php to initialise the WordPress variables (including $wpdb). Have a look at this answer, including the comment about only needing wp-load.php.
I'd consider using a relative path (what that would be would depend on where you put your page relative to WordPress) rather than using $_SERVER['DOCUMENT_ROOT'];, but that's just a personal preference.
EDIT
Rereading after seeing your comment, I've just realised $wpdb->words probably won't exist. Try
$words = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "words")
instead. That'll generate the table name correctly as wp_words. Of course, you'll need to populate it the same way.

Opencart where are extension status and position set?

Quick question about open cart, where are extension status and position set? I can see in the code
$postion = $this->config->get($extension . '_position');
and also
'status' => $this->config->get($extension . '_status')
However I can't see where these are defined?
At first, look into your extension file ( for example 'payment/free_checkout.php') and search for something like that
$this->model_setting_setting->editSetting( 'free_checkout', $this->request->post);
This is where settings stored into database ( you can go deeper into setting model, if you want )
After that, open admin/index.php and look at lines 38 - 48.
You can see, system gets data from database and store data into config object.
In Opencart Positions are used by Modules. They are set in admin unders extensions/modules. When you click save - it saves them to the database table oc_settings under the modulename_module
When Opencart is launched - in INDEX.php there is this code
// Settings
$query = $db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '0' OR store_id = '" . (int)$config->get('config_store_id') . "' ORDER BY store_id ASC");
foreach ($query->rows as $setting) {
if (!$setting['serialized']) {
$config->set($setting['key'], $setting['value']);
} else {
$config->set($setting['key'], unserialize($setting['value']));
}
}
it creates the config - a massive array of all the settings for the current store id.
Afterwards the position controllers (column_left.php, column_right.php, content_top.php and content_bottom.php) go through the extensions in the table oc_extension and finds all the modules that will need to be shown.
then it goes through this massive array CONFIG and collects the settings for these modules - this all is stored in a array $module_data
then the controller uses these settings to basicly launch every controller of the module that should be shown. It passes the controller route and $settings for every module in a foreach loop and in result gets a render of the modules.
You can access the config anywhere in the php file - it can be another controller, a model or even tpl file.
$this->config->get(...)
If you want - you can go directly to the databes oc_settings and get the data from there with these functions
$this->load->model('setting/setting'); // remeber to always load the model.
$this->model_setting_setting->editSetting( 'free_checkout', $this->request->post);
Hope this helps.
Also you can use this module to expend the number of positions for your opencart SUPER easy
Extra positions Unlimited

Drupal 6 - Content profile fields within page-user.tpl.php

Going a bit mad here... :)
I'm just trying to add CCK fields from a Content Profile content type into page-user.tpl.php (I'm creating a highly-themed user profile page).
There seem to be two methods, both of which have a unique disadvantage that I can't seem to overcome:
'$content profile' method.
$var = $content_profile->get_variables('profile');
print $var['field_last_name'][0]['safe'];
This is great, except I can't seem to pass the currently viewed user into $content_profile, and it therefore always shows the logged in user.
'$content profile load' method.
$account_id = arg(1);
$account = user_load($account_id);
$user_id = $account->uid;
$var = content_profile_load('profile', $user_id);
print $var->field_first_name[0]['value'];
Fine, but now I can't access the full rendered fields, only the plain values (i.e. if the field has paragraphs they won't show up).
How can I have both things at once? In other words how can I show fields relating to the currently viewed user that are also rendered (the 'safe' format in 1)?
I've Googled and Googled and I just end up going round in circles. :(
Cheers,
James
Your content profile load method seems to be the closest to what you want.
In your example:
$account_id = arg(1);
$account = user_load($account_id);
$user_id = $account->uid;
$var = content_profile_load('profile', $user_id);
print $var->field_first_name[0]['value'];
The $var is just a node object. You can get the "full rendered fields" in a number of ways (assuming you mean your field with a filter applied).
The most important thing to check is that you're field is actually configured properly.
Go to:
admin/content/node-type/[node-type]/fields/field_[field-name] to configure your field and make sure that under text processing that you've got "Filtered text" selected.
If that doesn't fix it,try applying this:
content_view_field(content_fields("field_last_name"), $var, FALSE, FALSE)
(more info on this here: http://www.trevorsimonton.com/blog/cck-field-render-node-formatter-format-output-print-echo )
in place of this:
print $var->field_first_name[0]['value'];
if none of that helps... try out some of the things i've got on my blog about this very problem:
http://www.trevorsimonton.com/blog/print-filtered-text-body-input-format-text-processing-node-template-field-php-drupal
When you're creating a user profile page there is a built in mechanism for it. just create a user template file, user_profile.tpl.php.
When you use the built in mechanism you automatically get access to the $account object of the user you are browsing, including all user profile cck fields. You have the fields you are looking for without having to programmatically load the user.
I have a field called profile_bio and am able to spit out any mark up that is in without ever having to ask for the $account.
<?php if ($account->content[Profile][profile_bio]['#value']) print "<h3>Bio</h3>".$account->content[Profile][profile_bio]['#value']; ?>
I've tried themeing content profiles by displaying profile node fields through the userpage before and it always seems a little "hacky" to me. What I've grown quite fond of is simply going to the content profile settings page for that node type and setting the display to "Display the full content". This is fine and dandy except for the stupid markup like the node type name that content profile injects.
a solution for that is to add a preprocess function for the content profile template. one that will unset the $title and remove the node-type name that appears on the profile normally.
function mymodule_preprocess_content_profile_display_view(&$variables) {
if ($variables['type'] == 'nodetypename') {
unset($variables['title']);
}
}
A function similar to this should do the trick. Now to theme user profiles you can simply theme your profile nodes as normal.

Categories