admin_table (1-103) vs table_builer (103-...)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
$at=new admin_table('width=100% align="center" cellspacing="0" cellpadding="3"');
$at->set_link('adminko.php?module=board&action=view_adverts');
$at->set_table_name('adverts');
$at->set_key_col('id');
$at->set_items_per_page(10);
$at->set_order_default('id');
$at->add_col('title',array(
'name' => 'title',
'is_ordered'=> true,
'title' => 'Заголовок',
'in_table' => '1',
'handler' => create_function('$id,$value,$data','return "<a href=\'?module=board&action=edit_advert&id=$id\' title=\'".strip_tags($data[\'text\'])."\'>$value</a>";'),
'width' => '25%',
));
$at->add_col('cat_id',array(
'name' => 'cat_id',
'is_ordered'=> true,
'title' => 'Категория',
'in_table' => '1',
'handler' => create_function('$id,$value','return get_cats_path($value,1);'),
'width' => '20%',
));
$at->add_col('add_date',array(
'name' => 'add_date',
'is_ordered'=> true,
'title' => 'Дата добавления',
'in_table' => '1',
'handler' => '',
'width' => '20%',
));
$at->add_col('user_id',array(
'name' => 'user_id',
'is_ordered'=> true,
'title' => 'Разместил',
'in_table' => '1',
'handler' => create_function('$id,$value','$tmp=board::get_user($value,0,\'id\'); return "<a href=\'?module=board&action=edit_user&id=$value\'>".$tmp[\'name\']."</a>";'),
'width' => '15%',
));
$at->add_col('edit',array(
'name' => 'edit',
'is_ordered'=> false,
'title' => '',
'in_table' => false,
'handler' => create_function('$id,$value','return "<a href=\'?module=board&action=edit_advert&id=$id\'><img src=\'./images/admin/ico_edit.gif\' alt=\'Редактировать\'></a>";'),
'width' => '5%',
'addition' => 'align="center"'
));
$at->add_col('enabled',array(
'name' => 'enabled',
'is_ordered'=> true,
'title' => 'enabled',
'in_table' => '1',
'handler' => create_function('$id,$value','return make_checkbox("enabled[".$id."]","",$value);'),
'width' => '10%',
'addition' => 'align="center"',
'footer' => make_submit('Обновить','update_adverts')
));
$at->add_col('deleted',array(
'name' => 'deleted',
'is_ordered'=> true,
'title' => 'deleted',
'in_table' => '1',
'handler' => create_function('$id,$value','return make_checkbox("enabled[".$id."]","",$value);'),
'width' => '5%',
'addition' => 'align="center"',
'footer' => make_submit('Обновить','update_adverts')
));
$at->add_col('del',array(
'name' => 'del',
'is_ordered'=> false,
'title' => 'del',
'in_table' => false,
'handler' => create_function('$id,$value','return make_checkbox("enabled[".$id."]","",$value);'),
'width' => '10%',
'addition' => 'align="center"',
'footer' => make_submit('Удалить','delete_adverts','class="delete"')
));
$at->process();
print "<form action='?module=board&action=update_adv' method='post'>";
$at->print_table();
print "<input name='ids' type='hidden' value='".implode(',',array_keys($at->items))."'>";
print "</form>";
$page=get_var('page',$_GET,'i');
$max_page=ceil($this->get_num_all_adverts()/ITEMS_PER_PAGE);
if(!$page) $page=1;
if($page>$max_page) $page=$max_page;
if($max_page>1){
$page_line='<div class=pages>'.make_pages($page,$max_page,"&nbsp;[%s]&nbsp;","&nbsp;<a href='?module=board&action=view_adverts&page=%1\$s'>%1\$s</a>&nbsp;",2).'</div>';
}
$adverts=$this->get_all_adverts(ITEMS_PER_PAGE,$page-1,0);
//print "<a href='?module=board&action=new'><img src='./images/admin/ico_add.gif' alt='+'>Создать новое объявление</a><br /><br />";
$adverts=array_id_keys($adverts,'id',0);
($max_page>1) && print $page_line;
$table_builder=new table_builder('width="100%" align="center" cellspacing="0" cellpadding="3"');
if(!(is_array($adverts) && count($adverts))){print 'Объявления не найдены';}
else{
$table_builder->set_widths('30%','20%','20%','15%','5%','10%','10%');
$table_builder->set_addition('','','','','class="center"','class="center"','class="center"');
foreach($adverts as $id=>$entry){
$url=get_cats_path($entry['cat_id'],1);
$table_builder->add_row(
"<a href='?module=board&action=edit_advert&id=$id'>{$entry['title']}</a>",
"<a href='?module=board&action=edit_category&id={$entry['cat_id']}'>$url</a>",
$entry['add_date'],
"<a href='?module=board&action=edit_user&id={$entry['user_id']}'>{$entry['username']}</a>",
"<a href='?module=board&action=edit_advert&id=$id'><img src='./images/admin/ico_edit.gif' alt='Редактировать'></a>",
make_checkbox('enabled['.$id.']','',$entry['enabled']),
make_checkbox('deleted['.$id.']','',0));
}
$table_builder->add_head_row('Заголовок','Категория','Дата добавления','Разместил','','<img src="./images/admin/ico_light.gif" alt="Включено">','<img src="./images/admin/ico_del.gif" alt="Удалить">');
$table_builder->add_foot_row('','','','','',make_submit('Обновить','update_adverts'),make_submit('Удалить','delete_adverts','class="delete"'));
print "<form action='?module=board&action=update_adv' method='post'>";
print $table_builder->Generate();
print "<input name='ids' type='hidden' value='".implode(',',array_keys($adverts))."'>";
print "</form>";
}
($max_page>1) && print $page_line;