コード例 #1
0
 public static function update($id, $data)
 {
     session_start();
     $headers = apache_request_headers();
     $token = $headers['X-Auth-Token'];
     if (!$headers['X-Auth-Token']) {
         header('Invalid CSRF Token', true, 401);
         return print json_encode(array('success' => false, 'status' => 400, 'msg' => 'Invalid CSRF Token / Bad Request / Unauthorized ... Please Login again'), JSON_PRETTY_PRINT);
     } else {
         if ($token != $_SESSION['form_token']) {
             header('Invalid CSRF Token', true, 401);
             return print json_encode(array('success' => false, 'status' => 400, 'msg' => 'Invalid CSRF Token / Bad Request / Unauthorized ... Please Login again'), JSON_PRETTY_PRINT);
         } else {
             if (!isset($data['coursecode']) && empty($data['coursecode'])) {
                 return print json_encode(array('success' => false, 'status' => 200, 'msg' => 'Course Code is required'), JSON_PRETTY_PRINT);
                 die;
             } else {
                 if (!isset($data['coursename']) && empty($data['coursename'])) {
                     return print json_encode(array('success' => false, 'status' => 200, 'msg' => 'Course Description is required'), JSON_PRETTY_PRINT);
                     die;
                 } else {
                     if (!isset($data['passing_score']) && empty($data['passing_score'])) {
                         return print json_encode(array('success' => false, 'status' => 200, 'msg' => 'Passing Score Limit is required'), JSON_PRETTY_PRINT);
                         die;
                     } else {
                         $var = ["coursecode" => $data['coursecode'], "coursename" => $data['coursename'], "passing_score" => $data['passing_score']];
                         Courses::update($id, $var);
                     }
                 }
             }
         }
     }
 }