Exemplo n.º 1
0
 public function update()
 {
     global $database;
     if (!empty($_POST['id']) && ctype_digit($_POST['id'])) {
         $id = $_POST["id"];
         $article = RJ_News::find_by_id($id);
         $val = new Val();
         $error = "";
         if ($val->maxlength($_POST['topic'], 500)) {
             $article->news_topic = htmlspecialchars($_POST['topic']);
         } else {
             $error .= "Topic Incorrect, ";
         }
         $article->news_content = htmlspecialchars($_POST['content']);
         $article->news_visible = $_POST['visible'];
         if (!empty($_FILES['image']['name'])) {
             $result = $this->upload;
             if ($result) {
                 $article->news_image = $result;
             } else {
                 $error .= "Image Incorrect";
             }
         }
         if ($error == "") {
             if ($article->update()) {
                 $_SESSION['adminmessage'] = "News successfully updated";
                 return true;
             } else {
                 $_SESSION['adminmessage'] = "An error occured while connecting with database, please try again";
                 return false;
             }
         } else {
             $_SESSION['adminmessage'] = $error;
             return false;
         }
     } else {
         return false;
     }
 }
Exemplo n.º 2
0
 public function updateProduct()
 {
     if (isset($_POST['name']) && !empty($_POST['name']) && isset($_POST['editor2']) && !empty($_POST['editor2']) && isset($_POST['prod_id'])) {
         $error = "";
         $product = Product::find_by_id($_POST['prod_id']);
         $val = new Val();
         if ($val->minlength($_POST['name'], 3) && $val->maxlength($_POST['name'], 255)) {
             $product->prod_name = strip_tags($_POST['name']);
         } else {
             $error .= "Name, ";
         }
         $product->prod_web_content = htmlspecialchars($_POST['editor2']);
         $product->prod_visible = $_POST['display'];
         if (isset($_POST['desc']) && !empty($_POST['desc'])) {
             $product->prod_desc = $_POST['desc'];
         }
         if (isset($_POST['series']) && !empty($_POST['series'])) {
             $product->prod_series = $_POST['series'];
         }
         if (isset($_POST['company']) && !empty($_POST['company'])) {
             $product->prod_company = $_POST['company'];
         }
         if (!empty($_FILES['image']['name'])) {
             $filepath = $this->upload_pix();
             if ($filepath) {
                 $product->prod_image = $filepath;
             } else {
                 $error .= "Image, ";
             }
         }
         if (!empty($_FILES['pdf']['name'])) {
             $filepath = $this->upload_document();
             if ($filepath) {
                 $product->prod_pdf = $filepath;
             } else {
                 $error .= "File, ";
             }
         }
         $product->prod_cat_id = $this->getCatID();
         if ($error == "") {
             if ($product->update()) {
                 $_SESSION['adminmessage'] = "Product updated successfully";
             } else {
                 $error = "An error occured please try again";
             }
         }
     } else {
         $error = "Please fill all the required spaces";
     }
     if ($error == "") {
         return true;
     } else {
         $_SESSION['adminmessage'] = $error;
         return false;
     }
 }