nun gut ich hab mal was geschrieben das eigentlich ganz intressant geworden ist...
das funktioniert aber nur wenn was dupliziert wird...
vorgehensweise:
ich suche zuerst mal die user_id + alle group_ids raus...
dann such ich die areaid + dazugehörige actionid
raus...
die unterscheidung gruppe und user hab ich zusammengefasst...
anschließend selektiere ich alle werte die in der con_rights vorhanden sind und dem kriterium der idarea + idaction + übergebenen idcat + user_id werten entsprechen raus
bau die insert statements und führe sie aus...
vielleicht kann es ja einer testen...
als platz für die funktion hab ich die functions.rights.php genommen...
die ist sowieso leer...
Code: Alles auswählen
<?php
/******************************************
* File : functions.rights.php
* Project : Contenido
* Descr : Defines the 'rights' related
* functions
*
* Author : Martin Horwath
* Created : 25.11.2004
* Modified : 11.12.2004
*
* © dayside.net
*****************************************/
/**
* Duplicate rights for any element
*
* @param string $area main area name
* @param int $iditem ID of element to copy
* @param int $newiditem ID of the new element
*
* @author Martin Horwath <horwath@dayside.net>
* @copyright dayside.net <dayside.net>
*/
function copyRightsForElement ($area, $iditem, $newiditem) {
global $cfg, $perm, $auth, $area_tree;
$db = new DB_Contenido;
$db2 = new DB_Contenido;
// get all user_id values for con_rights
$userIDContainer[0] = $auth->auth["uid"]; // user_id of current user
$userIDContainer = array_merge($userIDContainer, $perm->getGroupsForUser($auth->auth["uid"]));
// long way start
/*
$sql = "SELECT
group_id
FROM
".$cfg["tab"]["groupmembers"]."
WHERE
user_id = '".$userIDContainer[0]."'";
$db->query($sql);
while ($db->next_record()) {
$userIDContainer[] = $db->f("group_id"); // add group_ids
}
*/
// long way end
foreach ($userIDContainer as $key) {
$statement_where2[] = "user_id = '".$key."' ";
}
$where_users = "(".implode(" OR ", $statement_where2 ) .")"; // only duplicate on user and where user is member of
// get all idarea values for $area
// short way
$AreaContainer = $area_tree[showareas($area)];
// long way
/*
$AreaContainer[0] = $perm->getIDForArea($area);
$sql = "SELECT
idarea
FROM
".$cfg["tab"]["area"]."
WHERE
parent_id = '".$area."'";
$db->query($sql);
while ($db->next_record()) {
$AreaContainer[] = $db->f("idarea");
}
*/
// long version start
// get all actions for corresponding area
$AreaActionContainer = array();
$sql = "SELECT
idarea, idaction
FROM
".$cfg["tab"]["actions"]."
WHERE
idarea IN (".implode (',', $AreaContainer).")";
$db->query($sql);
while ($db->next_record()) {
$AreaActionContainer[] = Array ("idarea"=>$db->f("idarea"), "idaction"=>$db->f("idaction"));
}
// build sql statement for con_rights
foreach ($AreaActionContainer as $key) {
$statement_where[] = "( idarea = ".$key["idarea"]." AND idaction = ".$key["idaction"]." )";
}
$where_area_actions = "(".implode(" OR ", $statement_where ) .")"; // only correct area action pairs possible
// final sql statement to get all effected elements in con_right
$sql = "SELECT
*
FROM
".$cfg["tab"]["rights"]."
WHERE
{$where_area_actions} AND
{$where_users} AND
idcat = {$iditem}";
// long version end
/*
// short version start
$sql = "SELECT
*
FROM
".$cfg["tab"]["rights"]."
WHERE
idarea IN (".implode (',', $AreaContainer).") AND
idaction != 0 AND
{$where_users} AND
idcat = {$iditem}";
// short version end
*/
$db->query($sql);
while ($db->next_record()) {
$sql = "INSERT INTO ".$cfg["tab"]["rights"]." (idright,user_id,idarea,idaction,idcat,idclient,idlang,`type`) VALUES ('".$db2->nextid($cfg["tab"]["rights"])."','".$db->f("user_id")."','".$db->f("idarea")."','".$db->f("idaction")."','".$newiditem."','".$db->f("idclient")."','".$db->f("idlang")."','".$db->f("type")."');";
$db2->query($sql);
}
// permissions reloaded...
$perm->load_permissions(true);
}
/**
* Create rights for any element
*
* @param string $area main area name
* @param int $iditem ID of new element
*
* @author Martin Horwath <horwath@dayside.net>
* @copyright dayside.net <dayside.net>
*/
function createRightsForElement ($area, $iditem) {
global $cfg, $perm, $auth, $area_tree, $client;
$db = new DB_Contenido;
$db2 = new DB_Contenido;
// get all user_id values for con_rights
$userIDContainer[0] = $auth->auth["uid"]; // user_id of current user
$userIDContainer = array_merge($userIDContainer, $perm->getGroupsForUser($auth->auth["uid"])); // add group ids
foreach ($userIDContainer as $key) {
$statement_where2[] = "user_id = '".$key."' ";
}
$where_users = "(".implode(" OR ", $statement_where2 ) .")"; // only duplicate on user and where user is member of
// get all idarea values for $area
// short way
$AreaContainer = $area_tree[showareas($area)];
$sql="SELECT
*
FROM
".$cfg["tab"]["rights"]."
WHERE
idclient='$client' AND
idarea IN (".implode (',', $AreaContainer).") AND
idcat != 0 AND
idaction!='0' AND
{$where_users}";
$db->query($sql);
$RightsContainer = array();
while($db->next_record()){
$RightsContainer[$db->f("user_id")][$db->f("idlang")][$db->f("type")][$db->f("idaction")] = $db->f("idarea");
}
// i found no better way to set the rights
// double entries should not be possible anymore...
foreach ($RightsContainer as $userid=>$LangContainer) {
foreach ($LangContainer as $idlang=>$TypeContainer) {
foreach ($TypeContainer as $type=>$ActionContainer) {
foreach ($ActionContainer as $idaction=>$idarea) {
$sql="INSERT INTO ".$cfg["tab"]["rights"]."
(idright, user_id,idarea,idaction,idcat,idclient,idlang,`type`)
VALUES ('".$db2->nextid($cfg["tab"]["rights"])."', '".$userid."','".$idarea."','".$idaction."','$iditem','$client','".$idlang."','".$type."')";
$db2->query($sql);
}
}
}
}
// permissions reloaded...
$perm->load_permissions(true);
}
?>
anschließend folgende änderung in
functions.tpl.php bei
Code: Alles auswählen
function tplDuplicateTemplate($idtpl) {
...
return $new_idtpl;
}
folgendes vor dem return ergänzen:
Code: Alles auswählen
cInclude ("includes", "functions.rights.php");
copyRightsForElement("tpl", $idtpl, $new_idtpl);
und der letzte schritt... da hab ich noch nen bug entdeckt...
functions.general.php
die funktion
ersetzen durch
Code: Alles auswählen
function showareas($mainarea){
global $area_tree, $sess, $perm, $cfg;
$db=new DB_Contenido;
$mainarea = $perm->getIDForArea($mainarea);
//if $area_tree for this area is not register
if(!isset($area_tree[$mainarea])){
$sess->register("area_tree");
// parent_id uses the name not the idarea
$sql="SELECT name FROM ".$cfg["tab"]["area"]." WHERE idarea='$mainarea'";
$db->query($sql);
$db->next_record();
$name = $db->f("name");
//check which subareas are there and write them in the array
$sql="SELECT idarea FROM ".$cfg["tab"]["area"]." WHERE parent_id='$name' OR idarea='$mainarea'";
$db->query($sql);
$area_tree[$mainarea]=array();
while($db->next_record()){
$area_tree[$mainarea][]=$db->f("idarea");
}
}
return $mainarea;
}
das sollte es sein...