Passing value to Joomla Module from another URL - php

I'm newbie to Joomla module development, and would like to implement a custom module for Joomla CMS.
I need to display the sales history of the logged in user. For example, a user with [username] = "US001" logged in successfully, and go to view what sales orders have done by him. And the module display the data recordset in table format by passing the "US001" as username parameter to my database and retrieve the data.
How do I detect the user logged in and then remember the [username] for the whole session?
How can I pass this [username] parameter, e.g. "US001" to my external URL for retrieving data record set? My database for every user's sales history is in another different IP's server.
After query the data, how to return back my dataset to the module and draw my table out on that module?
Additional function would be Admin's user able to control which field to be display, eg. 'age', 'e-mail', etc on the table in module.

You want to access the user object. Joomla already has most of what you need built in, you just pull up the current user and you have the info.
To start with, you will need to get the current user info -
`$user =& JFactory::getUser();`
if ($user->guest) will tell you if the user is logged in, $user->name will give you the username
You will have to pass any info from Joomla to the external URL using either GET or POST. Easiest way is to pass it as part of the URL query string (GET) external.url.com/database-page.html?username=name; ?> or similar
Again, GET or POST the values you want to use back to the page containing your module.
Not sure what you mean here, but it sounds like you need to add parameters (called form fields in 1.6 and newer) to your module so you can turn on or off the display of some of the data the module will be getting.
User object tutorial - http://docs.joomla.org/Accessing_the_current_user_object
Parameters - http://docs.joomla.org/Standard_parameter_types
Form fields - http://docs.joomla.org/Form_field
Lastly, it sounds like you would be better served creating a component instead of a module, unless you plan to display the database info you are pulling as part of another page that will be displaying the main content.

Related

What kind of plugin should I use to make a whole page for one user only?

I try to make a website with multiple users of the same role on Wordpress. That may be "Informational system of hotel rooms". Every user should have an access to login page and the page for registration. But after the process of logging in the user should get own private page. In this page the subscriber should get the opportunity to review and edit the database table. But there's no exception of the fact that despite the whole list of database tables is the same by own quantity and structure of each of them, the data stored in those tables should be unique.
The uniqueness of data witnesses that I need to create a private page for every user, save for administrator. It must be private page, not post, because I'll use php snippet and html code for displaying the table with unique data.
So the question is: What kind of plugin should I use to make a whole page for one user only?

How to pass lot of collection and custom data to another route in laravel

Based on user input value, I am calculating product price and price breakdown dynamically and showing the price to the user.
How can I pass an entire collection and breakdown to the next page (like a checkout page).
I can JSON encode whole collection and kept inside a form and passing by post request. In this case user might manipulate using browser developer tool.
What could be alternative way to pass big data to another route (checkout route) in laravel. I am logically stuck.
You can achieve this by using session or local storage also
Solution Explanation:
Session Storage: store the data in session with user id and get it in next page and if you work is done then clearing the session.
Store the data in local storage and retrieve in next page then clear the storage.
It is not a good practice to pass entire collection between the pages.
Let's say, you have a person stored with id as 1 in your database. Person has lot of other detail also stored like name, email, job etc etc
If passing data is concerned, you first fetch data of that person from database, pass to the next page and then via post get the same data back to you.
Whereas, just the id having value 1 is more than enough to identify that it is that person and you can get those detail back again.
Considering e-commerce and checkout page, when items are added in cart, it's a cart quote. The items are not checked out yet. So you can create a cart_quotes table to store that data and then just pass the id of quotation to the next page instead of entire details like products added to cart, discounts etc etc.
The next question comes : id can also be manipulated from the url? The answer is, laravel has signed urls using which you can avoid url tampering.
Last but something I would recommend, if you are building an e-commerce in laravel, there are already packages available which does everything for you. Check :
- [vanilo](https://vanilo.io/)
- [aimeos](https://aimeos.org/laravel-ecommerce-package/)
- [bagisto](https://bagisto.com/en/)

See who is on the same page in CodeIgniter

I am using CodeIgniter and I connect to a remote database. Only people who are in the table "users" are allowed to log in through session. Some of the tables in the DB can be edited on the site and a form sends the info to the Model (which then updates the info to the DB), what I want to do is the site to tell you who is on the edit page aswell like "John Doe is already editing this table". Is it possible to achieve it with session or something else?
Thankfull for any response.
You can get the current URI with this method (be sure to load the URI helper):
$this->uri->uri_string();
Then I would keep a users table, since they're required to log in, you should already have this, then also keep a field which indicates whether they are logged in or not, then a nullable field indicating which page they are on. Then when you're on an admin/edit page, you can query all users which page = {admin/edit page}, and display which users are on this page.
Let me know if you have any other questions.

Pass Variable into Wordpress

Can someone tell me how to pass a variable into Wordpress from an incoming URL? For example, I have a visitor following this link:
http://mywebsite.com?variable=white
When they arrive at my wordpress site, I want to pull that "white" variable and store it for future use in my MailChimp list and departing links like this:
store mailchimp color
http://mySecondWebsite.com?favoriteColor=white
I want this to be temporary and specific to this user only. I understand the concept and use of session_start(), but I have no idea how to use this in conjunction with Wordpress. Any help is appreciated.
You can use the GET variables to fetch information from a URL. You can read out the $_GET array in PHP to get to your variable.
The part thats tricky, is that inside your wordpress application, you should check out if the user is logged in, and then update the users' information based on the current session. This is basically what you're looking for.
If the user is not logged in already, you can ofcourse not update his account by just that URL. You'd then need to add more info - something like a hash in the URL thats unique for this user and allows you to update a preference without logging in.

user profile page generation

I am developing a dynamic website using PHP. When a user of the website creates an account, a profile page should be created for that user. Say, a user called 'dev23' creates an account on my website, his profile should be accessible through the link www.mysite.com/dev23
How do I create such a thing? Should I create a standard page like userprofile.php which is populated with data specific to the username provided? Or should I create a permanent webpage for every user?
Please let me know the right approach to this porblem.
Is the www.mysite.com/dev23 meant to be public or only visible to the logged in user?
If it is only visible to the logged in user, you can create a myprofile.php file which retrieves the logged in user from the session and retrieves data accordingly.
If it is meant to be a URL that other users can hit, you probably want some sort of userprofile.php page with data passed along to identify the user to be viewed. For example, the url might be www.mysite.com/userprofile.php?user=dev23. If you are using Apache for your web server, you can look at using mod_rewrite to make the URL prettier. Thus, you could have the URL www.mysite.com/user/dev23 routed to userprofile.php?user=dev23 and your PHP processes the same. It is just a means of making URLs be more user friendly than a naked query string. This is common amongst many PHP-based CMS systems such as WordPress, Joomla, etc.
Ideally you should be creating a single file that handles all users.
Certain frameworks like SkyPHP allow this by defining the attributes after a valid page as "queryfolders" which can be used much like GET/POST variables.
If you are not using a framework, I might suggest you look into using one to simplify your tasks.
SkyPHP also has a functionality where a single field in a table can be used to pull this data simply by defining the page as _table.field_name_
It will check to see if there is a matching table and field to pull the data from and will automatically pull the id of the record whose field's value matches that of the url and assign it to a variable.
Example... If we have a table called category and a field named slug, one would create a page named _category.slug_.php
Then the url... http://mydomain.com/watches would look for "watches" in category.slug and pull back the identifier of the record as $category_id with $category_slug available also.
It would solve your issue if you are willing to give it a shot.
Again refer to the documentation here... http://switchbreak.com/skyphp

Categories