<? 
$CLS='ops_history';
class ops_history
{
	function init() {
		global $X;

		$X->NAVI[] 				= $X->ADMIN->module_name();
		$this->TABLE 			= '_admin_ops';
		$this->SKIP_OPS		= true;

		switch($_GET['action']) {
			default:	 							return $this->_list(); 						break;
			case 'delete':						return $this->_delete();					break;
			case 'delete_all':				return $this->_delete_all();				break;
			case 'batch':						return $this->_batch();						break;
		}
	}


	function _list() {
		global $X;

		$table['order_by']	= 'id';
		$table['order_dir']	= 'desc';

		$X->ADMIN->text_filter($this, 'this.id', 'ID', '=');
		$X->ADMIN->text_filter($this, 'login_id', 'Login_ID', '=');
		$X->ADMIN->text_filter($this, 'parent_row_id', 'Parent_ID', '=');
		$X->ADMIN->text_filter($this, 'row_id', 'Obj_ID', '=');
		$X->ADMIN->select_filter($this, 'module_id', 'Moduł', $X->UTIL->array_extend(array(''=>'-- Wszystkie --'), $X->FORM->get_array_tree('SELECT id,title FROM _modules WHERE parent_id="$" ORDER BY pozycja, id ', '$', 0, 0)));
		$X->ADMIN->select_filter($this, 'action', 'Akcja', array(''=>'-- Wszystkie --', 1=>'INSERT', 2=>'UPDATE', 3=>'DELETE', 5=>'SAVE', 0=>'OTHER', 11=>'AJAX_CHECKBOX', 12=>'AJAX_RADIO', 13=>'AJAX_SORT'));
		$X->ADMIN->select_filter($this, 'user_id', 'Użytkownik', $X->UTIL->array_extend(array(''=>'-- Wszyscy --'), $X->DB->get_array(' SELECT id,login FROM _admin_users ORDER BY id ',true)));

		$X->ADMIN->filter_form($this, $table, 160);


		$split=$X->DB->split('
			SELECT
				this.*,
				u.login,
				m.title AS module,
				m2.title AS module_parent
			FROM '.$this->TABLE.' this
			LEFT JOIN _admin_users AS u ON u.id=this.user_id
			LEFT JOIN _modules AS m ON m.id=this.module_id
			LEFT JOIN _modules AS m2 ON m2.id=m.parent_id
			WHERE 1
				'.$this->FILTER_SQL.'
			'.$X->DB->set_order($table).'
		', 20);


		$table['top_left']=$this->FILTER;
		$table['top_right']=$X->FORM->button_potwierdzenie('<span class="ico w_no"></span><span>All</span>',$X->URL->get('action=delete_all'),false,false,'button button_gfx');
		$table['bottom_left']=$X->ADMIN->batch_actions($split);
		$table['head']='
			'.$X->ADMIN->sortable_col($table,$split,'th').'
			'.$X->ADMIN->batch_col('th').'
			'.$X->ADMIN->head_col('ID','id',30,'center').'
			'.$X->ADMIN->head_col('Login_ID','login_id',66,'center').'
			'.$X->ADMIN->head_col('Data','date',120,'center').'
			'.$X->ADMIN->head_col('Użytkownik','login',130,'left').'
			'.$X->ADMIN->head_col('Moduł','module',190,'left').'
			'.$X->ADMIN->head_col('Par_ID','parent_row_id',60,'center').'
			'.$X->ADMIN->head_col('Obj ID','row_id',60,'center').'
			'.$X->ADMIN->head_col('Action','action',100,'left').'
			'.$X->ADMIN->head_col('Description','description',false,'left').'
			'.$X->ADMIN->head_col(false,false,30,'center').'
		';
		while($dane=$X->DB->fa($split['sql'])) {
			$dane['action']=$X->ADMIN->log_op_action($dane['action']);

			$rows.='
				<tr id="R:'.$dane['id'].'">
					'.$X->ADMIN->sortable_col($table,$split,'td').'
					'.$X->ADMIN->batch_col('td',$dane['id']).'
					<td class="center">'.$dane['id'].'</td>
					<td class="center"><a class="button button_small" href="index.php?module=5&filter='.$dane['login_id'].'">'.$X->STR->outt($dane['login_id']).'</a></td>
					<td class="center">'.$X->STR->outt($dane['date']).'</td>
					<td><b>'.$X->STR->outt($dane['login']).'</b></td>
					<td>'.(!empty($dane['module_parent']) ? $X->STR->outt($dane['module_parent']).' &raquo; ' : '').$X->STR->outt($dane['module']).'</td>
					<td class="center">'.($dane['parent_row_id']<=0 ? $dane['parent_row_id'] : '<a class="button button_small" target="_blank" href="index.php?module='.$dane['module_id'].'&parent_id='.$dane['parent_row_id'].'">'.$X->STR->outt($dane['parent_row_id']).'</a>').'</td>
					<td class="center">'.($dane['row_id']<=0 ? $dane['row_id'] : '<a class="button button_small" target="_blank" href="index.php?module='.$dane['module_id'].'&action=form&id='.$dane['row_id'].'">'.$X->STR->outt($dane['row_id']).'</a>').'</td>
					<td><b>'.$X->STR->outt($dane['action']).'</b></td>
					<td>'.$X->STR->outt($dane['description']).'</td>
					<td class="center">'.$X->FORM->button_potwierdzenie('<span class="ico w_no"></span>', $X->URL->get('action=delete&id='.$dane['id']), false, false, 'button button_gfx_small2').'</td>
				</tr>
			';
		}
		return $X->ADMIN->listbox($this, $table, $rows, $split).$html;
	}


	function _delete($id=false) {
		require(START_DELETE);

		$X->DB->q(' DELETE FROM '.$this->TABLE.' WHERE id="'.$_GET['id'].'" ');

		if(!is_numeric($id)) $X->URL->go2('action&id');
	}


	function _delete_all() {
		require(START_DELETE);

		$X->DB->q(' TRUNCATE TABLE '.$this->TABLE.' ');
		$X->URL->go2('action&id');
	}


	function _batch() {
		global $X;

		if(count($_POST['batch'])>0) foreach($_POST['batch'] as $b_id) {
			if($_POST['batch_action']=='delete') $this->_delete($b_id);
		}
		$X->URL->go2('action&id');
	}

}
?>