<?php

//setrelated request
$ctoId = '12x22';
// Contacts
$pdoId = '14x52';
// Product
$docId = '15x159';
// Document
$srvId = '26x151';
// Services
$params = array("sessionName" => $cbSessionID, "operation" => 'SetRelation', "relate_this_id" => $ctoId, 'with_these_ids' => json_encode(array($pdoId, $docId, $srvId)));
$response = $httpc->send_post_data($cbURL, $params, true);
$dmsg .= debugmsg("Raw response (json) SetRelation", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response SetRelation", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('SetRelation failed:' . $jsonResponse['error']['message']);
    echo 'SetRelation failed!';
} else {
    // Show response
    var_dump($jsonResponse['result']);
}
<?php

// Login Contact
// Validates a contact access to the portal: the contact must have an active portal access with correct access dates
//    and give the correct email and password.
// This method returns a valid logged in session with the internal "portal" user
$email = '*****@*****.**';
$password = '******';
$params = "operation=loginPortal&username={$email}&password={$password}";
$response = $httpc->fetch_url("{$cbURL}?{$params}");
$dmsg .= debugmsg("Raw response (json) Query", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response loginPortal", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('loginPortal failed: ' . $jsonResponse['message']);
    echo 'loginPortal failed!';
} else {
    if (!$jsonResponse['result']) {
        echo 'Contact with email ' . $email . ' could <b>NOT</b> be logged in correctly!';
    } else {
        echo 'Contact with ID ' . $jsonResponse['result'] . ' has been logged in correctly!';
    }
}
<?php

//fill in the details of the invoice id.
$invoiceId = $_REQUEST['invoiceID'];
//sessionId is obtained from loginResult.
$params = array("sessionName" => $cbSessionID, "operation" => 'getpdfdata', "id" => $invoiceId);
//Create must be POST Request.
$response = $httpc->send_post_data($cbURL, $params, true);
$dmsg .= debugmsg("Raw response (json) GetPDFData", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response GetPDFData", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('GetPDFData failed: ' . $jsonResponse['error']['message']);
    echo 'GetPDFData failed!';
} else {
    // fix for IE catching or PHP bug issue
    header("Pragma: public");
    header("Expires: 0");
    // set expiration time
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    // browser must download file from server instead of cache
    // force download dialog
    header("Content-Type: application/force-download");
    header('Content-Type: application/pdf');
    header("Content-Type: application/download");
    // use the Content-Disposition header to supply a recommended filename and
    // force the browser to display the save dialog.
    header('Content-Disposition: attachment; filename="invoice.pdf"');
    /*
    The Content-transfer-encoding header should be binary, since the file will be read
Ejemplo n.º 4
0
<?php

//SessionId is the session which is to be terminated.
$params = "operation=logout&sessionName={$cbSessionID}";
//logout must be GET Request.
$response = $httpc->fetch_url("{$cbURL}?{$params}");
$dmsg .= debugmsg("Raw response (json) Logout", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response Logout", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('logout failed: ' . $jsonResponse['message']);
    echo 'logout failed!';
} else {
    echo debugmsg("Webservice Logout", $jsonResponse);
}
<?php

//sessionId is obtained from loginResult.
$grefParams = '&term=' . urlencode('es') . '&filter=contains' . '&searchinmodules=Accounts,Contacts' . '&limit=10';
$params = "sessionName={$cbSessionID}&operation=getReferenceAutocomplete{$grefParams}";
//Call must be GET Request.
$response = $httpc->fetch_url("{$cbURL}?{$params}");
$dmsg .= debugmsg("Raw response (json) getReferenceAutocomplete", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response getReferenceAutocomplete", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('getReferenceAutocomplete failed: ' . $jsonResponse['error']['message']);
    echo 'getReferenceAutocomplete failed!';
} else {
    var_dump($jsonResponse['result']);
}
<?php

//listtypes request must be GET request.
$response = $httpc->fetch_url("{$cbURL}?sessionName={$cbSessionID}&operation=listtypes");
$dmsg .= debugmsg("Raw response (json) listtypes", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response listtypes", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('list types failed:' . $jsonResponse['error']['message']);
    echo 'list types failed!';
} else {
    //Get the List of all the modules accessible.
    $modules = $jsonResponse['result']['types'];
    echo "<b>Accesible Modules</b><br>";
    foreach ($modules as $modname) {
        echo "{$modname}<br>";
    }
}
Ejemplo n.º 7
0
<?php

include 'testcode/010_getchallenge.php';
//create md5 string concatenating user accesskey from my preference page
//and the challenge token obtained from get challenge result.
$generatedKey = md5($challengeToken . $cbAccessKey);
//login request must be POST request.
$response = $httpc->send_post_data($cbURL, array('operation' => 'login', 'username' => $cbUserName, 'accessKey' => $generatedKey), true);
$dmsg .= debugmsg("Raw response (json) doLogin", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response doLogin", $jsonResponse);
//operation was successful get the token from the response.
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('login failed:' . $jsonResponse['error']['message']);
    echo "Error trying to log in!";
} else {
    //login successful extract sessionId and userId from LoginResult so it can used for further calls.
    $sessionId = $jsonResponse['result']['sessionName'];
    $userId = $jsonResponse['result']['userId'];
    echo "doLogin sessionId: {$sessionId}<br>";
    echo "doLogin userId: {$userId}<br>";
}
<?php

// authenticate Contact
// Validates a contact access to the portal: the contact must have an active portal access with correct access dates
//    and give the correct email and password.
$email = '*****@*****.**';
$password = '******';
$params = array("sessionName" => $cbSessionID, "operation" => 'authenticateContact', 'email' => $email, 'password' => $password);
$response = $httpc->send_post_data($cbURL, $params, true);
$dmsg .= debugmsg("Raw response (json) Query", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response authenticateContact", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('authenticateContact failed: ' . $jsonResponse['message']);
    echo 'authenticateContact failed!';
} else {
    if (!$jsonResponse['result']) {
        echo 'Contact with email ' . $email . ' could <b>NOT</b> be authenticated correctly!';
    } else {
        echo 'Contact with ID ' . $jsonResponse['result'] . ' has been authenticated correctly!';
    }
}
<?php

//vtiger Object name which need be described or whose information is requested.
// Can be passed in with modulename parameter
$moduleName = 'Contacts';
//use sessionId created at the time of login.
$params = "sessionName={$cbSessionID}&operation=describe&elementType={$moduleName}";
//describe request must be GET request.
$response = $httpc->fetch_url("{$cbURL}?{$params}");
$dmsg .= debugmsg("Raw response (json) describe", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response describe", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('describe object failed:' . $jsonResponse['error']['message']);
    echo 'describe object failed!';
} else {
    //get describe result object.
    $description = $jsonResponse['result'];
    echo "<b>Module Name and Id:</b> " . $moduleName . ' (' . $description['idPrefix'] . ')</br>';
    echo "<b>User can create records:</b> " . ($description['createable'] == 1 ? 'Yes' : 'No') . '</br>';
    echo "<b>User can update records:</b> " . ($description['updateable'] == 1 ? 'Yes' : 'No') . '</br>';
    echo "<b>User can delete records:</b> " . ($description['deleteable'] == 1 ? 'Yes' : 'No') . '</br>';
    echo "<b>User can retrieve records:</b> " . ($description['retrieveable'] == 1 ? 'Yes' : 'No') . '</br>';
    echo "<b>Fields (hover over name for full details):</b> </br>";
    $i = 0;
    foreach ($description['fields'] as $field) {
        $ttname = "tt{$i}";
        $i++;
        $fieldname = $field['label'];
        $fielddesc = "{$fieldname}\nField: " . $field['name'] . "\nMandatory: ";
<?php

//fill in the details of the document id
// select id from documents
// 7x138 is an existing document
$docId = '7x138';
//sessionId is obtained from loginResult.
$params = array("sessionName" => $cbSessionID, "operation" => 'retrievedocattachment', "id" => $docId, 'returnfile' => false);
//Create must be POST Request.
$response = $httpc->send_post_data($cbURL, $params, true);
$dmsg .= debugmsg("Raw response (json) retrievedocattachment", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response retrievedocattachment", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('retrievedocattachment failed: ' . $jsonResponse['error']['message']);
    echo 'retrievedocattachment failed!';
} else {
    echo "<script type='text/javascript'>\n\t\tfunction doDOCDownload() {\n\t\t\tio = document.createElement('iframe');\n\t\t\tio.src = 'index.php?action=execCodeDirect&script=430_getDocumentDirect.php&docId=" . $docId . "';\n\t\t\tio.style.display = 'block';\n\t\t\tio = \$(io);\n\t\t\t\$('body').append(io);\n\t\t\tsetTimeout(function() {\n\t\t\t\tio.remove();\n\t\t\t}, 5000);\n\t\t}\n\t\t</script>";
    echo "<br><a href='javascript:doDOCDownload();' class='btn btn-primary btn-large'>Download Document</a>";
}
<?php

function tagLI($vli)
{
    echo "<li>{$vli}</li>";
}
echo '<ul>';
// show the variables we can use in our test code
tagLI("URL of the site we logged in with: <b>" . $cbURL . "</b>");
tagLI("Username we logged in with: <b>" . $cbUserName . "</b>");
tagLI("UserID we logged in with: <b>" . $cbUserID . "</b>");
tagLI("Accesskey we logged in with: <b>" . $cbAccessKey . "</b>");
tagLI("SessionID we logged in with: <b>" . $cbSessionID . "</b>");
tagLI('cbwsLibrary connection to coreBOS: <b>$cbconn</b>');
tagLI('http_curl connection to coreBOS: <b>$httpc</b>');
echo '</ul>';
// debug message
$dmsg = 'Any message we put into the <b>$dmsg</b> variable will be output to the Debug box';
$dmsg .= debugmsg('Result of the REST call', array('status' => 'success', 'result' => 'hello world'));
echo "<br>You can find some more information on our wiki: <a href='http://corebos.org/documentation/doku.php?id=en:devel:corebosws:coreBOSwsDevelopment'>coreBOSwsDevelopment</a>";
Ejemplo n.º 12
0
<?php

// Obtained from contact creation example
$contactId = '4x194';
//delete a record created in above examples, sessionId a obtain from the login result.
$params = array("sessionName" => $cbSessionID, "operation" => 'delete', "id" => $contactId);
//delete operation request must be POST request.
$response = $httpc->send_post_data($cbURL, $params, true);
$dmsg .= debugmsg("Raw response (json) Delete", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response Delete", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('delete failed: ' . $jsonResponse['error']['message']);
    echo 'delete failed!';
} else {
    echo debugmsg("Record Deleted", $jsonResponse);
}
Ejemplo n.º 13
0
function xmpp_presence($stanza, $sock, $ircsock)
{
    global $xmppparams, $ircdata;
    $obj = new CXMLTag();
    $obj->fromArray($stanza);
    $toparts = xmpp_parse_jid($obj->attribs['to']);
    $fromparts = xmpp_parse_jid($obj->attribs['from']);
    // Join only valid IRC channel
    if (!irc_valid_channel(from_utf($toparts['user']))) {
        debugmsg("Invalid channel name\n");
        return false;
    }
    // Ignore invalid jid
    if (!$toparts['user'] || !$toparts['resource'] || !$fromparts['user'] || !$fromparts['resource']) {
        $answer = $obj->createError("modify", "jid-malformed", true);
        debugmsg("No nickname or room name\n");
        xmpp_write($sock, $answer->toString());
        return false;
    }
    $channel = from_utf($toparts['user']);
    // Normalize case if channel exists
    if ($norm_ch = $ircdata->channel_exists($channel)) {
        $channel = $norm_ch;
    } else {
        $ircdata->add_channel($channel);
    }
    $nick = $ircdata->jid_exists(from_utf($obj->attribs['from']));
    $newnick = from_utf($toparts['resource']);
    $forcenick = '';
    //    dump_ircdata("ircdata.dump", FILE_APPEND, "Do");
    if (!$nick) {
        debugmsg("New user, trying to join IRC\n");
        if (isset($obj->attribs['type'])) {
            return false;
        }
        // First enter of JID
        $nick = from_utf($toparts['resource']);
        if (!irc_valid_nick($nick)) {
            $answer = $obj->createError("cancel", "not-acceptable", true);
            debugmsg("Invalid nick\n");
            xmpp_write($sock, $answer->toString());
            return false;
        }
        if ($ircdata->nick_exists($nick)) {
            $answer = $obj->createError("cancel", "conflict", true);
            debugmsg("Nick already exists\n");
            xmpp_write($sock, $answer->toString());
            return false;
        }
        $ircdata->add_nick($nick, '', '', '', from_utf($obj->attribs['from']));
        // Send new nick to IRC server
        irc_nick($ircsock, $nick);
    } else {
        if (isset($obj->attribs['type'])) {
            if ($obj->attribs['type'] == 'unavailable') {
                debugmsg("Part room\n");
                if ($ircdata->is_on($nick, $channel)) {
                    if ($statustag = $obj->firstSubtag('status')) {
                        $status = from_utf($statustag->text);
                    } else {
                        $status = '';
                    }
                    xmpp_write($sock, xmpp_part(to_utf($nick), $toparts['user']));
                    irc_part($ircsock, $nick, $channel);
                    $ircdata->part_channel($nick, $channel, $status);
                    if (!$ircdata->get_on_channels($nick)) {
                        irc_quit($ircsock, $nick, $status);
                        $ircdata->remove_nick($nick);
                    }
                } else {
                    return false;
                }
                return true;
            }
        }
        // JID already exists
        // Fix for status changes
        if ($nick == $newnick) {
            //return false;
            debugmsg("JID already exists\n");
        }
        if (strcasecmp(from_utf($toparts['resource']), $nick) != 0) {
            $forcenick = $nick;
        }
    }
    // Is channel pressent
    if ($nick != $newnick && $ircdata->is_on($nick, $channel)) {
        // debugmsg("   ---   Test: user on channel", 1);
        if (!irc_valid_nick($newnick)) {
            $answer = $obj->createError('cancel', 'not-acceptable', true);
            debugmsg("Invalid nick\n");
            xmpp_write($sock, $answer->toString());
            return false;
        }
        // Change nick
        $can_change = $ircdata->can_change_nick($nick, $newnick);
        if ($can_change === true) {
            debugmsg("Changing nick\n");
            irc_change_nick($ircsock, $nick, $newnick);
            xmpp_write($sock, xmpp_change_nick(to_utf($nick), to_utf($newnick)));
            $ircdata->change_nick($nick, $newnick);
            //	    dump_ircdata("ircdata2.dump", FILE_APPEND, "Posle");
            return true;
        } else {
            $errtag = $obj->createError('cancel', $can_change['error'], true);
            debugmsg("Nick can't change\n");
            xmpp_write($sock, $errtag->toString());
            return false;
        }
        return false;
    } else {
        // debugmsg("   ---   Test: can user join?", 1);
        if ($forcenick) {
            $nick = $forcenick;
        }
        $password = '';
        if ($xtag = $obj->validSubtag('x', 'xmlns', FEAT_MUC)) {
            if ($passtag = $xtag->firstSubtag('password')) {
                $password = $passtag->text;
            }
        }
        $join = $ircdata->can_join($nick, $channel, from_utf($password));
        // var_dump($join);
        if ($join === true) {
            $ircdata->join_channel($nick, $channel);
            // Give op to first user in channel
            if (count($ircdata->channels[$channel]['nicks']) == 1) {
                $ircdata->set_chumode($channel, $nick, 'o', true);
                irc_join($ircsock, $nick, $channel, '@');
            } else {
                irc_join($ircsock, $nick, $channel);
            }
            // Send channel members to new user
            xmpp_write($sock, xmpp_presence_to_new(to_utf($nick), $toparts['user']));
            // Send new user to channel members
            xmpp_write($sock, xmpp_presence_to_all(to_utf($nick), $toparts['user'], $forcenick ? to_utf($nick) : ''));
            // Send subject to new user
            xmpp_write($sock, xmpp_message_to_one(to_utf($ircdata->channels[$channel]['topic_by']), to_utf($nick), 'subject', to_utf(text_from_irc($ircdata->channels[$channel]['topic'])), $toparts['user']));
            return true;
        } else {
            // Send error messages
            $errtag = false;
            switch ($join['error']) {
                case 'invite':
                    $errtag = $obj->createError('auth', 'registration-required', true);
                    break;
                case 'password':
                    $errtag = $obj->createError('auth', 'not-authorized', true);
                    break;
                case 'limit':
                    $errtag = $obj->createError('wait', 'service-unavailable', true);
                    break;
                case 'ban':
                    $errtag = $obj->createError('auth', 'forbidden', true);
                    break;
            }
            if ($errtag) {
                xmpp_write($sock, $errtag->toString());
            }
        }
    }
    return false;
}
<?php

// show the variables we can use in our test code
echo "URL of the site we logged in with: <b>" . $cbURL . "</b><br>";
echo "Username we logged in with: <b>" . $cbUserName . "</b><br>";
echo "UserID we logged in with: <b>" . $cbUserID . "</b><br>";
echo "Accesskey we logged in with: <b>" . $cbAccessKey . "</b><br>";
echo "SessionID we logged in with: <b>" . $cbSessionID . "</b><br>";
echo 'cbwsLibrary connection to coreBOS: <b>$cbconn</b><br>';
echo 'http_curl connection to coreBOS: <b>$httpc</b><br>';
// debug message
$dmsg = 'Any message we put into the <b>$dmsg</b> variable will be output to the Debug box';
$dmsg .= debugmsg('we have a special function for debug messages which accepts complex variables', array('v1' => 'value 1', 'v2' => 'value2'));
echo "<br>You can find some more information on our wiki: <a href='http://corebos.org/documentation/doku.php?id=en:devel:corebosws:coreBOSwsDevelopment'>coreBOSwsDevelopment</a>";
Ejemplo n.º 15
0
<?php

// To obtain the identifier of the account you can use the Query operation
$accountId = '3x40';
//sessionId is obtained from loginResult.
$params = "sessionName={$cbSessionID}&operation=retrieve&id={$accountId}";
//Retrieve must be GET Request.
$response = $httpc->fetch_url("{$cbURL}?{$params}");
$dmsg .= debugmsg("Raw response (json) Retrieve", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response Retrieve", $jsonResponse);
//operation was successful get the token from the response.
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('retrieve failed:' . $jsonResponse['error']['message']);
    echo 'retrieve failed!';
} else {
    $retrievedObject = $jsonResponse['result'];
    var_dump($retrievedObject);
}
Ejemplo n.º 16
0
//query to select data from the server.
$query = "select lastname,firstname,account_id,assigned_user_id from Contacts;";
//urlencode to as its sent over http.
$queryParam = urlencode($query);
//sessionId is obtained from login result.
$params = "sessionName={$cbSessionID}&operation=query&query={$queryParam}";
//query must be GET Request.
$response = $httpc->fetch_url("{$cbURL}?{$params}");
$dmsg .= debugmsg("Raw response (json) Query", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response Query", $jsonResponse);
//operation was successful get the token from the response.
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('query failed: ' . $jsonResponse['message']);
    echo 'query failed!';
} else {
    //Array of vtigerObjects
    $retrievedObjects = $jsonResponse['result'];
    if (count($retrievedObjects) > 0) {
        echo "<table class='table table-striped small table-condensed'><tr>";
        foreach ($retrievedObjects[0] as $key => $value) {
            echo "<th>{$key}</th>";
        }
        echo "</tr>";
        foreach ($retrievedObjects as $record) {
            echo "<tr>";
            foreach ($record as $value) {
                echo "<td>&nbsp;{$value}</td>";
            }
<?php

$translate = array('Accounts' => 'Accounts', 'LBL_LIST_ACCOUNT_NAME' => 'LBL_LIST_ACCOUNT_NAME', 'Portal User' => 'Client Portal User');
//sessionId is obtained from loginResult.
$params = array("sessionName" => $cbSessionID, "operation" => 'gettranslation', "totranslate" => json_encode($translate), 'language' => 'es_es', 'module' => 'Contacts');
//Call must be POST Request.
$response = $httpc->send_post_data($cbURL, $params, true);
$dmsg .= debugmsg("Raw response (json) GetTranslation", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response GetTranslation", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('GetTranslation failed: ' . $jsonResponse['error']['message']);
    echo 'GetTranslation failed!';
} else {
    var_dump($jsonResponse['result']);
}
<?php

//Create a Contact and associate with an existing Account.
// To obtain the identifier of the account you can use the Query operation
$accountId = '3x2';
//fill in the details of the contacts.userId is obtained from loginResult.
$contactData = array('lastname' => 'CtoWithAccount', 'assigned_user_id' => $cbUserID, 'homephone' => '123456789', 'account_id' => $accountId);
//encode the object in JSON format to communicate with the server.
$objectJson = json_encode($contactData);
$dmsg .= debugmsg("Create, sending in", $objectJson);
//name of the module for which the entry has to be created.
$moduleName = 'Contacts';
//sessionId is obtained from loginResult.
$params = array("sessionName" => $cbSessionID, "operation" => 'create', "element" => $objectJson, "elementType" => $moduleName);
//Create must be POST Request.
$response = $httpc->send_post_data($cbURL, $params, true);
$dmsg .= debugmsg("Raw response (json) Create", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response Create", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('create failed:' . $jsonResponse['error']['message']);
    echo "Create failed!";
} else {
    $savedObject = $jsonResponse['result'];
    $id = $savedObject['id'];
    var_dump($savedObject);
}
$basModule = 'Products';
$relModule = 'Invoice';
$productDiscriminator = 'ProductLineSalesOrder';
// 'ProductLineSalesOrder'  ProductBundle
$docId = '13x6489';
$basModule = 'Quotes';
$relModule = 'Products';
$productDiscriminator = 'ProductLineSalesOrder';
// 'ProductLineSalesOrder'  ProductBundle
$docId = '9x104127';
$basModule = 'HelpDesk';
$relModule = 'Documents';
$productDiscriminator = 'ProductLineSalesOrder';
// 'ProductLineSalesOrder'  ProductBundle
$params = array("sessionName" => $cbSessionID, "operation" => 'getRelatedRecords', "id" => $docId, "module" => $basModule, "relatedModule" => $relModule, 'queryParameters' => json_encode(array("productDiscriminator" => $productDiscriminator, 'limit' => '3', 'offset' => '0', 'orderby' => '')));
$response = $httpc->send_post_data($cbURL, $params, true);
$dmsg .= debugmsg("Raw response (json) getrelated", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response getrelated", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('getrelated failed:' . $jsonResponse['error']['message']);
    echo 'getrelated failed!';
} else {
    //Get the List of related records.
    $records = $jsonResponse['result']['records'];
    echo "<b>Related Records</b><br>";
    foreach ($records as $record) {
        var_dump($record);
    }
}
<?php

$accountId = '11x20';
$input_array = array('assigned_user_id' => $cbUserID, 'subject' => 'REST salesOrderSubject', 'bill_city' => 'Drachten', 'bill_code' => '9205BB', 'bill_country' => 'Netherlands', 'bill_pobox' => '', 'bill_state' => '', 'bill_street' => 'schuur 86', 'carrier' => NULL, 'contact_id' => NULL, 'conversion_rate' => '1.000', 'currency_id' => '21x1', 'customerno' => NULL, 'description' => 'Producten in deze verkooporder: 2 X Heart of David - songbook 2', 'duedate' => '2014-11-06', 'enable_recurring' => '0', 'end_period' => NULL, 'exciseduty' => '0.000', 'invoicestatus' => 'Approved', 'payment_duration' => NULL, 'pending' => NULL, 'potential_id' => NULL, 'vtiger_purchaseorder' => NULL, 'quote_id' => NULL, 'recurring_frequency' => NULL, 'salescommission' => '0.000', 'ship_city' => 'schuur 86', 'ship_code' => '9205BB', 'ship_country' => 'Netherlands', 'ship_pobox' => NULL, 'ship_state' => NULL, 'ship_street' => 'Drachten', 'account_id' => $accountId, 'sostatus' => 'Approved', 'start_period' => NULL, 'salesorder_no' => NULL, 'terms_conditions' => NULL, 'discount_type_final' => 'percentage', 'hdnDiscountAmount' => '20.000', 'hdnDiscountPercent' => '10.000', 'shipping_handling_charge' => 15, 'shtax1' => 0, 'shtax2' => 8, 'shtax3' => 0, 'adjustmentType' => 'add', 'adjustment' => '40.000', 'taxtype' => 'group', 'pdoInformation' => array(array("productid" => 60, "comment" => 'cmt1', "qty" => 1, "listprice" => 10, 'discount' => 0, "discount_type" => 0, "discount_percentage" => 0, "discount_amount" => 0), array("productid" => 57, "qty" => 2, "comment" => 'cmt2', "listprice" => 10, 'discount' => 1, "discount_type" => 'percentage', "discount_percentage" => 2, "discount_amount" => 0)));
$dmsg .= debugmsg("Create, sending in", $input_array);
//name of the module for which the entry has to be created.
$moduleName = 'SalesOrder';
$create = $cbconn->doCreate($moduleName, $input_array);
//check for whether the requested operation was successful or not.
if ($create) {
    //operation was successful get the response.
    var_dump($create);
} else {
    echo "Create failed<br>";
    $err = $cbconn->lastError();
    echo $err['code'] . ': ' . $err['message'];
}
Ejemplo n.º 21
0
//encode the object in JSON format to communicate with the server.
$objectJson = json_encode($accountData);
//name of the module for which the entry has to be created.
$moduleName = 'Accounts';
//sessionId is obtained from loginResult.
$params = array("sessionName" => $cbSessionID, "operation" => 'create', "element" => $objectJson, "elementType" => $moduleName);
//Create must be POST Request.
$response = $httpc->send_post_data($cbURL, $params, true);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('create failed: ' . $jsonResponse['error']['message']);
    echo "test create record failed!";
} else {
    $createResult = $jsonResponse['result'];
    $params = "operation=sync&modifiedTime={$stime}&sessionName={$cbSessionID}";
    //sync must be GET Request.
    $response = $httpc->fetch_url("{$cbURL}?{$params}");
    $dmsg .= debugmsg("Raw response (json) Sync", $response);
    //decode the json encode response from the server.
    $jsonResponse = json_decode($response, true);
    $dmsg .= debugmsg("Webservice response Sync", $jsonResponse);
    if ($jsonResponse['success'] == false) {
        $dmsg .= debugmsg('query failed: ' . $jsonResponse['message']);
        echo 'query failed!';
    } else {
        //Array of vtigerObjects
        $retrievedObjects = $jsonResponse['result'];
        echo debugmsg("Webservice Sync", $retrievedObjects);
    }
}
<?php

//getchallenge must be a GET request.
$response = $httpc->fetch_url("{$cbURL}?operation=getchallenge&username={$cbUserName}");
$dmsg = debugmsg("Raw response (json) GetChallenge", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response GetChallenge", $jsonResponse);
//check for whether the requested operation was successful or not.
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('getchallenge failed:' . $jsonResponse['error']['message']);
    echo "Challenge failed.";
} else {
    //operation was successful get the token from the response.
    $challengeToken = $jsonResponse['result']['token'];
    echo "Challenge token: {$challengeToken}<br>";
}
<?php

//doglobalsearch request must be POST request.
$restrictionsID = json_encode(array('userId' => $cbUserID, 'accountId' => '11x4', 'contactId' => '12x30'));
$query = 'mary';
$params = array("sessionName" => $cbSessionID, "operation" => 'getSearchResults', "query" => $query, "search_onlyin" => '', 'restrictionids' => $restrictionsID);
//Call must be POST Request.
$response = $httpc->send_post_data($cbURL, $params, true);
$dmsg .= debugmsg("Raw response (json) unifiedsearch", $response);
//decode the json encode response from the server.
$jsonResponse = json_decode($response, true);
$dmsg .= debugmsg("Webservice response unifiedsearch", $jsonResponse);
if ($jsonResponse['success'] == false) {
    $dmsg .= debugmsg('unifiedsearch failed:' . $jsonResponse['error']['message']);
    echo 'unifiedsearch failed!';
} else {
    //Show the results
    $rdos = unserialize($jsonResponse['result']);
    $nrdos = count($rdos);
    echo "<b>SEARCH_CRITERIA: {$query}</b><br>";
    echo "<b>Results: {$nrdos}</b><br>";
    if ($nrdos > 0) {
        echo "<table class='table table-striped small table-condensed'>";
    }
    foreach ($rdos as $modrdo) {
        echo "<tr><td>";
        foreach ($modrdo as $fld) {
            echo "{$fld} |";
        }
        echo "</td></tr>";
    }