Allow user to submit data 3 times in a day with Codeigniter - mysql

On my Codeigniter project, I would like to allow user to submit data into database only 3 times in a day (that user can submit on another day). Have anyone know the better way to do this?
Sorry for my bad English and duplicated question.

field
[create_perday], [timestamp_update], [reset_times]
create_perday - times of update [ex. value = 1, 2, 3]
reset_times - is boolean [0 = not reset, 1 = reset]
sudo code :
if(date(timestamp_update) > date(now) ) { // check date
if(!reset_times) {
doReset[times]
}
if(create_perday < 3) { // check times
create_perday = create_perday + 1;
return true;
} else {
return false;;
}
}

Related

Spoof JSON (or other resource) while loading realtime Web site

I'm trying to write a userscript for a friend. The Website I'm writing it for (app.patientaccess.com) tells you what doctors appointments you have, (among other things). However, in order to write my userscript, I need to know how the app handle appointments for the following year.
At the moment, the only way to know is to wait until the end of the year when my friend starts making appointments for the following year. Since it's an Angular app, I'd rather, if possible, point it to a fabricated JSON file of my creation when the app requests that particular data. In that file I can give it some data for this year and next year and then I can see what happens with appointments made for the following year.
I'm hoping this can be done with an addon for Chrome or Firefox or perhaps some kind of free/open source software.
Thanks in advance.
I came up with a function that will accurately guess there year, given the day name, date and month, if it's within a couple of years either side of the current year.
function calculateYear(dayName, dayOfMonth, monthNum, returnDateObj) {
monthNum -= 1;
maxIterations = 3;
var startYear = (new Date()).getFullYear();
var dateObj = new Date(startYear, monthNum, dayOfMonth);
for (var i = 0; i < maxIterations; i++) {
dateObj.setYear(startYear + (1 * i));
if (dayName == daysOfTheWeek[dateObj.getDay()]) {
return (returnDateObj) ? dateObj : dateObj.getFullYear();
}
dateObj.setYear(startYear - (i + 1));
if (dayName == daysOfTheWeek[dateObj.getDay()]) {
return (returnDateObj) ? dateObj : dateObj.getFullYear();
}
}
return 'No Match';
}
It works a treat, as you can see here.

Storing top 3 scores

So I have a 3x3 grid of text fields that are meant to show to the 3 best score along with the lap times and carHealths that have been achieved since the game was launched and if a better score then one of the ones in the current leader board is made then the new score, lap time and carHealth replace the old one and move everything below it down by one.
The problem is it only replace the top score even if it is a worse score if just leaves the other 2 spots untouched. Am I just missing something very obvious or am i going about this all wrong?
function leaderBoard(): void
{
if (score < scoreArray[2])
{
return
}
if (score > scoreArray[0])
{
scoreArray.unshift(score);
lapTimerArray.unshift(lapTimer.currentCount);
carHealthArray.unshift(carHealth);
scoreArray.pop()
lapTimerArray.pop()
carHealthArray.pop()
}
else if (score > scoreArray[1])
{
scoreArray.splice(1, 0, score);
lapTimerArray.splice(1, 0, lapTimer.currentCount);
carHealthArray.splice(1, 0, carHealth);
scoreArray.pop();
lapTimerArray.pop();
carHealthArray.pop();
}
else if (score > scoreArray[2])
{
scoreArray.pop();
lapTimerArray.pop();
carHealthArray.pop();
scoreArray.append(score);
lapTimerArray.append(lapTimer.currentCount);
carHealthArray.append(carHealth);
}
}
Oh god :) What do you do if you suddenly want to display top 10 scores ?
How about this approach: You store all information of your cars in ONE object (or class) and then sort your array by score. This way you dan't have to mess with three separate arrays (and maybe you will want to add more properties to your car later):
var car1:Object = {name:"Car 1", score:100, lapTimer:100, carhealth:50};
var car2:Object = {name:"Car 2", score:1050, lapTimer:100, carhealth:50};
var car3:Object = {name:"Car 3", score:700, lapTimer:100, carhealth:50};
var myCars:Array = [car1, car2, car3];
// Then you probably want to pass your car objects to your cars and modify them from there: car3.score = 400 etc. The car objects can be created dynamically based on how many cars you want
// In the end
function displayScores():void
{
myCars.sortOn("score"); // sort cars on score property
// display top 3
for(i:int = 0, i < 3; i++)
{
trace("Place " + (i+1) + " - " + myCars[i].name + ", Score " + myCars[i].score);
}
}

How to create an auto click button

I have a list of cases in the queue that I need to grab. As you can imagine, it's a bit repetitive and time consuming. I'm new at programming and haven't figured a way to create a script that auto-click/grab these cases. Can someone help?
Code to:
1) Search and Click "Grab"
- will take 4 seconds for the page to refresh
2) Click grab again
3) stop after 50 cases are grabbed
This code doesn't work
window.setTimeout("pushSubmit()",3000);
function pushSubmit()
{document.getElementById('Grab').click();
Assuming your page is not refreshed in the process, you could keep a counter of how many "Grabs" you have done:
var counter = 0;
var maxCount = 50;
function pushSubmit() {
if(counter++ < maxCount) {
document.getElementById('Grab').click();
window.setTimeout(pushSubmit,3000);
}
}
//start the process
pushSubmit();
Here is a jsfiddle example
EDIT:
Or what I would probably prefer, set up the function so it can be used with any number of iterations.
function pushSubmit(max, count) {
count = typeof count !== 'undefined' ? count : 1;
if(count <= max) {
document.getElementById('Grab').click();
window.setTimeout(function() { pushSubmit(max, ++count) },3000);
}
}
//start the process with the max number of iterations it should perform
pushSubmit(50);
Example

Checking for same values using if statement in actionscript?

I'm working on a match-3 style puzzle game using Flixel, and so I'm working on checking each row and column to see if there is a match at any given time. However, I have 6 different pieces (as of right now) that are active, and each piece is identified by an integer. Given that, I can check, for each and every single piece, by doing something like this:
public function matchingCheck():void
{
if (piecesArray[0][1] == 1 && piecesArray[1][1] == 1 && piecesArray[2][1] == 1) {
FlxG.log("Yay!");
}
}
However, this is rather unwieldy and would basically cause way too much repetition for my liking.
At the very least, I would like to be able to check if the values in these arrays are equal to one another, without having to specify which value it is. At the very best, I'd love to be able to check an entire row for three (or more) adjacent pieces, but I will settle for doing that part manually.
Thanks for your help!
EDIT: Nevermind, my edit didn't work. It was just checking if piecesArray[2][1] == 1, which makes me a sad panda.
EDIT 2: I've selected the correct answer below - it's not exactly what I used, but it definitely got me started. Thanks Apocalyptic0n3!
You could cut down on that code a little bit by using another function
private function checkValid( arrayOfItemsToCheck:Array, value:* ):Boolean {
for ( var i:Number = 0; i < arrayOfItemsToCheck.length; i++ ) {
if ( arrayOfItemsToCheck[i] != value ) {
return false;
}
}
return true;
}
Then you just do this in your if statement:
if ( checkValid( [ piecesArray[0][1], piecesArray[1][1], piecesArray[2][1] ], 1 ) ) {
FlxG.log("Yay!");
}
That does assume all items need to be equal to 1, though. It's still a lot of code, but it cuts out one set of "= 1 &&" for each check.
How about something like this which would tell you both if a match existed and what match it was:
public function checkForMatch():void{
var rows:int = piecesArray.length;
for(var i:int=0; i<rows; i++){
var match:int = checkRow(piecesArray[i]);
if(match > -1) {
FlxG.log("Yay you matched " + match);
}
}
}
private function ckeckRow(row:Array):int{
if(row[0] == row[1] == row[2]){
return row[0];
}
return -1;
}

Only follows second parameter

in the following code script for google Spreadsheets, I tried to make a program in which two pieces of information would be inputted to return a desired value that depends on BOTH values. Say, getValcharge ("OptionA", 2000) would return "76", or getValcharge ("OptionB",6000) would return 70. However, it seems to me that I keep getting returned the very last value possible: getValcharge("OptionA"/"OptionB"/"OptionC",1000) would return me "30". Even if I were to put an "OptionD" for the value, it would return "30" if the second number is under 5001.
Thus, it seems to only follow the second parameter --and thus only the second--even when closed off and is supposed to be not accessible to the first.
I am new to Script editor but do have modest Java experience (it'd work were this Java..) Could someone offer any advice/fixes? Any is appreciated. Thanks.
function getValcharge (valType, valAmount) {
var valcost =0;
if(valType="OptionA"){
if(valAmount < 5001)
{valcost = 76;}
if(valAmount > 5000 && valAmount <10001)
{valcost = 113;}
}
if(valType="OptionB"){
if(valAmount < 5001)
{valcost=43; }
if(valAmount > 5000 && valAmount <10001)
{valcost = 70;}
}
if(valType="OptionC")
{
if(valAmount < 5001)
{ valcost = 30; }
if(valAmount > 5000 && valAmount <10001)
{ valcost = 46; }
}
return valcost;
}
In Javascript you need to use a double-equals sign to test for equivalence, eg:
if(valType=="OptionA"){