Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation since 09/21/2012 in all areas

  1. 3 points
    I have to agree - do a single query to get the events for the month. I would set up a calendar array of the days in the month (structure: $calendar[wk][wkday][events] ) Loop through the query results and drop the events into their respective week/day slots Loop throught the array to output the calendar DATA TABLE: event +----+----------+---------------------+ | id | name | date_time | +----+----------+---------------------+ | 1 | Event 1 | 2018-11-01 15:00:00 | | 2 | Event 2 | 2018-11-02 12:00:00 | | 3 | Event 3 | 2018-11-11 14:00:00 | | 4 | Event 4 | 2018-11-14 11:00:00 | | 5 | Event 5 | 2018-11-15 14:00:00 | | 6 | Event 6 | 2018-11-16 15:00:00 | | 7 | Event 7 | 2018-11-19 15:00:00 | | 8 | Event 8 | 2018-11-20 16:00:00 | | 9 | Event 9 | 2018-11-23 14:00:00 | | 10 | Event 10 | 2018-11-30 10:00:00 | | 11 | Event 3A | 2018-11-11 16:00:00 | +----+----------+---------------------+ CODE <?php include('db_inc.php'); $db = pdoConnect("test"); // connect to "test" database $curmonth = date('F Y'); // // set up the date range required // $dt1 = new DateTime("first day of this month"); $dt2 = clone $dt1; $dt2->add(new DateInterval('P1M')); $dint = new DateInterval('P1D'); $dper = new DatePeriod($dt1, $dint, $dt2); // // create an array calendar[wk][wkday][events] to store events then output // $calendar = []; foreach ($dper as $d) { $wk = $d->format("W"); $calendar[$wk] = array_fill_keys(range(0,6), []); } // // get the event data for current month // $stmt = $db->query("SELECT id , DATE_FORMAT(date_time, '%D') as day , WEEK(date_time, 1) as wkno , WEEKDAY(date_time) as wkday , DATE_FORMAT(date_time, '%k:%i') as time , name FROM event WHERE YEAR(date_time) = YEAR(CURDATE()) AND MONTH(date_time) = MONTH(CURDATE()) ORDER BY wkno, wkday, time "); // // loop through results and drop events into the array // foreach ($stmt as $ev) { $calendar[$ev['wkno']][$ev['wkday']][] = [ 'day' => $ev['day'], 'time' => $ev['time'], 'name' => $ev['name'] ]; } // // output the array // $tdata = ''; foreach ($calendar as $wk => $wdata) { $tdata .= '<tr>'; foreach ($wdata as $dno => $events) { $cls = $dno > 4 ? "class='we'":""; $tdata .= "<td $cls>"; foreach ($events as $ev) { $tdata .= "{$ev['day']} {$ev['time']} {$ev['name']}<br>"; } $tdata .= "</td>\n"; } $tdata .= "</tr>\n"; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="generator" content="PhpED 18.0 (Build 18044, 64bit)"> <meta name="creation-date" content="11/06/2018"> <title>Sample Calendar</title> <style> table { border-collapse: collapse; font-family: verdana, sans-serif; font-size: 10pt; } th { background-color: #369; color: white; padding: 5px; width: 14%; } th.we { background-color: #358; } td { background-color: #FFE; padding: 5px; } td.we { background-color: #FFC; } </style> </head> <body> <h3>Calendar <?=$curmonth?></h3> <table border='1'> <thead> <tr><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th class='we'>Sat</th><th class='we'>Sun</th></tr> </thead> <tbody> <?=$tdata?> </tbody> </table> </body> </html> OUTPUT
  2. 3 points
    I can't imagine a scenario where the gobbledy-gook of a system you apparently are trying to create would be justified, or possible within your demonstrated engineering capabilities. You are talking about trying to create a system that requires a user to only use one workstation and browser to access your system. I don't know what your system would be doing, but it better be providing literally life saving services, because short of that, nobody is going to put up with the restrictions you have in mind. They are anti-user, and when you make things difficult for users, they stop using your system, or never even stay long enough to pass the entry point. It is damn difficult to get anyone to sign up to use legitimately valuable services, which is why you see so many systems that integrate with facebook, google and twitter, so that you can create your account and trust authentication from those systems to allow access. Furthermore some of your plans reflect an apparent lack of understanding of Internet basics like NAT. In your system, if we were to follow along with your plans, for a large company with perhaps 1000 employees at a particular site, you plan to only allow 1 employee there to use your system. Ditto universities, or even an average household: "Hey there roommate, I just made an account at this site, you should too!" "WTF, the system says I'm banned!" Since you are focused on investigating a client IP, I will say this about IP addresses -- they are reliable at least to the degree that they reflect the tcp socket connection from the client to the server. That information bubbles up to PHP from the IP layer, to the server, and finally to PHP's $_SERVER superglob. The problem is, that a client could have bounced through a variety of gateways, proxy servers or VPN prior to the point that you are finally connected. In many sophisticated hosting environments there are things like load balancers or reverse proxy servers that sit between the client connection and the server which interfere with $_SERVER['REMOTE_ADDR']. Rather than see the client IP, you instead see the IP of the proxy server. If you have that sort of environment, then you can examine $_SERVER['X-Forwarded-For'] or $_SERVER['HTTP_X_FORWARDED_FOR'] variables. These may be arrays with a series of addresses. Again you have the issue that these are provided by the "client" so if it is a proxy server you can depend on at least the most recent address to have been the one that made the TCP socket connection to YOUR proxy server. Other legitimate proxy servers will provide the same data. However, someone who is taking steps to hide their origin is not going to be prevented from obscuring their IP and there is absolutely nothing you can do about it. Almost everyone uses NAT in some form, so the actual person IP address of a workstation on a network is never going to be visible (and would also be useless if it was, since these will be non-routable IP addresses that are shared by hundreds of millions of users). Solutions to the issue of certification and authentication, when people have real and legitimate reasons to solve them, involve cryptography. What you are trying to do can be accomplished using X.509 certificates which have support built into browsers. In a nutshell, at account creation time you would generate an client certificate for that user, installing that into your server, and then providing the signed cert back to them in a specific header (application/x-x509-user-cert ). This will cause the browser to prompt the user to install the cert into their browser. If they accept you know have a reliable way of identifying a specific user. At that point, whenever they connect (must be under SSL) you'll be able to authenticate them back to your system via that particular certificate. Those without a client certificate will be unable to connect. You can think of this as white listing. It is highly effective but is typically used only in environments where the system knows in advance who their allowed users are. Trying to use it in a public facing website with an unknown user base is something you just don't see because the benefits of trying to do this far outweigh the tolerance that people have for a system that has that degree of odious overhead and invasion of their privacy. In conclusion: The types of things you are obsessed with are all edge case items. No quality system begins with the premise that the #1 goal is to try and catch and outsmart an imaginary horde of people attacking your site for reasons unknown. This started as a specific thread about the contents of $_SERVER variables and then escalated into fairly delusional territory, with a dash of your personal Devshed drama thrown in. And let's just be clear about one thing: If you ever bring up your personal issues regarding your Devshed access again, which are irrelevant to this community, then your access to this community will end as well. It's off topic, it's a waste of people's time and efforts here, and it's rude. I just want to be clear that I won't tolerate it again.
  3. 2 points
    If this is a repetitive project that is going to build all of the mentioned arrays every time it is executed, perhaps you should consider not having to re-build your second array by using the SKU as the index value of the first array and avoid creating the 2nd array. Change this: $product_table[] = ['SKU' => $sku, 'Label' => $attribute_name, 'Value' => $term_obj->name ]; to: $product_table[$sku][] = ['Label' => $attribute_name, 'Value' => $term_obj->name ];
  4. 2 points
    You may find my reply to one of your previous topics of interest here. (I sometimes ask myself why we bother)
  5. 2 points
    Use absolute URLs <link rel="shortcut icon" href="/images/favicon.ico.png"> <a href="/index"> <img src="/images/logo.PNG" alt="logo" /> I don't understand how so many people can be unaware of them.
  6. 2 points
    OK, I've donned my red costume and white beard. Here's an example of displaying more or less text Data CREATE TABLE `product` ( `product_id` int(11) NOT NULL AUTO_INCREMENT, `description` text, PRIMARY KEY (`product_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `product` (`description`) VALUES ('Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci. Aenean nec lorem.'), ('In porttitor. Donec laoreet nonummy augue. Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc. Mauris eget neque at sem venenatis eleifend. Ut nonummy. Fusce aliquet pede non pede. Suspendisse dapibus lorem pellentesque magna. Integer nulla. Donec blandit feugiat ligula. Donec hendrerit, felis et imperdiet euismod, purus ipsum pretium metus, in lacinia nulla nisl eget sapien.'), ('Donec ut est in lectus consequat consequat. Etiam eget dui. Aliquam erat volutpat. Sed at lorem in nunc porta tristique. Proin nec augue. Quisque aliquam tempor magna. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc ac magna. Maecenas odio dolor, vulputate vel, auctor ac, accumsan id, felis. Pellentesque cursus sagittis felis.'); Example code <?php include('db_inc.php'); $db = pdoConnect("test"); // connect to "test" database // // this bit handles the AJAX request to get the full or partial description // if (isset($_GET['ajax'])) { $stmt = $db->prepare("SELECT description FROM product WHERE product_id = ? "); $stmt->execute( [ $_GET['id'] ] ); $descrip = $stmt->fetchColumn(); switch ($_GET['ajax']) { case 'more': $less = "<span class='less' data-id='{$_GET['id']}'> (less)</span>"; exit($descrip.$less); // send back the description in the ajax response case 'less': $words = explode(' ', $descrip); $partial_descrip = join(' ', array_slice($words, 0, 25)); $more = "<span class='more' data-id='{$_GET['id']}'> ...more</span>"; exit($partial_descrip.$more); } } // // select the product details from the table // $res = $db->query("SELECT product_id , description FROM product "); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="generator" content="PhpED 18.0 (Build 18044, 64bit)"> <title>Example</title> <style type='text/css'> .descrip { font-family: verdana, sans-serif; font-size: 10pt; margin-left: 50px; width: 50%; } .more, .less { color: blue; cursor: pointer; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type='text/javascript'> $().ready( function() { $(".more").click( function() { var id = $(this).data('id') var target = $(".descrip[data-id="+id+"]") // find descrip div with matching data-id $.get ( "", // send request to "self" { "ajax" : "more", "id" : id }, function(resp) { target.html(resp) // put returned description in target div enableLess() }, "TEXT" ) }) }) function enableLess() { $(".less").click( function() { var id = $(this).data('id') var target = $(".descrip[data-id="+id+"]") // find descrip div with matching data-id $.get ( "", // send request to "self" { "ajax" : "less", "id" : id }, function(resp) { target.html(resp) // put returned description in target div }, "TEXT" ) }) } </script> </head> <body> <?php // // display the data, putting description in its own div // foreach ($res as $row) { $words = explode(' ', $row['description']); $partial_descrip = join(' ', array_slice($words, 0, 25)); // show first 25 words of description $more = "<span class='more' data-id='{$row['product_id']}'> ...more</span>"; echo "<div class='product'> <h3>Product {$row['product_id']}</h3> <div class='descrip' data-id='{$row['product_id']}'> <h4>Description</h4> $partial_descrip $more </div> </div>\n"; } ?> </body> </html> Sample output
  7. 2 points
    OR if you use the same named hidden field for all the forms, 'action' for example, each with a unique value, you can eliminate any isset() tests for that field since it will be set if the request method is post.
  8. 2 points
    So we all (most of us) know some CSS. You might not consider yourself a web designer, be fluent with all the popular libraries, but you know your way around how to do it. Like if you want to make something bold you could inline it <span style="font-weight:bold;">An important statement</span> but you're smarter and you know you should .bold { font-weight: bold; } <span class="bold">An important statement</span> A trivial example, of course, but it demonstrates how you should use CSS. Right? No. God damn *#(*^y$&#ing NO. So maybe it's a bad example. People don't actually do that. Okay. Let's look at some official Bootstrap examples instead. <button type="button" class="btn btn-lg btn-default">Default</button> No. <table class="table table-striped"> Stop that. <ul class="list-group"> <li class="list-group-item">Cras justo odio</li> Dude. What's the problem here? You're restating the obvious! I know that button is a button. It's got #*^(ing "button" right in the (*^-@$ markup. Ooh, it's a LARGE button. Wow! And hey, that table has stripes? Amazing! And you mean to tell me that UL is a list and the LI is an item? You're blowing my mind! You're also DOING IT WRONG. The power behind CSS is (a) not having to tell the browser that yes, in fact, that button really is a button, and (b) not having to say the same thing over and over again in different places. And that is where Bootstrap fails miserably. You want to create a button? Go ahead. Create the button. Then throw a few classes at it so it looks the way you want. Want another button? Create another button and throw classes at that one too. Created a button and it doesn't look right? Oh damn, you forgot one of the classes you have to include. Ha ha, oops. "But that's how CSS should be used!" No. You're all missing the (*@#*^ing point and making everything hard on yourself and the people who have to deal with your crap. What if I want to add a dropdown list of items? What should I do? The page already has a couple dropdowns on it so I know the styling is in place. I'll add a simple <select> and... nope, looks like a plain list. No styling applied. What happened? What happened is that I didn't apply the handful of classes necessary to make the list appear like the damn list it should already be. What happened is that I forgot I have to add in the presentation aspects to my HTML. And that's what this whole stupid thing boils down to: people can't shift their mindset away from the presentation, and while they know not to mix presentation with markup they've not noticed that all they did was trade one syntax for another. The problem is still (@^$ there. "Oh, right, yeah, if you're so smart then how would you do it?" Thank you for asking. You want a button. You want a large button. You want a large button that draws peoples' eyes to it because it's the button they probably want to use and so it's the default. That's presentation. Forget about presentation. You want a default button. That's it. That's all you should have to care about. <button type="button" class="default">Default</button> Done. "But no, it doesn't look the way I want!" I don't give a damn how you want it to look. I want to know what the button means. What is the significance behind the button. What does it represent. Because ultimately that's what the HTML markup needs to concern itself with. Write semantic markup and leave out the presentation crap because it has no place in the document. "Oh, so you think we shouldn't have any CSS at all or what?" Take those words out of my mouth before I cram them back down yours. button { /* make it look like a nice button */ } button.default { /* blue or whatever */ } There. Now the presentation is accounted for in the @(!^)$ place where it should be: CSS. And if I want to add another default button somewhere I don't have to look up the Bootstrap reference because I don't remember which 5 classes are relevant. Default button? Default button. The only way this could improve is if HTML added a way to actually identify the default button of a form, in which case that class=default goes right out the damn window and the CSS targets that new attribute or whatever it is instead. "Noo, it's not a large button!" Alright. Fine. Let me take a deep breath before I have to deal with you. So. Why do you want it to be large? Don't give me some stupid reason like "because I want it to be large". What is the reason behind making it large? What decision process did you go through in your head that resulted in the button needing to be larger? Why is the normal size for buttons not appropriate? Maybe the form is a modal and you want larger buttons? Okay. Did you mark the form as modal? Because that's the first thing you have to do. <form class="modal"> form.modal button { /* larger */ } And done. Problem solved. Problem solved in a way that keeps the appearance of the button separate from the markup of the button. Want to add another button to the modal? Go on. Add another stupid button. One that doesn't require any classes just because it's supposed to be larger. What you might be able to realize here is that now I've established a rule saying "buttons in modal forms are larger". And it applies everywhere you have a modal form. If you make another modal form then magically the buttons are larger there too! And without having to find that first place you had that one modal form, what page was that again, oh right, over here, now what classes and CSS files did I have to use for it to make it look that way, oh right, those classes. How about a striped table? Why is it striped? Because it's a table that will grow vertically and has enough data in its columns that people need help scanning through them? So what you're telling me is that the table is, say, "dense"? <table class="dense"> table.dense > tbody > tr:nth-child(odd) { /* striped */ } Somehow I'm able to rub a couple brain cells together and end up with a way of identifying the table for what it is and not what I want it to look like on the page. How about a regular list? Nothing special? <ul> <li>Cras justo odio</li> Nothing (*&^!@ special. Now when I come along, I can write markup into your fancy page you spent a couple days tweaking until it looked oh so pretty, and I don't have to run off to the kitchen where I can cool my heels instead of planning your "accidental" death because I can write simple, logical, and minimal HTML that represents what I'm adding without having to fire up five different browsers to see that I got all the required classes. What's more, if someone decides that modal dialogs on mobile devices need to look a little different, I don't have to spend a day searching the codebase for anything modal because the work has gone from "go fix all the modal dialogs to use this new CSS class someone wrote" to "apply media queries to adjust the existing modal dialog to better suit mobile screens". This isn't damn rocket science. I know you web designers had a hard time in college with your liberal arts degree and that's it's so unfair you have to work with computer graphics instead of living in a loft painting bowls of fruit all day, but surely even you are smart enough to understand these principles. Stop thinking with your eyes and start thinking with your brain. And now I go back to work. Dealing with stupid crap. That I put off by ranting about it here.
  9. 2 points
    I found it here Or did you have something more like this in mind? Save this code as "stave.svg" <svg width="1000" height="200" viewBox="0 0 1000 200"> <defs> <style type="text/css"> .trebleclef { fill: black; font-size: 50pt; } .bassclef { fill: black; font-size: 40pt; } .curly { fill: black; stroke: none; font-size: 110pt; font-weight: 100; } .stave { stroke-width: 1px; stroke: gray; fill: none; } </style> </defs> <!-- treble --> <line x1='40' y1='30' x2='960' y2='30' class='stave' /> <line x1='40' y1='38' x2='960' y2='38' class='stave' /> <line x1='40' y1='46' x2='960' y2='46' class='stave' /> <line x1='40' y1='54' x2='960' y2='54' class='stave' /> <line x1='40' y1='62' x2='960' y2='62' class='stave' /> <text x='44' y='65' class='trebleclef'>&#x1D11E;</text> <!-- bass --> <line x1='40' y1='130' x2='960' y2='130' class='stave' /> <line x1='40' y1='138' x2='960' y2='138' class='stave' /> <line x1='40' y1='146' x2='960' y2='146' class='stave' /> <line x1='40' y1='154' x2='960' y2='154' class='stave' /> <line x1='40' y1='162' x2='960' y2='162' class='stave' /> <text x='44' y='165' class='bassclef'>&#x1D122;</text> <!-- stave ends --> <text x='-20' y='132' class='curly'>{</text> <path d="M 40 30 L 40 162" class='stave' /> <path d="M 960 30 L 960 162" class='stave' /> </svg> Then, in your html <div><?php include 'stave.svg'?></div> <div><?php include 'stave.svg'?></div> <div><?php include 'stave.svg'?></div> Which should give you
  10. 2 points
    Commencing with test_config.txt as # interface eth0 subnet 10.0.10.0 netmask 255.255.255.0 { } host cm-test1 { hardware ethernet 78:8d:f7:2b:bc:79; fixed-address 172.17.12.80; filename "srv-050.cfg"; } host cm-test2 { hardware ethernet 5c:35:3b:4d:73:4b; fixed-address 172.17.13.119; filename "srv-042.cfg"; } host cm-instrumenti { hardware ethernet 78:8d:f7:2b:bc:79; fixed-address 172.17.12.80; filename "srv-050.cfg"; } host cm-nimonmehmetaj { hardware ethernet 5c:35:3b:4d:73:4b; fixed-address 172.17.13.119; filename "srv-042.cfg"; } This is one way $unwanted = [ 'cm-instrumenti', 'cm-nimonmehmetaj' ]; // unwantedt host names $text = file_get_contents('test_config.txt'); $config = array_map('trim',explode('}', $text)); $new_config = array_filter($config, function ($v) use($unwanted) { foreach ($unwanted as $name) { if (strpos($v, $name)!==false) return false; // remove unwanted elements } return $v!=''; // remove blank entries }); file_put_contents('new_config.txt', join("\n}\n", $new_config) . "\n}\n"); giving new_config.txt as # interface eth0 subnet 10.0.10.0 netmask 255.255.255.0 { } host cm-test1 { hardware ethernet 78:8d:f7:2b:bc:79; fixed-address 172.17.12.80; filename "srv-050.cfg"; } host cm-test2 { hardware ethernet 5c:35:3b:4d:73:4b; fixed-address 172.17.13.119; filename "srv-042.cfg"; }
This leaderboard is set to New York/GMT-04:00
  • Newsletter

    Want to keep up to date with all our latest news and information?

    Sign Up
×

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.