/** * @see SugarController::loadBean() */ public function loadBean() { global $mod_strings; $this->importModule = isset($_REQUEST['import_module']) ? $_REQUEST['import_module'] : ''; $this->bean = loadBean($this->importModule); if ($this->bean) { if (!$this->bean->importable) { $this->bean = false; } elseif ($_REQUEST['import_module'] == 'Users' && !is_admin($GLOBALS['current_user'])) { $this->bean = false; } elseif ($this->bean->bean_implements('ACL')) { if (!ACLController::checkAccess($this->bean->module_dir, 'import', true)) { ACLController::displayNoAccess(); sugar_die(''); } } } if (!$this->bean && $this->importModule != "Administration") { $_REQUEST['message'] = $mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP']; $this->view = 'error'; $this->_processed = true; } else { $GLOBALS['FOCUS'] = $this->bean; } }
function remove_zero(SugarBean $bean, $event, $arguments) { if ($bean->number_of_floor == '' || $bean->number_of_floor == 0) { $bean->number_of_floor = ''; } if ($bean->floor == '' || $bean->floor == 0) { $bean->floor = ''; } if ($bean->rooms_quantity == '' || $bean->rooms_quantity == 0) { $bean->rooms_quantity = ''; } if ($bean->living_square == '' || $bean->living_square == 0) { $bean->living_square = ''; } if ($event == 'process_record') { // из какой заявки(интересующая недвижимость для контактов) if ($_REQUEST['module'] == 'Contacts' && $_REQUEST['action'] == 'DetailView') { global $db; $q = "SELECT rrit.request_id as id, r.name as name\n\t\t\t\t\tFROM realty_requests_interest_table AS rrit\n\t\t\t\t\tLEFT JOIN request as r ON r.id = rrit.request_id\n\t\t\t\t\tWHERE \n\t\t\t\t\t\trrit.realty_id = '{$bean->id}'\n\t\t\t\t\t\tAND rrit.deleted = 0\n\t\t\t\t\t\tAND r.deleted = 0"; $res = $db->query($q); if ($r = $db->fetchByAssoc($res)) { $bean->request = "<a href='index.php?module=Request&action=DetailView&record={$r['id']}'>{$r['name']}</a>"; } } // if ($_REQUEST['action'] == 'index') { $realty = loadBean('Realty'); $realty->retrieve($bean->id); if ($realty->reserved) { //бронь $bean->name .= "<img style='display:none;' src='themes/default/images/help.gif' width='0' height='0' onload=\"this.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = '#ccc';\" />"; } } } }
/** * @dataProvider providerCsvData */ public function testDateTimeImport($content_idx, $expected_datetime, $date_format, $time_format) { $file = $GLOBALS['sugar_config']['upload_dir'] . 'test.csv'; $ret = file_put_contents($file, self::$CsvContent[$content_idx]); $this->assertGreaterThan(0, $ret, 'Failed to write to ' . $file . ' for content ' . $content_idx); $importSource = new ImportFile($file, ',', '"'); $bean = loadBean($this->_importModule); $_REQUEST['columncount'] = 2; $_REQUEST['colnum_0'] = 'date_entered'; $_REQUEST['colnum_1'] = 'last_name'; $_REQUEST['import_module'] = 'Contacts'; $_REQUEST['importlocale_charset'] = 'UTF-8'; $_REQUEST['importlocale_dateformat'] = $date_format; $_REQUEST['importlocale_timeformat'] = $time_format; $_REQUEST['importlocale_timezone'] = 'GMT'; $_REQUEST['importlocale_default_currency_significant_digits'] = '2'; $_REQUEST['importlocale_currency'] = '-99'; $_REQUEST['importlocale_dec_sep'] = '.'; $_REQUEST['importlocale_currency'] = '-99'; $_REQUEST['importlocale_default_locale_name_format'] = 's f l'; $_REQUEST['importlocale_num_grp_sep'] = ','; $importer = new Importer($importSource, $bean); $importer->import(); $query = "SELECT date_entered from contacts where created_by='{$GLOBALS['current_user']->id}'"; $result = $GLOBALS['db']->query($query); $row = $GLOBALS['db']->fetchByAssoc($result); $this->assertEquals($expected_datetime, $GLOBALS['db']->fromConvert($row['date_entered'], 'datetime'), 'Got incorrect date_entered.'); }
public function ejecutar($focus, $string_parametros) { $this->procesar_parametros($string_parametros); $alarma = loadBean('gcoop_alarmas'); $alarma->parent_type = $focus->module_dir; $alarma->parent_id = $focus->id; $alarma->destinatario = $this->destinatario; $alarma->notificacion = $this->notificacion; $alarma->parametro = $this->parametro; $alarma->valor = $this->valor; #sumarle dias no fin de semana! $fecha = new DateTime(); $dia = new DateInterval('P1D'); while ($this->cantidad_dias > 0) { $fecha->add($dia); if ($fecha->format('N') < 6) { $this->cantidad_dias -= 1; } } $timedate = TimeDate::getInstance(); $alarma->fecha_disparo = $timedate->asDb($fecha); $alarma->save(); if (method_exists($focus, 'notificar')) { $focus->notificar("Se creó alarama con fecha de disparo {$alarma->fecha_disparo}", 'Alarma'); } }
public function testProcessFullListQuery() { $loadedContact = loadBean('Contacts'); $loadedContact->disable_row_level_security = true; $contactList = $loadedContact->get_full_list(); $exampleContact = array_pop($contactList); $this->assertNotNull($exampleContact->fetched_row['last_name']); }
function changeUserTitle(SugarBean $bean, $event, $arguments) { if ($bean->fetched_row['assigned_user_id'] != $bean->assigned_user_id) { $user = loadBean('Users'); $user->retrieve($bean->assigned_user_id); $user->title = 'branch'; $user->save(); } }
function echo_module_fields($module) { global $current_language, $app_list_strings; $bean = loadBean($module); $mod_strings = return_module_language($current_language, $bean->module_dir); echo "<div class='container' style='font-size:110%;'><center style='font-weight:bold;'>Поля модуля {$app_list_strings['moduleList'][$module]}:</center>\r\n\t\t<br/><table style='width:100%;font-size:100%;'>"; foreach ($bean->field_defs as $field) { echo "<tr><td style='background-color:#596971;color:#fff;text-align:right;padding-right:5px;' width='60%'>\r\n\t\t\t<b>{$mod_strings[$field['vname']]}</b> [{$field['type']}]:</td>\r\n\t\t<td style='background-color:#FFF'>\r\n\t\t\t{$field['name']}</td></tr>"; } echo "</table></div>"; }
public function setUp() { global $dictionary, $bean_list; $this->old_dictionary = $dictionary; $this->old_bean_list = $bean_list; $this->test_standart_field = new TestStandardField(); $this->test_standart_field->module = 'Accounts'; loadBean($this->test_standart_field->module); $this->test_field = get_widget('varchar'); $this->test_field->name = 'name'; $this->bean_name = get_valid_bean_name($this->test_standart_field->module); }
function remove_zero(SugarBean $bean, $event, $arguments) { if ($bean->number_of_floor == '' || $bean->number_of_floor == 0) { $bean->number_of_floor = ''; } if ($bean->floor == '' || $bean->floor == 0) { $bean->floor = ''; } if ($bean->rooms_quantity == '' || $bean->rooms_quantity == 0) { $bean->rooms_quantity = ''; } if ($bean->living_square == '' || $bean->living_square == 0) { $bean->living_square = ''; } if ($event == 'process_record') { // из какой заявки(интересующая недвижимость для контактов) if ($_REQUEST['module'] == 'Contacts' && $_REQUEST['action'] == 'DetailView') { global $db; $q = "SELECT rrit.request_id as id, r.name as name\n\t\t\t\t\tFROM realty_requests_interest_table AS rrit\n\t\t\t\t\tLEFT JOIN request as r ON r.id = rrit.request_id\n\t\t\t\t\tWHERE \n\t\t\t\t\t\trrit.realty_id = '{$bean->id}'\n\t\t\t\t\t\tAND rrit.deleted = 0\n\t\t\t\t\t\tAND r.deleted = 0"; $res = $db->query($q); if ($r = $db->fetchByAssoc($res)) { $bean->request = "<a href='index.php?module=Request&action=DetailView&record={$r['id']}'>{$r['name']}</a>"; } } // if ($_REQUEST['action'] == 'index') { $realty = loadBean('Realty'); $realty->retrieve($bean->id); if ($realty->reserved) { //бронь $bean->name .= "<img style='display:none;' src='themes/default/images/help.gif' width='0' height='0' onload=\"this.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = '#ccc';\" />"; } } elseif (in_array($_REQUEST['action'], array('DetailView', 'SubPanelViewer'))) { if ($_REQUEST['module'] == 'Request') { $date_entered = $GLOBALS['timedate']->to_db_date($bean->date_entered); $diff = DateTime::createFromFormat('Y#m#d', $date_entered)->diff(new DateTime())->days; $file = "custom/modules/Realty/number_days_new_application.txt"; $days_config = file_get_contents($file); //DaysSettings if ($diff < $days_config) { $bean->address_street .= "<img style='display:none;' src='themes/default/images/help.gif' width='0' height='0' onload=\"this.parentNode.parentNode.parentNode.style.backgroundColor = '#cFc';\" />"; } } } } }
function get_new_record_form() { $module = !empty($GLOBALS['QCModule']) ? $GLOBALS['QCModule'] : $GLOBALS['module']; $focus = loadBean($module); if (!$focus->ACLAccess('save')) { return; } $view_sqc = new ViewFactory(); //avoid ViewFactory::_loadConfig() undefined value $view_sqc->module = ''; $view_sqc->action = ''; $view_sqc = $view_sqc->loadView('sidequickcreate', $module); $view_sqc->module = $module; if ($view_sqc->preDisplay()) { return $view_sqc->display(); } }
protected function action_delete() { if ($_REQUEST['record'] != $GLOBALS['current_user']->id && $GLOBALS['current_user']->isAdminForModule('Users')) { $u = new User(); $u->retrieve($_REQUEST['record']); $u->status = 'Inactive'; $u->deleted = 1; $u->employee_status = 'Terminated'; $u->save(); $GLOBALS['log']->info("User id: {$GLOBALS['current_user']->id} deleted user record: {$_REQUEST['record']}"); $eapm = loadBean('EAPM'); $eapm->delete_user_accounts($_REQUEST['record']); $GLOBALS['log']->info("Removing user's External Accounts"); SugarApplication::redirect("index.php?module=Users&action=index"); } else { sugar_die("Unauthorized access to administration."); } }
private function process_relate($field) { $id_name = $this->bean->field_defs[$field]['id_name']; $link = $this->bean->field_defs[$field]['link']; $relationship = $this->bean->field_defs[$link]['relationship']; $id_list = array(); if (isset($_REQUEST[$id_name]) && !empty($_REQUEST[$id_name]) || isset($this->bean->{$id_name}) && !empty($this->bean->{$id_name})) { $parent_id = empty($this->bean->id) ? $_REQUEST[$id_name] : $this->bean->{$id_name}; $parent_bean = loadBean($this->bean->field_defs[$field]['module']); $parent_bean->retrieve($parent_id); foreach ($parent_bean->field_defs as $parent_field => $defs) { if ($defs['type'] == 'link' && $defs['relationship'] == $relationship) { $parent_bean->load_relationship($parent_field); $id_list = $parent_bean->{$parent_field}->get(); } } } return $id_list; }
function afterSave(&$bean) { if (isset($bean->realty_id) && $bean->realty_id != '') { $realty = new Realty(); $realty->retrieve($bean->realty_id); if (isset($realty->last_contact)) { $realty->last_contact = date('Y-m-d'); $realty->save(); } } if (isset($bean->parent_id) && $bean->parent_id != '') { $client = loadBean($bean->parent_type); $client->retrieve($bean->parent_id); if (isset($client->last_contact)) { $client->last_contact = date('Y-m-d'); $client->save(); } } }
public function testParentsAreRelatedDuringImport() { $file = 'upload://test50438.csv'; $ret = file_put_contents($file, $this->fileArr); $this->assertGreaterThan(0, $ret, 'Failed to write to ' . $file . ' for content ' . var_export($this->fileArr, true)); $importSource = new ImportFile($file, ',', '"'); $bean = loadBean('Calls'); $_REQUEST['columncount'] = 5; $_REQUEST['colnum_0'] = 'id'; $_REQUEST['colnum_1'] = 'subject'; $_REQUEST['colnum_2'] = 'status'; $_REQUEST['colnum_3'] = 'parent_type'; $_REQUEST['colnum_4'] = 'parent_id'; $_REQUEST['import_module'] = 'Contacts'; $_REQUEST['importlocale_charset'] = 'UTF-8'; $_REQUEST['importlocale_timezone'] = 'GMT'; $_REQUEST['importlocale_default_currency_significant_digits'] = '2'; $_REQUEST['importlocale_currency'] = '-99'; $_REQUEST['importlocale_dec_sep'] = '.'; $_REQUEST['importlocale_currency'] = '-99'; $_REQUEST['importlocale_default_locale_name_format'] = 's f l'; $_REQUEST['importlocale_num_grp_sep'] = ','; $_REQUEST['importlocale_dateformat'] = 'm/d/y'; $_REQUEST['importlocale_timeformat'] = 'h:i:s'; $importer = new Importer($importSource, $bean); $importer->import(); //fetch the bean using the passed in id and get related contacts require_once 'modules/Calls/Call.php'; $call = new Call(); $call->retrieve($this->call_id); $call->load_relationship('contacts'); $related_contacts = $call->contacts->get(); //test that the contact id is in the array of related contacts. $this->assertContains($this->contact->id, $related_contacts, ' Contact was not related during simulated import despite being set in related parent id'); unset($call); /* if (is_file($file)) { unlink($file); } */ }
/** * @see SugarView::preDisplay() */ public function preDisplay() { if (!empty($_REQUEST['source_module']) && $_REQUEST['source_module'] != 'undefined' && !empty($_REQUEST['record'])) { $this->bean = loadBean($_REQUEST['source_module']); if ($this->bean instanceof SugarBean && !in_array($this->bean->object_name, array('EmailMan'))) { $this->bean->retrieve($_REQUEST['record']); if (!empty($this->bean->id)) { $_REQUEST['parent_id'] = $this->bean->id; } if (!empty($this->bean->module_dir)) { $_REQUEST['parent_type'] = $this->bean->module_dir; } if (!empty($this->bean->name)) { $_REQUEST['parent_name'] = $this->bean->name; } if (!empty($this->bean->id)) { $_REQUEST['return_id'] = $this->bean->id; } if (!empty($this->bean->module_dir)) { $_REQUEST['return_module'] = $this->bean->module_dir; } //Now preload any related fields if (isset($_REQUEST['module'])) { $target_bean = loadBean($_REQUEST['module']); foreach ($target_bean->field_defs as $fields) { if ($fields['type'] == 'relate' && isset($fields['module']) && $fields['module'] == $_REQUEST['source_module'] && isset($fields['rname'])) { $rel_name = $fields['rname']; if (isset($this->bean->{$rel_name})) { $_REQUEST[$fields['name']] = $this->bean->{$rel_name}; } if (!empty($_REQUEST['record']) && !empty($fields['id_name'])) { $_REQUEST[$fields['id_name']] = $_REQUEST['record']; } } } } } $this->_isDCForm = true; } }
/** * Saves a new Contact as well as any related items passed in. * * @return null */ protected function handleSave() { require_once 'modules/Campaigns/utils.php'; require_once "include/formbase.php"; $lead = false; if (!empty($_REQUEST['record'])) { $lead = new Lead(); $lead->retrieve($_REQUEST['record']); } global $beanList; $this->loadDefs(); $beans = array(); $selectedBeans = array(); $selects = array(); // Make sure the contact object is availible for relationships. $beans['Contacts'] = new Contact(); // Contacts if (!empty($_REQUEST['selectedContact'])) { $beans['Contacts']->retrieve($_REQUEST['selectedContact']); if (!empty($beans['Contacts']->id)) { $beans['Contacts']->new_with_id = false; unset($_REQUEST["convert_create_Contacts"]); unset($_POST["convert_create_Contacts"]); } } elseif (!empty($_REQUEST["convert_create_Contacts"]) && $_REQUEST["convert_create_Contacts"] != "false" && !isset($_POST['ContinueContact'])) { require_once 'modules/Contacts/ContactFormBase.php'; $contactForm = new ContactFormBase(); $duplicateContacts = $contactForm->checkForDuplicates('Contacts'); if (isset($duplicateContacts)) { echo $contactForm->buildTableForm($duplicateContacts, 'Contacts'); return; } $this->new_contact = true; } elseif (isset($_POST['ContinueContact'])) { $this->new_contact = true; } // Accounts if (!empty($_REQUEST['selectedAccount'])) { $_REQUEST['account_id'] = $_REQUEST['selectedAccount']; unset($_REQUEST["convert_create_Accounts"]); unset($_POST["convert_create_Accounts"]); } elseif (!empty($_REQUEST["convert_create_Accounts"]) && $_REQUEST["convert_create_Accounts"] != "false" && empty($_POST['ContinueAccount'])) { require_once 'modules/Accounts/AccountFormBase.php'; $accountForm = new AccountFormBase(); $duplicateAccounts = $accountForm->checkForDuplicates('Accounts'); if (isset($duplicateAccounts)) { echo $accountForm->buildTableForm($duplicateAccounts); return; } } foreach ($this->defs as $module => $vdef) { //Create a new record if "create" was selected if (!empty($_REQUEST["convert_create_{$module}"]) && $_REQUEST["convert_create_{$module}"] != "false") { //Save the new record $bean = $beanList[$module]; if (empty($beans[$module])) { $beans[$module] = new $bean(); } $this->populateNewBean($module, $beans[$module], $beans['Contacts'], $lead); // when creating a new contact, create the id for linking with other modules // and do not populate it with lead's old account_id if ($module == 'Contacts') { $beans[$module]->id = create_guid(); $beans[$module]->new_with_id = true; $beans[$module]->account_id = ''; } } else { if (!empty($vdef['ConvertLead']['select'])) { //Save the new record $select = $vdef['ConvertLead']['select']; $fieldDef = $beans['Contacts']->field_defs[$select]; if (!empty($fieldDef['id_name']) && !empty($_REQUEST[$fieldDef['id_name']])) { $beans['Contacts']->{$fieldDef}['id_name'] = $_REQUEST[$fieldDef['id_name']]; $selects[$module] = $_REQUEST[$fieldDef['id_name']]; if (!empty($_REQUEST[$select])) { $beans['Contacts']->{$select} = $_REQUEST[$select]; } // Bug 39268 - Add the existing beans to a list of beans we'll potentially add the lead's activities to $bean = loadBean($module); $bean->retrieve($_REQUEST[$fieldDef['id_name']]); $selectedBeans[$module] = $bean; // If we selected the Contact, just overwrite the $beans['Contacts'] if ($module == 'Contacts') { $beans[$module] = $bean; } } } } } $this->handleActivities($lead, $beans); // Bug 39268 - Add the lead's activities to the selected beans $this->handleActivities($lead, $selectedBeans); //link selected account to lead if it exists if (!empty($selectedBeans['Accounts'])) { $lead->account_id = $selectedBeans['Accounts']->id; } // link account to contact, if we picked an existing contact and created a new account if (!empty($beans['Accounts']->id) && !empty($beans['Contacts']->account_id) && $beans['Accounts']->id != $beans['Contacts']->account_id) { $beans['Contacts']->account_id = $beans['Accounts']->id; } // Saving beans with priorities. // Contacts and Accounts should be saved before lead activities to create correct relations $saveBeanPriority = array('Contacts', 'Accounts'); $tempBeans = array(); foreach ($saveBeanPriority as $name) { if (isset($beans[$name])) { $tempBeans[$name] = $beans[$name]; } } $beans = array_merge($tempBeans, $beans); unset($tempBeans); //Handle non-contacts relationships foreach ($beans as $bean) { if (!empty($lead)) { if (empty($bean->assigned_user_id)) { $bean->assigned_user_id = $lead->assigned_user_id; } $leadsRel = $this->findRelationship($bean, $lead); if (!empty($leadsRel)) { $bean->load_relationship($leadsRel); $relObject = $bean->{$leadsRel}->getRelationshipObject(); if ($relObject->relationship_type == "one-to-many" && $bean->{$leadsRel}->_get_bean_position()) { $id_field = $relObject->rhs_key; $lead->{$id_field} = $bean->id; } else { $bean->{$leadsRel}->add($lead->id); } } } //Special case code for opportunities->Accounts if ($bean->object_name == "Opportunity" && empty($bean->account_id)) { if (isset($beans['Accounts'])) { $bean->account_id = $beans['Accounts']->id; $bean->account_name = $beans['Accounts']->name; } else { if (!empty($selects['Accounts'])) { $bean->account_id = $selects['Accounts']; } } } //create meetings-users relationship if ($bean->object_name == "Meeting") { $bean = $this->setMeetingsUsersRelationship($bean); } $this->copyAddressFields($bean, $beans['Contacts']); $bean->save(); //if campaign id exists then there should be an entry in campaign_log table for the newly created contact: bug 44522 if (isset($lead->campaign_id) && $lead->campaign_id != null && $bean->object_name == "Contact") { campaign_log_lead_or_contact_entry($lead->campaign_id, $lead, $beans['Contacts'], 'contact'); } } if (!empty($lead)) { //Mark the original Lead converted $lead->status = "Converted"; $lead->converted = '1'; $lead->in_workflow = true; $lead->save(); } $this->displaySaveResults($beans); }
/** * fillBeans * This function wraps the call to getList, but takes an additional Array argument * and loads the SugarBean's fields with the results as defined in the connector * loadBean configuration mapping * * @param $args Array of arguments to pass into getItem * @param $module String value of the module to map bean to * @param $bean Array to load SugarBean intances into * @throws Exception Thrown if errors are found */ public function fillBeans($args = array(), $module = null, $beans = array()) { $results = array(); $args = $this->mapInput($args, $module); if (empty($args)) { $GLOBALS['log']->fatal($GLOBALS['app_strings']['ERR_MISSING_MAPPING_ENTRY_FORM_MODULE']); throw new Exception($GLOBALS['app_strings']['ERR_MISSING_MAPPING_ENTRY_FORM_MODULE']); } require_once 'include/connectors/filters/FilterFactory.php'; $filter = FilterFactory::getInstance(get_class($this->_source)); $list = $filter->getList($args, $module); if (!empty($list)) { $resultSize = count($list); if (!empty($beans)) { if (count($beans) != $resultSize) { throw new Exception($GLOBALS['app_strings']['ERR_CONNECTOR_FILL_BEANS_SIZE_MISMATCH']); } } else { for ($x = 0; $x < $resultSize; $x++) { $beans[$x] = loadBean($module); } } $keys = array_keys($beans); $count = 0; foreach ($list as $entry) { //Change the result keys to lower case. This has important ramifications. //This was done because the listviewdefs.php files may not know the proper casing //of the fields to display. We change the keys to lowercase so that the values //may be mapped to the beans without having to rely on the proper string casing //in the listviewdefs.php files. $entry = array_change_key_case($entry, CASE_LOWER); $results[] = $this->mapOutput($beans[$keys[$count]], $entry); $count++; } $field_defs = $this->getFieldDefs(); $map = $this->getMapping(); $hasOptions = !empty($map['options']) ? true : false; if ($hasOptions) { $options = $map['options']; $optionFields = array(); foreach ($field_defs as $name => $field) { if (!empty($field['options']) && !empty($map['options'][$field['options']]) && !empty($map['beans'][$module][$name])) { $optionFields[$name] = $map['beans'][$module][$name]; } } foreach ($results as $key => $bean) { foreach ($optionFields as $sourceField => $sugarField) { $options_map = $options[$field_defs[$sourceField]['options']]; $results[$key]->{$sugarField} = !empty($options_map[$results[$key]->{$sugarField}]) ? $options_map[$results[$key]->{$sugarField}] : $results[$key]->{$sugarField}; } } //foreach } } return $results; }
/** * create_export_query is used for export and massupdate * We haven't handle the these fields: $field['type'] == 'relate' && isset($field['link'] * This function will correct the where clause and output necessary join condition for them * @param $module: the module name * @param $searchFields: searchFields which is got after $searchForm->populateFromArray() * @param $where: where clauses * @return $ret_array['where']: corrected where clause * @return $ret_array['join']: extra join condition */ function create_export_query_relate_link_patch($module, $searchFields, $where) { if (file_exists('modules/' . $module . '/SearchForm.html')) { $ret_array['where'] = $where; return $ret_array; } $seed = loadBean($module); foreach ($seed->field_defs as $name => $field) { if ($field['type'] == 'relate' && isset($field['link']) && !empty($searchFields[$name]['value'])) { $seed->load_relationship($field['link']); $params = array(); if (empty($join_type)) { $params['join_type'] = ' LEFT JOIN '; } else { $params['join_type'] = $join_type; } if (isset($data['join_name'])) { $params['join_table_alias'] = $field['join_name']; } else { $params['join_table_alias'] = 'join_' . $field['name']; } if (isset($data['join_link_name'])) { $params['join_table_link_alias'] = $field['join_link_name']; } else { $params['join_table_link_alias'] = 'join_link_' . $field['name']; } $join = $seed->{$field}['link']->getJoin($params, true); $join_table_alias = 'join_' . $field['name']; if (isset($field['db_concat_fields'])) { $db_field = db_concat($join_table_alias, $field['db_concat_fields']); $where = preg_replace('/' . $field['name'] . '/', $db_field, $where); } else { $where = preg_replace('/(^|[\\s(])' . $field['name'] . '/', '${1}' . $join_table_alias . '.' . $field['rname'], $where); } } } $ret_array = array('where' => $where, 'join' => $join['join']); return $ret_array; }
function __construct() { $result = $GLOBALS['db']->query("SELECT id FROM saved_search"); while ($row = $GLOBALS['db']->fetchByAssoc($result)) { $focus = new SavedSearch(); $focus->retrieve($row['id']); $contents = unserialize(base64_decode($focus->contents)); $has_team_name_saved = isset($contents['team_name_advanced']) || isset($contents['team_name_basic']) ? true : false; //If $contents['searchFormTab'] is set then this is coming from a 4.x saved search if (isset($contents['searchFormTab']) && $contents['searchFormTab'] == 'saved_views') { $new_contents = array(); $module = $contents['search_module']; $advanced = !empty($contents['advanced']); $field_map = array(); if (file_exists("custom/modules/{$module}/metadata/searchdefs.php")) { require "custom/modules/{$module}/metadata/searchdefs.php"; $field_map = $advanced ? $searchdefs[$module]['layout']['advanced_search'] : $searchdefs[$module]['layout']['basic_search']; } else { if (file_exists("modules/{$module}/metadata/SearchFields.php")) { require "modules/{$module}/metadata/SearchFields.php"; $field_map = $searchFields[$module]; } else { $bean = loadBean($module); $field_map = $bean->field_name_map; } } //Special case for team_id field (from 4.5.x) if (isset($contents['team_id'])) { $contents['team_name'] = $contents['team_id']; unset($contents['team_id']); } foreach ($contents as $key => $value) { if (isset($field_map[$key])) { $new_key = $key . ($advanced ? '_advanced' : '_basic'); if (preg_match('/^team_name_(advanced|basic)$/', $new_key)) { if (!is_array($value)) { $temp_value = array(); $teap_value[] = $value; $value = $temp_value; } $team_results = $GLOBALS['db']->query("SELECT id, name FROM teams where id in ('" . implode("','", $value) . "')"); if (!empty($team_results)) { $count = 0; while ($team_row = $GLOBALS['db']->fetchByAssoc($team_results)) { $team_key = $new_key . '_collection_' . $count; $new_contents[$team_key] = $team_row['name']; $new_contents['id_' . $team_key] = $team_row['id']; $count++; } //while } //if //Unset the original key unset($new_contents[$key]); //Add the any switch $new_contents[$new_key . '_type'] = 'any'; } else { $new_contents[$new_key] = $value; } } else { $new_contents[$key] = $value; } } $new_contents['searchFormTab'] = $advanced ? 'advanced_search' : 'basic_search'; $content = base64_encode(serialize($new_contents)); $GLOBALS['db']->query("UPDATE saved_search SET contents = '{$content}' WHERE id = '{$row['id']}'"); } else { if ($has_team_name_saved) { //Otherwise, if the boolean has_team_name_saved is set to true, we also need to parse (coming from 5.x) if (isset($contents['team_name_advanced'])) { $team_results = $GLOBALS['db']->query("SELECT name FROM teams where id = '{$contents['team_name_advanced']}'"); if (!empty($team_results)) { $team_row = $GLOBALS['db']->fetchByAssoc($team_results); $contents['team_name_advanced_collection_0'] = $team_row['name']; $contents['id_team_name_advanced_collection_0'] = $contents['team_name_advanced']; $contents['team_name_advanced_type'] = 'any'; unset($contents['team_name_advanced']); $content = base64_encode(serialize($contents)); $GLOBALS['db']->query("UPDATE saved_search SET contents = '{$content}' WHERE id = '{$row['id']}'"); } } } } } //while }
function populateRequest() { global $timedate; if (isset($this->contents['search_module'])) { $searchModuleBean = loadBean($this->contents['search_module']); } foreach ($this->contents as $key => $val) { if ($key != 'advanced' && $key != 'module' && !strpos($key, '_ORDER_BY') && $key != 'lvso') { if (isset($searchModuleBean) && !empty($val) && preg_match('/^(start_range_|end_range_|range_)?(.*?)(_advanced|_basic)$/', $key, $match)) { $field = $match[2]; if (isset($searchModuleBean->field_defs[$field]['type'])) { $type = $searchModuleBean->field_defs[$field]['type']; //Avoid macro values for the date types if (($type == 'date' || $type == 'datetime' || $type == 'datetimecombo') && preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $val) && !preg_match('/^\\[.*?\\]$/', $val)) { $val = $timedate->to_display_date($val, false); } else { if (($type == 'int' || $type == 'currency' || $type == 'decimal' || $type == 'float') && isset($this->contents[$key . '_unformatted_number']) && preg_match('/^\\d+$/', $val)) { require_once 'modules/Currencies/Currency.php'; $val = format_number($val); if ($type == 'currency' && isset($this->contents[$key . '_currency_symbol'])) { $val = $this->contents[$key . '_currency_symbol'] . $val; } } } } } $_REQUEST[$key] = $val; $_GET[$key] = $val; } } }
function action_DefaultSoapPopup() { $this->view = 'ajax'; $source_id = $_REQUEST['source_id']; $module = $_REQUEST['module_id']; $id = $_REQUEST['record_id']; $mapping = $_REQUEST['mapping']; $mapping = explode(',', $mapping); //Error checking //Load bean $bean = loadBean($module); $bean->retrieve($id); require_once 'include/connectors/ConnectorFactory.php'; $component = ConnectorFactory::getInstance($source_id); //Create arguments $args = array(); $field_defs = $bean->getFieldDefinitions(); foreach ($field_defs as $id => $field) { if (!empty($bean->{$id})) { $args[$id] = $bean->{$id}; } } $beans = $component->fillBeans($args, $module); if (!empty($beans) && !empty($mapping)) { $results = array(); $count = 0; foreach ($beans as $bean) { foreach ($mapping as $field) { $results[$count][$field] = $bean->{$field}; } $count++; } $json = getJSONobj(); echo $json->encode($results); } else { $GLOBALS['log']->error($GLOBALS['app_strings']['ERR_MISSING_MAPPING_ENTRY_FORM_MODULE']); echo ''; } }
/** * @see SugarFieldBase::importSanitize() */ public function importSanitize($value, $vardef, $focus, ImportFieldSanitize $settings) { if (!isset($vardef['module'])) { return false; } $newbean = loadBean($vardef['module']); // Bug 38885 - If we are relating to the Users table on user_name, there's a good chance // that the related field data is the full_name, rather than the user_name. So to be sure // let's try to lookup the field the relationship is expecting to use (user_name). if ($vardef['module'] == 'Users' && isset($vardef['rname']) && $vardef['rname'] == 'user_name') { $userFocus = new User(); $query = sprintf("SELECT user_name FROM {$userFocus->table_name} WHERE %s=%s AND deleted=0", $userFocus->db->concat('users', array('first_name', 'last_name')), $userFocus->db->quoted($value)); $username = $userFocus->db->getOne($query); if (!empty($username)) { $value = $username; } } // Bug 32869 - Assumed related field name is 'name' if it is not specified if (!isset($vardef['rname'])) { $vardef['rname'] = 'name'; } // Bug 27046 - Validate field against type as it is in the related field $rvardef = $newbean->getFieldDefinition($vardef['rname']); if (isset($rvardef['type']) && method_exists($this, $rvardef['type'])) { $fieldtype = $rvardef['type']; $returnValue = $settings->{$fieldtype}($value, $rvardef); if (!$returnValue) { return false; } else { $value = $returnValue; } } if (isset($vardef['id_name'])) { $idField = $vardef['id_name']; // Bug 24075 - clear out id field value if it is invalid if (isset($focus->{$idField})) { $checkfocus = loadBean($vardef['module']); if ($checkfocus && is_null($checkfocus->retrieve($focus->{$idField}))) { $focus->{$idField} = ''; } } // be sure that the id isn't already set for this row if (empty($focus->{$idField}) && $idField != $vardef['name'] && !empty($vardef['rname']) && !empty($vardef['table'])) { // Bug 27562 - Check db_concat_fields first to see if the field name is a concat $relatedFieldDef = $newbean->getFieldDefinition($vardef['rname']); if (isset($relatedFieldDef['db_concat_fields']) && is_array($relatedFieldDef['db_concat_fields'])) { $fieldname = $focus->db->concat($vardef['table'], $relatedFieldDef['db_concat_fields']); } else { $fieldname = $vardef['rname']; } // lookup first record that matches in linked table $query = "SELECT id\n FROM {$vardef['table']}\n WHERE {$fieldname} = '" . $focus->db->quote($value) . "'\n AND deleted != 1"; $result = $focus->db->limitQuery($query, 0, 1, true, "Want only a single row"); if (!empty($result)) { if ($relaterow = $focus->db->fetchByAssoc($result)) { $focus->{$idField} = $relaterow['id']; } elseif (!$settings->addRelatedBean || $newbean->bean_implements('ACL') && !$newbean->ACLAccess('save') || in_array($newbean->module_dir, array('Teams', 'Users'))) { return false; } else { // add this as a new record in that bean, then relate if (isset($relatedFieldDef['db_concat_fields']) && is_array($relatedFieldDef['db_concat_fields'])) { $relatedFieldParts = explode(' ', $value); foreach ($relatedFieldDef['db_concat_fields'] as $relatedField) { $newbean->{$relatedField} = array_shift($relatedFieldParts); } } else { $newbean->{$vardef}['rname'] = $value; } if (!isset($focus->assigned_user_id) || $focus->assigned_user_id == '') { $newbean->assigned_user_id = $GLOBALS['current_user']->id; } else { $newbean->assigned_user_id = $focus->assigned_user_id; } if (!isset($focus->modified_user_id) || $focus->modified_user_id == '') { $newbean->modified_user_id = $GLOBALS['current_user']->id; } else { $newbean->modified_user_id = $focus->modified_user_id; } // populate fields from the parent bean to the child bean $focus->populateRelatedBean($newbean); $newbean->save(false); $focus->{$idField} = $newbean->id; $settings->createdBeans[] = ImportFile::writeRowToLastImport($focus->module_dir, $newbean->object_name, $newbean->id); } } } } return $value; }
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 poplate 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 = 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']->quoteForEmail($search_value); } else { foreach ($search_value as $key => &$val) { $val = $GLOBALS['db']->quoteForEmail($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; } } } global $current_user; if (!is_admin($current_user)) { $params = array('massupdate' => false); $lv->export = false; } else { $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_once $metafiles[$this->module]['searchfields']; } elseif (file_exists('modules/' . $this->module . '/metadata/SearchFields.php')) { require_once 'modules/' . $this->module . '/metadata/SearchFields.php'; } $searchForm = new SearchForm($this->seed, $this->module, $this->action); $searchForm->setup($searchdefs, $searchFields, 'include/SearchForm/tpls/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; } if (empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false) { if (!is_admin($current_user)) { $lv->setup($seed, 'include/ListView/ListViewNoMassUpdate.tpl', $where, $params); } else { $lv->setup($seed, 'include/ListView/ListViewGeneric.tpl', $where, $params); } $savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : ' - ' . $_REQUEST['saved_search_select_name']; echo $lv->display(); } }
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'; } 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'; } if (!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)) { $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, 'include/SearchForm/tpls/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 */ $searchForm->populateFromArray(unserialize(base64_decode($query)), null, true); // see bug 31271 $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 = ''; } }
/** * Checks to see if the given bean is a duplicate based off the given indexes * * @param array $indexlist * @return bool true if this bean is a duplicate or false if it isn't */ public function isADuplicateRecord($indexlist) { // Bug #51264 : Importing updates to rows prevented by duplicates check if (!empty($this->_focus) && $this->_focus instanceof SugarBean && !empty($this->_focus->id)) { $_focus = clone $this->_focus; $_focus->id = null; $_focus->retrieve($this->_focus->id); if (!empty($_focus->id)) { return false; } unset($_focus); } //lets strip the indexes of the name field in the value and leave only the index name $origIndexList = $indexlist; $indexlist = array(); $fieldlist = array(); $customIndexlist = array(); foreach ($origIndexList as $iv) { if (empty($iv)) { continue; } $field_index_array = explode('::', $iv); if ($field_index_array[0] == 'customfield') { //this is a custom field, so place in custom array $customIndexlist[] = $field_index_array[1]; } else { //this is not a custom field, so place in index list $indexlist[] = $field_index_array[0]; if (isset($field_index_array[1])) { $fieldlist[] = $field_index_array[1]; } } } //if full_name is set, then manually search on the first and last name fields before iterating through rest of fields //this is a special handling of the name fields on people objects, the rest of the fields are checked individually if (in_array('full_name', $indexlist)) { $newfocus = loadBean($this->_focus->module_dir); $result = $newfocus->retrieve_by_string_fields(array('deleted' => '0', 'first_name' => $this->_focus->first_name, 'last_name' => $this->_focus->last_name), true); if (!is_null($result)) { //set dupe field to full_name and name fields $this->_dupedFields[] = 'full_name'; $this->_dupedFields[] = 'first_name'; $this->_dupedFields[] = 'last_name'; } } // loop through var def indexes and compare with selected indexes foreach ($this->_getIndexVardefs() as $index) { // if we get an index not in the indexlist, loop if (!in_array($index['name'], $indexlist)) { continue; } // This handles the special case of duplicate email checking if ($index['name'] == 'special_idx_email1' || $index['name'] == 'special_idx_email2') { $emailAddress = new SugarEmailAddress(); $email = $index['fields'][0]; if ($emailAddress->getCountEmailAddressByBean($this->_focus->{$email}, $this->_focus, $index['name'] == 'special_idx_email1') > 0) { foreach ($index['fields'] as $field) { if ($field != 'deleted') { $this->_dupedFields[] = $field; } } } } elseif (isset($index['dupeCheckFunction'])) { $functionName = substr_replace($index['dupeCheckFunction'], '', 0, 9); if (method_exists($this->_focus, $functionName) && $this->_focus->{$functionName}($index) === true) { return $this->_focus->{$functionName}($index); } } else { $index_fields = array('deleted' => '0'); //search only for the field we have selected foreach ($index['fields'] as $field) { if ($field == 'deleted' || !in_array($field, $fieldlist)) { continue; } if (!in_array($field, $index_fields)) { if (isset($this->_focus->{$field}) && strlen($this->_focus->{$field}) > 0) { $index_fields[$field] = $this->_focus->{$field}; } } } // if there are no valid fields in the index field list, loop if (count($index_fields) <= 1) { continue; } $newfocus = loadBean($this->_focus->module_dir); $result = $newfocus->retrieve_by_string_fields($index_fields, true); if (!is_null($result)) { //remove deleted as a duped field unset($index_fields['deleted']); //create string based on array of dupe fields $this->_dupedFields = array_merge(array_keys($index_fields), $this->_dupedFields); } } } //return true if any dupes were found if (!empty($this->_dupedFields)) { return true; } return false; }
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); } }
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. //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); } $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'; } if (!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, 'include/SearchForm/tpls/SearchFormGeneric.tpl'); } $searchForm->populateFromArray(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; }
/** * upgradeModulesForTeamsets * * This method adds the team_set_id values to the module tables that have the new team_set_id column * added through the SugarCRM 5.5.x upgrade process. It also adds the values into the team_sets and * team_sets_teams tables. * * @param filter Array of modules to process; empty by default */ function upgradeModulesForTeamsets($filter = array()) { require 'include/modules.php'; foreach ($beanList as $moduleName => $beanName) { if (!empty($filter) && array_search($moduleName, $filter) === false) { continue; } if ($moduleName == 'TeamMemberships' || $moduleName == 'ForecastOpportunities') { continue; } $bean = loadBean($moduleName); if (empty($bean) || empty($bean->table_name)) { continue; } $FieldArray = $GLOBALS['db']->helper->get_columns($bean->table_name); if (!isset($FieldArray['team_id'])) { continue; } upgradeTeamColumn($bean, 'team_id'); } //foreach //Upgrade users table $bean = loadBean('Users'); upgradeTeamColumn($bean, 'default_team'); $result = $GLOBALS['db']->query("SELECT id FROM teams where deleted=0"); while ($row = $GLOBALS['db']->fetchByAssoc($result)) { $teamset = new TeamSet(); $teamset->addTeams($row['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 = unserialize(base64_decode($current_query_by_page)); $module = $current_query_by_page_array['module']; $seed = loadBean($module); $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'])) { require_once $metafiles[$module]['searchdefs']; } elseif (file_exists('modules/' . $module . '/metadata/searchdefs.php')) { require_once 'modules/' . $module . '/metadata/searchdefs.php'; } if (!empty($metafiles[$module]['searchfields'])) {
/** * @see SugarView::display() */ public function display() { require_once 'include/connectors/utils/ConnectorUtils.php'; require_once 'include/connectors/sources/SourceFactory.php'; $connector_strings = ConnectorUtils::getConnectorStrings($_REQUEST['source_id']); $sources = ConnectorUtils::getConnectors(); $source_id = $_REQUEST['source_id']; $source = SourceFactory::getSource($source_id); $is_enabled = ConnectorUtils::isSourceEnabled($source_id); $script = ''; $display_data = array(); if ($is_enabled) { $mapping = $source->getMapping(); $source_defs = $source->getFieldDefs(); //Create the Javascript code to dynamically add the tables $json = getJSONobj(); foreach ($mapping['beans'] as $module => $field_mapping) { $mod_strings = return_module_language($GLOBALS['current_language'], $module); $bean = loadBean($module); if (!is_object($bean)) { continue; } $field_defs = $bean->getFieldDefinitions(); $available_fields = array(); $labels = array(); $duplicate_labels = array(); foreach ($field_defs as $id => $def) { //We are filtering out some fields here if ($def['type'] == 'relate' || $def['type'] == 'link' || isset($def['dbType']) && $def['dbType'] == 'id') { continue; } if (isset($def['vname'])) { $available_fields[$id] = !empty($mod_strings[$def['vname']]) ? $mod_strings[$def['vname']] : $id; } else { $available_fields[$id] = $id; } //Remove the ':' character in some labels if (preg_match('/\\:$/', $available_fields[$id])) { $available_fields[$id] = substr($available_fields[$id], 0, strlen($available_fields[$id]) - 1); } if (isset($labels[$available_fields[$id]])) { $duplicate_labels[$labels[$available_fields[$id]]] = $labels[$available_fields[$id]]; $duplicate_labels[$id] = $id; } else { $labels[$available_fields[$id]] = $id; } } foreach ($duplicate_labels as $id) { $available_fields[$id] = $available_fields[$id] . " ({$id})"; } asort($available_fields); $field_keys = array(); $field_values = array(); $source_fields = array(); foreach ($field_mapping as $id => $field) { if (!empty($source_defs[$id])) { $source_fields[$id] = $source_defs[$id]; } } $source_fields = array_merge($source_fields, $source_defs); foreach ($source_fields as $id => $def) { if (empty($def['hidden'])) { $field_keys[strtolower($id)] = !empty($connector_strings[$source_fields[$id]['vname']]) ? $connector_strings[$source_fields[$id]['vname']] : $id; $field_values[] = !empty($field_mapping[strtolower($id)]) ? $field_mapping[strtolower($id)] : ''; } } $display_data[$module] = array('field_keys' => $field_keys, 'field_values' => $field_values, 'available_fields' => $available_fields, 'field_mapping' => $field_mapping); } } $this->ss->assign('display_data', $display_data); $this->ss->assign('empty_mapping', empty($display_data) ? true : false); $this->ss->assign('dynamic_script', $script); $this->ss->assign('sources', $sources); $this->ss->assign('mod', $GLOBALS['mod_strings']); $this->ss->assign('APP', $GLOBALS['app_strings']); $this->ss->assign('source_id', $source_id); $this->ss->assign('source_name', $sources[$source_id]['name']); $this->ss->assign('theme', $GLOBALS['theme']); echo $this->ss->fetch('modules/Connectors/tpls/mapping_properties.tpl'); }