Пример #1
0
/**
 * @author Matthew McNaney <mcnaney at gmail dot com>
 * @version $Id$
 */
function users_register($module, &$content)
{
    PHPWS_Core::initModClass('users', 'Permission.php');
    PHPWS_Core::initModClass('users', 'My_Page.php');
    $no_permissions = $no_my_page = FALSE;
    $result = Users_Permission::createPermissions($module);
    if (is_null($result)) {
        PHPWS_Boost::addLog('users', dgettext('users', 'Permissions file not implemented.'));
        $content[] = dgettext('users', 'Permissions file not implemented.');
        $no_permissions = TRUE;
    } elseif (PHPWS_Error::isError($result)) {
        $content[] = dgettext('users', 'Permissions table not created successfully.');
        PHPWS_Error::log($result);
        return FALSE;
    } else {
        $content[] = dgettext('users', 'Permissions table created successfully.');
    }
    $result = My_Page::registerMyPage($module);
    if (PHPWS_Error::isError($result)) {
        PHPWS_Boost::addLog('users', dgettext('users', 'A problem occurred when trying to register this module to My Page.'));
        $content[] = dgettext('users', 'A problem occurred when trying to register this module to My Page.');
        return FALSE;
    } elseif ($result != FALSE) {
        $content[] = dgettext('users', 'My Page registered to Users module.');
    } else {
        $no_my_page = TRUE;
    }
    // If the module doesn't have permissions or a My Page
    // then don't register the module
    if ($no_permissions && $no_my_page) {
        return FALSE;
    } else {
        return TRUE;
    }
}
Пример #2
0
 /**
  * Exec
  *
  * @param CommandContext $context
  * @throws InvalidArgumentExection
  */
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'reports')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do no have permission to run reports.');
     }
     $reportId = $context->get('reportId');
     if (!isset($reportId) || is_null($reportId)) {
         throw new InvalidArgumentExection('Missing report id.');
     }
     // Instantiate the report controller with the requested report id
     PHPWS_Core::initModClass('hms', 'ReportFactory.php');
     $report = ReportFactory::getReportById($reportId);
     // Check to make sure the file exists
     if (!file_exists($report->getCsvOutputFilename())) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Could not open report file.');
         PHPWS_Error::log('Could not open report file ' . $report->getCsvOutputFilename(), 'hms');
         $reportCmd = CommandFactory::getCommand('ShowReportDetail');
         $reportCmd->setReportClass($report->getClass());
         $reportCmd->redirect();
     }
     $pdf = file_get_contents($report->getCsvOutputFilename());
     // Hoepfully force the browser to open a 'save as' dialogue
     header('Content-Type: text/csv');
     header('Cache-Control: public, must-revalidate, max-age=0');
     // HTTP/1.1
     header('Pragma: public');
     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
     // Date in the past
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     header('Content-Length: ' . strlen($pdf));
     header('Content-Disposition: attachment; filename="' . basename($report->getCsvOutputFilename()) . '";');
     echo $pdf;
     exit;
 }
Пример #3
0
 /**
  * Shows the requested report's HTML output.
  * 
  * @param CommandContext $context
  * @throws InvalidArgumentExection
  */
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'reports')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do no have permission to run reports.');
     }
     $reportId = $context->get('reportId');
     if (!isset($reportId) || is_null($reportId)) {
         throw new InvalidArgumentExection('Missing report id.');
     }
     // Instantiate the report controller with the requested report id
     PHPWS_Core::initModClass('hms', 'ReportFactory.php');
     $report = ReportFactory::getReportById($reportId);
     Layout::addPageTitle($report->getFriendlyName());
     $detailCmd = CommandFactory::getCommand('ShowReportDetail');
     $detailCmd->setReportClass($report->getClass());
     $content = '<div> ' . $detailCmd->getLink('&laquo; back') . ' </div>';
     $content .= file_get_contents($report->getHtmlOutputFilename());
     if ($content === FALSE) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Could not open report file.');
         PHPWS_Error::log('Could not open report file ' . $report->getCsvOutputFilename(), 'hms');
         $reportCmd = CommandFactory::getCommand('ShowReportDetail');
         $reportCmd->setReportClass($report->getClass());
         $reportCmd->redirect();
     }
     $context->setContent($content);
 }
Пример #4
0
 public function __construct($name = NULL, $data = NULL, $id = NULL, $type = NULL)
 {
     $editorList = $this->getEditorList();
     if (PHPWS_Error::isError($editorList)) {
         PHPWS_Error::log($editorList);
         $this->type = null;
         return;
     }
     if (empty($type)) {
         $type = $this->getUserType();
     }
     $this->editorList = $editorList;
     if (isset($type)) {
         $result = $this->setType($type);
         if (PHPWS_Error::isError($result)) {
             PHPWS_Error::log($result);
             $this->type = null;
             return;
         }
     }
     if (isset($id)) {
         $this->id = $id;
     }
     if (isset($name)) {
         $this->setName($name);
         if (empty($this->id)) {
             $this->id = $name;
         }
     }
     if (isset($data)) {
         $this->setData(trim($data));
     }
 }
Пример #5
0
/**
 * unregisters deleted keys from menu
 *
 * @author Matthew McNaney <mcnaney at gmail dot com>
 * @version $Id$
 */
function menu_unregister_key(Key $key)
{
    PHPWS_Core::initModClass('menu', 'Menu_Link.php');
    if (empty($key) || empty($key->id)) {
        return FALSE;
    }
    $db = new PHPWS_DB('menu_links');
    $db->addWhere('key_id', $key->id);
    $result = $db->delete();
    if (PHPWS_Error::isError($result)) {
        PHPWS_Error::log($result);
    }
    $db2 = new PHPWS_DB('menu_assoc');
    $db2->addWhere('key_id', $key->id);
    $result = $db2->delete();
    if (PHPWS_Error::isError($result)) {
        PHPWS_Error::log($result);
    }
    $db3 = new PHPWS_DB('menus');
    $db3->addWhere('assoc_key', $key->id);
    $db3->addValue('assoc_key', 0);
    $db3->addValue('assoc_url', null);
    $db3->update();
    return true;
}
Пример #6
0
 public static function logIfError($item)
 {
     if (PHPWS_Error::isError($item)) {
         PHPWS_Error::log($item);
         return true;
     } else {
         return false;
     }
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'RlcMembershipFactory.php');
     PHPWS_Core::initModClass('hms', 'RlcAssignmentSelfAssignedState.php');
     $requestId = $context->get('requestId');
     $mealPlan = $context->get('mealPlan');
     $errorCmd = CommandFactory::getCommand('LotteryShowConfirmRoommateRequest');
     $errorCmd->setRequestId($requestId);
     $errorCmd->setMealPlan($mealPlan);
     // Confirm the captcha
     PHPWS_Core::initCoreClass('Captcha.php');
     $captcha = Captcha::verify(TRUE);
     if ($captcha === FALSE) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'The words you entered were incorrect. Please try again.');
         $errorCmd->redirect();
     }
     // Check for a meal plan
     if (!isset($mealPlan) || $mealPlan == '') {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Please choose a meal plan.');
         $errorCmd->redirect();
     }
     $term = PHPWS_Settings::get('hms', 'lottery_term');
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     // Update the meal plan field on the application
     $app = HousingApplication::getApplicationByUser(UserStatus::getUsername(), $term);
     $app->setMealPlan($mealPlan);
     try {
         $app->save();
     } catch (Exception $e) {
         PHPWS_Error::log('hms', $e->getMessage());
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, there was an error confirming your roommate invitation. Please contact University Housing.');
         $errorCmd->redirect();
     }
     // Try to actually make the assignment
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     try {
         HMS_Lottery::confirm_roommate_request(UserStatus::getUsername(), $requestId, $mealPlan);
     } catch (Exception $e) {
         PHPWS_Error::log('hms', $e->getMessage());
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, there was an error confirming your roommate invitation. Please contact University Housing.');
         $errorCmd->redirect();
     }
     # Log the fact that the roommate was accepted and successfully assigned
     HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_CONFIRMED_ROOMMATE, UserStatus::getUsername(), "Captcha: \"{$captcha}\"");
     // Check for an RLC membership and update status if necessary
     // If this student was an RLC self-select, update the RLC memberhsip state
     $rlcAssignment = RlcMembershipFactory::getMembership($student, $term);
     if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') {
         $rlcAssignment->changeState(new RlcAssignmentSelfAssignedState($rlcAssignment));
     }
     $invite = HMS_Lottery::get_lottery_roommate_invite_by_id($requestId);
     $successCmd = CommandFactory::getCommand('LotteryShowConfirmedRoommateThanks');
     $successCmd->setRequestId($requestId);
     $successCmd->redirect();
 }
Пример #8
0
/**
 * @author Matthew McNaney <mcnaney at gmail dot com>
 * @version $Id$
 */
function calendar_uninstall(&$content)
{
    PHPWS_Core::initModClass('calendar', 'Schedule.php');
    // Need functions to remove old event tables
    $db = new PHPWS_DB('calendar_schedule');
    $schedules = $db->getObjects('Calendar_Schedule');
    if (PHPWS_Error::isError($schedules)) {
        return $schedules;
    } elseif (empty($schedules)) {
        $result = PHPWS_DB::dropTable('calendar_schedule');
        if (PHPWS_Error::isError($result)) {
            return $result;
        }
        $result = PHPWS_DB::dropTable('calendar_notice');
        if (PHPWS_Error::isError($result)) {
            return $result;
        }
        $result = PHPWS_DB::dropTable('calendar_suggestions');
        if (PHPWS_Error::isError($result)) {
            return $result;
        }
        return true;
    }
    $error = false;
    foreach ($schedules as $sch) {
        $result = $sch->delete();
        if (PHPWS_Error::isError($result)) {
            PHPWS_Error::log($result);
            $error = true;
        }
    }
    $result = PHPWS_DB::dropTable('calendar_schedule');
    if (PHPWS_Error::isError($result)) {
        return $result;
    }
    $result = PHPWS_DB::dropTable('calendar_notice');
    if (PHPWS_Error::isError($result)) {
        return $result;
    }
    $result = PHPWS_DB::dropTable('calendar_suggestions');
    if (PHPWS_Error::isError($result)) {
        return $result;
    }
    if (PHPWS_DB::isTable('converted')) {
        $db2 = new PHPWS_DB('converted');
        $db2->addWhere('convert_name', array('schedule', 'calendar'));
        $db2->delete();
        $content[] = dgettext('calendar', 'Removed convert flag.');
    }
    if (!$error) {
        $content[] = dgettext('calendar', 'Calendar tables removed.');
    } else {
        $content[] = dgettext('calendar', 'Some errors occurred when uninstalling Calendar.');
    }
    return true;
}
Пример #9
0
 public function __construct($id = null)
 {
     if (!isset($id)) {
         return;
     }
     $this->setId($id);
     $result = $this->init();
     if (PHPWS_Error::isError($result)) {
         PHPWS_Error::log($result);
     }
 }
Пример #10
0
/**
 * @author Matthew McNaney <mcnaney at gmail dot com>
 * @version $Id$
 */
function rss_unregister($module, &$content)
{
    $db = new PHPWS_DB('rssfeeds');
    $db->addWhere('module', $module);
    $result = $db->delete();
    if (PHPWS_Error::isError($result)) {
        PHPWS_Error::log($result);
        $content[] = dgettext('rss', 'An error occurred trying to unregister this module from RSSFeeds.');
        return FALSE;
    } else {
        $content[] = dgettext('rss', 'Module unregistered from RSSFeeds.');
        return TRUE;
    }
}
Пример #11
0
/**
 * @author Matthew McNaney <mcnaney at gmail dot com>
 * @version $Id$
 */
function menu_install(&$content)
{
    PHPWS_Core::initModClass('menu', 'Menu_Item.php');
    $menu = new Menu_Item();
    $menu->title = dgettext('menu', 'Main menu');
    $menu->template = 'basic';
    $menu->pin_all = 1;
    $result = $menu->save();
    if (PHPWS_Error::isError($result)) {
        PHPWS_Error::log($result);
        return false;
    } else {
        $content[] = dgettext('menu', 'Default menu created successfully.');
        return true;
    }
}
Пример #12
0
 public function userOption($module_title)
 {
     $module = new PHPWS_Module($module_title);
     $directory = $module->getDirectory();
     $final_file = $directory . 'inc/my_page.php';
     if (!is_file($final_file)) {
         PHPWS_Error::log(PHPWS_FILE_NOT_FOUND, 'users', 'userOption', $final_file);
         return dgettext('users', 'There was a problem with this module\'s My Page file.');
     }
     include $final_file;
     if (!function_exists('my_page')) {
         return PHPWS_Error::get(USER_MISSING_MY_PAGE, 'users', 'My_Page::userOption', $module_title);
     }
     $content = my_page();
     return $content;
 }
Пример #13
0
 public function __construct($id = 0)
 {
     if (empty($id)) {
         $this->start_time = PHPWS_Time::getUserTime();
         $this->end_time = PHPWS_Time::getUserTime();
         return;
     } else {
         $this->id = (int) $id;
         $result = $this->init();
         if (PHPWS_Error::isError($result)) {
             PHPWS_Error::log($result);
             $this->id = 0;
         } elseif (!$result) {
             $this->id = 0;
         }
     }
 }
Пример #14
0
 public static function registerModule($module, &$content)
 {
     if (is_file(PHPWS_SOURCE_DIR . 'mod/' . $module . '/conf/rss.php')) {
         $reg_file = PHPWS_Core::getConfigFile($module, 'rss.php');
     } else {
         $reg_file = false;
     }
     if ($reg_file == FALSE) {
         PHPWS_Boost::addLog($module, dgettext('rss', 'No RSS file found.'));
         return FALSE;
     }
     PHPWS_Core::initModClass('rss', 'Channel.php');
     include $reg_file;
     $oChannel = new RSS_Channel();
     $oChannel->module = $module;
     if (!isset($channel) || !is_array($channel)) {
         $content[] = dgettext('rss', 'RSS file found but no channel information.');
         PHPWS_Boost::addLog($module, dgettext('rss', 'RSS file found but no channel information.'));
     }
     $oModule = new PHPWS_Module($module);
     if (!empty($channel['title'])) {
         $oChannel->title = strip_tags($channel['title']);
     } else {
         $oChannel->title = $oModule->proper_name;
     }
     if (!empty($channel['description'])) {
         $oChannel->description = strip_tags($channel['description']);
     }
     if (!empty($channel['link'])) {
         $oChannel->link = strip_tags($channel['link']);
     } else {
         $oChannel->link = PHPWS_Core::getHomeHttp();
     }
     $result = $oChannel->save();
     if (PHPWS_Error::isError($result)) {
         PHPWS_Error::log($result);
         PHPWS_Boost::addLog($module, dgettext('rss', 'An error occurred registering to RSS module.'));
         $content[] = dgettext('rss', 'An error occurred registering to RSS module.');
         return NULL;
     } else {
         $content[] = sprintf(dgettext('rss', 'RSS registration to %s module successful.'), $oModule->proper_name);
         return TRUE;
     }
 }
Пример #15
0
 public static function sendEmail($to, $from, $subject, $content, $cc = NULL, $bcc = NULL)
 {
     $settings = InternSettings::getInstance();
     // Sanity checking
     if (!isset($to) || is_null($to)) {
         return false;
     }
     if (!isset($from) || is_null($from)) {
         $from = $settings->getSystemName() . ' <' . $settings->getEmailFromAddress() . '>';
     }
     if (!isset($subject) || is_null($subject)) {
         return false;
     }
     if (!isset($content) || is_nulL($content)) {
         return false;
     }
     // Create a Mail object and set it up
     PHPWS_Core::initCoreClass('Mail.php');
     $message = new PHPWS_Mail();
     $message->addSendTo($to);
     $message->setFrom($from);
     $message->setSubject($subject);
     $message->setMessageBody($content);
     if (isset($cc)) {
         $message->addCarbonCopy($cc);
     }
     if (isset($bcc)) {
         $message->addBlindCopy($bcc);
     }
     // Send the message
     if (EMAIL_TEST_FLAG) {
         $result = true;
     } else {
         $result = $message->send();
     }
     if (PEAR::isError($result)) {
         PHPWS_Error::log($result);
         return false;
     }
     self::logEmail($message);
     return true;
 }
Пример #16
0
 public static function showBlocks($key)
 {
     $db = new PHPWS_DB('block');
     $db->addWhere('block_pinned.key_id', $key->id);
     $db->addWhere('id', 'block_pinned.block_id');
     Key::restrictView($db, 'block');
     $result = $db->getObjects('Block_Item');
     if (PHPWS_Error::isError($result)) {
         PHPWS_Error::log($result);
         return NULL;
     }
     if (empty($result)) {
         return NULL;
     }
     foreach ($result as $block) {
         $block->setPinKey($key);
         Layout::add($block->view(), 'block', $block->getContentVar());
         $GLOBALS['Current_Blocks'][$block->id] = TRUE;
     }
 }
Пример #17
0
 public function init()
 {
     $db = new PHPWS_DB('hms_learning_community_assignment');
     $db->addWhere('id', $this->getId(), '=');
     $result = $db->select('row');
     if (PEAR::isError($result)) {
         PHPWS_Error::log($result, 'hms', 'init', "id:{$id}");
         return $result;
     }
     if (sizeof($result) < 1) {
         return FALSE;
     }
     if ($result == FALSE || $result == NULL) {
         return;
     }
     $this->user_id = $result['asu_username'];
     $this->rlc_id = $result['rlc_id'];
     $this->assigned_by_user = $result['assigned_by_user'];
     return $result;
 }
Пример #18
0
 public function loadTemplates()
 {
     PHPWS_Core::initModClass('pagesmith', 'PS_Template.php');
     if (!empty($this->tpl_list)) {
         return true;
     }
     $tpl_dir = $this->ps->pageTplDir();
     $templates = PHPWS_File::listDirectories($tpl_dir);
     if (empty($templates)) {
         PHPWS_Error::log(PS_TPL_DIR, 'pagesmith', 'PS_Forms::loadTemplates', $tpl_dir);
         return false;
     }
     foreach ($templates as $tpl) {
         $pg_tpl = new PS_Template($tpl);
         if ($pg_tpl->data) {
             $this->tpl_list[$tpl] = $pg_tpl;
         }
     }
     return true;
 }
Пример #19
0
 public static function send_email($to, $from, $subject, $content, $cc = NULL, $bcc = NULL)
 {
     # Sanity checking
     if (!isset($to) || is_null($to)) {
         return false;
     }
     if (!isset($from) || is_null($from)) {
         $from = SYSTEM_NAME . ' <' . FROM_ADDRESS . '>';
     }
     if (!isset($subject) || is_null($subject)) {
         return false;
     }
     if (!isset($content) || is_nulL($content)) {
         return false;
     }
     # Create a Mail object and set it up
     \PHPWS_Core::initCoreClass('Mail.php');
     $message = new PHPWS_Mail();
     $message->addSendTo($to);
     $message->setFrom($from);
     $message->setSubject($subject);
     $message->setMessageBody($content);
     if (isset($cc)) {
         $message->addCarbonCopy($cc);
     }
     if (isset($bcc)) {
         $message->addBlindCopy($bcc);
     }
     # Send the message
     if (EMAIL_TEST_FLAG) {
         HMS_Email::log_email($message);
         $result = true;
     } else {
         $result = $message->send();
     }
     if (PEAR::isError($result)) {
         PHPWS_Error::log($result);
         return false;
     }
     return true;
 }
Пример #20
0
 /**
  * Checks to see if the value isset in the global variable.
  * is_set does not load all of the modules at once to allow
  * checking against default settings. If all were pulled at once,
  * newly added settings would get ignored.
  */
 public static function is_set($module, $setting = null)
 {
     if (!isset($GLOBALS['PHPWS_Settings'][$module])) {
         $result = PHPWS_Settings::load($module);
         if (PHPWS_Error::isError($result)) {
             PHPWS_Error::log($result);
             return false;
         }
     }
     if (is_array($GLOBALS['PHPWS_Settings'][$module])) {
         if (empty($setting)) {
             return true;
         } elseif (isset($GLOBALS['PHPWS_Settings'][$module][$setting])) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Пример #21
0
 function goToStep()
 {
     switch ($this->step) {
         case '0':
             $this->welcome();
             break;
         case '1':
             $this->createConfig();
             break;
         case '2':
             if (!$this->postConfig()) {
                 // create config file and database
                 $this->createConfig();
             } else {
                 if ($this->writeConfigFile()) {
                     // config written, need to reload page for new defines
                     header('location: index.php?step=3');
                     exit;
                 } else {
                     echo implode('<br />', $this->messages);
                 }
                 exit;
             }
             break;
         case '3':
             if ($this->createCore()) {
                 if ($this->installCoreModules()) {
                     $this->content[] = dgettext('core', 'Core modules installed successfully.');
                     $this->content[] = sprintf('<a href="index.php?step=4">%s</a>', dgettext('core', 'Click to continue'));
                 }
             }
             break;
         case '4':
             $this->createUser();
             break;
         case '5':
             if ($this->postUser()) {
                 $db = new PHPWS_DB('users');
                 $result = $db->select();
                 if (empty($result)) {
                     $_SESSION['User']->setDisplayName('Administrator');
                     $_SESSION['User']->save();
                     $this->content[] = dgettext('core', 'New user created successfully.');
                     $this->step = 6;
                     $this->goToStep();
                     break;
                 } elseif (PHPWS_Error::isError($result)) {
                     PHPWS_Error::log($result);
                     $this->content[] = dgettext('core', 'Sorry an error occurred. Please check your logs.');
                 } else {
                     $this->content[] = dgettext('core', 'Cannot create a new user. Initial user already exists.');
                     $this->display();
                 }
             } else {
                 $this->createUser();
             }
             break;
         case '6':
             if ($this->installContentModules()) {
                 $this->content[] = dgettext('core', 'Starting modules installed.');
                 $this->content[] = dgettext('core', 'The site should be ready for you to use.');
                 //                    $this->content[] = sprintf('<a href="%s">%s</a>', PHPWS_SOURCE_HTTP, dgettext('core', 'Continue to your new site...'));
                 $this->content[] = sprintf('<a href="../">%s</a>', dgettext('core', 'Continue to your new site...'));
                 unset($_SESSION['configSettings']);
                 unset($_SESSION['User']);
                 unset($_SESSION['session_check']);
                 $this->display();
             }
         case '7':
             $dsn = $this->getDSN(2);
             $this->setConfigSet('dsn', $dsn);
             $_SESSION['configSettings']['database'] = true;
             if ($this->writeConfigFile()) {
                 // config written, need to reload page for new defines
                 header('location: index.php?step=3');
                 exit;
             } else {
                 $this->step = 2;
                 $this->createConfig();
             }
     }
     $this->display();
 }
Пример #22
0
 /**
  * Moves a box to a new location
  */
 public function move($dest)
 {
     if ($dest != 'move_box_up' && $dest != 'move_box_down' && $dest != 'move_box_top' && $dest != 'move_box_bottom' && $dest != 'restore') {
         $themeVars = $_SESSION['Layout_Settings']->getAllowedVariables();
         if (!in_array($dest, $themeVars)) {
             return PHPWS_Error::get(LAYOUT_BAD_THEME_VAR, 'layout', 'Layout_Box::move', $dest);
         }
         $themeVar = $this->theme_var;
         $this->setThemeVar($dest);
         $this->setBoxOrder(NULL);
         $this->save();
         $this->reorderBoxes($this->theme, $themeVar);
         return;
     }
     $db = new PHPWS_DB('layout_box');
     $db->addWhere('id', $this->id, '!=');
     $db->addWhere('theme', $this->theme);
     $db->addWhere('theme_var', $this->theme_var);
     $db->addOrder('box_order');
     $db->setIndexBy('box_order');
     $boxes = $db->getObjects('Layout_Box');
     if (empty($boxes)) {
         return NULL;
     }
     if (PHPWS_Error::isError($boxes)) {
         PHPWS_Error::log($boxes);
         return NULL;
     }
     switch ($dest) {
         case 'restore':
             $this->kill();
             $this->reorderBoxes($this->theme, $this->theme_var);
             Layout::resetBoxes();
             return;
             break;
         case 'move_box_up':
             if ($this->box_order == 1) {
                 $this->move('move_box_bottom');
                 return;
             } else {
                 $old_box =& $boxes[$this->box_order - 1];
                 $old_box->box_order++;
                 $this->box_order--;
                 if (!PHPWS_Error::logIfError($old_box->save())) {
                     PHPWS_Error::logIfError($this->save());
                 }
                 return;
             }
             break;
         case 'move_box_down':
             if ($this->box_order == count($boxes) + 1) {
                 $this->move('move_box_top');
                 return;
             } else {
                 $old_box =& $boxes[$this->box_order + 1];
                 $old_box->box_order--;
                 $this->box_order++;
                 if (!PHPWS_Error::logIfError($old_box->save())) {
                     PHPWS_Error::logIfError($this->save());
                 }
                 return;
             }
             break;
         case 'move_box_top':
             $this->box_order = 1;
             $this->save();
             $count = 2;
             break;
         case 'move_box_bottom':
             $this->box_order = count($boxes) + 1;
             $this->save();
             $count = 1;
             break;
     }
     foreach ($boxes as $box) {
         $box->box_order = $count;
         $box->save();
         $count++;
     }
 }
Пример #23
0
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'edit_terms')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to edit terms.');
     }
     $successCmd = CommandFactory::getCommand('ShowEditTerm');
     $errorCmd = CommandFactory::getCommand('ShowCreateTerm');
     $year = $context->get('year_drop');
     $sem = $context->get('term_drop');
     if (!isset($year) || is_null($year) || empty($year)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You must provide a year.');
         $errorCmd->redirect();
     }
     if (!isset($sem) || is_null($sem) || empty($sem)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You must provide a semester.');
         $errorCmd->redirect();
     }
     // Check to see if the specified term already exists
     if (!Term::isValidTerm($year . $sem)) {
         $term = new Term(NULL);
         $term->setTerm($year . $sem);
         $term->setBannerQueue(1);
         try {
             $term->save();
         } catch (DatabaseException $e) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error saving the term. Please try again or contact ESS.');
             $errorCmd->redirect();
         }
     } else {
         $term = new Term($year . $sem);
         // The term already exists, make sure there are no halls for this term
         $db = new PHPWS_DB('hms_residence_hall');
         $db->addWhere('term', $term->getTerm());
         $num = $db->count();
         if (!is_null($num) && $num > 0) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'One or more halls already exist for this term, so nothing can be copied.');
             $errorCmd->redirect();
         }
     }
     $text = Term::toString($term->getTerm());
     $copy = $context->get('copy_pick');
     $copyAssignments = false;
     $copyRoles = false;
     // If you want to copy roles and/or assignments
     // you must also copy the hall structure.
     if (isset($copy['struct'])) {
         // Copy hall structure
         if (isset($copy['assign'])) {
             // Copy assignments.
             $copyAssignments = true;
         }
         if (isset($copy['role'])) {
             // Copy roles.
             $copyRoles = true;
         }
     } else {
         // either $copy == 'nothing', or the view didn't specify... either way, we're done
         NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully.");
         $successCmd->redirect();
     }
     # Figure out which term we're copying from, if there isn't one then use the "current" term.
     $fromTerm = $context->get('from_term');
     if (is_null($fromTerm)) {
         $fromTerm = Term::getCurrentTerm();
     }
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     $db = new PHPWS_DB();
     try {
         $db->query('BEGIN');
         # Get the halls from the current term
         $halls = HMS_Residence_Hall::get_halls($fromTerm);
         set_time_limit(36000);
         foreach ($halls as $hall) {
             $hall->copy($term->getTerm(), $copyAssignments, $copyRoles);
         }
         $db->query('COMMIT');
     } catch (Exception $e) {
         $db->query('ROLLBACK');
         PHPWS_Error::log(print_r($e, true), 'hms');
         NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error copying the hall structure and/or assignments. The term was created, but nothing was copied.');
         $errorCmd->redirect();
     }
     if ($copyAssignments) {
         NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully. The hall structure and assignments were copied successfully.");
     } else {
         NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully and hall structure copied successfully.");
     }
     Term::setSelectedTerm($term->getTerm());
     $successCmd->redirect();
 }
Пример #24
0
 public function save()
 {
     $this->updated = time();
     if (!$this->id) {
         $this->created = time();
     }
     $this->timeout = $this->updated + 86400 * 30;
     $db = new \PHPWS_DB('properties');
     $result = $db->saveObject($this);
     if (\PEAR::isError($result)) {
         \PHPWS_Error::log($result);
         throw new \Exception('Could not save property to the database.');
     }
     return true;
 }
Пример #25
0
 /**
  * Deletes a branch from the hub's database
  */
 public function delete()
 {
     $db = new PHPWS_DB('branch_sites');
     $db->addWhere('id', $this->id);
     $result = $db->delete();
     if (PHPWS_Error::isError($result)) {
         PHPWS_Error::log($result);
         return false;
     }
     return true;
 }
Пример #26
0
 public static function channels()
 {
     PHPWS_Core::initModClass('rss', 'Channel.php');
     $final_tpl['TITLE'] = dgettext('rss', 'Administrate RSS Feeds');
     $db = new PHPWS_DB('rss_channel');
     $db->addOrder('title');
     $channels = $db->getObjects('RSS_Channel');
     if (empty($channels)) {
         $final_tpl['CONTENT'] = dgettext('rss', 'No channels have been registered.');
         return $final_tpl;
     } elseif (PHPWS_Error::isError($channels)) {
         PHPWS_Error::log($channels);
         $final_tpl['CONTENT'] = dgettext('rss', 'An error occurred when trying to access your RSS channels.');
         return $final_tpl;
     }
     foreach ($channels as $oChannel) {
         $row['TITLE'] = $oChannel->getTitle();
         $row['ACTION'] = implode(' | ', $oChannel->getActionLinks());
         if ($oChannel->active) {
             $row['ACTIVE'] = dgettext('rss', 'Yes');
         } else {
             $row['ACTIVE'] = dgettext('rss', 'No');
         }
         $tpl['channels'][] = $row;
     }
     $tpl['TITLE_LABEL'] = dgettext('rss', 'Title');
     $tpl['ACTIVE_LABEL'] = dgettext('rss', 'Active');
     $tpl['ACTION_LABEL'] = dgettext('rss', 'Action');
     $final_tpl['CONTENT'] = PHPWS_Template::process($tpl, 'rss', 'channel_list.tpl');
     return $final_tpl;
 }
Пример #27
0
 public function delete()
 {
     if (!$this->id) {
         throw new \Exception('Missing contact id');
     }
     $c_db = new \PHPWS_DB('prop_contacts');
     $c_db->addWhere('id', $this->id);
     $result = $c_db->delete();
     if (\PEAR::isError($result)) {
         \PHPWS_Error::log($result);
         throw new \Exception('Could not delete contact from database.');
     }
     $p_db = new \PHPWS_DB('properties');
     $p_db->addWhere('contact_id', $this->id);
     $result = $p_db->delete();
     if (\PEAR::isError($result)) {
         \PHPWS_Error::log($result);
         throw new \Exception('Could not delete contact properties from database.');
     }
     $i_db = new \PHPWS_DB('prop_photo');
     $i_db->addWhere('cid', $this->id);
     $result = $i_db->delete();
     if (\PEAR::isError($result)) {
         \PHPWS_Error::log($result);
         throw new \Exception('Could not delete contact photos from database.');
     }
     $dir = 'images/properties/c' . $this->id;
     \PHPWS_File::rmdir($dir);
     return true;
 }
Пример #28
0
 public function postMultimediaUpload()
 {
     $this->loadMultimedia();
     $result = $this->multimedia->importPost('file_name');
     if (PHPWS_Error::isError($result)) {
         PHPWS_Error::log($result);
         $vars['timeout'] = '3';
         $vars['refresh'] = 0;
         $this->content = dgettext('filecabinet', 'An error occurred when trying to save your multimedia file.');
         javascript('close_refresh', $vars);
         return;
     } elseif ($result) {
         if (empty($_FILES['file_name']['name'])) {
             $result = $this->multimedia->save(false, false);
         } else {
             $result = $this->multimedia->save();
         }
         if (PHPWS_Error::isError($result)) {
             PHPWS_Error::log($result);
             $this->content = dgettext('filecabinet', 'An error occurred when trying to save your multimedia file.');
             $this->content .= '<br /><strong>' . $result->getMessage() . '</strong>';
             $this->content .= '<br /><br />' . javascript('close_window', array('value' => dgettext('filecabinet', 'Close this window')));
             return;
         }
         $this->multimedia->moveToFolder();
         javascript('close_refresh');
     } else {
         Cabinet::setMessage($this->multimedia->printErrors());
         return;
     }
 }
Пример #29
0
 public static function loadHeaderTags(&$template)
 {
     $page_metatags = null;
     $theme = Layout::getCurrentTheme();
     $key = Key::getCurrent();
     if (Key::checkKey($key, false)) {
         $page_metatags = Layout::getMetaPage($key->id);
         if (PHPWS_Error::isError($page_metatags)) {
             PHPWS_Error::log($page_metatags);
             $page_metatags = null;
         }
     }
     if (!isset($_SESSION['javascript_enabled'])) {
         $jsHead[] = '<noscript><meta http-equiv="refresh" content="0;url=index.php?nojs=1&ret=' . urlencode(PHPWS_Core::getCurrentUrl()) . '"/></noscript>';
     }
     if (isset($_GET['nojs'])) {
         $_SESSION['javascript_enabled'] = false;
         PHPWS_Core::reroute(urldecode($_GET['ret']));
     } elseif (!isset($_SESSION['javascript_enabled'])) {
         $_SESSION['javascript_enabled'] = true;
     }
     if (isset($GLOBALS['Layout_JS'])) {
         foreach ($GLOBALS['Layout_JS'] as $script => $javascript) {
             $jsHead[] = $javascript['head'];
         }
     }
     if (!empty($jsHead)) {
         $template['JAVASCRIPT'] = implode("\n", $jsHead);
     }
     Layout::importStyleSheets();
     Layout::submitHeaders($theme, $template);
     if (!empty($GLOBALS['Layout_Links'])) {
         $template['STYLE'] .= "\n" . implode("\n", $GLOBALS['Layout_Links']);
     }
     $template['METATAGS'] = Layout::getMetaTags($page_metatags);
     if ($page_metatags) {
         $template['PAGE_TITLE'] = $page_metatags['page_title'] . PAGE_TITLE_DIVIDER . $_SESSION['Layout_Settings']->getPageTitle(true);
     } else {
         $template['PAGE_TITLE'] = $_SESSION['Layout_Settings']->getPageTitle();
     }
     $template['ONLY_TITLE'] = $_SESSION['Layout_Settings']->getPageTitle(TRUE);
     // Depricated
     // The Site's Name, as set in Layout 'Meta Tags' interface.
     $template['SITE_NAME'] = $_SESSION['Layout_Settings']->getPageTitle(TRUE);
     $template['BASE'] = Layout::getBase();
     $template['HTTP'] = PHPWS_Core::getHttp();
     // 'http' or 'https'
     // Complete URL of the site's home page
     $template['HOME_URL'] = PHPWS_Core::getHomeHttp(true, true, true);
 }
Пример #30
0
 public function needsUpdate()
 {
     $db = new PHPWS_DB('modules');
     $db->addWhere('title', $this->title);
     $result = $db->select('row');
     if (PHPWS_Error::isError($result)) {
         PHPWS_Error::log($result);
         return false;
     }
     return version_compare($result['version'], $this->getVersion(), '<');
 }