Example #1
2
/**
 * @license http://opensource.org/licenses/lgpl-3.0.html
 * @author Matthew McNaney <mcnaney at gmail dot com>
 */
function tailgate_install(&$content)
{
    $db = Database::newDB();
    $db->begin();
    try {
        $game = new \tailgate\Resource\Game();
        $t1 = $game->createTable($db);
        $lot = new \tailgate\Resource\Lot();
        $t2 = $lot->createTable($db);
        $lottery = new \tailgate\Resource\Lottery();
        $t3 = $lottery->createTable($db);
        $spot = new \tailgate\Resource\Spot();
        $t4 = $spot->createTable($db);
        $student = new \tailgate\Resource\Student();
        $t5 = $student->createTable($db);
        $visitor = new \tailgate\Resource\Visitor();
        $t6 = $visitor->createTable($db);
    } catch (\Exception $e) {
        $db->buildTable('tg_game')->drop(true);
        $db->buildTable('tg_lot')->drop(true);
        $db->buildTable('tg_lottery')->drop(true);
        $db->buildTable('tg_spot')->drop(true);
        $db->buildTable('tg_student')->drop(true);
        $db->buildTable('tg_visitor')->drop(true);
        $db->rollback();
        throw $e;
    }
    $db->commit();
    $content[] = 'Tables created';
    return true;
}
Example #2
0
/**
 * @license http://opensource.org/licenses/lgpl-3.0.html
 * @author Matthew McNaney <mcnaney at gmail dot com>
 */
function election_install(&$content)
{
    $db = Database::newDB();
    $db->begin();
    try {
        $election = new \election\Resource\Election();
        $election->createTable($db);
        $single = new \election\Resource\Single();
        $single->createTable($db);
        $multiple = new \election\Resource\Multiple();
        $multiple->createTable($db);
        $candidate = new \election\Resource\Candidate();
        $candidate->createTable($db);
        $referendum = new \election\Resource\Referendum();
        $referendum->createTable($db);
        $ticket = new \election\Resource\Ticket();
        $ticket->createTable($db);
    } catch (\Exception $e) {
        $db->buildTable($election->getTable())->drop(true);
        $db->buildTable($single->getTable())->drop(true);
        $db->buildTable($multiple->getTable())->drop(true);
        $db->buildTable($candidate->getTable())->drop(true);
        $db->buildTable($referendum->getTable())->drop(true);
        $db->buildTable($ticket->getTable())->drop(true);
        $db->rollback();
        throw $e;
    }
    $db->commit();
    $content[] = 'Tables created';
    return true;
}
Example #3
0
/**
 * @license http://opensource.org/licenses/lgpl-3.0.html
 * @author Matthew McNaney <mcnaney at gmail dot com>
 */
function pulse_uninstall(&$content)
{
    $content[] = 'Dropping schedule table.';
    $db = Database::newDB();
    $t1 = $db->addTable('pulse_schedule');
    $t1->drop();
    return true;
}
Example #4
0
 public function select()
 {
     foreach ($this->db_stack as $db) {
         $query[] = $db->selectQuery();
     }
     $f_query = '(' . implode(') UNION (', $query) . ')';
     $qdb = \Database::newDB();
     $qdb->loadStatement($f_query);
     return $qdb->fetchAll();
 }
Example #5
0
/**
 * @license http://opensource.org/licenses/lgpl-3.0.html
 * @author Matthew McNaney <mcnaney at gmail dot com>
 */
function tailgate_uninstall(&$content)
{
    $db = Database::newDB();
    $db->buildTable('tg_game')->drop(true);
    $db->buildTable('tg_lot')->drop(true);
    $db->buildTable('tg_lottery')->drop(true);
    $db->buildTable('tg_spot')->drop(true);
    $db->buildTable('tg_student')->drop(true);
    $db->buildTable('tg_visitor')->drop(true);
    return true;
}
Example #6
0
 /**
  * Pulls folders from the database according to folder type
  * @param integer $ftype Folder type (image, document, multimedia)
  * @return array
  */
 protected function pullFolderRows()
 {
     if (!$this->ftype) {
         throw new \Exception('Missing folder type');
     }
     $db = \Database::newDB();
     $f = $db->addTable('folders');
     $f->addFieldConditional('ftype', $this->ftype);
     $f->addOrderBy('title');
     $result = $db->select();
     return $result;
 }
Example #7
0
/**
 * @license http://opensource.org/licenses/lgpl-3.0.html
 * @author Matthew McNaney <mcnaney at gmail dot com>
 */
function election_uninstall(&$content)
{
    $db = Database::newDB();
    $db->buildTable('elect_candidate')->drop(true);
    $db->buildTable('elect_election')->drop(true);
    $db->buildTable('elect_multiple')->drop(true);
    $db->buildTable('elect_multi_chair_vote')->drop(true);
    $db->buildTable('elect_referendum')->drop(true);
    $db->buildTable('elect_referendum_vote')->drop(true);
    $db->buildTable('elect_single')->drop(true);
    $db->buildTable('elect_single_chair_vote')->drop(true);
    $db->buildTable('elect_ticket')->drop(true);
    $db->buildTable('elect_vote_complete')->drop(true);
    return true;
}
Example #8
0
 public function printFile($id)
 {
     $db = \Database::newDB();
     $t = $db->addTable('documents');
     $t->addFieldConditional('id', (int) $id);
     $row = $db->selectOneRow();
     if (empty($row)) {
         return null;
     }
     $template = new \Template();
     $template->setModuleTemplate('filecabinet', 'FC_Forms/document_view.html');
     $template->add('title', $row['title']);
     $template->add('filepath', './filecabinet/' . $row['id']);
     return $template->get();
 }
Example #9
0
 public static function execute()
 {
     session_start();
     PHPWS_Core::initModClass('hms', 'Term.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('users', 'Users.php');
     PHPWS_Core::initModClass('users', 'Current_User.php');
     PHPWS_Core::initModClass('hms', 'UserStatus.php');
     $errors = null;
     $term = Term::getSelectedTerm();
     $db1 = Database::newDB();
     $t1 = $db1->addTable('hms_new_application');
     $t1->addFieldConditional('term', $term);
     $t1->addField('username');
     $db2 = Database::newDB();
     $t2 = $db2->addTable('hms_assignment');
     $t2->addFieldConditional('term', $term);
     $t2->addField('asu_username');
     $union = new \Database\Union(array($db1, $db2));
     $result = $union->select();
     if (empty($result)) {
         return 'No assignments or applications. Check your database.';
     }
     $count = 0;
     $error_count = 0;
     $_SESSION['User'] = new PHPWS_User();
     $_SESSION['User']->username = '******';
     $_SESSION['User']->display_name = 'Nightly Cache';
     foreach ($result as $row) {
         $count++;
         try {
             //asking for the student updates the cache since the ttl is zero
             StudentFactory::getStudentByUsername($row['username'], $term);
         } catch (Exception $e) {
             $errors[] = $e->getMessage() . "\n";
             $error_count++;
         }
         if ($error_count >= HMS_CACHE_ERROR_THRESHOLD) {
             throw new \Exception(HMS_CACHE_ERROR_THRESHOLD . ' errors occurred. Shutting down cache prematurely.');
         }
     }
     $message = "{$count} student records cached.\n";
     if (!empty($errors)) {
         $message .= "Errors occurred:\n";
         $message .= implode("\n", $errors);
     }
     return $message;
 }
Example #10
0
 public function printFile($id)
 {
     $db = \Database::newDB();
     $t = $db->addTable('images');
     $t->addFieldConditional('id', (int) $id);
     $row = $db->selectOneRow();
     if (empty($row)) {
         return null;
     }
     $template = new \Template();
     $template->setModuleTemplate('filecabinet', 'FC_Forms/image_view.html');
     $template->add('title', $row['title']);
     $template->add('alt', $row['alt']);
     $template->add('filepath', $row['file_directory'] . $row['file_name']);
     return $template->get();
 }
Example #11
0
 public function printFile($id)
 {
     $db = \Database::newDB();
     $t = $db->addTable('multimedia');
     $t->addFieldConditional('id', (int) $id);
     $row = $db->selectOneRow();
     if (empty($row)) {
         return null;
     }
     $ext = \PHPWS_File::getFileExtension($row['file_name']);
     if ($ext == 'mp3') {
         $template = 'filters/audio.tpl';
     } else {
         $template = 'filters/media.tpl';
     }
     return \PHPWS_Template::process(array('FILE_PATH' => $row['file_directory'] . $row['file_name']), 'filecabinet', $template);
 }
 /**
  * Searches for suggestions based on username. If an exact match is found, then return
  * a student object. Otherwise return false.
  */
 private function userNameSearch($string)
 {
     $db = \Database::newDB();
     $pdo = $db->getPDO();
     $stmt = $pdo->prepare("SELECT * FROM intern_student_autocomplete WHERE username = :username");
     $stmt->execute(array('username' => $string));
     $result = $stmt->fetch(\PDO::FETCH_ASSOC);
     if ($result === false) {
         return false;
     }
     $students = array();
     try {
         $students = $this->studentIdSearch($result['banner_id']);
     } catch (\Intern\Exception\StudentNotFoundException $e) {
         // Skip any students that are returned from the database, but don't exist
         // in the student info web service
     }
     return $students;
 }
Example #13
0
/**
 * @license http://opensource.org/licenses/lgpl-3.0.html
 * @author Matthew McNaney <mcnaney at gmail dot com>
 */
function pulse_install(&$content)
{
    $db = Database::newDB();
    $db->begin();
    try {
        $pulse = new \pulse\PulseSchedule();
        $st = $pulse->createTable($db);
    } catch (\Exception $e) {
        $error_query = $pulse->createQuery();
        if (isset($st) && $db->tableExists($st->getName())) {
            $st->drop();
        }
        $content[] = 'Query:' . $error_query;
        $db->rollback();
        throw $e;
    }
    $db->commit();
    $content[] = 'Tables created';
    return true;
}
Example #14
0
 protected function loadSiteModules()
 {
     $db = Database::newDB();
     $mods = $db->addTable('modules');
     $mods->addOrderBy($mods->getField('priority'));
     $db->loadSelectStatement();
     while ($row = $db->fetch()) {
         $row = array_map('trim', $row);
         if (is_file(PHPWS_SOURCE_DIR . 'mod/' . $row['title'] . '/Module.php')) {
             $module = $this->loadModule($row);
         } else {
             $module = $this->loadCompatibilityModule($row);
         }
         $this->addModule($module);
     }
     if (count($this->getActiveModules()) == 0) {
         // @todo better exceptions
         throw new \Exception(t('No active modules installed'));
     }
 }
Example #15
0
/**
 *
 * @author Matthew McNaney <mcnaney at gmail dot com>
 * @package Global
 * @license http://opensource.org/licenses/lgpl-3.0.html
 */
function update_core_2_3_0()
{
    $db = Database::newDB();
    $dtable = $db->addTable('modules');
    if (!$dtable->columnExists('deprecated')) {
        $deprecated = $dtable->addDataType('deprecated', 'smallint');
        $deprecated->setDefault(1);
        $deprecated->add();
    }
    $db2 = Database::newDB();
    $db2->addTable('mod_settings');
    $result = $db2->select();
    if (!empty($result)) {
        Settings::createSettingsTable();
        $db3 = \Database::newDB();
        $settings = $db3->addTable('settings');
        $db3->delete();
        foreach ($result as $v) {
            $module = $setting_name = $setting_type = $small_num = $large_num = $small_char = $large_char = null;
            extract($v);
            $settings->addValue('module_name', $module);
            $settings->addValue('variable_name', $setting_name);
            switch ($setting_type) {
                case 1:
                    $settings->addValue('setting', $small_num);
                    break;
                case 2:
                    $settings->addValue('setting', $large_num);
                    break;
                case 3:
                    $settings->addValue('setting', $small_char);
                    break;
                case 4:
                    $settings->addValue('setting', $large_char);
                    break;
            }
            $settings->insert();
            $settings->resetValues();
        }
    }
}
Example #16
0
/**
 * Description
 * @author Jeff Tickle <jtickle at tux dot appstate dot edu>
 */
function pulse_update(&$content, $currentVersion)
{
    switch ($currentVersion) {
        case version_compare($currentVersion, '1.9.1', '<'):
            if (PHPWS_Error::logIfError(PHPWS_DB::dropTable('pulse_schedule'))) {
                $content[] = 'Could not drop pulse_schedule table.';
                return;
            }
            $result = PHPWS_DB::importFile(PHPWS_SOURCE_DIR . 'mod/pulse/boost/install.sql');
            if (PHPWS_Error::logIfError($result)) {
                $content[] = 'Could not run install.sql.';
                return;
            }
            $content[] = '<pre>Replaced pulse_schedule table</pre>';
        case version_compare($currentVersion, '2.0.0', '<'):
            if (PHPWS_Error::logIfError(PHPWS_DB::dropTable('pulse_schedule'))) {
                $content[] = 'Could not drop pulse_schedule table.';
                return;
            }
            $db = Database::newDB();
            $db->begin();
            try {
                $pulse = new \pulse\PulseSchedule();
                $st = $pulse->createTable($db);
            } catch (\Exception $e) {
                $error_query = $pulse->createQuery();
                if (isset($st) && $db->tableExists($st->getName())) {
                    $st->drop();
                }
                $content[] = 'Query:' . $error_query;
                $db->rollback();
                throw $e;
            }
            $db->commit();
            $content[] = 'New Pulse Schedule table created. ALL OLD SCHEDULES HAVE BEEN REMOVED!';
    }
    return TRUE;
}
Example #17
0
 protected function getJsonView($data, \Request $request)
 {
     $db = \Database::newDB();
     $sd = $db->addTable('systems_device');
     $conditional = $this->createSearchConditional($db);
     if (!empty($conditional)) {
         $db->addConditional($conditional);
     }
     $dbpager = new \DatabasePager($db);
     $dbpager->setHeaders(array('physical_id' => 'Physical ID', 'department_id' => 'Department', 'location_id' => 'Location', 'model' => 'Model', 'room_number' => 'Room Number', 'username' => 'Username', 'purchase_date' => 'Purchase Date'));
     $tbl_headers['physical_id'] = $sd->getField('physical_id');
     $tbl_headers['department_id'] = $sd->getField('department_id');
     $tbl_headers['location_id'] = $sd->getField('location_id');
     $tbl_headers['model'] = $sd->getField('model');
     $tbl_headers['room_number'] = $sd->getField('room_number');
     $tbl_headers['username'] = $sd->getField('username');
     $tbl_headers['purchase_date'] = $sd->getField('purchase_date');
     $dbpager->setTableHeaders($tbl_headers);
     $dbpager->setId('device-list');
     $dbpager->setRowIdColumn('id');
     $dbpager->setCallback(array('\\systemsinventory\\Controller\\Search', 'alterSearchRow'));
     $data = $dbpager->getJson();
     return parent::getJsonView($data, $request);
 }
Example #18
0
/**
 * @author Matthew McNaney <mcnaney at gmail dot com>
 * @version $Id$
 */
function layout_update(&$content, $currentVersion)
{
    switch ($currentVersion) {
        case version_compare($currentVersion, '2.2.0', '<'):
            $content[] = 'This package will not update versions under 2.2.0.';
            return false;
        case version_compare($currentVersion, '2.2.1', '<'):
            $content[] = '+ Fixed improper sql call in update_220.sql file.';
        case version_compare($currentVersion, '2.3.0', '<'):
            $content[] = '<pre>';
            if (PHPWS_Boost::updateFiles(array('conf/config.php', 'conf/error.php'), 'layout')) {
                $content[] = 'Updated conf/config.php and conf/error.php file.';
            } else {
                $content[] = 'Unable to update conf/config.php and conf/error.php file.';
            }
            $content[] = '
2.3.0 changes
-------------
+ Removed references from object constructors.
+ Added the plug function to allow users to inject content directly
  into a theme.
+ Added translate functions.
+ Layout now looks for and includes a theme\'s theme.php file.
+ Fixed unauthorized access.
+ Added XML mode to config.php file. Puts Layout in XHTML+XML content mode.
+ Added missing media parameters to XML mode.
</pre>';
        case version_compare($currentVersion, '2.4.0', '<'):
            $files = array('img/layout.png', 'templates/no_cookie.tpl');
            $content[] = '<pre>';
            if (PHPWS_Boost::updateFiles($files, 'layout')) {
                $content[] = '--- Successfully updated the following files:';
            } else {
                $content[] = '--- Was unable to copy the following files:';
            }
            $content[] = '     ' . implode("\n     ", $files);
            $content[] = '
2.4.0 changes
-------------
+ Layout now checks and forces a user to enable cookies on their
  browser.
+ Rewrote Javascript detection. Was buggy before as session
  destruction could disrupt it.
+ Added German translations
+ Updated language functions
+ Fixed: bug in Layout confused a user\'s style sheet settings after
  the theme was changed.
+ Rewrote theme change code.
+ Added ability to force theme on layout settings construction.
+ Changed Control Panel icon
</pre>';
        case version_compare($currentVersion, '2.4.1', '<'):
            $files = array('conf/config.php');
            $content[] = '<pre>';
            if (PHPWS_Boost::updateFiles($files, 'layout')) {
                $content[] = '--- Successfully updated the following files:';
            } else {
                $content[] = '--- Was unable to copy the following files:';
            }
            $content[] = '     ' . implode("\n     ", $files);
            $content[] = '
2.4.1 changes
-------------
+ Bug #1741111 - Fixed moving a top box up and a bottom box down.
+ The cookie check is not determined by a define in the config file.
+ The cookie check was interfering with the rss feed. Cut off the page
  too quickly. Moved cookie check to the close.php file.
</pre>';
        case version_compare($currentVersion, '2.4.2', '<'):
            $content[] = '<pre>';
            $files = array('templates/arrange.tpl', 'conf/error.php', 'templates/move_box_select.tpl');
            layoutUpdateFiles($files, $content);
            if (!PHPWS_Boost::inBranch()) {
                $content[] = file_get_contents(PHPWS_SOURCE_DIR . 'mod/layout/boost/changes/2_4_2.txt');
            }
            $content[] = '</pre>';
        case version_compare($currentVersion, '2.4.3', '<'):
            $content[] = '<pre>2.4.3 changes
-----------------
+ nakedDisplay now allows a choice whether to use the blank template
  or not when it wraps. Default is to not.
+ Fixed noCache.
</pre>';
        case version_compare($currentVersion, '2.4.4', '<'):
            $content[] = '<pre>';
            $db = new PHPWS_DB('layout_config');
            if (PHPWS_Error::logIfError($db->dropTableColumn('userAllow'))) {
                $content[] = '--- An error occurred when trying to drop the userAllow column from the layout_config table.';
            } else {
                $content[] = '--- Dropped the userAllow column from the layout_config table.';
            }
            layoutUpdateFiles(array('templates/user_form.tpl'), $content);
            $content[] = '2.4.4 changes
-------------------
+ Dropped unused column from config table.
+ Added collapse function. Adds id="layout-collapse" to theme template
  under the {COLLAPSE} tag.
+ Changed method of checking for javascript status. Less chance for
  error.
+ Fixed notice.</pre>';
        case version_compare($currentVersion, '2.4.5', '<'):
            $content[] = '<pre>';
            $db = new PHPWS_DB('layout_config');
            if (PHPWS_Error::logIfError($db->addTableColumn('deity_reload', 'smallint not null default 0'))) {
                $content[] = 'Could not create layout_config.deity_reload column.';
                return false;
            } else {
                $content[] = 'Added layout_config.deity_reload column.';
            }
            layoutUpdateFiles(array('templates/metatags.tpl', 'conf/config.php'), $content);
            $content[] = '2.4.5 changes
--------------------
+ Added option to use a Key\'s summary or title to fill in the meta
  description.
+ Added new cacheHeader function to retain javascript and css
  information should a module return cached content before the above
  can be established.
+ Deities can now move a box to a theme locked area.
+ Added LAYOUT_IGNORE_JS_CHECK to force javascript use.
+ PHP 5 formatted';
        case version_compare($currentVersion, '2.4.6', '<'):
            $content[] = '<pre>2.4.6 changes
---------------------
+ Fix to cache headers
</pre>';
        case version_compare($currentVersion, '2.4.7', '<'):
            $content[] = '<pre>';
            layoutUpdateFiles(array('templates/themes.tpl'), $content);
            $content[] = '2.4.7 changes
---------------------
+ Added option to layout theme tab to disable or order module style
  sheet inclusion.
+ Can enable box move from mini admin
</pre>';
        case version_compare($currentVersion, '2.4.8', '<'):
            $content[] = '<pre>2.4.8 changes
---------------------
+ Bug#2424256 - Removed browser check to use @import on style sheets.
</pre>';
        case version_compare($currentVersion, '2.5.0', '<'):
            $content[] = '<pre>2.5.0 changes
---------------------
+ Icon class used.
+ Change of template directories to conform with core hub/branch change.
+ PHP 5 strict fixes.
+ New javascript detection method.
+ Default theme is now simple.
+ Allow admin to use hub or local themes.
</pre>';
        case version_compare($currentVersion, '2.5.1', '<'):
            $content[] = '<pre>2.5.1 changes
---------------------
+ Eloi George javascript patch applied
</pre>';
        case version_compare($currentVersion, '2.5.2', '<'):
            $content[] = '<pre>2.5.2 changes
---------------------
+ Eloi George templating patch added.
+ Fixed silent javascript failure.
</pre>';
        case version_compare($currentVersion, '2.5.3', '<'):
            $content[] = '<pre>2.5.3 changes
---------------------
+ Added HTTP tag for theming. Assists with http vs https
+ HOME_URL also added for theming.
</pre>';
        case version_compare($currentVersion, '2.5.4', '<'):
            $content[] = '<pre>2.5.4 changes
---------------------
+ Static notice corrected.
+ Page title can be changed from miniadmin
</pre>';
        case version_compare($currentVersion, '2.5.5', '<'):
            require_once PHPWS_SOURCE_DIR . 'mod/users/class/My_Page.php';
            My_Page::unregisterMyPage('layout');
            $content[] = '<pre>2.5.5 changes
---------------------
+ Unregister My Page
</pre>';
        case version_compare($currentVersion, '2.6.0', '<'):
            $content[] = <<<EOF
<pre>2.6.0 changes
--------------------
+ Removed Layout\\'s caching code.
+ Fixed layout's problem with locked content variables.
+ Fixed: Content without a content_var was overwriting previously unlabeled content.
+ Added Layout method includeJavascript. Shortcut for script inclusion over addJSHeader.
+ Added Font Awesome icons.
+ Reworded box move command in miniadmin.
+ Removed deprecated ckeditor function.
</pre>
EOF;
        case version_compare($currentVersion, '2.6.1', '<'):
            $content[] = <<<EOF
<pre>2.6.1 changes
--------------------
+ Added THEME_HTTP to the Layout wrap function.
</pre>
EOF;
        case version_compare($currentVersion, '2.7.0', '<'):
            if (PHPWS_Core::moduleExists('block')) {
                $db = Database::newDB();
                $t = $db->addTable('layout_config');
                $t->addField('header');
                $t->addField('footer');
                $config_result = $db->selectOneRow();
                if (!empty($config_result['header'])) {
                    $header_block = new Block_Item();
                    $header_block->title = 'Layout header';
                    $header_block->content = $_SESSION['Layout_Settings']->header;
                    $header_block->hide_title = true;
                    $header_block->save();
                }
                if (!empty($config_result['footer'])) {
                    $footer_block = new Block_Item();
                    $footer_block->title = 'Layout footer';
                    $footer_block->content = $_SESSION['Layout_Settings']->footer;
                    $footer_block->hide_title = true;
                    $footer_block->save();
                }
            }
            $content[] = <<<EOF
<pre>2.7.0 changes
--------------------
+ Removed header and footer. Moved data to Blocks.
+ Fixed some admin forms
</pre>
EOF;
    }
    return true;
}
Example #19
0
/**
 * @author Matthew McNaney
 * @version $Id$
 */
function filecabinet_update(&$content, $version)
{
    $home_dir = PHPWS_Boost::getHomeDir();
    switch ($version) {
        case version_compare($version, '1.0.1', '<'):
            $content[] = '<pre>File Cabinet versions prior to 1.0.1 are not supported.
Please download version 1.0.2.</pre>';
            break;
        case version_compare($version, '1.0.2', '<'):
            $content[] = '<pre>';
            $db = new PHPWS_DB('folders');
            if (!$db->isTableColumn('key_id')) {
                if (PHPWS_Error::logIfError($db->addTableColumn('key_id', 'int NOT NULL default 0'))) {
                    $content[] = '--- An error occurred when trying to add key_id as a column to the folders table.</pre>';
                    return false;
                }
                $content[] = '--- Successfully added key_id column to folders table.';
                $db2 = new PHPWS_DB('phpws_key');
                $db2->addWhere('module', 'filecabinet');
                $db2->delete();
                $content[] = '--- Deleted false folder keys.';
                $db->reset();
                PHPWS_Core::initModClass('filecabinet', 'Folder.php');
                $result = $db->getObjects('Folder');
                if (!empty($result)) {
                    foreach ($result as $folder) {
                        $folder->saveKey(true);
                    }
                }
            }
            $content[] = '
1.0.2 changes
--------------
+ 1.0.0 update was missing key_id column addition to folders table.
</pre>';
        case version_compare($version, '1.1.0', '<'):
            $content[] = '<pre>';
            if (!checkMultimediaDir($content, $home_dir)) {
                return false;
            }
            if (!is_dir($home_dir . 'files/filecabinet/incoming')) {
                if (is_writable($home_dir . 'files/filecabinet') && @mkdir($home_dir . 'files/filecabinet/incoming')) {
                    $content[] = '--- "files/filecabinet/incoming" directory created.';
                } else {
                    $content[] = 'File Cabinet 1.1.0 is unable to create a "filecabinet/incoming" directory.
It is not required but if you want to classify files you will need to create it yourself.
Example: mkdir phpwebsite/files/filecabinet/incoming/</pre>';
                    return false;
                }
            }
            $source_dir = PHPWS_SOURCE_DIR . 'mod/filecabinet/templates/filters/';
            $dest_dir = $home_dir . 'templates/filecabinet/filters/';
            if (!is_dir($dest_dir)) {
                if (!PHPWS_File::copy_directory($source_dir, $dest_dir)) {
                    $content[] = '--- FAILED copying templates/filters/ directory locally.</pre>';
                    return false;
                }
            }
            $files = array('templates/manager/pick.tpl', 'templates/classify_file.tpl', 'templates/classify_list.tpl', 'templates/image_edit.tpl', 'templates/multimedia_edit.tpl', 'templates/multimedia_grid.tpl', 'templates/style.css', 'templates/settings.tpl', 'conf/config.php');
            if (PHPWS_Boost::updateFiles($files, 'filecabinet')) {
                $content[] = '--- Copied the following files:';
            } else {
                $content[] = '--- FAILED copying the following files:';
            }
            $content[] = "    " . implode("\n    ", $files);
            $db = new PHPWS_DB('images');
            if (!$db->isTableColumn('parent_id')) {
                if (PHPWS_Error::logIfError($db->addTableColumn('parent_id', 'int NOT NULL default 0'))) {
                    $content[] = 'Could not create parent_id column in images table.</pre>';
                    return false;
                }
            }
            if (!$db->isTableColumn('url')) {
                if (PHPWS_Error::logIfError($db->addTableColumn('url', 'varchar(255) NULL'))) {
                    $content[] = 'Could not create url column in images table.</pre>';
                    return false;
                }
            }
            if (!PHPWS_DB::isTable('multimedia')) {
                $result = PHPWS_DB::importFile(PHPWS_SOURCE_DIR . 'mod/filecabinet/boost/multimedia.sql');
                if (!PHPWS_Error::logIfError($result)) {
                    $content[] = '--- Multimedia table created successfully.';
                } else {
                    $content[] = '--- Failed to create multimedia table.</pre>';
                    return false;
                }
            }
            $content[] = '
1.1.0 changes
--------------
+ Fixed authorized check when unpinning folders
+ Images can now be linked to other pages.
+ Resized images can now be linked to their parent image.
+ Clip option moved outside edit_folder permissions when viewing images.
+ Added writable directory check before allowing new folders to be
  created.
+ Fixed some error messages in File_Common.
+ Commented out ext variable in File_Common. Doesn\'t appear to be in
  use.
+ Created setDirectory function for File_Common. Assures trailing
  forward slash on directory name.
+ Removed itemname variable from Document_Manager
+ Added ability to classify uploaded files.
+ New folder class - Multimedia
+ Multimedia files can be clipped and pasted via SmartTags.
</pre>
';
        case version_compare($version, '1.2.0', '<'):
            $content[] = '<pre>';
            $files = array('img/no_image.png', 'conf/config.php', 'conf/video_types.php', 'conf/embedded.php', 'javascript/folder_contents/head.js', 'javascript/clear_image/head.js', 'javascript/clear_image/body.js', 'javascript/pick_image/head.js', 'templates/image_folders.tpl', 'templates/settings.tpl', 'templates/style.css', 'templates/image_view.tpl', 'templates/multimedia_view.tpl', 'templates/style.css', 'img/video_generic.png', 'templates/image_edit.tpl', 'conf/error.php');
            fc_updatefiles($files, $content);
            if (!PHPWS_Boost::inBranch()) {
                $content[] = file_get_contents(PHPWS_SOURCE_DIR . 'mod/filecabinet/boost/changes/1_2_0.txt');
            }
            $content[] = '</pre>';
        case version_compare($version, '1.2.1', '<'):
            $content[] = '<pre>';
            if (!PHPWS_DB::isTable('filecabinet_pins')) {
                $db = new PHPWS_DB('filecabinet_pins');
                $db->addValue('key_id', 'int not null default 0');
                $db->addValue('folder_id', 'int not null default 0');
                if (PHPWS_Error::logIfError($db->createTable())) {
                    $content[] = 'Failed to create filecabinet_pins table.</pre>';
                    return false;
                }
                $content[] = '--- Created filecabinet_pins table.';
            }
            $files = array('templates/settings.tpl');
            fc_updatefiles($files, $content);
            if (!PHPWS_Boost::inBranch()) {
                $content[] = file_get_contents(PHPWS_SOURCE_DIR . 'mod/filecabinet/boost/changes/1_2_1.txt');
            }
            $content[] = '</pre>';
        case version_compare($version, '1.2.2', '<'):
            $content[] = '<pre>';
            $files = array('templates/image_edit.tpl');
            fc_updatefiles($files, $content);
            if (!PHPWS_Boost::inBranch()) {
                $content[] = file_get_contents(PHPWS_SOURCE_DIR . 'mod/filecabinet/boost/changes/1_2_2.txt');
            }
            $content[] = '</pre>';
        case version_compare($version, '1.3.0', '<'):
            $content[] = '<pre>';
            $db = new PHPWS_DB('folders');
            if (!$db->isTableColumn('module_created')) {
                if (PHPWS_Error::logIfError($db->addTableColumn('module_created', 'varchar(40) default null'))) {
                    $content[] = '--- Could not create column module_created on folders table.</pre>';
                    return false;
                } else {
                    $content[] = '--- Created module_created column on folders table.';
                }
            }
            $db = new PHPWS_DB('multimedia');
            $result = $db->addTableColumn('thumbnail', 'varchar(255) not null');
            if (PHPWS_Error::logIfError($result)) {
                $content[] = '--- Unable to add thumbnail column to multimedia table.</pre>';
                return false;
            } else {
                $content[] = '--- Added thumbnail column to multimedia table.';
            }
            $s1 = PHPWS_SOURCE_DIR . 'mod/filecabinet/templates/filters/flash/';
            $d1 = $home_dir . 'templates/filecabinet/filters/flash/';
            $s2 = PHPWS_SOURCE_DIR . 'mod/filecabinet/img/icons/';
            $d2 = $home_dir . 'images/mod/filecabinet/icons/';
            if (PHPWS_File::copy_directory($s1, $d1)) {
                $content[] = "--- Successfully copied {$s1} to {$d1}";
            } else {
                $content[] = "--- Failed to copy {$s1} to {$d1}</pre>";
                return false;
            }
            if (PHPWS_File::copy_directory($s2, $d2)) {
                $content[] = "--- Successfully copied {$s2} to {$d2}";
            } else {
                $content[] = "--- Failed to copy {$s2} to {$d2}</pre>";
                return false;
            }
            $content[] = '';
            $files = array('conf/error.php', 'conf/config.php', 'templates/filters/flash.tpl', 'templates/file_list.tpl', 'templates/multimedia_edit.tpl', 'templates/settings.tpl', 'templates/style.css', 'templates/thumbnail.tpl', 'templates/image_edit.tpl', 'javascript/pick_image/head.js', 'templates/folder_list.tpl', 'templates/manager/pick.tpl', 'img/delete.png');
            fc_updatefiles($files, $content);
            if (!PHPWS_Boost::inBranch()) {
                $content[] = file_get_contents(PHPWS_SOURCE_DIR . 'mod/filecabinet/boost/changes/1_3_0.txt');
            }
            $content[] = '</pre>';
        case version_compare($version, '1.4.0', '<'):
            $content[] = '<pre>';
            $files = array('javascript/folder_contents/head.js', 'javascript/folder_contents/scripts.js', 'javascript/pick_image/head.js', 'javascript/pick_image/scripts.js', 'javascript/clear_image/body.js', 'javascript/clear_image/head.js', 'templates/style.css', 'templates/settings.tpl');
            fc_updatefiles($files, $content);
            if (!PHPWS_Boost::inBranch()) {
                $content[] = file_get_contents(PHPWS_SOURCE_DIR . 'mod/filecabinet/boost/changes/1_4_0.txt');
            }
            $content[] = '</pre>';
        case version_compare($version, '1.4.1', '<'):
            $content[] = '<pre>';
            $db = new PHPWS_DB('folders');
            if (!$db->isTableColumn('module_created')) {
                if (PHPWS_Error::logIfError($db->addTableColumn('module_created', 'varchar(40) default null'))) {
                    $content[] = '--- Could not create column module_created on folders table.</pre>';
                    return false;
                } else {
                    $content[] = '--- Created module_created column on folders table.';
                }
            }
            $content[] = '1.4.1 changes
--------------
+ module_created column missing from > 1.3.0 install.
</pre>';
        case version_compare($version, '1.4.2', '<'):
            $content[] = '<pre>
1.4.2 changes
--------------
+ Removed test echo 1
+ moved all defines to one file.
</pre>';
        case version_compare($version, '2.0.0', '<'):
            $content[] = '<pre>';
            if (PHPWS_File::copy_directory(PHPWS_SOURCE_DIR . 'mod/filecabinet/templates/', $home_dir . 'templates/filecabinet/')) {
                $content[] = '--- Copied complete templates directory.';
            } else {
                $content[] = '--- Could not copy complete templates directory. Use revert or copy manually.';
            }
            if (PHPWS_File::copy_directory(PHPWS_SOURCE_DIR . 'mod/filecabinet/img/', $home_dir . 'images/mod/filecabinet/')) {
                $content[] = '--- Copied complete images directory.';
            } else {
                $content[] = '--- Could not copy complete images directory. Use revert or copy manually.';
            }
            if (PHPWS_File::copy_directory(PHPWS_SOURCE_DIR . 'mod/filecabinet/conf/', $home_dir . 'config/filecabinet/')) {
                $content[] = '--- Copied complete configuration directory.';
            } else {
                $content[] = '--- Could not copy complete configuration directory. Use revert or copy manually.';
            }
            if (PHPWS_File::copy_directory(PHPWS_SOURCE_DIR . 'mod/filecabinet/javascript/', $home_dir . 'javascript/modules/filecabinet/')) {
                $content[] = '--- Copied complete javascript directory.';
            } else {
                $content[] = '--- Could not copy complete javascript directory. Use revert or copy manually.';
            }
            if (!PHPWS_DB::isTable('fc_convert')) {
                $result = PHPWS_DB::importFile(PHPWS_SOURCE_DIR . 'mod/filecabinet/boost/fc_convert.sql');
                if (!PHPWS_Error::logIfError($result)) {
                    $content[] = '--- File conversion table created successfully.';
                } else {
                    $content[] = '--- Failed to create File conversion table.</pre>';
                    return false;
                }
            }
            if (!PHPWS_DB::isTable('fc_file_assoc')) {
                $result = PHPWS_DB::importFile(PHPWS_SOURCE_DIR . 'mod/filecabinet/boost/file_assoc.sql');
                if (!PHPWS_Error::logIfError($result)) {
                    $content[] = '--- File assoc table created successfully.';
                } else {
                    $content[] = '--- Failed to create File assoc table.</pre>';
                    return false;
                }
            }
            $db = new PHPWS_DB('multimedia');
            if (!$db->isTableColumn('duration')) {
                if (PHPWS_Error::logIfError($db->addTableColumn('duration', 'int not null default 0'))) {
                    $content[] = '--- Failed to create duration column on multimedia table.</pre>';
                    return false;
                } else {
                    $content[] = '--- Created duration column on multimedia table.';
                }
            }
            if (!$db->isTableColumn('embedded')) {
                if (PHPWS_Error::logIfError($db->addTableColumn('embedded', 'smallint not null default 0'))) {
                    $content[] = 'Failed to create embedded column on multimedia table.</pre>';
                    return false;
                } else {
                    $content[] = '--- Created embedded column on multimedia table.';
                }
            }
            PHPWS_Core::initModClass('filecabinet', 'Multimedia.php');
            $result = $db->getObjects('PHPWS_Multimedia');
            if ($result) {
                foreach ($result as $mm) {
                    $mm->loadDimensions();
                    PHPWS_Error::logIfError($mm->save());
                }
            }
            $content[] = '--- Durations added to multimedia files.';
            fc_update_parent_links();
            if (!checkMultimediaDir($content, $home_dir)) {
                return false;
            }
            if (!PHPWS_Boost::inBranch()) {
                $content[] = file_get_contents(PHPWS_SOURCE_DIR . 'mod/filecabinet/boost/changes/2_0_0.txt');
            }
            $content[] = '</pre>';
        case version_compare($version, '2.0.1', '<'):
            $content[] = '<pre>2.0.1 changes
-------------
+ Updated youTube import.
+ Removed unused code.</pre>';
        case version_compare($version, '2.1.0', '<'):
            $content[] = '<pre>';
            $files = array('templates/image_view.tpl', 'templates/settings.tpl', 'javascript/pick_file/head.js', 'javascript/pick_file/scripts.js', 'javascript/update_file/head.js', 'templates/file_manager/placeholder.tpl', 'templates/document_edit.tpl', 'templates/image_edit.tpl', 'templates/multimedia_edit.tpl', 'templates/edit_folder.tpl', 'templates/embed_edit.tpl', 'templates/style.css', 'templates/file_manager/folder_content_view.tpl', 'templates/file_manager/resize.tpl');
            fc_updatefiles($files, $content);
            $db = new PHPWS_DB('folders');
            $db->begin();
            if (PHPWS_Error::logIfError($db->addTableColumn('max_image_dimension', 'smallint  not null default 0'))) {
                $content[] = '--- Unable to add max_image_dimension column to folders table.';
                $db->rollback();
                return false;
            } else {
                $content[] = '--- Added max_image_dimension column to folders table.';
            }
            $db = new PHPWS_DB('fc_file_assoc');
            if (PHPWS_Error::logIfError($db->addTableColumn('width', 'smallint NOT NULL default 0'))) {
                $content[] = '--- Unable to add width column to fc_file_assoc.';
                $db->rollback();
                return false;
            } else {
                $content[] = '--- Added width column to fc_file_assoc table';
            }
            if (PHPWS_Error::logIfError($db->addTableColumn('height', 'smallint NOT NULL default 0'))) {
                $content[] = '--- Unable to add height column to fc_file_assoc.';
                $db->rollback();
                return false;
            } else {
                $content[] = '--- Added height column to fc_file_assoc table';
            }
            if (PHPWS_Error::logIfError($db->addTableColumn('cropped', 'smallint NOT NULL default 0'))) {
                $content[] = '--- Unable to add cropped column to fc_file_assoc.';
                $db->rollback();
                return false;
            } else {
                $content[] = '--- Added cropped column to fc_file_assoc table';
            }
            $db->commit();
            if (!PHPWS_Boost::inBranch()) {
                $content[] = file_get_contents(PHPWS_SOURCE_DIR . 'mod/filecabinet/boost/changes/2_1_0.txt');
            }
            $content[] = '</pre>';
        case version_compare($version, '2.2.0', '<'):
            $content[] = '<pre>';
            $db = new PHPWS_DB('fc_file_assoc');
            if (PHPWS_Error::logIfError($db->addTableColumn('vertical', 'smallint not null default 0'))) {
                $content[] = 'Unable to create vertical column in fc_file_assoc table.';
                return false;
            }
            if (PHPWS_Error::logIfError($db->addTableColumn('num_visible', 'smallint not null default 3'))) {
                $content[] = 'Unable to create num_visible column in fc_file_assoc table.';
                return false;
            }
            $db->dropTableColumn('cropped');
            $db = new PHPWS_DB('modules');
            $db->addWhere('title', 'filecabinet');
            $db->addValue('unregister', 1);
            PHPWS_Error::logIfError($db->update());
            $content[] = 'Unregister flag set in modules table.';
            $files = array('javascript/jcaro_lite/', 'javascript/shutter/', 'javascript/pick_file/', 'javascript/update_file/head.js', 'javascript/update_file/default.php', 'javascript/clear_file/body.js', 'javascript/clear_file/head.js', 'javascript/clear_file/default.php', 'templates/image_view.tpl', 'templates/carousel_horz.tpl', 'templates/carousel_vert.tpl', 'templates/classify_list.tpl', 'templates/ss_box.tpl', 'templates/file_manager/carousel_pick.tpl', 'templates/file_manager/folder_content_view.tpl', 'templates/settings.tpl', 'templates/style.css', 'templates/file_list.tpl', 'templates/folder_list.tpl', 'templates/pinned.tpl', 'img/add.png', 'img/arrow_left.png', 'img/arrow_right.png', 'conf/icons.php', 'conf/config.php');
            fc_updatefiles($files, $content);
            if (!PHPWS_Boost::inBranch()) {
                $content[] = file_get_contents(PHPWS_SOURCE_DIR . 'mod/filecabinet/boost/changes/2_2_0.txt');
            }
        case version_compare($version, '2.2.1', '<'):
            $content[] = '<pre>
2.2.1 changes
-----------------------
+ Fixed folder deletion.
+ Clipped documents and images now have full pathing.
+ Fixed document smarttag</pre>';
        case version_compare($version, '2.2.2', '<'):
            $content[] = '<pre>';
            $files = array('img/mime_types/', 'templates/document_download.tpl', 'templates/file_view.css', 'templates/multi_doc_download.tpl');
            fc_updatefiles($files, $content);
            $content[] = '2.2.2 changes
-----------------------
+ Fixed edit icon in document view. Needed to be salted.
+ Added error check to prevent possible divide by zero error.
+ Resized mime type icons
+ Changed the document download windows. Simplified.
+ Fixed image edit link.
+ Added pptm to known types.
+ Fixed permission checks on folders.</pre>';
        case version_compare($version, '2.2.3', '<'):
            $content[] = '<pre>2.2.3 changes
-----------------------
+ Fixed document delete link</pre>';
        case version_compare($version, '2.2.4', '<'):
            $content[] = '<pre>';
            $files = array('templates/fckeditor.tpl', 'templates/fckdocuments.tpl', 'templates/fck.css', 'templates/fckimages.tpl', 'templates/fckfolders.tpl', 'templates/folder_list.tpl', 'templates/settings.tpl', 'img/folder.gif', 'javascript/fckeditor/');
            fc_updatefiles($files, $content);
            $content[] = '2.2.4 changes
-----------------------
+ Error checking added to document upload.
+ Fixed multimedia folder pager.
+ Added method for fixing document directories.
+ Added file search to folder pager.
+ Added File Cabinet FCKeditor interaction.
+ Cleaned up so interface issues.
</pre>';
        case version_compare($version, '2.2.5', '<'):
            $content[] = '<pre>2.2.5 changes
-----------------------
+ Fixed bug that displayed error message on document upload.
+ Proper error message now on document uploaded to unwritable
  directory
+ Directory check on unwritable directory prevents upload link</pre>';
        case version_compare($version, '2.2.6', '<'):
            $content[] = '<pre>';
            $files = array('javascript/fckeditor/head.js', 'templates/fck.css');
            fc_updatefiles($files, $content);
            $content[] = '2.2.6 changes
-----------------------
+ Fixed bug with editing Multimedia.
+ Fixed bug with File Cabinet in FCKeditor not loading folders properly.
</pre>';
        case version_compare($version, '2.2.7', '<'):
            $content[] = '<pre>';
            $files = array('javascript/fckeditor/head.js', 'templates/filters/media/mediaplayer.swf', 'templates/filters/media/yt.swf');
            fc_updatefiles($files, $content);
            $content[] = '2.2.7 changes
-----------------------
+ Added trim to ffmpeg file directory
+ Added description to search for files
+ Media player updated to latest version.
+ FCKeditor media insertion had problems with any media other than
  YouTube embeds. SmartTag for media is displayed instead.</pre>';
        case version_compare($version, '2.3.0', '<'):
            $content[] = '<pre>2.3.0 changes
---------------------
+ Icon class implemented.
+ Video player changed to Flowplayer.
+ Lightbox option for public folders.
+ Image carousel switched to jcarousel with Lightbox usage.
+ Updated to work with core updates.</pre>';
        case version_compare($version, '2.3.1', '<'):
            $content[] = '<pre>2.3.1 changes
---------------------
+ Setting added to allow direct links to documents
+ Fixed captioned image template</pre>';
        case version_compare($version, '2.3.2', '<'):
            $content[] = '<pre>2.3.2 changes
---------------------
+ Changing public flag to private on document folders creates .htaccess file preventing world access
+ Added mp4/m4v to multimedia class.
</pre>';
        case version_compare($version, '2.4.0', '<'):
            $content[] = '<pre>2.4.0 changes
---------------------
+ Heavy ckeditor modifications.
+ rtmp support added.
+ Removed FCK code where found.
+ Minified some scripts.
+ Failed image upload will now display an error.
+ Can now add Access shortcut to a document.
+ Various bug fixes
</pre>';
        case version_compare($version, '2.4.1', '<'):
            $content[] = '<pre>2.4.1 changes
-----------------------
+ Fixed a possible XSS vulnerability discovered by Jakub Galczyk.
+ Users must have some File Cabinet permission to use the File Manager.
</pre>';
        case version_compare($version, '2.4.2', '<'):
            $content[] = '<pre>2.4.2 changes
-----------------------
+ Added error logging to image resize.
</pre>';
        case version_compare($version, '2.4.3', '<'):
            $content[] = '<pre>2.4.3 changes
-----------------------
+ Added checkbox in Settings to turn off autofloating of images in the ckeditor.
</pre>';
        case version_compare($version, '2.4.4', '<'):
            $content[] = '<pre>2.4.4 changes
-----------------------
+ Removed clipboard functionality. Confused users and was not
+ Bootstrap icons and styles added.
</pre>';
        case version_compare($version, '2.5.0', '<'):
            $content[] = '<pre>2.5.0 changes
-----------------------
+ img-responsive added to inserted images to work with Bootstrap
+ removed image widths and heights
+ Cropping and resizing removed from manager
+ Manager made larger.
+ Manager upload header fixed position
</pre>';
        case version_compare($version, '2.6.0', '<'):
            $content[] = <<<EOF
<pre>2.6.0 changes
----------------
+ Removed call to updateTag as it does not work.
+ Removed calls to Layout Cache (which was removed)
+ Updated filecabinet to work with ckeditor 4.
+ Updated ckeditor 4 filecabinet pop up layout.
+ Thumbnails of uploaded images are not shown.
</pre>
EOF;
        case version_compare($version, '2.7.0', '<'):
            $db = \Database::newDB();
            $t1 = $db->addTable('folders');
            $t1->addValue('module_created', null);
            $db->update();
            $content[] = <<<EOF
<pre>2.7.0 changes
----------------
+ Javascript windows replaced with Bootstrap modal dropdowns.
+ Fixed thumbnail form.
+ Removed module_created for all folders.
</pre>
EOF;
        case version_compare($version, '2.8.0', '<'):
            $content[] = <<<EOF
<pre>2.8.0 changes
----------------
+ Rewrote CKEditor interaction with Filecabinet. Images and documents functional,
  multimedia uploads not complete.
</pre>
EOF;
            return true;
    }
}
Example #20
0
 public static function edit(Block_Item $block, $js = FALSE)
 {
     javascript('jquery');
     javascript('ckeditor');
     $form = new PHPWS_Form('block-form');
     $form->addHidden('module', 'block');
     $form->addCheck('hide_title', 1);
     $form->setMatch('hide_title', $block->hide_title);
     $form->setLabel('hide_title', dgettext('block', 'Hide title'));
     $form->addCheck('hide_narrow', 1);
     $form->setMatch('hide_narrow', $block->hide_narrow);
     $form->setLabel('hide_narrow', dgettext('block', 'Hide when width &lt; 768px'));
     $form->addTextArea('block_content', $block->getContent(false));
     $form->setRows('block_content', '10');
     $form->setWidth('block_content', '80%');
     $form->setLabel('block_content', dgettext('block', 'Entry'));
     if ($js) {
         if (isset($_REQUEST['key_id']) && is_numeric($_REQUEST['key_id'])) {
             $key_id = (int) $_REQUEST['key_id'];
         } else {
             $key_id = 0;
         }
         $form->addHidden('key_id', $key_id);
         $form->addHidden('action', 'postJSBlock');
         $pdb = Database::newDB();
         $pdb->addTable('block_pinned');
         $all_pinned = $pdb->select();
         if (!empty($all_pinned)) {
             $pinned = new \Variable\Arr($all_pinned);
             $pinned->indexByColumn('block_id', true, 'key_id');
             $pinned_keys = $pinned->get();
         } else {
             $pinned_keys = null;
         }
         $db = Database::newDB();
         $blocks = $db->addTable('block');
         $blocks->addField('id');
         $blocks->addOrderBy($blocks->addField('title'));
         $db->loadSelectStatement();
         while ($b = $db->fetch()) {
             /**
              * Checking here to see if this block is already set for the current
              * key OR is this block is set to show everywhere. If either,
              * then don't add to select list.
              */
             if (!empty($pinned_keys)) {
                 if (isset($pinned_keys[$b['id']])) {
                     if (in_array($key_id, $pinned_keys[$b['id']]) || in_array('-1', $pinned_keys[$b['id']])) {
                         continue;
                     }
                 }
             }
             $block_options[$b['id']] = $b['title'];
         }
         if (!empty($block_options)) {
             $form->addSelect('block_list', $block_options);
             $form->addSubmit('pick_block', 'Add this block to the page');
         }
     } else {
         $form->useEditor('block_content');
         $form->addHidden('action', 'postBlock');
         if (empty($block->id)) {
             $form->addSubmit('submit', dgettext('block', 'Save New Block'));
         } else {
             $form->addHidden('block_id', $block->getId());
             $form->addSubmit('submit', dgettext('block', 'Update Current Block'));
         }
     }
     $form->addText('title', $block->getTitle());
     $form->setLabel('title', dgettext('block', 'Title'));
     $form->setSize('title', 50);
     $template = $form->getTemplate();
     if ($js) {
         if (!empty($block_options)) {
             $template['ALTERNATIVE'] = t('or create new block below');
         }
         $content = PHPWS_Template::process($template, 'block', 'js_edit.tpl');
     } else {
         $content = PHPWS_Template::process($template, 'block', 'edit.tpl');
     }
     return $content;
 }
Example #21
0
 private function deleteFile(\Request $request)
 {
     if (!Current_User::authorized('filecabinet')) {
         $this->sendErrorHeader('No permissions to delete files');
     }
     $db = \Database::newDB();
     switch ($request->getVar('ftype')) {
         case DOCUMENT_FOLDER:
             $table = $db->addTable('documents');
             break;
         case IMAGE_FOLDER:
             $table = $db->addTable('images');
             break;
         case MULTIMEDIA_FOLDER:
             $table = $db->addTable('multimedia');
             break;
     }
     $table->addFieldConditional('id', $request->getVar('id'));
     $row = $db->selectOneRow();
     $filepath = $row['file_directory'] . $row['file_name'];
     if (is_file($filepath)) {
         unlink($filepath);
     }
     $db->delete();
 }
Example #22
0
 /**
  * Removes a resource from its table.
  * @param \Resource $resource
  * @param string $table_name Not required if in Resource->table
  * @return integer Number of rows deleted.
  */
 public static function deleteResource(\Resource $resource, $table_name = null)
 {
     if (empty($table_name)) {
         $table_name = $resource->getTable();
     }
     $db = \Database::newDB();
     $tbl = $db->addTable($table_name);
     $db->addConditional($tbl->getFieldConditional('id', self::pullId($resource)));
     return $db->delete();
 }
Example #23
0
 /**
  * Removes any shortcuts associated with this page
  */
 private function removeShortcuts()
 {
     $db = \Database::newDB();
     $t1 = $db->addTable('access_shortcuts');
     $shortcut = 'pagesmith:' . $this->id;
     $t1->addFieldConditional('url', $shortcut);
     $db->delete();
 }
Example #24
0
/**
 * @version $Id$
 * @author Matthew McNaney <mcnaney at gmail dot com>
 */
function core_update(&$content, $version)
{
    $content[] = '';
    // Versions previous to 1.9.8 removed 2 May, 2013.
    switch (1) {
        case version_compare($version, '1.9.8', '<'):
            $content[] = '<h2>Sorry</h2>
<p>Your version of phpWebSite is too old to update using 1.8.0. Please update to
1.7.3 and return.</p>';
        case version_compare($version, '2.0.0', '<'):
            if (PHPWS_Core::isBranch()) {
                $content[] = 'This update can only be performed on the hub.';
                return false;
            }
            if (!PHPWS_Boost::inBranch()) {
                $config_dir = PHPWS_SOURCE_DIR . 'config/core/';
                if (!is_writable($config_dir)) {
                    $content[] = '<p>Core update can not continue until your hub installation\'s <strong>config/core/</strong> directory is writable.</p>';
                    return false;
                }
                $source_http = sprintf("<?php\ndefine('PHPWS_SOURCE_HTTP', '%s');\n?>", PHPWS_CORE::getHomeHttp());
                if (!file_put_contents($config_dir . 'source.php', $source_http)) {
                    $content[] = '<p>Could not create config/core/source.php file.</p>';
                    return false;
                }
                $content[] = <<<EOT
                <pre>2.0.0 changes
-----------------
+ Hub/Branch overhaul. Branches pull config, templates, javascript,
  and theme files from hub instead of locally.
+ Added Icon class. Standardizes icons and prevents overlap.
+ Added Tag class: extendable class used with Image and Form2.
+ Added tag_implode function.
+ Created Form2 class.
+ Added CKeditor.
+ Added Lightbox.
+ getConfigFile does not throw error now.
+ Dutch translation updated.
+ Added autoload function for core classes.
+ Source dir derived from file path and not simply "./"
+ Added Image class.
+ Critical functions changed to throw exceptions.
+ Setup steamlined.</pre>

<p><strong>Note:</strong> this update creates a backup of your config/core/config.php file named<br />
config-prior170.php.<br />
If your installation is working, this file may be safely deleted.</p>
<p>IMPORTANT! Many settings in the old config.php have been moved to core/conf/defines.php in the hub.
You can delete all settings <strong>except</strong> the following:</p>
<ul><li>PHPWS_SOURCE_DIR</li>
<li>PHPWS_HOME_DIR</li>
<li>PHPWS_SOURCE_HTTP</li>
<li>SITE_HASH</li>
<li>PHPWS_DSN</li>
<li>PHPWS_TABLE_PREFIX</li></ul>
</pre>
EOT;
            }
            if ($branch = PHPWS_Boost::inBranch(true)) {
                if (!PHPWS_File::copy_directory(PHPWS_SOURCE_DIR . 'javascript/editors/fckeditor/', $branch->directory . 'javascript/editors/fckeditor', true)) {
                    mkdir($branch->directory . 'images/ckeditor/');
                    $this->content[] = dgettext('branch', 'Failed to copy FCKeditor to branch.');
                } else {
                    $content[] = 'FCKeditor not copied to branch. Check directory permissions.';
                }
            } else {
                mkdir(PHPWS_SOURCE_DIR . 'images/ckeditor/');
            }
        case version_compare($version, '2.0.1', '<'):
            $content[] = <<<UPDATES
            <pre>2.0.1 changes
----------------------
+ Fixed captcha trying to pull from branch directory.
+ Fixed templates ignoring use_hub_themes setting.
+ Image class will accept tilde in source directory.
+ Database fix for insert and update on multiple tables.
+ Powerpoint types added to file check.
+ Background mode added to index (allows for selective loading on Ajax calls)
+ Freecap ereg_replace updated to preg_replace
+ Fix for js_calendar
+ Fix for javascript alert script
+ Fixes for Fckeditor and Tinymce
+ Inclusion of ngBackup
</pre>
UPDATES;
        case version_compare($version, '2.0.2', '<'):
            $content[] = <<<UPDATES
<pre>2.0.2 changes
----------------------
+ Added To top icon
+ Fixed table bug where names used in foreign key constrains (in CREATE TABLE statements) were not prefixed correctly
+ Removed HTML from some translations.
+ Fixed bug causing a table name to be repeated in a JOIN statement
+ Fixed some PHP notice errors.
+ Fixed some hub icon directory problems (Thanks Eloi).
+ Image resizing reworked to correct problems with irregular images.
+ ngBackup updates.
+ Fixed some templating issues (Thanks Tommy, Eloi).
+ URL validity checking in Text was made more robust.
+ Fixed some label id issues in form.
+ Fixed a loadDimensions error in Image (Thanks Eloi)
+ Fixed DBPager duplicating table insertions (Thanks Eloi)
+ Fixed some PEAR PHP 5 warnings.
+ Changed URL forwarding - if first value after the module is numeric, it is cast as an id.
+ Removed deny-all .htaccess file from file directory.
</pre>
UPDATES;
        case version_compare($version, '2.1.0', '<'):
            $content[] = <<<UPDATES
<pre>2.1.0 changes
----------------------
 + Another Powerpoint file mimetype added to file_types.php
 + Turned off collapse_urls as a default condition.
 + Added cosign configuration example in defines.dist.php
 + More static warnings silenced.

Classes
----------------
 + Form.php
    - Fixed bug with addCheckAssoc
    - Added onbeforeclose protection to forms
    - Fixed array handling in PHPWS_Form::grab(). If the array of elements isn't
      indexed by integers, it will return the entire array instead of trying to
      return element 0.
 + Error.php
    - Pear method call was called all lowercase. Probably a hold over
      from when function name case was irrelevant.
 + Cookie.php
    - Cookie assumes a cookie is set before deletion. Changed function
      call to check prior to operation.
 + File.php
    - Fix to file extension checking.
 + Core.php
    - Moved some logic for finding the site Base URL out of Layout and
      into Core, as the getBaseURL() function
 + Text.php
    - Missing variable added to parameter list.
    - Faulty parse_url is being silenced on failure and getGetValues returns null.
    - Filtering out high ascii using parseOutput
 + Init.php
    - Fixed overwrite problem with defines.php on updating.
 + Database.php
    - Removed restrictive join check
    - Database substitutes table "as" if it exists on column call and/or set order
    - Allow parenthesis and commas in addOrder, so we can order by function,
      like "order by coalesce(...)"
    - Fixed splat usage with count in addColumn and getColumn
+ DBPager.php
    - Rewrote CSV parser to use fputcsv
    - Fixed bug with csv reporting

Javascript
------------------
+ captcha/recaptcha - added recycle instructions
+ required_input - file inputs can now be required fields
+ protect_form - new javascript to prevent user leaving fields blank
+ jquery - updated
+ flowplayer - updated version
+ editors
    + ckeditor - added File Cabinet functionality
    + cleditor - added Cleditor by Hilmar
</pre>
UPDATES;
        case version_compare($version, '2.1.1', '<'):
            $content[] = <<<UPDATES
<pre>
2.1.1 changes
-----------------

Core Classes
-----------------
+ Fixed bugs with Key and Database. Registered users (not deities) were having problems
  with editing and view restricted items. PHPWS_DB::groupIn rewritten.
+ Core now has better error messages for Branches problems.
+ Image - removed px from width and height for xhtml compatibility.
+ Static notice fixes
+ Removed clone function call in Icon.

Javascript
----------------
+ jquery_ui and jquery updated
</pre>
UPDATES;
        case version_compare($version, '2.2.0', '<'):
            $changes = file_get_contents(PHPWS_SOURCE_DIR . 'core/boost/changes/2_2_0.txt');
            $content[] = "<pre>{$changes}</pre>";
        case version_compare($version, '2.3.0', '<'):
            try {
                include_once PHPWS_SOURCE_DIR . 'core/boost/updates/2_3_0.php';
                update_core_2_3_0();
            } catch (\Exception $e) {
                $content[] = 'Error: ' . $e->getMessage();
                return false;
            }
            $changes = file_get_contents(PHPWS_SOURCE_DIR . 'core/boost/changes/2_3_0.txt');
            $content[] = "<pre>{$changes}</pre>";
        case version_compare($version, '2.3.1', '<'):
            $db = \Database::newDB();
            $db->setConditional($db->addTable('modules')->getFieldConditional('title', 'comments'));
            $db->delete();
            $db = \Database::newDB();
            $db->setConditional($db->addTable('controlpanel_link')->getFieldConditional('itemname', 'comments'));
            $db->delete();
            $db = \Database::newDB();
            if ($db->tableExists('comments_items')) {
                $db->buildTable('comments_items')->drop();
            }
            if ($db->tableExists('comments_items_seq')) {
                $db->buildTable('comments_items_seq')->drop();
            }
            if ($db->tableExists('comments_monitors')) {
                $db->buildTable('comments_monitors')->drop();
            }
            if ($db->tableExists('comments_permissions')) {
                $db->buildTable('comments_permissions')->drop();
            }
            if ($db->tableExists('comments_ranks')) {
                $db->buildTable('comments_ranks')->drop();
            }
            if ($db->tableExists('comments_ranks_seq')) {
                $db->buildTable('comments_ranks_seq')->drop();
            }
            if ($db->tableExists('comments_threads')) {
                $db->buildTable('comments_threads')->drop();
            }
            if ($db->tableExists('comments_threads_seq')) {
                $db->buildTable('comments_threads_seq')->drop();
            }
            if ($db->tableExists('comments_users')) {
                $db->buildTable('comments_users')->drop();
            }
            if ($db->tableExists('comments_user_ranks')) {
                $db->buildTable('comments_user_ranks')->drop();
            }
            if ($db->tableExists('comments_user_ranks_seq')) {
                $db->buildTable('comments_user_ranks_seq')->drop();
            }
            $db = \Database::newDB();
            if ($db->tableExists('categories')) {
                $db->buildTable('categories')->drop();
            }
            if ($db->tableExists('categories_seq')) {
                $db->buildTable('categories_seq')->drop();
            }
            if ($db->tableExists('categories_permissions')) {
                $db->buildTable('categories_permissions')->drop();
            }
            if ($db->tableExists('category_items')) {
                $db->buildTable('category_items')->drop();
            }
            if ($db->tableExists('category_items_seq')) {
                $db->buildTable('category_items_seq')->drop();
            }
            $db = \Database::newDB();
            $db->setConditional($db->addTable('modules')->getFieldConditional('title', 'categories'));
            $db->delete();
            $db = \Database::newDB();
            $db->setConditional($db->addTable('controlpanel_link')->getFieldConditional('itemname', 'categories'));
            $db->delete();
            $content[] = '<pre>Core 2.3.1 Changes
-------------------
+ Removed Comments module
+ Removed Categories module
</pre>';
        case version_compare($version, '2.3.2', '<'):
            $content[] = '<pre>Core 2.3.2 Changes
-------------------
+ Bootstrap
    - Updated Bootstrap theme to Bootstrap 3.0.1
    - Added Bootstrap table styles to several modules.
    - Removed class name "label" from several templates as it is a reserved class name
        in Bootstrap. Leaving it caused white text.
+ Font Awesome
    - Font Awesome replaced several module icons.
    - Updated Icon class to use Font Awesome 4
+ Changed phpDSNLoader to accept the table prefix as a parameter instead of relying on a define.
+ added loadPDO to exec method should it get unset.
+ Removed remnants of category calls.
+ xml2php changed to catch an exception.
+ Added Dutch translation from Han Velthuis.
+ Rewrote some Global error messages to be more descriptive.
+ Removed "simple" theme.
+ Fixed define bug casuing setup errors.
+ Pear deprecated when possible.
+ Filter code (BB and pear) removed from Text parsing.
+ Removed firebug code, ngboost and ngcom.
+ A theme can now define default classes for inputs, labels, and element groups.
+ date_default_timezone_set added to index.php to conform with new PHP standards.
+ Error check on PHPWS_Form class added.
+ Removed setup/manager.php
+ Fixed GD version detection. Was causing resampled images to be downgraded.
+ Swiftmail library added. Not in use yet but will replace other mail functions.
+ Added abbr tag to allowed_tags.
+ Global\\Server
    - fixed getCurrentUrl adding extra slashes
+ Global\\Variable
    - setRange and setIncrement return $this to allow method chaining.
    - setText will change a bool to a 0 or 1 for display.
    - Integer creates a ranged select if setInputType is set to select.
    - Unlimited String will create a text column in the database and no longer a varchar.
    - Text input is no longer the default type for a Variable object
    - Fixed: String validity check would fail on empty or null values.
    - String-type variable limits raised to reflect higher varchar limits
    - Added unlink method to File class.
    - Boolean now shows up in a Debug call
+ Global\\Form
    - Form can now define groupings for use with Bootstrap
    - Form Labels are now a class instead of a string.
    - addInputClass will plug a css class to every input in the Global\\Form.
    - Placeholders can now be added to input objects.
    - Required check works with onblur instead of change allowing blanks to be detected.
    - Submit button will be disabled if form set to use required inputs.
    - Choice\\Select now allows first choice to be blank
    - Input\\Text now allow apostrophes.
    - Added to ability to theme buttons
    - Added return to Text to allow method chaining.
    - Removed code that automatically copied the options of integer keyed arrays
        over the key. Instead added a copyOptionToValue method.
+ Global\\Database
    - Added addFieldConditional method to Table class.
    - Text added as datatype.
    - Added joinResources method to replace join method
    - Large update to allow multiple conditionals to join statements
    - Update to subselects and tables to work properly with fields.
    - Added Exists class which is an extension of Conditional. Works with subselects.
    - DB quote changed to static method.
    - Conditionals were missing proper quoting methods.
    - Added stringAsField method to Expression.
    - Conditional checks for alias on getLeft
+ Global\\Resource returns the id of the resource as a hidden input.
    - createTable returns a table object
+ Global\\Request added methods for returning FILES information
    - Added new functions to Request to assist with command branching.
    - Added lastCommand method
+ Global\\ResourceFactory selectInto fixed as private and protected variables would not work
+ Global\\Pager
    - Added addJsonData and json_data variable. Allows entering a key=>value pair
        that will be included in the JSON return.
    - Fixed search box display
    - Fixed search clear
    - Added page count to JSON result. Not in UI yet.
    - Added method to set the data url to the pager template.
    - Added undefined check to prevent javascript error.
+ Global\\DatabasePager
    - added showQuery function and show_query variable. If variable is true, the
        select query will be inserted into the JSON return for evaluation
    - Total row calculation moved up in process so current page count is correct.
</pre>';
        case version_compare($version, '2.4.0', '<'):
            $db = \Database::newDB();
            $tbl = $db->addTable('modules');
            $tbl->addFieldConditional('title', 'clipboard');
            $db->delete();
            $db->clearConditional();
            $tbl->addFieldConditional('title', 'demographics');
            $db->delete();
            $db->clearTables();
            if ($db->tableExists('demographics')) {
                $tbl = $db->addTable('demographics');
                $tbl->drop();
            }
            $content[] = <<<EOF
<pre>Core 2.4.0 Changes
--------------------------------
+ Dropping clipboard module.
+ Dropping demographics module.
</pre>
EOF;
        case version_compare($version, '2.4.1', '<'):
            $db = \Database::newDB();
            $db->addTable('modules')->addFieldConditional('title', 'version');
            $db->delete();
            $content[] = <<<EOF
<pre>Core 2.4.1 Changes
--------------------------------
+ Removed Version module from Core modules
+ Pear DB changed to MDB2.
+ MDB2 using mysqli class instead of mysql class to prevent MySQL deprecation warnings.
+ Fixed GD library identification.
+ DTTIME format now includes hour, minute, and seconds set to zero as "all day" is interpreted differently by ical.
+ ResourceFactory returns True on successful load and false otherwise. Previously returned void.
+ Added aspell plugin for CKEditor. Written by Christian Boisjoli.
+ CKeditor
    - altered to have smoother button transitions when width is changed.
    - removed Style button
    - default width is 100% instead of hard coded pixel
    - imports images with img-responsive class added
+ Javascript added to avoid image loading on small screens
+ Fixed createConfig function in setup script
EOF;
        case version_compare($version, '2.4.2', '<'):
            $db = \Database::newDB();
            $t1 = $db->addTable('settings');
            $indexes = $t1->getIndexes();
            if (empty($indexes)) {
                $t1->createPrimaryIndexId();
            }
            $content[] = <<<EOF
<pre>
Core 2.4.2 Changes
--------------------
+ Index added to the Settings table
+ dropIndex and createPrimaryIndexId methods added to Database Table
+ Update autoloader to allow modules classes to be in their own top-level namespace
+ Global/Module: Unnecessary ampersand removed from afterRun
+ Global/Form: setAction missing https check.
+ Global/Form/Input/Date: Added min, max, and step parameters to conform with HTML5
+ Global/Form/Input/Date: setValue parses integer values
+ Global/Form/Label: required parameter made private. It was breaking the required tag.
+ Global/Modal: new class that allows for easier insertion of a bootstrap modal window.
+ Global/Variable/Integer: fixed typo with class name Exception
+ Global/Form: Added removeInput method
+ core/class/PHPWS_DB: Previously, Pear's DB class would return two column results
  as an array with the key as the first column and the value as the second. This
  behavior was inconsistent with the expected functionality. We had code programmed
  expecting this behavior. MDB2 did not replicate it, so two column results were
  broken. New code brings the result back to the expected action.
+ core/class/Link: addClass method added. setClass accepts an array
+ CKeditor: Allows i tags for use with Font Awesome and to not strip spans.
+ CKeditor: Shortened max height on autogrow. Previously, 600px frequently pushed
            it outside the monitor bounds.
</pre>
EOF;
        case version_compare($version, '2.5.0', '<'):
            $content[] = <<<EOF
<pre>
Core 2.5.0 Changes
------------------
+ Added selectAsCSV to Global Database class.
</pre>
EOF;
        case version_compare($version, '2.6.0', '<'):
            $content[] = <<<EOF
<pre>
Core 2.6.0 Changes
------------------
+ Improved DBPager Search bar and pagination
+ Updated CKEditor from 3 to 4.
+ Removed Editor class.
+ Added PHPWS_File stub file to work with autoload.
+ Added method to set width and height on Modal.
+ Added method to pull hidden variables.
+ Removed Simple and Tinymce editors
+ Updated datetimepicker script
</pre>
EOF;
        case version_compare($version, '2.7.0', '<'):
            $content[] = <<<EOF
<pre>
+ Bug Fix: CKEditor images folder returned.
+ Bug Fix: Database - Blank schema error check added to mysql Table class.
+ Bug Fix: Database - Mislabeled return on getDateType.
+ Change: datepicker - script tags put into head.js
+ Update: Bootstrap and Font Awesome version
+ Feature: Database - added "using" ability. Helps with multi-table deletions.
+ Update: Flowplayer version upped. Captioning ability added.
+ Removed: javascript/editor/ directory and all wysiwyg editors outside of ckeditor
+ Removed: Unsupported modules: phpwsbb, podcaster, and profiler
+ Bug Fix: core/class/DBPager - setDefaultOrder was ignored
+ Bug Fix: Removed @ error suppressors throughout code. Should be fun right?
+ Feature: Added exception messages to JsonErrorView.
           Previously info had to be dug out of an html encoded exception object.
+ Bug Fix: Global/Pager Search icon with bad class name
+ Feature: Global/Pager Search columns can now be set manually instead of depending on the headers.
+ Feature: Global/Tag - removeClass method - removes a class previously added to the class variable stack
+ Feature: Added authkey javascript for insertion of the authkey value for use in other js scripts.
+ Added:  &lt;s&gt; as allowed tag.
+ Feature: CKEditor Save button added for use with some modules.
</pre>
EOF;
        case version_compare($version, '2.8.0', '<'):
            $db = \Database::newDB();
            $t = $db->addTable('settings');
            $dt_old = $t->getDataType('setting');
            $dt_update = new \Database\Datatype\Text($t, 'setting');
            $dt_update->setIsNull(true);
            $t->alter($dt_old, $dt_update);
            $content[] = <<<EOF
<pre>2.8.0 changes
--------------------
+ Settings table setting column is now TEXT not VARCHAR.
</pre>               
EOF;
        case version_compare($version, '2.8.1', '<'):
            $db = \Database::newDB();
            $t = $db->addTable('settings');
            $dt_old = $t->getDataType('setting');
            $t->buildDatatype('mediumtext', 'setting');
            $dt_update = new \Database\Datatype\Text($t, 'setting');
            $dt_update->setIsNull(true);
            $t->alter($dt_old, $dt_update);
            $content[] = <<<EOF
<pre>2.8.1 changes
--------------------
+ Settings table setting column is now MEDIUMTEXT not TEXT.
</pre>               
EOF;
    }
    return true;
}
Example #25
0
 public function checkConnection()
 {
     $dsn = \Database::newDSN($this->dbtype, $this->dbuser, $this->dbpass, null, $this->dbhost, $this->dbport);
     try {
         $db = \Database::newDB($dsn);
     } catch (\PDOException $e) {
         if ($e->getCode() == 1045) {
             return BRANCH_NO_CONNECTION;
         }
     }
     $db->loadPDO();
     if (!$db->databaseExists($this->dbname)) {
         return BRANCH_CONNECT_NO_DB;
     }
     $dsn->setDatabaseName($this->dbname);
     $db->setDSN($dsn);
     $table_listing = $db->listTables();
     if (!empty($table_listing)) {
         return BRANCH_CONNECT_WITH_TABLES;
     }
     return BRANCH_CONNECT_SUCCESS;
 }
Example #26
0
 public static function getLikeGroups($name, PHPWS_Group $group)
 {
     $name = preg_replace('/[^\\w]/', '', $name);
     $db = \Database::newDB();
     $ug = $db->addTable('users_groups');
     $ug->addField('id');
     $ug->addField('name');
     $ug->addField('user_id');
     $u = $db->addTable('users', null, false);
     $u->addField('display_name');
     $cond = $db->createConditional($ug->getField('user_id'), $u->getField('id'));
     $db->joinResources($ug, $u, $cond, 'outer');
     $ug->addFieldConditional('name', "%{$name}%", 'LIKE');
     $members = $group->getMembers();
     if (isset($members)) {
         $ug->addFieldConditional('id', $members, 'not in');
     }
     $groups = $db->select();
     $tpl = new PHPWS_Template('users');
     $tpl->setFile('forms/likeGroups.tpl');
     $count = 0;
     $vars['action'] = 'admin';
     $vars['command'] = 'addMember';
     $vars['group_id'] = $group->getId();
     foreach ($groups as $member) {
         if (isset($members)) {
             if (in_array($member['id'], $members)) {
                 continue;
             }
         }
         $vars['member'] = $member['id'];
         $link = PHPWS_Text::secureLink('<i class="fa fa-plus"></i> ' . dgettext('users', 'Add'), 'users', $vars, NULL, dgettext('users', 'Add this user to this group.'), 'btn btn-sm btn-success');
         $tpl->setCurrentBlock('row');
         if (!empty($member['display_name'])) {
             $tpl->setData(array('NAME' => $member['name'] . ' (' . $member['display_name'] . ')', 'ADD' => $link));
         } else {
             $tpl->setData(array('NAME' => $member['name'], 'ADD' => $link));
         }
         $tpl->parseCurrentBlock();
     }
     $content = $tpl->get();
     return $content;
 }
Example #27
0
 public function emailContacts()
 {
     $oldtime = time() - 86400 * 30 * 12;
     $db = \Database::newDB();
     $pc = $db->addTable('prop_contacts');
     $pc->addField('first_name');
     $pc->addField('last_name');
     $pc->addField('company_name');
     $pc->addField('email_address');
     $c1 = $pc->getFieldConditional('last_log', $oldtime, '<');
     $id_pc = $pc->getField('id');
     $db->setGroupBy($id_pc);
     $properties = $db->addTable('properties');
     $exp = new \Database\Expression('count(' . $properties->getField('id') . ')', 'properties');
     $properties->addField($exp);
     $c2 = $properties->getFieldConditional('contact_id', $id_pc);
     $c3 = $properties->getFieldConditional('active', 0);
     $db->stackConditionals($c1, $c2, $c3);
     $contacts = $db->select();
     foreach ($contacts as $row) {
         extract($row);
         $row['email_address'] = "<a href='mailto:{$email_address}?subject=Account&#160;query'>{$email_address}</a>";
         $row['action'] = '';
         $result['rows'][] = $row;
     }
     if (empty($result)) {
         $this->content = 'No inactive properties';
     } else {
         $tpl = new \Template($result);
         $tpl->setModuleTemplate('properties', 'overdue.html');
         $this->content = $tpl->__toString();
     }
 }
Example #28
0
 public static function pullReadySchedules()
 {
     $db = \Database::newDB();
     $tbl = $db->addTable('pulse_schedule');
     $tbl->addFieldConditional('active', 1);
     $tbl->addFieldConditional('status', PULSE_STATUS_AWAKE);
     $tbl->addFieldConditional('execute_after', time(), '<');
     $tbl->addFieldConditional('hash', null, 'is');
     $schedules = $db->select();
     return $schedules;
 }
Example #29
0
 /**
  * Loads the database object and table object. This is not done at construct because
  * we want to allow the saveObject function in DB to be able to populate those variables
  * to prevent repeated instantiations.     */
 private function loadDatabase()
 {
     if (isset($this->DB)) {
         return;
     }
     $this->DB = \Database::newDB();
     if (empty($this->table_name)) {
         throw new \Exception(t('Missing table name'));
     }
     if (!$this->DB->tableExists($this->table_name)) {
         throw new \Exception(sprintf(t('Table does not exist: %s'), $this->table_name));
     }
     $this->table = $this->DB->addTable($this->table_name);
     if (empty($this->primary_key_column)) {
         $primary_index = $this->table->getPrimaryIndex();
         if ($primary_index) {
             $this->primary_key_column = $primary_index;
         } else {
             throw new \Exception(t('Object could not derive the table primary index'));
         }
     }
     $this->primary_key =& $this->{$this->primary_key_column};
 }
Example #30
0
 /**
  * Pulls the assignment history for the current bed and plugs in the student profile link.
  * Returns null if no history is found.
  * @return array
  */
 private function getBedHistoryArray()
 {
     $db = \Database::newDB();
     $t1 = $db->addTable('hms_assignment_history');
     $t1->addFieldConditional('bed_id', $this->bed->id);
     /*
      if (isset($this->bed->_curr_assignment)) {
      $t1->addFieldConditional('banner_id', $this->bed->_curr_assignment->banner_id, '!=');
      }
     *
     */
     $t1->addOrderBy('assigned_on', 'DESC');
     $result = $db->select();
     if (empty($result)) {
         return null;
     }
     foreach ($result as $key => $assignment) {
         $student = StudentFactory::getStudentByBannerID($assignment['banner_id'], $this->bed->getTerm());
         $result[$key]['assigned_on_date'] = HMS_Util::get_short_date_time($assignment['assigned_on']);
         if (empty($assignment['removed_on'])) {
             $result[$key]['removed_on_date'] = 'Never';
         } else {
             $result[$key]['removed_on_date'] = HMS_Util::get_short_date_time($assignment['removed_on']);
         }
         $result[$key]['student'] = $student->getProfileLink();
     }
     return $result;
 }