[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/include/utils/ -> SearchUtils.php (source)

   1  <?php
   2  
   3  /*********************************************************************************
   4  ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
   5   * ("License"); You may not use this file except in compliance with the License
   6   * The Original Code is:  vtiger CRM Open Source
   7   * The Initial Developer of the Original Code is vtiger.
   8   * Portions created by vtiger are Copyright (C) vtiger.
   9   * All Rights Reserved.
  10  *
  11   ********************************************************************************/
  12  
  13  
  14  require_once ('include/database/PearDatabase.php');
  15  require_once ('include/database/Postgres8.php');
  16  require_once ('include/ComboUtil.php'); //new
  17  require_once ('include/utils/CommonUtils.php'); //new
  18      
  19  $column_array=array('accountid','contact_id','product_id','campaignid');
  20  $table_col_array=array('vtiger_account.accountname','vtiger_contactdetails.firstname,vtiger_contactdetails.lastname','vtiger_products.productname','vtiger_campaign.campaignname');
  21  
  22  /**This function is used to get the list view header values in a list view during search
  23  *Param $focus - module object
  24  *Param $module - module name
  25  *Param $sort_qry - sort by value
  26  *Param $sorder - sorting order (asc/desc)
  27  *Param $order_by - order by
  28  *Param $relatedlist - flag to check whether the header is for listvie or related list
  29  *Param $oCv - Custom view object
  30  *Returns the listview header values in an array
  31  */
  32  
  33  function getSearchListHeaderValues($focus, $module,$sort_qry='',$sorder='',$order_by='',$relatedlist='',$oCv='')
  34  {
  35      global $log;
  36      $log->debug("Entering getSearchListHeaderValues(".$focus.",". $module.",".$sort_qry.",".$sorder.",".$order_by.",".$relatedlist.",".$oCv.") method ...");
  37          global $adb;
  38          global $theme;
  39          global $app_strings;
  40          global $mod_strings,$current_user;
  41  
  42          $arrow='';
  43          $qry = getURLstring($focus);
  44          $theme_path="themes/".$theme."/";
  45          $image_path=$theme_path."images/";
  46          $search_header = Array();
  47  
  48          //Get the vtiger_tabid of the module
  49          //require_once('include/utils/UserInfoUtil.php')
  50          $tabid = getTabid($module);
  51          //added for vtiger_customview 27/5
  52          if($oCv)
  53          {
  54                  if(isset($oCv->list_fields))
  55          {
  56                          $focus->list_fields = $oCv->list_fields;
  57                  }
  58          }
  59      //Added to reduce the no. of queries logging for non-admin vtiger_users -- by Minnie-start
  60      $field_list ='(';
  61      $j=0;
  62      require('user_privileges/user_privileges_'.$current_user->id.'.php');
  63      foreach($focus->list_fields as $name=>$tableinfo)
  64      {
  65          $fieldname = $focus->list_fields_name[$name];
  66          if($oCv)
  67          {
  68              if(isset($oCv->list_fields_name))
  69              {
  70                  $fieldname = $oCv->list_fields_name[$name];
  71              }
  72          }
  73          if($j != 0)
  74          {
  75              $field_list .= ', ';
  76          }
  77          $field_list .= "'".$fieldname."'";
  78          $j++;
  79      }
  80      $field_list .=')';
  81      //Getting the Entries from Profile2 vtiger_field vtiger_table
  82      if($is_admin == false)
  83      {
  84          $profileList = getCurrentUserProfileList();
  85          //changed to get vtiger_field.fieldname
  86          $query  = "SELECT vtiger_profile2field.*,vtiger_field.fieldname FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid=vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid=vtiger_field.fieldid WHERE vtiger_field.tabid=".$tabid." AND vtiger_profile2field.visible=0 AND vtiger_def_org_field.visible=0 AND vtiger_profile2field.profileid IN ".$profileList." AND vtiger_field.fieldname IN ".$field_list." GROUP BY vtiger_field.fieldid";
  87           if( $adb->dbType == "pgsql")
  88               $query = fixPostgresQuery( $query, $log, 0);
  89          $result = $adb->query($query);
  90          $field=Array();
  91          for($k=0;$k < $adb->num_rows($result);$k++)
  92          {
  93              $field[]=$adb->query_result($result,$k,"fieldname");
  94          }
  95      }
  96  
  97          //modified for vtiger_customview 27/5 - $app_strings change to $mod_strings
  98          foreach($focus->list_fields as $name=>$tableinfo)
  99          {
 100                  //$fieldname = $focus->list_fields_name[$name];  //commented for vtiger_customview 27/5
 101                  //added for vtiger_customview 27/5
 102                  if($oCv)
 103                  {
 104                          if(isset($oCv->list_fields_name))
 105                          {
 106                  if( $oCv->list_fields_name[$name] == '')
 107                      $fieldname = 'crmid';
 108                  else
 109                      $fieldname = $oCv->list_fields_name[$name];
 110                          }else
 111                          {
 112                  if( $focus->list_fields_name[$name] == '')
 113                      $fieldname = 'crmid';
 114                  else
 115                      $fieldname = $focus->list_fields_name[$name];
 116                      
 117                          }
 118                  }
 119          else
 120                  {
 121              if( $focus->list_fields_name[$name] == '')
 122                  $fieldname = 'crmid';
 123              else
 124                  $fieldname = $focus->list_fields_name[$name];
 125                  }
 126  
 127                  if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] ==0 || in_array($fieldname,$field))
 128          {
 129                          if(isset($focus->sortby_fields) && $focus->sortby_fields !='')
 130                          {
 131                                  //Added on 14-12-2005 to avoid if and else check for every list vtiger_field for arrow image and change order
 132  
 133                                  foreach($focus->list_fields[$name] as $tab=>$col)
 134                                  {
 135                                          if(in_array($col,$focus->sortby_fields))
 136                                          {
 137                                                  if($relatedlist !='')
 138                                                  {
 139                                                          if($app_strings[$name])
 140                                                          {
 141                                                                  $name = $app_strings[$name];
 142                                                          }
 143                                                          else
 144                                                          {
 145                                                                  $name = $mod_strings[$name];
 146                                                          }
 147                                                  }
 148                                                  else
 149                                                  {
 150                                                          if($app_strings[$name])
 151                                                          {
 152                                                                  $lbl_name = $app_strings[$name];
 153                                                          }
 154                                                          else
 155                                                          {
 156                                   $lbl_name = $mod_strings[$name];
 157                                                          }
 158                                                          $name = $lbl_name;
 159                                                  }
 160                                          }
 161                                          else
 162                                          {       if($app_strings[$name])
 163                                                  {
 164                                                          $name = $app_strings[$name];
 165                                                  }
 166                                                  elseif($mod_strings[$name])
 167                                                  {
 168                                                          $name = $mod_strings[$name];
 169                                                  }
 170                                          }
 171                                  }
 172                          }
 173                          //Added condition to hide the close column in Related Lists
 174                          //if($name == 'Close' && $relatedlist != '')
 175                          if($name == 'Close')
 176                          {
 177                                  //$list_header .= '';
 178                                  // $list_header[] = '';
 179              }
 180                          else
 181                          {
 182                  if($fieldname!='parent_id')
 183                  {
 184                      $fld_name=$fieldname;
 185                                      $search_header[$fld_name]=$name;
 186                  }
 187                          }
 188                  }
 189          }
 190      $log->debug("Exiting getSearchListHeaderValues method ...");    
 191          return $search_header;
 192  
 193  }
 194  
 195  /**This function is used to get the where condition for search listview query along with url_string
 196  *Param $module - module name
 197  *Returns the where conditions and url_string values in string format
 198  */
 199  
 200  function Search($module)
 201  {
 202      global $log;
 203          $log->debug("Entering Search(".$module.") method ...");
 204      $url_string='';    
 205      if(isset($_REQUEST['search_field']) && $_REQUEST['search_field'] !="")
 206          {
 207                  $search_column=$_REQUEST['search_field'];
 208          }
 209          if(isset($_REQUEST['search_text']) && $_REQUEST['search_text']!="")
 210          {
 211                  $search_string=addslashes(ltrim(rtrim($_REQUEST['search_text'])));
 212          }
 213          if(isset($_REQUEST['searchtype']) && $_REQUEST['searchtype']!="")
 214          {
 215  
 216  
 217                  $search_type=$_REQUEST['searchtype'];
 218  
 219                  if($search_type == "BasicSearch")
 220                  {
 221                          $where=BasicSearch($module,$search_column,$search_string);
 222                  }
 223                  else if ($search_type == "AdvanceSearch")
 224                  {
 225                  }
 226                  else //Global Search
 227                  {
 228                  }
 229          $url_string = "&search_field=".$search_column."&search_text=".$search_string."&searchtype=BasicSearch";
 230          if(isset($_REQUEST['type']) && $_REQUEST['type'] != '')
 231              $url_string .= "&type=".$_REQUEST['type'];
 232          return $where."#@@#".$url_string;
 233          $log->debug("Exiting Search method ...");
 234          }
 235  
 236  }
 237  
 238  /**This function is used to get user_id's for a given user_name during search
 239  *Param $table_name - vtiger_tablename
 240  *Param $column_name - columnname
 241  *Param $search_string - searchstring value (username)
 242  *Returns the where conditions for list query in string format
 243  */
 244  
 245  function get_usersid($table_name,$column_name,$search_string)
 246  {
 247  
 248      global $log;
 249          $log->debug("Entering get_usersid(".$table_name.",".$column_name.",".$search_string.") method ...");
 250      global $adb;
 251      $user_qry="select distinct(vtiger_users.id)from vtiger_users inner join vtiger_crmentity on vtiger_crmentity.smownerid=vtiger_users.id where vtiger_users.user_name like '%".$search_string."%' ";
 252      $user_result=$adb->query($user_qry);
 253      $noofuser_rows=$adb->num_rows($user_result);
 254      $x=$noofuser_rows-1;
 255      if($noofuser_rows!=0)
 256      {
 257          $where="(";
 258          for($i=0;$i<$noofuser_rows;$i++)
 259          {
 260              $user_id=$adb->query_result($user_result,$i,'id');
 261              $where .= "$table_name.$column_name =".$user_id;
 262              if($i != $x)
 263              {
 264                  $where .= " or ";
 265              }
 266          }
 267          $where.=" or vtiger_groups.groupname like '%".$search_string."%')";
 268      }
 269      else
 270      {
 271          //$where="$table_name.$column_name =''";
 272          $where="vtiger_groups.groupname like '%".$search_string."%' ";
 273      }    
 274      $log->debug("Exiting get_usersid method ...");
 275      return $where;    
 276  }
 277  
 278  /**This function is used to get where conditions for a given vtiger_accountid or contactid during search for their respective names
 279  *Param $column_name - columnname
 280  *Param $search_string - searchstring value (username)
 281  *Returns the where conditions for list query in string format
 282  */
 283  
 284  
 285  function getValuesforColumns($column_name,$search_string)
 286  {
 287      global $log;
 288      $log->debug("Entering getValuesforColumns(".$column_name.",".$search_string.") method ...");
 289      global $column_array,$table_col_array;
 290      for($i=0; $i<count($column_array);$i++)
 291      {
 292          if($column_name == $column_array[$i])
 293          {
 294              $val=$table_col_array[$i];
 295              $explode_column=explode(",",$val);
 296              $x=count($explode_column);    
 297              if($x == 1 )
 298              {
 299                  $where=" $val like '%".$search_string ."%'";
 300              }
 301              else 
 302              {
 303                  $where="(";
 304                  for($j=0;$j<count($explode_column);$j++)
 305                  {
 306                      $where .= $explode_column[$j]." like '%".$search_string."%'";
 307                      if($j != $x-1)
 308                      {
 309                          $where .= " or ";
 310                      }
 311                  }
 312                  $where.=")";
 313              }
 314              break 1;
 315          }
 316      }
 317      $log->debug("Exiting getValuesforColumns method ...");
 318      return $where;
 319  }
 320  
 321  /**This function is used to get where conditions in Basic Search
 322  *Param $module - module name
 323  *Param $search_field - columnname/field name in which the string has be searched
 324  *Param $search_string - searchstring value (username)
 325  *Returns the where conditions for list query in string format
 326  */
 327  
 328  function BasicSearch($module,$search_field,$search_string)
 329  {
 330       global $log;
 331           $log->debug("Entering BasicSearch(".$module.",".$search_field.",".$search_string.") method ...");
 332      global $adb;
 333      global $column_array,$table_col_array;
 334  
 335      if($search_field =='crmid')
 336      {
 337          $column_name='crmid';
 338          $table_name='vtiger_crmentity';
 339          $where="$table_name.$column_name like '%".$search_string."%'";    
 340      }else
 341      {    
 342          //Check added for tickets by accounts/contacts in dashboard
 343          $search_field_first = $search_field;
 344          if($module=='HelpDesk' && ($search_field == 'contactid' || $search_field == 'account_id'))
 345          {
 346              $search_field = "parent_id";
 347          }
 348          //Check ends
 349          
 350          $qry="select vtiger_field.columnname,tablename from vtiger_tab inner join vtiger_field on vtiger_field.tabid=vtiger_tab.tabid where name='".$module."' and (fieldname='".$search_field."' or columnname='".$search_field."')";
 351          $result = $adb->query($qry);
 352          $noofrows = $adb->num_rows($result);
 353          if($noofrows!=0)
 354          {
 355              $column_name=$adb->query_result($result,0,'columnname');
 356  
 357              //Check added for tickets by accounts/contacts in dashboard
 358              if ($column_name == 'parent_id')
 359                  {
 360                  if ($search_field_first    == 'account_id') $search_field_first = 'accountid';
 361                  if ($search_field_first    == 'contactid') $search_field_first = 'contact_id';
 362                  $column_name = $search_field_first;
 363              }
 364              //Check ends
 365              $table_name=$adb->query_result($result,0,'tablename');
 366              if($table_name == "vtiger_crmentity" && $column_name == "smownerid")
 367              {
 368                  $where = get_usersid($table_name,$column_name,$search_string);
 369              }
 370              elseif($table_name == "vtiger_activity" && $column_name == "status")
 371              {
 372                  $where="$table_name.$column_name like '%".$search_string."%' or vtiger_activity.eventstatus like '%".$search_string."%'";
 373              }
 374              elseif($table_name == "vtiger_pricebook" && $column_name == "active")
 375              {
 376                  if(stristr($search_string,'yes'))
 377                      $where="$table_name.$column_name = 1";
 378                  if(stristr($search_string,'no'))
 379                      $where="$table_name.$column_name is NULL";
 380              }
 381              elseif($table_name == "vtiger_activity" && $column_name == "status")
 382              {
 383                  $where="$table_name.$column_name like '%".$search_string."%' or vtiger_activity.eventstatus like '%".$search_string."%'";
 384              }
 385  
 386              else if(in_array($column_name,$column_array))
 387              {
 388                  $where = getValuesforColumns($column_name,$search_string);
 389              }
 390              else
 391              {
 392                  $where="$table_name.$column_name like '%".$search_string."%'";
 393              }
 394          }
 395      }
 396      if($_REQUEST['type'] == 'entchar')
 397      {
 398          $search = array('Un Assigned','%','like');
 399          $replace = array('','','=');
 400          $where= str_replace($search,$replace,$where);
 401      }
 402      if($_REQUEST['type'] == 'alpbt')
 403      {
 404              $where = str_replace_once("%", "", $where);
 405      }
 406      $log->debug("Exiting BasicSearch method ...");
 407      return $where;
 408  }
 409  
 410  /**This function is used to get where conditions in Advance Search
 411  *Param $module - module name
 412  *Returns the where conditions for list query in string format
 413  */
 414  
 415  function getAdvSearchfields($module)
 416  {
 417      global $log;
 418          $log->debug("Entering getAdvSearchfields(".$module.") method ...");
 419      global $adb;
 420      global $current_user;    
 421      global $mod_strings;
 422      require('user_privileges/user_privileges_'.$current_user->id.'.php');
 423  
 424      $tabid = getTabid($module);
 425  
 426      if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0)
 427      {
 428          $sql = "select * from vtiger_field ";
 429          $sql.= " where vtiger_field.tabid=".$tabid." and";
 430          $sql.= " vtiger_field.displaytype in (1,2)";
 431          $sql.= " order by block,sequence";
 432      }
 433      else
 434      {
 435          $profileList = getCurrentUserProfileList();
 436          $sql = "select * from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid ";
 437          $sql.= " where vtiger_field.tabid=".$tabid." and";
 438          $sql.= " vtiger_field.displaytype in (1,2) and vtiger_profile2field.visible=0";
 439          $sql.= " and vtiger_def_org_field.visible=0  and vtiger_profile2field.profileid in ".$profileList." order by block,sequence";
 440      }
 441  
 442  
 443      $result = $adb->query($sql);
 444      $noofrows = $adb->num_rows($result);
 445      $block = '';
 446  
 447      for($i=0; $i<$noofrows; $i++)
 448      {
 449          $fieldtablename = $adb->query_result($result,$i,"tablename");
 450          $fieldcolname = $adb->query_result($result,$i,"columnname");
 451          $block = $adb->query_result($result,$i,"block");
 452          $fieldtype = explode("~",$fieldtype);
 453          $fieldtypeofdata = $fieldtype[0];
 454          $fieldlabel = $adb->query_result($result,$i,"fieldlabel");
 455          if($fieldlabel == "Related To")
 456          {
 457              $fieldlabel = "Related to";
 458          }
 459          if($fieldlabel == "Start Date & Time")
 460          {
 461              $fieldlabel = "Start Date";
 462              if($module == 'Activities' && $block == 19)
 463                  $module_columnlist['vtiger_activity:time_start::Activities_Start Time:I'] = 'Start Time';
 464  
 465          }
 466          $fieldlabel1 = str_replace(" ","_",$fieldlabel);
 467          if($fieldlabel != 'Related to')
 468          {
 469              if ($i==0)
 470                  $OPTION_SET .= "<option value=\'".$fieldtablename.".".$fieldcolname."\' selected>".$fieldlabel."</option>";
 471              elseif($fieldlabel == "Product Code")
 472                  $OPTION_SET .= "<option value=\'".$fieldtablename.".".$fieldcolname."\'>".$mod_strings[$fieldlabel]."</option>";
 473              else
 474                  $OPTION_SET .= "<option value=\'".$fieldtablename.".".$fieldcolname."\'>".$fieldlabel."</option>";
 475          }
 476      }
 477      //Added to include Ticket ID in HelpDesk advance search
 478      if($module == 'HelpDesk')
 479      {
 480          $OPTION_SET .= "<option value=\'vtiger_crmentity.crmid\'>".$mod_strings['Ticket ID']."</option>";
 481      }
 482      //Added to include activity type in activity advance search
 483      if($module == 'Activities')
 484      {
 485          $OPTION_SET .= "<option value=\'vtiger_activity.activitytype\'>".$mod_strings['Activity Type']."</option>";
 486      }
 487      $log->debug("Exiting getAdvSearchfields method ...");
 488      return $OPTION_SET;
 489  }
 490  
 491  /**This function is returns the search criteria options for Advance Search
 492  *takes no parameter
 493  *Returns the criteria option in html format
 494  */
 495  
 496  function getcriteria_options()
 497  {
 498      global $log;
 499      $log->debug("Entering getcriteria_options() method ...");
 500      $CRIT_OPT = "<option value=\'cts\'>contains</option><option value=\'dcts\'>does not contains</option><option value=\'is\'>is</option><option value=\'isn\'>is not</option><option value=\'bwt\'>begins with</option><option value=\'ewt\'>ends with</option><option value=\'grt\'>greater than</option><option value=\'lst\'>less than</option><option value=\'grteq\'>greater or equal</option><option value=\'lsteq\'>lesser or equal</option>";
 501      $log->debug("Exiting getcriteria_options method ...");
 502      return $CRIT_OPT;
 503  }
 504  
 505  /**This function is returns the where conditions for each search criteria option in Advance Search
 506  *Param $criteria - search criteria option
 507  *Param $searchstring - search string
 508  *Param $searchfield - vtiger_fieldname to be search for 
 509  *Returns the search criteria option (where condition) to be added in list query
 510  */
 511  
 512  function getSearch_criteria($criteria,$searchstring,$searchfield)
 513  {
 514      global $log;
 515      $log->debug("Entering getSearch_criteria(".$criteria.",".$searchstring.",".$searchfield.") method ...");
 516      $where_string = '';
 517      switch($criteria)
 518      {
 519          case 'cts':
 520              $where_string = $searchfield." like '%".$searchstring."%' ";
 521              if($searchstring == NULL)
 522              $where_string = $searchfield." is NULL";
 523              break;
 524          
 525          case 'dcts':
 526              $where_string = $searchfield." not like '%".$searchstring."%' ";
 527              if($searchstring == NULL)
 528              $where_string = $searchfield." is not NULL";
 529              break;
 530              
 531          case 'is':
 532              $where_string = $searchfield." = '".$searchstring."' ";
 533              if($searchstring == NULL)
 534              $where_string = $searchfield." is NULL";
 535              break;
 536              
 537          case 'isn':
 538              $where_string = $searchfield." <> '".$searchstring."' ";
 539              if($searchstring == NULL)
 540              $where_string = $searchfield." is not NULL";
 541              break;
 542              
 543          case 'bwt':
 544              $where_string = $searchfield." like '".$searchstring."%' ";
 545              if($searchstring == NULL)
 546              $where_string = $searchfield." is NULL";
 547              break;
 548  
 549          case 'ewt':
 550              $where_string = $searchfield." like '%".$searchstring."' ";
 551              if($searchstring == NULL)
 552              $where_string = $searchfield." is NULL";
 553              break;
 554  
 555          case 'grt':
 556              $where_string = $searchfield." > '".$searchstring."' ";
 557              break;
 558  
 559          case 'lst':
 560              $where_string = $searchfield." < '".$searchstring."' ";
 561              break;
 562  
 563          case 'grteq':
 564              $where_string = $searchfield." >= '".$searchstring."' ";
 565              break;
 566  
 567          case 'lsteq':
 568              $where_string = $searchfield." <= '".$searchstring."' ";
 569              break;
 570  
 571  
 572      }
 573      $log->debug("Exiting getSearch_criteria method ...");
 574      return $where_string;
 575  }
 576  
 577  /**This function is returns the where conditions for search
 578  *Param $currentModule - module name
 579  *Returns the where condition to be added in list query in string format
 580  */
 581  
 582  function getWhereCondition($currentModule)
 583  {
 584      global $log;
 585      global $column_array,$table_col_array;
 586  
 587          $log->debug("Entering getWhereCondition(".$currentModule.") method ...");
 588      
 589      if($_REQUEST['searchtype']=='advance')
 590      {
 591          $adv_string='';
 592          $url_string='';
 593          if(isset($_REQUEST['search_cnt']))
 594          $tot_no_criteria = $_REQUEST['search_cnt'];
 595          if($_REQUEST['matchtype'] == 'all')
 596              $matchtype = "and";
 597          else
 598              $matchtype = "or";
 599          for($i=0; $i<$tot_no_criteria; $i++)
 600          {
 601              if($i == $tot_no_criteria-1)
 602              $matchtype= "";
 603              
 604              $table_colname = 'Fields'.$i;
 605              $search_condition = 'Condition'.$i;
 606              $search_value = 'Srch_value'.$i;
 607  
 608              $tab_col = str_replace('\'','',stripslashes($_REQUEST[$table_colname]));
 609              $srch_cond = str_replace('\'','',stripslashes($_REQUEST[$search_condition]));
 610              $srch_val = $_REQUEST[$search_value];
 611              list($tab_name,$column_name) = split("[.]",$tab_col);
 612              $url_string .="&Fields".$i."=".$tab_col."&Condition".$i."=".$srch_cond."&Srch_value".$i."=".$srch_val;
 613              if($tab_col == "vtiger_crmentity.smownerid")
 614              {
 615                  $adv_string .= " (".getSearch_criteria($srch_cond,$srch_val,'vtiger_users.user_name')." or";    
 616                  $adv_string .= " ".getSearch_criteria($srch_cond,$srch_val,'vtiger_groups.groupname')." )".$matchtype;    
 617              }
 618              elseif($tab_col == "vtiger_activity.status")
 619              {
 620                  $adv_string .= " (".getSearch_criteria($srch_cond,$srch_val,'vtiger_activity.status')." or";    
 621                  $adv_string .= " ".getSearch_criteria($srch_cond,$srch_val,'vtiger_activity.eventstatus')." )".$matchtype;    
 622              }
 623              elseif($tab_col == "vtiger_cntactivityrel.contactid")
 624              {
 625                  $adv_string .= " (".getSearch_criteria($srch_cond,$srch_val,'vtiger_contactdetails.firstname')." or";    
 626                  $adv_string .= " ".getSearch_criteria($srch_cond,$srch_val,'vtiger_contactdetails.lastname')." )".$matchtype;    
 627              }
 628              elseif($tab_col == "vtiger_pricebook.active")
 629              {
 630                  if(stristr($srch_val,'yes'))
 631                      $adv_string .= " ".getSearch_criteria($srch_cond,"1",'vtiger_pricebook.active')." ".$matchtype;    
 632                  if(stristr($srch_val,'no'))
 633                      $adv_string .= " ".getSearch_criteria($srch_cond,NULL,'vtiger_pricebook.active')." ".$matchtype;    
 634              }
 635  
 636              elseif(in_array($column_name,$column_array))
 637                          {
 638                                  $adv_string .= getValuesforColumns($column_name,$srch_val)." ".$matchtype;
 639                          }
 640              else
 641              {
 642                  $adv_string .= " ".getSearch_criteria($srch_cond,$srch_val,$tab_col)." ".$matchtype;    
 643              }
 644          }
 645          $where="(".$adv_string.")#@@#".$url_string."&searchtype=advance&search_cnt=".$tot_no_criteria."&matchtype=".$_REQUEST['matchtype'];
 646      }
 647      elseif($_REQUEST['type']=='dbrd')
 648      {
 649          $where = getdashboardcondition();
 650      }
 651      else
 652      {
 653           $where=Search($currentModule);
 654      }
 655      $log->debug("Exiting getWhereCondition method ...");
 656      return $where;
 657  
 658  }
 659  
 660  /**This function is returns the where conditions for dashboard and shows the records when clicked on dashboard graph
 661  *Takes no parameter, process the values got from the html request object
 662  *Returns the search criteria option (where condition) to be added in list query
 663  */
 664  
 665  function getdashboardcondition()
 666  {
 667      global $adb;
 668      $where_clauses = Array();
 669      $url_string = "";
 670  
 671      if (isset($_REQUEST['leadsource'])) $lead_source = $_REQUEST['leadsource'];
 672      if (isset($_REQUEST['date_closed'])) $date_closed = $_REQUEST['date_closed'];
 673      if (isset($_REQUEST['sales_stage'])) $sales_stage = $_REQUEST['sales_stage'];
 674      if (isset($_REQUEST['closingdate_start'])) $date_closed_start = $_REQUEST['closingdate_start'];
 675      if (isset($_REQUEST['closingdate_end'])) $date_closed_end = $_REQUEST['closingdate_end'];
 676      if (isset($_REQUEST['assigned_user_id'])) $assigned_user_id = $_REQUEST['assigned_user_id'];
 677      
 678  
 679      if(isset($date_closed_start) && $date_closed_start != "" && isset($date_closed_end) && $date_closed_end != "")
 680      {
 681          array_push($where_clauses, "vtiger_potential.closingdate >= ".$adb->quote($date_closed_start)." and vtiger_potential.closingdate <= ".$adb->quote($date_closed_end));
 682          $url_string .= "&closingdate_start=".$date_closed_start."&closingdate_end=".$date_closed_end;
 683      }
 684      
 685      if(isset($sales_stage) && $sales_stage!=''){
 686          if($sales_stage=='Other')
 687          array_push($where_clauses, "(vtiger_potential.sales_stage <> 'Closed Won' and vtiger_potential.sales_stage <> 'Closed Lost')");
 688          else
 689          array_push($where_clauses, "vtiger_potential.sales_stage = ".$adb->quote($sales_stage));
 690          $url_string .= "&sales_stage=".$sales_stage;
 691      }
 692      if(isset($lead_source) && $lead_source != "") {
 693          array_push($where_clauses, "vtiger_potential.leadsource = ".$adb->quote($lead_source));
 694          $url_string .= "&leadsource=".$lead_source;
 695      }
 696      if(isset($assigned_user_id) && $assigned_user_id != "") {
 697              array_push($where_clauses, "vtiger_crmentity.smownerid = ".$assigned_user_id);
 698              $url_string .= "&assigned_user_id=".$assigned_user_id;
 699          }
 700      if(isset($date_closed) && $date_closed != "") {
 701          array_push($where_clauses, $adb->getDBDateString("vtiger_potential.closingdate")." like ".$adb->quote($date_closed.'%')."");
 702          $url_string .= "&date_closed=".$date_closed;
 703      }
 704      $where = "";
 705      foreach($where_clauses as $clause)
 706      {
 707          if($where != "")
 708          $where .= " and ";
 709          $where .= $clause;
 710      }
 711      return $where."#@@#".$url_string;
 712  }
 713  
 714  /**This function is used to replace only the first occurence of a given string
 715  Param $needle - string to be replaced
 716  Param $replace - string to be replaced with
 717  Param $replace - given string
 718  Return type is string
 719  */
 720  function str_replace_once($needle, $replace, $haystack)
 721  {
 722      // Looks for the first occurence of $needle in $haystack
 723      // and replaces it with $replace.
 724      $pos = strpos($haystack, $needle);
 725      if ($pos === false) {
 726          // Nothing found
 727          return $haystack;
 728      }
 729      return substr_replace($haystack, $replace, $pos, strlen($needle));
 730  }
 731  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7