Skip to content

Commit

Permalink
inital
Browse files Browse the repository at this point in the history
  • Loading branch information
jankom committed Sep 20, 2010
0 parents commit 6478444
Show file tree
Hide file tree
Showing 46 changed files with 5,447 additions and 0 deletions.
Binary file added .api-invfox.php.swp
Binary file not shown.
Binary file added .invfoxapi.php.swp
Binary file not shown.
Binary file added .strpcapi.php.swp
Binary file not shown.
55 changes: 55 additions & 0 deletions api-invfox.php
@@ -0,0 +1,55 @@
<html>
<body>
<style>
body {
font-size: 12px;
font-family: Trebuchet MS, Arial, Tahoma;
padding: 0px;
margin: 0px;
}
div.type {
float: right;
color: gray;
font-weight: bold;
padding-right: 10px;
}
h1 {
margin: 0px;
padding 20px;
background-color: #444444;
color: white;
}
pre.req {
padding: 20px;
background-color: #f1f1f1;
}
pre.resp {
padding: 20px;
background-color: #f1f1f1;
}
form {
padding: 20px;
background-color: #f1f1ff;
}
</style>
<h1>InvoiceFox API explorer</h1>
<?php
require_once "pulp/Format.php";
require_once "strpcapi.php";
require_once "invfoxapi.php";

if (isset($_POST['call'])) {

$api = new InvfoxAPI('vr64g6891lgatnf83dmxticsc10ashr2f4s9ye7w');

$resp = $api->assurePartner("name=asdasd&street=asdasds&postal=12312&city=asdasd&vatid=&phone=&website=&email=&notes=&vatbound=0&custaddr=&payment_period=14&street2=asdsad");

echo "<br/><div class='type'>response</div><pre class='resp'>"; print_r($resp->res); echo "</pre>";

}
?>
<form method="post">
<input type="submit" name="call" value="Call" />
</body>
</html>
name=asdasd&street=asdasds&postal=12312&city=asdasd&vatid=&phone=&website=&email=&notes=&vatbound=0&custaddr=&payment_period=14&street2=asdsad
36 changes: 36 additions & 0 deletions api.pgp
@@ -0,0 +1,36 @@
<?php

class InvFoxAPI {

function get( ) {
$header = "GET /API.html?apitoken=9i7a6dnr4b0k82r6qaj583ssefy9otcp7am2dhr4&_r=partner&_m=select-all-safe&filter=all&page=0 HTTP/1.1\r\n".
"Host:example.com\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"User-Agent: PHP-Code\r\n".
"Content-Length: " . strlen($req) . "\r\n".
"Authorization: Basic ".base64_encode($username.':'.$password)."\r\n".
"Connection: close\r\n\r\n";

//$req .= "&cmd=_initiate_query";

$fp = fsockopen ('ssl://www.invoicefox.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header);
while (!feof($fp)) {
$result .= fgets ($fp, 128);
}
fclose ($fp);
}

}

function createInvoice() {


}

}

?>
70 changes: 70 additions & 0 deletions api.php
@@ -0,0 +1,70 @@
<html>
<body>
<style>
body {
font-size: 12px;
font-family: Trebuchet MS, Arial, Tahoma;
padding: 0px;
margin: 0px;
}
div.type {
float: right;
color: gray;
font-weight: bold;
padding-right: 10px;
}
h1 {
margin: 0px;
padding 20px;
background-color: #444444;
color: white;
}
pre.req {
padding: 20px;
background-color: #f1f1f1;
}
pre.resp {
padding: 20px;
background-color: #f1f1f1;
}
form {
padding: 20px;
background-color: #f1f1ff;
}
</style>
<h1>InvoiceFox API explorer</h1>
<?php
require_once "pulp/Format.php";
require_once "strpcapi.php";
require_once "invfoxapi.php";


$apidef = array(
'invoice-sent' => array('select-all'),
'invoice-recv' => array('select-all'),
'partner' => array('select-all'),
'preinvoice' => array('select-all')
);

$RESOURCE = isset($_POST['resource']) ? $_POST['resource'] : '';
$METHOD = isset($_POST['method']) ? $_POST['method'] : '';
$ARGS = isset($_POST['args']) ? $_POST['args'] : '';


if (isset($_POST['call'])) {
$strpc = new StrpcAPI('vr64g6891lgatnf83dmxticsc10ashr2f4s9ye7w');
$response = $strpc->call($RESOURCE, $METHOD, $ARGS);
echo "<br/><div class='type'>response</div><pre class='resp'>"; print_r($response->res); echo "</pre>";
}
?>
<form method="post">
resource:<br/><input name="resource" value="<?php echo $RESOURCE ?>" />
<small><?php foreach ( $apidef as $res => $meths ) { echo $res . " &nbsp; "; } ?></small>
<br/>
method: <br/><input name="method" value="<?php echo $METHOD ?>"/><br/>
<br/>
arguments: <br/><textarea name="args" cols="100" rows="5"></textarea><br/>
<input type="submit" name="call" value="Call" />
</body>
</html>
name=asdasd&street=asdasds&postal=12312&city=asdasd&vatid=&phone=&website=&email=&notes=&vatbound=0&custaddr=&payment_period=14&street2=asdsad
38 changes: 38 additions & 0 deletions create_invoice.php
@@ -0,0 +1,38 @@
<?php

class InvFoxAPI {

function get( ) {
$header = "GET /API.html?apitoken=9i7a6dnr4b0k82r6qaj583ssefy9otcp7am2dhr4&_r=partner&_m=select-all-safe&filter=all&page=0 HTTP/1.1\r\n".
"Host:example.com\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"User-Agent: PHP-Code\r\n".
"Content-Length: " . strlen($req) . "\r\n".
"Authorization: Basic ".base64_encode($username.':'.$password)."\r\n".
"Connection: close\r\n\r\n";

//$req .= "&cmd=_initiate_query";

$fp = fsockopen ('ssl://www.invoicefox.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header);
while (!feof($fp)) {
$result .= fgets ($fp, 128);
}
fclose ($fp);
}

}

function createInvoice() {


}

}

print_r(InvFoxAPI::get());

?>
50 changes: 50 additions & 0 deletions invfoxapi.php
@@ -0,0 +1,50 @@
<?php

class InvfoxAPI {

var $api;

function InvfoxAPI($apitoken) {
$this->api = new StrpcAPI($apitoken);
}

function assurePartner($data) {
$res = $this->api->call('partner', 'assure', $data);
if ($res->isErr()) {
// echo 'error' . $res->getErr();
}
return $res;
}

function createInvoice($header, $body) {
$res = $this->api->call('invoice-sent', 'insert', $header);
if ($res->isErr()) {
echo 'error' . $res->getErr();
} else {
foreach ($body as $bl) {
$res2 = $this->api->call('invoice-sent-b', 'insert', $bl);
if ($res->isErr()) {
echo 'error' . $res->getErr();
}
}
}
return $res->getData();
}

function downloadPDF($id) {
$res = $apipdf->load($id, $id.".pdf");
if ($res->isErr()) {
echo 'error' . $res->getErr();
}
}

function markPayed() {
$res = $this->api->call('invoice-sent', 'mark-payed', array('id' => $id));
if ($res->isErr()) {
echo 'error' . $res->getErr();
}
}

}

?>
Binary file added pulp/.Format.php.swp
Binary file not shown.
36 changes: 36 additions & 0 deletions pulp/Arr.php
@@ -0,0 +1,36 @@
<?php

require_once 'Http.php';

class Arr {

static function setDefaults($a, $defs)
{
foreach($defs as $k => $d){
if (!isset($a[$k]))
{
$a[$k] = $d;
}
}
return $a;
}

static function toIndexed($a, $ks)
{
$r = array();
foreach($ks as $k)
{
$r[] = $a[$k];
}
return $r;
}

static function reducek($array, $callback, $initial=null)
//reduce function with array key and value
{
$acc = $initial;
foreach($array as $k => $v)
$acc = call_user_func_array($callback, array($acc, $k, $v));
return $acc;
}
}
68 changes: 68 additions & 0 deletions pulp/Browser.php
@@ -0,0 +1,68 @@
<?php

class Browser
{

function redirect($location)
//i: redirect using the header command and exit
{
if (strtolower(substr($location, 0, 4)) == 'http')
{
header("Location: $location");
exit;
}
else
{
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
header("Location: http://$host$uri/" . htmlspecialchars_decode($location));
exit;
}
}

function redirectDelayed($location, $delay, $text='Redirecting...', $other=array())
//i: redirect using the header command and exit
{
$title = isset($other['title']) ? $other['title'] : 'Redirecting...';
$bodyParams = isset($other['bodyParams']) ? $other['bodyParams'] : '';
$divParams = isset($other['divParams']) ? $other['divParams'] : '';
$autoLink = isset($other['autoLink']) ? $other['autoLink'] : false;
$autoLinkTemplate = isset($other['autoLinkTemplate']) ? $other['autoLinkTemplate'] :
"<br/><br/><a href='%%'>Click here to go now</a>";
$location2 = isset($other['location2']) ? $other['location2'] : '';
$location3 = isset($other['location3']) ? $other['location3'] : '';
$location4 = isset($other['location4']) ? $other['location4'] : '';
$location5 = isset($other['location5']) ? $other['location5'] : '';
$location6 = isset($other['location6']) ? $other['location6'] : '';

if ($autoLink)
{
$autoLinkTemplate = str_replace('%delay%', $delay, $autoLinkTemplate);
$text .= str_replace('%location%', $location, $autoLinkTemplate);
if ($location2) $text = str_replace('%location2%', $location2, $text);
if ($location3) $text = str_replace('%location3%', $location3, $text);
if ($location4) $text = str_replace('%location4%', $location4, $text);
if ($location5) $text = str_replace('%location5%', $location5, $text);
if ($location6) $text = str_replace('%location6%', $location6, $text);
}

echo "<html>
<head>
<title>$title</title>
<META HTTP-EQUIV='Refresh'
CONTENT='$delay; URL=$location'>
</head>
<body $bodyParams>
<div $divParams>
$text
</div>
</body>
</html>
";
exit();
}


}

?>
35 changes: 35 additions & 0 deletions pulp/Crumbs.php
@@ -0,0 +1,35 @@
<?php

class Crumbs {

static private $crumbs = array();
static private $end;

static public function add($name, $link) {

self::$crumbs[] = array('name'=>ucfirst($name), 'link'=>$link);

}

static public function addAtEnd($name, $link) {

self::$end = array('name'=>ucfirst($name), 'link'=>$link);

}

static public function show() {

if (isset(self::$end)) {
self::$crumbs[] = self::$end;
}
$return = '<div id="crumbs"><ul>';
$return .= '<li><a href="' . URL::build('osnovna.php') . '"><span>Osnovna stran</span></a></li>';
foreach (self::$crumbs as $crumb) {
$return .= "<li><a href='{$crumb['link']}'><span>{$crumb['name']}</span></a></li>";
}
$return .= '</ul></div>';

return $return;
}

}

0 comments on commit 6478444

Please sign in to comment.