Code

Updated sieve templates
[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;
59     if(!isset($obj->by_object)){
60       trigger_error("No valid tab object specified for copy & paste.");
61       return;
62     }
63     
64     foreach($obj->by_object as $name => $obj){
65     
66       /* Prepare every single class, to be copied  */
67       $this->current->by_object[$name]->PrepareForCopyPaste($obj);
68  
69       /* handle some special vars */ 
70       foreach(array("is_account") as $attr){
71         if(isset($obj->$attr)){
72           $this->current->by_object[$name]->$attr = $obj->$attr;
73         }
74       }
75     }
76     if($this->isCurrentObjectPastAble()){
77       return(true);
78     }else{
79       $this->cutCurrent = $this->copyCurrent = false;
80       $this->obj = NULL;
81     }
82     return(false);
83   }
86   /* Add Object which should be cutted  */
87   function Cut($obj){
88     $this->cutCurrent = true;
89     $this->current        = $obj;
90     $this->objectdn    = $obj->dn;
91     if($this->isCurrentObjectPastAble()){
92       return(true);
93     }else{
94       $this->cutCurrent = $this->copyCurrent = false;
95       $this->obj = NULL;
96     }
97     return(false);
98   }
101   /* Returns true if current object 
102    *  is cutted. And awaits to be pasted anywhere  */
103   function isCurrentCutted(){
104     return($this->cutCurrent);
105   }
108   /* Returns true if current object  
109    *  was copied, and awaits to be pasted again  */
110   function isCurrentCopied(){
111     return($this->copyCurrent);
112   }
115   /* Returns true if the copy$paste dialog is still open  */
116   function stillOpen(){ 
117     if(isset($_POST['AbortCopyPaste'])){
118       $this->dialogOpen = false;
119     }
120     return($this->dialogOpen);
121   }
124   /* Displays a dialog which allows the user to fix all dependencies of this object.
125      Create unique names, ids, or what ever */
126   function execute()
127   {
128     $this->dialogOpen = true;
130     /* Cut & paste
131      */
132     if($this->cutCurrent){
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("type","cut");
149         $smarty->assign("Complete",false);
150         $smarty->assign("AttributesToFix","&nbsp;");
151         $smarty->assign("SubDialog",$this->current->SubDialog);
152         $smarty->assign("objectDN"     ,$this->objectdn);
153         $smarty->assign("message", sprintf(_("You are going to paste the cutted entry '%s'."), $this->objectdn));
154         return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
155       }
157       /* Copy & paste
158        */
159     }else{
160       if(isset($_POST['PerformCopyPaste'])){
161         $msgs = $this->check(); 
162         if(count ($msgs) ){
163           foreach( $msgs as $msg){
164             print_red($msg);
165           }
166         }else{
167           $this->current->save();
168           $this->lastdn = $this->current->dn;
169           $this->dialogOpen =false;
170           $this->Clear();
171         }
172       }
173       if($this->current){
174         $smarty = get_smarty(); 
175         $smarty->assign("type","copy");
176         $smarty->assign("Complete",false);
177         $smarty->assign("AttributesToFix",$this->generateAttributesToFix());    
178         $smarty->assign("SubDialog",$this->current->SubDialog);
179         $smarty->assign("objectDN"               ,$this->objectdn);     
180         $smarty->assign("message", sprintf(_("You are going to paste the copied entry '%s'."), $this->objectdn));       
181         return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
182       }
183     }
184   }
186   /* Create dialog which asks unique attributes/values ... 
187    *  call tabs -> getCopyDialog() 
188    *    which calls tab -> getCopyDialog()  */
189   function generateAttributesToFix()
190   {
191     if($this->current){
192       return($this->current->getCopyDialog());  
193     }
194   }
197   /* Set a single attribute to specified value
198    *  example :   ("base", $newBase );    */
199   function SetVar($name,$value)
200   {
201     foreach($this->     current->by_object as $key => $obj){
202       if(isset($this->current->by_object[$key]->$name)){
203         $this->current->by_object[$key]->$name = $value;
204       }
205     }
206   }
209   /* Save new values posted by copy & paste dialog */
210   function save_object()
211   {
212     /* Assign posted var to all tabs
213      */
214     if($this->current){
215       $this->current->saveCopyDialog();
216     }
217   }
220   /* Returns errors from including tabs. */
221   function check()
222   {
223     $ret = array();
224     foreach($this->     current->by_object as $obj){
225       if($obj->is_account){
226         $ret = array_merge($ret , $obj->check());
227       }
228     }
229     return($ret);
230   }
232   
233   /* returns the paste icon for headpages */ 
234   function generatePasteIcon()
235   {
236     $Copy_Paste= "&nbsp;<img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
237     if($this->isCurrentObjectPastAble()){
238       if($this->isCurrentCutted()){
239         $img= "images/cutpaste.png";
240       }else{
241         $img= "images/copypaste.png";
242       }
243       $Copy_Paste.= "<input type='image' name='editPaste' class='center'
244         src='".$img."' alt='"._("Paste")."' title='".$this->GetCurrentDn()."'>&nbsp;";
245     }else{
246       $Copy_Paste.= "<img class='center' src='images/cant_editpaste.png' alt=\""._("Can't paste")."\">&nbsp;";
247     }
249     return ($Copy_Paste);
250   }
253 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
254 ?>