[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
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 ?> 12 <html> 13 <body> 14 <script> 15 if (document.layers) 16 { 17 document.write("This feature requires IE 5.5 or higher for Windows on Microsoft Windows 2000, Windows NT4 SP6, Windows XP."); 18 document.write("<br><br>Click <a href='#' onclick='window.history.back();'>here</a> to return to the previous page"); 19 } 20 else if (document.layers || (!document.all && document.getElementById)) 21 { 22 document.write("This feature requires IE 5.5 or higher for Windows on Microsoft Windows 2000, Windows NT4 SP6, Windows XP."); 23 document.write("<br><br>Click <a href='#' onclick='window.history.back();'>here</a> to return to the previous page"); 24 } 25 else if(document.all) 26 { 27 document.write("<OBJECT Name='vtigerCRM' codebase='modules/Settings/vtigerCRM.CAB#version=1,5,0,0' id='objMMPage' classid='clsid:0FC436C2-2E62-46EF-A3FB-E68E94705126' width=0 height=0></object>"); 28 } 29 </script> 30 <?php 31 require_once ('include/database/PearDatabase.php'); 32 require_once ('config.php'); 33 //echo 'id is ....... ' .$_REQUEST['record']; 34 35 //echo 'merge file name is ...' .$_REQUEST['mergefile']; 36 37 $templateid = $_REQUEST['mergefile']; 38 39 if($templateid == "") 40 { 41 die("Select Mail Merge Template"); 42 } 43 //get the particular file from db and store it in the local hard disk. 44 //store the path to the location where the file is stored and pass it as parameter to the method 45 $sql = "select filename,data,filesize from vtiger_wordtemplates where templateid=".$templateid; 46 47 $result = $adb->query($sql); 48 $temparray = $adb->fetch_array($result); 49 50 $fileContent = $temparray['data']; 51 $filename=$temparray['filename']; 52 $filesize=$temparray['filesize']; 53 $wordtemplatedownloadpath =$root_directory ."/test/wordtemplatedownload/"; 54 55 $handle = fopen($wordtemplatedownloadpath .$temparray['filename'],"wb"); 56 fwrite($handle,base64_decode($fileContent),$filesize); 57 fclose($handle); 58 59 60 //<<<<<<<<<<<<<<<<<<<<<<<<<<<for mass merge>>>>>>>>>>>>>>>>>>>>>>>> 61 $mass_merge = $_REQUEST['idlist']; 62 $single_record = $_REQUEST['record']; 63 64 if($mass_merge != "") 65 { 66 $mass_merge = explode(";",$mass_merge); 67 $temp_mass_merge = $mass_merge; 68 if(array_pop($temp_mass_merge)=="") 69 array_pop($mass_merge); 70 $mass_merge = implode(",",$mass_merge); 71 }else if($single_record != "") 72 { 73 $mass_merge = $single_record; 74 }else 75 { 76 die("Record Id is not found, cannot merge the document"); 77 } 78 79 //<<<<<<<<<<<<<<<<header for csv and select columns for query>>>>>>>>>>>>>>>>>>>>>>>> 80 $query1="select vtiger_tab.name,vtiger_field.tablename,vtiger_field.columnname,vtiger_field.fieldlabel from vtiger_field inner join vtiger_tab on vtiger_tab.tabid = vtiger_field.tabid where vtiger_field.tabid in (4,6) and vtiger_field.block <> 6 and vtiger_field.block <> 75 order by vtiger_field.tablename"; 81 82 $result = $adb->query($query1); 83 $y=$adb->num_rows($result); 84 85 for ($x=0; $x<$y; $x++) 86 { 87 $tablename = $adb->query_result($result,$x,"tablename"); 88 $columnname = $adb->query_result($result,$x,"columnname"); 89 $modulename = $adb->query_result($result,$x,"name"); 90 91 if($tablename == "crmentity") 92 { 93 if($modulename == "Accounts") 94 { 95 $tablename = "crmentityAccounts"; 96 } 97 } 98 $querycolumns[$x] = $tablename.".".$columnname; 99 if($columnname == "smownerid") 100 { 101 if($modulename == "Accounts") 102 { 103 $querycolumns[$x]="concat(usersAccounts.last_name,' ',usersAccounts.first_name) as username"; 104 } 105 if($modulename == "Contacts") 106 { 107 $querycolumns[$x]="concat(vtiger_users.last_name,' ',vtiger_users.first_name) as usercname,vtiger_users.first_name,vtiger_users.last_name,vtiger_users.user_name,vtiger_users.yahoo_id,vtiger_users.title,vtiger_users.phone_work,vtiger_users.department,vtiger_users.phone_mobile,vtiger_users.phone_other,vtiger_users.phone_fax,vtiger_users.email1,vtiger_users.phone_home,vtiger_users.email2,vtiger_users.address_street,vtiger_users.address_city,vtiger_users.address_state,vtiger_users.address_postalcode,vtiger_users.address_country"; 108 } 109 } 110 if($columnname == "parentid") 111 { 112 $querycolumns[$x] = "accountAccounts.accountname"; 113 } 114 if($columnname == "accountid") 115 { 116 $querycolumns[$x] = "accountContacts.accountname"; 117 } 118 if($columnname == "reportsto") 119 { 120 $querycolumns[$x] = "contactdetailsContacts.lastname"; 121 } 122 123 124 if($modulename == "Accounts") 125 { 126 $field_label[$x] = "ACCOUNT_".strtoupper(str_replace(" ","",$adb->query_result($result,$x,"fieldlabel"))); 127 } 128 129 if($modulename == "Contacts") 130 { 131 $field_label[$x] = "CONTACT_".strtoupper(str_replace(" ","",$adb->query_result($result,$x,"fieldlabel"))); 132 if($columnname == "smownerid") 133 { 134 $field_label[$x] = $field_label[$x].",USER_FIRSTNAME,USER_LASTNAME,USER_USERNAME,USER_YAHOOID,USER_TITLE,USER_OFFICEPHONE,USER_DEPARTMENT,USER_MOBILE,USER_OTHERPHONE,USER_FAX,USER_EMAIL,USER_HOMEPHONE,USER_OTHEREMAIL,USER_PRIMARYADDRESS,USER_CITY,USER_STATE,USER_POSTALCODE,USER_COUNTRY"; 135 } 136 } 137 138 139 } 140 $csvheader = implode(",",$field_label); 141 //echo $csvheader; 142 //<<<<<<<<<<<<<<<<End>>>>>>>>>>>>>>>>>>>>>>>> 143 144 if(count($querycolumns) > 0) 145 { 146 $selectcolumns = implode($querycolumns,","); 147 148 149 $query = "select ".$selectcolumns." from vtiger_contactdetails 150 inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_contactdetails.contactid 151 inner join vtiger_contactaddress on vtiger_contactdetails.contactid = vtiger_contactaddress.contactaddressid 152 inner join vtiger_contactsubdetails on vtiger_contactdetails.contactid = vtiger_contactsubdetails.contactsubscriptionid 153 inner join vtiger_contactscf on vtiger_contactdetails.contactid = vtiger_contactscf.contactid 154 left join vtiger_contactdetails as contactdetailsContacts on contactdetailsContacts.contactid = vtiger_contactdetails.reportsto 155 left join vtiger_account as accountContacts on accountContacts.accountid = vtiger_contactdetails.accountid 156 left join vtiger_users on vtiger_users.id = vtiger_crmentity.smownerid 157 left join vtiger_account on vtiger_account.accountid = vtiger_contactdetails.accountid 158 left join vtiger_crmentity as crmentityAccounts on crmentityAccounts.crmid=vtiger_account.accountid 159 left join vtiger_accountbillads on vtiger_account.accountid=vtiger_accountbillads.accountaddressid 160 left join vtiger_accountshipads on vtiger_account.accountid=vtiger_accountshipads.accountaddressid 161 left join vtiger_accountscf on vtiger_account.accountid = vtiger_accountscf.accountid 162 left join vtiger_account as accountAccounts on accountAccounts.accountid = vtiger_account.parentid 163 left join vtiger_users as usersAccounts on usersAccounts.id = crmentityAccounts.smownerid 164 where vtiger_crmentity.deleted=0 and (crmentityAccounts.deleted <> 1) and vtiger_contactdetails.contactid in(".$mass_merge.")"; 165 166 167 $result = $adb->query($query); 168 169 while($columnValues = $adb->fetch_array($result)) 170 { 171 $y=$adb->num_fields($result); 172 for($x=0; $x<$y; $x++) 173 { 174 $value = $columnValues[$x]; 175 //<<<<<<<<<<<<<<< For blank Fields >>>>>>>>>>>>>>>>>>>>>>>>>>>> 176 if($value == "0") 177 { 178 $value = ""; 179 } 180 if(trim($value) == "--None--" || trim($value) == "--none--") 181 { 182 $value = ""; 183 } 184 //<<<<<<<<<<<<<<< End >>>>>>>>>>>>>>>>>>>>>>>>>>>> 185 $actual_values[$x] = $value; 186 $actual_values[$x] = str_replace('"'," ",$actual_values[$x]); 187 //if value contains any line feed or carriage return replace the value with ".value." 188 if (preg_match ("/(\r\n)/", $actual_values[$x])) 189 { 190 $actual_values[$x] = '"'.$actual_values[$x].'"'; 191 } 192 $actual_values[$x] = str_replace(","," ",$actual_values[$x]); 193 } 194 195 $mergevalue[] = implode($actual_values,","); 196 } 197 $csvdata = implode($mergevalue,"###"); 198 }else 199 { 200 die("No fields to do Merge"); 201 } 202 203 $handle = fopen($wordtemplatedownloadpath."datasrc.csv","wb"); 204 fwrite($handle,$csvheader."\r\n"); 205 fwrite($handle,str_replace("###","\r\n",$csvdata)); 206 fclose($handle); 207 208 ?> 209 <script> 210 if (window.ActiveXObject){ 211 try 212 { 213 ovtigerVM = eval("new ActiveXObject('vtigerCRM.ActiveX');"); 214 if(ovtigerVM) 215 { 216 var filename = "<?php echo $filename?>"; 217 if(filename != "") 218 { 219 if(objMMPage.bDLTempDoc("<?php echo $site_URL?>/test/wordtemplatedownload/<?php echo $filename?>","MMTemplate.doc")) 220 { 221 try 222 { 223 if(objMMPage.Init()) 224 { 225 objMMPage.vLTemplateDoc(); 226 objMMPage.bBulkHDSrc("<?php echo $site_URL;?>/test/wordtemplatedownload/datasrc.csv"); 227 objMMPage.vBulkOpenDoc(); 228 objMMPage.UnInit() 229 window.history.back(); 230 } 231 }catch(errorObject) 232 { 233 document.write("Error while processing mail merge operation"); 234 } 235 }else 236 { 237 document.write("Cannot get template document"); 238 } 239 } 240 } 241 } 242 catch(e) { 243 document.write("Requires to download ActiveX Control from vtigerCRM. Please, ensure that you have administration privilage"); 244 } 245 } 246 </script> 247 </body> 248 </html>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |