[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/components/com_weblinks/ -> weblinks.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @author Mambo Foundation Inc see README.php
   5  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   6  * See COPYRIGHT.php for copyright notices and details.
   7  * @license GNU/GPL Version 2, see LICENSE.php
   8  *
   9  * Redistributions of files must retain the above copyright notice.
  10  *
  11  * Mambo is free software; you can redistribute it and/or
  12  * modify it under the terms of the GNU General Public License
  13  * as published by the Free Software Foundation; version 2 of the License.
  14  */
  15  
  16  /** ensure this file is being included by a parent file */
  17  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  18  
  19  /** load the html drawing class */
  20  require_once( $mainframe->getPath( 'front_html' ) );
  21  require_once( $mainframe->getPath( 'class' ) );
  22  $mainframe->setPageTitle( T_('Web Links') );
  23  
  24  $task = trim( mosGetParam( $_REQUEST, 'task', "" ) );
  25  $id = intval( mosGetParam( $_REQUEST, 'id', 0 ) );
  26  $catid = intval( mosGetParam( $_REQUEST, 'catid', 0 ) );
  27  
  28  switch ($task) {
  29      case 'new':
  30      editWebLink( 0, $option );
  31      break;
  32  
  33      case 'edit':
  34      /** disabled until permissions system can handle it */
  35      editWebLink( 0, $option );
  36      break;
  37  
  38      case 'save':
  39      saveWebLink( $option );
  40      break;
  41  
  42      case 'cancel':
  43      cancelWebLink( $option );
  44      break;
  45  
  46      case 'view':
  47      showItem( $id, $catid );
  48      break;
  49  
  50      default:
  51      listWeblinks( $catid );
  52      break;
  53  }
  54  
  55  function listWeblinks( $catid ) {
  56      global $mainframe, $database, $my;
  57      global $mosConfig_shownoauth, $mosConfig_live_site, $mosConfig_absolute_path;
  58      global $cur_template, $Itemid;
  59  
  60      /* Query to retrieve all categories that belong under the web links section and that are published. */
  61      $query = "SELECT *, COUNT(a.id) AS numlinks FROM #__categories AS cc"
  62      . "\n LEFT JOIN #__weblinks AS a ON a.catid = cc.id"
  63      . "\n WHERE a.published='1' AND a.approved='1' AND section='com_weblinks' AND cc.published='1' AND cc.access <= '$my->gid'"
  64      . "\n GROUP BY cc.id"
  65      . "\n ORDER BY cc.ordering"
  66      ;
  67      $database->setQuery( $query );
  68      $categories = $database->loadObjectList();
  69  
  70      $rows = array();
  71      $currentcat = NULL;
  72      if ( $catid ) {
  73          // url links info for category
  74          $query = "SELECT id, url, title, description, date, hits, params FROM #__weblinks"
  75          . "\nWHERE catid = '$catid' AND published='1' AND approved='1' AND archived=0"
  76          . "\nORDER BY ordering"
  77          ;
  78          $database->setQuery( $query );
  79          $rows = $database->loadObjectList();
  80  
  81          // current cate info
  82          $query = "SELECT name, description, image, image_position FROM #__categories"
  83          . "\n WHERE id = '$catid'"
  84          . "\n AND published = '1'"
  85          ;
  86          $database->setQuery( $query );
  87          $database->loadObject( $currentcat );
  88      }
  89  
  90      // Parameters
  91      $menu =& new mosMenu( $database );
  92      $menu->load( $Itemid );
  93      $params =& new mosParameters( $menu->params );
  94      $params->def( 'page_title', 1 );
  95      $params->def( 'header', $menu->name );
  96      $params->def( 'pageclass_sfx', '' );
  97      $params->def( 'headings', 1 );
  98      $params->def( 'hits', $mainframe->getCfg( 'hits' ) );
  99      $params->def( 'item_description', 1 );
 100      $params->def( 'other_cat_section', 1 );
 101      $params->def( 'other_cat', 1 );
 102      $params->def( 'description', 1 );
 103      $params->def( 'description_text', T_('From the list below choose one of our web link categories, then select a URL to visit the site.') );
 104      $params->def( 'image', '-1' );
 105      $params->def( 'weblink_icons', '' );
 106      $params->def( 'image_align', 'right' );
 107      $params->def( 'back_button', $mainframe->getCfg( 'back_button' ) );
 108  
 109      if ( $catid ) {
 110          $params->set( 'type', 'category' );
 111      } else {
 112          $params->set( 'type', 'section' );
 113      }
 114      
 115      // page description
 116      $currentcat->descrip = '';
 117      if( ( @$currentcat->description ) <> '' ) {
 118          $currentcat->descrip = $currentcat->description;
 119      } else if ( !$catid ) {
 120          // show description
 121          if ( $params->get( 'description' ) ) {
 122              $currentcat->descrip = $params->get( 'description_text' );
 123          }
 124      }
 125  
 126      // page image
 127      $currentcat->img = '';
 128      $path = $mosConfig_live_site .'/images/stories/';
 129      if ( ( @$currentcat->image ) <> '' ) {
 130          $currentcat->img = $path . $currentcat->image;
 131          $currentcat->align = $currentcat->image_position;
 132      } else if ( !$catid ) {
 133          if ( $params->get( 'image' ) <> -1 ) {
 134              $currentcat->img = $path . $params->get( 'image' );
 135              $currentcat->align = $params->get( 'image_align' );
 136          }
 137      }
 138  
 139      // page header
 140      $currentcat->header = '';
 141      if ( @$currentcat->name <> '' ) {
 142          $currentcat->header = $currentcat->name;
 143          $pathway =& mosPathway::getInstance();
 144          $pathway->addItem($currentcat->name, '');
 145      } else {
 146          $currentcat->header = $params->get( 'header' );
 147      }
 148  
 149      // used to show table rows in alternating colours
 150      $tabclass = array( 'sectiontableentry1', 'sectiontableentry2' );
 151  
 152      HTML_weblinks::displaylist( $categories, $rows, $catid, $currentcat, $params, $tabclass );
 153  }
 154  
 155  
 156  function showItem ( $id, $catid ) {
 157      global $database;
 158  
 159      //Record the hit
 160      $sql="UPDATE #__weblinks SET hits = hits + 1 WHERE id = ". $id ."";
 161      $database->setQuery( $sql );
 162      $database->query();
 163  
 164      $database->setQuery( "SELECT url FROM #__weblinks WHERE id = ". $id ."" );
 165      $url = $database->loadResult();
 166  
 167      mosRedirect ( $url );
 168  
 169      listWeblinks( $catid );
 170  
 171  }
 172  
 173  function editWebLink( $id, $option ) {
 174      global $database, $my;
 175      global $mosConfig_absolute_path, $mosConfig_live_site;
 176  
 177      if ($my->gid < 1) {
 178          mosNotAuth();
 179          return;
 180      }
 181  
 182      $row = new mosWeblink( $database );
 183      // load the row from the db table
 184      $row->load( $id );
 185  
 186      // fail if checked out not by 'me'
 187      if ($row->checked_out && $row->checked_out <> $my->id) {
 188          mosRedirect( "index2.php?option=$option",sprintf(T_('The module %s is currently being edited by another administrator.'), $row->title) );
 189      }
 190  
 191      if ($id) {
 192          $row->checkout( $my->id );
 193      } else {
 194          // initialise new record
 195          $row->published         = 0;
 196          $row->approved         = 0;
 197          $row->ordering         = 0;
 198      }
 199  /*
 200      // make the select list for the image positions
 201      $yesno[] = mosHTML::makeOption( '0', 'No' );
 202      $yesno[] = mosHTML::makeOption( '1', 'Yes' );
 203      // build the html select list
 204      $applist = mosHTML::selectList( $yesno, 'approved', 'class="inputbox" size="2"', 'value', 'text', $row->approved );
 205      // build the html select list for ordering
 206      $query = "SELECT ordering AS value, title AS text"
 207      . "\n FROM #__weblinks"
 208      . "\n WHERE catid='$row->catid'"
 209      . "\n ORDER BY ordering"
 210      ;
 211      $lists['ordering']             = mosAdminMenus::SpecificOrdering( $row, $id, $query, 1 );
 212  */
 213  
 214      // build list of categories
 215      require_once ($mosConfig_absolute_path.'/administrator/includes/mosAdminMenus.php');
 216      $lists['catid']             = mosAdminMenus::ComponentCategory( 'catid', $option, intval( $row->catid ) );
 217  
 218      HTML_weblinks::editWeblink( $option, $row, $lists );
 219  }
 220  
 221  function cancelWebLink( $option ) {
 222      global $database, $my;
 223  
 224      if ($my->gid < 1) {
 225          mosNotAuth();
 226          return;
 227      }
 228  
 229      $row = new mosWeblink( $database );
 230      $row->id = intval( mosGetParam( $_POST, 'id', 0 ) );
 231      $row->checkin();
 232      $Itemid = mosGetParam( $_POST, 'Returnid', '' );
 233      mosRedirect( "index.php?Itemid=$Itemid" );
 234  }
 235  
 236  /**
 237  * Saves the record on an edit form submit
 238  * @param database A database connector object
 239  */
 240  function saveWeblink( $option ) {
 241      global $database, $my, $mosConfig_absolute_path, $mosConfig_mailfrom;
 242  
 243      if ($my->gid < 1) {
 244          mosNotAuth();
 245          return;
 246      }
 247  
 248      $row = new mosWeblink( $database );
 249      if (!$row->bind( $_POST, "approved published" )) {
 250          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 251          exit();
 252      }
 253      // sanitize
 254      $row->id = intval($row->id);
 255  
 256      $isNew = $row->id < 1;
 257  
 258      $row->date = date( "Y-m-d H:i:s" );
 259  
 260          $row->title = $database->getEscaped($row->title);
 261          $row->catid = $database->getEscaped($row->catid);
 262  
 263      if (!$row->check()) {
 264          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 265          exit();
 266      }
 267      if (!$row->store()) {
 268          echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
 269          exit();
 270      }
 271      $row->checkin();
 272  
 273      // messaging for new items
 274      require_once ( $mosConfig_absolute_path .'/components/com_messages/messages.class.php' );
 275  
 276      $query = "SELECT id,email FROM #__users WHERE sendEmail = '1'";            
 277      $database->setQuery( $query );
 278      $rows = $database->loadObjectList();
 279  
 280      foreach ($rows as $user) {    
 281      
 282          // admin message
 283          $msg = new mosMessage( $database );
 284          $msg->send( $my->id, $user->id, T_("New Item"), sprintf( T_('A new WebLink has been submitted by [ %s ]  titled [ %s ] '), $my->username, $row->title ) );
 285          
 286          // email message
 287          mosMail ( $mosConfig_mailfrom, $mosConfig_mailfrom, $user->email, "A new Web Link has been submitted", 'A new WebLink has been submitted by ['.$my->username.'] titled ['.$row->title.']. Please login to view and approve it.');
 288      
 289      }
 290  
 291      $msg     = $isNew ? T_('Thanks for your submission; it will be reviewed before being posted to the site.') : '';
 292      $Itemid = mosGetParam( $_POST, 'Returnid', '' );
 293      mosRedirect( 'index.php?Itemid='. $Itemid, $msg );
 294  }
 295  
 296  ?>