[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/modules/Accounts/ -> Save.php (source)

   1  <?php
   2  /*********************************************************************************
   3   * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
   4   * ("License"); You may not use this file except in compliance with the 
   5   * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
   6   * Software distributed under the License is distributed on an  "AS IS"  basis,
   7   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
   8   * the specific language governing rights and limitations under the License.
   9   * The Original Code is:  SugarCRM Open Source
  10   * The Initial Developer of the Original Code is SugarCRM, Inc.
  11   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12   * All Rights Reserved.
  13   * Contributor(s): ______________________________________.
  14   ********************************************************************************/
  15  /*********************************************************************************
  16   * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/modules/Accounts/Save.php,v 1.7 2005/03/15 09:55:31 shaw Exp $
  17   * Description:  Saves an Account record and then redirects the browser to the 
  18   * defined return URL.
  19   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  20   * All Rights Reserved.
  21   * Contributor(s): ______________________________________..
  22   ********************************************************************************/
  23  
  24  require_once ('modules/Accounts/Accounts.php');
  25  require_once ('include/logging.php');
  26  //require_once('database/DatabaseConnection.php');
  27  require_once ('include/database/PearDatabase.php');
  28  
  29  $local_log =& LoggerManager::getLogger('index');
  30  global $log;
  31  $focus = new Accounts();
  32  global $current_user;
  33  $currencyid=fetchCurrency($current_user->id);
  34  $rate_symbol = getCurrencySymbolandCRate($currencyid);
  35  $rate = $rate_symbol['rate'];
  36  $curr_symbol = $rate_symbol['symbol'];
  37  if(isset($_REQUEST['record']))
  38  {
  39      $focus->id = $_REQUEST['record'];
  40  $log->info("id is ".$focus->id);
  41  }
  42  if(isset($_REQUEST['mode']))
  43  {
  44      $focus->mode = $_REQUEST['mode'];
  45  }
  46  
  47  //$focus->retrieve($_REQUEST['record']);
  48  
  49  foreach($focus->column_fields as $fieldname => $val)
  50  {
  51      if(isset($_REQUEST[$fieldname]))
  52      {
  53          $value = $_REQUEST[$fieldname];
  54          //echo '<BR>';
  55          //echo $fieldname."         ".$value;
  56          //echo '<BR>';
  57          $focus->column_fields[$fieldname] = $value;
  58      }
  59      if(isset($_REQUEST['annual_revenue']))
  60          {
  61                          $value = convertToDollar($_REQUEST['annual_revenue'],$rate);
  62                          $focus->column_fields['annual_revenue'] = $value;
  63          }
  64          
  65  }
  66  //echo '<BR>';
  67  //print_r($focus->column_fields);
  68  //echo '<BR>';
  69  
  70  /* foreach($focus->additional_column_fields as $field)
  71  {
  72      if(isset($_REQUEST[$field]))
  73      {
  74          $value = $_REQUEST[$field];
  75          $focus->$field = $value;
  76          
  77      }
  78  }*/
  79  
  80  //$focus->saveentity("Accounts");
  81  $focus->save("Accounts");
  82  //echo '<BR>';
  83  //echo $focus->id;
  84  $return_id = $focus->id;
  85  //save_customfields($focus->id);
  86  
  87  if(isset($_REQUEST['parenttab']) && $_REQUEST['parenttab'] != "") $parenttab = $_REQUEST['parenttab'];
  88  if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "") $return_module = $_REQUEST['return_module'];
  89  else $return_module = "Accounts";
  90  if(isset($_REQUEST['return_action']) && $_REQUEST['return_action'] != "") $return_action = $_REQUEST['return_action'];
  91  else $return_action = "DetailView";
  92  if(isset($_REQUEST['return_id']) && $_REQUEST['return_id'] != "") $return_id = $_REQUEST['return_id'];
  93  
  94  $local_log->debug("Saved record with id of ".$return_id);
  95  
  96  
  97  //code added for returning back to the current view after edit from list view
  98  if($_REQUEST['return_viewname'] == '') $return_viewname='0';
  99  if($_REQUEST['return_viewname'] != '')$return_viewname=$_REQUEST['return_viewname'];
 100  
 101  //Send notification mail to the assigned to owner about the vtiger_account creation
 102  if($focus->column_fields['notify_owner'] == 1 || $focus->column_fields['notify_owner'] == 'on')
 103      $status = sendNotificationToOwner('Accounts',&$focus);
 104  
 105  header("Location: index.php?action=$return_action&module=$return_module&parenttab=$parenttab&record=$return_id&viewname=$return_viewname");
 106  
 107  /** Function to save Accounts custom field info into database
 108  * @param integer $entity_id - accountid
 109  */
 110  function save_customfields($entity_id)
 111  {
 112      global $log;
 113      $log->debug("Entering save_customfields(".$entity_id.") method ...");
 114      $log->info("save customfields invoked");
 115      global $adb;
 116      $dbquery = "SELECT * FROM customfields WHERE module = 'Accounts'";
 117          /*
 118      $result = mysql_query($dbquery);
 119      $custquery = "SELECT * FROM vtiger_accountcf WHERE vtiger_accountid = '".$entity_id."'";
 120          $cust_result = mysql_query($custquery);
 121      if(mysql_num_rows($result) != 0)
 122          */
 123      $result = $adb->query($dbquery);
 124      $custquery = "SELECT * FROM vtiger_accountcf WHERE vtiger_accountid = '".$entity_id."'";
 125          $cust_result = $adb->query($custquery);
 126      if($adb->num_rows($result) != 0)
 127      {
 128          
 129          $columns='';
 130          $values='';
 131          $update='';
 132                  //    $noofrows = mysql_num_rows($result);
 133                  $noofrows = $adb->num_rows($result);
 134          for($i=0; $i<$noofrows; $i++)
 135          {
 136                    //$fldName=mysql_result($result,$i,"fieldlabel");
 137                    //$colName=mysql_result($result,$i,"column_name");
 138      $fldName=$adb->query_result($result,$i,"fieldlabel");
 139              $colName=$adb->query_result($result,$i,"column_name");
 140              if(isset($_REQUEST[$colName]))
 141              {
 142                  $fldvalue=$_REQUEST[$colName];
 143                  if(get_magic_quotes_gpc() == 1)
 144                          {
 145                                  $fldvalue = stripslashes($fldvalue);
 146                          }
 147              }
 148              else
 149              {
 150                  $fldvalue = '';
 151              }
 152              //if(isset($_REQUEST['record']) && $_REQUEST['record'] != '' && mysql_num_rows($cust_result) !=0)
 153                            if(isset($_REQUEST['record']) && $_REQUEST['record'] != '' && $adb->num_rows($cust_result) !=0)
 154              {
 155                  //Update Block
 156                  if($i == 0)
 157                  {
 158                                    //$update = $colName.'="'.$fldvalue.'"';
 159                                          $update = $colName."='".$fldvalue."'";
 160                  }
 161                  else
 162                  {
 163                                    //$update .= ', '.$colName.'="'.$fldvalue.'"';
 164                                          $update .= ', '.$colName."='".$fldvalue."'";
 165                  }
 166              }
 167              else
 168              {
 169                  //Insert Block
 170                  if($i == 0)
 171                  {
 172                      $columns='accountid, '.$colName;
 173                      //$values='"'.$entity_id.'", "'.$fldvalue.'"';
 174                                          $values="'".$entity_id."', '".$fldvalue."'";
 175                  }
 176                  else
 177                  {
 178                      $columns .= ', '.$colName;
 179                      //$values .= ', "'.$fldvalue.'"';
 180                                          $values .= ", '".$fldvalue."'";
 181                  }
 182              }
 183              
 184                  
 185          }
 186          //if(isset($_REQUEST['record']) && $_REQUEST['record'] != '' && mysql_num_rows($cust_result) !=0)
 187                    if(isset($_REQUEST['record']) && $_REQUEST['record'] != '' && $adb->num_rows($cust_result) !=0)
 188          {
 189              //Update Block
 190                          $query = "UPDATE vtiger_accountcf SET ".$update." WHERE vtiger_accountid='".$entity_id."'"; 
 191              $adb->query($query);
 192          }
 193          else
 194          {
 195              //Insert Block
 196              $query = "INSERT INTO vtiger_accountcf (".$columns.") VALUES(".$values.")";
 197                          $adb->query($query);
 198          }
 199          
 200      }
 201      $log->debug("Exiting save_customfields method ...");
 202      // commented by srini - PATCH for saving vtiger_accounts
 203      /*else
 204      {
 205            //if(isset($_REQUEST['record']) && $_REQUEST['record'] != '' && mysql_num_rows($cust_result) !=0)
 206                    if(isset($_REQUEST['record']) && $_REQUEST['record'] != '' && $adb->num_rows($cust_result) !=0)
 207          {
 208              //Update Block
 209          }
 210          else
 211          {
 212              //Insert Block
 213              $query = "INSERT INTO vtiger_accountcf (".$columns.") VALUES(".$values.")";
 214                          $adb->query($query);
 215              //mysql_query($query);
 216          }
 217      }*/    
 218  }
 219  ?>


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