]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Connectors/controller.php
Release 6.1.4
[Github/sugarcrm.git] / modules / Connectors / controller.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
4 /*********************************************************************************
5  * SugarCRM is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2011 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 require_once('include/connectors/sources/SourceFactory.php');
40 require_once('include/connectors/ConnectorFactory.php');
41 require_once('include/MVC/Controller/SugarController.php');
42
43 class ConnectorsController extends SugarController {
44
45         var $admin_actions = array('ConnectorSettings', 'DisplayProperties', 'MappingProperties', 'ModifyMapping', 'ModifyDisplay', 'ModifyProperties',
46                                    'ModifySearch', 'SearchProperties', 'SourceProperties',
47                                    'SavedModifyDisplay', 'SaveModifyProperties', 'SaveModifySearch');
48                                    
49         
50         function process() {
51                 if(!is_admin($GLOBALS['current_user']) && in_array($this->action, $this->admin_actions)) {
52                         $this->hasAccess = false;
53                 }
54                 parent::process();
55         }
56         
57
58         /**
59          * When the user clicks the Search button, the form is posted back here and this action sets the 
60          * search parameters in the session.  Once this call returns, the tabs will then call RetrieveSource to load
61          * the data that was saved in the session.
62          *
63          */
64         function action_SetSearch(){
65                 if(empty($_REQUEST)) {
66                    return;
67                 }
68         
69                 $this->view = 'ajax';           
70                 require_once('include/connectors/utils/ConnectorUtils.php');
71         $searchdefs = ConnectorUtils::getSearchDefs();
72                 $merge_module = $_REQUEST['merge_module'];
73                 $record_id = $_REQUEST['record'];
74                 $searchDefs = isset($searchdefs) ? $searchdefs : array();
75                 unset($_SESSION['searchDefs'][$merge_module][$record_id]);
76                 $sMap = array();
77                 
78                 $search_source = $_REQUEST['source_id'];
79                 $source_instance = ConnectorFactory::getInstance($search_source);
80                 $source_map = $source_instance->getModuleMapping($merge_module);
81                 $module_fields = array();
82                 foreach($_REQUEST as $search_term => $val){
83                         if(!empty($source_map[$search_term])){
84                                 $module_fields[$source_map[$search_term]] = $val;
85                         }
86                 }
87
88                 foreach($module_fields as $search_term => $val){
89                         foreach($searchDefs as $source => $modules){
90                                 if(empty($sMap[$source])){
91                                         $instance = ConnectorFactory::getInstance($source);
92                                         $sMap[$source] = array_flip($instance->getModuleMapping($merge_module));
93                                 }
94                                 
95                                 if(!empty($sMap[$source][$search_term])){
96                                         $source_key = $sMap[$source][$search_term];
97                                         $_SESSION['searchDefs'][$merge_module][$record_id][$source][$source_key] = $val;
98                         }
99                 }
100                 }
101         }
102
103         /**
104          * This action it meant to handle the hover action on the listview.
105          *
106          */
107         function action_RetrieveSourceDetails() {
108                 $this->view = 'ajax';
109                 $source_id = $_REQUEST['source_id'];
110         $record_id = $_REQUEST['record_id'];
111         
112         if(empty($source_id) || empty($record_id)) {
113            //display error here
114            return;
115         }
116         $source = ConnectorFactory::getInstance($source_id);
117         $module = $_SESSION['merge_module'];
118         
119                 $result = $source->fillBean(array('id' => $record_id), $module);
120                 require_once('include/connectors/utils/ConnectorUtils.php');
121         $connector_strings = ConnectorUtils::getConnectorStrings($source_id);
122         
123         $fields = $source->getModuleMapping($module);
124                 $fieldDefs = $source->getFieldDefs();
125                 $str = '';
126
127                 foreach($fields as $key=>$field){
128                         
129                         $label = $field;
130                         if(isset($fieldDefs[$key])) {
131                            $label = isset($connector_strings[$fieldDefs[$key]['vname']]) ? $connector_strings[$fieldDefs[$key]['vname']] : $label;      
132                         }
133                         
134                         $val = $result->$field;
135                         if(!empty($val)){
136                            if(strlen($val) > 50) {
137                                   $val = substr($val, 0, 47) . '...';
138                            }
139                            $str .= $label . ': ' .  $val.'<br/>';
140                         }
141                 }
142                 global $theme;
143                 $json = getJSONobj();
144                 $retArray = array();
145                 
146                 $retArray['body'] = !empty($str) ? str_replace(array("\rn", "\r", "\n"), array('','','<br />'), $str) : $GLOBALS['mod_strings']['ERROR_NO_ADDITIONAL_DETAIL'];
147                 $retArray['caption'] = "<div style='float:left'>{$GLOBALS['app_strings']['LBL_ADDITIONAL_DETAILS']}</div>";
148             $retArray['width'] = (empty($results['width']) ? '300' : $results['width']);              
149             $retArray['theme'] = $theme;
150             echo 'result = ' . $json->encode($retArray);
151         }
152         
153         
154         function action_GetSearchForm(){
155         $this->view = 'ajax';
156                 if(!empty($_REQUEST['source_id'])){
157                         //get the search fields and return the search form
158                         
159                         $ss = new Sugar_Smarty();
160                     require_once('include/connectors/utils/ConnectorUtils.php');
161             $searchdefs = ConnectorUtils::getSearchDefs();
162                         $merge_module = $_REQUEST['merge_module'];
163                         $seed = loadBean($merge_module);
164                         $_searchDefs = isset($searchdefs) ? $searchdefs : array(); 
165                         $_trueFields = array();
166                         $source = $_REQUEST['source_id'];
167                         
168                         $searchLabels = ConnectorUtils::getConnectorStrings($source);
169                         $record = $_REQUEST['record'];
170                         $sourceObj = SourceFactory::getSource($source);
171                         $field_defs = $sourceObj->getFieldDefs();
172                         
173                     if(!empty($_searchDefs[$source][$merge_module])) {
174                                 foreach($_searchDefs[$source][$merge_module] as $key) {
175                                         if(!empty($_SESSION['searchDefs'][$merge_module][$record][$source][$key])){
176                                                 $_trueFields[$key]['value'] = $_SESSION['searchDefs'][$merge_module][$record][$source][$key];
177                                         }else{
178                                                 $_trueFields[$key]['value'] = '';
179                                         }
180                                         if(!empty($field_defs[$key]) && isset($searchLabels[$field_defs[$key]['vname']])){
181                                                 $_trueFields[$key]['label'] = $searchLabels[$field_defs[$key]['vname']];
182                                         }else{
183                                                 $_trueFields[$key]['label'] = $key;
184                                         }
185                                   }//foreach
186                         }//fi
187                         
188                         $ss->assign('mod', $GLOBALS['mod_strings']);            
189                         $ss->assign('search_fields', $_trueFields);
190                         $ss->assign('source_id', $source);
191                         $ss->assign('fields', $seed->field_defs);
192                         $ss->assign('module', $merge_module);
193                         $ss->assign('RECORD', $record);
194                         $ss->assign('APP', $GLOBALS['app_strings']);
195                         $ss->assign('MOD', $GLOBALS['mod_strings']);
196                         echo $ss->fetch('modules/Connectors/tpls/search_form.tpl');
197                 }
198         }
199
200
201         function pre_save(){}
202         function post_save(){}
203
204
205         function action_CallRest() {
206                 $this->view = 'ajax';
207                 
208                 if(false === ($result=@file_get_contents($_REQUEST['url']))) {
209            echo '';
210                 } else if(!empty($_REQUEST['xml'])){
211                    $values = array();
212                    $p = xml_parser_create();
213                    xml_parse_into_struct($p, $result, $values);
214                    xml_parser_free($p);
215                    $json = getJSONobj();
216                    echo $json->encode($values);   
217                 } else {
218                    echo $result;
219                 }
220         }
221         
222         function action_CallSoap() {
223             $this->view = 'ajax';
224             $source_id = $_REQUEST['source_id'];
225             $module = $_REQUEST['module_id'];
226             $return_params = explode(',', $_REQUEST['fields']);
227             require_once('include/connectors/ConnectorFactory.php');
228             $component = ConnectorFactory::getInstance($source_id);
229             $beans = $component->fillBeans($_REQUEST, $module);
230                 if(!empty($beans) && !empty($return_params)) {
231                     $results = array();
232                         $count = 0;
233                         foreach($beans as $bean) {
234                                 foreach($return_params as $field) {
235                                         $results[$count][$field] = $bean->$field; 
236                                 }
237                                 $count++;
238                         }
239                     $json = getJSONobj();
240                     echo $json->encode($results);       
241             } else {
242                 echo '';
243             }
244         }
245         
246         
247         function action_DefaultSoapPopup() {
248                 $this->view = 'ajax';
249             $source_id = $_REQUEST['source_id'];
250             $module = $_REQUEST['module_id'];
251             $id = $_REQUEST['record_id'];
252             $mapping = $_REQUEST['mapping'];
253             
254             $mapping = explode(',', $mapping);
255             //Error checking
256             
257             //Load bean
258             $bean = loadBean($module);
259             $bean->retrieve($id);
260             
261             require_once('include/connectors/ConnectorFactory.php');
262             $component = ConnectorFactory::getInstance($source_id);
263             //Create arguments
264             $args = array();
265             $field_defs = $bean->getFieldDefinitions();
266             foreach($field_defs as $id=>$field) {
267                     if(!empty($bean->$id)) {
268                        $args[$id] = $bean->$id;
269                     }
270             }
271
272             $beans = $component->fillBeans($args, $module);
273                 if(!empty($beans) && !empty($mapping)) {
274                     $results = array();
275                         $count = 0;
276                         foreach($beans as $bean) {
277                                 foreach($mapping as $field) {
278                                         $results[$count][$field] = $bean->$field; 
279                                 }
280                                 $count++;
281                         }
282                     $json = getJSONobj();
283                     echo $json->encode($results);       
284             } else {
285                 $GLOBALS['log']->error($GLOBALS['app_strings']['ERR_MISSING_MAPPING_ENTRY_FORM_MODULE']);
286                 echo '';
287             }                
288         }
289         
290         function action_SaveModifyProperties() {
291                 require_once('include/connectors/sources/SourceFactory.php');
292                 $sources = array();
293                 $properties = array();
294                 foreach($_REQUEST as $name=>$value) {
295                         if(preg_match("/^source[0-9]+$/", $name, $matches)) {
296                         $source_id = $value;
297                         $properties = array();
298                                 foreach($_REQUEST as $arg=>$val) {
299                                         if(preg_match("/^{$source_id}_(.*?)$/", $arg, $matches2)) {
300                                            $properties[$matches2[1]] = $val;
301                                         }
302                                         }
303                                         $source = SourceFactory::getSource($source_id);
304                                         if(!empty($properties)) {
305                                             $source->setProperties($properties);
306                                             $source->saveConfig();
307                                         }
308                         }
309                 }
310                 
311                 require_once('include/connectors/utils/ConnectorUtils.php');
312                 ConnectorUtils::updateMetaDataFiles();
313             // BEGIN SUGAR INT
314             if(empty($_REQUEST['from_unit_test'])) {
315             // END SUGAR INT
316             header("Location: index.php?action=ConnectorSettings&module=Connectors");
317             // BEGIN SUGAR INT
318             }
319             // END SUGAR INT
320         }
321         
322         function action_SaveModifyDisplay() {
323                         if(empty($_REQUEST['display_sources'])) {
324                            return;
325                         }
326                         
327                         require_once('include/connectors/utils/ConnectorUtils.php');            
328                         require_once('include/connectors/sources/SourceFactory.php');
329                         
330                         $connectors = ConnectorUtils::getConnectors();
331                         $connector_keys = array_keys($connectors);
332                         
333                         $modules_sources = ConnectorUtils::getDisplayConfig();
334                         
335                         $sources = array();
336                         $values = array();
337                         $new_modules_sources = array();
338                         
339                         if(!empty($_REQUEST['display_values'])) {
340                                 $display_values = explode(',', $_REQUEST['display_values']);
341                             foreach($display_values as $value) {
342                                     $entry = explode(':', $value);
343                                     $new_modules_sources[$entry[1]][$entry[0]] = $entry[0];
344                             }
345                         }
346
347                         //These are the sources that were modified.  
348                         //We only update entries for these sources that have been changed
349                     $display_sources = explode(',', $_REQUEST['display_sources']);
350                     foreach($display_sources as $source) {
351                             $sources[$source] = $source;
352                     } //foreach   
353                    
354                     $removedModules = array();
355                     
356             //Unset entries that have all sources removed
357                 foreach($modules_sources as $module=>$source_entries) {
358                      foreach($source_entries as $source_id) {
359                              if(!empty($sources[$source_id]) && empty($new_modules_sources[$module][$source_id])) {
360                                 unset($modules_sources[$module][$source_id]);
361                                 $removedModules[$module] = true;
362                              }
363                      }
364                 }
365                 $removedModules = array_keys($removedModules);
366                 foreach($removedModules as $key){
367                         if(empty($new_modules_sources[$key])){
368                                 ConnectorUtils::cleanMetaDataFile($key);
369                         }
370                 }
371                 
372                     //Update based on new_modules_sources
373                     foreach($new_modules_sources as $module=>$enabled_sources) {
374                          //If the module is not in $modules_sources add it there
375                          if(empty($modules_sources[$module])) {
376                                 $modules_sources[$module] = $enabled_sources;
377                          } else {
378                                 foreach($enabled_sources as $source_id) {
379                                             if(empty($modules_sources[$module][$source_id])) {
380                                                $modules_sources[$module][$source_id] = $source_id;
381                                             }
382                                 } //foreach
383                          }
384                     } //foreach
385                     
386                         //Should we just remove entries where all sources are disabled?             
387                     $unset_modules = array();
388                     foreach($modules_sources as $module=>$mapping) {
389                         if(empty($mapping)) {
390                            $unset_modules[] = $module;
391                         }
392                     }
393                     
394                     foreach($unset_modules as $mod) {
395                         unset($modules_sources[$mod]);
396                     }
397
398                         if(!write_array_to_file('modules_sources', $modules_sources, CONNECTOR_DISPLAY_CONFIG_FILE)) {
399                    //Log error and return empty array
400                    $GLOBALS['log']->fatal("Cannot write \$modules_sources to " . CONNECTOR_DISPLAY_CONFIG_FILE);
401                     }
402                     
403                     $sources_modules = array();
404                     foreach($modules_sources as $module=>$source_entries) {
405                         foreach($source_entries as $id) {
406                                     $sources_modules[$id][$module] = $module;
407                         }
408                     }
409                     
410
411             //Now update the searchdefs and field mapping entries accordingly
412             require('modules/Connectors/metadata/searchdefs.php');
413             $originalSearchDefs = $searchdefs;
414                         $connectorSearchDefs = ConnectorUtils::getSearchDefs();
415
416                         $searchdefs = array();
417             foreach($sources_modules as $source_id=>$modules) {
418                     foreach($modules as $module) {
419                                         $searchdefs[$source_id][$module] = !empty($connectorSearchDefs[$source_id][$module]) ? $connectorSearchDefs[$source_id][$module] : (!empty($originalSearchDefs[$source_id][$module]) ? $originalSearchDefs[$source_id][$module] : array());
420                     }
421             }           
422                 
423                         //Write the new searchdefs out
424                     if(!write_array_to_file('searchdefs', $searchdefs, 'custom/modules/Connectors/metadata/searchdefs.php')) {
425                        $GLOBALS['log']->fatal("Cannot write file custom/modules/Connectors/metadata/searchdefs.php");
426                     }
427
428                     //Unset the $_SESSION['searchDefs'] variable
429                     if (isset($_SESSION['searchDefs'])) {
430                             unset($_SESSION['searchDefs']);
431                     }
432
433
434                     
435                     //Clear mapping file if needed (this happens when all modules are removed from a source
436                         foreach($sources as $id) {
437                             if(empty($sources_modules[$source])) {
438                                 //Now write the new mapping entry to the custom folder
439                                             $dir = $connectors[$id]['directory'];
440                                                 if(!preg_match('/^custom\//', $dir)) {
441                                                    $dir = 'custom/' . $dir;
442                                                 }
443         
444                                             if(!file_exists("{$dir}")) {
445                                            mkdir_recursive("{$dir}");
446                                         }
447                 
448                                             if(!write_array_to_file('mapping', array('beans'=>array()), "{$dir}/mapping.php")) {
449                                                $GLOBALS['log']->fatal("Cannot write file {$dir}/mapping.php");
450                                             }                           
451                             } //if
452                     } //foreach
453                     
454                     //Now update the field mapping entries
455                     foreach($sources_modules as $id=>$modules) {
456                                     $source = SourceFactory::getSource($id);
457                                     $mapping = $source->getMapping();
458                                     $mapped_modules = array_keys($mapping['beans']);
459                                                                     
460                             foreach($mapped_modules as $module) {
461                            if(empty($sources_modules[$id][$module])) {
462                                   unset($mapping['beans'][$module]);
463                            }
464                     }                  
465                     
466                     //Remove modules from the mapping entries
467                     foreach($modules as $module) {         
468                                                         if(empty($mapping['beans'][$module])) {
469                                                                 $originalMapping = $source->getOriginalMapping();
470                                                                 if(empty($originalMapping['beans'][$module])) {
471                                                                     $defs = $source->getFieldDefs();
472                                                                     $keys = array_keys($defs);
473                                                                     $new_mapping_entry = array();
474                                                                     foreach($keys as $key) {
475                                                                             $new_mapping_entry[$key] = '';
476                                                                     } 
477                                                                     $mapping['beans'][$module] = $new_mapping_entry;
478                                                                 } else {
479                                                                         $mapping['beans'][$module] = $originalMapping['beans'][$module];                                                                        
480                                                                 }
481                                                         } //if
482                                            
483                     } //foreach
484                     
485                                     //Now write the new mapping entry to the custom folder
486                                     $dir = $connectors[$id]['directory'];
487                                         if(!preg_match('/^custom\//', $dir)) {
488                                            $dir = 'custom/' . $dir;
489                                         }
490
491                                     if(!file_exists("{$dir}")) {
492                                    mkdir_recursive("{$dir}");
493                                 }
494         
495                                     if(!write_array_to_file('mapping', $mapping, "{$dir}/mapping.php")) {
496                                        $GLOBALS['log']->fatal("Cannot write file {$dir}/mapping.php");
497                                     }
498                                                         
499                     } //foreach             
500                     
501                     ConnectorUtils::updateMetaDataFiles();
502                     // BEGIN SUGAR INT
503                     if(empty($_REQUEST['from_unit_test'])) {
504                     // END SUGAR INT
505                     header("Location: index.php?action=ConnectorSettings&module=Connectors");
506                     // BEGIN SUGAR INT
507                     }
508                     // END SUGAR INT
509         }
510
511
512
513
514         /**
515          * action_SaveModifyMapping
516          */
517         function action_SaveModifyMapping() {
518                 $mapping_sources = !empty($_REQUEST['mapping_sources']) ? explode(',', $_REQUEST['mapping_sources']) : array();
519                 $mapping_values = !empty($_REQUEST['mapping_values']) ? explode(',', $_REQUEST['mapping_values']) : array();
520                 
521                 //Build the source->module->fields mapping
522                 $source_modules_fields = array();
523                 foreach($mapping_values as $id) {
524                             $parts = explode(':', $id);
525                             $key_vals = explode('=', $parts[2]);            
526                             //Note the strtolwer call... we are lowercasing the key values
527                             $source_modules_fields[$parts[0]][$parts[1]][strtolower($key_vals[0])] = $key_vals[1];
528                 } //foreach
529                 
530                 foreach($mapping_sources as $source_id) {
531                             if(empty($source_modules_fields[$source_id])) {
532                                    $source = SourceFactory::getSource($source_id);
533                                    $mapping = $source->getMapping();
534                                    foreach($mapping['beans'] as $module=>$entry) {                              
535                                   $source_modules_fields[$source_id][$module] = array();
536                                    }
537                             }
538                 } //foreach
539                 
540
541
542                 
543                 require_once('include/connectors/utils/ConnectorUtils.php');
544                 $source_entries = ConnectorUtils::getConnectors();
545                 
546                 require_once('include/connectors/sources/SourceFactory.php');
547                 foreach($source_modules_fields as $id=>$mapping_entry) {
548                             //Insert the id mapping
549                             foreach($mapping_entry as $module=>$entry) {
550                                 $mapping_entry[$module]['id'] = 'id';
551                             }
552                             
553                             $source = SourceFactory::getSource($id);
554                             $mapping = $source->getMapping();
555                             $mapping['beans'] = $mapping_entry;
556                             
557                             //Now write the new mapping entry to the custom folder
558                             $dir = $source_entries[$id]['directory'];
559                                 if(!preg_match('/^custom\//', $dir)) {
560                                    $dir = 'custom/' . $dir;
561                                 }                                   
562                             
563                             if(!file_exists("{$dir}")) {
564                            mkdir_recursive("{$dir}");
565                         }
566                         
567                             if(!write_array_to_file('mapping', $mapping, "{$dir}/mapping.php")) {
568                                $GLOBALS['log']->fatal("Cannot write file {$dir}/mapping.php");
569                             }                           
570                 }
571
572                 //Rewrite the metadata files
573                 ConnectorUtils::updateMetaDataFiles();
574                 
575             // BEGIN SUGAR INT
576                 if(empty($_REQUEST['from_unit_test'])) {
577                 // END SUGAR INT                
578         header("Location: index.php?action=ConnectorSettings&module=Connectors");
579             // BEGIN SUGAR INT
580                 }
581                 // END SUGAR INT        
582         }               
583         
584         
585         function action_RunTest() {
586             $this->view = 'ajax';
587             $source_id = $_REQUEST['source_id'];
588             $source = SourceFactory::getSource($source_id);
589             $properties = array();
590             foreach($_REQUEST as $name=>$value) {
591                     if(preg_match("/^{$source_id}_(.*?)$/", $name, $matches)) {
592                        $properties[$matches[1]] = $value;
593                     }
594             }
595             $source->setProperties($properties);
596             $source->saveConfig();
597             
598             //Call again and call init
599             $source = SourceFactory::getSource($source_id);
600             $source->init();
601             
602             global $mod_strings;
603             try {
604                     if($source->isRequiredConfigFieldsForButtonSet() && $source->test()) {
605                       echo $mod_strings['LBL_TEST_SOURCE_SUCCESS'];
606                     } else {
607                       echo $mod_strings['LBL_TEST_SOURCE_FAILED'];
608                     }
609             } catch (Exception $ex) {
610                 $GLOBALS['log']->fatal($ex->getMessage());
611                 echo $ex->getMessage();
612             }
613         }
614         
615         
616         /**
617          * action_RetrieveSources
618          * Returns a JSON encoded format of the Connectors that are configured for the system
619          * 
620          */
621         function action_RetrieveSources() {
622                 require_once('include/connectors/utils/ConnectorUtils.php');
623                 $this->view = 'ajax';   
624                 $sources = ConnectorUtils:: getConnectors();
625                 $results = array();
626                 foreach($sources as $id=>$entry) {
627                             $results[$id] = !empty($entry['name']) ? $entry['name'] : $id;
628                 }
629             $json = getJSONobj();
630             echo $json->encode($results);
631         }
632         
633 }
634 ?>