iTx Technologies offre gratuitement
cet espace pour SugarCRM !

title

Body

[fermer]

/include/ -> formbase.php (source)

   1  <?php
   2  if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
   3  /*********************************************************************************
   4   * SugarCRM is a customer relationship management program developed by
   5   * SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
   6   * 
   7   * This program is free software; you can redistribute it and/or modify it under
   8   * the terms of the GNU General Public License version 3 as published by the
   9   * Free Software Foundation with the addition of the following permission added
  10   * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  11   * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  12   * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  13   * 
  14   * This program is distributed in the hope that it will be useful, but WITHOUT
  15   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  17   * details.
  18   * 
  19   * You should have received a copy of the GNU General Public License along with
  20   * this program; if not, see http://www.gnu.org/licenses or write to the Free
  21   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22   * 02110-1301 USA.
  23   * 
  24   * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  25   * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  26   * 
  27   * The interactive user interfaces in modified source and object code versions
  28   * of this program must display Appropriate Legal Notices, as required under
  29   * Section 5 of the GNU General Public License version 3.
  30   * 
  31   * In accordance with Section 7(b) of the GNU General Public License version 3,
  32   * these Appropriate Legal Notices must retain the display of the "Powered by
  33   * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  34   * technical reasons, the Appropriate Legal Notices must display the words
  35   * "Powered by SugarCRM".
  36   ********************************************************************************/
  37  /*********************************************************************************
  38  
  39   * Description:  is a form helper
  40   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  41   * All Rights Reserved.
  42   * Contributor(s): ______________________________________..
  43   ********************************************************************************/
  44  
  45  /**
  46   * Check for null or zero for list of values
  47   * @param $prefix the prefix of value to be checked
  48   * @param $required array of value to be checked
  49   * @return boolean true if all values are set in the array
  50   */
  51  function checkRequired($prefix, $required)
  52  {
  53      foreach($required as $key)
  54      {
  55          if(!isset($_POST[$prefix.$key]) || number_empty($_POST[$prefix.$key]))
  56          {
  57              return false;
  58          }
  59      }
  60      return true;
  61  }
  62  
  63  function populateFromPost($prefix, &$focus, $skipRetrieve=false) {
  64      global $current_user;
  65  
  66      if(!empty($_REQUEST[$prefix.'record']) && !$skipRetrieve)
  67          $focus->retrieve($_REQUEST[$prefix.'record']);
  68  
  69      if(!empty($_POST['assigned_user_id']) && 
  70          ($focus->assigned_user_id != $_POST['assigned_user_id']) && 
  71          ($_POST['assigned_user_id'] != $current_user->id)) {
  72          $GLOBALS['check_notify'] = true;
  73      }
  74      require_once ('include/SugarFields/SugarFieldHandler.php');
  75      $sfh = new SugarFieldHandler();
  76     
  77      foreach($focus->field_defs as $field=>$def) {
  78          $type = !empty($def['custom_type']) ? $def['custom_type'] : $def['type'];
  79          $sf = $sfh->getSugarField(ucfirst($type), true);
  80          if($sf != null){
  81              $sf->save($focus, $_POST, $field, $def);
  82          }
  83          if(isset($_POST[$prefix.$field])) {
  84              if(is_array($_POST[$prefix.$field]) && !empty($focus->field_defs[$field]['isMultiSelect'])) {
  85                  if(empty($_POST[$prefix.$field][0])) {
  86                      unset($_POST[$prefix.$field][0]);
  87                  }
  88                  $_POST[$prefix.$field] = encodeMultienumValue($_POST[$prefix.$field]);    
  89              }
  90  
  91              $focus->$field = $_POST[$prefix.$field];
  92              /* 
  93               * overrides the passed value for booleans.
  94               * this will be fully deprecated when the change to binary booleans is complete.
  95               */
  96              if(isset($focus->field_defs[$prefix.$field]) && $focus->field_defs[$prefix.$field]['type'] == 'bool' && isset($focus->field_defs[$prefix.$field]['options'])) {
  97                  $opts = explode("|", $focus->field_defs[$prefix.$field]['options']);
  98                  $bool = $_POST[$prefix.$field];
  99  
 100                  if(is_int($bool) || ($bool === "0" || $bool === "1" || $bool === "2")) {
 101                      // 1=on, 2=off
 102                      $selection = ($_POST[$prefix.$field] == "0") ? 1 : 0;
 103                  } elseif(is_bool($_POST[$prefix.$field])) {
 104                      // true=on, false=off
 105                      $selection = ($_POST[$prefix.$field]) ? 0 : 1;
 106                  }
 107                  $focus->$field = $opts[$selection];
 108              }
 109          } else if(!empty($focus->field_defs[$field]['isMultiSelect']) && !isset($_POST[$prefix.$field]) && isset($_POST[$prefix.$field . '_multiselect'])) {
 110              $focus->$field = '';
 111          }
 112      }
 113  
 114      foreach($focus->additional_column_fields as $field) {
 115          if(isset($_POST[$prefix.$field])) {
 116              $value = $_POST[$prefix.$field];
 117              $focus->$field = $value;
 118          }
 119      }
 120  
 121      return $focus;
 122  }
 123  
 124  
 125  function getPostToForm($ignore='', $isRegularExpression=false)
 126  {
 127      $fields = '';
 128      if(!empty($ignore) && $isRegularExpression) {
 129          foreach ($_POST as $key=>$value){
 130              if(!preg_match($ignore, $key)) {
 131                  $fields.= "<input type='hidden' name='$key' value='$value'>\n";
 132              }
 133          }    
 134      } else {
 135          foreach ($_POST as $key=>$value){
 136              if($key != $ignore) {
 137                 $fields.= "<input type='hidden' name='$key' value='$value'>\n";
 138              }
 139          }
 140      }
 141      return $fields;
 142  }
 143  
 144  function getGetToForm($ignore='', $usePostAsAuthority = false)
 145  {
 146      $fields = '';
 147      foreach ($_GET as $key=>$value)
 148      {
 149          if($key != $ignore){
 150              if(!$usePostAsAuthority || !isset($_POST[$key])){
 151                  $fields.= "<input type='hidden' name='$key' value='$value'>";
 152              }
 153          }
 154      }
 155      return $fields;
 156  
 157  }
 158  function getAnyToForm($ignore='', $usePostAsAuthority = false)
 159  {
 160      $fields = getPostToForm($ignore);
 161      $fields .= getGetToForm($ignore, $usePostAsAuthority);
 162      return $fields;
 163  
 164  }
 165  
 166  function handleRedirect($return_id='', $return_module='')
 167  {
 168      if(isset($_REQUEST['return_url']) && $_REQUEST['return_url'] != "")
 169      {
 170          header("Location: ". $_REQUEST['return_url']);
 171          exit;
 172      }
 173  
 174      if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "")
 175      {
 176          $return_module = $_REQUEST['return_module'];
 177      }
 178      else
 179      {
 180          $return_module = $return_module;
 181      }
 182      if(isset($_REQUEST['return_action']) && $_REQUEST['return_action'] != "")
 183      {
 184          
 185         //if we are doing a "Close and Create New"
 186          if(isCloseAndCreateNewPressed())
 187          {
 188              $return_action = "EditView";    
 189              $isDuplicate = "true";        
 190              $status = "";
 191              
 192              // Meeting Integration
 193              if(isset($_REQUEST['meetingIntegrationFlag']) && $_REQUEST['meetingIntegrationFlag'] == 1) {
 194                  $additionalFlags = array('meetingIntegrationShowForm' => '1');
 195              }
 196              // END Meeting Integration
 197          } 
 198          // if we create a new record "Save", we want to redirect to the DetailView
 199          else if($_REQUEST['action'] == "Save" 
 200              && $_REQUEST['return_module'] != 'Activities'
 201  
 202  
 203  
 204              && $_REQUEST['return_module'] != 'Home' 
 205              && $_REQUEST['return_module'] != 'Forecasts' 
 206              && $_REQUEST['return_module'] != 'Calendar'
 207              && $_REQUEST['return_module'] != 'MailMerge'
 208  
 209  
 210  
 211              ) 
 212              {
 213                  $return_action = 'DetailView';
 214              } elseif($_REQUEST['return_module'] == 'Activities' || $_REQUEST['return_module'] == 'Calendar') {
 215              $return_module = $_REQUEST['module'];
 216              $return_action = $_REQUEST['return_action']; 
 217              // wp: return action needs to be set for one-click close in task list
 218          } 
 219          else 
 220          {
 221              // if we "Cancel", we go back to the list view.
 222              $return_action = $_REQUEST['return_action'];
 223          }
 224      }
 225      else
 226      {
 227          $return_action = "DetailView";
 228      }
 229      
 230      if(isset($_REQUEST['return_id']) && $_REQUEST['return_id'] != "")
 231      {
 232          $return_id = $_REQUEST['return_id'];
 233      }
 234      
 235      if (!isset($isDuplicate) || !$isDuplicate)
 236      {
 237          header("Location: index.php?action=$return_action&module=$return_module&record=$return_id&return_module=$return_module&return_action=$return_action");
 238      } else {
 239          $standard = "action=$return_action&module=$return_module&record=$return_id&isDuplicate=true&return_module=$return_module&return_action=$return_action&status=$status";
 240             $add = '';
 241  
 242          if(isset($additionalFlags) && !empty($additionalFlags)) {
 243              foreach($additionalFlags as $k => $v) {
 244                  if(!empty($add)) {
 245                      $add .= "&";
 246                  }
 247                  $add .= "{$k}={$v}";
 248              }
 249          }
 250          if(!empty($add)) {
 251              $add = "&" . $add;
 252          }
 253          header("Location: index.php?{$standard}{$add}");
 254      }
 255      exit;
 256  }
 257  
 258  function getLikeForEachWord($fieldname, $value, $minsize=4)
 259  {
 260      $value = trim($value);
 261      $values = split(' ',$value);
 262      $ret = '';
 263      foreach($values as $val)
 264      {
 265          if(strlen($val) >= $minsize)
 266          {
 267              if(!empty($ret))
 268              {
 269                  $ret .= ' or';
 270              }
 271              $ret .= ' '. $fieldname . ' LIKE %'.$val.'%';
 272          }
 273  
 274      }
 275  
 276  
 277  }
 278  
 279  function isCloseAndCreateNewPressed() {
 280      return isset($_REQUEST['action']) && 
 281             $_REQUEST['action'] == "Save" &&
 282             isset($_REQUEST['isSaveAndNew']) && 
 283             $_REQUEST['isSaveAndNew'] == 'true';    
 284  }
 285  
 286  
 287  
 288  
 289  
 290  
 291  
 292  
 293  
 294  
 295  
 296  
 297  
 298  
 299  
 300  
 301  
 302  
 303  
 304  
 305  
 306  
 307  
 308  
 309  
 310  
 311  
 312  
 313  
 314  
 315  
 316  
 317  
 318  
 319  
 320  
 321  
 322  
 323  
 324  
 325  
 326  
 327  
 328  
 329  
 330  
 331  
 332  
 333  
 334  
 335  
 336  
 337  
 338  
 339  
 340  
 341  
 342  
 343  
 344  
 345  
 346  
 347  
 348  
 349  
 350  
 351  
 352  
 353  
 354  
 355  
 356  
 357  
 358  
 359  
 360  
 361  
 362  ?>


Generé en: Thu Mar 4 09:44:50 2010 | Cross-referenced par PHPXref 0.7