| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Rev: 258 $ | $LastChangedBy: brieb $ |
|---|
| 4 | $LastChangedDate: 2007-08-08 21:59:28 -0600 (Wed, 08 Aug 2007) $ |
|---|
| 5 | +-------------------------------------------------------------------------+ |
|---|
| 6 | | Copyright (c) 2004 - 2010, Kreotek LLC | |
|---|
| 7 | | All rights reserved. | |
|---|
| 8 | +-------------------------------------------------------------------------+ |
|---|
| 9 | | | |
|---|
| 10 | | Redistribution and use in source and binary forms, with or without | |
|---|
| 11 | | modification, are permitted provided that the following conditions are | |
|---|
| 12 | | met: | |
|---|
| 13 | | | |
|---|
| 14 | | - Redistributions of source code must retain the above copyright | |
|---|
| 15 | | notice, this list of conditions and the following disclaimer. | |
|---|
| 16 | | | |
|---|
| 17 | | - Redistributions in binary form must reproduce the above copyright | |
|---|
| 18 | | notice, this list of conditions and the following disclaimer in the | |
|---|
| 19 | | documentation and/or other materials provided with the distribution. | |
|---|
| 20 | | | |
|---|
| 21 | | - Neither the name of Kreotek LLC nor the names of its contributore may | |
|---|
| 22 | | be used to endorse or promote products derived from this software | |
|---|
| 23 | | without specific prior written permission. | |
|---|
| 24 | | | |
|---|
| 25 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
|---|
| 26 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
|---|
| 27 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
|---|
| 28 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
|---|
| 29 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
|---|
| 30 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
|---|
| 31 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
|---|
| 32 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
|---|
| 33 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
|---|
| 34 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
|---|
| 35 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
|---|
| 36 | | | |
|---|
| 37 | +-------------------------------------------------------------------------+ |
|---|
| 38 | */ |
|---|
| 39 | |
|---|
| 40 | include("../../include/session.php"); |
|---|
| 41 | include("include/tables.php"); |
|---|
| 42 | include("include/fields.php"); |
|---|
| 43 | include("include/imports.php"); |
|---|
| 44 | include("include/parsecsv.lib.php"); |
|---|
| 45 | |
|---|
| 46 | //if you need to overide the phpbmsTable class make sure to include the modules file |
|---|
| 47 | |
|---|
| 48 | include("modules/bms/include/clients.php"); |
|---|
| 49 | include("modules/bms/include/addresses.php"); |
|---|
| 50 | include("modules/bms/include/addresstorecord.php"); |
|---|
| 51 | |
|---|
| 52 | //If the addedit page will be accessd directly from a page other than the |
|---|
| 53 | // basic search results page, you may want to grab and pass the previous URL |
|---|
| 54 | //with the following code |
|---|
| 55 | |
|---|
| 56 | //=================================================== |
|---|
| 57 | if(!isset($_GET["backurl"])) |
|---|
| 58 | $backurl = NULL; |
|---|
| 59 | else{ |
|---|
| 60 | $backurl = $_GET["backurl"]; |
|---|
| 61 | if(isset($_GET["refid"])) |
|---|
| 62 | $backurl .= "?refid=".$_GET["refid"]; |
|---|
| 63 | } |
|---|
| 64 | //=================================================== |
|---|
| 65 | |
|---|
| 66 | if(isset($_GET["id"])) |
|---|
| 67 | $tabledefid = ((int)$_GET["id"]); |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | //Here you invoke the table and import classes. If you are going to use the standard phpbmsTable class |
|---|
| 71 | // for updates and the such you would access it like this |
|---|
| 72 | |
|---|
| 73 | //$thetable = new phpbmsTable($db,$tabledefid); |
|---|
| 74 | //$import = new phpbmsImport($thetable); |
|---|
| 75 | |
|---|
| 76 | //if you are going to overide the class you would instantiate |
|---|
| 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 |
|---|
| 95 | |
|---|
| 96 | $thetable = new clients($db,"tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083",$backurl); |
|---|
| 97 | $import = new clientsImport($thetable, $importType); |
|---|
| 98 | |
|---|
| 99 | //Next we process the form (if submitted) and |
|---|
| 100 | // return the current record as an array ($therecord) |
|---|
| 101 | // or if this is a new record, it returns the defaults |
|---|
| 102 | $therecord = $import->processImportPage(); |
|---|
| 103 | |
|---|
| 104 | //make sure that we set the status message id the processing returned one |
|---|
| 105 | // (e.g. "Record Updated") |
|---|
| 106 | if(isset($therecord["phpbmsStatus"])) |
|---|
| 107 | $statusmessage = $therecord["phpbmsStatus"]; |
|---|
| 108 | |
|---|
| 109 | $pageTitle = ($therecord["title"])?$therecord["title"]:"General Table Import"; |
|---|
| 110 | |
|---|
| 111 | $phpbms->cssIncludes[] = "pages/imports.css"; |
|---|
| 112 | $phpbms->jsIncludes[] = "modules/bms/javascript/clients_import.js"; |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | // We need to define them here in the head |
|---|
| 116 | // so that any necessay javascript is loaded appropriately. |
|---|
| 117 | |
|---|
| 118 | //Form Elements |
|---|
| 119 | //============================================================== |
|---|
| 120 | |
|---|
| 121 | // Create the form |
|---|
| 122 | $theform = new importForm(); |
|---|
| 123 | $theform->enctype = "multipart/form-data"; |
|---|
| 124 | //if you need to set specific form vaiables (like enctype, or extra onsubmit |
|---|
| 125 | // you can set those form properties here. |
|---|
| 126 | |
|---|
| 127 | // for each field we will use, create the field object and add it to |
|---|
| 128 | // the forms list. |
|---|
| 129 | |
|---|
| 130 | $list = array("phpBMS csv file" => 0, "Sugar CRM (v5.5.0)" => 1); |
|---|
| 131 | $default = 0; |
|---|
| 132 | if(isset($_POST["importType"])) |
|---|
| 133 | $default = ((int) $_POST["importType"]); |
|---|
| 134 | $theinput = new inputBasicList("importType", $default, $list, "File Type"); |
|---|
| 135 | $theform->addField($theinput); |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | // lastly, use the jsMerge method to create the final Javascript formatting |
|---|
| 139 | $theform->jsMerge(); |
|---|
| 140 | //============================================================== |
|---|
| 141 | //End Form Elements |
|---|
| 142 | |
|---|
| 143 | include("header.php"); |
|---|
| 144 | |
|---|
| 145 | ?><div class="bodyline"> |
|---|
| 146 | <!-- |
|---|
| 147 | Next we start the form. This also prints the H1 with title, and top save,cancel buttons |
|---|
| 148 | If you need to have other buttons, or need a specific top, you will need to create your form manually. |
|---|
| 149 | --> |
|---|
| 150 | <?php $theform->startForm($pageTitle, $import->pageType, count($import->transactionRecords))?> |
|---|
| 151 | |
|---|
| 152 | <div id="leftSideDiv"> |
|---|
| 153 | <!-- /* This next input is to store the temporary mysql table used for the confirmation insert */ --> |
|---|
| 154 | <input id="tempFileID" name="tempFileID" type="hidden" value="<?php echo $import->tempFileID?>" /> |
|---|
| 155 | <!-- /* This next input is to determine the action of the cancel button (i.e. whether to redirect to backurl or not)*/ --> |
|---|
| 156 | <!-- /* This next input also determines whether the file/import fieldset will be displayed or if the preview sections will be displayed*/ --> |
|---|
| 157 | <input id="pageType" name="pageType" type="hidden" value="<?php echo $import->pageType?>" /> |
|---|
| 158 | |
|---|
| 159 | <?php |
|---|
| 160 | if($import->pageType == "main"){ ?> |
|---|
| 161 | <fieldset> |
|---|
| 162 | <legend>import</legend> |
|---|
| 163 | |
|---|
| 164 | <p><?php $theform->showField("importType"); ?></p> |
|---|
| 165 | |
|---|
| 166 | <div id="uploadlabel"> |
|---|
| 167 | <p> |
|---|
| 168 | <label for="import">file</label><br /> |
|---|
| 169 | <input id="import" name="import" type="file" size="64"/><br/> |
|---|
| 170 | </p> |
|---|
| 171 | |
|---|
| 172 | <div id="info0" class="info"> |
|---|
| 173 | <p> |
|---|
| 174 | For any file that is a comma seperated value (csv) file: |
|---|
| 175 | </p> |
|---|
| 176 | <p> |
|---|
| 177 | Delimiters 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",...), or with |
|---|
| 180 | a backslash character (\) (e.g ...,"Benny \"The Jet\" Rodriguez",...). |
|---|
| 181 | </p> |
|---|
| 182 | <p> |
|---|
| 183 | The first row of your csv file should be the field-names of the table(s) |
|---|
| 184 | that you wish to import to. Additional lines will be the actual data |
|---|
| 185 | that will be imported. |
|---|
| 186 | </p> |
|---|
| 187 | <p> |
|---|
| 188 | When entering in currency, dates, or times use the format in the bms's configuration |
|---|
| 189 | (e.g. use English, US style dates if that is what the bms is configured to). |
|---|
| 190 | </p> |
|---|
| 191 | </div> |
|---|
| 192 | <div id="info1" class="info" style="display:none;"> |
|---|
| 193 | <p> |
|---|
| 194 | For any file that is a comma seperated value (csv) file: |
|---|
| 195 | </p> |
|---|
| 196 | <p> |
|---|
| 197 | Delimiters are commas (,) and enclosures are double-quotes ("). <span class="notes" >(This |
|---|
| 198 | is done by default by Sugar CRM)</span> If you wish to escape a double-quote character |
|---|
| 199 | inside of an enclosure, add another double-quote character (e.g ...,"Benny |
|---|
| 200 | ""The Jet"" Rodriguez",...). |
|---|
| 201 | </p> |
|---|
| 202 | <p> |
|---|
| 203 | The first row of your csv file should be the field-names of the table(s) |
|---|
| 204 | that you wish to import to. Additional lines will be the actual data |
|---|
| 205 | that will be imported. <span class="notes" >(Again, this is done by default by Sugar CRM)</span> |
|---|
| 206 | </p> |
|---|
| 207 | <p> |
|---|
| 208 | When entering in currency, dates, or times use the format in the bms's configuration |
|---|
| 209 | (e.g. use English, US style dates if that is what the bms is configured to). |
|---|
| 210 | </p> |
|---|
| 211 | </div> |
|---|
| 212 | </div> |
|---|
| 213 | |
|---|
| 214 | </fieldset> |
|---|
| 215 | <?php |
|---|
| 216 | }else{ |
|---|
| 217 | ?> |
|---|
| 218 | <!-- This input is to be able to keep the importType the same for both the initial upload and the final upload --> |
|---|
| 219 | <input id="importType" name="importType" type="hidden" value="<?php echo (isset($_POST["importType"]))?($_POST["importType"]):('0'); ?>" /> |
|---|
| 220 | <?php |
|---|
| 221 | }//end if |
|---|
| 222 | |
|---|
| 223 | if($import->error && $import->pageType != "main"){ |
|---|
| 224 | ?> |
|---|
| 225 | <h2>Import Errors</h2> |
|---|
| 226 | <div id="importError"> |
|---|
| 227 | <ul> |
|---|
| 228 | <?php echo $import->error ?> |
|---|
| 229 | </ul> |
|---|
| 230 | </div> |
|---|
| 231 | <?php |
|---|
| 232 | }//end if |
|---|
| 233 | $import->displayTransaction($import->transactionRecords,$import->table->fields); |
|---|
| 234 | ?> |
|---|
| 235 | </div> |
|---|
| 236 | <div id="createmodifiedby" > |
|---|
| 237 | <?php |
|---|
| 238 | //Last, we show the create/modifiy with the bottom save and cancel buttons |
|---|
| 239 | // and then close the form. |
|---|
| 240 | $theform->showButtons(2, $import->pageType, count($import->transactionRecords)); |
|---|
| 241 | ?></div><?php |
|---|
| 242 | $theform->endForm(); |
|---|
| 243 | ?> |
|---|
| 244 | </div> |
|---|
| 245 | <?php include("footer.php");?> |
|---|