Changeset 431
- Timestamp:
- 08/15/08 13:00:46
- Files:
-
- trunk/phpbms/include/imports.php (modified) (2 diffs)
- trunk/phpbms/modules/base/general_import.php (modified) (1 diff)
- trunk/phpbms/modules/base/users_import.php (modified) (1 diff)
- trunk/phpbms/modules/bms/clients_import.php (modified) (4 diffs)
- trunk/phpbms/modules/bms/include/clients.php (modified) (5 diffs)
- trunk/phpbms/modules/bms/javascript/clients_import.js (added)
- trunk/phpbms/modules/bms/products_import.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phpbms/include/imports.php
r427 r431 67 67 }//end swtich 68 68 69 }//end method --_parseFromFile-- 69 }//end method --_parseFromFile-- 70 70 71 71 … … 297 297 foreach($fieldsArray as $field => $junk){ 298 298 ?><td nowrap="nowrap"><?php 299 echo $record[$field];299 echo formatVariable($record[$field]); 300 300 ?></td><?php 301 301 }//end foreach trunk/phpbms/modules/base/general_import.php
r427 r431 170 170 <legend>import</legend> 171 171 172 <p id="uploadlabel"> 173 <label for="import">file</label><br /> 174 <input id="import" name="import" type="file" size="64"/><br/> 175 The file that you upload should be a comma seperated value (csv) file. 176 Delimeters are commas (,) and enclosures are double-quotes ("). If you 177 wish to escape a double-quote character inside of an enclosure, add another 178 double-quote character (e.g ...,"Benny ""The Jet"" Rodriguez",...).<br/> 179 <br/> 180 The first row of your csv file should be the field-names of the table(s) 181 that you wish to import to. Additional lines will be the actual data 182 that will be imported.<br/> 183 <br/> 184 When entering in currency, dates, or times use the format in the bms's configuration 185 (e.g. use English, US style dates if that is what the bms is configured to). 186 </p> 172 <div id="uploadlabel"> 173 <p> 174 <label for="import">file</label><br /> 175 <input id="import" name="import" type="file" size="64"/><br/> 176 </p> 177 178 <div id="info0" class="info"> 179 <p> 180 For any file that is a comma seperated value (csv) file: 181 </p> 182 <p> 183 Delimeters are commas (,) and enclosures are double-quotes ("). If you 184 wish to escape a double-quote character inside of an enclosure, add another 185 double-quote character (e.g ...,"Benny ""The Jet"" Rodriguez",...). 186 </p> 187 <p> 188 The first row of your csv file should be the field-names of the table(s) 189 that you wish to import to. Additional lines will be the actual data 190 that will be imported. 191 </p> 192 <p> 193 When entering in currency, dates, or times use the format in the bms's configuration 194 (e.g. use English, US style dates if that is what the bms is configured to). 195 </p> 196 </div> 197 </div> 187 198 188 199 </fieldset> trunk/phpbms/modules/base/users_import.php
r427 r431 169 169 <legend>import</legend> 170 170 171 <p id="uploadlabel"> 172 <label for="import">file</label><br /> 173 <input id="import" name="import" type="file" size="64"/><br/> 174 The file that you upload should be a comma seperated value (csv) file. 175 Delimeters are commas (,) and enclosures are double-quotes ("). If you 176 wish to escape a double-quote character inside of an enclosure, add another 177 double-quote character (e.g ...,"Benny ""The Jet"" Rodriguez",...).<br/> 178 <br/> 179 The first row of your csv file should be the field-names of the table(s) 180 that you wish to import to. Additional lines will be the actual data 181 that will be imported.<br/> 182 <br/> 183 When entering in currency, dates, or times use the format in the bms's configuration 184 (e.g. use English, US style dates if that is what the bms is configured to).<br/> 185 <br/> 186 <span class="notes"> 187 Users' roles should be set manually, and cannot be imported on this page. 188 </span> 189 </p> 171 <div id="uploadlabel"> 172 <p> 173 <label for="import">file</label><br /> 174 <input id="import" name="import" type="file" size="64"/><br/> 175 </p> 176 177 <div id="info0" class="info"> 178 <p> 179 For any file that is a comma seperated value (csv) file: 180 </p> 181 <p> 182 Delimeters are commas (,) and enclosures are double-quotes ("). If you 183 wish to escape a double-quote character inside of an enclosure, add another 184 double-quote character (e.g ...,"Benny ""The Jet"" Rodriguez",...). 185 </p> 186 <p> 187 The first row of your csv file should be the field-names of the table(s) 188 that you wish to import to. Additional lines will be the actual data 189 that will be imported. 190 </p> 191 <p> 192 When entering in currency, dates, or times use the format in the bms's configuration 193 (e.g. use English, US style dates if that is what the bms is configured to). 194 </p> 195 <p class="notes"> 196 Users' roles should be set manually, and cannot be imported on this page. 197 </p> 198 </div> 199 </div> 190 200 191 201 </fieldset> trunk/phpbms/modules/bms/clients_import.php
r427 r431 76 76 //if you are going to overide the class you would instantiate 77 77 // like this 78 79 $importType = "csv"; 80 if(isset($_POST["importType"])){ 81 82 switch($_POST["importType"]){ 83 84 case 0: 85 $importType = "csv"; 86 break; 87 88 case 1: 89 $importType = "sugarcrm"; 90 break; 91 92 }//end switch 93 94 }//end if 78 95 79 96 $thetable = new clients($db,2,$backurl); 80 $import = new clientsImport($thetable );97 $import = new clientsImport($thetable, $importType); 81 98 82 99 //and if you are setting the backurl, make sure you pass that as well … … 104 121 // will be using below. 105 122 $phpbms->cssIncludes[] = "pages/imports.css"; 106 //$phpbms->jsIncludes[] = "modules/[modulename]/javascript/[tablename].js";123 $phpbms->jsIncludes[] = "modules/bms/javascript/clients_import.js"; 107 124 108 125 // if you need to define a body onlload function, do so with the phpbms property … … 129 146 // for each field we will use, create the field object and add it to 130 147 // the forms list. 131 //$theinput = new inputDatePicker("orderdate", $therecord["orderdate"], "order date"); 132 //$theform->addField($theinput); 133 // 134 //$theinput = new inputCheckBox("weborder",$therecord["weborder"],NULL, false, false); 135 //$theform->addField($theinput); 136 // 137 //$theinput = new inputField("accountnumber",$therecord["accountnumber"], "account number" ,false, "integer", 20, 64); 138 //$theform->addField($theinput); 139 148 149 $list = array("phpBMS csv file" => 0, "Sugar CRM (v5.0)" => 1); 150 $default = 0; 151 if(isset($_POST["importType"])) 152 $default = ((int) $_POST["importType"]); 153 $theinput = new inputBasicList("importType", $default, $list, "File Type"); 154 $theform->addField($theinput); 140 155 141 156 // if you neeed to add additional attributes toa field, it's easy. … … 168 183 <?php 169 184 if($import->pageType == "main"){ ?> 170 <fieldset >185 <fieldset> 171 186 <legend>import</legend> 172 173 <p id="uploadlabel"> 174 <label for="import">file</label><br /> 175 <input id="import" name="import" type="file" size="64"/><br/> 176 The file that you upload should be a comma seperated value (csv) file. 177 Delimeters are commas (,) and enclosures are double-quotes ("). If you 178 wish to escape a double-quote character inside of an enclosure, add another 179 double-quote character (e.g ...,"Benny ""The Jet"" Rodriguez",...).<br/> 180 <br/> 181 The first row of your csv file should be the field-names of the table(s) 182 that you wish to import to. Additional lines will be the actual data 183 that will be imported.<br/> 184 <br/> 185 When entering in currency, dates, or times use the format in the bms's configuration 186 (e.g. use English, US style dates if that is what the bms is configured to). 187 </p> 187 188 <p><?php $theform->showField("importType"); ?></p> 189 190 <div id="uploadlabel"> 191 <p> 192 <label for="import">file</label><br /> 193 <input id="import" name="import" type="file" size="64"/><br/> 194 </p> 195 196 <div id="info0" class="info"> 197 <p> 198 For any file that is a comma seperated value (csv) file: 199 </p> 200 <p> 201 Delimeters are commas (,) and enclosures are double-quotes ("). If you 202 wish to escape a double-quote character inside of an enclosure, add another 203 double-quote character (e.g ...,"Benny ""The Jet"" Rodriguez",...). 204 </p> 205 <p> 206 The first row of your csv file should be the field-names of the table(s) 207 that you wish to import to. Additional lines will be the actual data 208 that will be imported. 209 </p> 210 <p> 211 When entering in currency, dates, or times use the format in the bms's configuration 212 (e.g. use English, US style dates if that is what the bms is configured to). 213 </p> 214 </div> 215 <div id="info1" class="info" style="display:none;"> 216 <p> 217 For any file that is a comma seperated value (csv) file: 218 </p> 219 <p> 220 Delimeters are commas (,) and enclosures are double-quotes ("). <span class="notes" >(This 221 is done by default by Sugar CRM)</span> If you wish to escape a double-quote character 222 inside of an enclosure, add another double-quote character (e.g ...,"Benny 223 ""The Jet"" Rodriguez",...). 224 </p> 225 <p> 226 The first row of your csv file should be the field-names of the table(s) 227 that you wish to import to. Additional lines will be the actual data 228 that will be imported. <span class="notes" >(Again, this is done by default by Sugar CRM)</span> 229 </p> 230 <p> 231 When entering in currency, dates, or times use the format in the bms's configuration 232 (e.g. use English, US style dates if that is what the bms is configured to). 233 </p> 234 </div> 235 </div> 188 236 189 237 </fieldset> 238 <?php 239 }else{ 240 ?> 241 <!-- This input is to be able to keep the importType the same for both the initial upload and the final upload --> 242 <input id="importType" name="importType" type="hidden" value="<?php echo (isset($_POST["importType"]))?($_POST["importType"]):('0'); ?>" /> 190 243 <?php 191 244 }//end if trunk/phpbms/modules/bms/include/clients.php
r427 r431 434 434 class clientsImport extends phpbmsImport{ 435 435 436 function clientsImport($table){ 437 438 parent::phpbmsImport($table); 436 437 function clientsImport($table, $importType = "csv"){ 438 439 if($importType == "sugarcrm"){ 440 441 $importType = "csv"; 442 $switchedFrom = "sugarcrm"; 443 444 }//end if 445 446 parent::phpbmsImport($table, $importType); 447 448 if(isset($switchedFrom)) 449 $this->importType = $switchedFrom; 439 450 440 451 }//end method --clientsImport-- 452 453 454 function _parseFromData($data){ 455 456 if($this->importType == "sugarcrm"){ 457 458 $this->importType = "csv"; 459 $switchedFrom = "sugarcrm"; 460 461 }//end if 462 463 $thereturn = parent::_parseFromData($data); 464 465 if(isset($switchedFrom)) 466 $this->importType = $switchedFrom; 467 468 return $thereturn; 469 470 }//end method --_parseFromFile-- 471 472 473 function _formatSugarVariables($rows, $titles){ 474 475 //Replace the titles with valid ones 476 //(At the moment we only really need 477 //the correct count, but, it seems 478 //logical to correct the titles in case 479 //they are needed in the future) 480 $newTitles = array(); 481 foreach($titles as $index => $name){ 482 483 switch($name){ 484 485 case "name": 486 $newTitles[] = "company"; 487 break; 488 489 case "date_entered": 490 $newTitles[] = "becameclient"; 491 break; 492 493 case "description": 494 $newTitles[] = "comments"; 495 break; 496 497 case "deleted": 498 $newTitles[] = "inactive"; 499 break; 500 501 case "account_type": 502 $newTitles[] = "type"; 503 break; 504 505 case "industry": 506 $newTitles[] = "category"; 507 break; 508 509 case "phone_fax": 510 $newTitles[] = "fax"; 511 break; 512 513 case "billing_address_street": 514 $newTitles[] = "address1"; 515 break; 516 517 case "billing_address_city": 518 $newTitles[] = "city"; 519 break; 520 521 case "billing_address_state": 522 $newTitles[] = "state"; 523 break; 524 525 case "billing_address_postalcode": 526 $newTitles[] = "postalcode"; 527 break; 528 529 case "billing_address_country": 530 $newTitles[] = "country"; 531 break; 532 533 case "phone_office": 534 $newTitles[] = "workphone"; 535 break; 536 537 case "phone_alternate": 538 $newTitles[] = "otherphone"; 539 break; 540 541 case "website": 542 $newTitles[] = "webaddress"; 543 break; 544 545 case "shipping_address_street": 546 $newTitles[] = "shipaddress1"; 547 break; 548 549 case "shipping_address_city": 550 $newTitles[] = "shipcity"; 551 break; 552 553 case "shipping_address_state": 554 $newTitles[] = "shipstate"; 555 break; 556 557 case "shipping_address_postalcode": 558 $newTitles[] = "shippostalcode"; 559 break; 560 561 case "shipping_address_country": 562 $newTitles[] = "shipcountry"; 563 break; 564 565 }//end switch 566 567 }//end foreach 568 569 570 $newRows = array(); 571 foreach($rows as $rowData){ 572 573 $newRowData = array(); 574 $addComments = ""; 575 foreach($rowData as $name => $data){ 576 577 switch($name){ 578 579 case "name": 580 $newRowData["company"] = trim($data); 581 break; 582 583 case "date_entered": 584 $newRowData["becameclient"] = trim($data); 585 break; 586 587 case "description": 588 $newRowData["comments"] = trim($data); 589 break; 590 591 case "deleted": 592 $newRowData["inactive"] = trim($data); 593 break; 594 595 case "industry": 596 $newRowData["category"] = trim($data); 597 break; 598 599 case "account_type": 600 $newRowData["type"] = trim($data); 601 break; 602 603 case "phone_fax": 604 $newRowData["fax"] = trim($data); 605 break; 606 607 case "billing_address_street": 608 $newRowData["address1"] = trim($data); 609 break; 610 611 case "billing_address_city": 612 $newRowData["city"] = trim($data); 613 break; 614 615 case "billing_address_state": 616 $newRowData["state"] = trim($data); 617 break; 618 619 case "billing_address_postalcode": 620 $newRowData["postalcode"] = trim($data); 621 break; 622 623 case "billing_address_country": 624 $newRowData["country"] = trim($data); 625 break; 626 627 case "phone_office": 628 $newRowData["workphone"] = trim($data); 629 break; 630 631 case "phone_alternate": 632 $newRowData["otherphone"] = trim($data); 633 break; 634 635 case "website": 636 $newRowData["webaddress"] = trim($data); 637 break; 638 639 case "shipping_address_street": 640 $newRowData["shipaddress1"] = trim($data); 641 break; 642 643 case "shipping_address_city": 644 $newRowData["shipcity"] = trim($data); 645 break; 646 647 case "shipping_address_state": 648 $newRowData["shipstate"] = trim($data); 649 break; 650 651 case "shipping_address_postalcode": 652 $newRowData["shippostalcode"] = trim($data); 653 break; 654 655 case "shipping_address_country": 656 $newRowData["shipcountry"] = trim($data); 657 break; 658 659 case "annual_revenue": 660 case "rating": 661 case "ownership": 662 case "employees": 663 case "ticker_symbol": 664 if($data) 665 $addComments .= "\n".str_replace("_"," ",$name).": ".trim($data); 666 break; 667 668 }//end switch 669 670 }//end foreach 671 672 if($newRowData["type"] == "prospect") 673 $newRowData["becameclient"] = NULL; 674 675 $newRowData["comments"] .= $addComments; 676 $newRows[] = $newRowData; 677 678 }//end foreach 679 680 $thereturn["rows"] = $newRows; 681 $thereturn["titles"] = $newTitles; 682 return $thereturn; 683 684 }//end method --_formatSugarvariables-- 685 686 687 function importRecords($rows, $titles){ 688 689 switch($this->importType){ 690 691 case "sugarcrm": 692 $thereturn = $this->_formatSugarVariables($rows, $titles); 693 $rows = $thereturn["rows"]; 694 $titles = $thereturn["titles"]; 695 696 case "csv": 697 //count total fieldnames (top row of csv document) 698 $fieldNum = count($titles); 699 700 //the file starts at line number 1, but since line 1 is 701 //supposed to be the fieldnames in the table(s), the lines 702 //being insereted start @ 2. 703 $rowNum = 2; 704 705 //get the data one row at a time 706 foreach($rows as $rowData){ 707 708 $theid = 0; 709 710 //trim off leading/trailing spaces 711 $trimmedRowData = array();&