public function index($advisorUserID = "all", $studentUserID = "all", $advisingLogEntryType = "all") { $user = new User_model(); if (!$user->loadPropertiesFromPrimaryKey($_SESSION['UserID'])) { redirect('Login/logout'); } if (!$user->isProgramChair() && !$user->isAdvisor()) { redirect('Login/logout'); } if ($advisingLogEntryType === "all") { $advisingLogEntryType = null; } if ($advisorUserID === "all") { $advisorUserID = null; } if ($user->isAdvisor() && !$user->isProgramChair() && ($advisorUserID == null || $advisorUserID != $user->getUserID())) { $advisorUserID = $user->getUserID(); } if ($studentUserID === "all") { $studentUserID = null; } $advisors = $user->isProgramChair() ? User_model::getAllAdvisors() : array($user); $students = $user->isProgramChair() ? array() : $user->getAdvisees(); $types = Advising_log_entry_model::getAllAdvisingLogEntryTypes(); $data = array('user' => $user, 'logEntries' => Advising_log_entry_model::getAllAdvisingLogEntries($advisorUserID, $studentUserID, $advisingLogEntryType), 'advisors' => $advisors, 'students' => $students, 'types' => $types, 'advisorUserID' => $advisorUserID == null ? "all" : $advisorUserID, 'studentUserID' => $studentUserID == null ? "all" : $studentUserID, 'advisingLogEntryType' => $advisingLogEntryType == null ? "all" : $advisingLogEntryType); $this->load->view('advisinglog_index_view', $data); }
public static function getAllAdvisingLogEntries($advisorUserID = null, $studentUserID = null, $advisingLogEntryTypeID = null) { $db = get_instance()->db; $db->select('AdvisingLogEntryID'); $db->from('AdvisingLogEntries'); if ($advisorUserID != null) { $db->where('AdvisorUserID', $advisorUserID); } if ($studentUserID != null) { $db->where('StudentUserID', $studentUserID); } if ($advisingLogEntryTypeID != null) { $db->where('AdvisingLogEntryTypeID', $advisingLogEntryTypeID); } $db->order_by('Timestamp', 'desc'); $models = array(); $results = $db->get(); if ($results->num_rows() > 0) { foreach ($results->result_array() as $row) { $model = new Advising_log_entry_model(); if ($model->loadPropertiesFromPrimaryKey($row['AdvisingLogEntryID'])) { array_push($models, $model); } } } return $models; }
public function save() { //*troubleshooting tip* //keep in mind when you press "save" this function will run //and what ever you print_r will show in the success window popup //print_r($_POST); //this should first remove all data that is currently saved //next this will gather the data from javascript //if(isset($_POST['name'])){ // print_r($_POST['name']); //$jsonReceiveData = json_encode($_POST['{"Info":'], JSON_PRETTY_PRINT); //$uid = $_SESSION['UserID']; if (isset($_SESSION['StudCWID'])) { $this->uid = $_SESSION['StudCWID']; } else { if (!isset($_SESSION['UserID'])) { redirect('login'); } $this->uid = $_SESSION['UserID']; } $currentquarter = academic_quarter_model::getLatestAcademicQuarter(); $previous_form = $this->loadAdvisingForm($this->uid); if ($previous_form !== false) { $previous_form->delete(); } if (!isset($_POST['data'])) { header("Content-type: text/plain", true, 400); echo "Missing data"; return; } //$data = $_POST['Info']; $data = json_decode($_POST['data']); //['data']); $mod = new advising_form_model(); $mod->setStudentUserID(intval($this->uid)); $mod->setAcademicQuarterID($currentquarter->getAcademicQuarterID()); $mod->create(); $entry = new Advising_log_entry_model(); $student = new User_model(); if ($student->loadPropertiesFromPrimaryKey($this->uid)) { $createdByAdvisor = $this->uid != $_SESSION['UserID']; $entry->setStudentUser($student); $entry->setAdvisorUser($student->getAdvisor()); $entry->setAdvisingLogEntryType($createdByAdvisor ? Advising_log_entry_model::ENTRY_TYPE_ADVISING_FORM_SAVED_BY_ADVISOR : Advising_log_entry_model::ENTRY_TYPE_ADVISING_FORM_SAVED_BY_STUDENT); $entry->create(); } foreach ($data->Info as $section) { //print_r($course->Type); $callNum = $section->CallNumber; $sections = $currentquarter->getAllCourseSections(); $target = new course_section_model(); /*foreach($sections as $sec) { if ($sec->getCallNumber() === $callNum) { $target->loadPropertiesFromPrimaryKey($sec->getCourseSectionID()); break; } }*/ $target->loadPropertiesFromPrimaryKey($callNum); $state = $section->Type == "norm" ? advising_form_model::COURSE_SECTION_STATE_PREFERRED : advising_form_model::COURSE_SECTION_STATE_ALTERNATE; $mod->addCourseSection($target, $state); } //$previous_form->delete(); //print_r($_POST['{"Info":']); /*$blarg = json_decode($jsonReceiveData, true); foreach($blarg as $item) { foreach($item as $key => $value) { $info = $json_decode($key, true); foreach($info as $inf) { echo "\n\n" . $inf; } } }*/ /*$blarg = json_decode($jsonReceiveData); var_dump($blarg);*/ //} //then it will store the new information in the database }
public function create() { if ($this->startTime != null && filter_var($this->startTime, FILTER_VALIDATE_INT) && $this->endTime != null && filter_var($this->endTime, FILTER_VALIDATE_INT)) { $data = array('AdvisingScheduleID' => $this->advisingScheduleID, 'StartTime' => $this->startTime, 'EndTime' => $this->endTime); $this->db->insert('AdvisingAppointments', $data); if ($this->db->affected_rows() > 0) { $this->advisingAppointmentID = $this->db->insert_id(); if (!$this->isOpen()) { $data = array('AdvisingAppointmentID' => $this->advisingAppointmentID, 'StudentUserID' => $this->studentUserID, 'AppointmentStateID' => $this->advisingAppointmentStateID); $this->db->where('AdvisingAppointmentID', $this->advisingAppointmentID); $this->db->update('ScheduledAdvisingAppointments', $data); if ($this->db->affected_rows() > 0) { return true; } else { $this->db->insert('ScheduledAdvisingAppointments', $data); if ($this->db->affected_rows() > 0) { $entry = new Advising_log_entry_model(); $student = new User_model(); $student->loadPropertiesFromPrimaryKey($this->studentUserID); $entry->setStudentUser($student); $entry->setAdvisorUser($student->getAdvisor()); if ($this->isCanceledByAdvisor()) { $entry->setAdvisingLogEntryType(Advising_log_entry_model::ENTRY_TYPE_ADVISING_APPOINTMENT_CANCELED_BY_ADVISOR); } else { if ($this->isCanceledByStudent()) { $entry->setAdvisingLogEntryType(Advising_log_entry_model::ENTRY_TYPE_ADVISING_APPOINTMENT_CANCELED_BY_STUDENT); } else { if ($this->isScheduled()) { $entry->setAdvisingLogEntryType(Advising_log_entry_model::ENTRY_TYPE_ADVISING_APPOINTMENT_SIGNED_UP_BY_STUDENT); } else { if ($this->isCompleted()) { $entry->setAdvisingLogEntryType(Advising_log_entry_model::ENTRY_TYPE_ADVISING_APPOINTMENT_COMPLETE); } } } } $entry->create(); return true; } } } return true; } } return false; }