示例#1
0
////////////////////////////////////////////////////////////////////////////////
// Define the operations to perform (one operation per call the rest service)
//
$aOperations = array(array('operation' => 'list_operations'), array('operation' => 'core/create', 'comment' => 'Synchronization from blah...', 'class' => 'UserRequest', 'output_fields' => 'id, friendlyname', 'fields' => array('org_id' => "SELECT Organization WHERE name = 'Demo'", 'caller_id' => array('name' => 'monet', 'first_name' => 'claude'), 'title' => 'issue blah', 'description' => 'something happened')), array('operation' => 'core/update', 'comment' => 'Synchronization from blah...', 'class' => 'UserRequest', 'key' => 'SELECT UserRequest WHERE id=1', 'output_fields' => 'id, friendlyname, title', 'fields' => array('title' => 'Issue #' . rand(0, 100), 'contacts_list' => array(array('role' => 'fireman #' . rand(0, 100), 'contact_id' => array('finalclass' => 'Person', 'name' => 'monet', 'first_name' => 'claude'))))), array('operation' => 'core/get', 'class' => 'UserRequest', 'key' => 'SELECT UserRequest', 'output_fields' => 'id, friendlyname, title, contacts_list'), array('operation' => 'core/delete', 'comment' => 'Cleanup for synchro with...', 'class' => 'UserRequest', 'key' => 'SELECT UserRequest WHERE org_id = 2', 'simulate' => true), array('operation' => 'core/apply_stimulus', 'comment' => 'Synchronization from blah...', 'class' => 'UserRequest', 'key' => 1, 'stimulus' => 'ev_assign', 'fields' => array('team_id' => 15, 'agent_id' => 9), 'output_fields' => 'id, friendlyname, title, contacts_list'), array('operation' => 'core/get_related', 'class' => 'Server', 'key' => 'SELECT Server', 'relation' => 'impacts', 'depth' => 4));
if (true) {
    echo "Please edit the sample script and configure the server URL";
    exit;
} else {
    $sUrl = "http://localhost/trunk/webservices/rest.php?version=1.1";
}
$aData = array();
$aData['auth_user'] = '******';
$aData['auth_pwd'] = 'admin';
foreach ($aOperations as $iOp => $aOperation) {
    echo "======================================\n";
    echo "Operation #{$iOp}: " . $aOperation['operation'] . "\n";
    $aData['json_data'] = json_encode($aOperation);
    echo "--------------------------------------\n";
    echo "Input:\n";
    print_r($aOperation);
    $response = DoPostRequest($sUrl, $aData);
    $aResults = json_decode($response);
    if ($aResults) {
        echo "--------------------------------------\n";
        echo "Reply:\n";
        print_r($aResults);
    } else {
        echo "ERROR rest.php replied:\n";
        echo $response;
    }
}
 $message = "";
 $piece = "";
 $name = @$_POST['piece_type'];
 //@ remove the warning alert
 if (is_array($name) || is_object($piece)) {
     foreach ($name as $piece) {
         //For each piece received, concatain message string
         $message .= $piece . ";";
         //.= concatains instead of replaces
     }
 }
 $message = trim($message, ";");
 //Remove the last ';' to send a valable message
 if ($message != null) {
     //Condition to see if message is null
     DoPostRequest($urlPost, $message);
     //If message isn't empty, function is executed
     echo '<script language="Javascript">document.location.replace("./done.php");</script>';
     //Redirect user to done.php
 } else {
     //Else function isn't, and a popup appears
     ?>
         <script type="text/javascript"> //JavaScript function to shox popup
             function run(){ //Create function
                 alert("No Piece Selected !"); //Popup text
             }
            <?php 
     echo "run();";
     //Execute function
     ?>
         </script>