2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
4 /*********************************************************************************
5 * SugarCRM is a customer relationship management program developed by
6 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Affero General Public License version 3 as published by the
10 * Free Software Foundation with the addition of the following permission added
11 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
20 * You should have received a copy of the GNU Affero General Public License along with
21 * this program; if not, see http://www.gnu.org/licenses or write to the Free
22 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28 * The interactive user interfaces in modified source and object code versions
29 * of this program must display Appropriate Legal Notices, as required under
30 * Section 5 of the GNU Affero General Public License version 3.
32 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33 * these Appropriate Legal Notices must retain the display of the "Powered by
34 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35 * technical reasons, the Appropriate Legal Notices must display the words
36 * "Powered by SugarCRM".
37 ********************************************************************************/
40 require_once('include/MVC/View/views/view.list.php');
41 require_once('include/connectors/sources/SourceFactory.php');
43 class ViewMappingProperties extends ViewList
46 * @see SugarView::process()
48 public function process()
50 $this->options['show_all'] = false;
51 $this->options['show_javascript'] = true;
52 $this->options['show_footer'] = false;
53 $this->options['show_header'] = false;
58 * @see SugarView::display()
60 public function display()
62 require_once('include/connectors/utils/ConnectorUtils.php');
63 require_once('include/connectors/sources/SourceFactory.php');
64 $connector_strings = ConnectorUtils::getConnectorStrings($_REQUEST['source_id']);
65 $sources = ConnectorUtils::getConnectors();
66 $source_id = $_REQUEST['source_id'];
67 $source = SourceFactory::getSource($source_id);
68 $is_enabled = ConnectorUtils::isSourceEnabled($source_id);
70 $display_data = array();
72 $mapping = $source->getMapping();
73 $source_defs = $source->getFieldDefs();
75 //Create the Javascript code to dynamically add the tables
77 foreach($mapping['beans'] as $module=>$field_mapping) {
79 $mod_strings = return_module_language($GLOBALS['current_language'], $module);
80 $bean = loadBean($module);
81 if ( !is_object($bean) )
83 $field_defs = $bean->getFieldDefinitions();
84 $available_fields = array();
87 $duplicate_labels = array();
88 foreach($field_defs as $id=>$def) {
90 //We are filtering out some fields here
91 if($def['type'] == 'relate' || $def['type'] == 'link' || (isset($def['dbType']) && $def['dbType'] == 'id')) {
96 if(isset($def['vname'])) {
97 $available_fields[$id] = !empty($mod_strings[$def['vname']]) ? $mod_strings[$def['vname']] : $id;
99 $available_fields[$id] = $id;
102 //Remove the ':' character in some labels
103 if(preg_match('/\:$/', $available_fields[$id])) {
104 $available_fields[$id] = substr($available_fields[$id], 0, strlen($available_fields[$id])-1);
107 if(isset($labels[$available_fields[$id]])) {
108 $duplicate_labels[$labels[$available_fields[$id]]] = $labels[$available_fields[$id]];
109 $duplicate_labels[$id] = $id;
111 $labels[$available_fields[$id]] = $id;
115 foreach($duplicate_labels as $id) {
116 $available_fields[$id] = $available_fields[$id] . " ({$id})";
119 asort($available_fields);
121 $field_keys = array();
122 $field_values = array();
124 $source_fields = array();
125 foreach($field_mapping as $id=>$field) {
126 if(!empty($source_defs[$id])) {
127 $source_fields[$id] = $source_defs[$id];
130 $source_fields = array_merge($source_fields, $source_defs);
132 foreach($source_fields as $id=>$def) {
133 if(empty($def['hidden'])){
134 $field_keys[strtolower($id)] = !empty($connector_strings[$source_fields[$id]['vname']]) ? $connector_strings[$source_fields[$id]['vname']] : $id;
135 $field_values[] = !empty($field_mapping[strtolower($id)]) ? $field_mapping[strtolower($id)] : '';
139 $display_data[$module] = array('field_keys' => $field_keys,
140 'field_values' => $field_values,
141 'available_fields' => $available_fields,
142 'field_mapping' => $field_mapping);
146 $this->ss->assign('display_data', $display_data);
147 $this->ss->assign('empty_mapping', empty($display_data) ? true : false);
148 $this->ss->assign('dynamic_script', $script);
149 $this->ss->assign('sources', $sources);
150 $this->ss->assign('mod', $GLOBALS['mod_strings']);
151 $this->ss->assign('APP', $GLOBALS['app_strings']);
152 $this->ss->assign('source_id', $source_id);
153 $this->ss->assign('source_name', $sources[$source_id]['name']);
154 $this->ss->assign('theme', $GLOBALS['theme']);
156 echo $this->ss->fetch('modules/Connectors/tpls/mapping_properties.tpl');