[Vtigercrm-commits] [vtiger-commits] r9078 - in /vtigercrm/trunk/modules: Accounts/Account.php Contacts/Contact.php HelpDesk/HelpDesk.php Leads/Lead.php

vtigercrm-commits at vtiger.fosslabs.com vtigercrm-commits at vtiger.fosslabs.com
Wed Aug 23 10:01:35 EDT 2006


Author: richie
Date: Wed Aug 23 08:00:50 2006
New Revision: 9078

Log:
Security implemented for WordPlugin

Modified:
    vtigercrm/trunk/modules/Accounts/Account.php
    vtigercrm/trunk/modules/Contacts/Contact.php
    vtigercrm/trunk/modules/HelpDesk/HelpDesk.php
    vtigercrm/trunk/modules/Leads/Lead.php

Modified: vtigercrm/trunk/modules/Accounts/Account.php
==============================================================================
--- vtigercrm/trunk/modules/Accounts/Account.php (original)
+++ vtigercrm/trunk/modules/Accounts/Account.php Wed Aug 23 08:00:50 2006
@@ -1,743 +1,751 @@
-<?php
-/*********************************************************************************
- * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
- * ("License"); You may not use this file except in compliance with the
- * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
- * Software distributed under the License is distributed on an  "AS IS"  basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
- * the specific language governing rights and limitations under the License.
- * The Original Code is:  SugarCRM Open Source
- * The Initial Developer of the Original Code is SugarCRM, Inc.
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
- * All Rights Reserved.
- * Contributor(s): ______________________________________.
- ********************************************************************************/
-/*********************************************************************************
- * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/modules/Accounts/Account.php,v 1.53 2005/04/28 08:06:45 rank Exp $
- * Description:  Defines the Account SugarBean Account entity with the necessary
- * methods and variables.
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
- * All Rights Reserved.
- * Contributor(s): ______________________________________..
- ********************************************************************************/
-
-include_once('config.php');
-require_once('include/logging.php');
-require_once('include/database/PearDatabase.php');
-require_once('data/SugarBean.php');
-require_once('data/CRMEntity.php');
-require_once('modules/Contacts/Contact.php');
-require_once('modules/Potentials/Opportunity.php');
-require_once('modules/Calendar/Activity.php');
-require_once('modules/Notes/Note.php');
-require_once('modules/Emails/Email.php');
-require_once('include/utils/utils.php');
-
-// Account is used to store vtiger_account information.
-class Account extends CRMEntity {
-	var $log;
-	var $db;
-
-	var $table_name = "vtiger_account";
-	var $tab_name = Array('vtiger_crmentity','vtiger_account','vtiger_accountbillads','vtiger_accountshipads','vtiger_accountscf');
-	var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_account'=>'accountid','vtiger_accountbillads'=>'accountaddressid','vtiger_accountshipads'=>'accountaddressid','vtiger_accountscf'=>'accountid');
-
-	var $entity_table = "vtiger_crmentity";
-
-	var $billadr_table = "vtiger_accountbillads";
-
-	var $object_name = "Accounts";
-	// Mike Crowe Mod --------------------------------------------------------added for general search
-	var $base_table_name = "vtiger_account";
-	var $cf_table_name = "vtiger_accountscf";
-
-	var $new_schema = true;
-
-	var $module_id = "accountid";
-
-	var $column_fields = Array();
-
-	var $sortby_fields = Array('accountname','city','website','phone','smownerid');		
-
-
-	// This is the list of vtiger_fields that are in the lists.
-	var $list_fields = Array(
-			'Account Name'=>Array('vtiger_account'=>'accountname'),
-			'City'=>Array('vtiger_accountbillads'=>'city'), 
-			'Website'=>Array('vtiger_account'=>'website'),
-			'Phone'=>Array('vtiger_account'=> 'phone'),
-			'Assigned To'=>Array('vtiger_crmentity'=>'smownerid')
-			);
-
-	var $list_fields_name = Array(
-			'Account Name'=>'accountname',
-			'City'=>'bill_city',
-			'Website'=>'website',
-			'Phone'=>'phone',
-			'Assigned To'=>'assigned_user_id'
-			);
-	var $list_link_field= 'accountname';
-
-	var $search_fields = Array(
-			'Account Name'=>Array('vtiger_account'=>'accountname'),
-			'City'=>Array('vtiger_accountbillads'=>'city'), 
-			);
-
-	var $search_fields_name = Array(
-			'Account Name'=>'accountname',
-			'City'=>'bill_city',
-			);
-
-	// This is the list of vtiger_fields that are required.
-	var $required_fields =  array("accountname"=>1);
-
-	//Added these variables which are used as default order by and sortorder in ListView
-	var $default_order_by = 'accountname';
-	var $default_sort_order = 'ASC';
-
-	function Account() {
-		$this->log =LoggerManager::getLogger('account');
-		$this->db = new PearDatabase();
-		$this->column_fields = getColumnFields('Accounts');
-	}
-
-	// Mike Crowe Mod --------------------------------------------------------Default ordering for us
-	/**
-	 * Function to get sort order
- 	 * return string  $sorder    - sortorder string either 'ASC' or 'DESC'
-	 */
-	function getSortOrder()
-	{
-		global $log;
-                $log->debug("Entering getSortOrder() method ...");	
-		if(isset($_REQUEST['sorder'])) 
-			$sorder = $_REQUEST['sorder'];
-		else
-			$sorder = (($_SESSION['ACCOUNTS_SORT_ORDER'] != '')?($_SESSION['ACCOUNTS_SORT_ORDER']):($this->default_sort_order));
-		$log->debug("Exiting getSortOrder() method ...");
-		return $sorder;
-	}
-	/**
-	 * Function to get order by
-	 * return string  $order_by    - fieldname(eg: 'accountname')
- 	 */
-	function getOrderBy()
-	{
-		global $log;
-                $log->debug("Entering getOrderBy() method ...");
-		if (isset($_REQUEST['order_by'])) 
-			$order_by = $_REQUEST['order_by'];
-		else
-			$order_by = (($_SESSION['ACCOUNTS_ORDER_BY'] != '')?($_SESSION['ACCOUNTS_ORDER_BY']):($this->default_order_by));
-		$log->debug("Exiting getOrderBy method ...");
-		return $order_by;
-	}	
-	// Mike Crowe Mod --------------------------------------------------------
-
-
-	/** Returns a list of the associated contacts
-	 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
-	 * All Rights Reserved..
-	 * Contributor(s): ______________________________________..
-	 */
-	function get_contacts($id)
-	{	
-		global $log;
-                $log->debug("Entering get_contacts(".$id.") method ...");
-		global $mod_strings;
-
-		$focus = new Contact();
-
-		$button = '';
-		if(isPermitted("Contacts",1,"") == 'yes')
-		{
-			$button .= '<input title="New Contact" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Contacts\'" type="submit" name="button" value="'.$mod_strings['LBL_NEW_CONTACT'].'">&nbsp;</td>';
-		}
-		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
-
-		//SQL
-		$query = "SELECT vtiger_contactdetails.*,
-			vtiger_crmentity.crmid,
-                        vtiger_crmentity.smownerid,
-			vtiger_users.user_name
-			FROM vtiger_contactdetails
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid
-			LEFT JOIN vtiger_contactgrouprelation
-				ON vtiger_contactdetails.contactid = vtiger_contactgrouprelation.contactid
-			LEFT JOIN vtiger_groups
-				ON vtiger_groups.groupname = vtiger_contactgrouprelation.groupname
-			LEFT JOIN vtiger_users
-				ON vtiger_crmentity.smownerid = vtiger_users.id
-			WHERE vtiger_crmentity.deleted = 0
-			AND vtiger_contactdetails.accountid = ".$id;
-		$log->debug("Exiting get_contacts method ...");
-		return GetRelatedList('Accounts','Contacts',$focus,$query,$button,$returnset);
-	}
-
-	/** Returns a list of the associated opportunities
-	 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
-	 * All Rights Reserved..
-	 * Contributor(s): ______________________________________..
-	 */
-	function get_opportunities($id)
-	{
-		global $log;
-                $log->debug("Entering get_opportunities(".$id.") method ...");
-		global $mod_strings;
-
-		$focus = new Potential();
-		$button = '';
-
-		if(isPermitted("Potentials",1,"") == 'yes')
-		{
-			$button .= '<input title="New Potential" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Potentials\'" type="submit" name="button" value="'.$mod_strings['LBL_NEW_POTENTIAL'].'">';
-		}
-		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
-
-		$query = "SELECT vtiger_potential.potentialid, vtiger_potential.accountid,
-			vtiger_potential.potentialname, vtiger_potential.sales_stage,
-			vtiger_potential.potentialtype, vtiger_potential.amount,
-			vtiger_potential.closingdate, vtiger_potential.potentialtype,
-			vtiger_users.user_name,
-			vtiger_crmentity.crmid, vtiger_crmentity.smownerid
-			FROM vtiger_potential
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_potential.potentialid
-			LEFT JOIN vtiger_users
-				ON vtiger_crmentity.smownerid = vtiger_users.id
-			LEFT JOIN vtiger_potentialgrouprelation
-				ON vtiger_potential.potentialid = vtiger_potentialgrouprelation.potentialid
-			LEFT JOIN vtiger_groups
-				ON vtiger_groups.groupname = vtiger_potentialgrouprelation.groupname
-			WHERE vtiger_crmentity.deleted = 0
-			AND vtiger_potential.accountid = ".$id;
-		$log->debug("Exiting get_opportunities method ...");
-
-		return GetRelatedList('Accounts','Potentials',$focus,$query,$button,$returnset);
-	}
-
-	/** Returns a list of the associated tasks
-	 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
-	 * All Rights Reserved..
-	 * Contributor(s): ______________________________________..
-	 */
-	function get_activities($id)
-	{
-		global $log;
-                $log->debug("Entering get_activities(".$id.") method ...");
-		global $mod_strings;
-
-		$focus = new Activity();
-		$button = '';
-		if(isPermitted("Calendar",1,"") == 'yes')
-		{
-
-			$button .= '<input title="New Task" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.return_action.value=\'DetailView\';this.form.module.value=\'Calendar\';this.form.return_module.value=\'Accounts\';this.form.activity_mode.value=\'Task\'" type="submit" name="button" value="'.$mod_strings['LBL_NEW_TASK'].'">&nbsp;';
-			$button .= '<input title="New Event" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.return_action.value=\'DetailView\';this.form.module.value=\'Calendar\';this.form.return_module.value=\'Accounts\';this.form.activity_mode.value=\'Events\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_EVENT'].'">&nbsp;</td>';
-		}
-		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
-
-		$query = "SELECT vtiger_activity.*,
-			vtiger_seactivityrel.*,
-			vtiger_crmentity.crmid, vtiger_crmentity.smownerid,
-			vtiger_crmentity.modifiedtime,
-			vtiger_users.user_name,
-			vtiger_recurringevents.recurringtype
-			FROM vtiger_activity
-			INNER JOIN vtiger_seactivityrel
-				ON vtiger_seactivityrel.activityid = vtiger_activity.activityid
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_activity.activityid
-			LEFT JOIN vtiger_users
-				ON vtiger_users.id = vtiger_crmentity.smownerid
-			LEFT OUTER JOIN vtiger_recurringevents
-				ON vtiger_recurringevents.activityid = vtiger_activity.activityid
-			LEFT JOIN vtiger_activitygrouprelation
-				ON vtiger_activitygrouprelation.activityid = vtiger_crmentity.crmid
-			LEFT JOIN vtiger_groups
-				ON vtiger_groups.groupname = vtiger_activitygrouprelation.groupname
-			WHERE vtiger_seactivityrel.crmid = ".$id."
-			AND (activitytype='Task'
-				OR activitytype='Call'
-				OR activitytype='Meeting')
-			AND vtiger_crmentity.deleted = 0
-			AND ((vtiger_activity.status IS NOT NULL
-					AND vtiger_activity.status != 'Completed')
-				AND (vtiger_activity.status IS NOT NULL
-					AND vtiger_activity.status != 'Deferred')
-				OR (vtiger_activity.eventstatus !=''
-					AND  vtiger_activity.eventstatus != 'Held'))";
-		$log->debug("Exiting get_activities method ...");
-		return GetRelatedList('Accounts','Calendar',$focus,$query,$button,$returnset);
-
-	}
-	/**
-	 * Function to get Account related Task & Event which have activity type Held, Completed or Deferred.
- 	 * @param  integer   $id      - accountid
- 	 * returns related Task or Event record in array format
- 	 */
-	function get_history($id)
-	{
-		global $log;
-                $log->debug("Entering get_history(".$id.") method ...");
-		$query = "SELECT vtiger_activity.activityid, vtiger_activity.subject,
-			vtiger_activity.status, vtiger_activity.eventstatus,
-			vtiger_activity.activitytype,
-			vtiger_crmentity.modifiedtime, vtiger_crmentity.createdtime,
-			vtiger_crmentity.description,
-			vtiger_users.user_name
-			FROM vtiger_activity
-			INNER JOIN vtiger_seactivityrel
-				ON vtiger_seactivityrel.activityid = vtiger_activity.activityid
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_activity.activityid
-			LEFT JOIN vtiger_activitygrouprelation
-				ON vtiger_activitygrouprelation.activityid = vtiger_activity.activityid
-			LEFT JOIN vtiger_groups
-				ON vtiger_groups.groupname = vtiger_activitygrouprelation.groupname
-			INNER JOIN vtiger_users
-				ON vtiger_crmentity.smcreatorid = vtiger_users.id
-			WHERE (vtiger_activity.activitytype = 'Meeting'
-				OR vtiger_activity.activitytype = 'Call'
-				OR vtiger_activity.activitytype = 'Task')
-			AND (vtiger_activity.status = 'Completed'
-				OR vtiger_activity.status = 'Deferred'
-				OR (vtiger_activity.eventstatus = 'Held'
-					AND vtiger_activity.eventstatus != ''))
-			AND vtiger_seactivityrel.crmid = ".$id;
-		//Don't add order by, because, for security, one more condition will be added with this query in include/RelatedListView.php
-		$log->debug("Exiting get_history method ...");
-		return getHistory('Accounts',$query,$id);
-	}
-	/**
-	 * Function to get Account related Attachments
- 	 * @param  integer   $id      - accountid
- 	 * returns related Attachment record in array format
- 	 */
-	function get_attachments($id)
-	{
-		 global $log;
-                 $log->debug("Entering get_attachments(".$id.") method ...");
-		// Armando Lüscher 18.10.2005 -> §visibleDescription
-		// Desc: Inserted crm2.createdtime, vtiger_notes.notecontent description, vtiger_users.user_name
-		// Inserted inner join vtiger_users on crm2.smcreatorid= vtiger_users.id
-		$query = "SELECT vtiger_notes.title, vtiger_notes.notecontent AS description,
-			vtiger_notes.filename, vtiger_notes.notesid AS crmid,
-				'Notes      ' AS ActivityType,
-			vtiger_attachments.type AS FileType,
-				crm2.modifiedtime AS lastmodified, crm2.createdtime,
-			vtiger_seattachmentsrel.attachmentsid,
-			vtiger_users.user_name
-			FROM vtiger_notes
-			INNER JOIN vtiger_senotesrel
-				ON vtiger_senotesrel.notesid = vtiger_notes.notesid
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_senotesrel.crmid
-			INNER JOIN vtiger_crmentity crm2
-				ON crm2.crmid = vtiger_notes.notesid
-				AND crm2.deleted = 0
-			LEFT JOIN vtiger_seattachmentsrel
-				ON vtiger_seattachmentsrel.crmid = vtiger_notes.notesid
-			LEFT JOIN vtiger_attachments
-				ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
-			INNER JOIN vtiger_users
-				ON crm2.smcreatorid = vtiger_users.id
-			WHERE vtiger_crmentity.crmid = ".$id."
-		 UNION ALL
-			SELECT vtiger_attachments.description AS title, vtiger_attachments.description,
-			vtiger_attachments.name AS filename,
-			vtiger_seattachmentsrel.attachmentsid AS crmid,
-				'Attachments' AS ActivityType,
-			vtiger_attachments.type AS FileType,
-				crm2.modifiedtime AS lastmodified, crm2.createdtime,
-			vtiger_attachments.attachmentsid,
-			vtiger_users.user_name
-			FROM vtiger_attachments
-			INNER JOIN vtiger_seattachmentsrel
-				ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_seattachmentsrel.crmid
-			INNER JOIN vtiger_crmentity crm2
-				ON crm2.crmid = vtiger_attachments.attachmentsid
-			INNER JOIN vtiger_users
-				ON crm2.smcreatorid = vtiger_users.id
-			WHERE vtiger_crmentity.crmid = ".$id."
-			ORDER BY createdtime DESC";
-		$log->debug("Exiting get_attachments method ...");
-		return getAttachmentsAndNotes('Accounts',$query,$id);
-	}
-	/**
-	* Function to get Account related Quotes
-	* @param  integer   $id      - accountid
-	* returns related Quotes record in array format
-	*/
-	function get_quotes($id)
-	{
-		global $log;
-                $log->debug("Entering get_quotes(".$id.") method ...");
-		global $app_strings;
-		require_once('modules/Quotes/Quote.php');
-
-		$focus = new Quote();
-
-		$button = '';
-		if(isPermitted("Quotes",1,"") == 'yes')
-		{
-			$button .= '<input title="'.$app_strings['LBL_NEW_QUOTE_BUTTON_TITLE'].'" accessyKey="'.$app_strings['LBL_NEW_QUOTE_BUTTON_KEY'].'" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Quotes\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_QUOTE_BUTTON'].'">&nbsp;</td>';
-		}
-		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
-
-		$query = "SELECT vtiger_users.user_name,
-			vtiger_groups.groupname,
-			vtiger_crmentity.*,
-			vtiger_quotes.*,
-			vtiger_potential.potentialname,
-			vtiger_account.accountname
-			FROM vtiger_quotes
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_quotes.quoteid
-			LEFT OUTER JOIN vtiger_account
-				ON vtiger_account.accountid = vtiger_quotes.accountid
-			LEFT OUTER JOIN vtiger_potential
-				ON vtiger_potential.potentialid = vtiger_quotes.potentialid
-			LEFT JOIN vtiger_quotegrouprelation
-				ON vtiger_quotes.quoteid = vtiger_quotegrouprelation.quoteid
-			LEFT JOIN vtiger_groups
-				ON vtiger_groups.groupname = vtiger_quotegrouprelation.groupname
-			LEFT JOIN vtiger_users
-				ON vtiger_crmentity.smownerid = vtiger_users.id
-			WHERE vtiger_crmentity.deleted = 0
-			AND vtiger_account.accountid = ".$id;
-		$log->debug("Exiting get_quotes method ...");
-		return GetRelatedList('Accounts','Quotes',$focus,$query,$button,$returnset);
-	}
-	/**
-	* Function to get Account related Invoices 
-	* @param  integer   $id      - accountid
-	* returns related Invoices record in array format
-	*/
-	function get_invoices($id)
-	{
-		global $log;
-                $log->debug("Entering get_invoices(".$id.") method ...");
-		global $app_strings;
-		require_once('modules/Invoice/Invoice.php');
-
-		$focus = new Invoice();
-
-		$button = '';
-		if(isPermitted("Invoice",1,"") == 'yes')
-		{
-			$button .= '<input title="'.$app_strings['LBL_NEW_INVOICE_BUTTON_TITLE'].'" accessyKey="'.$app_strings['LBL_NEW_INVOICE_BUTTON_KEY'].'" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Invoice\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_INVOICE_BUTTON'].'">&nbsp;</td>';
-		}
-		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
-
-		$query = "SELECT vtiger_users.user_name,
-			vtiger_groups.groupname,
-			vtiger_crmentity.*,
-			vtiger_invoice.*,
-			vtiger_account.accountname,
-			vtiger_salesorder.subject AS salessubject
-			FROM vtiger_invoice
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_invoice.invoiceid
-			LEFT OUTER JOIN vtiger_account
-				ON vtiger_account.accountid = vtiger_invoice.accountid
-			LEFT OUTER JOIN vtiger_salesorder
-				ON vtiger_salesorder.salesorderid = vtiger_invoice.salesorderid
-			LEFT JOIN vtiger_invoicegrouprelation
-				ON vtiger_invoice.invoiceid = vtiger_invoicegrouprelation.invoiceid
-			LEFT JOIN vtiger_groups
-				ON vtiger_groups.groupname = vtiger_invoicegrouprelation.groupname
-			LEFT JOIN vtiger_users
-				ON vtiger_crmentity.smownerid = vtiger_users.id
-			WHERE vtiger_crmentity.deleted = 0
-			AND vtiger_account.accountid = ".$id;
-		$log->debug("Exiting get_invoices method ...");
-		return GetRelatedList('Accounts','Invoice',$focus,$query,$button,$returnset);
-	}
-
-	/**
-	* Function to get Account related SalesOrder 
-	* @param  integer   $id      - accountid
-	* returns related SalesOrder record in array format
-	*/
-	function get_salesorder($id)
-	{
-		global $log;
-                $log->debug("Entering get_salesorder(".$id.") method ...");
-		require_once('modules/SalesOrder/SalesOrder.php');
-		global $app_strings;
-
-		$focus = new SalesOrder();
-
-		$button = '';
-		if(isPermitted("SalesOrder",1,"") == 'yes')
-		{
-			$button .= '<input title="'.$app_strings['LBL_NEW_SORDER_BUTTON_TITLE'].'" accessyKey="'.$app_strings['LBL_NEW_SORDER_BUTTON_KEY'].'" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'SalesOrder\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_SORDER_BUTTON'].'">&nbsp;</td>';
-		}
-
-		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
-
-		$query = "SELECT vtiger_crmentity.*,
-			vtiger_salesorder.*,
-			vtiger_quotes.subject AS quotename,
-			vtiger_account.accountname,
-			vtiger_users.user_name,
-			vtiger_groups.groupname
-			FROM vtiger_salesorder
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_salesorder.salesorderid
-			LEFT OUTER JOIN vtiger_quotes
-				ON vtiger_quotes.quoteid = vtiger_salesorder.quoteid
-			LEFT OUTER JOIN vtiger_account
-				ON vtiger_account.accountid = vtiger_salesorder.accountid
-			LEFT JOIN vtiger_sogrouprelation
-				ON vtiger_salesorder.salesorderid = vtiger_sogrouprelation.salesorderid
-			LEFT JOIN vtiger_groups
-				ON vtiger_groups.groupname = vtiger_sogrouprelation.groupname
-			LEFT JOIN vtiger_users
-				ON vtiger_crmentity.smownerid = vtiger_users.id
-			WHERE vtiger_crmentity.deleted = 0
-			AND vtiger_salesorder.accountid = ".$id;
-		$log->debug("Exiting get_salesorder method ...");		
-		return GetRelatedList('Accounts','SalesOrder',$focus,$query,$button,$returnset);
-	}
-	/**
-	* Function to get Account related Tickets
-	* @param  integer   $id      - accountid
-	* returns related Ticket record in array format
-	*/
-	function get_tickets($id)
-	{
-		global $log;
-                $log->debug("Entering get_tickets(".$id.") method ...");
-		global $app_strings;
-
-		$focus = new HelpDesk();
-		$button = '';
-
-		$button .= '<td valign="bottom" align="right"><input title="New TICKET" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'HelpDesk\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_TICKET'].'">&nbsp;</td>';
-		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
-
-		$query = "SELECT vtiger_users.user_name, vtiger_users.id,
-			vtiger_troubletickets.title, vtiger_troubletickets.ticketid AS crmid,
-			vtiger_troubletickets.status, vtiger_troubletickets.priority,
-			vtiger_troubletickets.parent_id,
-			vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime
-			FROM vtiger_troubletickets
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid
-			LEFT JOIN vtiger_account
-				ON vtiger_account.accountid = vtiger_troubletickets.parent_id
-			LEFT JOIN vtiger_contactdetails
-			        ON vtiger_contactdetails.contactid=vtiger_troubletickets.parent_id
-			LEFT JOIN vtiger_users
-				ON vtiger_users.id=vtiger_crmentity.smownerid
-			LEFT JOIN vtiger_ticketgrouprelation
-				ON vtiger_troubletickets.ticketid = vtiger_ticketgrouprelation.ticketid
-			LEFT JOIN vtiger_groups
-				ON vtiger_groups.groupname = vtiger_ticketgrouprelation.groupname
-			WHERE  vtiger_troubletickets.parent_id=".$id." or " ;
-
-		$query .= "vtiger_troubletickets.parent_id in(SELECT vtiger_contactdetails.contactid
-			FROM vtiger_contactdetails
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid
-			LEFT JOIN vtiger_contactgrouprelation
-				ON vtiger_contactdetails.contactid = vtiger_contactgrouprelation.contactid
-			LEFT JOIN vtiger_groups
-				ON vtiger_groups.groupname = vtiger_contactgrouprelation.groupname
-			LEFT JOIN vtiger_users
-				ON vtiger_crmentity.smownerid = vtiger_users.id
-			WHERE vtiger_crmentity.deleted = 0
-			AND vtiger_contactdetails.accountid = ".$id;
-
-			
-		//Appending the security parameter
-		global $current_user;
-		require('user_privileges/user_privileges_'.$current_user->id.'.php');
-		require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
-		$tab_id=getTabid('Contacts');
-		if($is_admin==false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $defaultOrgSharingPermission[$tab_id] == 3)
-		{
-			$sec_parameter=getListViewSecurityParameter('Contacts');
-			$query .= ' '.$sec_parameter;
-
-		}
-
-		$query .= ") ";
-		
-		/*
-		$query .= " UNION ALL
-			SELECT vtiger_users.user_name, vtiger_users.id,
-			vtiger_troubletickets.title, vtiger_troubletickets.ticketid AS crmid,
-			vtiger_troubletickets.status, vtiger_troubletickets.priority,
-			vtiger_troubletickets.parent_id,
-			vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime
-			FROM vtiger_troubletickets
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid
-			LEFT JOIN vtiger_contactdetails
-				ON vtiger_contactdetails.contactid = vtiger_troubletickets.parent_id
-			LEFT JOIN vtiger_account
-				ON vtiger_account.accountid = vtiger_contactdetails.accountid
-			LEFT JOIN vtiger_users
-				ON vtiger_users.id = vtiger_crmentity.smownerid
-			LEFT JOIN vtiger_ticketgrouprelation
-				ON vtiger_troubletickets.ticketid = vtiger_ticketgrouprelation.ticketid
-			LEFT JOIN vtiger_groups
-				ON vtiger_groups.groupname = vtiger_ticketgrouprelation.groupname
-			WHERE vtiger_account.accountid = ".$id;
-		*/	
-		$log->debug("Exiting get_tickets method ...");
-		return GetRelatedList('Accounts','HelpDesk',$focus,$query,$button,$returnset);
-	}
-	/**
-	* Function to get Account related Products 
-	* @param  integer   $id      - accountid
-	* returns related Products record in array format
-	*/
-	function get_products($id)
-	{
-		global $log;
-                $log->debug("Entering get_products(".$id.") method ...");
-		require_once('modules/Products/Product.php');
-		global $app_strings;
-
-		$focus = new Product();
-
-		$button = '';
-
-		if(isPermitted("Products",1,"") == 'yes')
-		{
-
-
-			$button .= '<input title="New Product" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Products\';this.form.return_module.value=\'Accounts\';this.form.return_action.value=\'DetailView\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_PRODUCT'].'">&nbsp;';
-		}
-		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
-
-		$query = "SELECT vtiger_products.productid, vtiger_products.productname,
-			vtiger_products.productcode, vtiger_products.commissionrate,
-			vtiger_products.qty_per_unit, vtiger_products.unit_price,
-			vtiger_crmentity.crmid, vtiger_crmentity.smownerid
-			FROM vtiger_products
-			INNER JOIN vtiger_seproductsrel
-				ON vtiger_products.productid = vtiger_seproductsrel.productid
-			INNER JOIN vtiger_crmentity
-				ON vtiger_crmentity.crmid = vtiger_products.productid
-			INNER JOIN vtiger_account
-				ON vtiger_account.accountid = vtiger_seproductsrel.crmid
-			WHERE vtiger_account.accountid = ".$id."
-			AND vtiger_crmentity.deleted = 0";
-		$log->debug("Exiting get_products method ...");
-		return GetRelatedList('Accounts','Products',$focus,$query,$button,$returnset);
-	}
-
-	/** Function to export the account records in CSV Format
-	* @param reference variable - order by is passed when the query is executed
-	* @param reference variable - where condition is passed when the query is executed
-	* Returns Export Accounts Query.
-	*/
-	function create_export_query(&$order_by, &$where)
-	{
-		global $log;
-                $log->debug("Entering create_export_query(".$order_by.",".$where.") method ...");
-		if($this->checkIfCustomTableExists('vtiger_accountscf'))
-		{
-
-			$query = $this->constructCustomQueryAddendum('vtiger_accountscf','Accounts') . "
-				vtiger_account.*,
-					".$this->entity_table.".*,
-				vtiger_accountbillads.city AS billing_city,
-				vtiger_accountbillads.country AS billing_country,
-				vtiger_accountbillads.code AS billing_code,
-				vtiger_accountbillads.state AS billing_state,
-				vtiger_accountbillads.street AS billing_street,
-				vtiger_accountshipads.city AS shipping_city,
-				vtiger_accountshipads.country AS shipping_country,
-				vtiger_accountshipads.code AS shipping_code,
-				vtiger_accountshipads.state AS shipping_state,
-				vtiger_accountshipads.street AS shipping_street,
-				vtiger_users.user_name,
-				vtiger_users.status AS user_status
-				FROM ".$this->entity_table."
-				INNER JOIN vtiger_account
-					ON vtiger_crmentity.crmid = vtiger_account.accountid
-				LEFT JOIN vtiger_accountbillads
-					ON vtiger_account.accountid = vtiger_accountbillads.accountaddressid
-				LEFT JOIN vtiger_accountshipads
-					ON vtiger_account.accountid = vtiger_accountshipads.accountaddressid
-				LEFT JOIN vtiger_accountscf 
-					ON vtiger_accountscf.accountid = vtiger_account.accountid
-				LEFT JOIN vtiger_users
-					ON vtiger_crmentity.smownerid = vtiger_users.id ";
-
-		}
-		else
-		{
-			$query = "SELECT vtiger_account.*,
-					".$this->entity_table.".*,
-				vtiger_accountbillads.city AS billing_city,
-				vtiger_accountbillads.country AS billing_country,
-				vtiger_accountbillads.code AS billing_code,
-				vtiger_accountbillads.state AS billing_state,
-				vtiger_accountbillads.street AS billing_street,
-				vtiger_accountshipads.city AS shipping_city,
-				vtiger_accountshipads.country AS shipping_country,
-				vtiger_accountshipads.code AS shipping_code,
-				vtiger_accountshipads.state AS shipping_state,
-				vtiger_accountshipads.street AS shipping_street,
-				vtiger_users.user_name,
-				vtiger_users.status AS user_status
-				FROM ".$this->entity_table."
-				INNER JOIN vtiger_account
-					ON vtiger_crmentity.crmid = vtiger_account.accountid
-				LEFT JOIN vtiger_accountbillads
-					ON vtiger_account.accountid = vtiger_accountbillads.accountaddressid
-				LEFT JOIN vtiger_accountshipads
-					ON vtiger_account.accountid = vtiger_accountshipads.accountaddressid
-				LEFT JOIN vtiger_users
-					ON vtiger_crmentity.smownerid = vtiger_users.id ";
-		}
-
-		$where_auto = " vtiger_users.status = 'Active'
-			AND vtiger_crmentity.deleted = 0 ";
-
-		if($where != "")
-			$query .= "WHERE ($where) AND ".$where_auto;
-		else
-			$query .= "WHERE ".$where_auto;
-
-		if(!empty($order_by))
-			$query .= " ORDER BY $order_by";
-		$log->debug("Exiting create_export_query method ...");
-		return $query;
-	}
-
-	/** Function to get the Columnnames of the Account Record
-	* Used By vtigerCRM Word Plugin
-	* Returns the Merge Fields for Word Plugin
-	*/
-	function getColumnNames_Acnt()
-	{
-		global $log;
-                $log->debug("Entering getColumnNames_Acnt() method ...");
-		$sql1 = "SELECT fieldlabel FROM vtiger_field WHERE tabid = 6";
-		$result = $this->db->query($sql1);
-		$numRows = $this->db->num_rows($result);
-		for($i=0; $i < $numRows;$i++)
-		{
-			$custom_fields[$i] = $this->db->query_result($result,$i,"fieldlabel");
-			$custom_fields[$i] = ereg_replace(" ","",$custom_fields[$i]);
-			$custom_fields[$i] = strtoupper($custom_fields[$i]);
-		}
-		$mergeflds = $custom_fields;
-		$log->debug("Exiting getColumnNames_Acnt method ...");
-		return $mergeflds;
-	}
-
-}
-
-?>
+<?php
+/*********************************************************************************
+ * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
+ * ("License"); You may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
+ * Software distributed under the License is distributed on an  "AS IS"  basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+ * the specific language governing rights and limitations under the License.
+ * The Original Code is:  SugarCRM Open Source
+ * The Initial Developer of the Original Code is SugarCRM, Inc.
+ * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
+ * All Rights Reserved.
+ * Contributor(s): ______________________________________.
+ ********************************************************************************/
+/*********************************************************************************
+ * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/modules/Accounts/Account.php,v 1.53 2005/04/28 08:06:45 rank Exp $
+ * Description:  Defines the Account SugarBean Account entity with the necessary
+ * methods and variables.
+ * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
+ * All Rights Reserved.
+ * Contributor(s): ______________________________________..
+ ********************************************************************************/
+
+include_once('config.php');
+require_once('include/logging.php');
+require_once('include/database/PearDatabase.php');
+require_once('data/SugarBean.php');
+require_once('data/CRMEntity.php');
+require_once('modules/Contacts/Contact.php');
+require_once('modules/Potentials/Opportunity.php');
+require_once('modules/Calendar/Activity.php');
+require_once('modules/Notes/Note.php');
+require_once('modules/Emails/Email.php');
+require_once('include/utils/utils.php');
+
+// Account is used to store vtiger_account information.
+class Account extends CRMEntity {
+	var $log;
+	var $db;
+
+	var $table_name = "vtiger_account";
+	var $tab_name = Array('vtiger_crmentity','vtiger_account','vtiger_accountbillads','vtiger_accountshipads','vtiger_accountscf');
+	var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_account'=>'accountid','vtiger_accountbillads'=>'accountaddressid','vtiger_accountshipads'=>'accountaddressid','vtiger_accountscf'=>'accountid');
+
+	var $entity_table = "vtiger_crmentity";
+
+	var $billadr_table = "vtiger_accountbillads";
+
+	var $object_name = "Accounts";
+	// Mike Crowe Mod --------------------------------------------------------added for general search
+	var $base_table_name = "vtiger_account";
+	var $cf_table_name = "vtiger_accountscf";
+
+	var $new_schema = true;
+
+	var $module_id = "accountid";
+
+	var $column_fields = Array();
+
+	var $sortby_fields = Array('accountname','city','website','phone','smownerid');		
+
+
+	// This is the list of vtiger_fields that are in the lists.
+	var $list_fields = Array(
+			'Account Name'=>Array('vtiger_account'=>'accountname'),
+			'City'=>Array('vtiger_accountbillads'=>'city'), 
+			'Website'=>Array('vtiger_account'=>'website'),
+			'Phone'=>Array('vtiger_account'=> 'phone'),
+			'Assigned To'=>Array('vtiger_crmentity'=>'smownerid')
+			);
+
+	var $list_fields_name = Array(
+			'Account Name'=>'accountname',
+			'City'=>'bill_city',
+			'Website'=>'website',
+			'Phone'=>'phone',
+			'Assigned To'=>'assigned_user_id'
+			);
+	var $list_link_field= 'accountname';
+
+	var $search_fields = Array(
+			'Account Name'=>Array('vtiger_account'=>'accountname'),
+			'City'=>Array('vtiger_accountbillads'=>'city'), 
+			);
+
+	var $search_fields_name = Array(
+			'Account Name'=>'accountname',
+			'City'=>'bill_city',
+			);
+
+	// This is the list of vtiger_fields that are required.
+	var $required_fields =  array("accountname"=>1);
+
+	//Added these variables which are used as default order by and sortorder in ListView
+	var $default_order_by = 'accountname';
+	var $default_sort_order = 'ASC';
+
+	function Account() {
+		$this->log =LoggerManager::getLogger('account');
+		$this->db = new PearDatabase();
+		$this->column_fields = getColumnFields('Accounts');
+	}
+
+	// Mike Crowe Mod --------------------------------------------------------Default ordering for us
+	/**
+	 * Function to get sort order
+ 	 * return string  $sorder    - sortorder string either 'ASC' or 'DESC'
+	 */
+	function getSortOrder()
+	{
+		global $log;
+                $log->debug("Entering getSortOrder() method ...");	
+		if(isset($_REQUEST['sorder'])) 
+			$sorder = $_REQUEST['sorder'];
+		else
+			$sorder = (($_SESSION['ACCOUNTS_SORT_ORDER'] != '')?($_SESSION['ACCOUNTS_SORT_ORDER']):($this->default_sort_order));
+		$log->debug("Exiting getSortOrder() method ...");
+		return $sorder;
+	}
+	/**
+	 * Function to get order by
+	 * return string  $order_by    - fieldname(eg: 'accountname')
+ 	 */
+	function getOrderBy()
+	{
+		global $log;
+                $log->debug("Entering getOrderBy() method ...");
+		if (isset($_REQUEST['order_by'])) 
+			$order_by = $_REQUEST['order_by'];
+		else
+			$order_by = (($_SESSION['ACCOUNTS_ORDER_BY'] != '')?($_SESSION['ACCOUNTS_ORDER_BY']):($this->default_order_by));
+		$log->debug("Exiting getOrderBy method ...");
+		return $order_by;
+	}	
+	// Mike Crowe Mod --------------------------------------------------------
+
+
+	/** Returns a list of the associated contacts
+	 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
+	 * All Rights Reserved..
+	 * Contributor(s): ______________________________________..
+	 */
+	function get_contacts($id)
+	{	
+		global $log;
+                $log->debug("Entering get_contacts(".$id.") method ...");
+		global $mod_strings;
+
+		$focus = new Contact();
+
+		$button = '';
+		if(isPermitted("Contacts",1,"") == 'yes')
+		{
+			$button .= '<input title="New Contact" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Contacts\'" type="submit" name="button" value="'.$mod_strings['LBL_NEW_CONTACT'].'">&nbsp;</td>';
+		}
+		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
+
+		//SQL
+		$query = "SELECT vtiger_contactdetails.*,
+			vtiger_crmentity.crmid,
+                        vtiger_crmentity.smownerid,
+			vtiger_users.user_name
+			FROM vtiger_contactdetails
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid
+			LEFT JOIN vtiger_contactgrouprelation
+				ON vtiger_contactdetails.contactid = vtiger_contactgrouprelation.contactid
+			LEFT JOIN vtiger_groups
+				ON vtiger_groups.groupname = vtiger_contactgrouprelation.groupname
+			LEFT JOIN vtiger_users
+				ON vtiger_crmentity.smownerid = vtiger_users.id
+			WHERE vtiger_crmentity.deleted = 0
+			AND vtiger_contactdetails.accountid = ".$id;
+		$log->debug("Exiting get_contacts method ...");
+		return GetRelatedList('Accounts','Contacts',$focus,$query,$button,$returnset);
+	}
+
+	/** Returns a list of the associated opportunities
+	 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
+	 * All Rights Reserved..
+	 * Contributor(s): ______________________________________..
+	 */
+	function get_opportunities($id)
+	{
+		global $log;
+                $log->debug("Entering get_opportunities(".$id.") method ...");
+		global $mod_strings;
+
+		$focus = new Potential();
+		$button = '';
+
+		if(isPermitted("Potentials",1,"") == 'yes')
+		{
+			$button .= '<input title="New Potential" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Potentials\'" type="submit" name="button" value="'.$mod_strings['LBL_NEW_POTENTIAL'].'">';
+		}
+		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
+
+		$query = "SELECT vtiger_potential.potentialid, vtiger_potential.accountid,
+			vtiger_potential.potentialname, vtiger_potential.sales_stage,
+			vtiger_potential.potentialtype, vtiger_potential.amount,
+			vtiger_potential.closingdate, vtiger_potential.potentialtype,
+			vtiger_users.user_name,
+			vtiger_crmentity.crmid, vtiger_crmentity.smownerid
+			FROM vtiger_potential
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_potential.potentialid
+			LEFT JOIN vtiger_users
+				ON vtiger_crmentity.smownerid = vtiger_users.id
+			LEFT JOIN vtiger_potentialgrouprelation
+				ON vtiger_potential.potentialid = vtiger_potentialgrouprelation.potentialid
+			LEFT JOIN vtiger_groups
+				ON vtiger_groups.groupname = vtiger_potentialgrouprelation.groupname
+			WHERE vtiger_crmentity.deleted = 0
+			AND vtiger_potential.accountid = ".$id;
+		$log->debug("Exiting get_opportunities method ...");
+
+		return GetRelatedList('Accounts','Potentials',$focus,$query,$button,$returnset);
+	}
+
+	/** Returns a list of the associated tasks
+	 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
+	 * All Rights Reserved..
+	 * Contributor(s): ______________________________________..
+	 */
+	function get_activities($id)
+	{
+		global $log;
+                $log->debug("Entering get_activities(".$id.") method ...");
+		global $mod_strings;
+
+		$focus = new Activity();
+		$button = '';
+		if(isPermitted("Calendar",1,"") == 'yes')
+		{
+
+			$button .= '<input title="New Task" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.return_action.value=\'DetailView\';this.form.module.value=\'Calendar\';this.form.return_module.value=\'Accounts\';this.form.activity_mode.value=\'Task\'" type="submit" name="button" value="'.$mod_strings['LBL_NEW_TASK'].'">&nbsp;';
+			$button .= '<input title="New Event" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.return_action.value=\'DetailView\';this.form.module.value=\'Calendar\';this.form.return_module.value=\'Accounts\';this.form.activity_mode.value=\'Events\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_EVENT'].'">&nbsp;</td>';
+		}
+		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
+
+		$query = "SELECT vtiger_activity.*,
+			vtiger_seactivityrel.*,
+			vtiger_crmentity.crmid, vtiger_crmentity.smownerid,
+			vtiger_crmentity.modifiedtime,
+			vtiger_users.user_name,
+			vtiger_recurringevents.recurringtype
+			FROM vtiger_activity
+			INNER JOIN vtiger_seactivityrel
+				ON vtiger_seactivityrel.activityid = vtiger_activity.activityid
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_activity.activityid
+			LEFT JOIN vtiger_users
+				ON vtiger_users.id = vtiger_crmentity.smownerid
+			LEFT OUTER JOIN vtiger_recurringevents
+				ON vtiger_recurringevents.activityid = vtiger_activity.activityid
+			LEFT JOIN vtiger_activitygrouprelation
+				ON vtiger_activitygrouprelation.activityid = vtiger_crmentity.crmid
+			LEFT JOIN vtiger_groups
+				ON vtiger_groups.groupname = vtiger_activitygrouprelation.groupname
+			WHERE vtiger_seactivityrel.crmid = ".$id."
+			AND (activitytype='Task'
+				OR activitytype='Call'
+				OR activitytype='Meeting')
+			AND vtiger_crmentity.deleted = 0
+			AND ((vtiger_activity.status IS NOT NULL
+					AND vtiger_activity.status != 'Completed')
+				AND (vtiger_activity.status IS NOT NULL
+					AND vtiger_activity.status != 'Deferred')
+				OR (vtiger_activity.eventstatus !=''
+					AND  vtiger_activity.eventstatus != 'Held'))";
+		$log->debug("Exiting get_activities method ...");
+		return GetRelatedList('Accounts','Calendar',$focus,$query,$button,$returnset);
+
+	}
+	/**
+	 * Function to get Account related Task & Event which have activity type Held, Completed or Deferred.
+ 	 * @param  integer   $id      - accountid
+ 	 * returns related Task or Event record in array format
+ 	 */
+	function get_history($id)
+	{
+		global $log;
+                $log->debug("Entering get_history(".$id.") method ...");
+		$query = "SELECT vtiger_activity.activityid, vtiger_activity.subject,
+			vtiger_activity.status, vtiger_activity.eventstatus,
+			vtiger_activity.activitytype,
+			vtiger_crmentity.modifiedtime, vtiger_crmentity.createdtime,
+			vtiger_crmentity.description,
+			vtiger_users.user_name
+			FROM vtiger_activity
+			INNER JOIN vtiger_seactivityrel
+				ON vtiger_seactivityrel.activityid = vtiger_activity.activityid
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_activity.activityid
+			LEFT JOIN vtiger_activitygrouprelation
+				ON vtiger_activitygrouprelation.activityid = vtiger_activity.activityid
+			LEFT JOIN vtiger_groups
+				ON vtiger_groups.groupname = vtiger_activitygrouprelation.groupname
+			INNER JOIN vtiger_users
+				ON vtiger_crmentity.smcreatorid = vtiger_users.id
+			WHERE (vtiger_activity.activitytype = 'Meeting'
+				OR vtiger_activity.activitytype = 'Call'
+				OR vtiger_activity.activitytype = 'Task')
+			AND (vtiger_activity.status = 'Completed'
+				OR vtiger_activity.status = 'Deferred'
+				OR (vtiger_activity.eventstatus = 'Held'
+					AND vtiger_activity.eventstatus != ''))
+			AND vtiger_seactivityrel.crmid = ".$id;
+		//Don't add order by, because, for security, one more condition will be added with this query in include/RelatedListView.php
+		$log->debug("Exiting get_history method ...");
+		return getHistory('Accounts',$query,$id);
+	}
+	/**
+	 * Function to get Account related Attachments
+ 	 * @param  integer   $id      - accountid
+ 	 * returns related Attachment record in array format
+ 	 */
+	function get_attachments($id)
+	{
+		 global $log;
+                 $log->debug("Entering get_attachments(".$id.") method ...");
+		// Armando Lüscher 18.10.2005 -> §visibleDescription
+		// Desc: Inserted crm2.createdtime, vtiger_notes.notecontent description, vtiger_users.user_name
+		// Inserted inner join vtiger_users on crm2.smcreatorid= vtiger_users.id
+		$query = "SELECT vtiger_notes.title, vtiger_notes.notecontent AS description,
+			vtiger_notes.filename, vtiger_notes.notesid AS crmid,
+				'Notes      ' AS ActivityType,
+			vtiger_attachments.type AS FileType,
+				crm2.modifiedtime AS lastmodified, crm2.createdtime,
+			vtiger_seattachmentsrel.attachmentsid,
+			vtiger_users.user_name
+			FROM vtiger_notes
+			INNER JOIN vtiger_senotesrel
+				ON vtiger_senotesrel.notesid = vtiger_notes.notesid
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_senotesrel.crmid
+			INNER JOIN vtiger_crmentity crm2
+				ON crm2.crmid = vtiger_notes.notesid
+				AND crm2.deleted = 0
+			LEFT JOIN vtiger_seattachmentsrel
+				ON vtiger_seattachmentsrel.crmid = vtiger_notes.notesid
+			LEFT JOIN vtiger_attachments
+				ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
+			INNER JOIN vtiger_users
+				ON crm2.smcreatorid = vtiger_users.id
+			WHERE vtiger_crmentity.crmid = ".$id."
+		 UNION ALL
+			SELECT vtiger_attachments.description AS title, vtiger_attachments.description,
+			vtiger_attachments.name AS filename,
+			vtiger_seattachmentsrel.attachmentsid AS crmid,
+				'Attachments' AS ActivityType,
+			vtiger_attachments.type AS FileType,
+				crm2.modifiedtime AS lastmodified, crm2.createdtime,
+			vtiger_attachments.attachmentsid,
+			vtiger_users.user_name
+			FROM vtiger_attachments
+			INNER JOIN vtiger_seattachmentsrel
+				ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_seattachmentsrel.crmid
+			INNER JOIN vtiger_crmentity crm2
+				ON crm2.crmid = vtiger_attachments.attachmentsid
+			INNER JOIN vtiger_users
+				ON crm2.smcreatorid = vtiger_users.id
+			WHERE vtiger_crmentity.crmid = ".$id."
+			ORDER BY createdtime DESC";
+		$log->debug("Exiting get_attachments method ...");
+		return getAttachmentsAndNotes('Accounts',$query,$id);
+	}
+	/**
+	* Function to get Account related Quotes
+	* @param  integer   $id      - accountid
+	* returns related Quotes record in array format
+	*/
+	function get_quotes($id)
+	{
+		global $log;
+                $log->debug("Entering get_quotes(".$id.") method ...");
+		global $app_strings;
+		require_once('modules/Quotes/Quote.php');
+
+		$focus = new Quote();
+
+		$button = '';
+		if(isPermitted("Quotes",1,"") == 'yes')
+		{
+			$button .= '<input title="'.$app_strings['LBL_NEW_QUOTE_BUTTON_TITLE'].'" accessyKey="'.$app_strings['LBL_NEW_QUOTE_BUTTON_KEY'].'" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Quotes\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_QUOTE_BUTTON'].'">&nbsp;</td>';
+		}
+		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
+
+		$query = "SELECT vtiger_users.user_name,
+			vtiger_groups.groupname,
+			vtiger_crmentity.*,
+			vtiger_quotes.*,
+			vtiger_potential.potentialname,
+			vtiger_account.accountname
+			FROM vtiger_quotes
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_quotes.quoteid
+			LEFT OUTER JOIN vtiger_account
+				ON vtiger_account.accountid = vtiger_quotes.accountid
+			LEFT OUTER JOIN vtiger_potential
+				ON vtiger_potential.potentialid = vtiger_quotes.potentialid
+			LEFT JOIN vtiger_quotegrouprelation
+				ON vtiger_quotes.quoteid = vtiger_quotegrouprelation.quoteid
+			LEFT JOIN vtiger_groups
+				ON vtiger_groups.groupname = vtiger_quotegrouprelation.groupname
+			LEFT JOIN vtiger_users
+				ON vtiger_crmentity.smownerid = vtiger_users.id
+			WHERE vtiger_crmentity.deleted = 0
+			AND vtiger_account.accountid = ".$id;
+		$log->debug("Exiting get_quotes method ...");
+		return GetRelatedList('Accounts','Quotes',$focus,$query,$button,$returnset);
+	}
+	/**
+	* Function to get Account related Invoices 
+	* @param  integer   $id      - accountid
+	* returns related Invoices record in array format
+	*/
+	function get_invoices($id)
+	{
+		global $log;
+                $log->debug("Entering get_invoices(".$id.") method ...");
+		global $app_strings;
+		require_once('modules/Invoice/Invoice.php');
+
+		$focus = new Invoice();
+
+		$button = '';
+		if(isPermitted("Invoice",1,"") == 'yes')
+		{
+			$button .= '<input title="'.$app_strings['LBL_NEW_INVOICE_BUTTON_TITLE'].'" accessyKey="'.$app_strings['LBL_NEW_INVOICE_BUTTON_KEY'].'" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Invoice\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_INVOICE_BUTTON'].'">&nbsp;</td>';
+		}
+		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
+
+		$query = "SELECT vtiger_users.user_name,
+			vtiger_groups.groupname,
+			vtiger_crmentity.*,
+			vtiger_invoice.*,
+			vtiger_account.accountname,
+			vtiger_salesorder.subject AS salessubject
+			FROM vtiger_invoice
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_invoice.invoiceid
+			LEFT OUTER JOIN vtiger_account
+				ON vtiger_account.accountid = vtiger_invoice.accountid
+			LEFT OUTER JOIN vtiger_salesorder
+				ON vtiger_salesorder.salesorderid = vtiger_invoice.salesorderid
+			LEFT JOIN vtiger_invoicegrouprelation
+				ON vtiger_invoice.invoiceid = vtiger_invoicegrouprelation.invoiceid
+			LEFT JOIN vtiger_groups
+				ON vtiger_groups.groupname = vtiger_invoicegrouprelation.groupname
+			LEFT JOIN vtiger_users
+				ON vtiger_crmentity.smownerid = vtiger_users.id
+			WHERE vtiger_crmentity.deleted = 0
+			AND vtiger_account.accountid = ".$id;
+		$log->debug("Exiting get_invoices method ...");
+		return GetRelatedList('Accounts','Invoice',$focus,$query,$button,$returnset);
+	}
+
+	/**
+	* Function to get Account related SalesOrder 
+	* @param  integer   $id      - accountid
+	* returns related SalesOrder record in array format
+	*/
+	function get_salesorder($id)
+	{
+		global $log;
+                $log->debug("Entering get_salesorder(".$id.") method ...");
+		require_once('modules/SalesOrder/SalesOrder.php');
+		global $app_strings;
+
+		$focus = new SalesOrder();
+
+		$button = '';
+		if(isPermitted("SalesOrder",1,"") == 'yes')
+		{
+			$button .= '<input title="'.$app_strings['LBL_NEW_SORDER_BUTTON_TITLE'].'" accessyKey="'.$app_strings['LBL_NEW_SORDER_BUTTON_KEY'].'" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'SalesOrder\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_SORDER_BUTTON'].'">&nbsp;</td>';
+		}
+
+		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
+
+		$query = "SELECT vtiger_crmentity.*,
+			vtiger_salesorder.*,
+			vtiger_quotes.subject AS quotename,
+			vtiger_account.accountname,
+			vtiger_users.user_name,
+			vtiger_groups.groupname
+			FROM vtiger_salesorder
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_salesorder.salesorderid
+			LEFT OUTER JOIN vtiger_quotes
+				ON vtiger_quotes.quoteid = vtiger_salesorder.quoteid
+			LEFT OUTER JOIN vtiger_account
+				ON vtiger_account.accountid = vtiger_salesorder.accountid
+			LEFT JOIN vtiger_sogrouprelation
+				ON vtiger_salesorder.salesorderid = vtiger_sogrouprelation.salesorderid
+			LEFT JOIN vtiger_groups
+				ON vtiger_groups.groupname = vtiger_sogrouprelation.groupname
+			LEFT JOIN vtiger_users
+				ON vtiger_crmentity.smownerid = vtiger_users.id
+			WHERE vtiger_crmentity.deleted = 0
+			AND vtiger_salesorder.accountid = ".$id;
+		$log->debug("Exiting get_salesorder method ...");		
+		return GetRelatedList('Accounts','SalesOrder',$focus,$query,$button,$returnset);
+	}
+	/**
+	* Function to get Account related Tickets
+	* @param  integer   $id      - accountid
+	* returns related Ticket record in array format
+	*/
+	function get_tickets($id)
+	{
+		global $log;
+                $log->debug("Entering get_tickets(".$id.") method ...");
+		global $app_strings;
+
+		$focus = new HelpDesk();
+		$button = '';
+
+		$button .= '<td valign="bottom" align="right"><input title="New TICKET" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'HelpDesk\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_TICKET'].'">&nbsp;</td>';
+		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
+
+		$query = "SELECT vtiger_users.user_name, vtiger_users.id,
+			vtiger_troubletickets.title, vtiger_troubletickets.ticketid AS crmid,
+			vtiger_troubletickets.status, vtiger_troubletickets.priority,
+			vtiger_troubletickets.parent_id,
+			vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime
+			FROM vtiger_troubletickets
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid
+			LEFT JOIN vtiger_account
+				ON vtiger_account.accountid = vtiger_troubletickets.parent_id
+			LEFT JOIN vtiger_contactdetails
+			        ON vtiger_contactdetails.contactid=vtiger_troubletickets.parent_id
+			LEFT JOIN vtiger_users
+				ON vtiger_users.id=vtiger_crmentity.smownerid
+			LEFT JOIN vtiger_ticketgrouprelation
+				ON vtiger_troubletickets.ticketid = vtiger_ticketgrouprelation.ticketid
+			LEFT JOIN vtiger_groups
+				ON vtiger_groups.groupname = vtiger_ticketgrouprelation.groupname
+			WHERE  vtiger_troubletickets.parent_id=".$id." or " ;
+
+		$query .= "vtiger_troubletickets.parent_id in(SELECT vtiger_contactdetails.contactid
+			FROM vtiger_contactdetails
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid
+			LEFT JOIN vtiger_contactgrouprelation
+				ON vtiger_contactdetails.contactid = vtiger_contactgrouprelation.contactid
+			LEFT JOIN vtiger_groups
+				ON vtiger_groups.groupname = vtiger_contactgrouprelation.groupname
+			LEFT JOIN vtiger_users
+				ON vtiger_crmentity.smownerid = vtiger_users.id
+			WHERE vtiger_crmentity.deleted = 0
+			AND vtiger_contactdetails.accountid = ".$id;
+
+			
+		//Appending the security parameter
+		global $current_user;
+		require('user_privileges/user_privileges_'.$current_user->id.'.php');
+		require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
+		$tab_id=getTabid('Contacts');
+		if($is_admin==false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $defaultOrgSharingPermission[$tab_id] == 3)
+		{
+			$sec_parameter=getListViewSecurityParameter('Contacts');
+			$query .= ' '.$sec_parameter;
+
+		}
+
+		$query .= ") ";
+		
+		/*
+		$query .= " UNION ALL
+			SELECT vtiger_users.user_name, vtiger_users.id,
+			vtiger_troubletickets.title, vtiger_troubletickets.ticketid AS crmid,
+			vtiger_troubletickets.status, vtiger_troubletickets.priority,
+			vtiger_troubletickets.parent_id,
+			vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime
+			FROM vtiger_troubletickets
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid
+			LEFT JOIN vtiger_contactdetails
+				ON vtiger_contactdetails.contactid = vtiger_troubletickets.parent_id
+			LEFT JOIN vtiger_account
+				ON vtiger_account.accountid = vtiger_contactdetails.accountid
+			LEFT JOIN vtiger_users
+				ON vtiger_users.id = vtiger_crmentity.smownerid
+			LEFT JOIN vtiger_ticketgrouprelation
+				ON vtiger_troubletickets.ticketid = vtiger_ticketgrouprelation.ticketid
+			LEFT JOIN vtiger_groups
+				ON vtiger_groups.groupname = vtiger_ticketgrouprelation.groupname
+			WHERE vtiger_account.accountid = ".$id;
+		*/	
+		$log->debug("Exiting get_tickets method ...");
+		return GetRelatedList('Accounts','HelpDesk',$focus,$query,$button,$returnset);
+	}
+	/**
+	* Function to get Account related Products 
+	* @param  integer   $id      - accountid
+	* returns related Products record in array format
+	*/
+	function get_products($id)
+	{
+		global $log;
+                $log->debug("Entering get_products(".$id.") method ...");
+		require_once('modules/Products/Product.php');
+		global $app_strings;
+
+		$focus = new Product();
+
+		$button = '';
+
+		if(isPermitted("Products",1,"") == 'yes')
+		{
+
+
+			$button .= '<input title="New Product" accessyKey="F" class="button" onclick="this.form.action.value=\'EditView\';this.form.module.value=\'Products\';this.form.return_module.value=\'Accounts\';this.form.return_action.value=\'DetailView\'" type="submit" name="button" value="'.$app_strings['LBL_NEW_PRODUCT'].'">&nbsp;';
+		}
+		$returnset = '&return_module=Accounts&return_action=CallRelatedList&return_id='.$id;
+
+		$query = "SELECT vtiger_products.productid, vtiger_products.productname,
+			vtiger_products.productcode, vtiger_products.commissionrate,
+			vtiger_products.qty_per_unit, vtiger_products.unit_price,
+			vtiger_crmentity.crmid, vtiger_crmentity.smownerid
+			FROM vtiger_products
+			INNER JOIN vtiger_seproductsrel
+				ON vtiger_products.productid = vtiger_seproductsrel.productid
+			INNER JOIN vtiger_crmentity
+				ON vtiger_crmentity.crmid = vtiger_products.productid
+			INNER JOIN vtiger_account
+				ON vtiger_account.accountid = vtiger_seproductsrel.crmid
+			WHERE vtiger_account.accountid = ".$id."
+			AND vtiger_crmentity.deleted = 0";
+		$log->debug("Exiting get_products method ...");
+		return GetRelatedList('Accounts','Products',$focus,$query,$button,$returnset);
+	}
+
+	/** Function to export the account records in CSV Format
+	* @param reference variable - order by is passed when the query is executed
+	* @param reference variable - where condition is passed when the query is executed
+	* Returns Export Accounts Query.
+	*/
+	function create_export_query(&$order_by, &$where)
+	{
+		global $log;
+                $log->debug("Entering create_export_query(".$order_by.",".$where.") method ...");
+		if($this->checkIfCustomTableExists('vtiger_accountscf'))
+		{
+
+			$query = $this->constructCustomQueryAddendum('vtiger_accountscf','Accounts') . "
+				vtiger_account.*,
+					".$this->entity_table.".*,
+				vtiger_accountbillads.city AS billing_city,
+				vtiger_accountbillads.country AS billing_country,
+				vtiger_accountbillads.code AS billing_code,
+				vtiger_accountbillads.state AS billing_state,
+				vtiger_accountbillads.street AS billing_street,
+				vtiger_accountshipads.city AS shipping_city,
+				vtiger_accountshipads.country AS shipping_country,
+				vtiger_accountshipads.code AS shipping_code,
+				vtiger_accountshipads.state AS shipping_state,
+				vtiger_accountshipads.street AS shipping_street,
+				vtiger_users.user_name,
+				vtiger_users.status AS user_status
+				FROM ".$this->entity_table."
+				INNER JOIN vtiger_account
+					ON vtiger_crmentity.crmid = vtiger_account.accountid
+				LEFT JOIN vtiger_accountbillads
+					ON vtiger_account.accountid = vtiger_accountbillads.accountaddressid
+				LEFT JOIN vtiger_accountshipads
+					ON vtiger_account.accountid = vtiger_accountshipads.accountaddressid
+				LEFT JOIN vtiger_accountscf 
+					ON vtiger_accountscf.accountid = vtiger_account.accountid
+				LEFT JOIN vtiger_users
+					ON vtiger_crmentity.smownerid = vtiger_users.id ";
+
+		}
+		else
+		{
+			$query = "SELECT vtiger_account.*,
+					".$this->entity_table.".*,
+				vtiger_accountbillads.city AS billing_city,
+				vtiger_accountbillads.country AS billing_country,
+				vtiger_accountbillads.code AS billing_code,
+				vtiger_accountbillads.state AS billing_state,
+				vtiger_accountbillads.street AS billing_street,
+				vtiger_accountshipads.city AS shipping_city,
+				vtiger_accountshipads.country AS shipping_country,
+				vtiger_accountshipads.code AS shipping_code,
+				vtiger_accountshipads.state AS shipping_state,
+				vtiger_accountshipads.street AS shipping_street,
+				vtiger_users.user_name,
+				vtiger_users.status AS user_status
+				FROM ".$this->entity_table."
+				INNER JOIN vtiger_account
+					ON vtiger_crmentity.crmid = vtiger_account.accountid
+				LEFT JOIN vtiger_accountbillads
+					ON vtiger_account.accountid = vtiger_accountbillads.accountaddressid
+				LEFT JOIN vtiger_accountshipads
+					ON vtiger_account.accountid = vtiger_accountshipads.accountaddressid
+				LEFT JOIN vtiger_users
+					ON vtiger_crmentity.smownerid = vtiger_users.id ";
+		}
+
+		$where_auto = " vtiger_users.status = 'Active'
+			AND vtiger_crmentity.deleted = 0 ";
+
+		if($where != "")
+			$query .= "WHERE ($where) AND ".$where_auto;
+		else
+			$query .= "WHERE ".$where_auto;
+
+		if(!empty($order_by))
+			$query .= " ORDER BY $order_by";
+		$log->debug("Exiting create_export_query method ...");
+		return $query;
+	}
+
+	/** Function to get the Columnnames of the Account Record
+	* Used By vtigerCRM Word Plugin
+	* Returns the Merge Fields for Word Plugin
+	*/
+	function getColumnNames_Acnt()
+	{
+		global $log,$current_user;
+    $log->debug("Entering getColumnNames_Acnt() method ...");
+    require('user_privileges/user_privileges_'.$current_user->id.'.php');
+	  if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0)
+	  {
+		  $sql1 = "SELECT fieldlabel FROM vtiger_field WHERE tabid = 6";
+		}else
+		{
+		  $profileList = getCurrentUserProfileList();
+		  $sql1 = "select fieldlabel from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=6 and vtiger_field.displaytype in (1,2,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_profile2field.profileid in ".$profileList;
+		} 
+		$result = $this->db->query($sql1);
+		$numRows = $this->db->num_rows($result);
+		for($i=0; $i < $numRows;$i++)
+		{
+			$custom_fields[$i] = $this->db->query_result($result,$i,"fieldlabel");
+			$custom_fields[$i] = ereg_replace(" ","",$custom_fields[$i]);
+			$custom_fields[$i] = strtoupper($custom_fields[$i]);
+		}
+		$mergeflds = $custom_fields;
+		$log->debug("Exiting getColumnNames_Acnt method ...");
+		return $mergeflds;
+	}
+
+}
+
+?>

Modified: vtigercrm/trunk/modules/Contacts/Contact.php
==============================================================================
--- vtigercrm/trunk/modules/Contacts/Contact.php (original)
+++ vtigercrm/trunk/modules/Contacts/Contact.php Wed Aug 23 08:00:50 2006
@@ -604,9 +604,17 @@
 */
 function getColumnNames()
 {
-	global $log;
+	global $log,$current_user;
 	$log->debug("Entering getColumnNames() method ...");
-	$sql1 = "select fieldlabel from vtiger_field where tabid=4 and block <> 6 and block <> 75";
+	require('user_privileges/user_privileges_'.$current_user->id.'.php');
+	if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0)
+	{
+	 $sql1 = "select fieldlabel from vtiger_field where tabid=4 and block <> 75";
+	}else
+	{
+	 $profileList = getCurrentUserProfileList();
+	 $sql1 = "select fieldlabel from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=4 and vtiger_field.block <> 6 and vtiger_field.block <> 75 and vtiger_field.displaytype in (1,2,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_profile2field.profileid in ".$profileList;
+  }
 	$result = $this->db->query($sql1);
 	$numRows = $this->db->num_rows($result);
 	for($i=0; $i < $numRows;$i++)

Modified: vtigercrm/trunk/modules/HelpDesk/HelpDesk.php
==============================================================================
--- vtigercrm/trunk/modules/HelpDesk/HelpDesk.php (original)
+++ vtigercrm/trunk/modules/HelpDesk/HelpDesk.php Wed Aug 23 08:00:50 2006
@@ -1,462 +1,470 @@
-<?php
-/*********************************************************************************
- * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
- * ("License"); You may not use this file except in compliance with the
- * License. You may obtain a copy of txhe License at http://www.sugarcrm.com/SPL
- * Software distributed under the License is distributed on an  "AS IS"  basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
- * the specific language governing rights and limitations under the License.
- * The Original Code is:  SugarCRM Open Source
- * The Initial Developer of the Original Code is SugarCRM, Inc.
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
- * All Rights Reserved.
- * Contributor(s): ______________________________________.
- ********************************************************************************/
-include_once('config.php');
-require_once('include/logging.php');
-require_once('include/database/PearDatabase.php');
-require_once('data/SugarBean.php');
-require_once('data/CRMEntity.php');
-require_once('include/utils/utils.php');
-
-
-class HelpDesk extends CRMEntity {
-	var $log;
-	var $db;
-
-	var $tab_name = Array('vtiger_crmentity','vtiger_troubletickets','vtiger_seticketsrel','vtiger_ticketcf','vtiger_ticketcomments','vtiger_attachments');
-	var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_troubletickets'=>'ticketid','vtiger_seticketsrel'=>'ticketid','vtiger_ticketcf'=>'ticketid','vtiger_ticketcomments'=>'ticketid','vtiger_attachments'=>'attachmentsid');
-	var $column_fields = Array();
-
-	var $sortby_fields = Array('title','status','priority','crmid','firstname','smownerid');
-
-	var $list_fields = Array(
-					'Ticket ID'=>Array('crmentity'=>'crmid'),
-					'Subject'=>Array('troubletickets'=>'title'),	  			
-					'Related to'=>Array('troubletickets'=>'parent_id'),	  			
-					'Status'=>Array('troubletickets'=>'status'),
-					'Priority'=>Array('troubletickets'=>'priority'),
-					'Assigned To'=>Array('crmentity','smownerid')
-				);
-
-	var $list_fields_name = Array(
-					'Ticket ID'=>'',
-					'Subject'=>'ticket_title',	  			
-					'Related to'=>'parent_id',	  			
-					'Status'=>'ticketstatus',
-					'Priority'=>'ticketpriorities',
-					'Assigned To'=>'assigned_user_id'
-				     );
-
-	var $list_link_field= 'ticket_title';
-			
-	var $range_fields = Array(
-				        'ticketid',
-					'title',
-			        	'firstname',
-				        'lastname',
-			        	'parent_id',
-			        	'productid',
-			        	'productname',
-			        	'priority',
-			        	'severity',
-				        'status',
-			        	'category',
-					'description',
-					'solution',
-					'modifiedtime',
-					'createdtime'
-				);
-
-	//Added these variables which are used as default order by and sortorder in ListView
-	var $default_order_by = 'crmid';
-	var $default_sort_order = 'DESC';
-
-	/**	Constructor which will set the column_fields in this object
-	 */
-	function HelpDesk() 
-	{
-		$this->log =LoggerManager::getLogger('helpdesk');
-		$this->log->debug("Entering HelpDesk() method ...");
-		$this->db = new PearDatabase();
-		$this->column_fields = getColumnFields('HelpDesk');
-		$this->log->debug("Exiting HelpDesk method ...");
-	}
-
-	/**	Function used to get the sort order for HelpDesk listview
-	 *	@return string	$sorder	- first check the $_REQUEST['sorder'] if request value is empty then check in the $_SESSION['HELPDESK_SORT_ORDER'] if this session value is empty then default sort order will be returned. 
-	 */
-	function getSortOrder()
-	{
-		global $log;
-                $log->debug("Entering getSortOrder() method ...");	
-		if(isset($_REQUEST['sorder'])) 
-			$sorder = $_REQUEST['sorder'];
-		else
-			$sorder = (($_SESSION['HELPDESK_SORT_ORDER'] != '')?($_SESSION['HELPDESK_SORT_ORDER']):($this->default_sort_order));
-		$log->debug("Exiting getSortOrder() method ...");
-		return $sorder;
-	}
-
-	/**	Function used to get the order by value for HelpDesk listview
-	 *	@return string	$order_by  - first check the $_REQUEST['order_by'] if request value is empty then check in the $_SESSION['HELPDESK_ORDER_BY'] if this session value is empty then default order by will be returned. 
-	 */
-	function getOrderBy()
-	{
-		global $log;
-                $log->debug("Entering getOrderBy() method ...");
-		if (isset($_REQUEST['order_by'])) 
-			$order_by = $_REQUEST['order_by'];
-		else
-			$order_by = (($_SESSION['HELPDESK_ORDER_BY'] != '')?($_SESSION['HELPDESK_ORDER_BY']):($this->default_order_by));
-		$log->debug("Exiting getOrderBy method ...");
-		return $order_by;
-	}	
-
-	/**     Function to form the query to get the list of activities
-         *      @param  int $id - ticket id
-	 *	@return array - return an array which will be returned from the function GetRelatedList
-        **/
-	function get_activities($id)
-	{
-		global $log;
-		$log->debug("Entering get_activities(".$id.") method ...");
-		global $mod_strings;
-		global $app_strings;
-		require_once('modules/Calendar/Activity.php');
-		$focus = new Activity();
-
-		$button = '';
-
-		$returnset = '&return_module=HelpDesk&return_action=CallRelatedList&return_id='.$id;
-
-		$query = "SELECT vtiger_activity.*, vtiger_crmentity.crmid, vtiger_recurringevents.recurringtype, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime, vtiger_users.user_name from vtiger_activity inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid=vtiger_activity.activityid inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid left outer join vtiger_recurringevents on vtiger_recurringevents.activityid=vtiger_activity.activityid left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid left join vtiger_activitygrouprelation on vtiger_activitygrouprelation.activityid=vtiger_crmentity.crmid left join vtiger_groups on vtiger_groups.groupname=vtiger_activitygrouprelation.groupname where vtiger_seactivityrel.crmid=".$id." and (activitytype='Task' or activitytype='Call' or activitytype='Meeting') AND ( vtiger_activity.status is NULL OR vtiger_activity.status != 'Completed' ) and ( vtiger_activity.eventstatus is NULL OR vtiger_activity.eventstatus != 'Held')";
-		$log->debug("Exiting get_activities method ...");
-		
-		return GetRelatedList('HelpDesk','Calendar',$focus,$query,$button,$returnset);
-	}
-
-	/**     Function to get the Ticket History information as in array format
-	 *	@param int $ticketid - ticket id
-	 *	@return array - return an array with title and the ticket history informations in the following format
-							array(	
-								header=>array('0'=>'title'),
-								entries=>array('0'=>'info1','1'=>'info2',etc.,)
-							     )
-	 */
-	function get_ticket_history($ticketid)
-	{
-		global $log, $adb;
-		$log->debug("Entering into get_ticket_history($ticketid) method ...");
-
-		$query="select title,update_log from vtiger_troubletickets where ticketid=".$ticketid;
-		$result=$adb->query($query);
-		$update_log = $adb->query_result($result,0,"update_log");
-
-		$splitval = split('--//--',trim($update_log,'--//--'));
-
-		$header[] = $adb->query_result($result,0,"title");
-
-		$return_value = Array('header'=>$header,'entries'=>$splitval);
-
-		$log->debug("Exiting from get_ticket_history($ticketid) method ...");
-
-		return $return_value;
-	}
-
-	/**	Function to form the query to get the list of attachments and notes
-	 *	@param  int $id - ticket id
-         *      @return array - return an array which will be returned from the function getAttachmentsAndNotes
-	**/
-	function get_attachments($id)
-	{
-		global $log;
-		$log->debug("Entering get_attachments(".$id.") method ...");
-		$query = "select vtiger_notes.title,'Notes      '  ActivityType, vtiger_notes.filename,
-		vtiger_attachments.type  FileType,crm2.modifiedtime lastmodified,
-		vtiger_seattachmentsrel.attachmentsid attachmentsid, vtiger_notes.notesid crmid,
-			crm2.createdtime, vtiger_notes.notecontent description, vtiger_users.user_name
-		from vtiger_notes
-			inner join vtiger_senotesrel on vtiger_senotesrel.notesid= vtiger_notes.notesid
-			inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_senotesrel.crmid
-			inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_notes.notesid and crm2.deleted=0
-			left join vtiger_seattachmentsrel  on vtiger_seattachmentsrel.crmid =vtiger_notes.notesid
-			left join vtiger_attachments on vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
-			inner join vtiger_users on crm2.smcreatorid= vtiger_users.id
-		where vtiger_crmentity.crmid=".$id;
-
-		$query .= ' union all ';
-
-		$query .= "select vtiger_attachments.description title ,'Attachments'  ActivityType,
-		vtiger_attachments.name filename, vtiger_attachments.type FileType,crm2.modifiedtime lastmodified,
-		vtiger_attachments.attachmentsid attachmentsid, vtiger_seattachmentsrel.attachmentsid crmid,
-			crm2.createdtime, vtiger_attachments.description, vtiger_users.user_name
-		from vtiger_attachments
-			inner join vtiger_seattachmentsrel on vtiger_seattachmentsrel.attachmentsid= vtiger_attachments.attachmentsid
-			inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_seattachmentsrel.crmid
-			inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_attachments.attachmentsid
-			left join vtiger_users on crm2.smcreatorid= vtiger_users.id
-		where vtiger_crmentity.crmid=".$id;	
-		$log->debug("Exiting get_attachments method ...");
-		return getAttachmentsAndNotes('HelpDesk',$query,$id);
-	}
-
-	/**	Function to get the ticket comments as a array
-	 *	@param  int   $ticketid - ticketid
-	 *	@return array $output - array(	
-						[$i][comments]    => comments
-						[$i][owner]       => name of the user or customer who made the comment
-						[$i][createdtime] => the comment created time
-					     ) 
-				where $i = 0,1,..n which are all made for the ticket
-	**/
-	function get_ticket_comments_list($ticketid)
-	{
-		global $log;
-		$log->debug("Entering get_ticket_comments_list(".$ticketid.") method ...");
-		 $sql = "select * from vtiger_ticketcomments where ticketid=".$ticketid." order by createdtime DESC";
-		 $result = $this->db->query($sql);
-		 $noofrows = $this->db->num_rows($result);
-		 for($i=0;$i<$noofrows;$i++)
-		 {
-			 $ownerid = $this->db->query_result($result,$i,"ownerid");
-			 $ownertype = $this->db->query_result($result,$i,"ownertype");
-			 if($ownertype == 'user')
-				 $name = getUserName($ownerid);
-			 elseif($ownertype == 'customer')
-			 {
-				 $sql1 = 'select * from vtiger_portalinfo where id='.$ownerid;
-				 $name = $this->db->query_result($this->db->query($sql1),0,'user_name');
-			 }
-
-			 $output[$i]['comments'] = nl2br($this->db->query_result($result,$i,"comments"));
-			 $output[$i]['owner'] = $name;
-			 $output[$i]['createdtime'] = $this->db->query_result($result,$i,"createdtime");
-		 }
-		$log->debug("Exiting get_ticket_comments_list method ...");
-		 return $output;
-	 }
-		
-	/**	Function to form the query which will give the list of tickets based on customername and id ie., contactname and contactid
-	 *	@param  string $user_name - name of the customer ie., contact name
-	 *	@param  int    $id	 - contact id 
-	 * 	@return array  - return an array which will be returned from the function process_list_query
-	**/
-	function get_user_tickets_list($user_name,$id,$where='',$match='')
-	{
-		global $log;
-		$log->debug("Entering get_user_tickets_list(".$user_name.",".$id.",".$where.",".$match.") method ...");
-
-		$this->db->println("where ==> ".$where);
-
-		$query = "select vtiger_crmentity.crmid, vtiger_troubletickets.*, vtiger_crmentity.smownerid, vtiger_crmentity.createdtime, vtiger_crmentity.modifiedtime, vtiger_contactdetails.firstname, vtiger_contactdetails.lastname, vtiger_products.productid, vtiger_products.productname, vtiger_ticketcf.* from vtiger_troubletickets inner join vtiger_ticketcf on vtiger_ticketcf.ticketid = vtiger_troubletickets.ticketid inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_troubletickets.ticketid left join vtiger_contactdetails on vtiger_troubletickets.parent_id=vtiger_contactdetails.contactid left join vtiger_products on vtiger_products.productid = vtiger_troubletickets.product_id left join vtiger_users on vtiger_crmentity.smownerid=vtiger_users.id  where vtiger_crmentity.deleted=0 and vtiger_contactdetails.email='".$user_name."' and vtiger_troubletickets.parent_id = '".$id."'";
-
-		if(trim($where) != '')
-		{
-			if($match == 'all' || $match == '')
-			{
-				$join = " and ";
-			}
-			elseif($match == 'any')
-			{
-				$join = " or ";
-			}
-			$where = explode("&&&",$where);
-			$count = count($where);
-			$count --;
-			$where_conditions = "";
-			foreach($where as $key => $value)
-			{
-				$this->db->println('key : '.$key.'...........value : '.$value);
-				$val = explode(" = ",$value);
-				$this->db->println('val0 : '.$val[0].'...........val1 : '.$val[1]);
-				if($val[0] == 'vtiger_troubletickets.title')
-				{
-					$where_conditions .= $val[0]."  ".$val[1];
-					if($count != $key) 	$where_conditions .= $join;
-				}
-				elseif($val[1] != '' && $val[1] != 'Any')
-				{
-					$where_conditions .= $val[0]." = ".$val[1];
-					if($count != $key)	$where_conditions .= $join;
-				}
-			}
-			if($where_conditions != '')
-				$where_conditions = " and ( ".$where_conditions." ) ";
-
-			$query .= $where_conditions;
-			$this->db->println("where condition for customer portal tickets search : ".$where_conditions);
-		}
-
-		$query .= " order by vtiger_crmentity.crmid desc";
-		$log->debug("Exiting get_user_tickets_list method ...");
-		return $this->process_list_query($query);
-	}
-
-	/**	Function to process the list query and return the result with number of rows
-	 *	@param  string $query - query 
-	 *	@return array  $response - array(	list           => array(   
-											$i => array(key => val)   
-									       ),
-							row_count      => '',
-							next_offset    => '',
-							previous_offset	=>''		 
-						)
-		where $i=0,1,..n & key = ticketid, title, firstname, ..etc(range_fields) & val = value of the key from db retrieved row 
-	**/
-	function process_list_query($query)
-	{
-		global $log;
-		$log->debug("Entering process_list_query(".$query.") method ...");
-	  
-   		$result =& $this->db->query($query,true,"Error retrieving $this->object_name list: ");
-		$list = Array();
-	        $rows_found =  $this->db->getRowCount($result);
-        	if($rows_found != 0)
-	        {
-			$ticket = Array();
-			for($index = 0 , $row = $this->db->fetchByAssoc($result, $index); $row && $index <$rows_found;$index++, $row = $this->db->fetchByAssoc($result, $index))
-			{
-		                foreach($this->range_fields as $columnName)
-                		{
-		                	if (isset($row[$columnName])) 
-					{
-			                	$ticket[$columnName] = $row[$columnName];
-                    			}
-		                       	else     
-				        {   
-		                        	$ticket[$columnName] = "";
-			                }   
-	     			}	
-    		                $list[] = $ticket;
-                	}
-        	}   
-
-		$response = Array();
-	        $response['list'] = $list;
-        	$response['row_count'] = $rows_found;
-	        $response['next_offset'] = $next_offset;
-        	$response['previous_offset'] = $previous_offset;
-
-		$log->debug("Exiting process_list_query method ...");
-	        return $response;
-	}
-
-	/**	Function to get the HelpDesk field labels in caps letters without space
-	 *	@return array $mergeflds - array(	key => val	)    where   key=0,1,2..n & val = ASSIGNEDTO,RELATEDTO, .,etc
-	**/
-	function getColumnNames_Hd()
-	{
-		global $log;
-		$log->debug("Entering getColumnNames_Hd() method ...");
-		$sql1 = "select fieldlabel from vtiger_field where tabid=13 and block <> 6 ";
-		$result = $this->db->query($sql1);
-		$numRows = $this->db->num_rows($result);
-		for($i=0; $i < $numRows;$i++)
-		{
-			$custom_fields[$i] = $this->db->query_result($result,$i,"fieldlabel");
-			$custom_fields[$i] = ereg_replace(" ","",$custom_fields[$i]);
-			$custom_fields[$i] = strtoupper($custom_fields[$i]);
-		}
-		$mergeflds = $custom_fields;
-		$log->debug("Exiting getColumnNames_Hd method ...");
-		return $mergeflds;
-	}
-
-	/**     Function to get the list of comments for the given ticket id
-	 *      @param  int  $ticketid - Ticket id
-	 *      @return list $list - return the list of comments and comment informations as a html output where as these comments and comments informations will be formed in div tag.
-	**/
-	function getCommentInformation($ticketid)
-	{
-		global $log;
-		$log->debug("Entering getCommentInformation(".$ticketid.") method ...");
-		global $adb;
-		global $mod_strings;
-		$sql = "select * from vtiger_ticketcomments where ticketid=".$ticketid;
-		$result = $adb->query($sql);
-		$noofrows = $adb->num_rows($result);
-
-		if($noofrows == 0)
-		{
-			$log->debug("Exiting getCommentInformation method ...");
-			return '';
-		}
-
-		$list .= '<div style="overflow: auto;height:200px;width:100%;">';
-		for($i=0;$i<$noofrows;$i++)
-		{
-			if($adb->query_result($result,$i,'comments') != '')
-			{
-				//this div is to display the comment
-				$list .= '<div valign="top" style="width:99%;padding-top:10px;" class="dataField">';
-				$list .= make_clickable(nl2br($adb->query_result($result,$i,'comments')));
-
-				$list .= '</div>';
-
-				//this div is to display the author and time
-				$list .= '<div valign="top" style="width:99%;border-bottom:1px dotted #CCCCCC;padding-bottom:5px;" class="dataLabel"><font color=darkred>';
-				$list .= $mod_strings['LBL_AUTHOR'].' : ';
-
-				if($adb->query_result($result,$i,'ownertype') == 'user')
-					$list .= getUserName($adb->query_result($result,$i,'ownerid'));
-				else
-					$list .= $this->getCustomerName($ticketid);
-
-				$list .= ' on '.$adb->query_result($result,$i,'createdtime').' &nbsp;';
-
-				$list .= '</font></div>';
-			}
-		}
-		$list .= '</div>';
-
-		$log->debug("Exiting getCommentInformation method ...");
-		return $list;
-	}
-
-	/**     Function to get the Customer Name who has made comment to the ticket from the customer portal
-	 *      @param  int    $id   - Ticket id
-	 *      @return string $customername - The contact name
-	**/
-	function getCustomerName($id)
-	{
-		global $log;
-		$log->debug("Entering getCustomerName(".$id.") method ...");
-        	global $adb;
-	        $sql = "select * from vtiger_portalinfo inner join vtiger_troubletickets on vtiger_troubletickets.parent_id = vtiger_portalinfo.id where vtiger_troubletickets.ticketid=".$id;
-        	$result = $adb->query($sql);
-	        $customername = $adb->query_result($result,0,'user_name');
-		$log->debug("Exiting getCustomerName method ...");
-        	return $customername;
-	}
-	
-	/**	Function used to get the Activity History
-	 *	@param	int	$id - ticket id to which we want to display the activity history
-	 *	@return  array	- return an array which will be returned from the function getHistory
-	 */
-	function get_history($id)
-	{
-		global $log;
-		$log->debug("Entering get_history(".$id.") method ...");
-		$query = "SELECT vtiger_activity.activityid, vtiger_activity.subject, vtiger_activity.status, vtiger_activity.eventstatus,
-		vtiger_activity.activitytype, vtiger_troubletickets.ticketid, vtiger_troubletickets.title, vtiger_crmentity.modifiedtime,
-		vtiger_crmentity.createdtime, vtiger_crmentity.description, vtiger_users.user_name
-				from vtiger_activity
-				inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid= vtiger_activity.activityid
-				inner join vtiger_troubletickets on vtiger_troubletickets.ticketid = vtiger_seactivityrel.crmid
-				inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid
-				left join vtiger_activitygrouprelation on vtiger_activitygrouprelation.activityid=vtiger_activity.activityid
-                                left join vtiger_groups on vtiger_groups.groupname=vtiger_activitygrouprelation.groupname
-				inner join vtiger_users on vtiger_crmentity.smcreatorid= vtiger_users.id
-				where (vtiger_activity.activitytype = 'Meeting' or vtiger_activity.activitytype='Call' or vtiger_activity.activitytype='Task')
-				and (vtiger_activity.status = 'Completed' or vtiger_activity.status = 'Deferred' or (vtiger_activity.eventstatus = 'Held' and vtiger_activity.eventstatus != ''))
-				and vtiger_seactivityrel.crmid=".$id;
-		//Don't add order by, because, for security, one more condition will be added with this query in include/RelatedListView.php
-		$log->debug("Entering get_history method ...");
-		return getHistory('HelpDesk',$query,$id);
-	}
-
-
-
-}
-?>
+<?php
+/*********************************************************************************
+ * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
+ * ("License"); You may not use this file except in compliance with the
+ * License. You may obtain a copy of txhe License at http://www.sugarcrm.com/SPL
+ * Software distributed under the License is distributed on an  "AS IS"  basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+ * the specific language governing rights and limitations under the License.
+ * The Original Code is:  SugarCRM Open Source
+ * The Initial Developer of the Original Code is SugarCRM, Inc.
+ * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
+ * All Rights Reserved.
+ * Contributor(s): ______________________________________.
+ ********************************************************************************/
+include_once('config.php');
+require_once('include/logging.php');
+require_once('include/database/PearDatabase.php');
+require_once('data/SugarBean.php');
+require_once('data/CRMEntity.php');
+require_once('include/utils/utils.php');
+
+
+class HelpDesk extends CRMEntity {
+	var $log;
+	var $db;
+
+	var $tab_name = Array('vtiger_crmentity','vtiger_troubletickets','vtiger_seticketsrel','vtiger_ticketcf','vtiger_ticketcomments','vtiger_attachments');
+	var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_troubletickets'=>'ticketid','vtiger_seticketsrel'=>'ticketid','vtiger_ticketcf'=>'ticketid','vtiger_ticketcomments'=>'ticketid','vtiger_attachments'=>'attachmentsid');
+	var $column_fields = Array();
+
+	var $sortby_fields = Array('title','status','priority','crmid','firstname','smownerid');
+
+	var $list_fields = Array(
+					'Ticket ID'=>Array('crmentity'=>'crmid'),
+					'Subject'=>Array('troubletickets'=>'title'),	  			
+					'Related to'=>Array('troubletickets'=>'parent_id'),	  			
+					'Status'=>Array('troubletickets'=>'status'),
+					'Priority'=>Array('troubletickets'=>'priority'),
+					'Assigned To'=>Array('crmentity','smownerid')
+				);
+
+	var $list_fields_name = Array(
+					'Ticket ID'=>'',
+					'Subject'=>'ticket_title',	  			
+					'Related to'=>'parent_id',	  			
+					'Status'=>'ticketstatus',
+					'Priority'=>'ticketpriorities',
+					'Assigned To'=>'assigned_user_id'
+				     );
+
+	var $list_link_field= 'ticket_title';
+			
+	var $range_fields = Array(
+				        'ticketid',
+					'title',
+			        	'firstname',
+				        'lastname',
+			        	'parent_id',
+			        	'productid',
+			        	'productname',
+			        	'priority',
+			        	'severity',
+				        'status',
+			        	'category',
+					'description',
+					'solution',
+					'modifiedtime',
+					'createdtime'
+				);
+
+	//Added these variables which are used as default order by and sortorder in ListView
+	var $default_order_by = 'crmid';
+	var $default_sort_order = 'DESC';
+
+	/**	Constructor which will set the column_fields in this object
+	 */
+	function HelpDesk() 
+	{
+		$this->log =LoggerManager::getLogger('helpdesk');
+		$this->log->debug("Entering HelpDesk() method ...");
+		$this->db = new PearDatabase();
+		$this->column_fields = getColumnFields('HelpDesk');
+		$this->log->debug("Exiting HelpDesk method ...");
+	}
+
+	/**	Function used to get the sort order for HelpDesk listview
+	 *	@return string	$sorder	- first check the $_REQUEST['sorder'] if request value is empty then check in the $_SESSION['HELPDESK_SORT_ORDER'] if this session value is empty then default sort order will be returned. 
+	 */
+	function getSortOrder()
+	{
+		global $log;
+                $log->debug("Entering getSortOrder() method ...");	
+		if(isset($_REQUEST['sorder'])) 
+			$sorder = $_REQUEST['sorder'];
+		else
+			$sorder = (($_SESSION['HELPDESK_SORT_ORDER'] != '')?($_SESSION['HELPDESK_SORT_ORDER']):($this->default_sort_order));
+		$log->debug("Exiting getSortOrder() method ...");
+		return $sorder;
+	}
+
+	/**	Function used to get the order by value for HelpDesk listview
+	 *	@return string	$order_by  - first check the $_REQUEST['order_by'] if request value is empty then check in the $_SESSION['HELPDESK_ORDER_BY'] if this session value is empty then default order by will be returned. 
+	 */
+	function getOrderBy()
+	{
+		global $log;
+                $log->debug("Entering getOrderBy() method ...");
+		if (isset($_REQUEST['order_by'])) 
+			$order_by = $_REQUEST['order_by'];
+		else
+			$order_by = (($_SESSION['HELPDESK_ORDER_BY'] != '')?($_SESSION['HELPDESK_ORDER_BY']):($this->default_order_by));
+		$log->debug("Exiting getOrderBy method ...");
+		return $order_by;
+	}	
+
+	/**     Function to form the query to get the list of activities
+         *      @param  int $id - ticket id
+	 *	@return array - return an array which will be returned from the function GetRelatedList
+        **/
+	function get_activities($id)
+	{
+		global $log;
+		$log->debug("Entering get_activities(".$id.") method ...");
+		global $mod_strings;
+		global $app_strings;
+		require_once('modules/Calendar/Activity.php');
+		$focus = new Activity();
+
+		$button = '';
+
+		$returnset = '&return_module=HelpDesk&return_action=CallRelatedList&return_id='.$id;
+
+		$query = "SELECT vtiger_activity.*, vtiger_crmentity.crmid, vtiger_recurringevents.recurringtype, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime, vtiger_users.user_name from vtiger_activity inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid=vtiger_activity.activityid inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid left outer join vtiger_recurringevents on vtiger_recurringevents.activityid=vtiger_activity.activityid left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid left join vtiger_activitygrouprelation on vtiger_activitygrouprelation.activityid=vtiger_crmentity.crmid left join vtiger_groups on vtiger_groups.groupname=vtiger_activitygrouprelation.groupname where vtiger_seactivityrel.crmid=".$id." and (activitytype='Task' or activitytype='Call' or activitytype='Meeting') AND ( vtiger_activity.status is NULL OR vtiger_activity.status != 'Completed' ) and ( vtiger_activity.eventstatus is NULL OR vtiger_activity.eventstatus != 'Held')";
+		$log->debug("Exiting get_activities method ...");
+		
+		return GetRelatedList('HelpDesk','Calendar',$focus,$query,$button,$returnset);
+	}
+
+	/**     Function to get the Ticket History information as in array format
+	 *	@param int $ticketid - ticket id
+	 *	@return array - return an array with title and the ticket history informations in the following format
+							array(	
+								header=>array('0'=>'title'),
+								entries=>array('0'=>'info1','1'=>'info2',etc.,)
+							     )
+	 */
+	function get_ticket_history($ticketid)
+	{
+		global $log, $adb;
+		$log->debug("Entering into get_ticket_history($ticketid) method ...");
+
+		$query="select title,update_log from vtiger_troubletickets where ticketid=".$ticketid;
+		$result=$adb->query($query);
+		$update_log = $adb->query_result($result,0,"update_log");
+
+		$splitval = split('--//--',trim($update_log,'--//--'));
+
+		$header[] = $adb->query_result($result,0,"title");
+
+		$return_value = Array('header'=>$header,'entries'=>$splitval);
+
+		$log->debug("Exiting from get_ticket_history($ticketid) method ...");
+
+		return $return_value;
+	}
+
+	/**	Function to form the query to get the list of attachments and notes
+	 *	@param  int $id - ticket id
+         *      @return array - return an array which will be returned from the function getAttachmentsAndNotes
+	**/
+	function get_attachments($id)
+	{
+		global $log;
+		$log->debug("Entering get_attachments(".$id.") method ...");
+		$query = "select vtiger_notes.title,'Notes      '  ActivityType, vtiger_notes.filename,
+		vtiger_attachments.type  FileType,crm2.modifiedtime lastmodified,
+		vtiger_seattachmentsrel.attachmentsid attachmentsid, vtiger_notes.notesid crmid,
+			crm2.createdtime, vtiger_notes.notecontent description, vtiger_users.user_name
+		from vtiger_notes
+			inner join vtiger_senotesrel on vtiger_senotesrel.notesid= vtiger_notes.notesid
+			inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_senotesrel.crmid
+			inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_notes.notesid and crm2.deleted=0
+			left join vtiger_seattachmentsrel  on vtiger_seattachmentsrel.crmid =vtiger_notes.notesid
+			left join vtiger_attachments on vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
+			inner join vtiger_users on crm2.smcreatorid= vtiger_users.id
+		where vtiger_crmentity.crmid=".$id;
+
+		$query .= ' union all ';
+
+		$query .= "select vtiger_attachments.description title ,'Attachments'  ActivityType,
+		vtiger_attachments.name filename, vtiger_attachments.type FileType,crm2.modifiedtime lastmodified,
+		vtiger_attachments.attachmentsid attachmentsid, vtiger_seattachmentsrel.attachmentsid crmid,
+			crm2.createdtime, vtiger_attachments.description, vtiger_users.user_name
+		from vtiger_attachments
+			inner join vtiger_seattachmentsrel on vtiger_seattachmentsrel.attachmentsid= vtiger_attachments.attachmentsid
+			inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_seattachmentsrel.crmid
+			inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_attachments.attachmentsid
+			left join vtiger_users on crm2.smcreatorid= vtiger_users.id
+		where vtiger_crmentity.crmid=".$id;	
+		$log->debug("Exiting get_attachments method ...");
+		return getAttachmentsAndNotes('HelpDesk',$query,$id);
+	}
+
+	/**	Function to get the ticket comments as a array
+	 *	@param  int   $ticketid - ticketid
+	 *	@return array $output - array(	
+						[$i][comments]    => comments
+						[$i][owner]       => name of the user or customer who made the comment
+						[$i][createdtime] => the comment created time
+					     ) 
+				where $i = 0,1,..n which are all made for the ticket
+	**/
+	function get_ticket_comments_list($ticketid)
+	{
+		global $log;
+		$log->debug("Entering get_ticket_comments_list(".$ticketid.") method ...");
+		 $sql = "select * from vtiger_ticketcomments where ticketid=".$ticketid." order by createdtime DESC";
+		 $result = $this->db->query($sql);
+		 $noofrows = $this->db->num_rows($result);
+		 for($i=0;$i<$noofrows;$i++)
+		 {
+			 $ownerid = $this->db->query_result($result,$i,"ownerid");
+			 $ownertype = $this->db->query_result($result,$i,"ownertype");
+			 if($ownertype == 'user')
+				 $name = getUserName($ownerid);
+			 elseif($ownertype == 'customer')
+			 {
+				 $sql1 = 'select * from vtiger_portalinfo where id='.$ownerid;
+				 $name = $this->db->query_result($this->db->query($sql1),0,'user_name');
+			 }
+
+			 $output[$i]['comments'] = nl2br($this->db->query_result($result,$i,"comments"));
+			 $output[$i]['owner'] = $name;
+			 $output[$i]['createdtime'] = $this->db->query_result($result,$i,"createdtime");
+		 }
+		$log->debug("Exiting get_ticket_comments_list method ...");
+		 return $output;
+	 }
+		
+	/**	Function to form the query which will give the list of tickets based on customername and id ie., contactname and contactid
+	 *	@param  string $user_name - name of the customer ie., contact name
+	 *	@param  int    $id	 - contact id 
+	 * 	@return array  - return an array which will be returned from the function process_list_query
+	**/
+	function get_user_tickets_list($user_name,$id,$where='',$match='')
+	{
+		global $log;
+		$log->debug("Entering get_user_tickets_list(".$user_name.",".$id.",".$where.",".$match.") method ...");
+
+		$this->db->println("where ==> ".$where);
+
+		$query = "select vtiger_crmentity.crmid, vtiger_troubletickets.*, vtiger_crmentity.smownerid, vtiger_crmentity.createdtime, vtiger_crmentity.modifiedtime, vtiger_contactdetails.firstname, vtiger_contactdetails.lastname, vtiger_products.productid, vtiger_products.productname, vtiger_ticketcf.* from vtiger_troubletickets inner join vtiger_ticketcf on vtiger_ticketcf.ticketid = vtiger_troubletickets.ticketid inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_troubletickets.ticketid left join vtiger_contactdetails on vtiger_troubletickets.parent_id=vtiger_contactdetails.contactid left join vtiger_products on vtiger_products.productid = vtiger_troubletickets.product_id left join vtiger_users on vtiger_crmentity.smownerid=vtiger_users.id  where vtiger_crmentity.deleted=0 and vtiger_contactdetails.email='".$user_name."' and vtiger_troubletickets.parent_id = '".$id."'";
+
+		if(trim($where) != '')
+		{
+			if($match == 'all' || $match == '')
+			{
+				$join = " and ";
+			}
+			elseif($match == 'any')
+			{
+				$join = " or ";
+			}
+			$where = explode("&&&",$where);
+			$count = count($where);
+			$count --;
+			$where_conditions = "";
+			foreach($where as $key => $value)
+			{
+				$this->db->println('key : '.$key.'...........value : '.$value);
+				$val = explode(" = ",$value);
+				$this->db->println('val0 : '.$val[0].'...........val1 : '.$val[1]);
+				if($val[0] == 'vtiger_troubletickets.title')
+				{
+					$where_conditions .= $val[0]."  ".$val[1];
+					if($count != $key) 	$where_conditions .= $join;
+				}
+				elseif($val[1] != '' && $val[1] != 'Any')
+				{
+					$where_conditions .= $val[0]." = ".$val[1];
+					if($count != $key)	$where_conditions .= $join;
+				}
+			}
+			if($where_conditions != '')
+				$where_conditions = " and ( ".$where_conditions." ) ";
+
+			$query .= $where_conditions;
+			$this->db->println("where condition for customer portal tickets search : ".$where_conditions);
+		}
+
+		$query .= " order by vtiger_crmentity.crmid desc";
+		$log->debug("Exiting get_user_tickets_list method ...");
+		return $this->process_list_query($query);
+	}
+
+	/**	Function to process the list query and return the result with number of rows
+	 *	@param  string $query - query 
+	 *	@return array  $response - array(	list           => array(   
+											$i => array(key => val)   
+									       ),
+							row_count      => '',
+							next_offset    => '',
+							previous_offset	=>''		 
+						)
+		where $i=0,1,..n & key = ticketid, title, firstname, ..etc(range_fields) & val = value of the key from db retrieved row 
+	**/
+	function process_list_query($query)
+	{
+		global $log;
+		$log->debug("Entering process_list_query(".$query.") method ...");
+	  
+   		$result =& $this->db->query($query,true,"Error retrieving $this->object_name list: ");
+		$list = Array();
+	        $rows_found =  $this->db->getRowCount($result);
+        	if($rows_found != 0)
+	        {
+			$ticket = Array();
+			for($index = 0 , $row = $this->db->fetchByAssoc($result, $index); $row && $index <$rows_found;$index++, $row = $this->db->fetchByAssoc($result, $index))
+			{
+		                foreach($this->range_fields as $columnName)
+                		{
+		                	if (isset($row[$columnName])) 
+					{
+			                	$ticket[$columnName] = $row[$columnName];
+                    			}
+		                       	else     
+				        {   
+		                        	$ticket[$columnName] = "";
+			                }   
+	     			}	
+    		                $list[] = $ticket;
+                	}
+        	}   
+
+		$response = Array();
+	        $response['list'] = $list;
+        	$response['row_count'] = $rows_found;
+	        $response['next_offset'] = $next_offset;
+        	$response['previous_offset'] = $previous_offset;
+
+		$log->debug("Exiting process_list_query method ...");
+	        return $response;
+	}
+
+	/**	Function to get the HelpDesk field labels in caps letters without space
+	 *	@return array $mergeflds - array(	key => val	)    where   key=0,1,2..n & val = ASSIGNEDTO,RELATEDTO, .,etc
+	**/
+	function getColumnNames_Hd()
+	{
+		global $log,$current_user;
+		$log->debug("Entering getColumnNames_Hd() method ...");
+		require('user_privileges/user_privileges_'.$current_user->id.'.php');
+	  if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0)
+	  {
+		  $sql1 = "select fieldlabel from vtiger_field where tabid=13 and block <> 30 ";
+		}else
+		{
+		  $profileList = getCurrentUserProfileList();
+		  $sql1 = "select fieldlabel from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=13 and vtiger_field.block <> 30 and vtiger_field.displaytype in (1,2,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_profile2field.profileid in ".$profileList;
+    }
+		$result = $this->db->query($sql1);
+		$numRows = $this->db->num_rows($result);
+		for($i=0; $i < $numRows;$i++)
+		{
+			$custom_fields[$i] = $this->db->query_result($result,$i,"fieldlabel");
+			$custom_fields[$i] = ereg_replace(" ","",$custom_fields[$i]);
+			$custom_fields[$i] = strtoupper($custom_fields[$i]);
+		}
+		$mergeflds = $custom_fields;
+		$log->debug("Exiting getColumnNames_Hd method ...");
+		return $mergeflds;
+	}
+
+	/**     Function to get the list of comments for the given ticket id
+	 *      @param  int  $ticketid - Ticket id
+	 *      @return list $list - return the list of comments and comment informations as a html output where as these comments and comments informations will be formed in div tag.
+	**/
+	function getCommentInformation($ticketid)
+	{
+		global $log;
+		$log->debug("Entering getCommentInformation(".$ticketid.") method ...");
+		global $adb;
+		global $mod_strings;
+		$sql = "select * from vtiger_ticketcomments where ticketid=".$ticketid;
+		$result = $adb->query($sql);
+		$noofrows = $adb->num_rows($result);
+
+		if($noofrows == 0)
+		{
+			$log->debug("Exiting getCommentInformation method ...");
+			return '';
+		}
+
+		$list .= '<div style="overflow: auto;height:200px;width:100%;">';
+		for($i=0;$i<$noofrows;$i++)
+		{
+			if($adb->query_result($result,$i,'comments') != '')
+			{
+				//this div is to display the comment
+				$list .= '<div valign="top" style="width:99%;padding-top:10px;" class="dataField">';
+				$list .= make_clickable(nl2br($adb->query_result($result,$i,'comments')));
+
+				$list .= '</div>';
+
+				//this div is to display the author and time
+				$list .= '<div valign="top" style="width:99%;border-bottom:1px dotted #CCCCCC;padding-bottom:5px;" class="dataLabel"><font color=darkred>';
+				$list .= $mod_strings['LBL_AUTHOR'].' : ';
+
+				if($adb->query_result($result,$i,'ownertype') == 'user')
+					$list .= getUserName($adb->query_result($result,$i,'ownerid'));
+				else
+					$list .= $this->getCustomerName($ticketid);
+
+				$list .= ' on '.$adb->query_result($result,$i,'createdtime').' &nbsp;';
+
+				$list .= '</font></div>';
+			}
+		}
+		$list .= '</div>';
+
+		$log->debug("Exiting getCommentInformation method ...");
+		return $list;
+	}
+
+	/**     Function to get the Customer Name who has made comment to the ticket from the customer portal
+	 *      @param  int    $id   - Ticket id
+	 *      @return string $customername - The contact name
+	**/
+	function getCustomerName($id)
+	{
+		global $log;
+		$log->debug("Entering getCustomerName(".$id.") method ...");
+        	global $adb;
+	        $sql = "select * from vtiger_portalinfo inner join vtiger_troubletickets on vtiger_troubletickets.parent_id = vtiger_portalinfo.id where vtiger_troubletickets.ticketid=".$id;
+        	$result = $adb->query($sql);
+	        $customername = $adb->query_result($result,0,'user_name');
+		$log->debug("Exiting getCustomerName method ...");
+        	return $customername;
+	}
+	
+	/**	Function used to get the Activity History
+	 *	@param	int	$id - ticket id to which we want to display the activity history
+	 *	@return  array	- return an array which will be returned from the function getHistory
+	 */
+	function get_history($id)
+	{
+		global $log;
+		$log->debug("Entering get_history(".$id.") method ...");
+		$query = "SELECT vtiger_activity.activityid, vtiger_activity.subject, vtiger_activity.status, vtiger_activity.eventstatus,
+		vtiger_activity.activitytype, vtiger_troubletickets.ticketid, vtiger_troubletickets.title, vtiger_crmentity.modifiedtime,
+		vtiger_crmentity.createdtime, vtiger_crmentity.description, vtiger_users.user_name
+				from vtiger_activity
+				inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid= vtiger_activity.activityid
+				inner join vtiger_troubletickets on vtiger_troubletickets.ticketid = vtiger_seactivityrel.crmid
+				inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid
+				left join vtiger_activitygrouprelation on vtiger_activitygrouprelation.activityid=vtiger_activity.activityid
+                                left join vtiger_groups on vtiger_groups.groupname=vtiger_activitygrouprelation.groupname
+				inner join vtiger_users on vtiger_crmentity.smcreatorid= vtiger_users.id
+				where (vtiger_activity.activitytype = 'Meeting' or vtiger_activity.activitytype='Call' or vtiger_activity.activitytype='Task')
+				and (vtiger_activity.status = 'Completed' or vtiger_activity.status = 'Deferred' or (vtiger_activity.eventstatus = 'Held' and vtiger_activity.eventstatus != ''))
+				and vtiger_seactivityrel.crmid=".$id;
+		//Don't add order by, because, for security, one more condition will be added with this query in include/RelatedListView.php
+		$log->debug("Entering get_history method ...");
+		return getHistory('HelpDesk',$query,$id);
+	}
+
+
+
+}
+?>

Modified: vtigercrm/trunk/modules/Leads/Lead.php
==============================================================================
--- vtigercrm/trunk/modules/Leads/Lead.php (original)
+++ vtigercrm/trunk/modules/Leads/Lead.php Wed Aug 23 08:00:50 2006
@@ -382,9 +382,17 @@
 */
 function getColumnNames_Lead()
 {
-	global $log;
+	global $log,$current_user;
 	$log->debug("Entering getColumnNames_Lead() method ...");
-	$sql1 = "select fieldlabel from vtiger_field where tabid=7";
+	require('user_privileges/user_privileges_'.$current_user->id.'.php');
+	if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0)
+	{
+    $sql1 = "select fieldlabel from vtiger_field where tabid=7";
+  }else
+  {
+    $profileList = getCurrentUserProfileList();
+    $sql1 = "select fieldlabel from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=7 and vtiger_field.displaytype in (1,2,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_profile2field.profileid in ".$profileList;
+  }
 	$result = $this->db->query($sql1);
 	$numRows = $this->db->num_rows($result);
 	for($i=0; $i < $numRows;$i++)





More information about the vtigercrm-commits mailing list