[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/modules/Emails/ -> 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/Emails/Save.php,v 1.27 2005/04/29 08:54:38 rank 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   //check for mail server configuration thro ajax
  24  if(isset($_REQUEST['server_check']) && $_REQUEST['server_check'] == 'true')
  25  {
  26      $sql="select * from vtiger_systems where server_type = 'email'";
  27      $records=$adb->num_rows($adb->query($sql),0,"id");
  28      if($records != '')
  29          echo 'SUCESS';
  30      else
  31          echo 'FAILURE';    
  32      die;    
  33  }
  34  
  35  //Added on 09-11-2005 to avoid loading the webmail vtiger_files in Email process
  36  if($_REQUEST['smodule'] != '')
  37  {
  38      define('SM_PATH','modules/squirrelmail-1.4.4/');
  39      /* SquirrelMail required vtiger_files. */
  40      require_once(SM_PATH . 'functions/strings.php');
  41      require_once(SM_PATH . 'functions/imap_general.php');
  42      require_once(SM_PATH . 'functions/imap_messages.php');
  43      require_once(SM_PATH . 'functions/i18n.php');
  44      require_once(SM_PATH . 'functions/mime.php');
  45      require_once(SM_PATH .'include/load_prefs.php');
  46      //require_once(SM_PATH . 'class/mime/Message.class.php');
  47      require_once(SM_PATH . 'class/mime.class.php');
  48      sqgetGlobalVar('key',       $key,           SQ_COOKIE);
  49      sqgetGlobalVar('username',  $username,      SQ_SESSION);
  50      sqgetGlobalVar('onetimepad',$onetimepad,    SQ_SESSION);
  51      $mailbox = 'INBOX';
  52  }
  53  
  54  require_once ('modules/Emails/Emails.php');
  55  require_once ('include/logging.php');
  56  require_once ('include/database/PearDatabase.php');
  57  
  58  $local_log =& LoggerManager::getLogger('index');
  59  
  60  $focus = new Emails();
  61  
  62  global $current_user;
  63  setObjectValuesFromRequest(&$focus);
  64  //Check if the file is exist or not.
  65  if($_FILES["filename"]["size"] == 0 && $_FILES["filename"]["name"] != '')
  66  {
  67          $file_upload_error = true;
  68          $_FILES = '';
  69  }
  70  if((isset($_REQUEST['deletebox']) && $_REQUEST['deletebox'] != null) && $_REQUEST['addbox'] == null)
  71  {
  72      imap_delete($mbox,$_REQUEST['deletebox']);
  73      imap_expunge($mbox);
  74      header("Location: index.php?module=Emails&action=index");
  75      exit();
  76  }
  77  /*if(isset($_REQUEST['fromemail']) && $_REQUEST['fromemail'] != null)
  78  {
  79      //get the list of data from the comma separated array
  80      $emailids = explode(",",$_REQUEST['fromemail']);
  81      $subjects = explode(",",$_REQUEST['subject']);
  82      $ids = explode(",",$_REQUEST['idlist']);
  83      $total = count($ids);
  84      for($z=0;$z<$total;$z++)
  85      {
  86          $msgData='';
  87          global $current_user;
  88          require_once('include/utils/UserInfoUtil.php');
  89          $mailInfo = getMailServerInfo($current_user);
  90          $temprow = $adb->fetch_array($mailInfo);
  91  
  92          $secretkey=$temprow["mail_password"];
  93          $imapServerAddress=$temprow["mail_servername"];
  94          $imapPort="143";
  95  
  96          $key = OneTimePadEncrypt($secretkey, $onetimepad);
  97          $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
  98          $mbx_response=sqimap_mailbox_select($imapConnection, $mailbox);
  99  
 100          $message = sqimap_get_message($imapConnection, $ids[$z], $mailbox);
 101          $header = $message->rfc822_header;
 102          $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
 103          $cnt = count($ent_ar);
 104          global $color;
 105          for ($u = 0; $u < $cnt; $u++)
 106          {
 107              $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$u], $ids[$z], $mailbox);
 108              $msgData = $messagebody;
 109          }
 110  
 111              $ctctExists = checkIfContactExists($emailids[$z]);
 112              if($ctctExists > 0)
 113              {
 114                  $focus->column_fields['parent_id']=$ctctExists;
 115              }
 116              global $current_user;
 117  
 118              $focus->column_fields['subject']=$subjects[$z];
 119              $focus->column_fields["activitytype"]="Emails";
 120              //this line has been added to get the related list data in the contact description
 121              $focus->column_fields["assigned_user_id"]=$current_user->id;
 122              $focus->column_fields["date_start"]=$_REQUEST['adddate'];
 123              $focus->column_fields["time_start"]=$_REQUEST['adddate'];
 124  
 125              $focus->column_fields["description"]=$msgData;
 126              $focus->save("Emails");
 127              $return_id = $focus->id;
 128              $return_module='Emails';    
 129              $return_action='DetailView';    
 130      }
 131      header("Location: index.php?action=$return_action&module=$return_module&parent_id=$parent_id&record=$return_id&filename=$filename");
 132      return;
 133  }*/
 134  
 135  /**    Function to check whether the contact is exist of not
 136   *    input  : contact id
 137   *    return : contact id if contact exist, else -1 will be return
 138   */
 139  function checkIfContactExists($mailid)
 140  {
 141      global $log;
 142      $log->debug("Entering checkIfContactExists(".$mailid.") method ...");
 143      global $adb;
 144      $sql = "select contactid from vtiger_contactdetails inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid where vtiger_crmentity.deleted=0 and email= ".$adb->quote($mailid);
 145      $result = $adb->query($sql);
 146      $numRows = $adb->num_rows($result);
 147      if($numRows > 0)
 148      {
 149          $log->debug("Exiting checkIfContactExists method ...");
 150          return $adb->query_result($result,0,"contactid");
 151      }
 152      else
 153      {
 154          $log->debug("Exiting checkIfContactExists method ...");
 155          return -1;
 156      }
 157  }
 158  //assign the focus values
 159  $focus->filename = $_REQUEST['file_name'];
 160  $focus->parent_id = $_REQUEST['parent_id'];
 161  $focus->parent_type = $_REQUEST['parent_type'];
 162  $focus->column_fields["assigned_user_id"]=$current_user->id;
 163  $focus->column_fields["activitytype"]="Emails";
 164  $focus->column_fields["date_start"]= date('Y-m-d');
 165  $focus->save("Emails");
 166  
 167  //saving the email details in vtiger_emaildetails vtiger_table
 168  $return_id = $focus->id;
 169  $email_id = $return_id;
 170  $query = 'select emailid from vtiger_emaildetails where emailid ='.$email_id;
 171  $result = $adb->query($query);
 172  if(isset($_REQUEST["hidden_toid"]) && $_REQUEST["hidden_toid"]!='')
 173      $all_to_ids = ereg_replace(",","###",$_REQUEST["hidden_toid"]);
 174  if(isset($_REQUEST["saved_toid"]) && $_REQUEST["saved_toid"]!='')
 175      $all_to_ids .= ereg_replace(",","###",$_REQUEST["saved_toid"]);
 176      
 177  $all_cc_ids = ereg_replace(",","###",$_REQUEST["ccmail"]);
 178  $all_bcc_ids = ereg_replace(",","###",$_REQUEST["bccmail"]);
 179  if($adb->num_rows($result) > 0)
 180  {
 181      $query = 'update vtiger_emaildetails set to_email="'.$all_to_ids.'",cc_email="'.$all_cc_ids.'",bcc_email="'.$all_bcc_ids.'",idlists="'.$_REQUEST["parent_id"].'",email_flag="SAVED" where emailid = '.$email_id;
 182  }else
 183  {
 184      $query = 'insert into vtiger_emaildetails values ('.$email_id.',"","'.$all_to_ids.'","'.$all_cc_ids.'","'.$all_bcc_ids.'","","'.$_REQUEST["parent_id"].'","SAVED")';
 185  }
 186  $adb->query($query);
 187  
 188  
 189  $focus->retrieve_entity_info($return_id,"Emails");
 190  
 191  //this is to receive the data from the Select Users button
 192  if($_REQUEST['source_module'] == null)
 193  {
 194      $module = 'users';
 195  }
 196  //this will be the case if the Select Contact button is chosen
 197  else
 198  {
 199      $module = $_REQUEST['source_module'];
 200  }
 201  
 202  if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "") $return_module = $_REQUEST['return_module'];
 203  else $return_module = "Emails";
 204  if(isset($_REQUEST['return_action']) && $_REQUEST['return_action'] != "") $return_action = $_REQUEST['return_action'];
 205  else $return_action = "DetailView";
 206  if(isset($_REQUEST['return_id']) && $_REQUEST['return_id'] != "") $return_id = $_REQUEST['return_id'];
 207  if(isset($_REQUEST['filename']) && $_REQUEST['filename'] != "") $filename = $_REQUEST['filename'];
 208  
 209  $local_log->debug("Saved record with id of ".$return_id);
 210  
 211  if($_REQUEST["parent_name"] != '' && isset($_REQUEST["parent_name"])) {
 212      include ("modules/Emails/webmailsend.php");
 213  
 214  } elseif( isset($_REQUEST['send_mail']) && $_REQUEST['send_mail'])
 215      include ("modules/Emails/mailsend.php");
 216  
 217  
 218  
 219  if(isset($_REQUEST['return_action']) && $_REQUEST['return_action'] == 'mailbox')
 220      header("Location: index.php?module=$return_module&action=index");
 221  else {
 222      if($_REQUEST['return_viewname'] == '') $return_viewname='0';
 223      if($_REQUEST['return_viewname'] != '')$return_viewname=$_REQUEST['return_viewname'];
 224      $inputs="<script>window.opener.location.href=window.opener.location.href;window.self.close();</script>";
 225      echo $inputs;
 226  }
 227  ?>


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