root/afridex/plugins/Flutter/RCCWP_CustomWritePanelPage.php @ 23

Revision 21, 14.6 kB (checked in by admin, 18 years ago)
Line 
1<?php
2include_once('RCCWP_CustomWritePanel.php');
3
4class RCCWP_CustomWritePanelPage
5{
6        function Content($customWritePanel = null)
7        {
8                $customWritePanelName = "";
9                $customWritePanelDescription = "";
10                $write_panel_category_ids = array();
11                $defaultTagChecked = 'checked="checked"';
12                $showPost = true;
13                if ($customWritePanel != null)
14                {
15                        $customWritePanelName = $customWritePanel->name;
16                        $customWritePanelDescription = $customWritePanel->description;
17                        $customWritePanelDisplayOrder = $customWritePanel->display_order;
18                        $customWritePanelType = $customWritePanel->type;
19                        if ($customWritePanelType == 'page') $showPost = false;
20                        $customWritePanelCategoryIds = RCCWP_CustomWritePanel::GetAssignedCategoryIds($customWritePanel->id);
21                        $customWritePanelStandardFieldIds = RCCWP_CustomWritePanel::GetStandardFields($customWritePanel->id);
22                        $defaultTagChecked = '';
23                        ?>
24                        <input type="hidden" name="custom-write-panel-id" value="<?php echo $customWritePanel->id?>" />
25                        <?php
26                }
27               
28                ?>
29
30
31                <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
32                <tbody>
33                <tr valign="top">
34                        <th scope="row">Placement</th>
35                        <td>
36                                <!-- START :: Javascript for Image/Photo' Css Class -->
37                                <script type="text/javascript" language="javascript">
38                                        jQuery(document).ready( function() {
39                                                        <?php if ($showPost){ ?>
40                                                                showHide("flutter_forpost", "flutter_forpage");
41                                                        <?php } else { ?>
42                                                                showHide("flutter_forpage", "flutter_forpost");
43                                                        <?php } ?>
44                                                });
45                                               
46                                        function showHide(showClassID, hideClassID)
47                                        {
48                                                jQuery( function($) {
49                                                        $("."+showClassID).css("display","");
50                                                        $("."+hideClassID).css("display","none");
51                                                        });
52                                        }
53                                </script>
54                                <!-- END :: Javascript for Image/Photo' Css Class -->
55                                <input type="radio" name="radPostPage" id="radPostPage" value="post" <?php if($customWritePanelType == 'post' || $customWritePanel == null){?> checked="checked" <?php } ?> onclick='showHide("flutter_forpost", "flutter_forpage");' /> <strong>Post </strong> &nbsp; &nbsp; &nbsp;
56                                <input type="radio" name="radPostPage" id="radPostPage" value="page" <?php if($customWritePanelType == 'page'){?> checked="checked" <?php } ?> onclick='showHide("flutter_forpage", "flutter_forpost");' /> <strong>Page</strong>
57                        </td>
58                </tr>
59
60
61                <tr valign="top">
62                        <th scope="row"  align="right">Name:</th>
63                        <td>
64                                <input name="custom-write-panel-name" id="custom-write-panel-name" size="40" type="text" value="<?php echo $customWritePanelName?>" />
65                        </td>
66                </tr>
67
68       
69                <tr valign="top"  id="catText">
70                        <th scope="row"  align="right"><div id="catLabel" style="display:inline;">Assigned Categories:</div></th>
71                        <td>
72                               
73                                <?php
74                                $cats = RCCWP_Application::GetWpCategories();
75       
76                                foreach ($cats as $cat) : 
77                                        $checked = "";
78                                        if(isset($customWritePanel->id) && !empty($customWritePanel->id))
79                                        {
80                                                if (in_array($cat->cat_ID, $customWritePanelCategoryIds))
81                                                {
82                                                        $checked = "checked=\"checked\"";
83                                                }
84                                        }
85                                ?>
86                                        <input type="checkbox" name="custom-write-panel-categories[]" value="<?php echo $cat->cat_ID?>" <?php echo $checked?> /> <?php echo $cat->cat_name ?> <br/>
87                                <?php
88                                endforeach;
89                                ?>
90                               
91                        </td>
92                </tr>
93
94
95                <tr valign="top">
96                        <th scope="row" align="right">Standard Fields:</th>
97                        <td>
98                                <?php 
99                                        global $STANDARD_FIELDS, $wp_version;
100                                        foreach ($STANDARD_FIELDS as $field) :
101                                                if ($field->excludeVersion <= substr($wp_version, 0, 3)) continue;
102                                                if ($field->isAdvancedField) continue;
103                                               
104                                                $checked = "";
105                                                $classes = "";
106                                                if ($customWritePanel != null)
107                                                {
108                                                        if (in_array($field->id, $customWritePanelStandardFieldIds))
109                                                        {
110                                                                $checked = "checked=\"checked\"";
111                                                        }
112                                                }
113                                                else
114                                                {
115                                                        if ($field->defaultChecked)
116                                                        {
117                                                                $checked = "checked=\"checked\""; 
118                                                        }
119                                                }
120                                               
121                                                if ($field->forPost && !$field->forPage) $classes = $classes . " flutter_forpost";
122                                                if ($field->forPage && !$field->forPost) $classes = $classes . " flutter_forpage";
123                                ?>
124                                        <div class="<?php echo $classes?>">
125                                                <input type="checkbox" name="custom-write-panel-standard-fields[]" value="<?php echo $field->id?>" <?php echo $checked?> />
126                                                <?php echo $field->displayName?> 
127                                                <br />
128                                        </div>
129                                <?php
130                                        endforeach;
131                                ?>
132                        </td>
133                </tr>
134
135                <tr valign="top">
136                        <th scope="row" align="right">Advanced Fields:</th>
137                        <td>
138                                <?php 
139                                        global $STANDARD_FIELDS, $wp_version;
140                                        foreach ($STANDARD_FIELDS as $field) :
141                                                if ($field->excludeVersion <= substr($wp_version, 0, 3)) continue;
142                                                if (!$field->isAdvancedField) continue;
143                                               
144                                                $checked = "";
145                                                $classes = "";
146                                                if ($customWritePanel != null)
147                                                {
148                                                        if (in_array($field->id, $customWritePanelStandardFieldIds))
149                                                        {
150                                                                $checked = "checked=\"checked\"";
151                                                        }
152                                                }
153                                                else
154                                                {
155                                                        if ($field->defaultChecked)
156                                                        {
157                                                                $checked = "checked=\"checked\""; 
158                                                        }
159                                                }
160                                                if ($field->forPost && !$field->forPage) $classes = $classes . " flutter_forpost";
161                                                if ($field->forPage && !$field->forPost) $classes = $classes . " flutter_forpage";
162                                               
163                                ?>
164                                        <div class="<?php echo $classes?>">
165                                                <input type="checkbox" name="custom-write-panel-standard-fields[]" value="<?php echo $field->id?>" <?php echo $checked?> />
166                                                <?php echo $field->displayName?> 
167                                                <br />
168                                        </div>
169                                <?php
170                                        endforeach;
171                                ?>
172                        </td>
173                </tr>
174
175                <tr valign="top">
176                        <th scope="row" align="right">Order:</th>
177                        <td><input name="custom-write-panel-order" id="custom-write-panel-order" size="2" type="text" value="<?php echo $customWritePanelDisplayOrder?>" /></td>
178                </tr>
179
180                <?php
181                if (!isset($customWritePanel)) :
182                ?>
183                <tr>
184                        <th scope="row" align="right">Custom Fields:</th>
185                        <td>Add custom fields later by editing this custom write panel.</td>
186                </tr>
187                <?php
188                endif;
189                ?>
190                </tbody>
191                </table>
192               
193                <?php
194        }
195       
196        function Edit()
197        {
198                $customWritePanel = RCCWP_CustomWritePanel::Get((int)$_REQUEST['custom-write-panel-id']);
199                ?>
200                <div class="wrap">
201               
202                <h2>Edit <?php echo $customWritePanel->name ?> Write Panel</h2>
203               
204                <form action="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('submit-edit-custom-write-panel')?>" method="post" id="submit-edit-custom-write-panel">
205               
206                <?php
207                RCCWP_CustomWritePanelPage::Content($customWritePanel);
208                ?>
209               
210                <p class="submit" >
211                        <a  style="color:black" href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('cancel-edit-custom-write-panel')?>" class="button"><?php _e('Cancel'); ?></a>
212                        <input type="submit" id="submit-edit-custom-write-panel" value="<?php _e('Update'); ?>" />
213                </p>
214                </form>
215               
216                </div>
217               
218                <?php
219        }
220       
221        function GetAssignedCategoriesString($customWritePanel)
222        {
223                $results = RCCWP_CustomWritePanel::GetAssignedCategories($customWritePanel);
224                $str = '';
225                foreach ($results as $r)
226                {
227                        $str .= $r->cat_name . ', ';   
228                }
229                $str = substr($str, 0, strlen($str) - 2); // deletes last comma and whitespace
230                return $str;
231        }
232       
233        function GetStandardFieldsString($customWritePanel)
234        {
235                $results = RCCWP_CustomWritePanel::GetStandardFields($customWritePanel);
236                foreach ($results as $r)
237                {
238                        $str .= $r->name . ', ';       
239                }
240                $str = substr($str, 0, strlen($str) - 2); // deletes last comma and whitespace
241                return $str;
242        }
243       
244       
245        /**
246         * View groups/fields of a write panel
247         *
248         */
249        function View()
250        {
251                //if(isset($_GET['custom-write-panel-id']) && !empty($_GET['custom-write-panel-id']) )
252                       
253                //if(isset($_POST['custom-write-panel-id']) && !empty($_POST['custom-write-panel-id']) )
254                        //$customWritePanelId = (int)$_POST['custom-write-panel-id'];
255                       
256                $customWritePanelId = (int)$_REQUEST['custom-write-panel-id'];
257
258                $customWritePanels = RCCWP_CustomWritePanel::GetCustomWritePanels();
259                $customWritePanel = RCCWP_CustomWritePanel::Get($customWritePanelId);
260                $custom_groups = RCCWP_CustomWritePanel::GetCustomGroups($customWritePanelId);
261               
262                // get default group id
263                foreach ($custom_groups as $group){
264                        if ($group->name == '__default'){
265                                $customDefaultGroupId = $group->id;
266                                break;
267                        }
268                }
269                       
270               
271                ?>
272
273                <script type="text/javascript" language="javascript">
274                        function confirmBeforeDelete()
275                        {
276                                return confirm("Are you sure you want to delete this write panel?");                                                   
277                        }
278                </script>
279                <div class="wrap">
280
281                <form action="<?php echo RCCWP_ManagementPage::GetPanelPage() . "&flutter_action=view-custom-write-panel"?>" method="post"  id="posts-filter" name="SelectWritePanel">
282                        <h2>
283                                <?php echo $customWritePanel->name?>
284                                <span style="font-size:small">
285                                        &nbsp; &nbsp;
286                                        <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('edit-custom-write-panel', $panel->id); ?>" ><?php _e('Edit'); ?></a>|
287                                        <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('delete-custom-write-panel', $panel->id); ?>" onclick="return confirmBeforeDelete();"><?php _e('Delete'); ?></a>|
288                                        <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('export-custom-write-panel', $panel->id); ?>" ><?php _e('Export'); ?></a>
289                                </span>
290                        </h2>
291                        <p id="post-search" style="margin-top:6px">
292                                <strong>
293                                        <?php _e('Choose a Write Panel')?>
294                                        <select name="custom-write-panel-id" style="margin-top:-2px" onchange="document.SelectWritePanel.submit()">
295                                                <?php
296                                                foreach ($customWritePanels as $panel) :
297                                                ?>
298                                                        <option <?php echo ($customWritePanelId==$panel->id?' selected ':''); ?> value="<?php echo $panel->id?>"><?php echo $panel->name;?></option>
299                                                <?php
300                                                endforeach;
301                                                ?>
302                                        </select>
303                                </strong>
304                                <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-group')?>" class="button-secondary"><?php _e('+ Create a Group')?></a>
305                                <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field')."&custom-group-id=$customDefaultGroupId"?>" class="button-secondary"><?php _e('+ Create a Field')?></a>
306                        </p>
307                </form>
308               
309                <br class="clear"/>
310
311                <table cellpadding="3" cellspacing="3" width="100%" class="widefat">
312                <thead>
313                        <tr>
314                                <th width="60%" scope="col">Name</th>
315                                <th width="20%" scope="col">Type</th>
316                                <th width="20%" scope="col">Actions</th>
317                        </tr>
318                </thead>
319                <tbody>
320                        <?php
321                        foreach ($custom_groups as $group) :
322                                if ($customDefaultGroupId != $group->id){                       
323                        ?>
324                                        <tr>
325                                                <td><strong><a style="color:#D54E21" href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('edit-custom-group')."&custom-group-id={$group->id}"?>"><?php echo $group->name?></a></strong>&nbsp;&nbsp;(<a style="font-size:very-small" href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field')."&custom-group-id={$group->id}"?>"><?php _e('create field'); ?></a>) </td>
326                                                <td>Group</td>
327                                                <td><a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('delete-custom-group')."&custom-group-id={$group->id}"?>"><?php _e('X Delete'); ?></a></td>
328                                               
329                                        </tr>
330                        <?php
331                                        RCCWP_CustomWritePanelPage::DisplayGroupFields($group->id, true);
332                                }
333                        endforeach;
334                        RCCWP_CustomWritePanelPage::DisplayGroupFields($customDefaultGroupId);
335                        ?>
336                </tbody>
337                </table>
338                </div>
339                <?php
340        }
341       
342        function DisplayGroupFields($customGroupId, $intended = false){
343                $custom_fields = RCCWP_CustomGroup::GetCustomFields($customGroupId);
344                foreach ($custom_fields as $field) :
345                ?>
346                        <tr>
347                                <td><a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('edit-custom-field')."&custom-field-id=$field->id"?> " ><?php if ($intended){ ?><img align="top" src="<?php echo FLUTTER_URI; ?>images/arrow_right.gif" alt=""/> <?php } ?><?php echo $field->description?></a></td>
348                                <td><?php echo $field->type?></td>
349                                <td><a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('delete-custom-field')."&custom-field-id=$field->id"?>" ><?php _e('X Delete'); ?></a></td>
350                               
351                        </tr>
352                       
353                <?php
354                endforeach;
355        }
356       
357        function Import()
358        {
359               
360                include_once('RCCWP_CustomWritePanel.php');
361               
362                if(isset($_FILES['import-write-panel-file']) && !empty($_FILES['import-write-panel-file']['tmp_name']) ) {
363                        $filePath = $_FILES['import-write-panel-file']['tmp_name'];
364                }
365                else {
366                        die("Error uploading file!");
367                }
368
369                $writePanelName = basename($_FILES['import-write-panel-file']['name'], ".pnl");
370                $panelID = RCCWP_CustomWritePanel::Import($filePath, $writePanelName);
371                unlink($filePath);
372               
373               
374                echo "<div class='wrap'><h3>The Write Panel was imported successfuly.</h3>";
375                echo '<p><a href="' . RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('view-custom-write-panel', $panelID).'"> Click here </a> to edit the write panel. </p>';
376                echo "</div>";
377               
378        }
379       
380        function ViewWritePanels()
381        {
382
383                $customWritePanels = RCCWP_CustomWritePanel::GetCustomWritePanels();
384                ?>
385
386                <div class="wrap">
387
388                <form action="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('import-write-panel')?>" method="post"  id="posts-filter" name="ImportWritePanelForm" enctype="multipart/form-data">
389                        <h2><?php _e('Custom Write Panel'); ?></h2>
390                        <p id="post-search">                                   
391                                <input id="import-write-panel-file" name="import-write-panel-file" type="file" />
392                                <a href="#none" class="button-secondary" style="display:inline" onclick="document.ImportWritePanelForm.submit();"><?php _e('Import a Write Panel'); ?></a>
393                                <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-write-panel'); ?>" class="button-secondary" style="display:inline"><?php _e('+ Create a Write Panel'); ?></a>
394                        </p>   
395                </form>
396                               
397                <br class="clear"/>
398               
399                <table cellpadding="3" cellspacing="3" width="100%" class="widefat">
400                        <thead>
401                                <tr>
402                                        <th scope="col" width="60%"><?php _e('Name'); ?></th>
403                                        <th colspan="4" style="text-align:center"><?php _e('Actions'); ?></th>
404                                </tr>
405                        </thead>
406                        <tbody>
407                                <?php
408                                foreach ($customWritePanels as $panel) :
409                                ?>
410                                        <tr">
411                                                <td><?php echo $panel->name ?></td>                     
412                                                <td><a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('view-custom-write-panel', $panel->id)?>" ><?php _e('Edit Fields/Groups') ?></a></td>
413                                                <td><a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('edit-custom-write-panel', $panel->id)?>" ><?php _e('Edit Write Panel') ?></a></td>
414                                                <td><a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('export-custom-write-panel', $panel->id); ?>" ><?php _e('Export'); ?></a></td>             
415                                        </tr>
416                                <?php
417                                endforeach;
418                                ?>
419                        </tbody>
420                </table>
421
422                </div>
423                <?php 
424        }
425       
426       
427}
428?>
Note: See TracBrowser for help on using the browser.