diff --git a/oss/vtiger/trunk/modules/Contacts/CallRelatedList.php b/oss/vtiger/trunk/modules/Contacts/CallRelatedList.php
new file mode 100644
index 00000000..545c1d7a
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Contacts/CallRelatedList.php
@@ -0,0 +1,110 @@
+retrieve_entity_info($RECORD,$currentmodule);
+ $focus->id = $RECORD;
+ $focus->name=$focus->column_fields['firstname'].' '.$focus->column_fields['lastname'];
+ $log->debug("id is ".$focus->id);
+ $log->debug("name is ".$focus->name);
+ }
+
+ global $adb;
+ $sql = $adb->pquery('select accountid from vtiger_contactdetails where contactid=?', array($focus->id));
+ $accountid = $adb->query_result($sql,0,'accountid');
+ if($accountid == 0) $accountid='';
+
+ global $mod_strings;
+ global $app_strings;
+ global $theme;
+ global $currentModule;
+ global $current_user;
+ $theme_path="themes/".$theme."/";
+ $image_path=$theme_path."images/";
+
+ $smarty = new vtigerCRM_Smarty;
+ $smarty->assign("accountid",$accountid);
+
+
+ if(isset($_request['isduplicate']) && $_request['isduplicate'] == 'true') {
+ $focus->id = "";
+ }
+ if(isset($_REQUEST['mode']) && $_REQUEST['mode'] != ' ') {
+ $smarty->assign("OP_MODE",vtlib_purify($_REQUEST['mode']));
+ }
+ $parent_email = getEmailParentsList('Contacts',$_REQUEST['record'], $focus);
+ $smarty->assign("HIDDEN_PARENTS_LIST",$parent_email);
+
+ if(isset($_REQUEST['record']) && $_REQUEST['record']!='') {
+ $userid = $current_user->id;
+ $sql = "select fieldname from vtiger_field where uitype = '13' and tabid = 4 and vtiger_field.presence in (0,2)";
+ $result = $adb->pquery($sql, array());
+ $num_fieldnames = $adb->num_rows($result);
+ for($i = 0; $i < $num_fieldnames; $i++) {
+ $fieldname = $adb->query_result($result,$i,"fieldname");
+ $permit= getFieldVisibilityPermission("Contacts",$userid,$fieldname);
+ }
+ }
+ $smarty->assign("TODO_PERMISSION",CheckFieldPermission('parent_id','Calendar'));
+ $smarty->assign("CONTACT_PERMISSION",CheckFieldPermission('contact_id','Calendar'));
+ $smarty->assign("EVENT_PERMISSION",CheckFieldPermission('parent_id','Events'));
+ $smarty->assign("CATEGORY",$category);
+ $smarty->assign("ID",$focus->id);
+ $smarty->assign("NAME",$focus->name);
+ $smarty->assign("EMAIL",$focus->column_fields['email']);
+ $smarty->assign("YAHOO",$focus->column_fields['yahooid']);
+
+ // Module Sequence Numbering
+ $mod_seq_field = getModuleSequenceField($currentModule);
+ if ($mod_seq_field != null) {
+ $mod_seq_id = $focus->column_fields[$mod_seq_field['name']];
+ } else {
+ $mod_seq_id = $focus->id;
+ }
+ $smarty->assign('MOD_SEQ_ID', $mod_seq_id);
+ // END
+
+ $related_array = getRelatedLists($currentModule,$focus);
+ require_once('include/ListView/RelatedListViewSession.php');
+ if(!empty($_REQUEST['selected_header']) && !empty($_REQUEST['relation_id'])) {
+ $relationId = vtlib_purify($_REQUEST['relation_id']);
+ RelatedListViewSession::addRelatedModuleToSession($relationId,
+ vtlib_purify($_REQUEST['selected_header']));
+ }
+ $open_related_modules = RelatedListViewSession::getRelatedModulesFromSession();
+ $smarty->assign("SELECTEDHEADERS", $open_related_modules);
+
+ $smarty->assign("RELATEDLISTS", $related_array);
+ $smarty->assign("MODULE",$currentmodule);
+ $smarty->assign("SINGLE_MOD",$app_strings['Contact']);
+ $smarty->assign("UPDATEINFO",updateInfo($focus->id));
+ $smarty->assign("MOD",$mod_strings);
+ $smarty->assign("APP",$app_strings);
+ $smarty->assign("THEME", $theme);
+ $smarty->assign("IMAGE_PATH", $image_path);
+
+ $check_button = Button_Check($module);
+ $smarty->assign("CHECK", $check_button);
+ $smarty->display("RelatedLists.tpl");
+}
+?>
\ No newline at end of file
diff --git a/oss/vtiger/trunk/modules/Contacts/Contacts.js b/oss/vtiger/trunk/modules/Contacts/Contacts.js
new file mode 100644
index 00000000..de29b5d9
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Contacts/Contacts.js
@@ -0,0 +1,250 @@
+/*********************************************************************************
+
+** The contents of this file are subject to the vtiger CRM Public License Version 1.0
+ * ("License"); You may not use this file except in compliance with the License
+ * The Original Code is: vtiger CRM Open Source
+ * The Initial Developer of the Original Code is vtiger.
+ * Portions created by vtiger are Copyright (C) vtiger.
+ * All Rights Reserved.
+ ********************************************************************************/
+
+document.write("
+pquery($sql, array($templateid));
+$temparray = $adb->fetch_array($result);
+
+$fileContent = $temparray['data'];
+$filename=html_entity_decode($temparray['filename'], ENT_QUOTES, $default_charset);
+// Fix For: http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/2107
+$filename= $randomfilename . "_word.doc";
+
+$filesize=$temparray['filesize'];
+$wordtemplatedownloadpath =$root_directory ."/test/wordtemplatedownload/";
+
+$handle = fopen($wordtemplatedownloadpath .$filename,"wb");
+fwrite($handle,base64_decode($fileContent),$filesize);
+fclose($handle);
+
+
+//<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>
+$mass_merge = $_REQUEST['allselectedboxes'];
+$single_record = $_REQUEST['record'];
+
+if($mass_merge != "")
+{
+ $mass_merge = explode(";",$mass_merge);
+ $temp_mass_merge = $mass_merge;
+ if(array_pop($temp_mass_merge)=="")
+ array_pop($mass_merge);
+ //$mass_merge = implode(",",$mass_merge);
+}else if($single_record != "")
+{
+ $mass_merge = $single_record;
+}else
+{
+ die("Record Id is not found, cannot merge the document");
+}
+
+//<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>
+
+global $current_user;
+require('user_privileges/user_privileges_'.$current_user->id.'.php');
+if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || $module == "Users" || $module == "Emails")
+{
+ $query1="select vtiger_tab.name,vtiger_field.tablename,vtiger_field.columnname,vtiger_field.fieldlabel from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid where vtiger_field.tabid in (4,6) and vtiger_field.block <> 75 order by vtiger_field.tablename and vtiger_field.presence in (0,2)";
+ $params1 = array();
+}
+else
+{
+ $profileList = getCurrentUserProfileList();
+ $query1="select vtiger_tab.name,vtiger_field.tablename,vtiger_field.columnname,vtiger_field.fieldlabel from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid 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 in (4,6) and vtiger_field.block <> 75 AND vtiger_profile2field.visible=0 AND vtiger_def_org_field.visible=0 AND vtiger_profile2field.profileid IN (". generateQuestionMarks($profileList) .") and vtiger_field.presence in (0,2) GROUP BY vtiger_field.fieldid order by vtiger_field.tablename";
+ $params1 = array($profileList);
+ //Postgres 8 fixes
+ if( $adb->dbType == "pgsql")
+ $query1 = fixPostgresQuery( $query1, $log, 0);
+}
+$result = $adb->pquery($query1, $params1);
+$y=$adb->num_rows($result);
+
+for ($x=0; $x<$y; $x++)
+{
+ $tablename = $adb->query_result($result,$x,"tablename");
+ $columnname = $adb->query_result($result,$x,"columnname");
+ $modulename = $adb->query_result($result,$x,"name");
+
+ if($tablename == "crmentity")
+ {
+ if($modulename == "Accounts")
+ {
+ $tablename = "crmentityAccounts";
+ }
+ }
+ $querycolumns[$x] = $tablename.".".$columnname;
+ if($columnname == "smownerid")
+ {
+ if($modulename == "Accounts")
+ {
+ $querycolumns[$x]="case when (usersAccounts.user_name not like '') then concat(usersAccounts.last_name,' ',usersAccounts.first_name) else groupsAccounts.groupname end as username";
+ }
+ if($modulename == "Contacts")
+ {
+ $querycolumns[$x]="case when (vtiger_users.user_name not like '') then concat(vtiger_users.last_name,' ',vtiger_users.first_name) else vtiger_groups.groupname end as usercname,vtiger_users.first_name,vtiger_users.last_name,vtiger_users.user_name,vtiger_users.yahoo_id,vtiger_users.title,vtiger_users.phone_work,vtiger_users.department,vtiger_users.phone_mobile,vtiger_users.phone_other,vtiger_users.phone_fax,vtiger_users.email1,vtiger_users.phone_home,vtiger_users.email2,vtiger_users.address_street,vtiger_users.address_city,vtiger_users.address_state,vtiger_users.address_postalcode,vtiger_users.address_country";
+ }
+ }
+ if($columnname == "parentid")
+ {
+ $querycolumns[$x] = "accountAccounts.accountname";
+ }
+ if($columnname == "accountid")
+ {
+ $querycolumns[$x] = "accountContacts.accountname";
+ }
+ if($columnname == "reportsto")
+ {
+ $querycolumns[$x] = "contactdetailsContacts.lastname";
+ }
+
+
+ if($modulename == "Accounts")
+ {
+ $field_label[$x] = "ACCOUNT_".strtoupper(str_replace(" ","",$adb->query_result($result,$x,"fieldlabel")));
+ }
+
+ if($modulename == "Contacts")
+ {
+ $field_label[$x] = "CONTACT_".strtoupper(str_replace(" ","",$adb->query_result($result,$x,"fieldlabel")));
+ if($columnname == "smownerid")
+ {
+ $field_label[$x] = $field_label[$x].",USER_FIRSTNAME,USER_LASTNAME,USER_USERNAME,USER_YAHOOID,USER_TITLE,USER_OFFICEPHONE,USER_DEPARTMENT,USER_MOBILE,USER_OTHERPHONE,USER_FAX,USER_EMAIL,USER_HOMEPHONE,USER_OTHEREMAIL,USER_PRIMARYADDRESS,USER_CITY,USER_STATE,USER_POSTALCODE,USER_COUNTRY";
+ }
+ }
+
+
+}
+$csvheader = implode(",",$field_label);
+//echo $csvheader;
+//<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>
+
+if(count($querycolumns) > 0)
+{
+ $selectcolumns = implode($querycolumns,",");
+
+
+ $query = "select $selectcolumns from vtiger_contactdetails
+ inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_contactdetails.contactid
+ inner join vtiger_contactaddress on vtiger_contactdetails.contactid = vtiger_contactaddress.contactaddressid
+ inner join vtiger_contactsubdetails on vtiger_contactdetails.contactid = vtiger_contactsubdetails.contactsubscriptionid
+ inner join vtiger_contactscf on vtiger_contactdetails.contactid = vtiger_contactscf.contactid
+ inner join vtiger_customerdetails on vtiger_contactdetails.contactid = vtiger_customerdetails.customerid
+ left join vtiger_contactdetails as contactdetailsContacts on contactdetailsContacts.contactid = vtiger_contactdetails.reportsto
+ left join vtiger_account as accountContacts on accountContacts.accountid = vtiger_contactdetails.accountid
+ left join vtiger_users on vtiger_users.id = vtiger_crmentity.smownerid
+ LEFT JOIN vtiger_groups
+ ON vtiger_groups.groupid = vtiger_crmentity.smownerid
+ left join vtiger_account on vtiger_account.accountid = vtiger_contactdetails.accountid
+ left join vtiger_crmentity as crmentityAccounts on crmentityAccounts.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_account.accountid = vtiger_accountscf.accountid
+ left join vtiger_account as accountAccounts on accountAccounts.accountid = vtiger_account.parentid
+ left join vtiger_users as usersAccounts on usersAccounts.id = crmentityAccounts.smownerid
+ LEFT JOIN vtiger_groups as groupsAccounts
+ ON groupsAccounts.groupid = vtiger_crmentity.smownerid
+ where vtiger_crmentity.deleted=0 and (crmentityAccounts.deleted is NULL or crmentityAccounts.deleted <> 1) and vtiger_contactdetails.contactid in(". generateQuestionMarks($mass_merge) .")";
+
+
+ $result = $adb->pquery($query, array($mass_merge));
+ $avail_pick_arr = getAccessPickListValues('Contacts');
+while($columnValues = $adb->fetch_array($result))
+{
+ $y=$adb->num_fields($result);
+ for($x=0; $x<$y; $x++)
+ {
+ $value = $columnValues[$x];
+ foreach($columnValues as $key=>$val)
+ {
+ if($val == $value && $value != '')
+ {
+ if(array_key_exists($key,$avail_pick_arr))
+ {
+ if(!in_array($val,$avail_pick_arr[$key]))
+ {
+ $value = "Not Accessible";
+ }
+ }
+ }
+ }
+ //<<<<<<<<<<<<<<< For blank Fields >>>>>>>>>>>>>>>>>>>>>>>>>>>>
+ if(trim($value) == "--None--" || trim($value) == "--none--")
+ {
+ $value = "";
+ }
+ //<<<<<<<<<<<<<<< End >>>>>>>>>>>>>>>>>>>>>>>>>>>>
+ $actual_values[$x] = $value;
+ $actual_values[$x] = str_replace('"'," ",$actual_values[$x]);
+ //if value contains any line feed or carriage return replace the value with ".value."
+ if (preg_match ("/(\r?\n)/", $actual_values[$x]))
+ {
+ $actual_values[$x] = '"'.$actual_values[$x].'"';
+ }
+ $actual_values[$x] = decode_html(str_replace(","," ",$actual_values[$x]));
+ }
+ $mergevalue[] = implode($actual_values,",");
+}
+$csvdata = implode($mergevalue,"###");
+}else
+{
+ die("No fields to do Merge");
+}
+// Fix for: http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/2107
+$datafilename = $randomfilename . "_data.csv";
+
+$handle = fopen($wordtemplatedownloadpath.$datafilename,"wb");
+fwrite($handle,$csvheader."\r\n");
+fwrite($handle,str_replace("###","\r\n",$csvdata));
+fclose($handle);
+
+?>
+
+