public function authenticate() { $this->errorCode = self::ERROR_NONE; $authenticated = false; $username = $this->username; $password = $this->password; $adauth = new ADAuth("adcontroller"); $user = new UserObj($username); if (!$adauth->authenticate($username, $password)) { $this->errorCode = 3; } $info = $adauth->lookup_user(); if ($info["count"] == 1) { $user->fullname = $info[0]["displayname"][0]; } /*if(!$user->save()) { StdLib::vdump($user->get_error()); }*/ if ($this->errorCode != 0) { if ($this->errorCode != 4) { $user->iterate_attempts(); } } return !$this->errorCode; }
public function actionDeleteCourseSyllabus() { $rest = new RestServer(); $request = RestUtils::processRequest(); $required = array("id"); $keys = array_keys($request); $user = new UserObj(Yii::app()->user->name); # Must be logged in and at least be a manager to delete syllabi if (Yii::app()->user->isGuest and $user->loaded and $user->atleast_permission("manager")) { return RestUtils::sendResponse(310); } # Not all parameters sent if (count(array_intersect($required, $keys)) != count($required)) { return RestUtils::sendResponse(308); } $CS = new CourseSyllabusObj($request["id"]); $CS->delete(); Yii::app()->user->setFlash("success", "Successfully deleted course syllabus."); return true; }
public function getUserById($user_id) { $sql = "SELECT * FROM user WHERE user_id = '{$user_id}'"; //Query $this->db->query($sql); //Fetch $row = $this->db->fetch(); //Khởi tạo đối tượng UserObj $userObj = new UserObj(); //Gán thông tin $userObj->setUserId($row['user_id']); $userObj->setUsername($row['username']); $userObj->setPassword($row['password']); $userObj->setFullname($row['fullname']); $userObj->setEmail($row['email']); $userObj->setStatus($row['status']); $userObj->setCreated($row['created']); $userObj->setModified($row['modified']); //Return return $userObj; }
<?php // Theme name from Jquery UI themes $theme = "bluebird"; if (!Yii::app()->user->isGuest) { $COREUSER = new UserObj(Yii::app()->user->name); $COREUSER->get_contact(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="language" content="en" /> <link rel="icon" type="image/png" href="<?php echo Yii::app()->request->baseUrl; ?> /images/person.png" /> <!-- blueprint CSS framework --> <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?> /css/screen.css" media="screen, projection" /> <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?> /css/print.css" media="print" /> <!--[if lt IE 8]> <link rel="stylesheet" type="text/css" href="<?php
public function action_save_contact() { // Must be an administrator or the actual user saving their information if (!$this->is_level(3) and Yii::app()->user->cid != $_REQUEST["cid"]) { return print "You do not have permission to edit this contact."; } $contact = new ContactObj($_REQUEST["cid"]); if (!$contact->loaded) { return print "Contact could not be found."; } $name = $contact->firstname . " " . $contact->lastname; foreach ($_REQUEST as $item => $value) { $contact->{$item} = $value; } $log = new LogObj(); if (!$contact->save()) { $log->type = "error"; $log->log_message = "Attempting to update information of contact (" . $contact->cid . ") \"{$name}\" bio.\n"; $log->log_message .= $contact->get_error(); if (!$log->save()) { die($log->get_error()); } return print $log->log_message; } $name = $contact->firstname . " " . $contact->lastname; $log->type = "update"; $log->log_message = "Successfully updated information of contact (" . $contact->cid . ") \"{$name}\"."; $log->save(); if (isset($contact->username) and $contact->username != "") { $user = new UserObj($contact->username); if (isset($_REQUEST["permission"])) { $permission = $_REQUEST["permission"]; if ($permission > @Yii::app()->user->userobj->permission) { $permission = @Yii::app()->user->userobj->permission; } $user->permission = $permission; $user->email = $user->username . "@colorado.edu"; $user->active = @$_REQUEST["makeuser"]; if (!$user->save()) { return print $user->get_error(); } } } return print 1; }
public function actionEdit() { $this->noGuest(); if (!isset($_REQUEST["id"])) { Yii::app()->user->setFlash('warning', 'Cannot edit: Invalid course syllabus ID.'); $this->redirect('index'); exit; } $CS = new CourseSyllabusObj($_REQUEST["id"]); if (!$CS->loaded) { Yii::app()->user->setFlash('warning', 'Could not load Course Syllabus. Something went really wrong.'); $this->redirect('index'); exit; } $syllabus = LOCAL_ARCHIVE . $CS->id; $CS->find_syllabus_links(); $syllabus_links = $CS->syllabus_links; # See if a topic/link was submitted if (isset($_POST["uniqueformid"], $_POST["datetime"])) { StdLib::Functions(); try { if (is_valid_form_id($_POST["uniqueformid"], $_POST["datetime"])) { unset($CS->id); # Grab the syllabus file and start up the File System $file = $_FILES["syllabus"]; # If the user added a file, let's continue with upload if ($file["size"] != 0) { $fileparts = pathinfo($file["name"]); $fs = new FileSystem(); if (!$fs->check_valid_extension($fileparts["extension"])) { throw new Exception("Extension was invalid: " . $fileparts["extension"]); } $fs->process_file_upload($file); $fs->upload_to(LOCAL_ARCHIVE . "temp/"); if (!$fs->is_uploaded()) { throw new Exception("Could not upload file. " . $fs->get_error()); } $file_locations = $fs->get_files_uploaded_location(); $file_location = @$file_locations[0]; } $sections = explode(",", $_POST["section"]); # Check the User permissions. # For now we are allowing any managers to have access to upload syllabi to the Archive $user = new UserObj(Yii::app()->user->name); if (!$user->atleast_permission("manager")) { throw new Exception("You cannot add syllabi at this time. Your permissions restrict your access."); } # See if we saved a syllabus (maybe multiple sections and one section already exists) $saved_at_least_one = FALSE; # Loop through each section and save each as a separate class foreach ($sections as $section) { $section = trim($section); if (!preg_match("/[0-9]{3}/", $section)) { continue; } $CS = new CourseSyllabusObj($_REQUEST["id"]); $CS->section = $section; $CS->id = $CS->generate_id(); $CS->load(); $CS->title = $_POST["title"]; $CS->special_topics_title = $_POST["special_topics_title"]; $CS->recitation = $_POST["recitation"]; $CS->restricted = $_POST["restricted"]; $CS->section = $section; # Add Instructors to Course Syllabus $instructors = explode("\n", $_POST["instructors"]); foreach ($instructors as $fullname) { $instructor = new InstructorObj(); $instructor->name = $fullname; $instructor->load(); if (!$instructor->loaded) { if (!$instructor->save()) { Yii::app()->user->setFlash("warning", "Could not save instructor <i>" . $instructor->name . "</i> for some reason. " . $instructor->get_error()); continue; } } $CS->instructors[] = $instructor->instrid; } $CS->id = $CS->generate_id(); $CS->find_syllabus_links(); if (!$CS->has_syllabus_file()) { foreach ($syllabus_links as $ext => $link) { if (!is_null($link)) { copy($syllabus . "." . $ext, LOCAL_ARCHIVE . $CS->id . "." . $ext); } } } # Save! if (!$CS->save()) { throw new Exception("Could not save Course Syllabus: " . $CS->get_error()); } # If the user added a file, let's continue with upload if ($file["size"] != 0) { # Move file to permanent home in the archive $fileName = $CS->id . "." . $fileparts["extension"]; copy($file_location, ROOT . "/archive/" . $fileName); # If the user selected OCR, then copy the file to the OCR directory if ($_POST["ocr"] == "yes" && $fileparts["extension"] == "pdf") { // Define OCR api location based on whether we're on the production or the development server $ocr_api = ($_SERVER["SERVER_NAME"] == "assettdev.colorado.edu" or $_SERVER["SERVER_NAME"] == "assetttest.colorado.edu") ? "http://assettdev.colorado.edu" : "http://compass.colorado.edu"; $url = $ocr_api . OCR_API . 'uploadfile'; $data = array('file_dir' => ROOT . "/archive/", 'file_name' => $fileName); $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data))); $context = stream_context_create($options); $result = json_decode(file_get_contents($url, false, $context)); if (isset($result->id)) { pclose(popen("start php " . ROOT . "/protected/models/system/OCRCheck.php " . ROOT . "/archive/ " . $result->id . " " . $_SERVER["SERVER_NAME"], 'w')); } } else { if ($fileparts["extension"] == "docx") { $content = read_zipped_xml(ROOT . "/archive/" . $fileName, "word/document.xml"); Yii::app()->db->createCommand()->update("course_syllabi", array("content" => $content), "id=:id", array(":id" => $CS->id)); } } } # Made it to here? We must have saved at least one course syllabus! $saved_at_least_one = TRUE; } } else { throw new Exception("Malformed form ID."); } # Let's set a message that we saved at least one file if ($saved_at_least_one) { Yii::app()->user->setFlash("success", "Successfully saved course syllabus to the archive!"); if ($_POST["savetype"] == "exit") { $this->redirect("index"); exit; } else { $this->redirect(Yii::app()->createUrl('course') . "?prefix=" . $CS->prefix . "&num=" . $CS->num); exit; } } else { Yii::app()->user->setFlash("info", "Did not save any course syllabi."); } # Remove the temporary file if (isset($file_location) and is_file($file_location)) { unlink($file_location); } } catch (Exception $e) { Yii::app()->user->setFlash("warning", $e->getMessage()); } } $this->render('editsyllabus', array("CS" => $CS)); }