update() public method

public update ( $id, $postdata )
<?php

include_once $CFG->dirroot . "/lib/classes/" . "application/Faq.Class.php5";
$faqObj = new Faq();
$vFromIP = $_SERVER['REMOTE_ADDR'];
$GeneralObj->getRequestVars();
$faqObj->setAllVar();
if ($mode == "Add") {
    $faqObj->insert();
    $msg = MSG_ADD;
    $url = 'index.php?file=Faq&AX=Yes&var_msg=' . $msg;
    header("Location:" . $url);
    exit;
} else {
    if ($mode == "Update") {
        $faqObj->update($iFaqId);
        $msg = MSG_UPDATE;
        $url = 'index.php?file=Faq&AX=Yes&var_msg=' . $msg;
        header("Location:" . $url);
        exit;
    }
}
Example #2
0
     break;
 case validateRoute('DELETE', 'rules/\\d+'):
     $rules = new Rules($db, $user);
     httpResponse($rules->delete($params[1]));
     break;
 case validateRoute('GET', 'faq'):
     $faq = new Faq($db, $user);
     httpResponse($faq->query());
     break;
 case validateRoute('POST', 'faq'):
     $faq = new Faq($db, $user);
     httpResponse($faq->create($postdata));
     break;
 case validateRoute('PATCH', 'faq/\\d+'):
     $faq = new Faq($db, $user);
     httpResponse($faq->update($params[1], $postdata));
     break;
 case validateRoute('DELETE', 'faq/\\d+'):
     $faq = new Faq($db, $user);
     httpResponse($faq->delete($params[1]));
     break;
 case validateRoute('GET', 'polls'):
     $polls = new Polls($db, $user);
     httpResponse($polls->query());
     break;
 case validateRoute('GET', 'polls/latest'):
     $polls = new Polls($db, $user);
     httpResponse($polls->getLatest());
     break;
 case validateRoute('POST', 'polls/votes/\\d+'):
     $polls = new Polls($db, $user);
            //Close Database Connection
            header('Content-type: application/json');
            echo json_encode($json);
        }
    }
    if (filter_input(INPUT_POST, "addNewFaq") != NULL && filter_input(INPUT_POST, "addNewFaq") == "editFaq") {
        $postVars = array('id', 'question', 'answer');
        // Form fields names
        //Validate the POST variables and add up to error message if empty
        foreach ($postVars as $postVar) {
            switch ($postVar) {
                default:
                    $faqObj->{$postVar} = filter_input(INPUT_POST, $postVar) ? mysqli_real_escape_string($dbObj->connection, filter_input(INPUT_POST, $postVar)) : '';
                    if ($faqObj->{$postVar} === "") {
                        array_push($errorArr, "Please enter {$postVar} ");
                    }
                    break;
            }
        }
        //If validated and not empty submit it to database
        if (count($errorArr) < 1) {
            echo $faqObj->update();
        } else {
            $json = array("status" => 0, "msg" => $errorArr);
            $dbObj->close();
            //Close Database Connection
            header('Content-type: application/json');
            echo json_encode($json);
        }
    }
}