[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/modules/Emails/ -> Emails.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/Emails.php,v 1.41 2005/04/28 08:11:21 rank 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  include_once ('config.php');
  24  require_once ('include/logging.php');
  25  require_once ('include/database/PearDatabase.php');
  26  require_once ('data/SugarBean.php');
  27  require_once ('data/CRMEntity.php');
  28  require_once ('modules/Contacts/Contacts.php');
  29  require_once ('modules/Accounts/Accounts.php');
  30  require_once ('modules/Potentials/Potentials.php');
  31  require_once ('modules/Users/Users.php');
  32  
  33  // Email is used to store customer information.
  34  class Emails extends CRMEntity {
  35      var $log;
  36      var $db;
  37  
  38      // Stored vtiger_fields
  39    // added to check email save from plugin or not
  40    var $plugin_save = false;
  41  
  42  
  43      var $tab_name = Array('vtiger_crmentity','vtiger_activity');
  44          var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_activity'=>'activityid','vtiger_seactivityrel'=>'activityid','vtiger_cntactivityrel'=>'activityid','vtiger_attachments'=>'attachmentsid');
  45  
  46      // This is the list of vtiger_fields that are in the lists.
  47          var $list_fields = Array(
  48                         'Subject'=>Array('activity'=>'subject'),
  49                         'Related to'=>Array('seactivityrel'=>'activityid'),
  50                         'Date Sent'=>Array('activity'=>'date_start'),
  51                         'Assigned To'=>Array('crmentity','smownerid')
  52                      );
  53  
  54         var $list_fields_name = Array(
  55                         'Subject'=>'subject',
  56                         'Related to'=>'activityid',
  57                         'Date Sent'=>'date_start',
  58                         'Assigned To'=>'assigned_user_id'
  59                      );
  60  
  61         var $list_link_field= 'subject';
  62  
  63      var $column_fields = Array();
  64  
  65      var $sortby_fields = Array('subject','date_start','smownerid');
  66  
  67      //Added these variables which are used as default order by and sortorder in ListView
  68      var $default_order_by = 'date_start';
  69      var $default_sort_order = 'ASC';
  70  
  71      /** This function will set the columnfields for Email module 
  72      */
  73  
  74  	function Emails() {
  75          $this->log = LoggerManager::getLogger('email');
  76          $this->log->debug("Entering Emails() method ...");
  77          $this->log = LoggerManager::getLogger('email');
  78          $this->db = new PearDatabase();
  79          $this->column_fields = getColumnFields('Emails');
  80          $this->log->debug("Exiting Email method ...");
  81      }
  82  
  83  
  84  	function save_module($module)
  85      {
  86          global $adb;
  87          //Inserting into seactivityrel
  88          
  89            //modified by Richie as raju's implementation broke the feature for addition of webmail to vtiger_crmentity.need to be more careful in future while integrating code
  90               if($_REQUEST['module']=="Emails" && $_REQUEST['smodule']!='webmails' && (!$this->plugin_save))
  91            {
  92                  if($_REQUEST['currentid']!='')
  93                  {
  94                      $actid=$_REQUEST['currentid'];
  95                  }
  96                  else 
  97                  {
  98                      $actid=$_REQUEST['record'];
  99                  }
 100                  $parentid=$_REQUEST['parent_id'];
 101                  if($_REQUEST['module'] != 'Emails' && $_REQUEST['module'] != 'Webmails')
 102                  {
 103                      if(!$parentid) {
 104                          $parentid = $adb->getUniqueID('vtiger_seactivityrel');
 105                      }
 106                      $mysql='insert into vtiger_seactivityrel values('.$parentid.','.$actid.')';
 107                      $adb->query($mysql);
 108                  }
 109                  else
 110                  {      
 111                      $myids=explode("|",$parentid);  //2@71|
 112                      for ($i=0;$i<(count($myids)-1);$i++)
 113                      {
 114                          $realid=explode("@",$myids[$i]);
 115                          $mycrmid=$realid[0];
 116                          //added to handle the relationship of emails with vtiger_users
 117                          if($realid[1] == -1)
 118                              $mysql='insert into vtiger_salesmanactivityrel values('.$mycrmid.','.$actid.')';
 119                          else    
 120                              $mysql='insert into vtiger_seactivityrel values('.$mycrmid.','.$actid.')';
 121                          $adb->query($mysql);
 122                      }
 123                  }
 124              }
 125              else
 126              {
 127                  if(isset($this->column_fields['parent_id']) && $this->column_fields['parent_id'] != '')
 128                  {
 129                      $this->insertIntoEntityTable('vtiger_seactivityrel', $module);
 130                  }
 131                  elseif($this->column_fields['parent_id']=='' && $insertion_mode=="edit")
 132                  {
 133                      $this->deleteRelation('vtiger_seactivityrel');
 134                  }
 135              }
 136  
 137  
 138              //Insert into cntactivity rel        
 139  
 140              if(isset($this->column_fields['contact_id']) && $this->column_fields['contact_id'] != '')
 141              {
 142                  $this->insertIntoEntityTable('vtiger_cntactivityrel', $module);
 143              }
 144              elseif($this->column_fields['contact_id'] =='' && $insertion_mode=="edit")
 145              {
 146                  $this->deleteRelation('vtiger_cntactivityrel');
 147              }
 148              
 149              //Inserting into attachment
 150              
 151              $this->insertIntoAttachment($this->id,$module);            
 152          
 153      }
 154  
 155  
 156  	function insertIntoAttachment($id,$module)
 157      {
 158          global $log, $adb;
 159          $log->debug("Entering into insertIntoAttachment($id,$module) method.");
 160          
 161          $file_saved = false;
 162  
 163          //This is to added to store the existing attachment id of the contact where we should delete this when we give new image
 164  
 165          foreach($_FILES as $fileindex => $files)
 166          {
 167              if($files['name'] != '' && $files['size'] > 0)
 168              {
 169                  $file_saved = $this->uploadAndSaveFile($id,$module,$files);
 170              }
 171          }
 172  
 173          $log->debug("Exiting from insertIntoAttachment($id,$module) method.");
 174      }    
 175      
 176  
 177      /** Returns a list of the associated contacts
 178       * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
 179       * All Rights Reserved..
 180       * Contributor(s): ______________________________________..
 181      */
 182  	function get_contacts($id)
 183      {
 184          global $log,$adb;
 185          $log->debug("Entering get_contacts(".$id.") method ...");
 186          global $mod_strings;
 187          global $app_strings;
 188  
 189          $focus = new Contacts();
 190  
 191          $button = '';
 192          $returnset = '&return_module=Emails&return_action=CallRelatedList&return_id='.$id;
 193  
 194          $query = 'select vtiger_contactdetails.accountid, vtiger_contactdetails.contactid, vtiger_contactdetails.firstname,vtiger_contactdetails.lastname, vtiger_contactdetails.department, vtiger_contactdetails.title, vtiger_contactdetails.email, vtiger_contactdetails.phone, vtiger_contactdetails.emailoptout, vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime from vtiger_contactdetails inner join vtiger_cntactivityrel on vtiger_cntactivityrel.contactid=vtiger_contactdetails.contactid inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_contactdetails.contactid left join vtiger_contactgrouprelation on vtiger_contactdetails.contactid=vtiger_contactgrouprelation.contactid left join vtiger_groups on vtiger_groups.groupname=vtiger_contactgrouprelation.groupname where vtiger_cntactivityrel.activityid='.$adb->quote($id).' and vtiger_crmentity.deleted=0';
 195          $log->info("Contact Related List for Email is Displayed");
 196          $log->debug("Exiting get_contacts method ...");
 197          return GetRelatedList('Emails','Contacts',$focus,$query,$button,$returnset);
 198      }
 199      
 200      /** Returns the column name that needs to be sorted
 201       * Portions created by vtigerCRM are Copyright (C) vtigerCRM.
 202       * All Rights Reserved..
 203       * Contributor(s): Mike Crowe
 204      */
 205  
 206  	function getSortOrder()
 207      {    
 208          global $log;
 209          $log->debug("Entering getSortOrder() method ...");
 210          if(isset($_REQUEST['sorder'])) 
 211              $sorder = $_REQUEST['sorder'];
 212          else
 213              $sorder = (($_SESSION['EMAILS_SORT_ORDER'] != '')?($_SESSION['EMAILS_SORT_ORDER']):($this->default_sort_order));
 214  
 215          $log->debug("Exiting getSortOrder method ...");
 216          return $sorder;
 217      }
 218  
 219      /** Returns the order in which the records need to be sorted
 220       * Portions created by vtigerCRM are Copyright (C) vtigerCRM.
 221       * All Rights Reserved..
 222       * Contributor(s): Mike Crowe
 223      */
 224  
 225  	function getOrderBy()
 226      {
 227          global $log;
 228          $log->debug("Entering getOrderBy() method ...");
 229          if (isset($_REQUEST['order_by'])) 
 230              $order_by = $_REQUEST['order_by'];
 231          else
 232              $order_by = (($_SESSION['EMAILS_ORDER_BY'] != '')?($_SESSION['EMAILS_ORDER_BY']):($this->default_order_by));
 233  
 234          $log->debug("Exiting getOrderBy method ...");
 235          return $order_by;
 236      }    
 237      // Mike Crowe Mod --------------------------------------------------------
 238  
 239      /** Returns a list of the associated vtiger_users
 240       * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
 241       * All Rights Reserved..
 242       * Contributor(s): ______________________________________..
 243      */
 244  	function get_users($id)
 245      {
 246          global $log;
 247          $log->debug("Entering get_users(".$id.") method ...");
 248          global $adb;
 249          global $mod_strings;
 250          global $app_strings;
 251  
 252          $id = $_REQUEST['record'];
 253  
 254          $query = 'SELECT vtiger_users.id, vtiger_users.first_name,vtiger_users.last_name, vtiger_users.user_name, vtiger_users.email1, vtiger_users.email2, vtiger_users.yahoo_id, vtiger_users.phone_home, vtiger_users.phone_work, vtiger_users.phone_mobile, vtiger_users.phone_other, vtiger_users.phone_fax from vtiger_users inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.smid=vtiger_users.id and vtiger_salesmanactivityrel.activityid='.$adb->quote($id);
 255          $result=$adb->query($query);   
 256  
 257          $noofrows = $adb->num_rows($result);
 258          $header [] = $app_strings['LBL_LIST_NAME'];
 259  
 260          $header []= $app_strings['LBL_LIST_USER_NAME'];
 261  
 262          $header []= $app_strings['LBL_EMAIL'];
 263  
 264          $header []= $app_strings['LBL_PHONE'];
 265          while($row = $adb->fetch_array($result))
 266          {
 267  
 268              global $current_user;
 269  
 270              $entries = Array();
 271  
 272              if(is_admin($current_user))
 273              {
 274                  $entries[] = $row['last_name'].' '.$row['first_name'];
 275              }
 276              else
 277              {
 278                  $entries[] = $row['last_name'].' '.$row['first_name'];
 279              }        
 280  
 281              $entries[] = $row['user_name'];
 282              $entries[] = $row['email1'];
 283              if($email == '')        $email = $row['email2'];
 284              if($email == '')        $email = $row['yahoo_id'];
 285  
 286              $entries[] = $row['phone_home'];
 287              if($phone == '')        $phone = $row['phone_work'];
 288              if($phone == '')        $phone = $row['phone_mobile'];
 289              if($phone == '')        $phone = $row['phone_other'];
 290              if($phone == '')        $phone = $row['phone_fax'];
 291  
 292              //Adding Security Check for User
 293  
 294              $entries_list[] = $entries;
 295          }
 296  
 297          if($entries_list != '')
 298              $return_data = array("header"=>$header, "entries"=>$entries);
 299          $log->debug("Exiting get_users method ...");
 300          return $return_data;
 301      }
 302  
 303      /**
 304        * Returns a list of the associated vtiger_attachments and vtiger_notes of the Email
 305        */
 306  	function get_attachments($id)
 307      {
 308          global $log,$adb;
 309          $log->debug("Entering get_attachments(".$id.") method ...");
 310          $query = "select vtiger_notes.title,'Notes      '  ActivityType, vtiger_notes.filename,
 311          vtiger_attachments.type  FileType,crm2.modifiedtime lastmodified,
 312          vtiger_seattachmentsrel.attachmentsid attachmentsid, vtiger_notes.notesid crmid,
 313              crm2.createdtime, vtiger_notes.notecontent description, vtiger_users.user_name
 314          from vtiger_notes
 315              inner join vtiger_senotesrel on vtiger_senotesrel.notesid= vtiger_notes.notesid
 316              inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_senotesrel.crmid
 317              inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_notes.notesid and crm2.deleted=0
 318              left join vtiger_seattachmentsrel  on vtiger_seattachmentsrel.crmid =vtiger_notes.notesid
 319              left join vtiger_attachments on vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
 320              inner join vtiger_users on crm2.smcreatorid= vtiger_users.id
 321          where vtiger_crmentity.crmid=".$adb->quote($id);
 322          $query .= ' union all ';
 323          $query .= "select vtiger_attachments.description title ,'Attachments'  ActivityType,
 324          vtiger_attachments.name filename, vtiger_attachments.type FileType,crm2.modifiedtime lastmodified,
 325          vtiger_attachments.attachmentsid  attachmentsid,vtiger_seattachmentsrel.attachmentsid crmid,
 326              crm2.createdtime, vtiger_attachments.description, vtiger_users.user_name
 327          from vtiger_attachments
 328              inner join vtiger_seattachmentsrel on vtiger_seattachmentsrel.attachmentsid= vtiger_attachments.attachmentsid
 329              inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_seattachmentsrel.crmid
 330              inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_attachments.attachmentsid
 331              inner join vtiger_users on crm2.smcreatorid= vtiger_users.id
 332          where vtiger_crmentity.crmid=".$adb->quote($id);
 333          
 334          $log->info("Notes&Attachments Related List for Email is Displayed");
 335          $log->debug("Exiting get_attachments method ...");
 336          return getAttachmentsAndNotes('Emails',$query,$id);
 337      }
 338  
 339          /**
 340            * Returns a list of the Emails to be exported
 341            */
 342  	function create_export_query(&$order_by, &$where)
 343      {
 344          global $log;
 345          global $current_user;
 346          $log->debug("Entering create_export_query(".$order_by.",".$where.") method ...");
 347  
 348          include ("include/utils/ExportUtils.php");
 349  
 350          //To get the Permitted fields query and the permitted fields list
 351          $sql = getPermittedFieldsQuery("Emails", "detail_view");
 352          $fields_list = getFieldsListFromQuery($sql);
 353  
 354          $query = "SELECT $fields_list FROM vtiger_activity 
 355              INNER JOIN vtiger_crmentity 
 356                  ON vtiger_crmentity.crmid=vtiger_activity.activityid 
 357              LEFT JOIN vtiger_users
 358                  ON vtiger_users.id = vtiger_crmentity.smownerid
 359              LEFT JOIN vtiger_seactivityrel
 360                  ON vtiger_seactivityrel.activityid = vtiger_activity.activityid
 361              LEFT JOIN vtiger_contactdetails
 362                  ON vtiger_contactdetails.contactid = vtiger_seactivityrel.crmid
 363              LEFT JOIN vtiger_cntactivityrel
 364                  ON vtiger_cntactivityrel.activityid = vtiger_activity.activityid
 365                  AND vtiger_cntactivityrel.contactid = vtiger_cntactivityrel.contactid
 366              LEFT JOIN vtiger_activitygrouprelation
 367                  ON vtiger_activitygrouprelation.activityid = vtiger_crmentity.crmid
 368              LEFT JOIN vtiger_groups
 369                  ON vtiger_groups.groupname = vtiger_activitygrouprelation.groupname
 370              LEFT JOIN vtiger_salesmanactivityrel
 371                  ON vtiger_salesmanactivityrel.activityid = vtiger_activity.activityid
 372              LEFT JOIN vtiger_emaildetails
 373                  ON vtiger_emaildetails.emailid = vtiger_activity.activityid
 374              LEFT JOIN vtiger_seattachmentsrel 
 375                  ON vtiger_activity.activityid=vtiger_seattachmentsrel.crmid 
 376              LEFT JOIN vtiger_attachments 
 377                  ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid 
 378              WHERE vtiger_activity.activitytype='Emails' AND vtiger_crmentity.deleted=0 ";
 379  
 380          require('user_privileges/user_privileges_'.$current_user->id.'.php');
 381          require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
 382          //we should add security check when the user has Private Access
 383  
 384          if($is_admin==false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1)
 385          {
 386              $sec_parameter=getListViewSecurityParameter("Emails");
 387              $query .= $sec_parameter;    
 388          }
 389  
 390          $log->debug("Exiting create_export_query method ...");
 391                  return $query;
 392          }
 393          
 394      /**
 395      * Used to releate email and contacts -- Outlook Plugin
 396      */  
 397  	function set_emails_contact_invitee_relationship($email_id, $contact_id)
 398      {
 399          global $log;
 400          $log->debug("Entering set_emails_contact_invitee_relationship(".$email_id.",". $contact_id.") method ...");
 401          $query = "insert into $this->rel_contacts_table (contactid,activityid) values('$contact_id','$email_id')";
 402          $this->db->query($query,true,"Error setting email to contact relationship: "."<BR>$query");
 403          $log->debug("Exiting set_emails_contact_invitee_relationship method ...");
 404      }
 405       
 406      /**
 407      * Used to releate email and salesentity -- Outlook Plugin
 408      */
 409  	function set_emails_se_invitee_relationship($email_id, $contact_id)
 410      {
 411          global $log;
 412          $log->debug("Entering set_emails_se_invitee_relationship(".$email_id.",". $contact_id.") method ...");
 413          $query = "insert into $this->rel_serel_table (crmid,activityid) values('$contact_id','$email_id')";
 414          $this->db->query($query,true,"Error setting email to contact relationship: "."<BR>$query");
 415          $log->debug("Exiting set_emails_se_invitee_relationship method ...");
 416      }
 417       
 418      /**
 419      * Used to releate email and Users -- Outlook Plugin
 420      */    
 421  	function set_emails_user_invitee_relationship($email_id, $user_id)
 422      {
 423          global $log;
 424          $log->debug("Entering set_emails_user_invitee_relationship(".$email_id.",". $user_id.") method ...");
 425          $query = "insert into $this->rel_users_table (smid,activityid) values ('$user_id', '$email_id')";
 426          $this->db->query($query,true,"Error setting email to user relationship: "."<BR>$query");
 427          $log->debug("Exiting set_emails_user_invitee_relationship method ...");
 428      }        
 429  
 430  
 431  }
 432  /** Function to get the emailids for the given ids form the request parameters 
 433   *  It returns an array which contains the mailids and the parentidlists
 434  */
 435  
 436  function get_to_emailids($module)
 437  {
 438      global $adb;
 439      $query = 'select columnname,fieldid from vtiger_field where fieldid in('.ereg_replace(':',',',$_REQUEST["field_lists"]).')';
 440      $result = $adb->query($query);
 441      $columns = Array();
 442      $idlists = '';
 443      $mailids = '';
 444      while($row = $adb->fetch_array($result))
 445      {
 446          $columns[]=$row['columnname'];
 447          $fieldid[]=$row['fieldid'];
 448      }
 449      $columnlists = implode(',',$columns);
 450      $crmids = ereg_replace(':',',',$_REQUEST["idlist"]);
 451      switch($module)
 452      {
 453          case 'Leads':
 454              $query = 'select crmid,concat(lastname," ",firstname) as entityname,'.$columnlists.' from vtiger_leaddetails inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_leaddetails.leadid left join vtiger_leadscf on vtiger_leadscf.leadid = vtiger_leaddetails.leadid where vtiger_crmentity.deleted=0 and vtiger_crmentity.crmid in ('.$crmids.')';
 455              break;
 456          case 'Contacts':
 457              $query = 'select crmid,concat(lastname," ",firstname) as entityname,'.$columnlists.' from vtiger_contactdetails inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid left join vtiger_contactscf on vtiger_contactscf.contactid = vtiger_contactdetails.contactid where vtiger_crmentity.deleted=0 and vtiger_crmentity.crmid in ('.$crmids.')';
 458              break;
 459          case 'Accounts':
 460              $query = 'select crmid,accountname as entityname,'.$columnlists.' from vtiger_account inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_account.accountid left join vtiger_accountscf on vtiger_accountscf.accountid = vtiger_account.accountid where vtiger_crmentity.deleted=0 and vtiger_crmentity.crmid in ('.$crmids.')';
 461              break;
 462      }    
 463      $result = $adb->query($query);
 464      while($row = $adb->fetch_array($result))
 465      {
 466          $name = $row['entityname'];
 467          for($i=0;$i<count($columns);$i++)
 468          {
 469              if($row[$columns[$i]] != NULL && $row[$columns[$i]] !='')
 470              {
 471                  $idlists .= $row['crmid'].'@'.$fieldid[$i].'|'; 
 472                  $mailids .= $name.'<'.$row[$columns[$i]].'>,';    
 473              }
 474          }
 475      }
 476  
 477      $return_data = Array('idlists'=>$idlists,'mailds'=>$mailids);
 478      return $return_data;
 479          
 480  }
 481  ?>


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