Code

Added new images which indicates the status of the object.
[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   /* Create CP handler
14    */
15   function CopyPasteHandler($config){
16     $this->config = $config;    
17     $this->current= NULL;
18   }
21   /* Returns wether the current object can be pasted 
22    */   
23   function isCurrentObjectPastAble(){
25     /* Check if we got a valid object 
26      */
27     if($this->current == NULL){
28       return(false);
29     }
30     return(true);
31   }     
34   /* Clears all copy & paste informations 
35    */
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    */
47   function GetCurrentDn()
48   {
49     return($this->objectdn);
50   }
53   /* Add Object which should be copied
54    */
55   function Copy($obj,$emptyObj)
56   {
57     $this->copyCurrent = true;
58     $this->objectdn    = $obj->dn;
59     $this->current = $emptyObj;
60     foreach($obj->by_object as $name => $obj){
61       foreach($obj->attributes as $attr){
62         $this->current->by_object[$name]->$attr = $obj->$attr;
63       }
64     }
65     if($this->isCurrentObjectPastAble()){
66       return(true);
67     }else{
68       $this->cutCurrent = $this->copyCurrent = false;
69       $this->obj = NULL;
70     }
71     return(false);
72   }
75   /* Add Object which should be cutted
76    */
77   function Cut($obj){
78     $this->cutCurrent = true;
79     $this->current        = $obj;
80     $this->objectdn    = $obj->dn;
81     if($this->isCurrentObjectPastAble()){
82       return(true);
83     }else{
84       $this->cutCurrent = $this->copyCurrent = false;
85       $this->obj = NULL;
86     }
87     return(false);
88   }
91   /* Returns true if current object 
92    *  is cutted. And awaits to be pasted anywhere
93    */
94   function isCurrentCutted(){
95     return($this->cutCurrent);
96   }
99   /* Returns true if current object  
100    *  was copied, and awaits to be pasted again
101    */
102   function isCurrentCopied(){
103     return($this->copyCurrent);
104   }
107   /* stillOpen
108    */
109   function stillOpen(){ 
110     if(isset($_POST['AbortCopyPaste'])){
111       $this->dialogOpen = false;
112     }
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          */
121         function execute()
122         {
123                 $this->dialogOpen = true;
125                 /* Cut & paste
126          */
127                 if($this->cutCurrent){
128                         $this->current->save();
129                         $this->dialogOpen =false;
130                         $smarty = get_smarty();
131                         $smarty->assign("Complete",true);
132                         $this->Clear();
133                         return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
135                 /* Copy & paste
136          */
137                 }else{
138                         if(isset($_POST['PerformCopyPaste'])){
139                                 $msgs = $this->check(); 
140                                 if(count ($msgs) ){
141                                         foreach( $msgs as $msg){
142                                                 print_red($msg);
143                                         }
144                                 }else{
145                                         $this->current->save();
146                                         $this->dialogOpen =false;
147                                         $smarty = get_smarty(); 
148                                         $smarty->assign("Complete",true);
149                                         $this->Clear();
150                                         return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
151                                 }
152                         }
153                         $smarty = get_smarty(); 
154                         $smarty->assign("Complete",false);
155                         $smarty->assign("AttributesToFix",$this->generateAttributesToFix());    
156                         $smarty->assign("objectDN"               ,$this->objectdn);     
157                         return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
158                 }
159         }
161   /* Create dialog which asks unique attributes values ... 
162    *  calls tabs -> getCopyDialog() 
163    *    which calls tab -> getCopyDialog()
164    */
165         function generateAttributesToFix()
166         {
167                 return($this->current->getCopyDialog());
168         }
171   /* Set a single attribute to specified value
172    *  example :   ("base", $newBase );
173    */
174         function SetVar($name,$value)
175         {
176                 foreach($this-> current->by_object as $key => $obj){
177                         if(isset($this->current->by_object[$key]->$name)){
178                                 $this->current->by_object[$key]->$name = $value;
179                         }
180                 }
181         }
184   /* Save new values posted by copy & paste dialog
185   */
186         function save_object()
187         {
188                 /* Assign posted var to all tabs
189      */
190     $this->current->saveCopyDialog();
191   }
194   /* Returns possible errors returned from all including tabs ..
195    */
196         function check()
197         {
198                 $ret = array();
199                 foreach($this-> current->by_object as $obj){
200                         $ret = array_merge($ret , $obj->check());
201                 }
202                 return($ret);
203         }
206 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
207 ?>