Пример #1
0
if (!isset($where)) {
    $where = "";
}
require_once 'modules/MySettings/StoreQuery.php';
$storeQuery = new StoreQuery();
if (!isset($_REQUEST['query'])) {
    $storeQuery->loadQuery($currentModule);
    $storeQuery->populateRequest();
} else {
    $storeQuery->saveFromGet($currentModule);
}
if (isset($_REQUEST['query'])) {
    // we have a query
    // first save columns
    $current_user->setPreference('ListViewDisplayColumns', $displayColumns, 0, $currentModule);
    $searchForm->populateFromRequest();
    // gathers search field inputs from $_REQUEST
    $where_clauses = $searchForm->generateSearchWhere(true, "Products");
    // builds the where clause from search field inputs
    if (count($where_clauses) > 0) {
        $where = implode(' and ', $where_clauses);
    }
    $GLOBALS['log']->info("Here is the where clause for the list view: {$where}");
}
// start display
// which tab of search form to display
if (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
    $searchForm->setup();
    if (isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'advanced_search') {
        $searchForm->displayAdvanced();
    } elseif (isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'saved_views') {
Пример #2
0
 function display()
 {
     if (!$this->bean->ACLAccess('list')) {
         ACLController::displayNoAccess();
         return;
     }
     $module = $GLOBALS['module'];
     $metadataFile = null;
     $foundViewDefs = false;
     if (file_exists('custom/modules/' . $module . '/metadata/listviewdefs.php')) {
         $metadataFile = 'custom/modules/' . $module . '/metadata/listviewdefs.php';
         $foundViewDefs = true;
     } else {
         if (file_exists('custom/modules/' . $module . '/metadata/metafiles.php')) {
             require_once 'custom/modules/' . $module . '/metadata/metafiles.php';
             if (!empty($metafiles[$module]['listviewdefs'])) {
                 $metadataFile = $metafiles[$module]['listviewdefs'];
                 $foundViewDefs = true;
             }
         } elseif (file_exists('modules/' . $module . '/metadata/metafiles.php')) {
             require_once 'modules/' . $module . '/metadata/metafiles.php';
             if (!empty($metafiles[$module]['listviewdefs'])) {
                 $metadataFile = $metafiles[$module]['listviewdefs'];
                 $foundViewDefs = true;
             }
         }
     }
     if (!$foundViewDefs && file_exists('modules/' . $module . '/metadata/listviewdefs.php')) {
         $metadataFile = 'modules/' . $module . '/metadata/listviewdefs.php';
     }
     require_once $metadataFile;
     $seed = $this->bean;
     if (!empty($this->bean->object_name) && isset($_REQUEST[$module . '2_' . strtoupper($this->bean->object_name) . '_offset'])) {
         //if you click the pagination button, it will poplate the search criteria here
         if (!empty($_REQUEST['current_query_by_page'])) {
             //The code support multi browser tabs pagination
             $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', 'request_data', 'current_query_by_page', $module . '2_' . strtoupper($this->bean->object_name) . '_ORDER_BY');
             if (isset($_REQUEST['lvso'])) {
                 $blockVariables[] = 'lvso';
             }
             $current_query_by_page = unserialize(base64_decode($_REQUEST['current_query_by_page']));
             foreach ($current_query_by_page as $search_key => $search_value) {
                 if ($search_key != $module . '2_' . strtoupper($this->bean->object_name) . '_offset' && !in_array($search_key, $blockVariables)) {
                     if (!is_array($search_value)) {
                         $_REQUEST[$search_key] = $GLOBALS['db']->quoteForEmail($search_value);
                     } else {
                         foreach ($search_value as $key => &$val) {
                             $val = $GLOBALS['db']->quoteForEmail($val);
                         }
                         $_REQUEST[$search_key] = $search_value;
                     }
                 }
             }
         }
     }
     if (!empty($_REQUEST['saved_search_select']) && $_REQUEST['saved_search_select'] != '_none') {
         if (empty($_REQUEST['button']) && (empty($_REQUEST['clear_query']) || $_REQUEST['clear_query'] != 'true')) {
             $this->saved_search = loadBean('SavedSearch');
             $this->saved_search->retrieveSavedSearch($_REQUEST['saved_search_select']);
             $this->saved_search->populateRequest();
         } elseif (!empty($_REQUEST['button'])) {
             // click the search button, after retrieving from saved_search
             $_SESSION['LastSavedView'][$_REQUEST['module']] = '';
             unset($_REQUEST['saved_search_select']);
             unset($_REQUEST['saved_search_select_name']);
         }
     }
     $lv = new ListViewSmarty();
     $displayColumns = array();
     if (!empty($_REQUEST['displayColumns'])) {
         foreach (explode('|', $_REQUEST['displayColumns']) as $num => $col) {
             if (!empty($listViewDefs[$module][$col])) {
                 $displayColumns[$col] = $listViewDefs[$module][$col];
             }
         }
     } else {
         foreach ($listViewDefs[$module] as $col => $params) {
             if (!empty($params['default']) && $params['default']) {
                 $displayColumns[$col] = $params;
             }
         }
     }
     global $current_user;
     if (!is_admin($current_user)) {
         $params = array('massupdate' => false);
         $lv->export = false;
     } else {
         $params = array('massupdate' => true, 'export' => true);
     }
     if (!empty($_REQUEST['orderBy'])) {
         $params['orderBy'] = $_REQUEST['orderBy'];
         $params['overrideOrder'] = true;
         if (!empty($_REQUEST['sortOrder'])) {
             $params['sortOrder'] = $_REQUEST['sortOrder'];
         }
     }
     $lv->displayColumns = $displayColumns;
     $this->seed = $seed;
     $this->module = $module;
     $searchForm = null;
     $storeQuery = new StoreQuery();
     if (!isset($_REQUEST['query'])) {
         $storeQuery->loadQuery($this->module);
         $storeQuery->populateRequest();
     } else {
         $storeQuery->saveFromRequest($this->module);
     }
     //search
     $view = 'basic_search';
     if (!empty($_REQUEST['search_form_view'])) {
         $view = $_REQUEST['search_form_view'];
     }
     $headers = true;
     if (!empty($_REQUEST['search_form_only']) && $_REQUEST['search_form_only']) {
         $headers = false;
     } elseif (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
         if (isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'advanced_search') {
             $view = 'advanced_search';
         } else {
             $view = 'basic_search';
         }
     }
     $use_old_search = true;
     if (file_exists('modules/' . $this->module . '/SearchForm.html')) {
         require_once 'include/SearchForm/SearchForm.php';
         $searchForm = new SearchForm($this->module, $this->seed);
     } else {
         $use_old_search = false;
         require_once 'include/SearchForm/SearchForm2.php';
         if (file_exists('custom/modules/' . $this->module . '/metadata/searchdefs.php')) {
             require_once 'custom/modules/' . $this->module . '/metadata/searchdefs.php';
         } elseif (!empty($metafiles[$this->module]['searchdefs'])) {
             require_once $metafiles[$this->module]['searchdefs'];
         } elseif (file_exists('modules/' . $this->module . '/metadata/searchdefs.php')) {
             require_once 'modules/' . $this->module . '/metadata/searchdefs.php';
         }
         if (!empty($metafiles[$this->module]['searchfields'])) {
             require_once $metafiles[$this->module]['searchfields'];
         } elseif (file_exists('modules/' . $this->module . '/metadata/SearchFields.php')) {
             require_once 'modules/' . $this->module . '/metadata/SearchFields.php';
         }
         $searchForm = new SearchForm($this->seed, $this->module, $this->action);
         $searchForm->setup($searchdefs, $searchFields, 'include/SearchForm/tpls/SearchFormGeneric.tpl', $view, $listViewDefs);
         $searchForm->lv = $lv;
     }
     if (isset($this->options['show_title']) && $this->options['show_title']) {
         $moduleName = isset($this->seed->module_dir) ? $this->seed->module_dir : $GLOBALS['mod_strings']['LBL_MODULE_NAME'];
         echo getClassicModuleTitle($moduleName, array($GLOBALS['mod_strings']['LBL_MODULE_TITLE']), FALSE);
     }
     $where = '';
     if (isset($_REQUEST['query'])) {
         // we have a query
         if (!empty($_SERVER['HTTP_REFERER']) && preg_match('/action=EditView/', $_SERVER['HTTP_REFERER'])) {
             // from EditView cancel
             $searchForm->populateFromArray($storeQuery->query);
         } else {
             $searchForm->populateFromRequest();
         }
         $where_clauses = $searchForm->generateSearchWhere(true, $this->seed->module_dir);
         if (count($where_clauses) > 0) {
             $where = '(' . implode(' ) AND ( ', $where_clauses) . ')';
         }
         $GLOBALS['log']->info("List View Where Clause: {$where}");
     }
     if ($use_old_search) {
         switch ($view) {
             case 'basic_search':
                 $searchForm->setup();
                 $searchForm->displayBasic($headers);
                 break;
             case 'advanced_search':
                 $searchForm->setup();
                 $searchForm->displayAdvanced($headers);
                 break;
             case 'saved_views':
                 echo $searchForm->displaySavedViews($listViewDefs, $lv, $headers);
                 break;
         }
     } else {
         echo $searchForm->display($headers);
     }
     if (!$headers) {
         return;
     }
     if (empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false) {
         if (!is_admin($current_user)) {
             $lv->setup($seed, 'include/ListView/ListViewNoMassUpdate.tpl', $where, $params);
         } else {
             $lv->setup($seed, 'include/ListView/ListViewGeneric.tpl', $where, $params);
         }
         $savedSearchName = empty($_REQUEST['saved_search_select_name']) ? '' : ' - ' . $_REQUEST['saved_search_select_name'];
         echo $lv->display();
     }
 }
 /**
  * @see SugarView::display()
  */
 public function display()
 {
     global $mod_strings;
     global $app_list_strings;
     global $app_strings;
     global $current_user;
     global $sugar_config;
     global $currentModule;
     $seed = new System();
     $searchForm = new SearchForm('Administration', $seed);
     $admin = Administration::getSettings();
     $system_id = 1;
     if (!empty($admin->settings['system_system_id'])) {
         $system_id = $admin->settings['system_system_id'];
     } else {
         $admin->saveSetting('system', 'system_id', $system_id);
     }
     $num_lic_oc = $admin->settings['license_num_lic_oc'];
     if (!isset($system_id) || empty($system_id)) {
         $system_id = 1;
     }
     $error = '';
     $where = 'system_id != ' . $system_id;
     $row_count = $seed->getEnabledOfflineClients($seed->create_new_list_query("", $where));
     if (isset($_REQUEST['view']) && ($_REQUEST['view'] == 'disable' || $_REQUEST['view'] == 'enable')) {
         if (isset($_REQUEST['system_id'])) {
             $system = new System();
             $system->retrieve($_REQUEST['system_id']);
             if ($system != null && $system->deleted != 1) {
                 if ($_REQUEST['view'] == 'disable') {
                     $system->status = 'Inactive';
                     $system->save();
                 } else {
                     if ($_REQUEST['view'] == 'enable') {
                         if ($row_count == $num_lic_oc) {
                             $error = $mod_strings['ERR_NUM_OFFLINE_CLIENTS_MET'];
                         } else {
                             $system->status = 'Active';
                             $system->save();
                             $row_count++;
                         }
                     }
                 }
                 if (!empty($_SESSION['EXCEEDING_OC_LICENSES']) && $_SESSION['EXCEEDING_OC_LICENSES'] == true) {
                     if ($row_count - 1 <= $num_lic_oc) {
                         unset($_SESSION['EXCEEDING_OC_LICENSES']);
                         header('Location: index.php?module=Administration&action=ListViewOfflineClient');
                     }
                 }
             }
         }
     }
     $user_name = '';
     if (isset($_REQUEST['query'])) {
         $user_name = isset($_REQUEST['user_name']) ? $_REQUEST['user_name'] : '';
         require_once 'modules/Administration/metadata/SearchFields.php';
         $searchForm->setup();
         $user = BeanFactory::getBean('Users');
         $searchForm->populateFromRequest('advanced_search');
         $where_clauses = $searchForm->generateSearchWhere(true, "Administration");
         $search_where = "";
         if (count($where_clauses) > 0) {
             $search_where = implode(' and ', $where_clauses);
         }
     }
     if (isset($search_where) && !empty($search_where)) {
         $where .= ' AND ' . $search_where;
     }
     echo getClassicModuleTitle("Administration", array("<a href='index.php?module=Administration&action=index'>" . translate('LBL_MODULE_NAME', 'Administration') . "</a>", $mod_strings['LBL_MANAGE_OFFLINE_CLIENT']), false);
     echo '<div class="listViewBody">';
     //now we want to display how many offline clients are currently in use
     echo "<h4>";
     if (!empty($error)) {
         echo "<span class='error'>{$error}</span><br />";
     }
     if ($row_count == 0) {
         echo "{$mod_strings['NO_ENABLED_OFFLINE_CLIENTS']}";
     } else {
         echo "{$row_count} of {$num_lic_oc} {$mod_strings['ENABLED_OFFLINE_CLIENTS']}";
     }
     echo "</h4>";
     //SEARCH
     if (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
         $search_form = new Sugar_Smarty();
         $search_form->assign("MOD", $mod_strings);
         $search_form->assign("APP", $app_strings);
         $search_form->assign("BASIC_SEARCH_PNG", SugarThemeRegistry::current()->getImage('basic_search', 'border="0"', null, null, '.gif', $app_strings['LNK_BASIC_SEARCH']));
         if (isset($user_name)) {
             $search_form->assign("USER_NAME", $user_name);
         }
         $search_form->assign("JAVASCRIPT", get_clear_form_js());
         $search_form->display('modules/Administration/templates/OfflineClientSearchForm.tpl');
     }
     //SEARCH
     $ListView = new ListView();
     $ListView->initNewXTemplate('modules/Administration/templates/ViewOfflineClients.html', $mod_strings);
     $ListView->xTemplateAssign("RETURN_URL", "&return_module=" . $currentModule . "&return_action=ListView");
     $ListView->xTemplateAssign("DELETE_INLINE_PNG", SugarThemeRegistry::current()->getImage('delete_inline', 'align="absmiddle" border="0"', null, null, '.gif', "{SYSTEM.LBL_DISABLE}"));
     $ListView->setQuery($where, "", "system_key", "SYSTEM");
     $ListView->show_export_button = false;
     $ListView->show_mass_update_form = true;
     $ListView->show_delete_button = false;
     $ListView->show_select_menu = false;
     $ListView->show_mass_update = false;
     $ListView->processListView($seed, "main", "SYSTEM");
     echo '</div>';
 }
Пример #4
0
 public function testRetrieveByDaterange()
 {
     global $current_user;
     $_REQUEST = $_POST = array("module" => "Meetings", "action" => "index", "searchFormTab" => "basic_search", "query" => "true", "name_basic" => "", "current_user_only_basic" => "0", "favorites_only_basic" => "0", "open_only_basic" => "0", "date_start_basic_range_choice" => "between", "range_date_start_basic" => "", "start_range_date_start_basic" => "13/07/2011", "end_range_date_start_basic" => "14/07/2011", "button" => "Search");
     $srch = new SearchForm(new Meeting(), "Meetings");
     $srch->setup($this->searchDefs, $this->searchFields, "");
     $srch->populateFromRequest();
     $w = $srch->generateSearchWhere();
     // Due to daylight savings, I cannot hardcode intervals...
     $GMTDatesStart = $this->timedate->getDayStartEndGMT("2011-07-13");
     $GMTDatesEnd = $this->timedate->getDayStartEndGMT("2011-07-14");
     // Current User is on GMT+2.
     // Asking for meeting between 13 and 14 July 2011, I expect to search (GMT) from 12 July at 22:00 until 14 July at 22:00 (excluded)
     $expectedWhere = "meetings.date_start >= '" . $GMTDatesStart['start'] . "' AND meetings.date_start <= '" . $GMTDatesEnd['end'] . "'";
     $this->assertEquals($w[0], $expectedWhere);
 }
Пример #5
0
 function display()
 {
     if (!$this->bean->ACLAccess('list')) {
         ACLController::displayNoAccess();
         return;
     }
     $module = $GLOBALS['module'];
     $metadataFile = SugarAutoLoader::loadWithMetafiles($module, 'listviewdefs');
     require_once $metadataFile;
     $this->bean->ACLFilterFieldList($listViewDefs[$module], array("owner_override" => true));
     $seed = $this->bean;
     if (!empty($this->bean->object_name) && isset($_REQUEST[$module . '2_' . strtoupper($this->bean->object_name) . '_offset'])) {
         //if you click the pagination button, it will populate the search criteria here
         if (!empty($_REQUEST['current_query_by_page'])) {
             //The code support multi browser tabs pagination
             $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', 'request_data', 'current_query_by_page', $module . '2_' . strtoupper($this->bean->object_name) . '_ORDER_BY');
             if (isset($_REQUEST['lvso'])) {
                 $blockVariables[] = 'lvso';
             }
             $current_query_by_page = unserialize(base64_decode($_REQUEST['current_query_by_page']));
             foreach ($current_query_by_page as $search_key => $search_value) {
                 if ($search_key != $module . '2_' . strtoupper($this->bean->object_name) . '_offset' && !in_array($search_key, $blockVariables)) {
                     if (!is_array($search_value)) {
                         $_REQUEST[$search_key] = $GLOBALS['db']->quote($search_value);
                     } else {
                         foreach ($search_value as $key => &$val) {
                             $val = $GLOBALS['db']->quote($val);
                         }
                         $_REQUEST[$search_key] = $search_value;
                     }
                 }
             }
         }
     }
     if (!empty($_REQUEST['saved_search_select']) && $_REQUEST['saved_search_select'] != '_none') {
         if (empty($_REQUEST['button']) && (empty($_REQUEST['clear_query']) || $_REQUEST['clear_query'] != 'true')) {
             $this->saved_search = BeanFactory::getBean('SavedSearch');
             $this->saved_search->retrieveSavedSearch($_REQUEST['saved_search_select']);
             $this->saved_search->populateRequest();
         } elseif (!empty($_REQUEST['button'])) {
             // click the search button, after retrieving from saved_search
             $_SESSION['LastSavedView'][$_REQUEST['module']] = '';
             unset($_REQUEST['saved_search_select']);
             unset($_REQUEST['saved_search_select_name']);
         }
     }
     $lv = new ListViewSmarty();
     $displayColumns = array();
     if (!empty($_REQUEST['displayColumns'])) {
         foreach (explode('|', $_REQUEST['displayColumns']) as $num => $col) {
             if (!empty($listViewDefs[$module][$col])) {
                 $displayColumns[$col] = $listViewDefs[$module][$col];
             }
         }
     } else {
         foreach ($listViewDefs[$module] as $col => $params) {
             if (!empty($params['default']) && $params['default']) {
                 $displayColumns[$col] = $params;
             }
         }
     }
     $params = array('massupdate' => true, 'export' => true);
     if (!empty($_REQUEST['orderBy'])) {
         $params['orderBy'] = $_REQUEST['orderBy'];
         $params['overrideOrder'] = true;
         if (!empty($_REQUEST['sortOrder'])) {
             $params['sortOrder'] = $_REQUEST['sortOrder'];
         }
     }
     $lv->displayColumns = $displayColumns;
     $this->seed = $seed;
     $this->module = $module;
     $searchForm = null;
     $storeQuery = new StoreQuery();
     if (!isset($_REQUEST['query'])) {
         $storeQuery->loadQuery($this->module);
         $storeQuery->populateRequest();
     } else {
         $storeQuery->saveFromRequest($this->module);
     }
     //search
     $view = 'basic_search';
     if (!empty($_REQUEST['search_form_view'])) {
         $view = $_REQUEST['search_form_view'];
     }
     $headers = true;
     if (!empty($_REQUEST['search_form_only']) && $_REQUEST['search_form_only']) {
         $headers = false;
     } elseif (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
         if (isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'advanced_search') {
             $view = 'advanced_search';
         } else {
             $view = 'basic_search';
         }
     }
     $use_old_search = true;
     if (SugarAutoLoader::existing('modules/' . $this->module . '/SearchForm.html')) {
         require_once 'include/SearchForm/SearchForm.php';
         $searchForm = new SearchForm($this->module, $this->seed);
     } else {
         $use_old_search = false;
         require_once 'include/SearchForm/SearchForm2.php';
         $defs = SugarAutoLoader::loadWithMetafiles($this->module, 'searchdefs');
         if (!empty($defs)) {
             require $defs;
         }
         $searchFields = SugarAutoLoader::loadSearchFields($this->module);
         $searchForm = new SearchForm($this->seed, $this->module, $this->action);
         $searchForm->setup($searchdefs, $searchFields, 'SearchFormGeneric.tpl', $view, $listViewDefs);
         $searchForm->lv = $lv;
     }
     if (isset($this->options['show_title']) && $this->options['show_title']) {
         $moduleName = isset($this->seed->module_dir) ? $this->seed->module_dir : $GLOBALS['mod_strings']['LBL_MODULE_NAME'];
         echo getClassicModuleTitle($moduleName, array($GLOBALS['mod_strings']['LBL_MODULE_TITLE']), FALSE);
     }
     $where = '';
     if (isset($_REQUEST['query'])) {
         // we have a query
         if (!empty($_SERVER['HTTP_REFERER']) && preg_match('/action=EditView/', $_SERVER['HTTP_REFERER'])) {
             // from EditView cancel
             $searchForm->populateFromArray($storeQuery->query);
         } else {
             $searchForm->populateFromRequest();
         }
         $where_clauses = $searchForm->generateSearchWhere(true, $this->seed->module_dir);
         if (count($where_clauses) > 0) {
             $where = '(' . implode(' ) AND ( ', $where_clauses) . ')';
         }
         $GLOBALS['log']->info("List View Where Clause: {$where}");
     }
     if ($use_old_search) {
         switch ($view) {
             case 'basic_search':
                 $searchForm->setup();
                 $searchForm->displayBasic($headers);
                 break;
             case 'advanced_search':
                 $searchForm->setup();
                 $searchForm->displayAdvanced($headers);
                 break;
             case 'saved_views':
                 echo $searchForm->displaySavedViews($listViewDefs, $lv, $headers);
                 break;
         }
     } else {
         echo $searchForm->display($headers);
     }
     if (!$headers) {
         return;
     }
     /*
      * Bug 50575 - related search columns not inluded in query in a proper way
      */
     $lv->searchColumns = $searchForm->searchColumns;
     if (isset($GLOBALS['mod_strings']['LBL_MODULE_NAME_SINGULAR'])) {
         $seed->module_title = $GLOBALS['mod_strings']['LBL_MODULE_NAME_SINGULAR'];
     }
     if (isset($GLOBALS['mod_strings']['LBL_LIST_PARENT_NAME'])) {
         $seed->parent_title = $GLOBALS['mod_strings']['LBL_LIST_PARENT_NAME'];
         $seed->parent_module_dir = 'Project';
     }
     $project = BeanFactory::getBean('Project');
     $project_query = new SugarQuery();
     $project_query->from($project);
     $project_list = $project->fetchFromQuery($project_query);
     if (count($project_list)) {
         $seed->show_link = true;
     }
     if (empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false) {
         //Bug 58841 - mass update form was not displayed for non-admin users that should have access
         if (ACLController::checkAccess($module, 'massupdate') || ACLController::checkAccess($module, 'export')) {
             $lv->setup($seed, 'include/ListView/ListViewGeneric.tpl', $where, $params);
         } else {
             $lv->setup($seed, 'include/ListView/ListViewNoMassUpdate.tpl', $where, $params);
         }
         echo $lv->display();
     }
 }