Example #1
0
         echo "no data";
     }
 } else {
     if ($_GET['itemtype'] == "featureditem") {
         $items = FeaturedItem::get_all();
         if (count($items) > 0) {
             foreach ($items as $item) {
                 $theitem = new Product();
                 $thedesc = "";
                 $thepicture = "";
                 if ($item->itemtype == "store") {
                     $theitem = Store::get_by_id($item->itemid);
                     $thedesc = $theitem->branchname;
                 } else {
                     if ($item->itemtype == "product") {
                         $theitem = Product::get_by_id($item->itemid);
                         $thedesc = $theitem->description;
                     }
                 }
                 if ($item->override == 1) {
                     $thepicture = $item->picture;
                 } else {
                     $thepicture = $theitem->picture;
                 }
                 $filename++;
                 $random = rand(0, 1);
                 file_put_contents("images/" . $filename . "x" . $random . ".jpg", base64_decode($thepicture));
                 $thepicture = HOST . "images/" . $filename . "x" . $random . ".jpg";
                 $html .= "<tr>";
                 $html .= "  <td><img src='data:image/jpeg;base64, " . $thepicture . "' style='height:25px;' /></td>";
                 $html .= "  <td>type: " . $item->itemtype . "</td>";
Example #2
0
 function index_put()
 {
     $models = json_decode($this->put('models'));
     $data["results"] = array();
     $data["count"] = 0;
     foreach ($models as $value) {
         $obj = new Product(null, $this->entity);
         $obj->get_by_id($value->id);
         $obj->category_id = $value->category_id;
         $obj->unit_id = $value->unit_id;
         $obj->sku = $value->sku;
         $obj->name = $value->name;
         $obj->description = $value->description;
         $obj->on_hand = $value->on_hand;
         $obj->order_point = $value->order_point;
         $obj->favorite = $value->favorite;
         $obj->image_url = $value->image_url;
         $obj->status = $value->status;
         $obj->deleted = $value->deleted;
         if ($obj->save()) {
             //Results
             $data["results"][] = array("id" => $obj->id, "category_id" => $obj->category_id, "unit_id" => $obj->unit_id, "sku" => $obj->sku, "name" => $obj->name, "description" => $obj->description, "on_hand" => floatval($obj->on_hand), "order_point" => intval($obj->order_point), "favorite" => $obj->favorite, "image_url" => $obj->image_url, "status" => intval($obj->status), "deleted" => $obj->deleted, "unit" => $obj->unit->get()->name);
         }
     }
     $data["count"] = count($data["results"]);
     $this->response($data, 200);
 }
    $object->description = $_POST['description'];
    $object->price = $_POST['price'];
    $object->producttypeid = $_POST['producttypeid'];
    $object->pending = $_POST['pending'];
    $object->enabled = $_POST['enabled'];
    $object->create();
    $log = new Log($session->userid, $clientip, "WEB", "CREATED USER: "******"WEB", "UPDATED PRODUCT: " . $_POST['id']);
        $log->create();
    } else {
        if ($_POST['oper'] == 'del') {
            if ($_POST['id'] != $session->userid) {
                $log = new Log($session->userid, $clientip, "WEB", "DELETED PRODUCT: " . $_POST['id']);
                $log->create();
                Product::get_by_id($_POST['id'])->delete();
            }
        }
    }
}
Example #4
0
 public function create_operation()
 {
     $this->load->helper('operations');
     $operation_data_temp = $this->input->post('operation');
     $this->db->trans_begin();
     $form = $this->get_form(@$operation_data_temp['type'], @$operation_data_temp['subtraction_type']);
     build_validator_from_form($form);
     if ($this->form_validation->run()) {
         $operation_data = $this->input->post('operation');
         $operation_service_data = $this->input->post('operation_service');
         $operation_product_data = $this->input->post('operation_product');
         $operations_addition = new Operation();
         $operations_addition->where('type', Operation::TYPE_ADDITION);
         $operations_addition->select_sum('amount', 'amount_sum');
         $operations_addition->where_related_person('id', '${parent}.id');
         $operations_subtraction_direct = new Operation();
         $operations_subtraction_direct->where('type', Operation::TYPE_SUBTRACTION);
         $operations_subtraction_direct->where('subtraction_type', Operation::SUBTRACTION_TYPE_DIRECT);
         $operations_subtraction_direct->select_sum('amount', 'amount_sum');
         $operations_subtraction_direct->where_related_person('id', '${parent}.id');
         $operations_subtraction_products = new Operation();
         $operations_subtraction_products->where('type', Operation::TYPE_SUBTRACTION);
         $operations_subtraction_products->where('subtraction_type', Operation::SUBTRACTION_TYPE_PRODUCTS);
         $operations_subtraction_products->where_related('product_quantity', 'price >', 0);
         $operations_subtraction_products->group_start(' NOT', 'AND');
         $operations_subtraction_products->where_related('product_quantity', 'product_id', NULL);
         $operations_subtraction_products->group_end();
         unset($operations_subtraction_products->db->ar_select[0]);
         $operations_subtraction_products->select_func('SUM', array('@product_quantities.quantity', '*', '@product_quantities.price', '*', '@product_quantities.multiplier'), 'amount_sum');
         $operations_subtraction_products->where_related_person('id', '${parent}.id');
         $operations_subtraction_services = new Operation();
         $operations_subtraction_services->where('type', Operation::TYPE_SUBTRACTION);
         $operations_subtraction_services->where('subtraction_type', Operation::SUBTRACTION_TYPE_SERVICES);
         $operations_subtraction_services->where_related('service_usage', 'price >', 0);
         $operations_subtraction_services->group_start(' NOT', 'AND');
         $operations_subtraction_services->where_related('service_usage', 'service_id', NULL);
         $operations_subtraction_services->group_end();
         unset($operations_subtraction_services->db->ar_select[0]);
         $operations_subtraction_services->select_func('SUM', array('@service_usages.quantity', '*', '@service_usages.price', '*', '@service_usages.multiplier'), 'amount_sum');
         $operations_subtraction_services->where_related_person('id', '${parent}.id');
         $person = new Person();
         $person->where('admin', 0);
         $person->select('*');
         $person->select_subquery($operations_addition, 'plus_amount');
         $person->select_subquery($operations_subtraction_direct, 'minus_amount_direct');
         $person->select_subquery($operations_subtraction_products, 'minus_amount_products');
         $person->select_subquery($operations_subtraction_services, 'minus_amount_services');
         $person->get_by_id((int) $operation_data['person_id']);
         if (!$person->exists()) {
             $this->db->trans_rollback();
             add_error_flash_message('Účastník sa nenašiel.');
             redirect(site_url('operations/new_operation'));
         }
         $admin = new Person();
         $admin->where('admin', 1);
         $admin->get_by_id((int) auth_get_id());
         if (!$admin->exists()) {
             $this->db->trans_rollback();
             add_error_flash_message('Administrátor sa nenašiel.');
             redirect(site_url('operations/new_operation'));
         }
         $workplace = new Workplace();
         if ((int) $operation_data['workplace_id'] > 0) {
             $workplace->get_by_id((int) $operation_data['workplace_id']);
             if (!$workplace->exists()) {
                 $this->db->trans_rollback();
                 add_error_flash_message('Zamestnanie sa nenašlo.');
                 redirect(site_url('operations/new_operation'));
             }
         }
         if ($operation_data['type'] == Operation::TYPE_ADDITION) {
             $amount_to_add = (double) $operation_data['amount'];
             $remaining = 0;
             if ($operation_data['addition_type'] == Operation::ADDITION_TYPE_TRANSFER && !operations_ledcoin_addition_possible($amount_to_add, $remaining)) {
                 $this->db->trans_rollback();
                 add_error_flash_message('Nedá sa prideliť <strong>' . $amount_to_add . '</strong> ' . get_inflection_ledcoin($amount_to_add) . ', na účte vedúcich zostáva iba <strong>' . $remaining . '</strong> ' . get_inflection_ledcoin($remaining) . '.');
                 redirect('operations');
                 return;
             }
             if ($operation_data['addition_type'] == Operation::ADDITION_TYPE_TRANSFER && !operations_ledcoin_limit_check($amount_to_add)) {
                 add_common_flash_message('Pozor, pridanie ' . $amount_to_add . ' LEDCOIN-ov presahuje denný limit. Pred pridaním bolo už použitých ' . operations_ledcoin_added_in_day() . ' z ' . operations_ledcoin_daily_limit() . ' LEDCOIN-ov!');
             }
             $operation = new Operation();
             $operation->from_array($operation_data, array('comment', 'amount', 'type', 'addition_type'));
             $operation->subtraction_type = Operation::SUBTRACTION_TYPE_DIRECT;
             if ($operation->save(array('person' => $person, 'admin' => $admin, 'workplace' => $workplace)) && $this->db->trans_status()) {
                 $this->db->trans_commit();
                 add_success_flash_message('Účastník <strong>' . $person->name . ' ' . $person->surname . '</strong> dostal <strong>' . $operation->amount . '</strong> ' . get_inflection_ledcoin((double) $operation->amount) . ' úspešne.');
                 redirect(site_url('operations'));
             } else {
                 $this->db->trans_rollback();
                 add_error_flash_message('Účastníkovi <strong>' . $person->name . ' ' . $person->surname . '</strong> sa nepodarilo prideliť <strong>' . $operation->amount . '</strong> ' . get_inflection_ledcoin((double) $operation->amount) . '.');
                 redirect(site_url('operations/new_operation'));
             }
         } else {
             $amount_at_disposal = doubleval($person->plus_amount) - doubleval($person->minus_amount_direct) - doubleval($person->minus_amount_products) - doubleval($person->minus_amount_services);
             $total_amount = 0;
             if ($operation_data['subtraction_type'] == Operation::SUBTRACTION_TYPE_DIRECT) {
                 $total_amount += (double) $operation_data['amount'];
             }
             $service_data = array();
             if ($operation_data['subtraction_type'] == Operation::SUBTRACTION_TYPE_SERVICES) {
                 $services = new Service();
                 $services->order_by('title', 'asc');
                 $services->get_iterated();
                 foreach ($services as $service) {
                     if (isset($operation_service_data[$service->id])) {
                         if (isset($operation_service_data[$service->id]['quantity']) && (int) $operation_service_data[$service->id]['quantity'] > 0 && isset($operation_service_data[$service->id]['price']) && (double) $operation_service_data[$service->id]['price'] > 0) {
                             $service_data[$service->id] = $operation_service_data[$service->id];
                             $total_amount += (int) $operation_service_data[$service->id]['quantity'] * (double) $operation_service_data[$service->id]['price'] * (double) $operation_data['multiplier'];
                         }
                     }
                 }
             }
             $product_data = array();
             if ($operation_data['subtraction_type'] == Operation::SUBTRACTION_TYPE_PRODUCTS) {
                 $quantity_addition = new Product_quantity();
                 $quantity_addition->select_sum('quantity', 'quantity_sum');
                 $quantity_addition->where('type', Product_quantity::TYPE_ADDITION);
                 $quantity_addition->where_related('product', 'id', '${parent}.id');
                 $quantity_subtraction = new Product_quantity();
                 $quantity_subtraction->select_sum('quantity', 'quantity_sum');
                 $quantity_subtraction->where('type', Product_quantity::TYPE_SUBTRACTION);
                 $quantity_subtraction->where_related('product', 'id', '${parent}.id');
                 $products = new Product();
                 $products->order_by('title', 'asc');
                 $products->select('*');
                 $products->select_subquery($quantity_addition, 'plus_quantity');
                 $products->select_subquery($quantity_subtraction, 'minus_quantity');
                 $products->get_iterated();
                 foreach ($products as $product) {
                     if (isset($operation_product_data[$product->id])) {
                         if (isset($operation_product_data[$product->id]['quantity']) && (int) $operation_product_data[$product->id]['quantity'] > 0 && isset($operation_product_data[$product->id]['price']) && (double) $operation_product_data[$product->id]['price'] > 0) {
                             $product_data[$product->id] = $operation_product_data[$product->id];
                             $total_amount += (int) $operation_product_data[$product->id]['quantity'] * (double) $operation_product_data[$product->id]['price'] * (double) $operation_data['multiplier'];
                         }
                     }
                 }
             }
             if ($total_amount > $amount_at_disposal) {
                 $this->db->trans_rollback();
                 add_error_flash_message('Účastník <strong>' . $person->name . ' ' . $person->surname . '</strong> nemá dostatok LEDCOIN-u. Potrebuje <strong>' . $total_amount . '</strong> ' . get_inflection_ledcoin((double) $total_amount) . ' ale má iba <strong>' . $amount_at_disposal . '</strong> ' . get_inflection_ledcoin((double) $amount_at_disposal) . '.');
                 redirect(site_url('operations/new_operation'));
             }
             if ($total_amount == 0) {
                 $this->db->trans_rollback();
                 add_error_flash_message('Celková suma LEDCOIN-u na odobratie je nulová, preto nie je možné pokračovať.');
                 redirect(site_url('operations/new_operation'));
             }
             $operation = new Operation();
             $operation->from_array($operation_data, array('comment', 'type', 'subtraction_type'));
             if ($operation_data['subtraction_type'] == Operation::SUBTRACTION_TYPE_DIRECT) {
                 $operation->amount = (double) $operation_data['amount'];
             } else {
                 $operation->amount = 0.0;
             }
             if ($operation->save(array('person' => $person, 'admin' => $admin, 'workplace' => $workplace)) && $this->db->trans_status()) {
                 if (count($service_data) > 0) {
                     foreach ($service_data as $service_id => $service_post) {
                         $service_usage = new Service_usage();
                         $service_usage->from_array($service_post, array('quantity', 'price'));
                         $service_usage->multiplier = (double) $operation_data['multiplier'];
                         $service_usage->service_id = (int) $service_id;
                         if (!$service_usage->save(array('operation' => $operation))) {
                             $service = new Service();
                             $service->get_by_id((int) $service_id);
                             $this->db->trans_rollback();
                             add_error_flash_message('Nepodarilo sa uložiť záznam o odobratí LEDCOIN-u za službu <strong>' . $service->title . '</strong>.');
                             redirect(site_url('operations/new_operation'));
                             die;
                         }
                     }
                 }
                 if (count($product_data) > 0) {
                     foreach ($product_data as $product_id => $product_post) {
                         $product_quantity = new Product_quantity();
                         $product_quantity->type = Product_quantity::TYPE_SUBTRACTION;
                         $product_quantity->from_array($product_post, array('quantity', 'price'));
                         $product_quantity->multiplier = (double) $operation_data['multiplier'];
                         $product_quantity->product_id = (int) $product_id;
                         if (!$product_quantity->save(array('operation' => $operation))) {
                             $product = new Product();
                             $product->get_by_id((int) $product_id);
                             $this->db->trans_rollback();
                             add_error_flash_message('Nepodarilo sa uložiť záznam o odobratí LEDCOIN-u za produkt <strong>' . $product->title . '</strong>.');
                             redirect(site_url('operations/new_operation'));
                             die;
                         }
                     }
                 }
                 $this->db->trans_commit();
                 add_success_flash_message('Účastníkovi <strong>' . $person->name . ' ' . $person->surname . '</strong> sa úspešne podarilo odobrať <strong>' . $total_amount . '</strong> ' . get_inflection_ledcoin((double) $total_amount) . '.');
                 redirect(site_url('operations'));
             } else {
                 $this->db->trans_rollback();
                 add_error_flash_message('Účastníkovi <strong>' . $person->name . ' ' . $person->surname . '</strong> sa nepodarilo odobrať <strong>' . $total_amount . '</strong> ' . get_inflection_ledcoin((double) $total_amount) . '.');
                 redirect(site_url('operations/new_operation'));
             }
         }
     } else {
         $this->db->trans_rollback();
         $this->new_operation();
     }
 }
Example #5
0
<?php

require_once "../initialize.php";
$message = "";
if (isset($_POST['productid']) && $_POST['productid'] != "" && isset($_POST['name']) && $_POST['name'] != "" && isset($_POST['price']) && $_POST['price'] != "" && isset($_POST['producttypeid']) && $_POST['producttypeid'] != "") {
    $object = Product::get_by_id($_POST['productid']);
    $object->storeid = $_POST['storeid'];
    $object->name = $_POST['name'];
    $object->description = $_POST['description'];
    $object->price = $_POST['price'];
    $object->producttypeid = $_POST['producttypeid'];
    $object->pending = $_POST['pending'];
    $object->enabled = $_POST['enabled'];
    $file = new File($_FILES['picture']);
    if ($file->valid) {
        $object->picture = $file->data;
    } else {
        $object->picture = base64_decode($object->picture);
    }
    $object->update();
    $log = new Log($session->userid, $clientip, "WEB", "UPDATED PRODUCT: " . $object->id);
    $log->create();
    $message .= "success";
} else {
    $message = "You have missed a required field.";
}
echo $message;
Example #6
0
if (isset($_GET['itemid']) && isset($_GET['itemtype'])) {
    $message = "success";
    if ($_GET['itemtype'] == "user") {
        User::get_by_id($_GET['itemid'])->delete();
    } else {
        if ($_GET['itemtype'] == "store") {
            Store::get_by_id($_GET['itemid'])->delete();
        } else {
            if ($_GET['itemtype'] == "storetype") {
                StoreType::get_by_id($_GET['itemid'])->delete();
            } else {
                if ($_GET['itemtype'] == "storepic") {
                    StorePic::get_by_id($_GET['itemid'])->delete();
                } else {
                    if ($_GET['itemtype'] == "product") {
                        Product::get_by_id($_GET['itemid'])->delete();
                    } else {
                        if ($_GET['itemtype'] == "producttype") {
                            ProductType::get_by_id($_GET['itemid'])->delete();
                        } else {
                            if ($_GET['itemtype'] == "productpic") {
                                ProductPic::get_by_id($_GET['itemid'])->delete();
                            } else {
                                if ($_GET['itemtype'] == "traffic") {
                                    Traffic::get_by_id($_GET['itemid'])->delete();
                                } else {
                                    if ($_GET['itemtype'] == "review") {
                                        Review::get_by_id($_GET['itemid'])->delete();
                                    } else {
                                        if ($_GET['itemtype'] == "featureditem") {
                                            FeaturedItem::get_by_id($_GET['itemid'])->delete();
<?php

require_once "../../includes/initialize.php";
global $session;
if (!$session->is_logged_in()) {
    redirect_to("../../index.php");
}
$page = $_GET['page'];
$limit = $_GET['rows'];
$sidx = $_GET['sidx'];
$sord = $_GET['sord'];
$object = Product::get_by_id($session->userid);
$objects_count = Product::get_by_sql("SELECT * FROM " . T_PRODUCTS);
$count = count($objects_count);
if ($count > 0 && $limit > 0) {
    $total_pages = ceil($count / $limit);
} else {
    $total_pages = 0;
}
if ($page > $total_pages) {
    $page = $total_pages;
}
$start = $limit * $page - $limit;
if ($start < 0) {
    $start = 0;
}
if (!$sidx) {
    $sidx = 1;
}
$ops = array('eq' => '=', 'ne' => '<>', 'lt' => '<', 'le' => '<=', 'gt' => '>', 'ge' => '>=', 'bw' => 'LIKE', 'bn' => 'NOT LIKE', 'in' => 'LIKE', 'ni' => 'NOT LIKE', 'ew' => 'LIKE', 'en' => 'NOT LIKE', 'cn' => 'LIKE', 'nc' => 'NOT LIKE');
if (isset($_GET['searchString']) && isset($_GET['searchField']) && isset($_GET['searchOper'])) {
Example #8
0
 public function upload_photo($product_id = NULL)
 {
     if (is_null($product_id)) {
         add_error_flash_message('Produkt sa nenašiel.');
         redirect(site_url('products'));
     }
     $product = new Product();
     $product->get_by_id((int) $product_id);
     if (!$product->exists()) {
         add_error_flash_message('Produkt sa nenašiel.');
         redirect(site_url('products'));
     }
     $upload_config = array('upload_path' => 'user/products/data/' . (int) $product->id . '/', 'allowed_types' => 'jpg|png', 'max_size' => '1024', 'max_width' => '1024', 'max_height' => '1024', 'file_name' => 'temp_product.png', 'overwrite' => TRUE);
     $this->load->library('upload', $upload_config);
     @mkdir($upload_config['upload_path'], DIR_WRITE_MODE, TRUE);
     if ($this->upload->do_upload('photo')) {
         $resize_config = array('image_library' => 'gd2', 'source_image' => $upload_config['upload_path'] . $upload_config['file_name'], 'create_thumb' => FALSE, 'maintain_ratio' => TRUE, 'width' => 256, 'height' => 256, 'quality' => '90%', 'new_image' => $upload_config['upload_path'] . 'product.png');
         $this->load->library('image_lib', $resize_config);
         if ($this->image_lib->resize()) {
             $resize_config['width'] = 64;
             $resize_config['height'] = 64;
             $resize_config['new_image'] = $upload_config['upload_path'] . 'product_min.png';
             @unlink($upload_config['new_image']);
             $this->image_lib->initialize($resize_config);
             $this->image_lib->resize();
             @unlink($resize_config['source_image']);
             add_success_flash_message('Súbor úspešne nahraný.');
             redirect(site_url('products/edit_photo/' . (int) $product->id));
         } else {
             @unlink($resize_config['source_image']);
             add_error_flash_message('Súbor sa nepodarilo preškálovať:' . $this->image_lib->display_errors('<br /><br />', ''));
             redirect(site_url('products/edit_photo/' . (int) $product->id));
         }
     } else {
         add_error_flash_message('Súbor sa nepodarilo nahrať, vznikla nasledujúca chyba:' . $this->upload->display_errors('<br /><br />', ''));
         redirect(site_url('products/edit_photo/' . (int) $product->id));
     }
 }
Example #9
0
<?php

require_once "header.php";
if (isset($_GET['id'])) {
    $object = Product::get_by_id($_GET['id']);
} else {
    header("location: index.php?negative");
}
if (!$session->is_logged_in()) {
    header("location: index.php?negative");
} else {
    $loggeduser = User::get_by_id($session->userid);
    if ($loggeduser->enabled == DISABLED) {
        header("location: index.php?disabled");
    }
}
$pathinfo = pathinfo($_SERVER["PHP_SELF"]);
$basename = $pathinfo["basename"];
$currentFile = str_replace(".php", "", $basename);
?>

<div class="container-fluid">
<div class="row-fluid">
  <div class="span1"></div>
  <div class="span9">
    <form id="theform" class="form-horizontal" action="#" method="post" enctype="multipart/form-data">
      <fieldset>
      <legend>
        Update
      </legend>