Ejemplo n.º 1
0
function generateSearchWhere($module, $query)
{
    //this function is similar with function prepareSearchForm() in view.list.php
    $seed = BeanFactory::newBean($module);
    if (SugarAutoLoader::fileExists('modules/' . $module . '/SearchForm.html')) {
        if (SugarAutoLoader::fileExists('modules/' . $module . '/metadata/SearchFields.php')) {
            require_once 'include/SearchForm/SearchForm.php';
            $searchForm = new SearchForm($module, $seed);
        } elseif (!empty($_SESSION['export_where'])) {
            //bug 26026, sometimes some module doesn't have a metadata/SearchFields.php, the searchfrom is generated in the ListView.php.
            // Currently, massupdate will not generate the where sql. It will use the sql stored in the SESSION. But this will cause bug 24722, and it cannot be avoided now.
            $where = $_SESSION['export_where'];
            $whereArr = explode(" ", trim($where));
            if ($whereArr[0] == trim('where')) {
                $whereClean = array_shift($whereArr);
            }
            $where = implode(" ", $whereArr);
            //rrs bug: 31329 - previously this was just returning $where, but the problem is the caller of this function
            //expects the results in an array, not just a string. So rather than fixing the caller, I felt it would be best for
            //the function to return the results in a standard format.
            $ret_array['where'] = $where;
            $ret_array['searchFields'] = array();
            return $ret_array;
        } else {
            return;
        }
    } else {
        require_once 'include/SearchForm/SearchForm2.php';
        $searchdefs_file = SugarAutoLoader::loadWithMetafiles($module, 'searchdefs');
        if ($searchdefs_file) {
            require $searchdefs_file;
        }
        $searchFields = SugarAutoLoader::loadSearchFields($module);
        if (empty($searchdefs) || empty($searchFields)) {
            //for some modules, such as iframe, it has massupdate, but it doesn't have search function, the where sql should be empty.
            return;
        }
        $searchForm = getSearchForm($seed, $module);
        $searchForm->setup($searchdefs, $searchFields, 'SearchFormGeneric.tpl');
    }
    $searchForm->populateFromArray(unserialize(base64_decode($query)));
    $where_clauses = $searchForm->generateSearchWhere(true, $module);
    if (count($where_clauses) > 0) {
        $where = '(' . implode(' ) AND ( ', $where_clauses) . ')';
    }
    $GLOBALS['log']->info("Export Where Clause: {$where}");
    $ret_array['where'] = $where;
    $ret_array['searchFields'] = $searchForm->searchFields;
    return $ret_array;
}
Ejemplo n.º 2
0
		 );
	  }
	);
</script>
<?php 
$sCode = '';
$_page['extra_js'] = ob_get_clean();
$_ni = $_page['name_index'];
$oZ = new BxDolSearch();
if (bx_get('keyword')) {
    $sCode = $oZ->response();
    if (mb_strlen($sCode) == 0) {
        $sCode = $oZ->getEmptyResult();
    }
}
$sForm = getSearchForm();
$sSearchArea = '<div id="searchArea">' . $sCode . '</div>';
$_page_cont[$_ni]['page_main_code'] = $sForm . $sSearchArea;
$aVars = array();
$GLOBALS['oTopMenu']->setCustomSubActions($aVars, '');
PageCode();
function getSearchForm()
{
    $aList = $GLOBALS['MySQL']->fromCache('sys_objects_search', 'getAllWithKey', 'SELECT `ID` as `id`,
                   `Title` as `title`,
                   `ClassName` as `class`,
                   `ClassPath` as `file`,
                   `ObjectName`
	        FROM `sys_objects_search`', 'ObjectName');
    $aValues = array();
    foreach ($aList as $sKey => $aValue) {