Пример #1
0
 /**
  * @see SugarView::display()
  */
 public function display()
 {
     $offset = -1;
     $modules = array();
     if (!empty($_REQUEST['zoom'])) {
         $modules = array($_REQUEST['zoom']);
         if (isset($_REQUEST['offset'])) {
             $offset = $_REQUEST['offset'];
         }
     }
     $limit = !empty($GLOBALS['sugar_config']['max_spotresults_initial']) ? $GLOBALS['sugar_config']['max_spotresults_initial'] : 5;
     if ($offset !== -1) {
         $limit = !empty($GLOBALS['sugar_config']['max_spotresults_more']) ? $GLOBALS['sugar_config']['max_spotresults_more'] : 20;
     }
     $options = array('current_module' => $this->module, 'modules' => $modules);
     $searchEngine = SugarSearchEngineFactory::getInstance('', array(), true);
     $trimmed_query = trim($_REQUEST['q']);
     $rs = $searchEngine->search($trimmed_query, $offset, $limit, $options);
     $formattedResults = $this->formatSearchResultsToDisplay($rs, $offset, $trimmed_query);
     $query_encoded = urlencode($trimmed_query);
     $displayMoreForModule = $formattedResults['displayMoreForModule'];
     $displayResults = $formattedResults['displayResults'];
     $ss = new Sugar_Smarty();
     $ss->assign('displayResults', $displayResults);
     $ss->assign('displayMoreForModule', $displayMoreForModule);
     $ss->assign('appStrings', $GLOBALS['app_strings']);
     $ss->assign('appListStrings', $GLOBALS['app_list_strings']);
     $ss->assign('queryEncoded', $query_encoded);
     $ss->assign('test', "#bwc/index.php?module=Home&action=UnifiedSearch&search_form=false&advanced=false&query_string=" . $query_encoded);
     echo $ss->fetch(SugarAutoLoader::existingCustomOne('include/SearchForm/tpls/SugarSpot.tpl'));
 }
Пример #2
0
function checkFTSSettings()
{
    installLog("Begining to check FTS Settings.");
    require_once 'include/SugarSearchEngine/SugarSearchEngineFactory.php';
    $searchEngine = SugarSearchEngineFactory::getInstance($_SESSION['setup_fts_type'], getFtsSettings());
    $status = $searchEngine->getServerStatus();
    installLog("FTS connection results: " . var_export($status, TRUE));
    return $status['valid'];
}
 protected function isFTSConnectionValid()
 {
     require_once 'include/SugarSearchEngine/SugarSearchEngineFactory.php';
     $searchEngine = SugarSearchEngineFactory::getInstance();
     $result = $searchEngine->getServerStatus();
     if ($result['valid']) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
 protected function isFTSConnectionValid()
 {
     $searchEngine = SugarSearchEngineFactory::getInstance();
     $result = $searchEngine->getServerStatus();
     if ($result['valid']) {
         $this->setFTSUp();
         return TRUE;
     } else {
         return FALSE;
     }
 }
 /**
  * @param string $data The job data set for this particular Scheduled Job instance
  * @return boolean true if the run succeeded; false otherwise
  */
 public function run($data)
 {
     $settings = Opportunity::getSettings();
     if (isset($settings['opps_view_by']) && $settings['opps_view_by'] !== 'Opportunities') {
         $GLOBALS['log']->fatal("Opportunity are being used with Revenue Line Items. " . __CLASS__ . " should not be running");
         return false;
     }
     $args = json_decode(html_entity_decode($data), true);
     $this->job->runnable_ran = true;
     $labels = $args['labels'];
     $data = $args['chunk'];
     $currencies = array();
     Activity::disable();
     // disable the fts index as well
     /* @var $ftsSearch SugarSearchEngineElastic */
     $ftsSearch = SugarSearchEngineFactory::getInstance();
     $ftsSearch->setForceAsyncIndex(true);
     foreach ($data as $opp_id => $rli_data) {
         /* @var $opp Opportunity */
         $opp = BeanFactory::getBean('Opportunities', $opp_id);
         /* @var $note Note */
         $note = BeanFactory::getBean('Notes');
         $note->parent_id = $opp_id;
         $note->parent_type = 'Opportunities';
         $note->assigned_user_id = $opp->assigned_user_id;
         $note->created_by = $opp->created_by;
         $note->name = 'Previous Associated Revenue Line Items';
         $desc = '';
         foreach ($rli_data as $rli) {
             $desc .= $rli['name'] . "\n";
             foreach ($rli as $field => $value) {
                 if (isset($labels[$field])) {
                     if ($field === 'currency_id') {
                         if (!isset($currencies[$value])) {
                             $currencies[$value] = SugarCurrency::getCurrencyByID($value);
                         }
                         $desc .= " - " . $labels[$field] . ": " . $currencies[$value]->name . "\n";
                     } elseif ($field !== 'name' && $field !== 'opportunity_id') {
                         $desc .= " - " . $labels[$field] . ": " . $value . "\n";
                     }
                 }
             }
             $desc .= "\n\n";
         }
         $note->description = trim($desc);
         $note->save();
     }
     // set it back to the default value from the config.
     $ftsSearch->setForceAsyncIndex(SugarConfig::getInstance()->get('search_engine.force_async_index', false));
     Activity::enable();
     $this->job->succeedJob();
     $this->notifyAssignedUser();
     return true;
 }
 /**
  * @param SugarSearchEngineAqbstractBase $engine
  */
 public function __construct(SugarSearchEngineAbstractBase $engine = null)
 {
     if ($engine != null) {
         $this->SSEngine = $engine;
     } else {
         $this->SSEngine = SugarSearchEngineFactory::getInstance();
     }
     $this->db = DBManagerFactory::getInstance('fts');
     $this->table_name = self::QUEUE_TABLE;
     $config = SugarConfig::getInstance();
     $this->max_bulk_threshold = $config->get('search_engine.max_bulk_threshold', $this->max_bulk_threshold);
     $this->max_bulk_query_threshold = $config->get('search_engine.max_bulk_query_threshold', $this->max_bulk_query_threshold);
     $this->max_bulk_delete_threshold = $config->get('search_engine.max_bulk_delete_threshold', $this->max_bulk_delete_threshold);
     $this->postpone_job_time = $config->get('search_engine.postpone_job_time', $this->postpone_job_time);
 }
 /**
  * @param $bean
  * @param $event
  * @param $args
  */
 function populateIndexQueue($bean, $event, $args)
 {
     $GLOBALS['log']->info("Adding the following bean to the populate queue- module: {$bean->object_name} , id: {$bean->id}");
     require_once 'include/SugarSearchEngine/SugarSearchEngineFactory.php';
     $searchEngine = SugarSearchEngineFactory::getInstance();
     /**
      * Due to the inability to update a documents fields when the field type is array
      * we need to reindex the entire bean.
      */
     if ($bean instanceof SugarFavorites) {
         $new_bean = BeanFactory::getBean($bean->module, $bean->record_id);
         $searchEngine->indexBean($new_bean, FALSE);
     } else {
         $searchEngine->indexBean($bean, FALSE);
     }
 }
 /**
  * @param $data
  * @return bool
  */
 public function run($data)
 {
     $this->job->runnable_ran = true;
     $this->job->runnable_data = $data;
     $data = json_decode($data, true);
     Activity::disable();
     $ftsInstance = SugarSearchEngineFactory::getInstance();
     $ftsInstance->setForceAsyncIndex(true);
     foreach ($data as $row) {
         /* @var $opp Opportunity */
         $opp = BeanFactory::getBean('Opportunities', $row['id']);
         $opp->save(false);
     }
     $ftsInstance->setForceAsyncIndex(SugarConfig::getInstance()->get('search_engine.force_async_index', false));
     Activity::enable();
     $this->job->succeedJob();
     $this->notifyAssignedUser();
     return true;
 }
Пример #9
0
 public function run()
 {
     global $sugar_config;
     $ftsConfig = isset($sugar_config['full_text_engine']) ? $sugar_config['full_text_engine'] : null;
     // Check that Elastic info is set (only currently supported search engine)
     if (empty($ftsConfig) || empty($ftsConfig['Elastic']) || empty($ftsConfig['Elastic']['host']) || empty($ftsConfig['Elastic']['port'])) {
         // error implies fail
         $this->error('Elastic Full Text Search engine needs to be configured on this Sugar instance prior to upgrade.');
         $this->error('Access Full Text Search configuration under Administration > Search.');
     } else {
         // Test Elastic FTS connection
         require_once 'include/SugarSearchEngine/SugarSearchEngineFactory.php';
         $searchEngine = SugarSearchEngineFactory::getInstance('Elastic', $ftsConfig['Elastic']);
         $status = $this->getServerStatusElastic($searchEngine, $ftsConfig['Elastic']);
         if (!$status['valid']) {
             $this->error('Connection test for Elastic Full Text Search engine failed.  Check your FTS configuration.');
             $this->error('Access Full Text Search configuration under Administration > Search.');
         }
     }
 }
Пример #10
0
 /**
  * This function is the global search
  * @param $api ServiceBase The API class of the request
  * @param $args array The arguments array passed in from the API
  * @return array result set
  */
 public function globalSearch(ServiceBase $api, array $args)
 {
     $api->action = 'list';
     require_once 'include/SugarSearchEngine/SugarSearchEngineFactory.php';
     // This is required to keep the loadFromRow() function in the bean from making our day harder than it already is.
     $GLOBALS['disable_date_format'] = true;
     $options = $this->parseSearchOptions($api, $args);
     // determine the correct serach engine, don't pass any configs and fallback to the default search engine if the determiend one is down
     $searchEngine = SugarSearchEngineFactory::getInstance($this->determineSugarSearchEngine($api, $args, $options), array(), false);
     if ($searchEngine instanceof SugarSearchEngine) {
         $options['resortResults'] = true;
         $recordSet = $this->globalSearchSpot($api, $args, $searchEngine, $options);
         $sortByDateModified = true;
     } else {
         $recordSet = $this->globalSearchFullText($api, $args, $searchEngine, $options);
         $sortByDateModified = false;
     }
     return $recordSet;
 }
Пример #11
0
 /**
  * action_saveglobalsearchsettings
  *
  * This method handles saving the selected modules to display in the Global Search Settings.
  * It instantiates an instance of UnifiedSearchAdvanced and then calls the saveGlobalSearchSettings
  * method.
  *
  */
 public function action_saveglobalsearchsettings()
 {
     global $current_user, $app_strings;
     if (!is_admin($current_user)) {
         sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']);
     }
     try {
         require_once 'modules/Home/UnifiedSearchAdvanced.php';
         $unifiedSearchAdvanced = new UnifiedSearchAdvanced();
         $unifiedSearchAdvanced->saveGlobalSearchSettings();
         //Save FTS Settings
         $type = !empty($_REQUEST['type']) ? $_REQUEST['type'] : '';
         $host = !empty($_REQUEST['host']) ? $_REQUEST['host'] : '';
         $port = !empty($_REQUEST['port']) ? $_REQUEST['port'] : '';
         $ftsConfig = $this->mergeFtsConfig($type, array('port' => $port, 'host' => $host));
         $this->cfg = new Configurator();
         $this->cfg->config['full_text_engine'] = '';
         $this->cfg->saveConfig();
         $ftsConnectionValid = TRUE;
         if (!empty($type)) {
             //Check if the connection is valid on save:
             require_once 'include/SugarSearchEngine/SugarSearchEngineFactory.php';
             $searchEngine = SugarSearchEngineFactory::getInstance($type, $ftsConfig);
             $result = $searchEngine->getServerStatus();
             if (!$result['valid']) {
                 $ftsConnectionValid = FALSE;
             }
             // bug 54274 -- only bother with an override if we have data to place there, empty string breaks Sugar On-Demand!
             $ftsConfig['valid'] = $ftsConnectionValid;
             $this->cfg->config['full_text_engine'] = array($type => $ftsConfig);
             $this->cfg->handleOverride();
         }
         // Refresh the server info & module list sections of the metadata
         MetaDataManager::refreshSectionCache(array(MetaDataManager::MM_SERVERINFO, MetaDataManager::MM_MODULES));
         if (!$ftsConnectionValid) {
             echo $GLOBALS['mod_strings']['LBL_FTS_CONNECTION_INVALID'];
         } else {
             echo "true";
         }
     } catch (Exception $ex) {
         echo "false";
     }
 }
 /**
  * Process the chunks of opportunities to create related Revenue Line Items
  *
  * - This always sets commit_stage to empty since forecasts is not setup any more.
  *
  * @param array $data
  */
 public static function processOpportunityIds(array $data)
 {
     Activity::disable();
     // disable the fts index as well
     /* @var $ftsSearch SugarSearchEngineElastic */
     $ftsSearch = SugarSearchEngineFactory::getInstance();
     $ftsSearch->setForceAsyncIndex(true);
     foreach ($data as $db_opp) {
         /* @var $opp Opportunity */
         $opp = BeanFactory::getBean('Opportunities', $db_opp['id']);
         if ($opp->id === $db_opp['id']) {
             /* @var $rli RevenueLineItem */
             $rli = BeanFactory::getBean('RevenueLineItems');
             $rli->update_modified_by = false;
             $rli->set_created_by = false;
             $rli->name = $opp->name;
             $rli->best_case = $opp->best_case;
             $rli->likely_case = $opp->amount;
             $rli->worst_case = $opp->worst_case;
             $rli->cost_price = $opp->amount;
             $rli->quantity = 1;
             $rli->currency_id = $opp->currency_id;
             $rli->base_rate = $opp->base_rate;
             $rli->probability = $opp->probability;
             $rli->date_closed = $opp->date_closed;
             $rli->date_closed_timestamp = $opp->date_closed_timestamp;
             $rli->assigned_user_id = $opp->assigned_user_id;
             $rli->modified_user_id = $opp->modified_user_id;
             $rli->modified_by_name = $opp->modified_by_name;
             $rli->created_by = $opp->created_by;
             $rli->created_by_name = $opp->created_by_name;
             $rli->account_id = $opp->account_id;
             $rli->commit_stage = '';
             $rli->sales_stage = $opp->sales_stage;
             $rli->deleted = $opp->deleted;
             $rli->save();
             // set the relationship up correctly
             $rli->load_relationship('opportunities');
             $rli->opportunities->add($opp->id);
         }
     }
     // set it back to the default value from the config.
     $ftsSearch->setForceAsyncIndex(SugarConfig::getInstance()->get('search_engine.force_async_index', false));
     Activity::enable();
 }
Пример #13
0
 /**
  * This function should be overridden in each module.  It marks an item as deleted.
  *
  * If it is not overridden, then marking this type of item is not allowed
  */
 public function mark_deleted($id)
 {
     global $current_user;
     $date_modified = $GLOBALS['timedate']->nowDb();
     if (isset($_SESSION['show_deleted'])) {
         $this->mark_undeleted($id);
     } else {
         // Ensure that Activity Messages do not occur in the context of a Delete action (e.g. unlink)
         // and do so for all nested calls within the Top Level Delete Context
         $opflag = static::enterOperation('delete');
         $aflag = Activity::isEnabled();
         Activity::disable();
         // call the custom business logic
         $custom_logic_arguments['id'] = $id;
         $this->call_custom_logic("before_delete", $custom_logic_arguments);
         $this->deleted = 1;
         $this->mark_relationships_deleted($id);
         if (isset($this->field_defs['modified_user_id'])) {
             if (!empty($current_user)) {
                 $this->modified_user_id = $current_user->id;
             } else {
                 $this->modified_user_id = 1;
             }
             $query = "UPDATE {$this->table_name} set deleted=1, date_modified = '{$date_modified}',\n                            modified_user_id = '{$this->modified_user_id}' where id='{$id}'";
             if ($this->isFavoritesEnabled()) {
                 SugarFavorites::markRecordDeletedInFavorites($id, $date_modified, $this->modified_user_id);
             }
         } else {
             $query = "UPDATE {$this->table_name} set deleted=1 , date_modified = '{$date_modified}' where id='{$id}'";
             if ($this->isFavoritesEnabled()) {
                 SugarFavorites::markRecordDeletedInFavorites($id, $date_modified);
             }
         }
         $this->db->query($query, true, "Error marking record deleted: ");
         // Take the item off the recently viewed lists
         $tracker = BeanFactory::getBean('Trackers');
         $tracker->makeInvisibleForAll($id);
         require_once 'include/SugarSearchEngine/SugarSearchEngineFactory.php';
         $searchEngine = SugarSearchEngineFactory::getInstance();
         $searchEngine->delete($this);
         SugarRelationship::resaveRelatedBeans();
         // call the custom business logic
         $this->call_custom_logic("after_delete", $custom_logic_arguments);
         if (static::leaveOperation('delete', $opflag) && $aflag) {
             Activity::enable();
         }
     }
 }
Пример #14
0
 function fetch($ac = false)
 {
     $fv = new FieldViewer();
     if (empty($_REQUEST['field']) && !empty($_REQUEST['name'])) {
         $_REQUEST['field'] = $_REQUEST['name'];
     }
     $field_name = '';
     if (!empty($this->view_object_map['field_name'])) {
         $field_name = $this->view_object_map['field_name'];
     } elseif (!empty($_REQUEST['field'])) {
         $field_name = $_REQUEST['field'];
     }
     // If this is a new field mark it as such
     $isNew = empty($field_name) || !empty($_REQUEST['is_new']);
     $action = 'saveField';
     // tyoung bug 17606: default action is to save as a dynamic field; but for standard OOB
     // fields we override this so don't create a new dynamic field instead of updating the existing field
     $isClone = false;
     if (!empty($this->view_object_map['is_clone']) && $this->view_object_map['is_clone'] && strcmp($field_name, "name") != 0) {
         $isClone = true;
     }
     /*
     $field_types =  array('varchar'=>'YourField', 'int'=>'Integer', 'float'=>'Decimal','bool'=>'Checkbox','enum'=>'DropDown',
     		'date'=>'Date', 'phone' => 'Phone', 'currency' => 'Currency', 'html' => 'HTML', 'radioenum' => 'Radio',
     		'relate' => 'Relate', 'address' => 'Address', 'text' => 'TextArea', 'url' => 'Link');
     */
     $field_types = $GLOBALS['mod_strings']['fieldTypes'];
     //bug 22264: Field name must not be an SQL keyword.
     $field_name_exceptions = array_merge(array_keys($GLOBALS['db']->getReservedWords()), array('ID', 'ID_C', 'PARENT_NAME', 'PARENT_ID'));
     //C.L. - Add support to mark related module id columns as reserved keywords
     require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
     $relatedModules = array_keys(DeployedRelationships::findRelatableModules());
     global $beanList, $current_language;
     foreach ($relatedModules as $relModule) {
         if (isset($beanList[$relModule])) {
             $field_name_exceptions[] = strtoupper($beanList[$relModule]) . '_ID';
         }
     }
     if (empty($_REQUEST['view_package']) || $_REQUEST['view_package'] == 'studio') {
         $moduleName = $_REQUEST['view_module'];
         $objectName = BeanFactory::getObjectName($moduleName);
         $module = BeanFactory::getBean($moduleName);
         VardefManager::loadVardef($moduleName, $objectName, true);
         global $dictionary;
         if (empty($module->mbvardefs)) {
             $module->mbvardefs = new stdClass();
         }
         $module->mbvardefs->vardefs = $dictionary[$objectName];
         $module->name = $moduleName;
         if (!$ac) {
             $ac = new AjaxCompose();
         }
         $vardef = !empty($module->mbvardefs->vardefs['fields'][$field_name]) ? $module->mbvardefs->vardefs['fields'][$field_name] : array();
         if ($isClone) {
             unset($vardef['name']);
         }
         // If this is a new field but we are loading this form a second time,
         // like from coming back from a dropdown create on a new field, then
         // keep the 'name' field open to allow the create field process to
         // continue like normal
         if (empty($vardef['name']) || $isNew) {
             if (!empty($_REQUEST['type'])) {
                 $vardef['type'] = $_REQUEST['type'];
             }
             $fv->ss->assign('hideLevel', 0);
         } elseif (isset($vardef['custom_module'])) {
             $fv->ss->assign('hideLevel', 2);
         } else {
             $action = 'saveSugarField';
             // tyoung - for OOB fields we currently only support modifying the label
             $fv->ss->assign('hideLevel', 3);
         }
         if ($isClone && isset($vardef['type']) && $vardef['type'] == 'datetime') {
             $vardef['type'] = 'datetimecombo';
         }
         require_once 'modules/DynamicFields/FieldCases.php';
         $tf = get_widget(empty($vardef['type']) ? "" : $vardef['type']);
         $tf->module = $module;
         $tf->populateFromRow($vardef);
         $vardef = array_merge($vardef, $tf->get_field_def());
         //          $GLOBALS['log']->debug('vardefs after loading = '.print_r($vardef,true));
         //Check if autoincrement fields are allowed
         $allowAutoInc = true;
         $enumFields = array();
         foreach ($module->field_defs as $field => $def) {
             if (!empty($def['type']) && $def['type'] == "int" && !empty($def['auto_increment'])) {
                 $allowAutoInc = false;
                 continue;
             }
             if (!empty($def['type']) && $def['type'] == "enum" && $field != $vardef['name']) {
                 if (!empty($def['studio']) && $def['studio'] == "false") {
                     continue;
                 }
                 //bug51866
                 $enumFields[$field] = translate($def['vname'], $moduleName);
                 if (substr($enumFields[$field], -1) == ":") {
                     $enumFields[$field] = substr($enumFields[$field], 0, strlen($enumFields[$field]) - 1);
                 }
             }
         }
         $fv->ss->assign('allowAutoInc', $allowAutoInc);
         $GLOBALS['log']->warn('view.modulefield: hidelevel ' . $fv->ss->get_template_vars('hideLevel') . " " . print_r($vardef, true));
         if (!empty($vardef['vname'])) {
             $fv->ss->assign('lbl_value', htmlentities(translate($vardef['vname'], $moduleName), ENT_QUOTES, 'UTF-8'));
         }
         $fv->ss->assign('module', $module);
         if (empty($module->mbvardefs->vardefs['fields']['parent_name']) || isset($vardef['type']) && $vardef['type'] == 'parent') {
             $field_types['parent'] = $GLOBALS['mod_strings']['parent'];
         }
         $edit_or_add = 'editField';
     } else {
         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
         $mb = new ModuleBuilder();
         $moduleName = $_REQUEST['view_module'];
         $module =& $mb->getPackageModule($_REQUEST['view_package'], $moduleName);
         $package =& $mb->packages[$_REQUEST['view_package']];
         $module->getVardefs();
         if (!$ac) {
             $ac = new AjaxCompose();
         }
         $vardef = !empty($module->mbvardefs->vardefs['fields'][$field_name]) ? $module->mbvardefs->vardefs['fields'][$field_name] : array();
         if ($isClone) {
             unset($vardef['name']);
         }
         if (empty($vardef['name'])) {
             if (!empty($_REQUEST['type'])) {
                 $vardef['type'] = $_REQUEST['type'];
             }
             $fv->ss->assign('hideLevel', 0);
         } else {
             if (!empty($module->mbvardefs->vardef['fields'][$vardef['name']])) {
                 $fv->ss->assign('hideLevel', 1);
             } elseif (isset($vardef['custom_module'])) {
                 $fv->ss->assign('hideLevel', 2);
             } else {
                 $fv->ss->assign('hideLevel', 3);
                 // tyoung bug 17350 - effectively mark template derived fields as readonly
             }
         }
         require_once 'modules/DynamicFields/FieldCases.php';
         $tf = get_widget(empty($vardef['type']) ? "" : $vardef['type']);
         $tf->module = $module;
         $tf->populateFromRow($vardef);
         $vardef = array_merge($vardef, $tf->get_field_def());
         $fv->ss->assign('module', $module);
         $fv->ss->assign('package', $package);
         $fv->ss->assign('MB', '1');
         if (isset($vardef['vname'])) {
             $fv->ss->assign('lbl_value', htmlentities($module->getLabel('en_us', $vardef['vname']), ENT_QUOTES, 'UTF-8'));
         }
         if (empty($module->mbvardefs->vardefs['fields']['parent_name']) || isset($vardef['type']) && $vardef['type'] == 'parent') {
             $field_types['parent'] = $GLOBALS['mod_strings']['parent'];
         }
         $enumFields = array();
         if (!empty($module->mbvardefs->vardefs['fields'])) {
             foreach ($module->mbvardefs->vardefs['fields'] as $field => $def) {
                 if (!empty($def['type']) && $def['type'] == "enum" && $field != $vardef['name']) {
                     $enumFields[$field] = isset($module->mblanguage->strings[$current_language][$def['vname']]) ? $this->mbModule->mblanguage->strings[$current_language][$def['vname']] : translate($field);
                     if (substr($enumFields[$field], -1) == ":") {
                         $enumFields[$field] = substr($enumFields[$field], 0, strlen($enumFields[$field]) - 1);
                     }
                 }
             }
         }
         $edit_or_add = 'mbeditField';
     }
     if ($_REQUEST['action'] == 'RefreshField') {
         require_once 'modules/DynamicFields/FieldCases.php';
         $field = get_widget($_POST['type']);
         $field->populateFromPost();
         $vardef = $field->get_field_def();
         $vardef['options'] = $_REQUEST['new_dropdown'];
         $fv->ss->assign('lbl_value', htmlentities($_REQUEST['labelValue'], ENT_QUOTES, 'UTF-8'));
     }
     foreach (array("formula", "default", "comments", "help", "visiblityGrid") as $toEscape) {
         if (!empty($vardef[$toEscape]) && is_string($vardef[$toEscape])) {
             $vardef[$toEscape] = htmlentities($vardef[$toEscape], ENT_QUOTES, 'UTF-8');
         }
     }
     if (!empty($vardef['studio']['no_duplicate']) || $field_name === 'name' || $field_name === 'parent_type' || $field_name === 'parent_id' || $field_name === 'parent_name' || isset($vardef['type']) && $vardef['type'] === 'name') {
         $fv->ss->assign('no_duplicate', true);
     }
     $fv->ss->assign('action', $action);
     $fv->ss->assign('isClone', $isClone ? 1 : 0);
     $fv->ss->assign('isNew', $isNew);
     $fv->ss->assign("module_dd_fields", $enumFields);
     $json = getJSONobj();
     $fv->ss->assign('field_name_exceptions', $json->encode($field_name_exceptions));
     ksort($field_types);
     $fv->ss->assign('field_types', $field_types);
     $ftsEngineType = getFTSEngineType();
     $usa = new UnifiedSearchAdvanced();
     if (SugarSearchEngineFactory::getInstance()->isTypeFtsEnabled($vardef['type']) && (!empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio' || $usa->shouldShowModule($moduleName))) {
         $ftsBoostOptions = getFTSBoostOptions($ftsEngineType . '_boost_options');
         $fv->ss->assign('fts_options', $ftsBoostOptions);
         $fv->ss->assign('show_fts', true);
     } else {
         $fv->ss->assign('show_fts', false);
     }
     //Ensure certain field types always have correct formula return types for validation.
     if (!empty($vardef['type'])) {
         switch ($vardef['type']) {
             case 'date':
             case 'datetime':
                 $fv->ss->assign('calcFieldType', 'date');
                 break;
             case 'bool':
                 $fv->ss->assign('calcFieldType', 'boolean');
                 break;
             default:
                 $fv->ss->assign('calcFieldType', '');
                 break;
         }
     }
     $fv->ss->assign('importable_options', $GLOBALS['app_list_strings']['custom_fields_importable_dom']);
     $fv->ss->assign('duplicate_merge_options', $GLOBALS['app_list_strings']['custom_fields_merge_dup_dom']);
     $triggers = array();
     $existing_field_names = array();
     foreach ($module->mbvardefs->vardefs['fields'] as $field) {
         if ($field['type'] == 'enum' || $field['type'] == 'multienum') {
             $triggers[] = $field['name'];
         }
         if (!isset($field['source']) || $field['source'] != 'non-db') {
             if (preg_match('/^(.*?)(_c)?$/', $field['name'], $matches)) {
                 $existing_field_names[] = strtoupper($matches[1]);
             }
         }
     }
     $fv->ss->assign('triggers', $triggers);
     $fv->ss->assign('existing_field_names', $json->encode($existing_field_names));
     $fv->ss->assign('mod_strings', $GLOBALS['mod_strings']);
     // jchi #24880
     if (!isset($vardef['reportable'])) {
         $vardef['reportable'] = 1;
     }
     // end
     $layout = $fv->getLayout($vardef);
     $fv->ss->assign('fieldLayout', $layout);
     if (empty($vardef['type'])) {
         $vardef['type'] = 'varchar';
     }
     $fv->ss->assign('vardef', $vardef);
     if (empty($_REQUEST['field'])) {
         $edit_or_add = 'addField';
     }
     $fv->ss->assign('help_group', $edit_or_add);
     $body = $this->fetchTemplate($fv, 'modules/ModuleBuilder/tpls/MBModule/field.tpl');
     $ac->addSection('east', translate('LBL_SECTION_FIELDEDITOR', 'ModuleBuilder'), $body);
     return $ac;
 }
Пример #15
0
// Enable the InsideView connector and add all modules
installLog("Enable InsideView Connector");
enableInsideViewConnector();
**/
///////////////////////////////////////////////////////////////////////////////
////    START DEMO DATA
/*
 * Enable asynchronous index mode before adding demo data. At this point
 * the ES idex has not been initialized yet. The demo data loader uses
 * SugarBean->save() which automatically triggers an inline index of each
 * object. This is pointless as we want to take care of this in bulk
 * during the intial full indexer run. This will also speed up the install
 * process significantly and avoids ES errors when dyamic update is
 * disabled on the ES cluster itself.
 */
$sse = SugarSearchEngineFactory::getInstance();
$sse->setForceAsyncIndex(true);
// populating the db with seed data
installLog("populating the db with seed data");
if ($_SESSION['demoData'] != 'no') {
    installerHook('pre_installDemoData');
    set_time_limit(301);
    echo "<br>";
    echo "<b>{$mod_strings['LBL_PERFORM_DEMO_DATA']}</b>";
    echo "<br><br>";
    print $render_table_close;
    print $render_table_open;
    global $current_user;
    $current_user = new User();
    $current_user->retrieve(1);
    include "install/populateSeedData.php";
Пример #16
0
 /**
  * @see SugarView::display()
  */
 public function display($return = false, $encode = false)
 {
     $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0;
     $resultSetOnly = !empty($_REQUEST['rs_only']) ? $_REQUEST['rs_only'] : FALSE;
     $refreshModuleFilter = !empty($_REQUEST['refreshModList']) ? $_REQUEST['refreshModList'] : FALSE;
     $limit = !empty($GLOBALS['sugar_config']['max_spotresults_initial']) ? $GLOBALS['sugar_config']['max_spotresults_initial'] : 10;
     $indexOffset = $offset / $limit;
     $moduleFilter = !empty($_REQUEST['m']) ? $_REQUEST['m'] : false;
     if (!empty($moduleFilter) && is_scalar($moduleFilter)) {
         $moduleFilter = str_getcsv($moduleFilter);
     }
     $disabledModules = !empty($_REQUEST['disabled_modules']) ? str_getcsv($_REQUEST['disabled_modules']) : array();
     //If no modules have been passed in then lets check user preferences.
     if ($moduleFilter === false) {
         $moduleFilter = SugarSearchEngineMetadataHelper::getUserEnabledFTSModules();
     }
     $filteredModules = $this->getFilterModules($moduleFilter, $disabledModules);
     $append_wildcard = !empty($_REQUEST['append_wildcard']) ? $_REQUEST['append_wildcard'] : false;
     $options = array('current_module' => $this->module, 'moduleFilter' => $moduleFilter, 'append_wildcard' => $append_wildcard);
     if ($this->fullView || $refreshModuleFilter) {
         $options['apply_module_facet'] = TRUE;
     }
     $searchEngine = SugarSearchEngineFactory::getInstance();
     $queryString = !empty($_REQUEST['q']) ? $_REQUEST['q'] : '';
     $trimmed_query = trim($queryString);
     $rs = $searchEngine->search($trimmed_query, $offset, $limit, $options);
     if ($rs == null) {
         $totalHitsFound = 0;
         $totalTime = 0;
         $hitsByModule = array();
     } else {
         $totalHitsFound = $rs->getTotalHits();
         $totalTime = $rs->getTotalTime();
         $hitsByModule = $rs->getModuleFacet();
     }
     $query_encoded = urlencode($trimmed_query);
     if (count($filteredModules['enabled']) != count($moduleFilter)) {
         // if there is a full module list we need to check "Show all"
         $this->ss->assign('moduleFilter', $moduleFilter);
     }
     $showMoreDivStyle = $totalHitsFound > $limit ? '' : "display:none;";
     $this->ss->assign('showMoreDivStyle', $showMoreDivStyle);
     $this->ss->assign('indexOffset', $indexOffset);
     $this->ss->assign('offset', $offset);
     $this->ss->assign('limit', $limit);
     $this->ss->assign('totalHits', $totalHitsFound);
     $this->ss->assign('totalTime', $totalTime);
     $this->ss->assign('queryEncoded', $query_encoded);
     $this->ss->assign('resultSet', $rs);
     $this->ss->assign('APP_LIST', $GLOBALS['app_list_strings']);
     $template = SugarAutoLoader::existingCustomOne("include/MVC/View/tpls/{$this->templateName}");
     $rsTemplate = SugarAutoLoader::existingCustomOne("include/MVC/View/tpls/{$this->rsTemplateName}");
     $this->ss->assign('rsTemplate', $rsTemplate);
     if ($this->fullView) {
         $this->ss->assign('filterModules', $this->filterModuleListByTypes($filteredModules['enabled'], $hitsByModule, $moduleFilter));
         if ($resultSetOnly) {
             $out = array('results' => $this->ss->fetch($rsTemplate), 'totalHits' => $totalHitsFound, 'totalTime' => $totalTime);
             if ($refreshModuleFilter) {
                 $out['mod_filter'] = $this->ss->fetch('include/MVC/View/tpls/fts_modfilter.tpl');
             }
             return $this->sendOutput(json_encode($out));
         }
         $this->ss->assign('enabled_modules', json_encode($filteredModules['enabled']));
         $this->ss->assign('disabled_modules', json_encode($filteredModules['disabled']));
     }
     $contents = $this->ss->fetch($template);
     return $this->sendOutput($contents, $return, $encode);
 }
Пример #17
0
 public function action_spot()
 {
     require_once 'include/SugarSearchEngine/SugarSearchEngineFactory.php';
     $searchEngine = SugarSearchEngineFactory::getInstance('', array(), true);
     //Default db search will be handled by the spot view, everything else by fts.
     if ($searchEngine instanceof SugarSearchEngine) {
         $this->view = 'spot';
     } else {
         $this->view = 'fts';
     }
 }
Пример #18
0
 /**
  * Get global search provider
  *
  * @return SugarSearchEngineElastic $engine
  */
 protected function getEngine()
 {
     $searchEngine = SugarSearchEngineFactory::getInstance();
     if ($searchEngine instanceof SugarSearchEngineElastic) {
         return $searchEngine;
     }
 }
Пример #19
0
 protected function performSearch(ServiceBase $api, $args, SugarBean $seed, $searchTerm, $options)
 {
     require_once 'include/SugarSearchEngine/SugarSearchEngineFactory.php';
     $searchEngine = SugarSearchEngineFactory::getInstance();
     //Default db search will be handled by the spot view, everything else by fts.
     if ($searchEngine instanceof SugarSearchEngine) {
     }
 }
Пример #20
0
 /**
  * Toggle Favorites
  * @param SugarBean $module
  * @param type $favorite
  * @return bool
  */
 protected function toggleFavorites($bean, $favorite)
 {
     $reindexBean = false;
     $favorite = (bool) $favorite;
     $module = $bean->module_dir;
     $record = $bean->id;
     $fav_id = SugarFavorites::generateGUID($module, $record);
     // get it even if its deleted
     $fav = BeanFactory::getBean('SugarFavorites', $fav_id, array("deleted" => false));
     // already exists
     if (!empty($fav->id)) {
         $deleted = $favorite ? 0 : 1;
         $fav->toggleExistingFavorite($fav_id, $deleted);
         $reindexBean = true;
     } elseif ($favorite && empty($fav->id)) {
         $fav = BeanFactory::getBean('SugarFavorites');
         $fav->id = $fav_id;
         $fav->new_with_id = true;
         $fav->module = $module;
         $fav->record_id = $record;
         $fav->created_by = $GLOBALS['current_user']->id;
         $fav->assigned_user_id = $GLOBALS['current_user']->id;
         $fav->deleted = 0;
         $fav->save();
     }
     $bean->my_favorite = $favorite;
     // Bug59888 - If a Favorite is toggled, we need to reindex the bean for FTS engines so that the document will be updated with this change
     if ($reindexBean === true) {
         $searchEngine = SugarSearchEngineFactory::getInstance(SugarSearchEngineFactory::getFTSEngineNameFromConfig());
         if ($searchEngine instanceof SugarSearchEngineAbstractBase) {
             $searchEngine->indexBean($bean, false);
         }
     }
     return true;
 }
Пример #21
0
 /**
  * Executes the massupdate form
  * @param displayname Name to display in the popup window
  * @param varname name of the variable
  */
 function handleMassUpdate($fetch_only = false, $update_blank = false)
 {
     require_once 'include/formbase.php';
     global $current_user, $db, $disable_date_format, $timedate;
     $retval = array();
     foreach ($_POST as $post => $value) {
         if (is_array($value)) {
             if (empty($value)) {
                 unset($_POST[$post]);
             }
         } elseif (strlen($value) == 0) {
             if (!$update_blank) {
                 if (isset($this->sugarbean->field_defs[$post]) && $this->sugarbean->field_defs[$post]['type'] == 'radioenum' && isset($_POST[$post])) {
                     $_POST[$post] = '';
                 } else {
                     unset($_POST[$post]);
                 }
             }
         }
         if (is_string($value) && isset($this->sugarbean->field_defs[$post])) {
             if ($this->sugarbean->field_defs[$post]['type'] == 'bool' || !empty($this->sugarbean->field_defs[$post]['custom_type']) && $this->sugarbean->field_defs[$post]['custom_type'] == 'bool') {
                 if (strcmp($value, '2') == 0) {
                     $_POST[$post] = 0;
                 }
                 if (!empty($this->sugarbean->field_defs[$post]['dbType']) && strcmp($this->sugarbean->field_defs[$post]['dbType'], 'varchar') == 0) {
                     $_POST[$post] = strcmp($value, '1') == 0 ? 'on' : 'off';
                 }
             }
             if ($this->sugarbean->field_defs[$post]['type'] == 'radioenum' && isset($_POST[$post]) && strlen($value) == 0 || $this->sugarbean->field_defs[$post]['type'] == 'enum' && $value == '__SugarMassUpdateClearField__') {
                 $_POST[$post] = '';
             }
             if ($this->sugarbean->field_defs[$post]['type'] == 'bool') {
                 $this->checkClearField($post, $value);
             }
             if ($this->sugarbean->field_defs[$post]['type'] == 'date' && !empty($_POST[$post])) {
                 $_POST[$post] = $timedate->to_db_date($_POST[$post], false);
             }
             if ($this->sugarbean->field_defs[$post]['type'] == 'datetime' && !empty($_POST[$post])) {
                 $_POST[$post] = $timedate->to_db($this->date_to_dateTime($post, $value));
             }
             if ($this->sugarbean->field_defs[$post]['type'] == 'datetimecombo' && !empty($_POST[$post])) {
                 $_POST[$post] = $timedate->to_db($_POST[$post]);
             }
         }
     }
     //We need to disable_date_format so that date values for the beans remain in database format
     //notice we make this call after the above section since the calls to TimeDate class there could wind up
     //making it's way to the UserPreferences objects in which case we want to enable the global date formatting
     //to correctly retrieve the user's date format preferences
     $old_value = $disable_date_format;
     $disable_date_format = true;
     if (!empty($_REQUEST['uid']) && !isset($_REQUEST['entire'])) {
         $_POST['mass'] = explode(',', $_REQUEST['uid']);
     } elseif (isset($_REQUEST['entire']) && empty($_POST['mass'])) {
         if (empty($order_by)) {
             $order_by = '';
         }
         // TODO: define filter array here to optimize the query
         // by not joining the unneeded tables
         $query = $this->sugarbean->create_new_list_query($order_by, $this->where_clauses, array(), array(), 0, '', false, $this, true, true);
         $result = $db->query($query, true);
         $new_arr = array();
         while ($val = $db->fetchByAssoc($result, false)) {
             array_push($new_arr, $val['id']);
         }
         $_POST['mass'] = $new_arr;
     }
     if ($fetch_only) {
         return;
     }
     /*-- Is Request to Add or Delete  one or more Prospects from One or More Prospect Lists ?? --*/
     if (isset($_POST['mass']) && is_array($_POST['mass']) && (!empty($_POST['add_to_prospect_lists']) || !empty($_POST['remove_from_prospect_lists']))) {
         if (!empty($_POST['remove_from_prospect_lists'])) {
             $bean_name = $_POST['module'];
             $prospect_list_ids = explode(',', $_POST['remove_from_prospect_lists']);
             $uids = $_POST['mass'];
             if (count($uids) > 0 && count($prospect_list_ids) > 0) {
                 foreach ($prospect_list_ids as $prospect_list_id) {
                     $this->remove_prospects_from_prospect_list($bean_name, $prospect_list_id, $uids);
                 }
             }
         } else {
             if (!empty($_POST['add_to_prospect_lists'])) {
                 $bean_name = $_POST['module'];
                 $prospect_list_ids = explode(',', $_POST['add_to_prospect_lists']);
                 $uids = $_POST['mass'];
                 if (count($uids) > 0 && count($prospect_list_ids) > 0) {
                     foreach ($prospect_list_ids as $prospect_list_id) {
                         $this->add_prospects_to_prospect_list($bean_name, $prospect_list_id, $uids);
                     }
                 }
             }
         }
         return;
     }
     if (isset($_POST['mass']) && is_array($_POST['mass']) && $_REQUEST['massupdate'] == 'true') {
         $count = 0;
         if (isset($_SESSION['REASSIGN_TEAMS'])) {
             unset($_SESSION['REASSIGN_TEAMS']);
         }
         // should use 'User Type' to change this field
         if ($this->sugarbean->object_name == 'User' && isset($_POST['is_admin'])) {
             unset($_POST['is_admin']);
         }
         foreach ($_POST['mass'] as $id) {
             if (empty($id)) {
                 continue;
             }
             if (isset($_POST['Delete'])) {
                 $this->sugarbean->retrieve($id);
                 if ($this->sugarbean->ACLAccess('Delete')) {
                     if ($this->sugarbean->object_name == 'Team' && $this->sugarbean->has_records_in_modules()) {
                         if (!isset($_SESSION['REASSIGN_TEAMS'])) {
                             $_SESSION['REASSIGN_TEAMS'] = array();
                         }
                         $_SESSION['REASSIGN_TEAMS'][] = $this->sugarbean->id;
                         continue;
                     }
                     $this->sugarbean->mark_deleted($id);
                     // ideally we should use after_delete logic hook
                     require_once 'include/SugarSearchEngine/SugarSearchEngineFactory.php';
                     $searchEngine = SugarSearchEngineFactory::getInstance();
                     $searchEngine->delete($this->sugarbean);
                 } else {
                     $retval[] = $id;
                 }
             } else {
                 if ($this->sugarbean->object_name == 'Contact' && isset($_POST['Sync'])) {
                     // special for contacts module
                     if ($_POST['Sync'] == 'true') {
                         $this->sugarbean->retrieve($id);
                         if ($this->sugarbean->ACLAccess('Save')) {
                             if ($this->sugarbean->object_name == 'Contact') {
                                 $this->sugarbean->contacts_users_id = $current_user->id;
                                 $this->sugarbean->save(false);
                             }
                         }
                     } elseif ($_POST['Sync'] == 'false') {
                         $this->sugarbean->retrieve($id);
                         if ($this->sugarbean->ACLAccess('Save')) {
                             if ($this->sugarbean->object_name == 'Contact') {
                                 if (!isset($this->sugarbean->users)) {
                                     $this->sugarbean->load_relationship('user_sync');
                                 }
                                 $this->sugarbean->contacts_users_id = null;
                                 $this->sugarbean->user_sync->delete($this->sugarbean->id, $current_user->id);
                             }
                         }
                     }
                 }
                 //end if for special Contact handling
                 if ($count++ != 0) {
                     //Create a new instance to clear values and handle additional updates to bean's 2,3,4...
                     $this->sugarbean = $this->sugarbean->getCleanCopy();
                 }
                 $this->sugarbean->retrieve($id);
                 ////////////////////////
                 //IS USER OFFLINE CLIENT ENABLED
                 if ($this->sugarbean->object_name == 'User' && isset($_POST['oc_status'])) {
                     $this->sugarbean->setPreference('OfflineClientStatus', $_POST['oc_status']);
                 }
                 //
                 ////////////////////////
                 if ($this->sugarbean->ACLAccess('Save', array("massupdate" => true))) {
                     $_POST['record'] = $id;
                     $_GET['record'] = $id;
                     $_REQUEST['record'] = $id;
                     $newbean = $this->sugarbean;
                     // ACL check above should have blocked non-admin users
                     if ($newbean->object_name == 'User') {
                         //admin can't change his own status and user type
                         if ($current_user->id == $id && (isset($_POST['UserType']) || isset($_POST['status']))) {
                             continue;
                         }
                         if (isset($_POST['UserType'])) {
                             if ($_POST['UserType'] == "Administrator") {
                                 $newbean->is_admin = 1;
                             } else {
                                 if ($_POST['UserType'] == "RegularUser") {
                                     $newbean->is_admin = 0;
                                 }
                             }
                         }
                     }
                     $old_reports_to_id = null;
                     if (!empty($_POST['reports_to_id']) && $newbean->reports_to_id != $_POST['reports_to_id']) {
                         $old_reports_to_id = empty($newbean->reports_to_id) ? 'null' : $newbean->reports_to_id;
                     }
                     $check_notify = false;
                     if (isset($this->sugarbean->assigned_user_id)) {
                         $old_assigned_user_id = $this->sugarbean->assigned_user_id;
                         if (!empty($_POST['assigned_user_id']) && $old_assigned_user_id != $_POST['assigned_user_id'] && $_POST['assigned_user_id'] != $current_user->id) {
                             $check_notify = true;
                         }
                     }
                     //Call include/formbase.php, but do not call retrieve again
                     populateFromPost('', $newbean, true);
                     $newbean->save_from_post = false;
                     if (!isset($_POST['parent_id'])) {
                         $newbean->parent_type = null;
                     }
                     $email_address_id = '';
                     if (!empty($_POST['optout_primary'])) {
                         $optout_flag_value = 0;
                         if ($_POST['optout_primary'] == 'true') {
                             $optout_flag_value = 1;
                         }
                         // if
                         if (isset($this->sugarbean->emailAddress)) {
                             if (!empty($this->sugarbean->emailAddress->addresses)) {
                                 foreach ($this->sugarbean->emailAddress->addresses as $key => $emailAddressRow) {
                                     if ($emailAddressRow['primary_address'] == '1') {
                                         $email_address_id = $emailAddressRow['email_address_id'];
                                         break;
                                     }
                                     // if
                                 }
                                 // foreach
                             }
                             // if
                         }
                         // if
                     }
                     // if
                     $newbean->save($check_notify);
                     if (!empty($email_address_id)) {
                         $query = "UPDATE email_addresses SET opt_out = {$optout_flag_value} where id = '{$emailAddressRow['email_address_id']}'";
                         $GLOBALS['db']->query($query);
                     }
                     // if
                     if (!empty($old_reports_to_id) && method_exists($newbean, 'update_team_memberships')) {
                         $old_id = $old_reports_to_id == 'null' ? '' : $old_reports_to_id;
                         $newbean->update_team_memberships($old_id);
                     }
                 }
             }
         }
         if (isset($_SESSION['REASSIGN_TEAMS'])) {
             header("Location: index.php?module=Teams&action=ReassignTeams");
             die;
         }
     }
     $disable_date_format = $old_value;
     return $retval;
 }