This commit is contained in:
2024-04-27 09:23:34 +02:00
commit 11e713ca6f
11884 changed files with 3263371 additions and 0 deletions

716
include/SearchForm/SearchForm.php Executable file
View File

@@ -0,0 +1,716 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/tabs.php');
class SearchForm {
/**
* SearchForm Template to use (xtpl)
* @var string
*/
var $tpl;
/**
* SearchField meta data array to use. Populated from moduleDir/metadata/SearchFields
* @var array
*/
var $searchFields;
/**
* Seed bean to use
* @var bean
*/
var $bean;
/**
* Module the search from is for
* @var string
*/
var $module;
/**
* meta data for the tabs to display
* @var array
*/
var $tabs;
/**
* XTPL object
* @var object
*/
var $xtpl;
/**
* Use to determine whether or not to show the saved search options
* @var boolean
*/
var $showSavedSearchOptions = true;
/**
* loads SearchFields MetaData, sets member variables
*
* @param string $module moduleDir
* @param bean $seedBean seed bean to use
* @param string $tpl template to use, defaults to moduleDir/SearchForm.html
*
*/
function SearchForm($module, &$seedBean, $tpl = null) {
global $app_strings;
$this->module = $module;
require_once('modules/' . $module . '/metadata/SearchFields.php');
if(file_exists('custom/modules/' . $module . '/metadata/SearchFields.php')){
require_once('custom/modules/' . $module . '/metadata/SearchFields.php');
}
//require_once('modules/' . $module . '/metadata/SearchFields.php');
$this->searchFields = $searchFields[$module];
if(empty($tpl)) {
$this->tpl = 'modules/' . $module . '/SearchForm.html';
if(!empty($GLOBALS['layout_edit_mode'])){
$this->tpl = $GLOBALS['sugar_config']['cache_dir'].'studio/custom/working/modules/' . $module . '/SearchForm.html';
}
}
else {
$this->tpl = $tpl;
}
$this->bean = $seedBean;
$this->tabs = array(array('title' => $app_strings['LNK_BASIC_SEARCH'],
'link' => $module . '|basic_search',
'key' => $module . '|basic_search'),
array('title' => $app_strings['LNK_ADVANCED_SEARCH'],
'link' => $module . '|advanced_search',
'key' => $module . '|advanced_search'));
if(file_exists('modules/'.$this->module.'/index.php')){
$this->tabs[] = array('title' => $app_strings['LNK_SAVED_VIEWS'],
'link' => $module . '|saved_views',
'key' => $module . '|saved_views');
}
}
/**
* Populate the searchFields from an array
*
* @param array $array array to search through
* @param string $switchVar variable to use in switch statement
* @param bool $addAllBeanFields true to process at all bean fields
*/
function populateFromArray(&$array, $switchVar = null, $addAllBeanFields = true) {
//CL Bug:33176
if(empty($array['searchFormTab']) && empty($switchvar)) {
$array['searchFormTab'] = 'advanced_search';
}
if(!empty($array['searchFormTab']) || !empty($switchVar)) {
$arrayKeys = array_keys($array);
$searchFieldsKeys = array_keys($this->searchFields);
if(empty($switchVar)) $switchVar = $array['searchFormTab'];
switch($switchVar) {
case 'basic_search':
foreach($this->searchFields as $name => $params) {
if(isset($array[$name . '_basic'])) {
$this->searchFields[$name]['value'] = $array[$name . '_basic'];
}
}
if($addAllBeanFields) {
foreach($this->bean->field_name_map as $key => $params) {
if(in_array($key . '_basic' , $arrayKeys) && !in_array($key, $searchFieldsKeys)) {
$this->searchFields[$key] = array('query_type' => 'default',
'value' => $array[$key . '_basic']);
}
}
}
break;
case 'advanced_search':
foreach($this->searchFields as $name => $params) {
if(isset($array[$name])) {
$this->searchFields[$name]['value'] = $array[$name];
}
}
if((empty($array['massupdate']) || $array['massupdate'] == 'false') && $addAllBeanFields) {
foreach($this->bean->field_name_map as $key => $params) {
if(in_array($key, $arrayKeys) && !in_array($key, $searchFieldsKeys)) {
$this->searchFields[$key] = array('query_type' => 'default',
'value' => $array[$key]);
}
}
}
break;
case 'saved_views':
foreach($this->searchFields as $name => $params) {
if(isset($array[$name . '_basic'])) { // save basic first
$this->searchFields[$name]['value'] = $array[$name . '_basic'];
}
if(isset($array[$name])) { // overwrite by advanced if available
$this->searchFields[$name]['value'] = $array[$name];
}
}
if($addAllBeanFields) {
foreach($this->bean->field_name_map as $key => $params) {
if(!in_array($key, $searchFieldsKeys)) {
if(in_array($key . '_basic', $arrayKeys) ) {
$this->searchFields[$key] = array('query_type' => 'default',
'value' => $array[$key . '_basic']);
}
if(in_array($key, $arrayKeys)) {
$this->searchFields[$key] = array('query_type' => 'default',
'value' => $array[$key]);
}
}
}
}
}
}
}
/**
* Populate the searchFields from $_REQUEST
*
* @param string $switchVar variable to use in switch statement
* @param bool $addAllBeanFields true to process at all bean fields
*/
function populateFromRequest($switchVar = null, $addAllBeanFields = true) {
$this->populateFromArray($_REQUEST, $switchVar, $addAllBeanFields);
}
/**
* The fuction will returns an array of filter conditions.
*
*/
function generateSearchWhere($add_custom_fields = false, $module='') {
global $timedate;
$values = $this->searchFields;
$where_clauses = array();
$like_char = '%';
$table_name = $this->bean->object_name;
foreach($this->searchFields as $field=>$parms) {
$customField = false;
// Jenny - Bug 7462: We need a type check here to avoid database errors
// when searching for numeric fields. This is a temporary fix until we have
// a generic search form validation mechanism.
$type = (!empty($this->bean->field_name_map[$field]['type']))?$this->bean->field_name_map[$field]['type']:'';
if(!empty($this->bean->field_name_map[$field]['source']) && $this->bean->field_name_map[$field]['source'] == 'custom_fields'){
$customField = true;
}
if ($type == 'int') {
if (!empty($parms['value'])) {
$tempVal = explode(',', $parms['value']);
$newVal = '';
foreach($tempVal as $key => $val) {
if (!empty($newVal))
$newVal .= ',';
if(!empty($val) && !(is_numeric($val)))
$newVal .= -1;
else
$newVal .= $val;
}
$parms['value'] = $newVal;
}
}
// do not include where clause for custom fields with checkboxes that are unchecked
elseif($type == 'bool' && empty($parms['value']) && $customField) {
continue;
}
elseif($type == 'bool' && !empty($parms['value'])){
if ($parms['value'] == 'on'){
$parms['value'] = 1;
}
}
if(isset($parms['value']) && $parms['value'] != "") {
$operator = 'like';
if(!empty($parms['operator'])) {
$operator = $parms['operator'];
}
if(is_array($parms['value'])) {
$field_value = '';
// If it is a custom field of mutliselect we have to do some special processing
if($customField && !empty($this->bean->field_name_map[$field]['isMultiSelect']) && $this->bean->field_name_map[$field]['isMultiSelect']) {
$operator = 'custom_enum';
$db_field = $this->bean->table_name . "_cstm." . $field;
foreach($parms['value'] as $key => $val) {
if($val != ' ' and $val != '') {
$qVal = $GLOBALS['db']->quote($val);
if (!empty($field_value)) {
$field_value .= ' or ';
}
$field_value .= "$db_field like '$qVal' or $db_field like '%$qVal^%' or $db_field like '%^$qVal%' or $db_field like '%^$qVal^%'";
}
}
} else {
$operator = $operator != 'subquery' ? 'in' : $operator;
foreach($parms['value'] as $key => $val) {
if($val != ' ' and $val != '') {
if (!empty($field_value)) {
$field_value .= ',';
}
$field_value .= "'" . $GLOBALS['db']->quote($val) . "'";
}
}
}
}
else {
$field_value = $GLOBALS['db']->quote($parms['value']);
}
//set db_fields array.
if(!isset($parms['db_field'])) {
$parms['db_field'] = array($field);
}
if(isset($parms['my_items']) and $parms['my_items'] == true) {
global $current_user;
$field_value = $GLOBALS['db']->quote($current_user->id);
$operator = '=';
}
$where = '';
$itr = 0;
if($field_value != '') {
foreach ($parms['db_field'] as $db_field) {
if (strstr($db_field, '.') === false) {
if(!$customField){
$db_field = $this->bean->table_name . "." . $db_field;
}else{
$db_field = $this->bean->table_name . "_cstm." . $db_field;
}
}
if($type == 'date') {
// Collin - Have mysql as first because it's usually the case
// The regular expression check is to circumvent special case YYYY-MM
if($GLOBALS['db']->dbType == 'mysql') {
if(preg_match('/^\d{4}.\d{1,2}$/', $field_value) == 0) {
$field_value = $timedate->to_db_date($field_value, false);
$operator = '=';
} else {
$operator = 'db_date';
}
} else if($GLOBALS['db']->dbType == 'oci8') {
if(preg_match('/^\d{4}.\d{1,2}$/', $field_value) == 0) {
$field_value = $timedate->to_db_date($field_value, false);
$field_value = "to_date('" . $field_value . "', 'YYYY-MM-DD hh24:mi:ss')";
}
$operator = 'db_date';
} else if($GLOBALS['db']->dbType == 'mssql') {
if(preg_match('/^\d{4}.\d{1,2}$/', $field_value) == 0) {
$field_value = "Convert(DateTime, '".$timedate->to_db_date($field_value, false)."')";
}
$operator = 'db_date';
} else {
$field_value = $timedate->to_db_date($field_value, false);
$operation = '=';
}
}
if($type == 'datetime') {//bug 22564, date type field may also have this problem. we may add a date type here.
$field_value = $timedate->to_db_date($field_value, false);//This think of the timezone problem
$temp_offset = strtotime($timedate->swap_formats($timedate->to_display_date_time($field_value." 00:00:00"),$timedate->get_date_time_format(),$timedate->get_db_date_time_format())) - strtotime($field_value." 00:00:00");
$start_datetime = date("Y-m-d H:i:s", strtotime($field_value." 00:00:00") - $temp_offset);
$end_datetime = date("Y-m-d H:i:s", strtotime($field_value." 23:59:59") - $temp_offset);
$field_value = $start_datetime . "<>" . $end_datetime;
$operator = 'between';
}
if($GLOBALS['db']->dbType == 'oci8' && isset($parms['query_type']) && $parms['query_type'] == 'case_insensitive') {
$db_field = 'upper(' . $db_field . ")";
$field_value = strtoupper($field_value);
}
$itr++;
if(!empty($where)) {
$where .= " OR ";
}
switch(strtolower($operator)) {
case 'subquery':
$in = 'IN';
if ( isset($parms['subquery_in_clause']) ) {
if ( !is_array($parms['subquery_in_clause']) ) {
$in = $parms['subquery_in_clause'];
}
elseif ( isset($parms['subquery_in_clause'][$field_value]) ) {
$in = $parms['subquery_in_clause'][$field_value];
}
}
$sq = $parms['subquery'];
if(is_array($sq)){
$and_or = ' AND ';
if (isset($sq['OR'])){
$and_or = ' OR ';
}
$first = true;
foreach($sq as $q){
if(empty($q) || strlen($q)<2) continue;
if(!$first){
$where .= $and_or;
}
$where .= " {$db_field} $in ({$q} '{$field_value}%') ";
$first = false;
}
}elseif(!empty($parms['query_type']) && $parms['query_type'] == 'format'){
$stringFormatParams = array(0 => $field_value, 1 => $GLOBALS['current_user']->id);
$where .= "{$db_field} $in (".string_format($parms['subquery'], $stringFormatParams).")";
}else{
$where .= "{$db_field} $in ({$parms['subquery']} '{$field_value}%')";
}
break;
case 'like':
$where .= $db_field . " like '".$field_value.$like_char."'";
break;
case 'in':
$where .= $db_field . " in (".$field_value.')';
break;
case '=':
$where .= $db_field . " = '".$field_value ."'";
break;
case 'db_date':
if(preg_match('/^\d{4}.\d{1,2}$/', $field_value) == 0) {
$where .= $db_field . " = ". $field_value;
} else {
// Create correct date_format conversion String
if($GLOBALS['db']->dbType == 'oci8') {
$where .= db_convert($db_field,'date_format',array("'YYYY-MM'")) . " = '" . $field_value . "'";
} else {
$where .= db_convert($db_field,'date_format',array("'%Y-%m'")) . " = '" . $field_value . "'";
}
}
break;
case 'between':
$field_value = explode('<>', $field_value);
$where .= $db_field . " > '".$field_value[0] . "' AND " .$db_field . " < '".$field_value[1]."'";
break;
}
}
}
if(!empty($where)) {
if($itr > 1) {
array_push($where_clauses, '( '.$where.' )');
}
else {
array_push($where_clauses, $where);
}
}
}
}
return $where_clauses;
}
/**
* displays the tabs (top of the search form)
*
* @param string $currentKey key in $this->tabs to show as the current tab
*
* @return string html
*/
function displayTabs($currentKey) {
$GLOBALS['log']->debug('SearchForm.php->displayTabs(): tabs='.print_r($this->tabs,true));
$tabPanel = new SugarWidgetTabs($this->tabs, $currentKey, 'SUGAR.searchForm.searchFormSelect');
if(isset($_REQUEST['saved_search_select']) && $_REQUEST['saved_search_select']!='_none') {
$saved_search=loadBean('SavedSearch');
$saved_search->retrieveSavedSearch($_REQUEST['saved_search_select']);
}
$str = $tabPanel->display();
$str .= '<script>';
if(!empty($_REQUEST['displayColumns']))
$str .= 'SUGAR.savedViews.displayColumns = "' . $_REQUEST['displayColumns'] . '";';
elseif(isset($saved_search->contents['displayColumns']) && !empty($saved_search->contents['displayColumns']))
$str .= 'SUGAR.savedViews.displayColumns = "' . $saved_search->contents['displayColumns'] . '";';
if(!empty($_REQUEST['hideTabs']))
$str .= 'SUGAR.savedViews.hideTabs = "' . $_REQUEST['hideTabs'] . '";';
elseif(isset($saved_search->contents['hideTabs']) && !empty($saved_search->contents['hideTabs']))
$str .= 'SUGAR.savedViews.hideTabs = "' . $saved_search->contents['hideTabs'] . '";';
if(!empty($_REQUEST['orderBy']))
$str .= 'SUGAR.savedViews.selectedOrderBy = "' . $_REQUEST['orderBy'] . '";';
elseif(isset($saved_search->contents['orderBy']) && !empty($saved_search->contents['orderBy']))
$str .= 'SUGAR.savedViews.selectedOrderBy = "' . $saved_search->contents['orderBy'] . '";';
if(!empty($_REQUEST['sortOrder']))
$str .= 'SUGAR.savedViews.selectedSortOrder = "' . $_REQUEST['sortOrder'] . '";';
elseif(isset($saved_search->contents['sortOrder']) && !empty($saved_search->contents['sortOrder']))
$str .= 'SUGAR.savedViews.selectedSortOrder = "' . $saved_search->contents['sortOrder'] . '";';
$str .= '</script>';
return $str;
}
/**
* sets up the search forms, populates the preset values
*
*/
function setup() {
global $mod_strings, $app_strings, $app_list_strings, $theme, $timedate;
$GLOBALS['log']->debug('SearchForm.php->setup()');
$this->xtpl = new XTemplate($this->tpl);
$this->xtpl->assign("MOD", $mod_strings);
$this->xtpl->assign("APP", $app_strings);
$this->xtpl->assign("THEME", $theme);
$this->xtpl->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format());
$this->xtpl->assign("USER_DATEFORMAT", '('. $timedate->get_user_date_format().')');
foreach($this->searchFields as $name => $params) {
if(isset($params['template_var'])) $templateVar = $params['template_var'];
else $templateVar = strtoupper($name);
if(isset($params['value'])) { // populate w/ preselected values
if(isset($params['options'])) {
$options = $app_list_strings[$params['options']];
if(isset($params['options_add_blank']) && $params['options_add_blank']) array_unshift($options, '');
$this->xtpl->assign($templateVar, get_select_options_with_id($options, $params['value']));
}
else {
if(isset($params['input_type'])) {
switch($params['input_type']) {
case 'checkbox': // checkbox input
if($params['value'] == 'on' || $params['value'])
$this->xtpl->assign($templateVar, 'checked');
break;
}
}
else {// regular text input
$this->xtpl->assign($templateVar, to_html($params['value']));
}
}
}
else { // populate w/o preselected values
if(isset($params['options'])) {
$options = $app_list_strings[$params['options']];
if(isset($params['options_add_blank']) && $params['options_add_blank']) array_unshift($options, '');
$this->xtpl->assign($templateVar, get_select_options_with_id($options, ''));
}
}
}
if (!empty($_REQUEST['assigned_user_id'])) $this->xtpl->assign("USER_FILTER", get_select_options_with_id(get_user_array(FALSE), $_REQUEST['assigned_user_id']));
else $this->xtpl->assign("USER_FILTER", get_select_options_with_id(get_user_array(FALSE), ''));
// handle my items only
if(isset($this->searchFields['current_user_only']) && isset($this->searchFields['current_user_only']['value']))
$this->xtpl->assign("CURRENT_USER_ONLY", "checked");
}
/**
* displays the search form header
*
* @param string $view which view is currently being displayed
*
*/
function displayHeader($view) {
global $current_user;
$GLOBALS['log']->debug('SearchForm.php->displayHeader()');
$header_text = '';
if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
$header_text = "<a href='index.php?action=index&module=DynamicLayout&from_action=SearchForm&from_module=".$_REQUEST['module'] ."'>".SugarThemeRegistry::current()->getImage("EditLayout","border='0' alt='Edit Layout' align='bottom'")."</a>";
}
echo $header_text . $this->displayTabs($this->module . '|' . $view);
echo "<form name='search_form' class='search_form'>" .
"<input type='hidden' name='searchFormTab' value='{$view}'/>" .
"<input type='hidden' name='module' value='{$_REQUEST['module']}'/>" .
"<input type='hidden' name='action' value='{$_REQUEST['action']}'/>" .
"<input type='hidden' name='query' value='true'/>";
}
/**
* displays the search form body, for example if basic_search is being displayed, then the function call would be
* displayWithHeaders('basic_search', $htmlForBasicSearchBody) {
*
* @param string $view which view is currently being displayed
* @param string $basic_search_text body of the basic search tab
* @param string $advanced_search_text body of the advanced search tab
* @param string $saved_views_text body of the saved views tab
*
*/
function displayWithHeaders($view, $basic_search_text = '', $advanced_search_text = '', $saved_views_text = '') {
$GLOBALS['log']->debug('SearchForm.php->displayWithHeaders()');
$this->displayHeader($view);
echo "<div id='{$this->module}basic_searchSearchForm' " . (($view == 'basic_search') ? '' : "style='display: none'") . ">" . $basic_search_text . "</div>";
echo "<div id='{$this->module}advanced_searchSearchForm' " . (($view == 'advanced_search') ? '' : "style='display: none'") . ">" . $advanced_search_text . "</div>";
echo "<div id='{$this->module}saved_viewsSearchForm' " . (($view == 'saved_views') ? '' : "style='display: none'") . ">" . $saved_views_text . "</div>";
echo $this->getButtons();
echo '</form>';
// echo '<script type="text/javascript">Calendar.setup ({inputField : "search_jscal_field", ifFormat : "'.$timedate->get_cal_date_format().'", showsTime : false, button : "search_jscal_trigger", singleClick : true, step : 1});</script>';
}
/**
* displays the basic search form body
*
* @param bool $header display this with headers
* @param bool $return echo or return the html
*
* @return string html of contents
*/
function displayBasic($header = true, $return = false) {
global $current_user;
$this->bean->custom_fields->populateAllXTPL($this->xtpl, 'search' );
$this->xtpl->parse("main");
if(!empty($GLOBALS['layout_edit_mode'])){
$this->xtpl->parse("advanced");
}
$text = $this->xtpl->text("main");
if(!empty($GLOBALS['layout_edit_mode'])){
$text .= $this->xtpl->text("advanced");
}
if($header && empty($GLOBALS['layout_edit_mode'])) {
$this->displayWithHeaders('basic_search', $text);
}
else {
if($return) return $text;
else echo $text;
}
}
/**
* displays the advanced search form body
*
* @param bool $header display this with headers
* @param bool $return echo or return the html
*
* @return string html of contents
*/
function displayAdvanced($header = true, $return = false, $listViewDefs='', $lv='') {
global $current_user, $current_language;
$GLOBALS['log']->debug('SearchForm.php->displayAdvanced()');
$this->bean->custom_fields->populateAllXTPL($this->xtpl, 'search' );
if(!empty($listViewDefs) && !empty($lv)){
$GLOBALS['log']->debug('SearchForm.php->displayAdvanced(): showing saved search');
$savedSearch = new SavedSearch($listViewDefs[$this->module], $lv->data['pageData']['ordering']['orderBy'], $lv->data['pageData']['ordering']['sortOrder']);
$this->xtpl->assign('SAVED_SEARCH', $savedSearch->getForm($this->module, false));
$this->xtpl->assign('MOD_SAVEDSEARCH', return_module_language($current_language, 'SavedSearch'));
$this->xtpl->assign('ADVANCED_SEARCH_IMG', SugarThemeRegistry::current()->getImageURL('advanced_search.gif'));
//this determines whether the saved search subform should be rendered open or not
if(isset($_REQUEST['showSSDIV']) && $_REQUEST['showSSDIV']=='yes'){
$this->xtpl->assign('SHOWSSDIV', 'yes');
$this->xtpl->assign('DISPLAYSS', '');
}else{
$this->xtpl->assign('SHOWSSDIV', 'no');
$this->xtpl->assign('DISPLAYSS', 'display:none');
}
}
$this->xtpl->parse("advanced");
$text = $this->xtpl->text("advanced");
if($header) {
$this->displayWithHeaders('advanced_search', '', $text);
}
else {
if($return) return $text;
else echo $text;
}
}
/**
* displays the saved views form body
*
* @param bool $header display this with headers
* @param bool $return echo or return the html
*
* @return string html of contents
*/
function displaySavedViews($listViewDefs, $lv, $header = true, $return = false) {
global $current_user;
$savedSearch = new SavedSearch($listViewDefs[$this->module], $lv->data['pageData']['ordering']['orderBy'], $lv->data['pageData']['ordering']['sortOrder']);
if($header) {
$this->displayWithHeaders('saved_views', $this->displayBasic(false, true), $this->displayAdvanced(false, true), $savedSearch->getForm($this->module));
echo '<script>SUGAR.savedViews.handleForm();</script>';
}
else {
echo $savedSearch->getForm($this->module, false);
}
}
/**
* get the search buttons
*
* @return string html of contents
*/
function getButtons() {
global $app_strings;
$SAVED_SEARCHES_OPTIONS = '';
$savedSearch = new SavedSearch();
$SAVED_SEARCHES_OPTIONS = $savedSearch->getSelect($this->module);
$str = "<input tabindex='2' title='{$app_strings['LBL_SEARCH_BUTTON_TITLE']}' accessKey='{$app_strings['LBL_SEARCH_BUTTON_KEY']}' onclick='SUGAR.savedViews.setChooser()' class='button' type='submit' name='button' value='{$app_strings['LBL_SEARCH_BUTTON_LABEL']}'/>&nbsp;";
$str .= "<input tabindex='2' title='{$app_strings['LBL_CLEAR_BUTTON_TITLE']}' accessKey='{$app_strings['LBL_CLEAR_BUTTON_KEY']}' onclick='SUGAR.searchForm.clear_form(this.form);' class='button' type='button' name='clear' value=' {$app_strings['LBL_CLEAR_BUTTON_LABEL']} '/>";
if(!empty($SAVED_SEARCHES_OPTIONS) && $this->showSavedSearchOptions){
$str .= " <span class='white-space'>
&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<b>{$app_strings['LBL_SAVED_SEARCH_SHORTCUT']}</b>&nbsp;
{$SAVED_SEARCHES_OPTIONS}
<span id='go_btn_span' style='display:none'><input tabindex='2' title='go_select' id='go_select' onclick='SUGAR.searchForm.clear_form(this.form);' class='button' type='button' name='go_select' value=' {$app_strings['LBL_GO_BUTTON_LABEL']} '/></span>
</span>
</form>";
}
$str .= "
<script>
function toggleInlineSearch(){
if (document.getElementById('inlineSavedSearch').style.display == 'none'){
document.getElementById('showSSDIV').value = 'yes'
document.getElementById('inlineSavedSearch').style.display = '';
document.getElementById('up_down_img').src='".SugarThemeRegistry::current()->getImageURL('basic_search.gif')."';
}else{
document.getElementById('up_down_img').src='".SugarThemeRegistry::current()->getImageURL('advanced_search.gif')."';
document.getElementById('showSSDIV').value = 'no';
document.getElementById('inlineSavedSearch').style.display = 'none';
}
}
</script>
";
return $str;
}
}
?>

View File

@@ -0,0 +1,882 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*
* Created on May 30, 2007
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
require_once ('include/tabs.php');
require_once ('include/ListView/ListViewSmarty.php');
require_once ('include/TemplateHandler/TemplateHandler.php');
require_once ('include/EditView/EditView2.php');
class SearchForm extends EditView {
var $seed = null;
var $module = '';
var $action = 'index';
var $searchdefs = array ();
var $listViewDefs = array ();
var $lv;
var $th;
var $tpl;
var $view = 'SearchForm';
var $displayView = 'basic_search';
var $formData;
var $fieldDefs;
var $customFieldDefs;
var $tabs;
var $parsedView = 'basic';
// may remove
var $searchFields;
var $displaySavedSearch = true;
// show the advanced tab
var $showAdvanced = true;
// show the basic tab
var $showBasic = true;
// array of custom tab to show declare in searchdefs (no custom tab if false)
var $showCustom = false;
// nb of tab to show
var $nbTabs = 0;
// hide saved searches drop and down near the search button
var $showSavedSearchesOptions = true;
var $displayType = 'searchView';
function SearchForm($seed, $module, $action = 'index') {
$this->th = new TemplateHandler ();
$this->th->loadSmarty ();
$this->seed = $seed;
$this->module = $module;
$this->action = $action;
$this->tabs = array (
array (
'title' => $GLOBALS ['app_strings'] ['LNK_BASIC_SEARCH'],
'link' => $module . '|basic_search',
'key' => $module . '|basic_search',
'name' => 'basic',
'displayDiv' => ''
),
array (
'title' => $GLOBALS ['app_strings'] ['LNK_ADVANCED_SEARCH'],
'link' => $module . '|advanced_search',
'key' => $module . '|advanced_search',
'name' => 'advanced',
'displayDiv' => 'display:none'
)
);
$this->searchColumns = array ();
}
function setup($searchdefs, $searchFields = array(), $tpl, $displayView = 'basic_search', $listViewDefs = array()) {;
$this->searchdefs = $searchdefs [$this->module];
$this->tpl = $tpl;
// used by advanced search
$this->listViewDefs = $listViewDefs;
$this->displayView = $displayView;
$this->view = $this->view . '_' . $displayView;
$tokens = explode ( '_', $this->displayView );
$this->parsedView = $tokens [0];
if ($this->displayView != 'saved_views') {
$this->_build_field_defs ();
}
/*
* if(file_exists('modules/' . $this->module . '/metadata/SearchFields.php'))
* require_once('modules/' . $this->module . '/metadata/SearchFields.php');
* if(file_exists('custom/modules/' . $this->module . '/metadata/SearchFields.php'))
* require_once('custom/modules/' . $this->module . '/metadata/SearchFields.php');
*/
$this->searchFields = $searchFields [$this->module];
// Setub the tab array
$this->tabs = array ();
if ($this->showBasic) {
$this->nbTabs ++;
$this->tabs [] = array (
'title' => $GLOBALS ['app_strings'] ['LNK_BASIC_SEARCH'],
'link' => $this->module . '|basic_search',
'key' => $this->module . '|basic_search',
'name' => 'basic',
'displayDiv' => ''
);
}
if ($this->showAdvanced) {
$this->nbTabs ++;
$this->tabs [] = array (
'title' => $GLOBALS ['app_strings'] ['LNK_ADVANCED_SEARCH'],
'link' => $this->module . '|advanced_search',
'key' => $this->module . '|advanced_search',
'name' => 'advanced',
'displayDiv' => 'display:none'
);
}
if ($this->showCustom) {
foreach ( $this->showCustom as $v ) {
$this->nbTabs ++;
$this->tabs [] = array (
'title' => $GLOBALS ['app_strings'] ["LNK_" . strtoupper ( $v )],
'link' => $this->module . '|' . $v,
'key' => $this->module . '|' . $v,
'name' => str_replace ( '_search', '', $v ),
'displayDiv' => 'display:none'
);
}
}
}
function display($header = true) {
global $theme, $timedate;
$header_txt = '';
$footer_txt = '';
$return_txt = '';
$this->th->ss->assign ( 'module', $this->module );
$this->th->ss->assign ( 'action', $this->action );
$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 () );
$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 = 'include/SearchForm/tpls/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->tpl );
if ($header) {
$this->th->ss->assign ( 'return_txt', $return_txt );
$header_txt = $this->th->displayTemplate ( $this->seed->module_dir, 'SearchFormHeader', 'include/SearchForm/tpls/header.tpl' );
// pass in info to render the select dropdown below the form
$footer_txt = $this->th->displayTemplate ( $this->seed->module_dir, 'SearchFormFooter', 'include/SearchForm/tpls/footer.tpl' );
$return_txt = $header_txt . $footer_txt;
}
return $return_txt;
}
function displaySavedSearch() {
$savedSearch = new SavedSearch ( $this->listViewDefs [$this->module], $this->lv->data ['pageData'] ['ordering'] ['orderBy'], $this->lv->data ['pageData'] ['ordering'] ['sortOrder'] );
return $savedSearch->getForm ( $this->module, false );
}
function displaySavedSearchSelect() {
$savedSearch = new SavedSearch ( $this->listViewDefs [$this->module], $this->lv->data ['pageData'] ['ordering'] ['orderBy'], $this->lv->data ['pageData'] ['ordering'] ['sortOrder'] );
return $savedSearch->getSelect ( $this->module );
}
/**
* displays the tabs (top of the search form)
*
* @param string $currentKey
* key in $this->tabs to show as the current tab
*
* @return string html
*/
function _displayTabs($currentKey) {
if (isset ( $_REQUEST ['saved_search_select'] ) && $_REQUEST ['saved_search_select'] != '_none') {
$saved_search = loadBean ( 'SavedSearch' );
$saved_search->retrieveSavedSearch ( $_REQUEST ['saved_search_select'] );
}
$str = '<script>';
if (! empty ( $_REQUEST ['displayColumns'] ))
$str .= 'SUGAR.savedViews.displayColumns = "' . $_REQUEST ['displayColumns'] . '";';
elseif (isset ( $saved_search->contents ['displayColumns'] ) && ! empty ( $saved_search->contents ['displayColumns'] ))
$str .= 'SUGAR.savedViews.displayColumns = "' . $saved_search->contents ['displayColumns'] . '";';
if (! empty ( $_REQUEST ['hideTabs'] ))
$str .= 'SUGAR.savedViews.hideTabs = "' . $_REQUEST ['hideTabs'] . '";';
elseif (isset ( $saved_search->contents ['hideTabs'] ) && ! empty ( $saved_search->contents ['hideTabs'] ))
$str .= 'SUGAR.savedViews.hideTabs = "' . $saved_search->contents ['hideTabs'] . '";';
if (! empty ( $_REQUEST ['orderBy'] ))
$str .= 'SUGAR.savedViews.selectedOrderBy = "' . $_REQUEST ['orderBy'] . '";';
elseif (isset ( $saved_search->contents ['orderBy'] ) && ! empty ( $saved_search->contents ['orderBy'] ))
$str .= 'SUGAR.savedViews.selectedOrderBy = "' . $saved_search->contents ['orderBy'] . '";';
if (! empty ( $_REQUEST ['sortOrder'] ))
$str .= 'SUGAR.savedViews.selectedSortOrder = "' . $_REQUEST ['sortOrder'] . '";';
elseif (isset ( $saved_search->contents ['sortOrder'] ) && ! empty ( $saved_search->contents ['sortOrder'] ))
$str .= 'SUGAR.savedViews.selectedSortOrder = "' . $saved_search->contents ['sortOrder'] . '";';
$str .= '</script>';
return $str;
}
/*
* Generate the data
*/
function _build_field_defs() {
$this->formData = array ();
$this->fieldDefs = array ();
foreach ( $this->searchdefs ['layout'] [$this->displayView] as $data ) {
if (is_array ( $data )) {
$data ['name'] = $data ['name'] . '_' . $this->parsedView;
$this->formData [] = array (
'field' => $data
);
$this->fieldDefs [$data ['name']] = $data;
} else {
$this->formData [] = array (
'field' => array (
'name' => $data . '_' . $this->parsedView
)
);
}
}
if ($this->seed) {
$this->seed->fill_in_additional_detail_fields ();
// hack to make the employee status field for the Users/Employees module display correctly
if ($this->seed->object_name == 'Employee' || $this->seed->object_name == 'User') {
$this->seed->field_defs ['employee_status'] ['type'] = 'enum';
$this->seed->field_defs ['employee_status'] ['massupdate'] = true;
$this->seed->field_defs ['employee_status'] ['options'] = 'employee_status_dom';
unset ( $this->seed->field_defs ['employee_status'] ['function'] );
}
foreach ( $this->seed->toArray () as $name => $value ) {
if (! empty ( $this->fieldDefs [$name . '_' . $this->parsedView] ))
$this->fieldDefs [$name . '_' . $this->parsedView] = array_merge ( $this->seed->field_defs [$name], $this->fieldDefs [$name . '_' . $this->parsedView] );
else {
$this->fieldDefs [$name . '_' . $this->parsedView] = $this->seed->field_defs [$name];
$this->fieldDefs [$name . '_' . $this->parsedView] ['name'] = $this->fieldDefs [$name . '_' . $this->parsedView] ['name'] . '_' . $this->parsedView;
}
if (isset ( $this->fieldDefs [$name . '_' . $this->parsedView] ['type'] ) && $this->fieldDefs [$name . '_' . $this->parsedView] ['type'] == 'relate') {
if (isset ( $this->fieldDefs [$name . '_' . $this->parsedView] ['id_name'] )) {
$this->fieldDefs [$name . '_' . $this->parsedView] ['id_name'] .= '_' . $this->parsedView;
}
}
if (isset ( $this->fieldDefs [$name . '_' . $this->parsedView] ['options'] ) && isset ( $GLOBALS ['app_list_strings'] [$this->fieldDefs [$name . '_' . $this->parsedView] ['options']] )) {
$this->fieldDefs [$name . '_' . $this->parsedView] ['options'] = $GLOBALS ['app_list_strings'] [$this->fieldDefs [$name . '_' . $this->parsedView] ['options']]; // fill in enums
}
if (isset ( $this->fieldDefs [$name . '_' . $this->parsedView] ['function'] )) {
$this->fieldDefs [$name . '_' . $this->parsedView] ['type'] = 'multienum';
if (is_array ( $this->fieldDefs [$name . '_' . $this->parsedView] ['function'] )) {
$this->fieldDefs [$name . '_' . $this->parsedView] ['function'] ['preserveFunctionValue'] = true;
}
$function = $this->fieldDefs [$name . '_' . $this->parsedView] ['function'];
if (is_array ( $function ) && isset ( $function ['name'] )) {
$function_name = $this->fieldDefs [$name . '_' . $this->parsedView] ['function'] ['name'];
} else {
$function_name = $this->fieldDefs [$name . '_' . $this->parsedView] ['function'];
}
if (! empty ( $this->fieldDefs [$name . '_' . $this->parsedView] ['function'] ['returns'] ) && $this->fieldDefs [$name . '_' . $this->parsedView] ['function'] ['returns'] == 'html') {
if (! empty ( $this->fieldDefs [$name . '_' . $this->parsedView] ['function'] ['include'] )) {
require_once ($this->fieldDefs [$name . '_' . $this->parsedView] ['function'] ['include']);
}
$value = $function_name ( $this->seed, $name, $value, $this->view );
$this->fieldDefs [$name . '_' . $this->parsedView] ['value'] = $value;
} else {
if (! isset ( $function ['params'] ) || ! is_array ( $function ['params'] )) {
$this->fieldDefs [$name . '_' . $this->parsedView] ['options'] = $function_name ( $this->seed, $name, $value, $this->view );
} else {
$this->fieldDefs [$name . '_' . $this->parsedView] ['options'] = call_user_func_array ( $function_name, $function ['params'] );
}
}
}
if (isset ( $this->fieldDefs [$name] ['type'] ) && $this->fieldDefs [$name . '_' . $this->parsedView] ['type'] == 'function' && isset ( $this->fieldDefs [$name . '_' . $this->parsedView] ['function_name'] )) {
$value = $this->callFunction ( $this->fieldDefs [$name . '_' . $this->parsedView] );
$this->fieldDefs [$name . '_' . $this->parsedView] ['value'] = $value;
}
$this->fieldDefs [$name] ['value'] = $value;
if ((! empty ( $_REQUEST [$name . '_' . $this->parsedView] ) || (isset ( $_REQUEST [$name . '_' . $this->parsedView] ) && $_REQUEST [$name . '_' . $this->parsedView] == '0')) && empty ( $this->fieldDefs [$name . '_' . $this->parsedView] ['function'] ['preserveFunctionValue'] )) {
$value = $_REQUEST [$name . '_' . $this->parsedView];
$this->fieldDefs [$name . '_' . $this->parsedView] ['value'] = $value;
}
} // foreach
}
}
/**
* Populate the searchFields from an array
*
* @param array $array
* array to search through
* @param string $switchVar
* variable to use in switch statement
* @param bool $addAllBeanFields
* true to process at all bean fields
*/
function populateFromArray(&$array, $switchVar = null, $addAllBeanFields = true) {
if ((! empty ( $array ['searchFormTab'] ) || ! empty ( $switchVar )) && ! empty ( $this->searchFields )) {
$arrayKeys = array_keys ( $array );
$searchFieldsKeys = array_keys ( $this->searchFields );
if (empty ( $switchVar ))
$switchVar = $array ['searchFormTab'];
// name of the search tab
$SearchName = str_replace ( '_search', '', $switchVar );
// add mz 2015-03-18
// check if field is date
foreach ( $this->searchFields as $name => $params ) {
include 'modules/' . $_REQUEST ['module'] . '/vardefs.php';
if ($dictionary [substr ( $_REQUEST ['module'], 0, - 1 )] ['fields'] [$name] ['type'] == 'date') {
$tmp = $params;
$tmp ['isDate'] = '1';
$tmp ['from'] = $_REQUEST [$name . '_' . $SearchName . '_from'];
$tmp ['to'] = $_REQUEST [$name . '_' . $SearchName . '_to'];
$this->searchFields [$name] = $tmp;
}
}
// end mz
if ($switchVar == 'saved_views') {
foreach ( $this->searchFields as $name => $params ) {
foreach ( $this->tabs as $tabName ) {
if (! empty ( $array [$name . '_' . $tabName ['name']] )) {
$this->searchFields [$name] ['value'] = $array [$name . '_' . $tabName ['name']];
if (empty ( $this->fieldDefs [$name . '_' . $tabName ['name']] ['value'] ))
$this->fieldDefs [$name . '_' . $tabName ['name']] ['value'] = $array [$name . '_' . $tabName ['name']];
}
}
}
if ($addAllBeanFields) {
foreach ( $this->seed->field_name_map as $key => $params ) {
if (! in_array ( $key, $searchFieldsKeys )) {
foreach ( $this->tabs->name as $tabName ) {
if (in_array ( $key . '_' . $tabName ['name'], $arrayKeys )) {
$this->searchFields [$key] = array (
'query_type' => 'default',
'value' => $array [$key . '_' . $tabName ['name']]
);
}
}
}
}
}
} else {
$fromMergeRecords = isset ( $array ['merge_module'] );
global $current_user;
foreach ( $this->searchFields as $name => $params ) {
$long_name = $name . '_' . $SearchName; /* nsingh 21648: Add additional check for bool values=0. empty() considers 0 to be empty Only repopulates if value is 0 or 1:( */
// add mz 2015-03-18
// populate date from and date to
if($long_name=='parent_name_basic')continue;
if($long_name=='parent_name_advanced')continue;
$this->fieldDefs [$long_name] ['value'] = $_REQUEST [$long_name];
if (isset ( $array [$long_name] ) && (! empty ( $array [$long_name] ) || (isset ( $this->fieldDefs [$long_name] ) && $this->fieldDefs [$long_name] ['type'] == 'bool' && ($array [$long_name] == '0' || $array [$long_name] == '1')))) { // advanced*/
$this->searchFields [$name] ['value'] = $array [$long_name];
if (empty ( $this->fieldDefs [$long_name] ['value'] ))
$this->fieldDefs [$long_name] ['value'] = $array [$long_name];
} else if (! empty ( $array [$name] ) && ! $fromMergeRecords) { // basic
$this->searchFields [$name] ['value'] = $array [$name];
if (empty ( $this->fieldDefs [$long_name] ['value'] ))
$this->fieldDefs [$long_name] ['value'] = $array [$name];
}
// // add mz 2015-03-18
// // populate date from and date to
if ($params ['isDate'] == '1') {
$this->fieldDefs [$long_name] ['value_from'] = $params['from'];
$this->fieldDefs [$long_name] ['value_to'] = $params['to'];
}
}
if ((empty ( $array ['massupdate'] ) || $array ['massupdate'] == 'false') && $addAllBeanFields) {
foreach ( $this->seed->field_name_map as $key => $params ) {
if ($key != 'assigned_user_name' && $key != 'modified_by_name') {
if (in_array ( $key . '_' . $SearchName, $arrayKeys ) && ! in_array ( $key, $searchFieldsKeys )) {
$this->searchFields [$key] = array (
'query_type' => 'default',
'value' => $array [$key . '_' . $SearchName]
);
if (! empty ( $params ['type'] ) && $params ['type'] == 'parent' && ! empty ( $params ['type_name'] ) && ! empty ( $this->searchFields [$key] ['value'] )) {
$this->searchFields [$params ['type_name']] = array (
'query_type' => 'default',
'value' => $array [$params ['type_name']]
);
}
}
}
}
}
}
}
}
/**
* Populate the searchFields from $_REQUEST
*
* @param string $switchVar
* variable to use in switch statement
* @param bool $addAllBeanFields
* true to process at all bean fields
*/
function populateFromRequest($switchVar = null, $addAllBeanFields = true) {
$this->populateFromArray ( $_REQUEST, $switchVar, $addAllBeanFields );
}
function generateSearchWhere($add_custom_fields = false, $module = '') {
global $timedate;
global $current_user;
$this->searchColumns = array ();
$values = $this->searchFields;
$where_clauses = array ();
$like_char = '%';
$table_name = $this->seed->object_name;
$this->seed->fill_in_additional_detail_fields ();
// rrs check for team_id
foreach ( $this->searchFields as $field => $parms ) {
if($field=='part_no' && $_REQUEST['module']=='EcmProducts')continue;
$customField = false;
// Jenny - Bug 7462: We need a type check here to avoid database errors
// when searching for numeric fields. This is a temporary fix until we have
// a generic search form validation mechanism.
$type = (! empty ( $this->seed->field_name_map [$field] ['type'] )) ? $this->seed->field_name_map [$field] ['type'] : '';
if (! empty ( $this->seed->field_name_map [$field] ['source'] ) && ($this->seed->field_name_map [$field] ['source'] == 'custom_fields' ||
// Non-db custom fields, such as custom relates
($this->seed->field_name_map [$field] ['source'] == 'non-db' && (! empty ( $this->seed->field_name_map [$field] ['custom_module'] ) || isset ( $this->seed->field_name_map [$field] ['ext2'] ))))) {
$customField = true;
}
if ($type == 'int') {
if (! empty ( $parms ['value'] )) {
$tempVal = explode ( ',', $parms ['value'] );
$newVal = '';
foreach ( $tempVal as $key => $val ) {
if (! empty ( $newVal ))
$newVal .= ',';
if (! empty ( $val ) && ! (is_numeric ( $val )))
$newVal .= - 1;
else
$newVal .= $val;
}
$parms ['value'] = $newVal;
}
}
// Navjeet- 6/24/08 checkboxes have been changed to dropdowns, so we can query unchecked checkboxes! Bug: 21648.
// elseif($type == 'bool' && empty($parms['value']) && preg_match("/current_user_only/", string subject, array subpatterns, int flags, [int offset])) {
// continue;
// }
//
elseif ($type == 'html' && $customField) {
continue;
}
if ((isset ( $parms ['value'] ) && $parms ['value'] != "") || $type == 'date') {
$operator = 'like';
if (! empty ( $parms ['operator'] )) {
$operator = $parms ['operator'];
}
if (is_array ( $parms ['value'] )) {
$field_value = '';
// always construct the where clause for multiselects using the 'like' form to handle combinations of multiple $vals and multiple $parms
if(/*$GLOBALS['db']->dbType != 'mysql' &&*/ ! empty ( $this->seed->field_name_map [$field] ['isMultiSelect'] ) && $this->seed->field_name_map [$field] ['isMultiSelect']) {
// construct the query for multenums
// use the 'like' query for all mssql and oracle examples as both custom and OOB multienums are implemented with types that cannot be used with an 'in'
$operator = 'custom_enum';
$table_name = $this->seed->table_name;
if ($customField)
$table_name .= "_cstm";
$db_field = $table_name . "." . $field;
foreach ( $parms ['value'] as $key => $val ) {
if ($val != ' ' and $val != '') {
$qVal = $GLOBALS ['db']->quote ( $val );
if (! empty ( $field_value )) {
$field_value .= ' or ';
}
$field_value .= "$db_field like '%^$qVal^%'";
}
}
} else {
$operator = $operator != 'subquery' ? 'in' : $operator;
foreach ( $parms ['value'] as $key => $val ) {
if ($val != ' ' and $val != '') {
if (! empty ( $field_value )) {
$field_value .= ',';
}
$field_value .= "'" . $GLOBALS ['db']->quote ( $val ) . "'";
}
}
}
} else {
$field_value = $GLOBALS ['db']->quote ( $parms ['value'] );
}
// set db_fields array.
if (! isset ( $parms ['db_field'] )) {
$parms ['db_field'] = array (
$field
);
}
if (isset ( $parms ['my_items'] ) and $parms ['my_items'] == true) {
if ($parms ['value'] == false) { // do not include where clause for custom fields with checkboxes that are unchecked
continue;
} else { // my items is checked.
global $current_user;
$field_value = $GLOBALS ['db']->quote ( $current_user->id );
$operator = '=';
}
// $operator = ($parms['value'] == '1') ? '=' : '!=';
}
$where = '';
$itr = 0;
if ($field_value != '' || $type == 'date') {
$this->searchColumns [strtoupper ( $field )] = $field;
foreach ( $parms ['db_field'] as $db_field ) {
if (strstr ( $db_field, '.' ) === false) {
// Try to get the table for relate fields from link defs
if ($type == 'relate' && ! empty ( $this->seed->field_name_map [$field] ['link'] ) && ! empty ( $this->seed->field_name_map [$field] ['rname'] )) {
$link = $this->seed->field_name_map [$field] ['link'];
$relname = $link ['relationship'];
if (($this->seed->load_relationship ( $link ))) {
// Martin fix #27494
$db_field = $this->seed->field_name_map [$field] ['name'];
} else {
// Best Guess for table name
$db_field = strtolower ( $link ['module'] ) . '.' . $db_field;
}
} else if ($type == 'parent') {
if (! empty ( $this->searchFields ['parent_type'] )) {
$parentType = $this->searchFields ['parent_type'];
$rel_module = $parentType ['value'];
global $beanFiles, $beanList;
if (! empty ( $beanFiles [$beanList [$rel_module]] )) {
require_once ($beanFiles [$beanList [$rel_module]]);
$rel_seed = new $beanList [$rel_module] ();
$db_field = 'parent_' . $rel_module . '_' . $rel_seed->table_name . '.name';
}
}
} // Relate fields in custom modules and custom relate fields
else if ($type == 'relate' && $customField && ! empty ( $this->seed->field_name_map [$field] ['module'] )) {
$db_field = ! empty ( $this->seed->field_name_map [$field] ['name'] ) ? $this->seed->field_name_map [$field] ['name'] : 'name';
} else if (! $customField) {
if (! empty ( $this->seed->field_name_map [$field] ['db_concat_fields'] ))
$db_field = db_concat ( $this->seed->table_name, $this->seed->field_name_map [$db_field] ['db_concat_fields'] );
else
$db_field = $this->seed->table_name . "." . $db_field;
} else {
if (! empty ( $this->seed->field_name_map [$field] ['db_concat_fields'] ))
$db_field = db_concat ( $this->seed->table_name . "_cstm.", $this->seed->field_name_map [$db_field] ['db_concat_fields'] );
else
$db_field = $this->seed->table_name . "_cstm." . $db_field;
}
}
if ($type == 'date') {
// Collin - Have mysql as first because it's usually the case
// The regular expression check is to circumvent special case YYYY-MM
if ($GLOBALS ['db']->dbType == 'mysql') {
if (preg_match ( '/^\d{4}.\d{1,2}$/', $field_value ) == 0) {
//add mz 2015-03-19
//deal with date from and date to
if ((empty ($_REQUEST [$field . '_' . $this->parsedView . '_from'] ) || $_REQUEST [$field . '_' . $this->parsedView . '_from'] == '') && (!empty ( $_REQUEST [$field . '_' . $this->parsedView . '_to'] ) || $_REQUEST [$field . '_' . $this->parsedView . '_from'] != ''))
$_REQUEST [$field . '_' . $this->parsedView . '_from'] = '01.01.1900';
if ((!empty ($_REQUEST [$field . '_' . $this->parsedView . '_from'] ) || $_REQUEST [$field . '_' . $this->parsedView . '_from'] != '') && (empty ( $_REQUEST [$field . '_' . $this->parsedView . '_to'] ) || $_REQUEST [$field . '_' . $this->parsedView . '_from'] == ''))
$_REQUEST [$field . '_' . $this->parsedView . '_to'] = '31.12.2100';
if (empty ( $_REQUEST [$field . '_' . $this->parsedView . '_from'] ) || $_REQUEST [$field . '_' . $this->parsedView . '_from'] == '' || empty ( $_REQUEST [$field . '_' . $this->parsedView . '_to'] ) || $_REQUEST [$field . '_' . $this->parsedView . '_from'] == '')
continue; // nothing to do
$from = $timedate->to_db_date ( $_REQUEST [$field . '_' . $this->parsedView . '_from'], false ) . ' 00:00:00';
$to = $timedate->to_db_date ( $_REQUEST [$field . '_' . $this->parsedView . '_to'], false ) . ' 23:59:59';
$field_value = $from . '<>' . $to;
$operator = 'between';
} else {
$operator = 'db_date';
}
} else if ($GLOBALS ['db']->dbType == 'mssql') {
if (preg_match ( '/^\d{4}.\d{1,2}$/', $field_value ) == 0) {
$field_value = "Convert(DateTime, '" . $timedate->to_db_date ( $field_value, false ) . "')";
}
$operator = 'db_date';
} else {
$field_value = $timedate->to_db_date ( $field_value, false );
$operator = '=';
}
}
if ($type == 'datetime' || $type == 'datetimecombo') { // bug 22564, date type field may also have this problem. we may add a date type here.
$field_value = $timedate->to_db_date ( $field_value, false ); // This think of the timezone problem
$temp_offset = strtotime ( $timedate->swap_formats ( $timedate->to_display_date_time ( $field_value . " 00:00:00" ), $timedate->get_date_time_format (), $timedate->get_db_date_time_format () ) ) - strtotime ( $field_value . " 00:00:00" );
$start_datetime = date ( "Y-m-d H:i:s", strtotime ( $field_value . " 00:00:00" ) - $temp_offset );
$end_datetime = date ( "Y-m-d H:i:s", strtotime ( $field_value . " 23:59:59" ) - $temp_offset );
$field_value = $start_datetime . "<>" . $end_datetime;
$operator = 'between';
}
if ($type == 'decimal' || $type == 'float' || $type == 'currency') {
require_once ('modules/Currencies/Currency.php');
$field_value = unformat_number ( $field_value );
if ($type == 'currency' && stripos ( $field, '_usdollar' ) !== FALSE) {
// It's a US Dollar field, we need to do some conversions from the user's local currency
$currency_id = $GLOBALS ['current_user']->getPreference ( 'currency' );
if (empty ( $currency_id )) {
$currency_id = - 99;
}
if ($currency_id != - 99) {
$currency = new Currency ();
$currency->retrieve ( $currency_id );
$field_value = $currency->convertToDollar ( $field_value );
}
}
// Databases can't really search for floating point numbers, because they can't be accurately described in binary,
// So we have to fuzz out the match a little bit
$top = $field_value + 0.01;
$bottom = $field_value - 0.01;
$field_value = $bottom . "<>" . $top;
$operator = 'between';
}
$itr ++;
if (! empty ( $where )) {
$where .= " OR ";
}
switch (strtolower ( $operator )) {
case 'subquery' :
$in = 'IN';
if (isset ( $parms ['subquery_in_clause'] )) {
if (! is_array ( $parms ['subquery_in_clause'] )) {
$in = $parms ['subquery_in_clause'];
} elseif (isset ( $parms ['subquery_in_clause'] [$field_value] )) {
$in = $parms ['subquery_in_clause'] [$field_value];
}
}
$sq = $parms ['subquery'];
if (is_array ( $sq )) {
$and_or = ' AND ';
if (isset ( $sq ['OR'] )) {
$and_or = ' OR ';
}
$first = true;
foreach ( $sq as $q ) {
if (empty ( $q ) || strlen ( $q ) < 2)
continue;
if (! $first) {
$where .= $and_or;
}
$where .= " {$db_field} $in ({$q} '{$field_value}%') ";
$first = false;
}
} elseif (! empty ( $parms ['query_type'] ) && $parms ['query_type'] == 'format') {
$stringFormatParams = array (
0 => $field_value,
1 => $GLOBALS ['current_user']->id
);
$where .= "{$db_field} $in (" . string_format ( $parms ['subquery'], $stringFormatParams ) . ")";
} else {
$where .= "{$db_field} $in ({$parms['subquery']} '{$field_value}%')";
}
break;
case 'like' :
if ($type == 'bool' && $field_value == 0) {
$where .= $db_field . " = '0' OR " . $db_field . " IS NULL";
} else {
// check to see if this is coming from unified search or not
$UnifiedSearch = ! empty ( $parms ['force_unifiedsearch'] );
if (isset ( $_REQUEST ['action'] ) && $_REQUEST ['action'] == 'UnifiedSearch') {
$UnifiedSearch = true;
}
// check to see if this is a universal search, AND the field name is "last_name"
if ($UnifiedSearch && strpos ( $db_field, 'last_name' ) !== false) {
// split the string value, and the db field name
$string = explode ( ' ', $field_value );
$column_name = explode ( '.', $db_field );
// when a search is done with a space, we concatenate and search against the full name.
if (count ( $string ) > 1) {
// add where clause agains concatenated fields
$where .= $GLOBALS ['db']->concat ( $column_name [0], array (
'first_name',
'last_name'
) ) . " LIKE '{$field_value}%'";
$where .= ' OR ' . $GLOBALS ['db']->concat ( $column_name [0], array (
'last_name',
'first_name'
) ) . " LIKE '{$field_value}%'";
} else {
// no space was found, add normal where clause
$where .= $db_field . " like '" . $field_value . $like_char . "'";
}
} else {
// field is not last name or this is not from global unified search, so do normal where clause
if($type=='id' && $db_field=='ecmsales.parent_id'){
$where .= $db_field . " = '" . $field_value . "'";
} else {
$where .= $db_field . " like '" . $field_value . $like_char . "'";
}
}
}
break;
case 'in' :
$where .= $db_field . " in (" . $field_value . ')';
break;
case '=' :
if ($type == 'bool' && $field_value == 0) {
$where .= $db_field . " = '0' OR " . $db_field . " IS NULL";
} else {
$where .= $db_field . " = '" . $field_value . "'";
}
break;
case 'db_date' :
if (preg_match ( '/^\d{4}.\d{1,2}$/', $field_value ) == 0) {
$where .= $db_field . " = " . $field_value;
} else {
// Create correct date_format conversion String
if ($GLOBALS ['db']->dbType == 'oci8') {
$where .= db_convert ( $db_field, 'date_format', array (
"'YYYY-MM'"
) ) . " = '" . $field_value . "'";
} else {
$where .= db_convert ( $db_field, 'date_format', array (
"'%Y-%m'"
) ) . " = '" . $field_value . "'";
}
}
break;
// tyoung bug 15971 - need to add these special cases into the $where query
case 'custom_enum' :
$where .= $field_value;
break;
case 'between' :
$field_value = explode ( '<>', $field_value );
$where .= $db_field . " >= '" . $field_value [0] . "' AND " . $db_field . " < '" . $field_value [1] . "'";
break;
case 'innerjoin' :
$this->seed->listview_inner_join [] = $parms ['innerjoin'] . " '" . $parms ['value'] . "%')";
break;
}
}
}
if (! empty ( $where )) {
if ($itr > 1) {
array_push ( $where_clauses, '( ' . $where . ' )' );
} else {
array_push ( $where_clauses, $where );
}
}
}
}
return $where_clauses;
}
}
?>

247
include/SearchForm/SugarSpot.php Executable file
View File

@@ -0,0 +1,247 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
class SugarSpot
{
/**
* Performs the search and returns the HTML widget containing the results
*
* @param $query string what we are searching for
* @param $modules array modules we are searching in
* @param $offset int search result offset
* @return string HTML widget
*/
public function searchAndDisplay(
$query,
$modules,
$offset = -1
)
{
$results = $this->_performSearch($query, $modules, $offset);
$str = '<div id="SpotResults">';
$actions=0;
$foundData = false;
foreach($results as $m=>$data){
if(empty($data['data'])){
continue;
}
$foundData = true;
$countRemaining = $data['pageData']['offsets']['total'] - count($data['data']);
if($offset > 0) $countRemaining -= $offset;
$more = '';
$data['pageData']['offsets']['next']++;
if($countRemaining > 0){
$more = <<<EOHTML
<small class='more' onclick="DCMenu.spotZoom('$query', '$m','{$data['pageData']['offsets']['next']}' )">($countRemaining more)</small>
EOHTML;
}
$str.= "<div>$m $more</div>";
$str.= '<ul>';
foreach($data['data'] as $row){
$name = '';
if(!empty($row['NAME'])){
$name = $row['NAME'];
}else{
foreach($row as $k=>$v){
if(strpos($k, 'NAME') !== false){
$name = $v;
break;
}
}
}
$str .= <<<EOHTML
<li><a href="index.php?module={$data['pageData']['bean']['moduleDir']}&action=DetailView&record={$row['ID']}">$name</a></li>
EOHTML;
}
$str.= '</ul>';
}
$str .= <<<EOHTML
<button onclick="document.location.href='index.php?module=Home&action=UnifiedSearch&search_form=false&advanced=false&query_string={$query}'">{$GLOBALS['app_strings']['LBL_EMAIL_SHOW_READ']}</button>
</div>
EOHTML;
return $str;
}
/**
* Returns the array containing the $searchFields for a module
*
* @param $moduleName string
* @return array
*/
protected function getSearchFields(
$moduleName
)
{
if(file_exists("modules/{$moduleName}/metadata/SearchFields.php")) {
$searchFields = array();
require "modules/{$moduleName}/metadata/SearchFields.php" ;
return $searchFields;
}
else {
return array();
}
}
/**
* Performs the search
*
* @param $query string what we are searching for
* @param $modules array modules we are searching in
* @param $offset int search result offset
* @return array
*/
protected function _performSearch(
$query,
$modules,
$offset = -1
)
{
$primary_module='';
$results = array();
require_once 'include/SearchForm/SearchForm2.php' ;
$where = '';
$searchEmail = preg_match("/^([^\%]|\%)*@([^\%]|\%)*$/", $query);
foreach($modules as $moduleName){
if (empty($primary_module)) $primary_module=$moduleName;
$searchFields = SugarSpot::getSearchFields($moduleName);
$class = $GLOBALS['beanList'][$moduleName];
$return_fields = array();
$seed = new $class();
if (empty($searchFields[$moduleName]))
continue;
if ($class == 'aCase') {
$class = 'Case';
}
foreach($searchFields[$moduleName] as $k=>$v){
$keep = false;
$searchFields[$moduleName][$k]['value'] = $query;
if(!empty($GLOBALS['dictionary'][$class]['unified_search'])){
if(empty($GLOBALS['dictionary'][$class]['fields'][$k]['unified_search'])){
if(isset($searchFields[$moduleName][$k]['db_field'])){
foreach($searchFields[$moduleName][$k]['db_field'] as $field){
if(!empty($GLOBALS['dictionary'][$class]['fields'][$field]['unified_search'])){
$return_fields[] = $field;
$keep = true;
}
}
}
if(!$keep){
if(strpos($k,'email') === false || !$searchEmail) {
unset($searchFields[$moduleName][$k]);
}
}
}else{
$return_fields[] = $k;
}
}else if(empty($GLOBALS['dictionary'][$class]['fields'][$k]) ){;
unset($searchFields[$moduleName][$k]);
}else{
switch($GLOBALS['dictionary'][$class]['fields'][$k]['type']){
case 'id':
case 'date':
case 'datetime':
case 'bool':
unset($searchFields[$moduleName][$k]);
default:
$return_fields[] = $k;
}
}
}
$searchForm = new SearchForm ( $seed, $moduleName ) ;
$searchForm->setup (array ( $moduleName => array() ) , $searchFields , '' , 'saved_views' /* hack to avoid setup doing further unwanted processing */ ) ;
$where_clauses = $searchForm->generateSearchWhere() ;
$where = "";
if (count($where_clauses) > 0 ){
$where = '('. implode(' ) OR ( ', $where_clauses) . ')';
}
$lvd = new ListViewData();
$lvd->additionalDetails = false;
$max = ( !empty($sugar_config['max_spotresults_initial']) ? $sugar_config['max_spotresults_initial'] : 5 );
if($offset !== -1){
$max = ( !empty($sugar_config['max_spotresults_more']) ? $sugar_config['max_spotresults_more'] : 20 );
}
$params = array();
if ( $moduleName == 'Reports') {
$params['overrideOrder'] = true;
$params['orderBy'] = 'name';
}
$results[$moduleName]= $lvd->getListViewData($seed, $where, $offset, $max, $return_fields,$params,'id') ;
}
return $results;
}
/**
* Function used to walk the array and find keys that map the queried string.
* if both the pattern and module name is found the promote the string to thet top.
*/
protected function _searchKeys(
$item1,
$key,
$patterns
)
{
//make the module name singular....
if ($patterns[1][strlen($patterns[1])-1] == 's') {
$patterns[1]=substr($patterns[1],0,(strlen($patterns[1])-1));
}
$module_exists = stripos($key,$patterns[1]); //primary module name.
$pattern_exists = stripos($key,$patterns[0]); //pattern provided by the user.
if ($module_exists !== false and $pattern_exists !== false) {
$GLOBALS['matching_keys']= array_merge(array(array('NAME'=>$key, 'ID'=>$key, 'VALUE'=>$item1)),$GLOBALS['matching_keys']);
}
else {
if ($pattern_exists !== false) {
$GLOBALS['matching_keys'][]=array('NAME'=>$key, 'ID'=>$key, 'VALUE'=>$item1);
}
}
}
}

View File

@@ -0,0 +1,82 @@
{*
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
*}
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
{{foreach name=colIteration from=$formData key=col item=colData}}
{counter assign=index}
{math equation="left % right"
left=$index
right=$templateMeta.maxColumns
assign=modVal
}
{if ($index % $templateMeta.maxColumns == 1 && $index != 1)}
</tr><tr>
{/if}
<td scope="row" nowrap="nowrap" width='1%' >
{{if isset($colData.field.label)}}
{sugar_translate label='{{$colData.field.label}}' module='{{$module}}'}
{{elseif isset($fields[$colData.field.name])}}
{sugar_translate label='{{$fields[$colData.field.name].vname}}' module='{{$module}}'}
{{/if}}
</td>
<td nowrap="nowrap" width='1%'>
{{if $fields[$colData.field.name]}}
{{sugar_field parentFieldArray='fields' vardef=$fields[$colData.field.name] displayType='searchView' displayParams=$colData.field.displayParams typeOverride=$colData.field.type formName=$form_name}}
{{/if}}
</td>
{{/foreach}}
{if $formData|@count >= $templateMeta.maxColumns}
</tr>
<tr>
<td colspan="{$searchTableColumnCount}">
{else}
<td style="padding-left: 10px !important;">
{/if}
<input tabindex='2' title='{$APP.LBL_SEARCH_BUTTON_TITLE}' accessKey='{$APP.LBL_SEARCH_BUTTON_KEY}' onclick='SUGAR.savedViews.setChooser()' class='button' type='submit' name='button' value='{$APP.LBL_SEARCH_BUTTON_LABEL}' id='search_form_submit'/>&nbsp;
<input tabindex='2' title='{$APP.LBL_CLEAR_BUTTON_TITLE}' accessKey='{$APP.LBL_CLEAR_BUTTON_KEY}' onclick='SUGAR.searchForm.clear_form(this.form);' class='button' type='button' name='clear' id='search_form_clear' value='{$APP.LBL_CLEAR_BUTTON_LABEL}'/>
{if $HAS_ADVANCED_SEARCH}
&nbsp;&nbsp;<a onclick="SUGAR.searchForm.searchFormSelect('{$module}|advanced_search','{$module}|basic_search')" href="#">{$APP.LNK_ADVANCED_SEARCH}</a>
{/if}
</td>
<td style="text-align: right" width="*"><img border='0' src='{sugar_getimagepath file="help-dashlet.gif"}' onmouseover="return overlib(SUGAR.language.get('app_strings', 'LBL_SEARCH_HELP_TEXT'), STICKY, MOUSEOFF,1000,WIDTH, 700, LEFT,CAPTION,'<div style=\'float:left\'>'+SUGAR.language.get('app_strings', 'LBL_SEARCH_HELP_TITLE')+'</div>', CLOSETEXT, '<div style=\'float: right\'><img border=0 style=\'margin-left:2px; margin-right: 2px;\' src={sugar_getimagepath file='close.gif'}></div>',CLOSETITLE, SUGAR.language.get('app_strings', 'LBL_SEARCH_HELP_CLOSE_TOOLTIP'), CLOSECLICK,FGCLASS, 'olFgClass', CGCLASS, 'olCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olCapFontClass');" class="help-search"></td>
</tr>
</table>

View File

@@ -0,0 +1,100 @@
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
{{foreach name=colIteration from=$formData key=col item=colData}}
{counter assign=index}
{math equation="left % right"
left=$index
right=$templateMeta.maxColumns
assign=modVal
}
{if ($index % $templateMeta.maxColumns == 1 && $index != 1)}
</tr><tr>
{/if}
<td scope="row" nowrap="nowrap" width='{{$templateMeta.widths.label}}%' >
{{if isset($colData.field.label)}}
{sugar_translate label='{{$colData.field.label}}' module='{{$module}}'}
{{elseif isset($fields[$colData.field.name])}}
{sugar_translate label='{{$fields[$colData.field.name].vname}}' module='{{$module}}'}
{{/if}}
</td>
<td nowrap="nowrap" width='{{$templateMeta.widths.field}}%'>
{{if $fields[$colData.field.name]}}
{{sugar_field parentFieldArray='fields' vardef=$fields[$colData.field.name] displayType=$displayType displayParams=$colData.field.displayParams typeOverride=$colData.field.type formName=$form_name}}
{{/if}}
</td>
{{/foreach}}
</tr>
<tr>
<td colspan='20'>
&nbsp;
</td>
</tr>
{if $DISPLAY_SAVED_SEARCH}
<tr>
<td colspan='2'>
<a class='tabFormAdvLink' onhover href='javascript:toggleInlineSearch()'>
<img src='{sugar_getimagepath file="advanced_search.gif"}' id='up_down_img' border=0>&nbsp;{$APP.LNK_SAVED_VIEWS}
</a><br>
<input type='hidden' id='showSSDIV' name='showSSDIV' value='{$SHOWSSDIV}'><p>
</td>
<td scope='row' width='10%' nowrap="nowrap">
{sugar_translate label='LBL_SAVE_SEARCH_AS' module='SavedSearch'}:
</td>
<td width='30%' nowrap>
<input type='text' name='saved_search_name'>
<input type='hidden' name='search_module' value=''>
<input type='hidden' name='saved_search_action' value=''>
<input title='{$APP.LBL_SAVE_BUTTON_LABEL}' value='{$APP.LBL_SAVE_BUTTON_LABEL}' class='button' type='button' name='saved_search_submit' onclick='SUGAR.savedViews.setChooser(); return SUGAR.savedViews.saved_search_action("save");'>
</td>
<td scope='row' width='10%' nowrap="nowrap">
{sugar_translate label='LBL_MODIFY_CURRENT_SEARCH' module='SavedSearch'}:
</td>
<td width='30%' nowrap>
<input class='button' onclick='SUGAR.savedViews.setChooser(); return SUGAR.savedViews.saved_search_action("update")' value='{$APP.LBL_UPDATE}' title='{$APP.LBL_UPDATE}' name='ss_update' id='ss_update' type='button' >
<input class='button' onclick='return SUGAR.savedViews.saved_search_action("delete", "{sugar_translate label='LBL_DELETE_CONFIRM' module='SavedSearch'}")' value='{$APP.LBL_DELETE}' title='{$APP.LBL_DELETE}' name='ss_delete' id='ss_delete' type='button'>
<br><span id='curr_search_name'></span>
</td>
</tr>
<tr>
<td colspan='6'>
<div style='{$DISPLAYSS}' id='inlineSavedSearch' >
{$SAVED_SEARCH}
</div>
</td>
</tr>
{/if}
{if $displayType != 'popupView'}
<tr>
<td colspan='5'>
<input tabindex='2' title='{$APP.LBL_SEARCH_BUTTON_TITLE}' accessKey='{$APP.LBL_SEARCH_BUTTON_KEY}' onclick='SUGAR.savedViews.setChooser()' class='button' type='submit' name='button' value='{$APP.LBL_SEARCH_BUTTON_LABEL}' id='search_form_submit'/>&nbsp;
<input tabindex='2' title='{$APP.LBL_CLEAR_BUTTON_TITLE}' accessKey='{$APP.LBL_CLEAR_BUTTON_KEY}' onclick='SUGAR.searchForm.clear_form(this.form);' class='button' type='button' name='clear' id='search_form_clear' value='{$APP.LBL_CLEAR_BUTTON_LABEL}'/>
{if $DOCUMENTS_MODULE}
&nbsp;<input title="{$APP.LBL_BROWSE_DOCUMENTS_BUTTON_TITLE}" accessKey="{$APP.LBL_BROWSE_DOCUMENTS_BUTTON_KEY}" type="button" class="button" value="{$APP.LBL_BROWSE_DOCUMENTS_BUTTON_LABEL}" onclick='open_popup("Documents", 600, 400, "&caller=Documents", true, false, "");' />
{/if}
<a id="basic_search_link" onclick="SUGAR.searchForm.searchFormSelect('{$module}|basic_search','{$module}|advanced_search')" href="#">{$APP.LNK_BASIC_SEARCH}</a>
<span class='white-space'>
&nbsp;&nbsp;&nbsp;{if $SAVED_SEARCHES_OPTIONS}|&nbsp;&nbsp;&nbsp;<b>{$APP.LBL_SAVED_SEARCH_SHORTCUT}</b>&nbsp;
{$SAVED_SEARCHES_OPTIONS} {/if}
<span id='go_btn_span' style='display:none'><input tabindex='2' title='go_select' id='go_select' onclick='SUGAR.searchForm.clear_form(this.form);' class='button' type='button' name='go_select' value=' {$APP.LBL_GO_BUTTON_LABEL} '/></span>
</span>
</td>
<td style="text-align: right">
{if $DISPLAY_SEARCH_HELP}
<img border='0' src='{sugar_getimagepath file="help-dashlet.gif"}' onmouseover="return overlib(SUGAR.language.get('app_strings', 'LBL_SEARCH_HELP_TEXT'), STICKY, MOUSEOFF,1000,WIDTH, 700, LEFT,CAPTION,'<div style=\'float:left\'>'+SUGAR.language.get('app_strings', 'LBL_SEARCH_HELP_TITLE')+'</div>', CLOSETEXT, '<div style=\'float: right\'><img border=0 style=\'margin-left:2px; margin-right: 2px;\' src={sugar_getimagepath file='close.gif'}></div>',CLOSETITLE, SUGAR.language.get('app_strings', 'LBL_SEARCH_HELP_CLOSE_TOOLTIP'), CLOSECLICK,FGCLASS, 'olFgClass', CGCLASS, 'olCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olCapFontClass');" class="help-search">
{/if}
</td>
</tr>
{/if}
</table>
<script>
{literal}
if(typeof(loadSSL_Scripts)=='function'){
loadSSL_Scripts();
}
{/literal}
</script>

View File

@@ -0,0 +1,66 @@
{*
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
*}
</form>
<input type='button' name='show_panel' onclick='checkdis();' value='Pokaż Schowaj panel'/>
{literal}
<script>
function checkdis()
{
if(document.getElementById("search_form").style.display == "none"){
document.getElementById("search_form").style.display = "block";
}else{
document.getElementById("search_form").style.display = "none";
}
}
function toggleInlineSearch()
{
if (document.getElementById('inlineSavedSearch').style.display == 'none'){
document.getElementById('showSSDIV').value = 'yes'
document.getElementById('inlineSavedSearch').style.display = '';
{/literal}
document.getElementById('up_down_img').src='{sugar_getimagepath file="basic_search.gif"}';
{literal}
}else{
{/literal}
document.getElementById('up_down_img').src='{sugar_getimagepath file="advanced_search.gif"}';
{literal}
document.getElementById('showSSDIV').value = 'no';
document.getElementById('inlineSavedSearch').style.display = 'none';
}
}
</script>
{/literal}

View File

@@ -0,0 +1,53 @@
{*
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
*}
<div class='listViewBody'>
<script type="text/javascript" src="{sugar_getjspath file='include/javascript/popup_parent_helper.js'}"></script>
{$TABS}
{{if $displayView == saved_views }}
{literal}
<script>SUGAR.savedViews.handleForm();</script>
{/literal}
{{/if}}
<form name='search_form' id='search_form' class='search_form' method='post' action='index.php?module={$module}&action={$action}'>
<input type='hidden' name='searchFormTab' value='{$displayView}'/>
<input type='hidden' name='module' value='{$module}'/>
<input type='hidden' name='action' value='{$action}'/>
<input type='hidden' name='query' value='true'/>
{foreach name=tabIteration from=$TAB_ARRAY key=tabkey item=tabData}
<div id='{$module}{$tabData.name}_searchSearchForm' style='{$tabData.displayDiv}' class="edit view search {$tabData.name}">{if $tabData.displayDiv}{else}{$return_txt}{/if}</div>
{/foreach}
<div id='{$module}saved_viewsSearchForm' {{if $displayView != 'saved_views'}}style='display: none';{{/if}}>{$saved_views_txt}</div>