[ 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 34 $templateid = $_REQUEST['mergefile']; 35 36 if($templateid == "") 37 { 38 die("Select Mail Merge Template"); 39 } 40 //get the particular file from db and store it in the local hard disk. 41 //store the path to the location where the file is stored and pass it as parameter to the method 42 $sql = "select filename,data,filesize from vtiger_wordtemplates where templateid=".$templateid; 43 44 $result = $adb->query($sql); 45 $temparray = $adb->fetch_array($result); 46 47 $fileContent = $temparray['data']; 48 $filename=$temparray['filename']; 49 $filesize=$temparray['filesize']; 50 $wordtemplatedownloadpath =$root_directory ."/test/wordtemplatedownload/"; 51 52 53 $handle = fopen($wordtemplatedownloadpath.$temparray['filename'],"wb"); 54 fwrite($handle,base64_decode($fileContent),$filesize); 55 fclose($handle); 56 57 //<<<<<<<<<<<<<<<<<<<<<<<<<<<for mass merge>>>>>>>>>>>>>>>>>>>>>>>>>>> 58 $mass_merge = $_REQUEST['idlist']; 59 $single_record = $_REQUEST['record']; 60 61 if($mass_merge != "") 62 { 63 $mass_merge = explode(";",$mass_merge); 64 $temp_mass_merge = $mass_merge; 65 if(array_pop($temp_mass_merge)=="") 66 array_pop($mass_merge); 67 $mass_merge = implode(",",$mass_merge); 68 }else if($single_record != "") 69 { 70 $mass_merge = $single_record; 71 }else 72 { 73 die("Record Id is not found, cannot merge the document"); 74 } 75 76 //echo $mass_merge; 77 //die; 78 //for setting vtiger_accountid=0 for the contacts which are deleted 79 $ct_query = "select crmid from vtiger_crmentity where setype='Contacts' and deleted=1"; 80 $result = $adb->query($ct_query); 81 82 while($row = $adb->fetch_array($result)) 83 { 84 $deleted_id[] = $row['crmid']; 85 } 86 87 if(count($deleted_id) > 0) 88 { 89 $deleted_id = implode(",",$deleted_id); 90 $update_query = "update vtiger_contactdetails set accountid = 0 where contactid in (".$deleted_id.")"; 91 $result = $adb->query($update_query); 92 } 93 //End setting vtiger_accountid=0 for the contacts which are deleted 94 95 //<<<<<<<<<<<<<<<<header for csv and select columns for query>>>>>>>>>>>>>>>>>>>>>>>> 96 $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"; 97 98 $result = $adb->query($query1); 99 $y=$adb->num_rows($result); 100 101 for ($x=0; $x<$y; $x++) 102 { 103 $tablename = $adb->query_result($result,$x,"tablename"); 104 $columnname = $adb->query_result($result,$x,"columnname"); 105 $modulename = $adb->query_result($result,$x,"name"); 106 107 if($tablename == "crmentity") 108 { 109 if($modulename == "Contacts") 110 { 111 $tablename = "vtiger_crmentityContacts"; 112 } 113 } 114 $querycolumns[$x] = $tablename.".".$columnname; 115 if($columnname == "smownerid") 116 { 117 if($modulename == "Accounts") 118 { 119 $querycolumns[$x] = "concat(vtiger_users.last_name,' ',vtiger_users.first_name) as userjoinname,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"; 120 } 121 if($modulename == "Contacts") 122 { 123 $querycolumns[$x] = "concat(vtiger_usersContacts.last_name,' ',vtiger_usersContacts.first_name) as userjoincname"; 124 } 125 } 126 if($columnname == "parentid") 127 { 128 $querycolumns[$x] = "vtiger_accountAccount.accountname"; 129 } 130 if($columnname == "accountid") 131 { 132 $querycolumns[$x] = "vtiger_accountContacts.accountname"; 133 } 134 if($columnname == "reportsto") 135 { 136 $querycolumns[$x] = "vtiger_contactdetailsContacts.lastname"; 137 } 138 139 if($modulename == "Accounts") 140 { 141 $field_label[$x] = "ACCOUNT_".strtoupper(str_replace(" ","",$adb->query_result($result,$x,"fieldlabel"))); 142 if($columnname == "smownerid") 143 { 144 $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"; 145 } 146 } 147 148 if($modulename == "Contacts") 149 { 150 $field_label[$x] = "CONTACT_".strtoupper(str_replace(" ","",$adb->query_result($result,$x,"fieldlabel"))); 151 } 152 153 } 154 155 $csvheader = implode(",",$field_label); 156 //<<<<<<<<<<<<<<<<End>>>>>>>>>>>>>>>>>>>>>>>> 157 158 if(count($querycolumns) > 0) 159 { 160 $selectcolumns = implode($querycolumns,","); 161 162 $query = "select ".$selectcolumns." from vtiger_account 163 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_account.accountid 164 inner join vtiger_accountbillads on vtiger_account.accountid=vtiger_accountbillads.accountaddressid 165 inner join vtiger_accountshipads on vtiger_account.accountid=vtiger_accountshipads.accountaddressid 166 inner join vtiger_accountscf on vtiger_account.accountid = vtiger_accountscf.accountid 167 left join vtiger_account as vtiger_accountAccount on vtiger_accountAccount.accountid = vtiger_account.parentid 168 left join vtiger_users on vtiger_users.id = vtiger_crmentity.smownerid 169 left join vtiger_contactdetails on vtiger_contactdetails.accountid=vtiger_account.accountid 170 left join vtiger_crmentity as vtiger_crmentityContacts on vtiger_crmentityContacts.crmid = vtiger_contactdetails.contactid 171 left join vtiger_contactaddress on vtiger_contactdetails.contactid = vtiger_contactaddress.contactaddressid 172 left join vtiger_contactsubdetails on vtiger_contactdetails.contactid = vtiger_contactsubdetails.contactsubscriptionid 173 left join vtiger_contactscf on vtiger_contactdetails.contactid = vtiger_contactscf.contactid 174 left join vtiger_contactdetails as vtiger_contactdetailsContacts on vtiger_contactdetailsContacts.contactid = vtiger_contactdetails.reportsto 175 left join vtiger_account as vtiger_accountContacts on vtiger_accountContacts.accountid = vtiger_contactdetails.accountid 176 left join vtiger_users as vtiger_usersContacts on vtiger_usersContacts.id = vtiger_crmentityContacts.smownerid 177 where vtiger_crmentity.deleted=0 and (vtiger_crmentityContacts.deleted=0 || vtiger_crmentityContacts.deleted is null) and vtiger_account.accountid in(".$mass_merge.")"; 178 //echo $query; 179 //die; 180 $result = $adb->query($query); 181 182 while($columnValues = $adb->fetch_array($result)) 183 { 184 $y=$adb->num_fields($result); 185 for($x=0; $x<$y; $x++) 186 { 187 $value = $columnValues[$x]; 188 //<<<<<<<<<<<<<<<for modifing default values>>>>>>>>>>>>>>>>>>>>>>>>>>>> 189 if($value == "0") 190 { 191 $value = ""; 192 } 193 if(trim($value) == "--None--" || trim($value) == "--none--") 194 { 195 $value = ""; 196 } 197 //<<<<<<<<<<<<<<<End>>>>>>>>>>>>>>>>>>>>>>>>>>>> 198 $actual_values[$x] = $value; 199 $actual_values[$x] = str_replace('"'," ",$actual_values[$x]); 200 //if value contains any line feed or carriage return replace the value with ".value." 201 if (preg_match ("/(\r\n)/", $actual_values[$x])) 202 { 203 $actual_values[$x] = '"'.$actual_values[$x].'"'; 204 } 205 $actual_values[$x] = str_replace(","," ",$actual_values[$x]); 206 } 207 $mergevalue[] = implode($actual_values,","); 208 } 209 $csvdata = implode($mergevalue,"###"); 210 }else 211 { 212 die("No fields to do Merge"); 213 } 214 215 $handle = fopen($wordtemplatedownloadpath."datasrc.csv","wb"); 216 fwrite($handle,$csvheader."\r\n"); 217 fwrite($handle,str_replace("###","\r\n",$csvdata)); 218 fclose($handle); 219 ?> 220 <script> 221 if (window.ActiveXObject){ 222 try 223 { 224 ovtigerVM = eval("new ActiveXObject('vtigerCRM.ActiveX');"); 225 if(ovtigerVM) 226 { 227 var filename = "<?php echo $filename?>"; 228 if(filename != "") 229 { 230 if(objMMPage.bDLTempDoc("<?php echo $site_URL;?>/test/wordtemplatedownload/<?php echo $filename; ?>","MMTemplate.doc")) 231 { 232 try 233 { 234 if(objMMPage.Init()) 235 { 236 objMMPage.vLTemplateDoc(); 237 objMMPage.bBulkHDSrc("<?php echo $site_URL;?>/test/wordtemplatedownload/datasrc.csv"); 238 objMMPage.vBulkOpenDoc(); 239 objMMPage.UnInit() 240 window.history.back(); 241 } 242 }catch(errorObject) 243 { 244 document.write("Error while processing mail merge operation"); 245 } 246 }else 247 { 248 document.write("Cannot get template document"); 249 } 250 } 251 } 252 } 253 catch(e) { 254 document.write("Requires to download ActiveX Control from vtigerCRM. Please, ensure that you have administration privilage"); 255 } 256 } 257 </script> 258 </body> 259 </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 |