コード例 #1
0
 /**
  * checks the request for the order by and if that is not set then it checks the session for it
  *
  * @return array containing the keys orderBy => field being ordered off of and sortOrder => the sort order of that field
  */
 function getOrderBy($orderBy = '', $direction = '')
 {
     if (!empty($orderBy) || !empty($_REQUEST[$this->var_order_by])) {
         if (!empty($_REQUEST[$this->var_order_by])) {
             $direction = 'ASC';
             $orderBy = $_REQUEST[$this->var_order_by];
             if (!empty($_REQUEST['lvso']) && (empty($_SESSION['lvd']['last_ob']) || strcmp($orderBy, $_SESSION['lvd']['last_ob']) == 0)) {
                 $direction = $_REQUEST['lvso'];
                 $trackerManager = TrackerManager::getInstance();
                 if ($monitor = $trackerManager->getMonitor('tracker')) {
                     $monitor->setValue('module_name', $GLOBALS['module']);
                     $monitor->setValue('item_summary', "lvso=" . $direction . "&" . $this->var_order_by . "=" . $_REQUEST[$this->var_order_by]);
                     $monitor->setValue('action', 'listview');
                     $monitor->setValue('user_id', $GLOBALS['current_user']->id);
                     $monitor->setValue('date_modified', gmdate($GLOBALS['timedate']->get_db_date_time_format()));
                     $monitor->save();
                 }
             }
         }
         $_SESSION[$this->var_order_by] = array('orderBy' => $orderBy, 'direction' => $direction);
         $_SESSION['lvd']['last_ob'] = $orderBy;
     } else {
         if (!empty($_SESSION[$this->var_order_by])) {
             $orderBy = $_SESSION[$this->var_order_by]['orderBy'];
             $direction = $_SESSION[$this->var_order_by]['direction'];
         }
     }
     return array('orderBy' => $orderBy, 'sortOrder' => $direction);
 }
コード例 #2
0
 function start()
 {
     $this->db = DBManagerFactory::getInstance();
     $this->userDemoData = new UserDemoData($this->user, false);
     $this->trackerManager = TrackerManager::getInstance();
     foreach ($this->modules as $mod) {
         $query = "select id from {$mod}";
         $result = $this->db->limitQuery($query, 0, 50);
         $ids = array();
         while ($row = $this->db->fetchByAssoc($result)) {
             $ids[] = $row['id'];
         }
         //while
         $this->beanIdMap[$mod] = $ids;
     }
     while ($this->monitorIds-- > 0) {
         $this->monitorId = create_guid();
         $this->trackerManager->setMonitorId($this->monitorId);
         $this->user = $this->userDemoData->guids[array_rand($this->userDemoData->guids)];
         $this->module = $this->modules[array_rand($this->modules)];
         $this->action = $this->actions[array_rand($this->actions)];
         $this->date = $this->randomTimestamp();
         $this->populate_tracker();
         $this->populate_tracker_perf();
         $this->populate_tracker_sessions();
         $this->populate_tracker_queries();
         $this->trackerManager->save();
     }
 }
コード例 #3
0
 public static function insertTrackerEntry($bean, $action)
 {
     require_once 'modules/Trackers/TrackerManager.php';
     $trackerManager = TrackerManager::getInstance();
     $timeStamp = gmdate($GLOBALS['timedate']->get_db_date_time_format());
     $_REQUEST['action'] = $action;
     if ($monitor = $trackerManager->getMonitor('tracker')) {
         $monitor->setValue('action', $action);
         $monitor->setValue('user_id', $GLOBALS['current_user']->id);
         $monitor->setValue('module_name', $bean->module_dir);
         $monitor->setValue('date_modified', $timeStamp);
         $monitor->setValue('visible', $action == 'detailview' || $action == 'editview' ? 1 : 0);
         if (!empty($bean->id)) {
             $monitor->setValue('item_id', $bean->id);
             $monitor->setValue('item_summary', $bean->get_summary_text());
         }
         //If visible is true, but there is no bean, do not track (invalid/unauthorized reference)
         //Also, do not track save actions where there is no bean id
         if ($monitor->visible && empty($bean->id)) {
             $trackerManager->unsetMonitor($monitor);
             return false;
         }
         $trackerManager->saveMonitor($monitor, true, true);
         if (empty(self::$_monitorId)) {
             self::$_monitorId = $monitor->monitor_id;
         }
     }
 }
コード例 #4
0
 /** 
  * @see SugarView::display()
  */
 public function display()
 {
     global $mod_strings, $app_strings;
     $admin = Administration::getSettings();
     require 'modules/Trackers/config.php';
     ///////////////////////////////////////////////////////////////////////////////
     ////	HANDLE CHANGES
     if (isset($_POST['process'])) {
         if ($_POST['process'] == 'true') {
             foreach ($tracker_config as $entry) {
                 if (isset($entry['bean'])) {
                     //If checkbox is unchecked, we add the entry into the config table; otherwise delete it
                     if (empty($_POST[$entry['name']])) {
                         $admin->saveSetting('tracker', $entry['name'], 1);
                     } else {
                         $db = DBManagerFactory::getInstance();
                         $db->query("DELETE FROM config WHERE category = 'tracker' and name = '" . $entry['name'] . "'");
                     }
                 }
             }
             //foreach
             //save the tracker prune interval
             if (!empty($_POST['tracker_prune_interval'])) {
                 $admin->saveSetting('tracker', 'prune_interval', $_POST['tracker_prune_interval']);
             }
             //save log slow queries and slow query interval
             $configurator = new Configurator();
             $configurator->saveConfig();
         }
         //if
         header('Location: index.php?module=Administration&action=index');
     }
     echo getClassicModuleTitle("Administration", array("<a href='index.php?module=Administration&action=index'>" . translate('LBL_MODULE_NAME', 'Administration') . "</a>", translate('LBL_TRACKER_SETTINGS', 'Administration')), false);
     $trackerManager = TrackerManager::getInstance();
     $disabledMonitors = $trackerManager->getDisabledMonitors();
     $trackerEntries = array();
     foreach ($tracker_config as $entry) {
         if (isset($entry['bean'])) {
             $disabled = !empty($disabledMonitors[$entry['name']]);
             $trackerEntries[$entry['name']] = array('label' => $mod_strings['LBL_' . strtoupper($entry['name']) . '_DESC'], 'helpLabel' => $mod_strings['LBL_' . strtoupper($entry['name']) . '_HELP'], 'disabled' => $disabled);
         }
     }
     $configurator = new Configurator();
     $this->ss->assign('config', $configurator->config);
     $config_strings = return_module_language($GLOBALS['current_language'], 'Configurator');
     $mod_strings['LOG_SLOW_QUERIES'] = $config_strings['LOG_SLOW_QUERIES'];
     $mod_strings['SLOW_QUERY_TIME_MSEC'] = $config_strings['SLOW_QUERY_TIME_MSEC'];
     $this->ss->assign('mod', $mod_strings);
     $this->ss->assign('app', $app_strings);
     $this->ss->assign('trackerEntries', $trackerEntries);
     $this->ss->assign('tracker_prune_interval', !empty($admin->settings['tracker_prune_interval']) ? $admin->settings['tracker_prune_interval'] : 30);
     $this->ss->display('modules/Trackers/tpls/TrackerSettings.tpl');
 }
コード例 #5
0
 /**
  * Track a view for a particular bean.
  *
  * @param SugarBean $seed
  * @param string $current_view
  */
 function trackView($seed, $current_view)
 {
     $trackerManager = TrackerManager::getInstance();
     if ($monitor = $trackerManager->getMonitor('tracker')) {
         $monitor->setValue('date_modified', TimeDate::getInstance()->nowDb());
         $monitor->setValue('user_id', $GLOBALS['current_user']->id);
         $monitor->setValue('module_name', $seed->module_dir);
         $monitor->setValue('action', $current_view);
         $monitor->setValue('item_id', $seed->id);
         $monitor->setValue('item_summary', $seed->get_summary_text());
         $monitor->setValue('visible', true);
         $trackerManager->saveMonitor($monitor, TRUE, TRUE);
     }
 }
コード例 #6
0
ファイル: Importer.php プロジェクト: jglaine/sugar761-ent
 public function __construct($importSource, $bean)
 {
     global $mod_strings, $sugar_config;
     $this->importSource = $importSource;
     //Vanilla copy of the bean object.
     $this->bean = $bean;
     // use our own error handler
     set_error_handler(array('Importer', 'handleImportErrors'), E_ALL & ~E_STRICT & ~E_DEPRECATED);
     // Increase the max_execution_time since this step can take awhile
     ini_set("max_execution_time", max($sugar_config['import_max_execution_time'], 3600));
     // stop the tracker
     TrackerManager::getInstance()->pause();
     // set the default locale settings
     $this->ifs = $this->getFieldSanitizer();
     //Get the default user currency
     $this->defaultUserCurrency = BeanFactory::getBean('Currencies', '-99');
     //Get our import column definitions
     $this->importColumns = $this->getImportColumns();
     $this->isUpdateOnly = isset($_REQUEST['import_type']) && $_REQUEST['import_type'] == 'update';
 }
コード例 #7
0
ファイル: SugarBean.php プロジェクト: rgauss/sugarcrm_dev
 /**
  * Tracks the viewing of a detail record.
  * This leverages get_summary_text() which is object specific.
  *
  * Internal function, do not override.
  * @param string $user_id - String value of the user that is viewing the record.
  * @param string $current_module - String value of the module being processed.
  * @param string $current_view - String value of the current view
  */
 function track_view($user_id, $current_module, $current_view = '')
 {
     $trackerManager = TrackerManager::getInstance();
     if ($monitor = $trackerManager->getMonitor('tracker')) {
         $monitor->setValue('date_modified', $GLOBALS['timedate']->nowDb());
         $monitor->setValue('user_id', $user_id);
         $monitor->setValue('module_name', $current_module);
         $monitor->setValue('action', $current_view);
         $monitor->setValue('item_id', $this->id);
         $monitor->setValue('item_summary', $this->get_summary_text());
         $monitor->setValue('visible', $this->tracker_visibility);
         $trackerManager->saveMonitor($monitor);
     }
 }
コード例 #8
0
ファイル: SugarView.php プロジェクト: omusico/sugar_work
 /**
  * track
  * Private function to track information about the view request
  */
 private function _track()
 {
     if (empty($this->responseTime)) {
         $this->_calculateFooterMetrics();
     }
     if (empty($GLOBALS['current_user']->id)) {
         return;
     }
     $trackerManager = TrackerManager::getInstance();
     $trackerManager->save();
 }
コード例 #9
0
 /**
  * This function takes a job_id, and updates schedulers last_run as well as
  * soft delete the job instance from schedulers_times
  * @return	boolean		Success
  */
 function finishJob()
 {
     $trackerManager = TrackerManager::getInstance();
     $trackerManager->pause();
     $GLOBALS['log']->debug('----->SchedulersJob updating Job Status and finishing Job execution.');
     $this->scheduler->retrieve($this->scheduler->id);
     $this->scheduler->last_run = gmdate($GLOBALS['timedate']->get_db_date_time_format());
     if ($this->scheduler->last_run == gmdate($GLOBALS['timedate']->get_db_date_time_format(), strtotime('Jan 01 2000 00:00:00'))) {
         $this->scheduler->last_run = $this->handleDateFormat('now');
         $GLOBALS['log']->fatal('Scheduler applying bogus date for "Last Run": ' . $this->scheduler->last_run);
     }
     $this->scheduler->save();
     $trackerManager->unPause();
 }
コード例 #10
0
ファイル: SugarView.php プロジェクト: jglaine/sugar761-ent
 /**
  * track
  * Private function to track information about the view request
  */
 private function _track()
 {
     if (empty($this->responseTime)) {
         $this->_calculateFooterMetrics();
     }
     if (empty($GLOBALS['current_user']->id)) {
         return;
     }
     $trackerManager = TrackerManager::getInstance();
     if (!$trackerManager->isPaused()) {
         $timeStamp = TimeDate::getInstance()->nowDb();
         //Track to tracker_perf
         if ($monitor2 = $trackerManager->getMonitor('tracker_perf')) {
             $monitor2->setValue('server_response_time', $this->responseTime);
             $dbManager =& DBManagerFactory::getInstance();
             $monitor2->db_round_trips = $dbManager->getQueryCount();
             $monitor2->setValue('date_modified', $timeStamp);
             $monitor2->setValue('db_round_trips', $dbManager->getQueryCount());
             $monitor2->setValue('files_opened', $this->fileResources);
             if (function_exists('memory_get_usage')) {
                 $monitor2->setValue('memory_usage', memory_get_usage());
             }
         }
         // Track to tracker_sessions
         if ($monitor3 = $trackerManager->getMonitor('tracker_sessions')) {
             $monitor3->setValue('date_end', $timeStamp);
             if (!isset($monitor3->date_start)) {
                 $monitor3->setValue('date_start', $timeStamp);
             }
             $seconds = strtotime($monitor3->date_end) - strtotime($monitor3->date_start);
             $monitor3->setValue('seconds', $seconds);
             $monitor3->setValue('user_id', $GLOBALS['current_user']->id);
         }
     }
     $trackerManager->save();
 }
コード例 #11
0
ファイル: xVendorFormBase.php プロジェクト: sunmo/snowlotus
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     $focus = new xVendor();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     } else {
         $check_notify = FALSE;
     }
     if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
         $duplicatexVendors = $this->checkForDuplicates($prefix);
         if (isset($duplicatexVendors)) {
             $location = 'module=xVendors&action=ShowDuplicates';
             $get = '';
             // Bug 25311 - Add special handling for when the form specifies many-to-many relationships
             if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) {
                 $get .= '&xVendorsrelate_to=' . $_POST['relate_to'];
             }
             if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) {
                 $get .= '&xVendorsrelate_id=' . $_POST['relate_id'];
             }
             //add all of the post fields to redirect get string
             foreach ($focus->column_fields as $field) {
                 if (!empty($focus->{$field}) && !is_object($focus->{$field})) {
                     $get .= "&xVendors{$field}=" . urlencode($focus->{$field});
                 }
             }
             foreach ($focus->additional_column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&xVendors{$field}=" . urlencode($focus->{$field});
                 }
             }
             if ($focus->hasCustomFields()) {
                 foreach ($focus->field_defs as $name => $field) {
                     if (!empty($field['source']) && $field['source'] == 'custom_fields') {
                         $get .= "&xVendors{$name}=" . urlencode($focus->{$name});
                     }
                 }
             }
             $emailAddress = new SugarEmailAddress();
             $get .= $emailAddress->getFormBaseURL($focus);
             //create list of suspected duplicate xvendor id's in redirect get string
             $i = 0;
             foreach ($duplicatexVendors as $xvendor) {
                 $get .= "&duplicate[{$i}]=" . $xvendor['id'];
                 $i++;
             }
             //add return_module, return_action, and return_id to redirect get string
             $get .= '&return_module=';
             if (!empty($_POST['return_module'])) {
                 $get .= $_POST['return_module'];
             } else {
                 $get .= 'xVendors';
             }
             $get .= '&return_action=';
             if (!empty($_POST['return_action'])) {
                 $get .= $_POST['return_action'];
             }
             //else $get .= 'DetailView';
             if (!empty($_POST['return_id'])) {
                 $get .= '&return_id=' . $_POST['return_id'];
             }
             if (!empty($_POST['popup'])) {
                 $get .= '&popup=' . $_POST['popup'];
             }
             if (!empty($_POST['create'])) {
                 $get .= '&create=' . $_POST['create'];
             }
             $_SESSION['SHOW_DUPLICATES'] = $get;
             //now redirect the post to modules/xVendors/ShowDuplicates.php
             if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
                 ob_clean();
                 $json = getJSONobj();
                 echo $json->encode(array('status' => 'dupe', 'get' => $location));
             } else {
                 if (!empty($_REQUEST['ajax_load'])) {
                     echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>";
                 } else {
                     if (!empty($_POST['to_pdf'])) {
                         $location .= '&to_pdf=' . $_POST['to_pdf'];
                     }
                     header("Location: index.php?{$location}");
                 }
             }
             return null;
         }
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     $focus->save($check_notify);
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
         $json = getJSONobj();
         echo $json->encode(array('status' => 'success', 'get' => ''));
         $trackerManager = TrackerManager::getInstance();
         $timeStamp = TimeDate::getInstance()->nowDb();
         if ($monitor = $trackerManager->getMonitor('tracker')) {
             $monitor->setValue('action', 'detailview');
             $monitor->setValue('user_id', $GLOBALS['current_user']->id);
             $monitor->setValue('module_name', 'xVendors');
             $monitor->setValue('date_modified', $timeStamp);
             $monitor->setValue('visible', 1);
             if (!empty($this->bean->id)) {
                 $monitor->setValue('item_id', $return_id);
                 $monitor->setValue('item_summary', $focus->get_summary_text());
             }
             $trackerManager->saveMonitor($monitor, true, true);
         }
         return null;
     }
     if (isset($_POST['popup']) && $_POST['popup'] == 'true') {
         $get = '&module=';
         if (!empty($_POST['return_module'])) {
             $get .= $_POST['return_module'];
         } else {
             $get .= 'xVendors';
         }
         $get .= '&action=';
         if (!empty($_POST['return_action'])) {
             $get .= $_POST['return_action'];
         } else {
             $get .= 'Popup';
         }
         if (!empty($_POST['return_id'])) {
             $get .= '&return_id=' . $_POST['return_id'];
         }
         if (!empty($_POST['popup'])) {
             $get .= '&popup=' . $_POST['popup'];
         }
         if (!empty($_POST['create'])) {
             $get .= '&create=' . $_POST['create'];
         }
         if (!empty($_POST['to_pdf'])) {
             $get .= '&to_pdf=' . $_POST['to_pdf'];
         }
         $get .= '&name=' . $focus->name;
         $get .= '&query=true';
         header("Location: index.php?{$get}");
         return;
     }
     if ($redirect) {
         handleRedirect($return_id, 'xVendors');
     } else {
         return $focus;
     }
 }
コード例 #12
0
 /**
  * save
  * This method retrieves the Store instances associated with monitor and calls
  * the flush method passing with the montior ($this) instance.
  * 
  */
 public function save($flush = true)
 {
     if (empty($this->date_modified)) {
         $this->date_modified = $GLOBALS['timedate']->nowDb();
     }
     $this->cached_data[] = $this->toArray();
     if ($flush && empty($GLOBALS['tracker_' . $this->table_name]) && !empty($this->cached_data)) {
         require_once 'modules/Trackers/TrackerUtility.php';
         $write_entries = array();
         foreach ($this->cached_data as $entry) {
             $query = str_replace(array("\r", "\n", "\r\n", "\t"), ' ', $entry['text']);
             $query = preg_replace("/\\s{2,}/", ' ', $query);
             $query = TrackerUtility::getGenericSQL($query);
             $entry['text'] = $query;
             $md5 = md5($query);
             if (!isset($write_entries[$md5])) {
                 $entry['query_hash'] = $md5;
                 $result = $GLOBALS['db']->query("SELECT * FROM tracker_queries WHERE query_hash = '{$md5}'");
                 if ($row = $GLOBALS['db']->fetchByAssoc($result)) {
                     $entry['query_id'] = $row['query_id'];
                     $entry['run_count'] = $row['run_count'] + 1;
                     $entry['sec_total'] = $row['sec_total'] + $entry['sec_total'];
                     $entry['sec_avg'] = $entry['sec_total'] / $entry['run_count'];
                 } else {
                     $entry['query_id'] = create_guid();
                     $entry['run_count'] = 1;
                     $entry['sec_total'] = $entry['sec_total'];
                     $entry['sec_avg'] = $entry['sec_total'];
                 }
                 $write_entries[$md5] = $entry;
             } else {
                 $write_entries[$md5]['run_count'] = $write_entries[$md5]['run_count']++;
                 $write_entries[$md5]['sec_total'] = $write_entries[$md5]['sec_total'] + $entry['sec_total'];
                 $write_entries[$md5]['sec_avg'] = $write_entries[$md5]['sec_total'] / $write_entries[$md5]['run_count'];
             }
             //if-else
         }
         //foreach
         $trackerManager = TrackerManager::getInstance();
         if ($monitor2 = $trackerManager->getMonitor('tracker_tracker_queries')) {
             $trackerManager->pause();
             //Loop through the stored cached data entries
             foreach ($write_entries as $write_e) {
                 //Set the values from the cached data entries
                 foreach ($write_e as $name => $value) {
                     $this->{$name} = $value;
                 }
                 //foreach
                 //Write to the tracker_tracker_monitor monitor
                 $monitor2->setValue('monitor_id', $this->monitor_id);
                 $monitor2->setValue('date_modified', $this->date_modified);
                 $monitor2->setValue('query_id', $this->query_id);
                 $monitor2->save($flush);
                 // <--- save to tracker_tracker_monitor
                 foreach ($this->stores as $s) {
                     $store = $this->getStore($s);
                     //Flush to the store
                     $store->flush($this);
                 }
                 //Clear the monitor
                 $this->clear();
             }
             //foreach
             $trackerManager->unPause();
         }
         unset($this->cached_data);
     }
     //if
 }
コード例 #13
0
 function endSession()
 {
     $trackerManager = TrackerManager::getInstance();
     if ($monitor = $trackerManager->getMonitor('tracker_sessions')) {
         $monitor->setValue('date_end', TimeDate::getInstance()->nowDb());
         $seconds = strtotime($monitor->date_end) - strtotime($monitor->date_start);
         $monitor->setValue('seconds', $seconds);
         $monitor->setValue('active', 0);
     }
     session_destroy();
 }
コード例 #14
0
ファイル: view.step4.php プロジェクト: aldridged/gtg-sugar
 /** 
  * @see SugarView::display()
  */
 public function display()
 {
     global $sugar_config;
     // Increase the max_execution_time since this step can take awhile
     ini_set("max_execution_time", max($sugar_config['import_max_execution_time'], 3600));
     // stop the tracker
     TrackerManager::getInstance()->pause();
     // use our own error handler
     set_error_handler('handleImportErrors', E_ALL);
     global $mod_strings, $app_strings, $current_user, $import_bean_map;
     global $app_list_strings, $timedate;
     $update_only = isset($_REQUEST['import_type']) && $_REQUEST['import_type'] == 'update';
     $firstrow = unserialize(base64_decode($_REQUEST['firstrow']));
     // All the Look Up Caches are initialized here
     $enum_lookup_cache = array();
     // Let's try and load the import bean
     $focus = loadImportBean($_REQUEST['import_module']);
     if (!$focus) {
         trigger_error($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'], E_USER_ERROR);
     }
     // setup the importable fields array.
     $importable_fields = $focus->get_importable_fields();
     // loop through all request variables
     $importColumns = array();
     foreach ($_REQUEST as $name => $value) {
         // only look for var names that start with "fieldNum"
         if (strncasecmp($name, "colnum_", 7) != 0) {
             continue;
         }
         // pull out the column position for this field name
         $pos = substr($name, 7);
         if (isset($importable_fields[$value])) {
             // now mark that we've seen this field
             $importColumns[$pos] = $value;
         }
     }
     // set the default locale settings
     $ifs = new ImportFieldSanitize();
     $ifs->dateformat = $_REQUEST['importlocale_dateformat'];
     $ifs->timeformat = $_REQUEST['importlocale_timeformat'];
     $ifs->timezone = $_REQUEST['importlocale_timezone'];
     $currency = new Currency();
     $currency->retrieve($_REQUEST['importlocale_currency']);
     $ifs->currency_symbol = $currency->symbol;
     $ifs->default_currency_significant_digits = $_REQUEST['importlocale_default_currency_significant_digits'];
     $ifs->num_grp_sep = $_REQUEST['importlocale_num_grp_sep'];
     $ifs->dec_sep = $_REQUEST['importlocale_dec_sep'];
     $ifs->default_locale_name_format = $_REQUEST['importlocale_default_locale_name_format'];
     // Check to be sure we are getting an import file that is in the right place
     if (realpath(dirname($_REQUEST['tmp_file']) . '/') != realpath($sugar_config['upload_dir'])) {
         trigger_error($mod_strings['LBL_CANNOT_OPEN'], E_USER_ERROR);
     }
     // Open the import file
     $importFile = new ImportFile($_REQUEST['tmp_file'], $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES));
     if (!$importFile->fileExists()) {
         trigger_error($mod_strings['LBL_CANNOT_OPEN'], E_USER_ERROR);
     }
     $fieldDefs = $focus->getFieldDefinitions();
     unset($focus);
     while ($row = $importFile->getNextRow()) {
         $focus = loadImportBean($_REQUEST['import_module']);
         $focus->unPopulateDefaultValues();
         $focus->save_from_post = false;
         $focus->team_id = null;
         $ifs->createdBeans = array();
         $do_save = true;
         for ($fieldNum = 0; $fieldNum < $_REQUEST['columncount']; $fieldNum++) {
             // loop if this column isn't set
             if (!isset($importColumns[$fieldNum])) {
                 continue;
             }
             // get this field's properties
             $field = $importColumns[$fieldNum];
             $fieldDef = $focus->getFieldDefinition($field);
             $fieldTranslated = translate(isset($fieldDef['vname']) ? $fieldDef['vname'] : $fieldDef['name'], $_REQUEST['module']) . " (" . $fieldDef['name'] . ")";
             // Bug 37241 - Don't re-import over a field we already set during the importing of another field
             if (!empty($focus->{$field})) {
                 continue;
             }
             //DETERMINE WHETHER OR NOT $fieldDef['name'] IS DATE_MODIFIED AND SET A VAR, USE DOWN BELOW
             // translate strings
             global $locale;
             if (empty($locale)) {
                 $locale = new Localization();
             }
             if (isset($row[$fieldNum])) {
                 $rowValue = $locale->translateCharset(strip_tags(trim($row[$fieldNum])), $_REQUEST['importlocale_charset'], $sugar_config['default_charset']);
             } else {
                 $rowValue = '';
             }
             // If there is an default value then use it instead
             if (!empty($_REQUEST[$field])) {
                 if (is_array($_REQUEST[$field])) {
                     $defaultRowValue = encodeMultienumValue($_REQUEST[$field]);
                 } else {
                     $defaultRowValue = $_REQUEST[$field];
                 }
                 // translate default values to the date/time format for the import file
                 if ($fieldDef['type'] == 'date' && $ifs->dateformat != $timedate->get_date_format()) {
                     $defaultRowValue = $timedate->swap_formats($defaultRowValue, $ifs->dateformat, $timedate->get_date_format());
                 }
                 if ($fieldDef['type'] == 'time' && $ifs->timeformat != $timedate->get_time_format()) {
                     $defaultRowValue = $timedate->swap_formats($defaultRowValue, $ifs->timeformat, $timedate->get_time_format());
                 }
                 if (($fieldDef['type'] == 'datetime' || $fieldDef['type'] == 'datetimecombo') && $ifs->dateformat . ' ' . $ifs->timeformat != $timedate->get_date_time_format()) {
                     $defaultRowValue = $timedate->swap_formats($defaultRowValue, $ifs->dateformat . ' ' . $ifs->timeformat, $timedate->get_date_time_format());
                 }
                 if (in_array($fieldDef['type'], array('currency', 'float', 'int', 'num')) && $ifs->num_grp_sep != $current_user->getPreference('num_grp_sep')) {
                     $defaultRowValue = str_replace($current_user->getPreference('num_grp_sep'), $ifs->num_grp_sep, $defaultRowValue);
                 }
                 if (in_array($fieldDef['type'], array('currency', 'float')) && $ifs->dec_sep != $current_user->getPreference('dec_sep')) {
                     $defaultRowValue = str_replace($current_user->getPreference('dec_sep'), $ifs->dec_sep, $defaultRowValue);
                 }
                 $currency->retrieve('-99');
                 $user_currency_symbol = $currency->symbol;
                 if ($fieldDef['type'] == 'currency' && $ifs->currency_symbol != $user_currency_symbol) {
                     $defaultRowValue = str_replace($user_currency_symbol, $ifs->currency_symbol, $defaultRowValue);
                 }
                 if (empty($rowValue)) {
                     $rowValue = $defaultRowValue;
                     unset($defaultRowValue);
                 }
             }
             // Bug 22705 - Don't update the First Name or Last Name value if Full Name is set
             if (in_array($field, array('first_name', 'last_name')) && !empty($focus->full_name)) {
                 continue;
             }
             // loop if this value has not been set
             if (!isset($rowValue)) {
                 continue;
             }
             // If the field is required and blank then error out
             if (array_key_exists($field, $focus->get_import_required_fields()) && empty($rowValue) && $rowValue != '0') {
                 $importFile->writeError($mod_strings['LBL_REQUIRED_VALUE'], $fieldTranslated, 'NULL');
                 $do_save = false;
             }
             // Handle the special case "Sync to Outlook"
             if ($focus->object_name == "Contacts" && $field == 'sync_contact') {
                 $bad_names = array();
                 $returnValue = $ifs->synctooutlook($rowValue, $fieldDef, $bad_names);
                 // try the default value on fail
                 if (!$returnValue && !empty($defaultRowValue)) {
                     $returnValue = $ifs->synctooutlook($defaultRowValue, $fieldDef, $bad_names);
                 }
                 if (!$returnValue) {
                     $importFile->writeError($mod_strings['LBL_ERROR_SYNC_USERS'], $fieldTranslated, explode(",", $bad_names));
                     $do_save = 0;
                 }
             }
             // Handle email1 and email2 fields ( these don't have the type of email )
             if ($field == 'email1' || $field == 'email2') {
                 $returnValue = $ifs->email($rowValue, $fieldDef);
                 // try the default value on fail
                 if (!$returnValue && !empty($defaultRowValue)) {
                     $returnValue = $ifs->email($defaultRowValue, $fieldDef);
                 }
                 if ($returnValue === FALSE) {
                     $do_save = 0;
                     $importFile->writeError($mod_strings['LBL_ERROR_INVALID_EMAIL'], $fieldTranslated, $rowValue);
                 } else {
                     $rowValue = $returnValue;
                     // check for current opt_out and invalid email settings for this email address
                     // if we find any, set them now
                     $emailres = $focus->db->query("SELECT opt_out, invalid_email FROM email_addresses \n                                WHERE email_address = '" . $focus->db->quote($rowValue) . "'");
                     if ($emailrow = $focus->db->fetchByAssoc($emailres)) {
                         $focus->email_opt_out = $emailrow['opt_out'];
                         $focus->invalid_email = $emailrow['invalid_email'];
                     }
                 }
             }
             // Handle splitting Full Name into First and Last Name parts
             if ($field == 'full_name' && !empty($rowValue)) {
                 $ifs->fullname($rowValue, $fieldDef, $focus);
             }
             // to maintain 451 compatiblity
             if (!isset($fieldDef['module']) && $fieldDef['type'] == 'relate') {
                 $fieldDef['module'] = ucfirst($fieldDef['table']);
             }
             if (isset($fieldDef['custom_type']) && !empty($fieldDef['custom_type'])) {
                 $fieldDef['type'] = $fieldDef['custom_type'];
             }
             // If the field is empty then there is no need to check the data
             if (!empty($rowValue)) {
                 switch ($fieldDef['type']) {
                     case 'enum':
                     case 'multienum':
                         if (isset($fieldDef['type']) && $fieldDef['type'] == "multienum") {
                             $returnValue = $ifs->multienum($rowValue, $fieldDef);
                         } else {
                             $returnValue = $ifs->enum($rowValue, $fieldDef);
                         }
                         // try the default value on fail
                         if (!$returnValue && !empty($defaultRowValue)) {
                             if (isset($fieldDef['type']) && $fieldDef['type'] == "multienum") {
                                 $returnValue = $ifs->multienum($defaultRowValue, $fieldDef);
                             } else {
                                 $returnValue = $ifs->enum($defaultRowValue, $fieldDef);
                             }
                         }
                         if ($returnValue === FALSE) {
                             $importFile->writeError($mod_strings['LBL_ERROR_NOT_IN_ENUM'] . implode(",", $app_list_strings[$fieldDef['options']]), $fieldTranslated, $rowValue);
                             $do_save = 0;
                         } else {
                             $rowValue = $returnValue;
                         }
                         break;
                     case 'relate':
                     case 'parent':
                         $returnValue = $ifs->relate($rowValue, $fieldDef, $focus, empty($defaultRowValue));
                         if (!$returnValue && !empty($defaultRowValue)) {
                             $returnValue = $ifs->relate($defaultRowValue, $fieldDef, $focus);
                         }
                         // Bug 33623 - Set the id value found from the above method call as an importColumn
                         if ($returnValue !== false) {
                             $importColumns[] = $fieldDef['id_name'];
                         }
                         break;
                     case 'teamset':
                         $returnValue = $ifs->teamset($rowValue, $fieldDef, $focus);
                         $importColumns[] = 'team_set_id';
                         $importColumns[] = 'team_id';
                         break;
                     case 'fullname':
                         break;
                     default:
                         if (method_exists('ImportFieldSanitize', $fieldDef['type'])) {
                             $fieldtype = $fieldDef['type'];
                             $returnValue = $ifs->{$fieldtype}($rowValue, $fieldDef);
                             // try the default value on fail
                             if (!$returnValue && !empty($defaultRowValue)) {
                                 $returnValue = $ifs->{$fieldtype}($defaultRowValue, $fieldDef);
                             }
                             if (!$returnValue) {
                                 $do_save = 0;
                                 $importFile->writeError($mod_strings['LBL_ERROR_INVALID_' . strtoupper($fieldDef['type'])], $fieldTranslated, $rowValue);
                             } else {
                                 $rowValue = $returnValue;
                             }
                         }
                 }
             }
             $focus->{$field} = $rowValue;
             unset($defaultRowValue);
         }
         // Now try to validate flex relate fields
         if (isset($focus->field_defs['parent_name']) && isset($focus->parent_name) && $focus->field_defs['parent_name']['type'] == 'parent') {
             // populate values from the picker widget if the import file doesn't have them
             $parent_idField = $focus->field_defs['parent_name']['id_name'];
             if (empty($focus->{$parent_idField}) && !empty($_REQUEST[$parent_idField])) {
                 $focus->{$parent_idField} = $_REQUEST[$parent_idField];
             }
             $parent_typeField = $focus->field_defs['parent_name']['type_name'];
             if (empty($focus->{$parent_typeField}) && !empty($_REQUEST[$parent_typeField])) {
                 $focus->{$parent_typeField} = $_REQUEST[$parent_typeField];
             }
             // now validate it
             $returnValue = $ifs->parent($focus->parent_name, $focus->field_defs['parent_name'], $focus, empty($_REQUEST['parent_name']));
             if (!$returnValue && !empty($_REQUEST['parent_name'])) {
                 $returnValue = $ifs->parent($_REQUEST['parent_name'], $focus->field_defs['parent_name'], $focus);
             }
         }
         // check to see that the indexes being entered are unique.
         if (isset($_REQUEST['display_tabs_def']) && $_REQUEST['display_tabs_def'] != "") {
             $idc = new ImportDuplicateCheck($focus);
             if ($idc->isADuplicateRecord(explode('&', $_REQUEST['display_tabs_def']))) {
                 $importFile->markRowAsDuplicate();
                 $this->_undoCreatedBeans($ifs->createdBeans);
                 continue;
             }
         }
         // if the id was specified
         $newRecord = true;
         if (!empty($focus->id)) {
             $focus->id = $this->_convertId($focus->id);
             // check if it already exists
             $query = "SELECT * FROM {$focus->table_name} WHERE id='" . $focus->db->quote($focus->id) . "'";
             $result = $focus->db->query($query) or sugar_die("Error selecting sugarbean: ");
             $dbrow = $focus->db->fetchByAssoc($result);
             if (isset($dbrow['id']) && $dbrow['id'] != -1) {
                 // if it exists but was deleted, just remove it
                 if (isset($dbrow['deleted']) && $dbrow['deleted'] == 1 && $update_only == false) {
                     $query2 = "DELETE FROM {$focus->table_name} WHERE id='" . $focus->db->quote($focus->id) . "'";
                     $result2 = $focus->db->query($query2) or sugar_die($mod_strings['LBL_ERROR_DELETING_RECORD'] . " " . $focus->id);
                     if ($focus->hasCustomFields()) {
                         $query3 = "DELETE FROM {$focus->table_name}_cstm WHERE id_c='" . $focus->db->quote($focus->id) . "'";
                         $result2 = $focus->db->query($query3);
                     }
                     $focus->new_with_id = true;
                 } else {
                     if (!$update_only) {
                         $do_save = 0;
                         $importFile->writeError($mod_strings['LBL_ID_EXISTS_ALREADY'], 'ID', $focus->id);
                         $this->_undoCreatedBeans($ifs->createdBeans);
                         continue;
                     }
                     $existing_focus = loadImportBean($_REQUEST['import_module']);
                     $newRecord = false;
                     if (!$existing_focus->retrieve($dbrow['id']) instanceof SugarBean) {
                         $do_save = 0;
                         $importFile->writeError($mod_strings['LBL_RECORD_CANNOT_BE_UPDATED'], 'ID', $focus->id);
                         $this->_undoCreatedBeans($ifs->createdBeans);
                         continue;
                     } else {
                         $newData = $focus->toArray();
                         foreach ($newData as $focus_key => $focus_value) {
                             if (in_array($focus_key, $importColumns)) {
                                 $existing_focus->{$focus_key} = $focus_value;
                             }
                         }
                         $focus = $existing_focus;
                     }
                     unset($existing_focus);
                 }
             } else {
                 $focus->new_with_id = true;
             }
         }
         if ($do_save) {
             // Populate in any default values to the bean
             $focus->populateDefaultValues();
             if (!isset($focus->assigned_user_id) || $focus->assigned_user_id == '' && $newRecord) {
                 $focus->assigned_user_id = $current_user->id;
             }
             /*
              * Bug 34854: Added all conditions besides the empty check on date modified. Currently, if
              * we do an update to a record, it doesn't update the date_modified value.
              * Hack note: I'm doing a to_display and back to_db on the fetched row to make sure that any truncating that happens
              * when $focus->date_modified goes to_display and back to_db also happens on the fetched db value. Otherwise,
              * in some cases we truncate the seconds on one and not the other, and the comparison fails when it should pass
              */
             if (!empty($focus->new_with_id) && !empty($focus->date_modified) || empty($focus->new_with_id) && $timedate->to_db($focus->date_modified) != $timedate->to_db($timedate->to_display_date_time($focus->fetched_row['date_modified']))) {
                 $focus->update_date_modified = false;
             }
             $focus->optimistic_lock = false;
             if ($focus->object_name == "Contacts" && isset($focus->sync_contact)) {
                 //copy the potential sync list to another varible
                 $list_of_users = $focus->sync_contact;
                 //and set it to false for the save
                 $focus->sync_contact = false;
             } else {
                 if ($focus->object_name == "User" && !empty($current_user) && $focus->is_admin && !is_admin($current_user) && is_admin_for_module($current_user, 'Users')) {
                     sugar_die($GLOBALS['mod_strings']['ERR_IMPORT_SYSTEM_ADMININSTRATOR']);
                 }
             }
             //bug# 40260 setting it true as the module in focus is involved in an import
             $focus->in_import = true;
             // call any logic needed for the module preSave
             $focus->beforeImportSave();
             $focus->save(false);
             // call any logic needed for the module postSave
             $focus->afterImportSave();
             if ($focus->object_name == "Contacts" && isset($list_of_users)) {
                 $focus->process_sync_to_outlook($list_of_users);
             }
             // Update the created/updated counter
             $importFile->markRowAsImported($newRecord);
             // Add ID to User's Last Import records
             if ($newRecord) {
                 ImportFile::writeRowToLastImport($_REQUEST['import_module'], $focus->object_name == 'Case' ? 'aCase' : $focus->object_name, $focus->id);
             }
         } else {
             $this->_undoCreatedBeans($ifs->createdBeans);
         }
     }
     // save mapping if requested
     if (isset($_REQUEST['save_map_as']) && $_REQUEST['save_map_as'] != '') {
         $mapping_file = new ImportMap();
         if (isset($_REQUEST['has_header']) && $_REQUEST['has_header'] == 'on') {
             $header_to_field = array();
             foreach ($importColumns as $pos => $field_name) {
                 if (isset($firstrow[$pos]) && isset($field_name)) {
                     $header_to_field[$firstrow[$pos]] = $field_name;
                 }
             }
             $mapping_file->setMapping($header_to_field);
         } else {
             $mapping_file->setMapping($importColumns);
         }
         // save default fields
         $defaultValues = array();
         for ($i = 0; $i < $_REQUEST['columncount']; $i++) {
             if (isset($importColumns[$i]) && !empty($_REQUEST[$importColumns[$i]])) {
                 $field = $importColumns[$i];
                 $fieldDef = $focus->getFieldDefinition($field);
                 if (!empty($fieldDef['custom_type']) && $fieldDef['custom_type'] == 'teamset') {
                     require_once 'include/SugarFields/Fields/Teamset/SugarFieldTeamset.php';
                     $sugar_field = new SugarFieldTeamset('Teamset');
                     $teams = $sugar_field->getTeamsFromRequest($field);
                     if (isset($_REQUEST['primary_team_name_collection'])) {
                         $primary_index = $_REQUEST['primary_team_name_collection'];
                     }
                     //If primary_index was selected, ensure that the first Array entry is the primary team
                     if (isset($primary_index)) {
                         $count = 0;
                         $new_teams = array();
                         foreach ($teams as $id => $name) {
                             if ($primary_index == $count++) {
                                 $new_teams[$id] = $name;
                                 unset($teams[$id]);
                                 break;
                             }
                         }
                         foreach ($teams as $id => $name) {
                             $new_teams[$id] = $name;
                         }
                         $teams = $new_teams;
                     }
                     //if
                     $json = getJSONobj();
                     $defaultValues[$field] = $json->encode($teams);
                 } else {
                     $defaultValues[$field] = $_REQUEST[$importColumns[$i]];
                 }
             }
         }
         $mapping_file->setDefaultValues($defaultValues);
         $result = $mapping_file->save($current_user->id, $_REQUEST['save_map_as'], $_REQUEST['import_module'], $_REQUEST['source'], isset($_REQUEST['has_header']) && $_REQUEST['has_header'] == 'on', $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES));
     }
     $importFile->writeStatus();
 }
コード例 #15
0
 /**
  * Initialize Sugar environment
  */
 protected function initSugar()
 {
     if ($this->sugar_initialized) {
         return;
     }
     // BR-385 - This fixes the issues around SugarThemeRegistry fatals.  The cache needs rebuild on stage-post init of sugar
     if ($this->current_stage == 'post') {
         $this->cleanFileCache();
     }
     if (!defined('sugarEntry')) {
         define('sugarEntry', true);
     }
     $this->log("Initializing SugarCRM environment");
     global $beanFiles, $beanList, $objectList, $timedate, $moduleList, $modInvisList, $sugar_config, $locale, $sugar_version, $sugar_flavor, $sugar_build, $sugar_db_version, $sugar_timestamp, $db, $locale, $installing, $bwcModules, $app_list_strings, $modules_exempt_from_availability_check;
     $installing = true;
     include 'include/entryPoint.php';
     $installing = false;
     $GLOBALS['current_language'] = $this->config['default_language'];
     if (empty($GLOBALS['current_language'])) {
         $GLOBALS['current_language'] = 'en_us';
     }
     $GLOBALS['log'] = LoggerManager::getLogger('SugarCRM');
     $this->db = $GLOBALS['db'] = DBManagerFactory::getInstance();
     //Once we have a DB, we can do a full cache clear
     if ($this->current_stage == 'post') {
         $this->cleanCaches();
     }
     SugarApplication::preLoadLanguages();
     $timedate = TimeDate::getInstance();
     if (empty($locale)) {
         if (method_exists('Localization', 'getObject')) {
             $locale = Localization::getObject();
         } else {
             $locale = new Localization();
         }
     }
     if (!isset($_SERVER['REQUEST_URI'])) {
         $_SERVER['REQUEST_URI'] = '';
     }
     // Load user
     $GLOBALS['current_user'] = $this->getUser();
     // Prepare DB
     if ($this->config['dbconfig']['db_type'] == 'mysql') {
         //Change the db wait_timeout for this session
         $now_timeout = $this->db->getOne("select @@wait_timeout");
         $this->db->query("set wait_timeout=28800");
         $now_timeout = $this->db->getOne("select @@wait_timeout");
         $this->log("DB timeout set to {$now_timeout}");
     }
     // stop trackers
     $trackerManager = TrackerManager::getInstance(true);
     $trackerManager->pause();
     $trackerManager->unsetMonitors();
     $this->sugar_initialized = true;
     $this->loadStrings();
     $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']);
     $this->log("Done initializing SugarCRM environment");
 }
コード例 #16
0
ファイル: Scheduler.php プロジェクト: aldridged/gtg-sugar
 /**
  * executes Scheduled job
  */
 function fire()
 {
     if (empty($this->job)) {
         // only execute when valid
         $GLOBALS['log']->fatal('Scheduler tried to fire an empty job!!');
         return false;
     }
     $exJob = explode('::', $this->job);
     if (is_array($exJob)) {
         // instantiate a new SchedulersJob object and prep it
         $trackerManager = TrackerManager::getInstance();
         $trackerManager->pause();
         $job = new SchedulersJob();
         $job->scheduler_id = $this->id;
         $job->scheduler =& $this;
         $job->execute_time = $job->handleDateFormat('now');
         $jobId = $job->save();
         $trackerManager->unPause();
         $job->retrieve($jobId);
         if ($exJob[0] == 'function') {
             $GLOBALS['log']->debug('----->Scheduler found a job of type FUNCTION');
             require_once 'modules/Schedulers/_AddJobsHere.php';
             $job->setJobFlag(1);
             $func = $exJob[1];
             $GLOBALS['log']->debug('----->SchedulersJob firing ' . $func);
             $res = call_user_func($func);
             if ($res) {
                 $job->setJobFlag(2);
                 $job->finishJob();
                 return true;
             } else {
                 $job->setJobFlag(3);
                 return false;
             }
         } elseif ($exJob[0] == 'url') {
             if (function_exists('curl_init')) {
                 $GLOBALS['log']->debug('----->SchedulersJob found a job of type URL');
                 $job->setJobFlag(1);
                 $GLOBALS['log']->debug('----->SchedulersJob firing URL job: ' . $exJob[1]);
                 if ($job->fireUrl($exJob[1])) {
                     $job->setJobFlag(2);
                     $job->finishJob();
                     return true;
                 } else {
                     $job->setJobFlag(3);
                     return false;
                 }
             } else {
                 $job->setJobFlag(4);
                 return false;
             }
         }
     }
     return false;
 }
コード例 #17
0
ファイル: DBManager.php プロジェクト: jglaine/sugar761-ent
 /**
  * Tracks slow queries in the tracker database table
  *
  * @param string $query  value of query to track
  */
 protected function track_slow_queries($query)
 {
     $trackerManager = TrackerManager::getInstance();
     if ($trackerManager->isPaused()) {
         return;
     }
     if ($monitor = $trackerManager->getMonitor('tracker_queries')) {
         $monitor->setValue('date_modified', $this->timedate->nowDb());
         $monitor->setValue('text', $query);
         $monitor->setValue('sec_total', $this->query_time);
         //Save the monitor to cache (do not flush)
         $trackerManager->saveMonitor($monitor, false);
     }
 }
コード例 #18
0
ファイル: utils.php プロジェクト: jglaine/sugar761-ent
/**
 * Clean up Sugar environment
 * @param bool $exit Should we exit() after we're done?
 */
function sugar_cleanup($exit = false)
{
    static $called = false;
    if ($called) {
        return;
    }
    $called = true;
    $root_path = sugar_root_dir();
    $paths = explode(PATH_SEPARATOR, get_include_path());
    if (in_array($root_path, $paths) == false) {
        set_include_path($root_path . PATH_SEPARATOR . get_include_path());
    }
    chdir($root_path);
    // if cleanup runs before autoloader was loaded then init autoloader.
    if (!class_exists('SugarAutoLoader')) {
        require_once 'include/utils/autoloader.php';
        SugarAutoLoader::init();
    }
    global $sugar_config;
    require_once 'include/utils/LogicHook.php';
    LogicHook::initialize();
    $GLOBALS['logic_hook']->call_custom_logic('', 'server_round_trip');
    //added this check to avoid errors during install.
    if (empty($sugar_config['dbconfig'])) {
        if ($exit) {
            exit;
        } else {
            return;
        }
    }
    if (!class_exists('Tracker', true)) {
        require_once 'modules/Trackers/Tracker.php';
    }
    Tracker::logPage();
    // Now write the cached tracker_queries
    if (class_exists("TrackerManager")) {
        $trackerManager = TrackerManager::getInstance();
        if ($monitor = $trackerManager->getMonitor('tracker_queries')) {
            $trackerManager->saveMonitor($monitor, true);
        }
    }
    if (!empty($GLOBALS['savePreferencesToDB']) && $GLOBALS['savePreferencesToDB']) {
        if (isset($GLOBALS['current_user']) && $GLOBALS['current_user'] instanceof User) {
            $GLOBALS['current_user']->savePreferencesToDB();
        }
    }
    //check to see if this is not an `ajax call AND the user preference error flag is set
    if (isset($_SESSION['USER_PREFRENCE_ERRORS']) && $_SESSION['USER_PREFRENCE_ERRORS'] && ($_REQUEST['action'] != 'modulelistmenu' && $_REQUEST['action'] != 'DynamicAction') && ($_REQUEST['action'] != 'favorites' && $_REQUEST['action'] != 'DynamicAction') && (empty($_REQUEST['to_pdf']) || !$_REQUEST['to_pdf']) && (empty($_REQUEST['sugar_body_only']) || !$_REQUEST['sugar_body_only'])) {
        global $app_strings;
        //this is not an ajax call and the user preference error flag is set, so reset the flag and print js to flash message
        $err_mess = $app_strings['ERROR_USER_PREFS'];
        $_SESSION['USER_PREFRENCE_ERRORS'] = false;
        echo "\n        <script>\n            ajaxStatus.flashStatus('{$err_mess}',7000);\n        </script>";
    }
    SugarAutoLoader::saveClassMap();
    if (class_exists('DBManagerFactory', false)) {
        DBManagerFactory::disconnectAll();
    }
    if ($exit) {
        exit;
    }
}
コード例 #19
0
ファイル: SugarApi.php プロジェクト: jglaine/sugar761-ent
 /**
  * Helper until we have dependency injection to grab a tracker manager
  * @return TrackerManager An instance of the tracker manager
  */
 public function getTrackerManager()
 {
     return TrackerManager::getInstance();
 }
コード例 #20
0
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     global $theme, $current_user;
     require_once 'include/formbase.php';
     global $timedate;
     $focus = new Contact();
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     if (!empty($_POST[$prefix . 'new_reports_to_id'])) {
         $focus->retrieve($_POST[$prefix . 'new_reports_to_id']);
         $focus->reports_to_id = $_POST[$prefix . 'record'];
     } else {
         $focus = populateFromPost($prefix, $focus);
         if (!empty($focus->portal_password) && $focus->portal_password != $_POST[$prefix . 'old_portal_password']) {
             $focus->portal_password = md5($focus->portal_password);
         }
         if (!isset($_POST[$prefix . 'email_opt_out'])) {
             $focus->email_opt_out = 0;
         }
         if (!isset($_POST[$prefix . 'do_not_call'])) {
             $focus->do_not_call = 0;
         }
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     if ($_REQUEST['action'] != 'BusinessCard' && $_REQUEST['action'] != 'ConvertLead' && $_REQUEST['action'] != 'ConvertProspect') {
         if (!empty($_POST[$prefix . 'sync_contact'])) {
             $focus->contacts_users_id = $current_user->id;
         } else {
             if (!isset($focus->users)) {
                 $focus->load_relationship('user_sync');
             }
             $focus->contacts_users_id = null;
             $focus->user_sync->delete($focus->id, $current_user->id);
         }
     }
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     } else {
         $check_notify = FALSE;
     }
     if (empty($_POST['dup_checked'])) {
         $duplicateContacts = $this->checkForDuplicates($prefix);
         if (isset($duplicateContacts)) {
             $location = 'module=Contacts&action=ShowDuplicates';
             $get = '';
             if (isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
                 $get .= '&inbound_email_id=' . $_POST['inbound_email_id'];
             }
             // Bug 25311 - Add special handling for when the form specifies many-to-many relationships
             if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) {
                 $get .= '&Contactsrelate_to=' . $_POST['relate_to'];
             }
             if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) {
                 $get .= '&Contactsrelate_id=' . $_POST['relate_id'];
             }
             //add all of the post fields to redirect get string
             foreach ($focus->column_fields as $field) {
                 if (!empty($focus->{$field}) && !is_object($focus->{$field})) {
                     $get .= "&Contacts{$field}=" . urlencode($focus->{$field});
                 }
             }
             foreach ($focus->additional_column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&Contacts{$field}=" . urlencode($focus->{$field});
                 }
             }
             if ($focus->hasCustomFields()) {
                 foreach ($focus->field_defs as $name => $field) {
                     if (!empty($field['source']) && $field['source'] == 'custom_fields') {
                         $get .= "&Contacts{$name}=" . urlencode($focus->{$name});
                     }
                 }
             }
             $emailAddress = new SugarEmailAddress();
             $get .= $emailAddress->getFormBaseURL($focus);
             //create list of suspected duplicate contact id's in redirect get string
             $i = 0;
             foreach ($duplicateContacts as $contact) {
                 $get .= "&duplicate[{$i}]=" . $contact['id'];
                 $i++;
             }
             //add return_module, return_action, and return_id to redirect get string
             $get .= "&return_module=";
             if (!empty($_POST['return_module'])) {
                 $get .= $_POST['return_module'];
             } else {
                 $get .= "Contacts";
             }
             $get .= "&return_action=";
             if (!empty($_POST['return_action'])) {
                 $get .= $_POST['return_action'];
             }
             //else $get .= "DetailView";
             if (!empty($_POST['return_id'])) {
                 $get .= "&return_id=" . $_POST['return_id'];
             }
             if (!empty($_POST['popup'])) {
                 $get .= '&popup=' . $_POST['popup'];
             }
             if (!empty($_POST['create'])) {
                 $get .= '&create=' . $_POST['create'];
             }
             // for InboundEmail flow
             if (!empty($_POST['start'])) {
                 $get .= '&start=' . $_POST['start'];
             }
             $_SESSION['SHOW_DUPLICATES'] = $get;
             //now redirect the post to modules/Contacts/ShowDuplicates.php
             if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
                 ob_clean();
                 $json = getJSONobj();
                 echo $json->encode(array('status' => 'dupe', 'get' => $location));
             } else {
                 if (!empty($_REQUEST['ajax_load'])) {
                     echo "<script>SUGAR.ajaxUI.loadContent('index.php?{$location}');</script>";
                 } else {
                     if (!empty($_POST['to_pdf'])) {
                         $location .= '&to_pdf=' . $_POST['to_pdf'];
                     }
                     header("Location: index.php?{$location}");
                 }
             }
             return null;
         }
     }
     global $current_user;
     if (is_admin($current_user)) {
         if (!isset($_POST[$prefix . 'portal_active'])) {
             $focus->portal_active = '0';
         }
         //if no password is set set account to inactive for portal
         if (empty($_POST[$prefix . 'portal_name'])) {
             $focus->portal_active = '0';
         }
     }
     ///////////////////////////////////////////////////////////////////////////////
     ////	INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     if (isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
         // fake this case like it's already saved.
         $focus->save($check_notify);
         $email = new Email();
         $email->retrieve($_REQUEST['inbound_email_id']);
         $email->parent_type = 'Contacts';
         $email->parent_id = $focus->id;
         $email->assigned_user_id = $current_user->id;
         $email->status = 'read';
         $email->save();
         $email->load_relationship('contacts');
         $email->contacts->add($focus->id);
         header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=" . $_REQUEST['inbound_email_id'] . "&parent_id=" . $email->parent_id . "&parent_type=" . $email->parent_type . '&start=' . $_REQUEST['start'] . '&assigned_user_id=' . $current_user->id);
         exit;
     }
     ////	END INBOUND EMAIL HANDLING
     ///////////////////////////////////////////////////////////////////////////////
     $focus->save($check_notify);
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
         $json = getJSONobj();
         echo $json->encode(array('status' => 'success', 'get' => ''));
         $trackerManager = TrackerManager::getInstance();
         $timeStamp = TimeDate::getInstance()->nowDb();
         if ($monitor = $trackerManager->getMonitor('tracker')) {
             $monitor->setValue('action', 'detailview');
             $monitor->setValue('user_id', $GLOBALS['current_user']->id);
             $monitor->setValue('module_name', 'Contacts');
             $monitor->setValue('date_modified', $timeStamp);
             $monitor->setValue('visible', 1);
             if (!empty($this->bean->id)) {
                 $monitor->setValue('item_id', $return_id);
                 $monitor->setValue('item_summary', $focus->get_summary_text());
             }
             $trackerManager->saveMonitor($monitor, true, true);
         }
         return null;
     }
     if (isset($_POST['popup']) && $_POST['popup'] == 'true') {
         $get = '&module=';
         if (!empty($_POST['return_module'])) {
             $get .= $_POST['return_module'];
         } else {
             $get .= 'Contacts';
         }
         $get .= '&action=';
         if (!empty($_POST['return_action'])) {
             $get .= $_POST['return_action'];
         } else {
             $get .= 'Popup';
         }
         if (!empty($_POST['return_id'])) {
             $get .= '&return_id=' . $_POST['return_id'];
         }
         if (!empty($_POST['popup'])) {
             $get .= '&popup=' . $_POST['popup'];
         }
         if (!empty($_POST['create'])) {
             $get .= '&create=' . $_POST['create'];
         }
         if (!empty($_POST['to_pdf'])) {
             $get .= '&to_pdf=' . $_POST['to_pdf'];
         }
         $get .= '&first_name=' . urlencode($focus->first_name);
         $get .= '&last_name=' . urlencode($focus->last_name);
         $get .= '&query=true';
         header("Location: index.php?{$get}");
         return;
     }
     if ($redirect) {
         $this->handleRedirect($return_id);
     } else {
         return $focus;
     }
 }
コード例 #21
0
ファイル: end.php プロジェクト: netconstructor/sugarcrm_dev
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
 * Reserved. Contributor(s): ______________________________________..
 * *******************************************************************************/
logThis('[At end.php]');
global $unzip_dir;
global $path;
global $sugar_config;
if ($unzip_dir == null) {
    $unzip_dir = $_SESSION['unzip_dir'];
}
//First repair the databse to ensure it is up to date with the new vardefs/tabledefs
logThis('About to repair the database.', $path);
//Use Repair and rebuild to update the database.
global $dictionary, $beanFiles;
require_once 'modules/Trackers/TrackerManager.php';
$trackerManager = TrackerManager::getInstance();
$trackerManager->pause();
$trackerManager->unsetMonitors();
require_once "modules/Administration/QuickRepairAndRebuild.php";
$rac = new RepairAndClear();
$rac->clearVardefs();
$rac->rebuildExtensions();
//bug: 44431 - defensive check to ensure the method exists since upgrades to 6.2.0 may not have this method define yet.
if (method_exists($rac, 'clearExternalAPICache')) {
    $rac->clearExternalAPICache();
}
$repairedTables = array();
foreach ($beanFiles as $bean => $file) {
    if (file_exists($file)) {
        require_once $file;
        unset($GLOBALS['dictionary'][$bean]);
コード例 #22
0
 function handleSave($prefix, $redirect = true, $useRequired = false)
 {
     require_once 'include/formbase.php';
     $focus = BeanFactory::getBean('Accounts');
     if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
         return null;
     }
     $focus = populateFromPost($prefix, $focus);
     if (isset($GLOBALS['check_notify'])) {
         $check_notify = $GLOBALS['check_notify'];
     } else {
         $check_notify = FALSE;
     }
     if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
         $duplicateAccounts = $this->checkForDuplicates($prefix);
         if (isset($duplicateAccounts)) {
             $location = 'module=Accounts&action=ShowDuplicates';
             $get = '';
             // Bug 25311 - Add special handling for when the form specifies many-to-many relationships
             if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) {
                 $get .= '&Accountsrelate_to=' . $_POST['relate_to'];
             }
             if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) {
                 $get .= '&Accountsrelate_id=' . $_POST['relate_id'];
             }
             //add all of the post fields to redirect get string
             foreach ($focus->column_fields as $field) {
                 if (!empty($focus->{$field}) && !is_object($focus->{$field})) {
                     $get .= "&Accounts{$field}=" . urlencode($focus->{$field});
                 }
             }
             foreach ($focus->additional_column_fields as $field) {
                 if (!empty($focus->{$field})) {
                     $get .= "&Accounts{$field}=" . urlencode($focus->{$field});
                 }
             }
             if ($focus->hasCustomFields()) {
                 foreach ($focus->field_defs as $name => $field) {
                     if (!empty($field['source']) && $field['source'] == 'custom_fields') {
                         $get .= "&Accounts{$name}=" . urlencode($focus->{$name});
                     }
                 }
             }
             $emailAddress = BeanFactory::getBean('EmailAddresses');
             $get .= $emailAddress->getFormBaseURL($focus);
             $get .= get_teams_url('Accounts');
             //create list of suspected duplicate account id's in redirect get string
             $i = 0;
             foreach ($duplicateAccounts as $account) {
                 $get .= "&duplicate[{$i}]=" . $account['id'];
                 $i++;
             }
             //add return_module, return_action, and return_id to redirect get string
             $urlData = array('return_module' => 'Accounts', 'return_action' => '');
             foreach (array('return_module', 'return_action', 'return_id', 'popup', 'create') as $var) {
                 if (!empty($_POST[$var])) {
                     $urlData[$var] = $_POST[$var];
                 }
             }
             $get .= "&" . http_build_query($urlData);
             $_SESSION['SHOW_DUPLICATES'] = $get;
             if (!empty($_POST['to_pdf'])) {
                 $location .= '&to_pdf=' . urlencode($_POST['to_pdf']);
             }
             header("Location: index.php?{$location}");
         }
     }
     if (!$focus->ACLAccess('Save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
     }
     $focus->save($check_notify);
     $return_id = $focus->id;
     $GLOBALS['log']->debug("Saved record with id of " . $return_id);
     if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
         $json = getJSONobj();
         echo $json->encode(array('status' => 'success', 'get' => ''));
         $trackerManager = TrackerManager::getInstance();
         $timeStamp = TimeDate::getInstance()->nowDb();
         if ($monitor = $trackerManager->getMonitor('tracker')) {
             $monitor->setValue('team_id', $GLOBALS['current_user']->getPrivateTeamID());
             $monitor->setValue('action', 'detailview');
             $monitor->setValue('user_id', $GLOBALS['current_user']->id);
             $monitor->setValue('module_name', 'Accounts');
             $monitor->setValue('date_modified', $timeStamp);
             $monitor->setValue('visible', 1);
             if (!empty($this->bean->id)) {
                 $monitor->setValue('item_id', $return_id);
                 $monitor->setValue('item_summary', $focus->get_summary_text());
             }
             $trackerManager->saveMonitor($monitor, true, true);
         }
         return null;
     }
     if (isset($_POST['popup']) && $_POST['popup'] == 'true') {
         $urlData = array("query" => true, "name" => $focus->name, "module" => 'Accounts', 'action' => 'Popup');
         if (!empty($_POST['return_module'])) {
             $urlData['module'] = $_POST['return_module'];
         }
         if (!empty($_POST['return_action'])) {
             $urlData['action'] = $_POST['return_action'];
         }
         foreach (array('return_id', 'popup', 'create', 'to_pdf') as $var) {
             if (!empty($_POST[$var])) {
                 $urlData[$var] = $_POST[$var];
             }
         }
         header("Location: index.php?" . http_build_query($urlData));
         return;
     }
     if ($redirect) {
         handleRedirect($return_id, 'Accounts');
     } else {
         return $focus;
     }
 }