All pastes #177444 Raw Edit

Someone

public text v1 · immutable
#177444 ·published 2006-09-20 13:43 UTC
rendered paste body
$file_output[$i][$internal] = array('widget' => array('type'	=> 'link',
																					'onClick'	=> "open_popup('" . $GLOBALS['phpgw']->link('/index.php',
																					array(
																						'menuaction' => 'filemanager.uifilemanager.history',
																						'file' => urlencode($file['name']),
																						'vers' => urlencode($file[$internal]),
																						'mime_type'=> urlencode($file['mime_type']),
																						'collapse' => urlencode('collapse'),
																						'history_path'=> urlencode($this->bofilemanager->path),
																						'history_file' => urlencode($file['name'])
																						)
																					).
																						"','1000','800');",
																					'href'		=> '#',
																					'caption'	=> $file[$internal]));

		function history()
		{
			$GLOBALS['phpgw_info']['flags']['noframework'] = True;
			$file = $this->bofilemanager->path.$this->bofilemanager->dispsep.$this->bofilemanager->file;
			$from_rev=$this->bofilemanager->from_rev;
			$to_rev=$this->bofilemanager->to_rev;
			$vers= $this->bofilemanager->vers;
			$collapse=$this->bofilemanager->collapse;
			$mime_type=$this->bofilemanager->mime_type;
			$page=$this->bofilemanager->page;
			$pages=0;

   			if($GLOBALS['phpgw']->vfs->file_exists(array('string' => $file,'relatives' => Array(RELATIVE_NONE))))
			{
				$col_headers = array
				(
					lang('')               => '',
					lang('version')				=> 'version',
					lang('date')				=> 'created',
					lang('performed by')		=> 'owner_id',
					lang('operation')			=> 'comment'
				);
				foreach($col_headers as $label => $field)
				{
					$header[] = array('widget' => array('type' => 'label','caption' => $label));
				}
				$table_head = array('table_col' => $header);
                
				if($from_rev && $to_rev)
				{
						if(!is_numeric($from_rev) || $from_rev <0 || $from_rev>$vers)
						{
							$from_rev=1;
						}	
						if(!is_numeric($to_rev) || $to_rev >$vers || $to_rev<0)
						{
							$to_rev=$vers;	
						}	
						
						if($from_rev>$to_rev)
						{
							$temp=$from_rev;
							$from_rev=$to_rev;
							$to_rev=$temp;
						}
				}
				elseif($from_rev)
				{
					if(!is_numeric($from_rev) || $from_rev <0 || $from_rev>$vers)
					{
						$from_rev=1;
					}
					$to_rev=$vers;
				}
				elseif($to_rev)
				{
					if(!is_numeric($to_rev) || $to_rev <0 || $to_rev>$vers)
					{
						$to_rev=$vers;
					}
					$from_rev=1;
				}

				$data = array(
					'string' => $file,
					'from_rev'=>$from_rev,
					'to_rev' => $to_rev,
					'vers' =>$vers,
					'relatives' => Array(RELATIVE_NONE)
				);

				if($collapse)
				{
					$data['collapse']='collapse';    
				}
				$journal_array = $GLOBALS['phpgw']->vfs->get_journal($data);
				$revision=count($journal_array);
				 // Calculate the number of pages
				$pages = floor($revision / $this->maxperpage);
				if($revision % $this->maxperpage) $pages++;
				if($page > $pages) 
				{
					$page= $pages;
				}
				else if($page<1)
				{
						$page=1;
				}
				$this->bofilemanager->save_page($page,$pages);
				if(is_array($journal_array))
				{
					@reset($journal_array);
					$startrevision=($page-1)*$this->maxperpage;
					$endrevision=$startrevision+$this->maxperpage;
					if($pages==0)
					{
						$startrevision=0;
						$endrevision=0;
					}
					for($i=$startrevision; $i<$endrevision;$i++)                       
					{
						if($i==$revision) break;
						$journal_entry=$journal_array[$i];
						$var = array();
						@reset($col_headers);
						foreach($col_headers as $label => $field)
						{
							switch($field)
							{
								case 'owner_id':
									$var[] = array('widget' => array('type' => 'label','caption' => $GLOBALS['phpgw']->common->grab_owner_name($journal_entry[$field])));
									break;
								case 'created':
									$var[] = array('widget' => array('type' => 'label','caption' => $this->bofilemanager->convert_date($journal_entry[$field])));
									break;
								case '':
									$var[] = array('widget' => array('type' => 'checkbox','name'=>'filehis[]','value'=>$journal_entry['version'],'onClick' => 'checkCB(this)'));
								    break;
								case 'version':
									if($mime_type=='Directory')
									{
										$href = '#';
										$onClick = "open_popup('" . $GLOBALS['phpgw']->link('/index.php',array(
																							'menuaction'	=> 'filemanager.ui'
																												.'filemanager.indexhis',
																							'path' => urlencode($this->bofilemanager->path),
																							'file' => urlencode($this->bofilemanager->file),
																							'history_path' => urlencode($this->bofilemanager->history_path),
																							'history_file' => urlencode($this->bofilemanager->history_file),
																							'vers' => urlencode($journal_entry[$field]))) . "','800','800');";
   									}
									else
									{
										$href = '#';
										$onClick = "open_popup('" . $GLOBALS['phpgw']->link('/index.php',array(
																							'menuaction'	=> 'filemanager.ui'
																												.'filemanager.viewhis',
																							'path' => urlencode($this->bofilemanager->path),
																							'history_path' => urlencode($this->bofilemanager->history_path),
																							'file' => urlencode($this->bofilemanager->file),
																							'history_file' => urlencode($this->bofilemanager->history_file),
																							'vers' => urlencode($journal_entry[$field]))) . "','800','800');";
									}														
									$var[] = array('widget' => array('type'	=> 'link','caption'	=> $journal_entry[$field],'href' => $href,'onClick'	=> $onClick));
									break;
								default:
									$var[] = array('widget' => array('type' => 'label','caption' => $journal_entry[$field]));
									break;
							}
						}
						$table_rows[] = array('table_col' => $var);
						$table_footer = array();					
					}
				}
				$data = array
				(
					'form'	=> array('action'	=> $GLOBALS['phpgw']->link('/index.php',array(
													'menuaction' => 'filemanager.uifilemanager.action',
														'path' => urlencode($this->bofilemanager->path))),
														'id'	=> 'form_history',
														'name'	=> 'history',
														'method'	=> 'POST',
														'enctype'	=> 'multipart/form-data'),
					'error'		=> (isset($this->bofilemanager->errors) && is_array(unserialize(base64_decode($this->bofilemanager->errors)))?$GLOBALS['phpgw']->common->error_list(unserialize(base64_decode($this->bofilemanager->errors)),'Results'):''),
					'error'			=> '',
					'action_url'	=> '#', 
					'title'			=> lang('history for %1',$file),
					'table'			=> array('width' => '100%','table_head' => $table_head ,'table_row' => $table_rows,'table_footer' => $table_footer),
					'lang_close'	=> lang('close window')
				);
				$data['lang_from_rev'] = lang('from rev'); 
				$data['from']	=  array('widget'	=> array('type' => 'text',
						 									'name' => 'from_rev',
											 				'maxlength' => '255',
											 				'size' => '15',
															'value' => $from_rev));
				$data['lang_to_rev']	= lang('to rev');
                    					
				$data['to']	= array('widget'	=> array('type' => 'text',
						 									'name' => 'to_rev',
											 				'maxlength' => '255',
															'size' => '15',
															'value' => $to_rev));
				$data['img_search'] =  array('widget' => array('type' => 'image',
																'src' => $GLOBALS['phpgw']->common->image('filemanager','reload'),
																'title' => lang('search'),
																'name'	=> 'params[research]',
																'value'	=> 'research'));
				$data['file']  = array('widget'	=> array('type' => 'hidden',
						'name'	=> 'file',
						'value' =>  $this->bofilemanager->file
						));
				$data['vers']  = array('widget'	=> array('type' => 'hidden',
						'name'	=> 'vers',
						'value' =>  $this->bofilemanager->vers
						));
				$data['mime_type']  = array('widget'	=> array('type' => 'hidden',
						'name'	=> 'mime_type',
						'value' =>  $this->bofilemanager->mime_type
						));		
				$data['collapse'] = array('widget' => array('type' => 'checkbox','name'=>'collapse','value'=>'collapse','caption'=> 'collapse','checked' => (isset($this->bofilemanager->collapse)?True:False))); 
				$data['img_compare'] = array('widget' => array('type' => 'image',
																	'src' => $GLOBALS['phpgw']->common->image('filemanager','button_ok'),
																	'title' => lang('Compare'),
																	'name'	=> 'params[compare]',
																	'value'	=> 'compare'));
				if($page>1)
				{
					$data['img_first'] = array('widget' => array('type' => 'image',
																'src' => $GLOBALS['phpgw']->common->image('filemanager','first-grey'),
																'title' => lang('first'),
																'name'	=> 'params[first]',
																'value'	=> 'first'));
					$data['img_prev'] = array('widget' => array('type' => 'image',
																'src' => $GLOBALS['phpgw']->common->image('filemanager','left-grey'),
																'title' => lang('previsous'),
																'name'	=> 'params[prev]',
																'value'	=> 'prev'));																		
				}												
				if($page<$pages)
				{
					$data['img_next'] = array('widget' => array('type' => 'image',
																'src' => $GLOBALS['phpgw']->common->image('filemanager','right-grey'),
																'title' => lang('next'),
																'name'	=> 'params[next]',
																'value'	=> 'next'));
					$data['img_last'] = array('widget' => array('type' => 'image',
																'src' => $GLOBALS['phpgw']->common->image('filemanager','last-grey'),
																'title' => lang('last'),
																'name'	=> 'params[last]',
																'value'	=> 'last'));																	
				}												
				if($pages>1)
					$data['page'] = array('widget' => array('type' => 'label',
														 'caption'	=> lang('Page').$page.'/'.$pages));
			}
			$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('history' => $data));
		}      
		
		function view_file($file_array='')
		{
			if(is_array($file_array))
			{
				$this->bofilemanager->path = $file_array['path'];
				$this->bofilemanager->file = $file_array['file'];
			}
			$file = $this->bofilemanager->path.SEP.$this->bofilemanager->file;
			if($GLOBALS['phpgw']->vfs->file_exists(array('string' => $file,'relatives' => Array(RELATIVE_NONE))))
			{
				$ls_array = $GLOBALS['phpgw']->vfs->ls(array('string' => $file,'relatives' => array (RELATIVE_ALL),'checksubdirs' => False,'nofiles' => True));
				$mime_type = $ls_array[0]['mime_type'];
				/*$mime_part = explode('/',$mime_type);
				$mime_type = ($mime_part=='text'?'application/octet-stream':$mime_type);
				echo $mime_type;
				exit;*/

				$browser = CreateObject('phpgwapi.browser');
				$browser->content_header($this->bofilemanager->file,$mime_type,$ls_array[0]['size']);

				echo $GLOBALS['phpgw']->vfs->read(array('string' => $file,'relatives' => Array(RELATIVE_NONE)));
				flush();
			}
			if(!is_array($file_array))
			{
				exit();
			}
		}