/** * This method calls functions on the implementation class and returns the output or Fault object in case of error to client * * @return unknown */ function serve() { $GLOBALS['log']->info('Begin: SugarRestSerialize->serve'); $data = !empty($_REQUEST['rest_data']) ? $_REQUEST['rest_data'] : ''; if (empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])) { $er = new SoapError(); $er->set_error('invalid_call'); $this->fault($er); } else { $method = $_REQUEST['method']; $data = sugar_unserialize(from_html($data)); if (!is_array($data)) { $data = array($data); } $GLOBALS['log']->info('End: SugarRestSerialize->serve'); return call_user_func_array(array($this->implementation, $method), $data); } // else }
function listViewPrepare() { $module = $GLOBALS['module']; $metadataFile = $this->getMetaDataFile(); if (!file_exists($metadataFile)) { sugar_die($GLOBALS['app_strings']['LBL_NO_ACTION']); } require $metadataFile; $this->listViewDefs = $listViewDefs; if (!empty($this->bean->object_name) && isset($_REQUEST[$module . '2_' . strtoupper($this->bean->object_name) . '_offset'])) { //if you click the pagination button, it will populate the search criteria here if (!empty($_REQUEST['current_query_by_page'])) { //The code support multi browser tabs pagination $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', 'request_data', 'current_query_by_page', $module . '2_' . strtoupper($this->bean->object_name) . '_ORDER_BY'); if (isset($_REQUEST['lvso'])) { $blockVariables[] = 'lvso'; } $current_query_by_page = sugar_unserialize(base64_decode($_REQUEST['current_query_by_page'])); foreach ($current_query_by_page as $search_key => $search_value) { if ($search_key != $module . '2_' . strtoupper($this->bean->object_name) . '_offset' && !in_array($search_key, $blockVariables)) { if (!is_array($search_value)) { $_REQUEST[$search_key] = securexss($search_value); } else { foreach ($search_value as $key => &$val) { $val = securexss($val); } $_REQUEST[$search_key] = $search_value; } } } } } if (!empty($_REQUEST['saved_search_select'])) { if ($_REQUEST['saved_search_select'] == '_none' || !empty($_REQUEST['button'])) { $_SESSION['LastSavedView'][$_REQUEST['module']] = ''; unset($_REQUEST['saved_search_select']); unset($_REQUEST['saved_search_select_name']); //use the current search module, or the current module to clear out layout changes if (!empty($_REQUEST['search_module']) || !empty($_REQUEST['module'])) { $mod = !empty($_REQUEST['search_module']) ? $_REQUEST['search_module'] : $_REQUEST['module']; global $current_user; //Reset the current display columns to default. $current_user->setPreference('ListViewDisplayColumns', array(), 0, $mod); } } else { if (empty($_REQUEST['button']) && (empty($_REQUEST['clear_query']) || $_REQUEST['clear_query'] != 'true')) { $this->saved_search = loadBean('SavedSearch'); $this->saved_search->retrieveSavedSearch($_REQUEST['saved_search_select']); $this->saved_search->populateRequest(); } elseif (!empty($_REQUEST['button'])) { // click the search button, after retrieving from saved_search $_SESSION['LastSavedView'][$_REQUEST['module']] = ''; unset($_REQUEST['saved_search_select']); unset($_REQUEST['saved_search_select_name']); } } } $this->storeQuery = new StoreQuery(); if (!isset($_REQUEST['query'])) { $this->storeQuery->loadQuery($this->module); $this->storeQuery->populateRequest(); } else { $this->storeQuery->saveFromRequest($this->module); } $this->seed = $this->bean; $displayColumns = array(); if (!empty($_REQUEST['displayColumns'])) { foreach (explode('|', $_REQUEST['displayColumns']) as $num => $col) { if (!empty($this->listViewDefs[$module][$col])) { $displayColumns[$col] = $this->listViewDefs[$module][$col]; } } } else { foreach ($this->listViewDefs[$module] as $col => $this->params) { if (!empty($this->params['default']) && $this->params['default']) { $displayColumns[$col] = $this->params; } } } $this->params = array('massupdate' => true); if (!empty($_REQUEST['orderBy'])) { $this->params['orderBy'] = $_REQUEST['orderBy']; $this->params['overrideOrder'] = true; if (!empty($_REQUEST['sortOrder'])) { $this->params['sortOrder'] = $_REQUEST['sortOrder']; } } $this->lv->displayColumns = $displayColumns; $this->module = $module; $this->prepareSearchForm(); if (isset($this->options['show_title']) && $this->options['show_title']) { $moduleName = isset($this->seed->module_dir) ? $this->seed->module_dir : $GLOBALS['mod_strings']['LBL_MODULE_NAME']; echo $this->getModuleTitle(true); } }
/** * For a group email account, create subscriptions for all users associated with the * team assigned to the account. * */ function createUserSubscriptionsForGroupAccount() { $team = new Team(); $team->retrieve($this->team_id); $usersList = $team->get_team_members(true); foreach ($usersList as $userObject) { $previousSubscriptions = sugar_unserialize(base64_decode($userObject->getPreference('showFolders', 'Emails', $userObject))); if ($previousSubscriptions === FALSE) { $previousSubscriptions = array(); } $previousSubscriptions[] = $this->id; $encodedSubs = base64_encode(serialize($previousSubscriptions)); $userObject->setPreference('showFolders', $encodedSubs, '', 'Emails'); $userObject->savePreferencesToDB(); } }
function generateSearchWhere($module, $query) { //this function is similar with function prepareSearchForm() in view.list.php $seed = loadBean($module); $this->use_old_search = true; if (file_exists('modules/' . $module . '/SearchForm.html')) { if (file_exists('modules/' . $module . '/metadata/SearchFields.php')) { require_once 'include/SearchForm/SearchForm.php'; $searchForm = new SearchForm($module, $seed); } elseif (!empty($_SESSION['export_where'])) { //bug 26026, sometimes some module doesn't have a metadata/SearchFields.php, the searchfrom is generated in the ListView.php. //So currently massupdate will not gernerate the where sql. It will use the sql stored in the SESSION. But this will cause bug 24722, and it cannot be avoided now. $where = $_SESSION['export_where']; $whereArr = explode(" ", trim($where)); if ($whereArr[0] == trim('where')) { $whereClean = array_shift($whereArr); } $this->where_clauses = implode(" ", $whereArr); return; } else { $this->where_clauses = ''; return; } } else { $this->use_old_search = false; require_once 'include/SearchForm/SearchForm2.php'; if (file_exists('custom/modules/' . $module . '/metadata/metafiles.php')) { require 'custom/modules/' . $module . '/metadata/metafiles.php'; } elseif (file_exists('modules/' . $module . '/metadata/metafiles.php')) { require 'modules/' . $module . '/metadata/metafiles.php'; } $searchFields = $this->getSearchFields($module); $searchdefs = $this->getSearchDefs($module); if (empty($searchdefs) || empty($searchFields)) { $this->where_clauses = ''; //for some modules, such as iframe, it has massupdate, but it doesn't have search function, the where sql should be empty. return; } $searchForm = new SearchForm($seed, $module); $searchForm->setup($searchdefs, $searchFields, 'SearchFormGeneric.tpl'); } /* bug 31271: using false to not add all bean fields since some beans - like SavedReports can have fields named 'module' etc. which may break the query */ $query = sugar_unserialize(base64_decode($query)); $searchForm->populateFromArray($query, null, true); $this->searchFields = $searchForm->searchFields; $where_clauses = $searchForm->generateSearchWhere(true, $module); if (count($where_clauses) > 0) { $this->where_clauses = '(' . implode(' ) AND ( ', $where_clauses) . ')'; $GLOBALS['log']->info("MassUpdate Where Clause: {$this->where_clauses}"); } else { $this->where_clauses = ''; } }
create_campaign_log_entry($id, $focus, $focus->module_dir, $focus, $focus->id); } $refreshsubpanel = true; } } else { global $beanFiles, $beanList; $bean_name = $beanList[$_REQUEST['module']]; require_once $beanFiles[$bean_name]; $focus = new $bean_name(); $focus->retrieve($_REQUEST['record']); // If the user selected "All records" from the selection menu, we pull up the list // based on the query they used on that popup to relate them to the parent record if (!empty($_REQUEST['select_entire_list']) && $_REQUEST['select_entire_list'] != 'undefined' && isset($_REQUEST['current_query_by_page'])) { $order_by = ''; $current_query_by_page = $_REQUEST['current_query_by_page']; $current_query_by_page_array = sugar_unserialize(base64_decode($current_query_by_page)); $module = $current_query_by_page_array['module']; $seed = BeanFactory::getBean($module); if (empty($seed)) { sugar_die($GLOBALS['app_strings']['ERROR_NO_BEAN']); } $where_clauses = ''; require_once 'include/SearchForm/SearchForm2.php'; if (file_exists('custom/modules/' . $module . '/metadata/metafiles.php')) { require 'custom/modules/' . $module . '/metadata/metafiles.php'; } elseif (file_exists('modules/' . $module . '/metadata/metafiles.php')) { require 'modules/' . $module . '/metadata/metafiles.php'; } if (file_exists('custom/modules/' . $module . '/metadata/searchdefs.php')) { require_once 'custom/modules/' . $module . '/metadata/searchdefs.php'; } elseif (!empty($metafiles[$module]['searchdefs'])) {
function display() { global $popupMeta, $mod_strings; if ($this->bean instanceof SugarBean && !$this->bean->ACLAccess('list')) { ACLController::displayNoAccess(); sugar_cleanup(true); } if (isset($_REQUEST['metadata']) && strpos($_REQUEST['metadata'], "..") !== false) { die("Directory navigation attack denied."); } if (!empty($_REQUEST['metadata']) && $_REQUEST['metadata'] != 'undefined' && file_exists('custom/modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php')) { require 'custom/modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php'; } elseif (!empty($_REQUEST['metadata']) && $_REQUEST['metadata'] != 'undefined' && file_exists('modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php')) { require 'modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php'; } elseif (file_exists('custom/modules/' . $this->module . '/metadata/popupdefs.php')) { require 'custom/modules/' . $this->module . '/metadata/popupdefs.php'; } elseif (file_exists('modules/' . $this->module . '/metadata/popupdefs.php')) { require 'modules/' . $this->module . '/metadata/popupdefs.php'; } if (!empty($popupMeta) && !empty($popupMeta['listviewdefs'])) { if (is_array($popupMeta['listviewdefs'])) { //if we have an array, then we are not going to include a file, but rather the //listviewdefs will be defined directly in the popupdefs file $listViewDefs[$this->module] = $popupMeta['listviewdefs']; } else { //otherwise include the file require_once $popupMeta['listviewdefs']; } } elseif (file_exists('custom/modules/' . $this->module . '/metadata/listviewdefs.php')) { require_once 'custom/modules/' . $this->module . '/metadata/listviewdefs.php'; } elseif (file_exists('modules/' . $this->module . '/metadata/listviewdefs.php')) { require_once 'modules/' . $this->module . '/metadata/listviewdefs.php'; } //check for searchdefs as well if (!empty($popupMeta) && !empty($popupMeta['searchdefs'])) { if (is_array($popupMeta['searchdefs'])) { //if we have an array, then we are not going to include a file, but rather the //searchdefs will be defined directly in the popupdefs file $searchdefs[$this->module]['layout']['advanced_search'] = $popupMeta['searchdefs']; } else { //otherwise include the file require_once $popupMeta['searchdefs']; } } else { if (empty($searchdefs) && file_exists('custom/modules/' . $this->module . '/metadata/searchdefs.php')) { require_once 'custom/modules/' . $this->module . '/metadata/searchdefs.php'; } else { if (empty($searchdefs) && file_exists('modules/' . $this->module . '/metadata/searchdefs.php')) { require_once 'modules/' . $this->module . '/metadata/searchdefs.php'; } } } //if you click the pagination button, it will populate the search criteria here if (!empty($this->bean) && isset($_REQUEST[$this->module . '2_' . strtoupper($this->bean->object_name) . '_offset'])) { if (!empty($_REQUEST['current_query_by_page'])) { $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', 'sortOrder', 'orderBy', 'request_data', 'current_query_by_page'); $current_query_by_page = sugar_unserialize(base64_decode($_REQUEST['current_query_by_page'])); foreach ($current_query_by_page as $search_key => $search_value) { if ($search_key != $this->module . '2_' . strtoupper($this->bean->object_name) . '_offset' && !in_array($search_key, $blockVariables)) { if (!is_array($search_value)) { $_REQUEST[$search_key] = securexss($search_value); } else { foreach ($search_value as $key => &$val) { $val = securexss($val); } $_REQUEST[$search_key] = $search_value; } } } } } if (!empty($listViewDefs) && !empty($searchdefs)) { require_once 'include/Popups/PopupSmarty.php'; $displayColumns = array(); $filter_fields = array(); $popup = new PopupSmarty($this->bean, $this->module); foreach ($listViewDefs[$this->module] as $col => $params) { $filter_fields[strtolower($col)] = true; if (!empty($params['related_fields'])) { foreach ($params['related_fields'] as $field) { //id column is added by query construction function. This addition creates duplicates //and causes issues in oracle. #10165 if ($field != 'id') { $filter_fields[$field] = true; } } } if (!empty($params['default']) && $params['default']) { $displayColumns[$col] = $params; } } $popup->displayColumns = $displayColumns; $popup->filter_fields = $filter_fields; $popup->mergeDisplayColumns = true; //check to see if popupdefs contains searchdefs $popup->_popupMeta = $popupMeta; $popup->listviewdefs = $listViewDefs; $popup->searchdefs = $searchdefs; if (isset($_REQUEST['query'])) { $popup->searchForm->populateFromRequest(); } $massUpdateData = ''; if (isset($_REQUEST['mass'])) { foreach (array_unique($_REQUEST['mass']) as $record) { $massUpdateData .= "<input style='display: none' checked type='checkbox' name='mass[]' value='{$record}'>\n"; } } $popup->massUpdateData = $massUpdateData; $tpl = 'include/Popups/tpls/PopupGeneric.tpl'; if (file_exists($this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupGeneric.tpl"))) { $tpl = $this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupGeneric.tpl"); } if (file_exists($this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupHeader.tpl"))) { $popup->headerTpl = $this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupHeader.tpl"); } if (file_exists($this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupFooter.tpl"))) { $popup->footerTpl = $this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupFooter.tpl"); } $popup->setup($tpl); //We should at this point show the header and javascript even if to_pdf is true. //The insert_popup_header javascript is incomplete and shouldn't be relied on. if (isset($this->options['show_all']) && $this->options['show_all'] == false) { unset($this->options['show_all']); $this->options['show_javascript'] = true; $this->options['show_header'] = true; $this->_displayJavascript(); } insert_popup_header(null, false); if (isset($this->override_popup['template_data']) && is_array($this->override_popup['template_data'])) { $popup->th->ss->assign($this->override_popup['template_data']); } echo $popup->display(); } else { if (file_exists('modules/' . $this->module . '/Popup_picker.php')) { require_once 'modules/' . $this->module . '/Popup_picker.php'; } else { require_once 'include/Popups/Popup_picker.php'; } $popup = new Popup_Picker(); $popup->_hide_clear_button = true; echo $popup->process_page(); } }
//them to the list of folders to show. foreach ($subs as $singleSub) { $email->et->folder->findAllChildren($singleSub, $childrenSubs); } $subs = array_merge($subs, $childrenSubs); $email->et->folder->setSubscriptions($subs); } elseif (empty($_REQUEST['subscriptions'])) { $email->et->folder->clearSubscriptions(); } break; case "refreshSugarFolders": $GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: refreshSugarFolders"); $rootNode = new ExtNode('', ''); $folderOpenState = $current_user->getPreference('folderOpenState', 'Emails'); $folderOpenState = empty($folderOpenState) ? "" : $folderOpenState; $ret = $email->et->folder->getUserFolders($rootNode, sugar_unserialize($folderOpenState), $current_user, true); $out = $json->encode($ret); echo $out; break; case "getFoldersForSettings": $GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: getFoldersForSettings"); $ret = $email->et->folder->getFoldersForSettings($current_user); $out = $json->encode($ret); echo $out; break; case "moveEmails": $GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: moveEmails"); $ie->moveEmails($_REQUEST['sourceIeId'], $_REQUEST['sourceFolder'], $_REQUEST['destinationIeId'], $_REQUEST['destinationFolder'], $_REQUEST['emailUids']); break; case "saveNewFolder": $GLOBALS['log']->debug("********** EMAIL 2.0 - Asynchronous - at: saveNewFolder");
protected function saveMappingFile() { global $current_user; $firstrow = sugar_unserialize(base64_decode($_REQUEST['firstrow'])); $mappingValsArr = $this->importColumns; $mapping_file = new ImportMap(); if (isset($_REQUEST['has_header']) && $_REQUEST['has_header'] == 'on') { $header_to_field = array(); foreach ($this->importColumns as $pos => $field_name) { if (isset($firstrow[$pos]) && isset($field_name)) { $header_to_field[$firstrow[$pos]] = $field_name; } } $mappingValsArr = $header_to_field; } //get array of values to save for duplicate and locale settings $advMapping = $this->retrieveAdvancedMapping(); //merge with mappingVals array if (!empty($advMapping) && is_array($advMapping)) { $mappingValsArr = $advMapping + $mappingValsArr; } //set mapping $mapping_file->setMapping($mappingValsArr); // save default fields $defaultValues = array(); for ($i = 0; $i < $_REQUEST['columncount']; $i++) { if (isset($this->importColumns[$i]) && !empty($_REQUEST[$this->importColumns[$i]])) { $field = $this->importColumns[$i]; $fieldDef = $this->bean->getFieldDefinition($field); if (!empty($fieldDef['custom_type']) && $fieldDef['custom_type'] == 'teamset') { require_once 'include/SugarFields/Fields/Teamset/SugarFieldTeamset.php'; $sugar_field = new SugarFieldTeamset('Teamset'); $teams = $sugar_field->getTeamsFromRequest($field); if (isset($_REQUEST['primary_team_name_collection'])) { $primary_index = $_REQUEST['primary_team_name_collection']; } //If primary_index was selected, ensure that the first Array entry is the primary team if (isset($primary_index)) { $count = 0; $new_teams = array(); foreach ($teams as $id => $name) { if ($primary_index == $count++) { $new_teams[$id] = $name; unset($teams[$id]); break; } } foreach ($teams as $id => $name) { $new_teams[$id] = $name; } $teams = $new_teams; } //if $json = getJSONobj(); $defaultValues[$field] = $json->encode($teams); } else { $defaultValues[$field] = $_REQUEST[$this->importColumns[$i]]; } } } $mapping_file->setDefaultValues($defaultValues); $result = $mapping_file->save($current_user->id, $_REQUEST['save_map_as'], $_REQUEST['import_module'], $_REQUEST['source'], isset($_REQUEST['has_header']) && $_REQUEST['has_header'] == 'on', $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES)); }
function getShowAccountsOptionsForSearch(&$ie) { global $current_user; global $app_strings; $ieAccountsFull = $ie->retrieveAllByGroupId($current_user->id); //$ieAccountsShowOptions = "<option value=''>{$app_strings['LBL_NONE']}</option>\n"; $ieAccountsShowOptionsMeta = array(); $ieAccountsShowOptionsMeta[] = array("value" => "", "text" => $app_strings['LBL_NONE'], 'selected' => ''); $showFolders = sugar_unserialize(base64_decode($current_user->getPreference('showFolders', 'Emails'))); foreach ($ieAccountsFull as $k => $v) { if (!in_array($v->id, $showFolders)) { continue; } $group = !$v->is_personal ? $app_strings['LBL_EMAIL_GROUP'] . "." : ""; $ieAccountsShowOptionsMeta[] = array("value" => $v->id, "text" => $group . $v->name, 'protocol' => $v->protocol); } return $ieAccountsShowOptionsMeta; }
function display() { if (!$this->bean->ACLAccess('list')) { ACLController::displayNoAccess(); return; } $module = $GLOBALS['module']; $metadataFile = null; $foundViewDefs = false; if (file_exists('custom/modules/' . $module . '/metadata/listviewdefs.php')) { $metadataFile = 'custom/modules/' . $module . '/metadata/listviewdefs.php'; $foundViewDefs = true; } else { if (file_exists('custom/modules/' . $module . '/metadata/metafiles.php')) { require_once 'custom/modules/' . $module . '/metadata/metafiles.php'; if (!empty($metafiles[$module]['listviewdefs'])) { $metadataFile = $metafiles[$module]['listviewdefs']; $foundViewDefs = true; } } elseif (file_exists('modules/' . $module . '/metadata/metafiles.php')) { require_once 'modules/' . $module . '/metadata/metafiles.php'; if (!empty($metafiles[$module]['listviewdefs'])) { $metadataFile = $metafiles[$module]['listviewdefs']; $foundViewDefs = true; } } } if (!$foundViewDefs && file_exists('modules/' . $module . '/metadata/listviewdefs.php')) { $metadataFile = 'modules/' . $module . '/metadata/listviewdefs.php'; } require_once $metadataFile; $seed = $this->bean; if (!empty($this->bean->object_name) && isset($_REQUEST[$module . '2_' . strtoupper($this->bean->object_name) . '_offset'])) { //if you click the pagination button, it will populate the search criteria here if (!empty($_REQUEST['current_query_by_page'])) { //The code support multi browser tabs pagination $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', 'request_data', 'current_query_by_page', $module . '2_' . strtoupper($this->bean->object_name) . '_ORDER_BY'); if (isset($_REQUEST['lvso'])) { $blockVariables[] = 'lvso'; } $current_query_by_page = sugar_unserialize(base64_decode($_REQUEST['current_query_by_page'])); foreach ($current_query_by_page as $search_key => $search_value) { if ($search_key != $module . '2_' . strtoupper($this->bean->object_name) . '_offset' && !in_array($search_key, $blockVariables)) { if (!is_array($search_value)) { $_REQUEST[$search_key] = $GLOBALS['db']->quote($search_value); } else { foreach ($search_value as $key => &$val) { $val = $GLOBALS['db']->quote($val); } $_REQUEST[$search_key] = $search_value; } } } } } if (!empty($_REQUEST['saved_search_select']) && $_REQUEST['saved_search_select'] != '_none') { if (empty($_REQUEST['button']) && (empty($_REQUEST['clear_query']) || $_REQUEST['clear_query'] != 'true')) { $this->saved_search = loadBean('SavedSearch'); $this->saved_search->retrieveSavedSearch($_REQUEST['saved_search_select']); $this->saved_search->populateRequest(); } elseif (!empty($_REQUEST['button'])) { // click the search button, after retrieving from saved_search $_SESSION['LastSavedView'][$_REQUEST['module']] = ''; unset($_REQUEST['saved_search_select']); unset($_REQUEST['saved_search_select_name']); } } $lv = new ListViewSmarty(); $displayColumns = array(); if (!empty($_REQUEST['displayColumns'])) { foreach (explode('|', $_REQUEST['displayColumns']) as $num => $col) { if (!empty($listViewDefs[$module][$col])) { $displayColumns[$col] = $listViewDefs[$module][$col]; } } } else { foreach ($listViewDefs[$module] as $col => $params) { if (!empty($params['default']) && $params['default']) { $displayColumns[$col] = $params; } } } $params = array('massupdate' => true, 'export' => true); if (!empty($_REQUEST['orderBy'])) { $params['orderBy'] = $_REQUEST['orderBy']; $params['overrideOrder'] = true; if (!empty($_REQUEST['sortOrder'])) { $params['sortOrder'] = $_REQUEST['sortOrder']; } } $lv->displayColumns = $displayColumns; $this->seed = $seed; $this->module = $module; $searchForm = null; $storeQuery = new StoreQuery(); if (!isset($_REQUEST['query'])) { $storeQuery->loadQuery($this->module); $storeQuery->populateRequest(); } else { $storeQuery->saveFromRequest($this->module); } //search $view = 'basic_search'; if (!empty($_REQUEST['search_form_view'])) { $view = $_REQUEST['search_form_view']; } $headers = true; if (!empty($_REQUEST['search_form_only']) && $_REQUEST['search_form_only']) { $headers = false; } elseif (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') { if (isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'advanced_search') { $view = 'advanced_search'; } else { $view = 'basic_search'; } } $use_old_search = true; if (file_exists('modules/' . $this->module . '/SearchForm.html')) { require_once 'include/SearchForm/SearchForm.php'; $searchForm = new SearchForm($this->module, $this->seed); } else { $use_old_search = false; require_once 'include/SearchForm/SearchForm2.php'; if (file_exists('custom/modules/' . $this->module . '/metadata/searchdefs.php')) { require_once 'custom/modules/' . $this->module . '/metadata/searchdefs.php'; } elseif (!empty($metafiles[$this->module]['searchdefs'])) { require_once $metafiles[$this->module]['searchdefs']; } elseif (file_exists('modules/' . $this->module . '/metadata/searchdefs.php')) { require_once 'modules/' . $this->module . '/metadata/searchdefs.php'; } if (!empty($metafiles[$this->module]['searchfields'])) { require $metafiles[$this->module]['searchfields']; } elseif (file_exists('modules/' . $this->module . '/metadata/SearchFields.php')) { require 'modules/' . $this->module . '/metadata/SearchFields.php'; } $searchForm = new SearchForm($this->seed, $this->module, $this->action); $searchForm->setup($searchdefs, $searchFields, 'SearchFormGeneric.tpl', $view, $listViewDefs); $searchForm->lv = $lv; } if (isset($this->options['show_title']) && $this->options['show_title']) { $moduleName = isset($this->seed->module_dir) ? $this->seed->module_dir : $GLOBALS['mod_strings']['LBL_MODULE_NAME']; echo getClassicModuleTitle($moduleName, array($GLOBALS['mod_strings']['LBL_MODULE_TITLE']), FALSE); } $where = ''; if (isset($_REQUEST['query'])) { // we have a query if (!empty($_SERVER['HTTP_REFERER']) && preg_match('/action=EditView/', $_SERVER['HTTP_REFERER'])) { // from EditView cancel $searchForm->populateFromArray($storeQuery->query); } else { $searchForm->populateFromRequest(); } $where_clauses = $searchForm->generateSearchWhere(true, $this->seed->module_dir); if (count($where_clauses) > 0) { $where = '(' . implode(' ) AND ( ', $where_clauses) . ')'; } $GLOBALS['log']->info("List View Where Clause: {$where}"); } if ($use_old_search) { switch ($view) { case 'basic_search': $searchForm->setup(); $searchForm->displayBasic($headers); break; case 'advanced_search': $searchForm->setup(); $searchForm->displayAdvanced($headers); break; case 'saved_views': echo $searchForm->displaySavedViews($listViewDefs, $lv, $headers); break; } } else { echo $searchForm->display($headers); } if (!$headers) { return; } /* * Bug 50575 - related search columns not inluded in query in a proper way */ $lv->searchColumns = $searchForm->searchColumns; if (empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false) { //Bug 58841 - mass update form was not displayed for non-admin users that should have access if (ACLController::checkAccess($module, 'massupdate') || ACLController::checkAccess($module, 'export')) { $lv->setup($seed, 'include/ListView/ListViewGeneric.tpl', $where, $params); } else { $lv->setup($seed, 'include/ListView/ListViewNoMassUpdate.tpl', $where, $params); } echo $lv->display(); } }
/** * Perform the actual massupdate. */ protected function action_massupdate() { if (!empty($_REQUEST['massupdate']) && $_REQUEST['massupdate'] == 'true' && (!empty($_REQUEST['uid']) || !empty($_REQUEST['entire']))) { if (!empty($_REQUEST['Delete']) && $_REQUEST['Delete'] == 'true' && !$this->bean->ACLAccess('delete') || (empty($_REQUEST['Delete']) || $_REQUEST['Delete'] != 'true') && !$this->bean->ACLAccess('save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } set_time_limit(0); //I'm wondering if we will set it never goes timeout here. // until we have more efficient way of handling MU, we have to disable the limit $GLOBALS['db']->setQueryLimit(0); require_once "include/MassUpdate.php"; require_once 'modules/MySettings/StoreQuery.php'; $seed = loadBean($_REQUEST['module']); $mass = new MassUpdate(); $mass->setSugarBean($seed); if (isset($_REQUEST['entire']) && empty($_POST['mass'])) { $mass->generateSearchWhere($_REQUEST['module'], $_REQUEST['current_query_by_page']); } $mass->handleMassUpdate(); $storeQuery = new StoreQuery(); //restore the current search. to solve bug 24722 for multi tabs massupdate. $temp_req = array('current_query_by_page' => $_REQUEST['current_query_by_page'], 'return_module' => $_REQUEST['return_module'], 'return_action' => $_REQUEST['return_action']); if ($_REQUEST['return_module'] == 'Emails') { if (!empty($_REQUEST['type']) && !empty($_REQUEST['ie_assigned_user_id'])) { $this->req_for_email = array('type' => $_REQUEST['type'], 'ie_assigned_user_id' => $_REQUEST['ie_assigned_user_id']); // Specifically for My Achieves } } $_REQUEST = array(); $_REQUEST = sugar_unserialize(base64_decode($temp_req['current_query_by_page'])); unset($_REQUEST[$seed->module_dir . '2_' . strtoupper($seed->object_name) . '_offset']); //after massupdate, the page should redirect to no offset page $storeQuery->saveFromRequest($_REQUEST['module']); $_REQUEST = array('return_module' => $temp_req['return_module'], 'return_action' => $temp_req['return_action']); //for post_massupdate, to go back to original page. } else { sugar_die("You must massupdate at least one record"); } }
function generateSearchWhere($module, $query) { //this function is similar with function prepareSearchForm() in view.list.php $seed = loadBean($module); if (file_exists('modules/' . $module . '/SearchForm.html')) { if (file_exists('modules/' . $module . '/metadata/SearchFields.php')) { require_once 'include/SearchForm/SearchForm.php'; $searchForm = new SearchForm($module, $seed); } elseif (!empty($_SESSION['export_where'])) { //bug 26026, sometimes some module doesn't have a metadata/SearchFields.php, the searchfrom is generated in the ListView.php. // Currently, massupdate will not generate the where sql. It will use the sql stored in the SESSION. But this will cause bug 24722, and it cannot be avoided now. $where = $_SESSION['export_where']; $whereArr = explode(" ", trim($where)); if ($whereArr[0] == trim('where')) { $whereClean = array_shift($whereArr); } $where = implode(" ", $whereArr); //rrs bug: 31329 - previously this was just returning $where, but the problem is the caller of this function //expects the results in an array, not just a string. So rather than fixing the caller, I felt it would be best for //the function to return the results in a standard format. $ret_array['where'] = $where; $ret_array['searchFields'] = array(); return $ret_array; } else { return; } } else { require_once 'include/SearchForm/SearchForm2.php'; if (file_exists('custom/modules/' . $module . '/metadata/metafiles.php')) { require 'custom/modules/' . $module . '/metadata/metafiles.php'; } elseif (file_exists('modules/' . $module . '/metadata/metafiles.php')) { require 'modules/' . $module . '/metadata/metafiles.php'; } if (file_exists('custom/modules/' . $module . '/metadata/searchdefs.php')) { require_once 'custom/modules/' . $module . '/metadata/searchdefs.php'; } elseif (!empty($metafiles[$module]['searchdefs'])) { require_once $metafiles[$module]['searchdefs']; } elseif (file_exists('modules/' . $module . '/metadata/searchdefs.php')) { require_once 'modules/' . $module . '/metadata/searchdefs.php'; } //fixing bug #48483: Date Range search on custom date field then export ignores range filter // first of all custom folder should be checked if (file_exists('custom/modules/' . $module . '/metadata/SearchFields.php')) { require_once 'custom/modules/' . $module . '/metadata/SearchFields.php'; } elseif (!empty($metafiles[$module]['searchfields'])) { require_once $metafiles[$module]['searchfields']; } elseif (file_exists('modules/' . $module . '/metadata/SearchFields.php')) { require_once 'modules/' . $module . '/metadata/SearchFields.php'; } if (empty($searchdefs) || empty($searchFields)) { //for some modules, such as iframe, it has massupdate, but it doesn't have search function, the where sql should be empty. return; } $searchForm = new SearchForm($seed, $module); $searchForm->setup($searchdefs, $searchFields, 'SearchFormGeneric.tpl'); } $searchForm->populateFromArray(sugar_unserialize(base64_decode($query))); $where_clauses = $searchForm->generateSearchWhere(true, $module); if (count($where_clauses) > 0) { $where = '(' . implode(' ) AND ( ', $where_clauses) . ')'; } $GLOBALS['log']->info("Export Where Clause: {$where}"); $ret_array['where'] = $where; $ret_array['searchFields'] = $searchForm->searchFields; return $ret_array; }