function process() { global $current_user, $timedate, $app_list_strings, $current_language, $mod_strings; $mod_strings = return_module_language($current_language, 'ProjectTask'); parent::process(); if ($this->viaAJAX) { // override for ajax call $this->ss->assign('saveOnclick', "onclick='if(check_form(\"projectTaskQuickCreate\")) return SUGAR.subpanelUtils.inlineSave(this.form.id, \"projecttask\"); else return false;'"); $this->ss->assign('cancelOnclick', "onclick='return SUGAR.subpanelUtils.cancelCreate(\"subpanel_projecttask\")';"); } $this->ss->assign('viaAJAX', $this->viaAJAX); $this->javascript = new javascript(); $this->javascript->setFormName('projectTaskQuickCreate'); $focus = BeanFactory::getBean('ProjectTask'); $this->javascript->setSugarBean($focus); $this->javascript->addAllFields(''); $this->ss->assign('additionalScripts', $this->javascript->getScript(false)); $json = getJSONobj(); /////////////////////////////////////// /// /// SETUP PARENT POPUP $popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'projectTypeQuickCreate', 'field_to_name_array' => array('id' => 'parent_id', 'name' => 'parent_name')); $encoded_parent_popup_request_data = $json->encode($popup_request_data); $this->ss->assign('encoded_parent_popup_request_data', $encoded_parent_popup_request_data); $popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'projectTaskQuickCreate', 'field_to_name_array' => array('id' => 'account_id', 'name' => 'account_name')); $encoded_popup_request_data = $json->encode($popup_request_data); $this->ss->assign('encoded_popup_request_data', $encoded_popup_request_data); $popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'projectTaskQuickCreate', 'field_to_name_array' => array('id' => 'team_id', 'name' => 'team_name')); $this->ss->assign('encoded_team_popup_request_data', $json->encode($popup_request_data)); }
function process() { global $current_user, $timedate, $app_list_strings, $current_language, $mod_strings; $mod_strings = return_module_language($current_language, 'Contracts'); parent::process(); if ($this->viaAJAX) { // override for ajax call $this->ss->assign('saveOnclick', "onclick='if(check_form(\"contractsQuickCreate\")) return SUGAR.subpanelUtils.inlineSave(this.form.id, \"contracts\"); else return false;'"); $this->ss->assign('cancelOnclick', "onclick='return SUGAR.subpanelUtils.cancelCreate(\"subpanel_contracts\")';"); } $this->ss->assign('viaAJAX', $this->viaAJAX); $this->javascript = new javascript(); $this->javascript->setFormName('contractsQuickCreate'); $focus = BeanFactory::getBean('Contracts'); $this->javascript->setSugarBean($focus); $this->javascript->addAllFields(''); $status_options = isset($focus->status) ? get_select_options_with_id($app_list_strings['contract_status_dom'], $focus->status) : get_select_options_with_id($app_list_strings['contract_status_dom'], ''); $this->ss->assign('STATUS_OPTIONS', $status_options); $json = getJSONobj(); $popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'contractsQuickCreate', 'field_to_name_array' => array('id' => 'account_id', 'name' => 'account_name')); $encoded_popup_request_data = $json->encode($popup_request_data); $this->ss->assign('encoded_popup_request_data', $encoded_popup_request_data); $popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'contractsQuickCreate', 'field_to_name_array' => array('id' => 'team_id', 'name' => 'team_name')); $this->ss->assign('encoded_team_popup_request_data', $json->encode($popup_request_data)); $this->ss->assign('additionalScripts', $this->javascript->getScript(false)); }
public function setUp() { SugarTestHelper::setUp('beanList'); SugarTestHelper::setUp('beanFiles'); SugarTestHelper::setUp('current_user'); $this->case = BeanFactory::getBean('Cases'); }
public function testGetLinkedBeans() { //Test the accounts_leads relationship $account = BeanFactory::newBean("Accounts"); $account->name = "GetLinkedBeans Test Account"; $account->save(); $this->createdBeans[] = $account; $case = BeanFactory::newBean("Cases"); $case->name = "GetLinkedBeans Test Cases"; $case->save(); $this->createdBeans[] = $case; $this->assertTrue($account->load_relationship("cases")); $this->assertInstanceOf("Link2", $account->cases); $this->assertTrue($account->cases->loadedSuccesfully()); $account->cases->add($case); $account->save(); $where = array('lhs_field' => 'id', 'operator' => ' LIKE ', 'rhs_value' => "{$case->id}"); $cases = $account->get_linked_beans('cases', 'Case', array(), 0, 10, 0, $where); $this->assertEquals(1, count($cases), 'Assert that we have found the test case linked to the test account'); $contact = BeanFactory::newBean("Contacts"); $contact->first_name = "First Name GetLinkedBeans Test Contacts"; $contact->last_name = "First Name GetLinkedBeans Test Contacts"; $contact->save(); $this->createdBeans[] = $contact; $this->assertTrue($account->load_relationship("contacts")); $this->assertInstanceOf("Link2", $account->contacts); $this->assertTrue($account->contacts->loadedSuccesfully()); $account->contacts->add($contact); $where = array('lhs_field' => 'id', 'operator' => ' LIKE ', 'rhs_value' => "{$contact->id}"); $contacts = $account->get_linked_beans('contacts', 'Contact', array(), 0, -1, 0, $where); $this->assertEquals(1, count($contacts), 'Assert that we have found the test contact linked to the test account'); }
public function run() { // this always needs to be ran // get the get_widget helper and the StandardField Helper require_once 'modules/DynamicFields/FieldCases.php'; require_once 'modules/ModuleBuilder/parsers/StandardField.php'; // we are working with opportunities $bean = BeanFactory::getBean('Opportunities'); // get the field defs $field_defs = $bean->getFieldDefinition('sales_stage'); // load the field type up $f = get_widget($field_defs['type']); // populate the row from the vardefs that were loaded $f->populateFromRow($field_defs); $this->log('Current Sales Stage Default is: ' . var_export($f->default, true)); // lets always make sure that the default is in the list of options if (isset($f->options) && isset($GLOBALS['app_list_strings'][$f->options])) { if (!in_array($f->default, array_keys($GLOBALS['app_list_strings'][$f->options]))) { $this->log(var_export($f->default, true) . ' Is Not In The List Of Options'); $f->default = array_shift(array_keys($GLOBALS['app_list_strings'][$f->options])); $f->default_value = array_shift(array_keys($GLOBALS['app_list_strings'][$f->options])); $this->log('New Sales Stage Default Is: ' . var_export($f->default, true)); // save the changes to the field $df = new StandardField($bean->module_name); $df->setup($bean); $f->module = $bean; $f->save($df); } } }
function save_lines(array $post, AOR_Report $bean, $postKey) { $seenIds = array(); if (isset($post[$postKey . 'id'])) { foreach ($post[$postKey . 'id'] as $key => $id) { if ($id) { $aorChart = BeanFactory::getBean('AOR_Charts', $id); } else { $aorChart = BeanFactory::newBean('AOR_Charts'); } $aorChart->name = $post[$postKey . 'title'][$key]; $aorChart->type = $post[$postKey . 'type'][$key]; $aorChart->x_field = $post[$postKey . 'x_field'][$key]; $aorChart->y_field = $post[$postKey . 'y_field'][$key]; $aorChart->aor_report_id = $bean->id; $aorChart->save(); $seenIds[] = $aorChart->id; } } //Any beans that exist but aren't in $seenIds must have been removed. foreach ($bean->get_linked_beans('aor_charts', 'AOR_Charts') as $chart) { if (!in_array($chart->id, $seenIds)) { $chart->mark_deleted($chart->id); } } }
public function process() { // fetch the data from the filter end point $file = 'modules/ForecastWorksheets/clients/base/api/ForecastWorksheetsFilterApi.php'; $klass = 'ForecastWorksheetsFilterApi'; SugarAutoLoader::requireWithCustom('include/api/RestService.php'); SugarAutoLoader::requireWithCustom($file); $klass = SugarAutoLoader::customClass($klass); /* @var $obj ForecastWorksheetsFilterApi */ $obj = new $klass(); $api = new RestService(); $api->user = $GLOBALS['current_user']; $data = $obj->forecastWorksheetsGet($api, array('module' => 'ForecastWorksheets', 'timeperiod_id' => $this->getArg('timeperiod_id'), 'user_id' => $this->getArg('user_id'))); $fields_array = array('date_closed' => 'date_closed', 'sales_stage' => 'sales_stage', 'name' => 'name', 'commit_stage' => 'commit_stage', 'probability' => 'probability'); $admin = BeanFactory::getBean('Administration'); $settings = $admin->getConfigForModule('Forecasts'); if ($settings['show_worksheet_best']) { $fields_array['best_case'] = 'best_case'; } if ($settings['show_worksheet_likely']) { $fields_array['likely_case'] = 'likely_case'; } if ($settings['show_worksheet_worst']) { $fields_array['worst_case'] = 'worst_case'; } $seed = BeanFactory::getBean('ForecastWorksheets'); return $this->getContent($data['records'], $seed, $fields_array, 'commit_stage', $this->getArg('filters')); }
function init($module_name, $subPanelName) { $GLOBALS['log']->debug("in ParserModifySubPanel: module_name={$module_name} child_module={$subPanelName}"); $this->moduleName = $module_name; $this->subPanelName = $subPanelName; global $beanList; // Sometimes we receive a module name which is not in the correct CamelCase, so shift to lower case for all beanList lookups $beanListLower = array_change_key_case($beanList); // Retrieve the definitions for all the available subpanels for this module $module = BeanFactory::newBeanByName($beanListLower[strtolower($this->moduleName)]); require_once 'include/SubPanel/SubPanelDefinitions.php'; $spd = new SubPanelDefinitions($module); // Get the lists of fields already in the subpanel and those that can be added in // Get the fields lists from an aSubPanel object describing this subpanel from the SubPanelDefinitions object $this->originalListViewDefs = array(); if (array_key_exists(strtolower($this->subPanelName), $spd->layout_defs['subpanel_setup'])) { $originalPanel = $spd->load_subpanel($this->subPanelName, true); $this->originalListViewDefs = $originalPanel->get_list_fields(); $this->panel = $spd->load_subpanel($subPanelName, false); $this->listViewDefs = $this->panel->get_list_fields(); // Retrieve a copy of the bean for the parent module of this subpanel - so we can find additional fields for the layout $subPanelParentModuleName = $this->panel->get_module_name(); $this->subPanelParentModule = null; if (!empty($subPanelParentModuleName) && isset($beanListLower[strtolower($subPanelParentModuleName)])) { $this->subPanelParentModule = BeanFactory::newBeanByName($beanListLower[strtolower($subPanelParentModuleName)]); } } $this->language_module = $this->panel->template_instance->module_dir; }
function displayList($layout_def) { global $app_strings; global $subpanel_item_count; $unique_id = $layout_def['subpanel_id'] . "_edit_" . $subpanel_item_count; //bug 51512 if ($layout_def['EditView']) { // @see SugarWidgetSubPanelTopButtonQuickCreate::get_subpanel_relationship_name() $relationship_name = ''; if (!empty($layout_def['linked_field'])) { $relationship_name = $layout_def['linked_field']; $bean = BeanFactory::getBean($layout_def['module']); if (!empty($bean->field_defs[$relationship_name]['relationship'])) { $relationship_name = $bean->field_defs[$relationship_name]['relationship']; } } $handler = 'subp_nav(\'' . $layout_def['module'] . '\', \'' . $layout_def['fields']['ID'] . '\', \'e\', this'; if (!empty($relationship_name)) { $handler .= ', \'' . $relationship_name . '\''; } $handler .= ');'; return '<a href="#" onmouseover="' . $handler . '" onfocus="' . $handler . '" class="listViewTdToolsS1" id="' . $unique_id . '">' . $app_strings['LNK_EDIT'] . '</a>'; } return ''; }
/** * @see SugarView::display() */ public function display() { $ss = new Sugar_Smarty(); $ss->assign("MOD", $GLOBALS['mod_strings']); $ss->assign("INSTRUCTION", "<h1>Retrieve seller list from ebay</h1>"); $bean = BeanFactory::getBean('xeBayAccounts'); $resp = $bean->get_list("", "ebay_auth_token<>''", 0, -1, -1, 0, false, array('name')); if ($resp['row_count'] > 0) { $ebay_account_options = "<select name='ebay_account_name' id='ebay_account_name' title=''>"; if ($resp['row_count'] > 1) { $ebay_account_options .= "<option value='All'>All</option>"; } foreach ($resp['list'] as &$account) { $name = $account->name; $ebay_account_options .= "<option value='{$name}'>{$name}</option>"; } $ebay_account_options .= "</select>"; $ss->assign("EBAY_ACCOUNT_OPTIONS", $ebay_account_options); } $javascript = <<<EOQ function ImportConfirm() { \t\treturn confirm("Do you want to retrieve seller list now ?"); } EOQ; $ss->assign("JAVASCRIPT", $javascript); echo $ss->fetch("modules/xeBaySellerLists/tpls/import.tpl"); }
/** * * @global type $locale * @codeCoverageIgnore */ public function __construct() { global $locale; $this->locale = $locale; $this->eventDefinitionBean = BeanFactory::getBean('pmse_BpmEventDefinition'); parent::__construct(); }
/** * Add records to a specific prospect list * * @param $moduleName the module name for the records that will be associated to the prospect list * @param $prospectListId the id of the prospect list * @param $recordIds Array of record ids to be added to the prospect list * @return $results Associative array containing status for each record. */ public function addRecordsToProspectList($moduleName, $prospectListId, $recordIds) { $prospectList = BeanFactory::getBean("ProspectLists", $prospectListId, array('strict_retrieve' => true)); if (empty($prospectList)) { return false; } $bean = BeanFactory::newBean($moduleName); $results = array(); $relationship = ''; foreach ($bean->get_linked_fields() as $field => $def) { if ($bean->load_relationship($field)) { if ($bean->{$field}->getRelatedModuleName() == 'ProspectLists') { $relationship = $field; break; } } } if ($relationship != '') { foreach ($recordIds as $id) { $retrieveResult = $bean->retrieve($id); if ($retrieveResult === null) { $results[$id] = false; } else { $bean->load_relationship($relationship); $bean->prospect_lists->add($prospectListId); $results[$id] = true; } } } return $results; }
function process() { global $current_user, $timedate, $app_list_strings, $current_language, $mod_strings; $mod_strings = return_module_language($current_language, 'Opportunities'); $json = getJSONobj(); parent::process(); list($num_grp_sep, $dec_sep) = get_number_seperators(); $this->ss->assign('NUM_GRP_SEP', $num_grp_sep); $this->ss->assign('DEC_SEP', $dec_sep); $this->ss->assign('CURRENCY_ID', $current_user->getPreference('currency')); $this->ss->assign("SALES_STAGE_OPTIONS", get_select_options_with_id($app_list_strings['sales_stage_dom'], '')); $this->ss->assign("LEAD_SOURCE_OPTIONS", get_select_options_with_id($app_list_strings['lead_source_dom'], '')); $this->ss->assign('prob_array', $json->encode($app_list_strings['sales_probability_dom'])); if ($this->viaAJAX) { // override for ajax call $this->ss->assign('saveOnclick', "onclick='if(check_form(\"opportunitiesQuickCreate\")) return SUGAR.subpanelUtils.inlineSave(this.form.id, \"opportunities\"); else return false;'"); $this->ss->assign('cancelOnclick', "onclick='return SUGAR.subpanelUtils.cancelCreate(\"subpanel_opportunities\")';"); } $this->ss->assign('viaAJAX', $this->viaAJAX); $this->javascript = new javascript(); $this->javascript->setFormName('opportunitiesQuickCreate'); $focus = BeanFactory::getBean('Opportunities'); $this->javascript->setSugarBean($focus); $this->javascript->addAllFields(''); $this->ss->assign('additionalScripts', $this->javascript->getScript(false)); }
public function run() { if (!($this->from_flavor == 'ce' && $this->toFlavor('pro'))) { return; } $result = $this->db->query("SELECT id, contents, assigned_user_id FROM user_preferences WHERE deleted = 0 AND category = 'Home'"); if (empty($result)) { return $this->fail("Unable to upgrade dashlets"); } while ($row = $this->db->fetchByAssoc($result)) { $content = unserialize(base64_decode($row['contents'])); $assigned_user_id = $row['assigned_user_id']; $record_id = $row['id']; $current_user = BeanFactory::getBean('Users', $row['assigned_user_id']); if (!empty($content['dashlets']) && !empty($content['pages'])) { $originalDashlets = $content['dashlets']; foreach ($originalDashlets as $key => $ds) { if (!empty($ds['options']['url']) && stristr($ds['options']['url'], 'http://www.sugarcrm.com/crm/product/gopro')) { unset($originalDashlets[$key]); } } $current_user->setPreference('dashlets', $originalDashlets, 0, 'Home'); } } }
/** * Method to save record in database * @param $projectData * @return bool */ public function saveProjectData($projectData) { $source_definition = json_decode($projectData['rst_source_definition']); if (isset($projectData[$this->suffix . 'name']) && !empty($projectData[$this->suffix . 'name'])) { $name = $this->getNameWithSuffix($projectData[$this->suffix . 'name']); } else { $name = $this->getNameWithSuffix($projectData[$this->name]); } $projectData['rst_uid'] = PMSEEngineUtils::generateUniqueID(); $source_definition->name = $name; $source_definition->id = $projectData['rst_uid']; $projectData['rst_source_definition'] = json_encode($source_definition); unset($projectData[$this->id]); unset($projectData['rst_uid']); $new_uid = parent::saveProjectData($projectData); if ($new_uid) { // Update new id into 'rst_source_definition' field $br_bean = BeanFactory::getBean('pmse_Business_Rules', $new_uid); $def = json_decode($br_bean->rst_source_definition); $def->id = $new_uid; $br_bean->rst_source_definition = json_encode($def); $br_bean->save(); return $new_uid; } else { return false; } }
public function run() { if (!$this->toFlavor('ent') && !$this->toFlavor('ult') || !version_compare($this->from_version, '7.0', '<')) { return; } $settings = Opportunity::getSettings(); if ($settings['opps_view_by'] !== 'RevenueLineItems') { $this->log('Not using Revenue Line Items; Skipping Upgrade Script'); return; } // get the get_widget helper and the StandardField Helper require_once 'modules/DynamicFields/FieldCases.php'; require_once 'modules/ModuleBuilder/parsers/StandardField.php'; // we are working with opportunities $module = 'Opportunities'; $bean = BeanFactory::getBean('Opportunities'); // the field set we need $fields = array('best_case', 'amount', 'worst_case', 'date_closed'); // loop over each field foreach ($fields as $field) { // get the field defs $field_defs = $bean->getFieldDefinition($field); // load the field type up $f = get_widget($field_defs['type']); // populate the row from the vardefs that were loaded $f->populateFromRow($field_defs); // lets make sure that the calculated is true $f->calculated = true; // now lets save, since these are OOB field, we use StandardField $df = new StandardField($module); $df->setup($bean); $f->module = $bean; $f->save($df); } }
private function createRelationship($lhs_module, $rhs_module = null, $relationship_type = 'one-to-many') { $rhs_module = $rhs_module == null ? $lhs_module : $rhs_module; // Adding relation between products and users $this->relationships = new DeployedRelationships($lhs_module); $definition = array('lhs_module' => $lhs_module, 'relationship_type' => $relationship_type, 'rhs_module' => $rhs_module, 'lhs_label' => $lhs_module, 'rhs_label' => $rhs_module, 'rhs_subpanel' => 'default'); $this->relationship = RelationshipFactory::newRelationship($definition); $this->relationships->add($this->relationship); $this->relationships->save(); $this->relationships->build(); LanguageManager::clearLanguageCache($lhs_module); // Updating $dictionary by created relation global $dictionary; $moduleInstaller = new ModuleInstaller(); $moduleInstaller->silent = true; $moduleInstaller->rebuild_tabledictionary(); require 'modules/TableDictionary.php'; // Updating vardefs VardefManager::$linkFields = array(); VardefManager::clearVardef(); VardefManager::refreshVardefs($lhs_module, BeanFactory::getObjectName($lhs_module)); if ($lhs_module != $rhs_module) { VardefManager::refreshVardefs($rhs_module, BeanFactory::getObjectName($rhs_module)); } SugarRelationshipFactory::rebuildCache(); }
public function action_getInviteesPersonName() { $personModules = array('Users', 'Contacts', 'Leads'); $ret = array(); $invitees = $_REQUEST['invitees']; foreach ($invitees as $invitee) { if (!isset($invitee['personName']) || !$invitee['personName']) { $person = BeanFactory::getBean($invitee['personModule'], $invitee['personModuleId']); $invitee['personName'] = $person->name; } if (isset($invitee['personModule']) && $invitee['personModule'] && in_array($invitee['personModule'], $personModules) && isset($invitee['personModuleId']) && $invitee['personModuleId'] && isset($invitee['personName']) && $invitee['personName']) { $ret[] = $invitee; } } // $personModules = array('Users', 'Contacts', 'Leads'); // $retInvitees = array(); // foreach($invitees as $invitee) { // if(isset($invitee['personModule']) && $invitee['personModule'] && in_array($invitee['personModule'], $personModules) && isset($invitee['personId']) && $invitee['personId'] && isset($invitee['personName']) && $invitee['personName']) { // $retInvitees[] = $invitee; // } // } $inviteeJson = json_encode($ret); echo $inviteeJson; die; }
/** * This method implements the run function of RunnableSchedulerJob and handles processing a SchedulersJob * * @param Mixed $data parameter passed in from the job_queue.data column when a SchedulerJob is run * @return bool true on success, false on error */ public function run($data) { global $app_strings, $language; $app_strings = return_application_language($language); $admin = BeanFactory::getBean('Administration'); $config = $admin->getConfigForModule('Forecasts', 'base'); $timeperiodInterval = $config['timeperiod_interval']; $timeperiodLeafInterval = $config['timeperiod_leaf_interval']; $parentTimePeriod = TimePeriod::getLatest($timeperiodInterval); $latestTimePeriod = TimePeriod::getLatest($timeperiodLeafInterval); $currentTimePeriod = TimePeriod::getCurrentTimePeriod($timeperiodLeafInterval); if (empty($latestTimePeriod)) { $GLOBALS['log']->error(string_format($app_strings['ERR_TIMEPERIOD_TYPE_DOES_NOT_EXIST'], array($timeperiodLeafInterval)) . '[latest]'); return false; } else { if (empty($currentTimePeriod)) { $GLOBALS['log']->error(string_format($app_strings['ERR_TIMEPERIOD_TYPE_DOES_NOT_EXIST'], array($timeperiodLeafInterval)) . ' [current]'); return false; } else { if (empty($parentTimePeriod)) { $GLOBALS['log']->error(string_format($app_strings['ERR_TIMEPERIOD_TYPE_DOES_NOT_EXIST'], array($timeperiodLeafInterval)) . ' [parent]'); return false; } } } $timedate = TimeDate::getInstance(); //We run the rebuild command if the latest TimePeriod is less than the specified configuration interval //from the current TimePeriod $correctStartDate = $timedate->fromDbDate($currentTimePeriod->start_date); $latestStartDate = $timedate->fromDbDate($latestTimePeriod->start_date); $shownForward = $config['timeperiod_shown_forward']; //Move the current start date forward by the leaf period amounts for ($x = 0; $x < $shownForward; $x++) { $correctStartDate->modify($parentTimePeriod->next_date_modifier); } $leafCycle = $latestTimePeriod->leaf_cycle; //If the current start data that was modified according to the shown forward period is past the latest //leaf period we need to build more timeperiods while ($correctStartDate > $latestStartDate) { //We need to keep creating leaf periods until we are in sync. //If the leaf period we need to create is the start of the leaf cycle //then we should also create the parent TimePeriod record. $startDate = $latestStartDate->modify($latestTimePeriod->next_date_modifier); $leafCycle = $leafCycle == $parentTimePeriod->leaf_periods ? 1 : $leafCycle + 1; if ($leafCycle == 1) { $parentTimePeriod = TimePeriod::getByType($timeperiodInterval); $parentTimePeriod->setStartDate($startDate->asDbDate()); $parentTimePeriod->name = $parentTimePeriod->getTimePeriodName($leafCycle); $parentTimePeriod->save(); } $leafTimePeriod = TimePeriod::getByType($timeperiodLeafInterval); $leafTimePeriod->setStartDate($startDate->asDbDate()); $leafTimePeriod->name = $leafTimePeriod->getTimePeriodName($leafCycle, $parentTimePeriod); $leafTimePeriod->leaf_cycle = $leafCycle; $leafTimePeriod->parent_id = $parentTimePeriod->id; $leafTimePeriod->save(); } $this->job->succeedJob(); return true; }
public function export(ServiceBase $api, $args = array()) { ob_start(); // Load up a seed bean $seed = BeanFactory::getBean('ForecastWorksheets'); if (!$seed->ACLAccess('list')) { throw new SugarApiExceptionNotAuthorized('No access to view records for module: ' . $seed->object_name); } $args['timeperiod_id'] = isset($args['timeperiod_id']) ? $args['timeperiod_id'] : TimePeriod::getCurrentId(); $args['user_id'] = isset($args['user_id']) ? $args['user_id'] : $api->user->id; if (!isset($args['filters'])) { $args['filters'] = array(); } elseif (!is_array($args['filters'])) { $args['filters'] = array($args['filters']); } // don't allow encoding to html for data used in export $args['encode_to_html'] = false; // base file and class name $file = 'include/SugarForecasting/Export/Individual.php'; $klass = 'SugarForecasting_Export_Individual'; // check for a custom file exists SugarAutoLoader::requireWithCustom($file); $klass = SugarAutoLoader::customClass($klass); // create the class /* @var $obj SugarForecasting_Export_AbstractExport */ $obj = new $klass($args); $content = $obj->process($api); ob_end_clean(); return $this->doExport($api, $obj->getFilename(), $content); }
public function display() { global $current_user, $current_language, $sugar_flavor, $sugar_config; if (!$current_user->is_admin) { sugar_die(translate("LBL_MUST_BE_ADMIN")); } //RemoveTabSave: let dashboard pass since we are still altering it if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'RemoveTabSave') { if (isset($_REQUEST['TabToRemove'])) { $dashboardManager = BeanFactory::newBean("dash_DashboardManager"); $dashboardManager->temp_unencoded_pages = $dashboardManager->deletePageByKey($_REQUEST['TabToRemove'], $current_user->getPreference('pages', 'Home')); $dashboardManager->temp_unencoded_dashlets = $current_user->getPreference('dashlets', 'Home'); $dashboardManager->setDashboardForUser($current_user); $current_user->getPreference('pages', 'Home'); $current_user->getPreference('dashlets', 'Home'); } } elseif (isset($this->bean->fetched_row['id'])) { //set this dashboard for current user $this->bean->setDashboardForUser($current_user); } else { //set dashboard back to clean template $current_user->resetPreferences('Home'); } parent::display(); //get language for dashboard $mod_strings = return_module_language($current_language, 'Home'); //render dashboard $lock_homepage = $sugar_config['lock_homepage']; $sugar_config['lock_homepage'] = false; require_once "modules/Home/index.php"; $sugar_config['lock_homepage'] = $lock_homepage; }
public function getListViewSmarty($parentFieldArray, $vardef, $displayParams, $col) { global $locale, $current_user; $tabindex = 1; $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex, false); $currencyUSD = '-99'; $amount = $parentFieldArray[strtoupper($vardef['name'])]; $currencyId = isset($parentFieldArray['CURRENCY_ID']) ? $parentFieldArray['CURRENCY_ID'] : ""; $currencySymbol = isset($parentFieldArray['CURRENCY_SYMBOL']) ? $parentFieldArray['CURRENCY_SYMBOL'] : ""; if (empty($currencyId)) { $currencyId = $locale->getPrecedentPreference('currency'); } if (empty($currencySymbol)) { $currencySymbol = $locale->getPrecedentPreference('default_currency_symbol'); } if (stripos($vardef['name'], '_USD')) { $userCurrencyId = $current_user->getPreference('currency'); if (!empty($userCurrencyId) && $currencyUSD !== $userCurrencyId) { $userCurrency = BeanFactory::getBean('Currencies', $userCurrencyId); $currencyId = $userCurrency->id; $currencySymbol = $userCurrency->symbol; $amount = $userCurrency->convertFromDollar($amount, 6); } else { $currencyId = $currencyUSD; $currencySymbol = $locale->getPrecedentPreference('default_currency_symbol'); } } $this->ss->assign('currency_id', $currencyId); $this->ss->assign('currency_symbol', $currencySymbol); $this->ss->assign('amount', $amount); return $this->fetch($this->findTemplate('ListView')); }
public function configSave(ServiceBase $api, $args) { $module = 'dm_Duplicates'; unset($args['__sugar_url']); //acl check, only allow if they are module admin if (!$api->user->isAdmin() && !$api->user->isDeveloperForModule($module)) { // No create access so we construct an error message and throw the exception $failed_module_strings = return_module_language($GLOBALS['current_language'], $module); $moduleName = $failed_module_strings['LBL_MODULE_NAME']; $args = null; if (!empty($moduleName)) { $args = array('moduleName' => $moduleName); } throw new SugarApiExceptionNotAuthorized($GLOBALS['app_strings']['EXCEPTION_CHANGE_MODULE_CONFIG_NOT_AUTHORIZED'], $args); } $admin = BeanFactory::getBean('Administration'); $platform = 'base'; foreach ($args as $name => $value) { if (is_array($value)) { $admin->saveSetting($module, $name, json_encode($value), $platform); } else { $admin->saveSetting($module, $name, $value, $platform); } } if ($this->skipMetadataRefresh === false) { MetaDataManager::refreshModulesCache(array($module)); } return $admin->getConfigForModule($module, $platform, true); }
public function customCaseAssignment($bean, $event, $args) { // if the email is related to a case, it is inbound and unread if (!empty($bean->parent_id) && !empty($bean->fetched_row) && $bean->parent_type == 'Cases' && $bean->type == 'inbound' && $bean->status == 'unread' && $bean->fetched_row['parent_type'] != 'Cases' && $bean->fetched_row['parent_id'] != $bean->parent_id) { $case = BeanFactory::getBean('Cases', $bean->parent_id); if (!empty($case->id)) { // find if our default inbound empty team exists... $inbound_team = BeanFactory::getBean('Teams'); $inbound_team->retrieve_by_string_fields(array('name' => $this->inbound_cases_team)); $assignment_team = BeanFactory::getBean('Teams'); $assignment_team->retrieve_by_string_fields(array('name' => $this->assignment_cases_team)); if (!empty($inbound_team->id) && !empty($case->team_id) && $inbound_team->id == $case->team_id && !empty($assignment_team->id)) { $GLOBALS['log']->debug('inboundEmailsLogic->customCaseAssignment - Routing appropriately case ' . $case->id); // START - CUSTOM ASSIGNMENT LOGIC GOES HERE! // assign both the email and the case to the correct team (who can see the case/email?) $bean->team_id = $bean->team_set_id = $assignment_team->id; $case->team_id = $case->team_set_id = $assignment_team->id; // now complete the custom case routing... if ($case->assigned_user_id == '') { // as an example let's assign the email and the case to a specific user (who needs to handle the case?) // let's route to the Sugar default Admin $case->assigned_user_id = '1'; $bean->assigned_user_id = '1'; } // END - CUSTOM ASSIGNMENT LOGIC GOES HERE! $GLOBALS['log']->debug('inboundEmailsLogic->customCaseAssignment - Case ' . $case->id . ' routed'); $case->save(); } } } }
/** * Add default menu for module * @param string $module */ protected function addMenu($moduleName) { $menu = array(); // Create default menu for the module $menu[] = array('route' => "#{$moduleName}/create", 'label' => 'LNK_NEW_RECORD', 'acl_action' => 'create', 'acl_module' => $moduleName, 'icon' => 'fa-plus'); // Handle link to vCard $bean = BeanFactory::getBean($moduleName); if (is_subclass_of($bean, 'Person')) { $vCardRoute = in_array($moduleName, $GLOBALS['bwcModules']) ? '#bwc/index.php?' . http_build_query(array('module' => $moduleName, 'action' => 'ImportVCard')) : "#{$moduleName}/vcard-import"; $menu[] = array('route' => $vCardRoute, 'label' => 'LNK_IMPORT_VCARD', 'acl_action' => 'create', 'acl_module' => $moduleName, 'icon' => 'fa-plus'); } $menu[] = array('route' => "#{$moduleName}", 'label' => 'LNK_LIST', 'acl_action' => 'list', 'acl_module' => $moduleName, 'icon' => 'fa-bars'); if ($bean instanceof SugarBean && $bean->importable) { $menu[] = array('route' => '#bwc/index.php?' . http_build_query(array('module' => 'Import', 'action' => 'Step1', 'import_module' => $moduleName)), 'label' => 'LNK_IMPORT_' . strtoupper($moduleName), 'acl_action' => 'import', 'acl_module' => $moduleName, 'icon' => 'fa-arrow-circle-o-up'); } $content = <<<END <?php /* Created by SugarUpgrader for module {$moduleName} */ \$viewdefs['{$moduleName}']['base']['menu']['header'] = END; $content .= var_export($menu, true) . ";\n"; $this->ensureDir("modules/{$moduleName}/clients/base/menus/header"); $this->putFile("modules/{$moduleName}/clients/base/menus/header/header.php", $content); $this->log("Added default menu file for {$moduleName}"); }
function action_mapping() { global $mod_strings, $current_user; $results = array('message' => ''); // handle publishing and deleting import maps if (isset($_REQUEST['delete_map_id'])) { $import_map = BeanFactory::deleteBean('Import_1', $_REQUEST['delete_map_id']); } if (isset($_REQUEST['publish'])) { $import_map = BeanFactory::getBean('Import_1', $_REQUEST['import_map_id'], array("encode" => false)); if ($_REQUEST['publish'] == 'yes') { $result = $import_map->mark_published($current_user->id, true); if (!$result) { $results['message'] = $mod_strings['LBL_ERROR_UNABLE_TO_PUBLISH']; } } elseif ($_REQUEST['publish'] == 'no') { // if you don't own this importmap, you do now, unless you have a map by the same name $result = $import_map->mark_published($current_user->id, false); if (!$result) { $results['message'] = $mod_strings['LBL_ERROR_UNABLE_TO_UNPUBLISH']; } } } echo json_encode($results); sugar_cleanup(TRUE); }
protected function fixRollupFormulas() { $oldFormula = 'rollupCurrencySum($revenuelineitems, "{{field}}")'; $newFormula = 'rollupConditionalSum($revenuelineitems, "{{field}}", "sales_stage", forecastSalesStages(true, false))'; // the field set we need $fields = array('best_case' => 'best_case', 'amount' => 'likely_case', 'worst_case' => 'worst_case'); // get the get_widget helper and the StandardField Helper SugarAutoLoader::load('modules/DynamicFields/FieldCases.php'); SugarAutoLoader::load('modules/ModuleBuilder/parsers/StandardField.php'); // we are working with opportunities $bean = BeanFactory::getBean('Opportunities'); // loop over each field foreach ($fields as $field => $rollup_field) { // get the field defs $field_defs = $bean->getFieldDefinition($field); // load the field type up $f = get_widget($field_defs['type']); // populate the row from the vardefs that were loaded $f->populateFromRow($field_defs); if ($f->formula == str_replace('{{field}}', $rollup_field, $oldFormula)) { $f->formula = str_replace('{{field}}', $rollup_field, $newFormula); // now lets save, since these are OOB field, we use StandardField $df = new StandardField($bean->module_name); $df->setup($bean); $f->module = $bean; $f->save($df); } } // lets fix up the data now to excluded closed lost $this->fixRollupAmountsToExcludeClosedLostValues(); }
/** * Validate the provided session information is correct and current. Load the session. * * @param String $session_id -- The session ID that was returned by a call to login. * @return true -- If the session is valid and loaded. * @return false -- if the session is not valid. */ function validate_authenticated($session_id) { $GLOBALS['log']->info('Begin: SoapHelperWebServices->validate_authenticated'); if (!empty($session_id)) { // only initialize session once in case this method is called multiple times if (!session_id()) { session_id($session_id); session_start(); } if (!empty($_SESSION['is_valid_session']) && $this->is_valid_ip_address('ip_address') && $_SESSION['type'] == 'user') { global $current_user; require_once 'modules/Users/User.php'; $current_user = BeanFactory::getBean('Users', $_SESSION['user_id']); $this->login_success(); $GLOBALS['log']->info('Begin: SoapHelperWebServices->validate_authenticated - passed'); $GLOBALS['log']->info('End: SoapHelperWebServices->validate_authenticated'); return true; } $GLOBALS['log']->debug("calling destroy"); session_destroy(); } LogicHook::initialize(); $GLOBALS['logic_hook']->call_custom_logic('Users', 'login_failed'); $GLOBALS['log']->info('End: SoapHelperWebServices->validate_authenticated - validation failed'); return false; }
public function projectImport($api, $args) { $this->checkACL($api, $args); $this->requireArgs($args, array('module')); $bean = BeanFactory::getBean($args['module']); if (!$bean->ACLAccess('save') || !$bean->ACLAccess('import')) { throw new SugarApiExceptionNotAuthorized('EXCEPTION_NOT_AUTHORIZED'); } if (isset($_FILES) && count($_FILES) === 1) { reset($_FILES); $first_key = key($_FILES); if (isset($_FILES[$first_key]['tmp_name']) && $this->isUploadedFile($_FILES[$first_key]['tmp_name']) && isset($_FILES[$first_key]['size']) && isset($_FILES[$first_key]['size']) > 0) { try { $importerObject = new PMSEProjectImporter(); $name = $_FILES[$first_key]['name']; $extension = pathinfo($name, PATHINFO_EXTENSION); if ($extension == $importerObject->getExtension()) { $data = $importerObject->importProject($_FILES[$first_key]['tmp_name']); $results = array('project_import' => $data); } else { throw new SugarApiExceptionRequestMethodFailure('ERROR_UPLOAD_FAILED'); } } catch (SugarApiExceptionNotAuthorized $e) { throw new SugarApiExceptionNotAuthorized('ERROR_UPLOAD_ACCESS_PD'); } catch (Exception $e) { throw new SugarApiExceptionRequestMethodFailure('ERROR_UPLOAD_FAILED'); } return $results; } } else { throw new SugarApiExceptionMissingParameter('ERROR_UPLOAD_FAILED'); } }
/** * Create the bug record and optionally perform post-save actions for Portal */ public function createRecord($api, $args) { //create the bug using the ModuleApi $contact = null; if (isset($_SESSION['type']) && $_SESSION['type'] == 'support_portal') { $contact = BeanFactory::getBean('Contacts', $_SESSION['contact_id'], array('strict_retrieve' => true)); if (!empty($contact)) { $args['assigned_user_id'] = $contact->assigned_user_id; $args['team_id'] = $contact->fetched_row['team_id']; $args['team_set_id'] = $contact->fetched_row['team_set_id']; } } $data = parent::createRecord($api, $args); $bugId = null; if (isset($data['id']) && !empty($data['id'])) { $bugId = $data['id']; } else { //bug not created, can't do post-processes - bail out return $data; } if (!empty($bugId) && !empty($contact)) { $bug = BeanFactory::getBean('Bugs', $bugId); $bug->load_relationship('contacts'); $bug->contacts->add($contact->id); $bug->load_relationship('accounts'); $bug->accounts->add($contact->account_id); } return $data; }