diff --git a/oss/vtiger/trunk/modules/Leads/CallRelatedList.php b/oss/vtiger/trunk/modules/Leads/CallRelatedList.php
new file mode 100644
index 00000000..c8b01574
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/CallRelatedList.php
@@ -0,0 +1,113 @@
+retrieve_entity_info($RECORD,$currentmodule);
+ $focus->id = $RECORD;
+ $focus->firstname=$focus->column_fields['firstname'];
+ $focus->lastname=$focus->column_fields['lastname'];
+ $log->debug("id is ".$focus->id);
+ $log->debug("name is ".$focus->name);
+ }
+
+ 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;
+
+
+ if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
+ $focus->id = "";
+ }
+ if(isset($_REQUEST['mode']) && $_REQUEST['mode'] != ' ') {
+ $smarty->assign("OP_MODE",vtlib_purify($_REQUEST['mode']));
+ }
+
+ if(!$_SESSION['rlvs'][$module])
+ {
+ unset($_SESSION['rlvs']);
+ }
+
+ if(isset($_REQUEST['record']) && $_REQUEST['record']!='')
+ {
+ $userid = $current_user->id;
+ $sql = "select fieldname from vtiger_field where uitype = '13' and tabid = 7 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("Leads",$userid,$fieldname);
+ }
+ }
+
+ $smarty->assign("TODO_PERMISSION",CheckFieldPermission('parent_id','Calendar'));
+ $smarty->assign("EVENT_PERMISSION",CheckFieldPermission('parent_id','Events'));
+ $smarty->assign("CATEGORY",$category);
+ $parent_email = getEmailParentsList('Leads',$focus->id, $focus);
+ $smarty->assign("HIDDEN_PARENTS_LIST",$parent_email);
+
+ // 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
+
+ $smarty->assign("ID",$focus->id);
+ $smarty->assign("NAME",$focus->lastname.' '.$focus->firstname);
+ $smarty->assign("EMAIL",$focus->column_fields['email']);
+ $smarty->assign("YAHOO",$focus->column_fields['yahooid']);
+ $related_array = getRelatedLists($currentModule,$focus);
+ $smarty->assign("RELATEDLISTS", $related_array);
+
+ 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("SINGLE_MOD",$app_strings['Lead']);
+ $smarty->assign("MODULE", $currentmodule);
+ $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/Leads/ConvertLead.php b/oss/vtiger/trunk/modules/Leads/ConvertLead.php
new file mode 100644
index 00000000..a3071f76
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/ConvertLead.php
@@ -0,0 +1,272 @@
+debug(" the id is ".$id);
+}
+$category = getParentTab();
+//Retreive lead details from database
+$sql = "SELECT firstname, lastname, company, smownerid from vtiger_leaddetails inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_leaddetails.leadid where vtiger_leaddetails.leadid =?";
+$result = $adb->pquery($sql, array($id));
+$row = $adb->fetch_array($result);
+
+//if company field is not present
+if(getFieldVisibilityPermission('Leads',$current_user->id,'company') == '1'){
+ $row["company"] = '';
+}
+
+$firstname = $row["firstname"];
+$lastname = $row["lastname"];
+$company = $row["company"];
+$potentialname = $row["company"] ."-";
+$userid = $row["smownerid"];
+
+//Retreiving the current user id
+$modified_user_id = $current_user->id;
+$log->info("Convert Lead view");
+
+$date_format = parse_calendardate($app_strings['NTC_DATE_FORMAT']);
+
+$roleid=$current_user->roleid;
+$subrole = getRoleSubordinates($roleid);
+if(count($subrole)> 0)
+{
+ $roleids = $subrole;
+ array_push($roleids, $roleid);
+}
+else
+{
+ $roleids = $roleid;
+}
+if($sortid != '') {
+ $sales_stage_query="select sales_stage from vtiger_sales_stage";
+ $params = array();
+}
+elseif($is_admin)
+{
+ $sales_stage_query="select sales_stage from vtiger_sales_stage inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_sales_stage.picklist_valueid where roleid != 'H1' order by sortid";
+ $params = array();
+}else
+{
+ if (count($roleids) > 0) {
+ $sales_stage_query="select sales_stage from vtiger_sales_stage inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_sales_stage.picklist_valueid where roleid in (". generateQuestionMarks($roleids) .") and picklistid in (select picklistid from vtiger_sales_stage) order by sortid";
+ $params = array($roleids);
+ } else {
+ $sales_stage_query="select sales_stage from vtiger_sales_stage inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_sales_stage.picklist_valueid where picklistid in (select picklistid from vtiger_sales_stage) order by sortid";
+ $params = array();
+ }
+}
+$sales_stage_result = $adb->pquery($sales_stage_query, $params);
+$noofsalesRows = $adb->num_rows($sales_stage_result);
+$sales_stage_fld = '';
+$sales_stage_list[] = array();
+for($j = 0; $j < $noofsalesRows; $j++)
+{
+
+ $sales_stageValue=$adb->query_result($sales_stage_result,$j,strtolower(sales_stage));
+ if(in_array($sales_stageValue,$sales_stage_list)) continue;
+ $sales_stage_list[] = $sales_stageValue;
+ if($value == $sales_stageValue)
+ {
+ $chk_val = "selected";
+ }
+ else
+ {
+ $chk_val = '';
+ }
+
+ $sales_stage_fld.= '';
+}
+function isActive($field,$mod){
+ global $adb,$theme;
+ $tabid = getTabid($mod);
+ $query = 'select * from vtiger_field where fieldname = ? and tabid = ? and presence in (0,2)';
+ $res = $adb->pquery($query,array($field,$tabid));
+ $rows = $adb->num_rows($res);
+ if($rows > 0){
+ return true;
+ }else
+ return false;
+}
+$userselected = '';
+$groupselected = '';
+$userdisplay = 'none';
+$groupdisplay = 'none';
+$private = '';
+if($userid != ''){
+ global $adb;
+ $query = "SELECT * from vtiger_users WHERE id = ?";
+ $res = $adb->pquery($query,array($userid));
+ $rows = $adb->num_rows($res);
+ if($rows > 0){
+ $userselected = 'checked';
+ $userdisplay= 'block';
+ }else{
+ $groupselected = 'checked';
+ $groupdisplay= 'block';
+ }
+}
+
+if($current_user->id != 1){
+ require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
+ $Acc_tabid= getTabid('Accounts');
+ $con_tabid = getTabid('Contacts');
+ if($defaultOrgSharingPermission[$Acc_tabid] === 0 || $defaultOrgSharingPermission[$Acc_tabid] == 3){
+ $private = 'private';
+ }elseif($defaultOrgSharingPermission[$con_tabid] === 0 || $defaultOrgSharingPermission[$con_tabid] == 3){
+ $private = 'private';
+ }
+}
+
+$convertlead = '
';
+echo $convertlead;
+
+?>
diff --git a/oss/vtiger/trunk/modules/Leads/CustomAction.php b/oss/vtiger/trunk/modules/Leads/CustomAction.php
new file mode 100644
index 00000000..f72082d0
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/CustomAction.php
@@ -0,0 +1,12 @@
+
diff --git a/oss/vtiger/trunk/modules/Leads/CustomView.php b/oss/vtiger/trunk/modules/Leads/CustomView.php
new file mode 100644
index 00000000..93231ed6
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/CustomView.php
@@ -0,0 +1,14 @@
+
diff --git a/oss/vtiger/trunk/modules/Leads/Delete.php b/oss/vtiger/trunk/modules/Leads/Delete.php
new file mode 100644
index 00000000..2f7b16bf
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/Delete.php
@@ -0,0 +1,39 @@
+
\ No newline at end of file
diff --git a/oss/vtiger/trunk/modules/Leads/DetailView.php b/oss/vtiger/trunk/modules/Leads/DetailView.php
new file mode 100644
index 00000000..b2bc849c
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/DetailView.php
@@ -0,0 +1,186 @@
+id = $_REQUEST['record'];
+
+ $focus->retrieve_entity_info($_REQUEST['record'],"Leads");
+ $focus->id = $_REQUEST['record'];
+ $log->debug("id is ".$focus->id);
+ $focus->firstname=$focus->column_fields['firstname'];
+ $focus->lastname=$focus->column_fields['lastname'];
+
+}
+if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
+ $focus->id = "";
+}
+
+global $theme,$current_user;
+$theme_path="themes/".$theme."/";
+$image_path=$theme_path."images/";
+
+$log->info("Lead detail view");
+
+$smarty = new vtigerCRM_Smarty;
+$smarty->assign("MOD", $mod_strings);
+$smarty->assign("APP", $app_strings);
+
+$smarty->assign("THEME", $theme);
+$smarty->assign("IMAGE_PATH", $image_path);
+$smarty->assign("PRINT_URL", "phprint.php?jt=".session_id().$GLOBALS['request_string']);
+$smarty->assign("ID", $focus->id);
+
+// 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
+
+$smarty->assign("SINGLE_MOD", 'Lead');
+
+$lead_name = $focus->lastname;
+if (getFieldVisibilityPermission($currentModule, $current_user->id,'firstname') == '0') {
+ $lead_name .= ' '.$focus->firstname;
+}
+$smarty->assign("NAME",$lead_name );
+
+$smarty->assign("UPDATEINFO",updateInfo($focus->id));
+$smarty->assign("BLOCKS", getBlocks($currentModule,"detail_view",'',$focus->column_fields));
+$smarty->assign("CUSTOMFIELD", $cust_fld);
+
+if(useInternalMailer() == 1)
+ $smarty->assign("INT_MAILER","true");
+
+
+$val = isPermitted("Leads","EditView",$_REQUEST['record']);
+
+if(isPermitted("Leads","EditView",$_REQUEST['record']) == 'yes')
+ $smarty->assign("EDIT_DUPLICATE","permitted");
+
+if(isPermitted("Leads","EditView",$_REQUEST['record']) == 'yes' && isPermitted("Leads","ConvertLead") =='yes' && (isPermitted("Accounts","EditView") =='yes' || isPermitted("Contacts","EditView") == 'yes') && (vtlib_isModuleActive('Contacts') || vtlib_isModuleActive('Accounts')))
+{
+ $smarty->assign("CONVERTLEAD","permitted");
+}
+
+$category = getParentTab();
+$smarty->assign("CATEGORY",$category);
+
+
+if(isPermitted("Leads","Delete",$_REQUEST['record']) == 'yes')
+ $smarty->assign("DELETE","permitted");
+
+if(isPermitted("Emails","EditView",'') == 'yes')
+{
+ //Added to pass the parents list as hidden for Emails -- 09-11-2005
+ $parent_email = getEmailParentsList('Leads',$_REQUEST['record'], $focus);
+ $smarty->assign("HIDDEN_PARENTS_LIST",$parent_email);
+ $smarty->assign("SENDMAILBUTTON","permitted");
+ $smarty->assign("EMAIL1",$focus->column_fields['email']);
+ $smarty->assign("EMAIL2",$focus->column_fields['yahooid']);
+
+}
+
+if(isPermitted("Leads","Merge",'') == 'yes')
+{
+ global $current_user;
+ require("user_privileges/user_privileges_".$current_user->id.".php");
+
+ $wordTemplateResult = fetchWordTemplateList("Leads");
+ $tempCount = $adb->num_rows($wordTemplateResult);
+ $tempVal = $adb->fetch_array($wordTemplateResult);
+ for($templateCount=0;$templateCount<$tempCount;$templateCount++)
+ {
+ $optionString[$tempVal["templateid"]] =$tempVal["filename"];
+ $tempVal = $adb->fetch_array($wordTemplateResult);
+ }
+ if($is_admin)
+ $smarty->assign("MERGEBUTTON","permitted");
+ elseif($tempCount >0)
+ $smarty->assign("MERGEBUTTON","permitted");
+
+ $smarty->assign("TEMPLATECOUNT",$tempCount);
+ $smarty->assign("WORDTEMPLATEOPTIONS",$app_strings['LBL_SELECT_TEMPLATE_TO_MAIL_MERGE']);
+ $smarty->assign("TOPTIONS",$optionString);
+}
+
+$tabid = getTabid("Leads");
+$validationData = getDBValidationData($focus->tab_name,$tabid);
+$data = split_validationdataArray($validationData);
+
+$smarty->assign("VALIDATION_DATA_FIELDNAME",$data['fieldname']);
+$smarty->assign("VALIDATION_DATA_FIELDDATATYPE",$data['datatype']);
+$smarty->assign("VALIDATION_DATA_FIELDLABEL",$data['fieldlabel']);
+
+$check_button = Button_Check($module);
+$smarty->assign("CHECK", $check_button);
+
+$smarty->assign("MODULE", $currentModule);
+$smarty->assign("EDIT_PERMISSION",isPermitted($currentModule,'EditView',$_REQUEST['record']));
+$smarty->assign("TODO_PERMISSION",CheckFieldPermission('parent_id','Calendar'));
+$smarty->assign("EVENT_PERMISSION",CheckFieldPermission('parent_id','Events'));
+
+$smarty->assign("IS_REL_LIST",isPresentRelatedLists($currentModule));
+$smarty->assign("USE_ASTERISK", get_use_asterisk($current_user->id));
+
+if($singlepane_view == 'true')
+{
+ $related_array = getRelatedLists($currentModule,$focus);
+ $smarty->assign("RELATEDLISTS", $related_array);
+
+ require_once('include/ListView/RelatedListViewSession.php');
+ if(!empty($_REQUEST['selected_header']) && !empty($_REQUEST['selected_tab_id'])) {
+ RelatedListViewSession::addRelatedModuleToSession(vtlib_purify($_REQUEST['selected_tab_id']), vtlib_purify($_REQUEST['selected_header']));
+ }
+ $open_related_modules = RelatedListViewSession::getRelatedModulesFromSession();
+ $smarty->assign("SELECTEDHEADERS", $open_related_modules);
+}
+$smarty->assign("SinglePane_View", $singlepane_view);
+
+if(PerformancePrefs::getBoolean('DETAILVIEW_RECORD_NAVIGATION', true) && isset($_SESSION[$currentModule.'_listquery'])){
+ $recordNavigationInfo = ListViewSession::getListViewNavigation($focus->id);
+ VT_detailViewNavigation($smarty,$recordNavigationInfo,$focus->id);
+}
+
+// Record Change Notification
+$focus->markAsViewed($current_user->id);
+// END
+
+include_once('vtlib/Vtiger/Link.php');
+$customlink_params = Array('MODULE'=>$currentModule, 'RECORD'=>$focus->id, 'ACTION'=>vtlib_purify($_REQUEST['action']));
+$smarty->assign('CUSTOM_LINKS', Vtiger_Link::getAllByType(getTabid($currentModule), Array('DETAILVIEWBASIC','DETAILVIEW','DETAILVIEWWIDGET'), $customlink_params));
+
+$smarty->assign('DETAILVIEW_AJAX_EDIT', PerformancePrefs::getBoolean('DETAILVIEW_AJAX_EDIT', true));
+
+$smarty->display("DetailView.tpl");
+
+?>
\ No newline at end of file
diff --git a/oss/vtiger/trunk/modules/Leads/DetailViewAjax.php b/oss/vtiger/trunk/modules/Leads/DetailViewAjax.php
new file mode 100644
index 00000000..fd3c44f9
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/DetailViewAjax.php
@@ -0,0 +1,47 @@
+retrieve_entity_info($crmid,"Leads");
+ $modObj->column_fields[$fieldname] = $fieldvalue;
+ $modObj->id = $crmid;
+ $modObj->mode = "edit";
+ $modObj->save("Leads");
+ if($modObj->id != "")
+ {
+ echo ":#:SUCCESS";
+ }else
+ {
+ echo ":#:FAILURE";
+ }
+ }else
+ {
+ echo ":#:FAILURE";
+ }
+} elseif($ajaxaction == "LOADRELATEDLIST" || $ajaxaction == "DISABLEMODULE"){
+ require_once 'include/ListView/RelatedListViewContents.php';
+}
+?>
\ No newline at end of file
diff --git a/oss/vtiger/trunk/modules/Leads/EditView.php b/oss/vtiger/trunk/modules/Leads/EditView.php
new file mode 100644
index 00000000..11a1886c
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/EditView.php
@@ -0,0 +1,141 @@
+assign("SEARCH", $searchurl);
+//4600 ends
+
+if(isset($_REQUEST['record']) && isset($_REQUEST['record'])) {
+ $focus->id = $_REQUEST['record'];
+ $focus->mode = 'edit';
+ $focus->retrieve_entity_info($_REQUEST['record'],"Leads");
+ $focus->firstname=$focus->column_fields['firstname'];
+ $focus->lastname=$focus->column_fields['lastname'];
+}
+if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
+ $focus->id = "";
+ $focus->mode = '';
+}
+if(empty($_REQUEST['record']) && $focus->mode != 'edit'){
+ setObjectValuesFromRequest($focus);
+}
+$disp_view = getView($focus->mode);
+if($disp_view == 'edit_view')
+ $smarty->assign("BLOCKS",getBlocks($currentModule,$disp_view,$mode,$focus->column_fields));
+else
+{
+ $smarty->assign("BASBLOCKS",getBlocks($currentModule,$disp_view,$mode,$focus->column_fields,'BAS'));
+ $smarty->assign("ADVBLOCKS",getBlocks($currentModule,$disp_view,$mode,$focus->column_fields,'ADV'));
+}
+$smarty->assign("OP_MODE",$disp_view);
+
+
+$theme_path="themes/".$theme."/";
+$image_path=$theme_path."images/";
+//retreiving the combo values array
+
+$smarty->assign("MOD", $mod_strings);
+$smarty->assign("APP", $app_strings);
+
+$category = getParentTab();
+$smarty->assign("CATEGORY",$category);
+
+$lead_name = $focus->lastname;
+if (getFieldVisibilityPermission($currentModule, $current_user->id,'firstname') == '0') {
+ $lead_name .= ' '.$focus->firstname;
+}
+$smarty->assign("NAME",$lead_name);
+
+if(isset($cust_fld))
+{
+ $smarty->assign("CUSTOMFIELD", $cust_fld);
+}
+if($focus->mode == 'edit')
+{
+ $smarty->assign("UPDATEINFO",updateInfo($focus->id));
+ $smarty->assign("MODE", $focus->mode);
+}
+
+if(isset($_REQUEST['campaignid']))
+$smarty->assign("campaignid",vtlib_purify($_REQUEST['campaignid']));
+if (isset($_REQUEST['return_module']))
+$smarty->assign("RETURN_MODULE", vtlib_purify($_REQUEST['return_module']));
+else
+$smarty->assign("RETURN_MODULE","Leads");
+if (isset($_REQUEST['return_action']))
+$smarty->assign("RETURN_ACTION", vtlib_purify($_REQUEST['return_action']));
+else
+$smarty->assign("RETURN_ACTION","index");
+if (isset($_REQUEST['return_id']))
+$smarty->assign("RETURN_ID", vtlib_purify($_REQUEST['return_id']));
+if (isset($_REQUEST['return_viewname']))
+$smarty->assign("RETURN_VIEWNAME", vtlib_purify($_REQUEST['return_viewname']));
+$smarty->assign("THEME", $theme);
+$smarty->assign("IMAGE_PATH", $image_path);$smarty->assign("PRINT_URL", "phprint.php?jt=".session_id());
+$smarty->assign("ID", $focus->id);
+$smarty->assign("MODULE",$currentModule);
+$smarty->assign("SINGLE_MOD",'Lead');
+
+//create the html select code here and assign it
+$smarty->assign("CALENDAR_LANG", $app_strings['LBL_JSCALENDAR_LANG']);
+$smarty->assign("CALENDAR_DATEFORMAT", parse_calendardate($app_strings['NTC_DATE_FORMAT']));
+
+
+ $tabid = getTabid("Leads");
+ $validationData = getDBValidationData($focus->tab_name,$tabid);
+ $data = split_validationdataArray($validationData);
+
+ $smarty->assign("VALIDATION_DATA_FIELDNAME",$data['fieldname']);
+ $smarty->assign("VALIDATION_DATA_FIELDDATATYPE",$data['datatype']);
+ $smarty->assign("VALIDATION_DATA_FIELDLABEL",$data['fieldlabel']);
+
+$check_button = Button_Check($module);
+$smarty->assign("CHECK", $check_button);
+$smarty->assign("DUPLICATE",vtlib_purify($_REQUEST['isDuplicate']));
+
+global $adb;
+// Module Sequence Numbering
+$mod_seq_field = getModuleSequenceField($currentModule);
+if($focus->mode != 'edit' && $mod_seq_field != null) {
+ $autostr = getTranslatedString('MSG_AUTO_GEN_ON_SAVE');
+ $mod_seq_string = $adb->pquery("SELECT prefix, cur_id from vtiger_modentity_num where semodule = ? and active=1",array($currentModule));
+ $mod_seq_prefix = $adb->query_result($mod_seq_string,0,'prefix');
+ $mod_seq_no = $adb->query_result($mod_seq_string,0,'cur_id');
+ if($adb->num_rows($mod_seq_string) == 0 || $adb->num_rows($mod_seq_string) == 0 || $focus->checkModuleSeqNumber($focus->table_name, $mod_seq_field['column'], $mod_seq_prefix.$mod_seq_no))
+ echo '
'. getTranslatedString('LBL_DUPLICATE'). ' '. getTranslatedString($mod_seq_field['label'])
+ .' - '. getTranslatedString('LBL_CLICK') .' '.getTranslatedString('LBL_HERE').' '
+ . getTranslatedString('LBL_TO_CONFIGURE'). ' '. getTranslatedString($mod_seq_field['label']) .'';
+ else
+ $smarty->assign("MOD_SEQ_ID",$autostr);
+} else {
+ $smarty->assign("MOD_SEQ_ID", $focus->column_fields[$mod_seq_field['name']]);
+}
+// END
+
+if($focus->mode == 'edit')
+$smarty->display("salesEditView.tpl");
+else
+$smarty->display("CreateView.tpl");
+
+?>
\ No newline at end of file
diff --git a/oss/vtiger/trunk/modules/Leads/ExportRecords.php b/oss/vtiger/trunk/modules/Leads/ExportRecords.php
new file mode 100644
index 00000000..dcbf10eb
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/ExportRecords.php
@@ -0,0 +1,13 @@
+
diff --git a/oss/vtiger/trunk/modules/Leads/FindDuplicateRecords.php b/oss/vtiger/trunk/modules/Leads/FindDuplicateRecords.php
new file mode 100644
index 00000000..02efee01
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/FindDuplicateRecords.php
@@ -0,0 +1,107 @@
+pquery($sql, array($id));
+ DeleteEntity($req_module,$return_module,$focus,$id,"");
+ }
+ else {
+ $ids_list[] = $id;
+ }
+ }
+ if(count($ids_list) > 0) {
+ $ret = getEntityName($req_module,$ids_list);
+ if(count($ret) > 0)
+ {
+ $errormsg = implode(',',$ret);
+ }
+ echo "";
+ exit;
+ }
+}
+
+
+include("include/saveMergeCriteria.php");
+$ret_arr=getDuplicateRecordsArr($req_module);
+
+$fld_values=$ret_arr[0];
+$total_num_group=count($fld_values);
+$fld_name=$ret_arr[1];
+$ui_type=$ret_arr[2];
+
+$smarty->assign("NAVIGATION",$ret_arr["navigation"]);//Added for page navigation
+$smarty->assign("MODULE",$req_module);
+$smarty->assign("NUM_GROUP",$total_num_group);
+$smarty->assign("FIELD_NAMES",$fld_name);
+$smarty->assign("CATEGORY",$parenttab);
+$smarty->assign("ALL_VALUES",$fld_values);
+if(isPermitted($req_module,'Delete','') == 'yes')
+ $button_del = $app_strings['LBL_MASS_DELETE'];
+$smarty->assign("DELETE",$button_del);
+
+$smarty->assign("MOD", return_module_language($current_language,$req_module));
+$smarty->assign("THEME", $theme);
+$smarty->assign("IMAGE_PATH",$image_path);
+$smarty->assign("APP", $app_strings);
+$smarty->assign("CMOD", $mod_strings);
+$smarty->assign("MODE",'view');
+if(isset($_REQUEST['button_view']))
+{
+ $smarty->assign("VIEW",'true');
+}
+if(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '')
+ $smarty->display("FindDuplicateAjax.tpl");
+else
+ $smarty->display('FindDuplicateDisplay.tpl');
+
+?>
\ No newline at end of file
diff --git a/oss/vtiger/trunk/modules/Leads/Import.php b/oss/vtiger/trunk/modules/Leads/Import.php
new file mode 100644
index 00000000..ae570f61
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/Import.php
@@ -0,0 +1,14 @@
+
diff --git a/oss/vtiger/trunk/modules/Leads/LeadConvertToEntities.php b/oss/vtiger/trunk/modules/Leads/LeadConvertToEntities.php
new file mode 100644
index 00000000..e083bd77
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/LeadConvertToEntities.php
@@ -0,0 +1,613 @@
+id.'.php');
+if($assigned_to == "U")
+ $log->debug("id = $id \n assigned_user_id = $assigned_user_id \n createpotential = $createpotential \n close date = $close_date \n current user id = $current_user_id \n accountname = $accountname \n module = $module");
+else
+ $log->debug("id = $id \n assigned_user_id = $assigned_group_id \n createpotential = $createpotential \n close date = $close_date \n current user id = $current_user_id \n accountname = $accountname \n module = $module");
+
+$rate_symbol=getCurrencySymbolandCRate($user_info['currency_id']);
+$rate = $rate_symbol['rate'];
+if($potential_amount != '')
+ $potential_amount = convertToDollar($potential_amount,$rate);
+
+//Retrieve info from all the vtiger_tables related to leads
+$focus = new Leads();
+$focus->retrieve_entity_info($id,"Leads");
+
+//get all the lead related columns
+$row = $focus->column_fields;
+
+$date_entered = $adb->formatDate(date('Y-m-d H:i:s'), true);
+$date_modified = $adb->formatDate(date('Y-m-d H:i:s'), true);
+
+/** Function for getting the custom values from leads and saving to vtiger_account/contact/potential custom vtiger_fields.
+ * @param string $type - Field Type (eg: text, list)
+ * @param integer $type_id - Field Type ID
+*/
+function getInsertValues($type,$type_id)
+{
+ global $id,$adb,$log;
+ $log->debug("Entering getInsertValues(".$type.",".$type_id.") method ...");
+ $sql_convert_lead="select * from vtiger_convertleadmapping ";
+ $convert_result = $adb->pquery($sql_convert_lead, array());
+ $noofrows = $adb->num_rows($convert_result);
+
+ $value_cf_array = Array();
+ for($i=0;$i<$noofrows;$i++)
+ {
+ $flag="false";
+ $log->info("In vtiger_convertleadmapping function");
+ $lead_id=$adb->query_result($convert_result,$i,"leadfid");
+ //Getting the relatd customfields for Accounts/Contact/potential from vtiger_convertleadmapping vtiger_table
+ $account_id_val=$adb->query_result($convert_result,$i,"accountfid");
+ $contact_id_val=$adb->query_result($convert_result,$i,"contactfid");
+ $potential_id_val=$adb->query_result($convert_result,$i,"potentialfid");
+
+ $sql_leads_column="select vtiger_field.uitype,vtiger_field.fieldid,vtiger_field.columnname from vtiger_field,vtiger_tab where vtiger_field.tabid=vtiger_tab.tabid and generatedtype=2 and vtiger_tab.name='Leads' and fieldid=? and vtiger_field.presence in (0,2)"; //getting the columnname for the customfield of the lead
+ $log->debug("Lead's custom vtiger_field coumn name is ".$sql_leads_column);
+
+ $lead_column_result = $adb->pquery($sql_leads_column, array($lead_id));
+ $leads_no_rows = $adb->num_rows($lead_column_result);
+ if($leads_no_rows>0)
+ {
+ $lead_column_name=$adb->query_result($lead_column_result,0,"columnname");
+ $lead_uitype=$adb->query_result($lead_column_result,0,"uitype");
+ $sql_leads_val="select $lead_column_name from vtiger_leadscf where leadid=?"; //custom vtiger_field value for lead
+ $lead_val_result = $adb->pquery($sql_leads_val,array($id));
+ $lead_value=$adb->query_result($lead_val_result,0,$lead_column_name);
+ $log->debug("Lead's custom vtiger_field value is ".$lead_value);
+ }
+ //Query for getting the column name for Accounts/Contacts/Potentials if custom vtiger_field for lead is mappped
+ $sql_type="select vtiger_field.fieldid,vtiger_field.uitype,vtiger_field.columnname from vtiger_field,vtiger_tab where vtiger_field.tabid=vtiger_tab.tabid and generatedtype=2 and vtiger_field.presence in (0,2) and vtiger_tab.name=";
+ $params = array();
+ if($type=="Accounts")
+ {
+ if($account_id_val!="" && $account_id_val!=0)
+ {
+ $flag="true";
+ $log->info("Getting the Accounts custom vtiger_field column name ");
+ $sql_type.="'Accounts' and fieldid=?";
+ array_push($params, $account_id_val);
+ }
+ }
+ else if($type == "Contacts")
+ {
+ if($contact_id_val!="" && $contact_id_val!=0)
+ {
+ $flag="true";
+ $log->info("Getting the Contacts custom vtiger_field column name ");
+ $sql_type.="'Contacts' and fieldid=?";
+ array_push($params, $contact_id_val);
+ }
+ }
+ else if($type == "Potentials")
+ {
+ if($potential_id_val!="" && $potential_id_val!=0)
+ {
+ $flag="true";
+ $log->info("Getting the Potentials custom vtiger_field column name ");
+ $sql_type.="'Potentials' and fieldid=?";
+ array_push($params, $potential_id_val);
+ }
+ }
+ if($flag=="true")
+ {
+ $type_result=$adb->pquery($sql_type, $params);
+ //To construct the cf array
+ $colname = $adb->query_result($type_result,0,"columnname");
+ $type_insert_column[] = $colname;
+ $type_uitype =$adb->query_result($type_result,0,"uitype") ;
+
+ //To construct the cf array
+ $ins_val = $adb->query_result($lead_val_result,0,$lead_column_name);
+
+ //This array is used to store the tablename as the key and the value for that table in the custom field of the uitype only for 15 and 33(Multiselect cf)...
+ if($lead_uitype == 33 || $lead_uitype == 15) {
+ $lead_val_arr[$colname] = $lead_column_name;
+ $value_cf_array[$colname]=$ins_val;
+ }
+
+ $insert_value[] = $ins_val;
+ }
+ }
+ if(count($value_cf_array) > 0)
+ {
+ if(count($type_insert_column) > 0)
+ {
+ foreach($value_cf_array as $key => $value)
+ {
+ $tableName = $key;
+ $tableVal = $value;
+ if($tableVal != '')
+ {
+ $tab_val = explode ("|##|",$value);
+ if(count($tab_val)>0)
+ {
+ for($k=0;$knum_rows($adb->query($sql));
+ $count=0;
+ for($n=0;$n < $numRow;$n++)
+ {
+ $exist_val = $adb->query_result($adb->query($sql),$n,$tableName);
+ if(trim($exist_val) == trim($val))
+ {
+ $count++;
+ }
+ }
+ if($count == 0)
+ {
+ $cfId=$adb->getUniqueID("vtiger_$tableName");
+ $unique_picklist_value = getUniquePicklistID();
+
+ $qry="insert into vtiger_$tableName values(?,?,?,?)";
+ $adb->pquery($qry, array($cfId,trim($val),1,$unique_picklist_value));
+ //added to fix ticket#4492
+ $picklistId_qry = "select picklistid from vtiger_picklist where name=?";
+ $picklistId_res = $adb->pquery($picklistId_qry,array($tableName));
+ $picklist_Id = $adb->query_result($picklistId_res,0,'picklistid');
+ //While adding a new value into the picklist table, the roleid's which has permission for the lead cf will only given permission for contacts,potentials and account module while converting. -- refer ticket #4885 ---
+ $role_qry = "select roleid from vtiger_role2picklist where picklistvalueid in (select picklist_valueid from vtiger_".$lead_val_arr[$tableName]." where ".$lead_val_arr[$tableName]."='".trim($val)."')";
+ $numOFRole=$adb->num_rows($adb->query($role_qry));
+ for($l=0;$l<$numOFRole;$l++)
+ {
+ $role_id = $adb->query_result($adb->query($role_qry),$l,'roleid');
+ $sort_qry = "select max(sortid)+1 as sortid from vtiger_role2picklist where picklistid=? and roleid=?";
+ $sort_qry_res = $adb->pquery($sort_qry,array($picklist_Id,$role_id));
+ $sort_id = $adb->query_result($sort_qry_res,0,'sortid');
+ $role_picklist = "insert into vtiger_role2picklist values (?,?,?,?)";
+ $adb->pquery($role_picklist,array($role_id,$unique_picklist_value,$picklist_Id,$sort_id));
+ }
+ //end
+ }
+ }
+ }
+
+ }
+ }
+ }
+ }
+ $log->debug("columns to be inserted are ".$type_insert_column);
+ $log->debug("columns to be inserted are ".$insert_value);
+ $values = array ('columns'=>$type_insert_column,'values'=>$insert_value);
+ $log->debug("Exiting getInsertValues method ...");
+ return $values;
+}
+//function Ends
+
+/** Function used to get the lead related Notes and Attachments with other entities Account, Contact and Potential
+ * @param integer $id - leadid
+ * @param integer $accountid - related entity id (accountid)
+ */
+function getRelatedNotesAttachments($id,$related_id)
+{
+ global $adb,$log,$id;
+ $log->debug("Entering getRelatedNotesAttachments(".$id.",".$related_id.") method ...");
+
+ $sql_lead_notes ="select * from vtiger_senotesrel where crmid=?";
+ $lead_notes_result = $adb->pquery($sql_lead_notes, array($id));
+ $noofrows = $adb->num_rows($lead_notes_result);
+
+ for($i=0; $i<$noofrows;$i++ )
+ {
+
+ $lead_related_note_id=$adb->query_result($lead_notes_result,$i,"notesid");
+ $log->debug("Lead related note id ".$lead_related_note_id);
+
+ $sql_insert_notes="insert into vtiger_senotesrel(crmid,notesid) values (?,?)";
+ $adb->pquery($sql_insert_notes, array($related_id, $lead_related_note_id));
+ }
+
+ $sql_lead_attachment="select * from vtiger_seattachmentsrel where crmid=?";
+ $lead_attachment_result = $adb->pquery($sql_lead_attachment, array($id));
+ $noofrows = $adb->num_rows($lead_attachment_result);
+
+ for($i=0;$i<$noofrows;$i++)
+ {
+ $lead_related_attachment_id=$adb->query_result($lead_attachment_result,$i,"attachmentsid");
+ $log->debug("Lead related attachment id ".$lead_related_attachment_id);
+
+ $sql_insert_attachment="insert into vtiger_seattachmentsrel(crmid,attachmentsid) values (?,?)";
+ $adb->pquery($sql_insert_attachment, array($related_id, $lead_related_attachment_id));
+ }
+ $log->debug("Exiting getRelatedNotesAttachments method ...");
+
+}
+
+/** Function used to get the lead related activities with other entities Account and Contact
+ * @param integer $accountid - related entity id
+ * @param integer $contact_id - related entity id
+ */
+function getRelatedActivities($accountid,$contact_id)
+{
+ global $adb,$log,$id;
+ $log->debug("Entering getRelatedActivities(".$accountid.",".$contact_id.") method ...");
+ $sql_lead_activity="select * from vtiger_seactivityrel where crmid=?";
+ $lead_activity_result = $adb->pquery($sql_lead_activity, array($id));
+ $noofrows = $adb->num_rows($lead_activity_result);
+ for($i=0;$i<$noofrows;$i++)
+ {
+ $lead_related_activity_id=$adb->query_result($lead_activity_result,$i,"activityid");
+ $log->debug("Lead related vtiger_activity id ".$lead_related_activity_id);
+
+ $sql_type_email="select setype from vtiger_crmentity where crmid=?";
+ $type_email_result = $adb->pquery($sql_type_email, array($lead_related_activity_id));
+ $type=$adb->query_result($type_email_result,0,"setype");
+ $log->debug("type of vtiger_activity id ".$type);
+
+ $sql_delete_lead_activity="delete from vtiger_seactivityrel where crmid=?";
+ $adb->pquery($sql_delete_lead_activity, array($id));
+
+ if($type != "Emails")
+ {
+ $sql_insert_account_activity="insert into vtiger_seactivityrel(crmid,activityid) values (?,?)";
+ $adb->pquery($sql_insert_account_activity, array($accountid, $lead_related_activity_id));
+
+ $sql_insert_contact_activity="insert into vtiger_cntactivityrel(contactid,activityid) values (?,?)";
+ $adb->pquery($sql_insert_contact_activity, array($contact_id, $lead_related_activity_id));
+ }
+ else
+ {
+ $sql_insert_contact_activity="insert into vtiger_seactivityrel(crmid,activityid) values (?,?)";
+ $adb->pquery($sql_insert_contact_activity, array($contact_id, $lead_related_activity_id));
+ }
+ }
+ $log->debug("Exiting getRelatedActivities method ...");
+
+}
+
+/** Function used to save the lead related products with other entities Account, Contact and Potential
+ * $leadid - leadid
+ * $relatedid - related entity id (accountid/contactid/potentialid)
+ * $setype - related module(Accounts/Contacts/Potentials)
+ */
+function saveLeadRelatedProducts($leadid, $relatedid, $setype)
+{
+ global $adb, $log;
+ $log->debug("Entering into function saveLeadRelatedProducts($leadid, $relatedid)");
+
+ $product_result = $adb->pquery("select * from vtiger_seproductsrel where crmid=?", array($leadid));
+ $noofproducts = $adb->num_rows($product_result);
+ for($i = 0; $i < $noofproducts; $i++)
+ {
+ $productid = $adb->query_result($product_result,$i,'productid');
+ $adb->pquery("insert into vtiger_seproductsrel values(?,?,?)", array($relatedid, $productid, $setype));
+ }
+
+ $log->debug("Exit from function saveLeadRelatedProducts.");
+}
+
+/** Function used to save the lead related Campaigns with Contact
+ * $leadid - leadid
+ * $relatedid - related entity id (contactid)
+ */
+function saveLeadRelatedCampaigns($leadid, $relatedid)
+{
+ global $adb, $log;
+ $log->debug("Entering into function saveLeadRelatedCampaigns($leadid, $relatedid)");
+
+ $campaign_result = $adb->pquery("select * from vtiger_campaignleadrel where leadid=?", array($leadid));
+ $noofcampaigns = $adb->num_rows($campaign_result);
+ for($i = 0; $i < $noofcampaigns; $i++)
+ {
+ $campaignid = $adb->query_result($campaign_result,$i,'campaignid');
+
+ $adb->pquery("insert into vtiger_campaigncontrel (campaignid, contactid, campaignrelstatusid) values(?,?,1)", array($campaignid, $relatedid));
+ }
+ $log->debug("Exit from function saveLeadRelatedCampaigns.");
+}
+function saveLeadConvertedAccounts($leadid,$relatedid){
+ global $adb, $log;
+ $log->debug("Entering into function saveLeadConvertedAccounts($leadid, $relatedid)");
+ $campaign_result = $adb->pquery("select * from vtiger_campaignleadrel where leadid=?", array($leadid));
+ $noofcampaigns = $adb->num_rows($campaign_result);
+ for($i = 0; $i < $noofcampaigns; $i++)
+ {
+ $campaignid = $adb->query_result($campaign_result,$i,'campaignid');
+ $adb->pquery("INSERT INTO vtiger_campaignaccountrel (campaignid, accountid, campaignrelstatusid) values(?,?,1)",array($campaignid,$relatedid));
+
+ }
+ $log->debug("Exit from function saveLeadConvertedAccounts.");
+}
+$crmid ='';
+if(vtlib_isModuleActive('Accounts') && isPermitted("Accounts","EditView") =='yes'){
+ /*Code integrated to avoid duplicate Account creation during ConvertLead Operation START-- by Bharathi*/
+ $acc_query = "select vtiger_account.accountid from vtiger_account left join vtiger_crmentity on vtiger_account.accountid = vtiger_crmentity.crmid where vtiger_crmentity.deleted=0 and vtiger_account.accountname = ?";
+ $acc_res = $adb->pquery($acc_query, array($accountname));
+ $acc_rows = $adb->num_rows($acc_res);
+ if($acc_rows != 0){
+ $crmid = $adb->query_result($acc_res,0,"accountid");
+ //Retrieve the lead related products and relate them with this new account
+ getRelatedNotesAttachments($id,$crmid);
+ saveLeadRelatedProducts($id, $crmid, "Accounts");
+ saveLeadRelations($id, $crmid, "Accounts");
+ $accountid=$crmid;
+ saveLeadConvertedAccounts($id,$accountid);
+
+ } else if($accountname==''){
+ $crmid='';
+ } else
+ {
+ $crmid = $adb->getUniqueID("vtiger_crmentity");
+
+ //Saving Account - starts
+
+ $sql_crmentity = "insert into vtiger_crmentity(crmid,smcreatorid,smownerid,setype,presence,createdtime,modifiedtime,deleted,description) values(?,?,?,?,?,?,?,?,?)";
+ $sql_params = array($crmid, $current_user_id, $assigned_user_id, 'Accounts', 1, $date_entered, $date_modified, 0, $row['description']);
+ $adb->pquery($sql_crmentity, $sql_params);
+
+ //Module Sequence Numbering
+ require_once('modules/Accounts/Accounts.php');
+ $acc_no_focus = new Accounts();
+ $account_no = $acc_no_focus->setModuleSeqNumber("increment",'Accounts');
+ // END
+
+ /* Modified by Minnie to fix the convertlead issue -- START*/
+ if(isset($row["annualrevenue"]) && !empty($row["annualrevenue"])) $annualrevenue = $row["annualrevenue"];
+ else $annualrevenue = 'null';
+
+ if(isset($row["noofemployees"]) && !empty($row["noofemployees"])) $employees = $row["noofemployees"];
+ else $employees = 'null';
+
+ $sql_insert_account = "INSERT INTO vtiger_account (account_no,accountid,accountname,industry,annualrevenue,phone,fax,rating,email1,website,employees) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
+ /* Modified by Minnie -- END*/
+ $account_params = array($account_no,$crmid, $accountname, $row["industry"], $annualrevenue, $row["phone"], $row["fax"], $row["rating"], $row["email"], $row["website"], $employees);
+ $adb->pquery($sql_insert_account, $account_params);
+
+ /*if($assigned_to !="U"){
+ $sql_crmentity = "insert into vtiger_accountgrouprelation(accountid,groupname) values(?,?)";
+ $sql_params = array($crmid,$assigned_group_name);
+ $adb->pquery($sql_crmentity, $sql_params);
+ }*/
+
+ $sql_insert_accountbillads = "INSERT INTO vtiger_accountbillads (accountaddressid,bill_city,bill_code,bill_country,bill_state,bill_street,bill_pobox) VALUES (?,?,?,?,?,?,?)";
+ $billads_params = array($crmid, $row["city"], $row["code"], $row["country"], $row["state"], $row["lane"], $row["pobox"]);
+ $adb->pquery($sql_insert_accountbillads, $billads_params);
+
+ $sql_insert_accountshipads = "INSERT INTO vtiger_accountshipads (accountaddressid,ship_city,ship_code,ship_country,ship_pobox,ship_state,ship_street) VALUES (?,?,?,?,?,?,?)";
+ $shipads_params = array($crmid, $row["city"], $row["code"], $row["country"], $row["pobox"], $row["state"], $row["lane"]);
+ $adb->pquery($sql_insert_accountshipads, $shipads_params);
+
+ //Getting the custom vtiger_field values from leads and inserting into Accounts if the vtiger_field is mapped - Jaguar
+ $col_val= getInsertValues("Accounts",$crmid);
+ $insert_columns = $col_val['columns'];
+ $insert_columns[] = "accountid";
+ $insert_values = $col_val['values'];
+ $insert_values[] = $crmid;
+ $insert_val_str = generateQuestionMarks($insert_values);
+ $sql_insert_accountcustomfield = "INSERT INTO vtiger_accountscf (". implode(",",$insert_columns) .") VALUES (".$insert_val_str.")";
+ $adb->pquery($sql_insert_accountcustomfield, $insert_values);
+ //Saving Account - ends
+
+ getRelatedNotesAttachments($id,$crmid);
+ //Retrieve the lead related products and relate them with this new account
+ saveLeadRelatedProducts($id, $crmid, "Accounts");
+ saveLeadRelations($id, $crmid, "Accounts");
+ $accountid = $crmid;
+ //Retrieve the lead related Campaigns and relate them with this new Account
+ saveLeadConvertedAccounts($id, $accountid);
+ }
+}
+//Up to this, Account related data save finshed
+
+if(vtlib_isModuleActive('Contacts') && isPermitted("Contacts","EditView") =='yes'){
+ $date_entered = $adb->formatDate(date('Y-m-d H:i:s'), true);
+ $date_modified = $adb->formatDate(date('Y-m-d H:i:s'), true);
+
+ //Saving Contact - starts
+ $crmcontactid = $adb->getUniqueID("vtiger_crmentity");
+
+ $sql_crmentity1 = "insert into vtiger_crmentity(crmid,smcreatorid,smownerid,setype,presence,deleted,description,createdtime,modifiedtime) values(?,?,?,?,?,?,?,?,?)";
+ $sql_params = array($crmcontactid, $current_user_id, $assigned_user_id, 'Contacts', 0, 0, $row['description'], $date_entered, $date_modified);
+ $adb->pquery($sql_crmentity1, $sql_params);
+
+ $contact_id = $crmcontactid;
+ $log->debug("contact id is ".$contact_id);
+
+ // Module Sequence Numbering
+ require_once('modules/Contacts/Contacts.php');
+ $cont_no_focus = new Contacts();
+ $contact_no = $cont_no_focus->setModuleSeqNumber("increment",'Contacts');
+ // END
+
+ $sql_insert_contact = "INSERT INTO vtiger_contactdetails (contact_no,contactid,accountid,salutation,firstname,lastname,email,phone,mobile,title,fax,yahooid) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
+ $contact_params = array($contact_no, $contact_id, $crmid, $row["salutationtype"], $row["firstname"], $row["lastname"], $row["email"], $row["phone"], $row["mobile"], $row["designation"], $row["fax"], $row['yahooid']);
+ $adb->pquery($sql_insert_contact, $contact_params);
+
+ /*if($assigned_to !="U"){
+ $sql_crmentity = "insert into vtiger_contactgrouprelation(contactid,groupname) values(?,?)";
+ $sql_params = array($contact_id,$assigned_group_name);
+ $adb->pquery($sql_crmentity, $sql_params);
+ }*/
+ $sql_insert_contactsubdetails = "INSERT INTO vtiger_contactsubdetails (contactsubscriptionid,homephone,otherphone,leadsource) VALUES (?,?,?,?)";
+ $c_subd_params = array($contact_id, '', '', $row['leadsource']);
+ $adb->pquery($sql_insert_contactsubdetails, $c_subd_params);
+
+ $sql_insert_contactaddress = "INSERT INTO vtiger_contactaddress (contactaddressid,mailingcity,mailingstreet,mailingstate,mailingcountry,mailingpobox,mailingzip) VALUES (?,?,?,?,?,?,?)";
+ $c_addr_params = array($contact_id, $row["city"], $row["lane"], $row['state'], $row["country"], $row["pobox"], $row['code']);
+ $adb->pquery($sql_insert_contactaddress, $c_addr_params);
+
+ $sql_insert_customerdetails = "INSERT INTO vtiger_customerdetails (customerid) VALUES (?)";
+ $adb->pquery($sql_insert_customerdetails, array($contact_id));
+
+ //Getting the customfield values from leads and inserting into the respected ContactCustomfield to which it is mapped - Jaguar
+ $col_val= getInsertValues("Contacts",$contact_id);
+ $insert_columns = $col_val['columns'];
+ $insert_columns[] = "contactid";
+ $insert_values = $col_val['values'];
+ $insert_values[] = $contact_id;
+ $insert_val_str = generateQuestionMarks($insert_values);
+ $sql_insert_contactcustomfield = "INSERT INTO vtiger_contactscf (". implode(",",$insert_columns) .") VALUES (".$insert_val_str.")";
+ $adb->pquery($sql_insert_contactcustomfield, $insert_values);
+ //Saving Contact - ends
+
+ getRelatedActivities($crmid,$contact_id); //To convert relates Activites and Email -Jaguar
+ getRelatedNotesAttachments($id,$contact_id);
+
+ //Retrieve the lead related products and relate them with this new contact
+ saveLeadRelatedProducts($id, $contact_id, "Contacts");
+ saveLeadRelations($id, $contact_id, "Contacts");
+
+ //Retrieve the lead related Campaigns and relate them with this new contact --Minnie
+ saveLeadRelatedCampaigns($id, $contact_id);
+}
+
+//Up to this, Contact related data save finshed
+
+//Saving Potential - starts
+if((! isset($createpotential) || ! $createpotential == "on") && (!empty($potential_name)) && isPermitted("Potentials","EditView") =='yes' && ($crmid != '' || $crmcontactid != '') && vtlib_isModuleActive('Potentials'))
+{
+ $log->info("createpotential is not set");
+
+ $date_entered = $adb->formatDate(date('Y-m-d H:i:s'), true);
+ $date_modified = $adb->formatDate(date('Y-m-d H:i:s'), true);
+
+ $oppid = $adb->getUniqueID("vtiger_crmentity");
+
+ $sql_crmentity = "insert into vtiger_crmentity(crmid,smcreatorid,smownerid,setype,presence,deleted,createdtime,modifiedtime,description) values(?,?,?,?,?,?,?,?,?)";
+ $sql_params = array($oppid, $current_user_id, $assigned_user_id, 'Potentials', 0, 0, $date_entered, $date_modified, $row['description']);
+ $adb->pquery($sql_crmentity, $sql_params);
+
+ // Module Sequence Numbering
+ require_once('modules/Potentials/Potentials.php');
+ $pot_no_focus = new Potentials();
+ $potential_no = $pot_no_focus->setModuleSeqNumber("increment",'Potentials');
+ // END
+
+ if(!isset($potential_amount) || $potential_amount == null)
+ {
+ $potential_amount=0;
+ }
+
+ if($crmid!=''){
+ $related_to = $crmid;
+ } else {
+ $related_to = $crmcontactid;
+ }
+
+ $sql_insert_opp = "INSERT INTO vtiger_potential (potential_no,potentialid,related_to,potentialname,leadsource,closingdate,sales_stage,amount) VALUES (?,?,?,?,?,?,?,?)";
+ $opp_params = array($potential_no, $oppid, $related_to, $potential_name, $row['leadsource'], $close_date, $potential_sales_stage, $potential_amount);
+ $adb->pquery($sql_insert_opp, $opp_params);
+
+ //Getting the customfield values from leads and inserting into the respected PotentialCustomfield to which it is mapped - Jaguar
+ $col_val= getInsertValues("Potentials",$oppid);
+ $insert_columns = $col_val['columns'];
+ $insert_columns[] = "potentialid";
+ $insert_values = $col_val['values'];
+ $insert_values[] = $oppid;
+ $insert_val_str = generateQuestionMarks($insert_values);
+ $sql_insert_potentialcustomfield = "INSERT INTO vtiger_potentialscf (". implode(",",$insert_columns) .") VALUES (".$insert_val_str.")";
+ $adb->pquery($sql_insert_potentialcustomfield, $insert_values);
+
+ if($crmid != '' && $contact_id != ''){
+ $sql_insert2contpotentialrel ="insert into vtiger_contpotentialrel values(?,?)";
+ $adb->pquery($sql_insert2contpotentialrel, array($contact_id, $oppid));
+ }
+ //Retrieve the lead related products and relate them with this new potential
+ saveLeadRelatedProducts($id, $oppid, "Potentials");
+ saveLeadRelations($id, $oppid, "Potentials");
+}
+//Saving Potential - ends
+//Up to this, Potential related data save finshed
+
+
+//Deleting from the vtiger_tracker
+$sql_delete_tracker= "DELETE from vtiger_tracker where item_id=?";
+$adb->pquery($sql_delete_tracker, array($id));
+$category = getParentTab();
+//Updating the deleted status
+if($crmid != '' || $crmcontactid != ''){
+ $sql_update_converted = "UPDATE vtiger_leaddetails SET converted = 1 where leadid=?";
+ $adb->pquery($sql_update_converted, array($id));
+ //updating the campaign-lead relation --Minnie
+ $sql_update_campleadrel = "delete from vtiger_campaignleadrel where leadid=?";
+ $adb->pquery($sql_update_campleadrel, array($id));
+}
+if($crmid!=''){
+ header("Location: index.php?action=DetailView&module=Accounts&record=$crmid&parenttab=$category");
+} elseif($crmcontactid != '') {
+ header("Location: index.php?action=DetailView&module=Contacts&record=$crmcontactid&parenttab=$category");
+}else{
+ echo "";
+ echo "";
+}
+
+/** Function used to save the lead related services with other entities Account, Contact and Potential
+ * $leadid - leadid
+ * $relatedid - related entity id (accountid/contactid/potentialid)
+ * $setype - related module(Accounts/Contacts/Potentials)
+ */
+function saveLeadRelations($leadid, $relatedid, $setype)
+{
+ global $adb, $log;
+ $log->debug("Entering into function saveLeadRelatedProducts($leadid, $relatedid)");
+
+ $result = $adb->pquery("select * from vtiger_crmentityrel where crmid=?", array($leadid));
+ $noofproducts = $adb->num_rows($result);
+ for($i = 0; $i < $noofproducts; $i++)
+ {
+ $recordid = $adb->query_result($result,$i,'relcrmid');
+ $recordmodule = $adb->query_result($result,$i,'relmodule');
+ $adb->pquery("insert into vtiger_crmentityrel values(?,?,?,?)", array($relatedid, $setype, $recordid, $recordmodule));
+ }
+ $result = $adb->pquery("select * from vtiger_crmentityrel where relcrmid=?", array($leadid));
+ $noofproducts = $adb->num_rows($result);
+ for($i = 0; $i < $noofproducts; $i++)
+ {
+ $recordid = $adb->query_result($result,$i,'crmid');
+ $recordmodule = $adb->query_result($result,$i,'module');
+ $adb->pquery("insert into vtiger_crmentityrel values(?,?,?,?)", array($relatedid, $setype, $recordid, $recordmodule));
+ }
+
+ $log->debug("Exit from function saveLeadRelatedProducts.");
+}
+
+?>
diff --git a/oss/vtiger/trunk/modules/Leads/Leads.js b/oss/vtiger/trunk/modules/Leads/Leads.js
new file mode 100644
index 00000000..a2ef6330
--- /dev/null
+++ b/oss/vtiger/trunk/modules/Leads/Leads.js
@@ -0,0 +1,152 @@
+/*********************************************************************************
+** 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);
+
+//for mass merge
+$mass_merge = $_REQUEST['allselectedboxes'];
+$single_record = $_REQUEST['record'];
+
+if($mass_merge != "")
+{
+ $mass_merge = explode(";",$mass_merge);
+ //array_pop($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");
+}
+
+//<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>
+
+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 tablename,columnname,fieldlabel from vtiger_field where tabid=7 and vtiger_field.presence in (0,2) order by tablename";
+ $params1 = array();
+}
+else
+{
+ $profileList = getCurrentUserProfileList();
+ $query1="select vtiger_field.tablename,vtiger_field.columnname,vtiger_field.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 in (7) 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");
+ $querycolumns[$x] = $tablename.".".$columnname;
+ if($columnname == "smownerid")
+ {
+ $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 username,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";
+ }
+ $field_label[$x] = "LEAD_".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);
+//<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>
+
+if(count($querycolumns) > 0)
+{
+ $selectcolumns = implode($querycolumns,",");
+
+$query = "select ".$selectcolumns." from vtiger_leaddetails
+ inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_leaddetails.leadid
+ inner join vtiger_leadsubdetails on vtiger_leadsubdetails.leadsubscriptionid=vtiger_leaddetails.leadid
+ inner join vtiger_leadaddress on vtiger_leadaddress.leadaddressid=vtiger_leadsubdetails.leadsubscriptionid
+ inner join vtiger_leadscf on vtiger_leaddetails.leadid = vtiger_leadscf.leadid
+ left join vtiger_campaignleadrel on vtiger_leaddetails.leadid = vtiger_campaignleadrel.leadid
+ left join vtiger_campaignrelstatus on vtiger_campaignrelstatus.campaignrelstatusid = vtiger_campaignleadrel.campaignrelstatusid
+ LEFT JOIN vtiger_groups
+ ON vtiger_groups.groupid = vtiger_crmentity.smownerid
+ left join vtiger_users on vtiger_users.id = vtiger_crmentity.smownerid
+ where vtiger_crmentity.deleted=0 and vtiger_leaddetails.leadid in (". generateQuestionMarks($mass_merge) .")";
+
+$result = $adb->pquery($query, array($mass_merge));
+$avail_pick_arr = getAccessPickListValues('Leads');
+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 vtiger_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);
+
+?>
+
+
+