本文整理汇总了PHP中Dataface_Application::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Dataface_Application::getResponse方法的具体用法?PHP Dataface_Application::getResponse怎么用?PHP Dataface_Application::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dataface_Application
的用法示例。
在下文中一共展示了Dataface_Application::getResponse方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeUpdate
function beforeUpdate(&$record)
{
if ($record->val('RegistrantName') == 'Larry2') {
return PEAR::raiseError("Larry2 doesn't like to be updated, so we won't update him.", DATAFACE_E_NOTICE);
} else {
if ($record->val('RegistrantName') == 'Larry3') {
return PEAR::raiseError("Larry3 cannot be added. Major errors!!!", DATAFACE_E_ERROR);
} else {
$response =& Dataface_Application::getResponse();
$response['--msg'] = @$response['--msg'] . "\nAll systems are good for update.";
return true;
}
}
}
示例2: handle
function handle(&$params)
{
import('Dataface/TranslationForm.php');
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
$resultSet =& $app->getResultSet();
$source = isset($_REQUEST['-sourceLanguage']) ? $_REQUEST['-sourceLanguage'] : $app->_conf['default_language'];
$dest = isset($_REQUEST['-destinationLanguage']) ? $_REQUEST['-destinationLanguage'] : null;
if ($resultSet->found() > 0) {
$form = new Dataface_TranslationForm($query['-table'], $source, $dest);
/*
* There is either a result to edit, or we are creating a new record.
*
*/
$res = $form->_build();
if (PEAR::isError($res)) {
throw new Exception($res->toString() . Dataface_Error::printStackTrace(), E_USER_ERROR);
}
/*
*
* We need to add the current GET parameter flags (the GET vars starting with '-') so
* that the controller knows to pass control to this method again upon form submission.
*
*/
foreach ($query as $key => $value) {
if (strpos($key, '-') === 0) {
$form->addElement('hidden', $key);
$form->setDefaults(array($key => $value));
}
}
/*
* Store the current query string (the portion after the '?') in the form, so we
* can retrieve it after and redirect back to our original location.
*/
$form->addElement('hidden', '-query');
$form->setDefaults(array('-action' => $query['-action'], '-query' => $_SERVER['QUERY_STRING']));
/*
*
* We have to deal with 3 cases.
* 1) The form has not been submitted.
* 2) The form was submitted but didn't validate (ie: it had some bad input)
* 3) The form was submitted and was validated.
*
* We deal with Case 3 first...
*
*/
if ($form->validate()) {
/*
*
* The form was submitted and it validated ok. We now process it (ie: save its contents).
*
*/
$app->clearMessages();
$result = $form->process(array(&$form, 'save'));
$success = true;
$response =& Dataface_Application::getResponse();
if (!$result) {
error_log("Error occurred in save: " . xf_db_error($app->db()) . Dataface_Error::printStackTrace());
throw new Exception("Error occurred in save. See error log for details.");
} else {
if (PEAR::isError($result) && !Dataface_Error::isNotice($result)) {
//echo "Error..";
if (Dataface_Error::isDuplicateEntry($result)) {
return $result;
} else {
//echo "not dup entry"; exit;
throw new Exception($result->toString(), E_USER_ERROR);
}
} else {
if (Dataface_Error::isNotice($result)) {
$app->addError($result);
//$response['--msg'] = @$response['--msg'] ."\n".$result->getMessage();
$success = false;
}
}
}
if ($success) {
/*
*
* The original query string will have the -new flag set. We need to remove this
* flag so that we don't redirect the user to create another new record.
*
*/
$vals = $form->exportValues();
$vals['-query'] = preg_replace('/[&\\?]-new=[^&]+/i', '', $vals['-query']);
$msg = implode("\n", $app->getMessages());
//$msg =@$response['--msg'];
$msg = urlencode(Dataface_LanguageTool::translate('Record successfully translated', "Record successfully translated.<br>") . $msg);
$link = $_SERVER['HOST_URI'] . DATAFACE_SITE_HREF . '?' . $vals['-query'] . '&--msg=' . $msg;
/*
*
* Redirect the user to the appropriate record.
*
*/
$app->redirect($link);
}
}
ob_start();
$form->display();
$out = ob_get_contents();
//.........这里部分代码省略.........
示例3: handle
function handle(&$params)
{
import('Dataface/FormTool.php');
import('Dataface/QuickForm.php');
$formTool =& Dataface_FormTool::getInstance();
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
$resultSet =& $app->getResultSet();
$currentRecord =& $app->getRecord();
$currentTable =& Dataface_Table::loadTable($query['-table']);
if (!isset($query['--tab']) and count($currentTable->tabs($currentRecord)) > 1) {
$tabs = $currentTable->tabs($currentRecord);
uasort($tabs, array($formTool, '_sortTabs'));
list($query['--tab']) = array_keys($tabs);
} else {
if (count($currentTable->tabs($currentRecord)) <= 1) {
unset($query['--tab']);
}
}
$includedFields = null;
// Null for all fields
if (@$query['-fields']) {
$includedFields = explode(' ', $query['-fields']);
}
/*
*
* Create the quickform for the current record.
*
*/
//$form = new Dataface_QuickForm($query['-table'], $app->db(), $query);
if ($resultSet->found() > @$query['-cursor']) {
$form = $formTool->createRecordForm($currentRecord, false, @$query['--tab'], $query, $includedFields);
/*
* There is either a result to edit, or we are creating a new record.
*
*/
$res = $form->_build();
if (PEAR::isError($res)) {
error_log($res->toString() . implode("\n", $res->getBacktrace()));
throw new Exception("An error occurred while building the edit form. See error log for details.", E_USER_ERROR);
}
$formTool->decorateRecordForm($currentRecord, $form, false, @$query['--tab']);
/*
*
* We need to add the current GET parameter flags (the GET vars starting with '-') so
* that the controller knows to pass control to this method again upon form submission.
*
*/
foreach ($query as $key => $value) {
if (strpos($key, '-') === 0) {
$form->addElement('hidden', $key);
$form->setDefaults(array($key => $value));
}
}
/*
* Store the current query string (the portion after the '?') in the form, so we
* can retrieve it after and redirect back to our original location.
*/
$form->addElement('hidden', '-query');
$form->setDefaults(array('-action' => $query['-action'], '-query' => $_SERVER['QUERY_STRING']));
/*
*
* We have to deal with 3 cases.
* 1) The form has not been submitted.
* 2) The form was submitted but didn't validate (ie: it had some bad input)
* 3) The form was submitted and was validated.
*
* We deal with Case 3 first...
*
*/
if ($formTool->validateRecordForm($currentRecord, $form, false, @$query['--tab'])) {
/*
*
* The form was submitted and it validated ok. We now process it (ie: save its contents).
*
*/
$app->clearMessages();
$formTool->handleTabSubmit($currentRecord, $form, @$query['--tab']);
if (!isset($query['--tab'])) {
// If we aren't using tabs we just do it the old way.
// (If it ain't broke don't fix it
$result = $form->process(array(&$form, 'save'));
} else {
// If we are using tabs, we will use the formtool's
// session aware saving function
$result = $formTool->saveSession($currentRecord);
}
$success = true;
$response =& Dataface_Application::getResponse();
if (!$result) {
error_log("Error occurred in save: " . xf_db_error($app->db()) . Dataface_Error::printStackTrace());
throw new Exception("An error occurred while attempting to save the record. See error log for details.", E_USER_ERROR);
} else {
if (PEAR::isError($result) && !Dataface_Error::isNotice($result)) {
if (Dataface_Error::isDuplicateEntry($result)) {
$app->addError($result);
$success = false;
} else {
error_log($result->toString() . implode("\n", $result->getBacktrace()));
throw new Exception("An error occurred while attempting to save the record. See error log for details.", E_USER_ERROR);
//.........这里部分代码省略.........
示例4: handle
function handle(&$params)
{
import('Dataface/ExistingRelatedRecordForm.php');
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
$resultSet =& $app->getResultSet();
//$record =& $app->getRecord(); // loads the current record
if (!isset($query['-relationship'])) {
return PEAR::raiseError(Dataface_LanguageTool::translate('Error: No relationship specified', 'Error. No relationship was specified when trying to add existing related record.'), DATAFACE_E_NOTICE);
}
$record = null;
$form = new Dataface_ExistingRelatedRecordForm($record, $query['-relationship']);
$res = $form->_build();
if (PEAR::isError($res)) {
return Dataface_Error::permissionDenied($res->getMessage());
}
/*
*
* We need to add the current GET parameter flags (the GET vars starting with '-') so
* that the controller knows to pass control to this method again upon form submission.
*
*/
foreach ($query as $key => $value) {
if (strpos($key, '-') === 0) {
$form->addElement('hidden', $key);
$form->setDefaults(array($key => $value));
}
}
/*
* Store the current query string (the portion after the '?') in the form, so we
* can retrieve it after and redirect back to our original location.
*/
$form->addElement('hidden', '-query');
$form->setDefaults(array('-action' => $query['-action'], '-query' => $_SERVER['QUERY_STRING']));
if (!$form->_record || !is_a($form->_record, 'Dataface_Record')) {
trigger_error(Dataface_LanguageTool::translate('Fatal Error', 'Fatal Error: Form should have loaded record but the record was null. ' . Dataface_Error::printStackTrace(), array('stack_trace' => Dataface_Error::printStackTrace(), 'msg' => 'Form should have loaded record but the record was null.')), E_USER_ERROR);
}
if (!Dataface_PermissionsTool::checkPermission('add existing related record', $form->_record)) {
return Dataface_Error::permissionDenied(Dataface_LanguageTool::translate('Error: Permission denied adding existing related record', 'Permission Denied. You do not have sufficient permissions to add an existing related record. Required permission: "add existing related record", but you have only been granted permissions: "' . implode(',', $form->_record->getPermissions()) . '".', array('required_permission' => 'add existing related record', 'granted_permissions' => implode(',', $form->_record->getPermissions()))));
}
if ($form->validate()) {
$res = $form->process(array(&$form, 'save'), true);
$response =& Dataface_Application::getResponse();
if (PEAR::isError($res) && !Dataface_Error::isNotice($res)) {
return $res;
} else {
if (Dataface_Error::isNotice($res)) {
//$response['--msg'] = @$response['--msg'] . "\n".$res->getMessage();
$app->addError(PEAR::raiseError(df_translate('Failed to add record because of errors', 'Failed to add record to relationship because of the following errors:'), DATAFACE_E_NOTICE));
$app->addError($res);
$success = false;
} else {
$success = true;
}
}
if ($success) {
import('Dataface/Utilities.php');
Dataface_Utilities::fireEvent('after_action_existing_related_record');
$fquery = array('-action' => 'browse');
$msg = Dataface_LanguageTool::translate('Record successfully added to relationship', "The record has been successfully added to the " . $query['-relationship'] . " relationship.\n", array('relationship' => $query['-relationship']));
$msg = urlencode(trim(($success ? $msg : '') . @$response['--msg']));
$vals = $form->exportValues();
if (isset($vals['--redirect'])) {
$qmark = strpos($vals['--redirect'], '?') !== false ? '&' : '?';
header('Location: ' . $vals['--redirect'] . $qmark . '--msg=' . $msg);
exit;
}
foreach ($vals['__keys__'] as $key => $value) {
$fquery[$key] = "=" . $value;
}
$link = Dataface_LinkTool::buildLink($fquery);
header("Location: {$link}" . "&--msg=" . $msg);
exit;
}
}
ob_start();
$form->display();
$out = ob_get_contents();
ob_end_clean();
$context = array('form' => $out);
if (isset($query['-template'])) {
$template = $query['-template'];
} else {
if (isset($params['action']['template'])) {
$template = $params['action']['template'];
} else {
$template = 'Dataface_Add_Existing_Related_Record.html';
}
}
df_display($context, $template, true);
}
示例5: handle
function handle(&$params)
{
$app = Dataface_Application::getInstance();
header('Content-type: text/html; charset=' . $app->_conf['oe']);
$record =& $app->getRecord();
$query =& $app->getQuery();
if (isset($_REQUEST['-form-id'])) {
$formid = $_REQUEST['-form-id'];
} else {
$formid = 'ajax-form-' . rand();
}
// First let's figure out what kind of form this is
$form_type = @$_REQUEST['-form-type'];
$form = null;
if (isset($_REQUEST['-fields'])) {
$fields = explode(',', $_REQUEST['-fields']);
} else {
$fields = null;
}
switch ($form_type) {
case 'new':
$form = df_create_new_record_form($query['-table'], $fields);
$form->_build();
break;
case 'edit':
$form = df_create_edit_record_form($query['-table'], $fields);
break;
case 'new_related_record':
$form = df_create_new_related_record_form($record, $query['-relationship'], $fields);
break;
case 'existing_related_record':
$form = df_create_existing_related_record_form($record, $query['-relationship']);
break;
case 'composite':
import('Dataface/CompositeForm.php');
$form = new Dataface_CompositeForm($fields);
$form->build();
break;
default:
@(include_once 'forms/' . $form_type . '.php');
if (!class_exists('forms_' . $form_type)) {
return PEAR::raiseError('Could not find form of type "' . $form_type . '".', DATAFACE_E_ERROR);
}
$classname = 'forms_' . $form_type;
$form = new $classname($fields);
break;
}
// We want the form to be submitted to the embedded iframe
$form->updateAttributes(array('target' => $formid . '-target', 'accept-charset' => $app->_conf['ie']));
$formparams = preg_grep('/^-[^\\-].*/', array_keys($query));
foreach ($formparams as $param) {
$form->addElement('hidden', $param);
$form->setDefaults(array($param => $query[$param]));
}
$form->addElement('hidden', '-form-id');
$form->setDefaults(array('-form-id' => $formid));
// Now that we have our form, we can do our thing with it.
if ($form->validate()) {
/*
*
* The form was submitted and it validated ok. We now process it (ie: save its contents).
*
*/
$app->clearMessages();
$result = $form->process(array(&$form, 'save'));
$success = true;
$response =& Dataface_Application::getResponse();
if (!$result) {
trigger_error("Error occurred in save: " . xf_db_error($app->db()) . Dataface_Error::printStackTrace(), E_USER_ERROR);
exit;
} else {
if (PEAR::isError($result) && !Dataface_Error::isNotice($result)) {
if (Dataface_Error::isDuplicateEntry($result)) {
return $result;
} else {
trigger_error($result->toString() . Dataface_Error::printStackTrace(), E_USER_ERROR);
exit;
}
} else {
if (Dataface_Error::isNotice($result)) {
$app->addError($result);
$success = false;
}
}
}
if ($success) {
import('Dataface/Utilities.php');
Dataface_Utilities::fireEvent('after_action_ajax_form');
$msg = implode("\n", $app->getMessages());
//$msg =@$response['--msg'];
$msg = urlencode(Dataface_LanguageTool::translate('Record successfully saved', "Record successfully saved.<br>") . $msg);
// We need to output the success content.
// This could be in any of the following formats:
// 1. HTML --- actually not yet.. let's just do JSON
// 2. JSON
// 3. XML --- not yet.. just JSON for now.
$targetid = @$_REQUEST['-target-id'];
// This should:
// 1. Get the target element.
// 2. Go through the element's subtree and replace
//.........这里部分代码省略.........
示例6: handle
function handle()
{
import('Dataface/FormTool.php');
import('Dataface/QuickForm.php');
$formTool =& Dataface_FormTool::getInstance();
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
$new = true;
$includedFields = null;
// Null for all fields
if (@$query['-fields']) {
$includedFields = explode(' ', $query['-fields']);
}
$currentRecord = new Dataface_Record($query['-table'], array());
$currentTable =& Dataface_Table::loadTable($query['-table']);
$app->setPageTitle(df_translate('actions.new.label', 'New ' . $currentTable->getSingularLabel(), array('tableObj' => $currentTable)));
if (!isset($query['--tab']) and count($currentTable->tabs($currentRecord)) > 1) {
$tabs = $currentTable->tabs($currentRecord);
uasort($tabs, array($formTool, '_sortTabs'));
list($query['--tab']) = array_keys($tabs);
} else {
if (count($currentTable->tabs($currentRecord)) <= 1) {
unset($query['--tab']);
}
}
$form = $formTool->createRecordForm($currentRecord, true, @$query['--tab'], $query, $includedFields);
//$form = new Dataface_QuickForm($query['-table'], $app->db(), $query, '',$new);
$res = $form->_build();
if (PEAR::isError($res)) {
error_log($res->toString() . Dataface_Error::printStackTrace());
throw new Exception("Error occurred while building the new record form. See error log for details.", E_USER_ERROR);
}
$formTool->decorateRecordForm($currentRecord, $form, true, @$query['--tab']);
/*
*
* We need to add the current GET parameter flags (the GET vars starting with '-') so
* that the controller knows to pass control to this method again upon form submission.
*
*/
foreach ($query as $key => $value) {
if (strpos($key, '-') === 0) {
$form->addElement('hidden', $key);
$form->setDefaults(array($key => $value));
}
}
/*
* Store the current query string (the portion after the '?') in the form, so we
* can retrieve it after and redirect back to our original location.
*/
$form->addElement('hidden', '-query');
$form->setDefaults(array('-action' => $query['-action'], '-query' => $_SERVER['QUERY_STRING']));
/*
*
* We have to deal with 3 cases.
* 1) The form has not been submitted.
* 2) The form was submitted but didn't validate (ie: it had some bad input)
* 3) The form was submitted and was validated.
*
* We deal with Case 3 first...
*
*/
if ($formTool->validateRecordForm($currentRecord, $form, true, @$query['--tab'])) {
/*
*
* The form was submitted and it validated ok. We now process it (ie: save its contents).
*
*/
$formTool->handleTabSubmit($currentRecord, $form, @$query['--tab']);
if (!isset($query['--tab'])) {
// If we aren't using tabs we just do it the old way.
// (If it ain't broke don't fix it
$result = $form->process(array(&$form, 'save'));
} else {
// If we are using tabs, we will use the formtool's
// session aware saving function
$result = $formTool->saveSession($currentRecord, true);
}
$success = true;
$response =& Dataface_Application::getResponse();
if (!$result) {
throw new Exception("Error occurred in save: " . xf_db_error($app->db()), E_USER_ERROR);
} else {
if (PEAR::isError($result) && !Dataface_Error::isNotice($result)) {
//echo "Error..";
if (Dataface_Error::isDuplicateEntry($result)) {
$success = false;
$form->_errors[] = $result->getMessage();
} else {
//echo "not dup entry"; exit;
error_log($result->toString() . "\n" . implode("\n", $result->getBacktrace()));
throw new Exception("An error occurred while attempting to save the record. See server error log for details.", E_USER_ERROR);
}
} else {
if (Dataface_Error::isNotice($result)) {
$app->addError($result);
$success = false;
}
}
}
if ($success) {
//.........这里部分代码省略.........
示例7: handle
function handle(&$params)
{
import('Dataface/RemoveRelatedRecordForm.php');
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
$record = null;
//& new Dataface_Record($this->_tablename, $_REQUEST['--__keys__']);
// let the form handle the loading of the record
$form = new Dataface_RemoveRelatedRecordForm($record, $query['-relationship']);
if (!$form->_record) {
// the record could not be loaded
return PEAR::raiseError(Dataface_LanguageTool::translate('Specified record could not be loaded', 'The specified record could not be loaded'), DATAFACE_E_NOTICE);
}
unset($app->currentRecord);
$app->currentRecord =& $form->_record;
if (!Dataface_PermissionsTool::checkPermission('remove related record', $form->_record, array('relationship' => $query['-relationship']))) {
return Dataface_Error::permissionDenied(Dataface_LanguageTool::translate('Insufficient permissions to delete record', 'Permission Denied. You do not have permissions to remove related records from the relationship "' . $query['-relationship'] . '" for this record.
Requires permission "remove related record" but you only have the following permissions: "' . df_permission_names_as_string($form->_record->getPermissions(array('relationship' => $query['-relationship']))) . '"', array('relationship' => $query['-relationship'], 'required_permission' => 'remove related record', 'granted_permissions' => df_permission_names_as_string($form->_record->getPermissions(array('relationship' => $query['-relationship']))))));
//$this->_vars['error'] = "<div class=\"error\">Error. Permission Denied.<!-- At line ".__LINE__." of file ".__FILE__." --></div>";
//return;
}
if (@$_POST['-confirm_delete_hidden'] and $form->validate()) {
$res = $form->process(array(&$form, 'delete'), true);
$response =& Dataface_Application::getResponse();
if (PEAR::isError($res) && !Dataface_Error::isNotice($res)) {
return $res;
//$this->_vars['error'] = "<div class=\"error\">Error. ".$res->toString()."<!-- At line ".__LINE__." of file ".__FILE__." --></div>";
//return;
} else {
if (count($res['warnings']) > 0) {
//Dataface_Error::isNotice($res) ){
foreach ($res['warnings'] as $warning) {
$app->addError($warning);
$response['--msg'] = 'Errors occurred trying to remove records';
}
} else {
$response['--msg'] = df_translate('Records successfully deleted from relationship', ' Records successfully removed from relationship') . "<br>" . @$response['--msg'];
}
}
if (count($res['warnings']) > 0) {
foreach (array_merge($res['confirmations'], $res['warnings']) as $confirmation) {
$response['--msg'] .= "<br>" . $confirmation;
}
}
$msg = urlencode(trim(@$response['--msg']));
header("Location: " . $form->_record->getURL(array('-action' => 'related_records_list', '-relationship' => $query['-relationship'])) . '&--msg=' . $msg);
//header("Location: ".$_SERVER['HOST_URI'].$_SERVER['PHP_SELF'].'?'.$_COOKIE['dataface_lastpage'].'&--msg='.$msg);
exit;
}
ob_start();
$form->display();
$out = ob_get_contents();
ob_end_clean();
$context = array('form' => $out);
if (isset($query['-template'])) {
$template = $query['-template'];
} else {
if (isset($params['action']['template'])) {
$template = $params['action']['template'];
} else {
$template = 'Dataface_Remove_Related_Record.html';
}
}
df_display($context, $template, true);
}
示例8: handle
function handle($params)
{
import('Dataface/ImportForm.php');
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
$form = new Dataface_ImportForm($query['-table']);
$record =& $form->_record;
if (is_object($record)) {
if (!$record->checkPermission('import')) {
return Dataface_Error::permissionDenied();
}
} else {
if (!Dataface_PermissionsTool::checkPermission('import', Dataface_Table::loadTable($query['-table']))) {
return Dataface_Error::permissionDenied();
}
}
$form->_build();
if ($form->validate()) {
//echo "validated";
$querystr = $form->exportValue('-query');
$returnPage = $form->exportValue('--redirect');
if (intval($form->_step) === 1) {
if (preg_match('/--step=1/', $querystr)) {
$querystr = preg_replace('/--step=1/', '--step=2', $querystr);
} else {
$querystr .= '&--step=2';
}
$importTablename = $form->process(array(&$form, 'import'));
//echo "Table: $importTablename";
//exit;
//$link = 'Location: '.$_SERVER['PHP_SELF'].'?'.$querystr.'&--importTablename='.$importTablename;
//echo $link;
//exit;
header('Location: ' . $_SERVER['PHP_SELF'] . '?' . $querystr . '&--importTablename=' . $importTablename . '&--redirect=' . urlencode($returnPage));
exit;
} else {
$records = $form->process(array(&$form, 'import'));
$returnPage = $form->exportValue('--redirect');
//$keys = $form->exportValue('__keys__');
//$keys['-action'] = 'browse';
//$keys['-step'] = null;
//$keys['-query'] = null;
//$link = Dataface_LinkTool::buildLink($keys);
$link = $returnPage;
$response =& Dataface_Application::getResponse();
$msg = urlencode(trim("Records imported successfully.\n" . @$response['--msg']));
if (strpos($link, '?') === false) {
$link .= '?';
}
header('Location: ' . $link . '&--msg=' . $msg);
exit;
}
}
ob_start();
$form->display();
$out = ob_get_contents();
ob_end_clean();
$context['form'] = $out;
$context['filters'] = $form->_filterNames;
$context['step'] = $form->_step;
if (isset($query['-template'])) {
$template = $query['-template'];
} else {
if (isset($params['action']['template'])) {
$template = $params['action']['template'];
} else {
if (isset($query['-relationship'])) {
$template = 'Dataface_Import_RelatedRecords.html';
} else {
$template = 'Dataface_Import_RelatedRecords.html';
}
}
}
df_display($context, $template, true);
}
示例9: handle
function handle()
{
import('Dataface/FormTool.php');
import('Dataface/QuickForm.php');
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
$new = true;
$currentRecord = new Dataface_Record($query['-table'], array());
$currentTable =& Dataface_Table::loadTable($query['-table']);
if (!isset($query['--tab']) and count($currentTable->tabs($currentRecord)) > 1) {
list($query['--tab']) = array_keys($currentTable->tabs($currentRecord));
} else {
if (count($currentTable->tabs($currentRecord)) <= 1) {
unset($query['--tab']);
}
}
$formTool =& Dataface_FormTool::getInstance();
$form = $formTool->createRecordForm($currentRecord, true, @$query['--tab'], $query);
//$form = new Dataface_QuickForm($query['-table'], $app->db(), $query, '',$new);
$res = $form->_build();
if (PEAR::isError($res)) {
trigger_error($res->toString() . Dataface_Error::printStackTrace(), E_USER_ERROR);
}
$formTool->decorateRecordForm($currentRecord, $form, true, @$query['--tab']);
/*
*
* We need to add the current GET parameter flags (the GET vars starting with '-') so
* that the controller knows to pass control to this method again upon form submission.
*
*/
foreach ($query as $key => $value) {
if (strpos($key, '-') === 0) {
$form->addElement('hidden', $key);
$form->setDefaults(array($key => $value));
}
}
/*
* Store the current query string (the portion after the '?') in the form, so we
* can retrieve it after and redirect back to our original location.
*/
$form->addElement('hidden', '-query');
$form->setDefaults(array('-action' => $query['-action'], '-query' => $_SERVER['QUERY_STRING']));
/*
*
* We have to deal with 3 cases.
* 1) The form has not been submitted.
* 2) The form was submitted but didn't validate (ie: it had some bad input)
* 3) The form was submitted and was validated.
*
* We deal with Case 3 first...
*
*/
if ($formTool->validateRecordForm($currentRecord, $form, true, @$query['--tab'])) {
/*
*
* The form was submitted and it validated ok. We now process it (ie: save its contents).
*
*/
$formTool->handleTabSubmit($currentRecord, $form, @$query['--tab']);
if (!isset($query['--tab'])) {
// If we aren't using tabs we just do it the old way.
// (If it ain't broke don't fix it
$result = $form->process(array(&$form, 'save'));
} else {
// If we are using tabs, we will use the formtool's
// session aware saving function
$result = $formTool->saveSession($currentRecord, true);
}
$success = true;
$response =& Dataface_Application::getResponse();
if (!$result) {
trigger_error("Error occurred in save: " . mysql_error($app->db()) . Dataface_Error::printStackTrace(), E_USER_ERROR);
exit;
} else {
if (PEAR::isError($result) && !Dataface_Error::isNotice($result)) {
//echo "Error..";
if (Dataface_Error::isDuplicateEntry($result)) {
$success = false;
$form->_errors[] = $result->getMessage();
} else {
//echo "not dup entry"; exit;
trigger_error($result->toString() . Dataface_Error::printStackTrace(), E_USER_ERROR);
exit;
}
} else {
if (Dataface_Error::isNotice($result)) {
$app->addError($result);
$success = false;
}
}
}
if ($success) {
if (@$query['-response'] == 'json') {
//header('Content-type: text/json; charset="'.$app->_conf['oe'].'"');
$rvals = $currentRecord->strvals();
$rvals['__title__'] = $currentRecord->getTitle();
echo json_encode(array('response_code' => 200, 'record_data' => $rvals, 'response_message' => df_translate('Record Successfully Saved', 'Record Successfully Saved')));
exit;
}
import('Dataface/Utilities.php');
//.........这里部分代码省略.........
示例10: handle
function handle(&$params)
{
import('Dataface/DeleteForm.php');
import('Dataface/LanguageTool.php');
import('Dataface/Record.php');
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
$record = new Dataface_Record($query['-table'], @$_REQUEST['--__keys__']);
// if ( !Dataface_PermissionsTool::delete($record) ) {
// return Dataface_Error::permissionDenied(
// Dataface_LanguageTool::translate(
// /* i18n id */
// 'No delete permissions',
// /* Default error message */
// 'Insufficient Permissions to delete this record',
// /* i18n parameters */
// array('record'=>$record->getTitle())
// )
// );
//
//
// }
$form = new Dataface_DeleteForm($query['-table'], $app->db(), $query);
$form->_build();
$form->addElement('hidden', '-table');
$form->setDefaults(array('-table' => $query['-table']));
$msg = '';
if ($form->validate()) {
$res = $form->process(array(&$form, 'delete'), true);
$response =& Dataface_Application::getResponse();
if (!isset($response['--msg'])) {
$response['--msg'] = '';
}
$failed = false;
if (PEAR::isError($res) && !Dataface_Error::isNotice($res)) {
return $res;
//$error = $res->getMessage();
//$msg .= "\n". $res->getUserInfo();
} else {
if (Dataface_Error::isNotice($res)) {
$app->addError($res);
//$response['--msg'] = @$response['--msg'] ."\n".$res->getMessage();
$failed = true;
} else {
if (is_array($res)) {
$msg = df_translate('Some errors occurred while deleting records', 'Some errors occurred while deleting records');
foreach ($res as $warning) {
$response['--msg'] .= "\n" . $warning->getMessage();
}
} else {
$msg = Dataface_LanguageTool::translate('Records successfully deleted', 'Records successfully deleted.');
}
}
}
$msg = urlencode(trim($msg . "\n" . $response['--msg']));
if (!$failed) {
import('Dataface/Utilities.php');
Dataface_Utilities::fireEvent('after_action_delete', array('record' => &$record));
header('Location: ' . $_SERVER['HOST_URI'] . DATAFACE_SITE_HREF . '?-table=' . $query['-table'] . '&--msg=' . $msg);
exit;
}
}
ob_start();
$form->display();
$out = ob_get_contents();
ob_end_clean();
$context = array('form' => $out);
if (isset($query['-template'])) {
$template = $query['-template'];
} else {
if (isset($params['action']['template'])) {
$template = $params['action']['template'];
} else {
$template = 'Dataface_Delete_Record.html';
}
}
df_display($context, $template, true);
}
示例11: _import_init
/**
* Handles initialization and control for the import records form.
*/
function _import_init()
{
import('Dataface/ImportForm.php');
$form = new Dataface_ImportForm($this->_tablename);
$record =& $form->_record;
if (!Dataface_PermissionsTool::edit($record)) {
$this->_vars['error'] = "<div class=\"error\">Error. Permission Denied.<!-- At line " . __LINE__ . " of file " . __FILE__ . " --></div>";
return;
}
$form->_build();
$this->_vars['form'] =& $form;
if ($form->validate()) {
//echo "validated";
$querystr = $form->exportValue('-query');
if (intval($form->_step) === 1) {
if (preg_match('/-step=1/', $querystr)) {
$querystr = preg_replace('/-step=1/', '-step=2', $querystr);
} else {
$querystr .= '&-step=2';
}
$importTablename = $form->process(array(&$form, 'import'));
//echo "Table: $importTablename";
//exit;
//$link = 'Location: '.$_SERVER['PHP_SELF'].'?'.$querystr.'&--importTablename='.$importTablename;
//echo $link;
//exit;
header('Location: ' . $_SERVER['PHP_SELF'] . '?' . $querystr . '&--importTablename=' . $importTablename);
exit;
} else {
$records = $form->process(array(&$form, 'import'));
$keys = $form->exportValue('__keys__');
$keys['-action'] = 'browse';
$keys['-step'] = null;
$keys['-query'] = null;
$link = Dataface_LinkTool::buildLink($keys);
$response =& Dataface_Application::getResponse();
$msg = urlencode(trim("Records imported successfully.\n" . @$response['--msg']));
header('Location: ' . $link . '&--msg=' . $msg);
exit;
}
}
//echo "Not validated";
}
示例12: handle
function handle(&$params)
{
//global $myctr;
$app =& Dataface_Application::getInstance();
$query =& $app->getQuery();
$resultSet =& $app->getResultSet();
//$record =& $app->getRecord(); // loads the current record
import('Dataface/ShortRelatedRecordForm.php');
if (!isset($query['-relationship'])) {
return PEAR::raiseError(Dataface_LanguageTool::translate('No relationship specified in new related record', 'No relationship was specified while trying to create new related record. Please specify a relationship.'), DATAFACE_E_ERROR);
}
$record = null;
// we let the Form automatically handle loading of record.
$form = new Dataface_ShortRelatedRecordForm($record, $query['-relationship']);
$form->_build();
/*
*
* We need to add the current GET parameter flags (the GET vars starting with '-') so
* that the controller knows to pass control to this method again upon form submission.
*
*/
//$myctr = 0;
foreach ($query as $key => $value) {
//echo "doing $key";
if (strpos($key, '-') === 0) {
$form->addElement('hidden', $key);
$form->setDefaults(array($key => $value));
//if ( $myctr == 2 ) exit;
}
//$myctr++;
}
/*
* Store the current query string (the portion after the '?') in the form, so we
* can retrieve it after and redirect back to our original location.
*/
$form->addElement('hidden', '-query');
$form->setDefaults(array('-action' => $query['-action'], '-query' => $_SERVER['QUERY_STRING']));
if (!Dataface_PermissionsTool::checkPermission('add new related record', $form->_record, array('relationship' => $query['-relationship']))) {
return Dataface_Error::permissionDenied(Dataface_LanguageTool::translate('Permission denied while trying to add new related record', 'Permission Denied: You do not have permission to add related records to the current record.'));
//$this->_vars['error'] = "<div class=\"error\">Error. Permission Denied.<!-- At line ".__LINE__." of file ".__FILE__." --></div>";
//return;
}
if ($form->validate()) {
$vals = $form->exportValues();
$res = $form->process(array(&$form, 'save'), true);
$response =& Dataface_Application::getResponse();
if (PEAR::isError($res) && !Dataface_Error::isNotice($res)) {
return $res;
//$this->_vars['error'] = "<div class=\"error\">Error. ".$res->toString()."<!-- At line ".__LINE__." of file ".__FILE__." --></div>";
//return;
} else {
if (Dataface_Error::isNotice($res)) {
$success = false;
$app->addError($res);
//$response['--msg'] = @$response['--msg'] . "\n".$res->getMessage();
} else {
$success = true;
}
}
if ($success) {
import('Dataface/Utilities.php');
Dataface_Utilities::fireEvent('after_action_new_related_record');
$fquery = array('-action' => 'browse');
$table = Dataface_Table::loadTable($query['-table']);
$rel = $table->getRelationship($query['-relationship']);
$msg = urlencode(trim(Dataface_LanguageTool::translate("Record successfully added to relationship", "Record successfully added to " . $rel->getLabel() . " relationship.\n", array('relationship' => $rel->getLabel())) . (isset($response['--msg']) ? $response['--msg'] : '')));
foreach ($vals['__keys__'] as $key => $value) {
$fquery[$key] = "=" . $value;
}
$fquery['-relationship'] = $query['-relationship'];
$fquery['-action'] = 'related_records_list';
$link = Dataface_LinkTool::buildLink($fquery);
$app->redirect("{$link}" . "&--msg=" . $msg);
}
}
ob_start();
$gdefs = array();
foreach ($_GET as $gkey => $gval) {
if (substr($gkey, 0, 4) == '--q:') {
$gdefs[substr($gkey, 4)] = $gval;
}
}
if (count($gdefs) > 0) {
$form->setDefaults($gdefs);
}
$form->display();
$out = ob_get_contents();
ob_end_clean();
$context = array('form' => $out);
if (isset($query['-template'])) {
$template = $query['-template'];
} else {
if (isset($params['action']['template'])) {
$template = $params['action']['template'];
} else {
$template = 'Dataface_Add_New_Related_Record.html';
}
}
df_display($context, $template, true);
}