-
Posts
522 -
Joined
-
Last visited
Everything posted by budimir
-
Hey guys, How to logout a user when a user clicks X or ALT+4??? I think I'll need some javascript or is it possible to solve it with php. ???
-
Anyone??? I really need this ... It's killing me ...
-
Hey Guys, Can someone take a look at this script and tell me how to change it so the week starts with monday, not sunday? I can't find it... /* * Copyright (C) 2004 Baron Schwartz <baron at sequent dot org> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation, version 2.1. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * $Revision: 1.2 $ */ Date.parseFunctions = {count:0}; Date.parseRegexes = []; Date.formatFunctions = {count:0}; Date.prototype.dateFormat = function(format) { if (Date.formatFunctions[format] == null) { Date.createNewFormat(format); } var func = Date.formatFunctions[format]; return this[func](); } Date.createNewFormat = function(format) { var funcName = "format" + Date.formatFunctions.count++; Date.formatFunctions[format] = funcName; var code = "Date.prototype." + funcName + " = function(){return "; var special = false; var ch = ''; for (var i = 0; i < format.length; ++i) { ch = format.charAt(i); if (!special && ch == "\\") { special = true; } else if (special) { special = false; code += "'" + String.escape(ch) + "' + "; } else { code += Date.getFormatCode(ch); } } eval(code.substring(0, code.length - 3) + ";}"); } Date.getFormatCode = function(character) { switch (character) { case "d": return "String.leftPad(this.getDate(), 2, '0') + "; case "D": return "Date.dayNames[this.getDay()].substring(0, 3) + "; case "j": return "this.getDate() + "; case "l": return "Date.dayNames[this.getDay()] + "; case "S": return "this.getSuffix() + "; case "w": return "this.getDay() + "; case "z": return "this.getDayOfYear() + "; case "W": return "this.getWeekOfYear() + "; case "F": return "Date.monthNames[this.getMonth()] + "; case "m": return "String.leftPad(this.getMonth() + 1, 2, '0') + "; case "M": return "Date.monthNames[this.getMonth()].substring(0, 3) + "; case "n": return "(this.getMonth() + 1) + "; case "t": return "this.getDaysInMonth() + "; case "L": return "(this.isLeapYear() ? 1 : 0) + "; case "Y": return "this.getFullYear() + "; case "y": return "('' + this.getFullYear()).substring(2, 4) + "; case "a": return "(this.getHours() < 12 ? 'am' : 'pm') + "; case "A": return "(this.getHours() < 12 ? 'AM' : 'PM') + "; case "g": return "((this.getHours() %12) ? this.getHours() % 12 : 12) + "; case "G": return "this.getHours() + "; case "h": return "String.leftPad((this.getHours() %12) ? this.getHours() % 12 : 12, 2, '0') + "; case "H": return "String.leftPad(this.getHours(), 2, '0') + "; case "i": return "String.leftPad(this.getMinutes(), 2, '0') + "; case "s": return "String.leftPad(this.getSeconds(), 2, '0') + "; case "O": return "this.getGMTOffset() + "; case "T": return "this.getTimezone() + "; case "Z": return "(this.getTimezoneOffset() * -60) + "; default: return "'" + String.escape(character) + "' + "; } } Date.parseDate = function(input, format) { if (Date.parseFunctions[format] == null) { Date.createParser(format); } var func = Date.parseFunctions[format]; return Date[func](input); } Date.createParser = function(format) { var funcName = "parse" + Date.parseFunctions.count++; var regexNum = Date.parseRegexes.length; var currentGroup = 1; Date.parseFunctions[format] = funcName; var code = "Date." + funcName + " = function(input){\n" + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1;\n" + "var d = new Date();\n" + "y = d.getFullYear();\n" + "m = d.getMonth();\n" + "d = d.getDate();\n" + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n" + "if (results && results.length > 0) {" var regex = ""; var special = false; var ch = ''; for (var i = 0; i < format.length; ++i) { ch = format.charAt(i); if (!special && ch == "\\") { special = true; } else if (special) { special = false; regex += String.escape(ch); } else { obj = Date.formatCodeToRegex(ch, currentGroup); currentGroup += obj.g; regex += obj.s; if (obj.g && obj.c) { code += obj.c; } } } code += "if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n" + "{return new Date(y, m, d, h, i, s);}\n" + "else if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n" + "{return new Date(y, m, d, h, i);}\n" + "else if (y > 0 && m >= 0 && d > 0 && h >= 0)\n" + "{return new Date(y, m, d, h);}\n" + "else if (y > 0 && m >= 0 && d > 0)\n" + "{return new Date(y, m, d);}\n" + "else if (y > 0 && m >= 0)\n" + "{return new Date(y, m);}\n" + "else if (y > 0)\n" + "{return new Date(y);}\n" + "}return null;}"; Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$"); eval(code); } Date.formatCodeToRegex = function(character, currentGroup) { switch (character) { case "D": return {g:0, c:null, s:"(?:Ned|Pon|Uto|Sri|Cet|Pet|Sub)"}; case "j": case "d": return {g:1, c:"d = parseInt(results[" + currentGroup + "], 10);\n", s:"(\\d{1,2})"}; case "l": return {g:0, c:null, s:"(?:" + Date.dayNames.join("|") + ")"}; case "S": return {g:0, c:null, s:"(?:st|nd|rd|th)"}; case "w": return {g:0, c:null, s:"\\d"}; case "z": return {g:0, c:null, s:"(?:\\d{1,3})"}; case "W": return {g:0, c:null, s:"(?:\\d{2})"}; case "F": return {g:1, c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "].substring(0, 3)], 10);\n", s:"(" + Date.monthNames.join("|") + ")"}; case "M": return {g:1, c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "]], 10);\n", s:"(Sij|Velj|Ožu|Tra|Svi|Lip|Srp|Kol|Ruj|Lis|Stu|Pro)"}; case "n": case "m": return {g:1, c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n", s:"(\\d{1,2})"}; case "t": return {g:0, c:null, s:"\\d{1,2}"}; case "L": return {g:0, c:null, s:"(?:1|0)"}; case "Y": return {g:1, c:"y = parseInt(results[" + currentGroup + "], 10);\n", s:"(\\d{4})"}; case "y": return {g:1, c:"var ty = parseInt(results[" + currentGroup + "], 10);\n" + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n", s:"(\\d{1,2})"}; case "a": return {g:1, c:"if (results[" + currentGroup + "] == 'am') {\n" + "if (h == 12) { h = 0; }\n" + "} else { if (h < 12) { h += 12; }}", s:"(am|pm)"}; case "A": return {g:1, c:"if (results[" + currentGroup + "] == 'AM') {\n" + "if (h == 12) { h = 0; }\n" + "} else { if (h < 12) { h += 12; }}", s:"(AM|PM)"}; case "g": case "G": case "h": case "H": return {g:1, c:"h = parseInt(results[" + currentGroup + "], 10);\n", s:"(\\d{1,2})"}; case "i": return {g:1, c:"i = parseInt(results[" + currentGroup + "], 10);\n", s:"(\\d{2})"}; case "s": return {g:1, c:"s = parseInt(results[" + currentGroup + "], 10);\n", s:"(\\d{2})"}; case "O": return {g:0, c:null, s:"[+-]\\d{4}"}; case "T": return {g:0, c:null, s:"[A-Z]{3}"}; case "Z": return {g:0, c:null, s:"[+-]\\d{1,5}"}; default: return {g:0, c:null, s:String.escape(character)}; } } Date.prototype.getTimezone = function() { return this.toString().replace( /^.*? ([A-Z]{3}) [0-9]{4}.*$/, "$1").replace( /^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/, "$1$2$3"); } Date.prototype.getGMTOffset = function() { return (this.getTimezoneOffset() > 0 ? "-" : "+") + String.leftPad(Math.floor(this.getTimezoneOffset() / 60), 2, "0") + String.leftPad(this.getTimezoneOffset() % 60, 2, "0"); } Date.prototype.getDayOfYear = function() { var num = 0; Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28; for (var i = 0; i < this.getMonth(); ++i) { num += Date.daysInMonth[i]; } return num + this.getDate() - 1; } Date.prototype.getWeekOfYear = function() { // Skip to Thursday of this week var now = this.getDayOfYear() + (4 - this.getDay()); // Find the first Thursday of the year var jan1 = new Date(this.getFullYear(), 0, 1); var then = (7 - jan1.getDay() + 4); document.write(then); return String.leftPad(((now - then) / 7) + 1, 2, "0"); } Date.prototype.isLeapYear = function() { var year = this.getFullYear(); return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year))); } Date.prototype.getFirstDayOfMonth = function() { var day = (this.getDay() - (this.getDate() - 1)) % 7; return (day < 0) ? (day + 7) : day; } Date.prototype.getLastDayOfMonth = function() { var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7; return (day < 0) ? (day + 7) : day; } Date.prototype.getDaysInMonth = function() { Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28; return Date.daysInMonth[this.getMonth()]; } Date.prototype.getSuffix = function() { switch (this.getDate()) { case 1: case 21: case 31: return "st"; case 2: case 22: return "nd"; case 3: case 23: return "rd"; default: return "th"; } } String.escape = function(string) { return string.replace(/('|\\)/g, "\\$1"); } String.leftPad = function (val, size, ch) { var result = new String(val); if (ch == null) { ch = " "; } while (result.length < size) { result = ch + result; } return result; } Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31]; Date.monthNames = ["Sijecanj", "Veljaca", "Ozujak", "Travanj", "Svibanj", "Lipanj", "Srpanj", "Kolovoz", "Rujan", "Listopad", "Studeni", "Prosinac"]; Date.dayNames = ["Nedjelja", "Ponedjeljak", "Utorak", "Srijeda", "Cetvrtak", "Petak", "Subota"]; Date.y2kYear = 50; Date.monthNumbers = { Jan:0, Feb:1, Mar:2, Apr:3, May:4, Jun:5, Jul:6, Aug:7, Sep:8, Oct:9, Nov:10, Dec:11}; Date.patterns = { ISO8601LongPattern:"Y-m-d H:i:s", ISO8601ShortPattern:"Y-m-d", ShortDatePattern: "n/j/Y", LongDatePattern: "l, F d, Y", FullDateTimePattern: "l, F d, Y g:i:s A", MonthDayPattern: "F d", ShortTimePattern: "g:i A", LongTimePattern: "g:i:s A", SortableDateTimePattern: "Y-m-d\\TH:i:s", UniversalSortableDateTimePattern: "Y-m-d H:i:sO", YearMonthPattern: "F, Y"};
-
[SOLVED] Display value in two different fields!
budimir replied to budimir's topic in Javascript Help
@uniflare Thanks, so much. It's exactly what I have been looking for. -
Try this: if ($_POST['doaction']=='delete') { $sql = "DELETE FROM trainingsdata WHERE id = ' ".$_POST['checkbox']." ' " ; echo 'data deleted'; } You need to put single quotations around variable so id could properly parsed. In first query it wasn't parsed properly especially if it's a number. I hope you can see the difference (don't just copy/paste the code, you need to take out the spaces!!!)
-
[SOLVED] Display value in two different fields!
budimir replied to budimir's topic in Javascript Help
Thanks. I'll try it out and let you know if everything is OK. Thank you very much. -
Hey Guys, I'd like when a user enters a date that it's displayes in two different input boxes. I have tried searching on google but only thing I come up is that I can display it in alert box. This is the code I found, but it's not suting my needs. <script type="text/javascript"> function notEmpty(){ var myTextField = document.getElementById('myText'); if(myTextField.value != "") alert("You entered: " + myTextField.value) else alert("Would you please enter some text?") } </script> <input type='text' id='myText' /> <input type='button' onclick='notEmpty()' value='Form Checker' /> So, I want. In input box1 user enters a date and at the same moment that date is displayed in input box2. Any solutions? You can point me to the web page that can help me!! Thanks.
-
[SOLVED] Adding three fields to one variable
budimir replied to twilitegxa's topic in PHP Coding Help
Of course it's not working. You need adjust it to your DB. The query is not returning anything, it's just for example... Adjust it to your code and post it back here and I'll take a look why is not working. I hade a tippo here: $sql = "SELECT * FROM table_name"; You need to put your table_name here $birthdateday = $row["day"]; $birthdatemonth = $row["month"]; $birthdateyear = $row["year"]; Hre you need to put names of your columns form your DB. -
[SOLVED] Adding three fields to one variable
budimir replied to twilitegxa's topic in PHP Coding Help
$sql = ""SELECT * FROM TABLE"; $result = mysql_query($sql, $conn) or die (mysql_error()); while($row = mysql_fetch_array($result){ $birthdateday = $row["day"]; $birthdatemonth = $row["month"]; $birthdateyear = $row["year"]; } $birthdate = $birthdateday ".-." $birthdatemonth ".-." $birthdateyear; echo "$birthdate"; Is this what you wanted??? -
[SOLVED] Values not passed because of a function???
budimir replied to budimir's topic in PHP Coding Help
Finally guys! I solved my problem in a totally simplier way. if ($_SESSION['last_reload'] != "" && $_SESSION['last_reload'] < strtotime("-180 minutes")) { header("Location:http://localhost/erp/logoutd.php"); } else { $_SESSION['last_reload'] = time(); } If anyone needs it, it's working perfectly and it's totally simple. Cheers. -
[SOLVED] Values not passed because of a function???
budimir replied to budimir's topic in PHP Coding Help
Anyone??? Ideas??? -
Try this: <?php session_start(); // start session and include db info include("includes/db.php"); //get user id $id = $_GET['id']; //get info about user from database $sql = "SELECT name, gender, about, s_phish, u_phish, p_phish, p_s, location FROM users WHERE id = '$id' "; $query=mysql_query($sql, $link) or die (mysql_error()); while($row=mysql_fetch_assoc($query)){ $name = $row['name']; $gender = $row['gender']; $about = $row['about']; $location = $row['location']; $s_phish = $row['s_phish']; $u_phish = $row['u_phish']; $p_phish = $row['p_phish']; $p_s = $row['p_s']; } ?> <?php include("siteincludes/header.php"); ?>
-
You have a problem here: <select name="year" id=year"> <option> value="2008"> id="2008"</option> Do it like this: <select name="year" id=year"> <option value="" selected="selected"></option> <option value="2008" >2008</option> Apply the same to month and day. Was originaly working????
-
[SOLVED] Values not passed because of a function???
budimir replied to budimir's topic in PHP Coding Help
I have ruled out that option too. I have set session timeout to 3mins and checked what's happening. But, it's the same thing. When I try to echo username and password variables in logout.php I can't get anything out. So, I think that these variables are not passed further because of the function which is logoing out inactive users, but I don't know why? Is there any other way to pass these variables to logout page through the function? -
[SOLVED] Values not passed because of a function???
budimir replied to budimir's topic in PHP Coding Help
No, that's not it. I have a session_start() on top of the login page, also I have session_start() on session.php where I'm keeping all the data information important for the session. And on the logout page I include session.php . Everything else connected to session is working. When I hit manually logout button everything is OK. But when I script detects that a user is inactive and redirects to logout page that it's not working. -
Hey guys, I have a script which is loging out inactive users and redircting them to the logout page. The problem is, when an inactive user is redirected to the logout page the sesion variables username and password are not passed to the logout page and because of that the user stays logged in. I don't see why is this happening. Can someone take a look and tell me what am I missing? Here is the script for loging out inactive users: <?php session_start(); $session_id = session_id(); include("db.php"); $upit = "SELECT * FROM korisnici WHERE session_id = '$session_id' && aktivan_s = 'ON'"; $rezultat = mysql_query($upit,$veza) or die (mysql_error()); $broj = mysql_num_rows($rezultat); $row = mysql_fetch_array($rezultat); $user_id = $row["id"]; $ime = $row["ime"]; $korisnicko_ime = $row["korisnicko_ime"]; $prezime = $row["prezime"]; $userData["status"] = $row["status"]; $lozinka = $row["lozinka"]; $status = $row["status"]; $aktivan = $row["aktivan"]; $online_vrijeme = $row["online_vrijeme"]; $g_servis = $row["g_servis"]; $g_izvjestaji = $row["g_izvjestaji"]; $g_popis_servisa = $row["g_popis_servisa"]; $g_naljepnice = $row["g_naljepnice"]; $g_poruke = $row["g_poruke"]; $g_taskovi = $row["g_taskovi"]; $g_zadaci = $row["g_zadaci"]; $g_forum = $row["g_forum"]; $g_korisnici = $row["g_korisnici"]; $g_newsletter = $row["g_newsletter"]; $g_putni_nalozi = $row["g_putni_nalog"]; $vrsta_korisnika = $row["vrsta_korisnika"]; $radno_mjesto = $row["radno_mjesto"]; $_SESSION['logged'] = TRUE; $_SESSION['korisnicko_ime'] = $korisnicko_ime; $_SESSION['lozinka'] = $lozinka; function isLogged(){ if($_SESSION['logged']){ # When logged in this variable is set to TRUE return TRUE; }else{ return FALSE; } } # Log a user Out function logOut(){ $_SESSION = array(); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } session_destroy(); } # Session Logout after in activity function sessionX(){ $logLength = 1800; # time in seconds :: 1800 = 30 minutes $ctime = strtotime("now"); # Create a time from a string # If no session time is created, create one if(!isset($_SESSION['sessionX'])){ # create session time $_SESSION['sessionX'] = $ctime; } else { # Check if they have exceded the time limit of inactivity if(((strtotime("now") - $_SESSION['sessionX']) > $logLength) && isLogged()){ # If exceded the time, log the user out logOut(); # Redirect to login page to log back in header("Location:http://localhost/erp/logoutd.php"); exit; } else { # If they have not exceded the time limit of inactivity, keep them logged in $_SESSION['sessionX'] = $ctime; } } } # Run Session logout check sessionX(); ?> And this is logout page, where I set all the status to 0 and logout users. Here I dont get values for username and password, so the query is not executing. I don't know why!!! <?php include ("admin/servis/include/session.php"); $upit = "UPDATE korisnici SET session_id = '0', aktivan_s = 'OFF' WHERE korisnicko_ime = '".$_SESSION['korisnicko_ime']."' AND lozinka = '".$_SESSION['lozinka']."'"; $rezultat = mysql_query($upit,$veza) or die (mysql_error()); session_destroy(); header("Location:index.php"); exit; ?> Help!!!
-
I don't think that is the problem. I have tried setting logout after 3 mins for testing and still I can't get the values passed to the query on logoutd.php I don't understand why isn't passed to it!
-
It was just a question. I was curious. I used some bad logic and I came up with this idea. Was able to work around. Now is OK. Thanks a lot.
-
Hey guys, Is it possible to send data values through header to some other page?? For example, I have a form and action is PHP_SELF. On second page I have a file where I store all the values. Is it possible to transfer all the values like $_POST["field"] through header()??? If I only redirect, the second page is getting the values. So, I'd like to do with header() something what is done with method=post, action="store_data.php" in a form when button is clicked! Any ideas??
-
Yep, that will probably work! I have header errors now. I need to check where I'm getting an output. Thanks a lot. I need to play with it now, but I will mark this as solved since my original question is resolved now!!!
-
That looks a little bit too complicated for me, because I already use ssession for diferent things, so I can not destroy it. Let me help with this. I have come up with a different idea. I would use one form and use action=PHP_SELF, becasue I need it for some onChange events and on the bottom of the page I would use submit button to send the complet form when everything is filled out. And then use php if function like this: if ($_POST["submit "] == submit){ header("Location:store_values.php"); exit; } else { echo "Error!"; } Now, my question is. On store_values.php I have $values = $_POST["values"]; where I'm getting everything from form and putting it in a query. Will that work???
-
Hey Guys, Quick question. I have two forms on my page. On first one i use javascript onChange event to execute PHP_SELF. And second one should get all the values from the first one and second one and send all the data to (here I use classic method="POST" action="data.php")data.php file. But, the problem is it's not getting data from the first form. How can I make it so both forms are collected when I hit Submit button? I'm stuck!!!
-
Hey guys, Can you tell me why this won't work when I enter decimal numbers? <script type="text/javascript"> <!-- Begin function startCalc5(){ interval = setInterval("calc5()",1); } function calc5(){ one = document.autoSumForm1.dnev.value; two = document.autoSumForm1.tecaj.value; document.autoSumForm1.iznos_dnevnice_kn.value = (one * 1) * (two * 1); } function stopCalc5(){ clearInterval(interval); } // End --> </script>
-
My XAMP(Apache) not working when Internet is disabled
budimir replied to gnawz's topic in PHP Installation and Configuration
Try only http://localhost and see what happens. It doesn'e matter if Internet is enabled or not. It's working on local computer only! -
Thanks, Mchl. You rock!!!!!! It's exactly what I have been looking for!!!!