private function printNode($node, $parentKey = null)
 {
     $systemFields = array("Id", "IsDeleted", "CreatedById", "CreatedDate", "LastModifiedById", "LastModifiedDate", "SystemModstamp");
     // TODO: remove this hacky special casing
     $escape = !($this->name == "listMetadataTree" && ($parentKey == "parentXmlName" || $parentKey == "childXmlNames"));
     foreach ($node as $nodeKey => $nodeValue) {
         $nodeKey = $escape ? htmlspecialchars($nodeKey) : $nodeKey;
         // TODO: replace special case with client defined strategies
         if ($this->name == "describeTree") {
             if (isset($parentKey) && strpos($parentKey, "Fields") > -1) {
                 if (in_array($nodeKey, $systemFields)) {
                     $nodeKey = "<span class='highlightSystemField'>{$nodeKey}</span>";
                 } else {
                     if (substr_compare($nodeKey, "__c", -3) == 0) {
                         $nodeKey = "<span class='highlightCustomField'>{$nodeKey}</span>";
                     }
                 }
             }
         }
         if (is_array($nodeValue) || is_object($nodeValue)) {
             if (is_numeric($nodeKey)) {
                 $nodeKey = $nodeKey + 1;
             }
             print "<li>{$nodeKey}<ul style='display:none;'>\n";
             if (is_array($nodeValue) && count($nodeValue) == 1 && isset($nodeValue[0]) && is_array($nodeValue[0])) {
                 $this->printNode($nodeValue[0], $nodeKey);
                 // flatten single element arrays
             } else {
                 $this->printNode($nodeValue, $nodeKey);
             }
             print "</ul></li>\n";
         } else {
             $nodeKey = is_numeric($nodeKey) ? "" : $nodeKey . ": ";
             if (is_bool($nodeValue)) {
                 $nodeValue = $nodeValue == 1 ? "<span class='trueColor'>true</span>" : "<span class='falseColor'>false</span>";
             } else {
                 $nodeValue = $escape ? htmlspecialchars($nodeValue) : $nodeValue;
                 $nodeValue = $this->containsDates ? localizeDateTimes($nodeValue) : $nodeValue;
                 $nodeValue = $this->containsIds ? addLinksToIds($nodeValue) : $nodeValue;
             }
             print "<li>{$nodeKey}<span style='font-weight:bold;'>{$nodeValue}</span></li>\n";
         }
     }
 }
Example #2
0
/**
 * Prints field mapping setter row
 * for non-Id fields
 *
 * @param $field
 * @param $csvArray
 */
function printPutFieldForMapping($field, $csvArray, $showRefCol, $currentRecord, $editable = true)
{
    print "<tr";
    if ($editable && !$field->nillable && !$field->defaultedOnCreate) {
        print " style='color: red;'";
    }
    print "><td style='cursor: pointer;' onmouseover=\"Tip('Type: " . htmlspecialchars($field->type, ENT_QUOTES) . " <br/> Length: " . htmlspecialchars($field->length, ENT_QUOTES) . "')\">" . htmlspecialchars($field->name, ENT_QUOTES) . ($currentRecord && $field->type == "base64" ? "&nbsp;<em style='color:grey'>(current value not retrieved)</em>" : "") . "</td>";
    if ($csvArray) {
        print "<td><select name='{$field->name}' style='width: 100%;'>";
        print "    <option value=''></option>\n";
        foreach ($csvArray[0] as $col) {
            print "<option value='{$col}'";
            if (strtolower($col) == strtolower($field->name)) {
                print " selected='true' ";
            }
            print ">{$col}</option>\n";
        }
        print "</select></td>";
    } else {
        $fieldName = htmlspecialchars($field->name, ENT_QUOTES);
        $fieldValue = "";
        if ($currentRecord != null && isset($currentRecord->fields->{$fieldName})) {
            $fieldValue = htmlspecialchars($currentRecord->fields->{$fieldName});
        }
        print "<td>" . ($editable ? "<input name='{$field->name}' style='width: 97%;' value=\"{$fieldValue}\"/>" : ($field->type == 'datetime' ? localizeDateTimes($fieldValue) : addLinksToIds($fieldValue))) . "</td>";
    }
    if ($showRefCol && WorkbenchConfig::get()->value("showReferenceBy")) {
        if (isset($field->referenceTo) && isset($field->relationshipName)) {
            $describeRefObjResult = WorkbenchContext::get()->describeSObjects($field->referenceTo);
            printRefField($field, $describeRefObjResult);
        } else {
            print "<td>&nbsp;</td>\n";
        }
    }
    print "</tr>\n";
}
 function createQueryResultsMatrix($records, $matrixCols, $matrixRows)
 {
     $allColNames = array();
     $allRowNames = array();
     foreach ($records as $rawRecord) {
         $record = new SObject($rawRecord);
         $data = "";
         if (isset($record->Id)) {
             $record->fields->Id = $record->Id;
         }
         foreach ($record->fields as $fieldName => $fieldValue) {
             if ($fieldName == $matrixCols || $fieldName == $matrixRows) {
                 continue;
             }
             $data .= "<em>" . htmlspecialchars($fieldName) . ":</em>  " . htmlspecialchars($fieldValue, ENT_QUOTES) . "<br/>";
         }
         foreach ($record->fields as $rowName => $rowValue) {
             if ($rowName != $matrixRows) {
                 continue;
             }
             foreach ($record->fields as $colName => $colValue) {
                 if ($colName != $matrixCols) {
                     continue;
                 }
                 $allColNames["{$colValue}"] = $colValue;
                 $allRowNames["{$rowValue}"] = $rowValue;
                 $matrix["{$rowValue}"]["{$colValue}"][] = $data;
             }
         }
     }
     if (count($allColNames) == 0 || count($allRowNames) == 0) {
         displayWarning("No records match matrix column and row selections.", false, true);
         return;
     }
     $table = "<table id='query_results_matrix' border='1' class='" . getTableClass() . "'>";
     $hw = false;
     foreach ($allRowNames as $rowName) {
         if (!$hw) {
             $table .= "<tr><td></td>";
             foreach ($allColNames as $colName) {
                 $table .= "<th>" . htmlspecialchars($colName) . "</th>";
             }
             $table .= "</tr>";
             $hw = true;
         }
         $table .= "<tr>";
         $table .= "<th>" . htmlspecialchars($rowName) . "</th>";
         foreach ($allColNames as $colName) {
             $table .= "<td>";
             if (isset($matrix["{$rowName}"]["{$colName}"])) {
                 foreach ($matrix["{$rowName}"]["{$colName}"] as $data) {
                     $table .= "<div class='matrixItem'" . ($data == "" ? "style='width: 0px;'" : "") . ">{$data}</div>";
                 }
             }
             $table .= "</td>";
         }
         $table .= "</tr>";
     }
     $table .= "</table>";
     return localizeDateTimes($table);
 }
function printStatusCell($resultName, $resultValue)
{
    print "<td style='text-align: right; padding-right: 2em; font-weight: bold;'>" . unCamelCase($resultName) . "</td><td>";
    if (is_bool($resultValue)) {
        print $resultValue ? "true" : "false";
    } else {
        print localizeDateTimes($resultValue);
    }
    print "</td>";
}
Example #5
0
function displaySearchResult($records, $searchTimeElapsed)
{
    //Check if records were returned
    if ($records) {
        if (WorkbenchConfig::get()->value("areTablesSortable")) {
            addFooterScript("<script type='text/javascript' src='" . getPathToStaticResource('/script/sortable.js') . "></script>");
        }
        try {
            print "<a name='sr'></a><div style='clear: both;'><br/><h2>Search Results</h2>\n";
            print "<p>Returned " . count($records) . " total record";
            if (count($records) !== 1) {
                print 's';
            }
            print " in ";
            printf("%01.3f", $searchTimeElapsed);
            print " seconds:</p>";
            $searchResultArray = array();
            foreach ($records as $record) {
                $recordObject = new Sobject($record->record);
                $searchResultArray[$recordObject->type][] = $recordObject;
            }
            foreach ($searchResultArray as $recordSetName => $records) {
                echo "<h3>{$recordSetName}</h3>";
                print "<table id='" . $recordSetName . "_results' class='" . getTableClass() . "'>\n";
                //Print the header row on screen
                $record0 = $records[0];
                print "<tr><th></th>";
                //If the user queried for the Salesforce ID, this special method is nessisary
                //to export it from the nested SOAP message. This will always be displayed
                //in the first column regardless of search order
                if (isset($record0->Id)) {
                    print "<th>Id</th>";
                }
                if ($record0->fields) {
                    foreach ($record0->fields->children() as $field) {
                        print "<th>";
                        print htmlspecialchars($field->getName(), ENT_QUOTES);
                        print "</th>";
                    }
                } else {
                    print "</td></tr>";
                }
                print "</tr>\n";
                //Print the remaining rows in the body
                $rowNum = 1;
                foreach ($records as $record) {
                    print "<tr><td>{$rowNum}</td>";
                    $rowNum++;
                    //Another check if there are ID columns in the body
                    if (isset($record->Id)) {
                        print "<td>" . addLinksToIds($record->Id) . "</td>";
                    }
                    //Print the non-ID fields
                    if (isset($record->fields)) {
                        foreach ($record->fields as $datum) {
                            print "<td>";
                            if ($datum) {
                                print localizeDateTimes(addLinksToIds(htmlspecialchars($datum, ENT_QUOTES)));
                            } else {
                                print "&nbsp;";
                            }
                            print "</td>";
                        }
                        print "</tr>\n";
                    } else {
                        print "</td></tr>\n";
                    }
                }
                print "</table>&nbsp;<p/>";
            }
            print "</div>\n";
        } catch (Exception $e) {
            $errors = null;
            $errors = $e->getMessage();
            print "<p />";
            displayError($errors, false, true);
        }
    } else {
        print "<p><a name='sr'>&nbsp;</a></p>";
        displayError("Sorry, no records returned.");
    }
    include_once 'footer.php';
}
    print "<tr>" . "<td class='dataLabel'>API Processing</td><td class='dataValue'>" . $jobInfo->getApiActiveProcessingTime() . " ms</td>" . "<td class='dataLabel'>Apex Processing</td><td class='dataValue'>" . $jobInfo->getApexProcessingTime() . " ms</td>" . "<td class='dataLabel'>Total Processing</td><td class='dataValue'>" . $jobInfo->getTotalProcessingTime() . " ms</td>" . "</tr>";
}
print "<tr>" . "<td class='dataLabel'>Created</td><td class='dataValue'>" . localizeDateTimes($jobInfo->getCreatedDate(), $timeOnlyFormat) . "</td>" . "<td class='dataLabel'>Last Modified</td><td class='dataValue'>" . localizeDateTimes($jobInfo->getSystemModstamp(), $timeOnlyFormat) . "</td>" . "<td class='dataLabel'>Retries</td><td class='dataValue'>" . $jobInfo->getNumberRetries() . "</td>" . "</tr>";
print "</table>";
print "<p>&nbsp;</p>";
if (count($batchInfos) > 0) {
    print "<h3>Batches</h3>";
    print "<table cellpadding='4' width='100%' class='lightlyBoxed'>";
    print "<tr>" . "<th>&nbsp;</th>" . "<th>Id</th>" . "<th>Status</th>" . "<th>Processed</th>" . (WorkbenchContext::get()->isApiVersionAtLeast(19.0) ? "<th>Failed</th>" : "") . "<th>Created</th>" . "<th>Last Modified</th>" . "</tr>";
    foreach ($batchInfos as $batchInfo) {
        print "<tr><td class='dataValue'>";
        if ($batchInfo->getState() == "Completed" || $batchInfo->getState() == "Failed") {
            $batchResultList = array(null);
            // default to an array of one null
            if ($jobInfo->getOpertion() == 'query' && $batchInfo->getState() == "Completed") {
                $batchResultList = $asyncConnection->getBatchResultList($jobInfo->getId(), $batchInfo->getId());
            }
            foreach ($batchResultList as $resultId) {
                print "<a href='downloadAsyncBatch.php?op=result&jobId=" . $jobInfo->getId() . "&batchId=" . $batchInfo->getId() . "&resultId=" . $resultId . "'>" . "<img src='" . getPathToStaticResource('/images/downloadIcon' . $batchInfo->getState() . '.gif') . "' border='0' onmouseover=\"Tip('Download " . $batchInfo->getState() . " Batch Results')\"/>" . "</a><br/>";
            }
        } else {
            print "&nbsp;";
        }
        print "</td>";
        $processingTimeDetails = "API Processing: " . $batchInfo->getApiActiveProcessingTime() . " ms<br/>" . "Apex Processing: " . $batchInfo->getApexProcessingTime() . " ms<br/>" . "Total Processing: " . $batchInfo->getTotalProcessingTime() . " ms<br/>";
        print "<td class='dataValue'>" . (WorkbenchContext::get()->isApiVersionAtLeast(19.0) ? "<a href='downloadAsyncBatch.php?op=request&jobId=" . $jobInfo->getId() . "&batchId=" . $batchInfo->getId() . "' onmouseover=\"Tip('Download Batch Request')\"/>" . $batchInfo->getId() . "</a>" : $batchInfo->getId()) . "</td>" . "<td class='dataValue'>" . $batchInfo->getState() . ($batchInfo->getStateMessage() != "" ? ": " . $batchInfo->getStateMessage() : "") . "</td>" . (WorkbenchContext::get()->isApiVersionAtLeast(19.0) ? "<td class='dataValue pseudoLink' style='cursor: default' onmouseover=\"Tip('{$processingTimeDetails}')\"/>" : "<td class='dataValue'>") . $batchInfo->getNumberRecordsProcessed() . ($batchInfo->getNumberRecordsProcessed() == "1" ? " record" : " records") . "</td>" . (WorkbenchContext::get()->isApiVersionAtLeast(19.0) ? "<td class='dataValue'>" . $batchInfo->getNumberRecordsFailed() . ($batchInfo->getNumberRecordsFailed() == "1" ? " record" : " records") . "</td>" : "") . "<td class='dataValue'>" . localizeDateTimes($batchInfo->getCreatedDate(), $timeOnlyFormat) . "</td>" . "<td class='dataValue'>" . localizeDateTimes($batchInfo->getSystemModstamp(), $timeOnlyFormat) . "</td>";
        print "</tr>";
    }
    print "</table>";
}
include_once 'footer.php';