tiki-admin_dsn.tpl 10.2 KB
Newer Older
1
{title help="Admin DSN"}{tr}Admin Content Sources{/tr}{/title}
awcolley's avatar
awcolley committed
2

3 4 5
{remarksbox type="tip" title="{tr}Tip{/tr}"}
	{tr}Use Admin DSN to define the database to be used by the SQL plugin.{/tr}
{/remarksbox}
6

7
<h2>{tr}Create/edit DSN{/tr}</h2>
8
<form action="tiki-admin_dsn.php" method="post" class="form-horizontal" role="form">
9
	{ticket}
10
	<input type="hidden" name="dsnId" value="{$dsnId|escape}">
11
	<div class="form-group row">
12
		<label class="col-sm-3 col-form-label" for="name">{tr}Name{/tr}</label>
13
		<div class="col-sm-9">
14 15 16
			<input type="text" maxlength="255" name="name" id="name" class="form-control" value="{$info.name|escape}">
		</div>
	</div>
17
	<div class="form-group row">
18
		<label class="col-sm-3 col-form-label" for="dsn">{tr}DSN{/tr}</label>
19
		<div class="col-sm-9">
20 21 22 23
			<input type="text" maxlength="255" class="form-control" name="dsn" id="dsn" value="{$info.dsn|escape}">
		</div>
	</div>
	<div class="form-group text-center">
24
		<input type="submit" class="btn btn-primary" name="save" value="{tr}Save{/tr}">
25
	</div>
awcolley's avatar
awcolley committed
26
</form>
27
<h2>{tr}DSN{/tr}</h2>
28
<div class="{if $js}table-responsive{/if}"> {* table-responsive class cuts off css drop-down menus *}
29
	<table class="table table-striped table-hover">
30 31 32 33 34 35 36
		<tr>
			<th>
				<a href="tiki-admin_dsn.php?offset={$offset}&amp;sort_mode={if $sort_mode eq 'name_desc'}name_asc{else}name_desc{/if}">{tr}Name{/tr}</a>
			</th>
			<th>
				<a href="tiki-admin_dsn.php?offset={$offset}&amp;sort_mode={if $sort_mode eq 'dsn_desc'}dsn_asc{else}dsn_desc{/if}">{tr}DSN{/tr}</a>
			</th>
37
			<th></th>
38
		</tr>
39 40

		<tr>
41 42
			<td class="text">{tr}Local (Tiki database){/tr}</td>
			<td class="text">{tr}See db/local.php{/tr}</td>
43
			<td class="action float-sm-right">
44
				{permission_link mode=icon type=dsn id=local title=local}
45 46
			</td>
		</tr>
47 48 49 50 51
		{section name=user loop=$channels}
			<tr>
				<td class="text">{$channels[user].name}</td>
				<td class="text">{$channels[user].dsn}</td>
				<td class="action">
52
					{actions}
53
						{strip}
54 55 56 57 58 59 60 61 62
							<action>
								<a href="tiki-admin_dsn.php?offset={$offset}&amp;sort_mode={$sort_mode}&amp;dsnId={$channels[user].dsnId}">
									{icon name='edit' _menu_text='y' _menu_icon='y' alt="{tr}Edit{/tr}"}
								</a>
							</action>
							<action>
								{permission_link mode=text type=dsn id=$channels[user].name title=$channels[user].name}
							</action>
							<action>
63
								<a id="delete-link" href="tiki-admin_dsn.php?offset={$offset}&amp;sort_mode={$sort_mode}&amp;remove={$channels[user].dsnId}" onclick="confirmSimple(event, '{tr}Remove DSN?{/tr}', '{ticket mode=get}')">
64 65 66
									{icon name='remove' _menu_text='y' _menu_icon='y' alt="{tr}Remove{/tr}"}
								</a>
							</action>
67
						{/strip}
68
					{/actions}
69 70 71 72
				</td>
			</tr>
		{/section}
	</table>
73
</div>
74

75
{pagination_links cant=$cant_pages step=$prefs.maxRecords offset=$offset}{/pagination_links}
76 77

<h2>{tr}Content Authentication{/tr}</h2>
78
<form id="source-form" method="post" action="{service controller=auth_source}" class="form-horizontal" role="form">
79
	{ticket}
80 81
	<fieldset>
		<legend>{tr}Identification{/tr}</legend>
82
		<div class="form-group row">
83
			<label class="col-sm-3 col-form-label">{tr}Identifier{/tr}</label>
84 85 86 87 88 89 90 91 92
			<div class="col-sm-3">
				<select name="existing" class="form-control">
					<option value="">{tr}New{/tr}</option>
				</select>
			</div>
			<div class="col-sm-4">
				<input type="text" name="identifier" class="form-control">
			</div>
		</div>
93
		<div class="form-group row">
94
			<label class="col-sm-3 col-form-label" for="url">{tr}URL{/tr}</label>
95 96 97 98
			<div class="col-sm-4">
				<input type="url" name="url" id="url" class="form-control" />
			</div>
		</div>
99
		<div class="form-group row">
100
			<label class="col-sm-3 col-form-label" for="method">{tr}Type{/tr}</label>
101
			<div class="col-sm-4">
102
				<select name="method" id="method" class="form-control">
103 104 105 106 107 108
					<option value="basic">{tr}HTTP Basic{/tr}</option>
					<option value="post">{tr}HTTP Session / Login{/tr}</option>
					<option value="get">{tr}HTTP Session / Visit{/tr}</option>
				</select>
			</div>
		</div>
109 110 111
	</fieldset>
	<fieldset class="method basic">
		<legend>{tr}HTTP Basic{/tr}</legend>
112
		<div class="form-group row">
113
			<label class="col-sm-3 col-form-label" for="basic_username">{tr}Username{/tr}</label>
114 115 116 117
			<div class="col-sm-9">
				<input type="text" name="basic_username" id="basic_username" class="form-control">
			</div>
		</div>
118
		<div class="form-group row">
119
			<label class="col-sm-3 col-form-label" for="basic_password">{tr}Password{/tr}</label>
120 121 122 123
			<div class="col-sm-9">
				<input type="password" name="basic_password" id="basic_password" class="form-control">
			</div>
		</div>
124
	</fieldset>
125 126
	<fieldset class="method post">
		<legend>{tr}HTTP Session / Login{/tr}</legend>
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
		<div class="form-group row">
			<label class="col-sm-3 col-form-label" for="post_url">{tr}URL{/tr}</label>
			<div class="col-sm-9">
				<input type="url" name="post_url" id="post_url" class="form-control">
			</div>
		</div>
		<div class="form-group row">
			<div class="col-sm-3"></div>
			<div class="col-sm-9 col-sm-offset-3">
				<table class="col-sm-9 col-sm-offset-3">
					<thead>
					<tr><th>{tr}Name{/tr}</th><th>{tr}Value{/tr}</th></tr>
					</thead>
					<tfoot>
					<tr>
						<td><input type="text" name="post_new_field"></td>
						<td><input type="text" name="post_new_value"></td>
						<td><input type="submit" class="btn btn-primary btn-sm" name="post_new_add" value="{tr}Add{/tr}"></td>
					</tr>
					</tfoot>
					<tbody>
					</tbody>
				</table>

			</div>
		</div>
153
	</fieldset>
154 155
	<fieldset class="method get">
		<legend>{tr}HTTP Session / Visit{/tr}</legend>
156 157 158 159 160 161
		<div class="form-group row">
			<label class="col-sm-3 col-form-label" for="get_url">{tr}URL{/tr}</label>
			<div class="col-sm-9">
				<input type="url" name="get_url" id="get_url" class="form-control">
			</div>
		</div>
162
	</fieldset>
163
	<fieldset>
164
		<div class="form-group text-center">
165
			{* checkTimeout() onclick function applied in JQuery code below *}
166
			<input type="submit" class="btn btn-primary" name="save" value="{tr}Save{/tr}">
167
			<input type="submit" class="btn btn-primary" name="delete" value="{tr}Delete{/tr}">
168
		</div>
169 170 171 172
	</fieldset>
</form>
{jq}
$('#source-form').each(function () {
173
	var form = this,
174 175
		reload = function () {
			$('option.added', form).remove();
176
			$.getJSON($.service('auth_source', 'list'), function (entries) {
177 178 179
				$.each(entries, function (k, v) {
					$(form.existing).append($('<option class="added"/>').text(v));
				});
180 181

				$(form.existing).trigger('chosen:updated');
182
			});
183 184 185 186 187
		},
		addPostRow = function (name, value) {
			var row = $('<tr/>');
			row.append($('<td/>').text(name));
			row.append($('<td/>').text(value));
lindonb's avatar
lindonb committed
188
			row.append($('<td>{{icon name=remove}}</td>').css('cursor', 'pointer').click(function () {
189 190 191 192
				$(this).closest('tr').remove();
				return false;
			}));
			$('fieldset.method.post tbody', form).append(row);
193 194 195
		},
		fetchAuthentication = function(identifier) {
			$(form.identifier).hide();
196

197
			$.getJSON($.service('auth_source', 'fetch'), {
198
				identifier: identifier
199
			}, function (data) {
200 201
				var id = data.identifier;
				$(form.existing).val(id);
202 203 204 205 206 207 208 209
				$(form.method).val(data.method).change();
				$(form.url).val(data.url);

				switch (data.method) {
				case 'basic':
					$(form.basic_username).val(data.arguments.username);
					$(form.basic_password).val(data.arguments.password);
					break;
210 211 212
				case 'get':
					$(form.get_url).val(data.arguments.url);
					break;
213 214 215 216 217 218 219 220
				case 'post':
					$(form.post_url).val(data.arguments.post_url);
					$.each(data.arguments, function (key, value) {
						if (key !== 'post_url') {
							addPostRow(key, value);
						}
					});
					break;
221 222
				}
			});
223 224 225 226 227 228 229 230 231 232 233
		};

	$(form).submit(function () {
		return false;
	});

	$(form.existing).change(function () {
		var val = $(this).val();

		if (val.length) {
			fetchAuthentication($(form.existing).val());
234 235
		} else {
			$(form.identifier).show().val('').focus();
236
			$('input:not(:submit):not([name=ticket])', form).val('');
237
			$('fieldset.method.post tbody').empty();
238 239 240
		}
	});

241
	$(form.method).change(function () {
242 243
		$('fieldset.method', form).hide();
		$('fieldset.method.' + $(this).val(), form).show();
244
	}).change();
245 246 247 248

	reload();

	$(form.save).click(function () {
249
		checkTimeout();
250 251 252 253
		var data = {
			action: 'save',
			identifier: $(form.identifier).val(),
			url: $(form.url).val(),
254 255
			method: $(form.method).val(),
			ticket: $(form.ticket).val()
256 257 258 259 260 261
		}, isNew = $(form.existing).val() === '';

		switch (data.method) {
		case 'basic':
			data['arguments~username'] = $(form.basic_username).val();
			data['arguments~password'] = $(form.basic_password).val();
262 263 264
			break;
		case 'get':
			data['arguments~url'] = $(form.get_url).val();
265
			break;
266 267 268 269 270 271 272
		case 'post':
			data['arguments~post_url'] = $(form.post_url).val();

			$('fieldset.method.post tbody tr').each(function () {
				var name = this.childNodes[0], value = this.childNodes[1];
				data['arguments~' + $(name).text()] = $(value).text();
			});
273 274 275 276
		}

		$(form.existing).val('').change();

277
		$.post($(form).attr('action'), data, function () {
278 279 280 281 282
			if (isNew) {
				$(form.existing).append($('<option/>').text(data.identifier));
			}

			$(form.existing).val(data.identifier).change();
283
			$(form.existing).trigger('chosen:updated');
284 285 286
		}, 'json')
		.done(function (data) {
			location.href = location.href.replace(/\?.*$/, "") + '?identifier=' + encodeURIComponent(data.identifier);
287 288 289 290 291
		});
		return false;
	});

	$(form.delete).click(function () {
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
		checkTimeout();
		if (confirm(tr('Delete authentication?'))) {
			$.post($(form).attr('action'), {
				action: 'delete',
				identifier: $(form.existing).val(),
				ticket: $(form.ticket).val()
			}, function () {
				$(form.existing).val('').change();
				reload();
			}, 'json')
			.done(function (data) {
				location.href = location.href.replace(/\?.*$/, "");
			});
			return false;
		}
307 308
	});

309 310 311 312 313 314
	$(form.post_new_add).click(function () {
		addPostRow($(form.post_new_field).val(), $(form.post_new_value).val());
		$(form.post_new_field).val('').focus();
		$(form.post_new_value).val('');
		return false;
	});
315 316 317 318 319 320 321 322 323 324

	if (location.href.indexOf('identifier=') > -1) {
		var oneparam = [], paramarray = {}, urlparams = location.href.slice(location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < urlparams.length; i++) {
			oneparam = urlparams[i].split('=');
			paramarray[oneparam[0]] = decodeURIComponent(oneparam[1]);
		}
		fetchAuthentication(paramarray['identifier']);
	}

325 326
});
{/jq}