Example #1
0
 public function delete($id = 0)
 {
     //get data product.
     $dgClass = new dg();
     $products = $dgClass->getProducts();
     $categories = $dgClass->getProductCategories();
     //get id products
     if (isset($_POST['ids']) && $_POST['ids'] != '') {
         $ids = $_POST['ids'];
     } else {
         if ($id != '' && (int) $id > 0) {
             $ids = array($id);
         } else {
             $ids = array();
         }
     }
     if (count($ids) > 0) {
         //remove products.
         if (count($products) > 0) {
             $content['products'] = array();
             foreach ($products as $product) {
                 if (!in_array($product->id, $ids)) {
                     $content['products'][] = $product;
                 }
             }
         }
         $content = json_encode($content);
         $path = dirname(ROOT) . DS . 'data' . DS . 'products.json';
         $dgClass->WriteFile($path, $content);
         //remove categories.
         if (count($categories) > 0) {
             $category_data = array();
             foreach ($categories as $category) {
                 if (!in_array($category->product_id, $ids)) {
                     $category_data[] = $category;
                 }
             }
             $category_data = json_encode($category_data);
             $path = dirname(ROOT) . DS . 'data' . DS . 'product_categories.json';
             $dgClass->WriteFile($path, $category_data);
         }
     }
     $dgClass->redirect('index.php/product');
 }
Example #2
0
 public function delete($id = 0)
 {
     $dgClass = new dg();
     if ($id > 0) {
         $products = $dgClass->getProducts();
         if (count($products) > 0) {
             $content = array('products' => array());
             foreach ($products as $product) {
                 if ($product->id != $id) {
                     $content['products'][] = $product;
                 }
             }
         }
         $path = dirname(ROOT) . DS . 'data' . DS . 'products.json';
         $check = $dgClass->WriteFile($path, json_encode($content));
     }
     $dgClass->redirect('index.php/product');
 }
Example #3
0
 public function logout()
 {
     $dgClass = new dg();
     setcookie("temail", "", time() - 36000, '/');
     setcookie("tpassword", "", time() - 36000, '/');
     $this->unset_session('login');
     $dgClass->redirect('index.php');
 }
Example #4
0
 public function saveCategory()
 {
     $dgClass = new dg();
     if (!empty($_POST)) {
         $id = $_POST['id'];
         $title = $_POST['title'];
         $parent_id = $_POST['parent_id'];
         // get categories
         $file = dirname(ROOT) . DS . 'data' . DS . 'categories_art.json';
         $categories = array();
         $categories[0] = new stdClass();
         $categories[0]->id = 0;
         $categories[0]->title = 'All art';
         $categories[0]->parent_id = '0';
         if (file_exists($file)) {
             $str = file_get_contents($file);
             $categories = json_decode($str);
         }
         if ($parent_id == 0) {
             $level = 1;
         } else {
             $level = 2;
         }
         if ($id == 0) {
             // add new category
             $index = 0;
             foreach ($categories as $category) {
                 if ($category->id > $index) {
                     $index = $category->id;
                 }
             }
             $index = $index + 1;
             $category = array('id' => $index, 'title' => $title, 'parent_id' => $parent_id);
             $categories[] = $category;
         } else {
             // edit category
             $index = $id;
             $array = array();
             foreach ($categories as $category) {
                 if ($category->id == $index) {
                     $array[] = array('id' => $index, 'title' => $title, 'parent_id' => $parent_id);
                 } else {
                     $array[] = $category;
                 }
             }
             $categories = $array;
         }
         $check = $dgClass->WriteFile($file, json_encode($categories));
         echo 1;
         exit;
     } else {
         $dgClass->redirect('index.php/clipart');
     }
 }
Example #5
0
 public function update($product_id = '')
 {
     include_once ROOT . DS . 'includes' . DS . 'functions.php';
     $dg = new dg();
     $path_info = dirname(ROOT) . DS . 'addons' . DS . 'install' . DS . $product_id . '.json';
     if ($product_id != '' && file_exists($path_info)) {
         $content = file_get_contents($path_info);
         if ($content != false) {
             $addon = json_decode($content);
             $args = array('woo_sl_action' => 'plugin_update', 'licence_key' => $addon->key, 'product_unique_id' => $product_id, 'domain' => $_SERVER['HTTP_HOST']);
             $result = $dg->sendPostData($this->api_url, $args);
             if ($result != false && $result != '') {
                 $content = json_decode($result);
                 if (isset($content[0]) && isset($content[0]->status) && isset($content[0]->message) && $content[0]->status == 'success') {
                     if (isset($content[0]->message->package)) {
                         $addon->version = $content[0]->message->new_version;
                         $addon->date = $content[0]->message->date;
                         // download and upzip file
                         $file = $dg->openURL($content[0]->message->package);
                         $zip = new ZipArchive();
                         $path = dirname(dirname(ROOT));
                         $path_file = $path . DS . 'addon.zip';
                         if ($dg->WriteFile($path_file, $file) && $zip->open($path_file) == true) {
                             $zip->extractTo($path);
                             $zip->close();
                             unlink($path_file);
                             $dg->WriteFile($path_info, json_encode($addon));
                         }
                     }
                 }
             }
         }
     }
     $dg->redirect('index.php/addon/installed');
 }