Source for file admin.modules.php

Documentation is available at admin.modules.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @subpackage Modules
  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'modules''all' $acl->acl_check'administration''install''users'$my->usertype'modules''all' ))) {
  15.     mosRedirect'index2.php'T_('You are not authorized to view this resource.') );
  16. }
  17.  
  18. require_once$mainframe->getPath'admin_html' ) );
  19.  
  20. $client     mosGetParam$_REQUEST'client''' );
  21. $cid         mosGetParam$_POST'cid'array(0) );
  22. $moduleid     mosGetParam$_REQUEST'moduleid'null );
  23. if ($cid[0== && isset($moduleid) ) {
  24.     $cid[0$moduleid;
  25. }
  26.  
  27. switch $task {
  28.     case 'copy':
  29.         copyModule$optionintval$cid[0)$client );
  30.         break;
  31.  
  32.     case 'new':
  33.         editModule$option0$client );
  34.         break;
  35.  
  36.     case 'edit':
  37.         editModule$option$cid[0]$client );
  38.         break;
  39.  
  40.     case 'editA':
  41.         editModule$option$id$client );
  42.         break;
  43.  
  44.     case 'save':
  45.     case 'apply':
  46.         mosCache::cleanCache'com_content' );
  47.         saveModule$option$client$task );
  48.         break;
  49.  
  50.     case 'remove':
  51.         removeModule$cid$option$client );
  52.         break;
  53.  
  54.     case 'cancel':
  55.         cancelModule$option$client );
  56.         break;
  57.  
  58.     case 'publish':
  59.     case 'unpublish':
  60.         mosCache::cleanCache'com_content' );
  61.         publishModule$cid($task == 'publish')$option$client );
  62.         break;
  63.  
  64.     case 'orderup':
  65.     case 'orderdown':
  66.         orderModule$cid[0]($task == 'orderup' ? -1)$option$client );
  67.         break;
  68.  
  69.     case 'accesspublic':
  70.     case 'accessregistered':
  71.     case 'accessspecial':
  72.         accessMenu$cid[0]$task$option$client );
  73.         break;
  74.  
  75.     case 'saveorder':
  76.         saveOrder$cid$client );
  77.         break;
  78.  
  79.     default:
  80.         viewModules$option$client );
  81.         break;
  82. }
  83.  
  84. /**
  85. * Compiles a list of installed or defined modules
  86. */
  87. function viewModules$option$client {
  88.     global $database$my$mainframe$mosConfig_list_limit$mosConfig_absolute_path;
  89.  
  90.     $filter_position     $mainframe->getUserStateFromRequest"filter_position{$option}{$client}"'filter_position');
  91.     $filter_type         $mainframe->getUserStateFromRequest"filter_type{$option}{$client}"'filter_type');
  92.     $limit                 $mainframe->getUserStateFromRequest"viewlistlimit"'limit'$mosConfig_list_limit );
  93.     $limitstart         $mainframe->getUserStateFromRequest"view{$option}limitstart"'limitstart');
  94.     $search             $mainframe->getUserStateFromRequest"search{$option}{$client}"'search''' );
  95.     $search             $database->getEscapedtrimstrtolower$search ) ) );
  96.  
  97.     if ($client == 'admin'{
  98.         $where["m.client_id = '1'";
  99.         $client_id 1;
  100.     else {
  101.         $where["m.client_id = '0'";
  102.         $client_id 0;
  103.     }
  104.  
  105.     // used by filter
  106.     if $filter_position {
  107.         $where["m.position = '$filter_position'";
  108.     }
  109.     if $filter_type {
  110.         $where["m.module = '$filter_type'";
  111.     }
  112.     if $search {
  113.         $where["LOWER( m.title ) LIKE '%$search%'";
  114.     }
  115.  
  116.     // get the total number of records
  117.     $query "SELECT COUNT(*) FROM #__modules AS m "count$where "\n WHERE " implode' AND '$where '' );
  118.     $database->setQuery$query );
  119.     $total $database->loadResult();
  120.  
  121.     require_once$mosConfig_absolute_path '/administrator/includes/pageNavigation.php' );
  122.     $pageNav new mosPageNav$total$limitstart$limit );
  123.  
  124.     $database->setQuery"SELECT m.*, u.name AS editor, g.name AS groupname, MIN(mm.menuid) AS pages"
  125.     . "\n FROM #__modules AS m"
  126.     . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out"
  127.     . "\n LEFT JOIN #__groups AS g ON g.id = m.access"
  128.     . "\n LEFT JOIN #__modules_menu AS mm ON mm.moduleid=m.id"
  129.     . count$where "\n WHERE " implode' AND '$where '' )
  130.     . "\n GROUP BY m.id"
  131.     . "\n ORDER BY position ASC, ordering ASC"
  132.     . "\n LIMIT $pageNav->limitstart,$pageNav->limit"
  133.     );
  134.     $rows $database->loadObjectList();
  135.     if ($database->getErrorNum()) {
  136.         echo $database->stderr();
  137.         return false;
  138.     }
  139.  
  140.     // get list of Positions for dropdown filter
  141.     $query "SELECT t.position AS value, t.position AS text"
  142.     . "\n FROM #__template_positions as t"
  143.     . "\n LEFT JOIN #__modules AS m ON m.position = t.position"
  144.     . "\n WHERE m.client_id = '$client_id'"
  145.     . "\n GROUP BY t.position"
  146.     . "\n ORDER BY t.position"
  147.     ;
  148.     $positions[mosHTML::makeOption'0'T_('- All Positions -') );
  149.     $database->setQuery$query );
  150.     $positions array_merge$positions$database->loadObjectList() );
  151.     $lists['position']    mosHTML::selectList$positions'filter_position''class="inputbox" size="1" onchange="document.adminForm.submit( );"''value''text'"$filter_position);
  152.  
  153.     // get list of Positions for dropdown filter
  154.     $query "SELECT module AS value, module AS text"
  155.     . "\n FROM #__modules"
  156.     . "\n WHERE client_id = '$client_id'"
  157.     . "\n GROUP BY module"
  158.     . "\n ORDER BY module"
  159.     ;
  160.     $types[mosHTML::makeOption'0'T_('- All Types -') );
  161.     $database->setQuery$query );
  162.     $types array_merge$types$database->loadObjectList() );
  163.     $lists['type']    mosHTML::selectList$types'filter_type''class="inputbox" size="1" onchange="document.adminForm.submit( );"''value''text'"$filter_type);
  164.  
  165.     HTML_modules::showModules$rows$my->id$client$pageNav$option$lists$search );
  166. }
  167.  
  168. /**
  169. * Compiles information to add or edit a module
  170. @param string The current GET/POST option
  171. @param integer The unique id of the record to edit
  172. */
  173. function copyModule$option$uid$client {
  174.     global $database$my;
  175.  
  176.     $row new mosModule$database );
  177.     // load the row from the db table
  178.     $row->load$uid );
  179.     $row->title 'Copy of '.$row->title;
  180.     $row->id 0;
  181.     $row->iscore 0;
  182.     $row->published 0;
  183.  
  184.     if (!$row->check()) {
  185.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  186.         exit();
  187.     }
  188.     if (!$row->store()) {
  189.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  190.         exit();
  191.     }
  192.     $row->checkin();
  193.     if ($client == 'admin'{
  194.         $where "client_id='1'";
  195.     else {
  196.         $where "client_id='0'";
  197.     }
  198.     $row->updateOrder"position='$row->position' AND ($where));
  199.  
  200.     $database->setQuery"SELECT menuid FROM #__modules_menu WHERE moduleid='$uid');
  201.     $rows $database->loadResultArray();
  202.  
  203.     foreach($rows as $menuid{
  204.         $database->setQuery"INSERT INTO #__modules_menu"
  205.         . "\nSET moduleid='$row->id', menuid='$menuid'"
  206.         );
  207.         $database->query();
  208.     }
  209.  
  210.     $msg sprintf(T_('Module Copied [%s]')$row->title);
  211.     mosRedirect'index2.php?option='$option .'&client='$client$msg );
  212. }
  213.  
  214. /**
  215. * Saves the module after an edit form submit
  216. */
  217. function saveModule$option$client$task {
  218.     global $database;
  219.  
  220.     $params mosGetParam$_POST'params''' _MOS_ALLOWHTML);
  221.     if (is_array$params )) {
  222.         $txt array();
  223.         foreach ($params as $k=>$v{
  224.             $txt["$k=$v";
  225.         }
  226.         $_POST['params'mosParameters::textareaHandling$txt );
  227.     }
  228.  
  229.     $row new mosModule$database );
  230.     if (!$row->bind$_POST'selections' )) {
  231.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  232.         exit();
  233.     }
  234.  
  235.     // special access groups
  236.     if (is_array($row->groups))
  237.         $row->groups implode(',',$row->groups);
  238.     else
  239.         $row->groups '';
  240.  
  241.     if (!$row->check()) {
  242.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  243.         exit();
  244.     }
  245.     if (!$row->store()) {
  246.         echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  247.         exit();
  248.     }
  249.     $row->checkin();
  250.     if ($client == 'admin'{
  251.         $where "client_id='1'";
  252.     else {
  253.         $where "client_id='0'";
  254.     }
  255.     $row->updateOrder"position='$row->position' AND ($where));
  256.  
  257.     $menus mosGetParam$_POST'selections'array() );
  258.  
  259.     $database->setQuery"DELETE FROM #__modules_menu WHERE moduleid='$row->id');
  260.     $database->query();
  261.  
  262.     foreach ($menus as $menuid){
  263.         // this check for the blank spaces in the select box that have been added for cosmetic reasons
  264.         if $menuid <> "-999" && $menuid <> "-998"{  
  265.             $query "INSERT INTO #__modules_menu SET moduleid='$row->id', menuid='$menuid'";
  266.             $database->setQuery$query );
  267.             $database->query();
  268.         }
  269.     }
  270.  
  271.  
  272.     switch $task {
  273.         case 'apply':
  274.             $msg sprintf(T_('Successfully Saved changes to Module: %s')$row->title;
  275.             mosRedirect'index2.php?option='$option .'&client='$client .'&task=editA&hidemainmenu=1&id='$row->id$msg );
  276.             break;
  277.  
  278.         case 'save':
  279.         default:
  280.             $msg sprintf(T_('Successfully Saved Module: %s')$row->title);
  281.             mosRedirect'index2.php?option='$option .'&client='$client$msg );
  282.             break;
  283.     }
  284. }
  285.  
  286. /**
  287. * Compiles information to add or edit a module
  288. @param string The current GET/POST option
  289. @param integer The unique id of the record to edit
  290. */
  291. function editModule$option$uid$client {
  292.     global $database$my$mainframe;
  293.     global $mosConfig_absolute_path;
  294.  
  295.     $lists array();
  296.     $row new mosModule$database );
  297.     // load the row from the db table
  298.     $row->load$uid );
  299.     // fail if checked out not by 'me'
  300.     if $row->checked_out && $row->checked_out <> $my->id {
  301.         echo "<script>alert('".sprintf(T_('The module %s is currently being edited by another administrator')$row->title)."'); document.location.href='index2.php?option=$option'</script>\n";
  302.         exit(0);
  303.     }
  304.  
  305.     $row->content htmlspecialcharsstr_replace'&amp;''&'$row->content ) );
  306.  
  307.     if $uid {
  308.         $row->checkout$my->id );
  309.     }
  310.     // if a new record we must still prime the mosModule object with a default
  311.     // position and the order; also add an extra item to the order list to
  312.     // place the 'new' record in last position if desired
  313.     if ($uid == 0{
  314.         $row->position 'left';
  315.         $row->showtitle true;
  316.         //$row->ordering = $l;
  317.         $row->published 1;
  318.     }
  319.  
  320.  
  321.     if $client == 'admin' {
  322.         $where                 "client_id='1'";
  323.         $lists['client_id'1;
  324.         //$path                = 'mod1_xml';
  325.     else {
  326.         $where                 "client_id='0'";
  327.         $lists['client_id'0;
  328.         //$path                = 'mod0_xml';
  329.     }
  330.     $path                'mod0_xml';
  331.     $query "SELECT position, ordering, showtitle, title"
  332.     . "\n FROM #__modules"
  333.     . "\n WHERE "$where
  334.     . "\n ORDER BY ordering"
  335.     ;
  336.  
  337.     $database->setQuery$query );
  338.     if !($orders $database->loadObjectList()) ) {
  339.         echo $database->stderr();
  340.         return false;
  341.     }
  342.  
  343.     $query "SELECT position, description"
  344.     . "\n FROM #__template_positions"
  345.     . "\n WHERE position <> ''"
  346.     ;
  347.     $database->setQuery$query );
  348.     // hard code options for now
  349.     $positions $database->loadObjectList();
  350.  
  351.     $orders2 array();
  352.     $pos array();
  353.     foreach ($positions as $position{
  354.         $orders2[$position->positionarray();
  355.         $pos[mosHTML::makeOption$position->position$position->description );
  356.     }
  357.  
  358.     $l 0;
  359.     $r 0;
  360.     for ($i=0$n=count$orders )$i $n$i++{
  361.         $ord 0;
  362.         if (array_key_exists$orders[$i]->position$orders2 )) {
  363.             $ord =countarray_keys$orders2[$orders[$i]->position) ) 1;
  364.         }
  365.  
  366.         $orders2[$orders[$i]->position][mosHTML::makeOption$ord$ord.'::'.addslashes$orders[$i]->title ) );
  367.     }
  368.  
  369.     // build the html select list
  370.     $pos_select 'onchange="changeDynaList(\'ordering\',orders,document.adminForm.position.options[document.adminForm.position.selectedIndex].value, originalPos, originalOrder)"';
  371.     $active $row->position $row->position 'left' );
  372.     $lists['position'mosHTML::selectList$pos'position''class="inputbox" size="1" '$pos_select'value''text'$active );
  373.  
  374.     // get selected pages for $lists['selections']
  375.     if $uid {
  376.         $query 'SELECT menuid AS value FROM #__modules_menu WHERE moduleid='$row->id;
  377.         $database->setQuery$query );
  378.         $lookup $database->loadObjectList();
  379.     else {
  380.         $lookup arraymosHTML::makeOption0'All' ) );
  381.     }
  382.  
  383.     if $row->access == 99 || $row->client_id == || $lists['client_id'{
  384.         $lists['access']             T_('Administrator').'<input type="hidden" name="access" value="99" />';
  385.         $lists['showtitle']         T_('N/A').' <input type="hidden" name="showtitle" value="1" />';
  386.         $lists['selections']         T_('N/A');
  387.     else {
  388.         if $client == 'admin' {
  389.             $lists['access']         T_('N/A');
  390.             $lists['selections']     T_('N/A');
  391.         else {
  392.             $lists['access']         mosAdminMenus::Access$row );
  393.             $lists['groups']         mosAdminMenus::groupAccess$row );
  394.             $lists['selections']     mosAdminMenus::MenuLinks$lookup1);
  395.         }
  396.         $lists['showtitle'mosHTML::yesnoRadioList'showtitle''class="inputbox"'$row->showtitle );
  397.     }
  398.  
  399.     // build the html select list for published
  400.     $lists['published']             mosAdminMenus::Published$row );
  401.  
  402.     // xml file for module
  403.     $xmlfile $mainframe->getPath$path$row->module );
  404.     if ($xmlfile{
  405.         $xmlparser =new mosXMLDescription ($xmlfile);
  406.         $row->description $xmlparser->getDescription('module');
  407.     else {
  408.         $row->description '';
  409.     }
  410.  
  411.     // get params definitions
  412.     $params =new mosAdminParameters$row->params$xmlfile'module' );
  413.  
  414.     HTML_modules::editModule$row$orders2$lists$params$option$client );
  415. }
  416.  
  417. /**
  418. * Deletes one or more modules
  419. *
  420. * Also deletes associated entries in the #__module_menu table.
  421. @param array An array of unique category id numbers
  422. */
  423. function removeModule&$cid$option$client {
  424.     global $database$my;
  425.  
  426.     if (count$cid 1{
  427.         echo "<script> alert('".T_('Select a module to delete')."'); window.history.go(-1);</script>\n";
  428.         exit;
  429.     }
  430.  
  431.     $cids implode','$cid );
  432.  
  433.     $database->setQuery"SELECT id, module, title, iscore, params FROM #__modules WHERE id IN ($cids));
  434.     if (!($rows $database->loadObjectList())) {
  435.         echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
  436.         exit;
  437.     }
  438.  
  439.     $err array();
  440.     $cid array();
  441.     foreach ($rows as $row{
  442.         if ($row->module == '' || $row->iscore == 0{
  443.             $cid[$row->id;
  444.         else {
  445.             $err[$row->title;
  446.         }
  447.         // mod_mainmenu modules only deletable via Menu Manager
  448.         if $row->module == 'mod_mainmenu' {
  449.             if strstr$row->params'منوی اصلی' ) ) {
  450.                 echo "<script> alert('".T_('You cannot delete mod_mainmenu module that displays the "mainmenu" as it is a core Menu')."'); window.history.go(-1); </script>\n";
  451.                 exit;
  452.             }
  453.         }
  454.     }
  455.  
  456.     if (count$cid )) {
  457.         $cids implode','$cid );
  458.         $database->setQuery"DELETE FROM #__modules WHERE id IN ($cids));
  459.         if (!$database->query()) {
  460.             echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
  461.             exit;
  462.         }
  463.         $database->setQuery"DELETE from #__modules_menu WHERE moduleid IN ($cids));
  464.         if (!$database->query()) {
  465.             echo "<script> alert('".$database->getErrorMsg()."');</script>\n";
  466.             exit;
  467.         }
  468.         $mod new mosModule$database );
  469.         $mod->ordering 0;
  470.         $mod->updateOrder"position='left'" );
  471.         $mod->updateOrder"position='right'" );
  472.     }
  473.  
  474.     if (count$err )) {
  475.         $cids addslashesimplode"', '"$err ) );
  476.         echo "<script>alert('".sprintf(T_('Module(s): "%s" cannot be deleted they can only be un-installed as they are Mambo modules.')$cids)."');</script>\n";
  477.     }
  478.  
  479.     mosRedirect'index2.php?option='$option .'&client='$client );
  480. }
  481.  
  482. /**
  483. * Publishes or Unpublishes one or more modules
  484. @param array An array of unique record id numbers
  485. @param integer 0 if unpublishing, 1 if publishing
  486. */
  487. function publishModule$cid=null$publish=1$option$client {
  488.     global $database$my;
  489.  
  490.     if (count$cid 1{
  491.         $action $publish T_('publish' )T_('unpublish');
  492.         echo "<script> alert('".sprintf(T_('Select a module to %s')$action)."'); window.history.go(-1);</script>\n";
  493.         exit;
  494.     }
  495.  
  496.     $cids implode','$cid );
  497.  
  498.     $query "UPDATE #__modules SET published='$publish'"
  499.     . "\n WHERE id IN ($cids)"
  500.     . "\n AND (checked_out=0 OR (checked_out='$my->id'))"
  501.     ;
  502.     $database->setQuery$query );
  503.     if (!$database->query()) {
  504.         echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
  505.         exit();
  506.     }
  507.  
  508.     if (count$cid == 1{
  509.         $row new mosModule$database );
  510.         $row->checkin$cid[0);
  511.     }
  512.  
  513.     mosRedirect'index2.php?option='$option .'&client='$client );
  514. }
  515.  
  516. /**
  517. * Cancels an edit operation
  518. */
  519. function cancelModule$option$client {
  520.     global $database;
  521.  
  522.     $row new mosModule$database );
  523.     // ignore array elements
  524.     $row->bind$_POST'selections params' );
  525.     // sanitize
  526.     $row->id intval($row->id);
  527.     $row->checkin();
  528.  
  529.     mosRedirect'index2.php?option='$option .'&client='$client );
  530. }
  531.  
  532. /**
  533. * Moves the order of a record
  534. @param integer The unique id of record
  535. @param integer The increment to reorder by
  536. */
  537. function orderModule$uid$inc$option {
  538.     global $database;
  539.  
  540.     $client mosGetParam$_POST'client''' );
  541.  
  542.     $row new mosModule$database );
  543.     $row->load$uid );
  544.     if ($client == 'admin'{
  545.         $where "client_id='1'";
  546.     else {
  547.         $where "client_id='0'";
  548.     }
  549.  
  550.     $row->move$inc"position='$row->position' AND ($where)"  );
  551.     if $client {
  552.         $client '&client=admin' ;
  553.     else {
  554.         $client '';
  555.     }
  556.  
  557.     mosRedirect'index2.php?option='$option .'&client='$client );
  558. }
  559.  
  560. /**
  561. * changes the access level of a record
  562. @param integer The increment to reorder by
  563. */
  564. function accessMenu$uid$access$option$client {
  565.     global $database;
  566.  
  567.     switch $access {
  568.         case 'accesspublic':
  569.             $access 0;
  570.             break;
  571.  
  572.         case 'accessregistered':
  573.             $access 1;
  574.             break;
  575.  
  576.         case 'accessspecial':
  577.             $access 2;
  578.             break;
  579.     }
  580.  
  581.     $row new mosModule$database );
  582.     $row->load$uid );
  583.     $row->access $access;
  584.  
  585.     if !$row->check() ) {
  586.         return $row->getError();
  587.     }
  588.     if !$row->store() ) {
  589.         return $row->getError();
  590.     }
  591.  
  592.     mosRedirect'index2.php?option='$option .'&client='$client );
  593. }
  594.  
  595. function saveOrder&$cid$client {
  596.     global $database;
  597.     $order         mosGetParam$_POST'order'array(0) );
  598.     $row        new mosMenu$database );
  599.     $positions array();
  600.     // update ordering values
  601.     foreach ($cid as $i=>$ciditem{
  602.         $row->load$ciditem );
  603.         if ($row->ordering != $order[$i]{
  604.             $row->ordering $order[$i];
  605.             if (!$row->store()) {
  606.                 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
  607.                 exit();
  608.             }
  609.             // remember to updateOrder this group
  610.             $positions[$row->position][$row->client_id$row->id;
  611.         }
  612.     }
  613.     // execute updateOrder for each group
  614.     foreach ($positions as $position=>$clients{
  615.         foreach ($clients as $client=>$rowid{
  616.             $row->updateOrder("position = '$position' AND client_id = '$client'");
  617.         }
  618.     // foreach
  619.  
  620.     $msg     T_('New ordering saved');
  621.     mosRedirect'index2.php?option=com_modules&client='$client$msg );
  622. // saveOrder
  623. ?>

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