Jump to content

drranch

Members
  • Posts

    78
  • Joined

  • Last visited

    Never

Posts posted by drranch

  1. need some assist... the script below sends out two emails and I cant seem to find out why...Im semi new to php and Im thinking Im missing something...

     

    <?php
    
    function dprint_r($array) {
      echo "<pre>";
      print_r($array);
      echo "</pre>";
      die();
    }
    
    function get_status($status_code) {
      switch ($status_code) {
      case 0:
        $status = "New";
        break;
      case 1:
        $status = "Assigned";
        break;
      case 2:
        $status = "Work In Progress";
        break;
      case 3:
        $status = "Pending";
        break;
      case 4:
        $status = "Resolved";
        break;
      case 5:
        $status = "Closed";
        break;
      default:
        $status = "??????";
      }
      return $status;
    }
    
    function get_report()
    {
      global $holidays, $unix_now, $unix_morning;
      switch(date('l', time())) {
      case 'Monday':
        if (in_array($curdate, $holidays))
          $report = "none";
        elseif ($unix_now < $unix_morning)
          $report = "weekend";
        elseif ($unix_now > $unix_morning)
          $report = "daily";
        break;
      case 'Tuesday':
        if (in_array($yesterday, $holidays))
          $report = "weekend";
        else
          $report = "daily";
        break;
      case 'Wednesday':
      case 'Thursday':
      case 'Friday':
        $report = "daily";
        break;
      case 'Saturday':
      case 'Sunday':
        $report = "none";
        break;
      default:
        die('Invalid day');
      }
      return $report;
    }
    
    require_once('include.php');
    require_once('Spreadsheet/Excel/Writer.php');
    require_once('email.class.php');
    
    $xls =& new Spreadsheet_Excel_Writer('daily.xls');
    $sheet =& $xls->addWorksheet('Sheet 1');
    $email_to = 'me@myemail.com;
    $email_from = 'your<me@youremail.com>';
    $email_subject = 'Daily report for ' . date('m/d/Y');
    $email = new Email($email_to, $email_from, $email_subject);
    
    $holidays = array("1/1/2007",
    	  "1/15/2007",
    	  "2/19/2007",
    	  "5/28/2007",
    	  "7/4/2007",
    	  "9/3/2007",
    	  "11/22/2007",
    	  "11/23/2007",
    	  "1/1/2008");
    
    $fields = array('Case ID',
    	'Requestor',
    	'New.TIME',
    	'Summary',
    	'Status',
    	'Assigned Group');
    
    
    $unix_now = time();
    $curtime = date('H:i:s');
    $curdate = date('m/d/Y');
    $yesterday = date('m/d/Y', strtotime('yesterday'));
    $curmorning = "$curdate 09:30:00";
    $midnight = "$curdate 00:00:00";
    $unix_morning = strtotime($curmorning);
    $unix_midnight = strtotime($midnight);
    $report = get_report();
    
    
    switch($report) {
    case 'daily':
       $time = strtotime('Yesterday 6:30am');
       $sqldate = "AND sh.new_time >= $time";
       break;
    case 'weekend':
       $time = strtotime('Last Friday 6:30am');
       $sqldate = "AND sh.new_time >= $time";
       break;
    default:
       die('No report generated');     
    }
        
    
        
    $sql = "SELECT h.case_id_, h.requester_name_, sh.new_time, h.summary, h.status, h.assigned_to_group_
                FROM hpd_helpdesk AS h, sh_hpd_helpdesk as sh
                WHERE h.priority = 2
                AND sh.case_id_ = h.case_id_
                $sqldate
                ORDER BY h.case_id_ ASC";
    $rs = $db->Execute($sql);
    
    
    $colheading =& $xls->addFormat();
    $colheading->setBold();
    $colheading->setAlign('center');
    $sheet->write(0, 0, 'Daily');
    $text[] = 'Daily High Ticket Report';
    $sheet->write(1, 0, '1234567');
    $text[] = '1234567';
    $sheet->write(2, 0, '1234567');
    $text[] = '1234567';
    $sheet->writeRow(4, 0, $fields, $colheading);
    $text[] = implode("\t", $fields);
    $rowcount = 5;
    
    $rowformat =& $xls->addFormat();
    $rowformat->setTextWrap(true);
    
    //die(print_r($rs));
    
    
    while ($row = $rs->FetchRow()) {
      $row['status'] = get_status($row['status']);
      $row['new_time'] = date('m/d/Y H:i', $row['new_time']);
      $sheet->setColumn(0, 0, 20);
      $sheet->setColumn(0, 1, 20);
      $sheet->setColumn(0, 2, 20);
      $sheet->setColumn(0, 3, 40);
      $sheet->setColumn(0, 4, 15);
      $sheet->setColumn(0, 5, 20);
      $sheet->writeRow($rowcount++, 0, $row, $rowformat);
      $text[] = implode("\t", $row);
    }
    
    // save the text file
    $fp = fopen('daily_high_tickets.txt', 'w');
    foreach($text as $row) {
      $row .= "\r\n";
      fwrite($fp, $row);
    }
    
    // save the xls file
    $xls->close();
    
    // attach the files and send the email
    $email->Attach('daily.xls', 'application/vnd.ms-excel');
    $email->Attach('daily.txt', 'text/plain');
    $email->Send();
    ?>
    
    

  2. I have a MYSQL query that pulls appointment data from my database and sends an email to the people who have appointments.  However, if there are several appointments for one person each appointment is sent in a different email.  How do I get for each user with several appointments one email sent with all appointments in the single email.

     

    $rsnotifier = mysql_query($query_notifier, $database);
    while($row_rsnotifier = mysql_fetch_assoc($rsnotifier))
    {
    $email_address = $row_rsnotifier["email_address"];
    $subject = "Appointment Reminder";
    $message = 
    "<html>
    <head>
    <title>My Calendar Appointment</title>
    </head>
    <body background='http://www.name.com/images/bkrnd.jpg'>
    <?php do { ?>
    <div>Hello,<br> Its time for {$row_rsnotifier['appdesc']} - {$row_rsnotifier['follow_up_date']}</div>
    <?php
    }
    while ($row_rsnotifier = mysql_fetch_assoc($rsnotifier));?>
    </body>
    </html>";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers = 'From: My Appointment Reminder <admin@name.com>' . "\r\n";

  3. If I understand you right you only want to know how to query and count how many times the word "very Good" is in all of the three columns...

     

     

    "SELECT column1, column2, columm3, COUNT(*) AS total FROM backup WHERE StartDate AND EndDate BETWEEN '2006-12-01' AND '2007-12-31' AND column1 = 'Very Good' AND column2=Very Good AND column3=Very Good GROUP BY column1")"

  4. My best guess is something is blocking the file from being written to.  Check the permissions on the folder to make sure they are read/write and if they are find out what applications are running on the server that could be blocking access for writing to the file.

     

    If you runnin through a hosted server call support and work with them in clearing temp files on the server.

  5. Are those all the columns in your bookings table?

     

    I see in your syntax you have in the sub query "SELECT 'bookings', ......

     

    If you don't have a colum called bookings in your table then your script should be catching that saying that there isn't a recognized column. 

     

    "SELECT distinct(departicao), depart FROM flights WHERE NOT EXISTS(Select ID FROM Bookings WHERE date = $date AND bookings.flightid=flights.id) AND $day=1 GROUP BY departicao"

     

    Just a guess I'm no expert, but learning along with everyone else.

     

     

  6. you must first create a database

     

    Then create the tables for the database

     

    if your using a hosting service you can create the database through them if you have an account that allows your ability to create the database.

     

    Then you can use the code you noted in your posting to create the table.  The code you show above will create a table called 'users'

  7. Is your site running on a hosted server?

     

    If so you will need to check to see if they have this option for you

     

    You would build the MYSQL/PHP scripting and then set up the cron option to run the MYSQL/PHP script.  Using the cron option through your provider will let you run the script at a certain time and day.

  8. The backslash is an escape charater in MYSQL and that was the reason for the error.

     

    Using the new one you built is fine since using mysql escape string is escaping the backslash escape character.  You could have used two back slashes on the orginal script, since they would have represented a single backslash and not recognized by MYSQL or PHP as an escape character of a single back slash.

     

    Using mysql_real_escape_String() around each variable prevents SQL injections from occuring by prepending backslashes to the following characters \x00, \n, \r, \, '," and \x1a

     

    This function should always be used with few exceptions to make data safe before sending a query to MYSQL

  9. The query does not recognize the column on the events table

     

    Table name: events

    Column name: fbla101

     

    double check to see if the column exists and if it does check to make sure your fbla101 in your query matches the name of the column

     

    and

     

    you will also want to check and make sure your table name is the same as the table name your using in your mysql query events

  10. I'm working on a query that will pull appointment information from four different tables based on a BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY)

     

    AND

     

    then populate the appointment information in an email script set up through cron

     

    However,

    there will be times that some of the tables will have several appointments and some tables may not have any appointments for this date range

     

    In addition,

    this script will pull information for different users and email the appointments to the user who has appointments for the date range.

     

    I was able to write and test the script for a single table, but I'm not sure how to incorporate the other three tables.

     

    apptcron.jpg

  11. <php?
    if ($appt1 exist !=null){
       echo "appt1 appointment date"
    }else if ($appt2 exist !=null){
       echo "appt2 appointment date"
    }else if ($appt3 exist !=null){
       echo "appt3 appointment date"
    }else if ($appt4 exist !=null){
       echo "appt4 appointment date"
    }else{
       echo "There are no appointments scheduled for the next 7 days."
    ?>

     

    Its working very nicely... Now on to the time side of appointments.  ;D

  12. empty string...

     

    I have four possible appointments to display for an end user on their home page.  At any given time any one of these types of appointments can have no available appointments..

     

    if

    appt1 exist

      echo appt1 date

    if appt2 exist

      echo appt 2 date

    if appt3 exist

      echo appt 3 date

    if appt4 exist

      echo appt 4 date

    else

    if there are no appointments for any appointment type 1 through 4

      echo "there are no appointments scheduled for the next 7 days.

  13. Each table represents a certain "type" of appointment, hence different tables.  On the users home page of the signed on user I want to display any appointment they may have on any of these four tables that is with in 7 days out from the current date.  So there may be times that they have an appointment for only one of these four tables or for all tables or multiple appointments for one of these tables.

     

    Originally I was hoping for a single MYSQL query of all tables and then build a single PHP script to display it on the users home page.

     

     

×
×
  • 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.