Пример #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
 public static function registerPermissions($module, &$content)
 {
     $tableName = Users_Permission::getPermissionTableName($module);
     if (!PHPWS_DB::isTable($tableName)) {
         return Users_Permission::createPermissions($module);
     }
     $file = sprintf('%smod/%s/boost/permission.php', PHPWS_SOURCE_DIR, $module);
     if (!is_file($file)) {
         return NULL;
     }
     include_once $file;
     if (!isset($permissions) || !is_array($permissions)) {
         return TRUE;
     }
     $db = new PHPWS_DB($tableName);
     $columns = $db->getTableColumns();
     $columnSetting = 'smallint NOT NULL default \'0\'';
     foreach ($permissions as $perm_name => $perm_proper) {
         if (in_array($perm_name, $columns)) {
             continue;
         }
         $result = $db->addTableColumn($perm_name, $columnSetting);
         if (PHPWS_Error::isError($result)) {
             $content[] = sprintf(dgettext('users', 'Could not create "%s" permission column.'), $perm_name);
             PHPWS_Error::log($result);
         } else {
             $content[] = sprintf(dgettext('users', '"%s" permission column created.'), $perm_name);
         }
     }
     return TRUE;
 }