Location: PHPKode > projects > Phpgw Time Tracking Add On App > timetrack/jobslist.php
<?php
  /**************************************************************************\
  * phpgwtimetrack - phpGroupWare addon application                          *
  * http://phpgwtimetrack.sourceforge.net                                    *
  * Written by Robert Schader <hide@address.com>                         *
  * --------------------------------------------                             *
  *  This program is free software; you can redistribute it and/or modify it *
  *  under the terms of the GNU General Public License as published by the   *
  *  Free Software Foundation; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: jobslist.php,v 1.6 2001/01/16 21:56:53 rschader Exp $ */
  // This page is going to be a drop-in replacement for jobslist.php, there
  // are no links to it under the current name.

  $phpgw_info["flags"]["enable_nextmatchs_class"] = "True";
  $phpgw_info["flags"]["currentapp"] = "timetrack";

  include("../header.inc.php");

  // Setup $searchobj array for setting up a listbox on the search form
  // so we can narrow down what field to query on.
  // Note: cname is a sql alias for concat(a.ab_firstname," ",a.ab_lastname)
  //       as cname
  // Note: I can always add more fields later.
  $searchobj = array(array("c.company_name", "Customer"),
                     array("cname"         , "Contact"),	
                     array("e.account_lid" , "Assigned To"),
                     array("j.description" , "Description"),
                     array("j.summary"     , "Summary")
                     );
	
  $filterobj = $phpgw->nextmatchs->filterobj("job_status", "status_id", "status_name");

  echo "<center><h3>" . lang("Job List") . "</h3>";

  if (! $start){
     $start = 0;
  }

  $limit =$phpgw->nextmatchs->sql_limit($start);

  if ($order){
     $ordermethod = "order by $order $sort";
  }else{
     $ordermethod = "order by c.company_name,j.job_number,j.job_revision asc";
  }

  if (($filter == "") || ($filter == 'none')) {
     $a_filtermethod = "";
     $w_filtermethod = "";
  } else {
     $a_filtermethod = " AND status_id=$filter";
     $w_filtermethod = " WHERE status_id=$filter";
  }

  if ($query) { // assume that $qfield is also set to the field name to query
   if($qfield == "cname") {
     $phpgw->db->query("SELECT count(*) "
       . "from jobs as j "
       . "left join customers as c on j.company_id = c.company_id "
       . "left join addressbook as a on j.contact_id = a.ab_id "
       . "left join accounts as e on j.account_id = e.account_id "
       . "WHERE concat(a.ab_firstname,\" \",a.ab_lastname) LIKE '%$query%' "
       . "$a_filtermethod ");
       //. "$ordermethod limit $limit");
   } else {
     $phpgw->db->query("SELECT count(*) "
       . "from jobs as j "
       . "left join customers as c on j.company_id = c.company_id "
       . "left join addressbook as a on j.contact_id = a.ab_id "
       . "left join accounts as e on j.account_id = e.account_id "
       . "WHERE $qfield LIKE '%$query%' "
       . "$a_filtermethod ");
       //. "$ordermethod limit $limit");
   }

   $phpgw->db->next_record();

   if ($phpgw->db->f(0) == 1) {
        echo lang("your search returned 1 match") . "<br>";
   } else {
        echo lang("your search returned x matchs",$phpgw->db->f(0)) . "<br>";
   }
  } else { //no query
     $phpgw->db->query("select count(*) from jobs $w_filtermethod");
     $phpgw->db->next_record();
  }
  $company_sortorder = "c.company_name";

  if ($phpgw->db->f(0) >= $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]){
     $end = $start + $phpgw_info["user"]["preferences"]["common"]["maxmatchs"];
     if ($end > $phpgw->db->f(0)) $end = $phpgw->db->f(0);
     echo lang("showing x - x of x",($start + 1),$end,$phpgw->db->f(0));
  } else {
     echo lang("showing x",$phpgw->db->f(0)); 
  }

  //$filterobj =
  //    $phpgw->nextmatchs->filterobj("job_status", "status_id", "status_name");

 $phpgw->nextmatchs->show("jobslist.php",$start,$phpgw->db->f(0),
                          "", "90%", $phpgw_info["theme"]["th_bg"],
                          $searchobj, $filterobj);
?>

  <table width=90% border=0 cellspacing=1 cellpadding=3>
    <tr bgcolor="<?php echo $phpgw_info["theme"]["th_bg"]; ?>">
    <?php
       // Company Name (c.company_name)
          echo '<th width="20%">';
          echo '<font size="-1" face="Arial, Helvetica, sans-serif">';
          echo $phpgw->nextmatchs->show_sort_order($sort,$company_sortorder,$order,"jobslist.php",lang("Customer"));
          echo '</font></th>';
       // Job No. (j.job_number)
           echo '<th width="8%">';
           echo '<font size="-1" face="Arial, Helvetica, sans-serif">';
           echo $phpgw->nextmatchs->show_sort_order($sort,"j.job_number",$order,"jobslist.php",
                              lang("Job No."));
           echo '</font></th>';
       // Rev (j.job_revision)
           echo '<th width="5%">';
           echo '<font size="-1" face="Arial, Helvetica, sans-serif">';
           echo $phpgw->nextmatchs->show_sort_order($sort,"j.job_revision",$order,"jobslist.php",
                              lang("Rev"));
           echo '</font></th>';
       // Summary Description (j.summary)
           echo '<th width="42%">';
           echo '<font size="-1" face="Arial, Helvetica, sans-serif">';
           echo $phpgw->nextmatchs->show_sort_order($sort,"j.summary",$order,"jobslist.php",
                              lang("Summary"));
           echo '</font></th>';
       // Quoted Hours (j.quoted_hours)
           echo '<th width="10%">';
           echo '<font size="-1" face="Arial, Helvetica, sans-serif">';
           echo $phpgw->nextmatchs->show_sort_order($sort,"j.quoted_hours",$order,"jobslist.php",
                              lang("Quoted Hours"));
           echo '</font></th>';
       // Hours Worked (j.quoted_hours) (i.e. sum(jd.numhours) as hours
           echo '<th width="10%">';
           echo '<font size="-1" face="Arial, Helvetica, sans-serif">';
           echo $phpgw->nextmatchs->show_sort_order($sort,"hours",$order,"jobslist.php",
                              lang("Hours Worked"));
           echo '</font></th>';
    ?>

      <th width="3%" width="5%">
       <font face="Arial, Helvetica, sans-serif" size="-1">
         <?php echo lang("View"); ?>
       </font>
      </th>
      <th width="5%" width="5%">
       <font face="Arial, Helvetica, sans-serif" size="-1">
         <?php echo lang("Edit"); ?>
       </font>
      </th>
    </tr>
  </form>


<?php
  if ($query) {
    if ($qfield == "cname") {
     $phpgw->db->query("SELECT sum(jd.num_hours) as hours,"
       . "j.job_id,j.job_number,j.job_revision,j.summary,j.quoted_hours,c.company_name,"
       . "concat(a.ab_firstname,\" \",a.ab_lastname) as cname,"
       . "e.account_lid from jobs as j "
       . "left join job_details as jd on jd.job_id = j.job_id "
       . "left join customers as c on j.company_id = c.company_id "
       . "left join addressbook as a on j.contact_id = a.ab_id "
       . "left join accounts as e on j.account_id = e.account_id "
       . "WHERE concat(a.ab_firstname,\" \",a.ab_lastname) like '%$query%' "
       . "$a_filtermethod "
       . "GROUP BY j.job_id "
       . "$ordermethod limit $limit");
    } else {
     $phpgw->db->query("SELECT sum(jd.num_hours) as hours,"
       . "j.job_id,j.job_number,j.job_revision,j.summary,j.quoted_hours,c.company_name,"
       . "concat(a.ab_firstname,\" \",a.ab_lastname) as cname,"
       . "e.account_lid from jobs as j "
       . "left join job_details as jd on jd.job_id = j.job_id "
       . "left join customers as c on j.company_id = c.company_id "
       . "left join addressbook as a on j.contact_id = a.ab_id "
       . "left join accounts as e on j.account_id = e.account_id "
       . "WHERE $qfield like '%$query%' "
       . "$a_filtermethod "
       . "GROUP BY j.job_id "
       . "$ordermethod limit $limit");
    }
  } else {
   $phpgw->db->query("SELECT sum(jd.num_hours) as hours,"
     . "j.job_id,j.job_number,j.job_revision,j.summary,j.quoted_hours,c.company_name,"
     . "concat(a.ab_firstname,\" \",a.ab_lastname) as cname,"
     . "e.account_lid from jobs as j "
     . "left join job_details as jd on jd.job_id = j.job_id "
     . "left join customers as c on j.company_id = c.company_id "
     . "left join addressbook as a on j.contact_id = a.ab_id "
     . "left join accounts as e on j.account_id = e.account_id "
     . "$w_filtermethod "
     . "GROUP BY j.job_id "
     . "$ordermethod limit $limit");
  }

  while ($phpgw->db->next_record()) {
    $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color);

    $job_id = $phpgw->db->f("job_id");
    $job_number = $phpgw->db->f("job_number");
    $job_revision = $phpgw->db->f("job_revision");
    $summary = $phpgw->db->f("summary");
    $quoted_hours = $phpgw->db->f("quoted_hours");
    $company_name = $phpgw->db->f("company_name");
    $total_hours = $phpgw->db->f("hours");

    if($job_number == "") $job_number = "&nbsp;";
    if($job_revision == "") $job_revision  = "&nbsp;";
    if($summary == "") $summary     = "&nbsp;";
    if($quoted_hours == "") $quoted_hours   = "&nbsp;";
    if($company_name == "") $company_name    = "&nbsp;";
    if($total_hours == "") $total_hours = "0.00";

    ?>
    <?php
     echo '<tr bgcolor="#'.$tr_color.'";>';
         echo '<td width="20%" valign=top>';
         echo '<font face=Arial, Helvetica, sans-serif size=2>';
         echo $company_name;
         echo '</font></td>';

         echo '<td width="8%" valign=top>';
         echo '<font face=Arial, Helvetica, sans-serif size=2>';
         echo $job_number;
         echo '</font></td>';

         echo '<td width="5%" valign=top>';
         echo '<font face=Arial, Helvetica, sans-serif size=2>';
         echo $job_revision;
         echo '</font></td>';

         echo '<td width="42%" valign=top>';
         echo '<font face=Arial, Helvetica, sans-serif size=2>';
         echo $summary;
         echo '</font></td>';

         echo '<td width="10%" valign=top>';
         echo '<font face=Arial, Helvetica, sans-serif size=2>';
         echo $quoted_hours;
         echo '</font></td>';

         echo '<td width="10%" valign=top>';
         echo '<font face=Arial, Helvetica, sans-serif size=2>';
	 
	 if ($total_hours > 0) 
	    echo "<a href=\"".$phpgw->link("detail_report1.php","job_id=$job_id&start=$start&order=$order&filter="
		 . "$filter&query=$job_id&sort=$sort&qfield=j.job_id")."\">";
         echo $total_hours; // this is a temporary filler for total hours.
         if ($total_hours > 0) echo "</a>";
         echo '</font></td>';

     ?>
       <td valign=top width=5%>
	<font face=Arial, Helvetica, sans-serif size=2>
          <a href="<?php echo $phpgw->link("viewjob.php","jobid=$job_id&start=$start&order=$order&filter="
		 . "$filter&query=$query&sort=$sort&qfield=$qfield");
	  ?>"> <?php echo lang("View"); ?> </a>
        </font>
       </td>
       <td valign=top width=5%>
        <font face=Arial, Helvetica, sans-serif size=2>
         <a href="<?php echo $phpgw->link("editjob.php","jobid=$job_id&start=$start&order=$order&filter="
		. "$filter&query=$query&sort=$sort&qfield=$qfield");
         ?>"> <?php echo lang("Edit"); ?> </a>
        </font>
       </td>
      </tr>
     <?php
  }

?>
  </table>

  <form method="POST" action="<?php echo $phpgw->link("newjob.php"); ?>">
   <input type="hidden" name="sort" value="<?php echo $sort; ?>">
   <input type="hidden" name="order" value="<?php echo $order; ?>">
   <input type="hidden" name="query" value="<?php echo $query; ?>">
   <input type="hidden" name="start" value="<?php echo $start; ?>">
   <input type="hidden" name="filter" value="<?php echo $filter; ?>">
   <input type="hidden" name="qfield" value="<?php echo $qfield; ?>">
  <table width="75%" border="0" cellspacing="0" cellpadding="4">
    <tr> 
      <td width="4%"> 
        <div align="right"> 
          <input type="submit" name="Add" value="<?php echo lang("Add"); ?>">
        </div>
      </td>
      <td width="72%">&nbsp;</td>
      <td width="24%">&nbsp;</td>
    </tr>
  </table>
  </form>
</center>

<?php
  $phpgw->common->phpgw_footer();
?>
Return current item: Phpgw Time Tracking Add On App