
ScreanerHS
Members-
Posts
3 -
Joined
-
Last visited
ScreanerHS's Achievements

Newbie (1/5)
0
Reputation
-
Fatal error: Call to undefined function seconds2human()
ScreanerHS posted a topic in PHP Coding Help
Hi Guys, I have a strange issue and can't get it to work properly. Here is the code that calculate the time in minutes between two dates with a 5 days work week and 8 hours a day. The script runs properly and calculate the right time in minutes. Here is the code: $begintime = '2013-17-06 12:00'; $endtime = '2013-19-06 10:00'; $start = new DateTime($begintime); $end = new DateTime($endtime); $oneday = new DateInterval('P1D'); $hours = 0; // start at 0 foreach(new DatePeriod($start, $oneday, $end->add($oneday)) as $day) { if($day->format('N') < 5) // weekday, 'N' number days 1 (mon) to 7 (sun) { $hours += 8; // add 8-hr workday } } echo $hours; date_default_timezone_set("Europe/Amsterdam"); $startDate=strtotime($begintime); $endDate = strtotime($endtime); seconds2human(work_hours_diff($startDate,$endDate)); function seconds2human($ss) { $s = $ss%60; $m = floor(($ss%3600)/60); $h = floor(($ss)/3600); $h_total = floor(($ss)/60); mysql_query("UPDATE table SET minutes = '$h_total' WHERE id = '$id'"); echo mysql_error(); return "$h hours, $m minutes, $s seconds, totaal: $h_total Minuten"; } function work_hours_diff($date1,$date2) { if ($date1>$date2) { $tmp=$date1; $date1=$date2; $date2=$tmp; unset($tmp); $sign=-1; } else $sign = 1; if ($date1==$date2) return 0; $days = 0; $working_days = array(1,2,3,4,5,6,7); // Monday-->Sunday $working_hours = array(9.5, 18); // from 9:30 to 18:00 $current_date = $date1; $beg_h = floor($working_hours[0]); $beg_m = ($working_hours[0]*60)%60; $end_h = floor($working_hours[1]); $end_m = ($working_hours[1]*60)%60; //In case date1 is on same day of date2 if (mktime(0,0,0,date('n', $date1), date('j', $date1), date('Y', $date1))==mktime(0,0,0,date('n', $date2), date('j', $date2), date('Y', $date2))) { //If its not working day, then return 0 if (!in_array(date('w', $date1), $working_days)) return 0; $date0 = mktime($beg_h, $beg_m, 0, date('n', $date1), date('j', $date1), date('Y', $date1)); $date3 = mktime($end_h, $end_m, 0, date('n', $date1), date('j', $date1), date('Y', $date1)); if ($date1<$date0) { if ($date2<$date0) return 0; $date1 = $date0; if ($date2>$date3) $date2=$date3; return $date2-$date1; } if ($date1>$date3) return 0; if ($date2>$date3) $date2=$date3; return $date2-$date1; } //setup the very next first working time stamp if (!in_array(date('w',$current_date) , $working_days)) { // the current day is not a working day // the current time stamp is set at the beginning of the working day $current_date = mktime( $beg_h, $beg_m, 0, date('n',$current_date), date('j',$current_date), date('Y',$current_date) ); // search for the next working day while ( !in_array(date('w',$current_date) , $working_days) ) { $current_date += 24*3600; // next day } } else { // check if the current timestamp is inside working hours $date0 = mktime( $beg_h, $beg_m, 0, date('n',$current_date), date('j',$current_date), date('Y',$current_date) ); // it's before working hours, let's update it if ($current_date<$date0) $current_date = $date0; $date3 = mktime( $end_h, $end_m, 0, date('n',$current_date), date('j',$current_date), date('Y',$current_date) ); if ($date3<$current_date) { // outch ! it's after working hours, let's find the next working day $current_date += 24*3600; // the day after // and set timestamp as the beginning of the working day $current_date = mktime( $beg_h, $beg_m, 0, date('n',$current_date), date('j',$current_date), date('Y',$current_date) ); while ( !in_array(date('w',$current_date) , $working_days) ) { $current_date += 24*3600; // next day } } } // so, $current_date is now the first working timestamp available... // calculate the number of seconds from current timestamp to the end of the working day $date0 = mktime( $end_h, $end_m, 0, date('n',$current_date), date('j',$current_date), date('Y',$current_date) ); $seconds = $date0-$current_date; // calculate the number of days from the current day to the end day $date3 = mktime( $beg_h, $beg_m, 0, date('n',$date2), date('j',$date2), date('Y',$date2) ); while ( $current_date < $date3 ) { $current_date += 24*3600; // next day if (in_array(date('w',$current_date) , $working_days) ) $days++; // it's a working day } if ($days>0) $days--; //because we've already count the first day (in $seconds) // check if end's timestamp is inside working hours $date0 = mktime( $beg_h, $beg_m, 0, date('n',$date2), date('j',$date2), date('Y',$date2) ); if ($date2<$date0) { // it's before, so nothing more ! } else { // is it after ? $date3 = mktime( $end_h, $end_m, 0, date('n',$date2), date('j',$date2), date('Y',$date2) ); if ($date2>$date3) $date2=$date3; // calculate the number of seconds from current timestamp to the final timestamp $tmp = $date2-$date0; $seconds += $tmp; } // calculate the working days in seconds $seconds += 3600*($working_hours[1]-$working_hours[0])*$days; return $sign * $seconds; } But when I add this: $query=mysql_query("SELECT * FROM table WHERE closed='yes'"); while($row=mysql_fetch_array($query)){ //The whole code above } I want to do this to change it like this to get all rows together $start = new DateTime($begintime); to $start = new DateTime($row[begin_time]); It give a error: Fatal error: Call to undefined function seconds2human() It only give this error when i place the { and the } above and after the code. But I need it otherwise the $row values doesn't work. The problem isn't the $row[begin_time] value because when I echo it, it works fine. Its just the { } thats buggin me Hope its something simple, but Im busy with it for last 8 hours and still doesn't work. Any idea's to get it fixed? -
Combine rows together in one email instead of single emails
ScreanerHS replied to ScreanerHS's topic in PHP Coding Help
Hi ginerjm, I can't get it to work Here is my full code including the HTML mail script i use. Hopefully you can help me out. I really don't see it anymore Thnx in advance <?php include("include/session.php"); include 'mysql.php'; /** * User has already logged in, so display relavent links, including * a link to the admin center if the user is an administrator. */ if($session->logged_in){ $q = mysql_query("SELECT * FROM MycomDHA_FILIALEN WHERE filiaal = '$session->username'") or die(mysql_error()); while($row = mysql_fetch_array($q)) { extract($row); } require('classes/class.mollie.php'); require_once('Mail.php'); require_once('Mail/mime.php'); if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox']; if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"]) $id = "('" . implode( "','", $checkbox ) . "');" ; $sql="UPDATE table SET afgerond = '".(isset($activate)?'Ja':'Weg')."' WHERE id IN $id" ; $result = mysql_query($sql) or die(mysql_error()); $datum_tijd_afmelden = date( "d-m-Y G:i" ); $sql="SELECT * FROM table WHERE afgerond='Ja' AND id IN $id"; $result=mysql_query($sql); $count2=mysql_num_rows($result); while($rows=mysql_fetch_array($result)){ $to = "$rows[klant_email]"; $from = "sender"; $subject = "subject"; // email header format complies the PEAR's Mail class // this header includes sender's email and subject $headers = array('From' => $from, 'Subject' => $subject); $htmlMessage = <<<PDFMAIL ////////////<MY HTML CODE with $rows[custom_item_nummer], $rows[amount], $rows[description] etc> <<<PDFMAIL $mime = new Mail_Mime(); $mime->setHtmlBody($htmlMessage); // build email message and save it in $body $body = $mime->get(); // build header $hdrs = $mime->headers($headers); // create Mail instance that will be used to send email later $mail = &Mail::factory('mail'); // Sending the email, according to the address in $to, // the email headers in $hdrs, // and the message body in $body. $mail->send($to, $hdrs, $body); } } $sql="SELECT * FROM table WHERE afgerond = 'Nee' AND behandeld = 'Ja' ORDER BY wpos ASC"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Openstaande web orders</title> <link rel="stylesheet" type="text/css" href="style.css" /> <link rel="stylesheet" type="text/css" href="smartDark.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="expires" content="0" /> <meta http-equiv="pragma" content="no-cache" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> <!-- function un_check(){ for (var i = 0; i < document.frmactive.elements.length; i++) { var e = document.frmactive.elements[i]; if ((e.name != 'allbox') && (e.type == 'checkbox')) { e.checked = document.frmactive.allbox.checked; }}} //--> </script> <body> <form name="frmactive" method="post" action=""> <p align="center"><a href='http://mycomwebbestellingen.nl/index.php'><img src='http://mycomwebbestellingen.nl/images/mycom_webbestellingen.png' /></a></p> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td> <table border="0" cellpadding="4" cellspacing="1" class="forumline" align="center" width="1380" height="50"> <tr> <td colspan="2" class="catBottom" nowrap="nowrap" align="left" valign="center"> <span class="postbody"><font color="#9A9999"><b>Locatie: <i>Verstuur Ontvangstbevestiging - <?php echo $filiaal ?></b></i></font></span></td> </tr> </table> <table cellpadding="4" cellspacing="1" width="650" align="center"> <td class="row2" width="130" align="right" valign="top"></td> <td width="644" class="row2"><span class="postbody" valign="top" align="left"> </td> </span></td> </table> <table cellpadding="4" cellspacing="1" class="forumline" align="center" > <td class="row2" width="23" align="center" valign="middle"><span class="postbody"><input type="checkbox" name="allbox" title="Select of Deselect alles" onclick="un_check()";/></span></td> <td class="row2" width="55" align="center" valign="middle"><span class="postbody"><b>BRAM</b></span></td> <td class="row2" width="55" align="center" valign="middle"><span class="postbody"><b>WPOS</b></span></td> <td class="row2" width="135" align="center" valign="middle"><span class="postbody"><b>Order Datum / Tijd</b></span></td> <td class="row2" width="370" align="left" valign="middle"> <span class="postbody"><b>Artikel Omschrijving</b></span></td> <td class="row2" width="20" align="center" valign="middle"> <span class="postbody"><b>#</b></span></td> <td class="row2" width="300" align="left" valign="middle"> <span class="postbody"><b>Klant Naam / Bedrijfsnaam</b></span></td> <td class="row2" width="90" align="left" valign="middle"> <span class="postbody"><b>Mobiel</b></span></td> <td class="row2" width="250" align="left" valign="middle"> <span class="postbody"><b>E-Mail adres</b></span></td> </table> <?php while($rows=mysql_fetch_array($result)){ ?> <table cellpadding="4" cellspacing="1" class="forumline" align="center"> <td class="row2" width="23" align="center" valign="middle"><span class="postbody"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></span></td> <td class="row2" width="55" align="center" valign="middle"><span class="postbody"><?php echo $rows[bram] ?></span></td> <td class="row2" width="55" align="center" valign="middle"><span class="postbody"><?php echo $rows[wpos] ?></span></td> <td class="row2" width="135" align="center" valign="middle"><span class="postbody"><?php echo $rows[aanmaaktijd] ?></span></td> <td class="row2" width="370" align="left" valign="middle"> <span class="postbody">[<?php echo $rows[custom_item_nummer] ?>] <?php echo $rows[beschrijving] ?></span></td> <td class="row2" width="20" align="center" valign="middle"><span class="postbody"><?php echo $rows[aantal] ?></span></td> <td class="row2" width="300" align="left" valign="middle"> <span class="postbody"><?php echo $rows[klant_naam] ?></span></td> <td class="row2" width="90" align="left" valign="middle"> <span class="postbody"><?php echo $rows[mobiel_nummer] ?></span></td> <td class="row2" width="250" align="left" valign="middle"> <span class="postbody"><?php echo $rows[klant_email] ?></span></td> </table> <?php } ?> </form> <br><br> <table border="0" cellpadding="4" cellspacing="1" align="center" width="1380"> <tr> <td colspan="1" nowrap="nowrap" align="left" valign="center"> <span class="postbody"><input name="activate" type="submit" id="activate" value="Verstuur bevestiging" /> <input name="deactivate" type="submit" id="deactivate" value="Verwijder bestelling" onclick="return confirm('Weet je zeker dat je deze regel(s) wilt verwijderen?')"/></span></td> </tr> </table> <?php } else{ header('Location: http://website.com'); } ?> -
Hello guys, I'm new to this board. I just signed up because I have a issue with something I can't get to work. I really don't know how to handle it. I hope someone with amazing PHP skills can help me out. I trust one you guys Ok, I made a script with orders in it from our customers. That placed a order, and the database will be filled. A script show the rows from a database. Every row has a checkbox in front of the row. When you select the checkbox and press submit that specified row will disappear from the list and a automatic email has been sent to the customer that his/her order has been shipped. Everything works fine. The script sends a email and a text message to the customer. Well, sometimes a customer orders 2 or more things. Now the customers get 2 or 3 emails and text message that their products are send out. I want to combine the products in 1 email. So instead of 3 separated emails, I only want the script to send out 1 with all 3 products in it. If a customer only has one product, the script has just to send out a email with 1 product inside. The "wpos" value is the order number, so i need something that check for the "wpos" value and combine all together in 1 email. Do you think something like this is possible? I'm busy to think of a way for 1.5 week now till deep in the night but can't get it to work. Here is my PHP code. <?php include 'mysql.php'; if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox']; if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"]) $id = "('" . implode( "','", $checkbox ) . "');" ; $sql="UPDATE table_name SET closed = '".(isset($activate)?'yes':'no')."' WHERE id IN $id" ; $result = mysql_query($sql) or die(mysql_error()); $sql="SELECT * FROM table_name WHERE closed='yes' AND id IN $id"; $result=mysql_query($sql); $count2=mysql_num_rows($result); while($rows=mysql_fetch_array($result)){ ////////// // script for sending out mime emails and text messages on cellphone taken out // using $rows[values] for reading the database ////////// } $sql="SELECT * FROM table_name WHERE closed = 'no' AND handled = 'yes' ORDER BY wpos ASC"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Openstaande web orders</title> <link rel="stylesheet" type="text/css" href="style.css" /> <link rel="stylesheet" type="text/css" href="smartDark.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="expires" content="0" /> <meta http-equiv="pragma" content="no-cache" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script src="javascript/jquery.toastmessage.js" type="text/javascript"></script> <link href="resources/css/jquery.toastmessage.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> <!-- function un_check(){ for (var i = 0; i < document.frmactive.elements.length; i++) { var e = document.frmactive.elements[i]; if ((e.name != 'allbox') && (e.type == 'checkbox')) { e.checked = document.frmactive.allbox.checked; }}} //--> </script> <body> <form name="frmactive" method="post" action=""> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td> <table border="0" cellpadding="4" cellspacing="1" class="forumline" align="center" width="1380" height="50"> <tr> <td colspan="2" class="catBottom" nowrap="nowrap" align="left" valign="center"> <span class="postbody"><font color="#9A9999"><b>Locatie: <i>Verstuur Ontvangstbevestiging - <?php echo $filiaal ?></b></i></font></span></td> </tr> </table> <table cellpadding="4" cellspacing="1" width="650" align="center"> <td class="row2" width="130" align="right" valign="top"></td> <td width="644" class="row2"><span class="postbody" valign="top" align="left"> </td> </span></td> </table> <table cellpadding="4" cellspacing="1" class="forumline" align="center" > <td class="row2" width="23" align="center" valign="middle"><span class="postbody"><input type="checkbox" name="allbox" title="Select of Deselect alles" onclick="un_check()";/></span></td> <td class="row2" width="55" align="center" valign="middle"><span class="postbody"><b>BRAM</b></span></td> <td class="row2" width="55" align="center" valign="middle"><span class="postbody"><b>WPOS</b></span></td> <td class="row2" width="135" align="center" valign="middle"><span class="postbody"><b>Order Datum / Tijd</b></span></td> <td class="row2" width="370" align="left" valign="middle"> <span class="postbody"><b>Artikel Omschrijving</b></span></td> <td class="row2" width="20" align="center" valign="middle"> <span class="postbody"><b>#</b></span></td> <td class="row2" width="300" align="left" valign="middle"> <span class="postbody"><b>Klant Naam / Bedrijfsnaam</b></span></td> <td class="row2" width="90" align="left" valign="middle"> <span class="postbody"><b>Mobiel</b></span></td> <td class="row2" width="250" align="left" valign="middle"> <span class="postbody"><b>E-Mail adres</b></span></td> </table> <?php while($rows=mysql_fetch_array($result)){ ?> <table cellpadding="4" cellspacing="1" class="forumline" align="center"> <td class="row2" width="23" align="center" valign="middle"><span class="postbody"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></span></td> <td class="row2" width="55" align="center" valign="middle"><span class="postbody"><?php echo $rows[bram] ?></span></td> <td class="row2" width="55" align="center" valign="middle"><span class="postbody"><?php echo $rows[wpos] ?></span></td> <td class="row2" width="135" align="center" valign="middle"><span class="postbody"><?php echo $rows[aanmaaktijd] ?></span></td> <td class="row2" width="370" align="left" valign="middle"> <span class="postbody">[<?php echo $rows[custom_item_nummer] ?>] <?php echo $rows[beschrijving] ?></span></td> <td class="row2" width="20" align="center" valign="middle"><span class="postbody"><?php echo $rows[aantal] ?></span></td> <td class="row2" width="300" align="left" valign="middle"> <span class="postbody"><?php echo $rows[klant_naam] ?></span></td> <td class="row2" width="90" align="left" valign="middle"> <span class="postbody"><?php echo $rows[mobiel_nummer] ?></span></td> <td class="row2" width="250" align="left" valign="middle"> <span class="postbody"><?php echo $rows[klant_email] ?></span></td> </table> <?php } ?> </form> <br><br> <table border="0" cellpadding="4" cellspacing="1" align="center" width="1380"> <tr> <td colspan="1" nowrap="nowrap" align="left" valign="center"> <span class="postbody"><input name="activate" type="submit" id="activate" value="Send notification" /> <input name="deactivate" type="submit" id="deactivate" value="remove order" onclick="return confirm('are you sure you want to remove the order?')"/></span></td> </tr> </table> <?php } else{ header('Location: http://website.com/index.php'); } ?> Hope someone can help me out. If you have questions, please let me know! Thanks in advanced! Marco Pavone