Jump to content

matleeds

Members
  • Posts

    36
  • Joined

  • Last visited

    Never

Everything posted by matleeds

  1. thanks for the help and extensive coding there but my problem has been solved by one line and one function $tomorrow = strtotime("tomorrow"); returns the unix datetime for the next day from midnight....just what the doctor ordered
  2. hi, I have some code that deals with sending out reminders for appointments due the following day. So if today is the 21/3 then only reminders for appointments due on the 22/3 should be sent. Currently this isn't happening... If reminders are sent on 21/3 at 9.50 am, my code adds 24 hours to this datetime and sends reminders due for all appointments that fall bewteen 21/3 9.50am and 22/3 9.49 am. What I want to do is simply send all reminders for appointments that are on the 22/3 exclusive of time. I'm not sure how do this in php, which uses the unix datetime format to mildy complicate issues anhy help or solutions would be massive, thanks.how to $days = time() + (1 * (60 * 60 * 24)); $apts = $db->fetch_all('status = 1 AND time > ? AND time < ?', array(time(), $days));
  3. thanks. how would one use that if ? : statement in this context
  4. Hi, I'd like to know what the most efficient code is for checking the first 2 digits of a string. eg a strings first 2 digits must equal '07' thanks,
  5. Hi, I'm struggling a bit with using a date format and strtotime() if(!empty($_GET['utime'])) { $time = strtotime($_GET['utime']); } utime is supplied in the format dd/mm/yyyy but when I use strtotime() it treats it as mm/dd/yyyy....so 07/12/2011 is taken as 12th Aug rather than 7th Dec..which is the date I want to use. I had a quick ganders through the forums but couldn't find anything specific to this. is there any other attributes to strtotime() that will help, or a similar fucntion or a neat way of swoping my dd/mm/yyyy round before i use strtotime() any help greatly appreciated...
  6. won't break break out of the second foreach then continue with the remaining code in the first foreach before returning to the next iteration? I don't want to continue with the first foreach's remaining code but go straight to the start of next iteration. apologies if i'm wrong i haven't tried your suggestion yet.
  7. Hi, I'd like to know what the best way of breaking out of a nested foreach loop is..but not breaking out of the first foreach ears the code like, foreach ($apts as $apt) { foreach($rdb as $rem) { // Check to see if we've already sent a reminder for this appointment if($apt->id == $rem->appid) { // TODO get out of this foreach and go to the next iterartion of the first foreach } } //rest of 1st foreach code here } is there some syntax i can put at the first foreach eg [here] and reference it within the second foreach continue[here]; or something? thanks,
  8. I've got it sorted thanks. In the do_login fucntion I've add a 'error' variable to the SESSION and pick up on this when the focus returns to the index/form. In short, I've learned that using the SESSION to handle messages fed back to the user/web pages is good practice. thanks fo ryou help tho.
  9. yes I am saying that the submit button name element is stating the name of the do_login function.
  10. the function do_login() is taken from the form <input> tag <p><input type='submit' name='do_login' value='Login'/> </p> and the file ot.php which holds it is included in index.php (see the top part of that code) which is called on the form submit, the $_server['request_uri'] equating to index.php <form action='<?php echo $_SERVER['REQUEST_URI']?>' method='post' > as i mentioned, i inherited this code, so the previous coder was either very good at php or has created a spagatti monster ( coder's rule no. 3 - blame the previous coder where ever possible so, i'm still stumped.
  11. Hi there, I follow the logic in what your says but I'm unsure where I'd put that code? In index.php, somewhere round <?php else: ?> <p>Please login below.</p> <?php ot::include_view('login_form')?> <?php endif; ?> or the login_form.php <p><input type='submit' name='do_login' value='Login'/> </p>
  12. Hi, I've inherited some html/php code (lucky me) and it's been years since i've played with it so I'm quite rusty. Anyway, I have a fairly bog standard login process and wish to simply display some text on the login page if the login detail is invalid and possibly log the error to a log file too. here's the index.php file...the login stuff is at the bottom <?php $dir = dirname(__FILE__); require_once "$dir/ot/ot.php"; ot::include_view('header', array('account' => null)) ?> <html> <head> <title>Welcome to ....</title> </head> <body style="font-size: 14pt; font-family=verdana;"> <div><img src="OTLogo1.bmp"/><h1> Welcome to ...</h1> </div> <?php if (!empty($account)): ?> <div style="border-bottom: 1px dotted #AAA; padding-bottom: 2px; margin-bottom: 10px;"> <div style="float: left"> <?php $mtime = (int)@file_get_contents(otDB_DIR."/updated"); $date = date("d/m/Y", $mtime); $time = date("G:i", $mtime); if ($mtime > 0) { echo "Last Updated $date at $time"; } ?> </div> <div style="float: right">Welcome, <?php echo $account->email;?> - <a href="?page=home">Home</a> - <?php ot::include_view('logout_link')?></div> <div style="clear: both"></div> </div> <?php if (ot::is_admin()) { ot::include_view('admin_page'); } else { ot::include_view('user_page'); } ?> <?php else: ?> <p>Please login below.</p> <?php ot::include_view('login_form')?> <?php endif; ?> </body> </html> here's login_form.php <form action='<?php echo $_SERVER['REQUEST_URI']?>' method='post' > <fieldset> <legend>Login</legend> <p>Email:<br/><input type='text' name='email' /></p> <p>Password:<br/><input type='password' name='pwd' /></p> <!-- <p><input type='submit' name='do_login' value='Login' /> <input type='submit' name='do_reset_password' value='Reset Password' /></p> --> <p><input type='submit' name='do_login' value='Login'/> </p> </fieldset> </form> and here's the function do_login (contained in ot.php..a php function file) public static function do_login(&$err="") { $adb = ot::db('account'); $e = self::post('email'); $p = self::post('pwd', '', false); if (self::post('do_login') && $e && $p) { $ao = self::account_from('email', $e); if ($ao) { if (self::validate_login($e, $p, $ao)) { $_SESSION['id'] = $ao->id; return $ao; } } $err = "Invalid email or password"; return false; } } I'm unclear if the do_login fails as to how that ($err) is fed back to the web pages. Any assistance would be greatly appreciated.
  13. thanks bud. i assumed when the page kind of reloaded after a submit that it would grab the db settings again...but alas not...you live and burn
  14. I'm fairly new to html/javascript/php and a bit confused. I've inherited a partially complete web app that seems to make great use of include()..as in including php files. here's the flow index page loads. index page includes(login.php) user logs in ok index page includes(admin.php) - the admin page, with a link to 'settings' user clicks on settings index page includes (settings.php) - this extracts the settings from a db and displays them on the page within the <form> tag user amends settings and submits form - settings are updated to db ok now, here's the thing after the submit process it looks like the settngs page is reloaded/refreshed? but the original settings are displayed. If i click on the browser 'page refresh' it does refresh with the updated/new settings values. i'd like 2 things, firstly a message box to appear after the submit saying 'settings updated successfully' and the settings to display/retain the updated details. (without having to click on the browser refresh. the solution maybe vey simple (hopefully) but like i say, i'm fairly new to the html/javascript/php side of things if there is a refresh page function i can use..which file name do i use..index.php or settings.php or is there a better way of doing it? ..i don't understand why it doesn't retain the updated details after the form submit? Here's the code for index.php .... <?php $dir = dirname(__FILE__); require_once "$dir/ot/ot.php"; ot::include_view('header', array('account' => null)) ?> <html> <head> <title>Welcome to ....</title> </head> <body style="font-size: 14pt; font-family=verdana;"> <div><img src="OTLogo1.bmp"/><h1> Welcome to ...</h1> </div> <?php if (!empty($account)): ?> <div style="border-bottom: 1px dotted #AAA; padding-bottom: 2px; margin-bottom: 10px;"> <div style="float: left"> <?php $mtime = (int)@file_get_contents(otDB_DIR."/updated"); $date = date("d/m/Y", $mtime); $time = date("G:i", $mtime); if ($mtime > 0) { echo "Last Updated $date at $time"; } ?> </div> <div style="float: right">Welcome, <?php echo $account->email;?> - <a href="?page=home">Home</a> - <?php ot::include_view('logout_link')?></div> <div style="clear: both"></div> </div> <?php if (ot::is_admin()) { ot::include_view('admin_page'); } else { ot::include_view('user_page'); } ?> <?php else: ?> <p>Please login below.</p> <?php ot::include_view('login_form')?> <?php endif; ?> </body> </html> and appointment-settings.php... <?php $settings = ot::db('settings')->fetch_all(); ?> <?php if ($settings): ?> <?php foreach($settings as $s): ?> <?php $smsEnabled = $s->smsEnabled; $emailEnabled = $s->emailEnabled; $smsMessage = $s->smsMessage; $emailMessage = $s->emailMessage; $daysBefore = $s->daysBefore; $spendLimit = $s->smsSpendLimit; ?> <script language="javascript" type="text/javascript"> <!-- function imposeMaxLength(Object, MaxLen) { return (Object.value.length <= MaxLen); } function validateForm() { var x=document.forms["settings"]["smsMessage"].value; var x=document.forms["settings"]["emailMessage"].value; if (x==null || x=="" || y==null || y=="") { alert("Both SMS and Email messages must be filled out."); return false; } } --> </script> <form name="settings" action="<?php echo $_SERVER['REQUEST_URI']?>" method="POST" onsubmit="return validateForm();"> <p>SMS Enabled: <select name="smsEnabled" size="1"> <option value="true" <?php echo($smsEnabled == 1 ? 'selected="selected"' : '');?>>Yes</option> <option value="false" <?php echo($smsEnabled == 0 ? 'selected="selected"' : '');?>>No</option> </select> <p>Email Enabled: <select name="emailEnabled" size="1"> <option value="true" <?php echo($emailEnabled == 1 ? 'selected="selected"' : '');?>>Yes</option> <option value="false" <?php echo($emailEnabled == 0 ? 'selected="selected"' : '');?>>No</option> </select> <p><b>Note:</b> The maximun character length for the SMS message is 160. Please ensure that both the SMS and Email messages include the {patient name} and {date} tags.</b></p> <p>SMS Message: <textarea rows="2" cols="80" name="smsMessage" onkeypress="return imposeMaxLength(this, 160);" ><?php echo $smsMessage?></textarea></p> <p>Email Message: <textarea rows="2" cols="80" name="emailMessage" onkeypress="return imposeMaxLength(this, 160);" ><?php echo $emailMessage?></textarea></p> <p>Days before appointment to send the reminder: <select name="daysBefore" size="1"> <option value="1" <?php echo($daysBefore==1 ? 'selected="selected"' : '');?>>1</option> <option value="2" <?php echo($daysBefore==2 ? 'selected="selected"' : '');?>>2</option> <option value="3" <?php echo($daysBefore==3 ? 'selected="selected"' : '');?>>3</option> <option value="4" <?php echo($daysBefore==4 ? 'selected="selected"' : '');?>>4</option> <option value="5" <?php echo($daysBefore==5 ? 'selected="selected"' : '');?>>5</option> <option value="6" <?php echo($daysBefore==6 ? 'selected="selected"' : '');?>>6</option> <option value="7" <?php echo($daysBefore==7 ? 'selected="selected"' : '');?>>7</option> </select> <p>Spend Limit per month (£): <input type="text" name="smsSpendLimit" size="6" maxlength="5" value="<?php echo($spendLimit);?>" readonly="yes"/></p> <p>Total spend / left this month (£): <input type="text" name="smsSpendLeft" size="6" maxlength="5" value="<?php echo($spendLimit);?>" readonly="yes"/><p> <p><input type="submit" value="Save settings" /><p> </form> <?php endforeach ?> <?php else: ?> <p>Currently unable to access the Settings table. Please contact your customer support</p> <?php endif ?> <?php if(isset($_POST["smsEnabled"])) { $db = ot::db('settings'); if ($db) { $smsEnb = ($_POST["smsEnabled"] == 'true' ? 1 : 0); $emailEnb = ($_POST["emailEnabled"] == 'true' ? 1 : 0); $db->update('smsEnabled=?,emailEnabled=?,smsMessage=?, emailMessage=?, daysBefore=?, smsSpendLimit=?', 'id = ?', array($smsEnb, $emailEnb, $_POST["smsMessage"], $_POST["emailMessage"], $_POST["daysBefore"], $_POST["smsSpendLimit"],1)); } echo "<p>Settings updated</p>"; } ?>
  15. thanks bud, that's done the job nicely!
  16. HI, coming from a .net background and picking up php as I go along, I was wondering what the best way of designing the following task is in php. It's part of an appointmnet reminder app and the admin can amend the message that is sent out. The default message is currently stored in a db table and displayed in a multi line box on the admin web page. for example, "This is a an appointment reminder for *patient name*. You have an appointment on *date* with *customer name*." There's two parts relating to the message process. 1. Allowing the admin to amend the message (but ensuring the *variable markers* are left in tact, so I know where to stick the variables for part 2) 2. When the messages are being sent out (for each loop), inserting the *variables* into the message. I have no problem getting hold of the *name*, *date*, *customer* for each iteration in the for each loop. I'm sure people have done stuff like this before and in .net I would use a stringbuilder object but like i say, I'm not all that groovy on php at the mo. I was thinking of maybe a function that accepts thats passed the message, name, date, customer or something.. thanks
  17. I suspect I’m trying to achieve this in a cack handed way but my HTML/PHP experience is extremely rusty at the moment. I want a button on a web page ‘SEND REMINDERS’. When the user clicks it I want to call do_send_reminders() that lives in ot.php on my webserver. I suspect some sort of javascript is the best option so if you can help on that then greta but I’m also looking at using forms to do it to. Here’s my admin page..the bit about forms is near the bottom... <?php $appointments = ot::db('appointment')->fetch_all('status > 0'); ?> <div style="border-bottom: 1px dotted #AAA"> <?php if ($appointments):?> <table class="appointment_table"> <thead> <th>Patient</th> <th></th> <th>Date</th> <th></th> <th>Treatment</th> </thead> <?php foreach($appointments as $a):?> <?php $p = ot::db('patient')->fetch('id = ?', array($a->pid)); $patient = $p->fname.' '.$p->lname; $t = ot::db('treatment')->fetch('id = ?', array($a->tid)); $treatment = $t->description; $date = date('l F jS, Y', $a->time).' at '.date('g:ia', $a->time); ?> <tr> <td><?php echo $patient?></td> <td> </td> <td><?php echo $date?></td> <td> </td> <td><?php echo $treatment?></td> </tr> <?php endforeach?> </table> </div> <form action='<?php echo $_SERVER['REQUEST_URI']?>' method='post' > <p>Email:<br/><input type='text' name='email' /></p> <p>Password:<br/><input type='password' name='pwd' /></p> <p><input type='submit' name='do_send_reminders' value='Send reminders' /> </form> <?php else:?> <p>There are currently no appointments where reminders have not been sent.</p> <?php endif?> As you can probably guess I’ve just copied the code from the login in page and tried to amend it. I don’t want any text boxes appearing re. email/password. When I click oon the button at the moment nothing appears to happen..the do_send_reminders() isn’t called. thanks.
  18. thanks guys, that's sorted it. I've moved the <html> tags down in the script so I can understand this, even having the standard <html> <head><title> etc tags means that the php parser automaticaly sends a header back to the client browser
  19. line 38 is the 5th'ish line up from the second code snippet...where the header() function is
  20. it's the fourth line down in the first code snippet <?php
  21. hi there, seems like I'm getting a fairly common beginners php error but as I'm using a number of differant files and as I'm not entirley clear on a couple of things I thought I'd tap into the immense php talent on this site here's the error - Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Epointment\index.php:4) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Epointment\ot\views\header.php on line 38 I have an index page that allows a user to log on, the processing go's away and checks the usual stuff then reloads the login page with the user detail or just reloads the login page with the user/password fields blank. This seemed to be working ok until I put my files onto another web server that had output_buffering turned off. here's part of the login page <html> <head><title></title></head> <body> <?php ini_set("display_errors", "1"); error_reporting(-1); $dir = dirname(__FILE__); require_once "$dir/ot/ot.php"; ot::include_view('header', array('account' => null)) ?> // various stuff <p>Please login below</p> <?php ot::include_view('login_form')?> the ot.php file doesn't have any echo's or print_r's etc if that helps?? here's the header.php file.. <?php if (ot::get('do_logout', 0) == 1) { ot::destroy_session(); header("Location: http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}"); exit; } elseif (self::post('do_reset_password')) { ot::do_reset_password($err); echo "$err"; } $adb = ot::db('account'); $account = null; $error = ""; $id = ot::account_id(); if ($id) { $account = ot::account_from('id', $id); $res = ot::do_change_password($account, $err); if ($res) { echo "<p>Password Changed Successfully</p>"; $account = $res; } else if ($err) { echo "<p>Error: $err</p>"; } $res = ot::do_change_email($account, $err); if ($res) { echo "<p>Email Changed Successfully</p>"; $account = $res; } else if ($err) { echo "<p>Error: $res</p>"; } } else { $account = ot::do_login(); if ($account) { header("Location: http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}"); exit; } } ?> here's the ot::do_login function public static function do_login(&$err="") { $adb = ot::db('account'); $e = self::post('email'); $p = self::post('pwd', '', false); if (self::post('do_login') && $e && $p) { $ao = self::account_from('email', $e); if ($ao) { if (self::validate_login($e, $p, $ao)) { //echo "\n"."hit2"; $_SESSION['id'] = $ao->id; return $ao; } } $err = "Invalid email or password"; return false; } } and here's the login_form.php, which is called from ot::do_login from header.php ... <form action='<?php echo $_SERVER['REQUEST_URI']?>' method='post' > <p>Email:<br/><input type='text' name='email' /></p> <p>Password:<br/><input type='password' name='pwd' /></p> <p><input type='submit' name='do_login' value='Login' /> <input type='submit' name='do_reset_password' value='Reset Password' /></p> </form> Any pointers or useful things I've not posted? is this bit of code from above ok? as in I'm doing some php stuff before the header() function gets used? <html> <head><title></title></head> <body> <?php ini_set("display_errors", "1"); error_reporting(-1); $dir = dirname(__FILE__); require_once "$dir/ot/ot.php"; ot::include_view('header', array('account' => null))
×
×
  • 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.