diff --git a/gosa-plugins/fai/admin/fai/class_faiScript.inc b/gosa-plugins/fai/admin/fai/class_faiScript.inc
index 9e33a5d884ad6a59b2ded89a30e04b7126a1262e..2703ae7219a1bc6b6f793396f920c84f7922642e 100644 (file)
var $is_dialog = false; // specifies which buttons will be shown to save or abort
var $SubObjects = array(); // All leafobjects of this object
var $is_dialog = false; // specifies which buttons will be shown to save or abort
var $SubObjects = array(); // All leafobjects of this object
- var $FAIstate = "";
+ var $FAIstate = "branch";
var $sort_by = "name";
var $sort_order = "up";
var $sort_by = "name";
var $sort_order = "up";
* First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
*/
if($dn != "new"){
* First read SubObjects from ldap ... and then the partition definitions for the SubObjects.
*/
if($dn != "new"){
-
$this->dn =$dn;
$this->dn =$dn;
- /* Get FAIstate
- */
- if(isset($this->attrs['FAIstate'][0])){
- $this->FAIstate = $this->attrs['FAIstate'][0];
- }
-
/* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
*/
/* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
*/
- $ldap = $this->config->get_ldap_link();
- $ldap->cd ($this->dn);
-
- $attrs_to_search = $this->subAttributes;
- $attrs_to_search[] = "FAIstate";
- $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search);
- $data = array();
- while($object = $ldap->fetch()){
- $data[] = $object;
- }
- foreach($data as $object){
+ $res = FAI::get_all_objects_for_given_base($this->dn,"(&(objectClass=FAIclass)(objectClass=".$this->subClass."))");
+ foreach($res as $obj){
- /* Skip objects, that are tagged as removed */
- if(isset($object['FAIstate'][0])){
- if(preg_match("/removed$/",$object['FAIstate'][0])){
- continue;
- }
- }
+ /* Skip not relevant objects */
+ if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
- /* Set status for save management */
$objects = array();
$objects['status'] = "FreshLoaded";
$objects = array();
$objects['status'] = "FreshLoaded";
- $objects['dn'] = $object['dn'];
+ $objects['dn'] = $obj['dn'];
$objects = $this->get_object_attributes($objects,$this->subAttributes);
$this->SubObjects[$objects['cn']] = $objects;
}
$objects = $this->get_object_attributes($objects,$this->subAttributes);
$this->SubObjects[$objects['cn']] = $objects;
}
-
}
$this->is_new = FALSE;
}
$this->is_new = FALSE;
}
$this->ui = get_userinfo();
}
$this->ui = get_userinfo();
+
+ $this->scriptListWidget= new sortableListing($this->convertList(TRUE), $this->convertList());
+ $this->scriptListWidget->setDeleteable(true);
+ $this->scriptListWidget->setInstantDelete(false);
+ $this->scriptListWidget->setEditable(true);
+ $this->scriptListWidget->setWidth("100%");
+ $this->scriptListWidget->setHeight("140px");
+ $this->scriptListWidget->setHeader(array(_("Name"),_("Description")));
+ }
+
+
+ function convertList($type = FALSE)
+ {
+ $data = array();
+ $s_acl = $this->ui->get_permissions($this->dn,"fai/faiScriptEntry","FAIscript");
+ foreach($this->SubObjects as $cn => $entry){
+ if($entry['status'] == "delete") continue;
+ if($type){
+ $data[$cn] = $entry;
+ }else{
+ if(!isset($entry['description'])) $entry['description']="";
+ $data[$cn] = array('data' => array($entry['cn'], $entry['description']));
+ }
+ }
+ return($data);
}
}
/* Return a valid dn to fetch acls. Because 'new' will not work. */
function acl_base_for_current_object($dn)
{
/* Return a valid dn to fetch acls. Because 'new' will not work. */
function acl_base_for_current_object($dn)
{
- if($dn == "new"){
+ if($dn == "new" || $dn == ""){
if($this->dn == "new"){
if($this->dn == "new"){
- $dn= "cn=dummy,".session::get('CurrentMainBase');
+ $dn= $this->parent->parent->acl_base;
}else{
$dn = $this->dn;
}
}else{
$dn = $this->dn;
}
$display= "";
/* Add new sub object */
$display= "";
/* Add new sub object */
- if(isset($_POST['AddSubObject'])){
+ if(isset($_POST['AddSubObject']) && !preg_match("/freeze/i",$this->FAIstate)){
$this->dialog= new $this->subClassName($this->config,"new");
$this->dialog= new $this->subClassName($this->config,"new");
+ $this->dialog->FAIstate = $this->FAIstate;
$this->dialog->set_acl_base($this->acl_base);
$this->dialog->set_acl_category("fai");
$this->dialog->parent = &$this;
$this->dialog->set_acl_base($this->acl_base);
$this->dialog->set_acl_category("fai");
$this->dialog->parent = &$this;
}
if($this->dn != "new"){
}
if($this->dn != "new"){
- session::set('objectinfo',$this->dn);
+ set_object_info($this->dn);
}
}
- /* File download requested */
- if(isset($_GET['getFAIscript'])){
- if(isset($this->SubObjects[base64_decode($_GET['getFAIscript'])])){
- $obj = $this->SubObjects[base64_decode($_GET['getFAIscript'])];
- $obj = $this->get_object_attributes($obj,$this->sub_Load_Later);
- send_binary_content(stripslashes($obj['FAIscript']),$obj['cn'].".FAIscript");
- }
- }
-
- /* Handle posts */
- $s_action = $s_entry = "";
- foreach($_POST as $name => $value){
-
- /* Edit script posted */
- if(preg_match("/^editscript_/",$name)){
- $s_action = "edit";
- $s_entry = preg_replace("/^editscript_/","",$name);
- $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry));
- break;
- }
+ $this->scriptListWidget->setAcl($this->getacl(""));
+ $this->scriptListWidget->save_object();
+ $action = $this->scriptListWidget->getAction();
+ if($action['action'] =="edit"){
+ $s_entry = $this->scriptListWidget->getKey($action['targets'][0]);
+ if(isset($this->SubObjects[$s_entry])){
- /* Delete script requested */
- if(preg_match("/^deletescript_/",$name)){
- $s_action = "remove";
- $s_entry = preg_replace("/^deletescript_/","",$name);
- $s_entry = base64_decode(preg_replace("/_.*/","",$s_entry));
- break;
- }
- }
-
- if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id'])){
- $s_entry = base64_decode($_GET['id']);
- if(isset($this->SubObjects[$s_entry])){
- $s_action = "edit";
- }
- }
+ $obj = $this->SubObjects[$s_entry];
+ if($obj['status'] == "FreshLoaded"){
+ $obj = $this->get_object_attributes($obj,$this->sub_Load_Later);
+ }
- if($s_action =="edit" && isset($this->SubObjects[$s_entry])){
+ /* Create new dialog and set acl attributes */
+ $this->dialog= new $this->subClassName($this->config,$this->dn,$obj);
+ $this->dialog->FAIstate = $this->FAIstate;
+ $this->dialog->set_acl_base($this->acl_base_for_current_object($obj['dn']));
+ $this->dialog->set_acl_category("fai");
- /* Get object, and load missing entry values */
- $obj = $this->SubObjects[$s_entry];
- if($obj['status'] == "FreshLoaded"){
- $obj = $this->get_object_attributes($obj,$this->sub_Load_Later);
+ /* Assign some additional dialog informations like headline and parent */
+ set_object_info($obj['dn']);
+ $this->dialog->parent = &$this;
+ $this->is_dialog=true;
}
}
-
- /* Create new dialog and set acl attributes */
- $this->dialog= new $this->subClassName($this->config,$this->dn,$obj);
- $this->dialog->set_acl_base($this->acl_base_for_current_object($obj['dn']));
- $this->dialog->set_acl_category("fai");
-
- /* Assign some additional dialog informations like headline and parent */
- session::set('objectinfo',$obj['dn']);
- $this->dialog->parent = &$this;
- $this->is_dialog=true;
}
/* Check acls, are we allowed to delete an entry */
}
/* Check acls, are we allowed to delete an entry */
- if($s_action == "remove" && isset($this->SubObjects[$s_entry])){
- $entry = $this->SubObjects[$s_entry];
- $acl = $this->ui->get_permissions($this->acl_base_for_current_object($entry['dn']),"fai/faiScriptEntry") ;
- if(preg_match("/d/",$acl)){
- $status = $entry['status'];
- if($status == "edited" || $status == "FreshLoaded"){
- $this->SubObjects[$s_entry]['status']= "delete";
- }else{
- unset($this->SubObjects[$s_entry]);
+ if($action['action'] =="delete"){
+ $s_entry = $this->scriptListWidget->getKey($action['targets'][0]);
+ if(isset($this->SubObjects[$s_entry])){
+ $entry = $this->SubObjects[$s_entry];
+ $acl = $this->ui->get_permissions($this->acl_base_for_current_object($entry['dn']),"fai/faiScriptEntry") ;
+ if(preg_match("/d/",$acl)){
+ $status = $entry['status'];
+ if($status == "edited" || $status == "FreshLoaded"){
+ $this->SubObjects[$s_entry]['status']= "delete";
+ }else{
+ unset($this->SubObjects[$s_entry]);
+ }
}
}
}
}
}
}
- /* Save the edited entry */
+
+ /* Save the edited entry */
if(isset($_POST['SaveSubObject'])){
/* Check if there are still errors remaining that must be fixed before saving */
if(isset($_POST['SaveSubObject'])){
/* Check if there are still errors remaining that must be fixed before saving */
}
}
}
}
- /* Sort entries */
- $tmp = $keys = array();
-
- if($this->sort_by == "name"){
- foreach($this->SubObjects as $key => $entry){
- $keys[$key]=$entry['cn'];
- }
- }elseif($this->sort_by == "priority"){
- foreach($this->SubObjects as $key => $entry){
- $keys[$key]=$entry['FAIpriority'];
- }
- }
-
- natcasesort($keys);
-
- if($this->sort_order == "down"){
- $keys =array_reverse($keys);
- }
-
- foreach($keys as $key => $order_var){
- $tmp[$key]=$this->SubObjects[$key];
- }
- $this->SubObjects = $tmp;
-
/* Cancel Dialog */
if(isset($_POST['CancelSubObject'])){
$this->is_dialog=false;
/* Cancel Dialog */
if(isset($_POST['CancelSubObject'])){
$this->is_dialog=false;
return($display);
}
return($display);
}
- /* Divlist added 23.02.2006
- Containing FAIscripts
- */
- $divlist = new divlist("FAIscripts");
- $divlist->SetEntriesPerPage(0);
- $plug = $_GET['plug'];
-
- if($this->sort_order == "up"){
- $dir = "<img src='images/lists/sort-up.png' title='"._("Sort direction")."' alt='\/' border=0>";
- }else{
- $dir = "<img src='images/lists/sort-down.png' title='"._("Sort direction")."' alt='/\' border=0>";
- }
-
- if($this->sort_by == "name"){
- $sort_name = $dir;
- $sort_prio = "";
- }else{
- $sort_name = "";
- $sort_prio = $dir;
- }
-
- $divlist->SetHeader(array( array("string"=>"<a href='?plug=".$plug."&sort=name'>"._("Name").$sort_name."</a>"),
- array("string"=>"<a href='?plug=".$plug."&sort=priority'>".$sort_prio._("Priority")."</a>",
- "attach"=>"style='width:100px;'"),
- array("string"=>_("Download"),
- "attach"=>"style='width:100px;'"),
- array("string"=>_("Action"),
- "attach"=>"style='border-right: 0px;width:100px;text-align:right;'")));
- $divlist->SetHeight(300);
- $divlist->SetWidth("100%");
- foreach($this->getList(true) as $key => $name){
-
- $dn= $this->acl_base_for_current_object($name['dn']);
- $acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry") ;
- $act = "";
-
- /* Hide delete icon if this object is freezed */
- if(preg_match("/freeze/", $this->FAIstate)){
- $act .= "<input type='image' src='images/lists/edit.png' name='editscript_%s' title='"._("edit")."' alt='"._("edit")."'>";
- }else{
- $act .= "<input type='image' src='images/lists/edit.png' name='editscript_%s' title='"._("edit")."' alt='"._("edit")."'>";
- if(preg_match("/d/",$acl)){
- $act .="<input type='image' src='images/lists/trash.png' name='deletescript_%s' title='"._("delete")."' alt='"._("delete")."'>";
- }
- }
-
- /* Check acls for download icon */
- $s_acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry","FAIscript") ;
- if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new") || !preg_match("/r/",$s_acl)){
- $down = "";
- }else{
- $down = "<a href='?plug=".$_GET['plug']."&getFAIscript=".base64_encode($key)."'>
- <img src='images/save.png' alt='"._("Download")."' title='"._("Download")."' border=0>
- </a>";
- }
-
- /* Check if we are allowed to view this object */
- $s_acl = $this->ui->get_permissions($dn,"fai/faiScriptEntry","cn") ;
- if(preg_match("/r/",$s_acl)){
- $divlist->AddEntry(array( array("string"=>"<a href='?plug=".$_GET['plug']."&act=edit&id=".base64_encode($key)."'>".$name['name']."</a>"),
- array("string"=>$name['FAIpriority'] , "attach" => "style='width:100px;'"),
- array("string"=>$down , "attach" => "style='width:100px;'"),
- array("string"=>str_replace("%s",base64_encode($key),$act),
- "attach"=>"style='border-right: 0px;width:100px;text-align:right;'")));
- }
- }
- $smarty->assign("Entry_divlist",$divlist->DrawList());
+ $this->scriptListWidget->setListData($this->convertList(TRUE), $this->convertList());
+ $this->scriptListWidget->update();
+ $smarty->assign("Entry_listing",$this->scriptListWidget->render());
/* Magic quotes GPC, escapes every ' " \, to solve some security risks
* If we post the escaped strings they will be escaped again
/* Magic quotes GPC, escapes every ' " \, to solve some security risks
* If we post the escaped strings they will be escaped again
$ldap = $this->config->get_ldap_link();
$ldap->cd ($this->dn);
$release = $this->parent->parent->fai_release;
$ldap = $this->config->get_ldap_link();
$ldap->cd ($this->dn);
$release = $this->parent->parent->fai_release;
- $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $release, $this->dn);
+ $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn);
new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
FAI::prepare_to_save_FAI_object($use_dn,array(),true);
foreach($this->SubObjects as $name => $obj){
new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
FAI::prepare_to_save_FAI_object($use_dn,array(),true);
foreach($this->SubObjects as $name => $obj){
- $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $release, $obj['dn']);
+ $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $obj['dn']);
FAI::prepare_to_save_FAI_object($use_dn,array(),true);
}
$this->handle_post_events("remove");
FAI::prepare_to_save_FAI_object($use_dn,array(),true);
}
$this->handle_post_events("remove");
{
if((isset($_POST['FAIscript_posted'])) && !preg_match("/freeze/", $this->FAIstate)){
plugin::save_object();
{
if((isset($_POST['FAIscript_posted'])) && !preg_match("/freeze/", $this->FAIstate)){
plugin::save_object();
- foreach($this->attributes as $attrs){
- if(isset($_POST[$attrs])){
- $this->$attrs = $_POST[$attrs];
- }
- }
}
/* Get sort order */
}
/* Get sort order */
*/
if($this->is_new){
$release = $this->parent->parent->fai_release;
*/
if($this->is_new){
$release = $this->parent->parent->fai_release;
- $new_dn= 'cn='.$this->cn.",".get_ou('faiscriptou').get_ou('faiou').$release;
+ $new_dn= 'cn='.$this->cn.",".get_ou('faiScriptRDN').get_ou('faiBaseRDN').$release;
$res = faiManagement::check_class_name("FAIscript",$this->cn,$new_dn);
if(isset($res[$this->cn])){
$message[] = msgPool::duplicated(_("Name"));
$res = faiManagement::check_class_name("FAIscript",$this->cn,$new_dn);
if(isset($res[$this->cn])){
$message[] = msgPool::duplicated(_("Name"));
$tmp = array();
$attributes = array_merge($this->sub_Load_Later,$this->subAttributes);
foreach($attributes as $attrs){
$tmp = array();
$attributes = array_merge($this->sub_Load_Later,$this->subAttributes);
foreach($attributes as $attrs){
-
- if(empty($obj[$attrs])){
+ if(!isset($obj[$attrs])) continue;
+ if($obj[$attrs] == ""){
$obj[$attrs] = array();
}
if(!is_array($obj[$attrs])){
$obj[$attrs] = array();
}
if(!is_array($obj[$attrs])){
/* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
*/
/* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
*/
- $ldap = $this->config->get_ldap_link();
- $ldap->cd ($source['dn']);
-
- $attrs_to_search = $this->subAttributes;
- $attrs_to_search[] = "FAIstate";
- $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search);
+ $res = FAI::get_all_objects_for_given_base($source['dn'],"(&(objectClass=FAIclass)(objectClass=".$this->subClass."))");
+ foreach($res as $obj){
- while($object = $ldap->fetch()){
+ /* Skip not relevant objects */
+ if(!preg_match("/".preg_quote($source['dn'], '/')."$/i",$obj['dn'])) continue;
- /* Skip objects, that are tagged as removed */
- if(isset($object['FAIstate'][0])){
- if(preg_match("/removed$/",$object['FAIstate'][0])){
- continue;
- }
- }
-
- /* Set status for save management */
$objects = array();
$objects['status'] = "edited";
$objects = array();
$objects['status'] = "edited";
- $objects['dn'] = $object['dn'];
+ $objects['dn'] = $obj['dn'];
$objects = $this->get_object_attributes($objects,$this->subAttributes);
$objects = $this->get_object_attributes($objects,$this->sub_Load_Later);
$objects = $this->get_object_attributes($objects,$this->subAttributes);
$objects = $this->get_object_attributes($objects,$this->sub_Load_Later);
-
$this->SubObjects[$objects['cn']] = $objects;
}
}
$this->SubObjects[$objects['cn']] = $objects;
}
}