Jump to content

rich_traff

Members
  • Posts

    44
  • Joined

  • Last visited

Everything posted by rich_traff

  1. i dont have access to the php.ini file and currently am unable to contact the host admin. phpinfo() gives the following; SMTP - localhost - localhost smtp_port - 25 - 25 if that helps?
  2. I tried setting error reporting by placing it in with the mail part of the script <?php $email_from = "Example"; ini_set("sendmail_from", $email_from); ini_set('error_reporting', E_ALL); $headers = "From: $email_from"; No errors showed though, would it make a difference where i placed it? Also i looked in the error_log file from the site root but found nothing there. the last entry was from a few days ago and detailed some missing css files, there's nothing recent that suggests anything to do with mail or the script i have written. Am still to try the mail log script you suggested
  3. Hi, i've written a script that use's mail() in it to send some information. I've tested this on my own server and it works fine, however when i put it onto a clients server the email does not come through. Here is the email part of the script <?php $to = "me@example.com"; $subject = "subject"; $body = "Body of email"; $email_from = "Example"; ini_set("sendmail_from", $email_from); $headers = "From: $email_from"; if (mail($to, $subject, $body, $headers)) { echo("<p>Your email has been sent</p>"); } else { echo("<p>An error has occured</p>"); } So on my own server, the script runs, the message "Your email has been sent" shows and i receive the email. On my clients server, the script runs, the message "Your email has been sent" still shows, i do not get an error message, but the email never gets received. So im assuming it must be a config issue with their server… A problem though is that i only have ftp details for it and currently no way of contacting the web host, i don't even know where its hosted, all i have is a host ip, username and password. So, i am looking for some advice on A) what i should be looking for to figure out why the email is not getting through B) how to go about finding that info? C) options for improving the script that will ensure the email is sent/received.. Can anyone offer any advice?
  4. Yeah i see you point, thanks for tip, il rethink the approach...
  5. I have 2 websites, a companies main website written in PHP and a web application they have purchased written in aspx (main site) www.example.com (web app) www.webapp.com/login.aspx?CompanyName=example The client wants people to be able to login from their main website which then redirect to the webapp (which will be styled like their branding) without the customer realising they have left the main site. I thought i may be able to achieve this with a simple include from a page within the main site such as; <?php // www.example.com/software include"http://www.webapp.com/login.aspx?CompanyName=example"; ?> This pulls in the login page fine, however when you try to login it does not redirect, it gives a 404 error as it trys to open this URL http://www.example.com/software/login.aspx?CompanyName=example Is there a way of pulling in the necessary html from the aspx site to provide a login box in my clients main site but then have it redirect to the correct aspx page (on the aspx site)? I have thought about using an iframe, but that wont redirect to the webapp upon login, but just keep everything withing the iframe thanks for any advice...
  6. I have this function that does 3 things; 1) determines how many modules are published to a certain row in a joomla template layout. 2) sets the module width accordingly 3) outputs the html The modules are labeled A through H, what i want returned is the html for every module position to be published, at the moment it only returns the last pass of the foreach loop - so it outputs the html for module H, if i unpublished module H it will only show module G etc… I know it makes sense for that to be happening from looking at the code as it is now but i don't know how to change it so it does what i need… So, i want $result, to return all the html from each pass of the second foreach loop, can anyone help? <?php function modWidth3($row, $siteWidth, $mod) { $published = 0; $array = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'); // Calculates how many modules are published to row foreach($array as $position) { if($mod->countModules('topRow' . $row . '_' . $position)) { $published = $published+1; } } // Sets module width according to number published $pixelsUsed = $published * 15; $pixelsLeft = $siteWidth - $pixelsUsed; $modWidth = $pixelsLeft / $published; $result =''; // Outputs published modules foreach ($array as $position) { if($mod->countModules('topRow' . $row . '_' . $position)) { $result =' <div id="topRow' . $row . '_' . $position.'" class="modRow" style="width:'.$modWidth.'px;"> <jdoc:include type="modules" name="topRow' . $row . '_' . $position.'" style="xhtml" /> </div>'; } } return $result; }
  7. As a side point, you may notice that im running a foreach loop twice, once to find out how many of the modules are published then again to output the html, on the second loop the module width is inserted (which depends on how many modules are published - ascertained from the first loop) I don't know if its possible to streamline this and only have to run 1 foreach loop but would appreciate any ideas...
  8. Hi, can anyone tell me how to turn this code into a function so i can reuse it again and again… It is for a joomla template file and calculates the widths of modules depending on how many are published to a certain row and what the site width is set at in the template parameters. So there is a row of module positions (rows increment in numbers 1, 2, 3 etc) each specific module has a letter (A, B, C etc) The code checks to see how many modules are published to that row and sets the width of each module accordingly, then outputs the div html. I am using an include at the moment like so <div id="topRow1_wrap"> <?php $row = 1; include 'includes/moduleWidths.php' ?> <div class="clear"></div> </div> with the code <?php $published = 0; $array = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'); // Calculates how many modules are published to row foreach($array as $position) { if($this->countModules('topRow' . $row . '_' . $position)) { $published = $published+1; } } // Sets module width according to number published $pixelsUsed = $published * 15; $pixelsLeft = $siteWidth - $pixelsUsed; $percentageLeft = ($pixelsLeft / $siteWidth) * 100; $modWidth = $percentageLeft / $published; // Outputs published modules foreach ($array as $position) { if($this->countModules('topRow' . $row . '_' . $position)) {?> <div id="<?php echo'topRow' . $row . '_' . $position?>" class="modRow" style="width:<?php echo $modWidth;?>%;"> <jdoc:include type="modules" name="<?php echo'topRow' . $row . '_' . $position?>" style="xhtml" /> </div> <?php } } The values currently being used from the index.php are $siteWidth $row I want to turn this into a function and call it from the index.php file, but im unsure how… i tried this, but it didn't work, can anyone help? <?php require_once 'includes/moduleWidths.php'; ?> <div id="topRow1_wrap"> <?php $row = 1; modWidth($row, $siteWidth) ?> <div class="clear"></div> </div> <?php function modWidth($row, $siteWidth) { $published = 0; $array = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'); // Calculates how many modules are published to row foreach($array as $position) { if($this->countModules('topRow' . $row . '_' . $position)) { $published = $published+1; } } // Sets module width according to number published $pixelsUsed = $published * 15; $pixelsLeft = $siteWidth - $pixelsUsed; $percentageLeft = ($pixelsLeft / $siteWidth) * 100; $modWidth = $percentageLeft / $published; // Outputs published modules $data = foreach($array as $position) { if($this->countModules('topRow' . $row . '_' . $position)) {?> <div id="<?php echo'topRow' . $row . '_' . $position?>" class="modRow" style="width:<?php echo $modWidth;?>%;"> <jdoc:include type="modules" name="<?php echo'topRow' . $row . '_' . $position?>" style="xhtml" /> </div> <?php } } return $data; }
  9. Tell me about it... At least its only one parameter thats changed, i've had a lot worse before. Your rewrite works perfectly, thanks again for your time
  10. Hi, i realise this is an old thread now but i have to make a change to the solution and am not sure how to do it so thought id repost here rather than start a new topic I am using this function supplied earlier in this thread by mjdamato <?php function getDateParts($startDate, $endDate) { //Normalize dates for 12noon to ensure full days calulation $startDate = strtotime(date("d F Y", $startDate) . " 12:00pm"); $endDate = strtotime(date("d F Y", $endDate) . " 12:00pm"); //Initialize array for return variable $return['totalWeeks'] = 0; $return['singeWeekendDays'] = 0; $return['singleWeekdays'] = 0; //Calculate total days, weeks, and remaining days $totalDays = round(($endDate-$startDate) / (60*60*24)) + 1; $return['totalWeeks'] = floor($totalDays/7); $remianingDays = $totalDays - ($return['totalWeeks']*7); //Determine types of remaining days while($remianingDays>0) { if(date("N", $endDate)>5) { $return['singeWeekendDays']++; } else { $return['singleWeekdays']++; } //Change end date to prev date, and reduce remaining days $endDate = strtotime(date("d F Y", $endDate) . " -1 day"); $remianingDays--; } return $return; } which takes a start date and end date and returns the number of full weeks (any 7 days), the remaining weekend days and week days. It currently counts any 7 day period as a week, so tues - mon is a valid week. The parameters have now changed though and i need to only count mon - sun as a full week. So if someone booked from wed to the following following fri, it should return 2 weekend days and 8 week days Where as if someone books from sun to the following tues, returned should be 1 week, 1 weekend day and 2 week days So, i need to input any start and end date and return; The number of full weeks (mon - sun) The number of remaining weekend days (sat, sun) The number of remaining week days (mon - fri) Now, i assume a way to adapt the function to give the full weeks would have something to do with counting any 7 day periods from the first date("N") to =1, then work out the remainders before and after this, but am not sure if this would be correct and even less sure how to implement it… can anyone help?
  11. Apologies… i didn't think that through before making my last post. I had in my head it would just be the query that would change, but the function would remain, clearly not so… You've given me more than enough help on this though and i really do appreciate it!
  12. @mjdamato, thanks so much for your help on this setting the if statement to this corrected the problem if ( datesAvailable($car_id, $start_date_unixTime, $end_date_unixTime)) Now, theres just one other thing, if you would be so kind... You mentioned the most efficient solution would be to check for a conflict in the db with the query itself, how would i go about that?
  13. ok, i think this is nearly there but have another issue which i think is just due to my inexperience using functions and not really knowing how to use them together properly… this code needs to be part of a larger function that checks a few things before returning a final output. I've taken the last rewritten function you provided and tested it on its own and it works no problems (the debugging helped me understand more so thanks for that) Im not really sure how to include functions within other functions though (and got errors whilst trying) so used an include. When i remove the redirects (from the controller file) your code echo's out everything you expect it to, correct date, returns true or false correctly etc. When i try to take the return value and base an if statement on it though (in the controller) it is always set to true… This is the controller file function <?php function points_spend() { // does stuff here $car_id = JRequest::getInt('id', ''); include 'bookings_overlap.php'; if ( $datesAvailable = true) { $this->setRedirect(JRoute::_('index.php?option=com_carbooking&id=' . $row->id . '&view=single'), 'The dates are true' . $datesAvailable); } elseif ( $datesAvailable = false) { $this->setRedirect(JRoute::_('index.php?option=com_carbooking&id=' . $row->id . '&view=single'), 'The dates are false' . $datesAvailable); } // does more stuff here } ?> and the included file <?php //Returns true/false based upon whether the requested dates conflict //with the already booked dates in the DB for the requested car id function datesAvailable($car_id, $start_date_unixTime, $end_date_unixTime) { /* $query = "SELECT start_date, end_date FROM #__carbooking_bookings WHERE car_id = '$car_id'"; $db->setQuery($query); $bookedDates = $db->loadRowList(); */ //Hard coded test array $bookedDates = array( array ('07/20/2011', '07/21/2011'), array ('08/16/2011', '08/17/2011') ); foreach($bookedDates as $key => $dates) { list($bookedStart, $bookedEnd) = $dates; if ($start_date_unixTime < strtotime($bookedEnd) && $end_date_unixTime > strtotime($bookedStart)) { //Conflicts detected, return false return false; } } //No conflicts detected, return true return true; } $datesAvailable = datesAvailable($car_id, $start_date_unixTime, $end_date_unixTime); ?> Can you tell me where im still going wrong with this? btw - i fully appreciate your time spent on this, i know i've already asked a lot...
  14. Yes, you were correct in your assumption... at least you were correct in assuming that i assumed the array would be formatted that way... turns out i should have checked more thoroughly...
  15. @mjdamato, ok - i understand your logic now and appreciate it is sound. What i have found is there is a problem with my array itself… After doing print_r it displayed '1' and nothing else… I should have done this first as i was copying the results of the query from another function elsewhere in the script (although it is the exact same query) Even when i insert the array manually though, it still shows '1' This is the exact code i am using right now… (it is a joomla component btw) $car_id = JRequest::getInt('id', ''); /* $db->setQuery("SELECT start_date, end_date FROM #__carbooking_bookings WHERE car_id = '$car_id'"); $bookedDates = $db->loadRowList(); */ $bookedDates = array( array ('07/20/2011', '07/21/2011'), array ('08/16/2011', '08/17/2011') ); $datesUnavailable = 0; foreach($bookedDates as $key => $dates) { //Create variables for rrecord start/end dates list($bookedStart, $bookedEnd) = $dates; if ($start_date_unixTime < strtotime($bookedEnd) && $end_date_unixTime > strtotime($bookedStart)) { $datesUnavailable = 1; } } if ($datesUnavailable = 1) { $this->setRedirect(JRoute::_('index.php?option=com_carbooking&id=' . $row->id . '&view=single'), 'Your selection falls over another booking, dates Unavailable: ' . $datesUnavailable . ', start date: ' . $start_date_unixTime . ', end date: ' . $end_date_unixTime . ', array: ' . print_r($bookedDates) . ', car id: ' . $car_id); } The message displayed on redirect ie from this $this->setRedirect(JRoute::_('index.php?option=com_carbooking&id=' . $row->id . '&view=single'), 'Your selection falls over another booking, dates Unavailable: ' . $datesUnavailable . ', start date: ' . $start_date_unixTime . ', end date: ' . $end_date_unixTime . ', array: ' . print_r($bookedDates) . ', car id: ' . $car_id) gives exactly this; Your selection falls over another booking, dates Unavailable: 1, start date: 1312844400, end date: 1312930800, array: 1, car id: 1 Showing $datesUnavailable is being set to 1 the start and end dates are formatted correctly the array however, instead of being this; Array ( [0] => Array ( [0] => 07/20/2011 [1] => 07/21/2011 ) [1] => Array ( [0] => 08/16/2011 [1] => 08/17/2011 ) ) is this; 1 do you know why this might be happening?
  16. apologies if i wasn't clear which dates were which. Im still getting invalid results though... I've been checking through the rest of my code to make sure there are no errors before getting to this point and cant find any... Here is a working example of the dates; Array of already booked dates: Array ( [0] => Array ( [0] => 07/20/2011 [1] => 07/21/2011 ) [1] => Array ( [0] => 08/16/2011 [1] => 08/17/2011 ) ) dates selected by user: start date: 1312844400, end date: 1312930800 // ok - should set $dateUnavailable to false start date: 1313362800, end date: 1313622000 // not aloud - should set $dateUnavailable to true currently, all date entries are resulting in $dateUnavailable being set to true
  17. Hi, im afraid that hasn't solved the problem, $dateUnavailable is still being set to true no matter what… Firstly Thanks for pointing that out Im not sure i follow here… Both record dates are less than the target end date, but neither of them are greater than the target start date so surely the if statement in my original code would not be true if (strtotime($recStart) < $end_date && strtotime($recEnd) < $start_date); Sorry but i don't think this is correct as it would not stop someone selecting new dates that fall either side of the record dates… Perhaps i've not been very clear in my original post, to reiterate the problem… I have a calendar that lets a user book out cars by selecting a start and end date for the booking. It currently shows all the days the car is already booked out on and will not let you select those days. There is nothing to stop someone selecting a start date before one booking and an end date after it though which would go through another booking, which is what i need to stop happening. ie - there is a booking for the 7th-8th, i need to stop someone selecting the 6th and 9th as start/end dates and creating a booking that overlaps the first...
  18. Hi, can anyone tell me whats wrong with this code? i have an array of arrays that contain start and end dates of bookings as shown here taken from mysql; Array ( [0] => Array ( [0] => 2011-05-26 [1] => 2011-05-28 ) [1] => Array ( [0] => 2011-05-28 [1] => 2011-05-30 ) [2] => Array ( [0] => 2011-06-13 [1] => 2011-06-24 ) ) ie; booking 1: start = 2011-05-26, end = 2011-05-28 booking 2: start = 2011-05-28, end = 2011-05-30 booking 3: start = 2011-06-13, end = 2011-06-24 i then have a new start_date and end_date and i need to check that none of the dates from the array fall between the 2 new dates, new dates being unix timestamp. $start_date // unix timestamp $end_date // unix timestamp $checkDates // array (as above) $dateUnavailable = 0; foreach( $checkDates as $key => $date) { if (strtotime($date) > $start_date && strtotime($date) < $end_date); { $dateUnavailable = 1; } } no matter what dates are used, $dateUnavailable is always set to 1... Can anyone tell me what im doing wrong here or suggest a better solution that works?
  19. thanks GuiltyGear, you've saved me a lot of searching much appreciated
  20. I have sets of date ranges stored as yyyy-mm-dd example; start date: 2011-05-26 end date: 2011-05-28 i have these stored in an array of arrays, print_r gives this; Array ( [0] => Array ( [0] => 2011-05-26 [1] => 2011-05-28 ) [1] => Array ( [0] => 2011-05-28 [1] => 2011-05-30 ) [2] => Array ( [0] => 2011-06-13 [1] => 2011-06-24 ) ) I need to rearrange the date format to mm/dd/yyyy whilst keeping the order of the array intact. Note changing the '-' to an '/' is important. I then need to be able to echo the date ranges separated by a comma, so the above array becomes 05/26/2011-05/28/2011, 05/28/2011-05/30/2011, 06/13/2011-06/24/2011 can anyone help with this?
  21. Hi Mjdamto, i found your code the easiest to understand so have implemented it into my script. Fully tested it does exactly what i need. Thanks very much
  22. Hi Teynon, Mjdamto Thanks to both of you for contributing to this, i really appreciate your time, you've helped me out a lot. Im unable to work on this today but will look at all the examples over the weekend and let you know which works out best.
  23. Teynon, I've included a way of finding out the day of the week and incorporated your code into my script but am getting differing results, not sure if i've misinterpreted how to implement it though… This is the full code so far… $start_date // = dd/mm/yyyy $end_date // = dd/mm/yyyy list($day,$month,$year) = explode("/", $start_date); $start_date_unixTime = mktime(0,0,0,$month,$day,$year); // reorders date then uses strtotime to find day of week $start_date_sql = ($year. '-' . $month . '-' . $day); $dayOfWeek = date('D', strtotime( $start_date_sql )); if ($dayOfWeek == 'Mon') {$dow = 1;} if ($dayOfWeek == 'Tue') {$dow = 2;} if ($dayOfWeek == 'Wed') {$dow = 3;} if ($dayOfWeek == 'Thu') {$dow = 4;} if ($dayOfWeek == 'Fri') {$dow = 5;} if ($dayOfWeek == 'Sat') {$dow = 6;} if ($dayOfWeek == 'Sun') {$dow = 7;} // creates unix timesstamp from end date $end_date = JRequest::getString('end_date', ''); list($day,$month,$year) = explode("/", $end_date); $end_date_unixTime = mktime(0,0,0,$month,$day,$year); // number of days between dates $seconds = $end_date_unixTime - $start_date_unixTime; $days = ($seconds / 86400) + 1; $weekdays=0; $weekends=0; $totalDays= $days; $x=0; $x=8-$dow; //x days left in week - 5 if ($x > 2) { $weekdays+=$x-2; //weekdays = 3 $weekends++; } else { $weekends+=x/2; } $totalDays-=$x; // 39 $totalWeeks = floor($totalDays / 7); // (5.57) 5 $weekends+=$totalWeeks; // 5 + 1 = 6 $weekdays+=(5*$totalWeeks); // 25 + 3 = 28 $totalDays=$totalDays-((5*$totalWeeks)-($totalWeeks*2)); // 39 - 25 - 10 = 4 days if ($totalDays <= 5) { $weekdays+=$totalDays; //weekdays = } else { $weekdays+=5; // 5+28 = 33 $weekends+=($totalDays-5)/2; } if i then output $days, $weekdays, $weekends, $totalweeks these are some results from different date ranges (Mon) 1/8/2011 - 7/8/2011: days = 7, week days = 5, weekends = 1, total weeks = 0 days - Correct 'C', week days - Correct 'C', weekends - Correct 'C', total weeks - Wrong 'W' (Mon) 1/8/2011 - 3/8/2011: days = 3, week days = -1, weekends = 0, total weeks = -1 days - C, week days - W, weekends - C, total weeks - W - notice the '-1' for each (Wed) 3/8/2011 - 16/8/2011: days = 14, week days = 13, weekends = 2.5, total weeks = 1 days - C, week days - W, weekends - W, total weeks - W (Mon) 4/7/2011 - 29/8/2011: days = 57, week days = 45, weekends = 20, total weeks = 7 days - C, week days - W, weekends - W, total weeks - W Now I know i haven't added the days from the first and last weeks to the total weeks as you have said so im not expecting those to be right but not sure where to grab these from, can you explain? Also, the other calculations are correct sometimes, not others...
  24. teynon, i will look at your code now, thanks very much do i need to know what day of the week the start date falls on though? ie - June 8 = Wednesday (3) as i will not know this...
×
×
  • 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.