Ejemplo n.º 1
1
 public function setUp()
 {
     global $beanList, $beanFiles;
     include 'include/modules.php';
     //Reload langauge strings
     $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
     $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
     $GLOBALS['mod_strings'] = return_module_language($GLOBALS['current_language'], 'Accounts');
     //Create an anonymous user for login purposes/
     $this->_user = new User();
     $this->_user->retrieve('1');
     $GLOBALS['current_user'] = $this->_user;
     self::$helperObject = new APIv3Helper();
     if (file_exists(sugar_cached('modules/unified_search_modules.php'))) {
         $this->unified_search_modules_content = file_get_contents(sugar_cached('modules/unified_search_modules.php'));
         unlink(sugar_cached('modules/unified_search_modules.php'));
     }
     require_once 'modules/Home/UnifiedSearchAdvanced.php';
     $unifiedSearchAdvanced = new UnifiedSearchAdvanced();
     $_REQUEST['enabled_modules'] = 'Accounts,Contacts,Opportunities';
     $unifiedSearchAdvanced->saveGlobalSearchSettings();
     $GLOBALS['db']->query("DELETE FROM accounts WHERE name like 'UNIT TEST%' ");
     $GLOBALS['db']->query("DELETE FROM opportunities WHERE name like 'UNIT TEST%' ");
     $GLOBALS['db']->query("DELETE FROM contacts WHERE first_name like 'UNIT TEST%' ");
     $GLOBALS['db']->query("DELETE FROM calls WHERE name like 'UNIT TEST%' ");
     $GLOBALS['db']->query("DELETE FROM tasks WHERE name like 'UNIT TEST%' ");
     $GLOBALS['db']->query("DELETE FROM meetings WHERE name like 'UNIT TEST%' ");
     //$this->useOutputBuffering = false;
 }
    /**
     * @see SugarView::display()
     */
    public function display()
    {
        global $mod_strings;
        echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr><td colspan="100"><h2>' . $this->getModuleTitle(false) . '</h2></td></tr><tr><td colspan="100">' . $mod_strings['LBL_GLOBAL_SEARCH_SETTINGS_TITLE'] . '</td></tr><tr><td><br></td></tr><tr><td colspan="100">';
        //echo $this->getModuleTitle();
        require_once 'modules/Home/UnifiedSearchAdvanced.php';
        $usa = new UnifiedSearchAdvanced();
        echo $usa->modifyGlobalSearchSettings();
    }
Ejemplo n.º 3
0
 public function testFisrtUnifiedSearchWithoutUserPreferences()
 {
     //Enable the Tasks, Accounts and Contacts modules
     require_once 'modules/Home/UnifiedSearchAdvanced.php';
     $_REQUEST = array();
     $_REQUEST['enabled_modules'] = 'Tasks,Accounts,Contacts';
     $unifiedSearchAdvanced = new UnifiedSearchAdvanced();
     $unifiedSearchAdvanced->saveGlobalSearchSettings();
     $_REQUEST = array();
     $_REQUEST['advanced'] = 'false';
     $unifiedSearchAdvanced->query_stirng = 'blah';
     $unifiedSearchAdvanced->search();
     global $current_user;
     $users_modules = $current_user->getPreference('globalSearch', 'search');
     $this->assertTrue(!empty($users_modules), 'Assert we have set the user preferences properly');
     $this->assertTrue(isset($users_modules['Tasks']), 'Assert that we have added the Tasks module');
     $this->assertEquals(count($users_modules), 3, 'Assert that we have 3 modules in user preferences for global search');
 }
Ejemplo n.º 4
0
 /**
  * @see SugarView::display()
  */
 public function display()
 {
     require_once 'modules/Home/UnifiedSearchAdvanced.php';
     $usa = new UnifiedSearchAdvanced();
     global $mod_strings, $app_strings, $app_list_strings;
     $sugar_smarty = new Sugar_Smarty();
     $sugar_smarty->assign('APP', $app_strings);
     $sugar_smarty->assign('MOD', $mod_strings);
     $sugar_smarty->assign('moduleTitle', $this->getModuleTitle(false));
     $modules = $usa->retrieveEnabledAndDisabledModules();
     $sugar_smarty->assign('enabled_modules', json_encode($modules['enabled']));
     $sugar_smarty->assign('disabled_modules', json_encode($modules['disabled']));
     $tpl = 'modules/Administration/templates/GlobalSearchSettings.tpl';
     if (file_exists('custom/' . $tpl)) {
         $tpl = 'custom/' . $tpl;
     }
     echo $sugar_smarty->fetch($tpl);
 }
Ejemplo n.º 5
0
 /**
  * @brief generation of new cache file and search for force_unifiedsearch fields in it
  * @group 42961
  */
 public function testBuildCache()
 {
     $beanList = array();
     $beanFiles = array();
     require 'include/modules.php';
     $GLOBALS['beanList'] = $beanList;
     $GLOBALS['beanFiles'] = $beanFiles;
     $unifiedSearchAdvanced = new UnifiedSearchAdvanced();
     $unifiedSearchAdvanced->buildCache();
     $this->assertFileExists($GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php', 'Here should be cache file with data');
     include $GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php';
     $force_unifiedsearch = 0;
     foreach ($unified_search_modules as $moduleName => $moduleInformation) {
         foreach ($moduleInformation['fields'] as $fieldName => $fieldInformation) {
             if (key_exists('force_unifiedsearch', $fieldInformation)) {
                 $force_unifiedsearch++;
             }
         }
     }
     $this->assertGreaterThan(0, $force_unifiedsearch, 'Here should be fields with force_unifiedsearch key');
 }
 /**
  * @see SugarView::display()
  */
 public function display()
 {
     require_once 'modules/Home/UnifiedSearchAdvanced.php';
     $usa = new UnifiedSearchAdvanced();
     global $mod_strings, $app_strings, $app_list_strings, $current_user;
     $sugar_smarty = new Sugar_Smarty();
     $sugar_smarty->assign('APP', $app_strings);
     $sugar_smarty->assign('MOD', $mod_strings);
     $sugar_smarty->assign('moduleTitle', $this->getModuleTitle(false));
     $modules = $usa->retrieveEnabledAndDisabledModules();
     $sugar_smarty->assign('enabled_modules', json_encode($modules['enabled']));
     $sugar_smarty->assign('disabled_modules', json_encode($modules['disabled']));
     $defaultEngine = SugarSearchEngineFactory::getFTSEngineNameFromConfig();
     $config = $GLOBALS['sugar_config']['full_text_engine'][$defaultEngine];
     $justRequestedAScheduledIndex = !empty($_REQUEST['sched']) ? true : false;
     $hide_fts_config = isset($GLOBALS['sugar_config']['hide_full_text_engine_config']) ? $GLOBALS['sugar_config']['hide_full_text_engine_config'] : false;
     $showSchedButton = $defaultEngine != '' && $this->isFTSConnectionValid() ? true : false;
     $sugar_smarty->assign("showSchedButton", $showSchedButton);
     $sugar_smarty->assign("hide_fts_config", $hide_fts_config);
     $sugar_smarty->assign("fts_type", get_select_options_with_id($app_list_strings['fts_type'], $defaultEngine));
     $sugar_smarty->assign("fts_host", $config['host']);
     $sugar_smarty->assign("fts_port", $config['port']);
     $sugar_smarty->assign("fts_scheduled", !empty($schedulerID) && !$schedulerCompleted);
     $sugar_smarty->assign('justRequestedAScheduledIndex', $justRequestedAScheduledIndex);
     //End FTS
     if (is_admin($current_user)) {
         if (!empty($GLOBALS['sugar_config']['fts_disable_notification'])) {
             displayAdminError(translate('LBL_FTS_DISABLED', 'Administration'));
         }
         // if fts indexing is done, show the notification to admin
         $admin = Administration::getSettings();
         if (!empty($admin->settings['info_fts_index_done'])) {
             displayAdminError(translate('LBL_FTS_INDEXING_DONE', 'Administration'));
             // reset flag
             $admin->saveSetting('info', 'fts_index_done', 0);
         }
     }
     echo $sugar_smarty->fetch(SugarAutoLoader::existingCustomOne('modules/Administration/templates/GlobalSearchSettings.tpl'));
 }
Ejemplo n.º 7
0
 public function setUp()
 {
     //Create an anonymous user for login purposes/
     $this->_user = SugarTestUserUtilities::createAnonymousUser();
     $GLOBALS['current_user'] = $this->_user;
     self::$helperObject = new APIv3Helper();
     if (file_exists(sugar_cached('modules/unified_search_modules.php'))) {
         $this->unified_search_modules_content = file_get_contents(sugar_cached('modules/unified_search_modules.php'));
         unlink(sugar_cached('modules/unified_search_modules.php'));
     }
     require_once 'modules/Home/UnifiedSearchAdvanced.php';
     $unifiedSearchAdvanced = new UnifiedSearchAdvanced();
     $_REQUEST['enabled_modules'] = 'Accounts,Contacts,Opportunities';
     $unifiedSearchAdvanced->saveGlobalSearchSettings();
     $GLOBALS['db']->query("DELETE FROM accounts WHERE name like 'UNIT TEST%' ");
     $GLOBALS['db']->query("DELETE FROM opportunities WHERE name like 'UNIT TEST%' ");
     $GLOBALS['db']->query("DELETE FROM contacts WHERE first_name like 'UNIT TEST%' ");
     $GLOBALS['db']->query("DELETE FROM calls WHERE name like 'UNIT TEST%' ");
     $GLOBALS['db']->query("DELETE FROM tasks WHERE name like 'UNIT TEST%' ");
     $GLOBALS['db']->query("DELETE FROM meetings WHERE name like 'UNIT TEST%' ");
     $GLOBALS['db']->commit();
     //$this->useOutputBuffering = false;
 }
Ejemplo n.º 8
0
 public function test_create_unified_search_modules_display()
 {
     if (file_exists('custom/modules/unified_search_modules_display.php')) {
         unlink('custom/modules/unified_search_modules_display.php');
     }
     require_once 'modules/UpgradeWizard/uw_utils.php';
     $usa = new UnifiedSearchAdvanced();
     $_REQUEST['enabled_modules'] = 'Accounts,Bug36845Test';
     $usa->saveGlobalSearchSettings();
     $this->assertTrue(file_exists('custom/modules/unified_search_modules_display.php'), 'Assert that unified_search_modules_display.php file was created');
 }
Ejemplo n.º 9
0
 function action_DeployPackage()
 {
     if (defined('TEMPLATE_URL')) {
         sugar_cache_reset();
         SugarTemplateUtilities::disableCache();
     }
     $mb = new ModuleBuilder();
     $load = $_REQUEST['package'];
     $message = $GLOBALS['mod_strings']['LBL_MODULE_DEPLOYED'];
     if (!empty($load)) {
         $zip = $mb->getPackage($load);
         require_once 'ModuleInstall/PackageManager/PackageManager.php';
         $pm = new PackageManager();
         $info = $mb->packages[$load]->build(false);
         mkdir_recursive($GLOBALS['sugar_config']['cache_dir'] . '/upload/upgrades/module/');
         rename($info['zip'], $GLOBALS['sugar_config']['cache_dir'] . '/' . 'upload/upgrades/module/' . $info['name'] . '.zip');
         copy($info['manifest'], $GLOBALS['sugar_config']['cache_dir'] . '/' . 'upload/upgrades/module/' . $info['name'] . '-manifest.php');
         $_REQUEST['install_file'] = $GLOBALS['sugar_config']['cache_dir'] . '/' . 'upload/upgrades/module/' . $info['name'] . '.zip';
         $GLOBALS['mi_remove_tables'] = false;
         $pm->performUninstall($load);
         //#23177 , js cache clear
         clearAllJsAndJsLangFilesWithoutOutput();
         //#30747, clear the cache in memory
         $cache_key = 'app_list_strings.' . $GLOBALS['current_language'];
         sugar_cache_clear($cache_key);
         sugar_cache_reset();
         //clear end
         $pm->performInstall($_REQUEST['install_file'], true);
         //clear the unified_search_module.php file
         require_once 'modules/Home/UnifiedSearchAdvanced.php';
         UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile();
     }
     echo 'complete';
 }
 public function testUserPreferencesSearch()
 {
     global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles, $current_user;
     require 'config.php';
     require 'include/modules.php';
     $usa = new UnifiedSearchAdvanced();
     $_REQUEST['enabled_modules'] = 'Accounts,Contacts';
     $usa->saveGlobalSearchSettings();
     $current_user->setPreference('globalSearch', array('Accounts', 'Contacts'), 0, 'search');
     $current_user->savePreferencesToDB();
     $_REQUEST = array();
     $_REQUEST['query_string'] = $this->_contact->first_name . ' ' . $this->_contact->last_name;
     $_REQUEST['module'] = 'Home';
     $usa->search();
     $modules = $current_user->getPreference('globalSearch', 'search');
     $this->assertEquals(count($modules), 2, 'Assert that there are two modules in the user preferences as defined from the global search');
     $this->assertEquals('Accounts', $modules[0], 'Assert that the Accounts module has been added');
     $this->assertEquals('Contacts', $modules[1], 'Assert that the Contacts module has been added');
 }
Ejemplo n.º 11
0
 /**
  * Determine which modules should be searched against.
  *
  * @return array
  */
 protected function getSearchModules()
 {
     $usa = new UnifiedSearchAdvanced();
     $unified_search_modules_display = $usa->getUnifiedSearchModulesDisplay();
     // load the list of unified search enabled modules
     $modules = array();
     //check to see if the user has  customized the list of modules available to search
     $users_modules = $GLOBALS['current_user']->getPreference('globalSearch', 'search');
     if (!empty($users_modules)) {
         // use user's previous selections
         foreach ($users_modules as $key => $value) {
             if (isset($unified_search_modules_display[$key]) && !empty($unified_search_modules_display[$key]['visible'])) {
                 $modules[$key] = $key;
             }
         }
     } else {
         foreach ($unified_search_modules_display as $key => $data) {
             if (!empty($data['visible'])) {
                 $modules[$key] = $key;
             }
         }
     }
     // make sure the current module appears first in the list
     if (isset($modules[$this->module])) {
         unset($modules[$this->module]);
         $modules = array_merge(array($this->module => $this->module), $modules);
     }
     return $modules;
 }
Ejemplo n.º 12
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";
     }
 }
Ejemplo n.º 13
0
 /**
  * Given a list of modules to search and a search string, return the id, module_name, along with the fields
  * We will support Accounts, Bug Tracker, Cases, Contacts, Leads, Opportunities, Project, ProjectTask, Quotes
  *
  * @param string $session			- Session ID returned by a previous call to login.
  * @param string $search_string 	- string to search
  * @param string[] $modules			- array of modules to query
  * @param int $offset				- a specified offset in the query
  * @param int $max_results			- max number of records to return
  * @return Array 'entry_list' -- Array('Accounts' => array(array('name' => 'first_name', 'value' => 'John', 'name' => 'last_name', 'value' => 'Do')))
  * @exception 'SoapFault' -- The SOAP error, if any
  */
 function search_by_module($session, $search_string, $modules, $offset, $max_results)
 {
     $GLOBALS['log']->info('Begin: SugarWebServiceImpl->search_by_module');
     global $beanList, $beanFiles;
     global $sugar_config, $current_language;
     $error = new SoapError();
     $output_list = array();
     if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
         $error->set_error('invalid_login');
         $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
         return;
     }
     global $current_user;
     if ($max_results > 0) {
         $sugar_config['list_max_entries_per_page'] = $max_results;
     }
     require_once 'modules/Home/UnifiedSearchAdvanced.php';
     require_once 'include/utils.php';
     $usa = new UnifiedSearchAdvanced();
     if (!file_exists($cachedfile = sugar_cached('modules/unified_search_modules.php'))) {
         $usa->buildCache();
     }
     include $cachedfile;
     $modules_to_search = array();
     $unified_search_modules['Users'] = array('fields' => array());
     $unified_search_modules['ProjectTask'] = array('fields' => array());
     foreach ($unified_search_modules as $module => $data) {
         if (in_array($module, $modules)) {
             $modules_to_search[$module] = $beanList[$module];
         }
         // if
     }
     // foreach
     $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - search string = ' . $search_string);
     if (!empty($search_string) && isset($search_string)) {
         $search_string = trim($GLOBALS['db']->quote(securexss(from_html(clean_string($search_string, 'UNIFIED_SEARCH')))));
         foreach ($modules_to_search as $name => $beanName) {
             $where_clauses_array = array();
             $unifiedSearchFields = array();
             foreach ($unified_search_modules[$name]['fields'] as $field => $def) {
                 $unifiedSearchFields[$name][$field] = $def;
                 $unifiedSearchFields[$name][$field]['value'] = $search_string;
             }
             $seed = BeanFactory::getBean($name);
             require_once 'include/SearchForm/SearchForm2.php';
             if ($beanName == "User" || $beanName == "ProjectTask") {
                 if (!self::$helperObject->check_modules_access($current_user, $seed->module_dir, 'read')) {
                     continue;
                 }
                 // if
                 if (!$seed->ACLAccess('ListView')) {
                     continue;
                 }
                 // if
             }
             if ($beanName != "User" && $beanName != "ProjectTask") {
                 $searchForm = new SearchForm($seed, $name);
                 $searchForm->setup(array($name => array()), $unifiedSearchFields, '', 'saved_views');
                 $where_clauses = $searchForm->generateSearchWhere();
                 require_once 'include/SearchForm/SearchForm2.php';
                 $searchForm = new SearchForm($seed, $name);
                 $searchForm->setup(array($name => array()), $unifiedSearchFields, '', 'saved_views');
                 $where_clauses = $searchForm->generateSearchWhere();
                 $emailQuery = false;
                 $where = '';
                 if (count($where_clauses) > 0) {
                     $where = '(' . implode(' ) OR ( ', $where_clauses) . ')';
                 }
                 $mod_strings = return_module_language($current_language, $seed->module_dir);
                 require_once SugarAutoLoader::loadWithMetafiles($seed->module_dir, 'listviewdefs');
                 $filterFields = array();
                 foreach ($listViewDefs[$seed->module_dir] as $colName => $param) {
                     if (!empty($param['default']) && $param['default'] == true) {
                         $filterFields[] = strtolower($colName);
                     }
                     // if
                 }
                 // foreach
                 if (!in_array('id', $filterFields)) {
                     $filterFields[] = 'id';
                 }
                 // if
                 $ret_array = $seed->create_new_list_query('', $where, $filterFields, array(), 0, '', true, $seed, true);
                 if (empty($params) or !is_array($params)) {
                     $params = array();
                 }
                 if (!isset($params['custom_select'])) {
                     $params['custom_select'] = '';
                 }
                 if (!isset($params['custom_from'])) {
                     $params['custom_from'] = '';
                 }
                 if (!isset($params['custom_where'])) {
                     $params['custom_where'] = '';
                 }
                 if (!isset($params['custom_order_by'])) {
                     $params['custom_order_by'] = '';
                 }
                 $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];
             } else {
                 if ($beanName == "User") {
                     // $search_string gets cleaned above, so we can use it here
                     $filterFields = array('id', 'user_name', 'first_name', 'last_name', 'email_address');
                     $main_query = "select users.id, ea.email_address, users.user_name, first_name, last_name from users ";
                     $main_query = $main_query . " LEFT JOIN email_addr_bean_rel eabl ON eabl.bean_module = '{$seed->module_dir}'\nLEFT JOIN email_addresses ea ON (ea.id = eabl.email_address_id) ";
                     $main_query = $main_query . "where ((users.first_name like '{$search_string}') or (users.last_name like '{$search_string}') or (users.user_name like '{$search_string}') or (ea.email_address like '{$search_string}')) and users.deleted = 0 and users.is_group = 0 and users.employee_status = 'Active'";
                 }
                 // if
                 if ($beanName == "ProjectTask") {
                     // $search_string gets cleaned above, so we can use it here
                     $filterFields = array('id', 'name', 'project_id', 'project_name');
                     $main_query = "select {$seed->table_name}.project_task_id id,{$seed->table_name}.project_id, {$seed->table_name}.name, project.name project_name from {$seed->table_name} ";
                     $seed->add_team_security_where_clause($main_query);
                     $main_query .= "LEFT JOIN teams ON {$seed->table_name}.team_id=teams.id AND (teams.deleted=0) ";
                     $main_query .= "LEFT JOIN project ON {$seed->table_name}.project_id = project.id ";
                     $main_query .= "where {$seed->table_name}.name like '{$search_string}%'";
                 }
                 // if
             }
             // else
             $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - query = ' . $main_query);
             if ($max_results < -1) {
                 $result = $seed->db->query($main_query);
             } else {
                 if ($max_results == -1) {
                     $limit = $sugar_config['list_max_entries_per_page'];
                 } else {
                     $limit = $max_results;
                 }
                 $result = $seed->db->limitQuery($main_query, $offset, $limit + 1);
             }
             $rowArray = array();
             while ($row = $seed->db->fetchByAssoc($result)) {
                 $nameValueArray = array();
                 foreach ($filterFields as $field) {
                     $nameValue = array();
                     if (isset($row[$field])) {
                         $nameValueArray[$field] = self::$helperObject->get_name_value($field, $row[$field]);
                     }
                     // if
                 }
                 // foreach
                 $rowArray[] = $nameValueArray;
             }
             // while
             $output_list[] = array('name' => $name, 'records' => $rowArray);
         }
         // foreach
         $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
         return array('entry_list' => $output_list);
     }
     // if
     return array('entry_list' => $output_list);
 }
Ejemplo n.º 14
0
 * 02110-1301 USA.
 * 
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by SugarCRM".
 ********************************************************************************/
/*********************************************************************************
 * Description:  TODO: To be written.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 ********************************************************************************/
require_once 'modules/Home/UnifiedSearchAdvanced.php';
if (!empty($_REQUEST['usa_form'])) {
    $usa = new UnifiedSearchAdvanced();
    echo $usa->getDropDownDiv();
} else {
    global $mod_strings, $modListHeader, $app_strings, $beanList, $beanFiles;
    echo get_module_title("Search", $mod_strings['LBL_SEARCH_RESULTS'], true);
    $usa = new UnifiedSearchAdvanced();
    $usa->search();
}
Ejemplo n.º 15
0
 function uninstall($base_dir)
 {
     if (defined('TEMPLATE_URL')) {
         SugarTemplateUtilities::disableCache();
     }
     global $app_strings;
     $total_steps = 5;
     //min steps with no tasks
     $current_step = 0;
     $this->base_dir = $base_dir;
     $tasks = array('pre_uninstall', 'uninstall_relationships', 'uninstall_copy', 'uninstall_dcactions', 'uninstall_dashlets', 'uninstall_connectors', 'uninstall_layoutfields', 'uninstall_extensions', 'uninstall_global_search', 'disable_manifest_logichooks', 'post_uninstall');
     $total_steps += count($tasks);
     //now the real number of steps
     if (file_exists($this->base_dir . '/manifest.php')) {
         if (!$this->silent) {
             $current_step++;
             display_progress_bar('install', $current_step, $total_steps);
             echo '<div id ="displayLoglink" ><a href="#" onclick="toggleDisplay(\'displayLog\')">' . $app_strings['LBL_DISPLAY_LOG'] . '</a> </div><div id="displayLog" style="display:none">';
         }
         global $moduleList;
         include $this->base_dir . '/manifest.php';
         $this->installdefs = $installdefs;
         $this->id_name = $this->installdefs['id'];
         $installed_modules = array();
         if (isset($this->installdefs['beans'])) {
             foreach ($this->installdefs['beans'] as $bean) {
                 $installed_modules[] = $bean['module'];
                 $this->uninstall_user_prefs($bean['module']);
             }
             $this->modulesInPackage = $installed_modules;
             $this->uninstall_beans($installed_modules);
             $this->uninstall_customizations($installed_modules);
             if (!$this->silent) {
                 $current_step++;
                 update_progress_bar('install', $total_steps, $total_steps);
             }
         }
         if (!$this->silent) {
             $current_step++;
             update_progress_bar('install', $current_step, $total_steps);
         }
         foreach ($tasks as $task) {
             $this->{$task}();
             if (!$this->silent) {
                 $current_step++;
                 update_progress_bar('install', $current_step, $total_steps);
             }
         }
         if (isset($installdefs['custom_fields']) && (isset($GLOBALS['mi_remove_tables']) && $GLOBALS['mi_remove_tables'])) {
             $this->log(translate('LBL_MI_UN_CUSTOMFIELD'));
             $this->uninstall_custom_fields($installdefs['custom_fields']);
         }
         if (!$this->silent) {
             $current_step++;
             update_progress_bar('install', $current_step, $total_steps);
             echo '</div>';
         }
         //since we are passing $silent = true to rebuildAll() in that method it will set $this->silent = true, so
         //we need to save the setting to set it back after rebuildAll() completes.
         $silentBak = $this->silent;
         $this->rebuild_all(true);
         $this->silent = $silentBak;
         //#27877, If the request from MB redeploy a custom module , we will not remove the ACL actions for this package.
         if (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'DeployPackage') {
             $this->remove_acl_actions();
         }
         //end
         if (!$this->silent) {
             $current_step++;
             update_progress_bar('install', $current_step, $total_steps);
             echo '</div>';
         }
         UpdateSystemTabs('Restore', $installed_modules);
         //clear the unified_search_module.php file
         require_once 'modules/Home/UnifiedSearchAdvanced.php';
         UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile();
         $this->log('<br><b>' . translate('LBL_MI_COMPLETE') . '</b>');
         if (!$this->silent) {
             update_progress_bar('install', $total_steps, $total_steps);
         }
     } else {
         die("No manifest.php Defined In {$this->base_dir}/manifest.php");
     }
 }
Ejemplo n.º 16
0
 function action_DeployPackage()
 {
     global $current_user;
     if (defined('TEMPLATE_URL')) {
         sugar_cache_reset();
         SugarTemplateUtilities::disableCache();
     }
     //increment etag for menu so the new module shows up when the AJAX UI reloads
     $current_user->incrementETag("mainMenuETag");
     $mb = new ModuleBuilder();
     $load = $_REQUEST['package'];
     $message = $GLOBALS['mod_strings']['LBL_MODULE_DEPLOYED'];
     if (!empty($load)) {
         $zip = $mb->getPackage($load);
         require_once 'ModuleInstall/PackageManager/PackageManager.php';
         $pm = new PackageManager();
         $info = $mb->packages[$load]->build(false);
         $uploadDir = $pm->upload_dir . '/upgrades/module/';
         mkdir_recursive($uploadDir);
         rename($info['zip'], $uploadDir . $info['name'] . '.zip');
         copy($info['manifest'], $uploadDir . $info['name'] . '-manifest.php');
         $_REQUEST['install_file'] = $uploadDir . $info['name'] . '.zip';
         $GLOBALS['mi_remove_tables'] = false;
         $pm->performUninstall($load);
         //#23177 , js cache clear
         clearAllJsAndJsLangFilesWithoutOutput();
         //#30747, clear the cache in memory
         $cache_key = 'app_list_strings.' . $GLOBALS['current_language'];
         sugar_cache_clear($cache_key);
         sugar_cache_reset();
         //clear end
         $pm->performInstall($_REQUEST['install_file'], true);
         //clear the unified_search_module.php file
         require_once 'modules/Home/UnifiedSearchAdvanced.php';
         UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile();
         //bug 44269 - start
         //clear workflow admin modules cache
         if (isset($_SESSION['get_workflow_admin_modules_for_user'])) {
             unset($_SESSION['get_workflow_admin_modules_for_user']);
         }
         //clear "is_admin_for_module" cache
         $sessionVar = 'MLA_' . $current_user->user_name;
         foreach ($mb->packages as $package) {
             foreach ($package->modules as $module) {
                 $_SESSION[$sessionVar][$package->name . '_' . $module->name] = true;
             }
         }
         //recreate acl cache
         $actions = ACLAction::getUserActions($current_user->id, true);
         //bug 44269 - end
     }
     echo 'complete';
 }
Ejemplo n.º 17
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();
         $return = 'true';
         echo $return;
     } catch (Exception $ex) {
         echo "false";
     }
 }
Ejemplo n.º 18
0
 /**
  * This function is used to hand off the global search to the built-in SugarSearchEngine (aka SugarSpot)
  * @param $api ServiceBase The API class of the request
  * @param $args array The arguments array passed in from the API
  * @param $searchEngine SugarSearchEngine The SugarSpot search engine created using the Factory in the caller
  * @param $options array An array of options to pass through to the search engine, they get translated to the $searchOptions array so you can see exactly what gets passed through
  * @return array Two elements, 'records' the list of returned records formatted through FormatBean, and 'next_offset' which will indicate to the user if there are additional records to be returned.
  */
 public function globalSearchSpot(ServiceBase $api, array $args, $searchEngine, array $options)
 {
     require_once 'modules/Home/UnifiedSearchAdvanced.php';
     $searchOptions = array('modules' => $options['moduleList'], 'current_module' => $options['primaryModule'], 'return_beans' => true, 'my_items' => $options['my_items'], 'favorites' => $options['favorites'], 'orderBy' => $options['orderBy'], 'fields' => $options['fieldFilters'], 'selectFields' => $options['selectFields'], 'limitPerModule' => $options['limitPerModule'], 'allowEmptySearch' => true, 'distinct' => 'DISTINCT', 'return_beans' => true);
     if (isset($options['deleted'])) {
         $searchOptions['deleted'] = $options['deleted'];
     }
     $multiModule = false;
     if (empty($options['moduleList']) || count($options['moduleList']) == 0 || count($options['moduleList']) > 1) {
         $multiModule = true;
     }
     if (empty($options['moduleList'])) {
         require_once 'modules/ACL/ACLController.php';
         $usa = new UnifiedSearchAdvanced();
         $moduleList = $usa->getUnifiedSearchModules();
         // get the module names [array keys]
         $moduleList = array_keys($moduleList);
         // filter based on User Access if Blank
         $ACL = new ACLController();
         // moduleList is passed by reference
         $ACL->filterModuleList($moduleList);
         $searchOptions['modules'] = $options['moduleList'] = $moduleList;
     }
     if (!empty($options['searchFields'])) {
         $customWhere = array();
         foreach ($options['moduleList'] as $module) {
             $seed = BeanFactory::getBean($module);
             $fields = array_keys($seed->field_defs);
             $existingfields = array_intersect($fields, $options['searchFields']);
             if (!empty($existingfields)) {
                 $customTable = $seed->get_custom_table_name();
                 $table = $seed->table_name;
                 foreach ($existingfields as $field) {
                     if (!isset($seed->field_defs[$field]['unified_search']) || $seed->field_defs[$field]['unified_search'] !== true) {
                         continue;
                     }
                     $prefix = $table;
                     if (isset($GLOBALS['dictionary'][$seed->object_name]['custom_fields'][$field])) {
                         $prefix = $customTable;
                     }
                     if (!isset($seed->field_defs[$field]['source']) || $seed->field_defs[$field]['source'] != 'non-db') {
                         $customWhere[$module][] = "{$prefix}.{$field} LIKE '{$options['query']}%'";
                     }
                 }
                 if (isset($customWhere[$module])) {
                     $searchOptions['custom_where_module'][$module] = '(' . implode(' OR ', $customWhere[$module]) . ')';
                 }
             }
         }
     }
     $offset = $options['offset'];
     // One for luck.
     // Well, actually it's so that we know that there are additional results
     $limit = $options['limit'] + 1;
     if ($multiModule && $options['offset'] != 0) {
         // With more than one module, there is no way to do offsets for real, so we have to fake it.
         $limit = $limit + $offset;
         $offset = 0;
     }
     if (!$multiModule) {
         // It's not multi-module, the per-module limit should be the same as the master limit
         $searchOptions['limitPerModule'] = $limit;
     }
     if (isset($options['custom_select'])) {
         $searchOptions['custom_select'] = $options['custom_select'];
     }
     if (isset($options['custom_from'])) {
         $searchOptions['custom_from'] = $options['custom_from'];
     }
     if (isset($options['custom_where'])) {
         $searchOptions['custom_where'] = $options['custom_where'];
     }
     $results = $searchEngine->search($options['query'], $offset, $limit, $searchOptions);
     $returnedRecords = array();
     $api->action = 'list';
     foreach ($results as $module => $moduleResults) {
         if (!is_array($moduleResults['data'])) {
             continue;
         }
         $moduleArgs = $args;
         // Need to override the filter arg so that it looks like something formatBean expects
         if (!empty($options['fieldFilters'][$module])) {
             $moduleFields = $options['fieldFilters'][$module];
         } else {
             if (!empty($options['fieldFilters']['_default'])) {
                 $moduleFields = $options['fieldFilters']['_default'];
             } else {
                 $moduleFields = array();
             }
         }
         $moduleArgs['fields'] = implode(',', $moduleFields);
         foreach ($moduleResults['data'] as $record) {
             $formattedRecord = $this->formatBean($api, $moduleArgs, $record);
             $formattedRecord['_module'] = $module;
             // The SQL based search engine doesn't know how to score records, so set it to 1
             $formattedRecord['_search']['score'] = 1.0;
             $returnedRecords[] = $formattedRecord;
         }
     }
     if ($multiModule) {
         // Need to re-sort the results because the DB search engine clumps them together per-module
         $this->resultSetSortData = $options['orderByArray'];
         usort($returnedRecords, array($this, 'resultSetSort'));
     }
     if ($multiModule && $options['offset'] != 0) {
         // The merged module mess leaves us in a bit of a pickle with offsets and limits
         if (count($returnedRecords) > $options['offset'] + $options['limit']) {
             $nextOffset = $options['offset'] + $options['limit'];
         } else {
             $nextOffset = -1;
         }
         $returnedRecords = array_slice($returnedRecords, $options['offset'], $options['limit']);
     } else {
         // Otherwise, offsets and limits should work.
         if (count($returnedRecords) > $options['limit']) {
             $nextOffset = $options['offset'] + $options['limit'];
         } else {
             $nextOffset = -1;
         }
         $returnedRecords = array_slice($returnedRecords, 0, $options['limit']);
     }
     if ($options['offset'] === 'end') {
         $nextOffset = -1;
     }
     return array('next_offset' => $nextOffset, 'records' => $returnedRecords);
 }
Ejemplo n.º 19
0
 /**
  * Remove the cached unified_search_modules.php file
  */
 public function clearSearchCache()
 {
     global $mod_strings, $sugar_config;
     if ($this->show_output) {
         echo "<h3>{$mod_strings['LBL_QR_CLEARSEARCH']}</h3>";
     }
     // clear sugar_cache backend for SugarSearchEngine
     SugarSearchEngineMetadataHelper::clearCache();
     // Clear the cache file AFTER the cache clear, as it will be rebuilt by
     // clearCache otherwise
     UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile();
 }
 /**
  *
  * Clear FTS metadata cache
  */
 public static function clearCache()
 {
     // clear possible cache entries per module
     $usa = new UnifiedSearchAdvanced();
     $list = $usa->retrieveEnabledAndDisabledModules();
     foreach ($list as $modules) {
         foreach ($modules as $module) {
             $cacheKey = self::FTS_FIELDS_CACHE_KEY_PREFIX . $module['module'];
             sugar_cache_clear($cacheKey);
         }
     }
     // clear master list of enabled modules
     sugar_cache_clear(self::ENABLE_MODULE_CACHE_KEY);
 }
Ejemplo n.º 21
0
 public function testUnifiedSearchAdvancedBuildCache()
 {
     require_once 'modules/Home/UnifiedSearchAdvanced.php';
     $usa = new UnifiedSearchAdvanced();
     $usa->buildCache();
     //Assert we could build the file without problems
     $this->assertTrue(file_exists($this->unified_search_modules_file), "Assert {$this->unified_search_modules_file} file was created");
     include $this->unified_search_modules_file;
     $this->assertTrue(isset($unified_search_modules['Bug44030_TestPerson']), "Assert that we have the custom module set in unified_search_modules.php file");
     $this->assertTrue(isset($unified_search_modules['Bug44030_TestPerson']['fields']['email']), "Assert that the email field was set for the custom module");
 }
Ejemplo n.º 22
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;
 }
Ejemplo n.º 23
0
 /**
  * Given a list of modules to search and a search string, return the id, module_name, along with the fields
  * We will support Accounts, Bug Tracker, Cases, Contacts, Leads, Opportunities, Project, ProjectTask, Quotes
  *
  * @param string $session			- Session ID returned by a previous call to login.
  * @param string $search_string 	- string to search
  * @param string[] $modules			- array of modules to query
  * @param int $offset				- a specified offset in the query
  * @param int $max_results			- max number of records to return
  * @param string $assigned_user_id	- a user id to filter all records by, leave empty to exclude the filter
  * @param string[] $select_fields   - An array of fields to return.  If empty the default return fields will be from the active list view defs.
  * @param bool $unified_search_only - A boolean indicating if we should only search against those modules participating in the unified search.
  * @param bool $favorites           - A boolean indicating if we should only search against records marked as favorites.
  * @return Array return_search_result 	- Array('Accounts' => array(array('name' => 'first_name', 'value' => 'John', 'name' => 'last_name', 'value' => 'Do')))
  * @exception 'SoapFault' -- The SOAP error, if any
  */
 function search_by_module($session, $search_string, $modules, $offset, $max_results, $assigned_user_id = '', $select_fields = array(), $unified_search_only = TRUE, $favorites = FALSE)
 {
     $GLOBALS['log']->info('Begin: SugarWebServiceImpl->search_by_module');
     global $beanList, $beanFiles;
     global $sugar_config, $current_language;
     $error = new SoapError();
     $output_list = array();
     if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', '', '', '', $error)) {
         $error->set_error('invalid_login');
         $GLOBALS['log']->error('End: SugarWebServiceImpl->search_by_module - FAILED on checkSessionAndModuleAccess');
         return;
     }
     global $current_user;
     if ($max_results > 0) {
         $sugar_config['list_max_entries_per_page'] = $max_results;
     }
     require_once 'modules/Home/UnifiedSearchAdvanced.php';
     require_once 'include/utils.php';
     $usa = new UnifiedSearchAdvanced();
     if (!file_exists($cachefile = sugar_cached('modules/unified_search_modules.php'))) {
         $usa->buildCache();
     }
     include $cachefile;
     $modules_to_search = array();
     $unified_search_modules['Users'] = array('fields' => array());
     $unified_search_modules['ProjectTask'] = array('fields' => array());
     //If we are ignoring the unified search flag within the vardef we need to re-create the search fields.  This allows us to search
     //against a specific module even though it is not enabled for the unified search within the application.
     if (!$unified_search_only) {
         foreach ($modules as $singleModule) {
             if (!isset($unified_search_modules[$singleModule])) {
                 $newSearchFields = array('fields' => self::$helperObject->generateUnifiedSearchFields($singleModule));
                 $unified_search_modules[$singleModule] = $newSearchFields;
             }
         }
     }
     foreach ($unified_search_modules as $module => $data) {
         if (in_array($module, $modules)) {
             $modules_to_search[$module] = $beanList[$module];
         }
         // if
     }
     // foreach
     $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - search string = ' . $search_string);
     if (!empty($search_string) && isset($search_string)) {
         $search_string = trim($GLOBALS['db']->quote(securexss(from_html(clean_string($search_string, 'UNIFIED_SEARCH')))));
         foreach ($modules_to_search as $name => $beanName) {
             $where_clauses_array = array();
             $unifiedSearchFields = array();
             foreach ($unified_search_modules[$name]['fields'] as $field => $def) {
                 $unifiedSearchFields[$name][$field] = $def;
                 $unifiedSearchFields[$name][$field]['value'] = $search_string;
             }
             require_once $beanFiles[$beanName];
             $seed = new $beanName();
             require_once 'include/SearchForm/SearchForm2.php';
             if ($beanName == "User" || $beanName == "ProjectTask") {
                 if (!self::$helperObject->check_modules_access($current_user, $seed->module_dir, 'read')) {
                     continue;
                 }
                 // if
                 if (!$seed->ACLAccess('ListView')) {
                     continue;
                 }
                 // if
             }
             if ($beanName != "User" && $beanName != "ProjectTask") {
                 $searchForm = new SearchForm($seed, $name);
                 $searchForm->setup(array($name => array()), $unifiedSearchFields, '', 'saved_views');
                 $where_clauses = $searchForm->generateSearchWhere();
                 require_once 'include/SearchForm/SearchForm2.php';
                 $searchForm = new SearchForm($seed, $name);
                 $searchForm->setup(array($name => array()), $unifiedSearchFields, '', 'saved_views');
                 $where_clauses = $searchForm->generateSearchWhere();
                 $emailQuery = false;
                 $where = '';
                 if (count($where_clauses) > 0) {
                     $where = '(' . implode(' ) OR ( ', $where_clauses) . ')';
                 }
                 $mod_strings = return_module_language($current_language, $seed->module_dir);
                 if (count($select_fields) > 0) {
                     $filterFields = $select_fields;
                 } else {
                     if (file_exists('custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php')) {
                         require_once 'custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php';
                     } else {
                         require_once 'modules/' . $seed->module_dir . '/metadata/listviewdefs.php';
                     }
                     $filterFields = array();
                     foreach ($listViewDefs[$seed->module_dir] as $colName => $param) {
                         if (!empty($param['default']) && $param['default'] == true) {
                             $filterFields[] = strtolower($colName);
                         }
                     }
                     if (!in_array('id', $filterFields)) {
                         $filterFields[] = 'id';
                     }
                 }
                 //Pull in any db fields used for the unified search query so the correct joins will be added
                 $selectOnlyQueryFields = array();
                 foreach ($unifiedSearchFields[$name] as $field => $def) {
                     if (isset($def['db_field']) && !in_array($field, $filterFields)) {
                         $filterFields[] = $field;
                         $selectOnlyQueryFields[] = $field;
                     }
                 }
                 //Add the assigned user filter if applicable
                 if (!empty($assigned_user_id) && isset($seed->field_defs['assigned_user_id'])) {
                     $ownerWhere = $seed->getOwnerWhere($assigned_user_id);
                     $where = "({$where}) AND {$ownerWhere}";
                 }
                 if ($beanName == "Employee") {
                     $where = "({$where}) AND users.deleted = 0 AND users.is_group = 0 AND users.employee_status = 'Active'";
                 }
                 $list_params = array();
                 $ret_array = $seed->create_new_list_query('', $where, $filterFields, $list_params, 0, '', true, $seed, true);
                 if (empty($params) or !is_array($params)) {
                     $params = array();
                 }
                 if (!isset($params['custom_select'])) {
                     $params['custom_select'] = '';
                 }
                 if (!isset($params['custom_from'])) {
                     $params['custom_from'] = '';
                 }
                 if (!isset($params['custom_where'])) {
                     $params['custom_where'] = '';
                 }
                 if (!isset($params['custom_order_by'])) {
                     $params['custom_order_by'] = '';
                 }
                 $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];
             } else {
                 if ($beanName == "User") {
                     $filterFields = array('id', 'user_name', 'first_name', 'last_name', 'email_address');
                     $main_query = "select users.id, ea.email_address, users.user_name, first_name, last_name from users ";
                     $main_query = $main_query . " LEFT JOIN email_addr_bean_rel eabl ON eabl.bean_module = '{$seed->module_dir}'\n    LEFT JOIN email_addresses ea ON (ea.id = eabl.email_address_id) ";
                     $main_query = $main_query . "where ((users.first_name like '{$search_string}') or (users.last_name like '{$search_string}') or (users.user_name like '{$search_string}') or (ea.email_address like '{$search_string}')) and users.deleted = 0 and users.is_group = 0 and users.employee_status = 'Active'";
                 }
                 // if
                 if ($beanName == "ProjectTask") {
                     $filterFields = array('id', 'name', 'project_id', 'project_name');
                     $main_query = "select {$seed->table_name}.project_task_id id,{$seed->table_name}.project_id, {$seed->table_name}.name, project.name project_name from {$seed->table_name} ";
                     $seed->add_team_security_where_clause($main_query);
                     $main_query .= "LEFT JOIN teams ON {$seed->table_name}.team_id=teams.id AND (teams.deleted=0) ";
                     $main_query .= "LEFT JOIN project ON {$seed->table_name}.project_id = project.id ";
                     $main_query .= "where {$seed->table_name}.name like '{$search_string}%'";
                 }
                 // if
             }
             // else
             $GLOBALS['log']->info('SugarWebServiceImpl->search_by_module - query = ' . $main_query);
             if ($max_results < -1) {
                 $result = $seed->db->query($main_query);
             } else {
                 if ($max_results == -1) {
                     $limit = $sugar_config['list_max_entries_per_page'];
                 } else {
                     $limit = $max_results;
                 }
                 $result = $seed->db->limitQuery($main_query, $offset, $limit + 1);
             }
             $rowArray = array();
             while ($row = $seed->db->fetchByAssoc($result)) {
                 $nameValueArray = array();
                 foreach ($filterFields as $field) {
                     if (in_array($field, $selectOnlyQueryFields)) {
                         continue;
                     }
                     $nameValue = array();
                     if (isset($row[$field])) {
                         $nameValueArray[$field] = self::$helperObject->get_name_value($field, $row[$field]);
                     }
                     // if
                 }
                 // foreach
                 $rowArray[] = $nameValueArray;
             }
             // while
             $output_list[] = array('name' => $name, 'records' => $rowArray);
         }
         // foreach
         $GLOBALS['log']->info('End: SugarWebServiceImpl->search_by_module');
         return array('entry_list' => $output_list);
     }
     // if
     return array('entry_list' => $output_list);
 }
/**
 * Given a list of modules to search and a search string, return the id, module_name, along with the fields
 * We will support Accounts, Bugs, Calls, Cases, Contacts, Leads, Opportunities, Project, ProjectTask, Quotes
 * 
 * @param string $user_name 		- username of the Sugar User
 * @param string $password			- password of the Sugar User
 * @param string $search_string 	- string to search
 * @param string[] $modules			- array of modules to query
 * @param int $offset				- a specified offset in the query
 * @param int $max_results			- max number of records to return
 * @return Array return_search_result 	- Array('Accounts' => array(array('name' => 'first_name', 'value' => 'John', 'name' => 'last_name', 'value' => 'Do')))
 * @exception 'SoapFault' -- The SOAP error, if any
 */
function new_search_by_module($user_name, $password, $search_string, $modules, $offset, $max_results)
{
    global $beanList, $beanFiles;
    global $sugar_config;
    $error = new SoapError();
    $output_list = array();
    if (!validate_user($user_name, $password)) {
        $error->set_error('invalid_login');
        setFaultObject($error);
        return;
    }
    global $current_user;
    if ($max_results > 0) {
        $sugar_config['list_max_entries_per_page'] = $max_results;
    }
    require_once 'modules/Home/UnifiedSearchAdvanced.php';
    $usa = new UnifiedSearchAdvanced();
    if (!file_exists($GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php')) {
        $usa->buildCache();
    }
    include $GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php';
    $modules_to_search = array();
    foreach ($unified_search_modules as $module => $data) {
        if (in_array($module, $modules)) {
            $modules_to_search[$module] = $beanList[$module];
        }
        // if
    }
    // foreach
    if (!empty($search_string) && isset($search_string)) {
        foreach ($modules_to_search as $name => $beanName) {
            $where_clauses_array = array();
            foreach ($unified_search_modules[$name]['fields'] as $field => $def) {
                $clause = '';
                if (isset($def['table'])) {
                    // if field is from joining table
                    $clause = "{$def['table']}.{$def['rname']} ";
                } else {
                    $clause = "{$unified_search_modules[$name]['table']}.{$field} ";
                }
                // else
                switch ($def['type']) {
                    case 'int':
                        if (is_numeric($_REQUEST['query_string'])) {
                            $clause .= "in ('{$_REQUEST['query_string']}')";
                        } else {
                            $clause .= "in ('-1')";
                        }
                        break;
                    default:
                        //MFH BUG 15405 - added support for seaching full names in global search
                        if ($field == 'last_name') {
                            if (strpos($_REQUEST['query_string'], ' ')) {
                                $string = explode(' ', $_REQUEST['query_string']);
                                $clause .= "LIKE '{$string[1]}%'";
                            } else {
                                $clause .= "LIKE '{$_REQUEST['query_string']}%'";
                            }
                        } else {
                            $clause .= "LIKE '{$_REQUEST['query_string']}%'";
                        }
                        break;
                }
                // switch
                array_push($where_clauses_array, $clause);
            }
            // foreach
            $where = '(' . implode(' or ', $where_clauses_array) . ')';
            require_once $beanFiles[$beanName];
            $seed = new $beanName();
            $mod_strings = return_module_language($current_language, $seed->module_dir);
            if (file_exists('custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php')) {
                require_once 'custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php';
            } else {
                require_once 'modules/' . $seed->module_dir . '/metadata/listviewdefs.php';
            }
            $filterFields = array();
            foreach ($listViewDefs[$seed->module_dir] as $colName => $param) {
                if (!empty($param['default']) && $param['default'] == true) {
                    $filterFields[] = strtolower($colName);
                }
                // if
            }
            // foreach
            if (!in_array('id', $filterFields)) {
                $filterFields[] = 'id';
            }
            // if
            $ret_array = $seed->create_new_list_query('', $where, $filterFields, array(), 0, '', true, $seed, true);
            if (!is_array($params)) {
                $params = array();
            }
            if (!isset($params['custom_select'])) {
                $params['custom_select'] = '';
            }
            if (!isset($params['custom_from'])) {
                $params['custom_from'] = '';
            }
            if (!isset($params['custom_where'])) {
                $params['custom_where'] = '';
            }
            if (!isset($params['custom_order_by'])) {
                $params['custom_order_by'] = '';
            }
            $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];
            if ($max_results < -1) {
                $result = $seed->db->query($main_query);
            } else {
                if ($max_results == -1) {
                    $limit = $sugar_config['list_max_entries_per_page'];
                } else {
                    $limit = $max_results;
                }
                $result = $seed->db->limitQuery($main_query, $offset, $limit + 1);
            }
            $rowArray = array();
            while ($row = $seed->db->fetchByAssoc($result)) {
                $nameValueArray = array();
                foreach ($filterFields as $field) {
                    $nameValue = array();
                    if (isset($row[$field])) {
                        $nameValue['name'] = $field;
                        $nameValue['value'] = $row[$field];
                        $nameValueArray[] = $nameValue;
                    }
                    // if
                }
                // foreach
                $rowArray[] = $nameValueArray;
            }
            // while
            $output_list[] = array('name' => $name, 'records' => $rowArray);
        }
        // foreach
        return array('entry_list' => $output_list);
    }
    // if
}