[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/modules/Notes/ -> 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/Notes/Save.php,v 1.7 2005/04/18 10:37:49 samk 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/Notes/Notes.php');
  25  require_once ('include/logging.php');
  26  require_once ('include/upload_file.php');
  27  
  28  $local_log =& LoggerManager::getLogger('index');
  29  
  30  $focus = new Notes();
  31  
  32  setObjectValuesFromRequest(&$focus);
  33  
  34  //Check if the file is exist or not.
  35  if($_FILES["filename"]["size"] == 0 && $_FILES["filename"]["name"] != '')
  36  {
  37      $file_upload_error = true;
  38      $_FILES = '';
  39  }
  40  
  41  if (!isset($_REQUEST['date_due_flag'])) $focus->date_due_flag = 'off';
  42  
  43  //Save the Note
  44  $focus->save("Notes");
  45  
  46  //Added to retrieve the existing attachment of the notes and save it for the new duplicated note
  47  if($_FILES['filename']['name'] == '' && $_REQUEST['mode'] != 'edit' && $_REQUEST['old_id'] != '')
  48  {
  49          $sql = "select vtiger_attachments.* from vtiger_attachments inner join vtiger_seattachmentsrel on vtiger_seattachmentsrel.attachmentsid=vtiger_attachments.attachmentsid where vtiger_seattachmentsrel.crmid= ".$_REQUEST['old_id'];
  50          $result = $adb->query($sql);
  51          if($adb->num_rows($result) != 0)
  52      {
  53                  $attachmentid = $adb->query_result($result,0,'attachmentsid');
  54          $filename = $adb->query_result($result,0,'name');
  55          $filetype = $adb->query_result($result,0,'type');
  56          $filepath = $adb->query_result($result,0,'path');
  57  
  58          $new_attachmentid = $adb->getUniqueID("vtiger_crmentity");
  59          $date_var = $adb->formatDate(date('YmdHis'));    
  60  
  61          $upload_filepath = decideFilePath();
  62  
  63          //Read the old file contents and write it as a new file with new attachment id
  64          $handle = @fopen($upload_filepath.$new_attachmentid."_".$filename,'w');
  65          fputs($handle, file_get_contents($filepath.$attachmentid."_".$filename));
  66          fclose($handle);    
  67  
  68          $adb->query("update vtiger_notes set filename=\"$filename\" where notesid=$focus->id");    
  69          $adb->query("insert into vtiger_crmentity (crmid,setype,createdtime) values('".$new_attachmentid."','Notes Attachment','".$date_var."')");
  70  
  71          $adb->query("insert into vtiger_attachments values(".$new_attachmentid.",'".$filename."','','".$filetype."','".$upload_filepath."')");
  72  
  73          $adb->query("insert into vtiger_seattachmentsrel values('".$focus->id."','".$new_attachmentid."')");
  74      }
  75  }
  76  
  77  
  78  $return_id = $focus->id;
  79  $note_id = $return_id;
  80  
  81  if(isset($_REQUEST['parenttab']) && $_REQUEST['parenttab'] != "") $parenttab = $_REQUEST['parenttab'];
  82  if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "") $return_module = $_REQUEST['return_module'];
  83  else $return_module = "Notes";
  84  if(isset($_REQUEST['return_action']) && $_REQUEST['return_action'] != "") $return_action = $_REQUEST['return_action'];
  85  else $return_action = "DetailView";
  86  if(isset($_REQUEST['return_id']) && $_REQUEST['return_id'] != "") $return_id = $_REQUEST['return_id'];
  87  
  88  // Notes added to Contacts should also update Accounts
  89  // Added by DG 16 Nov 2005
  90  if($_REQUEST['mode'] != 'edit' && ($_REQUEST['return_module']=='Contacts'))
  91  {
  92      $crmid = $_REQUEST['return_id'];
  93      $noteid = $focus->id;
  94      $query = 'select accountid from vtiger_contactdetails where contactid='.$crmid;
  95      $result = $adb->query($query);
  96      if($adb->num_rows($result) != 0)
  97      {
  98          $associated_account = $adb->query_result($result,0,"accountid");
  99      }
 100      else
 101      {
 102          $associated_account = '';
 103      }
 104      if ($associated_account)
 105      {
 106          $sql1 = "insert into vtiger_senotesrel (notesid, crmid) values('";
 107          $sql1 .= $noteid."','".$associated_account."')";
 108          $result = $adb->query($sql1);
 109      }
 110  }
 111  
 112  if($_REQUEST['mode'] != 'edit' && (($_REQUEST['return_module']=='Emails') ||($_REQUEST['return_module']=='HelpDesk') ))
 113  {
 114      if($_REQUEST['email_id'] != '')
 115          $crmid = $_REQUEST['email_id'];
 116      if($_REQUEST['ticket_id'] != '')
 117          $crmid = $_REQUEST['ticket_id'];
 118      if($crmid != $_REQUEST['parent_id'])
 119      {
 120          $sql = "insert into vtiger_senotesrel (notesid, crmid) values('".$focus->id."','".$crmid."')";
 121          $adb->query($sql);
 122      }
 123  }
 124  
 125  $local_log->debug("Saved record with id of ".$return_id);
 126  
 127  //Redirect to EditView if the given file is not valid.
 128  if($file_upload_error)
 129  {
 130      $return_module = 'Notes';
 131      $return_action = 'EditView';
 132      $return_id = $note_id.'&upload_error=true&return_module='.$_REQUEST['return_module'].'&return_action='.$_REQUEST['return_action'].'&return_id='.$_REQUEST['return_id'];
 133  }
 134  
 135  //code added for returning back to the current view after edit from list view
 136  if($_REQUEST['return_viewname'] == '') $return_viewname='0';
 137  if($_REQUEST['return_viewname'] != '')$return_viewname=$_REQUEST['return_viewname'];
 138  header("Location: index.php?action=$return_action&module=$return_module&parenttab=$parenttab&record=$return_id&viewname=$return_viewname");
 139  ?>


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