| Server IP : 162.214.74.102 / Your IP : 216.73.217.80 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/www/lrsys_apps/marisol/application/controllers/ |
Upload File : |
<?php
_auth();
$ui->assign('_application_menu', 'settings');
$ui->assign('_title', $_L['Category of Product'] . ' - ' . $config['CompanyName']);
$ui->assign('_st', $_L['Category of Product']);
$ui->assign('content_inner', inner_contents($config['c_cache']));
$action = $routes['1'];
$user = User::_info();
$ui->assign('user', $user);
switch ($action) {
case 'list':
$ui->assign('categoryes', ProductCategory::all());
//adiciona os js necessários
$css_arr = array('s2/css/select2.min');
$js_arr = array('s2/js/select2.min', 'jslib/product-category');
$ui->assign('xheader', Asset::css($css_arr));
$ui->assign('xfooter', Asset::js($js_arr));
//seta o idioma para o js
$ui->assign('jsvar', '
_L[\'are_you_sure\'] = \'' . $_L['are_you_sure'] . '\';
_L[\'Save\'] = \'' . $_L['Save'] . '\';
_L[\'Add New Category\'] = \'' . $_L['Add New Category'] . '\';
_L[\'Edit\'] = \'' . $_L['Edit'] . '\';
_L[\'Category\'] = \'' . $_L['Category'] . '\';
_L[\'OK\'] = \'' . $_L['OK'] . '\';
_L[\'Cancel\'] = \'' . $_L['Cancel'] . '\';
_L[\'Parent Category\'] = \'' . $_L['Parent Category'] . '\';
_L[\'Select Category\'] = \'' . $_L['Select Category'] . '\';
_L[\'This category having daughters\'] = \'' . $_L['This category having daughters'] . '\';
');
$ui->display('list-product-category.tpl');
break;
case 'add-post':
//recebe o nome da categoria e a categoria parent
$msg = "";
$name = _post('name');
$parent = _post('parent');
if (trim($name) == '') {
$msg = $_L['Category'] . $_L['is required'];
}
if ($msg == '') {
$d = ORM::for_table('sys_items_category')->create();
$d->name = $name;
if(!empty($parent)){
$d->parent = $parent;
}
$d->save();
_log( $_L['Category of Product'] ." ".$_L['Added'] . " - $d->id - " + $d->name, 'Admin', $user['id']);
//se informar que deve emitir msg de salvo
if ($routes['2'] == 'msg') {
_msglog("s", $_L['added_successful']);
}
echo $d->id();
} else {
echo $msg;
}
break;
case 'edit-post':
//padrão do dit
$id = _post('id');
$name = _post('name');
$parent = _post('parent');
$msg = "";
if ($name == '') {
$msg = $_L['Category'] . $_L['is required'];
}
if ($msg == '') {
$d = ORM::for_table('sys_items_category')->find_one($id);
if ($d) {
// update all gname in contacts
$d->name = $name;
$d->parent = empty($parent)?null:$parent;
$d->save();
_log( $_L['Category of Product'] ." ".$_L['Edited'] . " - $d->id - " + $d->name, 'Admin', $user['id']);
//se informar que deve emitir msg de salvo
if ($routes['2'] == 'msg') {
_msglog("s", $_L['edit_successful']);
}
echo $d->id;
}
} else {
echo $msg;
}
break;
///listagem ajax
case 'ajax-list':
//recebe o parametro do estado
$all = ProductCategory::all();
$data=array();
foreach ($all as $s) {
$data[] = array(
'id' => $s['id'],
'name' => $s['name'], //verifica se são os dados pre cadastrados que são traduzidos
'parent' => $s['parent'],
'name_parent'=>$s['name_parent']
);
}
echo json_encode($data);
break;
///listagem ajax
case 'ajax-list-parent':
//recebe o parametro do estado
$parent = ProductCategory::allParent();
$data = '';
foreach ($parent as $s) {
$data[] = array(
'id' => $s->id,
'name' => $s->name, //verifica se são os dados pre cadastrados que são traduzidos
'parent' => $s->parent
);
}
echo json_encode($data);
break;
case 'delete':
$id = intval(str_replace('c', '', $routes[2]));
$d = ORM::for_table('sys_items_category')->find_one($id);
if ($d) {
// find all items com a unidade
//se encontrar emite mensagem de impossibilidade de exclusão
$itens = ORM::for_table('sys_items')->raw_query(" select 1 from sys_items where category_id = $id")->find_many();
$categorias = ORM::for_table('sys_items_category')->raw_query(" select 1 from sys_items_category where parent = $id")->find_many();
if (count($itens) > 0) {
r2(U . 'product_category/list/', 'e', $_L['Not permited remove this category. Category having products']);
}
else if (count($categorias) > 0) {
r2(U . 'product_category/list/', 'e', $_L['Not permited remove this category. Category having categorys daughters']);
} else {
$d->delete();
_log($_L['Category Deleted'] . " - " + $d->name, 'Admin', $user['id']);
r2(U . 'product_category/list/', 's', $_L['Category Deleted Successfully']);
}
} else {
echo $_L['Not found'];
}
break;
default:
echo 'action not defined';
}