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 /* Add Object which should be copied
46 */
47 function Copy($obj,$emptyObj)
48 {
49 $this->copyCurrent = true;
50 $this->objectdn = $obj->dn;
51 $this->current = $emptyObj;
52 foreach($obj->by_object as $name => $obj){
53 foreach($obj->attributes as $attr){
54 $this->current->by_object[$name]->$attr = $obj->$attr;
55 }
56 }
57 if($this->isCurrentObjectPastAble()){
58 return(true);
59 }else{
60 $this->cutCurrent = $this->copyCurrent = false;
61 $this->obj = NULL;
62 }
63 return(false);
64 }
67 /* Add Object which should be cutted
68 */
69 function Cut($obj){
70 $this->cutCurrent = true;
71 $this->current = $obj;
72 if($this->isCurrentObjectPastAble()){
73 return(true);
74 }else{
75 $this->cutCurrent = $this->copyCurrent = false;
76 $this->obj = NULL;
77 }
78 return(false);
79 }
82 /* Returns true if current object
83 * is cutted. And awaits to be pasted anywhere
84 */
85 function isCurrentCutted(){
86 return($this->cutCurrent);
87 }
90 /* Returns true if current object
91 * was copied, and awaits to be pasted again
92 */
93 function isCurrentCopied(){
94 return($this->copyCurrent);
95 }
98 /* stillOpen
99 */
100 function stillOpen(){
101 if(isset($_POST['AbortCopyPaste'])){
102 $this->dialogOpen = false;
103 }
105 return($this->dialogOpen);
106 }
109 /* Displays a dialog which allows the user to fix all dependencies of this object.
110 Create unique names, ids, or what ever
111 */
112 function execute()
113 {
114 $this->dialogOpen = true;
116 /* Cut & paste
117 */
118 if($this->cutCurrent){
119 $this->current->save();
120 $this->dialogOpen =false;
121 $smarty = get_smarty();
122 $smarty->assign("Complete",true);
123 $this->Clear();
124 return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
126 /* Copy & paste
127 */
128 }else{
129 if(isset($_POST['PerformCopyPaste'])){
130 $msgs = $this->check();
131 if(count ($msgs) ){
132 foreach( $msgs as $msg){
133 print_red($msg);
134 }
135 }else{
136 $this->current->save();
137 $this->dialogOpen =false;
138 $smarty = get_smarty();
139 $smarty->assign("Complete",true);
140 $this->Clear();
141 return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
142 }
143 }
144 $smarty = get_smarty();
145 $smarty->assign("Complete",false);
146 $smarty->assign("AttributesToFix",$this->generateAttributesToFix());
147 $smarty->assign("objectDN" ,$this->objectdn);
148 return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE)));
149 }
150 }
152 /* Create dialog which asks unique attributes values ...
153 * calls tabs -> getCopyDialog()
154 * which calls tab -> getCopyDialog()
155 */
156 function generateAttributesToFix()
157 {
158 return($this->current->getCopyDialog());
159 }
162 /* Set a single attribute to specified value
163 * example : ("base", $newBase );
164 */
165 function SetVar($name,$value)
166 {
167 foreach($this-> current->by_object as $key => $obj){
168 if(isset($this->current->by_object[$key]->$name)){
169 $this->current->by_object[$key]->$name = $value;
170 }
171 }
172 }
175 /* Save new values posted by copy & paste dialog
176 */
177 function save_object()
178 {
179 /* Assign posted var to all tabs
180 */
181 $this->current->saveCopyDialog();
182 }
185 /* Returns possible errors returned from all including tabs ..
186 */
187 function check()
188 {
189 $ret = array();
190 foreach($this-> current->by_object as $obj){
191 $ret = array_merge($ret , $obj->check());
192 }
193 return($ret);
194 }
196 }
197 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
198 ?>