Пример #1
0
 function build()
 {
     //we will assume that if the ListView.html file exists we will want to use that one
     if (SugarAutoLoader::fileExists('modules/' . $this->module . '/ListView.html')) {
         $this->type = 1;
         $this->lv = new ListView();
         $this->template = 'modules/' . $this->module . '/ListView.html';
     } else {
         $metadataFile = SugarAutoLoader::loadWithMetafiles($this->module, 'listviewdefs');
         if ($metadataFile) {
             require $metadataFile;
         }
         SugarACL::listFilter($this->module, $listViewDefs[$this->module], array("owner_override" => true));
         $this->lv = new ListViewSmarty();
         $displayColumns = array();
         if (!empty($_REQUEST['displayColumns'])) {
             foreach (explode('|', $_REQUEST['displayColumns']) as $num => $col) {
                 if (!empty($listViewDefs[$this->module][$col])) {
                     $displayColumns[$col] = $listViewDefs[$this->module][$col];
                 }
             }
         } else {
             if (isset($listViewDefs[$this->module])) {
                 foreach ($listViewDefs[$this->module] as $col => $params) {
                     if (!empty($params['default']) && $params['default']) {
                         $displayColumns[$col] = $params;
                     }
                 }
             }
         }
         $this->lv->displayColumns = $displayColumns;
         $this->type = 2;
         $this->template = 'include/ListView/ListViewGeneric.tpl';
     }
 }
Пример #2
0
 function setup($file)
 {
     if (isset($this->_popupMeta)) {
         if (isset($this->_popupMeta['create']['formBase'])) {
             require_once 'modules/' . $this->seed->module_dir . '/' . $this->_popupMeta['create']['formBase'];
             $this->_create = true;
         }
     }
     if (!empty($this->_popupMeta['create'])) {
         $formBase = new $this->_popupMeta['create']['formBaseClass']();
         if (isset($_REQUEST['doAction']) && $_REQUEST['doAction'] == 'save') {
             //If it's a new record, set useRequired to false
             $useRequired = empty($_REQUEST['id']) ? false : true;
             $formBase->handleSave('', false, $useRequired);
         }
     }
     $params = array();
     if (!empty($this->_popupMeta['orderBy'])) {
         $params['orderBy'] = $this->_popupMeta['orderBy'];
     }
     $searchFields = SugarAutoLoader::loadSearchFields($this->module);
     $this->searchdefs[$this->module]['templateMeta']['maxColumns'] = 2;
     $this->searchdefs[$this->module]['templateMeta']['widths']['label'] = 10;
     $this->searchdefs[$this->module]['templateMeta']['widths']['field'] = 30;
     $this->searchForm->view = 'PopupSearchForm';
     $this->searchForm->setup($this->searchdefs, $searchFields, 'SearchFormGenericAdvanced.tpl', 'advanced_search', $this->listviewdefs);
     $lv = new ListViewSmarty();
     $displayColumns = array();
     if (!empty($_REQUEST['displayColumns'])) {
         foreach (explode('|', $_REQUEST['displayColumns']) as $num => $col) {
             if (!empty($listViewDefs[$this->module][$col])) {
                 $displayColumns[$col] = $this->listviewdefs[$this->module][$col];
             }
         }
     } else {
         foreach ($this->listviewdefs[$this->module] as $col => $para) {
             if (!empty($para['default']) && $para['default']) {
                 $displayColumns[$col] = $para;
             }
         }
     }
     $params['massupdate'] = true;
     if (!empty($_REQUEST['orderBy'])) {
         $params['orderBy'] = $_REQUEST['orderBy'];
         $params['overrideOrder'] = true;
         if (!empty($_REQUEST['sortOrder'])) {
             $params['sortOrder'] = $_REQUEST['sortOrder'];
         }
     }
     $lv->displayColumns = $displayColumns;
     $this->searchForm->lv = $lv;
     $this->searchForm->displaySavedSearch = false;
     SugarACL::listFilter($this->module, $this->searchForm->fieldDefs, array("owner_override" => true), array("use_value" => true, "suffix" => '_advanced', "add_acl" => true));
     $this->searchForm->populateFromRequest('advanced_search');
     $searchWhere = $this->_get_where_clause();
     $this->searchColumns = $this->searchForm->searchColumns;
     //parent::setup($this->seed, $file, $searchWhere, $params, 0, -1, $this->filter_fields);
     $this->should_process = true;
     if (isset($params['export'])) {
         $this->export = $params['export'];
     }
     if (!empty($params['multiSelectPopup'])) {
         $this->multi_select_popup = $params['multiSelectPopup'];
     }
     if (!empty($params['massupdate']) && $params['massupdate'] != false) {
         $this->show_mass_update_form = true;
         $this->mass = new MassUpdate();
         $this->mass->setSugarBean($this->seed);
         if (!empty($params['handleMassupdate']) || !isset($params['handleMassupdate'])) {
             $this->mass->handleMassUpdate();
         }
     }
     // create filter fields based off of display columns
     if (empty($this->filter_fields) || $this->mergeDisplayColumns) {
         foreach ($this->displayColumns as $columnName => $def) {
             $this->filter_fields[strtolower($columnName)] = true;
             if (!empty($def['related_fields'])) {
                 foreach ($def['related_fields'] as $field) {
                     //id column is added by query construction function. This addition creates duplicates
                     //and causes issues in oracle. #10165
                     if ($field != 'id') {
                         $this->filter_fields[$field] = true;
                     }
                 }
             }
             if (!empty($this->seed->field_defs[strtolower($columnName)]['db_concat_fields'])) {
                 foreach ($this->seed->field_defs[strtolower($columnName)]['db_concat_fields'] as $index => $field) {
                     if (!isset($this->filter_fields[strtolower($field)]) || !$this->filter_fields[strtolower($field)]) {
                         $this->filter_fields[strtolower($field)] = true;
                     }
                 }
             }
         }
         foreach ($this->searchColumns as $columnName => $def) {
             $this->filter_fields[strtolower($columnName)] = true;
         }
     }
     /**
      * Bug #46842 : The relate field field_to_name_array fails to copy over custom fields
      * By default bean's create_new_list_query function loads fields displayed on the page or used in the search
      * add fields used to populate forms from _viewdefs :: field_to_name_array to retrive from db
      */
     if (isset($_REQUEST['field_to_name']) && $_REQUEST['field_to_name']) {
         $_REQUEST['field_to_name'] = is_array($_REQUEST['field_to_name']) ? $_REQUEST['field_to_name'] : array($_REQUEST['field_to_name']);
         foreach ($_REQUEST['field_to_name'] as $add_field) {
             $add_field = strtolower($add_field);
             if ($add_field != 'id' && !isset($this->filter_fields[$add_field]) && isset($this->seed->field_defs[$add_field])) {
                 $this->filter_fields[$add_field] = true;
             }
         }
     } else {
         if (isset($_REQUEST['request_data'])) {
             $request_data = get_object_vars(json_decode(htmlspecialchars_decode($_REQUEST['request_data'])));
             $request_data['field_to_name'] = get_object_vars($request_data['field_to_name_array']);
             if (isset($request_data['field_to_name']) && is_array($request_data['field_to_name'])) {
                 foreach ($request_data['field_to_name'] as $add_field) {
                     $add_field = strtolower($add_field);
                     if ($add_field != 'id' && !isset($this->filter_fields[$add_field]) && isset($this->seed->field_defs[$add_field])) {
                         $this->filter_fields[$add_field] = true;
                     }
                 }
             }
         }
     }
     //check for team_set_count
     if (!empty($this->filter_fields['team_name']) && empty($this->filter_fields['team_count'])) {
         $this->filter_fields['team_count'] = true;
         $this->displayColumns['TEAM_NAME']['type'] = 'teamset';
         $this->displayColumns['TEAM_NAME']['width'] = '2';
         $this->displayColumns['TEAM_NAME']['label'] = 'LBL_LIST_TEAM';
         unset($this->displayColumns['TEAM_NAME']['link']);
         //Add the team_id entry so that we can retrieve the team_id to display primary team
         $this->filter_fields['team_id'] = true;
     }
     if (!empty($_REQUEST['query']) || !empty($GLOBALS['sugar_config']['save_query']) && $GLOBALS['sugar_config']['save_query'] != 'populate_only') {
         $data = $this->lvd->getListViewData($this->seed, $searchWhere, 0, -1, $this->filter_fields, $params, 'id');
     } else {
         $this->should_process = false;
         $data = array('data' => array(), 'pageData' => array('bean' => array('moduleDir' => $this->seed->module_dir), 'ordering' => '', 'offsets' => array('total' => 0, 'next' => 0, 'current' => 0)));
     }
     $this->fillDisplayColumnsWithVardefs();
     $data = $this->setupHTMLFields($data);
     $this->process($file, $data, $this->seed->object_name);
 }
Пример #3
0
 /**
  * Gets the ACL's for the module, will also expand them so the client side of the ACL's don't have to do as many checks.
  *
  * @param  string $module     The module we want to fetch the ACL for
  * @param  object $userObject The user object for the ACL's we are retrieving.
  * @param  object|bool $bean       The SugarBean for getting specific ACL's for a module
  * @param bool $showYes Do not unset Yes Results
  * @return array       Array of ACL's, first the action ACL's (access, create, edit, delete) then an array of the field level acl's
  */
 public function getAclForModule($module, $userObject, $bean = false, $showYes = false)
 {
     $outputAcl = array('fields' => array());
     $outputAcl['admin'] = $userObject->isAdminForModule($module) ? 'yes' : 'no';
     $outputAcl['developer'] = $userObject->isDeveloperForModule($module) ? 'yes' : 'no';
     if (!SugarACL::moduleSupportsACL($module)) {
         foreach (array('access', 'view', 'list', 'edit', 'delete', 'import', 'export', 'massupdate') as $action) {
             $outputAcl[$action] = 'yes';
         }
     } else {
         $context = array('user' => $userObject);
         if ($bean instanceof SugarBean) {
             $context['bean'] = $bean;
         }
         // if the bean is not set, or a new bean.. set the owner override
         // this will allow fields marked Owner to pass through ok.
         if ($bean == false || empty($bean->id) || isset($bean->new_with_id) && $bean->new_with_id == true) {
             $context['owner_override'] = true;
         }
         $moduleAcls = SugarACL::getUserAccess($module, array(), $context);
         // Bug56391 - Use the SugarACL class to determine access to different actions within the module
         foreach (SugarACL::$all_access as $action => $bool) {
             $outputAcl[$action] = $moduleAcls[$action] == true || !isset($moduleAcls[$action]) ? 'yes' : 'no';
         }
         // Only loop through the fields if we have a reason to, admins give full access on everything, no access gives no access to anything
         if ($outputAcl['access'] == 'yes') {
             // Currently create just uses the edit permission, but there is probably a need for a separate permission for create
             $outputAcl['create'] = $outputAcl['edit'];
             if ($bean === false) {
                 $bean = BeanFactory::newBean($module);
             }
             // we cannot use ACLField::getAvailableFields because it limits the fieldset we return.  We need all fields
             // for instance assigned_user_id is skipped in getAvailableFields, thus making the acl's look odd if Assigned User has ACL's
             // only assigned_user_name is returned which is a derived ["fake"] field.  We really need assigned_user_id to return as well.
             if (empty($GLOBALS['dictionary'][$bean->object_name]['fields'])) {
                 if (empty($bean->acl_fields)) {
                     $fieldsAcl = array();
                 } else {
                     $fieldsAcl = $bean->field_defs;
                 }
             } else {
                 $fieldsAcl = $GLOBALS['dictionary'][$bean->object_name]['fields'];
                 if (isset($GLOBALS['dictionary'][$bean->object_name]['acl_fields']) && $GLOBALS['dictionary'][$bean->object_name] === false) {
                     $fieldsAcl = array();
                 }
             }
             // get the field names
             SugarACL::listFilter($module, $fieldsAcl, $context, array('add_acl' => true));
             $fieldsAcl = $this->getMetaDataHacks()->fixAcls($fieldsAcl);
             foreach ($fieldsAcl as $field => $fieldAcl) {
                 switch ($fieldAcl['acl']) {
                     case SugarACL::ACL_READ_WRITE:
                         // Default, don't need to send anything down
                         break;
                     case SugarACL::ACL_READ_ONLY:
                         $outputAcl['fields'][$field]['write'] = 'no';
                         $outputAcl['fields'][$field]['create'] = 'no';
                         break;
                     case 2:
                         $outputAcl['fields'][$field]['read'] = 'no';
                         break;
                     case SugarACL::ACL_NO_ACCESS:
                     default:
                         $outputAcl['fields'][$field]['read'] = 'no';
                         $outputAcl['fields'][$field]['write'] = 'no';
                         $outputAcl['fields'][$field]['create'] = 'no';
                         break;
                 }
             }
         }
     }
     // there are times when we need the yes results, for instance comparing access for a record
     if ($showYes === false) {
         // for brevity, filter out 'yes' fields since UI assumes 'yes'
         foreach ($outputAcl as $k => $v) {
             if ($v == 'yes') {
                 unset($outputAcl[$k]);
             }
         }
     }
     $outputAcl['_hash'] = $this->hashChunk($outputAcl);
     return $outputAcl;
 }
Пример #4
0
 /**
  * Filter list of fields and remove/blank fields that we can not access
  * Modifies the list directly.
  * @param array $list list of fields, keys are field names
  * @param array $context
  * @param array options Filtering options:
  * - blank_value (bool) - instead of removing inaccessible field put '' there
  * - add_acl (bool) - instead of removing fields add 'acl' value with access level
  * - suffix (string) - strip suffix from field names
  * - min_access (int) - require this level of access for field
  * - use_value (bool) - look for field name in value, not in key of the list
  */
 public function ACLFilterFieldList(&$list, $context = array(), $options = array())
 {
     if (empty($context['bean'])) {
         $context['bean'] = $this;
     }
     SugarACL::listFilter($this->getACLCategory(), $list, $context, $options);
 }
Пример #5
0
 function aSubPanel($name, $instance_properties, $parent_bean, $reload = false, $original_only = false, $forApi = false)
 {
     $this->_instance_properties = $instance_properties;
     $this->name = $name;
     $this->parent_bean = $parent_bean;
     //set language
     global $current_language;
     if (!isset($parent_bean->mbvardefs)) {
         $mod_strings = return_module_language($current_language, $parent_bean->module_dir);
     }
     $this->mod_strings = $mod_strings;
     if ($this->isCollection()) {
         $this->canDisplay = $this->load_sub_subpanels();
         //load sub-panel definition.
     } else {
         if (!SugarAutoLoader::existing('modules/' . $this->_instance_properties['module'])) {
             $GLOBALS['log']->fatal("Directory for {$this->_instance_properties['module']} does not exist!");
         }
         $def_path = array('modules/' . $this->_instance_properties['module'] . '/metadata/subpanels/' . $this->_instance_properties['subpanel_name'] . '.php');
         if (!$original_only) {
             $def_path[] = 'custom/' . $def_path[0];
             if (isset($this->_instance_properties['override_subpanel_name'])) {
                 $def_path[] = 'custom/modules/' . $this->_instance_properties['module'] . '/metadata/subpanels/' . $this->_instance_properties['override_subpanel_name'] . '.php';
             }
         }
         $loaded = false;
         foreach (SugarAutoLoader::existing($def_path) as $file) {
             require $file;
             $loaded = true;
         }
         if (!$loaded) {
             $defaultSubpanelFile = "modules/{$this->_instance_properties['module']}/metadata/subpanels/default.php";
             if (!file_exists($defaultSubpanelFile)) {
                 $GLOBALS['log']->fatal("Failed to load original or custom subpanel data for {$name} in " . join(DIRECTORY_SEPARATOR, $def_path));
                 $this->canDisplay = false;
             } else {
                 require $defaultSubpanelFile;
             }
         }
         // load module info from the module's bean file
         $this->load_module_info();
         // check that the loaded subpanel definition includes a $subpanel_layout section - some, such as
         // projecttasks/default do not...
         $this->panel_definition = array();
         if (isset($subpanel_layout) && is_array($subpanel_layout)) {
             $this->set_panel_definition($subpanel_layout);
             if (!$forApi) {
                 SugarACL::listFilter($this->_instance_properties['module'], $this->panel_definition['list_fields'], array("owner_override" => true));
             }
         }
     }
 }
Пример #6
0
 function display($header = true)
 {
     global $theme, $timedate, $current_user;
     $header_txt = '';
     $footer_txt = '';
     $return_txt = '';
     $this->th->ss->assign('module', $this->module);
     $this->th->ss->assign('action', $this->action);
     SugarACL::listFilter($this->module, $this->fieldDefs, array("owner_override" => true), array("use_value" => true, "suffix" => '_' . $this->parsedView, "add_acl" => true));
     $this->th->ss->assign('displayView', $this->displayView);
     $this->th->ss->assign('APP', $GLOBALS['app_strings']);
     //Show the tabs only if there is more than one
     if ($this->nbTabs > 1) {
         $this->th->ss->assign('TABS', $this->_displayTabs($this->module . '|' . $this->displayView));
     }
     $this->th->ss->assign('searchTableColumnCount', (isset($this->searchdefs['templateMeta']['maxColumns']) ? $this->searchdefs['templateMeta']['maxColumns'] : 2) * 2 - 1);
     $this->th->ss->assign('fields', $this->fieldDefs);
     $this->th->ss->assign('customFields', $this->customFieldDefs);
     $this->th->ss->assign('formData', $this->formData);
     $time_format = $timedate->get_user_time_format();
     $this->th->ss->assign('TIME_FORMAT', $time_format);
     $this->th->ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
     $this->th->ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week());
     $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('TIME_SEPARATOR', $time_separator);
     //Show and hide the good tab form
     foreach ($this->tabs as $tabkey => $viewtab) {
         $viewName = str_replace(array($this->module . '|', '_search'), '', $viewtab['key']);
         if (strpos($this->view, $viewName) !== false) {
             $this->tabs[$tabkey]['displayDiv'] = '';
             //if this is advanced tab, use form with saved search sub form built in
             if ($viewName == 'advanced') {
                 $this->tpl = 'SearchFormGenericAdvanced.tpl';
                 if ($this->action == 'ListView') {
                     $this->th->ss->assign('DISPLAY_SEARCH_HELP', true);
                 }
                 $this->th->ss->assign('DISPLAY_SAVED_SEARCH', $this->displaySavedSearch);
                 $this->th->ss->assign('SAVED_SEARCH', $this->displaySavedSearch());
                 //this determines whether the saved search subform should be rendered open or not
                 if (isset($_REQUEST['showSSDIV']) && $_REQUEST['showSSDIV'] == 'yes') {
                     $this->th->ss->assign('SHOWSSDIV', 'yes');
                     $this->th->ss->assign('DISPLAYSS', '');
                 } else {
                     $this->th->ss->assign('SHOWSSDIV', 'no');
                     $this->th->ss->assign('DISPLAYSS', 'display:none');
                 }
             }
         } else {
             $this->tabs[$tabkey]['displayDiv'] = 'display:none';
         }
     }
     $this->th->ss->assign('TAB_ARRAY', $this->tabs);
     $totalWidth = 0;
     if (isset($this->searchdefs['templateMeta']['widths']) && isset($this->searchdefs['templateMeta']['maxColumns'])) {
         $totalWidth = ($this->searchdefs['templateMeta']['widths']['label'] + $this->searchdefs['templateMeta']['widths']['field']) * $this->searchdefs['templateMeta']['maxColumns'];
         // redo the widths in case they are too big
         if ($totalWidth > 100) {
             $resize = 100 / $totalWidth;
             $this->searchdefs['templateMeta']['widths']['label'] = $this->searchdefs['templateMeta']['widths']['label'] * $resize;
             $this->searchdefs['templateMeta']['widths']['field'] = $this->searchdefs['templateMeta']['widths']['field'] * $resize;
         }
     }
     $this->th->ss->assign('templateMeta', $this->searchdefs['templateMeta']);
     $this->th->ss->assign('HAS_ADVANCED_SEARCH', !empty($this->searchdefs['layout']['advanced_search']));
     $this->th->ss->assign('displayType', $this->displayType);
     // return the form of the shown tab only
     if ($this->showSavedSearchesOptions) {
         $this->th->ss->assign('SAVED_SEARCHES_OPTIONS', $this->displaySavedSearchSelect());
     }
     if ($this->module == 'Documents') {
         $this->th->ss->assign('DOCUMENTS_MODULE', true);
     }
     $return_txt = $this->th->displayTemplate($this->seed->module_dir, 'SearchForm_' . $this->parsedView, $this->locateFile($this->tpl));
     if ($header) {
         $this->th->ss->assign('return_txt', $return_txt);
         $header_txt = $this->th->displayTemplate($this->seed->module_dir, 'SearchFormHeader', $this->locateFile('header.tpl'));
         //pass in info to render the select dropdown below the form
         $footer_txt = $this->th->displayTemplate($this->seed->module_dir, 'SearchFormFooter', $this->locateFile('footer.tpl'));
         $return_txt = $header_txt . $footer_txt;
     }
     return $return_txt;
 }