Dotclear

source: plugins/myDashboard/index.php @ 1729

Revision 1729, 8.9 KB checked in by kozlika, 14 years ago (diff)

mydashboard: typo.

  • Property svn:executable set to *
Line 
1<?php
2# ***** BEGIN LICENSE BLOCK *****
3#
4# This file is part of My Dashboard, a plugin for Dotclear 2
5# Copyright (C) 2009 Moe (http://gniark.net/)
6#
7# My Dashboard is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License v2.0
9# as published by the Free Software Foundation.
10#
11# My Dashboard is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software Foundation,
18# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19#
20# Icon (icon.png) is from Silk Icons : http://www.famfamfam.com/lab/icons/silk/
21#
22# ***** END LICENSE BLOCK *****
23
24if (!defined('DC_CONTEXT_ADMIN')) {return;}
25
26dcPage::checkSuper();
27
28$tab = 'links';
29
30$settings =& $core->blog->settings;
31
32$msg = (string)'';
33
34$title = $url = $icon = (string)'';
35
36$title_edit = $url_edit = $icon_edit = (string)'';
37
38if (isset($_GET['edit_link']))
39{
40     $link_id = $_GET['edit_link'];
41     
42     $links = myDashboard::loadLinks();
43     
44     $link = $links[$link_id];
45     
46     $title_edit = $link['title'];
47     $url_edit = $link['url'];
48     $icon_edit = $link['icon'];
49     
50     $tab = 'edit-link';
51}
52
53# save order
54if (!empty($_POST['saveorder']))
55{
56     try
57     {
58          $links = array();
59         
60          foreach ($_POST['title'] as $k => $v)
61          {
62               $title = $v;
63               $url = $_POST['url'][$k];
64               $icon = $_POST['icon'][$k];
65               
66               myDashboard::addLink($links,$title,$url,$icon);
67          }
68         
69          myDashboard::saveLinks($links);
70         
71          http::redirect($p_url.'&saveorder=1');
72     }
73     catch (Exception $e)
74     {
75          $core->error->add($e->getMessage());
76     }
77}
78elseif ((!empty($_POST['removeaction'])) && (!empty($_POST['remove'])))
79{
80     try
81     {
82          $links = myDashboard::loadLinks();
83         
84          foreach ($_POST['remove'] as $k => $v)
85          {
86               unset($links[$v]);
87          }
88         
89          myDashboard::saveLinks($links);
90         
91          http::redirect($p_url.'&removed=1');
92     }
93     catch (Exception $e)
94     {
95          $core->error->add($e->getMessage());
96     }
97}
98elseif (!empty($_POST['add_link']))
99{
100     $tab = 'add-link';
101     
102     try
103     {
104          $links = myDashboard::loadLinks();
105         
106          $title = $_POST['title'];
107          $url = $_POST['url'];
108          $icon = $_POST['icon'];
109         
110          if (empty($title)) {throw new Exception(__('Empty title'));}
111         
112          if (empty($url)) {throw new Exception(__('Empty URL'));}
113         
114          myDashboard::addLink($links,$title,$url,$icon);
115     }
116     catch (Exception $e)
117     {
118          $core->error->add($e->getMessage());
119     }
120     
121     if (!$core->error->flag()) {
122          http::redirect($p_url.'&addlink=1');
123     }
124}
125elseif (!empty($_POST['edit_link']))
126{
127     $tab = 'add-link';
128     
129     try
130     {
131          $links = myDashboard::loadLinks();
132         
133          $link_id = $_GET['edit_link'];
134         
135          $title = $_POST['title'];
136          $url = $_POST['url'];
137          $icon = $_POST['icon'];
138         
139          if (empty($title)) {throw new Exception(__('Empty title'));}
140         
141          if (empty($url)) {throw new Exception(__('Empty URL'));}
142         
143          $links[$link_id] = array(
144               'title' => $title,
145               'url' => $url,
146               'icon' => $icon,
147          );
148         
149          myDashboard::saveLinks($links);
150     }
151     catch (Exception $e)
152     {
153          $core->error->add($e->getMessage());
154     }
155     
156     if (!$core->error->flag()) {
157          http::redirect($p_url.'&edit_link='.$link_id.'&link_saved=1');
158     }
159}
160
161if (isset($_GET['saveorder']))
162{
163     $msg = __('Items order has been successfully updated');
164}
165elseif (isset($_GET['removed']))
166{
167     $msg = __('Items have been successfully removed.');
168}
169elseif (isset($_GET['addlink']))
170{
171     $msg = __('Link has been successfully created.');
172}
173elseif (isset($_GET['link_saved']))
174{
175     $msg = __('Link has been successfully updated');
176}
177
178$links = myDashboard::loadLinks();
179
180?><html>
181<head>
182     <title><?php echo __('My Dashboard'); ?></title>
183     <?php echo dcPage::jsPageTabs($tab).
184          dcPage::jsToolMan().
185     dcPage::jsConfirmClose('links-form','add-link-form',
186          'add-category-form'); ?>
187  <script type="text/javascript">
188  //<![CDATA[
189 
190     <?php echo dcPage::jsVar('dotclear.msg.confirm_cleanconfig_delete',
191          __('Are you sure you want to delete settings?')).
192          dcPage::jsVar('dotclear.msg.confirm_remove',
193          __('Are you sure you want to delete selected links?')); ?>
194     
195  var dragsort = ToolMan.dragsort();
196  $(function() {
197     dragsort.makeTableSortable($("#links-list").get(0),
198     dotclear.sortable.setHandle,dotclear.sortable.saveOrder);
199     
200          $('.checkboxes-helpers').each(function() {
201               dotclear.checkboxesHelpers(this);
202          });
203         
204          $('input[@name="removeaction"]').click(function() {
205                    return window.confirm(dotclear.msg.confirm_remove);
206               });
207  });
208 
209  dotclear.sortable = {
210       setHandle: function(item) {
211          var handle = $(item).find('td.handle').get(0);
212          while (handle.firstChild) {
213               handle.removeChild(handle.firstChild);
214          }
215         
216          item.toolManDragGroup.setHandle(handle);
217          handle.className = handle.className+' handler';
218       },
219       
220       saveOrder: function(item) {
221          var group = item.toolManDragGroup;
222          var order = document.getElementById('links_order');
223          group.register('dragend', function() {
224               order.value = '';
225               items = item.parentNode.getElementsByTagName('tr');
226               
227               for (var i=0; i<items.length; i++) {
228                    order.value += items[i].id.substr(2)+',';
229               }
230          });
231       }
232  };
233  //]]>
234  </script>
235     <?php echo(dcPage::jsConfirmClose('links-form','add-link-form',
236          'edit-link-form')); ?>
237</head>
238<body>
239
240     <h2><?php echo html::escapeHTML($core->blog->name).' &rsaquo; '.
241          __('My Dashboard'); ?></h2>
242     
243     <?php 
244          if (!empty($msg)) {echo '<p class="message">'.$msg.'</p>';}
245     ?>
246     
247     <!--<?php echo('<pre>'.print_r($links,true).'</pre>'); ?>-->
248     
249     <div class="multi-part" id="links" title="<?php echo __('Links'); ?>">
250          <form method="post" id="links-form" action="<?php echo http::getSelfURI(); ?>">
251               <table class="clear maximal dragable">
252                    <thead>
253                         <tr>
254                              <th colspan="3"><?php echo __('Title'); ?></th>
255                              <th><?php echo __('URL'); ?></th>
256                              <th><?php echo __('Image URL'); ?></th>
257                         </tr>
258                    </thead>
259                    <tbody id="links-list">
260                    <?php
261                         $i = 0;
262                         
263                         foreach ($links as $id => $v)
264                         {
265                              echo('<tr class="line" id="l_'.$i.'">'.
266                             
267                              '<td class="handle minimal">&nbsp;</td>'.
268                             
269                              '<td class="minimal">'.
270                                   form::checkbox(array('remove[]'),$i).'</td>'.
271                              '<td class="minimal">'.
272                                   '<a href="'.$p_url.'&edit_link='.$i.'">'.$v['title'].'</a>'.
273                                   form::hidden(array('title[]'),$v['title']).
274                                   form::hidden(array('url[]'),$v['url']).
275                                   form::hidden(array('icon[]'),$v['icon']).
276                              '</td>'.
277                              '<td class="minimal">'.$v['url'].'</td>'.
278                              '<td class="minimal">'.$v['icon'].'</td>'.
279                              '</tr>');
280                              $i++;
281                         }
282                    ?>
283                    </tbody>
284               </table>
285               
286               <p><?php echo form::hidden('links_order',''); ?></p>
287               <p><?php echo $core->formNonce(); ?></p>
288               <p>
289                    <input type="submit" name="saveorder"
290                         value="<?php echo __('Save order'); ?>" />
291                    <input type="submit" name="removeaction"
292                         value="<?php echo __('Delete selected links'); ?>" />
293               </p>
294          </form>
295     </div>
296     
297     <div class="multi-part" id="add-link" title="<?php echo __('Add a link'); ?>">
298          <form method="post" id="add-link-form" action="<?php echo http::getSelfURI(); ?>">
299               <?php
300                    echo('<p>'.
301                         '<label class="required" title="'.__('Required field').'">'.
302                         __('Title:').
303                         form::field('title',40,255,$title).
304                         '</label></p> '.
305                         '<p><label class="required"  title="'.__('Required field').'">'.
306                         __('URL:').
307                         form::field('url',40,255,$url).
308                         '</label></p> '.
309                         '<p><label>'.__('Icon:').
310                         form::field('icon',40,255,$icon).
311                         /*'<a href="'.$p_url.'&amp;file=media&amp;link_id='.
312                              $i.'">&nbsp;'.
313                              '<img src="images/plus.png" alt="'.
314                              __('Use a image from the media manager').'" />'.
315                              '</a>'.*/
316                         '</label>'.
317                         '</p>');
318                    ?>
319                    </tbody>
320               </table>
321               <p><?php echo $core->formNonce(); ?></p>
322               <p><input type="submit" name="add_link"
323                    value="<?php echo __('save'); ?>" /></p>
324          </form>
325     </div>
326     
327     <?php if (isset($_GET['edit_link'])) { ?>
328     
329     <div class="multi-part" id="edit-link" title="<?php echo __('Edit link'); ?>">
330          <form method="post" id="edit-link-form" action="<?php echo http::getSelfURI(); ?>">
331               <?php
332                    echo('<p>'.
333                         '<label class="required" title="'.__('Required field').'">'.
334                         __('Title:').
335                         form::field('title',40,255,$title_edit).
336                         '</label></p> '.
337                         '<p><label class="required"  title="'.__('Required field').'">'.
338                         __('URL:').
339                         form::field('url',40,255,$url_edit).
340                         '</label></p> '.
341                         '<p><label>'.__('Icon:').
342                         form::field('icon',40,255,$icon_edit).
343                         /*'<a href="'.$p_url.'&amp;file=media&amp;link_id='.
344                              $link_id.'">&nbsp;'.
345                              '<img src="images/plus.png" alt="'.
346                              __('Use a image from the media manager').'" />'.
347                              '</a>'.*/
348                         '</label>'.
349                         '</p>');
350                    ?>
351                    </tbody>
352               </table>
353               <p><?php echo form::hidden('edit_link',$link_id); ?></p>
354               <p><?php echo $core->formNonce(); ?></p>
355               <p><input type="submit" name="edit_link"
356                    value="<?php echo __('save'); ?>" /></p>
357          </form>
358     </div>
359     
360     <?php } ?>
361     
362</body>
363</html>
Note: See TracBrowser for help on using the repository browser.

Sites map