Exemple #1
0
function showFP()
{
    $db = new PHPWS_DB('ps_page');
    $db->addWhere('front_page', 1);
    if ($db->isTableColumn('deleted')) {
        $db->addWhere('deleted', 0);
    }
    Key::restrictView($db, 'pagesmith');
    $db->loadClass('pagesmith', 'PS_Page.php');
    $result = $db->getObjects('PS_Page');
    if (!PHPWS_Error::logIfError($result) && !empty($result)) {
        PHPWS_Core::initModClass('pagesmith', 'PageSmith.php');
        foreach ($result as $page) {
            $content = $page->view();
            if ($content && !PHPWS_Error::logIfError($content)) {
                if (Current_User::allow('pagesmith', 'edit_page', $page->id)) {
                    $content .= sprintf('<p class="pagesmith-edit">%s</p>', $page->editLink());
                }
                Layout::add($content, 'pagesmith', 'view_' . $page->id, TRUE);
            }
        }
    } else {
        return null;
    }
}
 /**
  * Main searching function. Does the database lookup and then checks each student though the various functions.
  */
 public function doSearch()
 {
     // Clear all the caches
     StudentDataProvider::clearAllCache();
     $term = $this->term;
     $query = "select DISTINCT * FROM (select hms_new_application.username from hms_new_application WHERE term={$term} AND cancelled != 1 UNION select hms_assignment.asu_username from hms_assignment WHERE term={$term}) as foo";
     $result = PHPWS_DB::getCol($query);
     if (PHPWS_Error::logIfError($result)) {
         throw new Exception($result->toString());
     }
     foreach ($result as $username) {
         $student = null;
         try {
             $student = StudentFactory::getStudentByUsername($username, $term);
         } catch (Exception $e) {
             $this->actions[$username][] = 'WARNING!! Unknown student!';
             // Commenting out the NQ line, since this doesn't work when the search is run from cron/Pulse
             //NQ::simple('hms', hms\NotificationView::WARNING, 'Unknown student: ' . $username);
             continue;
         }
         if ($student->getType() != TYPE_WITHDRAWN && $student->getAdmissionDecisionCode() != ADMISSION_WITHDRAWN_PAID && $student->getAdmissionDecisionCode() != ADMISSION_RESCIND) {
             continue;
         }
         $this->actions[$username][] = $student->getBannerId() . ' (' . $student->getUsername() . ')';
         $this->withdrawnCount++;
         $this->handleApplication($student);
         $this->handleAssignment($student);
         $this->handleRoommate($student);
         $this->handleRlcAssignment($student);
         $this->handleRlcApplication($student);
     }
 }
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'edit_role_members')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to edit role members.');
     }
     $username = $context->get('username');
     $rolename = $context->get('role');
     $class = $context->get('className');
     $instance = $context->get('instance');
     if (is_null($username) || is_null($rolename)) {
         echo json_encode(false);
         exit;
     }
     $db = new PHPWS_DB('hms_role');
     $db->addWhere('name', $rolename);
     $result = $db->select('row');
     if (PHPWS_Error::logIfError($result) || is_null($result['id'])) {
         echo json_encode(false);
         exit;
     }
     $role_id = $result['id'];
     $role = new HMS_Role();
     $role->id = $role_id;
     if ($role->load()) {
         echo json_encode($role->removeUser($username, $class, $instance));
         exit;
     }
     echo json_encode(false);
     exit;
 }
 public function execute(CommandContext $context)
 {
     $term = Term::getSelectedTerm();
     $messageAll = Current_User::allow('hms', 'email_all');
     $db = new PHPWS_DB('hms_residence_hall');
     $db->addWhere('term', $term);
     $results = $db->getObjects('HMS_Residence_Hall');
     if (PHPWS_Error::logIfError($results) || is_null($results)) {
         $errorMsg = array();
         if (is_null($results)) {
             $errorMsg['error'] = 'You do not have permission to message any halls, sorry.';
         } else {
             $errorMsg['error'] = 'There was a problem reading the database, please try reloading the page.  If the problem persists contact ESS.';
         }
         echo json_encode($errorMsg);
         exit;
     }
     $permission = new HMS_Permission();
     $data = array();
     foreach ($results as $hall) {
         $somethingEnabled = false;
         $floors = $hall->get_floors();
         unset($obj);
         $obj = new stdClass();
         $obj->name = $hall->getHallName();
         $obj->id = $hall->getId();
         $obj->floors = array();
         //$blah = 'Verify: ' . ($permission->verify(UserStatus::getUsername(), $hall, 'email') ? 'true' : 'false');
         if ($permission->verify(UserStatus::getUsername(), $hall, 'email') || $messageAll) {
             $obj->enabled = true;
             $somethingEnabled = true;
             foreach ($floors as $floor) {
                 unset($floor_obj);
                 $floor_obj = new stdClass();
                 $floor_obj->name = "Floor: " . $floor->getFloorNumber();
                 $floor_obj->id = $floor->getId();
                 $floor_obj->enabled = true;
                 $obj->floors[] = $floor_obj;
             }
         } else {
             $obj->enabled = false;
             foreach ($floors as $floor) {
                 unset($floor_obj);
                 $floor_obj = new stdClass();
                 $floor_obj->name = "Floor: " . $floor->getFloorNumber();
                 $floor_obj->id = $floor->getId();
                 $floor_obj->enabled = $permission->verify(Current_User::getUsername(), $floor, 'email');
                 $obj->floors[] = $floor_obj;
                 if ($floor_obj->enabled) {
                     $somethingEnabled = true;
                 }
             }
         }
         if ($somethingEnabled) {
             $data[] = $obj;
         }
     }
     echo json_encode($data);
     exit;
 }
 public static function saveObject(DbStorable $o)
 {
     $vars = $o->extractVars();
     $tableName = $o::getTableName();
     // Check if the key already exists
     $query = "SELECT * FROM {$tableName} WHERE id = {$vars['id']}";
     $result = \PHPWS_DB::getAll($query);
     if (count($result) > 0) {
         $exists = true;
     } else {
         $exists = false;
     }
     $db = new \PHPWS_DB($o->getTableName());
     foreach ($vars as $key => $value) {
         $db->addValue($key, $value);
     }
     if ($exists) {
         $db->addWhere('id', $vars['id']);
         $result = $db->update();
     } else {
         $result = $db->insert(false);
     }
     if (\PHPWS_Error::logIfError($result)) {
         throw new \Exception($result->toString());
     }
 }
 public function execute(CommandContext $context)
 {
     // Check for report ID
     $reportId = $context->get('reportId');
     if (!isset($reportId) || is_null($reportId)) {
         throw new InvalidArgumentException('Missing report id.');
     }
     PHPWS_Core::initModClass('hms', 'ReportFactory.php');
     // Load the report to get its class
     try {
         $report = ReportFactory::getReportById($reportId);
     } catch (InvalidArgumentException $e) {
         NQ::simple('hms', hms\NotificationView::SUCCESS, 'Report canceled.');
         $context->goBack();
     }
     $db = new PHPWS_DB('hms_report');
     $db->addWhere('id', $reportId);
     $result = $db->delete();
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Report canceled.');
     $cmd = CommandFactory::getCommand('ShowReportDetail');
     $cmd->setReportClass($report->getClass());
     $cmd->redirect();
 }
Exemple #7
0
 public function init()
 {
     $DB = new PHPWS_DB('controlpanel_tab');
     $result = $DB->loadObject($this);
     if (PHPWS_Error::logIfError($result) || !$result) {
         $this->id = null;
     }
 }
Exemple #8
0
 public function save()
 {
     $db = new PHPWS_DB('analytics_tracker');
     $result = $db->saveObject($this);
     if (PHPWS_Error::logIfError($result)) {
         return $result;
     }
 }
 /**
  * @see Command::execute()
  */
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'hall_attributes')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to edit halls.');
     }
     // Make sure a hall ID was set
     $hallId = $context->get('hallId');
     if (is_null($hallId)) {
         throw new InvalidArgumentException('Missing hall ID.');
     }
     $viewCmd = CommandFactory::getCommand('EditResidenceHallView');
     $viewCmd->setHallId($hallId);
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     // Create the hall object given the hall id
     $hall = new HMS_Residence_Hall($hallId);
     if (!$hall) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid hall.');
         $viewCmd->redirect();
     }
     if ($context->get('tab') == 'settings') {
         // Compare the hall's gender and the gender the user selected
         // If they're not equal, call 'can_change_gender' public function
         if ($hall->gender_type != $_REQUEST['gender_type']) {
             if (!$hall->can_change_gender($_REQUEST['gender_type'])) {
                 NQ::simple('hms', hms\NotificationView::ERROR, 'Incompatible gender detected. No changes were made.');
                 $viewCmd->redirect();
             }
         }
         // Grab all the input from the form and save the hall
         $hall->hall_name = $context->get('hall_name');
         $hall->gender_type = $context->get('gender_type');
         // Set the defaults for the check boxes
         $context->setDefault('air_conditioned', 0);
         $context->setDefault('is_online', 0);
         $context->setDefault('meal_plan_required', 0);
         $context->setDefault('assignment_notifications', 0);
         $hall->air_conditioned = $context->get('air_conditioned');
         $hall->is_online = $context->get('is_online');
         $hall->meal_plan_required = $context->get('meal_plan_required');
         $hall->assignment_notifications = $context->get('assignment_notifications');
         $hall->setPackageDeskId($context->get('package_desk'));
     } else {
         if ($context->get('tab') == 'images') {
             $hall->exterior_image_id = $context->get('exterior_image_id');
             $hall->other_image_id = $context->get('other_image_id');
             $hall->map_image_id = $context->get('map_image_id');
             $hall->room_plan_image_id = $context->get('room_plan_image_id');
         }
     }
     $result = $hall->save();
     if (!$result || PHPWS_Error::logIfError($result)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'There was a problem saving the Residence Hall. No changes were made.');
         $viewCmd->redirect();
     }
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'The Residence hall was updated successfully.');
     $viewCmd->redirect();
 }
Exemple #10
0
/**
 * @version $Id$
 * @author Matthew McNaney <mcnaney at gmail dot com>
 */
function filecabinet_unregister($module, &$content)
{
    $db = new PHPWS_DB('folders');
    $db->addValue('module_created', null);
    $db->addWhere('module_created', $module);
    PHPWS_Error::logIfError($db->update());
    $content[] = dgettext('filecabinet', 'Unregistered from File Cabinet.');
    return true;
}
 public function save()
 {
     $db = new PHPWS_DB('hms_eligibility_waiver');
     $result = $db->saveObject($this);
     if (!$result || PHPWS_Error::logIfError($result)) {
         return false;
     }
     return true;
 }
 public function delete()
 {
     $db = new PHPWS_DB('hms_movein_time');
     $db->addWhere('id', $this->id);
     $result = $db->delete();
     if (!$result || PHPWS_Error::logIfError($result)) {
         return false;
     }
     return true;
 }
 /**
  * Deletes this item from the queue
  */
 public function delete()
 {
     $db = new PHPWS_DB('hms_banner_queue');
     $db->addWhere('id', $this->id);
     $result = $db->delete();
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     return TRUE;
 }
 public function __construct($term)
 {
     parent::__construct($term);
     $db = new PHPWS_DB('hms_special_assignment');
     $db->addWhere('term', $this->term);
     $result = $db->getObjects('SpecialAssignment');
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->getMessage());
     }
     $this->specials = $result;
 }
 public static function getChangesForInternship(Internship $internship)
 {
     $db = new \PHPWS_DB('intern_change_history');
     $db->addWhere('internship_id', $internship->getId());
     $db->addOrder('timestamp ASC');
     $results = $db->getObjects('\\Intern\\ChangeHistory');
     if (\PHPWS_Error::logIfError($results)) {
         throw new \Exception($results->toString());
     }
     return $results;
 }
Exemple #16
0
 public function save()
 {
     $db = $this->getDb();
     $result = $db->saveObject($this);
     if (PHPWS_Error::logIfError($result)) {
         PHPWS_Core::initModClass('faxmaster', 'exception/DatabaseException.php');
         throw new DatabaseException($result->toString());
     }
     // return new id
     return $result;
 }
 public static function getForTerm($term)
 {
     $db = new PHPWS_DB('hms_application_feature');
     $db->addWhere('term', $term);
     $result = $db->getObjects('ApplicationFeature');
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     // TODO: Reorg so the array is indexed by the class name.
     return $result;
 }
 public function execute(CommandContext $context)
 {
     $db = new PHPWS_DB('hms_role');
     $result = $db->select();
     if (PHPWS_Error::logIfError($result)) {
         echo json_encode(array());
     } else {
         echo json_encode($result);
     }
     exit;
 }
Exemple #19
0
 public static function getUserRolesForInstance($instance)
 {
     $db = new PHPWS_DB('hms_user_role');
     $db->addWhere('hms_user_role.class', strtolower(get_class($instance)));
     $db->addWhere('hms_user_role.instance', $instance->id);
     $result = $db->select();
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     return $result;
 }
Exemple #20
0
 public function delete()
 {
     $db = $this->getDb();
     $db->addWhere('id', $this->id);
     //$db->setTestMode();
     $result = $db->delete();
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     return TRUE;
 }
 public static function getChangesForInternship(Internship $internship)
 {
     PHPWS_Core::initModClass('intern', 'ChangeHistory.php');
     $db = new PHPWS_DB('intern_change_history');
     $db->addWhere('internship_id', $internship->getId());
     $db->addOrder('timestamp ASC');
     $results = $db->getObjects('ChangeHistory');
     if (PHPWS_Error::logIfError($results)) {
         throw new Exception($results->toString());
     }
     return $results;
 }
Exemple #22
0
 public static function getRoomByPersistentId($roomId, $term)
 {
     $db = new PHPWS_DB('hms_room');
     $db->addWhere('term', $term);
     $db->addWhere('persistent_id', $roomId);
     $room = new HMS_Room(0);
     $result = $db->loadObject($room);
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     return $room;
 }
Exemple #23
0
 public function save($term)
 {
     $this->term = $term;
     $this->timestamp = time();
     $db = new PHPWS_DB('hms_student_cache');
     try {
         $result = $db->saveObject($this);
     } catch (\Exception $e) {
         // Silently log any errors
         PHPWS_Error::logIfError($e);
     }
 }
 public function execute(CommandContext $context)
 {
     $this->searchString = $context->get('studentSearchQuery');
     // NB: this is the *search term*, not the semester
     $this->hmsTerm = Term::getCurrentTerm();
     // If the search string is empty, just return an empty json array
     if (!isset($this->searchString) || $this->searchString == '') {
         echo json_encode(array());
         exit;
     }
     // Strip any non-alphanumeric characters, escape slashes
     $this->searchString = pg_escape_string($this->searchString);
     // Check for a direct banner ID match
     if (preg_match("/^[0-9]{9}/", $this->searchString)) {
         // String is all-numeric, probably a Banner ID
         // If the seach string is exactly 9 digits, then try to find a match
         $sql = $this->getBannerIdSearchSql();
     } else {
         // Do fancy string matching instead
         $sql = $this->getFuzzyTextSql();
     }
     // TODO join for only assigned students / applied students in current/future terms
     // Add a limit on the number of results
     $sql .= " LIMIT " . self::resultLimit;
     //test($sql,1);
     $this->db = new PHPWS_DB('hms_student_autocomplete');
     $results = PHPWS_DB::getAll($sql);
     //test($results,1);
     if (is_null($results)) {
         echo json_encode();
         exit;
     }
     // Log any DB errors and echo an empty result
     if (PHPWS_Error::logIfError($results)) {
         echo json_encode(array());
         exit;
     }
     $resultObjects = array();
     foreach ($results as $row) {
         $obj = new stdClass();
         $obj->banner_id = $row['banner_id'];
         $obj->name = $row['first_name'] . ' ' . $row['last_name'];
         $obj->username = $row['username'];
         $resultObjects[] = $obj;
     }
     $jsonResult = json_encode($resultObjects);
     //test($jsonResult,1);
     echo $jsonResult;
     exit;
     // NB: using setContent adds escape characters to quotes in the JSON string... WRONG.
     //$context->setContent(json_encode($jsonResult));
 }
 /**
  * Delete model from database.
  */
 public function delete()
 {
     if (is_null($this->id) || !is_numeric($this->id)) {
         return false;
     }
     $db = $this->getDb();
     $db->addWhere('id', $this->id);
     $result = $db->delete();
     if (PHPWS_Error::logIfError($result)) {
         throw new Exception($result->getMessage(), $result->getCode());
     }
     return true;
 }
 public function delete()
 {
     $db = new PHPWS_DB('hms_summer_application');
     $db->addWhere('id', $this->id);
     $result = $db->delete();
     if (!$result || PHPWS_Error::logIfError($result)) {
         return $result;
     }
     if (!parent::delete()) {
         return false;
     }
     return TRUE;
 }
Exemple #27
0
 public function delete()
 {
     $result = parent::delete();
     if (PHPWS_Error::isError($result)) {
         return $result;
     }
     $db = new PHPWS_DB('analytics_tracker_piwik');
     $db->addWhere('id', $this->id);
     $result = $db->delete();
     if (PHPWS_Error::logIfError($result)) {
         return $result;
     }
 }
 public function load()
 {
     if (is_null($this->id) || !is_numeric($this->id)) {
         return false;
     }
     $db = new PHPWS_DB('hms_special_assignment');
     $db->addWhere('id', $this->id);
     $result = $db->loadObject($this);
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->getMessage());
     }
     return true;
 }
Exemple #29
0
 public function init()
 {
     $db = new PHPWS_DB('ps_block');
     $result = $db->loadObject($this);
     if (PHPWS_Error::logIfError($result)) {
         return $result;
     }
     if (!$result) {
         $this->id = 0;
         return false;
     } else {
         return true;
     }
 }
 /**
  * Deletes the passed in EmergencyContact from the database.
  * @param EmergencyContact $contact
  * @throws InvalidArgumentException
  * @throws Exception
  */
 public static function delete(EmergencyContact $contact)
 {
     $contactId = $contact->getId();
     if (is_null($contactId) || !isset($contactId)) {
         throw new \InvalidArgumentException('Missing contact id.');
     }
     $db = new \PHPWS_DB('intern_emergency_contact');
     $db->addWhere('id', $contactId);
     $result = $db->delete();
     if (\PHPWS_Error::logIfError($result)) {
         throw new \Exception($result->toString());
     }
     return true;
 }