Source for file admin.weblinks.php

Documentation is available at admin.weblinks.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @subpackage Weblinks
  5. @copyright  Refer to copyright.php
  6. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. @author Mambo Foundation Inc see README.php
  8. */ 
  9.  
  10. /** ensure this file is being included by a parent file */
  11. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  12.  
  13. // ensure user has access to this function
  14. if (!($acl->acl_check'administration''edit''users'$my->usertype'components''all' )
  15.         | $acl->acl_check'administration''edit''users'$my->usertype'components''com_weblinks' ))) {
  16.     mosRedirect'index2.php'T_('You are not authorized to view this resource.') );
  17. }
  18.  
  19. require_once$mainframe->getPath'admin_html' ) );
  20. require_once$mainframe->getPath'class' ) );
  21.  
  22. $cid mosGetParam$_POST'cid'array(0) );
  23.  
  24. switch ($task{
  25.     case 'new':
  26.         editWeblink$option);
  27.         break;
  28.  
  29.     case 'edit':
  30.         editWeblink$option$cid[0);
  31.         break;
  32.  
  33.     case 'editA':
  34.         editWeblink$option$id );
  35.         break;
  36.  
  37.     case 'save':
  38.         saveWeblink$option );
  39.         break;
  40.  
  41.     case 'remove':
  42.         removeWeblinks$cid$option );
  43.         break;
  44.  
  45.     case 'publish':
  46.         publishWeblinks$cid1$option );
  47.         break;
  48.  
  49.     case 'unpublish':
  50.         publishWeblinks$cid0$option );
  51.         break;
  52.  
  53.     case 'approve':
  54.         break;
  55.  
  56.     case 'cancel':
  57.         cancelWeblink$option );
  58.         break;
  59.  
  60.     case 'orderup':
  61.         orderWeblinks$cid[0]-1$option );
  62.         break;
  63.  
  64.     case 'orderdown':
  65.         orderWeblinks$cid[0]1$option );
  66.         break;
  67.  
  68.     default:
  69.         showWeblinks$option );
  70.         break;
  71. }
  72.  
  73. /**
  74. * Compiles a list of records
  75. @param database A database connector object
  76. */
  77. function showWeblinks$option {
  78.     global $database$mainframe$mosConfig_list_limit;
  79.  
  80.     $catid $mainframe->getUserStateFromRequest"catid{$option}"'catid');
  81.     $limit $mainframe->getUserStateFromRequest"viewlistlimit"'limit'$mosConfig_list_limit );
  82.     $limitstart $mainframe->getUserStateFromRequest"view{$option}limitstart"'limitstart');
  83.     $search $mainframe->getUserStateFromRequest"search{$option}"'search''' );
  84.     $search $database->getEscapedtrimstrtolower$search ) ) );
  85.  
  86.     $where array();
  87.  
  88.     if ($catid 0{
  89.         $where["a.catid='$catid'";
  90.     }
  91.     if ($search{
  92.         $where["LOWER(a.title) LIKE '%$search%'";
  93.     }
  94.  
  95.     // get the total number of records
  96.     $database->setQuery"SELECT count(*) FROM #__weblinks AS a"
  97.         . (count$where "\nWHERE " implode' AND '$where "")
  98.     );
  99.     $total $database->loadResult();
  100.  
  101.     require_once$GLOBALS['mosConfig_absolute_path''/administrator/includes/pageNavigation.php' );
  102.     $pageNav new mosPageNav$total$limitstart$limit  );
  103.  
  104.     $query "SELECT a.*, cc.name AS category, u.name AS editor"
  105.     . "\n FROM #__weblinks AS a"
  106.     . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid"
  107.     . "\n LEFT JOIN #__users AS u ON u.id = a.checked_out"
  108.     . count$where "\n WHERE " implode' AND '$where "")
  109.     . "\n ORDER BY a.catid, a.ordering"
  110.     . "\n LIMIT $pageNav->limitstart$pageNav->limit"
  111.     ;
  112.     $database->setQuery$query );
  113.  
  114.     $rows $database->loadObjectList();
  115.     if ($database->getErrorNum()) {
  116.         echo $database->stderr();
  117.         return false;
  118.     }
  119.  
  120.     // build list of categories
  121.     $javascript 'onchange="document.adminForm.submit();"';
  122.     $lists['catid'mosAdminMenus::ComponentCategory'catid'$optionintval$catid )$javascript );
  123.  
  124.     HTML_weblinks::showWeblinks$option$rows$lists$search$pageNav );
  125. }
  126.  
  127. /**
  128. * Compiles information to add or edit
  129. @param integer The unique id of the record to edit (0 if new)
  130. */
  131. function editWeblink$option$id {
  132.     global $database$my$mosConfig_absolute_path$mosConfig_live_site;
  133.  
  134.     $lists array();
  135.  
  136.     $row new mosWeblink$database );
  137.     // load the row from the db table
  138.     $row->load$id );
  139.  
  140.     // fail if checked out not by 'me'
  141.     if ($row->checked_out && $row->checked_out <> $my->id{
  142.         mosRedirect'index2.php?option='$optionsprintf(T_('The module %s is currently being edited by another administrator.')$row->title) );
  143.     }
  144.  
  145.     if ($id{
  146.         $row->checkout$my->id );
  147.     else {
  148.         // initialise new record
  149.         $row->published         1;
  150.         $row->approved         1;
  151.         $row->order             0;
  152.         $row->catid mosGetParam$_POST'catid');
  153.     }
  154.  
  155.     // build the html select list for ordering
  156.     $query "SELECT ordering AS value, title AS text"
  157.     . "\n FROM #__weblinks"
  158.     . "\n WHERE catid='$row->catid'"
  159.     . "\n ORDER BY ordering"
  160.     ;
  161.     $lists['ordering']             mosAdminMenus::SpecificOrdering$row$id$query);
  162.  
  163.     // build list of categories
  164.     $lists['catid']             mosAdminMenus::ComponentCategory'catid'$optionintval$row->catid ) );
  165.     // build the html select list
  166.     $lists['approved']             mosHTML::yesnoRadioList'approved''class="inputbox"'$row->approved );
  167.     // build the html select list
  168.     $lists['published']         mosHTML::yesnoRadioList'published''class="inputbox"'$row->published );
  169.  
  170.     $file $mosConfig_absolute_path .'/administrator/components/com_weblink_items/weblink_items.xml';
  171.     $params =new mosAdminParameters$row->params$file'component' );
  172.  
  173.     HTML_weblinks::editWeblink$row$lists$params$option );
  174. }
  175. /**
  176. * Saves the record on an edit form submit
  177. @param database A database connector object
  178. */
  179. function saveWeblink$option {
  180.     global $database$my;
  181.  
  182.     $row new mosWeblink$database );
  183.     if (!$row->bind$_POST )) {
  184.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  185.         exit();
  186.     }
  187.     // save params
  188.     $params mosGetParam$_POST'params''' );
  189.     if (is_array$params )) {
  190.         $txt array();
  191.         foreach $params as $k=>$v{
  192.             $txt["$k=$v";
  193.         }
  194.         $row->params implode"\n"$txt );
  195.     }
  196.  
  197.     $row->date = date"Y-m-d H:i:s" );
  198.     if (!$row->check()) {
  199.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  200.         exit();
  201.     }
  202.     if (!$row->store()) {
  203.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  204.         exit();
  205.     }
  206.     $row->checkin();
  207.     $row->updateOrder"catid='$row->catid');
  208.  
  209.     mosRedirect"index2.php?option=$option);
  210. }
  211.  
  212. /**
  213. * Deletes one or more records
  214. @param array An array of unique category id numbers
  215. @param string The current url option
  216. */
  217. function removeWeblinks$cid$option {
  218.     global $database;
  219.  
  220.     if (!is_array$cid || count$cid 1{
  221.         echo "<script> alert('".T_('Select an item to delete')."'); window.history.go(-1);</script>\n";
  222.         exit;
  223.     }
  224.     if (count$cid )) {
  225.         $cids implode','$cid );
  226.         $database->setQuery"DELETE FROM #__weblinks WHERE id IN ($cids));
  227.         if (!$database->query()) {
  228.             echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
  229.         }
  230.     }
  231.  
  232.     mosRedirect"index2.php?option=$option);
  233. }
  234.  
  235. /**
  236. * Publishes or Unpublishes one or more records
  237. @param array An array of unique category id numbers
  238. @param integer 0 if unpublishing, 1 if publishing
  239. @param string The current url option
  240. */
  241. function publishWeblinks$cid=null$publish=1,  $option {
  242.     global $database$my;
  243.  
  244.     $catid mosGetParam$_POST'catid'array(0) );
  245.  
  246.     if (!is_array$cid || count$cid 1{
  247.         $action $publish T_('publish'T_('unpublish');
  248.         echo "<script> alert('".sprintf(T_('Select an item to %s')$action)."'); window.history.go(-1);</script>\n";
  249.         exit;
  250.     }
  251.  
  252.     $cids implode','$cid );
  253.  
  254.     $database->setQuery"UPDATE #__weblinks SET published='$publish'"
  255.         . "\nWHERE id IN ($cids) AND (checked_out=0 OR (checked_out='$my->id'))"
  256.     );
  257.     if (!$database->query()) {
  258.         echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
  259.         exit();
  260.     }
  261.  
  262.     if (count$cid == 1{
  263.         $row new mosWeblink$database );
  264.         $row->checkin$cid[0);
  265.     }
  266.     mosRedirect"index2.php?option=$option);
  267. }
  268. /**
  269. * Moves the order of a record
  270. @param integer The increment to reorder by
  271. */
  272. function orderWeblinks$uid$inc$option {
  273.     global $database;
  274.     $row new mosWeblink$database );
  275.     $row->load$uid );
  276.     $row->move$inc"published >= 0" );
  277.  
  278.     mosRedirect"index2.php?option=$option);
  279. }
  280.  
  281. /**
  282. * Cancels an edit operation
  283. @param string The current url option
  284. */
  285. function cancelWeblink$option {
  286.     global $database;
  287.     $row new mosWeblink$database );
  288.     $row->bind$_POST );
  289.     // sanitize
  290.     $row->id intval($row->id);
  291.     $row->checkin();
  292.     mosRedirect"index2.php?option=$option);
  293. }
  294. ?>

Documentation generated on Mon, 05 May 2008 16:16:41 +0400 by phpDocumentor 1.4.0