// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 *
 *
 * @version $Id$
 * @copyright 2011
 */
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
$site = get_site();
global $CFG, $DB;
require_once 'lib.php';
$entity = $_POST['entity'];
$where = $_POST['where'];
if (md5($entity . $where . $_POST['timestamp'] . $CFG->uaimssecret) == $_POST['mac']) {
    echo generate_valid_xml_from_array($DB->get_records_select($entity, $where), $entity . 's', $entity);
} else {
    echo 'Invalid mac';
}
function generate_xml_from_array($array, $nodename)
{
    $xml = '';
    if (is_array($array) || is_object($array)) {
        foreach ($array as $key => $value) {
            if (is_numeric($key)) {
                $key = $nodename;
            }
            $xml .= '<' . $key . '>' . "" . generate_xml_from_array($value, $nodename) . '</' . $key . '>' . "\n";
        }
    } else {
        $xml = htmlspecialchars($array, ENT_QUOTES) . "";
function xml_encode($obj)
{
    return generate_valid_xml_from_array($obj, get_class($obj));
}
 public function captureAll($differenceData, $creds = null)
 {
     if (!$this->signOn()) {
         return false;
     }
     try {
         $msgBody = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' . '<s:Body>' . '<CaptureAll xmlns="http://schemas.ipcommerce.com/CWS/v2.0/TransactionProcessing">' . '<sessionToken>' . $this->session_token . '</sessionToken>' . $differenceData . '<applicationProfileId>' . $this->appProfileID . '</applicationProfileId>' . '<merchantProfileId>' . $this->merchantProfileID . '</merchantProfileId>' . '<workflowId>' . $this->workflowId . '</workflowId>' . '</CaptureAll>' . '</s:Body>' . '</s:Envelope>';
         $action = 'http://schemas.ipcommerce.com/CWS/v2.0/TransactionProcessing/ICwsTransactionProcessing/CaptureAll';
         $response = curl_soap($msgBody, $this->txn, $action);
         if (isset($response['Body']['Fault'])) {
             $xmlFault = generate_valid_xml_from_array($response);
             throw new SoapFault($response['Body']['Fault']['faultcode'], $response['Body']['Fault']['faultstring'], null, $response['Body']['Fault']['detail'], $xmlFault);
         }
         return $response['Body']['CaptureAllResponse']['CaptureAllResult'];
     } catch (SoapFault $e) {
         echo 'SERVER ERROR: Error trying to Capture.<br/>';
         $errors = handleTxnFault($e, $xmlFault);
         echo $errors;
         exit;
     }
 }