17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
39 function paintLookupValues(&$owner, &$o, &$ei, $keywords=NULL)
42 $prefix = $owner->getPrefix();
43 $lookups = $owner->getLookups(
'url');
44 $lookup_values = $owner->getLookupValues(TRUE);
46 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
48 $lookup_value_types = $am->getTypeDescendants(
'lookup_value');
49 $lookup_value_details = Array();
53 foreach ($lookup_value_types as $type_code) {
54 $am->includeAsset($type_code);
55 eval (
'$name_prefix = '.$type_code.
'::namePrefix();');
56 eval (
'$title = '.$type_code.
'::lookupValueName();');
57 $lookup_value_details[$type_code] = Array(
58 'name_prefix' => $name_prefix,
61 $values[$name_prefix] = Array();
64 uasort($lookup_value_details, create_function(
'$a,$b',
'return strcmp(strtolower($a[\'title\']), strtolower($b[\'title\']));'));
66 foreach ($lookup_values as $url => $data) {
67 foreach ($data as $value_name => $value_data) {
69 if (!preg_match(
'/^([^:]+)(::|$)/', $value_name, $matches)) {
72 if (!isset($values[$matches[1]]))
continue;
73 if (!isset($values[$matches[1]][$url])) {
74 $values[$matches[1]][$url] = Array();
76 $values[$matches[1]][$url][$value_name] = $value_data;
79 unset($lookup_values);
81 $editing_fields = FALSE;
83 for (reset($lookup_value_details); NULL !== ($type_code = key($lookup_value_details)); next($lookup_value_details)) {
84 $o->openSection($lookup_value_details[$type_code][
'title']);
85 $name_prefix = $lookup_value_details[$type_code][
'name_prefix'];
86 eval(
'$editing_fields |= '.$type_code.
'::paintInterface($owner, $o, $lookups, $values[$name_prefix], $prefix.\'_lookup_values_\'.$name_prefix);');
91 return $editing_fields;
107 function processLookupValues(&$owner, &$o, &$ei)
109 $prefix = $owner->getPrefix();
110 $lookups = $owner->getLookups(
'url');
112 $lookup_values = $owner->getLookupValues(FALSE);
114 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
116 $lookup_value_types = $am->getTypeDescendants(
'lookup_value');
118 $layouts_changed = FALSE;
121 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
122 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
123 foreach ($lookup_value_types as $type_code) {
124 $am->includeAsset($type_code);
125 eval(
'$name_prefix = '.$type_code.
'::namePrefix();');
127 eval(
'$success = '.$type_code.
'::processInterface($owner, $o, $lookups, $values, $prefix.\'_lookup_values_\'.$name_prefix);');
130 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
131 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
135 foreach ($values as $resource => $values_data) {
136 foreach ($values_data as $value_name => $data) {
137 if ($resource ===
'asset') {
139 $layout_name = $value_name.
'::system::frontend';
140 $existing_layout_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($owner->id, SQ_LINK_NOTICE,
'paint_layout_page', TRUE, $layout_name);
141 $create_new = $delete_existing = FALSE;
142 if (empty($data[
'value'])) {
143 $delete_existing = TRUE;
144 }
else if (empty($existing_layout_link)) {
149 if ($existing_layout_link[
'minorid'] !== $data[
'value']) {
150 $delete_existing = TRUE;
155 if ($delete_existing) {
156 if ($existing_layout_link) {
157 if (!$owner->deleteLink($existing_layout_link[
'linkid'])) {
158 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
162 $layouts_changed = TRUE;
167 if (!$new_values = $owner->deleteLookupValue($layout_name, $existing_layout_link[
'minorid'])) {
168 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
172 $lookup_values = $new_values;
180 $layout = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($data[
'value']);
181 if (is_null($layout)) {
182 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
186 if (!$owner->createLink($layout, SQ_LINK_NOTICE, $layout_name)) {
187 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
191 $layouts_changed = TRUE;
199 if (empty($data[
'value'])) {
200 if (isset($lookup_values[$resource][$value_name])) {
201 unset($lookup_values[$resource][$value_name]);
204 $layouts_changed = TRUE;
206 if (!isset($lookup_values[$resource])) {
207 $lookup_values[$resource] = Array();
209 $lookup_values[$resource][$value_name] = Array(
'value' => $data[
'value']);
216 if (!$owner->setLookupValues($lookup_values)) {
217 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
218 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
222 if ($layouts_changed) {
223 if (!$owner->updateLookups()) {
224 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
225 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
231 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
232 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();