Jump to content

Strahan

Members
  • Posts

    80
  • Joined

  • Last visited

Everything posted by Strahan

  1. OK, I got it working. However, I'm still curious if there is a better way to do this as my solution seems awful awkward: $fd = array(); $fd["hf0"] = "8:00 AM"; $fd["ht0"] = "4:30 PM"; $fd["hf1"] = "8:00 AM"; $fd["ht1"] = "4:30 PM"; $fd["hf2"] = ""; $fd["ht2"] = ""; $fd["hf3"] = "9:00 AM"; $fd["ht3"] = "1:00 PM"; $fd["hf4"] = ""; $fd["ht4"] = ""; $fd["hf5"] = "9:00 AM"; $fd["ht5"] = "1:00 PM"; $fd["hf6"] = ""; $fd["ht6"] = ""; $WeekDays = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); $hours = ""; $sd = ""; $ld = ""; $sxnt = true; $fr = ""; $to = ""; for ($x=0; $x<=5; $x++) { if (empty($fd["hf$x"])) { $hours .= "$sd" . ((empty($ld))?", ":" - $ld") . " $fr to $to<br/>{$WeekDays[$x]}, Closed<BR>"; $sd = ""; $ld = ""; } else { if (empty($sd)) { $sd = $WeekDays[$x]; $fr = $fd["hf$x"]; $to = $fd["ht$x"]; } if (empty($ld) && $sd != $WeekDays[$x]) $ld = $WeekDays[$x]; if ($fd["hf$x"] != $fr || $fd["ht$x"] != $to) { $hours .= "$sd - $ld, $fr to $to<BR>"; $sd = $WeekDays[$x]; $fr = $fd["hf$x"]; $to = $fd["ht$x"]; $ld = ""; } else { if ($sd != $WeekDays[$x]) $ld = $WeekDays[$x]; } } } if ($fd["hf6"] != $fr || $fd["ht6"] != $to) { $hours .= "$sd" . ((empty($ld))?", ":" - $ld") . " $fr to $to<br/>Sun, " . ((empty($fd["hf6"]))?"Closed":"{$fd["hf6"]} to {$fd["ht6"]}") . "<BR>"; } else { $hours .= "$sd - Sun, $fr to $to<BR>"; } Which gives me: Mon - Tue 8:00 AM to 4:30 PM Wed, Closed Thu, 9:00 AM to 1:00 PM Fri, Closed Sat, 9:00 AM to 1:00 PM Sun, Closed
  2. I have a weird issue. I'm working on something where people will submit hours for a business. Originally it was free form text, but then I figured it may get messy with people doing M-F 9-5 then Monday through Friday, 9AM to 5PM, Mon-Fri, etc. So I switched to a bunch of inputs. It has each day then a select for from and one for to. Data is passed to the script as a form submission. Vars are named HF# and HT# (hours from, hours to and a 0-6 digit for Mon-Sun). I want to take the input and output a string as such: Mon-Tue, 8:00 AM to 5:00 PM Thu-Fri, 8:00 AM to 5:00 PM Sat, 9:00 AM to 1:00 PM Sun, 12:00 PM to 3:00 PM I did this: $formdata = array(); $formdata["hf0"] = "8:00 AM"; $formdata["ht0"] = "4:30 PM"; $formdata["hf1"] = "8:00 AM"; $formdata["ht1"] = "4:30 PM"; $formdata["hf2"] = ""; $formdata["ht2"] = ""; $formdata["hf3"] = "8:00 AM"; $formdata["ht3"] = "4:30 PM"; $formdata["hf4"] = "8:00 AM"; $formdata["ht4"] = "4:30 PM"; $formdata["hf5"] = "9:00 AM"; $formdata["ht5"] = "1:00 PM"; $formdata["hf6"] = "12:00 PM"; $formdata["ht6"] = "3:00 PM"; $WeekDays = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); $hours = ""; $sd = "Mon"; $ld = ""; $fr = $formdata["hf0"]; $to = $formdata["ht0"]; for ($x=0; $x<=6; $x++) { if (empty($sd) && !empty($formdata["hf$x"])) { $sd = $WeekDays[$x]; $fr = $formdata["hf$x"]; $to = $formdata["ht$x"]; } if ($fr != $formdata["hf$x"] || $to != $formdata["ht$x"]) { $hours .= "$sd" . (($sd==$ld)?", ":" - $ld, ") . " $fr to $to<br/>"; if (!empty($formdata["hf$x"])) { $sd = $WeekDays[$x]; $fr = $formdata["hf$x"]; $to = $formdata["ht$x"]; } else { $sd = ""; } } $ld = $WeekDays[$x]; } ($formdata was because I was tired of hitting back, changing the data then resubmitting) This kinda works, but it skips Sunday. There has got to be a better way to do this.. any ideas?
  3. Hi. I'm trying to make my folder management tool able to remove stuff. Problem is, I get permission denied. I've checked the NFTS perms for the share and for the folder. It's also not read only. I logged into my other workstation as the service account the web server is using and opened a DOS window and did "rd \\server\share\folder" and it removed it no problem. It just fails in PHP. Any idea what I should be looking at? Thanks!
  4. Odd, it cut off my text after the code. Anyway, it works fine for months that have whole, unbroken weeks. Like this month, June 14. 16 days matching my criteria (Mon-Thu). However, if I try it with a month like July where the first is on Tuesday and the thirty-first is on Thursday, there are 19 days but the code returns 18. In September, there are 18 days but the code returns 17. I could add $days++, but for unbroken months it will be wrong and I'm not sure how to programatically tell that a month is broken up or not. Then again, it's after midnight so maybe I should try tomorrow when I am not sleepy
  5. I found some code while Googling: $workdays = explode(",", "1,1,1,1,0,0,0"); // turn string to array (Monday to Sunday) $days = 0; $time = strtotime("2014-06-01"); $end_time = strtotime("2014-06-30"); while ($time < $end_time) { $day_of_week = date("N", $time) - 1; // 0 = Monday, 6 = Sunday if ($workdays[$day_of_week] == 1) { $days++; } $time = strtotime("+1 day", $time); // add one day to time } echo $days;
  6. Hi. I am writing software to choose employees for drug testing. Originally it was choosing 5 per day, Mon-Thu. No problem there, that's easy. Now, they want to ensure everyone gets tested each calendar year. So now I need the program to look at the date and calculate the days between now and 12/31 then divide the people that haven't been tested by days to get number per day that need testing so it gets all done by the end of the year. The snag I hit is how to calculate it. I can easily get days to 12/31, but I need to drop the Fridays, Saturdays and Sundays of each week. That has me a little perplexed. Is there a way to make that kind of calculation? Thanks!
  7. Cool, thanks. So would this be better then? <?php stuff stuff stuff $pdo = new pdo blah blah blah stuff stuff stuff $pdo = null; function dosomething() { global $pdo; stuff } ?>
  8. Hi. I always wondered about this.. if I do: function getName($userid) { $pdo = new PDO("blah blah blah"); $sql = $pdo->query("blah blah"); $row = $sql->fetch(PDO::FETCH_ASSOC); return $row["UserName"]; $pdo = null; } Since the $pdo = null is after the return, does that mean the pdo object isn't getting closed? I've been doing functions like that this way since I wasn't sure: function getName($userid) { $pdo = new PDO("blah blah blah"); $retval = ""; $sql = $pdo->query("blah blah"); $row = $sql->fetch(PDO::FETCH_ASSOC); $retval = $row["UserName"]; $pdo = null; return $retval; } I was just wondering if it's necessary, or if the objects clean themselves up automatically anyway?
  9. Hi. I have a machine that has content on several drives. For example, lets say I am referring to E:\Videos\SomeShow. The machine has a share, \\machine\video2$ that points to E:\Videos. I have an intranet page that I use for managing and launching my content. It has a function as such: function num_files($dir, $onlyvideo = false) { global $ArchiveTypes, $VideoTypes; $counter = 0; if(is_dir($dir)) { if (file_exists($dir)) { if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if ($onlyvideo) { if (ValidFiles($file, $VideoTypes)) $counter++; } else { if (ValidFiles($file, $ArchiveTypes)) $counter++; } } } closedir($handle); } } } return $counter; } When that code runs and I pass it "//machine/video2$/someshow", it correctly returns the file count. Now.. in order to prevent having the annoyance of having to track my video shares across multiple drives and multiple machines, I made a DFS root called "//domain.com/videos". I have a script that runs daily and manages the DFS links to that root my scanning the folders in each drive share. Works great. However.. I have found that if I pass that function "//domain.com/videos/someshow" I get: Warning: opendir(//domain.com/videos/someshow,//domain.com/videos/someshow): Access is denied. (code: 5) in D:\Sites\domain.com\media\RootLibrary.php on line 447 I was wondering why it listed the path twice, so just to be sure it was passed correctly I echoed it out just before the opendir and it is correct. Is there some way around that? Thanks!
  10. Ahh, thanks, your link led me down the right path After reading it I tried echo "Please freaking work: " . $annoying->attributes('xml', TRUE)->lang . "<BR>"; and now as it loops I'm seeing the actual language codes, w00t! Thanks again
  11. This is making me crazy. I am trying to find data from AniDB.net. I have an XML file of all the titles, this is the XML: <?xml version="1.0" encoding="UTF-8"?> <animetitles> <anime aid="1"> <title type="short" xml:lang="en">CotS</title> <title type="official" xml:lang="en">Crest of the Stars</title> <title type="official" xml:lang="fr">Crest of the Stars</title> <title type="official" xml:lang="pl">Crest of the Stars</title> <title type="syn" xml:lang="cs">Hvězdný erb</title> <title type="main" xml:lang="x-jat">Seikai no Monshou</title> <title type="short" xml:lang="x-jat">SnM</title> <title type="syn" xml:lang="zh-Hans">星界之纹章</title> <title type="official" xml:lang="ja">星界の紋章</title> </anime> <anime aid="9887"> <title type="main" xml:lang="x-jat">Chihayafuru OAD</title> <title type="official" xml:lang="ja">ちはやふる OAD</title> </anime> </animetitles> <!-- Created: Thu May 16 02:00:33 2013 (7692 anime, 41979 titles) --> What I'm doing is pulling these animes and inserting into a MySQL database. I just need to get the main title and the official english titles. I have no problem iterating through the title tags and checking the type, but the namespaced "xml:lang" attribute is screwing me up. This is my code: $data = simplexml_load_file("anime-titles_2.xml"); foreach ($data->anime AS $anime) { $namestr = ";;"; foreach ($anime->title AS $annoying) { echo "**********<BR>"; var_dump($annoying); echo "<BR>**********<BR><BR>"; $ass = $annoying->children('xml', true); var_dump($ass); echo "<BR><BR>Title type: {$annoying["type"]}<BR>"; echo "Language: {$annoying["lang"]}<BR>"; echo "Language: {$annoying["xml:lang"]}<BR>"; echo "Language: {$ass["lang"]}<BR>"; echo "Language: {$ass->lang}<BR>"; echo "Language: {$ass->attributes["lang"]}<BR>"; echo "Language: {$ass["attributes"]["lang"]}<BR>"; echo "Language: {$ass["@attributes"]["lang"]}<BR>"; echo "<BR><HR><HR><BR>"; } } The var names kinda express my frustration at my attempts to figure this out lol. For example, this is the first block of output I get: ********** object(SimpleXMLElement)#8 (2) { ["@attributes"]=> array(1) { ["type"]=> string(5) "short" } [0]=> string(4) "CotS" } ********** object(SimpleXMLElement)#9 (1) { ["@attributes"]=> array(1) { ["lang"]=> string(2) "en" } } Title type: short Language: Language: Language: Language: Language: Language: Language: I can freaking see the data I want in the second var dump - the "en" is what I want to see. But I cannot for the life of me figure out how to actually address it outside of the var dump! Please save me from going bald
  12. I changed to the ABS method and the problem went away. Pesky floats! Thanks a lot!
  13. I'm assuming I'm perhaps suffering from some sort of type issue, but I can't figure this out. I pay my ex girlfriend to do housework for me. We were using a spreadsheet to track her hours and stuff, but I figured since I love tinkering with PHP this would be a good thing to convert to a web app. Everything is good, but when I wrote the payroll history report I'm having a problem. This is the code: case "payhistory": $sql = $pdo->query("SELECT * FROM hours WHERE paid IS NOT NULL ORDER BY paid"); $subpay = 0; $subhrs = 0; $curpd = ""; $totpay = 0; $tothrs = 0; $subhrs = 0; while ($row = $sql->fetch(PDO::FETCH_ASSOC)) { if ($curpd != $row["paid"]) { if (!empty($curpd)) { Write("<BR><BR>SUBTOTAL: $subpay"); $actualpay = getpay($payid); if ($actualpay <> $subpay && !empty($actualpay)) Write("<BR><I>(" . money($actualpay) . ")</i>"); Write("<BR><HR>"); } $subpay = 0; $subhrs = 0; $curpd = $row["paid"]; $payid = $row["payid"]; } if ($row["debt_incurred"] == "0") { Write("Hours: " . sec2time(strtotime($row["ended"]) - strtotime($row["started"])) . ", pay: " . pay_amount($row["started"], $row["ended"]) . "<BR>"); $totpay += pay_amount($row["started"], $row["ended"]); $tothrs += strtotime($row["ended"]) - strtotime($row["started"]); $subpay += pay_amount($row["started"], $row["ended"]); $subhrs += strtotime($row["ended"]) - strtotime($row["started"]); } else { if ($row["debt_incurred"] > 0) { $totpay -= $row["debt_incurred"]; $subpay -= $row["debt_incurred"]; } else { $totpay += str_replace("-", "", $row["debt_incurred"]); $subpay += str_replace("-", "", $row["debt_incurred"]); } Write("Debt: {$row["debt_reason"]}, amount: {$row["debt_incurred"]}<BR>"); } } Write("<BR><BR>SUBTOTAL: $subpay"); $actualpay = getpay($payid); if ($actualpay <> $subpay && !empty($actualpay)) Write("<BR><I>(" . money($actualpay) . ")</i><BR><BR>"); Write("|$subpay| |$actualpay|<BR><BR>"); if ("|$subpay|" != "|$actualpay|") { Write("Does NOT match!<BR>"); } else { Write("Matches!<BR>"); } if ($subpay != $actualpay) { Write("Does NOT match!<BR>"); } else { Write("Matches!<BR>"); } if (floatval($subpay) != floatval($actualpay)) { Write("Does NOT match!<BR>"); } else { Write("Matches!<BR>"); } if (floatval($subpay) <> floatval($actualpay)) { Write("Does NOT match!<BR>"); } else { Write("Matches!<BR>"); } break; I've removed a bunch of the formatting junk to make it less bulky, but that's it. It loops through my data and breaks on a change in "paid", the field that marks the date that work was paid for. I subtotal the amount earned in $subpay during the looping. I have a function getpay that makes a call to a separate table to get the amount I actually paid (sometimes the actual amt I pay her is different than the tallied hours). It returns that to $actualpay then it compares and if they aren't matched up, it prints the subpay with the actualpay beneath it in italics. Works great until the last record. I get this output: Debt: Dollar Tree, amount: 4.12 Debt: Fax, amount: 20.00 Hours: 45 minutes, pay: 11.25 Hours: 1 hour, pay: 15 Hours: 45 minutes, pay: 11.25 Hours: 30 minutes, pay: 7.5 Hours: 30 minutes, pay: 7.5 Hours: 15 minutes, pay: 3.75 Debt: Phone card, amount: 47.00 Hours: 1 hour, pay: 15 Hours: 30 minutes, pay: 7.5 Debt: Loan to me, amount: -30.00 SUBTOTAL: 37.63 ($37.63) |37.63| |37.63| Matches! Does NOT match! Does NOT match! Does NOT match! It matches the two if I make them strings but I can't figure out how to match them otherwise. I'm sure it's a dumb mistake on my part, but it's one I cannot find and it drives me nuts because the same code works fine during the loop, it just dies outside of it. ??
  14. A - Good idea, maybe that will stop the SQL from crapping itself. I'll try that. B - Average time a service ticket was open. System logs open time and last activity time (UNIX time) so what I'm actually doing is a sum of ticket end-ticket open where ticket status = closed. C - Cool, wasn't aware of that feature. If A still fails, I'll try that. Thanks a lot for the tips! EDIT: Just tried it, A works like a champ. My SQL: SELECT AVG(DATEDIFF(second, created, lastupdate)/60) AS ddiff FROM tickets WHERE ticket_status = 0 AND created >= CAST('2011-11-01' AS DATETIME) AND created <= CAST('2012-11-03' AS DATETIME) Gives me back average minutes open on 35k records in a practically an instant. Whoo hoo Thanks again!
  15. Hmm, I'll have to read up on ajax. As for the SQL, it's not so much the time it takes for SQL to send data back as it is the time for me to process it. Orig, I was doing something like SELECT SUM(numberfield) AS blah but then someone put in a date range for a whole year of data and I got an arithmetic failure. Apparently it chokes trying to sum 35,000 records worth of numeric fields that can get large (it's seconds that a service ticket has been open, and some tickets go 60+ days). I switched to just doing SELECT numberfield then doing a while ($row = $sql->fetch(PDO::FETCH_ASSOC)) $tot += $row["numberfield"];. The looping is what takes so darned long. Thanks guys.
  16. Hi. I have code that does a SQL query which can take ten seconds or so. I figured rather than have people just sit there wondering if it's working, I'd display something like "Please wait ..." then after the query display the data. I did: ob_end_flush(); echo "Please wait ...<BR><BR>"; (sql stuff) echo "Done!"; ...however it waits until the whole thing is done before it displays anything. I thought from ob_end_flush would do it. What would? Thanks!
  17. I was wanting to make my own version of TinyURL for my personal use. So far, the only way I can get it to work as trim as possible is using the format: http://www.mysite.com/?tag TinyURL can do http://tinyurl.com/tag instead. I know dropping the ? is a trifling thing, but I'd like to figure out how they did it. I could do it by just creating subfolders and dropping an index.php in there that does a redirect, but I wasn't sure if there was a more efficient way....?
  18. I was curious.. I read that after using a PDO connection you should set the object to null to close it out. In this instance: function IsOwner($regionid, $user) { global $Username, $SQL_Server, $SQL_User, $SQL_Pass; $pdo = new PDO("mysql:host=$SQL_Server;dbname=$SQL_Database", $SQL_User, $SQL_Pass); $sql = $pdo->prepare("SELECT count(region_id) FROM region_players WHERE region_id = ? AND user_id = ? AND owner = 1"); $sql->execute(array($regionid, $user)); if ($sql->rowCount() == 0) { return false; } else { return true; } $pdo = null; } Since the return is called prior to the nulling, does it leave a connection hanging or does PHP do some sort of auto-closeout when a function ends? Should I instead be doing: function IsOwner($regionid, $user) { global $Username, $SQL_Server, $SQL_User, $SQL_Pass; $ownerstatus = false; $pdo = new PDO("mysql:host=$SQL_Server;dbname=$SQL_Database", $SQL_User, $SQL_Pass); $sql = $pdo->prepare("SELECT count(region_id) FROM region_players WHERE region_id = ? AND user_id = ? AND owner = 1"); $sql->execute(array($regionid, $user)); if ($sql->rowCount() > 0) $ownerstatus = true; $pdo = null; return $ownerstatus; } ?
  19. Well, I didn't figure out what was wrong but I did find a workaround. I never could get PHP to send the data and have it work with fsockopen, but I fired up C# and wrote a class library that sends the data then registered it and I just call the COM component from the webpage. Took a little wrestling to learn how to get PHP and COM to work together (permissions problems mostly) but now it works smoothly.
  20. OK, just ran it through Wireshark. Annoyingly, the data part was identical. There were some variances in the frame data, but I don't know if that's relevant (different boxes, different hardware, etc etc). Then again, I'm no expert heh. I won't put the screen shot inline since it's kinda big (1680x1050) but this is the link to it. Telnet works fine: 0000 Zoom Player Home Professional 0001 7.00 1300 1 1000 0 5100,fnExit Connection to host lost. *sigh* I have a post in to ZP as well, but at this point I can't figure out where the problem would lie; ZP or a TCP sending issue. If the data are the same, it doesn't make sense for it to be TCP but then if ZP works fine with telnet and C#, doesn't make sense why it'd fail with just PHP. Oh yea, I also tried VB.NET just to try a different flavor of TCP communicator.. Sub Main() Dim tcpClient As New System.Net.Sockets.TcpClient() On Error Resume Next tcpClient.Connect("lioth", 4769) If Err.Number <> 0 Then Console.WriteLine("Error connecting") : End Else Dim networkStream As NetworkStream = tcpClient.GetStream() If networkStream.CanWrite Then SendCommand("5100,fnExit" + vbCrLf, tcpClient, networkStream, True) Else Console.WriteLine("Error connecting") End If End If End End Sub Function SendCommand(ByVal strCommand, ByVal TcpClient, ByVal NetworkStream, Optional ByVal SkipResponse = False) Dim sendBytes As [byte]() = Encoding.ASCII.GetBytes(strCommand) NetworkStream.Write(sendBytes, 0, sendBytes.Length) If Not SkipResponse Then Dim bytes(TcpClient.ReceiveBufferSize) As Byte NetworkStream.Read(bytes, 0, CInt(TcpClient.ReceiveBufferSize)) Dim returndata As String = Encoding.ASCII.GetString(bytes) If InStr(returndata, Chr(0)) > 0 Then returndata = returndata.Substring(0, InStr(returndata, Chr(0)) - 1) SendCommand = returndata End If End Function Works great. *siiiiigh* hehe
  21. Good ideas, I do have Wireshark but never thought to use that too (doh!) or telnet. I'll give it a whirl thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.