17 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_CORE_PACKAGE_PATH.
'/data_source/data_source/data_source_edit_fns.inc';
35 public $result = NULL;
36 public $fields = Array();
37 public $selected_fields = Array();
38 public $group_by = Array();
48 parent::__construct();
66 $connector_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE,
'db_connector', FALSE,
'db_connector');
67 if (empty($connector_link)) {
68 $connector_asset_id = NULL;
70 $connector_asset_id = $connector_link[
'minorid'];
73 if ($asset->writeAccess(
'links')) {
74 asset_finder($prefix.
'_connector_node', $connector_asset_id, Array(
'db_connector'=>
'D'));
76 if (empty($connector_asset_id)) {
77 echo
'No connector selected';
79 echo get_asset_tag_line($connector_asset_id);
99 $new_connector_id = @$_REQUEST[$prefix.
'_connector_node'][
'assetid'];
101 if (!$asset->writeAccess(
'links')) {
102 trigger_error(
'You do not have write access to change the connector link', E_USER_WARNING);
106 $current_connector_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE,
'db_connector', FALSE,
'db_connector');
107 $current_connector_asset_id = @$current_connector_link[
'minorid'];
109 if (!empty($current_connector_link)) {
112 if ((!empty($new_connector_id)) && ($current_connector_asset_id === $new_connector_id)) {
117 $GLOBALS[
'SQ_SYSTEM']->am->deleteAssetLink($current_connector_link[
'linkid']);
121 if (empty($new_connector_id))
return TRUE;
125 if (!empty($new_connector_id)) {
126 $new_connector_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($new_connector_id);
127 $result_id = $GLOBALS[
'SQ_SYSTEM']->am->createAssetLink($asset, $new_connector_asset, SQ_LINK_NOTICE,
'db_connector');
129 if (empty($result_id)) {
130 trigger_error(
'Could not link the connector to this asset', E_USER_WARNING);
156 $wa = $asset->writeAccess(
'attributes');
157 $db_type = $asset->attr(
'db_type');
158 $database = $asset->attr(
'database');
159 $host = $asset->attr(
'host');
161 <table
class=
"sq-backend-table">
163 <td><?php echo translate(
'database_type');?></td>
166 $options = Array(
'postgres' =>
'PostgreSQL',
'oracle' =>
'Oracle',
'mysql' =>
'MySQL');
168 combo_box(
'dsn[db_type]', $options, FALSE, $db_type);
170 if (empty($db_type)) {
171 ?><em>Ignored due to Complete
DSN entry</em><?php
173 echo $options[$db_type];
180 <td><?php echo translate(
'database_name');?></td>
184 text_box(
'dsn[database]', $database, 35);
192 <td><?php echo translate(
'host_name');?></td>
196 text_box(
'dsn[host]', $host, 35);
226 $dsn = $asset->attr(
'dsn');
227 $new_dsn_string = NULL;
228 $new_dsn = $_POST[
'dsn'];
229 if (!empty($_POST[
'dsn'][
'dsn'])) {
230 $new_dsn_string = $_POST[
'dsn'][
'dsn'];
231 $new_dsn[
'db_type'] = NULL;
232 $new_dsn[
'host'] = NULL;
233 $new_dsn[
'database'] = NULL;
235 switch ($new_dsn[
'db_type']) {
237 $new_dsn_string =
"pgsql:";
240 $new_dsn_string =
"mysql:";
243 $new_dsn_string =
"oci:";
247 if ($new_dsn[
'db_type'] ==
'oracle') {
253 $new_dsn_string .=
'dbname=';
256 if (!empty($new_dsn[
'host'])) {
257 $new_dsn_string .=
"$new_dsn[host]/";
261 $new_dsn_string .=
"$new_dsn[database]";
263 $new_dsn_string .=
"dbname=$new_dsn[database];host=$new_dsn[host]";
266 if (strcasecmp($dsn, $new_dsn_string) != 0) {
267 foreach ($new_dsn as $key => $value) {
268 $asset->setAttrValue($key, $value);
271 $asset->setAttrValue(
'dsn', $new_dsn_string);
291 $dsn = $asset->attr(
'dsn');
292 $wa = $asset->writeAccess(
'attributes');
293 $database = $asset->attr(
'database');
295 text_area(
'dsn[dsn]', empty($database) ? $dsn :
'', 70, 5);
298 if (!empty($dsn)) echo $dsn;
337 $wa = $asset->writeAccess(
'attributes');
338 $sql = $asset->attr(
'sql');
341 $dynamic_vars = $asset->attr(
'dynamic_vars');
342 if (!empty($dynamic_vars)) {
343 foreach ($dynamic_vars as $var => $value) {
344 $keywords[
'%%'.$var.
'%%'] = $var;
346 keyword_selector($keywords, $prefix.
'_sql');
348 text_area($prefix.
'_sql', $sql, 100, 40, 0,
'style="width: 100%; height: 30em; font-family: \'Courier New\', Courier, monospace; display: block"');
352 hidden_field($prefix.
'_sql', $sql);
374 if (isset($_POST[$prefix.
'_sql'])) {
375 return $asset->setAttrValue(
'sql', $_POST[$prefix.
'_sql']);
395 if ($asset->connectToDB()) {
396 echo
'<div style="color: green"><b>Connected</b></div>';
398 echo
'<div style="color: red"><b>Not connected</b></div>';
401 if (isset($asset->_tmp[
'db_conection_exception'])) {
402 echo
"<div>Connection failed: ".$asset->_tmp[
'db_conection_exception']->getMessage().
"</div>";