]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Connectors/views/view.mappingproperties.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Connectors / views / view.mappingproperties.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
4 /*********************************************************************************
5  * SugarCRM Community Edition is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7  * 
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.
14  * 
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
18  * details.
19  * 
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
23  * 02110-1301 USA.
24  * 
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.
27  * 
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.
31  * 
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  ********************************************************************************/
38
39
40 require_once('include/MVC/View/views/view.list.php');
41 require_once('include/connectors/sources/SourceFactory.php');
42
43 class ViewMappingProperties extends ViewList 
44 {   
45         /**
46          * @see SugarView::process()
47          */
48         public function process() 
49         {
50                 $this->options['show_all'] = false;
51                 $this->options['show_javascript'] = true;
52                 $this->options['show_footer'] = false;
53                 $this->options['show_header'] = false;
54             parent::process();
55         }
56         
57     /**
58          * @see SugarView::display()
59          */
60         public function display() 
61         {
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);
69                 $script = '';
70                 $display_data = array();
71                 if($is_enabled) {
72                 $mapping = $source->getMapping();
73                 $source_defs = $source->getFieldDefs();
74             
75                 //Create the Javascript code to dynamically add the tables
76                 $json = getJSONobj();
77                 foreach($mapping['beans'] as $module=>$field_mapping) {
78                     
79                         $mod_strings = return_module_language($GLOBALS['current_language'], $module);
80                         $bean = loadBean($module);
81                         if ( !is_object($bean) )
82                             continue;
83                         $field_defs = $bean->getFieldDefinitions();
84                         $available_fields = array();
85         
86                         $labels = array();
87                             $duplicate_labels = array();
88                         foreach($field_defs as $id=>$def) {
89                                 
90                                 //We are filtering out some fields here
91                                 if($def['type'] == 'relate' || $def['type'] == 'link' || (isset($def['dbType']) && $def['dbType'] == 'id')) {
92                                    continue;
93                                 }
94                                    
95                                 
96                                 if(isset($def['vname'])) {
97                                    $available_fields[$id] = !empty($mod_strings[$def['vname']]) ? $mod_strings[$def['vname']] : $id;
98                                 } else {
99                                    $available_fields[$id] = $id;
100                                 }
101                                 
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);
105                             }
106                             
107                             if(isset($labels[$available_fields[$id]])) {
108                               $duplicate_labels[$labels[$available_fields[$id]]] = $labels[$available_fields[$id]];
109                               $duplicate_labels[$id] = $id;
110                             } else {
111                               $labels[$available_fields[$id]] = $id;
112                             }                       
113                         }
114         
115                         foreach($duplicate_labels as $id) {
116                                     $available_fields[$id] = $available_fields[$id] . " ({$id})";
117                             }
118                             
119                             asort($available_fields);
120                             
121                     $field_keys = array();
122                         $field_values = array();
123                         
124                         $source_fields = array();
125                         foreach($field_mapping as $id=>$field) {
126                                     if(!empty($source_defs[$id])) {
127                                        $source_fields[$id] = $source_defs[$id];
128                                     }
129                         }
130                         $source_fields = array_merge($source_fields, $source_defs);
131                         
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)] : '';
136                                 }
137                         }
138
139                         $display_data[$module] = array('field_keys' => $field_keys,
140                                                        'field_values' => $field_values,
141                                                        'available_fields' => $available_fields,
142                                                        'field_mapping' => $field_mapping,
143                                                'module_name' => isset($GLOBALS['app_list_strings']['moduleList'][$module]) ? $GLOBALS['app_list_strings']['moduleList'][$module] : $module
144                                                 );
145                 }
146                 }
147
148                 $this->ss->assign('display_data', $display_data);
149         $this->ss->assign('empty_mapping', empty($display_data) ? true : false);
150         $this->ss->assign('dynamic_script', $script);   
151         $this->ss->assign('sources', $sources);
152         $this->ss->assign('mod', $GLOBALS['mod_strings']);
153         $this->ss->assign('APP', $GLOBALS['app_strings']);
154         $this->ss->assign('source_id', $source_id);
155         $this->ss->assign('source_name', $sources[$source_id]['name']);
156         $this->ss->assign('theme', $GLOBALS['theme']);
157                 
158         echo $this->ss->fetch($this->getCustomFilePathIfExists('modules/Connectors/tpls/mapping_properties.tpl'));
159     }
160 }