<?php
/**
 * phpwsBusinesses
 *
 * See docs/AUTHORS and docs/COPYRIGHT for relevant info.
 *
 * 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.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @version     $Id: Business.php,v 1.6 2005/09/29 19:55:54 verdonv Exp $
 */

require_once(PHPWS_SOURCE_DIR . 'core/Item.php');
require_once(PHPWS_SOURCE_DIR . 'core/EZform.php');
require_once(PHPWS_SOURCE_DIR . 'core/Error.php');
require_once(PHPWS_SOURCE_DIR . 'core/Text.php');
require_once(PHPWS_SOURCE_DIR . 'core/WizardBag.php');
require_once(PHPWS_SOURCE_DIR . 'mod/help/class/CLS_help.php');
require_once(PHPWS_SOURCE_DIR . 'mod/phpwsbusinesses/class/Manager.php');

if($GLOBALS['core']->moduleExists('comments')) {
  require_once(PHPWS_SOURCE_DIR . 'mod/comments/class/CommentManager.php');
}

// Include PEAR objects
require_once('Date.php');
require_once('Contact_Vcard_Build.php');
require_once('Contact_Vcard_Parse.php');


class BUSINESSES_Business extends PHPWS_Item {

    /**
     * Image information for the business
     *
     * @var      string
     * @access   private
     */
    var $_image = NULL;


    /**
     * Flag 1/0 to enable comments
     *
     * @var      bit
     * @access   private
     */
    var $_sw_comments = 0;


    /**
     * Flag 1/0 to enable anonymous comments
     *
     * @var      bit
     * @access   private
     */
    var $_sw_anonymous = 0;


    /**
     * datetime stamp for record expiry date, if enabled
     *
     * @var      string
     * @access   private
     */
    var $_expiryDate = 0;


    /**
     * The given (first) name of the contact
     *
     * @var      string
     * @access   private
     */
    var $_firstname = NULL;


    /**
     * The middle name of the contact
     *
     * @var      string
     * @access   private
     */
    var $_middlename = NULL;


    /**
     * The family (last) name of the contact
     *
     * @var      string
     * @access   private
     */
    var $_lastname = NULL;


    /**
     * The prefix (Dr. , Mr. , Fr. , etc) of the contact
     *
     * @var      string
     * @access   private
     */
    var $_prefix = NULL;


    /**
     * The suffix (Jr. , Sr. , III, M.D., PhD) of the contact
     *
     * @var      string
     * @access   private
     */
    var $_suffix = NULL;


    /**
     * The email address of the business
     *
     * @var      string
     * @access   private
     */
    var $_email = NULL;


    /**
     * Toll-free phone number
     *
     * @var      string
     * @access   private
     */
    var $_phone_tollfree = NULL;


    /**
     * Work phone number
     *
     * @var      string
     * @access   private
     */
    var $_phone_work = NULL;


    /**
     * Fax phone number
     *
     * @var      string
     * @access   private
     */
    var $_phone_fax = NULL;


    /**
     * Company name
     *
     * @var      string
     * @access   private
     */
    var $_company_name = NULL;


    /**
     * Contact's title/position within company
     *
     * @var      string
     * @access   private
     */
    var $_company_title = NULL;


    /**
     * Company street address
     *
     * @var      string
     * @access   private
     */
    var $_company_street = NULL;


    /**
     * Company city
     *
     * @var      string
     * @access   private
     */
    var $_company_city = NULL;


    /**
     * Company state
     *
     * @var      string
     * @access   private
     */
    var $_company_state = NULL;


    /**
     * Company postal/zip code
     *
     * @var      string
     * @access   private
     */
    var $_company_zip = NULL;


    /**
     * Company country
     *
     * @var      string
     * @access   private
     */
    var $_company_country = NULL;


    /**
     * Company website
     *
     * @var      string
     * @access   private
     */
    var $_company_website = NULL;


    /**
     * Description for the Business
     *
     * @var      string
     * @access   private
     */
    var $_comments = NULL;

    /**
     * Business visibility
     *
     * 0 = Public (default)
     * 1 = Protected
     * 2 = Private
     *
     * @var      int
     * @access   private
     */
    var $_visibility = NULL;

    /**
     * Flag if business is info for owner
     *
     * @var      int
     * @access   private
     */
    var $_mine = 0;

    /**
     * Custom fields
     *
     * @var      string
     * @access   private
     */
    var $_custom1 = NULL;
    var $_custom2 = NULL;
    var $_custom3 = NULL;
    var $_custom4 = NULL;
    var $_custom1_priv = NULL;
    var $_custom2_priv = NULL;
    var $_custom3_priv = NULL;
    var $_custom4_priv = NULL;

    var $visibilities = array();


    function BUSINESSES_Business($BUSINESS_ID = NULL) {
        /* These vars are excluded on commit() */
        $exclude = array('visibilities');
        $this->addExclude($exclude);
        $this->visibilities = array(
                                '0'=>$_SESSION['translate']->it('Public'),
                                '1'=>$_SESSION['translate']->it('Protected'),
                                '2'=>$_SESSION['translate']->it('Private')
                              );


        $this->setTable('mod_phpwsbusinesses_businesses');

		$busSettings = BUSINESSES_Manager::getSettingsRow();

        if (isset($BUSINESS_ID)) {
            if (is_numeric($BUSINESS_ID)) {
                $this->setId($BUSINESS_ID);
                $this->init();
            } elseif (is_array($BUSINESS_ID)) {
                $this->init($BUSINESS_ID);
            }
        } else {
            if ($_REQUEST['BUSINESSES_MAN_OP'] == 'edit') {
                // Find business owned by this username
                $sql = "select id from " . $GLOBALS['core']->tbl_prefix . "mod_phpwsbusinesses_businesses where owner='" . $_SESSION['OBJ_user']->username . "' order by mine desc, created asc";
                $results = $GLOBALS['core']->getCol($sql);
                if (sizeof($results) > 0) {
                    $this->setId($results[0]);
                    $this->init();
                } else {
					header("location:index.php?module=phpwsbusinesses&BUSINESSES_MAN_OP=addAppl");
                }

				/* Check for and create image directory if needed */
				if (!is_dir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_SESSION['OBJ_user']->username))
					mkdir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_SESSION['OBJ_user']->username);
					if (is_dir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_SESSION['OBJ_user']->username))
						$tags['IMAGE_DIR_TEXT'] = 'phpwsBusinesses image directory ' . $GLOBALS['core']->home_dir . 'images/phpwsbusinesses successfully created!<br />';
					else
						$tags['IMAGE_DIR_TEXT'] = 'phpwsBusinesses could not create the image directory: ' . $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_SESSION['OBJ_user']->username .'<br />You will have to do this manually!<br />';
			
            }
            if ($_REQUEST['BUSINESSES_MAN_OP'] == 'add') {
				$this->setLabel($_SESSION['OBJ_user']->username);
				$this->setOwner($_SESSION['OBJ_user']->username);
				// Do I want to set this to 1?  Don't want to do this if user is admin who can own multiple businesses.
				$this->_mine = 1;

				$expires = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")+$busSettings['expireInterval'], date("Y")));
				$this->_expiryDate = $expires . " 12:00:00";

				/* Check for and create image directory if needed */
				if (!is_dir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_SESSION['OBJ_user']->username))
					mkdir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_SESSION['OBJ_user']->username);
					if (is_dir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_SESSION['OBJ_user']->username))
						$tags['IMAGE_DIR_TEXT'] = 'phpwsBusinesses image directory ' . $GLOBALS['core']->home_dir . 'images/phpwsbusinesses successfully created!<br />';
					else
						$tags['IMAGE_DIR_TEXT'] = 'phpwsBusinesses could not create the image directory: ' . $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_SESSION['OBJ_user']->username .'<br />You will have to do this manually!<br />';
			
            }
            if ($_REQUEST['BUSINESSES_MAN_OP'] == 'addAppl') {

				if (!empty($_SESSION['OBJ_user']->username)) { 
					$this->setLabel($_SESSION['OBJ_user']->username);
					$this->setOwner($_SESSION['OBJ_user']->username);
				} else { 
					$_SESSION['OBJ_user']->username = $_COOKIE["app_name"];
					$this->setLabel($_COOKIE["app_name"]);
					$this->setOwner($_COOKIE["app_name"]);
				}

				// Do I want to set this to 1?  Don't want to do this if user is admin who can own multiple businesses.
				$this->_mine = 1;

				$expires = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")+$busSettings['expireInterval'], date("Y")));
				$this->_expiryDate = $expires . " 12:00:00";

				// first check for the existance of the img dir
				if (!is_dir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_SESSION['OBJ_user']->username . '/')) {
					// if it don't exist, make it
					/* Create image directory */
					mkdir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_SESSION['OBJ_user']->username);
					if (is_dir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_SESSION['OBJ_user']->username))
						$tags['IMAGE_DIR_TEXT'] = 'phpwsBusinesses image directory ' . $GLOBALS['core']->home_dir . 'images/phpwsbusinesses successfully created!<br />';
					else
						$tags['IMAGE_DIR_TEXT'] = 'phpwsBusinesses could not create the image directory: ' . $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_SESSION['OBJ_user']->username .'<br />You will have to do this manually!<br />';
				}
            }
        }
    }// END FUNC BUSINESSES_Business


	function viewDate($date) {
		$info = explode(" ", $date);
		$date = explode("-", $info[0]);
		$time = explode(":", $info[1]);
		return date(PHPWS_DATE_FORMAT . " " . PHPWS_TIME_FORMAT, (mktime($time[0], $time[1], $time[2], $date[1], $date[2], $date[0])+$GLOBALS['core']->datetime->time_dif));
	}
	
	function formatDate($date) {
		return date("Ymd", strtotime($date));
	}
	
    function _view() {
        $tags = array();

        if ($_SESSION['OBJ_fatcat']) {
            $cat = $_SESSION['OBJ_fatcat']->fatcatLinks($this->getId());
            if (isset($cat) && !empty($cat)) {
                $tags['CATEGORY_TEXT'] = $_SESSION['translate']->it('Category');
                $tags['CATEGORY'] = $cat;
            }

            // Not sure if we want this
            $_SESSION['OBJ_fatcat']->whatsRelated($this->getId());
        }

        if (!empty($this->_image)) {
            $tags['IMAGE'] = '<img src="images/phpwsbusinesses/' . $this->getOwner() .'/' . $this->_image['name'] . '" alt="' . $this->getLabel() . '" border="0" />';
            if (isset($this->_image['thumb_name']))
                $tags['THUMBNAIL'] = '<img src="images/phpwsbusinesses/' . $this->getOwner() . '/' . $this->_image['thumb_name'] . '" alt="' . $this->getLabel() . '" border="0" />';
        }

        if (!empty($this->_visibility)) {
            $tags['VISIBILITY_TEXT'] = $_SESSION['translate']->it('Visbility');
            $tags['VISIBILITY'] = $this->visibilities[$this->_visibility];
        }

        if (!empty($this->_prefix)) {
            $tags['NAME_TEXT'] = $_SESSION['translate']->it('Name');
            $tags['PREFIX_TEXT'] = $_SESSION['translate']->it('Prefix');
            $tags['PREFIX'] = PHPWS_Text::parseOutput($this->_prefix);
        }

        if (!empty($this->_lastname)) {
            $tags['NAME_TEXT'] = $_SESSION['translate']->it('Name');
            $tags['LASTNAME'] = PHPWS_Text::parseOutput($this->_lastname);
            $tags['LASTNAME_TEXT'] = $_SESSION['translate']->it('Last');
        }

        if (!empty($this->_firstname)) {
            $tags['NAME_TEXT'] = $_SESSION['translate']->it('Name');
            $tags['FIRSTNAME_TEXT'] = $_SESSION['translate']->it('First');
            $tags['FIRSTNAME'] = PHPWS_Text::parseOutput($this->_firstname);
        }

        if (!empty($this->_middlename)) {
            $tags['NAME_TEXT'] = $_SESSION['translate']->it('Name');
            $tags['MIDDLENAME_TEXT'] = $_SESSION['translate']->it('Middle');
            $tags['MIDDLENAME'] = PHPWS_Text::parseOutput($this->_middlename);
        }

        if (!empty($this->_suffix)) {
            $tags['NAME_TEXT'] = $_SESSION['translate']->it('Name');
            $tags['SUFFIX_TEXT'] = $_SESSION['translate']->it('Suffix');
            $tags['SUFFIX'] = PHPWS_Text::parseOutput($this->_suffix);
        }

        if (!empty($this->_email)) {
            $tags['NAME_TEXT'] = $_SESSION['translate']->it('Name');
            $tags['EMAIL_TEXT'] = $_SESSION['translate']->it('Email');
            $tags['EMAIL'] = PHPWS_Text::parseOutput($this->_email);
        }

        if (!empty($this->_phone_tollfree)) {
            $tags['PHONE_TOLLFREE'] = PHPWS_Text::parseOutput($this->_phone_tollfree);
            $tags['PHONE_TOLLFREE_TEXT'] = $_SESSION['translate']->it('Toll-Free');
            $tags['PHONE_TEXT'] = $_SESSION['translate']->it('Phone');
        }

        if (!empty($this->_phone_work)) {
            $tags['PHONE_WORK'] = PHPWS_Text::parseOutput($this->_phone_work);
            $tags['PHONE_WORK_TEXT'] = $_SESSION['translate']->it('Work');
            $tags['PHONE_TEXT'] = $_SESSION['translate']->it('Phone');
        }

        if (!empty($this->_phone_fax)) {
            $tags['PHONE_FAX'] = PHPWS_Text::parseOutput($this->_phone_fax);
            $tags['PHONE_FAX_TEXT'] = $_SESSION['translate']->it('Fax');
            $tags['PHONE_TEXT'] = $_SESSION['translate']->it('Phone');
        }

        if (!empty($this->_company_name)) {
            $tags['COMPANY_NAME'] = PHPWS_Text::parseOutput($this->_company_name);
            $tags['COMPANY_NAME_TEXT'] = $_SESSION['translate']->it('Company');
        }

        if (!empty($this->_company_title)) {
            $tags['COMPANY_TITLE'] = PHPWS_Text::parseOutput($this->_company_title);
            $tags['COMPANY_TITLE_TEXT'] = $_SESSION['translate']->it('Title');
        }

        if (!empty($this->_company_street)) {
            $tags['COMPANY_ADDRESS_TEXT'] = $_SESSION['translate']->it('Address');
            $tags['COMPANY_STREET'] = PHPWS_Text::parseOutput($this->_company_street);
            $tags['COMPANY_STREET_TEXT'] = $_SESSION['translate']->it('Street');
        }

        if (!empty($this->_company_city)) {
            $tags['COMPANY_ADDRESS_TEXT'] = $_SESSION['translate']->it('Address');
            $tags['COMPANY_CITY'] = PHPWS_Text::parseOutput($this->_company_city);
            $tags['COMPANY_CITY_TEXT'] = $_SESSION['translate']->it('City');
        }

        if (!empty($this->_company_state)) {
            $tags['COMPANY_ADDRESS_TEXT'] = $_SESSION['translate']->it('Address');
            $tags['COMPANY_STATE'] = PHPWS_Text::parseOutput($this->_company_state);
            $tags['COMPANY_STATE_TEXT'] = $_SESSION['translate']->it('Prov/State');
        }

        if (!empty($this->_company_zip)) {
            $tags['COMPANY_ADDRESS_TEXT'] = $_SESSION['translate']->it('Address');
            $tags['COMPANY_ZIP'] = PHPWS_Text::parseOutput($this->_company_zip);
            $tags['COMPANY_ZIP_TEXT'] = $_SESSION['translate']->it('Postal/Zip');
        }

        if (!empty($this->_company_country)) {
            $tags['COMPANY_ADDRESS_TEXT'] = $_SESSION['translate']->it('Address');
            $tags['COMPANY_COUNTRY'] = PHPWS_Text::parseOutput($this->_company_country);
            $tags['COMPANY_COUNTRY_TEXT'] = $_SESSION['translate']->it('Country');
        }

        if (!empty($this->_company_website)) {
            $tags['COMPANY_WEBSITE'] = PHPWS_Text::parseOutput($this->_getWebsite($this->_company_website));
            $tags['COMPANY_WEBSITE_TEXT'] = $_SESSION['translate']->it('Website');
        }

        if (!empty($this->_comments)) {
            $tags['COMMENTS_TEXT'] = $_SESSION['translate']->it('Description');
            $tags['COMMENTS'] = PHPWS_Text::parseOutput($this->_comments);
        }

        if (!empty($this->_custom1)) {
            $tags['CUSTOM1_TEXT'] = $_SESSION['BUSINESSES_Manager']->_custom1label;
            $tags['CUSTOM1'] = PHPWS_Text::parseOutput($this->_custom1);
        }

        if (!empty($this->_custom2)) {
            $tags['CUSTOM2_TEXT'] = $_SESSION['BUSINESSES_Manager']->_custom2label;
            $tags['CUSTOM2'] = PHPWS_Text::parseOutput($this->_custom2);
        }

        if (!empty($this->_custom3)) {
            $tags['CUSTOM3_TEXT'] = $_SESSION['BUSINESSES_Manager']->_custom3label;
            $tags['CUSTOM3'] = PHPWS_Text::parseOutput($this->_custom3);
        }

        if (!empty($this->_custom4)) {
            $tags['CUSTOM4_TEXT'] = $_SESSION['BUSINESSES_Manager']->_custom4label;
            $tags['CUSTOM4'] = PHPWS_Text::parseOutput($this->_custom4);
        }

		if ($this->showPrivOK()) 
			if (!empty($this->_custom1_priv)) {
				$tags['CUSTOM1_TEXT_PRIV'] = $_SESSION['BUSINESSES_Manager']->_custom1label_priv;
				$tags['CUSTOM1_PRIV'] = PHPWS_Text::parseOutput($this->_custom1_priv);
			}

		if ($this->showPrivOK()) 
			if (!empty($this->_custom2_priv)) {
				$tags['CUSTOM2_TEXT_PRIV'] = $_SESSION['BUSINESSES_Manager']->_custom2label_priv;
				$tags['CUSTOM2_PRIV'] = PHPWS_Text::parseOutput($this->_custom2_priv);
			}

		if ($this->showPrivOK()) 
			if (!empty($this->_custom3_priv)) {
				$tags['CUSTOM3_TEXT_PRIV'] = $_SESSION['BUSINESSES_Manager']->_custom3label_priv;
				$tags['CUSTOM3_PRIV'] = PHPWS_Text::parseOutput($this->_custom3_priv);
			}

		if ($this->showPrivOK()) 
			if (!empty($this->_custom4_priv)) {
				$tags['CUSTOM4_TEXT_PRIV'] = $_SESSION['BUSINESSES_Manager']->_custom4label_priv;
				$tags['CUSTOM4_PRIV'] = PHPWS_Text::parseOutput($this->_custom4_priv);
			}

		if (!empty($this->_custom1) || !empty($this->_custom2) || !empty($this->_custom3) || !empty($this->_custom4))
			$tags['CUSTOM_TEXT'] = $_SESSION['translate']->it('Additional Information');

		if (!empty($this->_custom1_priv) || !empty($this->_custom2_priv) || !empty($this->_custom3_priv) || !empty($this->_custom4_priv))
			if ($this->showPrivOK()) 
				$tags['CUSTOM_TEXT_PRIV'] = $_SESSION['translate']->it('Hidden Additional Information');

		$tags['ADDRESS_TEXT'] = $_SESSION['translate']->it('Address');
		$tags['CONTACT_TEXT'] = $_SESSION['translate']->it('Contact');
        $tags['VCARD'] = '<a href="index.php?module=phpwsbusinesses&amp;BUSINESSES_Business_OP=vcard">' . $_SESSION['translate']->it('Get vCard') . '</a>';

        if (($_SESSION['OBJ_user']->username == $this->getOwner()) || $_SESSION['OBJ_user']->allow_access('phpwsbusinesses','edit_businesses'))
            $tags['EDIT'] = '<a href="index.php?module=phpwsbusinesses&amp;BUSINESSES_MAN_OP=edit&amp;PHPWS_MAN_ITEMS[]=' . $this->getId() . '">' . $_SESSION['translate']->it('Edit') . '</a>';

		$busSettings = BUSINESSES_Manager::getSettingsRow();
		if($GLOBALS["core"]->moduleExists("comments") && $busSettings['enableComments'] && $this->_sw_comments) {
			if(!isset($_SESSION["PHPWS_CommentManager"]))
				$_SESSION["PHPWS_CommentManager"] = new PHPWS_CommentManager;
				$tags["USER_COMMENTS"] = $_SESSION["PHPWS_CommentManager"]->listCurrentComments("phpwsbusinesses", $this->_id, $this->_sw_anonymous);
		}

        return PHPWS_Template::processTemplate($tags, 'phpwsbusinesses', 'view.tpl');
    }// END FUNC _view

    
    function _edit() {
        if (($_SESSION['OBJ_user']->username != $this->getOwner()) && !$_SESSION['OBJ_user']->allow_access('phpwsbusinesses','edit_businesses')) {
            $message = $_SESSION['translate']->it('Access to edit business was denied due to lack of proper permissions.');
            $error = new PHPWS_Error('phpwsbusinesses', 'BUSINESSES_Business::_edit()', $message, 'exit', 1);
            $error->message();
            return FALSE;
        }

		/* get the module settings */
		$busSettings = BUSINESSES_Manager::getSettingsRow();

        /* Create form */
        $form = new EZform('BUSINESSES_Business_edit');
        $tabs = 1;

        /* Company Name */
        $form->add('Business_company_name', 'text', $this->_company_name);
        $form->setSize('Business_company_name', 30);
        $form->setTab('Business_company_name', $tabs);
        $tabs++;

        /* Description */
        $form->add('Business_comments', 'textarea', $this->_comments);
        $form->setRows('Business_comments', 5);
        $form->setCols('Business_comments', 40);
        $form->setTab('Business_comments', $tabs);
        $tabs++;

        if ($_SESSION['OBJ_user']->allow_access('phpwsbusinesses','edit_businesses')) {
            $users = array();
            $sql = 'SELECT username FROM ' . $GLOBALS['core']->tbl_prefix . 'mod_users order by username';
            $result = $GLOBALS['core']->query($sql);

            if ($result) {
                while($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
                    $users[$row['username']] = $row['username'];
                }
            }
            
            /* Business Owner */
            $form->add('Business_owner', 'select', $users);
            $form->setMatch('Business_owner', $this->getOwner());
            $form->setTab('Business_owner', $tabs);
            $tabs++;
			$form->add('Business_owner_old', 'hidden', $this->getOwner());

			/* Expiry date */
			$form->dateForm('Business_expiryDate', $this->formatDate($this->_expiryDate), substr($this->formatDate($this->_expiryDate), 0, 4), date('Y') + 10, TRUE, TRUE);
			$form->setTab('Business_expiryDate', $tabs);
			$tabs++; 

        }

        /* Company Address */
        $form->add('Business_company_street', 'textarea', $this->_company_street);
        $form->setRows('Business_company_street', 2);
        $form->setCols('Business_company_street', 40);
        $form->setTab('Business_company_street', $tabs);
        $tabs++;

        /* Company City */
        $form->add('Business_company_city', 'text', $this->_company_city);
        $form->setSize('Business_company_city', 20);
        $form->setTab('Business_company_city', $tabs);
        $tabs++;

        /* Company State */
        $form->add('Business_company_state', 'text', $this->_company_state);
        $form->setSize('Business_company_state', 10);
        $form->setTab('Business_company_state', $tabs);
        $tabs++;

        /* Company Postal/Zip Code */
        $form->add('Business_company_zip', 'text', $this->_company_zip);
        $form->setSize('Business_company_zip', 10);
        $form->setTab('Business_company_zip', $tabs);
        $tabs++;

        /* Company Country */
        $form->add('Business_company_country', 'text', $this->_company_country);
        $form->setSize('Business_company_country', 20);
        $form->setTab('Business_company_country', $tabs);
        $tabs++;

        /* Company Website */
        $form->add('Business_company_website', 'text', $this->_getWebsite($this->_company_website));
        $form->setSize('Business_company_website', 40);
        $form->setTab('Business_company_website', $tabs);
        $tabs++;

        /* Business Email */
        $form->add('Business_email', 'text', $this->_email);
        $form->setSize('Business_email', 33);
        $form->setTab('Business_email', $tabs);
        $tabs++;

        /* Work Phone */
        $form->add('Business_phone_work', 'text', $this->_phone_work);
        $form->setSize('Business_phone_work', 20);
        $form->setTab('Business_phone_work', $tabs);
        $tabs++;

        /* Fax Phone */
        $form->add('Business_phone_fax', 'text', $this->_phone_fax);
        $form->setSize('Business_phone_fax', 20);
        $form->setTab('Business_phone_fax', $tabs);
        $tabs++;

        /* Toll-free Phone */
        $form->add('Business_phone_tollfree', 'text', $this->_phone_tollfree);
        $form->setSize('Business_phone_tollfree', 20);
        $form->setTab('Business_phone_tollfree', $tabs);
        $tabs++;

        /* Contact Prefix */
        $form->add('Contact_prefix', 'text', $this->_prefix);
        $form->setSize('Contact_prefix', 5);
        $form->setTab('Contact_prefix', $tabs);
        $tabs++;

        /* Contact Given Name */
        $form->add('Contact_firstname', 'text', $this->_firstname);
        $form->setSize('Contact_firstname', 20);
        $form->setTab('Contact_firstname', $tabs);
        $tabs++;

        /* Contact Middle Name */
        $form->add('Contact_middlename', 'text', $this->_middlename);
        $form->setSize('Contact_middlename', 15);
        $form->setTab('Contact_middlename', $tabs);
        $tabs++;

        /* Contact Family Name */
        $form->add('Contact_lastname', 'text', $this->_lastname);
        $form->setSize('Contact_lastname', 25);
        $form->setTab('Contact_lastname', $tabs);
        $tabs++;

        /* Contact Suffix */
        $form->add('Contact_suffix', 'text', $this->_suffix);
        $form->setSize('Contact_suffix', 5);
        $form->setTab('Contact_suffix', $tabs);
        $tabs++;

        /* Company Title/Position */
        $form->add('Contact_company_title', 'text', $this->_company_title);
        $form->setSize('Contact_company_title', 20);
        $form->setTab('Contact_company_title', $tabs);
        $tabs++;

        /* Custom Field 1 */
        $form->add('Business_custom1', 'text', $this->_custom1);
        $form->setSize('Business_custom1', 20);
        $form->setTab('Business_custom1', $tabs);
        $tabs++;

        /* Custom Field 2 */
        $form->add('Business_custom2', 'text', $this->_custom2);
        $form->setSize('Business_custom2', 20);
        $form->setTab('Business_custom2', $tabs);
        $tabs++;

        /* Custom Field 3 */
        $form->add('Business_custom3', 'text', $this->_custom3);
        $form->setSize('Business_custom3', 20);
        $form->setTab('Business_custom3', $tabs);
        $tabs++;

        /* Custom Field 4 */
        $form->add('Business_custom4', 'text', $this->_custom4);
        $form->setSize('Business_custom4', 20);
        $form->setTab('Business_custom4', $tabs);
        $tabs++;

        /* Custom Field 1_priv */
        $form->add('Business_custom1_priv', 'text', $this->_custom1_priv);
        $form->setSize('Business_custom1_priv', 20);
        $form->setTab('Business_custom1_priv', $tabs);
        $tabs++;

        /* Custom Field 2_priv */
        $form->add('Business_custom2_priv', 'text', $this->_custom2_priv);
        $form->setSize('Business_custom2_priv', 20);
        $form->setTab('Business_custom2_priv', $tabs);
        $tabs++;

        /* Custom Field 3_priv */
        $form->add('Business_custom3_priv', 'text', $this->_custom3_priv);
        $form->setSize('Business_custom3_priv', 20);
        $form->setTab('Business_custom3_priv', $tabs);
        $tabs++;

        /* Custom Field 4_priv */
        $form->add('Business_custom4_priv', 'text', $this->_custom4_priv);
        $form->setSize('Business_custom4_priv', 20);
        $form->setTab('Business_custom4_priv', $tabs);
        $tabs++;

        /* Image */
//        $form->imageForm('Business_image', $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/', $this->_image['name']);

		if ($current_images = PHPWS_File::readDirectory($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/', FALSE, TRUE)){
			$imageList = array();
			foreach ($current_images as $imageName){
				if (preg_match("/\.+(jpg|png|gif)$/i", $imageName) && !preg_match("/\_tn.+(jpg|png|gif)$/i", $imageName))
					$imageList[$imageName] = $imageName;
				}
			if (sizeof($imageList) > 0)
				$current_images = array("none"=>"&lt;".$_SESSION["translate"]->it("None")."&gt;") + $imageList;
			else
				$current_images = array("none"=>"&lt;".$_SESSION["translate"]->it("None")."&gt;");
		}

		$form->add("NEW_Business_image", "file");
		$form->setSize("NEW_Business_image", 30);
		if ($current_images){
			$form->add("CURRENT_Business_image", "select", $current_images);
			$form->setMatch("CURRENT_Business_image", $this->_image['name']);
			$form->add("REMOVE_Business_image", "submit", $_SESSION["translate"]->it("Remove Image"));
		}

		/* Visibility */
		$form->add('Business_visibility', 'select', $this->visibilities);
		$form->setMatch('Business_visibility', $this->_visibility);
		$form->setTab('Business_visibility', $tabs);
		$tabs++;

		/* Mine */
		$form->add('Business_mine', 'checkbox');
		$form->setMatch('Business_mine', $this->_mine);
		$form->setTab('Business_mine', $tabs);
		$tabs++;

        /* Save Button */
        $form->add('Business_save', 'submit', $_SESSION['translate']->it('Save'));
        $form->setTab('Business_save', $tabs);

        /* Module Information */
        $form->add('module', 'hidden', 'phpwsbusinesses');
        $form->add('BUSINESSES_Business_OP', 'hidden', 'save');
        if ($_REQUEST['BUSINESSES_MAN_OP'] == 'addAppl') 
			$form->add('addAppl', 'hidden', '1');

        $tags = array();
        $tags = $form->getTemplate();

		/* comment manager stuff */
		if($GLOBALS['core']->moduleExists('comments')) {
			if ($busSettings['enableComments']) {
				if (!$busSettings['enforceComments']) {
					$tags['COMMENTS_LABEL'] = $_SESSION['translate']->it('Allow User Comments?');
					$tags['YES_COMMENTS'] = PHPWS_Form::formRadio('Business_sw_comments', 1, $this->_sw_comments, NULL, $_SESSION['translate']->it('Yes'));
					$tags['NO_COMMENTS'] = PHPWS_Form::formRadio('Business_sw_comments', 0, $this->_sw_comments, NULL, $_SESSION['translate']->it('No'));
				} else {
					$tags['YES_COMMENTS'] = PHPWS_Form::formHidden('Business_sw_comments', 1);
					$tags['COMMENTS_LABEL'] = $_SESSION['translate']->it('User comments are globally enabled.');
				}
			}
			if ($busSettings['enableComments'] && $busSettings['enableAnnonComments']) {
				if (!$busSettings['enforceAnnonComments']) {
					$tags['ANON_LABEL'] = $_SESSION['translate']->it('Allow Anonymous Comments?');
					$tags['ANON_YES'] = PHPWS_Form::formRadio('Business_sw_anonymous', 1, $this->_sw_anonymous, NULL, $_SESSION['translate']->it('Yes'));
					$tags['ANON_NO'] = PHPWS_Form::formRadio('Business_sw_anonymous', 0, $this->_sw_anonymous, NULL, $_SESSION['translate']->it('No'));
				} else {
					$tags['ANON_YES'] = PHPWS_Form::formHidden('Business_sw_anonymous', 1);
					$tags['ANON_LABEL'] = $_SESSION['translate']->it('Anonymous comments are globally enabled.');
				}
			}
		}

        /* FatCat Category */
        if ($_SESSION['OBJ_fatcat']) {
            $tags['CATEGORIES_TEXT'] = $_SESSION['translate']->it('Category');
            $tags['CATEGORIES'] = $_SESSION['OBJ_fatcat']->showSelect($this->getId(), 'multiple', NULL, 'phpwsbusinesses', NULL, FALSE);
        }

        $tags['PRIMARY_TEXT'] = $_SESSION['translate']->it('Primary Information');
        $tags['COMPANY_NAME_TEXT'] = $_SESSION['translate']->it('Company');
        $tags['IMAGE_TEXT'] = $_SESSION['translate']->it('Image');
        $tags['COMMENTS_TEXT'] = $_SESSION['translate']->it('Description');
        if ($_SESSION['OBJ_user']->allow_access('phpwsbusinesses','edit_businesses')) {
            $tags['OWNER_TEXT'] = $_SESSION['translate']->it('Owner');
			$tags["EXPIRYDATE_TEXT"] = $_SESSION["translate"]->it("Expiry Date");
			$tags["EXPIRYDATE_JS"] = PHPWS_WizardBag::js_insert("popcalendar", NULL, NULL, FALSE,
									array("month"=>"Business_expiryDate_month", 
									  "day"=>"Business_expiryDate_day", 
									  "year"=>"Business_expiryDate_year"));
        }

        $tags['ADDRESS_TEXT'] = $_SESSION['translate']->it('Address');
        $tags['COMPANY_ADDRESS_TEXT'] = $_SESSION['translate']->it('Address');
        $tags['COMPANY_STREET_TEXT'] = $_SESSION['translate']->it('Street');
        $tags['COMPANY_CITY_TEXT'] = $_SESSION['translate']->it('City');
        $tags['COMPANY_STATE_TEXT'] = $_SESSION['translate']->it('Prov/State');
        $tags['COMPANY_ZIP_TEXT'] = $_SESSION['translate']->it('Postal/Zip');
        $tags['COMPANY_COUNTRY_TEXT'] = $_SESSION['translate']->it('Country');
        $tags['COMPANY_WEBSITE_TEXT'] = $_SESSION['translate']->it('Website');
        $tags['EMAIL_TEXT'] = $_SESSION['translate']->it('Email');

        $tags['PHONE_TEXT'] = $_SESSION['translate']->it('Phone Numbers');
        $tags['PHONE_WORK_TEXT'] = $_SESSION['translate']->it('Work');
        $tags['PHONE_FAX_TEXT'] = $_SESSION['translate']->it('Fax');
        $tags['PHONE_TOLLFREE_TEXT'] = $_SESSION['translate']->it('Toll-Free');

        $tags['PERSONAL_TEXT'] = $_SESSION['translate']->it('Contact');
        $tags['NAME_TEXT'] = $_SESSION['translate']->it('Name');
        $tags['FIRSTNAME_TEXT'] = $_SESSION['translate']->it('First');
        $tags['MIDDLENAME_TEXT'] = $_SESSION['translate']->it('Middle');
        $tags['LASTNAME_TEXT'] = $_SESSION['translate']->it('Last');
        $tags['PREFIX_TEXT'] = $_SESSION['translate']->it('Prefix');
        $tags['SUFFIX_TEXT'] = $_SESSION['translate']->it('Suffix');

        $tags['COMPANY_TITLE_TEXT'] = $_SESSION['translate']->it('Title');
        $tags['PERSONAL_ADDRESS_TEXT'] = $_SESSION['translate']->it('Address');

		$tags['VISIBILITY_TEXT'] = $_SESSION['translate']->it('Visibility');
		$tags['VISIBILITY_HELP'] = CLS_help::show_link('phpwsbusinesses', 'visibility');
		$tags['MINE_TEXT'] = $_SESSION['translate']->it('My Business');
		$tags['MINE_HELP'] = CLS_help::show_link('phpwsbusinesses', 'mine');

        
		if (!empty($_SESSION['BUSINESSES_Manager']->_custom1label) || !empty($_SESSION['BUSINESSES_Manager']->_custom2label) || !empty($_SESSION['BUSINESSES_Manager']->_custom3label) || !empty($_SESSION['BUSINESSES_Manager']->_custom4label))
			$tags['CUSTOM_TEXT'] = $_SESSION['translate']->it('Additional Information');

		if (!empty($_SESSION['BUSINESSES_Manager']->_custom1label_priv) || !empty($_SESSION['BUSINESSES_Manager']->_custom2label_priv) || !empty($_SESSION['BUSINESSES_Manager']->_custom3label_priv) || !empty($_SESSION['BUSINESSES_Manager']->_custom4label_priv))
			$tags['CUSTOM_TEXT_PRIV'] = $_SESSION['translate']->it('Hidden Additional Information');

        if (empty($_SESSION['BUSINESSES_Manager']->_custom1label))
            $tags['BUSINESS_CUSTOM1'] = NULL;
        else
            $tags['CUSTOM1_TEXT'] = $_SESSION['BUSINESSES_Manager']->_custom1label;

        if (empty($_SESSION['BUSINESSES_Manager']->_custom2label))
            $tags['BUSINESS_CUSTOM2'] = NULL;
        else
            $tags['CUSTOM2_TEXT'] = $_SESSION['BUSINESSES_Manager']->_custom2label;

        if (empty($_SESSION['BUSINESSES_Manager']->_custom3label))
            $tags['BUSINESS_CUSTOM3'] = NULL;
        else
            $tags['CUSTOM3_TEXT'] = $_SESSION['BUSINESSES_Manager']->_custom3label;
            
        if (empty($_SESSION['BUSINESSES_Manager']->_custom4label))
            $tags['BUSINESS_CUSTOM4'] = NULL;
        else
            $tags['CUSTOM4_TEXT'] = $_SESSION['BUSINESSES_Manager']->_custom4label;

        if (empty($_SESSION['BUSINESSES_Manager']->_custom1label_priv))
            $tags['BUSINESS_CUSTOM1_PRIV'] = NULL;
        else
            $tags['CUSTOM1_TEXT_PRIV'] = $_SESSION['BUSINESSES_Manager']->_custom1label_priv;

        if (empty($_SESSION['BUSINESSES_Manager']->_custom2label_priv))
            $tags['BUSINESS_CUSTOM2_PRIV'] = NULL;
        else
            $tags['CUSTOM2_TEXT_PRIV'] = $_SESSION['BUSINESSES_Manager']->_custom2label_priv;

        if (empty($_SESSION['BUSINESSES_Manager']->_custom3label_priv))
            $tags['BUSINESS_CUSTOM3_PRIV'] = NULL;
        else
            $tags['CUSTOM3_TEXT_PRIV'] = $_SESSION['BUSINESSES_Manager']->_custom3label_priv;
            
        if (empty($_SESSION['BUSINESSES_Manager']->_custom4label_priv))
            $tags['BUSINESS_CUSTOM4_PRIV'] = NULL;
        else
            $tags['CUSTOM4_TEXT_PRIV'] = $_SESSION['BUSINESSES_Manager']->_custom4label_priv;


        return PHPWS_Template::processTemplate($tags, 'phpwsbusinesses', 'edit.tpl');

    }// END FUNC _edit


    function _save() {
        if (($_SESSION['OBJ_user']->username != $this->getOwner()) && !$_SESSION['OBJ_user']->allow_access('phpwsbusinesses','edit_businesses')) {
            $message = $_SESSION['translate']->it('Access to save business was denied due to lack of proper permissions.');
            $error = new PHPWS_Error('phpwsbusinesses', 'BUSINESSES_Business::_save()', $message, 'exit', 1);
            $error->message();
            return FALSE;
        }

        if (isset($_REQUEST['Contact_lastname']))
            $this->_lastname = PHPWS_Text::parseInput($_REQUEST['Contact_lastname']);
        if (isset($_REQUEST['Contact_middlename']))
            $this->_middlename = PHPWS_Text::parseInput($_REQUEST['Contact_middlename']);
        else
            $this->_middlename = "";

        if (isset($_REQUEST['Contact_firstname']))
            $this->_firstname = PHPWS_Text::parseInput($_REQUEST['Contact_firstname']);

        $label = $this->_company_name;
        $this->setLabel($label);


        if (isset($_REQUEST['Contact_prefix']))
            $this->_prefix = PHPWS_Text::parseInput($_REQUEST['Contact_prefix']);
        if (isset($_REQUEST['Contact_suffix']))
            $this->_suffix = PHPWS_Text::parseInput($_REQUEST['Contact_suffix']);

        if (isset($_REQUEST['Business_email']))
            $this->_email = PHPWS_Text::parseInput($_REQUEST['Business_email']);

        /* May need to set to NULL if '' */
        if (isset($_REQUEST['Business_owner'])) 
            $this->_owner = $_REQUEST['Business_owner'];

        if (isset($_REQUEST['Business_expiryDate_YEAR'])) {
            $year = $_REQUEST['Business_expiryDate_YEAR'];
            $month = $_REQUEST['Business_expiryDate_MONTH'];
            $day = $_REQUEST['Business_expiryDate_DAY'];
            $this->_expiryDate = $year . '-' . $month . '-' . $day . ' 12:00:00';
        }

        if (isset($_REQUEST['Business_phone_tollfree']))
            $this->_phone_tollfree = PHPWS_Text::parseInput($_REQUEST['Business_phone_tollfree']);
        if (isset($_REQUEST['Business_phone_work']))
            $this->_phone_work = PHPWS_Text::parseInput($_REQUEST['Business_phone_work']);
        if (isset($_REQUEST['Business_phone_fax']))
            $this->_phone_fax = PHPWS_Text::parseInput($_REQUEST['Business_phone_fax']);

        if (isset($_REQUEST['Business_company_name']))
            $this->_company_name = PHPWS_Text::parseInput($_REQUEST['Business_company_name']);
        if (isset($_REQUEST['Contact_company_title']))
            $this->_company_title = PHPWS_Text::parseInput($_REQUEST['Contact_company_title']);
        if (isset($_REQUEST['Business_company_street']))
            $this->_company_street = PHPWS_Text::parseInput($_REQUEST['Business_company_street']);
        if (isset($_REQUEST['Business_company_city']))
            $this->_company_city = PHPWS_Text::parseInput($_REQUEST['Business_company_city']);
        if (isset($_REQUEST['Business_company_state']))
            $this->_company_state = PHPWS_Text::parseInput($_REQUEST['Business_company_state']);
        if (isset($_REQUEST['Business_company_zip']))
            $this->_company_zip = PHPWS_Text::parseInput($_REQUEST['Business_company_zip']);
        if (isset($_REQUEST['Business_company_country']))
            $this->_company_country = PHPWS_Text::parseInput($_REQUEST['Business_company_country']);
        if (isset($_REQUEST['Business_company_website']))
            $this->_company_website = $this->_getWebsite(PHPWS_Text::parseInput($_REQUEST['Business_company_website']));


        if (isset($_REQUEST['Business_custom1']))
            $this->_custom1 = PHPWS_Text::parseInput($_REQUEST['Business_custom1']);
        if (isset($_REQUEST['Business_custom2']))
            $this->_custom2 = PHPWS_Text::parseInput($_REQUEST['Business_custom2']);
        if (isset($_REQUEST['Business_custom3']))
            $this->_custom3 = PHPWS_Text::parseInput($_REQUEST['Business_custom3']);
        if (isset($_REQUEST['Business_custom4']))
            $this->_custom4 = PHPWS_Text::parseInput($_REQUEST['Business_custom4']);

        if (isset($_REQUEST['Business_custom1_priv']))
            $this->_custom1_priv = PHPWS_Text::parseInput($_REQUEST['Business_custom1_priv']);
        if (isset($_REQUEST['Business_custom2_priv']))
            $this->_custom2_priv = PHPWS_Text::parseInput($_REQUEST['Business_custom2_priv']);
        if (isset($_REQUEST['Business_custom3_priv']))
            $this->_custom3_priv = PHPWS_Text::parseInput($_REQUEST['Business_custom3_priv']);
        if (isset($_REQUEST['Business_custom4_priv']))
            $this->_custom4_priv = PHPWS_Text::parseInput($_REQUEST['Business_custom4_priv']);

        if (isset($_REQUEST['Business_comments']))
            $this->_comments = PHPWS_Text::parseInput($_REQUEST['Business_comments']);

        if (isset($_FILES['NEW_Business_image']) && !empty($_FILES['NEW_Business_image']['name'])) {
            $imgarray = NULL;
            $dir = 'images/phpwsbusinesses/' . $this->getOwner() .'/';
            $imgarray = EZform::saveImage('NEW_Business_image', $GLOBALS['core']->home_dir . $dir);
            if (PHPWS_Error::isError($imgarray) || !is_array($imgarray)) {
                $imgarray->message('CNT_phpwsbusinesses');
            }

            $thumbnail = PHPWS_File::makeThumbnail($imgarray['name'], $dir, $dir);
            if (PHPWS_Error::isError($thumbnail) || !is_array($thumbnail)) {
                $thumbnail->message('CNT_phpwsbusinesses');
            }

            if (is_file($GLOBALS['core']->home_dir . $dir . $thumbnail[0])) {
                $imgarray['thumb_name'] = $thumbnail[0];
                $imgarray['thumb_width'] = $thumbnail[1];
                $imgarray['thumb_height'] = $thumbnail[2];
            }

            $this->_image = $imgarray;
        } elseif (isset($_REQUEST['REMOVE_Business_image'])) {
            // Delete image
            $dir = $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() .'/';
            unlink($dir . $this->_image['name']);
            if (isset($this->_image['thumb_name']))
                unlink($dir . $this->_image['thumb_name']);
            $this->_image = NULL;

            $GLOBALS['CNT_phpwsbusinesses']['content'] .= $_SESSION['translate']->it('The image for [var1] was removed.', $this->getLabel());
        } elseif (isset($_REQUEST['CURRENT_Business_image']) && ($_REQUEST['CURRENT_Business_image'] != 'none') && ($_REQUEST['CURRENT_Business_image'] != $this->_image['name'])) {
            $dir = 'images/phpwsbusinesses' . '/' . $this->getOwner() .'/';
            $fulldir = $GLOBALS['core']->home_dir . $dir;

            $size = getimagesize($fulldir . $_REQUEST['CURRENT_Business_image']);
            $imgarray['name'] = $_REQUEST['CURRENT_Business_image'];
            $imgarray['width'] = $size[0];
            $imgarray['height'] = $size[1];

            // Assuming last 4 chars in 
            $tnbase = substr($imgarray['name'], 0, -4);
            $tnext = substr($imgarray['name'], -4);

            if (is_file($GLOBALS['core']->home_dir . $dir . $tnbase . '_tn' . $tnext)) {
				$imgarray['thumb_name'] = $tnbase . '_tn' . $tnext;
				$size = getimagesize($fulldir . $imgarray['thumb_name']);
				$imgarray['thumb_width'] = $size[0];
				$imgarray['thumb_height'] = $size[1];
			}

            $this->_image = $imgarray;
        }

        if (isset($_REQUEST['Business_visibility']))
            $this->_visibility = $_REQUEST['Business_visibility'];

        if (isset($_REQUEST['Business_mine']))
            $this->_mine = 1;
        else
            $this->_mine = 0;
            
		if (isset($_REQUEST["Business_sw_comments"]))
			$this->_sw_comments = (int)$_REQUEST["Business_sw_comments"];

		if (isset($_REQUEST["Business_sw_anonymous"]))
			$this->_sw_anonymous = $_REQUEST["Business_sw_anonymous"];

        $error = $this->commit();

        if (PHPWS_Error::isError($error)) {
            $message = $_SESSION['translate']->it('The business could not be saved to the database.');
            $error = new PHPWS_Error('phpwsbusinesses', $message, 'continue', 0);
            $error->message('CNT_phpwsbusinesses');

            $_REQUEST['BUSINESSES_Business_OP'] = 'edit';
            $this->action();
            return;
        } else {
        	
			// FatCat
			if ($_SESSION['OBJ_fatcat'])
				$_SESSION['OBJ_fatcat']->saveSelect($this->_company_name, 'index.php?module=phpwsbusinesses&amp;BUSINESSES_MAN_OP=view&PHPWS_MAN_ITEMS[]=' . $this->getId(), $this->getId());

			// There can be only one, set all others to mine=0 where owner=this->getOwner()
			if ($this->_mine == 1)
				$GLOBALS['core']->sqlUpdate(array('mine'=>0), 'mod_phpwsbusinesses_businesses', array('id'=>$this->getId(),'owner'=>$this->getOwner()), NULL,array('id'=>'!=','owner'=>'='));

			// get the settings
			$busSettings = BUSINESSES_Manager::getSettingsRow();
        	if (isset($_REQUEST['addAppl']) && $busSettings['requireApproval']) {
				$data["approved"] = 0;
				$GLOBALS["core"]->sqlUpdate($data, "mod_phpwsbusinesses_businesses", "id", $this->getId());
				$short = "<b>" . $this->getOwner() . "</b><br />New Application";
				PHPWS_Approval::add($this->getId(), $short, "phpwsbusinesses");
				PHPWS_Fatcat::deactivate($this->getId(), "phpwsbusinesses");
				$message = $_SESSION["translate"]->it("Your listing was submitted for approval.");
				$_SESSION['OBJ_user']->username = '';
            } else {
				$message = $_SESSION['translate']->it('The business was successfully saved.');
            }

			$message .= '<br />';

			// CHECK FOR NEW OWNER AND COPY DIRS AND IMAGES IF NEEDED
			
			// first check to see if Business_owner_old is set
			if (isset($_REQUEST['Business_owner_old'])) {
			
				// then see if it doesn't match Business_owner (current owner after commit()
				if ($_REQUEST['Business_owner_old'] !== $this->getOwner()) {
			
					// if it doesn't, make the dirs and move the files

					// first check for the existance of the img dir
					if (!is_dir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/')) {
						// if they don't exist, make em
						mkdir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/');
						// check the success
						if (is_dir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/'))
							// report the success
							$message .= $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . " succesfully created <br />";
						else
							$message .= $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . " not created, you will have to do it manually <br />";
					} else {
						$message .= $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . " already exists <br />";
					}
	
					// then check for the existance of the image
					if (!file_exists($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . $this->_image['name'])) {
						// if it don't exist, copy it
						PHPWS_File::fileCopy($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_REQUEST['Business_owner_old'] . '/' . $this->_image['name'], $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/', $this->_image['name'], false, false);
						// check the success
						if (file_exists($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . $this->_image['name']))
							// report the success
							$message .= $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . $this->_image['name'] . " successfully copied <br />";
						else
							$message .= $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . $this->_image['name'] . " not copied <br />";
					} elseif ($this->_image['name'] == '') {
						$message .= " no image to copy <br />";
					} else {
						$message .= $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . $this->_image['name'] . " already exists <br />";
					}
				
					// then check for the existance of the thumb
					if (!file_exists($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . $this->_image['thumb_name'])) {
						// if it don't exist, copy it
						PHPWS_File::fileCopy($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $_REQUEST['Business_owner_old'] . $this->_image['thumb_name'], $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/', $this->_image['thumb_name'], false, false);
						// check the success
						if (file_exists($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . $this->_image['thumb_name']))
							// report the success
							$message .= $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . $this->_image['thumb_name'] . " successfully copied <br />";
						else
							$message .= $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . $this->_image['thumb_name'] . " not copied <br />";
					} elseif ($this->_image['thumb_name'] == '') {
						$message .= " no thumb to copy <br />";
					} else {
						$message .= $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/' . $this->_image['thumb_name'] . " already exists <br />";
					}
				
				} else { 
			
				// if it does, you're OK
				$message .= $_SESSION['translate']->it('Your images are OK');
				
				}
			
			}

            return $message . $this->_view();

        }


    }// END FUNC _save


    function _delete() {
        if (!$_SESSION['OBJ_user']->allow_access('phpwsbusinesses', 'delete_businesses')) {
            $message = $_SESSION['translate']->it('Access to delete business was denied due to lack of proper permissions.');
            $error = new PHPWS_Error('phpwsbusinesses', 'BUSINESSES_Business::_delete()', $message, 'exit', 1);
            $error->message();
            return FALSE;
        }

        $content = null;

        if (isset($_REQUEST['Business_yes'])) {

			// get rid of dirs if the owner only owns one business listing
			$dirCheck = $GLOBALS["core"]->sqlSelect("mod_phpwsbusinesses_businesses", "owner", $this->getOwner(), NULL, NULL, NULL, NULL, NULL, NULL);
			$numDirs = count($dirCheck);
			if ($numDirs == '1') { 
				if (PHPWS_File::rmdir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/'))
					$content .= $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/'. ' was fully removed.<br />';
				else
					$content .= $GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $this->getOwner() . '/'. ' was not removed.<br />';
			}

            $this->kill();

            // Remove FatCat entry
            if ($_SESSION['OBJ_fatcat'])
                $_SESSION['OBJ_fatcat']->purge($this->getId(), 'phpwsbusinesses');
			
			/* remove comments */
			if (class_exists("PHPWS_Comment")){
				$where['module'] = "phpwsbusinesses";
				$where['itemId'] = $this->getId();
				$GLOBALS['core']->sqlDelete("mod_comments_data", $where);
			}

            $content .= $_SESSION['translate']->it('The business [var1] was successfully deleted from the database.', '<b><i>' . $this->getLabel() . '</i></b>');
			
        } elseif (isset($_REQUEST['Business_no'])) {
            $content .= $_SESSION['translate']->it('No business was deleted from the database.');
        } else {
	$dirCheck = $GLOBALS["core"]->sqlSelect("mod_phpwsbusinesses_businesses", "owner", $this->getOwner(), NULL, NULL, NULL, NULL, NULL, NULL);
	$numDirs = count($dirCheck);
//	echo "$numDirs";
	
            $form = new EZform('BUSINESSES_Business_delete');
            $form->add('module', 'hidden', 'phpwsbusinesses');
            $form->add('BUSINESSES_Business_OP', 'hidden', 'delete');

            $form->add('Business_yes', 'submit', $_SESSION['translate']->it('Yes'));
            $form->add('Business_no', 'submit', $_SESSION['translate']->it('No'));

            $tags = array();
            $tags = $form->getTemplate();
            $tags['MESSAGE'] = $_SESSION['translate']->it('Are you sure you want to delete this business listing?');
            
            $content .= PHPWS_Template::processTemplate($tags, 'phpwsbusinesses', 'delete.tpl');
        }

        return $content;

    }// END FUNC _delete


    function _vcard() {
        $v = new Contact_Vcard_Build();

        $v->setFormattedName($this->_firstname . ' ' . $this->_lastname);
        $v->setName($this->_lastname, $this->_firstname, $this->_middlename, $this->_prefix, $this->_suffix);

        if (!empty($this->_email)) {
            $v->addEmail($this->_email);
            $v->addParam('TYPE', 'PREF');
            $v->addParam('TYPE', 'INTERNET');
        }

        // Need to find out what types I should use
        if (!empty($this->_phone_tollfree)) {
            $v->addTelephone($this->_phone_tollfree);
            $v->addParam('TYPE', 'TOLL-FREE');
        }
        if (!empty($this->_phone_work)) {
            $v->addTelephone($this->_phone_work);
            $v->addParam('TYPE', 'WORK');
        }
        if (!empty($this->_phone_fax)) {
            $v->addTelephone($this->_phone_fax);
            $v->addParam('TYPE', 'FAX');
        }

        if (!empty($this->_company_name))
            $v->addOrganization($this->_company_name);

        if (!empty($this->_company_title))
            $v->setTitle($this->_company_title);

        if (!empty($this->_company_street) ||
            !empty($this->_company_city) ||
            !empty($this->_company_state) ||
            !empty($this->_company_zip) ||
            !empty($this->_company_country)) {
            $v->addAddress('', '', $this->_company_street, $this->_company_city, $this->_company_state, $this->_company_zip, $this->_company_country);
            $v->addParam('TYPE', 'WORK');
        }
        if (!empty($this->_company_website)) {
            $v->setURL($this->_getWebsite($this->_company_website));
            $v->addParam('TYPE', 'WORK');
        }

        if (!empty($this->_comments))
            $v->setNote($this->_comments);
        
        $output = $v->fetch();
        $filename = $this->_company_name . '.vcf';

        
        Header('Content-Disposition: attachment; filename=' . $filename);
        Header('Content-Length: ' . strlen($output));
        Header('Connection: close');
        Header('Content-Type: text/x-vCard; name=' . $filename);
        
        echo $output;
        exit();
    }// END FUNC _vcard


    function _import() {
        /* Create form */
        $form = new EZform('BUSINESSES_Business_import');
        $tabs = 1;


        /* Contact Prefix */
        $form->add('Business_vcard', 'file');
        $form->setTab('Business_vcard', $tabs);
        $tabs++;

        /* Save Button */
        $form->add('Business_save', 'submit', $_SESSION['translate']->it('Import vCard'));
        $form->setTab('Business_save', $tabs);

        /* Module Information */
        $form->add('module', 'hidden', 'phpwsbusinesses');
        $form->add('BUSINESSES_Business_OP', 'hidden', 'parse');

        $tags = array();
        $tags = $form->getTemplate();

        $tags['VCARD_TEXT'] = $_SESSION['translate']->it('vCard');

        return PHPWS_Template::processTemplate($tags, 'phpwsbusinesses', 'import.tpl');

    }// END FUNC _import


    function _parse() {
        if (isset($_FILES['Business_vcard']) && !empty($_FILES['Business_vcard']['name'])) {
            $parse = new Contact_Vcard_Parse();
            $cardinfo = $parse->fromFile($_FILES['Business_vcard']['tmp_name']);

            foreach(array_keys($cardinfo[0]) as $datatype) {
                if ($datatype == 'N') {
                    $this->_lastname = $cardinfo[0][$datatype][0]['value'][0][0];
                    $this->_firstname = $cardinfo[0][$datatype][0]['value'][1][0];
                    $this->_middlename = $cardinfo[0][$datatype][0]['value'][2][0];
                    $this->_prefix = $cardinfo[0][$datatype][0]['value'][3][0];
                    $this->_suffix = $cardinfo[0][$datatype][0]['value'][4][0];
                } elseif ($datatype == 'ADR') {
                    foreach($cardinfo[0][$datatype] as $addresses) {
                        if ($addresses['param']['TYPE'][0] == 'WORK') {
                            $this->_company_street = $addresses['value'][2][0];
                            $this->_company_city = $addresses['value'][3][0];
                            $this->_company_state = $addresses['value'][4][0];
                            $this->_company_zip = $addresses['value'][5][0];
                            $this->_company_country = $addresses['value'][6][0];
                        }
                    }
                } elseif ($datatype == 'TEL') {
                    foreach($cardinfo[0][$datatype] as $phones) {
                        if ($phones['param']['TYPE'][0] == 'HOME') {
                            $this->_phone_tollfree = $phones['value'][0][0];
                        } elseif ($phones['param']['TYPE'][0] == 'WORK') {
                            $this->_phone_work = $phones['value'][0][0];
                        } elseif ($phones['param']['TYPE'][0] == 'FAX') {
                            $this->_phone_fax = $phones['value'][0][0];
                        }                         }
                } elseif ($datatype == 'EMAIL') {
                    foreach($cardinfo[0][$datatype] as $emails) {
                        foreach($emails['param']['TYPE'] as $type) {
                            if ($type == 'PREF') {
                                if (!empty($this->_email))
									$this->_email = $emails['value'][0][0];
                            } elseif (empty($this->_email)) {
                                $this->_email = $emails['value'][0][0];
                            }
                        }
                    }
                } elseif ($datatype == 'ORG') {
                    $this->_company_name = $cardinfo[0][$datatype][0]['value'][0][0];
                } elseif ($datatype == 'TITLE') {
                    $this->_company_title = $cardinfo[0][$datatype][0]['value'][0][0];
                } elseif (($datatype == 'ROLE') && empty($this->_company_title)) {
                    $this->_company_title = $cardinfo[0][$datatype][0]['value'][0][0];
                } elseif ($datatype == 'NOTE') {
                    $this->_comments = $cardinfo[0][$datatype][0]['value'][0][0];
                } elseif ($datatype == 'URL') {
                    foreach($cardinfo[0][$datatype] as $urls) {
                        foreach($urls['param']['TYPE'] as $type) {
                            if ($type == 'WORK') {
                                $this->_company_website = $urls['value'][0][0];
                            }
                        }
                    }
                } elseif ($datatype == 'BDAY') {
                }
            }

            $this->setLabel($this->_company_name);
            $this->_visibility = 0;

            $error = $this->commit();

            if (PHPWS_Error::isError($error)) {
                $message = $_SESSION['translate']->it('The business could not be saved to the database.');
                $error = new PHPWS_Error('phpwsbusinesses', $message, 'continue', 0);
                $error->message('CNT_phpwsbusinesses');
    
                $_REQUEST['BUSINESSES_Business_OP'] = 'edit';
                $this->action();
                return;
            } else {
                // FatCat
                //if ($_SESSION['OBJ_fatcat'])
                    //$_SESSION['OBJ_fatcat']->saveSelect($this->getLabel(), 'index.php?module=phpwsbusinesses&amp;BUSINESSES_MAN_OP=view&PHPWS_MAN_ITEMS[]=' . $this->getId(), $this->getId());
    
                $message = $_SESSION['translate']->it('The business was successfully saved.');
                return $message . $this->_view();
    
            }
        }
    }// END FUNC _parse

    function action() {
        switch($_REQUEST['BUSINESSES_Business_OP']) {
            case 'view':
                $title = $_SESSION['translate']->it('View Business Information');
                $content = $_SESSION['BUSINESSES_Manager']->_menu() . $_SESSION['BUSINESSES_Manager']->_alphaClick() . $this->_view();
                break;

            case 'viewprintable':
                $title = NULL;
                $content = $this->_view();
                break;

            case 'edit':
                $title = $_SESSION['translate']->it('Edit Business Information');
                $content = $_SESSION['BUSINESSES_Manager']->_menu() . $this->_edit();
                break;
            
            case 'add':
                $title = $_SESSION['translate']->it('Add Business Information');
                $content = $_SESSION['BUSINESSES_Manager']->_menu() . $this->_edit();
                break;
            
            case 'addAppl':
                $title = $_SESSION['translate']->it('Add Business Information');
//                $content = $_SESSION['BUSINESSES_Manager']->_menu() . $this->_edit();
                $content = $_SESSION['BUSINESSES_Manager']->_menuMini() . $this->_edit();
                break;
            
            case 'save':
                $title = $_SESSION['translate']->it('Save Business Information');
//                $content = $_SESSION['BUSINESSES_Manager']->_menu() . $this->_save();
                $content = $_SESSION['BUSINESSES_Manager']->_menuMini() . $this->_save();
                break;

            case 'delete':
                $title = $_SESSION['translate']->it('Delete Business Information');
                $content = $_SESSION['BUSINESSES_Manager']->_menu() . $this->_delete();
                break;

            case 'vcard':
                $this->_vcard();
                break;

            case 'import':
                $title = $_SESSION['translate']->it('Import vCard');
                $content = $_SESSION['BUSINESSES_Manager']->_menu() . $this->_import();
                break;

            case 'parse':
                $title = $_SESSION['translate']->it('Import vCard');
                $content = $_SESSION['BUSINESSES_Manager']->_menu() . $this->_parse();
                break;

            default:
                $title = 'NO OP';
                $content = 'This function is not yet implemented.';
        }

        if (isset($content)) {
            $GLOBALS['CNT_phpwsbusinesses']['title'] = $title;
            $GLOBALS['CNT_phpwsbusinesses']['content'] .= $content;
        }
    }// END FUNC action


	function approve($id) {
		$data["approved"] = 1;
		$data["created"] = date("Y-m-d H:i:s");
		$data["updated"] = date("Y-m-d H:i:s");
		
		$GLOBALS["core"]->sqlUpdate($data, "mod_phpwsbusinesses_businesses", "id", $id);
		PHPWS_Fatcat::activate($id, "phpwsbusinesses");
	}
	
	function refuse($id) {

		//get the owners name, so the dirs can be deleted
    	$dirCheck = $GLOBALS["core"]->sqlSelect("mod_phpwsbusinesses_businesses", "id", $id, NULL, NULL, NULL, NULL, NULL, NULL);
//    	print_r($dirCheck);
//    	echo "<br />";
		PHPWS_File::rmdir($GLOBALS['core']->home_dir . 'images/phpwsbusinesses/' . $dirCheck[0]['owner'] . '/');

		$GLOBALS["core"]->sqlDelete("mod_phpwsbusinesses_businesses", "id", $id);
		PHPWS_Fatcat::purge($id, "phpwsbusinesses");
	}


    function isVisible() {
        if ($this->getOwner() == $_SESSION['OBJ_user']->username)
            return TRUE;
        elseif ($this->_visibility == 0)
            return TRUE;
        elseif ($this->_visibility == 1) {
            if ($_SESSION['OBJ_user']->username)
                return TRUE;
            else
                return FALSE;
        } elseif ($this->_visibility == 2) {
            if ($_SESSION['OBJ_user']->allow_access('phpwsbusinesses','view_privates'))
                return TRUE;
            else
                return FALSE;
        } else
            return FALSE;
    }// END FUNC isVisible


    function showPrivOK() {
        if ($this->getOwner() == $_SESSION['OBJ_user']->username)
            return TRUE;
		elseif ($_SESSION['OBJ_user']->allow_access('phpwsbusinesses','view_privates'))
			return TRUE;
		else
			return FALSE;
    }// END FUNC showPrivOK


    function printCSVHeader() {
        $content = NULL;

        $content .= '"' . $_SESSION['translate']->it('Company Name') . '",';
        $content .= '"' . $_SESSION['translate']->it('Last Name') . '",';
        $content .= '"' . $_SESSION['translate']->it('First Name') . '",';
        $content .= '"' . $_SESSION['translate']->it('Middle Name') . '",';
        $content .= '"' . $_SESSION['translate']->it('Prefix') . '",';
        $content .= '"' . $_SESSION['translate']->it('Suffix') . '",';
        $content .= '"' . $_SESSION['translate']->it('Company Title') . '",';
        if ($_SESSION['OBJ_fatcat'])
            $content .= '"' . $_SESSION['translate']->it('Category') . '",';
        $content .= '"' . $_SESSION['translate']->it('E-Mail') . '",';
        $content .= '"' . $_SESSION['translate']->it('Work Phone') . '",';
        $content .= '"' . $_SESSION['translate']->it('Fax') . '",';
        $content .= '"' . $_SESSION['translate']->it('Toll-Free Phone') . '",';
        $content .= '"' . $_SESSION['translate']->it('Company Street Address') . '",';
        $content .= '"' . $_SESSION['translate']->it('Company City') . '",';
        $content .= '"' . $_SESSION['translate']->it('Company Prov/State') . '",';
        $content .= '"' . $_SESSION['translate']->it('Company Postal/Zip') . '",';
        $content .= '"' . $_SESSION['translate']->it('Company Country') . '",';
        $content .= '"' . $_SESSION['translate']->it('Company Website') . '",';
        if (!empty($_SESSION['BUSINESSES_Manager']->_custom1label))
            $content .= '"' . $_SESSION['BUSINESSES_Manager']->_custom1label . '",';
        if (!empty($_SESSION['BUSINESSES_Manager']->_custom2label))
            $content .= '"' . $_SESSION['BUSINESSES_Manager']->_custom2label . '",';
        if (!empty($_SESSION['BUSINESSES_Manager']->_custom3label))
            $content .= '"' . $_SESSION['BUSINESSES_Manager']->_custom3label . '",';
        if (!empty($_SESSION['BUSINESSES_Manager']->_custom4label))
            $content .= '"' . $_SESSION['BUSINESSES_Manager']->_custom4label . '",';
//		if ($this->showPrivOK()) 
			if (!empty($_SESSION['BUSINESSES_Manager']->_custom1label_priv))
				$content .= '"' . $_SESSION['BUSINESSES_Manager']->_custom1label_priv . '",';
//		if ($this->showPrivOK()) 
			if (!empty($_SESSION['BUSINESSES_Manager']->_custom2label_priv))
				$content .= '"' . $_SESSION['BUSINESSES_Manager']->_custom2label_priv . '",';
//		if ($this->showPrivOK()) 
			if (!empty($_SESSION['BUSINESSES_Manager']->_custom3label_priv))
				$content .= '"' . $_SESSION['BUSINESSES_Manager']->_custom3label_priv . '",';
//		if ($this->showPrivOK()) 
			if (!empty($_SESSION['BUSINESSES_Manager']->_custom4label_priv))
				$content .= '"' . $_SESSION['BUSINESSES_Manager']->_custom4label_priv . '",';
        $content .= '"' . $_SESSION['translate']->it('Description') . '"';

        $content .= "\n";
        return $content;
    }// END FUNC printCSVHeader


    function printCSV() {
        $content = NULL;

        $content .= '"' . $this->_company_name . '",';
        $content .= '"' . $this->_lastname . '",';
        $content .= '"' . $this->_firstname . '",';
        $content .= '"' . $this->_middlename . '",';
        $content .= '"' . $this->_prefix . '",';
        $content .= '"' . $this->_suffix . '",';
        $content .= '"' . $this->_company_title . '",';
        if ($_SESSION['OBJ_fatcat']) {
            if (!($row = $_SESSION['OBJ_fatcat']->getModuleElements('phpwsbusinesses', $this->getId())))
                $content .= '",';
            else {
                $cats = NULL;
                foreach ($row as $element) {
                    $catid = $_SESSION['OBJ_fatcat']->getElementCatId($element['element_id'],'phpwsbusinesses');
                    $cat = new PHPWS_Fatcat_Category($catid);
                    if (isset($cats))
                        $cats .= '; ';
                    $cats .= $cat->title;
                }
                $content .= '"' . $cats . '",';
            }
        }
        $content .= '"' . $this->_email . '",';
        $content .= '"' . $this->_phone_work . '",';
        $content .= '"' . $this->_phone_fax . '",';
        $content .= '"' . $this->_phone_tollfree . '",';
        $content .= '"' . $this->stripLF($this->_company_street) . '",';
        $content .= '"' . $this->_company_city . '",';
        $content .= '"' . $this->_company_state . '",';
        $content .= '"' . $this->_company_zip . '",';
        $content .= '"' . $this->_company_country . '",';
        $content .= '"' . $this->_getWebsite($this->_company_website) . '",';
        if (!empty($_SESSION['BUSINESSES_Manager']->_custom1label))
            $content .= '"' . $this->_custom1 . '",';
        if (!empty($_SESSION['BUSINESSES_Manager']->_custom2label))
            $content .= '"' . $this->_custom2 . '",';
        if (!empty($_SESSION['BUSINESSES_Manager']->_custom3label))
            $content .= '"' . $this->_custom3 . '",';
        if (!empty($_SESSION['BUSINESSES_Manager']->_custom4label))
            $content .= '"' . $this->_custom4 . '",';
		if (!empty($_SESSION['BUSINESSES_Manager']->_custom1label_priv))
			if ($this->showPrivOK()) 
				$content .= '"' . $this->_custom1_priv . '",';
			else
				$content .= '"",';
		if (!empty($_SESSION['BUSINESSES_Manager']->_custom2label_priv))
			if ($this->showPrivOK()) 
				$content .= '"' . $this->_custom2_priv . '",';
			else
				$content .= '"",';
		if (!empty($_SESSION['BUSINESSES_Manager']->_custom3label_priv))
			if ($this->showPrivOK()) 
				$content .= '"' . $this->_custom3_priv . '",';
			else
				$content .= '"",';
		if (!empty($_SESSION['BUSINESSES_Manager']->_custom4label_priv))
			if ($this->showPrivOK()) 
				$content .= '"' . $this->_custom4_priv . '",';
			else
				$content .= '"",';
        $content .= '"' . $this->stripLF($this->_comments) . '"';

        $content .= "\n";
        return $content;
    }// END FUNC printCSV


    function stripLF($str) {
        $str = str_replace("\r\n", '; ', $str);
        $str = str_replace("\n", '; ', $str);
        return $str;
    }// END FUNC stripLF


    function getListID() {
        return $this->getId();
    }

    function getListOwner() {
        return $this->_owner;
    }

    function getListName() {
        $name = NULL;
        if ($_SESSION['BUSINESSES_Manager']->_sortbylastname) {
            $name .= $this->_lastname;
            /*
            if (isset($this->_middlename) && !empty($this->_middlename))
                $name .= ' ' . $this->_middlename;
            */
            $name .= ', ' . $this->_firstname;
        } else {
            $name .= $this->_firstname;
            $name .= ' ' . $this->_lastname;
            /*
            if (isset($this->_middlename) && !empty($this->_middlename))
                $name .= ' ' . $this->_middlename;
            */
        }
        return $name;
    }

    function getListFirstName() {
        return $this->_firstname;
    }

    function getListLastName() {
        return $this->_lastname;
    }

    function getListEmail() {
        return $this->_email;
    }

    function getListPhone_TollFree() {
        if (isset($this->_phone_tollfree) && !empty($this->_phone_tollfree))
            return $this->_phone_tollfree;
        else
            return NULL;
    }

    function getListPhone_TollFree_Label() {
        if (isset($this->_phone_tollfree) && !empty($this->_phone_tollfree))
            return $_SESSION['translate']->it('Toll-Free');
        else
            return NULL;
    }

    function getListPhone_Work() {
        if (isset($this->_phone_work) && !empty($this->_phone_work))
            return $this->_phone_work;
        else
            return NULL;
    }

    function getListPhone_Work_Label() {
        if (isset($this->_phone_work) && !empty($this->_phone_work))
            return $_SESSION['translate']->it('Work');
        else
            return NULL;
    }

    function getListEdit_Link() {
        if (isset($_SESSION['OBJ_user']->username) && (($_SESSION['OBJ_user']->username == $this->getOwner()) || $_SESSION['OBJ_user']->allow_access('phpwsbusinesses','edit_businesses')))
            return '<a href="index.php?module=phpwsbusinesses&amp;BUSINESSES_MAN_OP=edit&amp;PHPWS_MAN_ITEMS[]=' . $this->getId() . '">' . $_SESSION['translate']->it('Edit') . '</a>';
        else
            return NULL;
    }

    function getListThumbnail() {
        if (!empty($this->_image)) {
            if (isset($this->_image['thumb_name'])) {
                return '<img src="images/phpwsbusinesses/' . $this->getListOwner() . '/' . $this->_image['thumb_name'] . '" alt="' . $this->getLabel() . '" border="0" />';
            } else {
                return '<img src="images/phpwsbusinesses/' . $this->getListOwner() . '/' . $this->_image['name'] . '" alt="' . $this->getLabel() . '" border="0" />';
            }
        } else {
            return NULL;
        }
    }

    function getListCompany_Name() {
        return $this->_company_name;
    }

    function getListCompany_Website() {
        return $this->_company_website;
    }

    function getListCompany_Title() {
        return $this->_company_title;
    }

    function getListCustom1() {
        return $this->_custom1;
    }

    function getListCustom2() {
        return $this->_custom2;
    }

    function getListCustom3() {
        return $this->_custom3;
    }

    function getListCustom4() {
        return $this->_custom4;
    }

    function getListCustom1_priv() {
        return $this->_custom1_priv;
    }

    function getListCustom2_priv() {
        return $this->_custom2_priv;
    }

    function getListCustom3_priv() {
        return $this->_custom3_priv;
    }

    function getListCustom4_priv() {
        return $this->_custom4_priv;
    }


    /**
     * Returns website, prepending 'http://' if missing
     */
    function _getWebsite($url) {
        if (!empty($url)) {
            if (eregi("^http", $url)) {
                return $url;
            } else {
                return 'http://' . $url;
            }
        } else {
            return $url;
        }
    }

  /**
   * Creates an array of the English alphabet
   *
   * If '$letter_case' is lower then the character set
   * will be lowercase. If it is NULL, then uppercase.
   * Needs internationalization
   *
   * @author Matthew McNaney <matt@NOSPAM.tux.appstate.edu>
   * @param  string $letter_case Indicates to return an uppercase or lowercase array
   * @return array  $ret_array   Numerically indexed array of alphabet
   * @access public
   */
  function alphabet($letter_case=NULL) {
    if ($letter_case == "lower") {
      $start = ord("a");
      $end = ord("z");
    } else {
      $start = ord("A");
      $end = ord("Z");
    }
    
    for ($i=$start;$i<=$end;$i++)
      $ret_array[] = chr($i);

    return $ret_array;
  }// END FUNC alphabet()

}// END CLASS BUSINESSES_Business

?>
