<script language="javascript" >
<!--
{literal}
	// open a popup at the center of the screen
	function centeredPopup(url, width, height, options) {
		var top=(screen.height - height) / 2;
		var left=(screen.width - width) / 2;
		window.open(url,"","top="+top+",left="+left+",width="+width+",height="+height+","+options);
	} // end of centeredPopup(url, width, height, options)
	
	// this function un/checks all checkboxes in the 'main' form
	function select_ids(cmd) {
		formElements = document.forms['main'].elements;
		chckboxes = new Array();
		for(i = 0; i < formElements.length; i++) {
			if (formElements[i].type == 'checkbox') { // take all checkboxes in the current form
				// alert('in : ' + formElements[i].name);
				chckboxes[chckboxes.length] = formElements[i]; // add this element in the checkboxes Array
			}
		}
		
		switch(cmd) {
			case 'select_all' :
				for(i = 0; i < chckboxes.length; i++) { // select all checkboxes
					chckboxes[i].checked = true;
				}
				break;
			case 'unselect_all' :
				for(i = 0; i < chckboxes.length; i++) { // unselect all checkboxes
					chckboxes[i].checked = false;
				}
				break;
		}
	} // end of select_ids(cmd)

	// this function checks if each checkbox is checked
	// If it's checked, it copies into a cookie the list of selected file ids
	// Used when a checkbox is used, or when the user clicks on a un/select_all link
	function treatSelectedFiles() {
		// alert('Start treatSelectedFiles()');
		formElements = document.forms['main'].elements;
		// chckboxes = new Array();
		var pathname=location.pathname;
		var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
		var date_exp = new Date();
		var s = '';
		for(i = 0; i < formElements.length; i++) {
			var chkbx = formElements[i];
			if (formElements[i].type != 'checkbox') // if it's not a checkbox, ignore it
				continue;
			
			if (formElements[i].checked == true) { // for all cheked checkboxes
				// DEBUG
				s +='checked : ' + chkbx.name + "\n";
				date_exp.setTime(date_exp.getTime() + (24*3600*1000)); // cookie life = 1 day
				// store in a cookie the name of checked checkboxes
				// SetCookie(chkbx.name, chkbx.value, date_exp, myDomain);
				SetCookie(chkbx.name, chkbx.value);
			} else {
				// DEBUG
				s +='unchecked : ' + chkbx.name + "\n";
				SetCookie(chkbx.name, -1);
			}
		}
		// alert(s);
		// alert('End treatSelectedFiles()');
	} // treatSelectedFiles()	
	// alert('cookie = ' + unescape(document.cookie));
{/literal}
-->
</script>
	<table cellpadding="2" border="0" width="100%">
		<TR valign="top">
		 	<td align="left" colspan="{$nb_columns}"> 
			
				<b>&nbsp;{$TITLE.search_result} : </b>
				<!-- TODO : create a "back to search form" link -->
				<!-- &nbsp;<a href="{$smarty.server.PHP_SELF}?op=query&form=advanced">{$STRING.QUERY.AdvancedQueryPage}</a> -->
				<hr size="1">
			</td>
			
		</TR>
	</table>
		{if $no_result }
		<table cellpadding="2">
		<tr>
			<td>
				{$STRING.no_result} 
				<br>
				<br>
				<a href="javascript:history.go(-1)">{$STRING.PreviousPage}</a>
			</td>
		</tr>
		</table>
		{else}
		<!-- print the number of pages, list of pages with links -->
		<table cellpadding="2">
		<tr>
		 	<td align="left" colspan="{$nb_columns}"> 
				<div align="left" class="bugdisplaylinks">
					<b>
						<a href="{$smarty.server.PHP_SELF}?op=export">
							{$STRING.WRAP.ExportList}
						</a>
					</b> 
				</div>
	 		</td> 			
		</tr>
		</table><table align="center" cellpadding="2">
		<tr align="center">
			<td colspan="{$nb_columns}" align="center">
				{$fileCount} {$STRING.nb_of_files_found}
				<br>
				{$first_url} &nbsp; {$page_links} &nbsp; {$last_url}
			</td>
		</tr>
		</table>
<table cellpadding="2">
		<!-- headers -->
		<!--	<th></th> -->
		{foreach name=header_url key=k item=v from=$field_conf}
			<th {if $v.field_name == $order}class="selected"{/if} title="{$v.description}">
				<a	title="{$v.description}"
					href="{$smarty.server.PHP_SELF}?op=redoquery&sort={if $sort == 'asc'}desc{else}asc{/if}&order={$v.field_name}&page={$page}">
					{$v.title}
				</a>
			</th>
		{/foreach}
		<!-- data -->
		{foreach name=files key=k item=v from=$files}
		<tr valign="top" align=center {if $smarty.foreach.files.iteration is even}class="alt"{/if}>
		<!--	<td>
				{* Is this file already selected ? *}
				{assign var=file_id value=$v.bug_id}
				{if $smarty.session.queryinfo.selected_file_ids.$file_id}
					{assign var=ck value=true}
				{else}
					{assign var=ck value=false}
				{/if}
				
				{* Print the checkbox for this file  *}
				{select_file_by_id 
					value=$v.project_id
					name=$v.bug_id
					checked=$ck
					input_options="onClick=\"javascript:treatSelectedFiles()\""
				}
			</td>  -->
			{foreach name=fc item=fc from=$field_conf}
				{if $fc.field_name == 'assigned_to'} 
				<td align="left"> 
					{build_dynamic_input 
						field_conf=$fc
						mpfile=$mpfile_per_file.$k
						name=$fc.field_name
						file_id=$v.bug_id
						multiple=0
						read_only=1
						override_system=0
						prepare_options=0
					}
				{elseif $fc.field_name == 'project_id'}
					<td align="left">
					{build_dynamic_input 
						field_conf=$fc
						mpfile=$mpfile_per_file.$k
						name=$fc.field_name
						value=$mpfile_per_file.$k->project_data.project_id
						multiple=0
						read_only=1
						override_system=0
						prepare_options=0
					}
				{else}
					<td align="left">
					{if (($fc.field_name == 'bug_id') or ($fc.field_name == 'title'))}
						<A href="bug.php?op=show&file_id={$v.bug_id}">
					{/if}
					{foreach name=col key=fk item=fv from=$v}					
						{if $fc.field_name == $fk}
							{build_dynamic_input 
								field_conf=$fc
								mpfile=$mpfile_per_file.$k
								name=$fk
								value=$v.$fk
								multiple=0
								read_only=1
								override_system=0
								prepare_options=0
							}
						{/if}
					{/foreach}
					{if (($fc.field_name == 'bug_id') or ($fc.field_name == 'title'))}
						</A>
					{/if}
				{/if}
			</td>
			{/foreach}
		</tr>
		{/foreach}
	</table>
		<!-- print the number of pages, list of pages with links -->
	<table align="center" cellpadding="2">
		<tr>
			<td colspan="{$nb_columns}" align="center">
				{$first_url} &nbsp; {$page_links} &nbsp; {$last_url}
				<br>
				{$fileCount} {$STRING.nb_of_files_found}
			</td>
		</tr>
	</table>
		{/if}
	<!-- Action table 
	<table>
		<tr>
			<td>
				 --un/select all files of this page -- 
				<a href="javascript:select_ids('select_all');treatSelectedFiles();">
					{$STRING.check_all_files}
				</a>
				<br>
				<a href="javascript:select_ids('unselect_all');treatSelectedFiles();">
					{$STRING.uncheck_all_files}
				</a>
			</td>
			<td width="1">				
			</td>
			<td>
				{$STRING.action} :
				<br>
				<select name="{$selected_files_array}[action_to_do]">
					{foreach item=v key=k name=action_list from=$action_list}
					<option value={$k}>
						{$STRING.action_list.$k}
					</option>
					{/foreach}
				</select>
				<input type="submit" value="OK">
			</td>
			<td width="1"></td> 
			<td colspan="{$nb_columns}" align="left">
				-- un/select all result files --
				<a href="javascript:centeredPopup('{$smarty.server.PHP_SELF|dirname}/actions.php?op=select_all_result_files', 200, 200, ''); select_ids('select_all');">
					{$STRING.select_all_files}
				</a>
				<br>
				<a href="javascript:centeredPopup('{$smarty.server.PHP_SELF|dirname}/actions.php?op=unselect_all_result_files', 200, 200, ''); select_ids('unselect_all');">
					{$STRING.unselect_all_files}
				</a>
			</td>
		</tr>		
	</table> -->
</form>
