Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2008-03-11, 09:39 PM
Junior Member
 
Join Date: Mar 2008
Posts: 1
redknights is on a distinguished road
Default Switched Hosts. PHP Form No Longer Works

Had to switch hosts and now a PHP form that worked flawlessly doesn't work at all (and it's not a connectivity issue.) Anyone have any ideas?
Thanks,
RedKnights

Code:
<?php
require_once('../config.php');
require_once('topnav.inc.php');
session_start();
if(!isset($_SESSION['admin'])) {
 session_destroy();
 echo "<meta http-equiv=\"refresh\" content=\"1; URL=login.php\" target='mainFrame'>";
 die();
}
function format_phone($phone)
{
  return "(".substr($phone, 0, 3).") ".substr($phone, 3, 3)."-".substr($phone, 6);
}
function query_with_callback($from, $to, $rowcallback)
{
  global $report_type, $report_clinics, $report_sort, $report_questions;
 
  $dfrom = "20".substr($from, 6, 2)."-".substr($from, 0, 2)."-".substr($from, 3, 2)." 00:00:00";
  $dto = "20".substr($to, 6, 2)."-".substr($to, 0, 2)."-".substr($to, 3, 2)." 23:59:59";
  $link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
  mysql_select_db(DB_NAME ,$link);
  if (!$link)
  {
    die('Could not connect: ' . mysql_error());
  }
 
  $query = "SELECT * FROM ((SELECT a.formtype, a.clinicid, a.cliniccompany, a.clinicemail, a.datesent, CONCAT(a.patientname,' ',a.patientlastname) as patientname, a.patientphone, a.patientemail";
  if ($report_questions)
  {
//     if ($report_type == "0" || $report_type == "1")
        $query .= ", a.patientquestion";
//     if ($report_type == "0" || $report_type == "2")
        $query .= ", a.q1 as areas_threat, a.q2 as skin_type, a.q3 as sun_tanned, a.q4 as photosensitive, a.q5 as hair_color";
  }
  $query .= " FROM askexpert a INNER JOIN customer c ON c.id = a.clinicid ) UNION (";
 $query .= "SELECT '3' as formtype, customer_id as clinicid, company as cliniccompany, c.email as clinicemail, from_unixtime(ci.date_timestamp) as datesent, CONCAT(firstname,' ',realname) as patientname, ci.phone as patientphone, ci.email as patientemail";
 if ($report_questions)
 {
  $query .= ", ci.info as patientquestion, areas_treat, skin_type, sun_tanned, photosensitive, hair_color";
 }
 $query .= " FROM contact_ip ci INNER JOIN customer c ON c.id = ci.customer_id )) AS res";
  $query .= " WHERE datesent >= '$dfrom' AND datesent <='$dto'";
  if ($report_type != "0")
     $query .= " AND formtype = '$report_type'";
  if ($report_clinics == "1")
     $query .= " AND (clinicid BETWEEN 1 AND 14)";
  else if ($report_clinics == "2")
     $query .= " AND c.user_id <> 1";
  if ($report_sort == "0")
     $query .= " ORDER BY datesent ASC";
  else if ($report_sort == "1")
     $query .= " ORDER BY datesent DESC";
  else if ($report_sort == "2")
     $query .= " ORDER BY clinicid ASC";
  else if ($report_sort == "3")
     $query .= " ORDER BY clinicid DESC";
  $result = mysql_query($query, $link);
  if ($result)
  {
    while ($row = mysql_fetch_assoc($result))
      $rowcallback($row);
    mysql_free_result($result);
  }
  mysql_close($link);
}
function print_report_row($row)
{
  global $report_type, $report_questions;
  echo "<tr><td><span style=\"color:#000099;font-weight:bold\">";
 if ($row['formtype'] == '1')
  echo "AE";
 else if ($row['formtype'] == '2')
  echo "IC";
 else
  echo "GC";
 echo "</span></td><td>".$row['clinicid']."</td>";
  echo "<td>".$row['cliniccompany']."</td>";
  echo "<td>".$row['clinicemail']."</td>";
  echo "<td>".$row['datesent']."</td>";
  echo "<td>".$row['patientname']."</td>";
  echo "<td>".$row['patientemail']."</td>";
  echo "<td>".format_phone($row['patientphone'])."</td>";
  if ($report_questions)
  {
    if ($report_type == "0" || $report_type == "1")
       echo "<td>".$row['patientquestion']."</td>";
    if ($report_type == "0" || $report_type == "2")
    {
       echo "<td>".$row['areas_threat']."</td>";
       echo "<td>".$row['skin_type']."</td>";
       echo "<td>".$row['sun_tanned']."</td>";
       echo "<td>".$row['photosensitive']."</td>";
       echo "<td>".$row['hair_color']."</td>";
    }
  }
  echo "</tr>";
}
function print_report($from, $to)
{
  global $report_type, $report_questions;
  echo "<table width=100%>";
  $cs = 7;
  if ($report_questions && ($report_type == "0" || $report_type == "1"))
     $cs +=2;
  if ($report_questions && ($report_type == "0" || $report_type == "2"))
     $cs +=6;
  echo "<tr><td bgcolor=#fffff0 colspan=$cs><h2>Report for dates from $from to $to</h2></td></tr>";
  echo "<tr><th></th><th>Clinic ID</th><th>Clinic Name</th><th>Clinic Email</th><th>Date Sent</th><th>Patient Name</th><th>Patient Email</th><th>Patient Phone</th>";
  if ($report_questions)
  {
    if ($report_type == "0" || $report_type == "1")
       echo "<th>Patient Question</th>";
    if ($report_type == "0" || $report_type == "2")
       echo "<th>Areas Threat</th><th>Skin Type</th><th>Sun Tanned ?</th><th>Photosensitive ?</th><th>Hair Color</th>";
  }
  echo "</tr>";
  query_with_callback($from, $to, print_report_row);
  echo "</table>";
}
function stream_field($row, $field, $formatfn = null)
{
  $sep = ";";
  if(!isset($row[$field]))
    return "NULL".$sep;
  elseif ($row[$field] != "")
    if ($formatfn)
       return $formatfn(preg_replace("/\r\n|\r|\n/", " ", $row[$field])).$sep;
    else
       return preg_replace("/\r\n|\r|\n/", " ", $row[$field]).$sep;
  else
    return "".$sep;
}
function stream_row($row)
{
  global $report_type, $report_questions;
  $sep = ";";
  $schema_insert = "";
  $schema_insert .= stream_field($row, 'clinicid');
  $schema_insert .= stream_field($row, 'cliniccompany');
  $schema_insert .= stream_field($row, 'clinicemail');
  $schema_insert .= stream_field($row, 'datesent');
  $schema_insert .= stream_field($row, 'patientname');
  $schema_insert .= stream_field($row, 'patientemail');
  $schema_insert .= stream_field($row, 'patientphone', format_phone);
  if ($report_questions)
  {
    if ($report_type == "0" || $report_type == "1")
       $schema_insert .= stream_field($row, 'patientquestion');
    if ($report_type == "0" || $report_type == "2")
    {
       $schema_insert .= stream_field($row, 'areas_threat');
       $schema_insert .= stream_field($row, 'skin_type');
       $schema_insert .= stream_field($row, 'sun_tanned');
       $schema_insert .= stream_field($row, 'photosensitive');
       $schema_insert .= stream_field($row, 'hair_color');
    }
  }
  $schema_insert .= ";";
  print(trim($schema_insert));
  print "\n";
}
 
if (!isset($date_to))
   $date_to = date("m/d/y");
if (!isset($date_from))
   $date_from = date("m/d/y", time()-30*24*60*60);
if (!isset($report_type))
   $report_type = "0";
if (!isset($report_clinics))
   $report_clinics = "0";
if (!isset($report_sort))
   $report_sort = "0";
if (!isset($report_questions))
   $report_questions = 0;
 
if (isset($report_download))
{
  download_report($date_from, $date_to);
}
?>
<html>
<BODY>
<center>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr><td height="40"><h1>Admin - Ask Expert report</h1></td></tr>
  </table>
  <?php admin_top_nav(); ?>
  <form method='post'>
  <table>
    <tr>
      <td>Select form types for report :</td>
      <td>
        <select name="report_type" id="report_type" size=1>
          <option value="0" <?php if ($report_type == "0"){echo "selected";}?>>ALL</option>
          <option value="1" <?php if ($report_type == "1"){echo "selected";}?>>Ask an Expert</option>
          <option value="2" <?php if ($report_type == "2"){echo "selected";}?>>Instant Consultation</option>
          <option value="3" <?php if ($report_type == "3"){echo "selected";}?>>General Contact</option>
        </select>
      </td>
    <tr>
    <tr>
        <td>Filter clinics :</td>
        <td>
            <select name="report_clinics" id="report_clinics" size=1>
              <option value="0" <?php if ($report_clinics == "0"){echo "selected";}?>>ALL clinics</option>
              <option value="1" <?php if ($report_clinics == "1"){echo "selected";}?>>Signature Web</option>
              <option value="2" <?php if ($report_clinics == "2"){echo "selected";}?>>All except Signature</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>Sort results by :</td>
        <td><input type=radio name="report_sort" value="0" <?php if ($report_sort == "0"){echo "checked";}?>>Sent date (ASC)</td>
    <tr>
    <tr>
        <td></td>
        <td><input type=radio name="report_sort" value="1" <?php if ($report_sort == "1"){echo "checked";}?>>Sent date (DESC)</td>
    <tr>
    <tr>
        <td></td>
        <td><input type=radio name="report_sort" value="2" <?php if ($report_sort == "2"){echo "checked";}?>>Clinic ID (ASC)</td>
    <tr>
    <tr>
        <td></td>
        <td><input type=radio name="report_sort" value="3" <?php if ($report_sort == "3"){echo "checked";}?>>Clinic ID (DESC)</td>
    <tr>
    <tr><td colspan=2><input type="checkbox" name="report_questions" id="report_questions" <?php if ($report_questions){echo "checked";}?> />Include questions in report</td></tr>
    <tr><td colspan=2>Select time range for report : (in mm/dd/yy format example 09/19/07)</td></tr>
    <tr>
      <td>From : <input id='date_from' name='date_from' size=15 value='<?php echo $date_from; ?>'/></td>
      <td>To : <input id='date_to' name='date_to' size=15 value='<?php echo $date_to; ?>' /></td>
    </tr>
    <tr>
      <td><input type='submit' value='View results' name='report_view'/></td>
      <td><input type='submit' value='Download exel report' name='report_download' /></td>
    </tr>
  </table>
  </form>
  <?php
  if (isset($report_view))
  {
    echo "<hr/>";
    print_report($date_from, $date_to);
  }
  ?>
</body>
</html>
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.0 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.0 (a popular PHP IDE) and NuCoder 1.4 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:13 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.