Skip to content

Commit

Permalink
library conversion and demo
Browse files Browse the repository at this point in the history
  • Loading branch information
csantala committed Jan 6, 2012
1 parent ede5982 commit aa7a710
Show file tree
Hide file tree
Showing 15 changed files with 773 additions and 568 deletions.
Binary file added .DS_Store
Binary file not shown.
17 changes: 7 additions & 10 deletions README
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
SETUP
To get setup, you will need to modify the values in the _config.php file to your own requirements and application settings
Special options for Partner applications - should be commented out for non-partner applications

DEBUGGING
If you append: ?debug=1 to example.php so you have /example.php?debug=1
- this will output some debug information
- this will include a "CURL ERROR:" line
- under this, if you are getting any errors it should provide this in the returned oauth_problem and oauth_problem_advice parameters - the error messages should be quite self explanatory
- if there are no errors, you should just oauth_token and oauth_token_secret paramters returned, indicating all is ok

1. edit Xro_config.php
1.1 set $xro_app_type
1.2 set $oauth_callback to point to authorise.php (ie https://domain.com/authorise.php)
1.3. set consumer_key and shared_secret

XERO APP SETTINGS (https://api.xero.com/Application)
URL of your copany or product: https://[domain]/[path]/authorise.php
OAuth callback domaing: [domain]
97 changes: 0 additions & 97 deletions XeroOAuth.php

This file was deleted.

55 changes: 0 additions & 55 deletions _config.php

This file was deleted.

12 changes: 12 additions & 0 deletions authorise.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
require('setup.php');
require('lib/Xero.php');

$xero = new Xero;

$authorization = $xero->oauth();

if (isset($authorization)) {
header('Location: ' . $web_root);
}
?>
52 changes: 52 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}

a {
color: #003399;
background-color: transparent;
font-weight: normal;
}

h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 19px;
font-weight: normal;
margin: 0 0 14px 0;
padding: 14px 15px 10px 15px;
}

code {
font-family: Consolas, Monaco, Courier New, Courier, monospace;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}

#body{
margin: 0 15px 0 15px;
}

p.footer{
text-align: right;
font-size: 11px;
border-top: 1px solid #D0D0D0;
line-height: 32px;
padding: 0 10px 0 10px;
margin: 20px 0 0 0;
}

#container{
margin: 10px;
border: 1px solid #D0D0D0;
-webkit-box-shadow: 0 0 8px #D0D0D0;
}
115 changes: 115 additions & 0 deletions edit_contact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

include('lib/Xero.php');
include('setup.php');

$xero = new Xero;

function check_for_exception($client_data) {
// if this data structure is not retured then we have an exception; dump exception and exit.
if (! isset($client_data->Contacts->Contact->ContactID)) {
echo "<pre>"; print_r($client_data); echo "</pre>"; exit;
}
else {
// all good
$id = $client_data->Contacts->Contact->ContactID;
return $id;
}
}

// when receiving id from list_contacts.php
if (isset($_GET['id'])) {
$id = $_GET['id'];
$label = 'Update Client';
$method = 'edit';

}
else {
$label = 'Add Client';
$method = 'add';
}

// when form posts to itself
if (isset($_POST['method'])) {
// when adding a new client
if ($_POST['method'] == 'add') {

// post new contact to Xero
// if contact name is same as existing contact name then an error will be returned by the library
$client_data = simplexml_load_string($xero->api_put($_POST));

$id = check_for_exception($client_data);

$new_client = true;
$label = 'Update Client';
$method = 'edit';
}
elseif ($_POST['method'] == 'edit') {
// when editing a client
$client_data = simplexml_load_string($xero->api_post($_POST));

$id = check_for_exception($client_data);

$edited_client = true;
$label = 'Update Client';
$method = 'edit';
}

}

// get contact from xero if we have an id
if (isset($id)) {
// get contact data for form
$contactData = simplexml_load_string($xero->api_call('contacts', $id));
$contact = $contactData->Contacts->Contact;
}



?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="<?php echo $web_root?>/css/style.css" />
<title><?php echo $label ?></title>
</head>
<body>
<div id="container">
<h1><?php echo $label ?></h1>
<p style="margin:15px"><a href="<?php echo $web_root?>/">home</a></p>

<div id="body">
<?php if (isset($new_client)):?>
<p>New Client added: <b><?php echo $contact->Name ?></b></p>
<?php endif ?>
<?php if (isset($edited_client)):?>
<p>Client edited: <b><?php echo $contact->Name ?></b></p>
<?php endif ?>

<form action="<?php echo $web_root . '/' . 'edit_contact.php'?>" method="post">
<p>
<label>Name</label><br>
<input type="text" name="name" value="<?=isset($contact->Name) ? $contact->Name : ''?>">
</p>
<p>
<label>First Name</label><br>
<input type="text" name="first_name" value="<?=isset($contact->FirstName) ? $contact->FirstName : ''?>">
</p>
<p>
<label>Last Name</label><br>
<input type="text" name="last_name" value="<?=isset($contact->LastName) ? $contact->LastName : ''?>">
</p>
<p>
<label>email</label><br>
<input type="text" name="email" value="<?=isset($contact->EmailAddress) ? $contact->EmailAddress : ''?>">
</p>

<p>
<input type="hidden" name="method" value="<?php echo $method?>">
<input type="submit" value="<?php echo $label?>">
</p>
</div>
</div>
</body>
</html>
Loading

0 comments on commit aa7a710

Please sign in to comment.