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){
60 /* Prepare every single class, to be copied */
61 $this->current->by_object[$name]->PrepareForCopyPaste($obj);
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){
128 $msgs = $this->check();
129 if(count ($msgs) ){
130 foreach( $msgs as $msg){
131 print_red($msg);
132 }
133 $this->dialogOpen =false;
134 }else{
135 $this->current->save();
136 $this->dialogOpen =false;
137 $this->Clear();
138 }
139 /* Copy & paste
140 */
141 }else{
142 if(isset($_POST['PerformCopyPaste'])){
143 $msgs = $this->check();
144 if(count ($msgs) ){
145 foreach( $msgs as $msg){
146 print_red($msg);
147 }
148 }else{
149 $this->current->save();
150 $this->lastdn = $this->current->dn;
151 $this->dialogOpen =false;
152 $this->Clear();
153 }
154 }
155 if($this->current){
156 $smarty = get_smarty();
157 $smarty->assign("Complete",false);
158 $smarty->assign("AttributesToFix",$this->generateAttributesToFix());
159 $smarty->assign("SubDialog",$this->current->SubDialog);
160 $smarty->assign("objectDN" ,$this->objectdn);
161 $smarty->assign("message", sprintf(_("You are going to copy the entry '%s'."), $this->objectdn));
162 return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
163 }
164 }
165 }
167 /* Create dialog which asks unique attributes/values ...
168 * call tabs -> getCopyDialog()
169 * which calls tab -> getCopyDialog() */
170 function generateAttributesToFix()
171 {
172 if($this->current){
173 return($this->current->getCopyDialog());
174 }
175 }
178 /* Set a single attribute to specified value
179 * example : ("base", $newBase ); */
180 function SetVar($name,$value)
181 {
182 foreach($this-> current->by_object as $key => $obj){
183 if(isset($this->current->by_object[$key]->$name)){
184 $this->current->by_object[$key]->$name = $value;
185 }
186 }
187 }
190 /* Save new values posted by copy & paste dialog */
191 function save_object()
192 {
193 /* Assign posted var to all tabs
194 */
195 if($this->current){
196 $this->current->saveCopyDialog();
197 }
198 }
201 /* Returns errors from including tabs. */
202 function check()
203 {
204 $ret = array();
205 foreach($this-> current->by_object as $obj){
206 if($obj->is_account){
207 $ret = array_merge($ret , $obj->check());
208 }
209 }
210 return($ret);
211 }
214 /* returns the paste icon for headpages */
215 function generatePasteIcon()
216 {
217 $Copy_Paste= " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
218 if($this->isCurrentObjectPastAble()){
219 if($this->isCurrentCutted()){
220 $img= "images/cutpaste.png";
221 }else{
222 $img= "images/copypaste.png";
223 }
224 $Copy_Paste.= "<input type='image' name='editPaste' class='center'
225 src='".$img."' alt='"._("Paste")."' title='".$this->GetCurrentDn()."'> ";
226 }else{
227 $Copy_Paste.= "<img class='center' src='images/cant_editpaste.png' alt=\""._("Can't paste")."\" > ";
228 }
230 return ($Copy_Paste);
231 }
233 }
234 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
235 ?>