public function deletestudentAction()
 {
     $studentID = $this->_request->getParam('s');
     $groupID = $this->_request->getParam('g');
     $students_DB = new Application_Model_DbTable_Student();
     $id = $students_DB->getID($studentID, $_SESSION['Default']['field']);
     $student_DB = new Application_Model_DbTable_StudentsInField();
     $data = array('groupID' => NULL);
     $student_DB->update($data, "id = {$id}");
     $this->_redirect("/managegroups");
 }
 public function savegradeAction()
 {
     if ($this->getRequest()->isPost()) {
         $_params = $this->_request->getParams();
         if ($_params['studentID'] && $_params['gradeID'] && $_params['gameID'] && $_params['groupID']) {
             $student_DB = new Application_Model_DbTable_Student();
             $studentinfieldID = $student_DB->getID($_params['studentID'], $_SESSION['Default']['field']);
             $records_DB = new Application_Model_DbTable_Records();
             //if record in this game already exists, delete and insert again
             $prev_record = $records_DB->isExists($studentinfieldID, $_params['gameID']);
             $isUpdate = false;
             if ($prev_record && isset($_SESSION['Default']['updateGrade'])) {
                 $where['studentinfieldID = ?'] = $studentinfieldID;
                 $where['gameID = ?'] = $_params['gameID'];
                 $where['gradeID = ?'] = $prev_record['gradeID'];
                 $where['date = ?'] = $prev_record['date'];
                 try {
                     $records_DB->delete($where);
                 } catch (Exception $ex) {
                     die(json_encode(array('status' => 'danger', 'msg' => $this->lang->_('FAILED_DOC'))));
                 }
                 $isUpdate = true;
             }
             $new_record = array('studentinfieldID' => $studentinfieldID, 'gameID' => $_params['gameID'], 'gradeID' => $_params['gradeID'], 'date' => date('Y-m-d H:i:s'), 'groupID' => $_params['groupID'], 'fieldID' => $_SESSION['Default']['field']);
             try {
                 $doc_id = $records_DB->insert($new_record);
                 $_SESSION['Default']['updateGrade'] = true;
             } catch (Exception $ex) {
                 die(json_encode(array('status' => 'danger', 'msg' => $this->lang->_('FAILED_DOC'))));
             }
             if ($isUpdate) {
                 die(json_encode(array('status' => 'success', 'msg' => $this->lang->_('SUCCESS_UPDATE'))));
             } else {
                 die(json_encode(array('status' => 'success', 'msg' => $this->lang->_('SUCCESS_DOC'))));
             }
         }
         die(json_encode(array('status' => 'danger', 'msg' => $this->lang->_('FAILED_DOC'))));
     }
 }