<?php /**/ ?><?php
  
if (!defined("WHMCS")) die("This file cannot be accessed directly");

  
//Number of List items to display on a page.
  
define("SHOWITEMS"50);

  class 
todolist
  
{
    function 
__construct() {}
    function 
__destruct()  {}
    
/***************************************************************
* Function: _get_list_items()
* Visibility: Private
*
* Parameter: $post - array - Array of $_POST data from the view/filter.
* Parameter: $limit - string - Limit string generated by the get_page_item(s) functions.
* Parameter: $get_count - bool - Indicates whether or not this query just retrieves a record count.
*
* Returns: array - returns the queried To-Do list information
*
* Description: Builds a query for the tbltodolist and mod_todolist tables to retrieve all 
* to-do list information for the specified page/edit screen.
***************************************************************/
    
private function _get_list_items($post = array(), $limit ""$get_count false)
    {
      
$list = array();
      
      if(
$get_count)
        
$fields "COUNT(id)";
      else
        
$fields "*";

      
$query  "SELECT " $fields " FROM `tbltodolist`";
      
$query .= $this->_build_where($post);
        
      if(!empty(
$limit))
        
$query .= " " $limit;

      
$query .= ";";

      
$results full_query($query);
      
      
//Gets meta information for the list item and inserts it into the array.
      
if(!$get_count)
      {
        while (
$row mysql_fetch_assoc($results))
        {
          
//Default values for orderstatus, hostingstatus, invoicestatus, clientname, and adminname
          
$row['orderstatus'] = "";
          
$row['hostingstatus'] = "";
          
$row['invoicestatus'] = "";
          
$row['clientname'] = "Unassigned";
          
$row['adminname'] = "Unassigned";

          if(!empty(
$row['date']))
            
$row['date'] = $this->_mysql_to_date($row['date']);
          else
            
$row['date'] = "00/00/0000";

          if(!empty(
$row['duedate']))
            
$row['duedate'] = $this->_mysql_to_date($row['duedate']);
          else
            
$row['date'] = "00/00/0000";

          
$row['meta'] = $this->_get_meta($row['id']);
          if(!empty(
$row['meta']))
          {
            if(!empty(
$row['meta']['orderid']) && $row['meta']['orderid'] != 0)
              
$row['orderstatus'] = "#" $row['meta']['orderid']/* . " - " . $this->_get_orderstatus($row['meta']['orderid'])*/;
              
            if(!empty(
$row['meta']['hostingid']) && $row['meta']['hostingid'] != 0)
              
$row['hostingstatus'] = "#" $row['meta']['hostingid']/* . " - " . $this->_get_hostingstatus($row['meta']['hostingid'])*/;
              
            if(!empty(
$row['meta']['invoiceid']) && $row['meta']['invoiceid'] != 0)
              
$row['invoicestatus'] = "#" $row['meta']['invoiceid']/* . " - " . $this->_get_invoicestatus($row['meta']['invoiceid'])*/;
              
            if(!empty(
$row['meta']['userid']) && $row['meta']['userid'] != 0)
              
$row['clientname'] = $this->_get_clientname($row['meta']['userid']);
          } 
//end if
              
          
if(!empty($row['admin']) && $row['admin'] != 0)
            
$row['adminname'] = $this->_get_adminname($row['admin']);

          
$list[] = $row;
        } 
//end while
      
//end if
      
else
      {
        
$list mysql_fetch_assoc($results);
      } 
//end else

      
unset($results);
      return 
$list;
    } 
//end _get_list_items()
    
/***************************************************************
* Function: _build_where()
* Visibility: Private
*
* Parameter: $post - array - Array of $_POST data from the view/filter.
*
* Returns: string - WHERE clause
*
* Description: Generates the WHERE clause for a query based on $_POST
* data sent to the function.
***************************************************************/
    
private function _build_where($post)
    {
      
$args = array();
      if(!empty(
$post))
      {
        if(!empty(
$post['id']))
          
$args[] = "`id` = '" $post['id'] . "'";

        if(!empty(
$post['date']))
          
$args[] = "`date` LIKE '" serialize($this->_date_to_mysql($post['date'])) . "'";

        if(!empty(
$post['duedate']))
          
$args[] = "`duedate` LIKE '" serialize($this->_date_to_mysql($post['duedate'])) . "'";

        if(!empty(
$post['title']))
          
$args[] = "`title` LIKE '%" serialize($post['title']) . "%'";

        if(!empty(
$post['admin']))
          
$args[] = "`admin` = '" $post['admin'] . "'";

        if(!empty(
$post['description']))
          
$args[] = "`description` LIKE '%" serialize($post['description']) . "%'";

        if(!empty(
$post['status']))
        {
          switch(
$post['status'])
          {
            case 
'New':
            case 
'Pending':
            case 
'In Progress':
            case 
'Completed':
            case 
'Canceled':
            case 
'Postponed':
              
$args[] = "`status` LIKE '%" serialize($post['status']) . "%'";
              break;
            default:
              
$args[] = "`status` <> 'Completed' AND `status` <> 'Cancelled'";
              break;
          } 
//end switch
        
//end if
        
unset($post);
        return 
" WHERE " implode(" AND "$args);
      } 
//end if
      
else
        return 
" WHERE `status` <> 'Completed' AND `status` <> 'Canceled'";
    }
    
/***************************************************************
* Function: _get_meta()
* Visibility: Private
*
* Parameter: $id - string - List item ID number
*
* Returns: array - returns the meta information for the list item.
*
* Description: Queries the mod_todolist table to retrieve the invoiceid, orderid,
* hostingid, and clientid information about a list item.
***************************************************************/
    
private function _get_meta($id)
    {
      
$results select_query("mod_todolist""*", array("listid" => sanitize($id)));
      
$result mysql_fetch_assoc($results);
      unset(
$results);
      
      return(
$result);
    } 
//end _get_meta()
    
/***************************************************************
* Function: _get_orderstatus()
* Visibility: Private
*
* Parameter: $orderid - string - Order ID number.
*
* Returns: string - returns the status of the order.
*
* Description: Queries the tblorders table for the order's status based on the
* $orderid passed to the function.
***************************************************************/
    
private function _get_orderstatus($orderid)
    {
      
$query "SELECT `status` FROM `tblorders` WHERE `id` = '" sanitize($orderid) . "' LIMIT 1;";
      
$results full_query($query);
      
$result mysql_fetch_assoc($results);
      unset(
$results);

      return 
$result['status'];
    } 
//end _get_orderstatus()
    
/***************************************************************
* Function: _get_hostingstatus()
* Visibility: Private
*
* Parameter: $hostingid - string - Hosting ID number.
*
* Returns: string - returns the status of the hosting account.
*
* Description: Queries the tblhosting table for the hosting account's status 
* based on the $hostingid passed to the function.
***************************************************************/
    
private function _get_hostingstatus($hostingid)
    {
      
$query "SELECT `domainstatus` FROM `tblhosting` WHERE `id` = '" sanitize($hostingid) . "' LIMIT 1;";
      
$results full_query($query);
      
$result mysql_fetch_assoc($results);
      unset(
$results);

      return 
$result['domainstatus'];
    } 
//end _get_hostingstatus()

/***************************************************************
* Function: _get_invoicestatus()
* Visibility: Private
*
* Parameter: $invoiceid - string - Invoice ID number.
*
* Returns: string - returns the status of the invoice.
*
* Description: Queries the tblinvoices table for the invoice's status based on the
* $invoiceid passed to the function.
***************************************************************/
    
private function _get_invoicestatus($invoiceid)
    {
      
$query "SELECT `status` FROM `tblinvoices` WHERE `id` = '" sanitize($invoiceid) . "' LIMIT 1;";
      
$results full_query($query);
      
$result mysql_fetch_assoc($results);
      unset(
$results);

      return 
$result['status'];
    } 
//end _get_invoicestatus()
    
/***************************************************************
* Function: _get_adminname()
* Visibility: Private
*
* Parameter: $adminid - string - Admin ID number.
*
* Returns: string - returns the admin's name.
*
* Description: Queries the tbladmins table for the admin's name based on the
* $adminid passed to the function.
***************************************************************/
    
private function _get_adminname($adminid)
    {
      
$results select_query("tbladmins""firstname, lastname", array("id" => sanitize($adminid)));
      
$result mysql_fetch_assoc($results);
      unset(
$results);
      
      if(!empty(
$result['firstname']))
        return 
$result['firstname'] . " " $result['lastname'];
      else
        return 
"Unassigned";
    } 
//end _get_adminname()
    
/***************************************************************
* Function: _mysql_to_date()
* Visibility: Private
*
* Parameter: $date - string - Date in the YYYY-MM-DD format
*
* Returns: string - returns the date in a MM/DD/YYYY format.
*
* Description: Converts the date to a format the date() function can recognize
* (using strtotime) for reformatting.
***************************************************************/
    
private function _mysql_to_date($date)
    {
      return 
date("m/d/Y"strtotime($date));
    } 
//end _mysql_to_date()

/***************************************************************
* Function: _date_to_mysql()
* Visibility: Private
*
* Parameter: $date - string - Date in the MM/DD/YYYY format
*
* Returns: string - returns the date in a YYYY-MM-DD format.
*
* Description: Converts the date to a format the date() function can recognize
* (using strtotime) for reformatting.
***************************************************************/
    
private function _date_to_mysql($date)
    {
      return 
date("Y-m-d"strtotime($date));
    } 
//end _date_to_mysql()
    
/***************************************************************
* Function: _get_clientname()
* Visibility: Private
*
* Parameter: $clientid - string - Client ID number.
*
* Returns: string - returns the client's name.
*
* Description: Queries the tblclients table for the client's name based on the
* $clientid passed to the function.
***************************************************************/
    
private function _get_clientname($clientid)
    {
      
$results select_query("tblclients""firstname, lastname", array("id" => sanitize($clientid)));
      
$result mysql_fetch_assoc($results);
      unset(
$results);
      
      if(!empty(
$result['firstname']) || !empty($result['lastname']))
        return 
$result['firstname'] . " " $result['lastname'];
      else
        return 
"Unassigned";
    } 
//end _get_clientname()
    
/***************************************************************
* Function: _get_offset()
* Visibility: Private
*
* Returns: int - returns an offset for use in a LIMIT statement in a MySQL query.
*
* Description: Generates an offset by multiplying the current page value by the
* number of items to display on a page.  This tells the LIMIT statement how many
* records to pass by before pulling the number saved in SHOWITEMS into the query.
***************************************************************/
    
private function _get_offset($page)
    {
      
$nav $page SHOWITEMS;
      return (int) 
$nav;
    } 
//end _get_offset()
    
/***************************************************************
* Function: link()
*
* Parameter: $location - string - File location where the link will point
* Parameter: $get - array - Array of variables to be passed to the URL
*
* Returns: string - URL to be echoed into the <a href=""> tag.
*
* Description: Generates a URL from passed variable and location data.  If the location
* passed to the function was the default link to the addon module, then it already
* contains a ? marking the beginning of the variable string, and a & needs to be inserted instead
* to add the rest of the passed variable data.
***************************************************************/
    
function link($location$get = array())
    {
      
$link $location;
      if(!empty(
$get))
      {
        
//Checks if the call was made using the system-defined $modulelink variable.
        //If it was, it specifies an & before the first $get value (instead of a ?), 
        //because $location was passed with a $_GET variable already in it.
        
if(!strrpos($location"?"))
          
$link .= "?";
        else
          
$link .= "&";

        
//Parses the array key/val pairs into an index/key=val pair for use in the URL.
        
array_walk($get create_function('&$val, $key''$val = $key . "=" . $val ;'));

        
//Condenses the modified $get array into a single string and plugs it into $link.
        
$link .= implode("&"$get);
      } 
//end if

      
return urldecode($link);
    } 
//end generate_link()
    
/***************************************************************
* Function: get_page_item()
*
* Parameter: $id - int - Integer value of the current item requested
*
* Returns: array - Array of item information about the specified $id.
*
* Description: Calls _get_list_items() for specific information about a single to-do list 
* item.  The appropriate query information and LIMIT information is passed to the
* function for return of a single entry's information.
***************************************************************/
    
function get_page_item($id)
    {
      
$post = array("id" => $id);
      echo 
"<script language=\"javascript\">alert();</script>";
      return 
$this->_get_list_items(array("id" => $id), "LIMIT 1"false);
    } 
//end get_page_item()
    
/***************************************************************
* Function: get_page_items()
*
* Parameter: $page - int - Integer value of the current page number
* Parameter: $post - array - Array with the current view filter values
*
* Returns: array - Array of items from _get_list_items()
*
* Description: Creates a MySQL query LIMIT command with the current page information
* contained in it.  It then passes this information to the _get_list_items() 
* function so the query generated in that function knows which chunk of data items
* to call from the database.
***************************************************************/
    
function get_page_items($page 0$post = array())
    {
      
$nav $this->_get_offset($page);

      
$limit "LIMIT " $nav "," SHOWITEMS;

      return 
$this->_get_list_items($post$limitfalse); 
    } 
//end get_page_items()
    
/***************************************************************
* Function: get_page_stats()
*
* Parameter: $totals - array - Array with the # of to-do items and total number of pages
* Parameter: $page - int - Integer value of the current page number
*
* Returns: $stats - string - Text indicating page number info.
*
* Description: Displays a string that tells the user how many total to-do items
* were returned in the current query/view, what page the user is currently on
* and how many total pages there are in the current view.
***************************************************************/
    
function get_page_stats($totals$page 0)
    {
      
$stats  $totals['num_items'] . " Records Found, ";
      
//Page and Num_pages are incrimented because they start counting at 0, not 1.
      
$stats .= "Page " . ++$page " of " . ++$totals['num_pages'];

      unset(
$totals);
      return 
$stats;
    } 
//end get_page_stats()
    
/***************************************************************
* Function: get_skipto()
*
* Parameter: $totals - array - Array with the # of to-do items and total number of pages
* Parameter: $page - int - Integer value of the current page number
*
* Returns: $skipto - string - Drop-down list of available pagenumbers
*
* Description: Displays a drop-down list that will send the user to the selected
* page in the view.
*
* NOTE: CURRENTLY NOT USED.
***************************************************************/
    
function get_skipto($totals$page 0)
    {
      
$skipto  "Jump to Page: \n";
      
$skipto .= "            <select name=\"page\">\n";

      for(
$i 0$i <= $totals['num_pages']; $i++)
      {
        
$skipto .= '                <option value="' $i '"';
        if(
$i == $page)
          
$skipto .= " selected";

        
$skipto .= '>' . ($i 1) . "</option>\n";
      } 
//end for

      
$skipto .= "              </select>\n";
      
$skipto .= "              <input type=\"submit\" value=\"Go\" />";
      unset(
$totals);
      return 
$skipto;
    } 
//end get_skipto()
    
/***************************************************************
* Function: navigate_first()
*
* Parameter: $modulelink - string - Pre-defined $modulelink value from the addonmodule.
* Parameter: $page - int - Integer value of the current page number
* Parameter: $num_pages - int - Total number of pages available to this view.
*
* Returns: $navigate_first - string - Link to the first page in the current view or a text placeholder
*
* Description: If the current page is not the first page in the view, a link to the first 
* page is returned to be echoed.  If the current page is the first page, a text placeholder
* is returned.
***************************************************************/
    
function navigate_first(&$modulelink$page 0)
    {
      if(
$page 0)
        
$navigate_first '<a href="' $this->link($modulelink, array()) . '">&laquo;&laquo; First Page</a>';
      else
        
$navigate_first "&laquo;&laquo; First Page";
        
      return 
$navigate_first;
    } 
//end navigate_first()
    
/***************************************************************
* Function: navigate_prev()
*
* Parameter: $modulelink - string - Pre-defined $modulelink value from the addonmodule.
* Parameter: $page - int - Integer value of the current page number
* Parameter: $num_pages - int - Total number of pages available to this view.
*
* Returns: $navigate_prev - string - Link to the previous page in the current view or a text placeholder
*
* Description: If the current page is not the first page in the view, a link to the prev 
* page is returned to be echoed.  If the current page is the first page, a text placeholder
* is returned.
***************************************************************/
    
function navigate_prev(&$modulelink$page 0)
    {
      if(
$page 0)
      {
        if(
$page != 0)
          
$navigate_prev '<a href="' $this->link($modulelink, array("page" => --$page)) . '">&laquo; Previous Page</a>';
        else
          
$navigate_prev '<a href="' $this->link($modulelink, array()) . '">&laquo; Previous Page</a>';
      }
      else
        
$navigate_prev "&laquo; Previous Page";

      return 
$navigate_prev;
    } 
//end navigate_prev()

/***************************************************************
* Function: navigate_next()
*
* Parameter: $modulelink - string - Pre-defined $modulelink value from the addonmodule.
* Parameter: $page - int - Integer value of the current page number
* Parameter: $num_pages - int - Total number of pages available to this view.
*
* Returns: $navigate_next - string - Link to the next page in the current view or a text placeholder
*
* Description: If the current page is not the final page in the view, a link to the next 
* page is returned to be echoed.  If the current page is the final page, a text placeholder
* is returned.
***************************************************************/
    
function navigate_next(&$modulelink$page 0$num_pages 0)
    {
      if(
$num_pages $page)
        
$navigate_next '<a href="' $this->link($modulelink, array("page" => ++$page)) . '">Next Page &raquo;</a>';
      else
        
$navigate_next "Next Page &raquo;";

      return 
$navigate_next;
    } 
//end navigate_next()
    
/***************************************************************
* Function: navigate_last()
*
* Parameter: $modulelink - string - Pre-defined $modulelink value from the addonmodule.
* Parameter: $page - int - Integer value of the current page number
* Parameter: $num_pages - int - Total number of pages available to this view.
*
* Returns: $navigate_last - string - Link to the last page in the current view or a text placeholder
*
* Description: If the current page is not the final page in the view, a link to the final 
* page is returned to be echoed.  If the current page is the final page, a text placeholder
* is returned.
***************************************************************/
    
function navigate_last(&$modulelink$page 0$num_pages 0)
    {
      if(
$num_pages $page)
        
$navigate_last '<a href="' $this->link($modulelink, array("page" => $num_pages)) . '">Last Page &raquo;&raquo;</a>';
      else
        
$navigate_last "Last Page &raquo;&raquo;";

      return 
$navigate_last;
    } 
//end navigate_first()

/***************************************************************
* Function: mass_status_update()
*
* Parameter: $post - array - List of to-do items to be updated.
* Parameter: $status - string - Status value the items are to be assigned
*
* Description: Receives a $_POST array and assigns all the ID numbers the status 
* specified in $status.
***************************************************************/
    
function mass_status_update($post$status)
    {
      foreach(
$post as $item)
      {
        
update_query("tbltodolist", array("status" => $status), array("id" => $item));
      } 
//end foreach
    
//end mass_inprogress()
    
/***************************************************************
* Function: mass_delete()
*
* Parameter: $post - array - List of to-do items to be deleted.
*
* Description: Receives a $_POST array and passes each individual ID number
* to delete_item() to be deleted.
***************************************************************/
    
function mass_delete($post)
    {
      foreach(
$post as $item)
      {
        
$this->delete_item($item);
      } 
//end foreach
    
//end mass_delete()
    
/***************************************************************
* Function: mass_assign()
*
* Parameter: $post - array - List of to-do items to be updated.
* Parameter: $adminid - string - ID number of the user who gets the items assigned to them
*
* Description: Receives a $_POST array and assigns all the ID numbers the admin specified
* in $adminid.
***************************************************************/
    
function mass_assign($post$adminid)
    {
      foreach(
$post as $item)
      {
        
update_query("tbltodolist", array("admin" => $adminid), array("id" => $item));
      } 
//end foreach
    
//end mass_assign()

/***************************************************************
* Function: delete_item()
*
* Parameter: $id - string - ID number of the to-do list item to be removed.
*
* Description: Receives a $_GET value and deletes the corresponding records from
* "tbltodolist" and "mod_todolist".
***************************************************************/
    
function delete_item($id)
    {
      
delete_query("tbltodolist""id='$id'");
      
delete_query("mod_todolist""listid='$id'");
    } 
//end delete_item()

/***************************************************************
* Function: add_item()
*
* Parameter: $post - array - Array of attribute values for the list item to be saved.
*
* Description: Receives a $_POST value from the "Edit" screen and inserts
* those values into "tbltodolist" and "mod_todolist".
***************************************************************/
    
function add_item($post)
    {
      
//Converts date and duedate to a mysql-friendly format.
      
$post['add_date'] = $this->_date_to_mysql($post['add_date']);
      
$post['add_duedate'] = $this->_date_to_mysql($post['add_duedate']);
      
      if(empty(
$post['add_status']))
        
$post['add_status'] = "New";

      
insert_query("tbltodolist", array("date" => sanitize($post['add_date']), "title" => sanitize($post['add_title']), "description" => sanitize($post['add_description']), "admin" => $post['add_admin'], "status" => $post['add_status'], "duedate" => sanitize($post['add_duedate'])));
      
$id mysql_insert_id();
      
insert_query("mod_todolist", array("listid" => $id"userid" => sanitize($post['add_clientid']), "orderid" => sanitize($post['add_orderid']), "invoiceid" => sanitize($post['add_invoiceid']), "hostingid" => sanitize($post['add_hostingid'])));
    } 
//end add_item()

/***************************************************************
* Function: save_item()
*
* Parameter: $post - array - Array of attribute values for the list item to be saved.
*
* Description: Receives a $_POST value from the "Edit" screen and updates
* the corresponding records in "tbltodolist" and "mod_todolist".
***************************************************************/
    
function save_item($post)
    {
      
//Converts date and duedate to a mysql-friendly format.
      
$post['date'] = $this->_date_to_mysql($post['date']);
      
$post['duedate'] = $this->_date_to_mysql($post['duedate']);

      
update_query("tbltodolist", array("date" => sanitize($post['date']), "title" => sanitize($post['title']), "description" => sanitize($post['description']), "admin" => $post['admin'], "status" => $post['status'], "duedate" => sanitize($post['duedate'])), array("id" => $post['id']));
      
update_query("mod_todolist", array("userid" => sanitize($post['clientid']), "orderid" => sanitize($post['orderid']), "invoiceid" => sanitize($post['invoiceid']), "hostingid" => sanitize($post['hostingid'])), array("listid" => $post['id']));
    } 
//end save_item()
    
/***************************************************************
* Function: get_totals()
*
* Parameter: $post - array - Array of values used to filter the to-do list items.
*
* Returns: mixed array - Contains the number of to-do list items and the number
* of pages the items take up.
*
* Description: Requests an COUNT() query from _get_list_items.  Uses the value
* to calculate the number of display pages the entire list will take up.  Values
* are returned to help calculate pagination values in default.php.
***************************************************************/
    
function get_totals(&$post = array())
    {
      
$count $this->_get_list_items($post""true);

      
// -1 to account for a weird bug where items that are multiples of SHOWITEMS
      //will add an extra (blank) page to the calculations.
      
$num_pages = ($count['COUNT(id)'] - 1) / SHOWITEMS;
      
$num_pages = (int)floor($num_pages);
      
      return array(
"num_items" => $count['COUNT(id)'], "num_pages" => $num_pages);
    } 
//end get_totals()
    
/***************************************************************
* Function: check_admin_status()
*
* Parameter: $adminid - string - ID# of the current user.
*
* Returns: bool - True if the user had admin access, False if not.
*
* Description: Checks the User's ID against the permissions table to see if the user 
* has administrator level access to WHMCS (By way of the Configure Products/Services
* permission).  If the user does have Administrator access, they can do mass changes
* to the To-Do list items.  If not, they don't have access to deleteitems, or see 
* multiple user's items. 
***************************************************************/
    
function check_admin_status($adminid)
    {
      
$query  "SELECT perm.permid ";
      
$query .= "FROM `tbladminperms` AS `perm` INNER JOIN `tbladmins` AS `admin` ON perm.roleid = admin.roleid ";
      
$query .= "WHERE admin.id = " $adminid " AND perm.permid = 71 LIMIT 1;";
      
      
$results full_query($query);
      
$result mysql_fetch_assoc($results);
      
      if(empty(
$result))
        return 
false;
      else
        return 
true;
    } 
//end check_admin_status()
    
/***************************************************************
* Function: get_status_list()
*
* Parameter: $selected - string - Value of the drop-down item to be marked selected
* Parameter: $is_new - bool - Indicates whether or not drop-down is displayed in the 
*   "create new" window.  If it is, certain items are left out.
*
* Returns: $list - string - Drop-down list to be echoed out on the page.
*
* Description: Generates generates a drop-down list to be displayed in the filter and 
* "add new" window.  If the list is displayed in the "add new" window, the POST name
* is changed, and the "Incomplete" and "Canceled" options is left out.
***************************************************************/
    
function get_status_list($selected ""$is_new false)
    {
      
$statuses = array("New""Pending""In Progress""Completed""Postponed");
      
      if(
$is_new)
        
$list "<select name=\"add_status\">\n";
      else
        
$list "<select name=\"status\">\n";
      if(!
$is_new && $selected == "Incomplete")
        
$list .= "              <option selected>Incomplete</option>\n";
      elseif(!
$is_new)
        
$list .= "              <option>Incomplete</option>\n";
      else
        
$list .= "";

      foreach(
$statuses as $status)
      {
        if(
$selected == $status)
          
$list .= "              <option selected>";
        else
          
$list .= "              <option>";
        
$list .= $status "</option>\n";
      } 
//end foreach
      
if(!$is_new)
        
$list .= "              <option>Overdue</option>\n              <option>Canceled</option>\n";
      
$list .= "              <option value=\"\">All</option>\n            </select>";
      return 
$list;
    } 
//end get_status_list()

/***************************************************************
* Function: get_admin_list()
*
* Parameter: $selected - string - Value of the drop-down item to be marked selected
* Parameter: $is_new - bool - Indicates whether or not drop-down is displayed in the 
*   "create new" window.  If it is, certain items are left out.
*
* Returns: $list - string - Drop-down list to be echoed out on the page.
*
* Description: Generates generates a drop-down list to be displayed in the filter and 
* "add new" window.  If the list is displayed in the "add new" window, the POST name
* is changed.
***************************************************************/
    
function get_admin_list($selected ""$is_new false)
    {
      
$query  "SELECT admin.id, admin.firstname, admin.lastname ";
      
$query .= "FROM `tbladmins` AS `admin` INNER JOIN `tbladminperms` AS `perm` ON admin.roleid = perm.roleid ";
      
$query .= "WHERE perm.permid = 50 AND admin.lastname <> 'Account' ";
      
$query .= "ORDER BY admin.firstname;";
      
      
$results full_query($query);
      if(
$is_new)
        
$list "<select name=\"add_admin\">\n";
      else
        
$list "<select name=\"admin\">\n";
      
$list .= "              <option value=\"\">Assign To:</option>\n";
      while(
$row mysql_fetch_assoc($results))
      {
        
$list .= '              <option value="' $row['id'] . '"';
        if(
$row['id'] == $selected)
          
$list .= " selected ";
        
$list .= '>' $row['firstname'] . " " $row['lastname'] . "</option>\n";
      } 
//end while
      
      
$list .= '            </select>';
      
      return 
$list;
    } 
//end get_admin_list()
    
  
//end class{}
  
  //Global class variable.
  
if(!isset($list))
  {
    
$list = new todolist();
  } 
//end if
?>