View Full Version : Need help with product coding
almannai
03-15-2008, 04:07 PM
I'm creating a vb product and having this scenario which i don't know how to do it.
In the product there is two textbox options that the administrator can alter their values. The first box got a values like 3,4,7,...,100 and the second can take any integer number like 2.
A variable x in the product should start with the first number in the first textbox which is 3. The second textbox represent a time in hours where each time the system time elapsed that time the variable x will jump to the next value of the first textbox which is 4 in the example above and so on until it reaches 100 then it will get back to value 3.
regards,
Opserty
03-15-2008, 05:53 PM
You need to create a scheduled task that runs once an hour then use some PHP along the lines of:
// You need to create a setting field that holds the current value
// You don't really need this line I just added to make it easier to see what is going on below
$curval =& $vbulletin->options['settingcurval'];
// Explode the comma seperated values into array
$settinglist = explode(',', $vbulletin->options['varsettingname']);
$curkey = array_search($curval, $settinglist);
// Move the key along one
$curkey++;
// Set the new value
$curval = $settinglist[$curkey];
// RUN A QUERY TO UPDATE SETTINGS TABLE
// To update the $curval into the database.
// Includes adminfunctions.php
require_once('/includes/adminfunctions.php');
// Update the datastore
build_options();
Something like that I think should work, there might be a better way to do it. But that is the way I would have done it anyway :p
almannai
03-16-2008, 07:53 AM
Thanks Opserty for your reply but the problem I don't know how to
create a scheduled task for the plugin or product?:o
I tried to search the forum to see how but to many posts to find what i need.
Dismounted
03-16-2008, 08:45 AM
Admin CP > Scheduled Task > Add New Task?
almannai
03-16-2008, 10:13 AM
Admin CP > Scheduled Task > Add New Task?
Thanks for the reply.
But I don't get it! this is ok for my forum but how to distribute the corn with the product files to be used by other vb forums.
Also what is the line in code to check if number of hours had elapsed in the corn php file
something like
if((timenow-lasttimesaved)>numberofhours){
lasttimesaved=timenow;
do something...
}
Thanks for your time
Dismounted
03-17-2008, 06:22 AM
Have you turned on debug mode, attached the task to your product, and export the product like that?
almannai
03-17-2008, 02:56 PM
Ok I got this task working but how to read a variable like $curval in the product templates? It always returns null!
Opserty
03-17-2008, 03:20 PM
// RUN A QUERY TO UPDATE SETTINGS TABLE
// To update the $curval into the database.
Make sure you do that bit.
Then run build_options(). Then you should be able to read curval from $vbulletin->options array.
Bear in mind this is just a rough guide to the procedure to follow, it is by no means a work example. You will need to refine it appropriately.
almannai
03-17-2008, 04:29 PM
// RUN A QUERY TO UPDATE SETTINGS TABLE
// To update the $curval into the database.
How to do it? I don't know what is the settings table and never done it before...
almannai
03-19-2008, 10:16 AM
Anybody has any clue on how to solve this issue? Hint , example...
Opserty
03-19-2008, 11:43 AM
You need to do a query to the database to update the setting in the setting table. You will need to this through PHP, if you don't know PHP or MySQL I suggest you learn and understand what is going on before proceeding with your product.
Check the "Articles" section for more information on these subjects.
Dismounted
03-20-2008, 10:18 AM
Not only check the Articles section, but on Google for PHP tutorials, as they will provide more information on PHP/MySQL.
almannai
03-20-2008, 11:15 AM
You need to do a query to the database to update the setting in the setting table. You will need to this through PHP, if you don't know PHP or MySQL I suggest you learn and understand what is going on before proceeding with your product.
Check the "Articles" section for more information on these subjects.
Not only check the Articles section, but on Google for PHP tutorials, as they will provide more information on PHP/MySQL.
Thanks guys to reply,
I know php and mysql coding and i've build many products before but this is the first that i need cron to be used in a product. I'am just confused about what the meaning of "RUN A QUERY TO UPDATE SETTINGS TABLE". As is this settings table already exist as a part of vbulliten or i have to create? What is its name exactly? Also do i have to create a field in that table for each of the variables i want to pass its value to the template?
Sorry if it is still not clear what i want to do, but this is my best in english.
Regards,
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.