Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
search_list_edit_fns.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/cms/listing_engine/listing_engine_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42 
43  }//end constructor
44 
45 
56  function paintSearchPage(&$asset, &$o, $prefix)
57  {
58  $search_page_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', false, 'search_page');
59  $write_access = $asset->writeAccess('links');
60 
61  if (!$write_access) {
62  $search_page = null;
63  if (!empty($search_page_link)) {
64  echo get_asset_tag_line($search_page_link['minorid']);
65  } else {
66  echo translate('sch_no_search_page_specified');
67  }
68 
69  } else {
70  asset_finder($prefix.'_search_page', (!empty($search_page_link)) ? $search_page_link['minorid'] : '', Array('search_page' => 'I'));
71  }
72 
73  return $write_access;
74 
75  }//end paintSearchPage()
76 
77 
88  function processSearchPage(&$asset, &$o, $prefix)
89  {
90  if (!isset($_POST[$prefix.'_search_page']['assetid'])) {
91  return false;
92  }
93 
94  $new_search_page = $_POST[$prefix.'_search_page']['assetid'];
95 
96  // getting existing search page
97  $search_page_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', false, 'search_page');
98 
99  // dont process anything if the search page has not changed
100  if (!empty($search_page_link) && $search_page_link['minorid'] == $new_search_page) {
101  return false;
102  }
103 
104  $ok = true;
105 
106  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
107  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
108 
109  // deleting old search page link if any found...
110  if (!empty($search_page_link) && !$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($search_page_link['linkid'])) {
111  $ok = false;
112  } else if ($new_search_page) {
113  $search_page = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_search_page);
114  if (!is_null($search_page)) {
115  if (!$asset->createLink($search_page, SQ_LINK_NOTICE, 'search_page')) {
116  $ok = false;
117  trigger_localised_error('SCH0011', E_USER_WARNING, $search_page->name, $search_page->id);
118  }
119  }
120  }
121 
122  if ($ok) {
123  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
124  } else {
125  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
126  }
127 
128  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
129  return $ok;
130 
131  }//end processSearchPage()
132 
133 
144  function paintSearchField(&$asset, &$o, $prefix)
145  {
146  $search_page = null;
147  $search_page_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', false, 'search_page');
148  if (!empty($search_page_link)) {
149  $search_page = $GLOBALS['SQ_SYSTEM']->am->getAsset($search_page_link['minorid']);
150  }
151 
152  if (is_null($search_page)) {
153  echo translate('sch_list_page_before_field');
154  return false;
155  }
156 
157  if ($asset->writeAccess('attributes')) {
158  $fields = $search_page->attr('fields');
159 
160  $options = Array();
161  foreach ($fields as $field_name => $field) {
162  $can_use = true;
163 
164  // loop through each data source and if it contains an 'include all'
165  // or 'exclude' anywhere, then it cannot be used
166  foreach($field['data_sources'] as $data_source) {
167  if (($data_source['type'] == 'include_all') || ($data_source['type'] == 'exclude')) {
168  $can_use = false;
169  break;
170  }
171  }
172 
173  if ($can_use) {
174  $options[$field_name] = $field['name'];
175  }
176  }
177 
178  $options = array_merge(Array('' => translate('none')), $options);
179  combo_box($prefix.'_field_name', $options, false, $asset->attr('search_field'));
180  return true;
181  } else {
182  echo $asset->attr('search_field');
183  return false;
184  }
185 
186  }//end paintSearchField()
187 
188 
199  function processSearchField(&$asset, &$o, $prefix)
200  {
201  if (!isset($_POST[$prefix.'_field_name'])) {
202  return false;
203  }
204 
205  return $asset->setAttrValue('search_field', $_POST[$prefix.'_field_name']);
206 
207  }//end processSearchField()
208 
209 
210 }//end class
211 
212 ?>