[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/modules/Contacts/ -> 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/Contacts/Save.php,v 1.9 2005/03/15 09:58:21 shaw Exp $
  17   * Description:  TODO: To be written.
  18   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  19   * All Rights Reserved.
  20   * Contributor(s): ______________________________________..
  21   ********************************************************************************/
  22  
  23  require_once ('modules/Contacts/Contacts.php');
  24  require_once ('include/logging.php');
  25  require_once ('include/database/PearDatabase.php');
  26  require_once ("modules/Emails/mail.php");
  27  
  28  
  29  /**
  30   * This function is used to get a random password.
  31   * @return a random password with alpha numeric chanreters of length 8
  32   */
  33  function makeRandomPassword() 
  34  {
  35      global $log;
  36      $log->debug("Entering makeRandomPassword() method ...");
  37          $salt = "abcdefghijklmnopqrstuvwxyz0123456789";
  38          srand((double)microtime()*1000000);
  39          $i = 0;
  40          while ($i <= 7)
  41      {
  42                  $num = rand() % 33;
  43                  $tmp = substr($salt, $num, 1);
  44                  $pass = $pass . $tmp;
  45                  $i++;
  46      }
  47  $log->debug("Exiting makeRandomPassword method ...");
  48        return $pass;
  49  }
  50  
  51  $local_log =& LoggerManager::getLogger('index');
  52  
  53  global $log,$adb;
  54  $focus = new Contacts();
  55  
  56  setObjectValuesFromRequest(&$focus);
  57  
  58  if($_REQUEST['salutation'] == '--None--')    $_REQUEST['salutation'] = '';
  59  if (!isset($_REQUEST['email_opt_out'])) $focus->email_opt_out = 'off';
  60  if (!isset($_REQUEST['do_not_call'])) $focus->do_not_call = 'off';
  61  
  62  //Checking If image is given or not
  63  //$image_upload_array=SaveImage($_FILES,'contact',$focus->id,$focus->mode);
  64  $image_name_val=$image_upload_array['imagename'];
  65  $image_error="false";
  66  $errormessage=$image_upload_array['errormessage'];
  67  $saveimage=$image_upload_array['saveimage'];
  68  
  69  //code added for returning back to the current view after edit from list view
  70  if($_REQUEST['return_viewname'] == '') $return_viewname='0';
  71  if($_REQUEST['return_viewname'] != '')$return_viewname=$_REQUEST['return_viewname'];
  72  
  73  if($image_error=="true") //If there is any error in the file upload then moving all the data to EditView.
  74  {
  75          //re diverting the page and reassigning the same values as image error occurs
  76          if($_REQUEST['activity_mode'] != '')$activity_mode=$_REQUEST['activity_mode'];
  77          if($_REQUEST['return_module'] != '')$return_module=$_REQUEST['return_module'];
  78          if($_REQUEST['return_action'] != '')$return_action=$_REQUEST['return_action'];
  79          if($_REQUEST['return_id'] != '')$return_id=$_REQUEST['return_id'];
  80  
  81          $log->debug("There is an error during the upload of contact image.");
  82          $field_values_passed.="";
  83          foreach($focus->column_fields as $fieldname => $val)
  84          {
  85                  if(isset($_REQUEST[$fieldname]))
  86                  {
  87              $log->debug("Assigning the previous values given for the contact to respective vtiger_fields ");
  88                          $field_values_passed.="&";
  89                          $value = $_REQUEST[$fieldname];
  90                          $focus->column_fields[$fieldname] = $value;
  91                          $field_values_passed.=$fieldname."=".$value;
  92  
  93                  }
  94          }
  95          $values_pass=$field_values_passed;
  96          $encode_field_values=base64_encode($values_pass);
  97  
  98          $error_module = "Contacts";
  99          $error_action = "EditView";
 100  
 101      if(isset($_request['return_id']) && $_request['return_id'] != "")
 102                  $return_id = $_request['return_id'];
 103          if(isset($_request['activity_mode']))
 104                  $return_action .= '&activity_mode='.$_request['activity_mode'];
 105  
 106          if($mode=="edit")
 107          {
 108                  $return_id=$_REQUEST['record'];
 109          }
 110          header("location: index.php?action=$error_action&module=$error_module&record=$return_id&return_id=$return_id&return_action=$return_action&return_module=$return_module&activity_mode=$activity_mode&return_viewname=$return_viewname&saveimage=$saveimage&error_msg=$errormessage&image_error=$image_error&encode_val=$encode_field_values");
 111  
 112  }
 113  if($saveimage=="true")
 114  {
 115          $focus->column_fields['imagename']=$image_name_val;
 116          $log->debug("Assign the Image name to the vtiger_field name ");
 117  }
 118  
 119  //if image added then we have to set that $_FILES['name'] in imagename field then only the image will be displayed
 120  if($_FILES['imagename']['name'] != '')
 121      $focus->column_fields['imagename'] = $_FILES['imagename']['name'];
 122      
 123  //Saving the contact
 124  if($image_error=="false")
 125  {
 126      $focus->save("Contacts");
 127      $return_id = $focus->id;
 128  
 129      if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "") $return_module = $_REQUEST['return_module'];
 130      else $return_module = "Contacts";
 131      if(isset($_REQUEST['return_action']) && $_REQUEST['return_action'] != "") $return_action = $_REQUEST['return_action'];
 132      else $return_action = "DetailView";
 133      if(isset($_REQUEST['return_id']) && $_REQUEST['return_id'] != "") $return_id = $_REQUEST['return_id'];
 134  
 135      if(isset($_REQUEST['activity_mode']) && $_REQUEST['activity_mode'] != '') $activitymode = $_REQUEST['activity_mode'];
 136  
 137      $local_log->debug("Saved record with id of ".$return_id);
 138  
 139      if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] == "Campaigns")
 140      {
 141          if(isset($_REQUEST['return_id']) && $_REQUEST['return_id'] != "")
 142          {
 143              $sql = "insert into vtiger_campaigncontrel values (".$_REQUEST['return_id'].",".$focus->id.")";
 144              $adb->query($sql);
 145          }
 146      }
 147  
 148      //BEGIN -- Code for Create Customer Portal Users password and Send Mail 
 149      if($_REQUEST['portal'] == '' && $_REQUEST['mode'] == 'edit')
 150      {
 151          $sql = "update vtiger_portalinfo set user_name='".$_REQUEST['email']."',isactive=0 where id=".$_REQUEST['record'];
 152          $adb->query($sql);
 153      }
 154      elseif($_REQUEST['portal'] != '' && $_REQUEST['email'] != '')// && $_REQUEST['mode'] != 'edit')
 155      {
 156          $id = $_REQUEST['record'];
 157          $username = $_REQUEST['email'];
 158  
 159          if($_REQUEST['mode'] != 'edit')
 160              $insert = 'true';
 161  
 162          $sql = "select id,user_name,user_password,isactive from vtiger_portalinfo";
 163          $result = $adb->query($sql);
 164  
 165          for($i=0;$i<$adb->num_rows($result);$i++)
 166          {
 167              if($id == $adb->query_result($result,$i,'id'))
 168              {
 169                  $dbusername = $adb->query_result($result,$i,'user_name');
 170                  $isactive = $adb->query_result($result,$i,'isactive');
 171  
 172                  if($username == $dbusername && $isactive == 1)
 173                      $flag = 'true';
 174                  else
 175                  {
 176                      $sql = "update vtiger_portalinfo set user_name='".$username."', isactive=1 where id=".$id;
 177                      $adb->query($sql);
 178                      $update = 'true';
 179                      $flag = 'true';
 180                      $password = $adb->query_result($result,$i,'user_password');
 181                  }
 182              }
 183          }
 184          if($flag != 'true')
 185              $insert = 'true';
 186          else
 187              $insert = 'false';
 188  
 189          if($insert == 'true')
 190          {
 191              $password = makeRandomPassword();
 192              $sql = "insert into vtiger_portalinfo (id,user_name,user_password,type,isactive) values(".$focus->id.",'".$username."','".$password."','C',1)";
 193              $adb->query($sql);
 194          }
 195  
 196          $subject = "Customer Portal Login Details";
 197          $contents = "Dear ".$_REQUEST['firstname'].' '.$_REQUEST['lastname'].',<br><br>';
 198          $contents .= 'Your Customer Portal Login details are given below:';
 199          $contents .= "<br><br>User Id : ".$_REQUEST['email'];
 200          $contents .= '<br>Password : '.$password;
 201          $contents .= "<br><br><a href='".$PORTAL_URL."/login.php'>Please Login Here</a>";
 202  
 203          $contents .= '<br><br><b>Note : </b>We suggest you to change your password after logging in first time.';
 204          $contents .= '<br><br>Support Team';
 205  
 206          $log->info("Customer Portal Information Updated in database and details are going to send => '".$_REQUEST['email']."'");
 207          if($insert == 'true' || $update == 'true')
 208          {
 209              $mail_status = send_mail('Contacts',$_REQUEST['email'],$current_user->user_name,'',$subject,$contents);
 210          }
 211          $log->info("After return from the SendMailToCustomer function. Now control will go to the header.");
 212      }
 213      //END -- Code for Create Customer Portal Users password and Send Mail
 214  
 215      $log->info("This Page is redirected to : ".$return_module." / ".$return_action."& return id =".$return_id);
 216  
 217      //code added for returning back to the current view after edit from list view
 218      if($_REQUEST['return_viewname'] == '') $return_viewname='0';
 219      if($_REQUEST['return_viewname'] != '')$return_viewname=$_REQUEST['return_viewname'];
 220  
 221      if(isset($_REQUEST['parenttab']) && $_REQUEST['parenttab'] != "") $parenttab = $_REQUEST['parenttab'];
 222  
 223      //Send notification mail to the assigned to owner about the contact creation
 224      if($focus->column_fields['notify_owner'] == 1 || $focus->column_fields['notify_owner'] == 'on')
 225          $status = sendNotificationToOwner('Contacts',&$focus);
 226  
 227      header("Location: index.php?action=$return_action&module=$return_module&parenttab=$parenttab&record=$return_id&activity_mode=$activitymode&viewname=$return_viewname");
 228  
 229  }
 230  
 231  
 232  ?>


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