1{* $Id$ *}
2<h2 class="card-title">{tr}Occurrences of string in database{/tr}</h2>
3<div class="adminoptionbox clearfix form-group row">
4	<label for="string_in_db_search_table" class="col-form-label col-sm-4">
5		{tr}Set default table:{/tr}
6	</label>
7	<div class="col-sm-7">
8		<div class="input-group">
9			<select name="string_in_db_search_table" class="form-control" id="string_in_db_search_table">
10			<option value="">All tables</option>
11			{foreach $tables as $table}
12				<option value="{$table|escape}" {if isset($tableFilter) && $table eq $tableFilter} selected="selected"{/if}>{$table|escape}</option>
13			{/foreach}
14			</select>
15		</div>
16	</div>
17</div>
18<div class="adminoptionbox clearfix form-group row">
19	<label for="string_in_db_search" class="col-form-label col-sm-4">
20		{tr}Text to search:{/tr}
21	</label>
22	<div class="col-sm-4">
23		<div class="input-group">
24			<input type="text" id="string_in_db_search" name="string_in_db_search" class="form-control" value="{$searchStringAgain|escape}" />
25		</div>
26	</div>
27	<div class="col-sm-3">
28		<div class="input-group">
29			<input type="submit" id="string_in_db_search_button" class="btn btn-primary" value="{tr}Search{/tr}" onClick="document.getElementById('redirect').value='0';"/>
30		</div>
31	</div>
32	{jq}
33		$('#string_in_db_search').keypress(function (e) {
34			var key = e.which;
35			if(key == 13)  // the enter key code
36			{
37				$('#string_in_db_search_button').click();
38				return false;
39			}
40		});
41	{/jq}
42	<input type="hidden" id="redirect" name="redirect" value="1">
43</div>
44
45<hr/>
46{if isset($errorMsg)}
47	<span id="error">{$errorMsg}</span>
48{else}
49	{if isset($searchString)}
50		{remarksbox}{tr}Results for {/tr}<b>{$searchString|escape}</b> {tr}in {if isset($tableFilter)}table <b>{$tableFilter|escape}</b>{else}all tables{/if}:{/tr}{/remarksbox}
51		<p>
52
53		<input type="hidden" name="query" value="{$searchString|escape}">
54		<input type="hidden" id="table" name="table" value="">
55		<input type="hidden" id="column" name="column" value="">
56
57		<table class="string_in_db_search table normal">
58		<tr>
59		<th>{tr}Table{/tr}</th>
60		<th>{tr}Column{/tr}</th>
61		<th>{tr}Occurrences{/tr}</th>
62		</tr>
63		{$last = ''}
64		{foreach from=$searchResult item=res}
65			{$table = $res['table']}
66			{if isset($tableFilter) && $table neq $tableFilter}
67				{continue}
68			{/if}
69			<tr>
70			{if $last eq '' || $last neq $table}
71				{$span = $tableCount["$table"]}
72				<td rowspan="{$span}">{$table|escape}</td>
73			{/if}
74			<td><input type="submit" class="btn btn-link" value="{$res['column']|escape}" title="{tr}View occurrences{/tr}" onClick="document.getElementById('table').value='{$res['table']}'; document.getElementById('column').value='{$res['column']}'; document.getElementById('redirect').value='0'; document.getElementById('string_in_db_search').value='';"></td>
75			<td>{$res['occurrences']|escape}</td>
76			</tr>
77			{$last = $table}
78		{/foreach}
79		</table>
80		</p>
81		<hr>
82	{/if}
83
84	{if isset($tableHeaders)}
85		{remarksbox}{tr}Results for {/tr}<b>{$searchStringAgain|escape}</b> {tr}in table {/tr} <b>{$tableName}</b>, {tr}column{/tr} <b>{$columnName}</b>:{/remarksbox}
86		<table class="table-responsive">
87		<tr>
88		{foreach from=$tableHeaders item=hdr}
89			<th>{if $hdr eq $columnName}<em>{$hdr}</em>{else}{$hdr}{/if}</th>
90		{/foreach}
91		</tr>
92
93		{foreach from=$tableData item=row}
94			<tr>
95			{foreach from=$row key=column item=val}
96				{$value = $val|truncate:30|escape}
97				{if $tableName=='tiki_pages' && ($column=='pageName' || $column=='pageSlug' || $column=='data' || $column=='description') && $val}
98					{if $column=='data'}
99						<td><a tabindex='0' target='_blank' data-trigger='hover' title='{tr}Page preview{/tr}' class="ajaxtips" data-ajaxtips="{service controller='wiki' action='get_page' page=$row['pageName']}">
100								 {$row['snippet']}
101							</a>
102						</td>
103					{else}
104						<td><a href="{$row['pageName']|sefurl:wiki}"  class="link tips" title="{$row['pageName']}: {tr}View page{/tr}" target="_blank">{$value}</a></td>
105						<!-- TODO: (but see note about object_link in templates/tiki-listpages_content.tpl) <td>{object_link type='wiki page' id={$row['pageName']|escape} class="link tips" title="{$val|escape}:{tr}View page{/tr}"}</td> -->
106					{/if}
107				{elseif $column=='lastModif' || $column=='created' || $column=='commentDate' || $column=='publishDate' || $column=='expireDate'}
108					<td>{$value|tiki_short_datetime}</td>
109				{elseif $tableName=='tiki_blog_posts' && ($column=='data' || $column=='title')}
110					<td><a href=tiki-view_blog_post.php?postId={$row['postId']} class="link tips" title="{$row['title']|escape}:{tr}View blog post{/tr}" target="_blank">{$value}</a></td>
111				{elseif $tableName=='tiki_files' && ($column=='name' || $column=='description' || $column=='filename')}
112					<td><a href=tiki-download_file.php?fileId={$row['fileId']}&display class="link tips" title="{$row['name']|escape}:{tr}View file{/tr}" target="_blank">{$value}</a></td>
113				{elseif $tableName=='tiki_file_galleries' && $column=='name'}
114					<td><a href=tiki-list_file_gallery.php?galleryId={$row['galleryId']} class="link tips" title="{$val|escape}:{tr}View gallery{/tr}" target="_blank">{$value}</a></td>
115				{elseif $tableName=='tiki_categories' && ($column=='name'|| $column=='description')}
116					<td><a href=tiki-admin_categories.php?parentId={$row['parentId']}&categId={$row['categId']} class="link tips" title="{$row['name']|escape}:{tr}View category{/tr}" target="_blank">{$value}</a></td>
117				{elseif $tableName=='tiki_articles' && ($column=='title'|| $column=='heading')}
118					<td><a href=tiki-read_article.php?articleId={$row['articleId']} class="link tips" title="{$row['title']|escape}:{tr}View article{/tr}" target="_blank">{$value}</a></td>
119				{elseif $tableName=='tiki_forums' && ($column=='name'|| $column=='description')}
120					<td><a href=tiki-view_forum.php?forumId={$row['forumId']} class="link tips" title="{$row['name']|escape}:{tr}View forum{/tr}" target="_blank">{$value}</a></td>
121				{elseif $tableName=='tiki_calendars' && ($column=='name'|| $column=='description')}
122					<td><a href=tiki-calendar.php?calIds[]={$row['calendarId']} class="link tips" title="{$row['name']|escape}:{tr}View calendar{/tr}" target="_blank">{$value}</a></td>
123				{elseif $tableName=='tiki_calendar_items' && ($column=='name'|| $column=='description')}
124					<td><a href=tiki-calendar_edit_item.php?viewcalitemId={$row['calitemId']} class="link tips" title="{$row['name']|escape}:{tr}View calendar item{/tr}" target="_blank">{$value}</a></td>
125				{elseif $tableName=='tiki_trackers' && ($column=='name'|| $column=='description')}
126					<td><a href=tiki-view_tracker.php?trackerId={$row['trackerId']} class="link tips" title="{$row['name']|escape}:{tr}View tracker{/tr}" target="_blank">{$value}</a></td>
127				{elseif $tableName=='tiki_tracker_item_fields' && $column=='value'}
128					<td><a href=tiki-view_tracker_item.php?itemId={$row['itemId']} class="link tips" title="{$row['value']|escape}:{tr}View tracker item{/tr}" target="_blank">{$value}</a></td>
129				{elseif $tableName=='tiki_comments'}
130					{if $row['objectType']=='blog post'}
131						{if ($column=='objectType' || $column=='data')}
132							<td><a href=tiki-view_blog_post.php?postId={$row['object']} class="link tips" title="{$row['data']|escape}:{tr}View blog post{/tr}" target="_blank">{$value}</a></td>
133						{else}
134							<td>{$value}</td>
135						{/if}
136					{elseif $row['objectType']=='forum'}
137						{if ($column=='objectType' || $column=='data' || $column=='title')}
138							{if $row['parentId']==0}
139								<td><a href=tiki-view_forum_thread.php?forumId={$row['object']}&comments_parentId={$row['threadId']}#threadId{$row['threadId']} class="link tips" title="{$row['title']|escape:'htmlall'}:{tr}View forum comment{/tr}" target="_blank">{$value}</a></td>
140							{else}
141								<td><a href=tiki-view_forum_thread.php?comments_parentId={$row['parentId']}#threadId{$row['threadId']} class="link tips" title="{$row['title']|escape:'htmlall'}:{tr}View forum comment{/tr}" target="_blank">{$value}</a></td>
142							{/if}
143						{else}
144							<td>{$value}</td>
145						{/if}
146					{elseif $row['objectType']=='article'}
147						{if ($column=='objectType' || $column=='data')}
148							<td><a href=tiki-read_article.php?articleId={$row['object']} class="link tips" title="{$row['data']|escape}:{tr}View article{/tr}" target="_blank">{$value}</a></td>
149						{else}
150							<td>{$value}</td>
151						{/if}
152					{elseif $row['objectType']=='wiki page'}
153						{if ($column=='objectType' || $column=='data' || $column=='object')}
154							<td><a href="{$row['object']|sefurl}?threadId={$row['threadId']|escape:"url"}&comzone=show#threadId{$row['threadId']|escape:"url"}" class="link tips" title="{$row['object']|escape}: {tr}View page{/tr}" target="_blank">{$value}</a></td>
155						{else}
156							<td>{$value}</td>
157						{/if}
158					{else}
159						<td>{$value}</td>
160					{/if}
161				{else}
162					<td>{$value}</td>
163				{/if}
164			{/foreach}
165			</tr>
166		{/foreach}
167		</table>
168		<p><a href="javascript:void(0)" class="btn btn-primary btn-sm" title="{tr}Back to first level results{/tr}" onClick="document.getElementById('string_in_db_search').value='{$searchStringAgain|escape}'; document.getElementById('string_in_db_search_button').click();">{tr}Back to first level results{/tr}</a></p>
169	{/if}
170{/if}
171