/** * Saves the content of a form editing new or existing records. It returns the same form + status messages rendered into the current view, inherited from ActionController * * @param array $pa_options Array of options passed through to _initView and saveBundlesForScreen() */ public function Save($pa_options = null) { list($vn_subject_id, $t_subject, $t_ui) = $this->_initView($pa_options); if (!is_array($pa_options)) { $pa_options = array(); } $vs_message = ''; $vs_auth_table_name = $this->ops_table_name; if (in_array($this->ops_table_name, array('ca_object_representations', 'ca_representation_annotations'))) { $vs_auth_table_name = 'ca_objects'; } if (!sizeof($_POST)) { $this->notification->addNotification(_t("Cannot save using empty request. Are you using a bookmark?"), __NOTIFICATION_TYPE_ERROR__); $this->render('screen_html.php'); return; } // set "context" id from those editors that need to restrict idno lookups to within the context of another field value (eg. idno's for ca_list_items are only unique within a given list_id) $vn_context_id = null; if ($vs_idno_context_field = $t_subject->getProperty('ID_NUMBERING_CONTEXT_FIELD')) { if ($vn_subject_id > 0) { $this->view->setVar('_context_id', $vn_context_id = $t_subject->get($vs_idno_context_field)); } if ($vn_context_id) { $t_subject->set($vs_idno_context_field, $vn_context_id); } } if (!($vs_type_name = $t_subject->getTypeName())) { $vs_type_name = $t_subject->getProperty('NAME_SINGULAR'); } if ($vn_subject_id && !$t_subject->getPrimaryKey()) { $this->notification->addNotification(_t("%1 does not exist", $vs_type_name), __NOTIFICATION_TYPE_ERROR__); return; } # trigger "BeforeSaveItem" hook $this->opo_app_plugin_manager->hookBeforeSaveItem(array('id' => $vn_subject_id, 'table_num' => $t_subject->tableNum(), 'table_name' => $t_subject->tableName(), 'instance' => $t_subject, 'is_insert' => $vb_is_insert)); $vb_is_insert = !$t_subject->getPrimaryKey(); // Set access and status if (strlen($vn_access = ContributePlugin::getFormSetting('access'))) { $t_subject->set("access", $vn_access); } if (strlen($vn_status = ContributePlugin::getFormSetting('status'))) { $t_subject->set("status", $vn_status); } $vb_save_rc = $t_subject->saveBundlesForScreen($this->request->getActionExtra(), $this->request, array_merge($pa_options, array('ui_instance' => $t_ui))); $this->view->setVar('t_ui', $t_ui); if (!$vn_subject_id) { $vn_subject_id = $t_subject->getPrimaryKey(); if (!$vb_save_rc) { $vs_message = ""; } else { if (isset($pa_options['setNotifictionOnSuccess']) && $pa_options['setNotifictionOnSuccess']) { $vs_message = _t("Added %1", $vs_type_name); } $this->request->setParameter($t_subject->primaryKey(), $vn_subject_id, 'GET'); $this->view->setVar($t_subject->primaryKey(), $vn_subject_id); $this->view->setVar('subject_id', $vn_subject_id); $this->request->session->setVar($this->ops_table_name . '_browse_last_id', $vn_subject_id); // set last edited } } else { $vs_message = _t("Saved changes to %1", $vs_type_name); } $va_errors = $this->request->getActionErrors(); // all errors from all sources $va_general_errors = $this->request->getActionErrors('general'); // just "general" errors - ones that are not attached to a specific part of the form if (is_array($va_general_errors) && sizeof($va_general_errors) > 0) { foreach ($va_general_errors as $o_e) { $this->notification->addNotification($o_e->getErrorDescription(), __NOTIFICATION_TYPE_ERROR__); } } if (sizeof($va_errors) + sizeof($va_general_errors) > 0) { $va_error_list = array(); $vb_no_save_error = false; foreach ($va_errors as $o_e) { $va_error_list[$o_e->getErrorDescription()] = "<li>" . $o_e->getErrorDescription() . "</li>\n"; switch ($o_e->getErrorNumber()) { case 1100: // duplicate/invalid idno if (!$vn_subject_id) { // can't save new record if idno is not valid (when updating everything but idno is saved if it is invalid) $vb_no_save_error = true; } break; } } if ($vb_no_save_error) { $this->notification->addNotification(_t("There are errors preventing <strong>ALL</strong> information from being saved. Correct the problems and click \"save\" again.\n<ul>") . join("\n", $va_error_list) . "</ul>", __NOTIFICATION_TYPE_ERROR__); } else { if ($vs_message) { $this->notification->addNotification($vs_message, __NOTIFICATION_TYPE_INFO__); } $this->notification->addNotification(_t("There are errors preventing information in specific fields from being saved as noted below.\n<ul>") . join("\n", $va_error_list) . "</ul>", __NOTIFICATION_TYPE_ERROR__); } $this->render('screen_html.php'); } else { if ($vs_message) { $this->notification->addNotification($vs_message, __NOTIFICATION_TYPE_INFO__); } $this->opo_result_context->invalidateCache(); $this->opo_result_context->saveContext(); # trigger "SaveItem" hook $this->opo_app_plugin_manager->hookSaveItem(array('id' => $vn_subject_id, 'table_num' => $t_subject->tableNum(), 'table_name' => $t_subject->tableName(), 'instance' => $t_subject, 'is_insert' => $vb_is_insert)); if ((bool) $this->opa_ui_info['set_post_submission_notification']) { if ($t_subject->tableName() == 'ca_objects' && $t_subject->getRepresentationCount() > 0) { $this->notification->addNotification($this->opa_ui_info['post_submission_notification_message_with_media'], __NOTIFICATION_TYPE_INFO__); } else { $this->notification->addNotification($this->opa_ui_info['post_submission_notification_message'], __NOTIFICATION_TYPE_INFO__); } } # --- check if email notification should be sent to administrator if ($this->opo_plugin_config->get('admin_email_notification') && $this->opo_plugin_config->get('admin_email_notification_address')) { $vs_app_name = __CA_APP_DISPLAY_NAME__; $vs_app_url = __CA_SITE_HOSTNAME__; $vs_record_name = $t_subject->getLabelForDisplay(); # -- generate mail text from template - get both html and text versions ob_start(); require __CA_APP_DIR__ . "/plugins/Contribute/themes/" . $this->ops_theme . "/views/mailTemplates/contribute_admin_notification_email_text.tpl"; $vs_mail_message_text = ob_get_contents(); ob_end_clean(); ob_start(); require __CA_APP_DIR__ . "/plugins/Contribute/themes/" . $this->ops_theme . "/views/mailTemplates/contribute_admin_notification_email_html.tpl"; $vs_mail_message_html = ob_get_contents(); ob_end_clean(); if (!caSendmail($this->opo_plugin_config->get('admin_email_notification_address'), $this->opo_plugin_config->get('admin_email_notification_address'), _t($vs_app_name . " Contribute notification"), $vs_mail_message_text, $vs_mail_message_html)) { $this->notification->addNotification(_t("Admin notification email was not sent"), "message"); } } switch ($this->opa_ui_info['post_submission_destination']) { case 'url': $vs_url = caNavUrl($this->request, $this->opa_ui_info['post_submission_destination_url']['module'], $this->opa_ui_info['post_submission_destination_url']['controller'], $this->opa_ui_info['post_submission_destination_url']['action']); $this->response->setRedirect($vs_url); break; case 'splash': if ($vs_default_action = $this->request->config->get('default_action')) { $va_tmp = explode('/', $vs_default_action); $vs_action = array_pop($va_tmp); if (sizeof($va_tmp)) { $vs_controller = array_pop($va_tmp); } if (sizeof($va_tmp)) { $vs_module_path = join('/', $va_tmp); } } else { $vs_controller = 'Splash'; $vs_action = 'Index'; } $vs_url = caNavUrl($this->request, $vs_module_path, $vs_controller, $vs_action); $this->response->setRedirect($vs_url); break; case 'last_page': if (!($vs_url = $this->request->session->getVar('pawtucket2_last_page'))) { $vs_action = $vs_controller = $vs_module_path = ''; if ($vs_default_action = $this->request->config->get('default_action')) { $va_tmp = explode('/', $vs_default_action); $vs_action = array_pop($va_tmp); if (sizeof($va_tmp)) { $vs_controller = array_pop($va_tmp); } if (sizeof($va_tmp)) { $vs_module_path = join('/', $va_tmp); } } else { $vs_controller = 'Splash'; $vs_action = 'Index'; } $vs_url = caNavUrl($this->request, $vs_module_path, $vs_controller, $vs_action); } $this->response->setRedirect($vs_url); break; case 'page': default: $this->render('result_html.php'); break; } } }
?> Item_{n}" class="labelInfo"> <span class="formLabelError">{error}</span> <table class="caListItem"> <tr> <td> <?php if ($vn_type_id = ContributePlugin::getFormSetting("representation_type_id")) { print caHTMLHiddenInput('{fieldNamePrefix}type_id_{n}', array('value' => $vn_type_id)); } else { print $t_item->htmlFormElement('type_id', null, array('classname' => '{fieldNamePrefix}type_id_select objectRepresentationType', 'id' => "{fieldNamePrefix}type_id_{n}", 'name' => "{fieldNamePrefix}type_id_{n}", "value" => "", 'no_tooltips' => false, 'tooltip_namespace' => 'bundle_ca_object_representations', 'hide_select_if_only_one_option' => true)); } if ($vn_status = ContributePlugin::getFormSetting("representation_status")) { print caHTMLHiddenInput('{fieldNamePrefix}status_{n}', array('value' => $vn_status)); } if ($vn_access = ContributePlugin::getFormSetting("representation_access")) { print caHTMLHiddenInput('{fieldNamePrefix}access_{n}', array('value' => $vn_access)); } ?> <?php print $t_item->htmlFormElement('media', null, array('name' => "{fieldNamePrefix}media_{n}", 'id' => "{fieldNamePrefix}media_{n}", "value" => "", 'no_tooltips' => false, 'tooltip_namespace' => 'bundle_ca_object_representations')); ?> </td> <td> <div style="float:right; margin:5px 0px 0px 125px; position:absolute;"> <a href="#" class="caDeleteItemButton"><?php print caNavIcon($this->request, __CA_NAV_BUTTON_DEL_BUNDLE__, null, null, array('graphicsPath' => $this->getVar('graphicsPath'))); ?> </a> </div> </td>