/**
  * @see SugarView::display()
  */
 public function display()
 {
     require_once 'include/connectors/utils/ConnectorUtils.php';
     require_once 'include/connectors/sources/SourceFactory.php';
     $source_id = $_REQUEST['source_id'];
     $connector_strings = ConnectorUtils::getConnectorStrings($source_id);
     $is_enabled = ConnectorUtils::isSourceEnabled($source_id);
     $modules_sources = array();
     $sources = ConnectorUtils::getConnectors();
     $display_data = array();
     if ($is_enabled) {
         $searchDefs = ConnectorUtils::getSearchDefs();
         $searchDefs = !empty($searchDefs[$_REQUEST['source_id']]) ? $searchDefs[$_REQUEST['source_id']] : array();
         $source = SourceFactory::getSource($_REQUEST['source_id']);
         $field_defs = $source->getFieldDefs();
         //Create the Javascript code to dynamically add the tables
         $json = getJSONobj();
         foreach ($searchDefs as $module => $fields) {
             $disabled = array();
             $enabled = array();
             $enabled_fields = array_flip($fields);
             $field_keys = array_keys($field_defs);
             foreach ($field_keys as $index => $key) {
                 if (!empty($field_defs[$key]['hidden']) || empty($field_defs[$key]['search'])) {
                     continue;
                 }
                 if (!isset($enabled_fields[$key])) {
                     $disabled[$key] = !empty($connector_strings[$field_defs[$key]['vname']]) ? $connector_strings[$field_defs[$key]['vname']] : $key;
                 } else {
                     $enabled[$key] = !empty($connector_strings[$field_defs[$key]['vname']]) ? $connector_strings[$field_defs[$key]['vname']] : $key;
                 }
             }
             $modules_sources[$module] = array_merge($enabled, $disabled);
             asort($disabled);
             $display_data[$module] = array('enabled' => $enabled, 'disabled' => $disabled);
         }
     }
     $this->ss->assign('no_searchdefs_defined', !$is_enabled);
     $this->ss->assign('display_data', $display_data);
     $this->ss->assign('modules_sources', $modules_sources);
     $this->ss->assign('sources', $sources);
     $this->ss->assign('mod', $GLOBALS['mod_strings']);
     $this->ss->assign('APP', $GLOBALS['app_strings']);
     $this->ss->assign('source_id', $_REQUEST['source_id']);
     $this->ss->assign('theme', $GLOBALS['theme']);
     $this->ss->assign('connector_language', $connector_strings);
     echo $this->ss->fetch('modules/Connectors/tpls/search_properties.tpl');
 }
示例#2
0
 function action_SaveModifyDisplay()
 {
     if (empty($_REQUEST['display_sources'])) {
         return;
     }
     require_once 'include/connectors/utils/ConnectorUtils.php';
     require_once 'include/connectors/sources/SourceFactory.php';
     $connectors = ConnectorUtils::getConnectors();
     $connector_keys = array_keys($connectors);
     $modules_sources = ConnectorUtils::getDisplayConfig();
     if (!is_array($modules_sources)) {
         $modules_sources = (array) $modules_sources;
     }
     $sources = array();
     $values = array();
     $new_modules_sources = array();
     if (!empty($_REQUEST['display_values'])) {
         $display_values = explode(',', $_REQUEST['display_values']);
         foreach ($display_values as $value) {
             $entry = explode(':', $value);
             $new_modules_sources[$entry[1]][$entry[0]] = $entry[0];
         }
     }
     //These are the sources that were modified.
     //We only update entries for these sources that have been changed
     $display_sources = explode(',', $_REQUEST['display_sources']);
     foreach ($display_sources as $source) {
         $sources[$source] = $source;
     }
     //foreach
     $removedModules = array();
     //Unset entries that have all sources removed
     foreach ($modules_sources as $module => $source_entries) {
         foreach ($source_entries as $source_id) {
             if (!empty($sources[$source_id]) && empty($new_modules_sources[$module][$source_id])) {
                 unset($modules_sources[$module][$source_id]);
                 $removedModules[$module] = true;
             }
         }
     }
     $removedModules = array_keys($removedModules);
     foreach ($removedModules as $key) {
         if (empty($new_modules_sources[$key])) {
             ConnectorUtils::cleanMetaDataFile($key);
         }
     }
     //Update based on new_modules_sources
     foreach ($new_modules_sources as $module => $enabled_sources) {
         //If the module is not in $modules_sources add it there
         if (empty($modules_sources[$module])) {
             $modules_sources[$module] = $enabled_sources;
         } else {
             foreach ($enabled_sources as $source_id) {
                 if (empty($modules_sources[$module][$source_id])) {
                     $modules_sources[$module][$source_id] = $source_id;
                 }
             }
             //foreach
         }
     }
     //foreach
     //Should we just remove entries where all sources are disabled?
     $unset_modules = array();
     foreach ($modules_sources as $module => $mapping) {
         if (empty($mapping)) {
             $unset_modules[] = $module;
         }
     }
     foreach ($unset_modules as $mod) {
         unset($modules_sources[$mod]);
     }
     if (!write_array_to_file('modules_sources', $modules_sources, CONNECTOR_DISPLAY_CONFIG_FILE)) {
         //Log error and return empty array
         $GLOBALS['log']->fatal("Cannot write \$modules_sources to " . CONNECTOR_DISPLAY_CONFIG_FILE);
     }
     $sources_modules = array();
     foreach ($modules_sources as $module => $source_entries) {
         foreach ($source_entries as $id) {
             $sources_modules[$id][$module] = $module;
         }
     }
     //Now update the searchdefs and field mapping entries accordingly
     require 'modules/Connectors/metadata/searchdefs.php';
     $originalSearchDefs = $searchdefs;
     $connectorSearchDefs = ConnectorUtils::getSearchDefs();
     $searchdefs = array();
     foreach ($sources_modules as $source_id => $modules) {
         foreach ($modules as $module) {
             $searchdefs[$source_id][$module] = !empty($connectorSearchDefs[$source_id][$module]) ? $connectorSearchDefs[$source_id][$module] : (!empty($originalSearchDefs[$source_id][$module]) ? $originalSearchDefs[$source_id][$module] : array());
         }
     }
     //Write the new searchdefs out
     if (!write_array_to_file('searchdefs', $searchdefs, 'custom/modules/Connectors/metadata/searchdefs.php')) {
         $GLOBALS['log']->fatal("Cannot write file custom/modules/Connectors/metadata/searchdefs.php");
     }
     //Unset the $_SESSION['searchDefs'] variable
     if (isset($_SESSION['searchDefs'])) {
         unset($_SESSION['searchDefs']);
     }
     //Clear mapping file if needed (this happens when all modules are removed from a source
     foreach ($sources as $id) {
         if (empty($sources_modules[$source])) {
             //Now write the new mapping entry to the custom folder
             $dir = $connectors[$id]['directory'];
             if (!preg_match('/^custom\\//', $dir)) {
                 $dir = 'custom/' . $dir;
             }
             if (!file_exists("{$dir}")) {
                 mkdir_recursive("{$dir}");
             }
             $fakeMapping = array('beans' => array());
             if (!write_array_to_file('mapping', $fakeMapping, "{$dir}/mapping.php")) {
                 $GLOBALS['log']->fatal("Cannot write file {$dir}/mapping.php");
             }
             $s = SourceFactory::getSource($id);
             $s->saveMappingHook($fakeMapping);
         }
         //if
     }
     //foreach
     //Now update the field mapping entries
     foreach ($sources_modules as $id => $modules) {
         $source = SourceFactory::getSource($id);
         $mapping = $source->getMapping();
         $mapped_modules = array_keys($mapping['beans']);
         foreach ($mapped_modules as $module) {
             if (empty($sources_modules[$id][$module])) {
                 unset($mapping['beans'][$module]);
             }
         }
         //Remove modules from the mapping entries
         foreach ($modules as $module) {
             if (empty($mapping['beans'][$module])) {
                 $originalMapping = $source->getOriginalMapping();
                 if (empty($originalMapping['beans'][$module])) {
                     $defs = $source->getFieldDefs();
                     $keys = array_keys($defs);
                     $new_mapping_entry = array();
                     foreach ($keys as $key) {
                         $new_mapping_entry[$key] = '';
                     }
                     $mapping['beans'][$module] = $new_mapping_entry;
                 } else {
                     $mapping['beans'][$module] = $originalMapping['beans'][$module];
                 }
             }
             //if
         }
         //foreach
         //Now write the new mapping entry to the custom folder
         $dir = $connectors[$id]['directory'];
         if (!preg_match('/^custom\\//', $dir)) {
             $dir = 'custom/' . $dir;
         }
         if (!file_exists("{$dir}")) {
             mkdir_recursive("{$dir}");
         }
         if (!write_array_to_file('mapping', $mapping, "{$dir}/mapping.php")) {
             $GLOBALS['log']->fatal("Cannot write file {$dir}/mapping.php");
         }
         $source->saveMappingHook($mapping);
     }
     //foreach
     // save eapm configs
     foreach ($connectors as $connector_name => $data) {
         if (isset($sources[$connector_name]) && !empty($data["eapm"])) {
             // if we touched it AND it has EAPM data
             $connectors[$connector_name]["eapm"]["enabled"] = !empty($_REQUEST[$connector_name . "_external"]);
         }
     }
     ConnectorUtils::saveConnectors($connectors);
     ConnectorUtils::updateMetaDataFiles();
     // BEGIN SUGAR INT
     if (empty($_REQUEST['from_unit_test'])) {
         // END SUGAR INT
         header("Location: index.php?action=ConnectorSettings&module=Connectors");
         // BEGIN SUGAR INT
     }
     // END SUGAR INT
 }
示例#3
0
 /**
  * @see SugarView::process()
  */
 public function process()
 {
     //Load Sources Here...
     if (!empty($_REQUEST['merge_module'])) {
         $this->_merge_module = $_REQUEST['merge_module'];
     } else {
         //Error
     }
     $moduleError = false;
     require_once 'include/connectors/utils/ConnectorUtils.php';
     require_once 'include/connectors/sources/SourceFactory.php';
     $modules_sources = ConnectorUtils::getDisplayConfig();
     if (empty($modules_sources)) {
         $moduleError = true;
     } else {
         $this->_modules_sources = $modules_sources;
         if (empty($this->_modules_sources[$this->_merge_module]) || empty($this->_modules_sources[$this->_merge_module])) {
             $moduleError = true;
         }
     }
     if ($moduleError) {
         $GLOBALS['log']->error($GLOBALS['mod_strings']['ERROR_NO_CONNECTOR_DISPLAY_CONFIG_FILE']);
         echo $GLOBALS['mod_strings']['ERROR_NO_CONNECTOR_DISPLAY_CONFIG_FILE'];
         return;
     }
     $_SESSION['merge_module'] = $this->_merge_module;
     $this->seed = BeanFactory::getBean($this->_merge_module, $_REQUEST['record']);
     //search form
     $searchdefs = ConnectorUtils::getSearchDefs();
     $this->_searchDefs = isset($searchdefs) ? $searchdefs : array();
     $mapped_fields = array();
     unset($_SESSION['searchDefs'][$this->_merge_module][$this->seed->id]);
     $sources = $modules_sources[$this->_merge_module];
     $source = array_shift($sources);
     foreach ($sources as $lsource) {
         if (!empty($this->_searchDefs[$lsource][$this->_merge_module])) {
             $s = ConnectorFactory::getInstance($lsource);
             if ($s->getSource()->isEnabledInWizard()) {
                 $source_map = $s->getModuleMapping($this->_merge_module);
                 foreach ($this->_searchDefs[$lsource][$this->_merge_module] as $key) {
                     $beanKey = $key;
                     if (!empty($source_map[$key])) {
                         $beanKey = $source_map[$key];
                     }
                     if (!empty($this->seed->{$beanKey})) {
                         $val = $this->seed->{$beanKey};
                         if (is_object($val) && get_class($val) == 'SugarEmailAddress') {
                             $emailaddress = '';
                             if (!empty($val->addresses)) {
                                 foreach ($val->addresses as $email) {
                                     if (!empty($email['primary_address'])) {
                                         $emailaddress = $email['email_address'];
                                         break;
                                     }
                                 }
                             }
                             $val = $emailaddress;
                         }
                     } else {
                         $val = '';
                     }
                     $_SESSION['searchDefs'][$this->_merge_module][$this->seed->id][$lsource][$key] = $val;
                 }
                 //foreach
             }
         }
         //if
     }
     //end search form
     parent::process();
 }
示例#4
0
 function action_SaveModifySearch()
 {
     $search_sources = !empty($_REQUEST['search_sources']) ? explode(',', $_REQUEST['search_sources']) : array();
     $search_values = !empty($_REQUEST['search_values']) ? explode(',', $_REQUEST['search_values']) : array();
     //Build the source->module->fields mapping
     $source_modules_fields = array();
     foreach ($search_values as $id) {
         $parts = explode(':', $id);
         $source_modules_fields[$parts[0]][$parts[1]][] = $parts[2];
     }
     require_once 'include/connectors/utils/ConnectorUtils.php';
     $searchdefs = ConnectorUtils::getSearchDefs();
     //Now update for each source
     foreach ($search_sources as $source) {
         $existing_modules = !empty($searchdefs[$source]) ? array_keys($searchdefs[$source]) : array();
         unset($searchdefs[$source]);
         foreach ($existing_modules as $module) {
             if (empty($source_modules_fields[$source][$module])) {
                 $searchdefs[$source][$module] = array();
             }
         }
         if (!empty($source_modules_fields[$source])) {
             foreach ($source_modules_fields[$source] as $module => $def) {
                 $searchdefs[$source][$module] = $def;
             }
         }
     }
     if (!file_exists('custom/modules/Connectors/metadata')) {
         mkdir_recursive('custom/modules/Connectors/metadata');
     }
     if (!write_array_to_file('searchdefs', $searchdefs, 'custom/modules/Connectors/metadata/searchdefs.php')) {
         $GLOBALS['log']->fatal("Cannot write file custom/modules/Connectors/metadata/searchdefs.php");
         return array();
     }
     if (isset($_SESSION['searchDefs'])) {
         unset($_SESSION['searchDefs']);
     }
     // refresh connector cache
     require_once 'include/connectors/ConnectorManager.php';
     $cm = new ConnectorManager();
     $connectors = $cm->buildConnectorsMeta();
     // BEGIN SUGAR INT
     if (empty($_REQUEST['from_unit_test'])) {
         // END SUGAR INT
         header("Location: index.php?action=ConnectorSettings&module=Connectors");
         // BEGIN SUGAR INT
     }
     // END SUGAR INT
 }
示例#5
0
 /**
  * uninstallSource
  *
  * @param String $source String value of the id of the connector to un-install
  * @return boolean $result boolean value indicating whether or not connector was un-installed
  */
 public static function uninstallSource($source)
 {
     if (empty($source)) {
         return false;
     }
     //Remove the source from the connectors.php file
     $connectorsFile = 'custom/modules/Connectors/metadata/connectors.php';
     if (file_exists($connectorsFile)) {
         require $connectorsFile;
         if (isset($connectors[$source])) {
             unset($connectors[$source]);
             if (!write_array_to_file('connectors', $connectors, $connectorsFile)) {
                 //Log error and return empty array
                 $GLOBALS['log']->fatal("Cannot write connectors to file");
                 return false;
             }
         }
     }
     //Update the display_config.php file to remove this source
     $modules_sources = array();
     require CONNECTOR_DISPLAY_CONFIG_FILE;
     foreach ($modules_sources as $module => $mapping) {
         foreach ($mapping as $id => $src) {
             if ($src == $source) {
                 unset($modules_sources[$module][$id]);
             }
         }
     }
     //Make the directory for the config file
     if (!file_exists('custom/modules/Connectors/metadata')) {
         mkdir_recursive('custom/modules/Connectors/metadata');
     }
     if (!write_array_to_file('modules_sources', $modules_sources, CONNECTOR_DISPLAY_CONFIG_FILE)) {
         //Log error and return empty array
         $GLOBALS['log']->fatal("Cannot write \$modules_sources to " . CONNECTOR_DISPLAY_CONFIG_FILE);
         return false;
     }
     //Remove from searchdefs
     $searchdefs = ConnectorUtils::getSearchDefs();
     if (!empty($searchdefs[$source])) {
         unset($searchdefs[$source]);
     }
     if (!write_array_to_file('searchdefs', $searchdefs, 'custom/modules/Connectors/metadata/searchdefs.php')) {
         $GLOBALS['log']->fatal("Cannot write file custom/modules/Connectors/metadata/searchdefs.php");
         return false;
     }
     return true;
 }