annamaria-daneswood-25102012 /administrator/components/com_virtuemart/classes/export/ps_olsi.php

Language PHP Lines 414
MD5 Hash 8bb3c7d7b8ea0d3a39ef7928d5952d2d Estimated Cost $6,170 (why?)
Repository https://bitbucket.org/dgough/annamaria-daneswood-25102012.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
*
* @version $Id: ps_olsi.php 1095 2007-12-19 20:19:16Z soeren_nb $
* @package VirtueMart
* @subpackage export
* @copyright Copyright (C) 2004-2007 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/


/**
*
* The ps_xmlexport class, containing the default export processing code
* for export methods that have no own class
*
*/
require_once( $mosConfig_absolute_path. '/includes/domit/xml_domit_include.php' );
require_once( $mosConfig_absolute_path. '/includes/domit/xml_domit_utilities.php');

class ps_olsi {

	var $classname = 'ps_olsi';
	var $xmldoc = null;

	/**
    * Show all configuration parameters for this export method
    * @returns boolean False when the export method has no configration
    */
	function show_configuration() {
		global $VM_LANG;
		$db = new ps_DB();

		/** Read current Configuration ***/
		include_once(CLASSPATH ."export/".$this->classname.".cfg.php");
    ?>
    <table class="adminform">
        <!--tr class="row0">
        <td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_AUTORIZENET_TESTMODE') ?></strong></td>
            <td>
                <select name="PAYPAL_DEBUG" class="inputbox" >
                <option <?php if (@PAYPAL_DEBUG == '1') echo "selected=\"selected\""; ?> value="1"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES') ?></option>
                <option <?php if (@PAYPAL_DEBUG != '1') echo "selected=\"selected\""; ?> value="0"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO') ?></option>
                </select>
            </td>
            <td>
            <?php
    printf( $VM_LANG->_('VM_ADMIN_CFG_PAYPAL_NOTIFYSCRIPT_TIP'), '<pre>'. COMPONENTURL."notify.php</pre>" );
			?>            
            </td>
        </tr-->
        <tr class="row1">
        <td><strong>Shipping module mapping</strong></td>
            <td>
                <input type="text" name="SHIPPINGMODULEMAP" class="inputbox" value="<?  echo SHIPPINGMODULEMAP ?>" />
            </td>
            <td>
            </td>
        </tr>
        <tr class="row0">
            <td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYPAL_STATUS_SUCCESS') ?></strong></td>
            <td>
                <select name="PAYPAL_VERIFIED_STATUS" class="inputbox" >
                <?php
                $q = "SELECT order_status_name,order_status_code FROM #__{vm}_order_status ORDER BY list_order";
                $db->query($q);
                $order_status_code = Array();
                $order_status_name = Array();

                while ($db->next_record()) {
                	$order_status_code[] = $db->f("order_status_code");
                	$order_status_name[] =  $db->f("order_status_name");
                }
                for ($i = 0; $i < sizeof($order_status_code); $i++) {
                	echo "<option value=\"" . $order_status_code[$i];
                	if (PAYPAL_VERIFIED_STATUS == $order_status_code[$i])
                	echo "\" selected=\"selected\">";
                	else
                	echo "\">";
                	echo $order_status_name[$i] . "</option>\n";
                    }?>
                    </select>
            </td>
            <td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYPAL_STATUS_SUCCESS_EXPLAIN') ?>
            </td>
        </tr>
        <tr class="row1">
            <td><strong><?php echo $VM_LANG->_('VM_ADMIN_CFG_PAYPAL_STATUS_PENDING') ?></strong></td>
            <td>
                <select name="PAYPAL_PENDING_STATUS" class="inputbox" >
                <?php
                for ($i = 0; $i < sizeof($order_status_code); $i++) {
                	echo "<option value=\"" . $order_status_code[$i];
                	if (PAYPAL_PENDING_STATUS == $order_status_code[$i])
                	echo "\" selected=\"selected\">";
                	else
                	echo "\">";
                	echo $order_status_name[$i] . "</option>\n";
                    } ?>
                    </select>
            </td>
            <td><?php echo $VM_LANG->_('VM_ADMIN_CFG_PAYPAL_STATUS_PENDING_EXPLAIN') ?></td>
        </tr>
        <tr class="row0">
            <td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYPAL_STATUS_FAILED') ?></strong></td>
            <td>
                <select name="PAYPAL_INVALID_STATUS" class="inputbox" >
                <?php
                for ($i = 0; $i < sizeof($order_status_code); $i++) {
                	echo "<option value=\"" . $order_status_code[$i];
                	if (PAYPAL_INVALID_STATUS == $order_status_code[$i])
                	echo "\" selected=\"selected\">";
                	else
                	echo "\">";
                	echo $order_status_name[$i] . "</option>\n";
                    } ?>
                    </select>
            </td>
            <td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYPAL_STATUS_FAILED_EXPLAIN') ?>
            </td>
        </tr>
      </table>
    <?php
	}

	function has_configuration() {
		// return false if there's no configuration
		return true;
	}

	/**
	* Returns the "is_writeable" status of the configuration file
	* @param void
	* @returns boolean True when the configuration file is writeable, false when not
	*/
	function configfile_writeable() {
		return is_writeable( CLASSPATH."export/".$this->classname.".cfg.php" );
	}

	/**
	* Returns the "is_readable" status of the configuration file
	* @param void
	* @returns boolean True when the configuration file is writeable, false when not
	*/
	function configfile_readable() {
		return is_readable( CLASSPATH."export/".$this->classname.".cfg.php" );
	}

	/**
	* Writes the configuration file for this payment method
	* @param array An array of objects
	* @return boolean True when writing was successful
	*/
	function write_configuration( &$d ) {
		/* ... */
		return true;
	}
	
	/**
	 * Load default configuration for module into form-fields
	 *
	 *
	 * @param array $d
	 * @return array
	 */
	function process_installation ($d = array()) {
		echo 'yes!';
		if (!$d['export_name']) {
			$d['export_name'] = "SAGE Office Line Connector";
		}
		
		if (!$d['export_desc']) {
			$d['export_desc'] = 'Export Module for Sage Office Line, requires Office Line Shop Interface from <a href="http://www.1st-vision.de">1st Vision</a>.';
		}		
		return $d;
	}
	
	/**
	 * Process authentication method
	 *
	 * @return boolean Authentication success or error
	 */
	function process_authentication () {
		global $database, $acl;
		$usrname 	= $database->getEscaped( vmGet( $_REQUEST, 'user', '' ) );
		$pass 		= $database->getEscaped( vmGet( $_REQUEST, 'password', '' ) );

		if (!$usrname) {
			echo 'Please enter a username';
			return false;
		}

		if (!$pass) {
			echo 'Please enter a password';
			return false;
		} else {
			$pass = md5( $pass );
		}


		$query = "SELECT COUNT(*)"
		. "\n FROM #__users"
		. "\n WHERE ("
		// Administrators
		. "\n gid = 24"
		// Super Administrators
		. "\n OR gid = 25"
		. "\n )"
		;
		$database->setQuery( $query );
		$count = intval( $database->loadResult() );
		if ($count < 1) {
			echo _LOGIN_NOADMINS;
			return false;
		}

		$my = null;
		$query = "SELECT *"
		. "\n FROM #__users"
		. "\n WHERE username = '$usrname'"
		. "\n AND block = 0"
		;
		$database->setQuery( $query );
		$database->loadObject( $my );

		/** find the user group (or groups in the future) */
		if (@$my->id) {
			$grp 			= $acl->getAroGroup( $my->id );
			$my->gid 		= $grp->group_id;
			$my->usertype 	= $grp->name;

			if ( strcmp( $my->password, $pass ) || !$acl->acl_check( 'administration', 'login', 'users', $my->usertype ) ) {
				echo "Incorrect Username, Password, or Access Level.";
				return false;
			}
		} else {
			echo "Incorrect Username, Password.  Please try again";
			return false;
		}
		return true;
	}

	/**
  * process export
  * @name process_export
  * @param Filterstatement to select orders
  * @param db-object
  * @return bool true/false
  */
	function process_export(&$db) {
		global $mosConfig_absolute_path, $database;
		$xmldoc = new DOMIT_Document();
		$xmldoc->appendEntityTranslationTable(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES)); //damit sollte htmlspecialchars nicht mehr notwendig sein
		$xmldoc->expandEmptyElementTags(false);
		$xmldoc->appendChild($xmldoc->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"IS0-8859-1\""));
		$xmldoc->setDocumentElement($xmldoc->createElement('OLOrders'));
		$xmldoc->documentElement->appendChild($xmldoc->createElement('Version1.1'));


		
		$order_status = vmGet( $_REQUEST, 'status', '' );
		$order_from = vmGet( $_REQUEST, 'from', '' );
		$order_since = vmGet( $_REQUEST, 'since', '' );
		$order_since = vmGet( $_REQUEST, 'since', '' );
		$order_to = vmGet( $_REQUEST, 'to', '' );
		$order_id = vmGet( $_REQUEST, 'order_id', '' );

		$where = array();
		if (!$order_status && !$order_from && !$order_since && !$order_to && !$order_id){
			$order_status = 'P';
		}
		if ($order_status) {
			$where[] = "order_status = '" . $db->getEscaped( $order_status ) . "'";
		}
		if($order_from) {
			$where[] = "order_id >= '" . $db->getEscaped($order_from) . "'";
		} elseif ($order_since) {
			$where[] = "order_id > '" . $db->getEscaped($order_since) . "'";
		} elseif ($order_id) {
			$where[] = "order_id = '" . $db->getEscaped($order_id) . "'";
		}

		if($order_to && !$order_id) {
			$where[] = "order_id <= '" . $db->getEscaped($order_to) . "'";
		}
		
		//select the orders to export
		$q = 'SELECT * FROM #__{vm}_orders WHERE vendor_id=\'' . $db->f('vendor_id') . '\' AND ';
		$q .= implode($where);
		$db->setQuery($q);
		$orders = $db->loadAssocList();

		for($i=0; $i < count($orders); $i++ ) {
			//get billing and shipping address
			$q = "SELECT * FROM #__{vm}_order_user_info WHERE order_id='". $orders[$i]['order_id'] ."'";
			$db->setQuery($q);
			$orders[$i]['user_info'] = $db->loadAssocList();
			//get shipping address
			$q = "SELECT * FROM #__{vm}_order_item WHERE order_id='". $orders[$i]['order_id'] ."'";
			$db->setQuery($q);
			$orders[$i]['item'] = $db->loadAssocList();
			//get payment info
			$q = "SELECT * FROM #__{vm}_order_payment WHERE order_id='". $orders[$i]['order_id'] ."'";
			$db->setQuery($q);
			$orders[$i]['payment'] = $db->loadAssocList();
		}


		foreach($orders as $order) {

			//print_r($order);
			$OLWebOrder['OLWebOrder']['TransactionHeader']['TransactionID'] = $order['order_id'];
			$OLWebOrder['OLWebOrder']['OrderHeader']['ProcessingOptions']['OrderDate'] = date('d.m.Y H:i:s', $order['cdate']);
			$OLWebOrder['OLWebOrder']['OrderHeader']['HeaderText'] = $order['customer_note'];
			$OLWebOrder['OLWebOrder']['OrderHeader']['ProcessingOptions']['RefNo'] = str_pad($order['order_id'], 8, 0,STR_PAD_LEFT);
			for($i = 0; $i < count($order['user_info']) ; $i++) {
				switch ($order['user_info'][$i]['address_type']) {
					case 'BT':
					default:

						if($order['company']) {
							$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['Name1'] = $order['user_info'][$i]['company'];
							$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['Name2'] = $order['user_info'][$i]['first_name'] . (($order['user_info'][$i]['middle_name']) ? ' ' . $order['user_info'][$i]['middle_name'] . ' ' : ' ') . $order['user_info'][$i]['last_name'];
							$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['Matchcode'] = $order['user_info'][$i]['company'] . ', ' .$order['user_info'][$i]['customers_city'] ;
						} else {
							$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['Name1'] = $order['user_info'][$i]['last_name'];
							$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['Name2'] = $order['user_info'][$i]['first_name'] . (($order['user_info'][$i]['middle_name']) ? ' ' . $order['user_info'][$i]['middle_name'] : '');
							$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['Matchcode'] = $order['user_info'][$i]['last_name'] . ', ' .$order['user_info'][$i]['city'] ;
						}
						$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['Title'] = 	$order['user_info'][$i]['title'];
						$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['Street'] = $order['user_info'][$i]['address_1'] . (($order['user_info'][$i]['address_2']) ? ', ' . $order['user_info'][$i]['address_2'] : '');
						$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['ZIPCode'] = $order['user_info'][$i]['zip'];
						$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['City'] = $order['user_info'][$i]['city'];
						$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['State'] = $order['user_info'][$i]['state'];
						$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['Country'] = $this->getISOCode2($order['user_info'][$i]['country']);
						$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['EMail'] = $order['user_info'][$i]['user_email'];

						$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['AddrTelefon'] = $order['user_info'][$i]['phone_1'];
						$OLWebOrder['OLWebOrder']['OrderHeader']['Address']['AddrFax'] = $order['user_info'][$i]['fax'];

						break;

					case 'ST':

						if($order['company']) {
							$OLWebOrder['OLWebOrder']['OrderHeader']['DeliveryAddress']['DAName1'] = $order['user_info'][$i]['company'];
							$OLWebOrder['OLWebOrder']['OrderHeader']['DeliveryAddress']['DAName2'] = $order['user_info'][$i]['first_name'] . (($order['user_info'][$i]['middle_name']) ? ' ' . $order['user_info'][$i]['middle_name'] . ' ' : ' ') . $order['user_info'][$i]['last_name'];
						} else {

							$OLWebOrder['OLWebOrder']['OrderHeader']['DeliveryAddress']['DAName1'] = $order['user_info'][$i]['last_name'];
							$OLWebOrder['OLWebOrder']['OrderHeader']['DeliveryAddress']['DAName2'] = $order['user_info'][$i]['first_name'] . (($order['user_info'][$i]['middle_name']) ? ' ' . $order['user_info'][$i]['middle_name'] : '');
						}
						$OLWebOrder['OLWebOrder']['OrderHeader']['DeliveryAddress']['DATitle'] = $order['user_info'][$i]['title'];
						$OLWebOrder['OLWebOrder']['OrderHeader']['DeliveryAddress']['DAStreet'] = $order['user_info'][$i]['address_1'] . (($order['user_info'][$i]['address_2']) ? ', ' . $order['user_info'][$i]['address_2'] : '');
						$OLWebOrder['OLWebOrder']['OrderHeader']['DeliveryAddress']['DAZIPCode'] = $order['user_info'][$i]['zip'];
						$OLWebOrder['OLWebOrder']['OrderHeader']['DeliveryAddress']['DACity'] = $order['user_info'][$i]['city'];
						$OLWebOrder['OLWebOrder']['OrderHeader']['DeliveryAddress']['DAState'] = $order['user_info'][$i]['state'];
						$OLWebOrder['OLWebOrder']['OrderHeader']['DeliveryAddress']['DACountry'] = $this->getISOCode2($order['user_info'][$i]['country']);

						break;
				}
			}
			$OLWebOrder['OLWebOrder']['OrderHeader']['ProcessingOptions']['CarrierCode'] = $this->getCarrierCode($order[$i]['ship_method_id']);
			$OLWebOrder['OLWebOrder']['OrderHeader']['ProcessingOptions']['DeliveryPriceGross'] = 0;
			$OLWebOrder['OLWebOrder']['OrderHeader']['Payment']['Currency'] = $order['order_currency'];
			$OLWebOrder['OLWebOrder']['OrderHeader']['Payment']['BelOLPayCond'] = $this->getPaymentCode($order['payment'][0]['payment_method_id']);

			$this->OLWebOrder[] = $OLWebOrder;
			$OLWebOrder = array();
		}
		$this->xmldoc = &$xmldoc;
		return true;
	}

	/**
    * output of export
    * @return bool true/false
    */
	function output_export() {
		header ("Last-Modified: ". gmdate ("D, d M Y H:i:s"). " GMT");  // immer ge�ndert
		header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
		header ("Pragma: no-cache"); // HTTP/1.0
		header ("Content-type: text/xml");

		DOMIT_Utilities::fromArray($this->xmldoc, $this->OLWebOrder);

		echo $this->xmldoc->toString(false, true);
		/*echo '<pre>';
		print_r($orders);
		echo '</pre>';*/
		return true;
	}

	function getISOCode2($isocode3) {
		return $isocode3;
	}

	function getCarrierCode($ship_method_id) {
		return $ship_method_id;
	}

	function getPaymentCode($payment_method_id) {
		return $payment_method_id;
	}
}
Back to Top