header('Content-Type: text/html; charset=utf-8');
require_once('config.php');
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка верхней одежды')");
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка дубленок')");
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка курток')");
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка пуховиков')");
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка пальто')");
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка шуб')");
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка обуви')");
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка кроссовок')");
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка сапог')");
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка угги')");
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка сумок и чемоданов')");
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка одеял и подушек')");
// mysqli_query($link, "insert into items_categories (title) values ('Химчистка штор')");
require_once($root_dir.'/functions/functions.php');
foreach (glob($root_dir.'/classes/*.php') as $filename) require_once $filename;
require_once($root_dir.'/auth.php');
$action=htmlspecialchars($_GET['action']);
$tpl = new tpl;
$item = new items;
$order = new orders;
$client = new clients;
$paneluser = new panelusers;
$cur_filial=$paneluser->get_filial();
switch ($action) {
case 'additem':
$id=intval($_GET['id']);
$was=array("{item_price}","{item_title}","{edit}","{category_options}");
if ($id>0) {
$item->item_id=$id;
$item->get();
$sql="select id,title from items_categories order by id desc";
$result=mysqli_query($link,$sql);
while ($row=mysqli_fetch_array($result)) {
if (substr_count($item->item_category,$row['id'])>0) {$sel="selected";} else {$sel="";}
$cat_options .='';
}
$is=array($item->item_price,$item->item_title,$item->item_id,$cat_options);
} else {
$sql="select id,title from items_categories order by id desc";
$result=mysqli_query($link,$sql);
while ($row=mysqli_fetch_array($result)) {
if ($row['id']==$item->item_category) {$sel="selected";} else {$sel="";}
$cat_options .='';
}
$is=array("","","0",$cat_options);
}
$tpl->name="additem.tpl";
$all_out .=$tpl->show($was,$is);
break;
case 'addorder':
$id=intval($_GET['id']);
$was=array("{options}","{fil_options}");
$options=$item->do_list();
$filial_list=$order->get_filials();
foreach ($options as $value) {
$opts .="";
}
foreach ($filial_list as $value) {
$fil_opts .="";
}
if ($cur_filial) {$fil_opts="";}
$is=array($opts,$fil_opts);
$tpl->name="addorder.tpl";
$all_out .=$tpl->show($was,$is);
break;
case 'site_orders':
$ajax=intval($_GET['ajax']);
if ($ajax>0) {
$descr=htmlspecialchars($_REQUEST['descr']);
$sql="update mad_orders set descr = '$descr' where ord_id = '$ajax'";
mysqli_query($link,"SET NAMES utf8");
mysqli_query($link,$sql);
} else {
$ipp=50;
$page=intval($_GET['page']);
$first=$page*$ipp;
mysqli_query($link,"SET NAMES utf8");
$sql="select count(ord_id) from mad_orders limit 0,1";
$result=mysqli_query($link,$sql);
$row=mysqli_fetch_array($result);
$counter=$row[0];
$sql="select * from mad_orders order by ord_date desc limit $first,$ipp";
$result=mysqli_query($link,$sql);
mysqli_query($link,"SET NAMES latin1");
while ($row=mysqli_fetch_array($result)) {
$tpl->name="mad_orders.tpl";
if ($row['ord_item']==1) {
$ord_item="Не определена";
}
elseif ($row['ord_item']==7777) {
$ord_item="Запрос на доставку";
}
else {
$item->item_id=$row['ord_item'];
$item->get();
$ord_item=$item->item_title;
}
$was=array("{order_id}","{date}","{name}","{phone}","{order_item}","{descr}");
$is=array($row['ord_id'],$row['ord_date'],$row['ord_name'],$row['ord_phone'],$ord_item,$row['descr']);
$mad_orders .=$tpl->show($was,$is);
}
$tpl->name='mad_orders_full.tpl';
$url="/?action=site_orders";
$pages=simple_pagination ($counter,$url,$ipp);
$was=array("{mad_orders}","{pages}");
$is=array($mad_orders,$pages);
$all_out .=$tpl->show($was,$is);
}
break;
case 'addclient':
$id=intval($_GET['id']);
$was=array("{addclient_name}","{addclient_email}","{addclient_address}","{addclient_phone}","{addclient_discount}","{addclient_edit}","{addclient_source}","{addclient_filial}","{fil_options}");
$filial_list=$client->get_filials();
$fil_opts='';
foreach ($filial_list as $value) {
$fil_opts .="";
}
if ($cur_filial) {$fil_opts="";}
if ($id>0) {
$client->clients_id=$id;
$client->get_one();
$is=array($client->clients_name,$client->clients_email,$client->clients_address,$client->clients_phone,$client->clients_discount,$client->clients_id,$client->clients_source,$client->clients_filial,$fil_opts);
}
$is=array($client->clients_name,$client->clients_email,$client->clients_address,$client->clients_phone,$client->clients_discount,$client->clients_id,$client->clients_source,$client->clients_filial,$fil_opts);
$tpl->name="addclient.tpl";
$all_out .=$tpl->show($was,$is);
break;
case 'list_clients':
$ipp=50;
$page=intval($_GET['page']);
$mass=$client->do_list($page,$ipp,$cur_filial);
$counter=$client->count($cur_filial);
$url="/?action=list_clients";
foreach ($mass as $value) {
$tpl->name="clients_list.tpl";
$tpl->objecttotpl($value);
$clients_list .=$tpl->show($tpl->was,$tpl->is);
}
$pages=simple_pagination ($counter,$url,$ipp);
$tpl->name='full_clients_list.tpl';
$was=array("{clients_list}","{pages}");
$is=array($clients_list,$pages);
$all_out .=$tpl->show($was,$is);
break;
case 'list_orders':
$ipp=20;
$page=intval($_GET['page']);
$mass=$order->do_list($page,$ipp,$cur_filial);
$counter=$order->count($cur_filial);
$url="/?action=list_orders";
foreach ($mass as $value) {
if ($value['client']>0) {
$client->clients_id=$value['client'];
$client->get_one();
$value['client_name']=$client->clients_name;
if ($client->clients_source) {
$value['client_source']="(".$client->clients_source.")"; } else {$value['client_source']="(не указан)";}
} else {
$value['client_name']="Не указан";
}
$tpl->name="orders_list.tpl";
$tpl->objecttotpl($value);
$orders_list .=$tpl->show($tpl->was,$tpl->is);
}
$pages=simple_pagination ($counter,$url,$ipp);
$tpl->name='full_orders_list.tpl';
$was=array("{orders_list}","{pages}");
$is=array($orders_list,$pages);
$all_out .=$tpl->show($was,$is);
break;
case 'list':
$mass=$item->do_list();
foreach ($mass as $value) {
$tpl->name="items_list.tpl";
$tpl->objecttotpl($value);
$tpl->was[]="{category_name}";
$cats=explode(",",$value['category']);
unset($cats_names);
foreach($cats as $vvalue) {
$cats_names[]=get_category_name($vvalue);
}
$cats_names1=implode(",",$cats_names);
$tpl->is[]= $cats_names1;
$items_list .=$tpl->show($tpl->was,$tpl->is);
}
$tpl->name='full_items_list.tpl';
$was=array("{items_list}");
$is=array($items_list);
$all_out .=$tpl->show($was,$is);
break;
}
$left_side =new tpl;
$left_side->name="left_side.tpl";
$leftside=$left_side->show(array("{left_widget}"),array($left_widget));
$maintpl = new tpl;
$maintpl->name='main.tpl';
$ord_id='';
$sql="select ord_id from mad_orders where descr = '' order by ord_id limit 0,1";
$result=mysqli_query($link,$sql);
$row=mysqli_fetch_array($result);
$ord_id=intval($row['ord_id']);
if ($ord_id>0) {$ord_id=1;}
$was=array("{leftside}","{left_servers_options}","{content}","{server_id}","{ord_id}");
$is=array($leftside,$left_servers_options,$all_out,$server_id,$ord_id);
echo $maintpl->show($was,$is);
?>