[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /*+*********************************************************************************** 3 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 *************************************************************************************/ 10 11 class Emails_MassSaveAjax_View extends Vtiger_Footer_View { 12 function __construct() { 13 parent::__construct(); 14 $this->exposeMethod('massSave'); 15 } 16 17 public function checkPermission(Vtiger_Request $request) { 18 $moduleName = $request->getModule(); 19 20 if (!Users_Privileges_Model::isPermitted($moduleName, 'Save')) { 21 throw new AppException(vtranslate($moduleName).' '.vtranslate('LBL_NOT_ACCESSIBLE')); 22 } 23 } 24 25 public function process(Vtiger_Request $request) { 26 $mode = $request->getMode(); 27 if(!empty($mode)) { 28 echo $this->invokeExposedMethod($mode, $request); 29 return; 30 } 31 } 32 33 /** 34 * Function Sends/Saves mass emails 35 * @param <Vtiger_Request> $request 36 */ 37 public function massSave(Vtiger_Request $request) { 38 global $upload_badext; 39 $adb = PearDatabase::getInstance(); 40 41 $moduleName = $request->getModule(); 42 $currentUserModel = Users_Record_Model::getCurrentUserModel(); 43 $recordIds = $this->getRecordsListFromRequest($request); 44 $documentIds = $request->get('documentids'); 45 46 // This is either SENT or SAVED 47 $flag = $request->get('flag'); 48 49 $result = Vtiger_Util_Helper::transformUploadedFiles($_FILES, true); 50 $_FILES = $result['file']; 51 52 $recordId = $request->get('record'); 53 54 if(!empty($recordId)) { 55 $recordModel = Vtiger_Record_Model::getInstanceById($recordId,$moduleName); 56 $recordModel->set('mode', 'edit'); 57 }else{ 58 $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); 59 $recordModel->set('mode', ''); 60 } 61 62 63 $parentEmailId = $request->get('parent_id',null); 64 $attachmentsWithParentEmail = array(); 65 if(!empty($parentEmailId) && !empty ($recordId)) { 66 $parentEmailModel = Vtiger_Record_Model::getInstanceById($parentEmailId); 67 $attachmentsWithParentEmail = $parentEmailModel->getAttachmentDetails(); 68 } 69 $existingAttachments = $request->get('attachments',array()); 70 if(empty($recordId)) { 71 if(is_array($existingAttachments)) { 72 foreach ($existingAttachments as $index => $existingAttachInfo) { 73 $existingAttachInfo['tmp_name'] = $existingAttachInfo['name']; 74 $existingAttachments[$index] = $existingAttachInfo; 75 if(array_key_exists('docid',$existingAttachInfo)) { 76 $documentIds[] = $existingAttachInfo['docid']; 77 unset($existingAttachments[$index]); 78 } 79 80 } 81 } 82 }else{ 83 //If it is edit view unset the exising attachments 84 //remove the exising attachments if it is in edit view 85 86 $attachmentsToUnlink = array(); 87 $documentsToUnlink = array(); 88 89 90 foreach($attachmentsWithParentEmail as $i => $attachInfo) { 91 $found = false; 92 foreach ($existingAttachments as $index => $existingAttachInfo) { 93 if($attachInfo['fileid'] == $existingAttachInfo['fileid']) { 94 $found = true; 95 break; 96 } 97 } 98 //Means attachment is deleted 99 if(!$found) { 100 if(array_key_exists('docid',$attachInfo)) { 101 $documentsToUnlink[] = $attachInfo['docid']; 102 }else{ 103 $attachmentsToUnlink[] = $attachInfo; 104 } 105 } 106 unset($attachmentsWithParentEmail[$i]); 107 } 108 //Make the attachments as empty for edit view since all the attachments will already be there 109 $existingAttachments = array(); 110 if(!empty($documentsToUnlink)) { 111 $recordModel->deleteDocumentLink($documentsToUnlink); 112 } 113 114 if(!empty($attachmentsToUnlink)){ 115 $recordModel->deleteAttachment($attachmentsToUnlink); 116 } 117 118 } 119 120 121 // This will be used for sending mails to each individual 122 $toMailInfo = $request->get('toemailinfo'); 123 124 $to = $request->get('to'); 125 if(is_array($to)) { 126 $to = implode(',',$to); 127 } 128 129 130 $recordModel->set('description', $request->get('description')); 131 $recordModel->set('subject', $request->get('subject')); 132 $recordModel->set('toMailNamesList',$request->get('toMailNamesList')); 133 $recordModel->set('saved_toid', $to); 134 $recordModel->set('ccmail', $request->get('cc')); 135 $recordModel->set('bccmail', $request->get('bcc')); 136 $recordModel->set('assigned_user_id', $currentUserModel->getId()); 137 $recordModel->set('email_flag', $flag); 138 $recordModel->set('documentids', $documentIds); 139 140 $recordModel->set('toemailinfo', $toMailInfo); 141 foreach($toMailInfo as $recordId=>$emailValueList) { 142 if($recordModel->getEntityType($recordId) == 'Users'){ 143 $parentIds .= $recordId.'@-1|'; 144 }else{ 145 $parentIds .= $recordId.'@1|'; 146 } 147 } 148 $recordModel->set('parent_id', $parentIds); 149 150 //save_module still depends on the $_REQUEST, need to clean it up 151 $_REQUEST['parent_id'] = $parentIds; 152 153 $success = false; 154 $viewer = $this->getViewer($request); 155 if ($recordModel->checkUploadSize($documentIds)) { 156 $recordModel->save(); 157 158 //To Handle existing attachments 159 $current_user = Users_Record_Model::getCurrentUserModel(); 160 $ownerId = $recordModel->get('assigned_user_id'); 161 $date_var = date("Y-m-d H:i:s"); 162 if(is_array($existingAttachments)) { 163 foreach ($existingAttachments as $index => $existingAttachInfo) { 164 $file_name = $existingAttachInfo['attachment']; 165 $path = $existingAttachInfo['path']; 166 $fileId = $existingAttachInfo['fileid']; 167 168 $oldFileName = $file_name; 169 //SEND PDF mail will not be having file id 170 if(!empty ($fileId)) { 171 $oldFileName = $existingAttachInfo['fileid'].'_'.$file_name; 172 } 173 $oldFilePath = $path.'/'.$oldFileName; 174 175 $binFile = sanitizeUploadFileName($file_name, $upload_badext); 176 177 $current_id = $adb->getUniqueID("vtiger_crmentity"); 178 179 $filename = ltrim(basename(" " . $binFile)); //allowed filename like UTF-8 characters 180 $filetype = $existingAttachInfo['type']; 181 $filesize = $existingAttachInfo['size']; 182 183 //get the file path inwhich folder we want to upload the file 184 $upload_file_path = decideFilePath(); 185 $newFilePath = $upload_file_path . $current_id . "_" . $binFile; 186 187 copy($oldFilePath, $newFilePath); 188 189 $sql1 = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) values(?, ?, ?, ?, ?, ?, ?)"; 190 $params1 = array($current_id, $current_user->getId(), $ownerId, $moduleName . " Attachment", $recordModel->get('description'), $adb->formatDate($date_var, true), $adb->formatDate($date_var, true)); 191 $adb->pquery($sql1, $params1); 192 193 $sql2 = "insert into vtiger_attachments(attachmentsid, name, description, type, path) values(?, ?, ?, ?, ?)"; 194 $params2 = array($current_id, $filename, $recordModel->get('description'), $filetype, $upload_file_path); 195 $result = $adb->pquery($sql2, $params2); 196 197 $sql3 = 'insert into vtiger_seattachmentsrel values(?,?)'; 198 $adb->pquery($sql3, array($recordModel->getId(), $current_id)); 199 } 200 } 201 $success = true; 202 if($flag == 'SENT') { 203 $status = $recordModel->send(); 204 if ($status === true) { 205 // This is needed to set vtiger_email_track table as it is used in email reporting 206 $recordModel->setAccessCountValue(); 207 } else { 208 $success = false; 209 $message = $status; 210 } 211 } 212 213 } else { 214 $message = vtranslate('LBL_MAX_UPLOAD_SIZE', $moduleName).' '.vtranslate('LBL_EXCEEDED', $moduleName); 215 } 216 $viewer->assign('SUCCESS', $success); 217 $viewer->assign('MESSAGE', $message); 218 $loadRelatedList = $request->get('related_load'); 219 if(!empty($loadRelatedList)){ 220 $viewer->assign('RELATED_LOAD',true); 221 } 222 $viewer->view('SendEmailResult.tpl', $moduleName); 223 } 224 225 /** 226 * Function returns the record Ids selected in the current filter 227 * @param Vtiger_Request $request 228 * @return integer 229 */ 230 public function getRecordsListFromRequest(Vtiger_Request $request) { 231 $cvId = $request->get('viewname'); 232 $selectedIds = $request->get('selected_ids'); 233 $excludedIds = $request->get('excluded_ids'); 234 235 if(!empty($selectedIds) && $selectedIds != 'all') { 236 if(!empty($selectedIds) && count($selectedIds) > 0) { 237 return $selectedIds; 238 } 239 } 240 241 if($selectedIds == 'all'){ 242 $sourceRecord = $request->get('sourceRecord'); 243 $sourceModule = $request->get('sourceModule'); 244 if ($sourceRecord && $sourceModule) { 245 $sourceRecordModel = Vtiger_Record_Model::getInstanceById($sourceRecord, $sourceModule); 246 return $sourceRecordModel->getSelectedIdsList($request->get('parentModule'), $excludedIds); 247 } 248 249 $customViewModel = CustomView_Record_Model::getInstanceById($cvId); 250 if($customViewModel) { 251 $searchKey = $request->get('search_key'); 252 $searchValue = $request->get('search_value'); 253 $operator = $request->get('operator'); 254 if(!empty($operator)) { 255 $customViewModel->set('operator', $operator); 256 $customViewModel->set('search_key', $searchKey); 257 $customViewModel->set('search_value', $searchValue); 258 } 259 return $customViewModel->getRecordIds($excludedIds); 260 } 261 } 262 return array(); 263 } 264 265 public function validateRequest(Vtiger_Request $request) { 266 $request->validateWriteAccess(); 267 } 268 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |