Пример #1
0
 /**
  * Gets the default Portal settings.
  *
  * @return array the array containing default Portal settings.
  */
 private function getDefaultPortalSettings()
 {
     $portalConfig = array('platform' => 'portal', 'debugSugarApi' => true, 'logLevel' => 'ERROR', 'logWriter' => 'ConsoleWriter', 'logFormatter' => 'SimpleFormatter', 'metadataTypes' => array(), 'defaultModule' => 'Cases', 'orderByDefaults' => array('Cases' => array('field' => 'case_number', 'direction' => 'desc'), 'Bugs' => array('field' => 'bug_number', 'direction' => 'desc'), 'Notes' => array('field' => 'date_modified', 'direction' => 'desc'), 'KBDocuments' => array('field' => 'date_modified', 'direction' => 'desc')));
     if (inDeveloperMode()) {
         $portalConfig['logLevel'] = 'DEBUG';
     }
     return $portalConfig;
 }
Пример #2
0
 /**
  * Load a dictionary for a particular api
  * @internal
  * @param string $apiType The api type for the dictionary you want to load ("Rest" or "Soap")
  * @return array The data stored in saveDictionaryToStorage()
  */
 protected function loadDictionaryFromStorage($apiType)
 {
     $dictFile = $this->cacheDir . 'ServiceDictionary.' . $apiType . '.php';
     if (!file_exists($dictFile) || inDeveloperMode()) {
         // No stored service dictionary, I need to build them
         $this->buildAllDictionaries();
     }
     require $dictFile;
     return $apiDictionary[$apiType];
 }
Пример #3
0
 /**
  * Called from VardefManager to allow for caching a lang file for a module
  * @param module - the name of the module we are working with
  * @param templates - an array of templates this module uses
  */
 public static function createLanguageFile($module, $templates = array('default'), $refresh = false)
 {
     global $mod_strings, $current_language;
     if (inDeveloperMode() || !empty($_SESSION['developerMode'])) {
         $refresh = true;
     }
     $temp_mod_strings = $mod_strings;
     $lang = $current_language;
     if (empty($lang)) {
         $lang = $GLOBALS['sugar_config']['default_language'];
     }
     if (empty(self::$createdModules[$module]) && ($refresh || !file_exists(sugar_cached('modules/') . $module . '/language/' . $lang . '.lang.php'))) {
         $loaded_mod_strings = array();
         $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module, $templates, $lang, $loaded_mod_strings);
         self::$createdModules[$module] = true;
         LanguageManager::refreshLanguage($module, $lang, $loaded_mod_strings);
     }
 }
Пример #4
0
 public function setup()
 {
     $themedef = array();
     include 'themes/' . SugarTestThemeUtilities::createAnonymousTheme() . '/themedef.php';
     $this->_themeDef = $themedef;
     SugarThemeRegistry::add($this->_themeDef);
     $this->_themeObject = SugarThemeRegistry::get($this->_themeDef['dirName']);
     $themedef = array();
     include 'themes/' . SugarTestThemeUtilities::createAnonymousChildTheme($this->_themeObject->__toString()) . '/themedef.php';
     $this->_themeDefChild = $themedef;
     SugarThemeRegistry::add($this->_themeDefChild);
     $this->_themeObjectChild = SugarThemeRegistry::get($this->_themeDefChild['dirName']);
     // test assumes developerMode is off, so css minifying happens
     if (inDeveloperMode()) {
         $this->_olddeveloperMode = $GLOBALS['sugar_config']['developerMode'];
     }
     $GLOBALS['sugar_config']['developerMode'] = false;
 }
Пример #5
0
 protected function jsParser()
 {
     if (inDeveloperMode()) {
         return $this->text;
     }
     //If the JSMIn extension is loaded, use that as it can be as much as 1000x faster than JShrink
     if (extension_loaded("jsmin")) {
         return @jsmin($this->text);
     }
     if (!empty($GLOBALS['sugar_config']['uglify'])) {
         $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"));
         $process = proc_open($GLOBALS['sugar_config']['uglify'], $descriptorspec, $pipes);
         if (is_resource($process)) {
             fwrite($pipes[0], $this->text);
             fclose($pipes[0]);
             $out = stream_get_contents($pipes[1]);
             fclose($pipes[1]);
             proc_close($process);
             return $out;
         }
     }
     require_once 'jssource/Minifier.php';
     return JShrink\Minifier::minify($this->text);
 }
Пример #6
0
 /**
  * This method checks to see if the configuration file exists and, if not, creates one by default
  *
  */
 public function preDisplay()
 {
     global $app_strings;
     //Rebuild config file if it doesn't exist
     if (!file_exists($this->configFile)) {
         ModuleInstaller::handleBaseConfig();
     }
     $this->ss->assign("configFile", $this->configFile);
     $config = ModuleInstaller::getBaseConfig();
     $this->ss->assign('configHash', md5(serialize($config)));
     $sugarSidecarPath = ensureJSCacheFilesExist();
     $this->ss->assign("sugarSidecarPath", $sugarSidecarPath);
     // TODO: come up with a better way to deal with the various JS files
     // littered in sidecar.tpl.
     $voodooFile = 'custom/include/javascript/voodoo.js';
     if (SugarAutoLoader::fileExists($voodooFile)) {
         $this->ss->assign('voodooFile', $voodooFile);
     }
     //Load sidecar theme css
     $theme = new SidecarTheme();
     $this->ss->assign("css_url", $theme->getCSSURL());
     $this->ss->assign("developerMode", inDeveloperMode());
     //Loading label
     $this->ss->assign('LBL_LOADING', $app_strings['LBL_ALERT_TITLE_LOADING']);
     $this->ss->assign('LBL_ENABLE_JAVASCRIPT', $app_strings['LBL_ENABLE_JAVASCRIPT']);
     $slFunctionsPath = inDeveloperMode() ? "cache/Expressions/functions_cache_debug.js" : "cache/Expressions/functions_cache.js";
     if (!is_file($slFunctionsPath)) {
         $GLOBALS['updateSilent'] = true;
         include "include/Expressions/updatecache.php";
     }
     $this->ss->assign("SLFunctionsPath", $slFunctionsPath);
     if (!empty($this->authorization)) {
         $this->ss->assign('appPrefix', $config['env'] . ":" . $config['appId'] . ":");
         $this->ss->assign('authorization', $this->authorization);
     }
 }
Пример #7
0
 /**
  * Checks for database not being connected
  *
  * @param  string $msg        message to prepend to the error message
  * @param  bool   $dieOnError true if we want to die immediately on error
  * @return bool
  */
 public function checkError($msg = '', $dieOnError = false)
 {
     $userMsg = inDeveloperMode() ? "{$msg}: " : "";
     if (!isset($this->database)) {
         $GLOBALS['log']->error("Database Is Not Connected");
         if ($this->dieOnError || $dieOnError) {
             sugar_die($userMsg . "Database Is Not Connected");
         } else {
             $this->last_error = $userMsg . "Database Is Not Connected";
         }
         return true;
     }
     return false;
 }
Пример #8
0
function getModuleField($module, $fieldname, $aow_field, $view = 'EditView', $value = '', $alt_type = '')
{
    global $current_language, $app_strings, $app_list_strings, $current_user, $beanFiles, $beanList;
    // use the mod_strings for this module
    $mod_strings = return_module_language($current_language, $module);
    // set the filename for this control
    $file = create_cache_directory('modules/AOW_WorkFlow/') . $module . $view . $alt_type . $fieldname . '.tpl';
    if (!is_file($file) || inDeveloperMode() || !empty($_SESSION['developerMode'])) {
        if (!isset($vardef)) {
            require_once $beanFiles[$beanList[$module]];
            $focus = new $beanList[$module]();
            $vardef = $focus->getFieldDefinition($fieldname);
        }
        $displayParams = array();
        //$displayParams['formName'] = 'EditView';
        // if this is the id relation field, then don't have a pop-up selector.
        if ($vardef['type'] == 'relate' && $vardef['id_name'] == $vardef['name']) {
            $vardef['type'] = 'varchar';
        }
        if (isset($vardef['precision'])) {
            unset($vardef['precision']);
        }
        //$vardef['precision'] = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user);
        //TODO Fix datetimecomebo
        //temp work around
        if ($vardef['type'] == 'datetimecombo') {
            $vardef['type'] = 'datetime';
        }
        // trim down textbox display
        if ($vardef['type'] == 'text') {
            $vardef['rows'] = 2;
            $vardef['cols'] = 32;
        }
        // create the dropdowns for the parent type fields
        if ($vardef['type'] == 'parent_type') {
            $vardef['type'] = 'enum';
        }
        if ($vardef['type'] == 'link') {
            $vardef['type'] = 'relate';
            $vardef['rname'] = 'name';
            $vardef['id_name'] = $vardef['name'] . '_id';
            if ((!isset($vardef['module']) || $vardef['module'] == '') && $focus->load_relationship($vardef['name'])) {
                $vardef['module'] = $focus->{$vardef}['name']->getRelatedModuleName();
            }
        }
        //check for $alt_type
        if ($alt_type != '') {
            $vardef['type'] = $alt_type;
        }
        // remove the special text entry field function 'getEmailAddressWidget'
        if (isset($vardef['function']) && ($vardef['function'] == 'getEmailAddressWidget' || $vardef['function']['name'] == 'getEmailAddressWidget')) {
            unset($vardef['function']);
        }
        if (isset($vardef['name']) && ($vardef['name'] == 'date_entered' || $vardef['name'] == 'date_modified')) {
            $vardef['name'] = 'aow_temp_date';
        }
        // load SugarFieldHandler to render the field tpl file
        static $sfh;
        if (!isset($sfh)) {
            require_once 'include/SugarFields/SugarFieldHandler.php';
            $sfh = new SugarFieldHandler();
        }
        $contents = $sfh->displaySmarty('fields', $vardef, $view, $displayParams);
        // Remove all the copyright comments
        $contents = preg_replace('/\\{\\*[^\\}]*?\\*\\}/', '', $contents);
        if ($view == 'EditView' && ($vardef['type'] == 'relate' || $vardef['type'] == 'parent')) {
            $contents = str_replace('"' . $vardef['id_name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.id_name}"{literal}', $contents);
            $contents = str_replace('"' . $vardef['name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.name}"{literal}', $contents);
        }
        // hack to disable one of the js calls in this control
        if (isset($vardef['function']) && ($vardef['function'] == 'getCurrencyDropDown' || $vardef['function']['name'] == 'getCurrencyDropDown')) {
            $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}";
        }
        // Save it to the cache file
        if ($fh = @sugar_fopen($file, 'w')) {
            fputs($fh, $contents);
            fclose($fh);
        }
    }
    // Now render the template we received
    $ss = new Sugar_Smarty();
    // Create Smarty variables for the Calendar picker widget
    global $timedate;
    $time_format = $timedate->get_user_time_format();
    $date_format = $timedate->get_cal_date_format();
    $ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
    $ss->assign('TIME_FORMAT', $time_format);
    $time_separator = ":";
    $match = array();
    if (preg_match('/\\d+([^\\d])\\d+([^\\d]*)/s', $time_format, $match)) {
        $time_separator = $match[1];
    }
    $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
    if (!isset($match[2]) || $match[2] == '') {
        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M");
    } else {
        $pm = $match[2] == "pm" ? "%P" : "%p";
        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm);
    }
    $ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week());
    // populate the fieldlist from the vardefs
    $fieldlist = array();
    if (!isset($focus) || !$focus instanceof SugarBean) {
        require_once $beanFiles[$beanList[$module]];
    }
    $focus = new $beanList[$module]();
    // create the dropdowns for the parent type fields
    if (isset($vardef['type']) && $vardef['type'] == 'parent_type') {
        $focus->field_defs[$vardef['name']]['options'] = $focus->field_defs[$vardef['group']]['options'];
    }
    $vardefFields = $focus->getFieldDefinitions();
    foreach ($vardefFields as $name => $properties) {
        $fieldlist[$name] = $properties;
        // fill in enums
        if (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']])) {
            $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']];
        } elseif (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']])) {
            $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']];
        }
        // Bug 22730: make sure all enums have the ability to select blank as the default value.
        if (!isset($fieldlist[$name]['options'][''])) {
            $fieldlist[$name]['options'][''] = '';
        }
    }
    // fill in function return values
    if (!in_array($fieldname, array('email1', 'email2'))) {
        if (!empty($fieldlist[$fieldname]['function']['returns']) && $fieldlist[$fieldname]['function']['returns'] == 'html') {
            $function = $fieldlist[$fieldname]['function']['name'];
            // include various functions required in the various vardefs
            if (isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include'])) {
                require_once $fieldlist[$fieldname]['function']['include'];
            }
            $_REQUEST[$fieldname] = $value;
            $value = $function($focus, $fieldname, $value, $view);
            $value = str_ireplace($fieldname, $aow_field, $value);
        }
    }
    if ($fieldlist[$fieldname]['type'] == 'link') {
        $fieldlist[$fieldname]['id_name'] = $fieldlist[$fieldname]['name'] . '_id';
        if ((!isset($fieldlist[$fieldname]['module']) || $fieldlist[$fieldname]['module'] == '') && $focus->load_relationship($fieldlist[$fieldname]['name'])) {
            $fieldlist[$fieldname]['module'] = $focus->{$fieldlist}[$fieldname]['name']->getRelatedModuleName();
        }
    }
    if (isset($fieldlist[$fieldname]['name']) && ($fieldlist[$fieldname]['name'] == 'date_entered' || $fieldlist[$fieldname]['name'] == 'date_modified')) {
        $fieldlist[$fieldname]['name'] = 'aow_temp_date';
        $fieldlist['aow_temp_date'] = $fieldlist[$fieldname];
        $fieldname = 'aow_temp_date';
    }
    if (isset($fieldlist[$fieldname]['id_name']) && $fieldlist[$fieldname]['id_name'] != '' && $fieldlist[$fieldname]['id_name'] != $fieldlist[$fieldname]['name']) {
        $rel_value = $value;
        if (isset($fieldlist[$fieldname]['module']) && $fieldlist[$fieldname]['module'] == 'Users') {
            $rel_value = get_assigned_user_name($value);
        } else {
            if (isset($fieldlist[$fieldname]['module'])) {
                require_once $beanFiles[$beanList[$fieldlist[$fieldname]['module']]];
                $rel_focus = new $beanList[$fieldlist[$fieldname]['module']]();
                $rel_focus->retrieve($value);
                if (isset($fieldlist[$fieldname]['rname']) && $fieldlist[$fieldname]['rname'] != '') {
                    $rel_value = $rel_focus->{$fieldlist}[$fieldname]['rname'];
                } else {
                    $rel_value = $rel_focus->name;
                }
            }
        }
        $fieldlist[$fieldlist[$fieldname]['id_name']]['value'] = $value;
        $fieldlist[$fieldname]['value'] = $rel_value;
        $fieldlist[$fieldname]['id_name'] = $aow_field;
        $fieldlist[$fieldlist[$fieldname]['id_name']]['name'] = $aow_field;
        $fieldlist[$fieldname]['name'] = $aow_field . '_display';
    } else {
        if (isset($fieldlist[$fieldname]['type']) && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime' || $fieldlist[$fieldname]['type'] == 'date')) {
            $fieldlist[$fieldname]['value'] = $timedate->to_display_date($value);
            //$fieldlist[$fieldname]['value'] = $timedate->to_display_date_time($value, true, true);
            //$fieldlist[$fieldname]['value'] = $value;
            $fieldlist[$fieldname]['name'] = $aow_field;
        } else {
            $fieldlist[$fieldname]['value'] = $value;
            $fieldlist[$fieldname]['name'] = $aow_field;
        }
    }
    $ss->assign("fields", $fieldlist);
    $ss->assign("form_name", $view);
    $ss->assign("bean", $focus);
    // add in any additional strings
    $ss->assign("MOD", $mod_strings);
    $ss->assign("APP", $app_strings);
    //$return = str_replace($fieldname,$ss->fetch($file));
    return $ss->fetch($file);
}
 function checkTemplate($cacheRowFile)
 {
     if (inDeveloperMode() || !empty($_SESSION['developerMode'])) {
         return false;
     }
     return file_exists($cacheRowFile);
 }
Пример #10
0
 /**
  * Returns the URL for an image in the current theme. If not found in the current theme, will revert
  * to looking in the base theme.
  *
  * @param  string $jsFileName js file name
  * @param  bool   $returnURL if true, returns URL with unique image mark, otherwise returns path to the file
  * @return string path to js file
  */
 public function getJSURL($jsFileName, $returnURL = true)
 {
     if (isset($this->_jsCache[$jsFileName]) && sugar_is_file(sugar_cached($this->_jsCache[$jsFileName]))) {
         if ($returnURL) {
             return getJSPath("cache/" . $this->_jsCache[$jsFileName]);
         } else {
             return sugar_cached($this->_jsCache[$jsFileName]);
         }
     }
     $jsFileContents = '';
     $fullFileName = $this->getJSPath() . '/' . $jsFileName;
     $defaultFileName = $this->getDefaultJSPath() . '/' . $jsFileName;
     if (isset($this->parentTheme) && SugarThemeRegistry::get($this->parentTheme) instanceof SugarTheme && ($filename = SugarThemeRegistry::get($this->parentTheme)->getJSURL($jsFileName, false)) != '' && !in_array($jsFileName, $this->ignoreParentFiles)) {
         $jsFileContents .= file_get_contents($filename);
     } else {
         if (sugar_is_file($defaultFileName)) {
             $jsFileContents .= file_get_contents($defaultFileName);
         }
         if (sugar_is_file('custom/' . $defaultFileName)) {
             $jsFileContents .= file_get_contents('custom/' . $defaultFileName);
         }
     }
     if (sugar_is_file($fullFileName)) {
         $jsFileContents .= file_get_contents($fullFileName);
     }
     if (sugar_is_file('custom/' . $fullFileName)) {
         $jsFileContents .= file_get_contents('custom/' . $fullFileName);
     }
     if (empty($jsFileContents)) {
         $GLOBALS['log']->warn("Javascript File {$jsFileName} not found");
         return false;
     }
     // create the cached file location
     $jsFilePath = create_cache_directory($fullFileName);
     // minify the js
     if (!inDeveloperMode() && !sugar_is_file(str_replace('.js', '-min.js', $jsFilePath))) {
         $jsFileContents = SugarMin::minify($jsFileContents);
         $jsFilePath = str_replace('.js', '-min.js', $jsFilePath);
         $fullFileName = str_replace('.js', '-min.js', $fullFileName);
     }
     // now write the js to cache
     sugar_file_put_contents($jsFilePath, $jsFileContents);
     $this->_jsCache[$jsFileName] = $fullFileName;
     if ($returnURL) {
         return getJSPath("cache/" . $fullFileName);
     }
     return sugar_cached($fullFileName);
 }
Пример #11
0
 /**
  * Checks if a template exists
  *
  * @param module string module name
  * @param view string view need (eg DetailView, EditView, etc)
  */
 function checkTemplate($module, $view, $checkFormName = false, $formName = '')
 {
     if (inDeveloperMode() || !empty($_SESSION['developerMode'])) {
         return false;
     }
     $view = $checkFormName ? $formName : $view;
     return file_exists($this->cacheDir . $this->templateDir . $module . '/' . $view . '.tpl');
 }
Пример #12
0
 /**
  * Get the list of available APIs
  * @param bool $forceRebuild
  * @param bool $ignoreDisabled Should we ignore disabled status?
  * @return array
  */
 public static function loadFullAPIList($forceRebuild = false, $ignoreDisabled = false)
 {
     if (inDeveloperMode()) {
         static $beenHereBefore = false;
         if (!$beenHereBefore) {
             $forceRebuild = true;
             $beenHereBefore = true;
         }
     }
     $cached = sugar_cached('include/externalAPI.cache.php');
     if (!$forceRebuild && file_exists($cached)) {
         // Already have a cache file built, no need to rebuild
         require $cached;
         return $ignoreDisabled ? $fullAPIList : self::filterAPIList($fullAPIList);
     }
     $apiFullList = array();
     $meetingPasswordList = array();
     $needUrlList = array();
     $baseDirList = array('include/externalAPI/', 'custom/include/externalAPI/');
     foreach ($baseDirList as $baseDir) {
         $dirList = glob($baseDir . '*', GLOB_ONLYDIR);
         foreach ($dirList as $dir) {
             if ($dir == $baseDir . '.' || $dir == $baseDir . '..' || $dir == $baseDir . 'Base') {
                 continue;
             }
             $apiName = str_replace($baseDir, '', $dir);
             if (file_exists($dir . '/ExtAPI' . $apiName . '.php')) {
                 $apiFullList[$apiName]['className'] = 'ExtAPI' . $apiName;
                 $apiFullList[$apiName]['file'] = $dir . '/' . $apiFullList[$apiName]['className'] . '.php';
             }
             if (file_exists($dir . '/ExtAPI' . $apiName . '_cstm.php')) {
                 $apiFullList[$apiName]['className'] = 'ExtAPI' . $apiName . '_cstm';
                 $apiFullList[$apiName]['file_cstm'] = $dir . '/' . $apiFullList[$apiName]['className'] . '.php';
             }
         }
     }
     $optionList = array('supportedModules', 'useAuth', 'requireAuth', 'supportMeetingPassword', 'docSearch', 'authMethod', 'oauthFixed', 'needsUrl', 'canInvite', 'sendsInvites', 'sharingOptions', 'connector', 'oauthParams', 'restrictUploadsByExtension');
     foreach ($apiFullList as $apiName => $apiOpts) {
         require_once $apiOpts['file'];
         if (!empty($apiOpts['file_cstm'])) {
             require_once $apiOpts['file_cstm'];
         }
         $className = $apiOpts['className'];
         $apiClass = new $className();
         foreach ($optionList as $opt) {
             if (isset($apiClass->{$opt})) {
                 $apiFullList[$apiName][$opt] = $apiClass->{$opt};
             }
         }
         // Special handling for the show/hide of the Meeting Password field, we need to create a dropdown for the Sugar Logic code.
         if (isset($apiClass->supportMeetingPassword) && $apiClass->supportMeetingPassword == true) {
             $meetingPasswordList[$apiName] = $apiName;
         }
     }
     create_cache_directory('/include/');
     $cached_tmp = sugar_cached('include/externalAPI.cache-tmp.php');
     $fd = fopen($cached_tmp, 'w');
     fwrite($fd, "<" . "?php\n//This file is auto generated by " . basename(__FILE__) . "\n\$fullAPIList = " . var_export($apiFullList, true) . ";\n\n");
     fclose($fd);
     rename($cached_tmp, $cached);
     $fd = fopen(sugar_cached('include/externalAPI.cache-tmp.js'), 'w');
     fwrite($fd, "//This file is auto generated by " . basename(__FILE__) . "\nSUGAR.eapm = " . json_encode($apiFullList) . ";\n\n");
     fclose($fd);
     rename(sugar_cached('include/externalAPI.cache-tmp.js'), sugar_cached('include/externalAPI.cache.js'));
     if (!isset($GLOBALS['app_list_strings']['extapi_meeting_password']) || is_array($GLOBALS['app_list_strings']['extapi_meeting_password']) && count(array_diff($meetingPasswordList, $GLOBALS['app_list_strings']['extapi_meeting_password'])) != 0) {
         // Our meeting password list is different... we need to do something about this.
         require_once 'modules/Administration/Common.php';
         $languages = get_languages();
         foreach ($languages as $lang => $langLabel) {
             $contents = return_custom_app_list_strings_file_contents($lang);
             $new_contents = replace_or_add_dropdown_type('extapi_meeting_password', $meetingPasswordList, $contents);
             save_custom_app_list_strings_contents($new_contents, $lang);
         }
     }
     return $ignoreDisabled ? $apiFullList : self::filterAPIList($apiFullList);
 }
Пример #13
0
/**
 * Getting backtrace information for called function
 * @param $function
 * @return bool | array
 */
function getBacktraceData($function)
{
    if (inDeveloperMode()) {
        $backtrace = debug_backtrace();
        foreach ($backtrace as $backtraceItem) {
            if ($backtraceItem['function'] == $function) {
                return $backtraceItem;
            }
        }
    }
    return false;
}
Пример #14
0
    /**
     * Called from process(). This method will display the correct javascript.
     */
    protected function _displayJavascript()
    {
        global $locale, $sugar_config, $timedate;
        if ($this->_getOption('show_javascript')) {
            if (!$this->_getOption('show_header')) {
                $langHeader = get_language_header();
                echo <<<EOHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html {$langHeader}>
<head>
EOHTML;
            }
            $js_vars = array("sugar_cache_dir" => "cache/");
            if (isset($this->bean->module_dir)) {
                $js_vars['module_sugar_grp1'] = $this->bean->module_dir;
            }
            if (isset($_REQUEST['action'])) {
                $js_vars['action_sugar_grp1'] = $_REQUEST['action'];
            }
            echo '<script>jscal_today = 1000*' . $timedate->asUserTs($timedate->getNow()) . '; if(typeof app_strings == "undefined") app_strings = new Array();</script>';
            // Make sure the necessary cache files are in place
            $jsFiles = array("sugar_grp1.js", "sugar_grp1_yui.js", "sugar_grp1_jquery.js");
            ensureJSCacheFilesExist($jsFiles);
            echo getVersionedScript('cache/include/javascript/sugar_grp1_jquery.js');
            echo getVersionedScript('cache/include/javascript/sugar_grp1_yui.js');
            echo getVersionedScript('cache/include/javascript/sugar_grp1.js');
            $version_mark = getVersionedPath(null);
            echo '<script>SUGAR = SUGAR || {}; SUGAR.VERSION_MARK = ' . json_encode($version_mark) . ';</script>';
            // output necessary config js in the top of the page
            $config_js = $this->getSugarConfigJS();
            if (!empty($config_js)) {
                echo "<script>\n" . implode("\n", $config_js) . "</script>\n";
            }
            // CSRF form token
            echo $this->getCsrfFormTokenJscript();
            if (isset($sugar_config['email_sugarclient_listviewmaxselect'])) {
                echo "<script>SUGAR.config.email_sugarclient_listviewmaxselect = {$GLOBALS['sugar_config']['email_sugarclient_listviewmaxselect']};</script>";
            }
            $image_server = defined('TEMPLATE_URL') ? TEMPLATE_URL . '/' : '';
            echo '<script type="text/javascript">SUGAR.themes.image_server="' . $image_server . '";</script>';
            // cn: bug 12274 - create session-stored key to defend against CSRF
            echo '<script type="text/javascript">var name_format = "' . $locale->getLocaleFormatMacro() . '";</script>';
            echo self::getJavascriptValidation();
            if (!is_file(sugar_cached('jsLanguage/') . $GLOBALS['current_language'] . '.js')) {
                require_once 'include/language/jsLanguage.php';
                jsLanguage::createAppStringsCache($GLOBALS['current_language']);
            }
            echo getVersionedScript('cache/jsLanguage/' . $GLOBALS['current_language'] . '.js', $GLOBALS['sugar_config']['js_lang_version']);
            echo $this->_getModLanguageJS();
            echo getVersionedScript('include/javascript/productTour.js');
            if (isset($sugar_config['disc_client']) && $sugar_config['disc_client']) {
                echo getVersionedScript('modules/Sync/headersync.js');
            }
            if (!is_file(sugar_cached("Expressions/functions_cache.js"))) {
                $GLOBALS['updateSilent'] = true;
                include "include/Expressions/updatecache.php";
            }
            if (inDeveloperMode()) {
                echo getVersionedScript('cache/Expressions/functions_cache_debug.js');
            } else {
                echo getVersionedScript('cache/Expressions/functions_cache.js');
            }
            require_once "include/Expressions/DependencyManager.php";
            echo "\n" . '<script type="text/javascript">' . DependencyManager::getJSUserVariables($GLOBALS['current_user']) . "</script>\n";
            //echo out the $js_vars variables as javascript variables
            echo "<script type='text/javascript'>\n";
            foreach ($js_vars as $var => $value) {
                echo "var {$var} = '{$value}';\n";
            }
            echo "</script>\n";
        }
    }
Пример #15
0
 /**
  * getConnectors
  * Returns an Array of the connectors that have been loaded into the system
  * along with attributes pertaining to each connector.
  *
  * @param boolean $refresh boolean flag indicating whether or not to force rewriting the file; defaults to false
  * @returns mixed $connectors Array of the connector entries found
  */
 public static function getConnectors($refresh = false)
 {
     if (inDeveloperMode()) {
         $refresh = true;
     }
     if (!empty(self::$connectors_cache) && !$refresh) {
         return self::$connectors_cache;
     }
     //define paths
     $src1 = 'modules/Connectors/connectors/sources';
     $src2 = 'custom/modules/Connectors/connectors/sources';
     $src3 = 'custom/modules/Connectors/metadata';
     $src4 = 'custom/modules/Connectors/metadata/connectors.php';
     $connectors = array();
     if ($refresh || !SugarAutoLoader::existing($src4)) {
         $sources = array_merge(self::getSources($src1), self::getSources($src2));
         if (!file_exists($src3)) {
             mkdir_recursive($src3);
         }
         if (file_exists($src4)) {
             require $src4;
             //define connectors if it doesn't exist or is not an array
             if (!isset($connectors) || !is_array($connectors)) {
                 $err_str = string_format($GLOBALS['app_strings']['ERR_CONNECTOR_NOT_ARRAY'], array($src4));
                 $GLOBALS['log']->error($err_str);
             }
             $sources = array_merge($sources, $connectors);
         }
         if (!self::saveConnectors($sources, $src4)) {
             return array();
         }
     }
     //if
     require $src4;
     self::$connectors_cache = $connectors;
     return $connectors;
 }
Пример #16
0
 /**
  * getConnectors
  * Returns an Array of the connectors that have been loaded into the system
  * along with attributes pertaining to each connector.
  *
  * @param boolean $refresh boolean flag indicating whether or not to force rewriting the file; defaults to false
  * @returns mixed $connectors Array of the connector entries found
  */
 public static function getConnectors($refresh = false)
 {
     if (inDeveloperMode()) {
         $refresh = true;
     }
     if (!empty(self::$connectors_cache) && !$refresh) {
         return self::$connectors_cache;
     }
     //define paths
     $src1 = 'modules/Connectors/connectors/sources';
     $src2 = 'custom/modules/Connectors/connectors/sources';
     $src3 = 'custom/modules/Connectors/metadata';
     $src4 = 'custom/modules/Connectors/metadata/connectors.php';
     //if this is a templated environment, then use utilities to get the proper paths
     if (defined('TEMPLATE_URL')) {
         $src1 = SugarTemplateUtilities::getFilePath($src1);
         $src2 = SugarTemplateUtilities::getFilePath($src2);
         $src3 = SugarTemplateUtilities::getFilePath($src3);
         $src4 = SugarTemplateUtilities::getFilePath($src4);
     }
     if ($refresh || !file_exists($src4)) {
         $sources = array_merge(self::getSources($src1), self::getSources($src2));
         if (!file_exists($src3)) {
             mkdir_recursive($src3);
         }
         if (file_exists($src4)) {
             require $src4;
             //define connectors if it doesn't exist or is not an array
             if (!isset($connectors) || !is_array($connectors)) {
                 $connectors = array();
                 $err_str = string_format($GLOBALS['app_strings']['ERR_CONNECTOR_NOT_ARRAY'], array($src4));
                 $GLOBALS['log']->error($err_str);
             }
             $sources = array_merge($sources, $connectors);
         }
         if (!self::saveConnectors($sources, $src4)) {
             return array();
         }
     }
     //if
     require $src4;
     self::$connectors_cache = $connectors;
     return $connectors;
 }
Пример #17
0
 /**
  * Builds the javascript file used by the clients
  *
  * @param array $data The metadata to build from
  * @param boolean $onlyReturnModuleComponents Indicator to return only module
  *                                            components
  * @return string A url to the file that was just built
  */
 protected function buildJavascriptComponentFile(&$data, $onlyReturnModuleComponents = false)
 {
     $platform = $this->platforms[0];
     $js = "(function(app) {\n SUGAR.jssource = {";
     $compJS = $this->buildJavascriptComponentSection($data);
     if (!$onlyReturnModuleComponents) {
         $js .= $compJS;
     }
     if (!empty($data['modules'])) {
         if (!empty($compJS) && !$onlyReturnModuleComponents) {
             $js .= ",";
         }
         $js .= "\n\t\"modules\":{";
         $allModuleJS = '';
         //Grab the keys this way rather than through $key => $value to preserve pass by reference for $data
         $modules = array_keys($data['modules']);
         foreach ($modules as $module) {
             $moduleJS = $this->buildJavascriptComponentSection($data['modules'][$module], true);
             if (!empty($moduleJS)) {
                 $allModuleJS .= ",\n\t\t\"{$module}\":{{$moduleJS}}";
             }
         }
         //Chop off the first comma in $allModuleJS
         $js .= substr($allModuleJS, 1);
         $js .= "\n\t}";
     }
     $js .= "}})(SUGAR.App);";
     $hash = md5($js);
     //If we are going to be using uglify to minify our JS, we should minify the entire file rather than each component separately.
     if (!inDeveloperMode() && SugarMin::isMinifyFast()) {
         $js = SugarMin::minify($js);
     }
     $path = "cache/javascript/{$platform}/components_{$hash}.js";
     if (!file_exists($path)) {
         mkdir_recursive(dirname($path));
         sugar_file_put_contents_atomic($path, $js);
     }
     return $this->getUrlForCacheFile($path);
 }
Пример #18
0
 /**
  * Constructor for the bean, it performs following tasks:
  *
  * 1. Initalized a database connections
  * 2. Load the vardefs for the module implemeting the class. cache the entries
  *    if needed
  * 3. Setup row-level security preference
  * All implementing classes  must call this constructor using the parent::__construct()
  *
  */
 public function __construct()
 {
     // FIXME: this will be removed, needed for ensuring BeanFactory is always used
     //$this->checkBacktrace();
     global $dictionary, $current_user;
     $this->db = DBManagerFactory::getInstance();
     if (empty($this->module_name)) {
         $this->module_name = $this->module_dir;
     }
     if (isset($this->disable_team_security)) {
         $this->disable_row_level_security = $this->disable_team_security;
     }
     // Verify that current user is not null then do an ACL check.  The current user check is to support installation.
     if (!$this->disable_row_level_security && !empty($current_user->id) && (is_admin($current_user) || $this->bean_implements('ACL') && (ACLAction::getUserAccessLevel($current_user->id, $this->module_dir, 'access') == ACL_ALLOW_ENABLED && (ACLAction::getUserAccessLevel($current_user->id, $this->module_dir, 'admin') == ACL_ALLOW_ADMIN || ACLAction::getUserAccessLevel($current_user->id, $this->module_dir, 'admin') == ACL_ALLOW_ADMIN_DEV)))) {
         $this->disable_row_level_security = true;
     }
     if (false == $this->disable_vardefs && (empty(self::$loadedDefs[$this->object_name]) || !empty($GLOBALS['reload_vardefs']))) {
         $refresh = inDeveloperMode() || !empty($_SESSION['developerMode']);
         if ($refresh && !empty(VardefManager::$inReload["{$this->module_dir}:{$this->object_name}"])) {
             // if we're already reloading this vardef, no need to do it again
             $refresh = false;
         }
         VardefManager::loadVardef($this->module_dir, $this->object_name, $refresh, array("bean" => $this));
         // build $this->column_fields from the field_defs if they exist
         if (!empty($dictionary[$this->object_name]['fields'])) {
             foreach ($dictionary[$this->object_name]['fields'] as $key => $value_array) {
                 $column_fields[] = $key;
                 if (!empty($value_array['required']) && !empty($value_array['name'])) {
                     $this->required_fields[$value_array['name']] = 1;
                 }
             }
             $this->column_fields = $column_fields;
         }
         //setup custom fields
         if (!isset($this->custom_fields) && empty($this->disable_custom_fields)) {
             $this->setupCustomFields($this->module_dir);
         }
         //load up field_arrays from CacheHandler;
         if (empty($this->list_fields)) {
             $this->list_fields = $this->_loadCachedArray($this->module_dir, $this->object_name, 'list_fields');
         }
         if (empty($this->column_fields)) {
             $this->column_fields = $this->_loadCachedArray($this->module_dir, $this->object_name, 'column_fields');
         }
         if (empty($this->required_fields)) {
             $this->required_fields = $this->_loadCachedArray($this->module_dir, $this->object_name, 'required_fields');
         }
         if (isset($GLOBALS['dictionary'][$this->object_name]) && !$this->disable_vardefs) {
             $this->field_name_map = $dictionary[$this->object_name]['fields'];
             $this->field_defs = $dictionary[$this->object_name]['fields'];
             if (isset($dictionary[$this->object_name]['name_format_map'])) {
                 $this->name_format_map = $dictionary[$this->object_name]['name_format_map'];
             }
             if (!empty($dictionary[$this->object_name]['optimistic_locking'])) {
                 $this->optimistic_lock = true;
             }
             if (isset($dictionary[$this->object_name]['importable'])) {
                 $this->importable = isTruthy($dictionary[$this->object_name]['importable']);
             }
         }
         self::$loadedDefs[$this->object_name]['column_fields'] =& $this->column_fields;
         self::$loadedDefs[$this->object_name]['list_fields'] =& $this->list_fields;
         self::$loadedDefs[$this->object_name]['required_fields'] =& $this->required_fields;
         self::$loadedDefs[$this->object_name]['field_name_map'] =& $this->field_name_map;
         self::$loadedDefs[$this->object_name]['field_defs'] =& $this->field_defs;
         self::$loadedDefs[$this->object_name]['name_format_map'] =& $this->name_format_map;
     } else {
         $this->column_fields =& self::$loadedDefs[$this->object_name]['column_fields'];
         $this->list_fields =& self::$loadedDefs[$this->object_name]['list_fields'];
         $this->required_fields =& self::$loadedDefs[$this->object_name]['required_fields'];
         $this->field_name_map =& self::$loadedDefs[$this->object_name]['field_name_map'];
         $this->field_defs =& self::$loadedDefs[$this->object_name]['field_defs'];
         $this->name_format_map =& self::$loadedDefs[$this->object_name]['name_format_map'];
         $this->added_custom_field_defs = true;
         if (!isset($this->custom_fields) && empty($this->disable_custom_fields)) {
             $this->setupCustomFields($this->module_dir, false);
         }
         if (!empty($dictionary[$this->object_name]['optimistic_locking'])) {
             $this->optimistic_lock = true;
         }
     }
     // Verify that current user is not null then do an ACL check.  The current user check is to support installation.
     if (!$this->disable_row_level_security && !empty($current_user->id) && !isset($this->disable_team_security) && !SugarACL::checkAccess($this->module_dir, 'team_security', array('bean' => $this))) {
         // We can disable team security for this module
         $this->disable_row_level_security = true;
     }
     if ($this->bean_implements('ACL')) {
         $this->acl_fields = isset($dictionary[$this->object_name]['acl_fields']) && $dictionary[$this->object_name]['acl_fields'] === false ? false : true;
         if (!empty($current_user->id)) {
             ACLField::loadUserFields($this->module_dir, $this->object_name, $current_user->id);
         }
         $this->addVisibilityStrategy("ACLVisibility");
     }
     $this->populateDefaultValues();
     if (isset($this->disable_team_security)) {
         $this->disable_row_level_security = $this->disable_team_security;
     }
 }
Пример #19
0
 /**
  * load the vardefs for a given module and object
  * @param string $module the given module we want to load the vardefs for
  * @param string $object the given object we wish to load the vardefs for
  * @param bool   $refresh whether or not we wish to refresh the cache file.
  */
 static function loadVardef($module, $object, $refresh = false, $params = array())
 {
     //here check if the cache file exists, if it does then load it, if it doesn't
     //then call refreshVardef
     //if either our session or the system is set to developerMode then refresh is set to true
     if (inDeveloperMode() || !empty($_SESSION['developerMode'])) {
         $refresh = true;
     }
     // Retrieve the vardefs from cache.
     $key = "VardefManager.{$module}.{$object}";
     if (!$refresh) {
         $return_result = sugar_cache_retrieve($key);
         $return_result = self::applyGlobalAccountRequirements($return_result);
         if (!empty($return_result)) {
             $GLOBALS['dictionary'][$object] = $return_result;
             return;
         }
     }
     // Some of the vardefs do not correctly define dictionary as global.  Declare it first.
     global $dictionary;
     if (empty($GLOBALS['dictionary'][$object]) || $refresh) {
         //if the consumer has demanded a refresh or the cache/modules... file
         //does not exist, then we should do out and try to reload things
         $cachedfile = sugar_cached('modules/') . $module . '/' . $object . 'vardefs.php';
         if ($refresh || !file_exists($cachedfile)) {
             VardefManager::refreshVardefs($module, $object, null, true, $params);
         }
         //at this point we should have the cache/modules/... file
         //which was created from the refreshVardefs so let's try to load it.
         if (file_exists($cachedfile)) {
             if (is_readable($cachedfile)) {
                 include $cachedfile;
             }
             // now that we hae loaded the data from disk, put it in the cache.
             if (!empty($GLOBALS['dictionary'][$object])) {
                 $GLOBALS['dictionary'][$object] = self::applyGlobalAccountRequirements($GLOBALS['dictionary'][$object]);
                 sugar_cache_put($key, $GLOBALS['dictionary'][$object]);
             }
         }
     }
 }
Пример #20
0
function getEditFieldHTML($module, $fieldname, $aow_field, $view = 'EditView', $id = '', $alt_type = '', $currency_id = '')
{
    global $current_language, $app_strings, $app_list_strings, $current_user, $beanFiles, $beanList;
    $bean = BeanFactory::getBean($module, $id);
    if (!checkAccess($bean)) {
        return false;
    }
    $value = getFieldValueFromModule($fieldname, $module, $id);
    // use the mod_strings for this module
    $mod_strings = return_module_language($current_language, $module);
    // set the filename for this control
    $file = create_cache_directory('include/InlineEditing/') . $module . $view . $alt_type . $fieldname . '.tpl';
    if (!is_file($file) || inDeveloperMode() || !empty($_SESSION['developerMode'])) {
        if (!isset($vardef)) {
            require_once $beanFiles[$beanList[$module]];
            $focus = new $beanList[$module]();
            $vardef = $focus->getFieldDefinition($fieldname);
        }
        $displayParams = array();
        //$displayParams['formName'] = 'EditView';
        // if this is the id relation field, then don't have a pop-up selector.
        if ($vardef['type'] == 'relate' && $vardef['id_name'] == $vardef['name']) {
            $vardef['type'] = 'varchar';
        }
        if (isset($vardef['precision'])) {
            unset($vardef['precision']);
        }
        //$vardef['precision'] = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user);
        //TODO Fix datetimecomebo
        //temp work around
        if ($vardef['type'] == 'datetime') {
            $vardef['type'] = 'datetimecombo';
        }
        // trim down textbox display
        if ($vardef['type'] == 'text') {
            $vardef['rows'] = 2;
            $vardef['cols'] = 32;
        }
        // create the dropdowns for the parent type fields
        if ($vardef['type'] == 'parent_type') {
            $vardef['type'] = 'enum';
        }
        if ($vardef['type'] == 'link') {
            $vardef['type'] = 'relate';
            $vardef['rname'] = 'name';
            $vardef['id_name'] = $vardef['name'] . '_id';
            if ((!isset($vardef['module']) || $vardef['module'] == '') && $focus->load_relationship($vardef['name'])) {
                $vardef['module'] = $focus->{$vardef['name']}->getRelatedModuleName();
            }
        }
        //check for $alt_type
        if ($alt_type != '') {
            $vardef['type'] = $alt_type;
        }
        // remove the special text entry field function 'getEmailAddressWidget'
        if (isset($vardef['function']) && ($vardef['function'] == 'getEmailAddressWidget' || $vardef['function']['name'] == 'getEmailAddressWidget')) {
            unset($vardef['function']);
        }
        if (isset($vardef['name']) && $vardef['name'] == 'date_modified') {
            $vardef['name'] = 'aow_temp_date';
        }
        // load SugarFieldHandler to render the field tpl file
        static $sfh;
        if (!isset($sfh)) {
            require_once 'include/SugarFields/SugarFieldHandler.php';
            $sfh = new SugarFieldHandler();
        }
        $contents = $sfh->displaySmarty('fields', $vardef, $view, $displayParams);
        // Remove all the copyright comments
        $contents = preg_replace('/\\{\\*[^\\}]*?\\*\\}/', '', $contents);
        // remove extra wrong javascript which breaks auto complete on flexi relationship parent fields
        $contents = preg_replace("/<script language=\"javascript\">if\\(typeof sqs_objects == \\'undefined\\'\\){var sqs_objects = new Array;}sqs_objects\\[\\'EditView_parent_name\\'\\].*?<\\/script>/", "", $contents);
        if ($view == 'EditView' && ($vardef['type'] == 'relate' || $vardef['type'] == 'parent')) {
            $contents = str_replace('"' . $vardef['id_name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.id_name}"{literal}', $contents);
            $contents = str_replace('"' . $vardef['name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.name}"{literal}', $contents);
            // regex below fixes button javascript for flexi relationship
            if ($vardef['type'] == 'parent') {
                $contents = str_replace("onclick='open_popup(document.{\$form_name}.parent_type.value, 600, 400, \"\", true, false, {literal}{\"call_back_function\":\"set_return\",\"form_name\":\"EditView\",\"field_to_name_array\":{\"id\":{/literal}\"{\$fields.parent_name.id_name}", "onclick='open_popup(document.{\$form_name}.parent_type.value, 600, 400, \"\", true, false, {literal}{\"call_back_function\":\"set_return\",\"form_name\":\"EditView\",\"field_to_name_array\":{\"id\":{/literal}\"parent_id", $contents);
            }
        }
        // hack to disable one of the js calls in this control
        if (isset($vardef['function']) && ($vardef['function'] == 'getCurrencyDropDown' || $vardef['function']['name'] == 'getCurrencyDropDown')) {
            $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}";
        }
        // Save it to the cache file
        if ($fh = @sugar_fopen($file, 'w')) {
            fputs($fh, $contents);
            fclose($fh);
        }
    }
    // Now render the template we received
    $ss = new Sugar_Smarty();
    // Create Smarty variables for the Calendar picker widget
    global $timedate;
    $time_format = $timedate->get_user_time_format();
    $date_format = $timedate->get_cal_date_format();
    $ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
    $ss->assign('TIME_FORMAT', $time_format);
    $time_separator = ":";
    $match = array();
    if (preg_match('/\\d+([^\\d])\\d+([^\\d]*)/s', $time_format, $match)) {
        $time_separator = $match[1];
    }
    $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
    if (!isset($match[2]) || $match[2] == '') {
        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M");
    } else {
        $pm = $match[2] == "pm" ? "%P" : "%p";
        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm);
    }
    $ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week());
    $fieldlist = array();
    if (!isset($focus) || !$focus instanceof SugarBean) {
        require_once $beanFiles[$beanList[$module]];
    }
    $focus = new $beanList[$module]();
    // create the dropdowns for the parent type fields
    $vardefFields[$fieldname] = $focus->field_defs[$fieldname];
    if ($vardefFields[$fieldname]['type'] == 'parent') {
        $focus->field_defs[$fieldname]['options'] = $focus->field_defs[$vardefFields[$fieldname]['group']]['options'];
    }
    foreach ($vardefFields as $name => $properties) {
        $fieldlist[$name] = $properties;
        // fill in enums
        if (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']])) {
            $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']];
        } elseif (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']])) {
            $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']];
        }
    }
    // fill in function return values
    if (!in_array($fieldname, array('email1', 'email2'))) {
        if (!empty($fieldlist[$fieldname]['function']['returns']) && $fieldlist[$fieldname]['function']['returns'] == 'html') {
            $function = $fieldlist[$fieldname]['function']['name'];
            // include various functions required in the various vardefs
            if (isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include'])) {
                require_once $fieldlist[$fieldname]['function']['include'];
            }
            $_REQUEST[$fieldname] = $value;
            $value = $function($focus, $fieldname, $value, $view);
            $value = str_ireplace($fieldname, $aow_field, $value);
        }
    }
    if ($fieldlist[$fieldname]['type'] == 'link') {
        $fieldlist[$fieldname]['id_name'] = $fieldlist[$fieldname]['name'] . '_id';
        if ((!isset($fieldlist[$fieldname]['module']) || $fieldlist[$fieldname]['module'] == '') && $focus->load_relationship($fieldlist[$fieldname]['name'])) {
            $relateField = $fieldlist[$fieldname]['name'];
            $fieldlist[$fieldname]['module'] = $focus->{$relateField}->getRelatedModuleName();
        }
    }
    if ($fieldlist[$fieldname]['type'] == 'parent') {
        $fieldlist['parent_id']['name'] = 'parent_id';
    }
    if (isset($fieldlist[$fieldname]['name']) && $fieldlist[$fieldname]['name'] == 'date_modified') {
        $fieldlist[$fieldname]['name'] = 'aow_temp_date';
        $fieldlist['aow_temp_date'] = $fieldlist[$fieldname];
        $fieldname = 'aow_temp_date';
    }
    if (isset($fieldlist[$fieldname]['id_name']) && $fieldlist[$fieldname]['id_name'] != '' && $fieldlist[$fieldname]['id_name'] != $fieldlist[$fieldname]['name']) {
        if ($value) {
            $relateIdField = $fieldlist[$fieldname]['id_name'];
            $rel_value = $bean->{$relateIdField};
        }
        $fieldlist[$fieldlist[$fieldname]['id_name']]['value'] = $rel_value;
        $fieldlist[$fieldname]['value'] = $value;
        $fieldlist[$fieldname]['id_name'] = $aow_field;
        $fieldlist[$fieldname]['name'] = $aow_field . '_display';
    } else {
        if (isset($fieldlist[$fieldname]['type']) && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime')) {
            $value = $focus->convertField($value, $fieldlist[$fieldname]);
            if (!$value) {
                $value = date($timedate->get_date_time_format());
            }
            $fieldlist[$fieldname]['name'] = $aow_field;
            $fieldlist[$fieldname]['value'] = $value;
        } else {
            if (isset($fieldlist[$fieldname]['type']) && $fieldlist[$fieldname]['type'] == 'date') {
                $value = $focus->convertField($value, $fieldlist[$fieldname]);
                $fieldlist[$fieldname]['name'] = $aow_field;
                if (empty($value) == "") {
                    $value = str_replace("%", "", date($date_format));
                }
                $fieldlist[$fieldname]['value'] = $value;
            } else {
                $fieldlist[$fieldname]['value'] = $value;
                $fieldlist[$fieldname]['name'] = $aow_field;
            }
        }
    }
    if ($fieldlist[$fieldname]['type'] == 'currency' && $view != 'EditView') {
        static $sfh;
        if (!isset($sfh)) {
            require_once 'include/SugarFields/SugarFieldHandler.php';
            $sfh = new SugarFieldHandler();
        }
        if ($currency_id != '' && !stripos($fieldname, '_USD')) {
            $userCurrencyId = $current_user->getPreference('currency');
            if ($currency_id != $userCurrencyId) {
                $currency = new Currency();
                $currency->retrieve($currency_id);
                $value = $currency->convertToDollar($value);
                $currency->retrieve($userCurrencyId);
                $value = $currency->convertFromDollar($value);
            }
        }
        $parentfieldlist[strtoupper($fieldname)] = $value;
        return $sfh->displaySmarty($parentfieldlist, $fieldlist[$fieldname], 'ListView', $displayParams);
    }
    $ss->assign("fields", $fieldlist);
    $ss->assign("form_name", $view);
    $ss->assign("bean", $focus);
    $ss->assign("MOD", $mod_strings);
    $ss->assign("APP", $app_strings);
    return json_encode($ss->fetch($file));
}
Пример #21
0
function getVersionedPath($path, $additional_attrs = '')
{
    if (empty($GLOBALS['sugar_config']['js_custom_version'])) {
        $GLOBALS['sugar_config']['js_custom_version'] = 1;
    }
    $js_version_key = isset($GLOBALS['js_version_key']) ? $GLOBALS['js_version_key'] : '';
    if (inDeveloperMode()) {
        static $rand;
        if (empty($rand)) {
            $rand = mt_rand();
        }
        $dev = $rand;
    } else {
        $dev = '';
    }
    if (is_array($additional_attrs)) {
        $additional_attrs = join("|", $additional_attrs);
    }
    // cutting 2 last chars here because since md5 is 32 chars, it's always ==
    $str = substr(base64_encode(md5("{$js_version_key}|{$GLOBALS['sugar_config']['js_custom_version']}|{$dev}|{$additional_attrs}", true)), 0, -2);
    // remove / - it confuses some parsers
    $str = strtr($str, '/+', '-_');
    if (empty($path)) {
        return $str;
    }
    return $path . "?v={$str}";
}
Пример #22
0
 public function repairDatabaseSelectModules()
 {
     global $current_user, $mod_strings, $dictionary;
     set_time_limit(3600);
     include 'include/modules.php';
     //bug 15661
     $db = DBManagerFactory::getInstance();
     if (is_admin($current_user) || is_admin_for_any_module($current_user)) {
         $export = false;
         if ($this->show_output) {
             echo getClassicModuleTitle($mod_strings['LBL_REPAIR_DATABASE'], array($mod_strings['LBL_REPAIR_DATABASE']), false);
         }
         if ($this->show_output) {
             echo "<h1 id=\"rdloading\">{$mod_strings['LBL_REPAIR_DATABASE_PROCESSING']}</h1>";
             ob_flush();
         }
         $sql = '';
         if ($this->module_list && !in_array($mod_strings['LBL_ALL_MODULES'], $this->module_list)) {
             $repair_related_modules = array_keys($dictionary);
             //repair DB
             $dm = inDeveloperMode();
             $GLOBALS['sugar_config']['developerMode'] = true;
             foreach ($this->module_list as $bean_name) {
                 if (isset($beanFiles[$bean_name]) && file_exists($beanFiles[$bean_name])) {
                     require_once $beanFiles[$bean_name];
                     $GLOBALS['reload_vardefs'] = true;
                     $focus = new $bean_name();
                     #30273
                     if ($focus->disable_vardefs == false) {
                         include 'modules/' . $focus->module_dir . '/vardefs.php';
                         if ($this->show_output) {
                             print_r("<p>" . $mod_strings['LBL_REPAIR_DB_FOR'] . ' ' . $bean_name . "</p>");
                         }
                         $sql .= $db->repairTable($focus, $this->execute);
                     }
                 }
             }
             $GLOBALS['sugar_config']['developerMode'] = $dm;
             if ($this->show_output) {
                 echo "<script type=\"text/javascript\">document.getElementById('rdloading').style.display = \"none\";</script>";
             }
             if (isset($sql) && !empty($sql)) {
                 $qry_str = "";
                 foreach (explode("\n", $sql) as $line) {
                     if (!empty($line) && substr($line, -2) != "*/") {
                         $line .= ";";
                     }
                     $qry_str .= $line . "\n";
                 }
                 if ($this->show_output) {
                     echo "<h3>{$mod_strings['LBL_REPAIR_DATABASE_DIFFERENCES']}</h3>";
                     echo "<p>{$mod_strings['LBL_REPAIR_DATABASE_TEXT']}</p>";
                     echo "<form method=\"post\" action=\"index.php?module=Administration&amp;action=repairDatabase\">";
                     echo "<textarea name=\"sql\" rows=\"24\" cols=\"150\" id=\"repairsql\">{$qry_str}</textarea>";
                     echo "<br /><input type=\"submit\" value=\"" . $mod_strings['LBL_REPAIR_DATABASE_EXECUTE'] . "\" name=\"raction\" /> <input type=\"submit\" name=\"raction\" value=\"" . $mod_strings['LBL_REPAIR_DATABASE_EXPORT'] . "\" />";
                 }
             } else {
                 if ($this->show_output) {
                     echo "<h3>{$mod_strings['LBL_REPAIR_DATABASE_SYNCED']}</h3>";
                 }
             }
         }
     } else {
         sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']);
     }
 }
Пример #23
0
 /**
  * @see DBManager::checkError()
  */
 public function checkError($msg = '', $dieOnError = false)
 {
     if (DBManager::checkError($msg, $dieOnError)) {
         return true;
     }
     $userMsg = inDeveloperMode() ? "{$msg}: " : "";
     if (mysqli_errno($this->getDatabase())) {
         if ($this->dieOnError || $dieOnError) {
             $GLOBALS['log']->fatal("{$msg}: MySQL error " . mysqli_errno($this->database) . ": " . mysqli_error($this->database));
             sugar_die($userMsg . $GLOBALS['app_strings']['ERR_DB_FAIL']);
         } else {
             $this->last_error = $userMsg . "MySQL error " . mysqli_errno($this->database) . ": " . mysqli_error($this->database);
             $GLOBALS['log']->error("{$msg}: MySQL error " . mysqli_errno($this->database) . ": " . mysqli_error($this->database));
         }
         return true;
     }
     return false;
 }
Пример #24
0
 /**
  * Returns the URL for an image in the current theme. If not found in the current theme, will revert
  * to looking in the base theme.
  * 
  * @param  string $jsFileName js file name
  * @param  bool   $addJSPath call getJSPath() with the results to add some unique image tracking support
  * @return string path to js file
  */
 public function getJSURL($jsFileName, $addJSPath = true)
 {
     if (isset($this->_jsCache[$jsFileName])) {
         if ($addJSPath) {
             return getJSPath($this->_jsCache[$jsFileName]);
         } else {
             return $this->_jsCache[$jsFileName];
         }
     }
     $jsFileContents = '';
     if (isset($this->parentTheme) && SugarThemeRegistry::get($this->parentTheme) instanceof SugarTheme && ($filename = SugarThemeRegistry::get($this->parentTheme)->getJSURL($jsFileName, false)) != '') {
         $jsFileContents .= file_get_contents($filename);
     } else {
         if (sugar_is_file($this->getDefaultJSPath() . '/' . $jsFileName)) {
             $jsFileContents .= file_get_contents($this->getDefaultJSPath() . '/' . $jsFileName);
         }
         if (sugar_is_file('custom/' . $this->getDefaultJSPath() . '/' . $jsFileName)) {
             $jsFileContents .= file_get_contents('custom/' . $this->getDefaultJSPath() . '/' . $jsFileName);
         }
     }
     if (sugar_is_file($this->getJSPath() . '/' . $jsFileName)) {
         $jsFileContents .= file_get_contents($this->getJSPath() . '/' . $jsFileName);
     }
     if (sugar_is_file('custom/' . $this->getJSPath() . '/' . $jsFileName)) {
         $jsFileContents .= file_get_contents('custom/' . $this->getJSPath() . '/' . $jsFileName);
     }
     if (empty($jsFileContents)) {
         $GLOBALS['log']->warn("Javascript File {$jsFileName} not found");
         return false;
     }
     // create the cached file location
     $jsFilePath = create_cache_directory($this->getJSPath() . "/{$jsFileName}");
     // now write the js to cache
     sugar_file_put_contents($jsFilePath, $jsFileContents);
     // minify the js
     $jsFilePathMin = str_replace('.js', '-min.js', $jsFilePath);
     if (!inDeveloperMode() && !sugar_is_file($jsFilePathMin)) {
         $jMin = new JSMin($jsFilePath, $jsFilePathMin);
         $jMin->minify();
         $jsFilePath = $jsFilePathMin;
     }
     $this->_jsCache[$jsFileName] = $jsFilePath;
     if ($addJSPath) {
         return getJSPath($jsFilePath);
     }
     return $jsFilePath;
 }
Пример #25
0
 /**
  * Displays the header on section of the page; basically everything before the content
  */
 public function displayHeader($retModTabs = false)
 {
     global $theme;
     global $max_tabs;
     global $app_strings;
     global $current_user;
     global $sugar_config;
     global $app_list_strings;
     global $mod_strings;
     global $current_language;
     $GLOBALS['app']->headerDisplayed = true;
     $themeObject = SugarThemeRegistry::current();
     $theme = $themeObject->__toString();
     $ss = new Sugar_Smarty();
     $ss->assign("APP", $app_strings);
     $ss->assign("THEME", $theme);
     $ss->assign("THEME_IE6COMPAT", $themeObject->ie6compat ? 'true' : 'false');
     $ss->assign("MODULE_NAME", $this->module);
     $ss->assign("langHeader", get_language_header());
     // set ab testing if exists
     $testing = isset($_REQUEST["testing"]) ? $_REQUEST['testing'] : "a";
     $ss->assign("ABTESTING", $testing);
     // get browser title
     $ss->assign("SYSTEM_NAME", $this->getBrowserTitle());
     // get css
     $css = $themeObject->getCSS();
     if ($this->_getOption('view_print')) {
         $css .= '<link rel="stylesheet" type="text/css" href="' . $themeObject->getCSSURL('print.css') . '" media="all" />';
     }
     $ss->assign("SUGAR_CSS", $css);
     // get javascript
     ob_start();
     $this->renderJavascript();
     $ss->assign("SUGAR_JS", ob_get_contents() . $themeObject->getJS());
     ob_end_clean();
     // get favicon
     if (isset($GLOBALS['sugar_config']['default_module_favicon'])) {
         $module_favicon = $GLOBALS['sugar_config']['default_module_favicon'];
     } else {
         $module_favicon = false;
     }
     $favicon = $this->getFavicon();
     $ss->assign('FAVICON_URL', $favicon['url']);
     // build the shortcut menu
     $shortcut_menu = array();
     foreach ($this->getMenu() as $key => $menu_item) {
         $shortcut_menu[$key] = array("URL" => $menu_item[0], "LABEL" => $menu_item[1], "MODULE_NAME" => $menu_item[2], "IMAGE" => $themeObject->getImage($menu_item[2], "border='0' align='absmiddle'", null, null, '.gif', $menu_item[1]));
     }
     $ss->assign("SHORTCUT_MENU", $shortcut_menu);
     // handle rtl text direction
     if (isset($_REQUEST['RTL']) && $_REQUEST['RTL'] == 'RTL') {
         $_SESSION['RTL'] = true;
     }
     if (isset($_REQUEST['LTR']) && $_REQUEST['LTR'] == 'LTR') {
         unset($_SESSION['RTL']);
     }
     if (isset($_SESSION['RTL']) && $_SESSION['RTL']) {
         $ss->assign("DIR", 'dir="RTL"');
     }
     // handle resizing of the company logo correctly on the fly
     $companyLogoURL = $themeObject->getImageURL('company_logo.png');
     $companyLogoURL_arr = explode('?', $companyLogoURL);
     $companyLogoURL = $companyLogoURL_arr[0];
     $company_logo_attributes = sugar_cache_retrieve('company_logo_attributes');
     if (!empty($company_logo_attributes)) {
         $ss->assign("COMPANY_LOGO_MD5", $company_logo_attributes[0]);
         $ss->assign("COMPANY_LOGO_WIDTH", $company_logo_attributes[1]);
         $ss->assign("COMPANY_LOGO_HEIGHT", $company_logo_attributes[2]);
     } else {
         // Always need to md5 the file
         $ss->assign("COMPANY_LOGO_MD5", md5_file($companyLogoURL));
         list($width, $height) = getimagesize($companyLogoURL);
         if ($width > 212 || $height > 40) {
             $resizePctWidth = ($width - 212) / 212;
             $resizePctHeight = ($height - 40) / 40;
             if ($resizePctWidth > $resizePctHeight) {
                 $resizeAmount = $width / 212;
             } else {
                 $resizeAmount = $height / 40;
             }
             $ss->assign("COMPANY_LOGO_WIDTH", round($width * (1 / $resizeAmount)));
             $ss->assign("COMPANY_LOGO_HEIGHT", round($height * (1 / $resizeAmount)));
         } else {
             $ss->assign("COMPANY_LOGO_WIDTH", $width);
             $ss->assign("COMPANY_LOGO_HEIGHT", $height);
         }
         // Let's cache the results
         sugar_cache_put('company_logo_attributes', array($ss->get_template_vars("COMPANY_LOGO_MD5"), $ss->get_template_vars("COMPANY_LOGO_WIDTH"), $ss->get_template_vars("COMPANY_LOGO_HEIGHT")));
     }
     $ss->assign("COMPANY_LOGO_URL", getJSPath($companyLogoURL) . "&logo_md5=" . $ss->get_template_vars("COMPANY_LOGO_MD5"));
     // get the global links
     $gcls = array();
     $global_control_links = array();
     require "include/globalControlLinks.php";
     foreach ($global_control_links as $key => $value) {
         if ($key == 'users') {
             //represents logout link.
             $ss->assign("LOGOUT_LINK", $value['linkinfo'][key($value['linkinfo'])]);
             $ss->assign("LOGOUT_LABEL", key($value['linkinfo']));
             //key value for first element.
             continue;
         }
         foreach ($value as $linkattribute => $attributevalue) {
             // get the main link info
             if ($linkattribute == 'linkinfo') {
                 $gcls[$key] = array("LABEL" => key($attributevalue), "URL" => current($attributevalue), "SUBMENU" => array());
                 if (substr($gcls[$key]["URL"], 0, 11) == "javascript:") {
                     $gcls[$key]["ONCLICK"] = substr($gcls[$key]["URL"], 11);
                     $gcls[$key]["URL"] = "javascript:void(0)";
                 }
             }
             // and now the sublinks
             if ($linkattribute == 'submenu' && is_array($attributevalue)) {
                 foreach ($attributevalue as $submenulinkkey => $submenulinkinfo) {
                     $gcls[$key]['SUBMENU'][$submenulinkkey] = array("LABEL" => key($submenulinkinfo), "URL" => current($submenulinkinfo));
                 }
                 if (substr($gcls[$key]['SUBMENU'][$submenulinkkey]["URL"], 0, 11) == "javascript:") {
                     $gcls[$key]['SUBMENU'][$submenulinkkey]["ONCLICK"] = substr($gcls[$key]['SUBMENU'][$submenulinkkey]["URL"], 11);
                     $gcls[$key]['SUBMENU'][$submenulinkkey]["URL"] = "javascript:void(0)";
                 }
             }
         }
     }
     $ss->assign("GCLS", $gcls);
     $ss->assign("SEARCH", isset($_REQUEST['query_string']) ? $_REQUEST['query_string'] : '');
     if ($this->action == "EditView" || $this->action == "Login") {
         $ss->assign("ONLOAD", 'onload="set_focus()"');
     }
     $ss->assign("AUTHENTICATED", isset($_SESSION["authenticated_user_id"]));
     // get other things needed for page style popup
     if (isset($_SESSION["authenticated_user_id"])) {
         // get the current user name and id
         $ss->assign("CURRENT_USER", $current_user->full_name == '' || !showFullName() ? $current_user->user_name : $current_user->full_name);
         $ss->assign("CURRENT_USER_ID", $current_user->id);
         // get the last viewed records
         $tracker = new Tracker();
         $history = $tracker->get_recently_viewed($current_user->id);
         $ss->assign("recentRecords", $this->processRecentRecords($history));
     }
     $bakModStrings = $mod_strings;
     if (isset($_SESSION["authenticated_user_id"])) {
         // get the module list
         $moduleTopMenu = array();
         $max_tabs = $current_user->getPreference('max_tabs');
         // Attempt to correct if max tabs count is extremely high.
         if (!isset($max_tabs) || $max_tabs <= 0 || $max_tabs > 10) {
             $max_tabs = $GLOBALS['sugar_config']['default_max_tabs'];
             $current_user->setPreference('max_tabs', $max_tabs, 0, 'global');
         }
         /*$moduleTab = $this->_getModuleTab();
           $ss->assign('MODULE_TAB',$moduleTab);*/
         // See if they are using grouped tabs or not (removed in 6.0, returned in 6.1)
         $user_navigation_paradigm = $current_user->getPreference('navigation_paradigm');
         if (!isset($user_navigation_paradigm)) {
             $user_navigation_paradigm = $GLOBALS['sugar_config']['default_navigation_paradigm'];
         }
         // Get the full module list for later use
         foreach (query_module_access_list($current_user) as $module) {
             // Bug 25948 - Check for the module being in the moduleList
             if (isset($app_list_strings['moduleList'][$module])) {
                 $fullModuleList[$module] = $app_list_strings['moduleList'][$module];
             }
         }
         if (!should_hide_iframes()) {
             $iFrame = new iFrame();
             $frames = $iFrame->lookup_frames('tab');
             foreach ($frames as $key => $values) {
                 $fullModuleList[$key] = $values;
             }
         } elseif (isset($fullModuleList['iFrames'])) {
             unset($fullModuleList['iFrames']);
         }
         if ($user_navigation_paradigm == 'gm' && isset($themeObject->group_tabs) && $themeObject->group_tabs) {
             // We are using grouped tabs
             require_once 'include/GroupedTabs/GroupedTabStructure.php';
             $groupedTabsClass = new GroupedTabStructure();
             $modules = query_module_access_list($current_user);
             //handle with submoremodules
             $max_tabs = $current_user->getPreference('max_tabs');
             // If the max_tabs isn't set incorrectly, set it within the range, to the default max sub tabs size
             if (!isset($max_tabs) || $max_tabs <= 0 || $max_tabs > 10) {
                 // We have a default value. Use it
                 if (isset($GLOBALS['sugar_config']['default_max_tabs'])) {
                     $max_tabs = $GLOBALS['sugar_config']['default_max_tabs'];
                 } else {
                     $max_tabs = 8;
                 }
             }
             $subMoreModules = false;
             $groupTabs = $groupedTabsClass->get_tab_structure(get_val_array($modules));
             // We need to put this here, so the "All" group is valid for the user's preference.
             $groupTabs[$app_strings['LBL_TABGROUP_ALL']]['modules'] = $fullModuleList;
             // Setup the default group tab.
             $allGroup = $app_strings['LBL_TABGROUP_ALL'];
             $ss->assign('currentGroupTab', $allGroup);
             $currentGroupTab = $allGroup;
             $usersGroup = $current_user->getPreference('theme_current_group');
             // Figure out which tab they currently have selected (stored as a user preference)
             if (!empty($usersGroup) && isset($groupTabs[$usersGroup])) {
                 $currentGroupTab = $usersGroup;
             } else {
                 $current_user->setPreference('theme_current_group', $currentGroupTab);
             }
             $ss->assign('currentGroupTab', $currentGroupTab);
             $usingGroupTabs = true;
         } else {
             // Setup the default group tab.
             $ss->assign('currentGroupTab', $app_strings['LBL_TABGROUP_ALL']);
             $usingGroupTabs = false;
             $groupTabs[$app_strings['LBL_TABGROUP_ALL']]['modules'] = $fullModuleList;
         }
         $topTabList = array();
         // Now time to go through each of the tab sets and fix them up.
         foreach ($groupTabs as $tabIdx => $tabData) {
             $topTabs = $tabData['modules'];
             if (!is_array($topTabs)) {
                 $topTabs = array();
             }
             $extraTabs = array();
             // Split it in to the tabs that go across the top, and the ones that are on the extra menu.
             if (count($topTabs) > $max_tabs) {
                 $extraTabs = array_splice($topTabs, $max_tabs);
             }
             // Make sure the current module is accessable through one of the top tabs
             if (!isset($topTabs[$moduleTab])) {
                 // Nope, we need to add it.
                 // First, take it out of the extra menu, if it's there
                 if (isset($extraTabs[$moduleTab])) {
                     unset($extraTabs[$moduleTab]);
                 }
                 if (count($topTabs) >= $max_tabs - 1) {
                     // We already have the maximum number of tabs, so we need to shuffle the last one
                     // from the top to the first one of the extras
                     $lastElem = array_splice($topTabs, $max_tabs - 1);
                     $extraTabs = $lastElem + $extraTabs;
                 }
                 if (!empty($moduleTab)) {
                     $topTabs[$moduleTab] = $app_list_strings['moduleList'][$moduleTab];
                 }
             }
             /*
             // This was removed, but I like the idea, so I left the code in here in case we decide to turn it back on
             // If we are using group tabs, add all the "hidden" tabs to the end of the extra menu
             if ( $usingGroupTabs ) {
                 foreach($fullModuleList as $moduleKey => $module ) {
                     if ( !isset($topTabs[$moduleKey]) && !isset($extraTabs[$moduleKey]) ) {
                         $extraTabs[$moduleKey] = $module;
                     }
                 }
             }
             */
             // Get a unique list of the top tabs so we can build the popup menus for them
             foreach ($topTabs as $moduleKey => $module) {
                 $topTabList[$moduleKey] = $module;
             }
             $groupTabs[$tabIdx]['modules'] = $topTabs;
             $groupTabs[$tabIdx]['extra'] = $extraTabs;
         }
     }
     if (isset($topTabList) && is_array($topTabList)) {
         // Adding shortcuts array to menu array for displaying shortcuts associated with each module
         $shortcutTopMenu = array();
         foreach ($topTabList as $module_key => $label) {
             global $mod_strings;
             $mod_strings = return_module_language($current_language, $module_key);
             foreach ($this->getMenu($module_key) as $key => $menu_item) {
                 $shortcutTopMenu[$module_key][$key] = array("URL" => $menu_item[0], "LABEL" => $menu_item[1], "MODULE_NAME" => $menu_item[2], "IMAGE" => $themeObject->getImage($menu_item[2], "border='0' align='absmiddle'", null, null, '.gif', $menu_item[1]), "ID" => $menu_item[2] . "_link");
             }
         }
         $ss->assign("groupTabs", $groupTabs);
         $ss->assign("shortcutTopMenu", $shortcutTopMenu);
         $ss->assign('USE_GROUP_TABS', $usingGroupTabs);
         // This is here for backwards compatibility, someday, somewhere, it will be able to be removed
         $ss->assign("moduleTopMenu", $groupTabs[$app_strings['LBL_TABGROUP_ALL']]['modules']);
         $ss->assign("moduleExtraMenu", $groupTabs[$app_strings['LBL_TABGROUP_ALL']]['extra']);
     }
     if (isset($extraTabs) && is_array($extraTabs)) {
         // Adding shortcuts array to extra menu array for displaying shortcuts associated with each module
         $shortcutExtraMenu = array();
         foreach ($extraTabs as $module_key => $label) {
             global $mod_strings;
             $mod_strings = return_module_language($current_language, $module_key);
             foreach ($this->getMenu($module_key) as $key => $menu_item) {
                 $shortcutExtraMenu[$module_key][$key] = array("URL" => $menu_item[0], "LABEL" => $menu_item[1], "MODULE_NAME" => $menu_item[2], "IMAGE" => $themeObject->getImage($menu_item[2], "border='0' align='absmiddle'", null, null, '.gif', $menu_item[1]), "ID" => $menu_item[2] . "_link");
             }
         }
         $ss->assign("shortcutExtraMenu", $shortcutExtraMenu);
     }
     if (!empty($current_user)) {
         $ss->assign("max_tabs", $current_user->getPreference("max_tabs"));
     }
     $imageURL = SugarThemeRegistry::current()->getImageURL("dashboard.png");
     $homeImage = "<img src='{$imageURL}'>";
     $ss->assign("homeImage", $homeImage);
     global $mod_strings;
     $mod_strings = $bakModStrings;
     $headerTpl = $themeObject->getTemplate('header.tpl');
     if (inDeveloperMode()) {
         $ss->clear_compiled_tpl($headerTpl);
     }
     if ($retModTabs) {
         return $ss->fetch($themeObject->getTemplate('_headerModuleList.tpl'));
     } else {
         $ss->display($headerTpl);
         $this->includeClassicFile('modules/Administration/DisplayWarnings.php');
         $errorMessages = SugarApplication::getErrorMessages();
         if (!empty($errorMessages)) {
             foreach ($errorMessages as $error_message) {
                 echo '<p class="error">' . $error_message . '</p>';
             }
         }
     }
 }
Пример #26
0
/**
 * Returns an input control for this fieldname given
 *
 * @param  string $module
 * @param  string $fieldname
 * @param  string $vardef
 * @param  string $value
 * @return string html for input element for this control
 */
function getControl($module, $fieldname, $vardef = null, $value = '')
{
    global $current_language, $app_strings, $dictionary, $app_list_strings, $current_user;
    // use the mod_strings for this module
    $mod_strings = return_module_language($current_language, $module);
    // set the filename for this control
    $file = create_cache_directory('modules/Import/') . $module . $fieldname . '.tpl';
    if (!is_file($file) || inDeveloperMode() || !empty($_SESSION['developerMode'])) {
        if (!isset($vardef)) {
            $focus = BeanFactory::getBean($module);
            $vardef = $focus->getFieldDefinition($fieldname);
        }
        // if this is the id relation field, then don't have a pop-up selector.
        if ($vardef['type'] == 'relate' && $vardef['id_name'] == $vardef['name']) {
            $vardef['type'] = 'varchar';
        }
        // create the dropdowns for the parent type fields
        if ($vardef['type'] == 'parent_type') {
            $vardef['type'] = 'enum';
        }
        // remove the special text entry field function 'getEmailAddressWidget'
        if (isset($vardef['function'])) {
            if (is_array($vardef['function']) && isset($vardef['function']['name'])) {
                $fn = $vardef['function']['name'];
            } else {
                $fn = $vardef['function'];
            }
            if ($fn === 'getEmailAddressWidget') {
                unset($vardef['function']);
            }
        }
        // load SugarFieldHandler to render the field tpl file
        static $sfh;
        if (!isset($sfh)) {
            require_once 'include/SugarFields/SugarFieldHandler.php';
            $sfh = new SugarFieldHandler();
        }
        $displayParams = array();
        $displayParams['formName'] = 'importstep3';
        $contents = $sfh->displaySmarty('fields', $vardef, 'ImportView', $displayParams);
        // Remove all the copyright comments
        $contents = preg_replace('/\\{\\*[^\\}]*?\\*\\}/', '', $contents);
        // hack to disable one of the js calls in this control
        if (isset($vardef['function'])) {
            if (is_array($vardef['function']) && isset($vardef['function']['name'])) {
                $fn = $vardef['function']['name'];
            } else {
                $fn = $vardef['function'];
            }
            if ($fn === 'getCurrencyDropDown' || $fn === 'getCurrencies') {
                $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}";
            }
        }
        // Save it to the cache file
        if ($fh = @sugar_fopen($file, 'w')) {
            fputs($fh, $contents);
            fclose($fh);
        }
    }
    // Now render the template we received
    $ss = new Sugar_Smarty();
    // Create Smarty variables for the Calendar picker widget
    global $timedate;
    $time_format = $timedate->get_user_time_format();
    $date_format = $timedate->get_cal_date_format();
    $ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
    $ss->assign('TIME_FORMAT', $time_format);
    $time_separator = ":";
    $match = array();
    if (preg_match('/\\d+([^\\d])\\d+([^\\d]*)/s', $time_format, $match)) {
        $time_separator = $match[1];
    }
    $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
    if (!isset($match[2]) || $match[2] == '') {
        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M");
    } else {
        $pm = $match[2] == "pm" ? "%P" : "%p";
        $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm);
    }
    $ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week());
    // populate the fieldlist from the vardefs
    $fieldlist = array();
    if (!isset($focus) || !$focus instanceof SugarBean) {
        $focus = BeanFactory::getBean($module);
    }
    // create the dropdowns for the parent type fields
    if ($vardef['type'] == 'parent_type') {
        $focus->field_defs[$vardef['name']]['options'] = $focus->field_defs[$vardef['group']]['options'];
    }
    $vardefFields = $focus->getFieldDefinitions();
    foreach ($vardefFields as $name => $properties) {
        $fieldlist[$name] = $properties;
        // fill in enums
        if (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']])) {
            $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']];
        } elseif (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']])) {
            $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']];
        }
        // Bug 22730: make sure all enums have the ability to select blank as the default value.
        if (isset($fieldlist[$name]['options']) && is_array($fieldlist[$name]['options']) && !isset($fieldlist[$name]['options'][''])) {
            $fieldlist[$name]['options'][''] = '';
        }
    }
    // fill in function return values
    if (!in_array($fieldname, array('email1', 'email2'))) {
        if (!empty($fieldlist[$fieldname]['function']['returns']) && $fieldlist[$fieldname]['function']['returns'] == 'html' || isset($fieldlist[$fieldname]['function']) && $fieldlist[$fieldname]['function'] == 'getCurrencies') {
            $doRegex = false;
            if (isset($fieldlist[$fieldname]['function']) && $fieldlist[$fieldname]['function'] == 'getCurrencies') {
                $doRegex = true;
                $function = 'getCurrencyDropDown';
            } else {
                $function = $fieldlist[$fieldname]['function']['name'];
            }
            // include various functions required in the various vardefs
            if (isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include'])) {
                require_once $fieldlist[$fieldname]['function']['include'];
            }
            $value = $function($focus, $fieldname, $value, 'EditView');
            // Bug 22730 - add a hack for the currency type dropdown, since it's built by a function.
            if (preg_match('/getCurrency.*DropDown/s', $function) || $doRegex) {
                $value = str_ireplace('</select>', '<option value="">' . $app_strings['LBL_NONE'] . '</option></select>', $value);
            }
        } elseif ($fieldname == 'assigned_user_name' && empty($value)) {
            $fieldlist['assigned_user_id']['value'] = $GLOBALS['current_user']->id;
            $value = $GLOBALS['current_user']->full_name;
        } elseif ($fieldname == 'team_name' && empty($value)) {
            $value = json_encode(array());
        }
    }
    $fieldlist[$fieldname]['value'] = $value;
    $ss->assign("fields", $fieldlist);
    $ss->assign("form_name", 'importstep3');
    $ss->assign("bean", $focus);
    // add in any additional strings
    $ss->assign("MOD", $mod_strings);
    $ss->assign("APP", $app_strings);
    return $ss->fetch($file);
}
Пример #27
0
function getJSPath($relative_path, $additional_attrs = '')
{
    if (defined('TEMPLATE_URL')) {
        $relative_path = SugarTemplateUtilities::getWebPath($relative_path);
    }
    if (empty($GLOBALS['sugar_config']['js_custom_version'])) {
        $GLOBALS['sugar_config']['js_custom_version'] = 1;
    }
    $js_version_key = isset($GLOBALS['js_version_key']) ? $GLOBALS['js_version_key'] : '';
    $path = $relative_path . '?s=' . $js_version_key . '&c=' . $GLOBALS['sugar_config']['js_custom_version'];
    if (inDeveloperMode()) {
        $path .= '&developerMode=' . mt_rand();
    }
    if (!empty($additonal_attrs)) {
        $path .= '&' . $additional_attrs;
    }
    return $path;
}
Пример #28
0
 /**
  * Capture PHP error output and handle it
  *
  * @param string $errorType The error type to hand down through the exception (default: 'php_error')
  * @throw SugarApiExceptionError
  */
 public function handleErrorOutput($errorType = 'php_error')
 {
     if (ob_get_level() > 0 && ob_get_length() > 0) {
         // Looks like something errored out first
         $errorOutput = ob_get_clean();
         if (trim($errorOutput) == '') {
             // whitespace only, we may let it slide on account of 6.x having broken templates with whitespace
             // See BR-1038
             return;
         }
         $GLOBALS['log']->error("A PHP error occurred:\n" . $errorOutput);
         $e = new SugarApiExceptionError();
         $e->errorLabel = $errorType;
         if (inDeveloperMode()) {
             $e->setExtraData('error_output', $errorOutput);
         }
         throw $e;
     }
 }