<script language="javascript" >
{literal}
function SetCookie (name, value) {
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=name+"="+escape(value)+
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
}
	// 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)
	
	function select_ids(cmd) {
		formElements = document.forms['main'].elements;
		chckboxes = new Array();
		// alert('il y a formelements ' + formElements.length);
		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;
		}
		//document.main.submit();
	} // end of select_ids(cmd)

	function centeredPopup2(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 checks if each checkbox is checked
	// If it is 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()');
		var 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 = '';
		alert('il y a formelements ' + formElements.length);
		for(i = 0; i < formElements.length; i++) {
			var chkbx = formElements[i];
			if (formElements[i].type != 'checkbox') // if it is not a checkbox, ignore it
			{
				continue;
				alert('is not a checkbox ' + i );
			}
			
			if (formElements[i].checked == true) { // for all cheked checkboxes
				// DEBUG
				s +='checked : ' + chkbx.name + "";
				/*// 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 + "";
				 SetCookie(chkbx.name, 0);
			}
		}
		 alert(s);
		// alert('End treatSelectedFiles() total ' + i);
	} // 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>
				<div align="left" class="bugdisplaylinks">
					<b>
						<a href="{$smarty.server.PHP_SELF}?op=print">
							<!--	{$STRING.WRAP.PrintList}-->
						</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>
<form method="POST" action="bug.php" name="main" onSubmit="">
<input type="hidden" name="op" value="edit_multi" />
<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.sel.$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_old()\""
				}
			<input type="hidden" name="sel_stct[{$v.bug_id}]" value="{$v.bug_id}" />
			</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 -->
	{if $smarty.session.uid}
	<table>
		<tr>
			<td>
				 <!--un/select all files of this page --> 
				<a href="javascript:select_ids('select_all');">
					{$STRING.check_all_files}
				</a>
				/
				<a href="javascript:select_ids('unselect_all');">
					{$STRING.uncheck_all_files}
				</a>
			</td>
			<td width="1">				
			</td>
			<td>
				{$STRING.action} :
				<br> {$select_field}
<!--				<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" name="modify" value="OK">
			</td>
			<td width="1"></td> 
			<td colspan="{$nb_columns}" align="left">
				<!-- un/select all result files -->
			</td>
		</tr>		
		<tr>
			<td>
				 {$STRING.remember_selection}
				<input type="submit" name="remember" value="{$STRING.remember}">
				<br>
				 {$STRING.erase_selection}
				<input type="submit" name="erase" value="{$STRING.erase}">
			</td>
			<td>
		{$STRING.SaveListAs}: <input maxlength="40" type="text" name="savedqueryname">
	<input type="submit" name="save" value="{$STRING.Save}">
		<br><br>
			</td>
		</tr>		
	</table>
	{/if}
</form>