UsedAttrs = array("cn","description","FAIpartitionType","FAIpartitionNr","FAIfsType","FAImountPoint","FAIpartitionSize",
"FAImountOptions","FAIfsOptions","FAIpartitionFlags");
/* Default status is new */
$this->status = "new";
/* We want to edit an entry */
if($disk){
/* Set disk status */
$this->status = $disk['status'];
/* Walk through partitions */
foreach($disk['partitions'] as $name => $values){
/* If a partition is already marked as delete, attach it to deletePartitions only. */
if($values['status'] == "delete"){
unset($disk['partitions'][$name]);
$this->deletePartitions[]=$values;
}else{
/* Set status, to know which partition must be deleted from ldap
new : Neu partition entry // save
edited : Update partition entry in ldap
deleted: Remove partition from ldap
*/
/* If status is not new, set to edit mode.
* New means that this partition currently wasn't saved to ldap.
*/
if($disk['partitions'][$name]['status']!="new"){
$disk['partitions'][$name]['status']="edited";
}
$disk['partitions'][$name]['old_cn']= $disk['partitions'][$name]['cn'];
/* Assign empty attributes, if attribute is missing */
foreach($this->UsedAttrs as $attr){
if(!isset($values[$attr])){
$disk['partitions'][$name][$attr]="";
}
}
if (preg_match('/^_/', $disk['partitions'][$name]['FAIfsType'])){
$disk['partitions'][$name]['FAIfsType']= preg_replace('/^_/', '', $disk['partitions'][$name]['FAIfsType']);
}
}
}
/* Set default attributes */
$this->DISKcn = $disk['cn'];
$this->DISKdescription = $disk['description'];
$this->partitions = $disk['partitions'];
$this->is_edit = true;
$this->old_cn = $disk['cn'];
}
}
function execute()
{
/* Call parent execute */
plugin::execute();
/* Fill templating stuff */
$smarty = get_smarty();
$s_action = "";
$s_entry = "";
$display = "";
/* Assign values
* And Checkbox selection
*/
foreach($this->attributes as $attrs){
$smarty->assign($attrs,$this->$attrs);
if($this->$attrs){
$smarty->assign($attrs."CHK"," ");
}else{
$smarty->assign($attrs."CHK"," disabled ");
}
}
/* Check all Posts if there is something usefull for us,
* For example : Delete is posted as Delete_1
* The number specifies the index we want to delete
*/
foreach($_POST as $name => $value){
if((preg_match("/Delete_.*/",$name)) && $this->acl_is_removeable() && !preg_match("/freeze/i",$this->FAIstate)){
$tmp = split("_",$name);
$s_action = "remove";
$s_entry = $tmp[1];
}
}
/* To remove a partition we unset the index posted.
* We must sort the index again, else we possibly got problems
* with partitions order.
*/
if($s_action == "remove" && $this->acl_is_removeable() && !preg_match("/freeze/i",$this->FAIstate)){
if($this->partitions[$s_entry]['status'] == "edited"){
$this->deletePartitions[$s_entry]= $this->partitions[$s_entry];
$this->deletePartitions[$s_entry]['FAIpartitionNr']=$s_entry;
unset($this->partitions[$s_entry]);
}else{
unset($this->partitions[$s_entry]);
}
$tmp= array();
foreach($this->partitions as $part){
$tmp[count($tmp)+1]=$part;
}
$this->partitions = $tmp;
}
/* To add a partitions we only append an empty
* array to the already defined partitions.
*/
if(isset($_POST['AddPartition']) && $this->acl_is_createable() && !preg_match("/freeze/i",$this->FAIstate)){
foreach($this->UsedAttrs as $attr){
$tmp[$attr] = "";
}
$tmp["old_cn"] = "";
$tmp['status']="new";
$this->partitions[count($this->partitions)+1]=$tmp;
}
/* $setup contains a table with the partitions.
*/
$smarty->assign("setup", $this->generateParts());
foreach($this->attributes as $attr){
$smarty->assign($attr,$this->$attr);
}
$tmp = $this->plInfo();
$sacl = "";
foreach($tmp['plProvidedAcls'] as $name => $translated){
$acl = $this->getacl($name, preg_match("/freeze/i",$this->FAIstate));
$smarty->assign($name."ACL",$acl);
}
$smarty->assign("sub_object_is_createable",$this->acl_is_createable());
$smarty->assign("freeze",preg_match("/freeze/i",$this->FAIstate));
/* Fetch template and show the result
*/
$display.= $smarty->fetch(get_template_path('faiPartitionTableEntry.tpl', TRUE));
return($display);
}
function generateParts()
{
/* Define Arrays with allowed syntax */
$PartitionTypes = array("primary"=>_("primary"),"logical"=>_("logical"));
$FAIfsTypes = array("ext2","ext3","xfs","swap","reiser","dosfat16","winfat32");
/* Display Header */
$str = "";
if (count($this->partitions)){
$str .= "
";
$str .= "
"._("Type")."
";
$str .= "
"._("FS type")."
";
$str .= "
"._("Mount point")."
";
$str .= "
"._("Size in MB")."
";
$str .= "
"._("Mount options")."
";
$str .= "
"._("FS option")."
";
$str .= "
"._("Preserve")."
";
$str .= "
";
$str .= "
";
}
/* Walk through all defined partitions.
* Create a new row for each partition and append it to
* the header defined above.
* To be able to check the posts later, we append a key to each single postfield. like cn_1 ... cn_2
*/
foreach($this->partitions as $key => $part){
$dis = "";
if($part['FAIpartitionFlags'] == "preserve"){
$dis = " disabled ";
}
$disableALL = "";
if (preg_match("/freeze/", $this->FAIstate)){
$disableALL = " disabled ";
}
if($part['status']!="delete"){
/* Generate Partition select box
*/
$PartitionType = "";
if($this->acl_is_writeable("FAIpartitionType")){
$PartitionType = "";
}elseif($this->acl_is_readable("FAIpartitionType")){
$PartitionType = $part['FAIpartitionType'];
}
/* Generate fsType select box
*/
$FAIfsType= "";
if($this->acl_is_writeable("FAIfsType")){
$FAIfsType= "";
}elseif($this->acl_is_readable("FAIfsType")){
$FAIfsType = $part['FAIfsType'];
}
foreach(array("FAImountPoint","FAIpartitionSize","FAImountOptions","FAIfsOptions") as $attr){
$$attr = "";
if($this->acl_is_writeable($attr)){
$$attr = "";
}elseif($this->acl_is_readable($attr)){
$$attr = $part[$attr];
}
}
$str .= "\n