function loadApi($action)
{
    switch ($action) {
        case 'insert':
            if (!isset($_COOKIE['groupid'])) {
                throw new Exception("You must be login.");
            }
            try {
                if (!($id = Categories::insert(Request::make('send')))) {
                    throw new Exception("Error. " . Database::$error);
                }
                return json_encode(array('error' => 'no'));
            } catch (Exception $e) {
                throw new Exception($e->getMessage());
            }
            break;
        case 'get':
            try {
                $data = Categories::get();
                return json_encode($data);
            } catch (Exception $e) {
                throw new Exception($e->getMessage());
            }
            break;
    }
}
Example #2
0
 private function insertRel($value)
 {
     try {
         $this->log->addInfo("Inicia funcion MainProject::insertRel() ");
         $categories = new Categories();
         $rel = array(0, "lkp_projects", $value->id);
         $categories->insert($rel);
     } catch (\Excetion $e) {
         $this->log->addError($e->getMessage(), array(basename(__FILE__) . "::" . __LINE__));
     }
 }
function insertProcess()
{
    $send = Request::get('send');
    $valid = Validator::make(array('send.title' => 'required|min:1|slashes', 'send.parentid' => 'slashes'));
    if (!$valid) {
        throw new Exception("Error Processing Request: " . Validator::getMessage());
    }
    if (Request::hasFile('image')) {
        if (Request::isImage('image')) {
            $send['image'] = File::upload('image');
        }
    }
    if (!($id = Categories::insert($send))) {
        throw new Exception("Error. " . Database::$error);
    }
}
Example #4
0
 public function store()
 {
     //
     $rules = array('title' => 'sometimes|required|min:2|max:30');
     $messages = array('title.required' => 'Title is required.');
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return $this->response(array('statusCode' => 400, 'statusDescription' => 'Bad Request', 'errors' => $validator->messages()->toJson()));
     } else {
         $title = Input::get('title');
         $parent_id = Input::get('parent_id');
         $status = Input::get('status');
         $is_featured = Input::get('is_featured');
         Categories::insert(array('title' => $title, 'parent_id' => $parent_id, 'status' => $status, 'is_featured' => $is_featured, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")));
         return $this->response(array('statusCode' => 100, 'statusDescription' => 'Success', 'message' => "Category Added Successfully"));
     }
 }
Example #5
0
function loadApi($action)
{
    $groupid = Users::getCookieGroupId();
    $userid = Users::getCookieUserId();
    if ((int) $groupid <= 0 || (int) $userid <= 0) {
        throw new Exception('You must login');
    }
    if ((int) $groupid != 1) {
        throw new Exception('You can not do this action');
    }
    switch ($action) {
        case 'changeHomePage':
            $send_url = trim(Request::get('send_url'));
            $send_url = str_replace(System::getUrl(), '', $send_url);
            $inputData = array('default_page_method' => 'url', 'default_page_url' => $send_url);
            System::saveSetting($inputData);
            break;
        case 'getSetting':
            if (!isset($_COOKIE['groupid'])) {
                throw new Exception("You must be login.");
            }
            try {
                if (!($id = Categories::insert(Request::make('send')))) {
                    throw new Exception("Error. " . Database::$error);
                }
                return json_encode(array('error' => 'no'));
            } catch (Exception $e) {
                throw new Exception($e->getMessage());
            }
            break;
        case 'addSetting':
            try {
                $data = Categories::get();
                return json_encode($data);
            } catch (Exception $e) {
                throw new Exception($e->getMessage());
            }
            break;
    }
}
Example #6
0
                // $response['data'] = 'Deleted';
                // $response['status'] = 'Bad Request';
                // $json_response = json_encode($response);
                // echo $json_response;
            }
        }
    } else {
        //insert action
        var_dump($_POST);
        $cat = new Categories();
        $cat->number = $_POST['number'];
        // echo $cat->number;
        $cat->name = $_POST['name'];
        $cat->des = $_POST['des'];
        $cat->parent = $_POST['parent'];
        $cat->id = $cat->insert();
        if ($cat->id > 0) {
            // $status=200;
            $response['data'] = array('cat_id' => $cat->id);
            $rest = new categories_server();
            $rest->handle_response($response['data'], 200);
            // $response['status'] = 'OK';
            // $json_response = json_encode($response);
            // echo $json_response;
        }
    }
    //get user either with id or all
} else {
    if ($_method == 'GET') {
        // get user with a specific id
        if (isset($_GET['id'])) {
<?php

require_once "inc/models/categories.php";
$action = 'category-create-prepare';
$again = true;
$path = '';
if (isset($_POST['abort'])) {
    $action = 'categories-show-prepare';
} else {
    if (isset($_POST['name']) && $_POST['name'] != '') {
        $target_path = realpath(__FILE__) . '/../../../../uploads/' . basename($_FILES['path']['name']);
        if (move_uploaded_file($_FILES['path']['tmp_name'], $target_path)) {
            $path = '/uploads/' . basename($_FILES['path']['name']);
        } else {
            $path = 'Fehler aufgetreten';
        }
        $name = $_POST['name'];
        $categoryObject = new Categories($name);
        $categoryObject->insert();
        $action = 'categories-show-prepare';
    } else {
        $action = 'categories-create-prepare';
        $msgObject = array("type" => "danger", "msg" => "Kategorie konnte nicht angelegt werden.");
    }
}