Ejemplo n.º 1
0
 public function getAgenda($api, $args)
 {
     // Fetch the next 14 days worth of meetings (limited to 20)
     $end_time = new SugarDateTime("+14 days");
     $start_time = new SugarDateTime("-1 hour");
     $meeting = BeanFactory::newBean('Meetings');
     $meetingList = $meeting->get_list('date_start', "date_start > " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($start_time->asDb()), 'datetime') . " AND date_start < " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($end_time->asDb()), 'datetime'));
     // Setup the breaks for the various time periods
     $datetime = new SugarDateTime();
     $today_stamp = $datetime->get_day_end()->getTimestamp();
     $tomorrow_stamp = $datetime->setDate($datetime->year, $datetime->month, $datetime->day + 1)->get_day_end()->getTimestamp();
     $timeDate = TimeDate::getInstance();
     $returnedMeetings = array('today' => array(), 'tomorrow' => array(), 'upcoming' => array());
     foreach ($meetingList['list'] as $meetingBean) {
         $meetingStamp = $timeDate->fromUser($meetingBean->date_start)->getTimestamp();
         $meetingData = $this->formatBean($api, $args, $meetingBean);
         if ($meetingStamp < $today_stamp) {
             $returnedMeetings['today'][] = $meetingData;
         } else {
             if ($meetingStamp < $tomorrow_stamp) {
                 $returnedMeetings['tomorrow'][] = $meetingData;
             } else {
                 $returnedMeetings['upcoming'][] = $meetingData;
             }
         }
     }
     return $returnedMeetings;
 }
Ejemplo n.º 2
0
 protected function updateBean(SugarBean $bean, ServiceBase $api, $args)
 {
     $id = parent::updateBean($bean, $api, $args);
     //retrieve a Bean created
     if (isset($args['record']) && !empty($args['record'])) {
         $projectBean = BeanFactory::retrieveBean($args['module'], $args['record']);
     } else {
         $projectBean = $bean;
     }
     //Create a Diagram row
     $diagramBean = BeanFactory::getBean('pmse_BpmnDiagram')->retrieve_by_string_fields(array('prj_id' => $id));
     if (empty($diagramBean)) {
         $diagramBean = BeanFactory::newBean('pmse_BpmnDiagram');
         $diagramBean->dia_uid = PMSEEngineUtils::generateUniqueID();
     }
     $diagramBean->name = $projectBean->name;
     $diagramBean->description = $projectBean->description;
     $diagramBean->assigned_user_id = $projectBean->assigned_user_id;
     $diagramBean->prj_id = $id;
     $dia_id = $diagramBean->save();
     //Create a Process row
     $processBean = BeanFactory::getBean('pmse_BpmnProcess')->retrieve_by_string_fields(array('prj_id' => $id));
     if (empty($processBean)) {
         $processBean = BeanFactory::newBean('pmse_BpmnProcess');
         $processBean->pro_uid = PMSEEngineUtils::generateUniqueID();
     }
     $processBean->name = $projectBean->name;
     $processBean->description = $projectBean->description;
     $processBean->assigned_user_id = $projectBean->assigned_user_id;
     $processBean->prj_id = $id;
     $processBean->dia_id = $dia_id;
     $pro_id = $processBean->save();
     //Create a ProcessDefinition row
     $processDefinitionBean = BeanFactory::getBean('pmse_BpmProcessDefinition')->retrieve_by_string_fields(array('prj_id' => $id));
     if (empty($processDefinitionBean)) {
         $processDefinitionBean = BeanFactory::newBean('pmse_BpmProcessDefinition');
         $processDefinitionBean->id = $pro_id;
         $processDefinitionBean->new_with_id = true;
     }
     $processDefinitionBean->prj_id = $id;
     $processDefinitionBean->pro_module = $projectBean->prj_module;
     $processDefinitionBean->pro_status = $projectBean->prj_status;
     $processDefinitionBean->assigned_user_id = $projectBean->assigned_user_id;
     $processDefinitionBean->save();
     $relDepStatus = $projectBean->prj_status == 'ACTIVE' ? 'INACTIVE' : 'ACTIVE';
     while ($relatedDepBean = BeanFactory::getBean('pmse_BpmRelatedDependency')->retrieve_by_string_fields(array('prj_id' => $id, 'pro_status' => $relDepStatus))) {
         $relatedDepBean->pro_status = $projectBean->prj_status;
         $relatedDepBean->save();
     }
     $keysArray = array('prj_id' => $id, 'pro_id' => $pro_id);
     $dynaF = BeanFactory::getBean('pmse_BpmDynaForm')->retrieve_by_string_fields(array('prj_id' => $id, 'pro_id' => $pro_id, 'name' => 'Default'));
     if (empty($dynaF)) {
         $editDyna = false;
     } else {
         $editDyna = true;
     }
     $dynaForm = new PMSEDynaForm();
     $dynaForm->generateDefaultDynaform($processDefinitionBean->pro_module, $keysArray, $editDyna);
     return $id;
 }
Ejemplo n.º 3
0
 public static function getRelationship($modulo)
 {
     $bean = BeanFactory::newBean($modulo);
     require_once "modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php";
     $res = array();
     $x = new DeployedRelationships($modulo);
     $res = array();
     //print_r($bean->field_name_map);
     foreach ($bean->field_name_map as $field => $data) {
         if ($data['type'] === 'link') {
             if ($def = $x->get($data['relationship'])) {
                 $def = $def->getDefinition();
                 if ($def['relationship_type'] == 'many-to-many') {
                     continue;
                 } elseif ($def['lhs_module'] == $modulo && $def['relationship_type'] == 'one-to-many') {
                     continue;
                 } else {
                     $res[$data['name']] = "{$data['name']} : {$def['lhs_module']} {$def['relationship_type']} {$def['rhs_module']}";
                 }
                 //print_r($def);
             }
         }
     }
     return $res;
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
0
 /**
  * Saves the Dashboard Backup
  *
  * @param boolean $check_notify Optional, default false, if set to true assignee of the record is notified via email.
  * @return parent function
  */
 function save($check_notify = FALSE)
 {
     //handle user default backup - for admins to retrieve their favorite dashboard easily
     if ($this->user_default == 1) {
         $backup_list = BeanFactory::newBean("dash_DashboardBackups");
         $results = $backup_list->get_list("", "assigned_user_id='{$this->assigned_user_id}'");
         foreach ($results['list'] as $id => $backupObj) {
             if (!isset($this->fetched_row['id']) || $this->id != $id) {
                 $backupObj->user_default = 0;
                 $backupObj->ignore = true;
                 $backupObj->save();
             }
         }
     }
     //if being manually created
     if (empty($this->name) && !empty($this->assigned_user_id) && isset($_REQUEST['module']) && $this->ignore == false) {
         $userObj = BeanFactory::getBean("Users", $this->assigned_user_id);
         $this->unencoded_pages = $userObj->getPreference('pages', 'Home');
         $this->unencoded_dashlets = $userObj->getPreference('dashlets', 'Home');
         $this->name = "Manual Backup";
     }
     //encode for save
     $this->encoded_pages = base64_encode(serialize($this->unencoded_pages));
     $this->encoded_dashlets = base64_encode(serialize($this->unencoded_dashlets));
     return parent::save($check_notify);
 }
Ejemplo n.º 6
0
 public function expandField()
 {
     if (!isset($this->def['source']) || $this->def['source'] == 'db') {
         return;
     }
     // Exists only checks
     if (!empty($this->def['rname_exists'])) {
         $this->markNonDb();
         $this->rNameExists = true;
         return;
     }
     if (!empty($this->def['rname']) && !empty($this->def['link'])) {
         $this->table = $this->query->getJoinAlias($this->def['link']);
         $this->field = $this->def['rname'];
     } elseif (!empty($this->def['rname']) && !empty($this->def['table'])) {
         $this->table = $this->query->getJoinAlias($this->def['table'], false);
         $this->field = $this->def['rname'];
     } elseif (!empty($this->def['rname_link']) && !empty($this->def['link'])) {
         $this->field = $this->def['rname_link'];
     }
     if (!empty($this->def['module'])) {
         $this->moduleName = $this->def['module'];
         $bean = BeanFactory::newBean($this->moduleName);
         if (isset($bean->field_defs[$this->field])) {
             $this->def = $bean->field_defs[$this->field];
         }
     }
     $this->checkCustomField();
 }
Ejemplo n.º 7
0
 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);
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Gets a single temporary file for rendering and removes it from filesystem.
  *
  * @param ServiceBase $api The service base
  * @param array $args Arguments array built by the service base
  */
 public function getTempImage($api, $args)
 {
     // Get the field
     if (empty($args['field'])) {
         // @TODO Localize this exception message
         throw new SugarApiExceptionMissingParameter('Field name is missing');
     }
     $field = $args['field'];
     // Get the bean
     $bean = BeanFactory::newBean($args['module']);
     // Handle ACL
     $this->verifyFieldAccess($bean, $field);
     $filepath = UploadStream::path("upload://tmp/") . $args['temp_id'];
     if (is_file($filepath)) {
         $filedata = getimagesize($filepath);
         $info = array('content-type' => $filedata['mime'], 'path' => $filepath);
         require_once "include/download_file.php";
         $dl = new DownloadFileApi($api);
         $dl->outputFile(false, $info);
         if (!empty($args['keep'])) {
             return;
         }
         register_shutdown_function(function () use($filepath) {
             if (is_file($filepath)) {
                 unlink($filepath);
             }
         });
     } else {
         throw new SugarApiExceptionInvalidParameter('File not found');
     }
 }
Ejemplo n.º 9
0
 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;
 }
Ejemplo n.º 10
0
 /**
  *	Esta funcion devuelve los tags disponibles para el PDF
  */
 public static function getTags($plantilla_id)
 {
     require_once "modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php";
     $res = array();
     $plantilla_bean = BeanFactory::getBean('opalo_plantillas', $plantilla_id);
     $modulo = $plantilla_bean->pariente;
     $relaciones = unencodeMultienum($plantilla_bean->relaciones);
     ///CARGA LOS CAMPOS DEL MODULO
     $bean = BeanFactory::newBean($modulo);
     foreach ($bean->field_name_map as $campo => $data) {
         $res[$campo] = $data['type'];
     }
     $x = new DeployedRelationships($modulo);
     ///CARGA LOS CAMPOS DE LA RELACION <relationship_name>::<field_name>
     foreach ($relaciones as $relation) {
         $rel = $bean->field_name_map[$relation]['relationship'];
         $def = $x->get($rel)->getDefinition();
         $otro_modulo = $def['rhs_module'];
         if ($modulo == $def['rhs_module']) {
             $otro_modulo = $def['lhs_module'];
         }
         $bean_seg = BeanFactory::newBean($otro_modulo);
         foreach ($bean_seg->field_name_map as $campo => $data) {
             $res[$relation . "::" . $campo] = $data['type'];
         }
         $bean->load_relationship($relation);
     }
     return $res;
 }
Ejemplo n.º 11
0
 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');
 }
Ejemplo n.º 12
0
 /**
  * To perform massupdate, either update or delete, based on the args parameter
  * @param $api ServiceBase The API class of the request, used in cases where the API changes how the fields are pulled from the args array.
  * @param $args array The arguments array passed in from the API
  * @return String
  */
 public function massUpdate($api, $args)
 {
     $this->requireArgs($args, array('massupdate_params', 'module'));
     $mu_params = $args['massupdate_params'];
     $mu_params['module'] = $args['module'];
     // should pass success status once uid is empty.
     if (empty($mu_params['uid']) && empty($mu_params['entire'])) {
         return array('status' => 'done', 'failed' => 0);
     }
     if (isset($mu_params['entire']) && empty($mu_params['entire'])) {
         unset($mu_params['entire']);
     }
     if (isset($mu_params['team_name'])) {
         if (isset($mu_params['team_name_type']) && $mu_params['team_name_type'] === '1') {
             $mu_params['team_name_type'] = "add";
         } else {
             $mu_params['team_name_type'] = "replace";
         }
     }
     // check ACL
     $bean = BeanFactory::newBean($mu_params['module']);
     if (!$bean instanceof SugarBean) {
         throw new SugarApiExceptionInvalidParameter("Invalid bean, is module valid?");
     }
     $action = $this->delete ? 'delete' : 'save';
     if (!$bean->ACLAccess($action)) {
         throw new SugarApiExceptionNotAuthorized('No access to mass update records for module: ' . $mu_params['module']);
     }
     $mu_params['action'] = $action;
     $massUpdateJob = new SugarJobMassUpdate();
     $result = $massUpdateJob->runUpdate($mu_params);
     $result['status'] = 'done';
     return $result;
 }
Ejemplo n.º 13
0
 /**
  * Creates lead records
  * @param $apiServiceBase The API class of the request, used in cases where the API changes how the fields are pulled from the args array.
  * @param $args array The arguments array passed in from the API
  * @return array properties on lead bean formatted for display
  */
 public function createLeadRecord($api, $args)
 {
     // Bug 54647 Lead registration can create empty leads
     if (!isset($args['last_name'])) {
         throw new SugarApiExceptionMissingParameter();
     }
     /**
      *
      * Bug56194: This API can be hit without logging into Sugar, but the creation of a Lead SugarBean
      * uses messages that require the use of the app strings.
      *
      **/
     global $app_list_strings;
     global $current_language;
     if (!isset($app_list_strings)) {
         $app_list_strings = return_app_list_strings_language($current_language);
     }
     $bean = BeanFactory::newBean('Leads');
     // we force team and teamset because there is no current user to get them from
     $fields = array('team_set_id' => '1', 'team_id' => '1', 'lead_source' => 'Support Portal User Registration');
     $admin = Administration::getSettings();
     if (isset($admin->settings['portal_defaultUser']) && !empty($admin->settings['portal_defaultUser'])) {
         $fields['assigned_user_id'] = json_decode(html_entity_decode($admin->settings['portal_defaultUser']));
     }
     $fieldList = array('first_name', 'last_name', 'phone_work', 'email', 'primary_address_country', 'primary_address_state', 'account_name', 'title', 'preferred_language');
     foreach ($fieldList as $fieldName) {
         if (isset($args[$fieldName])) {
             $fields[$fieldName] = $args[$fieldName];
         }
     }
     $id = $this->updateBean($bean, $api, $fields);
     return $id;
 }
Ejemplo n.º 14
0
 public function testGetRelatedListFunctionWithLink2Class()
 {
     $focusModule = 'Accounts';
     $linkedModules = array('Bugs', 'Contacts');
     $focus = BeanFactory::newBean($focusModule);
     $focus->name = "bug49505";
     $focus->save();
     $this->_createdBeans[] = $focus;
     foreach ($linkedModules as $v) {
         $linkedBean = BeanFactory::newBean($v);
         $linkedBean->name = "bug49505";
         $linkedBean->save();
         $this->_createdBeans[] = $linkedBean;
         $link = new Link2(strtolower($v), $focus);
         $link->add(array($linkedBean));
         // get relation from 'Link2' class
         $link2List = $focus->get_related_list($linkedBean, strtolower($v));
         // get relation for 'get_related_list' function from Link class
         $focus->field_defs[strtolower($v)]['link_class'] = 'Link';
         $focus->field_defs[strtolower($v)]['link_file'] = 'data/Link.php';
         $linkList = $focus->get_related_list($linkedBean, strtolower($v));
         unset($focus->field_defs[strtolower($v)]['link_class']);
         unset($focus->field_defs[strtolower($v)]['link_file']);
         $this->assertEquals($linkedBean->id, $linkList['list'][0]->id);
         $this->assertEquals($linkedBean->id, $link2List['list'][0]->id);
     }
 }
Ejemplo n.º 15
0
 protected function newBean($module)
 {
     $bean = BeanFactory::newBean($module);
     if (empty($bean)) {
         throw new Exception("No bean for module {$module}");
     }
     return $bean;
 }
Ejemplo n.º 16
0
 /**
  * Copy the value of the user_id field to the created_by field for all UserSignatures records.
  */
 public function run()
 {
     if (!version_compare($this->from_version, '7.2.1', '<')) {
         return;
     }
     $seed = BeanFactory::newBean('UserSignatures');
     $sql = "UPDATE " . $seed->getTableName() . " SET created_by=user_id, modified_user_id=" . $GLOBALS['db']->quoted($GLOBALS['current_user']->id) . ", date_modified=" . $GLOBALS['db']->quoted($GLOBALS['timedate']->nowDb()) . " WHERE " . $this->db->convert('created_by', 'ifnull') . "<>user_id";
     $GLOBALS['db']->query($sql);
 }
 /**
  * Forecast Manager Worksheet API handler to return data formatted for the chart
  *
  * @param ServiceBase $api
  * @param array $args
  * @return array|string
  */
 public function forecastManagerWorksheetsChartGet(ServiceBase $api, array $args)
 {
     if (isset($args['no_data']) && $args['no_data'] == 1) {
         $worksheetData = array('records' => array());
     } else {
         //get data via forecastWorksheetsGet, no need to bother with filter setup, get will do that
         $worksheetData = $this->ForecastManagerWorksheetsGet($api, $args);
         //get all users in direct hierarchy
         $usersList = $this->getDirectHierarchyUsers($api, $args);
         $assignedUser = BeanFactory::getBean("Users", $args['user_id']);
         // get the list of users we have
         $worksheet_users = array_map(function ($i) {
             return $i['user_id'];
         }, $worksheetData['records']);
         //compare users and worksheet data to fill in gaps
         foreach ($usersList['records'] as $user) {
             if (!in_array($user['id'], $worksheet_users)) {
                 $blankWorksheet = BeanFactory::newBean('ForecastManagerWorksheets');
                 $blankWorksheet->assigned_user_id = $args['user_id'];
                 $blankWorksheet->user_id = $user['id'];
                 $blankWorksheet->timeperiod_id = $args['timeperiod_id'];
                 $blankWorksheet->assigned_user_name = $assignedUser->user_name;
                 $blankWorksheet->quota = 0;
                 $blankWorksheet->likely_case = 0;
                 $blankWorksheet->likely_case_adjusted = 0;
                 $blankWorksheet->best_case = 0;
                 $blankWorksheet->best_case_adjusted = 0;
                 $blankWorksheet->worst_case = 0;
                 $blankWorksheet->worst_case_adjusted = 0;
                 $blankWorksheet->currency_id = '-99';
                 $blankWorksheet->base_rate = 1.0;
                 $blankWorksheet->id = '';
                 $blankWorksheet->name = $user['full_name'];
                 array_push($worksheetData['records'], $this->formatBean($api, $args, $blankWorksheet));
             }
         }
     }
     // default to the Individual Code
     $file = 'include/SugarForecasting/Chart/Manager.php';
     $klass = 'SugarForecasting_Chart_Manager';
     // check for a custom file exists
     SugarAutoLoader::requireWithCustom($file);
     $klass = SugarAutoLoader::customClass($klass);
     // create the class
     /* @var $obj SugarForecasting_Chart_AbstractChart */
     $args['data_array'] = $worksheetData['records'];
     $obj = new $klass($args);
     $chartData = $obj->process();
     // check to see if we need to return the target quota with the chartData
     if (isset($args['target_quota']) && $args['target_quota'] == 1) {
         /* @var $quota Quota */
         $quota = BeanFactory::getBean('Quotas');
         $targetQuota = $quota->getRollupQuota($args['timeperiod_id'], $args['user_id'], true);
         $chartData['target_quota'] = $targetQuota['amount'];
     }
     return $chartData;
 }
Ejemplo n.º 18
0
 private function getCase()
 {
     // Cache intentionally bypassed
     $case = BeanFactory::newBean("Cases");
     $case->retrieve($this->ie->parent_id);
     $this->assertTrue($case->load_relationship("accounts"));
     $this->assertTrue($case->load_relationship("contacts"));
     return $case;
 }
Ejemplo n.º 19
0
 function getOrCreate($day)
 {
     $bhList = $this->getBusinessHoursForDay($day);
     if ($bhList) {
         return $bhList[0];
     } else {
         return BeanFactory::newBean("AOBH_BusinessHours");
     }
 }
Ejemplo n.º 20
0
 /**
  * Load bean from context
  * @static
  * @param string $module
  * @param array $context
  * @return SugarBean
  */
 protected static function loadBean($module, $context = array())
 {
     if (isset($context['bean']) && $context['bean'] instanceof SugarBean && $context['bean']->module_dir == $module) {
         $bean = $context['bean'];
     } else {
         $bean = BeanFactory::newBean($module);
     }
     return $bean;
 }
 /**
  * This method check acl access in custom APIs
  * @param $api
  * @param $args
  * @throws SugarApiExceptionNotAuthorized
  */
 private function checkACL($api, $args)
 {
     $route = $api->getRequest()->getRoute();
     if (isset($route['acl'])) {
         $acl = $route['acl'];
         $seed = BeanFactory::newBean($args['module']);
         if (!$seed->ACLAccess($acl)) {
             throw new SugarApiExceptionNotAuthorized('No access to view/edit records for module: ' . $args['module']);
         }
     }
 }
Ejemplo n.º 22
0
 public function viewChangeLog($api, $args)
 {
     global $focus, $current_user;
     $this->requireArgs($args, array('module', 'record'));
     $focus = BeanFactory::getBean($args['module'], $args['record']);
     if (!$focus->ACLAccess('view')) {
         throw new SugarApiExceptionNotAuthorized('no access to the bean');
     }
     $auditBean = BeanFactory::newBean('Audit');
     return array('next_offset' => -1, 'records' => $auditBean->getAuditLog($focus));
 }
Ejemplo n.º 23
0
 public function action_create_record()
 {
     global $current_user;
     $favorite = BeanFactory::newBean('Favorites');
     $favorite->name = $_REQUEST['record_module'] . ' ' . $_REQUEST['record_id'] . ' ' . $current_user->id;
     $favorite->parent_type = $_REQUEST['record_module'];
     $favorite->parent_id = $_REQUEST['record_id'];
     $favorite->assigned_user_id = $current_user->id;
     $favorite->save();
     echo json_encode($favorite->id);
 }
Ejemplo n.º 24
0
 /**
  * Creates a record list from a saved report
  * @param $api ServiceBase The API class of the request, used in cases where the API changes how the fields are pulled from the args array.
  * @param $args array The arguments array passed in from the API containing the module and the records
  * @throws SugarApiExceptionNotAuthorized
  * @throws SugarApiException
  * @return array id, module, records
  */
 public function createRecordList($api, $args)
 {
     $this->requireArgs($args, array("record"));
     $savedReport = BeanFactory::newBean("Reports");
     if (!$savedReport->ACLAccess('access')) {
         throw new SugarApiExceptionNotAuthorized();
     }
     $recordIds = $this->getRecordIdsFromReport($args["record"]);
     $id = RecordListFactory::saveRecordList($recordIds, "Reports");
     $loadedRecordList = RecordListFactory::getRecordList($id);
     return $loadedRecordList;
 }
Ejemplo n.º 25
0
 /**
  * display the form
  */
 public function display()
 {
     global $db, $timedate, $current_language;
     parent::display();
     $index = BeanFactory::getBean("AOD_Index");
     $index = $index->getIndex();
     $beanList = $index->getIndexableModules();
     $moduleCounts = array();
     foreach ($beanList as $beanModule => $beanName) {
         $bean = BeanFactory::getBean($beanModule);
         if (!$bean || !method_exists($bean, "getTableName") || !$bean->getTableName()) {
             continue;
         }
         $query = "SELECT COUNT(DISTINCT b.id) FROM " . $bean->getTableName() . " b WHERE b.deleted = 0";
         $moduleCounts[$beanModule] = $db->getOne($query);
     }
     $revisionCount = array_sum($moduleCounts);
     $indexedCount = $db->getOne("SELECT COUNT(*) FROM aod_indexevent WHERE deleted = 0 AND success = 1");
     $failedCount = $db->getOne("SELECT COUNT(*) FROM aod_indexevent WHERE deleted = 0 AND success = 0");
     $indexFiles = count(glob($index->location . "/*.cfs"));
     $this->ss->assign("revisionCount", $revisionCount);
     $this->ss->assign("indexedCount", $indexedCount);
     $this->ss->assign("failedCount", $failedCount);
     $this->ss->assign("index", $index);
     $this->ss->assign("indexFiles", $indexFiles);
     echo $this->ss->fetch('modules/AOD_Index/tpls/indexdata.tpl');
     if ($failedCount) {
         $seed = BeanFactory::newBean("AOD_IndexEvent");
         $lv = new ListViewSmarty();
         $lv->lvd->additionalDetails = false;
         $mod_strings = return_module_language($current_language, $seed->module_dir);
         require 'modules/' . $seed->module_dir . '/metadata/listviewdefs.php';
         if (file_exists('custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php')) {
             require 'custom/modules/' . $seed->module_dir . '/metadata/listviewdefs.php';
         }
         $lv->displayColumns = $listViewDefs[$seed->module_dir];
         $lv->quickViewLinks = false;
         $lv->export = false;
         $lv->mergeduplicates = false;
         $lv->multiSelect = false;
         $lv->delete = false;
         $lv->select = false;
         $lv->showMassupdateFields = false;
         $lv->email = false;
         $lv->setup($seed, 'include/ListView/ListViewNoMassUpdate.tpl', 'success = 0', '', 0, 10);
         echo '<br /><br />' . get_form_header($GLOBALS['mod_strings']['LBL_FAILED_RECORDS'] . ' (' . $lv->data['pageData']['offsets']['total'] . ')', '', false);
         if ($lv->data['pageData']['offsets']['total'] == 0) {
             echo "No data";
         } else {
             echo $lv->display();
         }
     }
 }
Ejemplo n.º 26
0
 function handleBackup($view)
 {
     $backupObj = BeanFactory::newBean("dash_DashboardBackups");
     $backup_id = $backupObj->checkUserForDashboardBackup();
     if (isset($_REQUEST['runbackup']) && $_REQUEST['runbackup'] == 1 && $backup_id === false) {
         $backup_id = $backupObj->createDashboardBackup('', 'First Time Backup', 'Defaulted when using the dashboard manager for the first time', null, true);
     }
     if ($backup_id !== false) {
         return $view;
     } else {
         return 'makedefaultbackup';
     }
 }
Ejemplo n.º 27
0
 public function opportunityStats($api, $args)
 {
     // TODO make all APIs wrapped on tries and catches
     // TODO: move this to own module (in this case accounts)
     // TODO: Fix information leakage if user cannot list or view records not
     // belonging to them. It's hard to tell if the user has access if we
     // never get the bean.
     // Check for permissions on both Accounts and opportunities.
     // Load up the bean
     $record = BeanFactory::getBean($args['module'], $args['record']);
     if (!$record->ACLAccess('view')) {
         return;
     }
     // Load up the relationship
     if (!$record->load_relationship('opportunities')) {
         // The relationship did not load, I'm guessing it doesn't exist
         return;
     }
     // Figure out what is on the other side of this relationship, check permissions
     $linkModuleName = $record->opportunities->getRelatedModuleName();
     $linkSeed = BeanFactory::newBean($linkModuleName);
     if (!$linkSeed->ACLAccess('view')) {
         return;
     }
     $status_field = $this->getOpportunityStatusField();
     $query = new SugarQuery();
     $query->select(array($status_field, 'amount_usdollar'));
     $query->from($linkSeed);
     // making this more generic so we can use this on contacts also as soon
     // as we move it to a proper module
     $query->join('accounts', array('alias' => 'record'));
     $query->where()->equals('record.id', $record->id);
     // FIXME add the security query here!!!
     // TODO: When we can sum on the database side through SugarQuery, we can
     // use the group by statement.
     $results = $query->execute();
     // TODO this can't be done this way since we can change the status on
     // studio and add more
     $data = array('won' => array('amount_usdollar' => 0, 'count' => 0), 'lost' => array('amount_usdollar' => 0, 'count' => 0), 'active' => array('amount_usdollar' => 0, 'count' => 0));
     foreach ($results as $row) {
         $map = array('Closed Lost' => 'lost', 'Closed Won' => 'won');
         if (array_key_exists($row[$status_field], $map)) {
             $status = $map[$row[$status_field]];
         } else {
             $status = 'active';
         }
         $data[$status]['amount_usdollar'] += $row['amount_usdollar'];
         $data[$status]['count']++;
     }
     return $data;
 }
Ejemplo n.º 28
0
 /**
  * This public static function is a wrapper for BeanFactory::newBean
  * @param array $args
  */
 public static function newBean($args)
 {
     if (count($args) != 2) {
         throw new Exception("Wrong number of arguments for newBean");
     }
     $bean = BeanFactory::newBean($args[0]);
     foreach ($args[1] as $property) {
         $p = $property[0];
         $v = $property[1];
         $bean->{$p} = $v;
     }
     $bean->save();
     return $bean;
 }
Ejemplo n.º 29
0
 /**
  * Creates new role set from set of roles
  *
  * If there's deleted role set, marks it as non-deleted
  *
  * @param ACLRole[] $roles
  * @return static
  */
 public static function createFromRoles(array $roles)
 {
     $hash = self::getHashByRoles($roles);
     $instance = self::loadByHash($hash, false);
     if ($instance) {
         $instance->mark_undeleted($instance->id);
     } else {
         $instance = BeanFactory::newBean('ACLRoleSets');
         $instance->hash = $hash;
         $instance->save();
     }
     $instance->load_relationship('acl_roles');
     $instance->acl_roles->add($roles);
     return $instance;
 }
Ejemplo n.º 30
0
function unit_crearSolCoti($sbIdSolic)
{
    FnCrm::crearSolCoti($sbIdSolic);
    $bnSolicit = BeanFactory::getBean("opalo_solicitudes", $sbIdSolic);
    $bnSoliCot = BeanFactory::newBean("opalo_solicitudes_cotizacion");
    $bnSoliCos = $bnSoliCot->get_full_list('', "opalo_solicitudes_cotizacion.name like '" . $bnSolicit->name . "%'");
    if ($bnSoliCos != null) {
        echo $bnSolicit->name . "se creo la solicitud de cotizacion <br>";
        foreach ($bnSoliCos as $bnISolCot) {
            echo $bnISolCot->name . "<br>";
        }
    } else {
        echo "fallo con " . $bnSolicit->name . "<br>";
    }
}