[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/admin/ -> editevent.php (source)

   1  <?php
   2  #CMS - CMS Made Simple
   3  #(c)2004 by Ted Kulp (wishy@users.sf.net)
   4  #This project's homepage is: http://cmsmadesimple.sf.net
   5  #
   6  #This program is free software; you can redistribute it and/or modify
   7  #it under the terms of the GNU General Public License as published by
   8  #the Free Software Foundation; either version 2 of the License, or
   9  #(at your option) any later version.
  10  #
  11  #This program 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  #You should have received a copy of the GNU General Public License
  16  #along with this program; if not, write to the Free Software
  17  #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18  #
  19  #$Id: listtags.php 2772 2006-05-17 02:25:27Z wishy $
  20  
  21  $CMS_ADMIN_PAGE=1;
  22  
  23  require_once ("../include.php");
  24  global $gCms;
  25  $db =& $gCms->GetDb();
  26  
  27  $userid = get_userid();
  28  $access = check_permission($userid, "Modify Events");
  29  
  30  function display_error( $text )
  31  {
  32    echo "<div class=\"pageerrorcontainer\"><p class=\"pageerror\">$text</p></div>\n";
  33  }
  34  
  35  check_login();
  36  
  37  include_once ("header.php");
  38  
  39  $downImg = $themeObject->DisplayImage('icons/system/arrow-d.gif', lang('down'),'','','systemicon');
  40  $upImg = $themeObject->DisplayImage('icons/system/arrow-u.gif', lang('up'),'','','systemicon');
  41  $deleteImg = $themeObject->DisplayImage('icons/system/delete.gif', lang('delete'),'','','systemicon');
  42  
  43  
  44  echo "<div class=\"pagecontainer\">\n";
  45  echo "<div class=\"pageoverflow\">\n";
  46  echo $themeObject->ShowHeader('editeventhandler');
  47  echo "</div>\n";
  48  
  49  if ($access)
  50  {
  51      $action = "";
  52      $module = "";
  53      $event = "";
  54      $handler = "";
  55      if( isset( $_POST['add'] ) )
  56      {
  57          // we're adding some funky event handler
  58          if( isset( $_POST['module'] ) && $_POST['module'] != '' )
  59          {
  60          $module = $_POST['module'];
  61          }
  62          if( isset( $_POST['event'] ) && $_POST['event'] != '' )
  63          {
  64          $event = $_POST['event'];
  65          }
  66          if( isset( $_POST['handler'] ) )
  67          {
  68          // handler is set, we just have to try to set it
  69          $handler = $_POST['handler'];
  70          }
  71          if( $module && $event && $handler )
  72          {
  73          if( substr( $handler, 0, 2 ) == "m:" )
  74          {
  75              $handler = substr( $handler, 2 );
  76              Events::AddEventHandler( $module, $event, false, $handler );
  77          }
  78          else
  79          {
  80              Events::AddEventHandler( $module, $event, $handler );
  81          }
  82          }
  83      }
  84      else
  85      {
  86          $cur_order = -1;
  87      
  88          // we're processing an up/down or delete
  89          if( isset( $_GET['action'] ) && $_GET['action'] != '' )
  90          {
  91          $action = $_GET['action'];
  92          }
  93          if( isset( $_GET['module'] ) && $_GET['module'] != '' )
  94          {
  95          $module = $_GET['module'];
  96          }
  97          if( isset( $_GET['event'] ) && $_GET['event'] != '' )
  98          {
  99          $event = $_GET['event'];
 100          }
 101          if( isset( $_GET['handler'] ) && $_GET['handler'] != '' )
 102          {
 103          $handler = $_GET['handler'];
 104          }
 105          if( isset( $_GET['order'] ) && $_GET['order'] != '' )
 106          {
 107          $cur_order = $_GET['order'];
 108          }
 109      
 110          switch( $action )
 111          {
 112          case 'up':
 113          // move an item up (decrease the order)
 114          // increases the previous order, and decreases the current handler id
 115          if( $handler == "" || $module == "" || $event == "" || $action == "" ||
 116              ($cur_order == "" && $action != "delete") )
 117          {
 118              display_error( lang("missingparams" ) );
 119          }
 120      
 121          $q = "SELECT handler_id FROM ".cms_db_prefix()."event_handlers WHERE handler_order = ?";
 122          $dbresult = $db->Execute( $q, array($cur_order - 1) );
 123          $row = $dbresult->FetchRow();
 124          $prev_id = -1;
 125          if( isset( $row['handler_id'] ) )
 126          {
 127              $prev_id = $row['handler_id'];
 128      
 129              $q = "UPDATE ".cms_db_prefix()."event_handlers SET handler_order = (handler_order - 1)
 130                      where handler_id = ?";
 131              $db->Execute( $q, array( $handler ) );
 132      
 133              $q = "UPDATE ".cms_db_prefix()."event_handlers SET handler_order = (handler_order + 1)
 134                      where handler_id = ?";
 135              $db->Execute( $q, array( $prev_id ) );
 136          }
 137          break;
 138              
 139          case 'down':
 140          // move an item down (increase the order)
 141          // move an item up (decrease the order)
 142          // increases the previous order, and decreases the current handler id
 143          if( $handler == "" || $module == "" || $event == "" || $action == "" ||
 144              ($cur_order == "" && $action != "delete") )
 145          {
 146              display_error( lang("missingparams" ) );
 147          }
 148      
 149          $q = "SELECT handler_id FROM ".cms_db_prefix()."event_handlers WHERE handler_order = ?";
 150          $dbresult = $db->Execute( $q, array($cur_order + 1) );
 151          $row = $dbresult->FetchRow();
 152          $next_id = -1;
 153          if( isset( $row['handler_id'] ) )
 154          {
 155              $next_id = $row['handler_id'];
 156      
 157              $q = "UPDATE ".cms_db_prefix()."event_handlers SET handler_order = (handler_order + 1)
 158                      where handler_id = ?";
 159              $db->Execute( $q, array( $handler ) );
 160      
 161              $q = "UPDATE ".cms_db_prefix()."event_handlers SET handler_order = (handler_order - 1)
 162                      where handler_id = ?";
 163              $db->Execute( $q, array( $next_id ) );
 164          }
 165          break;
 166              
 167          case 'delete':
 168          {
 169          if( $handler == "" || $module == "" || $event == "" || $action == "" ||
 170              ($cur_order == "" && $action != "delete") )
 171              {
 172              display_error( lang("missingparams" ) );
 173              }
 174      
 175          // get the details about the handler
 176          $q = "SELECT * FROM ".cms_db_prefix()."event_handlers WHERE
 177                          handler_id = ?";
 178          $dbresult = $db->Execute( $q, array( $handler ) );
 179          if( $dbresult && $dbresult->RecordCount() )
 180              {
 181              $row = $dbresult->FetchRow();
 182              $event_id = $row['event_id'];
 183      
 184              // delete a handler
 185              $q = "DELETE FROM ".cms_db_prefix()."event_handlers WHERE
 186                          handler_id = ?";
 187              $dbresult = $db->Execute( $q, array( $handler ) );
 188      
 189              // re-order the events
 190              $q = "UPDATE ".cms_db_prefix()."event_handlers SET handler_order = (handler_order - 1)
 191                          WHERE handler_order > ? AND event_id = ?";
 192              $dbresult = $db->Execute( $q, array( $cur_order, $event_id ) );
 193              }
 194          }
 195          break;
 196              
 197          default:
 198          // unknown or unset action
 199          break;
 200          } // switch
 201      }
 202          
 203      // get the event description
 204      global $gCms;
 205      $usertagops =& $gCms->GetUserTagOperations();
 206      //$description = $gCms->modules[$module]['object']->GetEventDescription($event);
 207      
 208      $description = '';
 209      $modulename = '';
 210      if ($module == 'Core') {
 211          $description = Events::GetEventDescription($event);
 212          $modulename = lang('core');
 213      }
 214      else if (isset($gCms->modules[$module])) {
 215          $objinstance =& $gCms->modules[$module]['object'];
 216          $description = $objinstance->GetEventDescription($event);
 217          $modulename = $objinstance->GetFriendlyName();
 218      }
 219      
 220      // and now get the list of handlers for this event
 221      $handlers = Events::ListEventHandlers( $module, $event );
 222      //print_r( $handlers ); echo "<br/><br/>";
 223      
 224      // and the list of all available handlers
 225      $allhandlers = array();
 226      // we get the list of user tags, and add them to the list
 227      $usertags = $usertagops->ListUserTags();
 228      foreach( $usertags as $key => $value )
 229      {
 230      $allhandlers[$value] = $key;
 231      }
 232      // and the list of modules, and add them
 233      foreach( $gCms->modules as $key => $value )
 234      {
 235      if( $key == $modulename )
 236          {
 237          continue;
 238          }
 239      
 240      if( $gCms->modules[$key]['object']->HandlesEvents() )
 241          {
 242          $allhandlers[$key] = 'm:'.$key;
 243          }
 244      }
 245      
 246      echo "<div class=\"pageoverflow\">\n";
 247      echo "<p class=\"pagetext\">".lang("module_name").":</p>\n";
 248      echo "<p class=\"pageinput\">".$modulename."</p>\n";
 249      echo "</div>\n";
 250      echo "<div class=\"pageoverflow\">\n";
 251      echo "<p class=\"pagetext\">".lang("event_name").":</p>\n";
 252      echo "<p class=\"pageinput\">".$event."</p>\n";
 253      echo "</div>\n";
 254      echo "<div class=\"pageoverflow\">\n";
 255      echo "<p class=\"pagetext\">".lang("event_description").":</p>\n";
 256      echo "<p class=\"pageinput\">".$description."</p>\n";
 257      echo "</div>\n";
 258      
 259      echo "<br/><table cellspacing=\"0\" class=\"pagetable\">\n";
 260      echo "<thead>\n";
 261      echo "  <tr>\n";
 262      echo "    <th>".lang('order')."</th>\n";
 263      echo "    <th>".lang('user_tag')."</th>\n";
 264      echo "    <th>".lang('module')."</th>\n";
 265      echo "    <th class=\"pageicon\">&nbsp;</th>\n";
 266      echo "    <th class=\"pageicon\">&nbsp;</th>\n";
 267      echo "    <th class=\"pageicon\">&nbsp;</th>\n";
 268      echo "  </tr>\n";
 269      echo "</thead>\n";
 270      
 271      $rowclass = "row1";
 272      if( $handlers != false )
 273      {
 274          echo "<tbody>\n";
 275          $idx = 0;
 276          $url = "editevent.php?module=".$module."&amp;event=".$event;
 277          foreach( $handlers as $onehandler )
 278          {
 279          echo "<tr class=\"$rowclass\">\n";
 280          echo "  <td>".$onehandler['handler_order']."</td>\n";
 281          echo "  <td>".$onehandler['tag_name']."</td>\n";
 282          echo "  <td>".$onehandler['module_name']."</td>\n";
 283          if( $idx != 0 ) 
 284          {
 285              echo "  <td><a href=\"".$url."&amp;action=up&amp;order=".$onehandler['handler_order']."&amp;handler=".$onehandler['handler_id']."\">$upImg</a></td>\n";
 286          }
 287          else
 288          {
 289              echo "<td>&nbsp;</td>";
 290          }
 291          if( $idx + 1 != count($handlers) )
 292          {
 293              echo "  <td><a href=\"".$url."&amp;action=down&amp;order=".$onehandler['handler_order']."&amp;handler=".$onehandler['handler_id']."\">$downImg</a></td>\n";
 294          }
 295          else
 296          {
 297              echo "<td>&nbsp;</td>";
 298          }
 299          if( $onehandler['removable'] == 1 )
 300          {
 301              echo "  <td><a href=\"".$url."&amp;action=delete&amp;order=".$onehandler['handler_order']."&amp;handler=".$onehandler['handler_id']."\">$deleteImg</a></td>\n";
 302          }
 303          else
 304          {
 305              echo "  <td>&nbsp;</td>\n";
 306          }
 307          echo "</tr>\n";
 308      
 309          $idx++;
 310          }
 311          echo "</tbody>\n";
 312      }
 313      echo "</table>\n";
 314      
 315      echo "<br/><form action=\"editevent.php?action=create\" method=\"post\">\n";
 316      echo "<select name=\"handler\">\n";
 317      foreach( $allhandlers as $key => $value )
 318      {
 319      echo "<option value=\"$value\">$key</option>\n";
 320      }
 321      echo "</select>\n";
 322      echo "<input type=\"hidden\" name=\"module\" value=\"$module\">\n";
 323      echo "<input type=\"hidden\" name=\"event\" value=\"$event\">\n";
 324      echo "<input type=\"submit\" name=\"add\" value=\"".lang('add')."\">";
 325      echo "</form>\n";
 326      echo "<p class=\"pageback\"><a class=\"pageback\" href=\"".$themeObject->BackUrl()."\">&#171; ".lang('back')."</a></p>\n";
 327      
 328      echo "</div>\n";
 329  }
 330  else
 331  {
 332      display_error(lang('noaccessto', array(lang('editeventhandler'))));
 333  }
 334  include_once ("footer.php");
 335  
 336  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7