Beispiel #1
0
 function popup_select(&$bean, $event, $arguments)
 {
     global $sugar_config;
     //only process if action is Save (meaning a user has triggered this event and not the portal or automated process)
     if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'Save' && isset($sugar_config['securitysuite_popup_select']) && $sugar_config['securitysuite_popup_select'] == true && empty($bean->fetched_row['id']) && $bean->module_dir != "Users") {
         require_once 'modules/SecurityGroups/SecurityGroup.php';
         $groupFocus = new SecurityGroup();
         $security_modules = $groupFocus->getSecurityModules();
         //if(in_array($bean->module_dir,$security_modules)) {
         if (in_array($bean->module_dir, array_keys($security_modules))) {
             //check if user is in more than 1 group. If so then set the session var otherwise inherit it's only group
             global $current_user;
             $memberships = $groupFocus->getMembershipCount($current_user->id);
             if ($memberships > 1) {
                 $_REQUEST['return_module'] = $bean->module_dir;
                 $_REQUEST['return_action'] = "DetailView";
                 $_REQUEST['return_id'] = $bean->id;
                 $_SESSION['securitygroups_popup_' . $bean->module_dir] = $bean->id;
             } else {
                 if ($memberships == 1) {
                     $groupFocus->inheritOne($current_user->id, $bean->id, $bean->module_dir);
                 }
             }
         }
     }
     if (isset($sugar_config['securitysuite_user_popup']) && $sugar_config['securitysuite_user_popup'] == true && empty($bean->fetched_row['id']) && $bean->module_dir == "Users" && $_REQUEST['action'] != 'SaveSignature') {
         //Bug: 589
         $_REQUEST['return_module'] = $bean->module_dir;
         $_REQUEST['return_action'] = "DetailView";
         $_REQUEST['return_id'] = $bean->id;
         $_SESSION['securitygroups_popup_' . $bean->module_dir] = $bean->id;
     }
 }
 function inherit(&$focus, $isUpdate)
 {
     global $sugar_config;
     SecurityGroup::assign_default_groups($focus, $isUpdate);
     //this must be first because it does not check for dups
     SecurityGroup::inherit_assigned($focus, $isUpdate);
     SecurityGroup::inherit_parent($focus, $isUpdate);
     //don't do creator inheritance if popup selector method is chosen and a user is making the request...
     //don't if saving from a popup (subpanel_field_name check. Save2 is the action but to be safe use the subpanel check)
     if (isset($sugar_config['securitysuite_popup_select']) && $sugar_config['securitysuite_popup_select'] == true && isset($_REQUEST['action']) && $_REQUEST['action'] == 'Save' || !empty($_REQUEST['subpanel_field_name'])) {
         //check to see if a member of more than 1 group...if not then just inherit the one.
         //Otherwise, this is taken on the edit view on create now
         $groupFocus = new SecurityGroup();
         $security_modules = $groupFocus->getSecurityModules();
         if (in_array($focus->module_dir, array_keys($security_modules))) {
             //check if user is in more than 1 group. If so then set the session var otherwise inherit it's only group
             global $current_user;
             $memberships = $groupFocus->getMembershipCount($current_user->id);
             if ($memberships > 1) {
                 return;
             }
         }
     }
     SecurityGroup::inherit_creator($focus, $isUpdate);
 }
Beispiel #3
0
    /**
     * display
     * This method makes the Smarty variable assignments and then displays the
     * generated view.
     * @param $showTitle boolean value indicating whether or not to show a title on the resulting page
     * @param $ajaxSave boolean value indicating whether or not the operation is an Ajax save request
     * @return HTML display for view as String
     */
    function display($showTitle = true, $ajaxSave = false)
    {
        global $mod_strings, $sugar_config, $app_strings, $app_list_strings, $theme, $current_user;
        if (isset($this->defs['templateMeta']['javascript'])) {
            if (is_array($this->defs['templateMeta']['javascript'])) {
                //$this->th->ss->assign('externalJSFile', 'modules/' . $this->module . '/metadata/editvewdefs.js');
                $this->th->ss->assign('externalJSFile', $this->defs['templateMeta']['javascript']);
            } else {
                $this->th->ss->assign('scriptBlocks', $this->defs['templateMeta']['javascript']);
            }
        }
        $this->th->ss->assign('id', $this->fieldDefs['id']['value']);
        $this->th->ss->assign('offset', $this->offset + 1);
        $this->th->ss->assign('APP', $app_strings);
        $this->th->ss->assign('MOD', $mod_strings);
        $this->th->ss->assign('fields', $this->fieldDefs);
        $this->th->ss->assign('sectionPanels', $this->sectionPanels);
        $this->th->ss->assign('config', $sugar_config);
        $this->th->ss->assign('returnModule', $this->returnModule);
        $this->th->ss->assign('returnAction', $this->returnAction);
        $this->th->ss->assign('returnId', $this->returnId);
        $this->th->ss->assign('isDuplicate', $this->isDuplicate);
        $this->th->ss->assign('def', $this->defs);
        $this->th->ss->assign('useTabs', isset($this->defs['templateMeta']['useTabs']) && isset($this->defs['templateMeta']['tabDefs']) ? $this->defs['templateMeta']['useTabs'] : false);
        $this->th->ss->assign('maxColumns', isset($this->defs['templateMeta']['maxColumns']) ? $this->defs['templateMeta']['maxColumns'] : 2);
        $this->th->ss->assign('module', $this->module);
        $this->th->ss->assign('headerTpl', isset($this->defs['templateMeta']['form']['headerTpl']) ? $this->defs['templateMeta']['form']['headerTpl'] : 'include/' . $this->view . '/header.tpl');
        $this->th->ss->assign('footerTpl', isset($this->defs['templateMeta']['form']['footerTpl']) ? $this->defs['templateMeta']['form']['footerTpl'] : 'include/' . $this->view . '/footer.tpl');
        $this->th->ss->assign('current_user', $current_user);
        $this->th->ss->assign('bean', $this->focus);
        $this->th->ss->assign('isAuditEnabled', $this->focus->is_AuditEnabled());
        $this->th->ss->assign('gridline', $current_user->getPreference('gridline') == 'on' ? '1' : '0');
        $this->th->ss->assign('tabDefs', isset($this->defs['templateMeta']['tabDefs']) ? $this->defs['templateMeta']['tabDefs'] : false);
        $this->th->ss->assign('VERSION_MARK', getVersionedPath(''));
        global $js_custom_version;
        global $sugar_version;
        $this->th->ss->assign('SUGAR_VERSION', $sugar_version);
        $this->th->ss->assign('JS_CUSTOM_VERSION', $js_custom_version);
        //this is used for multiple forms on one page
        if (!empty($this->formName)) {
            $form_id = $this->formName;
            $form_name = $this->formName;
        } else {
            $form_id = $this->view;
            $form_name = $this->view;
        }
        if ($ajaxSave && empty($this->formName)) {
            $form_id = 'form_' . $this->view . '_' . $this->module;
            $form_name = $form_id;
            $this->view = $form_name;
            //$this->defs['templateMeta']['form']['buttons'] = array();
            //$this->defs['templateMeta']['form']['buttons']['ajax_save'] = array('id' => 'AjaxSave', 'customCode'=>'<input type="button" class="button" value="Save" onclick="this.form.action.value=\'AjaxFormSave\';return saveForm(\''.$form_name.'\', \'multiedit_form_{$module}\', \'Saving {$module}...\');"/>');
        }
        $form_name = $form_name == 'QuickCreate' ? "QuickCreate_{$this->module}" : $form_name;
        $form_id = $form_id == 'QuickCreate' ? "QuickCreate_{$this->module}" : $form_id;
        if (isset($this->defs['templateMeta']['preForm'])) {
            $this->th->ss->assign('preForm', $this->defs['templateMeta']['preForm']);
        }
        if (isset($this->defs['templateMeta']['form']['closeFormBeforeCustomButtons'])) {
            $this->th->ss->assign('closeFormBeforeCustomButtons', $this->defs['templateMeta']['form']['closeFormBeforeCustomButtons']);
        }
        if (isset($this->defs['templateMeta']['form']['enctype'])) {
            $this->th->ss->assign('enctype', 'enctype="' . $this->defs['templateMeta']['form']['enctype'] . '"');
        }
        //for SugarFieldImage, we must set form enctype to "multipart/form-data"
        foreach ($this->fieldDefs as $field) {
            if (isset($field['type']) && $field['type'] == 'image') {
                $this->th->ss->assign('enctype', 'enctype="multipart/form-data"');
                break;
            }
        }
        $this->th->ss->assign('showDetailData', $this->showDetailData);
        $this->th->ss->assign('showSectionPanelsTitles', $this->showSectionPanelsTitles);
        $this->th->ss->assign('form_id', $form_id);
        $this->th->ss->assign('form_name', $form_name);
        $this->th->ss->assign('set_focus_block', get_set_focus_js());
        $this->th->ss->assign('form', isset($this->defs['templateMeta']['form']) ? $this->defs['templateMeta']['form'] : null);
        $this->th->ss->assign('includes', isset($this->defs['templateMeta']['includes']) ? $this->defs['templateMeta']['includes'] : null);
        $this->th->ss->assign('view', $this->view);
        //Calculate time & date formatting (may need to calculate this depending on a setting)
        global $timedate;
        $this->th->ss->assign('CALENDAR_DATEFORMAT', $timedate->get_cal_date_format());
        $this->th->ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
        $time_format = $timedate->get_user_time_format();
        $this->th->ss->assign('TIME_FORMAT', $time_format);
        $date_format = $timedate->get_cal_date_format();
        $time_separator = ':';
        if (preg_match('/\\d+([^\\d])\\d+([^\\d]*)/s', $time_format, $match)) {
            $time_separator = $match[1];
        }
        // Create Smarty variables for the Calendar picker widget
        $t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
        if (!isset($match[2]) || $match[2] == '') {
            $this->th->ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . '%M');
        } else {
            $pm = $match[2] == 'pm' ? '%P' : '%p';
            $this->th->ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . '%M' . $pm);
        }
        $this->th->ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week());
        $this->th->ss->assign('TIME_SEPARATOR', $time_separator);
        $seps = get_number_seperators();
        $this->th->ss->assign('NUM_GRP_SEP', $seps[0]);
        $this->th->ss->assign('DEC_SEP', $seps[1]);
        if ($this->view == 'EditView') {
            $height = $current_user->getPreference('text_editor_height');
            $width = $current_user->getPreference('text_editor_width');
            $height = isset($height) ? $height : '300px';
            $width = isset($width) ? $width : '95%';
            $this->th->ss->assign('RICH_TEXT_EDITOR_HEIGHT', $height);
            $this->th->ss->assign('RICH_TEXT_EDITOR_WIDTH', $width);
        } else {
            $this->th->ss->assign('RICH_TEXT_EDITOR_HEIGHT', '100px');
            $this->th->ss->assign('RICH_TEXT_EDITOR_WIDTH', '95%');
        }
        $this->th->ss->assign('SHOW_VCR_CONTROL', $this->showVCRControl);
        $str = $this->showTitle($showTitle);
        //Use the output filter to trim the whitespace
        $this->th->ss->load_filter('output', 'trimwhitespace');
        $str .= $this->th->displayTemplate($this->module, $form_name, $this->tpl, $ajaxSave, $this->defs);
        /* BEGIN - SECURITY GROUPS */
        //if popup select add panel if user is a member of multiple groups to metadataFile
        global $sugar_config;
        if (isset($sugar_config['securitysuite_popup_select']) && $sugar_config['securitysuite_popup_select'] == true && empty($this->focus->fetched_row['id']) && $this->focus->module_dir != "Users" && $this->focus->module_dir != "SugarFeed") {
            //there are cases such as uploading an attachment to an email template where the request module may
            //not be the same as the current bean module. If that happens we can just skip it
            //however...let quickcreate through
            if ($this->view != 'QuickCreate' && (empty($_REQUEST['module']) || $_REQUEST['module'] != $this->focus->module_dir)) {
                return $str;
            }
            require_once 'modules/SecurityGroups/SecurityGroup.php';
            $groupFocus = new SecurityGroup();
            $security_modules = $groupFocus->getSecurityModules();
            if (in_array($this->focus->module_dir, array_keys($security_modules))) {
                global $current_user;
                $group_count = $groupFocus->getMembershipCount($current_user->id);
                if ($group_count > 1) {
                    $groups = $groupFocus->getUserSecurityGroups($current_user->id);
                    $group_options = '';
                    foreach ($groups as $group) {
                        $group_options .= '<option value="' . $group['id'] . '" label="' . $group['name'] . '" selected="selected">' . $group['name'] . '</option>';
                    }
                    //multilingual support
                    global $current_language;
                    $ss_mod_strings = return_module_language($current_language, 'SecurityGroups');
                    $lbl_securitygroups_select = $ss_mod_strings['LBL_GROUP_SELECT'];
                    $lbl_securitygroups = $ss_mod_strings['LBL_LIST_FORM_TITLE'];
                    $group_panel = <<<EOQ
<div class="edit view edit508 " id="detailpanel_securitygroups">
    <h4>&nbsp;&nbsp;
    {$lbl_securitygroups_select}
    </h4>
    <table width="100%" cellspacing="1" cellpadding="0" border="0" class="edit view panelContainer" id="LBL_PANEL_SECURITYGROUPS">
    <tbody><tr>
    <td width="12.5%" valign="top" scope="col" id="account_type_label">
        {$lbl_securitygroups}:
    </td>
    <td width="37.5%" valign="top">
        <select title="" id="securitygroup_list" name="securitygroup_list[]" multiple="multiple" size="{$group_count}">
        {$group_options}
        </select>
    </td>
    </tr>
    </tbody></table>
</div>
EOQ;
                    $group_panel = preg_replace("/[\r\n]+/", "", $group_panel);
                    $group_panel_append = <<<EOQ
<script>
    \$('#{$form_name}_tabs div:first').append(\$('{$group_panel}'));
</script>
EOQ;
                    $str .= $group_panel_append;
                }
            }
        }
        /* END - SECURITY GROUPS */
        return $str;
    }
 public function testgetMembershipCount()
 {
     //unset and reconnect Db to resolve mysqli fetch exeception
     global $db;
     unset($db->database);
     $db->checkConnection();
     $securityGroup = new SecurityGroup();
     $result = $securityGroup->getMembershipCount('1');
     $this->assertEquals(0, $result);
 }