Code

Branch for testing
[gosa.git] / include / class_CopyPasteHandler.inc
1 <?php
3 class CopyPasteHandler {
5   var $config;
6   var $current;
8   var $copyCurrent = false;
9   var $cutCurrent  = false;
10   var $dialogOpen  = false;
11   var $objectdn    = false;
13   var $lastdn      = "";
15   var $was_successfull = false;
17   /* Create CP handler  */
18   function CopyPasteHandler($config){
19     $this->config = $config;    
20     $this->current= NULL;
21   }
24   /* Returns wether the current object can be pasted */ 
25   function isCurrentObjectPastAble(){
27     /* Check if we got a valid object */
28     if($this->current == NULL){
29       return(false);
30     }
31     return(true);
32   }     
35   /* Clears all copy & paste informations */
36   function Clear()
37   {
38     $this->copyCurrent  = false;
39     $this->cutCurrent   = false;
40     $this->dialogOpen   = false;
41     $this->current              = NULL;
42   }
45   /* return current obejct dn */
46   function GetCurrentDn()
47   {
48     return($this->objectdn);
49   }
52   /* Add Object which should be copied  */
53   function Copy($obj,$emptyObj)
54   {
55     $this->copyCurrent = true;
56     $this->objectdn    = $obj->dn;
57     $this->current = $emptyObj;
58     foreach($obj->by_object as $name => $obj){
59     
60       /* Prepare every single class, to be copied  */
61       $this->current->by_object[$name]->PrepareForCopyPaste($obj);
62  
63       /* handle some special vars */ 
64       foreach(array("is_account") as $attr){
65         if(isset($obj->$attr)){
66           $this->current->by_object[$name]->$attr = $obj->$attr;
67         }
68       }
69     }
70     if($this->isCurrentObjectPastAble()){
71       return(true);
72     }else{
73       $this->cutCurrent = $this->copyCurrent = false;
74       $this->obj = NULL;
75     }
76     return(false);
77   }
80   /* Add Object which should be cutted  */
81   function Cut($obj){
82     $this->cutCurrent = true;
83     $this->current        = $obj;
84     $this->objectdn    = $obj->dn;
85     if($this->isCurrentObjectPastAble()){
86       return(true);
87     }else{
88       $this->cutCurrent = $this->copyCurrent = false;
89       $this->obj = NULL;
90     }
91     return(false);
92   }
95   /* Returns true if current object 
96    *  is cutted. And awaits to be pasted anywhere  */
97   function isCurrentCutted(){
98     return($this->cutCurrent);
99   }
102   /* Returns true if current object  
103    *  was copied, and awaits to be pasted again  */
104   function isCurrentCopied(){
105     return($this->copyCurrent);
106   }
109   /* Returns true if the copy$paste dialog is still open  */
110   function stillOpen(){ 
111     if(isset($_POST['AbortCopyPaste'])){
112       $this->dialogOpen = false;
113     }
114     return($this->dialogOpen);
115   }
118   /* Displays a dialog which allows the user to fix all dependencies of this object.
119      Create unique names, ids, or what ever */
120   function execute()
121   {
122     $this->dialogOpen = true;
124     /* Cut & paste
125      */
126     if($this->cutCurrent){
127       $this->current->save();
128       $this->dialogOpen =false;
129       $this->Clear();
131       /* Copy & paste
132        */
133     }else{
134       if(isset($_POST['PerformCopyPaste'])){
135         $msgs = $this->check(); 
136         if(count ($msgs) ){
137           foreach( $msgs as $msg){
138             print_red($msg);
139           }
140         }else{
141           $this->current->save();
142           $this->dialogOpen =false;
143           $this->Clear();
144         }
145       }
146       if($this->current){
147         $smarty = get_smarty(); 
148         $smarty->assign("Complete",false);
149         $smarty->assign("AttributesToFix",$this->generateAttributesToFix());    
150         $smarty->assign("SubDialog",$this->current->SubDialog);
151         $smarty->assign("objectDN"               ,$this->objectdn);     
152         $smarty->assign("message", sprintf(_("You are going to copy the entry '%s'."), $this->objectdn));       
153         return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
154       }
155     }
156   }
158   /* Create dialog which asks unique attributes/values ... 
159    *  call tabs -> getCopyDialog() 
160    *    which calls tab -> getCopyDialog()  */
161   function generateAttributesToFix()
162   {
163     if($this->current){
164       return($this->current->getCopyDialog());  
165     }
166   }
169   /* Set a single attribute to specified value
170    *  example :   ("base", $newBase );    */
171   function SetVar($name,$value)
172   {
173     foreach($this->     current->by_object as $key => $obj){
174       if(isset($this->current->by_object[$key]->$name)){
175         $this->current->by_object[$key]->$name = $value;
176       }
177     }
178   }
181   /* Save new values posted by copy & paste dialog */
182   function save_object()
183   {
184     /* Assign posted var to all tabs
185      */
186     if($this->current){
187       $this->current->saveCopyDialog();
188     }
189   }
192   /* Returns errors from including tabs. */
193   function check()
194   {
195     $ret = array();
196     foreach($this->     current->by_object as $obj){
197       if($obj->is_account){
198         $ret = array_merge($ret , $obj->check());
199       }
200     }
201     return($ret);
202   }
204   
205   /* returns the paste icon for headpages */ 
206   function generatePasteIcon()
207   {
208     $Copy_Paste= "&nbsp;<img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
209     if($this->isCurrentObjectPastAble()){
210       if($this->isCurrentCutted()){
211         $img= "images/cutpaste.png";
212       }else{
213         $img= "images/copypaste.png";
214       }
215       $Copy_Paste.= "<input type='image' name='editPaste' class='center'
216         src='".$img."' alt='"._("Paste")."' title='".$this->GetCurrentDn()."'>&nbsp;";
217     }else{
218       $Copy_Paste.= "<img class='center' src='images/cant_editpaste.png' alt='"._("Can't paste")."'>&nbsp;";
219     }
221     return ($Copy_Paste);
222   }
225 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
226 ?>