#!/usr/bin/tclsh
#
# This file is part of Helga.
#
# Helga is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Helga is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Helga. If not, see .
#
if { $argc != 2 } {
puts "usage: \"\""
exit 1
}
package require helga
::helga::db::init
set typeId [::helga::assets::getTypeIdFromName user]
set userName [lindex $argv 0]
set assetId [::helga::assets::getAssetIdFromPath "/"]
set parentId [::helga::assets::getAssetIdFromName "users" $assetId]
# add row to assets
set sql "INSERT INTO `assets` ( `assetId`, `typeId`, `assetName`, `parentId`, `position` ) VALUES ( NULL, $typeId, '$userName', $parentId, NULL )"
::helga::db::insert $sql
# get new assetId
set userId [::helga::assets::getAssetIdFromName $userName $parentId]
set fullName [lindex $argv 1]
# add row to users
set sql "INSERT INTO `users` ( `assetId`, `fullName` ) VALUES ( $userId, '$fullName' )"
::helga::db::insert $sql
# add row to permissions
set sql "INSERT INTO `permissions` ( `permId`, `userId`, `assetId`, `permLevel` ) VALUES ( NULL, $userId, $assetId, 'admin' )"
::helga::db::insert $sql
puts "added user $userName."