19 require_once SQ_INCLUDE_PATH.
'/asset.inc';
20 require_once SQ_CORE_PACKAGE_PATH.
'/data_source/data_source/data_source.inc';
21 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
22 require_once SQ_PACKAGES_PATH.
'/trim/lib/trim_common.inc';
48 parent::__construct($assetid);
50 $this->_ser_attrs = TRUE;
51 $this->search_clauses = NULL;
69 if (!parent::_createAdditional($link))
return FALSE;
93 $allowed_link[
'asset'][
'card'] =
'M';
94 $allowed_link[
'asset'][
'exclusive'] = FALSE;
96 $links[SQ_LINK_TYPE_1] = $allowed_link;
97 $links[SQ_LINK_TYPE_2] = $allowed_link;
98 $links[SQ_LINK_TYPE_3] = $allowed_link;
99 $links[SQ_LINK_NOTICE] = $allowed_link;
116 $result = $this->getCachedResults($hash);
117 if (empty($result)) {
123 if (!empty($connection[
'wsdl'])) {
127 if ($this->
attr(
'download_files')) {
128 foreach ($object_list as &$record_info) {
135 if (!isset($res[0][
'error'])) {
136 $result = $object_list;
137 if (!empty($result)) {
138 $this->cacheResult($result, $hash);
140 }
else if (isset($res[0][
'FoundCount']) && $res[0][
'FoundCount'] != 0) {
143 }
catch (Exception $sf) {
153 public function getCachedResults($hash_key)
155 $result = $this->
attr(
'cached_result');
156 if (isset($result[$hash_key])) {
157 return $result[$hash_key];
165 public function cacheResult($result, $hash_key)
167 $cached_result = $this->
attr(
'cached_result');
168 $cached_result[$hash_key] = $result;
170 $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($this->
id,
'attributes');
174 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($this->
id,
'attributes');
192 $result = $this->getCachedResults($hash);
193 if (!empty($result)) {
194 $ordered_result = Array();
198 if (!empty($connection[
'wsdl'])) {
205 $new_result_uris = $this->
resultUris($new_object_list);
211 $uris_to_delete = array_diff($result_uris, $new_result_uris);
212 foreach ($result as $index => $record_info) {
213 if (isset($record_info[
'Uri']) && in_array($record_info[
'Uri'], $uris_to_delete)) {
215 $dir_path = $this->data_path.
'/'.$record_info[
'Uri'];
216 $files_stored = glob($dir_path.
'/*');
217 foreach ($files_stored as $file_name) {
222 if (is_dir($dir_path)) {
227 unset($result[$index]);
235 foreach ($result as $index => $record_info) {
236 foreach ($new_object_list as $new_index => $new_record_info) {
238 if ($record_info[
'Uri'] == $new_record_info[
'Uri']) {
240 if ($record_info[
'Version'] !== $new_record_info[
'Version'] || $forced) {
242 if ($this->
attr(
'download_files')) {
245 $ordered_result[$new_index] = $new_record_info;
248 $ordered_result[$new_index] = $new_record_info;
251 if (isset($new_record_info[
'recDocumentType']) && $new_record_info[
'recDocumentType'] !=
'Record has no document attached.') {
253 $final_file_path = $this->data_path.
'/'.$new_record_info[
'Uri'];
254 $files_stored = glob($final_file_path.
'/*');
256 if (empty($files_stored)) {
259 }
else if (!isset($record_info[
'download_url'])) {
261 $ordered_result[$new_index][
'document_url'] = $this->
getURL().
'?Uri='.$new_record_info[
'Uri'];
271 $ordered_result_uris = $this->
resultUris($result);
274 if (count($new_object_list) > count($ordered_result)) {
275 $uris_to_add = array_diff($new_result_uris, $ordered_result_uris);
276 foreach ($new_object_list as $index => $new_record_info) {
277 if (in_array($new_record_info[
'Uri'], $uris_to_add)) {
279 if ($this->
attr(
'download_files')) {
282 $ordered_result[$index] = $new_record_info;
289 ksort($ordered_result);
293 $result = array_values($ordered_result);
295 if (!empty($result)) {
296 $this->cacheResult($result, $hash);
314 $new_result = Array();
315 foreach ($result as $index => $record_info) {
316 $new_result[$record_info[
'Uri']] = $record_info;
319 return array_keys($new_result);
332 require_once SQ_FUDGE_PATH.
'/standards_lists/mime_types.inc';
334 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'SQ_REPLACE_MYSOURCE_LEVEL_KEYWORDS', FALSE);
336 $dir_path = $this->data_path.
'/'.$uri;
337 $path_parts = Array();
338 if (file_exists($dir_path)) {
339 if(defined(
"RecursiveDirectoryIterator::SKIP_DOTS"))
341 $dir =
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir_path, RecursiveDirectoryIterator::SKIP_DOTS));
344 $dir =
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir_path));
347 if (empty($dir))
return FALSE;
349 foreach ($dir as $file) {
350 $mtime = $file->getMTime();
351 if($mtime > $pre_mtime) {
352 $file_path = $file->getPathname();
353 $path_parts = pathinfo($file_path);
361 if (empty($path_parts)) {
365 $ext = strtolower($path_parts[
'extension']);
366 $type = (empty($standards_lists_mime_types[$ext])) ?
'text/plain' : $standards_lists_mime_types[$ext];
369 header(
"Pragma: public");
370 header(
"Expires: 0");
371 header(
"Cache-Control: must-revalidate, post-check=0, pre-check=0");
372 header(
"Cache-Control: private",
false);
375 header(
'Content-Type: '.$type);
378 header(
'Content-Disposition: attachment; filename="'.$path_parts[
'basename'].
'";');
379 header(
'Content-Length: '.filesize($file_path));
382 readfile($file_path);
399 $containers = Array();
403 $classification_title = $this->
attr(
'classification');
404 $classification_include_sub = $this->
attr(
'classification_sub');
410 if(array_key_exists(
'recContainerTitle', $record_properties) && !array_key_exists(
'recContainer', $record_properties)) {
411 $record_properties[
'recContainer'] =
'Container';
415 $classifications = Array();
416 if(!empty($classification_title)) {
419 foreach ($classification_uris as $classification) {
421 if($classification_include_sub) {
422 if (!preg_match (
'/^'.$classification_title.
'( - )?/',$classification[
'plnTitle']))
continue;
425 if ($classification[
'plnTitle'] != $classification_title)
continue;
427 $classifications[$classification[
'Uri']] = $classification[
'plnTitle'];
430 $record_properties[
'recClassification'] =
'Classification';
437 $search_clauses = Array();
438 if (!empty($parent_container_record_number)) {
445 $operations = Array (
455 if(!empty($classification_title)) {
456 foreach ($object_list as $index => $record_info) {
457 if (!isset($classifications[$record_info[
'recClassification']]))
continue;
458 $record_classification = $classifications[$record_info[
'recClassification']];
459 $object_list[$index][
'classification_title'] = $record_classification;
460 $object_list[$index][
'classification_title_1'] = $classification_title;
462 if ($record_classification !== $classification_title) {
463 $record_classification = preg_replace(
'/^'.$classification_title.
' - /',
'', $record_classification, 1);
464 $record_classification_level = explode (
' - ', $record_classification);
466 foreach ($record_classification_level as $level_title) {
467 $object_list[$index][
'classification_title_'.$i] = $level_title;
474 $record_type_uris = Array();
475 foreach ($object_list as $index => $record_info) {
476 foreach ($record_info as $key => $value) {
478 if($this->
attr(
'convert_timezone') && preg_match(
'/ GMT$/', $value)) {
479 $local_datetime = date(
'D, d M Y H:i:s', strtotime($value));
480 $object_list[$index][$key] = empty($local_datetime) ? $value : $local_datetime;
484 if(preg_match(
'/[^a-zA-Z0-9_-]/', $key)) {
485 $new_key = preg_replace(
'/[^a-zA-Z0-9_-]+/',
'', $key);
486 $new_value = $object_list[$index][$key];
487 unset($object_list[$index][$key]);
488 $object_list[$index][$new_key] = $new_value;
492 if($key ===
'recRecordType') {
493 $record_type_uris[] = $value;
499 if(!empty($record_type_uris)) {
501 $retrieved_info = $this->
attr(
'retrieved_fields');
502 if(isset($retrieved_info[
'record_types'])) {
503 $record_names_data = $retrieved_info[
'record_types'];
509 foreach ($object_list as $index => $record_info) {
510 foreach ($record_info as $key => $value) {
511 if($key ===
'recRecordType') {
512 $new_value = isset($record_names_data[$value]) ? $record_names_data[$value] : $value;
513 $object_list[$index][$key] = $new_value;
519 if(array_key_exists(
'recContainerTitle', $record_properties)) {
520 $record_properties = Array(
'recTitle' => 1 );
521 foreach ($object_list as $index => $record_info) {
522 if($record_info[
'recContainer']!=
'') {
523 if(!array_key_exists($record_info[
'recContainer'], $containers)) {
525 foreach($results as $r) {
526 $containers[$record_info[
'recContainer']] = $r[
'recTitle'];
529 $object_list[$index][
'recContainerTitle'] = $containers[$record_info[
'recContainer']];
531 $object_list[$index][
'recContainerTitle'] =
'';
565 $hash = md5(
'resultSet');
580 $connector_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_NOTICE,
'trim_connector', FALSE,
'trim_connector');
581 if (!empty($connector_link)) {
582 $connector = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($connector_link[
'minorid']);
587 $connection = Array();
588 $connection[
'wsdl'] = $connector->attr(
'wsdl');
589 $connection[
'authentication'] = Array (
590 'login' => $connector->attr(
'username'),
591 'password' => $connector->attr(
'password'),
593 'exceptions' => TRUE,
596 if(method_exists($connector,
'getProxy')) {
597 $proxy = $connector->getProxy();
598 $connection[
'authentication'] = array_merge($connection[
'authentication'], $proxy);
614 $record_search_options = Array();
625 return $record_search_options;
639 if (isset($record_info[
'Uri']) && $record_info[
'Uri'] != 0 && (!isset($record_info[
'error']))) {
640 $record_info[
'document_url'] =
'';
642 if (isset($record_info[
'recDocumentType']) && $record_info[
'recDocumentType'] !=
'Record has no document attached.') {
644 $operations = Array (
649 $hash_key = $GLOBALS[
'SQ_SYSTEM']->user->attr(
'username').time();
650 $final_file_path = $this->data_path.
'/'.$record_info[
'Uri'];
651 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
652 create_directory($final_file_path);
656 $record_info[
'document_url'] = $this->
getURL().
'?Uri='.$record_info[
'Uri'];
673 $dynamic_vars = $this->
attr(
'dynamic_vars');
674 if (!isset($dynamic_vars[$variable_name]))
return '';
677 $value = $parameter_map->getParameterValue($variable_name);
680 $value = array_get_index($dynamic_vars, $variable_name,
'');
701 if (isset($_GET[
'Uri']) && !empty($_GET[
'Uri'])) {
703 if (!$download_result) {
704 trigger_error(
'Unable to retrieve file', E_USER_WARNING);
706 }
else if (isset($_GET[
'check_update']) && !empty($_GET[
'check_update'])) {
708 echo
'var numUpdate = false;';
712 $result = $this->getCachedResults($hash);
714 if (!empty($result)) {
717 foreach ($result as $index => $record_info) {
718 foreach ($new_object_list as $new_index => $new_record_info) {
720 if ($record_info[
'Uri'] == $new_record_info[
'Uri']) {
721 if ($record_info[
'Version'] !== $new_record_info[
'Version']) {
729 $final_count = $i+abs(count($result) - count($new_object_list));
730 echo
'var numUpdate = '.$final_count.
';';
733 echo
'var numUpdate = '.count($new_object_list).
';';
737 }
else if (isset($_GET[
'synch_now']) && !empty($_GET[
'synch_now'])) {
765 if ($name ==
'download_files') {
766 $res_val = parent::setAttrValue($name, $value);
770 return parent::setAttrValue($name, $value);
789 public function getAsset($assetid, $type_code=
'', $mute_errors=FALSE)
791 $asset = parent::getAsset($assetid, $type_code=
'', $mute_errors=FALSE);
792 if (isset($_REQUEST[
'a']) && isset($_REQUEST[
'a']) == $assetid) {
794 if (!is_null($asset)) {
795 if (isset($asset->vars[
'Uri']) && !empty($asset->vars[
'Uri'])) {
817 $fields = $this->
attr(
'retrieved_fields');
818 if(empty($fields))
return Array();
820 if ($type ==
'additional') {
821 return $fields[
'additional_fields'];
823 else if ($type ==
'standard') {
824 return $fields[
'standard_fields'];
827 return (array_merge($fields[
'standard_fields'], $fields[
'additional_fields']));
841 $fields = $this->
attr(
'retrieved_fields');
842 if(empty($fields) || !isset($fields[
'field_types']))
return '';
843 $field_types = $fields[
'field_types'];
844 return (isset($field_types[$field]) ? $field_types[$field] :
'');